26#include <d3d12sdklayers.h>
30#include "D3D12MemAlloc.h"
38#ifdef __ID3D12Device2_INTERFACE_DEFINED__
39#define QRHI_D3D12_AVAILABLE
43static const int QD3D12_FRAMES_IN_FLIGHT = 2;
47struct QD3D12Descriptor
49 D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = {};
50 D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {};
52 bool isValid()
const {
return cpuHandle.ptr != 0; }
55struct QD3D12ReleaseQueue;
57struct QD3D12DescriptorHeap
59 bool isValid()
const {
return heap &&
capacity; }
62 D3D12_DESCRIPTOR_HEAP_TYPE heapType,
63 D3D12_DESCRIPTOR_HEAP_FLAGS heapFlags);
64 void createWithExisting(
const QD3D12DescriptorHeap &
other,
68 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
74 QD3D12Descriptor incremented(
const QD3D12Descriptor &descriptor,
quint32 offsetInDescriptors)
const
76 D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = descriptor.cpuHandle;
77 cpuHandle.ptr += offsetInDescriptors * descriptorByteSize;
78 D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = descriptor.gpuHandle;
80 gpuHandle.ptr += offsetInDescriptors * descriptorByteSize;
81 return { cpuHandle, gpuHandle };
84 ID3D12DescriptorHeap *heap =
nullptr;
86 QD3D12Descriptor heapStart;
89 D3D12_DESCRIPTOR_HEAP_TYPE heapType;
90 D3D12_DESCRIPTOR_HEAP_FLAGS heapFlags;
93struct QD3D12CpuDescriptorPool
95 bool isValid()
const {
return !heaps.isEmpty(); }
96 bool create(ID3D12Device *
device, D3D12_DESCRIPTOR_HEAP_TYPE heapType,
const char *debugName =
"");
102 static const int DESCRIPTORS_PER_HEAP = 256;
105 QD3D12DescriptorHeap heap;
107 static HeapWithMap
init(
const QD3D12DescriptorHeap &heap,
quint32 descriptorCount) {
110 result.map.resize(descriptorCount);
117 QVector<HeapWithMap> heaps;
118 const char *debugName;
121struct QD3D12QueryHeap
123 bool isValid()
const {
return heap &&
capacity; }
126 D3D12_QUERY_HEAP_TYPE heapType);
129 ID3D12QueryHeap *heap =
nullptr;
133struct QD3D12StagingArea
135 static const quint32 ALIGNMENT = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
139 D3D12_GPU_VIRTUAL_ADDRESS gpuAddr = 0;
140 ID3D12Resource *
buffer =
nullptr;
142 bool isValid()
const {
return p !=
nullptr; }
145 bool isValid()
const {
return allocation && mem.isValid(); }
148 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
152 quint32 remainingCapacity()
const
159 return count * ((
size + ALIGNMENT - 1) & ~(ALIGNMENT - 1));
163 ID3D12Resource *resource =
nullptr;
169struct QD3D12ObjectHandle
175 bool isNull()
const {
return index == 0 && generation == 0; }
178inline bool operator==(
const QD3D12ObjectHandle &
a,
const QD3D12ObjectHandle &
b)
noexcept
180 return a.index ==
b.index &&
a.generation ==
b.generation;
183inline bool operator!=(
const QD3D12ObjectHandle &
a,
const QD3D12ObjectHandle &
b)
noexcept
189struct QD3D12ObjectPool
191 void create(
const char *debugName =
"")
193 this->debugName = debugName;
201 if (
d.object.has_value()) {
203 d.object->releaseResources();
209 static bool leakCheck =
true;
216 qWarning(
"QD3D12ObjectPool::destroy(): Pool %p '%s' had %d unreleased objects",
217 this, debugName, leakCount);
222 bool isValid(
const QD3D12ObjectHandle &
handle)
const
231 T lookup(
const QD3D12ObjectHandle &
handle)
const
236 const T *lookupRef(
const QD3D12ObjectHandle &
handle)
const
241 T *lookupRef(
const QD3D12ObjectHandle &
handle)
246 QD3D12ObjectHandle
add(
const T &
object)
259 return {
index, generation };
268 if (T *
object = lookupRef(
handle)) {
269 object->releaseResources();
274 const char *debugName;
284 ID3D12Resource *resource;
285 D3D12_RESOURCE_STATES
state;
286 D3D12_RESOURCE_DESC
desc;
289 enum { UavUsageRead = 0x01, UavUsageWrite = 0x02 };
295 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12Resource> *
pool,
296 ID3D12Resource *resource,
297 D3D12_RESOURCE_STATES
state,
299 void *cpuMapPtr =
nullptr)
302 return pool->add({ resource,
state, resource->GetDesc(),
allocation, cpuMapPtr, 0,
true });
306 static QD3D12ObjectHandle addNonOwningToPool(QD3D12ObjectPool<QD3D12Resource> *
pool,
307 ID3D12Resource *resource,
308 D3D12_RESOURCE_STATES
state)
311 return pool->add({ resource,
state, resource->GetDesc(),
nullptr,
nullptr, 0,
false });
314 void releaseResources()
332 ID3D12PipelineState *pso;
334 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12Pipeline> *
pool,
336 ID3D12PipelineState *pso)
341 void releaseResources()
347struct QD3D12RootSignature
349 ID3D12RootSignature *rootSig;
351 static QD3D12ObjectHandle addToPool(QD3D12ObjectPool<QD3D12RootSignature> *
pool,
352 ID3D12RootSignature *rootSig)
354 return pool->add({ rootSig });
357 void releaseResources()
363struct QD3D12ReleaseQueue
365 void create(QD3D12ObjectPool<QD3D12Resource> *resourcePool,
366 QD3D12ObjectPool<QD3D12Pipeline> *pipelinePool,
367 QD3D12ObjectPool<QD3D12RootSignature> *rootSignaturePool)
369 this->resourcePool = resourcePool;
370 this->pipelinePool = pipelinePool;
371 this->rootSignaturePool = rootSignaturePool;
374 void deferredReleaseResource(
const QD3D12ObjectHandle &
handle);
375 void deferredReleaseResourceWithViews(
const QD3D12ObjectHandle &
handle,
376 QD3D12CpuDescriptorPool *
pool,
377 const QD3D12Descriptor &viewsStart,
379 void deferredReleasePipeline(
const QD3D12ObjectHandle &
handle);
380 void deferredReleaseRootSignature(
const QD3D12ObjectHandle &
handle);
381 void deferredReleaseCallback(std::function<
void(
void*)> callback,
void *userData);
382 void deferredReleaseResourceAndAllocation(ID3D12Resource *resource,
384 void deferredReleaseDescriptorHeap(ID3D12DescriptorHeap *heap);
385 void deferredReleaseViews(QD3D12CpuDescriptorPool *
pool,
386 const QD3D12Descriptor &viewsStart,
389 void activatePendingDeferredReleaseRequests(
int frameSlot);
390 void executeDeferredReleases(
int frameSlot,
bool forced =
false);
393 struct DeferredReleaseEntry {
399 ResourceAndAllocation,
404 std::optional<int> frameSlotToBeReleasedIn;
405 QD3D12ObjectHandle
handle;
406 QD3D12CpuDescriptorPool *poolForViews =
nullptr;
407 QD3D12Descriptor viewsStart;
409 std::function<
void(
void*)> callback =
nullptr;
410 void *callbackUserData =
nullptr;
411 QPair<ID3D12Resource *, D3D12MA::Allocation *> resourceAndAllocation = {};
412 ID3D12DescriptorHeap *descriptorHeap =
nullptr;
414 QVector<DeferredReleaseEntry>
queue;
415 QD3D12ObjectPool<QD3D12Resource> *resourcePool =
nullptr;
416 QD3D12ObjectPool<QD3D12Pipeline> *pipelinePool =
nullptr;
417 QD3D12ObjectPool<QD3D12RootSignature> *rootSignaturePool =
nullptr;
420struct QD3D12CommandBuffer;
422struct QD3D12ResourceBarrierGenerator
424 static const int PREALLOC = 16;
426 void create(QD3D12ObjectPool<QD3D12Resource> *resourcePool)
428 this->resourcePool = resourcePool;
431 void addTransitionBarrier(
const QD3D12ObjectHandle &resourceHandle, D3D12_RESOURCE_STATES stateAfter);
432 void enqueueBufferedTransitionBarriers(QD3D12CommandBuffer *cbD);
433 void enqueueSubresourceTransitionBarrier(QD3D12CommandBuffer *cbD,
434 const QD3D12ObjectHandle &resourceHandle,
436 D3D12_RESOURCE_STATES stateBefore,
437 D3D12_RESOURCE_STATES stateAfter);
438 void enqueueUavBarrier(QD3D12CommandBuffer *cbD,
const QD3D12ObjectHandle &resourceHandle);
440 struct TransitionResourceBarrier {
441 QD3D12ObjectHandle resourceHandle;
442 D3D12_RESOURCE_STATES stateBefore;
443 D3D12_RESOURCE_STATES stateAfter;
445 QVarLengthArray<TransitionResourceBarrier, PREALLOC> transitionResourceBarriers;
446 QD3D12ObjectPool<QD3D12Resource> *resourcePool =
nullptr;
449struct QD3D12ShaderBytecodeCache
454 : bytecode(bytecode), nativeResourceBindingMap(rbm)
460 QHash<QRhiShaderStage, Shader>
data;
465struct QD3D12ShaderVisibleDescriptorHeap
469 void destroyWithDeferredRelease(QD3D12ReleaseQueue *releaseQueue);
471 QD3D12DescriptorHeap heap;
472 QD3D12DescriptorHeap perFrameHeapSlice[QD3D12_FRAMES_IN_FLIGHT];
476struct Q_D3D12_SAMPLER_DESC
478 D3D12_SAMPLER_DESC
desc;
480 friend bool operator==(
const Q_D3D12_SAMPLER_DESC &lhs,
const Q_D3D12_SAMPLER_DESC &rhs)
noexcept
482 return lhs.desc.Filter == rhs.desc.Filter
483 && lhs.desc.AddressU == rhs.desc.AddressU
484 && lhs.desc.AddressV == rhs.desc.AddressV
485 && lhs.desc.AddressW == rhs.desc.AddressW
486 && lhs.desc.MipLODBias == rhs.desc.MipLODBias
487 && lhs.desc.MaxAnisotropy == rhs.desc.MaxAnisotropy
488 && lhs.desc.ComparisonFunc == rhs.desc.ComparisonFunc
490 && lhs.desc.MinLOD == rhs.desc.MinLOD
491 && lhs.desc.MaxLOD == rhs.desc.MaxLOD;
494 friend bool operator!=(
const Q_D3D12_SAMPLER_DESC &lhs,
const Q_D3D12_SAMPLER_DESC &rhs)
noexcept
496 return !(lhs == rhs);
499 friend size_t qHash(
const Q_D3D12_SAMPLER_DESC &
key,
size_t seed = 0) noexcept
516struct QD3D12SamplerManager
518 const quint32 MAX_SAMPLERS = 512;
523 QD3D12Descriptor getShaderVisibleDescriptor(
const D3D12_SAMPLER_DESC &desc);
525 ID3D12Device *
device =
nullptr;
526 QD3D12ShaderVisibleDescriptorHeap shaderVisibleSamplerHeap;
527 QHash<Q_D3D12_SAMPLER_DESC, QD3D12Descriptor> gpuMap;
530enum QD3D12Stage { VS = 0, HS, DS, GS, PS, CS };
548 Q_UNREACHABLE_RETURN(VS);
551static inline D3D12_SHADER_VISIBILITY qd3d12_stageToVisibility(QD3D12Stage
s)
555 return D3D12_SHADER_VISIBILITY_VERTEX;
557 return D3D12_SHADER_VISIBILITY_HULL;
559 return D3D12_SHADER_VISIBILITY_DOMAIN;
561 return D3D12_SHADER_VISIBILITY_GEOMETRY;
563 return D3D12_SHADER_VISIBILITY_PIXEL;
565 return D3D12_SHADER_VISIBILITY_ALL;
567 Q_UNREACHABLE_RETURN(D3D12_SHADER_VISIBILITY_ALL);
589struct QD3D12ShaderStageData
592 QD3D12Stage stage = VS;
596struct QD3D12ShaderResourceBindings;
598struct QD3D12ShaderResourceVisitor
600 enum StorageOp { Load = 0, Store, LoadStore };
602 QD3D12ShaderResourceVisitor(
const QD3D12ShaderResourceBindings *srb,
603 const QD3D12ShaderStageData *stageData,
606 stageData(stageData),
607 stageCount(stageCount)
619 const QD3D12ShaderResourceBindings *srb;
620 const QD3D12ShaderStageData *stageData;
629 QD3D12StagingArea staging;
638struct QD3D12MipmapGenerator
640 bool create(QRhiD3D12 *rhiD);
642 void generate(QD3D12CommandBuffer *cbD,
const QD3D12ObjectHandle &textureHandle);
645 QD3D12ObjectHandle rootSigHandle;
646 QD3D12ObjectHandle pipelineHandle;
649struct QD3D12MemoryAllocator
651 bool create(ID3D12Device *
device, IDXGIAdapter1 *adapter);
654 HRESULT createResource(D3D12_HEAP_TYPE heapType,
655 const D3D12_RESOURCE_DESC *resourceDesc,
656 D3D12_RESOURCE_STATES initialState,
657 const D3D12_CLEAR_VALUE *optimizedClearValue,
658 D3D12MA::Allocation **maybeAllocation,
662 void getBudget(D3D12MA::Budget *localBudget, D3D12MA::Budget *nonLocalBudget);
664 bool isUsingD3D12MA()
const {
return allocator !=
nullptr; }
666 ID3D12Device *
device =
nullptr;
667 D3D12MA::Allocator *allocator =
nullptr;
675 void destroy()
override;
678 char *beginFullDynamicBufferUpdateForCurrentFrame()
override;
679 void endFullDynamicBufferUpdateForCurrentFrame()
override;
681 void executeHostWritesForFrameSlot(
int frameSlot);
683 QD3D12ObjectHandle handles[QD3D12_FRAMES_IN_FLIGHT] = {};
688 QVarLengthArray<HostWrite, 16> pendingHostWrites[QD3D12_FRAMES_IN_FLIGHT];
689 friend class QRhiD3D12;
690 friend struct QD3D12CommandBuffer;
697 const QSize &pixelSize,
701 ~QD3D12RenderBuffer();
702 void destroy()
override;
706 static const DXGI_FORMAT DS_FORMAT = DXGI_FORMAT_D24_UNORM_S8_UINT;
708 QD3D12ObjectHandle
handle;
709 QD3D12Descriptor rtv;
710 QD3D12Descriptor dsv;
711 DXGI_FORMAT dxgiFormat;
712 DXGI_SAMPLE_DESC sampleDesc;
714 friend class QRhiD3D12;
722 void destroy()
override;
724 bool createFrom(NativeTexture
src)
override;
725 NativeTexture nativeTexture()
override;
726 void setNativeLayout(
int layout)
override;
728 bool prepareCreate(
QSize *adjustedSize =
nullptr);
731 QD3D12ObjectHandle
handle;
732 QD3D12Descriptor srv;
733 DXGI_FORMAT dxgiFormat;
734 DXGI_FORMAT srvFormat;
735 DXGI_FORMAT rtFormat;
737 DXGI_SAMPLE_DESC sampleDesc;
739 friend class QRhiD3D12;
740 friend struct QD3D12CommandBuffer;
745 QD3D12Sampler(
QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
746 AddressMode u, AddressMode
v, AddressMode
w);
748 void destroy()
override;
751 QD3D12Descriptor lookupOrCreateShaderVisibleDescriptor();
753 D3D12_SAMPLER_DESC
desc = {};
754 QD3D12Descriptor shaderVisibleDescriptor;
760 ~QD3D12RenderPassDescriptor();
761 void destroy()
override;
764 QVector<quint32> serializedFormat()
const override;
766 void updateSerializedFormat();
768 static const int MAX_COLOR_ATTACHMENTS = 8;
769 int colorAttachmentCount = 0;
770 bool hasDepthStencil =
false;
773 QVector<quint32> serializedFormatData;
776struct QD3D12RenderTargetData
780 QD3D12RenderPassDescriptor *rp =
nullptr;
784 int colorAttCount = 0;
787 static const int MAX_COLOR_ATTACHMENTS = QD3D12RenderPassDescriptor::MAX_COLOR_ATTACHMENTS;
788 D3D12_CPU_DESCRIPTOR_HANDLE rtv[MAX_COLOR_ATTACHMENTS];
789 D3D12_CPU_DESCRIPTOR_HANDLE dsv;
795 ~QD3D12SwapChainRenderTarget();
796 void destroy()
override;
798 QSize pixelSize()
const override;
799 float devicePixelRatio()
const override;
800 int sampleCount()
const override;
802 QD3D12RenderTargetData
d;
810 ~QD3D12TextureRenderTarget();
811 void destroy()
override;
813 QSize pixelSize()
const override;
814 float devicePixelRatio()
const override;
815 int sampleCount()
const override;
820 QD3D12RenderTargetData
d;
821 bool ownsRtv[QD3D12RenderTargetData::MAX_COLOR_ATTACHMENTS];
822 QD3D12Descriptor rtv[QD3D12RenderTargetData::MAX_COLOR_ATTACHMENTS];
823 bool ownsDsv =
false;
824 QD3D12Descriptor dsv;
825 friend class QRhiD3D12;
831 ~QD3D12ShaderResourceBindings();
832 void destroy()
override;
834 void updateResources(UpdateFlags
flags)
override;
836 QD3D12ObjectHandle createRootSignature(
const QD3D12ShaderStageData *stageData,
int stageCount);
839 QVarLengthArray<D3D12_ROOT_PARAMETER1, 2> cbParams[6];
841 D3D12_ROOT_PARAMETER1 srvTables[6] = {};
842 QVarLengthArray<D3D12_DESCRIPTOR_RANGE1, 4> srvRanges[6];
843 quint32 currentSrvRangeOffset[6] = {};
845 QVarLengthArray<D3D12_ROOT_PARAMETER1, 4> samplerTables[6];
846 std::array<D3D12_DESCRIPTOR_RANGE1, 16> samplerRanges[6] = {};
847 int samplerRangeHeads[6] = {};
849 D3D12_ROOT_PARAMETER1 uavTables[6] = {};
850 QVarLengthArray<D3D12_DESCRIPTOR_RANGE1, 4> uavRanges[6];
851 quint32 currentUavRangeOffset[6] = {};
855 void visitUniformBuffer(QD3D12Stage
s,
859 void visitTexture(QD3D12Stage
s,
862 void visitSampler(QD3D12Stage
s,
865 void visitStorageBuffer(QD3D12Stage
s,
867 QD3D12ShaderResourceVisitor::StorageOp op,
869 void visitStorageImage(QD3D12Stage
s,
871 QD3D12ShaderResourceVisitor::StorageOp op,
874 bool hasDynamicOffset =
false;
877 friend class QRhiD3D12;
878 friend struct QD3D12ShaderResourceVisitor;
884 ~QD3D12GraphicsPipeline();
885 void destroy()
override;
888 QD3D12ObjectHandle
handle;
889 QD3D12ObjectHandle rootSigHandle;
890 std::array<QD3D12ShaderStageData, 5> stageData;
891 D3D12_PRIMITIVE_TOPOLOGY topology;
892 UINT viewInstanceMask = 0;
894 friend class QRhiD3D12;
900 ~QD3D12ComputePipeline();
901 void destroy()
override;
904 QD3D12ObjectHandle
handle;
905 QD3D12ObjectHandle rootSigHandle;
906 QD3D12ShaderStageData stageData;
908 friend class QRhiD3D12;
914 ~QD3D12CommandBuffer();
915 void destroy()
override;
919 ID3D12GraphicsCommandList1 *cmdList =
nullptr;
920 QRhiD3D12CommandBufferNativeHandles nativeHandlesStruct;
930 recordingPass = NoPass;
931 currentTarget =
nullptr;
936 void resetPerPassState()
938 currentGraphicsPipeline =
nullptr;
939 currentComputePipeline =
nullptr;
940 currentPipelineGeneration = 0;
941 currentGraphicsSrb =
nullptr;
942 currentComputeSrb =
nullptr;
943 currentSrbGeneration = 0;
944 currentIndexBuffer = {};
945 currentIndexOffset = 0;
946 currentIndexFormat = DXGI_FORMAT_R16_UINT;
947 currentVertexBuffers = {};
948 currentVertexOffsets = {};
952 PassType recordingPass;
956 QD3D12GraphicsPipeline *currentGraphicsPipeline;
957 QD3D12ComputePipeline *currentComputePipeline;
958 uint currentPipelineGeneration;
961 uint currentSrbGeneration;
962 QD3D12ObjectHandle currentIndexBuffer;
964 DXGI_FORMAT currentIndexFormat;
965 std::array<QD3D12ObjectHandle, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> currentVertexBuffers;
966 std::array<quint32, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> currentVertexOffsets;
969 double lastGpuTime = 0;
973 QVarLengthArray<QPair<QD3D12ObjectHandle, quint32>, 4> cbufs[6];
974 QVarLengthArray<QD3D12Descriptor, 8> srvs[6];
975 QVarLengthArray<QD3D12Descriptor, 8>
samplers[6];
976 QVarLengthArray<QPair<QD3D12ObjectHandle, D3D12_UNORDERED_ACCESS_VIEW_DESC>, 4> uavs[6];
979 void visitUniformBuffer(QD3D12Stage
s,
983 int dynamicOffsetCount,
985 void visitTexture(QD3D12Stage
s,
988 void visitSampler(QD3D12Stage
s,
991 void visitStorageBuffer(QD3D12Stage
s,
993 QD3D12ShaderResourceVisitor::StorageOp op,
995 void visitStorageImage(QD3D12Stage
s,
997 QD3D12ShaderResourceVisitor::StorageOp op,
1005 void destroy()
override;
1009 QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer)
override;
1011 QSize surfacePixelSize()
override;
1012 bool isFormatSupported(
Format f)
override;
1016 bool createOrResize()
override;
1018 void releaseBuffers();
1019 void waitCommandCompletionForFrameSlot(
int frameSlot);
1020 void addCommandCompletionSignalForCurrentFrameSlot();
1021 void chooseFormats();
1024 IDXGISwapChain1 *sourceSwapChain1 =
nullptr;
1025 IDXGISwapChain3 *swapChain =
nullptr;
1027 UINT swapInterval = 1;
1028 UINT swapChainFlags = 0;
1029 BOOL stereo =
false;
1031 DXGI_FORMAT srgbAdjustedColorFormat;
1032 DXGI_COLOR_SPACE_TYPE hdrColorSpace;
1033 IDCompositionTarget *dcompTarget =
nullptr;
1034 IDCompositionVisual *dcompVisual =
nullptr;
1039 DXGI_SAMPLE_DESC sampleDesc;
1042 QD3D12RenderBuffer *ds =
nullptr;
1043 UINT currentBackBufferIndex = 0;
1044 QD3D12SwapChainRenderTarget rtWrapper;
1045 QD3D12SwapChainRenderTarget rtWrapperRight;
1046 QD3D12CommandBuffer cbWrapper;
1048 struct FrameResources {
1049 ID3D12Fence *
fence =
nullptr;
1050 HANDLE fenceEvent =
nullptr;
1051 UINT64 fenceCounter = 0;
1052 ID3D12GraphicsCommandList1 *cmdList =
nullptr;
1053 } frameRes[QD3D12_FRAMES_IN_FLIGHT];
1055 int currentFrameSlot = 0;
1058template<
typename T, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type>
1059struct alignas(void*) QD3D12PipelineStateSubObject
1061 D3D12_PIPELINE_STATE_SUBOBJECT_TYPE
type =
Type;
1070 static const quint32 SMALL_STAGING_AREA_BYTES_PER_FRAME = 16 * 1024 * 1024;
1072 static const quint32 SHADER_VISIBLE_CBV_SRV_UAV_HEAP_PER_FRAME_START_SIZE = 16384;
1074 QRhiD3D12(QRhiD3D12InitParams *
params, QRhiD3D12NativeHandles *importDevice =
nullptr);
1077 void destroy()
override;
1083 QRhiBuffer::UsageFlags
usage,
1086 const QSize &pixelSize,
1088 QRhiRenderBuffer::Flags
flags,
1091 const QSize &pixelSize,
1095 QRhiTexture::Flags
flags)
override;
1104 QRhiTextureRenderTarget::Flags
flags)
override;
1117 const QColor &colorClearValue,
1120 QRhiCommandBuffer::BeginPassFlags
flags)
override;
1128 int dynamicOffsetCount,
1154 QRhiCommandBuffer::BeginPassFlags
flags)
override;
1164 QList<int> supportedSampleCounts()
const override;
1165 int ubufAlignment()
const override;
1166 bool isYUpInFramebuffer()
const override;
1167 bool isYUpInNDC()
const override;
1168 bool isClipDepthZeroToOne()
const override;
1169 QMatrix4x4 clipSpaceCorrMatrix()
const override;
1171 bool isFeatureSupported(
QRhi::Feature feature)
const override;
1176 bool makeThreadLocalNativeContextCurrent()
override;
1177 void releaseCachedResources()
override;
1178 bool isDeviceLost()
const override;
1184 DXGI_SAMPLE_DESC effectiveSampleDesc(
int sampleCount, DXGI_FORMAT
format)
const;
1185 bool ensureDirectCompositionDevice();
1186 bool startCommandListForCurrentFrameSlot(ID3D12GraphicsCommandList1 **cmdList);
1188 void finishActiveReadbacks(
bool forced =
false);
1189 bool ensureShaderVisibleDescriptorHeapCapacity(QD3D12ShaderVisibleDescriptorHeap *
h,
1190 D3D12_DESCRIPTOR_HEAP_TYPE
type,
1192 quint32 neededDescriptorCount,
1194 void bindShaderVisibleHeaps(QD3D12CommandBuffer *cbD);
1196 bool debugLayer =
false;
1197 ID3D12Device2 *dev =
nullptr;
1198 D3D_FEATURE_LEVEL minimumFeatureLevel = D3D_FEATURE_LEVEL(0);
1199 LUID adapterLuid = {};
1200 bool importedDevice =
false;
1201 bool importedCommandQueue =
false;
1202 QRhi::Flags rhiFlags;
1203 IDXGIFactory2 *dxgiFactory =
nullptr;
1204 bool supportsAllowTearing =
false;
1205 IDXGIAdapter1 *activeAdapter =
nullptr;
1207 QRhiD3D12NativeHandles nativeHandlesStruct;
1208 bool deviceLost =
false;
1209 ID3D12CommandQueue *cmdQueue =
nullptr;
1210 ID3D12Fence *fullFence =
nullptr;
1211 HANDLE fullFenceEvent =
nullptr;
1212 UINT64 fullFenceCounter = 0;
1213 ID3D12CommandAllocator *cmdAllocators[QD3D12_FRAMES_IN_FLIGHT] = {};
1214 QD3D12MemoryAllocator vma;
1215 QD3D12CpuDescriptorPool rtvPool;
1216 QD3D12CpuDescriptorPool dsvPool;
1217 QD3D12CpuDescriptorPool cbvSrvUavPool;
1218 QD3D12ObjectPool<QD3D12Resource> resourcePool;
1219 QD3D12ObjectPool<QD3D12Pipeline> pipelinePool;
1220 QD3D12ObjectPool<QD3D12RootSignature> rootSignaturePool;
1221 QD3D12ReleaseQueue releaseQueue;
1222 QD3D12ResourceBarrierGenerator barrierGen;
1223 QD3D12SamplerManager samplerMgr;
1224 QD3D12MipmapGenerator mipmapGen;
1225 QD3D12StagingArea smallStagingAreas[QD3D12_FRAMES_IN_FLIGHT];
1226 QD3D12ShaderVisibleDescriptorHeap shaderVisibleCbvSrvUavHeap;
1227 UINT64 timestampTicksPerSecond = 0;
1228 QD3D12QueryHeap timestampQueryHeap;
1229 QD3D12StagingArea timestampReadbackArea;
1230 IDCompositionDevice *dcompDevice =
nullptr;
1231 QD3D12SwapChain *currentSwapChain =
nullptr;
1232 QSet<QD3D12SwapChain *> swapchains;
1233 QD3D12ShaderBytecodeCache shaderBytecodeCache;
1234 QVarLengthArray<QD3D12Readback, 4> activeReadbacks;
1235 bool offscreenActive =
false;
1236 QD3D12CommandBuffer *offscreenCb[QD3D12_FRAMES_IN_FLIGHT] = {};
1239 bool multiView =
false;
1240 bool textureViewFormat =
false;
IOBluetoothDevice * device
The QColor class provides colors based on RGB, HSV or CMYK values.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Type
Specifies storage type of buffer resource.
QPair< int, quint32 > DynamicOffset
Synonym for QPair<int, quint32>.
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
IndexFormat
Specifies the index data type.
Type
Specifies the type of the renderbuffer.
Filter
Specifies the minification, magnification, or mipmap filtering.
AddressMode
Specifies the addressing mode.
StageFlag
Flag values to indicate which stages the shader resource is visible in.
@ TessellationEvaluationStage
@ TessellationControlStage
Type
Specifies the type of the shader stage.
Format
Specifies the texture format.
ResourceLimit
Describes the resource limit to query.
Feature
Flag values to indicate what features are supported by the backend currently in use.
FrameOpResult
Describes the result of operations that can have a soft failure.
QHash< int, QWidget * > hash
[35multi]
QMap< QString, QString > map
[6]
auto visit(Fn &&fn, QIODevice *socket, Args &&...args)
Combined button and popup list for selecting options.
Q_ALWAYS_INLINE void fence()
static QRhiGraphicsPipeline * createGraphicsPipeline(QRhi *rhi, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc, PipelineBlend blend)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static QDBusError::ErrorType get(const char *name)
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
static QT_BEGIN_NAMESPACE const int BUFFER_COUNT
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum colorFormat
GLsizeiptr const void GLenum usage
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
QT_BEGIN_NAMESPACE typedef void(* Callback)(QQmlNotifierEndpoint *, void **)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
static bool isCompatible(const QImage &img1, const QImage &img2)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
std::unique_ptr< ThunkPool::ThunkAllocation > allocation
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
settings remove("monkey")
view viewport() -> scroll(dx, dy, deviceRect)
myFilter draw(painter, QPoint(0, 0), originalPixmap)
manager head(request, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[6]
\variable QRhiReadbackResult::completed