From 3192f34f57abd3245995342a0a5971ebbbbd945c Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 15 Apr 2024 23:28:28 -0700 Subject: [GFX] Fix d3d12 buffer view creation logic for StructuredBuffers. (#3954) --- tools/gfx/d3d12/d3d12-shader-object.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tools/gfx/d3d12/d3d12-shader-object.cpp') diff --git a/tools/gfx/d3d12/d3d12-shader-object.cpp b/tools/gfx/d3d12/d3d12-shader-object.cpp index 1b7b51106..3d38df5ab 100644 --- a/tools/gfx/d3d12/d3d12-shader-object.cpp +++ b/tools/gfx/d3d12/d3d12-shader-object.cpp @@ -939,6 +939,8 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* } ResourceViewInternalImpl* internalResourceView = nullptr; + auto resourceViewImpl = static_cast(resourceView); + switch (resourceView->getViewDesc()->type) { #if SLANG_GFX_HAS_DXR_SUPPORT @@ -953,7 +955,6 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* #endif default: { - auto resourceViewImpl = static_cast(resourceView); // Hold a reference to the resource to prevent its destruction. const auto resourceOffset = bindingRange.baseIndex + offset.bindingArrayIndex; m_boundResources[resourceOffset] = resourceViewImpl->m_resource; @@ -964,13 +965,21 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* } auto descriptorSlotIndex = bindingRange.baseIndex + (int32_t)offset.bindingArrayIndex; - if (internalResourceView->m_descriptor.cpuHandle.ptr) + D3D12Descriptor srcDescriptor = {}; + + SLANG_RETURN_ON_FAIL(internalResourceView->getBufferDescriptorForBinding( + static_cast(m_device.get()), + resourceViewImpl, + bindingRange.bufferElementStride, + srcDescriptor)); + + if (srcDescriptor.cpuHandle.ptr) { d3dDevice->CopyDescriptorsSimple( 1, m_descriptorSet.resourceTable.getCpuHandle( bindingRange.baseIndex + (int32_t)offset.bindingArrayIndex), - internalResourceView->m_descriptor.cpuHandle, + srcDescriptor.cpuHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); } else -- cgit v1.2.3