21std::atomic<QRhi*> s_cachedRhi{
nullptr};
24std::atomic<QQuickWindow*> s_connectedWindow{
nullptr};
28std::array<QMetaObject::Connection, 3> s_connections;
32 s_snapshot.
backend.store(-1, std::memory_order_release);
33 s_snapshot.
d3d11Device.store(
nullptr, std::memory_order_release);
34 s_snapshot.
d3d12Device.store(
nullptr, std::memory_order_release);
35 s_snapshot.
adapterLuid.store(0, std::memory_order_release);
38 s_snapshot.
vkQueueIdx.store(0, std::memory_order_release);
42void populateSnapshot(QRhi* rhi)
48 const int backend =
static_cast<int>(rhi->backend());
49 void* d3d11 =
nullptr;
50 void* d3d12 =
nullptr;
52 void* vkPhysDev =
nullptr;
53 quint32 vkQueueFamilyIdx = 0;
54 quint32 vkQueueIdx = 0;
56#if defined(Q_OS_WIN) && defined(QGC_HAS_GST_D3D11_GPU_PATH)
57 if (rhi->backend() == QRhi::D3D11) {
58 if (
auto* h =
static_cast<const QRhiD3D11NativeHandles*
>(rhi->nativeHandles())) {
61 luid = (
static_cast<qint64
>(h->adapterLuidHigh) << 32) |
62 (
static_cast<qint64
>(h->adapterLuidLow) & 0xFFFFFFFFLL);
66#if defined(Q_OS_WIN) && defined(QGC_HAS_GST_D3D12_GPU_PATH)
67 if (rhi->backend() == QRhi::D3D12) {
68 if (
auto* h =
static_cast<const QRhiD3D12NativeHandles*
>(rhi->nativeHandles())) {
70 luid = (
static_cast<qint64
>(h->adapterLuidHigh) << 32) |
71 (
static_cast<qint64
>(h->adapterLuidLow) & 0xFFFFFFFFLL);
75#if defined(QGC_HAS_GST_VULKAN_GPU_PATH) && QT_CONFIG(vulkan)
76 if (rhi->backend() == QRhi::Vulkan) {
77 if (
auto* h =
static_cast<const QRhiVulkanNativeHandles*
>(rhi->nativeHandles())) {
78 vkPhysDev =
static_cast<void*
>(h->physDev);
79 vkQueueFamilyIdx = h->gfxQueueFamilyIdx;
80 vkQueueIdx = h->gfxQueueIdx;
87 s_snapshot.
d3d11Device.store(d3d11, std::memory_order_release);
88 s_snapshot.
d3d12Device.store(d3d12, std::memory_order_release);
89 s_snapshot.
adapterLuid.store(luid, std::memory_order_release);
91 s_snapshot.
vkQueueFamilyIdx.store(vkQueueFamilyIdx, std::memory_order_release);
92 s_snapshot.
vkQueueIdx.store(vkQueueIdx, std::memory_order_release);
93 s_snapshot.
framesInFlight.store(rhi->resourceLimit(QRhi::FramesInFlight), std::memory_order_release);
94 s_snapshot.
backend.store(backend, std::memory_order_release);
100 return s_cachedRhi.load(std::memory_order_acquire);
112 if (s_connectedWindow.load(std::memory_order_acquire) == window)
117 if (s_connectedWindow.load(std::memory_order_acquire) !=
nullptr) {
118 s_cachedRhi.store(
nullptr, std::memory_order_release);
120#if defined(QGC_HAS_ANY_GPU_PATH)
127 for (std::size_t i = 0; i < s_connections.size(); ++i) {
128 auto& conn = s_connections[i];
129 QObject::disconnect(conn);
130 conn = QMetaObject::Connection();
133 s_connectedWindow.store(window, std::memory_order_release);
136 s_connections[0] = QObject::connect(
137 window, &QQuickWindow::sceneGraphInitialized, window,
139 QRhi* rhi = window->rhi();
140 s_cachedRhi.store(rhi, std::memory_order_release);
141 populateSnapshot(rhi);
143 Qt::DirectConnection);
144 s_connections[1] = QObject::connect(
145 window, &QQuickWindow::sceneGraphInvalidated, window,
147 s_cachedRhi.store(
nullptr, std::memory_order_release);
149#if defined(QGC_HAS_ANY_GPU_PATH)
154 Qt::DirectConnection);
156 s_connections[2] = QObject::connect(
157 window, &QQuickWindow::destroyed, window,
159 s_connectedWindow.store(
nullptr, std::memory_order_release);
160 s_cachedRhi.store(
nullptr, std::memory_order_release);
162#if defined(QGC_HAS_ANY_GPU_PATH)
166 Qt::DirectConnection);
169 if (window->isSceneGraphInitialized()) {
170 window->scheduleRenderJob(QRunnable::create([window]() {
171 QRhi* rhi = window->rhi();
172 s_cachedRhi.store(rhi, std::memory_order_release);
173 populateSnapshot(rhi);
175 QQuickWindow::BeforeSynchronizingStage);