Детали, собранные из разных мест MSDN
![]() |
| картинка из MSDN |
Code Snippet
- typedef enum D3D12_DESCRIPTOR_HEAP_TYPE
- {
- D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
- D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
- D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
- D3D12_DESCRIPTOR_HEAP_TYPE_DSV,
- D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES
- } D3D12_DESCRIPTOR_HEAP_TYPE;
Constant Buffer View, Shader Resource View и Unordered Access View можно комбинировать в одной куче.
Создается куча методом:
Code Snippet
- HRESULT ID3D12Device::CreateDescriptorHeap(...)
Code Snippet
- HRESULT ID3D12Device::GetDescriptorHandleIncrementSize(...)
Code Snippet
- D3D12_CPU_DESCRIPTOR_HANDLE cpuDescriptorHandle = m_DescriptorHeap->GetCPUDescriptorHandleForHeapStart();
- D3D12_GPU_DESCRIPTOR_HANDLE gpuDescriptorHandle = m_DescriptorHeap->GetGPUDescriptorHandleForHeapStart();
Code Snippet
- descriptorHandle.ptr += idx * descriptorHandleIncrementSize;
Code Snippet
- HRESULT ID3D12Device::CreateConstantBufferView(...)
Code Snippet
- HRESULT ID3D12GraphicsCommandList::ClearRenderTargetView(...)
Code Snippet
- HRESULT ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable(...)
Шейдеры "видят" HEAP_TYPE_CBV_SRV_UAV и HEAP_TYPE_SAMPLER. Одновременно "активными" могут быть только по одной куче каждого из этих двух типов:
Code Snippet
- HRESULT ID3D12GraphicsCommandList::SetDescriptorHeaps(...)
Code Snippet
- const int ranges_num = 2;
- const int parameters_num = 2;
- CD3DX12_DESCRIPTOR_RANGE ranges[ranges_num];
- ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 2, 0);
- ranges[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
- CD3DX12_ROOT_PARAMETER rootParameters[parameters_num];
- rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_PIXEL);
- rootParameters[1].InitAsDescriptorTable(1, &ranges[1], D3D12_SHADER_VISIBILITY_VERTEX);
Code Snippet
- m_commandList->SetGraphicsRootDescriptorTable(0, m_SRV_CBR_DescriptorsHeap.GetGPUDescriptorHandleForHeapStart());
Code Snippet
- D3D12_GPU_DESCRIPTOR_HANDLE gpuCBVdescriptor = m_SRV_CBR_DescriptorsHeap.GetGPUDescriptorHandleForHeapStart();
- gpuCBVdescriptor.ptr += 2 * m_SRV_CBR_DescriptorsHeap.GetDescriptorIncrementSize();
- m_commandList->SetGraphicsRootDescriptorTable(1, gpuCBVdescriptor);
И в шейдере можно получить доступ к ресурсам указав нужные регистры:
Code Snippet
- Texture2D g_texture : register(t0);
- cbuffer g_constants: register(b0)
- {
- float4 offset;
- }
Про наследование состояния:
- Descriptor Table State неопределен в начале записи Command List-а и после того, как меняется Descriptors Heaps в Command List-е.
- Повторное назначение того же самого Descriptors Heap-а не приводит к неопределенному состоянию Descriptors Table State.
- В Draw Bundle назначать Descriptors Heaps можно только 1 раз. (Повторное назначение тех же самых куч не приводит к ошибке).

Комментариев нет:
Отправить комментарий