3#if defined(Q_OS_WIN) && (defined(QGC_HAS_GST_D3D11_GPU_PATH) || defined(QGC_HAS_GST_D3D12_GPU_PATH))
8#include <glib-object.h>
10namespace GstD3DContextBridgeCommon {
16QRhi *checkRhiBackend(BridgeState &state,
17 const QLoggingCategory &cat,
19 const char *backendName)
23 qCDebug(cat) <<
"QRhi not yet available; will retry on next NEED_CONTEXT";
26 if (
static_cast<int>(rhi->backend()) != expectedBackend) {
27 if (!state.warnedWrongBackend) {
28 qCInfo(cat) <<
"QRhi backend is" << rhi->backendName()
29 <<
"(not" << backendName <<
"); bridge inactive";
30 state.warnedWrongBackend =
true;
37GstElement *matchNeedContext(GstMessage *message,
const char *expectedContextType)
39 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_NEED_CONTEXT) {
42 const gchar *contextType =
nullptr;
43 if (!gst_message_parse_context_type(message, &contextType) || !contextType) {
46 if (g_strcmp0(contextType, expectedContextType) != 0) {
49 return GST_ELEMENT(GST_MESSAGE_SRC(message));
52void logHandoff(BridgeState &state,
53 const QLoggingCategory &cat,
57 if (!state.loggedFirstHandoff.exchange(
true, std::memory_order_relaxed)) {
58 qCInfo(cat) <<
"First" << apiName <<
"device handoff to element"
59 << GST_ELEMENT_NAME(element);
61 qCDebug(cat) <<
"Provided" << apiName <<
"device context to" << GST_ELEMENT_NAME(element);
65gint64 readAdapterLuid(gpointer device)
67 if (!device || !G_IS_OBJECT(device))
return 0;
69 g_object_get(G_OBJECT(device),
"adapter-luid", &luid,
nullptr);
73void logAdapterMatch(QRhi *rhi, gint64 expectedLuid, gpointer gstDevice,
74 const QLoggingCategory &cat,
const char *apiName)
76 const gint64 actualLuid = readAdapterLuid(gstDevice);
77 if (actualLuid != expectedLuid) {
78 qCWarning(cat).noquote()
79 << apiName <<
"bridge: gst device LUID mismatch — QRhi LUID="
80 << expectedLuid <<
"but wrapped device LUID=" << actualLuid
81 <<
"(zero-copy will appear corrupt; check NEED_CONTEXT race)";
85 const QRhiDriverInfo info = rhi->driverInfo();
87 << apiName <<
"bridge adapter:" << info.deviceName
88 << QString::asprintf(
"(vendorId=0x%04X deviceId=0x%04X type=%d luid=%lld)",
89 unsigned(info.vendorId),
unsigned(info.deviceId),
90 int(info.deviceType),
static_cast<long long>(expectedLuid));
struct _GstElement GstElement
QRhi * cachedRhi() noexcept