what is descriptor heap
- User
what is descriptor heap
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
what is descriptor heap
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
A descriptor heap is a fundamental concept in DirectX 12 that serves as a collection of descriptors (resource views). Think of it as an array of "pointers" that describe how the GPU should access your resources (textures, buffers, etc.).
A descriptor is a small data structure that tells the GPU:
Common descriptor types:
Performance Optimization:
Explicit Control:
Hardware Efficiency:
Here's how to create a simple descriptor heap for render targets:
// Describe the descriptor heap
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = 2; // Number of descriptors (e.g., for double buffering)
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; // Type of descriptors
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; // Not shader-visible
ComPtr<ID3D12DescriptorHeap> rtvHeap;
device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&rtvHeap));
// Get the starting CPU handle
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle =
rtvHeap->GetCPUDescriptorHandleForHeapStart();
// Calculate handle increment size
UINT rtvDescriptorSize = device->GetDescriptorHandleIncrementSize(
D3D12_DESCRIPTOR_HEAP_TYPE_RTV
);
// Get handle for second descriptor
rtvHandle.ptr += rtvDescriptorSize;
// Get swap chain buffer
ComPtr<ID3D12Resource> backBuffer;
swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer));
// Create RTV
device->CreateRenderTargetView(
backBuffer.Get(), // Resource
nullptr, // Description (nullptr for default)
rtvHandle // CPU handle to descriptor
);
// For shader-visible heaps (CBV/SRV/UAV/Sampler)
commandList->SetDescriptorHeaps(1, srvHeap.GetAddressOf());
// For RTV/DSV heaps (set during render pass setup)
commandList->OMSetRenderTargets(
1, // Number of RTVs
&rtvHandle, // CPU handle to RTV
FALSE, // No depth stencil
nullptr // No depth stencil descriptor
);
CPU vs GPU Handles:
Shader-Visible vs Non-Shader-Visible:
// Shader-visible heap (for CBV/SRV/UAV/Sampler)
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
// Non-shader-visible heap (for RTV/DSV)
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
Descriptor Tables:
D3D12_GPU_DESCRIPTOR_HANDLE rangesDescriptor Heap (ID3D12DescriptorHeap)
├── Descriptor 0 [CPU Handle: 0x1000]
│ └── Points to: Back Buffer 0
├── Descriptor 1 [CPU Handle: 0x1000 + increment]
│ └── Points to: Back Buffer 1
├── ...
└── Descriptor N
GetDescriptorHandleIncrementSize() for pointer mathWould you like me to explain how descriptor tables work or show an example of a shader-visible heap?