From db6641cecf4b9a840434440fec02de110251c280 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Mon, 16 Sep 2024 02:19:32 +0200 Subject: [PATCH] Support buffer srvs --- .../Sources/kope/direct3d12/descriptorset.cpp | 15 +++++++++++++++ .../kope/direct3d12/descriptorset_functions.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset.cpp index ce9a2ff0b..34c7321d4 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset.cpp @@ -13,6 +13,21 @@ void kope_d3d12_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_ device->d3d12.device->CreateConstantBufferView(&desc, descriptor_handle); } +void kope_d3d12_descriptor_set_set_buffer_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index) { + D3D12_SHADER_RESOURCE_VIEW_DESC desc = {}; + desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + desc.Format = DXGI_FORMAT_UNKNOWN; + desc.Buffer.FirstElement = 0; + desc.Buffer.NumElements = 1; + desc.Buffer.StructureByteStride = (UINT)buffer->d3d12.size; + desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE; + + D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = device->d3d12.descriptor_heap->GetCPUDescriptorHandleForHeapStart(); + descriptor_handle.ptr += (set->descriptor_allocation.offset + index) * device->d3d12.cbv_srv_uav_increment; + device->d3d12.device->CreateShaderResourceView(buffer->d3d12.resource, &desc, descriptor_handle); +} + void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index) { D3D12_SHADER_RESOURCE_VIEW_DESC desc = {}; desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset_functions.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset_functions.h index 68a2d1db0..d0c49d945 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset_functions.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/descriptorset_functions.h @@ -12,6 +12,7 @@ extern "C" { #endif void kope_d3d12_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index); +void kope_d3d12_descriptor_set_set_buffer_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index); void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index); void kope_d3d12_descriptor_set_set_texture_view_uav(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index); void kope_d3d12_descriptor_set_set_sampler(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index);