Skip to content

Commit

Permalink
Merge pull request #11226 from K0bin/d3d12-fix
Browse files Browse the repository at this point in the history
VideoBackends:D3D12: Fix hang in Twilight Princess
  • Loading branch information
AdmiralCurtiss committed Oct 29, 2022
2 parents a1e41f3 + a07ee72 commit 0628794
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ bool D3D12BoundingBox::CreateBuffers()
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS};

HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource(
&gpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&m_gpu_buffer));
&gpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COMMON,
nullptr, IID_PPV_ARGS(&m_gpu_buffer));
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating bounding box GPU buffer failed: {}", DX12HRWrap(hr));
if (FAILED(hr) || !g_dx_context->GetDescriptorHeapManager().Allocate(&m_gpu_descriptor))
return false;
Expand Down
12 changes: 7 additions & 5 deletions Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,20 @@ void Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)

void Renderer::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
{
BindFramebuffer(static_cast<DXFramebuffer*>(framebuffer));
SetFramebuffer(framebuffer);

static const D3D12_DISCARD_REGION dr = {0, nullptr, 0, 1};
if (framebuffer->HasColorBuffer())
{
g_dx_context->GetCommandList()->DiscardResource(
static_cast<DXTexture*>(framebuffer->GetColorAttachment())->GetResource(), &dr);
DXTexture* color_attachment = static_cast<DXTexture*>(framebuffer->GetColorAttachment());
color_attachment->TransitionToState(D3D12_RESOURCE_STATE_RENDER_TARGET);
g_dx_context->GetCommandList()->DiscardResource(color_attachment->GetResource(), &dr);
}
if (framebuffer->HasDepthBuffer())
{
g_dx_context->GetCommandList()->DiscardResource(
static_cast<DXTexture*>(framebuffer->GetDepthAttachment())->GetResource(), &dr);
DXTexture* depth_attachment = static_cast<DXTexture*>(framebuffer->GetDepthAttachment());
depth_attachment->TransitionToState(D3D12_RESOURCE_STATE_DEPTH_WRITE);
g_dx_context->GetCommandList()->DiscardResource(depth_attachment->GetResource(), &dr);
}
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Core/VideoBackends/D3D12/DescriptorHeapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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();
m_num_descriptors = num_descriptors;
m_descriptor_increment_size = device->GetDescriptorHandleIncrementSize(type);

Expand Down Expand Up @@ -60,7 +59,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 = 0;
return true;
}

Expand Down
1 change: 0 additions & 1 deletion Source/Core/VideoBackends/D3D12/DescriptorHeapManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class DescriptorHeapManager final
u32 m_descriptor_increment_size = 0;

D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {};
D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {};

static constexpr u32 BITSET_SIZE = 1024;
using BitSetType = std::bitset<BITSET_SIZE>;
Expand Down

0 comments on commit 0628794

Please sign in to comment.