9#include <QtCore/QCoreApplication>
10#include <QtQuick/QQuickWindow>
11#include <QtQuick/QSGRendererInterface>
15#if defined(QGC_HAS_ANY_GPU_PATH)
20#if defined(QGC_HAS_GST_DMABUF_GPU_PATH)
26#if defined(QGC_UNITTEST_BUILD) && (defined(QGC_HAS_GST_DMABUF_GPU_PATH) || \
27 (defined(QGC_HAS_GST_D3D11_GPU_PATH) && defined(QGC_HAS_GST_D3D12_GPU_PATH)))
33#if defined(QGC_HAS_ANY_GPU_PATH)
40void forEachCompiledPath(Fn&& fn)
55std::atomic<bool> s_softwareRendering{
false};
61#if defined(QGC_HAS_ANY_GPU_PATH)
64 if (path->bridge && (path->bridge().handleSyncMessage(msg) == GST_BUS_DROP)) {
76#if defined(QGC_HAS_ANY_GPU_PATH)
79 path->bridge().rearm();
87#if defined(QGC_HAS_ANY_GPU_PATH)
89 for (
const HwPathDescriptor* path : paths) {
91 path->bridge().reset();
94 for (
const HwPathDescriptor* path : paths) {
95 if (path->resetCaches) {
104#if defined(QGC_HAS_ANY_GPU_PATH)
106 std::vector<GStreamer::GstElementPtr> pipelines;
113 return other.get() == pipeline.get();
116 pipelines.push_back(std::move(pipeline));
122 (void) gst_element_post_message(
131#if defined(QGC_HAS_ANY_GPU_PATH)
133 if (path->bridge && path->bridge().deviceLost()) {
143 s_softwareRendering.store(softwareRendering, std::memory_order_release);
144#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && \
145 (defined(QGC_HAS_GST_GLMEMORY_GPU_PATH) || defined(QGC_HAS_GST_DMABUF_GPU_PATH))
149 if (!softwareRendering && !qEnvironmentVariableIsSet(
"QSG_RHI_BACKEND")) {
150 QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
154 if (!qEnvironmentVariableIsSet(
"QT_XCB_GL_INTEGRATION")) {
155 (void) qputenv(
"QT_XCB_GL_INTEGRATION",
"xcb_egl");
159#if defined(QGC_HAS_GST_GLMEMORY_GPU_PATH) || defined(QGC_HAS_GST_DMABUF_GPU_PATH)
160 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
163#if defined(QGC_HAS_GST_DMABUF_VULKAN_IMPORT)
164 GstDmaBufVulkan::requestDeviceExtensions();
170 return s_softwareRendering.load(std::memory_order_acquire);
175#if defined(QGC_HAS_ANY_GPU_PATH)
185#if defined(QGC_HAS_ANY_GPU_PATH)
193 qCDebug(HwBuffersFacadeLog).noquote()
194 <<
"zero-copy paths compiled:" << available.trimmed() <<
"— actual path chosen at caps negotiation";
196 if (path->prepareContext) {
197 path->prepareContext(ctx);
201 Q_UNUSED(gpuEnabled);
208#if defined(QGC_HAS_GST_DMABUF_GPU_PATH)
209 if (GstDmaBufVideoBuffer::importDisabled()) {
212#ifdef QGC_UNITTEST_BUILD
213 if (
const std::optional<GstQgc::SinkEnvironment> environment = GstQgc::sinkEnvironmentForTest()) {
214 return environment->dmaBufDisplay;
219#if defined(QGC_HAS_GST_DMABUF_VULKAN_IMPORT)
220 return GstDmaBufVulkan::importDevice();
233#if defined(QGC_HAS_GST_D3D11_GPU_PATH) || defined(QGC_HAS_GST_D3D12_GPU_PATH)
242#if defined(QGC_HAS_ANY_GPU_PATH)
249#if defined(QGC_HAS_GST_D3D11_GPU_PATH) && defined(QGC_HAS_GST_D3D12_GPU_PATH)
250#ifdef QGC_UNITTEST_BUILD
251 if (
const std::optional<GstQgc::SinkEnvironment> environment = GstQgc::sinkEnvironmentForTest()) {
252 return environment->d3d11OpensD3D12;
263#if defined(QGC_HAS_ANY_GPU_PATH)
265 if (path->bridge && path->bridge().answerContextQuery(query, sink)) {
276 guint minBuffers)
noexcept
278#if defined(QGC_HAS_ANY_GPU_PATH)
280 if (path->proposePool && path->proposePool(query, caps, vinfo, size, minBuffers)) {
289 Q_UNUSED(minBuffers);
297#if defined(QGC_HAS_ANY_GPU_PATH)
301 return now.
count(path, key) - baseline.
count(path, key);
309 std::optional<Counter> second = std::nullopt;
312 static constexpr CounterField kCounterFields[] = {
313 {
"failures", Counter::MapFailures},
314 {
"reuse", Counter::TextureReuse},
315 {
"wait[gpu/cpu]", Counter::GpuWaits, Counter::CpuWaits},
316 {
"fence-timeouts", Counter::ProducerFenceTimeouts},
317 {
"image-cache[hit/miss]", Counter::ImageCacheHits, Counter::ImageCacheMisses},
319 static constexpr std::pair<GstHwPathTelemetry::HwFallbackReason, const char*> kReasons[] = {
330 for (
const CounterField& field : kCounterFields) {
331 const quint64 first = delta(path, field.first);
332 bool nonzero = (first > 0);
333 QString counts = QString::number(first);
335 const quint64 second = delta(path, *field.second);
336 nonzero = nonzero || (second > 0);
337 counts += u
'/' + QString::number(second);
340 out += QStringLiteral(
" %1-%2:%3").arg(pathLabel, QLatin1String(field.label), counts);
345 out += QStringLiteral(
" %1-map-us:%2").arg(pathLabel).arg(ewmaUs);
347 QString reasonBreakdown;
348 for (
const auto& [reason, label] : kReasons) {
349 const quint64 n = delta(path, reason);
351 reasonBreakdown += QStringLiteral(
"%1=%2,").arg(QLatin1String(label)).arg(n);
354 if (!reasonBreakdown.isEmpty()) {
355 reasonBreakdown.chop(1);
356 out += QStringLiteral(
" %1-fallback[%2]").arg(pathLabel).arg(reasonBreakdown);
361 if (unknownMem > 0) {
362 out += QStringLiteral(
" None-fallback[unknown-mem=%1]").arg(unknownMem);
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
struct _GstElement GstElement
#define QGC_LOGGING_CATEGORY(name, categoryStr)
std::unique_ptr< GstElement, GstObjectDeleter > GstElementPtr
bool has(HwVideoBufferPath path) noexcept
std::span< const HwPathDescriptor *const > paths() noexcept
Counter
Per-path event counts.
quint64 peekMapDurationUsEwma(HwVideoBufferPath path) noexcept
Snapshot snapshot() noexcept
constexpr std::size_t kPathCount
constexpr const char * toString(HwVideoBufferPath path) noexcept
qint64 graphicsAdapterLuid() noexcept
bool d3d11OpensD3D12() noexcept
bool proposeDeviceBoundPool(GstQuery *query, GstCaps *caps, const GstVideoInfo *vinfo, gsize size, guint minBuffers) noexcept
constexpr char kGraphicsDeviceLostMessage[]
GstBusSyncReply onBusSyncMessage(GstMessage *msg) noexcept
void onGraphicsDeviceRemoved()
void setGraphicsDevicePublishedHandler(void(*handler)()) noexcept
void * dmaBufImportDisplay() noexcept
void resetCachedGpuResources()
void connectMainWindow(QQuickWindow *window)
void configureQtGraphics(bool softwareRendering)
QString extraPathStatsSince(const GstHwPathTelemetry::Snapshot &baseline)
bool graphicsDeviceLost() noexcept
bool answerSinkBinContextQuery(GstQuery *query, GstElement *sink) noexcept
bool softwareRenderingRequested() noexcept
What configureQtGraphics() was told: the user asked for software rendering (–swrast)....
HwVideoBufferContext makeAdapterContext(bool gpuEnabled) noexcept
void setPublishedHandler(void(*handler)()) noexcept
void connectWindow(QQuickWindow *window)
DeviceSnapshot & deviceSnapshot() noexcept
Returns the global snapshot. Atomic fields make individual reads thread-safe.
Every counter and fallback reason at one instant; a reader's baseline for counts since then.
quint64 count(HwVideoBufferPath path, Counter counter) const noexcept
std::atomic< bool > d3d11OpensD3D12
std::atomic< qint64 > adapterLuid