27#include <d3d12sdklayers.h>
31#include "D3D12MemAlloc.h"
39#ifdef __ID3D12Device2_INTERFACE_DEFINED__
40#define QRHI_D3D12_AVAILABLE
44#ifdef __ID3D12GraphicsCommandList5_INTERFACE_DEFINED__
45#define QRHI_D3D12_CL5_AVAILABLE
46using D3D12GraphicsCommandList = ID3D12GraphicsCommandList5;
48using D3D12GraphicsCommandList = ID3D12GraphicsCommandList1;
51#ifdef __ID3D12InfoQueue1_INTERFACE_DEFINED__
52#define QRHI_D3D12_INFOQUEUE1_AVAILABLE
55#ifdef __ID3D12PipelineLibrary1_INTERFACE_DEFINED__
56#define QRHI_D3D12_PIPELINE_LIBRARY_AVAILABLE
61static const int QD3D12_FRAMES_IN_FLIGHT = 2;
65struct QD3D12Descriptor
67 D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = {};
68 D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {};
70 bool isValid()
const {
return cpuHandle.ptr != 0; }
73struct QD3D12ReleaseQueue;
75struct QD3D12DescriptorHeap
77 bool isValid()
const {
return heap && capacity; }
78 bool create(ID3D12Device *device,
79 quint32 descriptorCount,
80 D3D12_DESCRIPTOR_HEAP_TYPE heapType,
81 D3D12_DESCRIPTOR_HEAP_FLAGS heapFlags);
82 void createWithExisting(
const QD3D12DescriptorHeap &other,
83 quint32 offsetInDescriptors,
84 quint32 descriptorCount);
86 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
88 QD3D12Descriptor get(quint32 count);
89 QD3D12Descriptor at(quint32 index)
const;
90 quint32 remainingCapacity()
const {
return capacity - head; }
92 QD3D12Descriptor incremented(
const QD3D12Descriptor &descriptor, quint32 offsetInDescriptors)
const
94 D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = descriptor.cpuHandle;
95 cpuHandle.ptr += offsetInDescriptors * descriptorByteSize;
96 D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = descriptor.gpuHandle;
98 gpuHandle.ptr += offsetInDescriptors * descriptorByteSize;
99 return { cpuHandle, gpuHandle };
102 ID3D12DescriptorHeap *heap =
nullptr;
103 quint32 capacity = 0;
104 QD3D12Descriptor heapStart;
106 quint32 descriptorByteSize = 0;
107 D3D12_DESCRIPTOR_HEAP_TYPE heapType;
108 D3D12_DESCRIPTOR_HEAP_FLAGS heapFlags;
111struct QD3D12CpuDescriptorPool
113 bool isValid()
const {
return !heaps.isEmpty(); }
114 bool create(ID3D12Device *device, D3D12_DESCRIPTOR_HEAP_TYPE heapType,
const char *debugName =
"");
117 QD3D12Descriptor allocate(quint32 count);
118 void release(
const QD3D12Descriptor &descriptor, quint32 count);
120 static const int DESCRIPTORS_PER_HEAP = 256;
123 QD3D12DescriptorHeap heap;
125 static HeapWithMap init(
const QD3D12DescriptorHeap &heap, quint32 descriptorCount) {
128 result.map.resize(descriptorCount);
133 ID3D12Device *device;
134 quint32 descriptorByteSize;
135 QVector<HeapWithMap> heaps;
136 const char *debugName;
139struct QD3D12QueryHeap
141 bool isValid()
const {
return heap && capacity; }
142 bool create(ID3D12Device *device,
144 D3D12_QUERY_HEAP_TYPE heapType);
147 ID3D12QueryHeap *heap =
nullptr;
148 quint32 capacity = 0;
151struct QD3D12StagingArea
153 static const quint32 ALIGNMENT = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
157 D3D12_GPU_VIRTUAL_ADDRESS gpuAddr = 0;
158 ID3D12Resource *buffer =
nullptr;
159 quint32 bufferOffset = 0;
160 bool isValid()
const {
return p !=
nullptr; }
163 bool isValid()
const {
return allocation && mem.isValid(); }
164 bool create(QRhiD3D12 *rhi, quint32 capacity, D3D12_HEAP_TYPE heapType);
166 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
168 Allocation get(quint32 byteSize);
170 quint32 remainingCapacity()
const
172 return capacity - head;
175 static quint32 allocSizeForArray(quint32 size,
int count = 1)
177 return count * ((size + ALIGNMENT - 1) & ~(ALIGNMENT - 1));
181 ID3D12Resource *resource =
nullptr;
182 D3D12MA::Allocation *allocation =
nullptr;
187struct QD3D12ObjectHandle
190 quint32 generation = 0;
193 bool isNull()
const {
return index == 0 && generation == 0; }
196inline bool operator==(
const QD3D12ObjectHandle &a,
const QD3D12ObjectHandle &b)
noexcept
198 return a.index == b.index && a.generation == b.generation;
201inline bool operator!=(
const QD3D12ObjectHandle &a,
const QD3D12ObjectHandle &b)
noexcept
207struct QD3D12ObjectPool
209 void create(
const char *debugName =
"")
211 this->debugName = debugName;
212 Q_ASSERT(data.isEmpty());
218 for (Data &d : data) {
219 if (d.object.has_value()) {
221 d.object->releaseResources();
227 static bool leakCheck =
true;
230 static bool leakCheck = qEnvironmentVariableIntValue(
"QT_RHI_LEAK_CHECK");
234 qWarning(
"QD3D12ObjectPool::destroy(): Pool %p '%s' had %d unreleased objects",
235 this, debugName, leakCount);
240 bool isValid(
const QD3D12ObjectHandle &handle)
const
242 return handle.index > 0
243 && handle.index < quint32(data.count())
244 && handle.generation > 0
245 && handle.generation == data[handle.index].generation
246 && data[handle.index].object.has_value();
249 T lookup(
const QD3D12ObjectHandle &handle)
const
251 return isValid(handle) ? *data[handle.index].object : T();
254 const T *lookupRef(
const QD3D12ObjectHandle &handle)
const
256 return isValid(handle) ? &*data[handle.index].object :
nullptr;
259 T *lookupRef(
const QD3D12ObjectHandle &handle)
261 return isValid(handle) ? &*data[handle.index].object :
nullptr;
264 QD3D12ObjectHandle add(
const T &object)
266 Q_ASSERT(!data.isEmpty());
267 const quint32 count = quint32(data.count());
269 for (; index < count; ++index) {
270 if (!data[index].object.has_value())
274 data[index].object = object;
275 quint32 &generation = data[index].generation;
277 return { index, generation };
279 data.append({ object, 1 });
284 void remove(
const QD3D12ObjectHandle &handle)
286 if (T *object = lookupRef(handle)) {
287 object->releaseResources();
288 data[handle.index].object.reset();
292 const char *debugName;
294 std::optional<T> object;
295 quint32 generation = 0;
302 ID3D12Resource *resource;
303 D3D12_RESOURCE_STATES state;
304 D3D12_RESOURCE_DESC desc;
305 D3D12MA::Allocation *allocation;
307 enum { UavUsageRead = 0x01, UavUsageWrite = 0x02 };
313 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12Resource> *pool,
314 ID3D12Resource *resource,
315 D3D12_RESOURCE_STATES state,
316 D3D12MA::Allocation *allocation =
nullptr,
317 void *cpuMapPtr =
nullptr)
320 return pool->add({ resource, state, resource->GetDesc(), allocation, cpuMapPtr, 0,
true });
324 static QD3D12ObjectHandle addNonOwningToPool(QD3D12ObjectPool<QD3D12Resource> *pool,
325 ID3D12Resource *resource,
326 D3D12_RESOURCE_STATES state)
329 return pool->add({ resource, state, resource->GetDesc(),
nullptr,
nullptr, 0,
false });
332 void releaseResources()
338 allocation->Release();
350 ID3D12PipelineState *pso;
352 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12Pipeline> *pool,
354 ID3D12PipelineState *pso)
356 return pool->add({ type, pso });
359 void releaseResources()
365struct QD3D12RootSignature
367 ID3D12RootSignature *rootSig;
369 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12RootSignature> *pool,
370 ID3D12RootSignature *rootSig)
372 return pool->add({ rootSig });
375 void releaseResources()
381struct QD3D12ReleaseQueue
383 void create(QD3D12ObjectPool<QD3D12Resource> *resourcePool,
384 QD3D12ObjectPool<QD3D12Pipeline> *pipelinePool,
385 QD3D12ObjectPool<QD3D12RootSignature> *rootSignaturePool)
387 this->resourcePool = resourcePool;
388 this->pipelinePool = pipelinePool;
389 this->rootSignaturePool = rootSignaturePool;
392 void deferredReleaseResource(
const QD3D12ObjectHandle &handle);
393 void deferredReleaseResourceWithViews(
const QD3D12ObjectHandle &handle,
394 QD3D12CpuDescriptorPool *pool,
395 const QD3D12Descriptor &viewsStart,
397 void deferredReleasePipeline(
const QD3D12ObjectHandle &handle);
398 void deferredReleaseRootSignature(
const QD3D12ObjectHandle &handle);
399 void deferredReleaseCallback(std::function<
void(
void*)> callback,
void *userData);
400 void deferredReleaseResourceAndAllocation(ID3D12Resource *resource,
401 D3D12MA::Allocation *allocation);
402 void deferredReleaseDescriptorHeap(ID3D12DescriptorHeap *heap);
403 void deferredReleaseViews(QD3D12CpuDescriptorPool *pool,
404 const QD3D12Descriptor &viewsStart,
407 void activatePendingDeferredReleaseRequests(
int frameSlot);
408 void executeDeferredReleases(
int frameSlot,
bool forced =
false);
411 struct DeferredReleaseEntry {
417 ResourceAndAllocation,
421 Type type = Resource;
422 std::optional<
int> frameSlotToBeReleasedIn;
423 QD3D12ObjectHandle handle;
424 QD3D12CpuDescriptorPool *poolForViews =
nullptr;
425 QD3D12Descriptor viewsStart;
427 std::function<
void(
void*)> callback =
nullptr;
428 void *callbackUserData =
nullptr;
429 std::pair<ID3D12Resource *, D3D12MA::Allocation *> resourceAndAllocation = {};
430 ID3D12DescriptorHeap *descriptorHeap =
nullptr;
432 QVector<DeferredReleaseEntry> queue;
433 QD3D12ObjectPool<QD3D12Resource> *resourcePool =
nullptr;
434 QD3D12ObjectPool<QD3D12Pipeline> *pipelinePool =
nullptr;
435 QD3D12ObjectPool<QD3D12RootSignature> *rootSignaturePool =
nullptr;
438struct QD3D12CommandBuffer;
440struct QD3D12ResourceBarrierGenerator
442 static const int PREALLOC = 16;
444 void create(QD3D12ObjectPool<QD3D12Resource> *resourcePool)
446 this->resourcePool = resourcePool;
449 void addTransitionBarrier(
const QD3D12ObjectHandle &resourceHandle, D3D12_RESOURCE_STATES stateAfter);
450 void enqueueBufferedTransitionBarriers(QD3D12CommandBuffer *cbD);
451 void enqueueSubresourceTransitionBarrier(QD3D12CommandBuffer *cbD,
452 const QD3D12ObjectHandle &resourceHandle,
454 D3D12_RESOURCE_STATES stateBefore,
455 D3D12_RESOURCE_STATES stateAfter);
456 void enqueueUavBarrier(QD3D12CommandBuffer *cbD,
const QD3D12ObjectHandle &resourceHandle);
458 struct TransitionResourceBarrier {
459 QD3D12ObjectHandle resourceHandle;
460 D3D12_RESOURCE_STATES stateBefore;
461 D3D12_RESOURCE_STATES stateAfter;
463 QVarLengthArray<TransitionResourceBarrier, PREALLOC> transitionResourceBarriers;
464 QD3D12ObjectPool<QD3D12Resource> *resourcePool =
nullptr;
467struct QD3D12ShaderBytecodeCache
471 Shader(
const QByteArray &bytecode,
const QShader::NativeResourceBindingMap &rbm)
472 : bytecode(bytecode), nativeResourceBindingMap(rbm)
475 QShader::NativeResourceBindingMap nativeResourceBindingMap;
478 QHash<QRhiShaderStage, Shader> data;
480 void insertWithCapacityLimit(
const QRhiShaderStage &key,
const Shader &s);
483struct QD3D12ShaderVisibleDescriptorHeap
485 bool create(ID3D12Device *device, D3D12_DESCRIPTOR_HEAP_TYPE type, quint32 perFrameDescriptorCount);
487 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
489 QD3D12DescriptorHeap heap;
490 QD3D12DescriptorHeap perFrameHeapSlice[QD3D12_FRAMES_IN_FLIGHT];
494struct Q_D3D12_SAMPLER_DESC
496 D3D12_SAMPLER_DESC desc;
498 friend bool operator==(
const Q_D3D12_SAMPLER_DESC &lhs,
const Q_D3D12_SAMPLER_DESC &rhs)
noexcept
500 return lhs.desc.Filter == rhs.desc.Filter
501 && lhs.desc.AddressU == rhs.desc.AddressU
502 && lhs.desc.AddressV == rhs.desc.AddressV
503 && lhs.desc.AddressW == rhs.desc.AddressW
504 && lhs.desc.MipLODBias == rhs.desc.MipLODBias
505 && lhs.desc.MaxAnisotropy == rhs.desc.MaxAnisotropy
506 && lhs.desc.ComparisonFunc == rhs.desc.ComparisonFunc
508 && lhs.desc.MinLOD == rhs.desc.MinLOD
509 && lhs.desc.MaxLOD == rhs.desc.MaxLOD;
512 friend bool operator!=(
const Q_D3D12_SAMPLER_DESC &lhs,
const Q_D3D12_SAMPLER_DESC &rhs)
noexcept
514 return !(lhs == rhs);
517 friend size_t qHash(
const Q_D3D12_SAMPLER_DESC &key, size_t seed = 0)
noexcept
519 QtPrivate::QHashCombine hash(seed);
520 seed = hash(seed, key.desc.Filter);
521 seed = hash(seed, key.desc.AddressU);
522 seed = hash(seed, key.desc.AddressV);
523 seed = hash(seed, key.desc.AddressW);
524 seed = hash(seed, key.desc.MipLODBias);
525 seed = hash(seed, key.desc.MaxAnisotropy);
526 seed = hash(seed, key.desc.ComparisonFunc);
528 seed = hash(seed, key.desc.MinLOD);
529 seed = hash(seed, key.desc.MaxLOD);
536struct Q_D3D12_SAMPLER_DESC_LIST
538 QVarLengthArray<Q_D3D12_SAMPLER_DESC, 8> descs;
540 friend bool operator==(
const Q_D3D12_SAMPLER_DESC_LIST &lhs,
const Q_D3D12_SAMPLER_DESC_LIST &rhs)
noexcept
542 return lhs.descs == rhs.descs;
545 friend bool operator!=(
const Q_D3D12_SAMPLER_DESC_LIST &lhs,
const Q_D3D12_SAMPLER_DESC_LIST &rhs)
noexcept
547 return !(lhs == rhs);
550 friend size_t qHash(
const Q_D3D12_SAMPLER_DESC_LIST &key, size_t seed = 0)
noexcept
552 return qHashRange(key.descs.cbegin(), key.descs.cend(), seed);
556struct QD3D12SamplerManager
558 const quint32 MAX_SAMPLERS = 512;
560 bool create(ID3D12Device *device);
563 QD3D12Descriptor getShaderVisibleDescriptor(
const D3D12_SAMPLER_DESC &desc);
567 QD3D12Descriptor getShaderVisibleDescriptors(
const QVarLengthArray<Q_D3D12_SAMPLER_DESC, 8> &descs);
569 ID3D12Device *device =
nullptr;
570 QD3D12ShaderVisibleDescriptorHeap shaderVisibleSamplerHeap;
581 QHash<Q_D3D12_SAMPLER_DESC, QD3D12Descriptor> gpuMap;
582 QHash<Q_D3D12_SAMPLER_DESC_LIST, QD3D12Descriptor> gpuArrayMap;
585enum QD3D12Stage { VS = 0, HS, DS, GS, PS, CS };
587static inline QD3D12Stage qd3d12_stage(QRhiShaderStage::Type type)
590 case QRhiShaderStage::Vertex:
592 case QRhiShaderStage::TessellationControl:
594 case QRhiShaderStage::TessellationEvaluation:
596 case QRhiShaderStage::Geometry:
598 case QRhiShaderStage::Fragment:
600 case QRhiShaderStage::Compute:
603 Q_UNREACHABLE_RETURN(VS);
606static inline D3D12_SHADER_VISIBILITY qd3d12_stageToVisibility(QD3D12Stage s)
610 return D3D12_SHADER_VISIBILITY_VERTEX;
612 return D3D12_SHADER_VISIBILITY_HULL;
614 return D3D12_SHADER_VISIBILITY_DOMAIN;
616 return D3D12_SHADER_VISIBILITY_GEOMETRY;
618 return D3D12_SHADER_VISIBILITY_PIXEL;
620 return D3D12_SHADER_VISIBILITY_ALL;
622 Q_UNREACHABLE_RETURN(D3D12_SHADER_VISIBILITY_ALL);
625static inline QRhiShaderResourceBinding::StageFlag qd3d12_stageToSrb(QD3D12Stage s)
629 return QRhiShaderResourceBinding::VertexStage;
631 return QRhiShaderResourceBinding::TessellationControlStage;
633 return QRhiShaderResourceBinding::TessellationEvaluationStage;
635 return QRhiShaderResourceBinding::GeometryStage;
637 return QRhiShaderResourceBinding::FragmentStage;
639 return QRhiShaderResourceBinding::ComputeStage;
641 Q_UNREACHABLE_RETURN(QRhiShaderResourceBinding::VertexStage);
644struct QD3D12ShaderStageData
647 QD3D12Stage stage = VS;
648 QShader::NativeResourceBindingMap nativeResourceBindingMap;
651struct QD3D12ShaderResourceBindings;
653struct QD3D12ShaderResourceVisitor
655 enum StorageOp { Load = 0, Store, LoadStore };
657 QD3D12ShaderResourceVisitor(
const QD3D12ShaderResourceBindings *srb,
658 const QD3D12ShaderStageData *stageData,
661 stageData(stageData),
662 stageCount(stageCount)
666 std::function<
void(QD3D12Stage,
const QRhiShaderResourceBinding::Data::UniformBufferData &,
int,
int)> uniformBuffer =
nullptr;
673 std::function<
void(QD3D12Stage,
const QRhiShaderResourceBinding::TextureAndSampler *,
int,
int)> textures =
nullptr;
674 std::function<
void(QD3D12Stage,
const QRhiShaderResourceBinding::TextureAndSampler *,
int,
int)> samplers =
nullptr;
675 std::function<
void(QD3D12Stage,
const QRhiShaderResourceBinding::Data::StorageImageData &, StorageOp,
int)> storageImage =
nullptr;
676 std::function<
void(QD3D12Stage,
const QRhiShaderResourceBinding::Data::StorageBufferData &, StorageOp,
int)> storageBuffer =
nullptr;
680 const QD3D12ShaderResourceBindings *srb;
681 const QD3D12ShaderStageData *stageData;
689 QRhiReadbackResult *result =
nullptr;
690 QD3D12StagingArea staging;
691 quint32 byteSize = 0;
693 quint32 bytesPerLine = 0;
695 QRhiTexture::Format format = QRhiTexture::UnknownFormat;
696 quint32 stagingRowPitch = 0;
699struct QD3D12MipmapGenerator
701 void create(QRhiD3D12 *rhiD);
703 void generate(QD3D12CommandBuffer *cbD,
const QD3D12ObjectHandle &textureHandle);
705 bool ensureCreated();
706 bool buildPipeline();
708 QRhiD3D12 *rhiD =
nullptr;
709 QD3D12ObjectHandle rootSigHandle;
710 QD3D12ObjectHandle pipelineHandle;
711 bool createFailed =
false;
714struct QD3D12MipmapGenerator3D
716 void create(QRhiD3D12 *rhiD);
718 void generate(QD3D12CommandBuffer *cbD,
const QD3D12ObjectHandle &textureHandle);
720 bool ensureCreated();
721 bool buildPipeline();
723 QRhiD3D12 *rhiD =
nullptr;
724 QD3D12ObjectHandle rootSigHandle;
725 QD3D12ObjectHandle pipelineHandle;
726 bool createFailed =
false;
729struct QD3D12MemoryAllocator
731 bool create(ID3D12Device *device, IDXGIAdapter1 *adapter);
734 HRESULT createResource(D3D12_HEAP_TYPE heapType,
735 const D3D12_RESOURCE_DESC *resourceDesc,
736 D3D12_RESOURCE_STATES initialState,
737 const D3D12_CLEAR_VALUE *optimizedClearValue,
738 D3D12MA::Allocation **maybeAllocation,
742 void getBudget(D3D12MA::Budget *localBudget, D3D12MA::Budget *nonLocalBudget);
744 bool isUsingD3D12MA()
const {
return allocator !=
nullptr; }
746 ID3D12Device *device =
nullptr;
747 D3D12MA::Allocator *allocator =
nullptr;
750struct QD3D12Buffer :
public QRhiBuffer
752 QD3D12Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
755 void destroy() override;
756 bool create() override;
757 QRhiBuffer::NativeBuffer nativeBuffer() override;
758 char *beginFullDynamicBufferUpdateForCurrentFrame() override;
759 void endFullDynamicBufferUpdateForCurrentFrame() override;
761 void executeHostWritesForFrameSlot(
int frameSlot);
763 QD3D12ObjectHandle handles[QD3D12_FRAMES_IN_FLIGHT] = {};
768 QVarLengthArray<HostWrite, 16> pendingHostWrites[QD3D12_FRAMES_IN_FLIGHT];
770 friend class QRhiD3D12;
771 friend struct QD3D12ShaderResourceBindings;
774struct QD3D12RenderBuffer :
public QRhiRenderBuffer
776 QD3D12RenderBuffer(QRhiImplementation *rhi,
778 const QSize &pixelSize,
781 QRhiTexture::Format backingFormatHint);
782 ~QD3D12RenderBuffer();
783 void destroy() override;
784 bool create() override;
785 QRhiTexture::Format backingFormat()
const override;
787 static const DXGI_FORMAT DS_FORMAT = DXGI_FORMAT_D24_UNORM_S8_UINT;
789 QD3D12ObjectHandle handle;
790 QD3D12Descriptor rtv;
791 QD3D12Descriptor dsv;
792 DXGI_FORMAT dxgiFormat;
793 DXGI_SAMPLE_DESC sampleDesc;
795 friend class QRhiD3D12;
798struct QD3D12Texture :
public QRhiTexture
800 QD3D12Texture(QRhiImplementation *rhi, Format format,
const QSize &pixelSize,
int depth,
801 int arraySize,
int sampleCount, Flags flags);
803 void destroy() override;
804 bool create() override;
805 bool createFrom(NativeTexture src) override;
806 NativeTexture nativeTexture() override;
807 void setNativeLayout(
int layout) override;
809 bool prepareCreate(QSize *adjustedSize =
nullptr);
812 QD3D12ObjectHandle handle;
813 QD3D12Descriptor srv;
814 DXGI_FORMAT dxgiFormat;
815 DXGI_FORMAT srvFormat;
816 DXGI_FORMAT rtFormat;
818 DXGI_SAMPLE_DESC sampleDesc;
819 QBitArray resolveDestInitialized;
821 friend class QRhiD3D12;
822 friend struct QD3D12ShaderResourceBindings;
825struct QD3D12Sampler :
public QRhiSampler
827 QD3D12Sampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
828 AddressMode u, AddressMode v, AddressMode w);
830 void destroy() override;
831 bool create() override;
833 QD3D12Descriptor lookupOrCreateShaderVisibleDescriptor();
835 D3D12_SAMPLER_DESC desc = {};
836 QD3D12Descriptor shaderVisibleDescriptor;
838 friend class QRhiD3D12;
841struct QD3D12ShadingRateMap :
public QRhiShadingRateMap
843 QD3D12ShadingRateMap(QRhiImplementation *rhi);
844 ~QD3D12ShadingRateMap();
845 void destroy() override;
846 bool createFrom(QRhiTexture *src) override;
848 QD3D12ObjectHandle handle;
849 friend class QRhiD3D12;
852struct QD3D12RenderPassDescriptor :
public QRhiRenderPassDescriptor
854 QD3D12RenderPassDescriptor(QRhiImplementation *rhi);
855 ~QD3D12RenderPassDescriptor();
856 void destroy() override;
857 bool isCompatible(
const QRhiRenderPassDescriptor *other)
const override;
858 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const override;
859 QVector<quint32> serializedFormat()
const override;
861 void updateSerializedFormat();
863 static const int MAX_COLOR_ATTACHMENTS = 8;
864 int colorAttachmentCount = 0;
865 bool hasDepthStencil =
false;
866 int colorFormat[MAX_COLOR_ATTACHMENTS];
868 bool hasShadingRateMap =
false;
869 QVector<quint32> serializedFormatData;
872struct QD3D12RenderTargetData
874 QD3D12RenderTargetData(QRhiImplementation *) { }
876 QD3D12RenderPassDescriptor *rp =
nullptr;
880 int colorAttCount = 0;
882 QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList;
883 static const int MAX_COLOR_ATTACHMENTS = QD3D12RenderPassDescriptor::MAX_COLOR_ATTACHMENTS;
884 D3D12_CPU_DESCRIPTOR_HANDLE rtv[MAX_COLOR_ATTACHMENTS];
885 D3D12_CPU_DESCRIPTOR_HANDLE dsv;
888struct QD3D12SwapChainRenderTarget :
public QRhiSwapChainRenderTarget
890 QD3D12SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
891 ~QD3D12SwapChainRenderTarget();
892 void destroy() override;
894 QSize pixelSize()
const override;
895 float devicePixelRatio()
const override;
896 int sampleCount()
const override;
898 QD3D12RenderTargetData d;
901struct QD3D12TextureRenderTarget :
public QRhiTextureRenderTarget
903 QD3D12TextureRenderTarget(QRhiImplementation *rhi,
904 const QRhiTextureRenderTargetDescription &desc,
906 ~QD3D12TextureRenderTarget();
907 void destroy() override;
909 QSize pixelSize()
const override;
910 float devicePixelRatio()
const override;
911 int sampleCount()
const override;
913 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
914 bool create() override;
916 QD3D12RenderTargetData d;
917 bool ownsRtv[QD3D12RenderTargetData::MAX_COLOR_ATTACHMENTS];
918 QD3D12Descriptor rtv[QD3D12RenderTargetData::MAX_COLOR_ATTACHMENTS];
919 bool ownsDsv =
false;
920 QD3D12Descriptor dsv;
921 friend class QRhiD3D12;
924struct QD3D12GraphicsPipeline;
925struct QD3D12ComputePipeline;
927struct QD3D12ShaderResourceBindings :
public QRhiShaderResourceBindings
929 QD3D12ShaderResourceBindings(QRhiImplementation *rhi);
930 ~QD3D12ShaderResourceBindings();
931 void destroy() override;
932 bool create() override;
933 void updateResources(UpdateFlags flags) override;
935 QD3D12ObjectHandle createRootSignature(
const QD3D12ShaderStageData *stageData,
int stageCount);
938 QVarLengthArray<D3D12_ROOT_PARAMETER1, 2> cbParams[6];
940 D3D12_ROOT_PARAMETER1 srvTables[6] = {};
941 QVarLengthArray<D3D12_DESCRIPTOR_RANGE1, 4> srvRanges[6];
942 quint32 currentSrvRangeOffset[6] = {};
944 QVarLengthArray<D3D12_ROOT_PARAMETER1, 4> samplerTables[6];
945 std::array<D3D12_DESCRIPTOR_RANGE1, 16> samplerRanges[6] = {};
946 int samplerRangeHeads[6] = {};
948 D3D12_ROOT_PARAMETER1 uavTables[6] = {};
949 QVarLengthArray<D3D12_DESCRIPTOR_RANGE1, 4> uavRanges[6];
950 quint32 currentUavRangeOffset[6] = {};
954 void visitUniformBuffer(QD3D12Stage s,
955 const QRhiShaderResourceBinding::Data::UniformBufferData &d,
958 void visitTextures(QD3D12Stage s,
959 const QRhiShaderResourceBinding::TextureAndSampler *d,
961 int baseShaderRegister);
962 void visitSamplers(QD3D12Stage s,
963 const QRhiShaderResourceBinding::TextureAndSampler *d,
965 int baseShaderRegister);
966 void visitStorageBuffer(QD3D12Stage s,
967 const QRhiShaderResourceBinding::Data::StorageBufferData &d,
968 QD3D12ShaderResourceVisitor::StorageOp op,
970 void visitStorageImage(QD3D12Stage s,
971 const QRhiShaderResourceBinding::Data::StorageImageData &d,
972 QD3D12ShaderResourceVisitor::StorageOp op,
979 struct BindingCache {
987 QVarLengthArray<CBuf, 2> cbufs[6];
988 QVarLengthArray<D3D12_CPU_DESCRIPTOR_HANDLE, 8> srvs[6];
989 QVarLengthArray<D3D12_GPU_DESCRIPTOR_HANDLE, 8> samplers[6];
991 QD3D12ObjectHandle handle;
992 D3D12_UNORDERED_ACCESS_VIEW_DESC desc;
994 QVarLengthArray<Uav, 4> uavs[6];
995 quint32 srvUavCount = 0;
998 for (
int s = 0; s < 6; ++s) {
1001 samplers[s].clear();
1008 bool bindingCacheValid =
false;
1009 uint bindingCacheGeneration = 0;
1011 void rebuildBindingCache(
const QD3D12ShaderStageData *stageData,
int stageCount);
1015 void cacheUniformBuffer(QD3D12Stage s,
1016 const QRhiShaderResourceBinding::Data::UniformBufferData &d,
1019 void cacheTextures(QD3D12Stage s,
1020 const QRhiShaderResourceBinding::TextureAndSampler *d,
1022 int baseShaderRegister);
1023 void cacheSamplers(QD3D12Stage s,
1024 const QRhiShaderResourceBinding::TextureAndSampler *d,
1026 int baseShaderRegister);
1027 void cacheStorageBuffer(QD3D12Stage s,
1028 const QRhiShaderResourceBinding::Data::StorageBufferData &d,
1029 QD3D12ShaderResourceVisitor::StorageOp op,
1030 int shaderRegister);
1031 void cacheStorageImage(QD3D12Stage s,
1032 const QRhiShaderResourceBinding::Data::StorageImageData &d,
1033 QD3D12ShaderResourceVisitor::StorageOp op,
1034 int shaderRegister);
1036 struct BoundUniformBufferData {
1040 struct BoundSampledTextureData {
1046 uint samplerGeneration;
1047 } d[QRhiShaderResourceBinding::Data::MAX_TEX_SAMPLER_ARRAY_SIZE];
1049 struct BoundStorageImageData {
1053 struct BoundStorageBufferData {
1057 struct BoundResourceData {
1059 BoundUniformBufferData ubuf;
1060 BoundSampledTextureData stex;
1061 BoundStorageImageData simage;
1062 BoundStorageBufferData sbuf;
1065 QVarLengthArray<BoundResourceData, 8> boundResourceData;
1067 bool hasDynamicOffset =
false;
1068 uint generation = 0;
1069 QD3D12GraphicsPipeline *lastUsedGraphicsPipeline =
nullptr;
1070 QD3D12ComputePipeline *lastUsedComputePipeline =
nullptr;
1071 uint lastUsedPipelineGeneration = 0;
1073 friend class QRhiD3D12;
1074 friend struct QD3D12ShaderResourceVisitor;
1077struct QD3D12GraphicsPipeline :
public QRhiGraphicsPipeline
1079 QD3D12GraphicsPipeline(QRhiImplementation *rhi);
1080 ~QD3D12GraphicsPipeline();
1081 void destroy() override;
1082 bool create() override;
1084 QD3D12ObjectHandle handle;
1085 QD3D12ObjectHandle rootSigHandle;
1086 std::array<QD3D12ShaderStageData, 5> stageData;
1087 D3D12_PRIMITIVE_TOPOLOGY topology;
1088 UINT viewInstanceMask = 0;
1089 uint generation = 0;
1090 friend class QRhiD3D12;
1093struct QD3D12ComputePipeline :
public QRhiComputePipeline
1095 QD3D12ComputePipeline(QRhiImplementation *rhi);
1096 ~QD3D12ComputePipeline();
1097 void destroy() override;
1098 bool create() override;
1100 QD3D12ObjectHandle handle;
1101 QD3D12ObjectHandle rootSigHandle;
1102 QD3D12ShaderStageData stageData;
1103 uint generation = 0;
1104 friend class QRhiD3D12;
1107struct QD3D12CommandBuffer :
public QRhiCommandBuffer
1109 QD3D12CommandBuffer(QRhiImplementation *rhi);
1110 ~QD3D12CommandBuffer();
1111 void destroy() override;
1113 const QRhiNativeHandles *nativeHandles();
1115 D3D12GraphicsCommandList *cmdList =
nullptr;
1116 QRhiD3D12CommandBufferNativeHandles nativeHandlesStruct;
1126 recordingPass = NoPass;
1127 currentTarget =
nullptr;
1129 resetPerPassState();
1132 void resetPerPassState()
1134 currentGraphicsPipeline =
nullptr;
1135 currentComputePipeline =
nullptr;
1136 currentPipelineGeneration = 0;
1137 currentGraphicsSrb =
nullptr;
1138 currentComputeSrb =
nullptr;
1139 currentSrbGeneration = 0;
1140 currentIndexBuffer = {};
1141 currentIndexOffset = 0;
1142 currentIndexFormat = DXGI_FORMAT_R16_UINT;
1143 currentVertexBuffers = {};
1144 currentVertexOffsets = {};
1145 hasShadingRateSet =
false;
1146 hasShadingRateMapSet =
false;
1147 hasCustomScissorSet =
false;
1148 currentViewport = {};
1152 PassType recordingPass;
1153 QRhiRenderTarget *currentTarget;
1156 QD3D12GraphicsPipeline *currentGraphicsPipeline;
1157 QD3D12ComputePipeline *currentComputePipeline;
1158 uint currentPipelineGeneration;
1159 QRhiShaderResourceBindings *currentGraphicsSrb;
1160 QRhiShaderResourceBindings *currentComputeSrb;
1161 uint currentSrbGeneration;
1162 QD3D12ObjectHandle currentIndexBuffer;
1163 quint32 currentIndexOffset;
1164 DXGI_FORMAT currentIndexFormat;
1165 std::array<QD3D12ObjectHandle, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> currentVertexBuffers;
1166 std::array<quint32, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> currentVertexOffsets;
1167 bool hasShadingRateSet;
1168 bool hasShadingRateMapSet;
1169 bool hasCustomScissorSet;
1170 QRhiViewport currentViewport;
1173 double lastGpuTime = 0;
1176struct QD3D12SwapChain :
public QRhiSwapChain
1178 QD3D12SwapChain(QRhiImplementation *rhi);
1180 void destroy() override;
1182 QRhiCommandBuffer *currentFrameCommandBuffer() override;
1183 QRhiRenderTarget *currentFrameRenderTarget() override;
1184 QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer) override;
1186 QSize surfacePixelSize() override;
1187 bool isFormatSupported(Format f) override;
1188 QRhiSwapChainHdrInfo hdrInfo() override;
1190 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
1191 bool createOrResize() override;
1193 void releaseBuffers();
1194 void waitCommandCompletionForFrameSlot(
int frameSlot);
1195 void addCommandCompletionSignalForCurrentFrameSlot();
1196 void chooseFormats();
1198 QWindow *window =
nullptr;
1199 IDXGISwapChain1 *sourceSwapChain1 =
nullptr;
1200 IDXGISwapChain3 *swapChain =
nullptr;
1202 UINT swapInterval = 1;
1203 UINT swapChainFlags = 0;
1204 BOOL stereo =
false;
1205 DXGI_FORMAT colorFormat;
1206 DXGI_FORMAT srgbAdjustedColorFormat;
1207 DXGI_COLOR_SPACE_TYPE hdrColorSpace;
1208 IDCompositionTarget *dcompTarget =
nullptr;
1209 IDCompositionVisual *dcompVisual =
nullptr;
1210 static const UINT BUFFER_COUNT = 3;
1211 QD3D12ObjectHandle colorBuffers[BUFFER_COUNT];
1212 QD3D12Descriptor rtvs[BUFFER_COUNT];
1213 QD3D12Descriptor rtvsRight[BUFFER_COUNT];
1214 DXGI_SAMPLE_DESC sampleDesc;
1215 QD3D12ObjectHandle msaaBuffers[QD3D12_FRAMES_IN_FLIGHT];
1216 QD3D12Descriptor msaaRtvs[QD3D12_FRAMES_IN_FLIGHT];
1217 QD3D12RenderBuffer *ds =
nullptr;
1218 UINT currentBackBufferIndex = 0;
1219 QD3D12SwapChainRenderTarget rtWrapper;
1220 QD3D12SwapChainRenderTarget rtWrapperRight;
1221 QD3D12CommandBuffer cbWrapper;
1222 HANDLE frameLatencyWaitableObject =
nullptr;
1224 struct FrameResources {
1225 ID3D12Fence *fence =
nullptr;
1226 HANDLE fenceEvent =
nullptr;
1227 UINT64 fenceCounter = 0;
1228 D3D12GraphicsCommandList *cmdList =
nullptr;
1229 } frameRes[QD3D12_FRAMES_IN_FLIGHT];
1231 int currentFrameSlot = 0;
1232 int lastFrameLatencyWaitSlot = -1;
1235template<
typename T, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type>
1236struct alignas(
void*) QD3D12PipelineStateSubObject
1238 D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = Type;
1242class QD3D12Adapter :
public QRhiAdapter
1245 QRhiDriverInfo info()
const override;
1248 QRhiDriverInfo adapterInfo;
1251class QRhiD3D12 :
public QRhiImplementation
1255 static constexpr quint32 SMALL_STAGING_AREA_BYTES_PER_FRAME_START = 512 * 1024;
1256 static constexpr quint32 SMALL_STAGING_AREA_BYTES_PER_FRAME_MAX = 16 * 1024 * 1024;
1259 static constexpr int SMALL_STAGING_AREA_LOW_DEMAND_FRAMES = 60;
1261 static constexpr quint32 SHADER_VISIBLE_CBV_SRV_UAV_HEAP_PER_FRAME_START_SIZE = 16384;
1263 QRhiD3D12(QRhiD3D12InitParams *params, QRhiD3D12NativeHandles *importDevice =
nullptr);
1265 bool create(QRhi::Flags flags) override;
1266 void destroy() override;
1267 QRhi::AdapterList enumerateAdaptersBeforeCreate(QRhiNativeHandles *nativeHandles)
const override;
1269 QRhiGraphicsPipeline *createGraphicsPipeline() override;
1270 QRhiComputePipeline *createComputePipeline() override;
1271 QRhiShaderResourceBindings *createShaderResourceBindings() override;
1272 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
1273 QRhiBuffer::UsageFlags usage,
1274 quint32 size) override;
1275 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
1276 const QSize &pixelSize,
1278 QRhiRenderBuffer::Flags flags,
1279 QRhiTexture::Format backingFormatHint) override;
1280 QRhiTexture *createTexture(QRhiTexture::Format format,
1281 const QSize &pixelSize,
1285 QRhiTexture::Flags flags) override;
1286 QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
1287 QRhiSampler::Filter minFilter,
1288 QRhiSampler::Filter mipmapMode,
1289 QRhiSampler:: AddressMode u,
1290 QRhiSampler::AddressMode v,
1291 QRhiSampler::AddressMode w) override;
1293 QRhiTextureRenderTarget *createTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
1294 QRhiTextureRenderTarget::Flags flags) override;
1296 QRhiShadingRateMap *createShadingRateMap() override;
1298 QRhiSwapChain *createSwapChain() override;
1299 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
1300 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
1301 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override;
1302 QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override;
1303 QRhi::FrameOpResult finish() override;
1305 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
1307 void beginPass(QRhiCommandBuffer *cb,
1308 QRhiRenderTarget *rt,
1309 const QColor &colorClearValue,
1310 const QRhiDepthStencilClearValue &depthStencilClearValue,
1311 QRhiResourceUpdateBatch *resourceUpdates,
1312 QRhiCommandBuffer::BeginPassFlags flags) override;
1313 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
1315 void setGraphicsPipeline(QRhiCommandBuffer *cb,
1316 QRhiGraphicsPipeline *ps) override;
1318 void setShaderResources(QRhiCommandBuffer *cb,
1319 QRhiShaderResourceBindings *srb,
1320 int dynamicOffsetCount,
1321 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
1323 void setVertexInput(QRhiCommandBuffer *cb,
1324 int startBinding,
int bindingCount,
const QRhiCommandBuffer::VertexInput *bindings,
1325 QRhiBuffer *indexBuf, quint32 indexOffset,
1326 QRhiCommandBuffer::IndexFormat indexFormat) override;
1328 void setViewport(QRhiCommandBuffer *cb,
const QRhiViewport &viewport) override;
1329 void setScissor(QRhiCommandBuffer *cb,
const QRhiScissor &scissor) override;
1330 void setBlendConstants(QRhiCommandBuffer *cb,
const QColor &c) override;
1331 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
1332 void setShadingRate(QRhiCommandBuffer *cb,
const QSize &coarsePixelSize) override;
1334 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
1335 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
1337 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
1338 quint32 instanceCount, quint32 firstIndex,
1339 qint32 vertexOffset, quint32 firstInstance) override;
1341 void drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
1342 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override;
1344 void drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
1345 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override;
1347 void debugMarkBegin(QRhiCommandBuffer *cb,
const QByteArray &name) override;
1348 void debugMarkEnd(QRhiCommandBuffer *cb) override;
1349 void debugMarkMsg(QRhiCommandBuffer *cb,
const QByteArray &msg) override;
1351 void beginComputePass(QRhiCommandBuffer *cb,
1352 QRhiResourceUpdateBatch *resourceUpdates,
1353 QRhiCommandBuffer::BeginPassFlags flags) override;
1354 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
1355 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
1356 void dispatch(QRhiCommandBuffer *cb,
int x,
int y,
int z) override;
1358 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
1359 void beginExternal(QRhiCommandBuffer *cb) override;
1360 void endExternal(QRhiCommandBuffer *cb) override;
1361 double lastCompletedGpuTime(QRhiCommandBuffer *cb) override;
1363 QList<
int> supportedSampleCounts()
const override;
1364 QList<QSize> supportedShadingRates(
int sampleCount)
const override;
1365 int ubufAlignment()
const override;
1366 bool isYUpInFramebuffer()
const override;
1367 bool isYUpInNDC()
const override;
1368 bool isClipDepthZeroToOne()
const override;
1369 QMatrix4x4 clipSpaceCorrMatrix()
const override;
1370 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags)
const override;
1371 bool isFeatureSupported(QRhi::Feature feature)
const override;
1372 int resourceLimit(QRhi::ResourceLimit limit)
const override;
1373 const QRhiNativeHandles *nativeHandles() override;
1374 QRhiDriverInfo driverInfo()
const override;
1375 QRhiStats statistics() override;
1376 bool makeThreadLocalNativeContextCurrent() override;
1377 void setQueueSubmitParams(QRhiNativeHandles *params) override;
1378 void releaseCachedResources() override;
1379 bool isDeviceLost()
const override;
1381 QByteArray pipelineCacheData() override;
1382 void setPipelineCacheData(
const QByteArray &data) override;
1390 void recordSmallStagingAreaDemand(quint32 byteSize)
1392 smallStagingAreaBytesNeeded[currentFrameSlot] += byteSize;
1394 void resetAndResizeSmallStagingArea(
int frameSlot);
1396 ID3D12PipelineState *loadOrCreatePipelineState(
const D3D12_PIPELINE_STATE_STREAM_DESC *streamDesc,
1397 const QByteArray &cacheKey,
1399 bool ensurePipelineLibrary();
1400 bool createPipelineLibrary(
const QByteArray &blob);
1401 void destroyPipelineLibrary();
1404 DXGI_SAMPLE_DESC effectiveSampleDesc(
int sampleCount, DXGI_FORMAT format)
const;
1405 bool ensureDirectCompositionDevice();
1406 bool startCommandListForCurrentFrameSlot(D3D12GraphicsCommandList **cmdList);
1407 void enqueueResourceUpdates(QD3D12CommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates);
1408 void finishActiveReadbacks(
bool forced =
false);
1409 bool ensureShaderVisibleDescriptorHeapCapacity(QD3D12ShaderVisibleDescriptorHeap *h,
1410 D3D12_DESCRIPTOR_HEAP_TYPE type,
1412 quint32 neededDescriptorCount,
1414 void bindShaderVisibleHeaps(QD3D12CommandBuffer *cbD);
1415 void setDefaultScissor(QD3D12CommandBuffer *cbD);
1417 bool debugLayer =
false;
1418#ifdef QRHI_D3D12_INFOQUEUE1_AVAILABLE
1419 ID3D12InfoQueue1 *infoQueue1 =
nullptr;
1420 DWORD infoQueueCallbackCookie = 0;
1422 UINT maxFrameLatency = 2;
1423 ID3D12Device2 *dev =
nullptr;
1424 D3D_FEATURE_LEVEL minimumFeatureLevel = D3D_FEATURE_LEVEL(0);
1425 LUID adapterLuid = {};
1426 bool importedDevice =
false;
1427 bool importedCommandQueue =
false;
1428 QRhi::Flags rhiFlags;
1429 IDXGIFactory2 *dxgiFactory =
nullptr;
1430 bool supportsAllowTearing =
false;
1431 IDXGIAdapter1 *activeAdapter =
nullptr;
1432 QRhiDriverInfo driverInfoStruct;
1433 QRhiD3D12NativeHandles nativeHandlesStruct;
1434 bool deviceLost =
false;
1435 ID3D12CommandQueue *cmdQueue =
nullptr;
1436 ID3D12Fence *fullFence =
nullptr;
1437 HANDLE fullFenceEvent =
nullptr;
1438 UINT64 fullFenceCounter = 0;
1439 ID3D12CommandAllocator *cmdAllocators[QD3D12_FRAMES_IN_FLIGHT] = {};
1440 QD3D12MemoryAllocator vma;
1441 QD3D12CpuDescriptorPool rtvPool;
1442 QD3D12CpuDescriptorPool dsvPool;
1443 QD3D12CpuDescriptorPool cbvSrvUavPool;
1444 QD3D12ObjectPool<QD3D12Resource> resourcePool;
1445 QD3D12ObjectPool<QD3D12Pipeline> pipelinePool;
1446 QD3D12ObjectPool<QD3D12RootSignature> rootSignaturePool;
1447 QD3D12ReleaseQueue releaseQueue;
1448 QD3D12ResourceBarrierGenerator barrierGen;
1449 QD3D12SamplerManager samplerMgr;
1450 QD3D12MipmapGenerator mipmapGen;
1451 QD3D12MipmapGenerator3D mipmapGen3D;
1452 QD3D12StagingArea smallStagingAreas[QD3D12_FRAMES_IN_FLIGHT];
1453 quint32 smallStagingAreaBytesNeeded[QD3D12_FRAMES_IN_FLIGHT] = {};
1454 int smallStagingAreaLowDemandFrames[QD3D12_FRAMES_IN_FLIGHT] = {};
1455 QD3D12ShaderVisibleDescriptorHeap shaderVisibleCbvSrvUavHeap;
1456 UINT64 timestampTicksPerSecond = 0;
1457 QD3D12QueryHeap timestampQueryHeap;
1458 QD3D12StagingArea timestampReadbackArea;
1459 IDCompositionDevice *dcompDevice =
nullptr;
1460 QD3D12SwapChain *currentSwapChain =
nullptr;
1461 QSet<QD3D12SwapChain *> swapchains;
1462 QD3D12ShaderBytecodeCache shaderBytecodeCache;
1463 QVarLengthArray<QD3D12Readback, 4> activeReadbacks;
1464 bool offscreenActive =
false;
1465 QD3D12CommandBuffer *offscreenCb[QD3D12_FRAMES_IN_FLIGHT] = {};
1466 UINT shadingRateImageTileSize = 0;
1467 ID3D12CommandSignature *drawCommandSignature =
nullptr;
1468 ID3D12CommandSignature *drawIndexedCommandSignature =
nullptr;
1469#ifdef QRHI_D3D12_PIPELINE_LIBRARY_AVAILABLE
1470 ID3D12PipelineLibrary1 *pipelineLibrary =
nullptr;
1473 QByteArray pipelineLibraryBlob;
1475 QSet<QByteArray> pipelineLibraryNames;
1479 bool multiView =
false;
1480 bool textureViewFormat =
false;
1482 bool vrsMap =
false;
1483 bool vrsAdditionalRates =
false;