summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhid3d12_p.h
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-06-20 14:14:24 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-06-22 15:20:26 +0200
commitb7d9b7fa6921161da8e4d048d5660f3181d89739 (patch)
tree50987605b0d7d521e133467ca2026d2019b5261d /src/gui/rhi/qrhid3d12_p.h
parent1d9bf6ea38f12f55acc00cfd1072b1ef040a4cc4 (diff)
rhi: d3d12: Implement multiview support
This relies on qsb being able to invoke dxc instead of fxc when the request HLSL (shader model) version is 6.1. (6.1 is required for SV_ViewID) This currently works only when conditioning offline with qsb (or via CMake), because qsb can easily invoke dxc instead of fxc. When shipping HLSL inside the .qsb package (so when -c is not specified or running the external tool fails), this won't work since the D3D12 backend still uses D3DCompile(), not IDxcCompiler. Support for that will be investigated separately. We also need to bump to ID3D12Device2 and ID3D12GraphicsCommandList1. With Windows 10 version 1703 being quite old now, this should not be a problem at run time. There are however issues at build time, namely that MinGW and MinGW/LLVM and similar seems to have ancient Windows SDK headers according to the CI test runs. None of the MSVC configurations have this in the CI, they have reasonable versions of d3d12.h and similar. Therefore, one important aspect of this change is that the D3D12 backend of QRhi will only be available from now on when the SDK headers are new enough (meaning ID3D12Device2 is declared, which is a several years old type now). Otherwise, QRhi::create() will simply fail when asking for D3D12 with a helpful warning message about the Qt build being crippled. Implementation-wise, there are surprises in store as well: The way the PSO is created needs to be revamped to follow the extensible approach that uses a pipeline state stream description. Both the graphics and compute pipeline creation is changed to use CreatePipelineState() and the associated machinery. This is only really essential for graphics pipelines since we know have to include data for view instancing (multiview). For compute the result is the same as before. Additionally, the view count must now be baked into the QRhiGraphicsPipeline. This means that applications must call setMultiViewCount() with the same value (typically 2) *both* on the render target's color attachment and on the pipeline. Backends that do not care about the pipeline's view count (GL, Vulkan) will of course ignore it, but if it's not set correctly D3D12 will fail. The manual test is updated accordingly. Fixes: QTBUG-114772 Change-Id: I93db7313377e711c2faeb956815899b12132d23b Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhid3d12_p.h')
-rw-r--r--src/gui/rhi/qrhid3d12_p.h31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/gui/rhi/qrhid3d12_p.h b/src/gui/rhi/qrhid3d12_p.h
index a6954d279c..bfc2f530db 100644
--- a/src/gui/rhi/qrhid3d12_p.h
+++ b/src/gui/rhi/qrhid3d12_p.h
@@ -30,6 +30,15 @@
#include "D3D12MemAlloc.h"
+// ID3D12Device2 and ID3D12GraphicsCommandList1 and types and enums introduced
+// with those are hard requirements now. These should be declared in any
+// moderately recent d3d12.h, but if it is an SDK from before Windows 10
+// version 1703 then these types could be missing. In the absence of other
+// options, handle this by skipping all the code and making QRhi::create() fail
+// in such builds.
+#ifdef __ID3D12Device2_INTERFACE_DEFINED__
+#define QRHI_D3D12_AVAILABLE
+
QT_BEGIN_NAMESPACE
static const int QD3D12_FRAMES_IN_FLIGHT = 2;
@@ -863,6 +872,7 @@ struct QD3D12GraphicsPipeline : public QRhiGraphicsPipeline
QD3D12ObjectHandle rootSigHandle;
std::array<QD3D12ShaderStageData, 5> stageData;
D3D12_PRIMITIVE_TOPOLOGY topology;
+ UINT viewInstanceMask = 0;
uint generation = 0;
friend class QRhiD3D12;
};
@@ -889,7 +899,7 @@ struct QD3D12CommandBuffer : public QRhiCommandBuffer
const QRhiNativeHandles *nativeHandles();
- ID3D12GraphicsCommandList *cmdList = nullptr; // not owned
+ ID3D12GraphicsCommandList1 *cmdList = nullptr; // not owned
QRhiD3D12CommandBufferNativeHandles nativeHandlesStruct;
enum PassType {
@@ -984,12 +994,19 @@ struct QD3D12SwapChain : public QRhiSwapChain
ID3D12Fence *fence = nullptr;
HANDLE fenceEvent = nullptr;
UINT64 fenceCounter = 0;
- ID3D12GraphicsCommandList *cmdList = nullptr;
+ ID3D12GraphicsCommandList1 *cmdList = nullptr;
} frameRes[QD3D12_FRAMES_IN_FLIGHT];
int currentFrameSlot = 0; // index in frameRes
};
+template<typename T, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type>
+struct alignas(void*) QD3D12PipelineStateSubObject
+{
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = Type;
+ T object = {};
+};
+
class QRhiD3D12 : public QRhiImplementation
{
public:
@@ -1111,7 +1128,7 @@ public:
void waitGpu();
DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount, DXGI_FORMAT format) const;
bool ensureDirectCompositionDevice();
- bool startCommandListForCurrentFrameSlot(ID3D12GraphicsCommandList **cmdList);
+ bool startCommandListForCurrentFrameSlot(ID3D12GraphicsCommandList1 **cmdList);
void enqueueResourceUpdates(QD3D12CommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates);
void finishActiveReadbacks(bool forced = false);
bool ensureShaderVisibleDescriptorHeapCapacity(QD3D12ShaderVisibleDescriptorHeap *h,
@@ -1122,7 +1139,7 @@ public:
void bindShaderVisibleHeaps(QD3D12CommandBuffer *cbD);
bool debugLayer = false;
- ID3D12Device *dev = nullptr;
+ ID3D12Device2 *dev = nullptr;
D3D_FEATURE_LEVEL minimumFeatureLevel = D3D_FEATURE_LEVEL(0);
LUID adapterLuid = {};
bool importedDevice = false;
@@ -1187,8 +1204,14 @@ public:
const QRhiShaderResourceBinding::Data::StorageImageData &d,
QD3D12ShaderResourceVisitor::StorageOp op,
int shaderRegister);
+
+ struct {
+ bool multiView = false;
+ } caps;
};
QT_END_NAMESPACE
+#endif // __ID3D12Device2_INTERFACE_DEFINED__
+
#endif