Merge pull request #11226 from K0bin/d3d12-fix

VideoBackends:D3D12: Fix hang in Twilight Princess
This commit is contained in:
Admiral H. Curtiss 2022-10-30 00:24:16 +02:00 committed by GitHub
commit 0628794cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -101,8 +101,8 @@ bool D3D12BoundingBox::CreateBuffers()
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS}; D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS};
HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource( HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource(
&gpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc, &gpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COMMON,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&m_gpu_buffer)); nullptr, IID_PPV_ARGS(&m_gpu_buffer));
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating bounding box GPU buffer failed: {}", DX12HRWrap(hr)); ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating bounding box GPU buffer failed: {}", DX12HRWrap(hr));
if (FAILED(hr) || !g_dx_context->GetDescriptorHeapManager().Allocate(&m_gpu_descriptor)) if (FAILED(hr) || !g_dx_context->GetDescriptorHeapManager().Allocate(&m_gpu_descriptor))
return false; return false;

View File

@ -236,18 +236,20 @@ void Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)
void Renderer::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer) void Renderer::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
{ {
BindFramebuffer(static_cast<DXFramebuffer*>(framebuffer)); SetFramebuffer(framebuffer);
static const D3D12_DISCARD_REGION dr = {0, nullptr, 0, 1}; static const D3D12_DISCARD_REGION dr = {0, nullptr, 0, 1};
if (framebuffer->HasColorBuffer()) if (framebuffer->HasColorBuffer())
{ {
g_dx_context->GetCommandList()->DiscardResource( DXTexture* color_attachment = static_cast<DXTexture*>(framebuffer->GetColorAttachment());
static_cast<DXTexture*>(framebuffer->GetColorAttachment())->GetResource(), &dr); color_attachment->TransitionToState(D3D12_RESOURCE_STATE_RENDER_TARGET);
g_dx_context->GetCommandList()->DiscardResource(color_attachment->GetResource(), &dr);
} }
if (framebuffer->HasDepthBuffer()) if (framebuffer->HasDepthBuffer())
{ {
g_dx_context->GetCommandList()->DiscardResource( DXTexture* depth_attachment = static_cast<DXTexture*>(framebuffer->GetDepthAttachment());
static_cast<DXTexture*>(framebuffer->GetDepthAttachment())->GetResource(), &dr); depth_attachment->TransitionToState(D3D12_RESOURCE_STATE_DEPTH_WRITE);
g_dx_context->GetCommandList()->DiscardResource(depth_attachment->GetResource(), &dr);
} }
} }

View File

@ -25,7 +25,6 @@ bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_T
return false; return false;
m_heap_base_cpu = m_descriptor_heap->GetCPUDescriptorHandleForHeapStart(); m_heap_base_cpu = m_descriptor_heap->GetCPUDescriptorHandleForHeapStart();
m_heap_base_gpu = m_descriptor_heap->GetGPUDescriptorHandleForHeapStart();
m_num_descriptors = num_descriptors; m_num_descriptors = num_descriptors;
m_descriptor_increment_size = device->GetDescriptorHandleIncrementSize(type); m_descriptor_increment_size = device->GetDescriptorHandleIncrementSize(type);
@ -60,7 +59,7 @@ bool DescriptorHeapManager::Allocate(DescriptorHandle* handle)
handle->index = index; handle->index = index;
handle->cpu_handle.ptr = m_heap_base_cpu.ptr + index * m_descriptor_increment_size; 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 = 0;
return true; return true;
} }

View File

@ -41,7 +41,6 @@ private:
u32 m_descriptor_increment_size = 0; u32 m_descriptor_increment_size = 0;
D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {}; D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {};
D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {};
static constexpr u32 BITSET_SIZE = 1024; static constexpr u32 BITSET_SIZE = 1024;
using BitSetType = std::bitset<BITSET_SIZE>; using BitSetType = std::bitset<BITSET_SIZE>;