From 822e508d133a1e75694d14a0038cc5d6bf8a8f88 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 27 May 2022 00:07:22 +1000 Subject: [PATCH] D3D12: Don't call GetGPUDescriptorHandleForHeapStart() on non-shader-visible heaps --- common/D3D12/DescriptorHeapManager.cpp | 8 ++++++-- common/D3D12/DescriptorHeapManager.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/D3D12/DescriptorHeapManager.cpp b/common/D3D12/DescriptorHeapManager.cpp index 48df3eb373..36b96f3b99 100644 --- a/common/D3D12/DescriptorHeapManager.cpp +++ b/common/D3D12/DescriptorHeapManager.cpp @@ -36,9 +36,12 @@ bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_T return false; m_heap_base_cpu = m_descriptor_heap->GetCPUDescriptorHandleForHeapStart(); - m_heap_base_gpu = m_descriptor_heap->GetGPUDescriptorHandleForHeapStart(); + if (shader_visible) + m_heap_base_gpu = m_descriptor_heap->GetGPUDescriptorHandleForHeapStart(); + m_num_descriptors = num_descriptors; m_descriptor_increment_size = device->GetDescriptorHandleIncrementSize(type); + m_shader_visible = shader_visible; // Set all slots to unallocated (1) const u32 bitset_count = num_descriptors / BITSET_SIZE + (((num_descriptors % BITSET_SIZE) != 0) ? 1 : 0); @@ -56,6 +59,7 @@ void DescriptorHeapManager::Destroy() pxAssert(bs.all()); } + m_shader_visible = false; m_num_descriptors = 0; m_descriptor_increment_size = 0; m_heap_base_cpu = {}; @@ -85,7 +89,7 @@ bool DescriptorHeapManager::Allocate(DescriptorHandle* handle) handle->index = index; handle->cpu_handle.ptr = m_heap_base_cpu.ptr + index * m_descriptor_increment_size; - handle->gpu_handle.ptr = m_heap_base_gpu.ptr + index * m_descriptor_increment_size; + handle->gpu_handle.ptr = m_shader_visible ? (m_heap_base_gpu.ptr + index * m_descriptor_increment_size) : 0; return true; } diff --git a/common/D3D12/DescriptorHeapManager.h b/common/D3D12/DescriptorHeapManager.h index 467f717b74..a0edf9822a 100644 --- a/common/D3D12/DescriptorHeapManager.h +++ b/common/D3D12/DescriptorHeapManager.h @@ -80,6 +80,7 @@ namespace D3D12 wil::com_ptr_nothrow m_descriptor_heap; u32 m_num_descriptors = 0; u32 m_descriptor_increment_size = 0; + bool m_shader_visible = false; D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {}; D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {};