QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstD3D12ContextBridge.cc
Go to the documentation of this file.
2
4
5#if defined(Q_OS_WIN) && defined(QGC_HAS_GST_D3D12_GPU_PATH)
6
7#include <gst/d3d12/gstd3d12.h>
8#include <rhi/qrhi.h> // QRhi::Implementation enum only; native handles come from the snapshot
9
10#include "QGCLoggingCategory.h"
11#include "QGCRhiCapture.h"
12
13QGC_LOGGING_CATEGORY(GstD3D12BridgeLog, "Video.GStreamer.HwBuffers.GstD3D12Bridge")
14
15namespace GstD3D12ContextBridge {
16namespace {
17
18GstD3DContextBridgeCommon::BridgeState s_state;
19
20GstObject* createDevice(const QLoggingCategory& cat)
21{
22 // LUID halves were sign-extended into a 64-bit value matching LARGE_INTEGER::QuadPart when the snapshot was
23 // composed.
24 const gint64 luid = QGCRhiCapture::deviceSnapshot().adapterLuid.load(std::memory_order_acquire);
25
26 GstD3D12Device* device = gst_d3d12_device_new_for_adapter_luid(luid);
27 if (!device) {
28 qCWarning(cat) << "gst_d3d12_device_new_for_adapter_luid failed (luid=" << luid << ")";
29 return nullptr;
30 }
31
32 GstD3DContextBridgeCommon::logAdapterMatch(luid, device, cat, "D3D12");
33 return GST_OBJECT(device);
34}
35
36GstContext* makeContext(GstObject* device)
37{
38 // gst_d3d12_context_new gst_object_ref's the device internally; caller retains ownership.
39 return gst_d3d12_context_new(GST_D3D12_DEVICE_CAST(device));
40}
41
42const GstD3DContextBridgeCommon::BridgeOps s_ops = {
43 "D3D12", GST_D3D12_DEVICE_HANDLE_CONTEXT_TYPE, &GstD3D12BridgeLog, int(QRhi::D3D12), &createDevice, &makeContext,
44};
45
46struct D3D12BridgeRegistrar
47{
48 D3D12BridgeRegistrar() { GstD3DContextBridgeCommon::registerBridge(GstD3D12BridgeLog(), &handleSyncMessage, &reset); }
49};
50
51static D3D12BridgeRegistrar s_d3d12BridgeRegistrar;
52
53} // namespace
54
55bool prime()
56{
57 return GstD3DContextBridgeCommon::prime(s_state, s_ops);
58}
59
60GstD3D12Device* currentDevice()
61{
62 return GST_D3D12_DEVICE_CAST(GstD3DContextBridgeCommon::currentDevice(s_state));
63}
64
65GstBusSyncReply handleSyncMessage(GstMessage* message)
66{
67 return GstD3DContextBridgeCommon::handleSyncMessage(s_state, s_ops, message);
68}
69
70bool answerContextQuery(GstQuery* query)
71{
72 return GstD3DContextBridgeCommon::answerContextQuery(s_state, s_ops, query);
73}
74
75void reset()
76{
77 GstD3DContextBridgeCommon::reset(s_state, s_ops);
78}
79
80} // namespace GstD3D12ContextBridge
81
82#endif // Q_OS_WIN && QGC_HAS_GST_D3D12_GPU_PATH
#define QGC_LOGGING_CATEGORY(name, categoryStr)
DeviceSnapshot & deviceSnapshot() noexcept
Returns the global snapshot. Atomic fields make individual reads thread-safe.
std::atomic< qint64 > adapterLuid
Composed (high<<32)|low LUID, 0 if unknown.