Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12087 from Dentomologist/dx12_use_correct_framebu…
…ffer_descriptor

D3D12: Only use framebuffer integer descriptor if allocated
  • Loading branch information
AdmiralCurtiss committed Aug 10, 2023
2 parents 54d3a22 + 83f307e commit b0dc067
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 21 additions & 0 deletions Source/Core/VideoBackends/D3D12/DX12Texture.cpp
Expand Up @@ -422,6 +422,23 @@ DXFramebuffer::~DXFramebuffer()
}
}

const D3D12_CPU_DESCRIPTOR_HANDLE* DXFramebuffer::GetIntRTVDescriptorArray() const
{
if (m_color_attachment == nullptr)
return nullptr;

const auto& handle = m_int_rtv_descriptor.cpu_handle;

// To save space in the descriptor heap, m_int_rtv_descriptor.cpu_handle.ptr is only allocated
// when the integer RTV format corresponding to the current abstract format differs from the
// non-integer RTV format. Only use the integer handle if it has been allocated.
if (handle.ptr != 0)
return &handle;

// The integer and non-integer RTV formats are the same, so use the non-integer descriptor.
return GetRTVDescriptorArray();
}

void DXFramebuffer::Unbind()
{
static const D3D12_DISCARD_REGION dr = {0, nullptr, 0, 1};
Expand Down Expand Up @@ -556,6 +573,10 @@ bool DXFramebuffer::CreateIRTVDescriptor()
const bool multisampled = m_samples > 1;
DXGI_FORMAT non_int_format = D3DCommon::GetRTVFormatForAbstractFormat(m_color_format, false);
DXGI_FORMAT int_format = D3DCommon::GetRTVFormatForAbstractFormat(m_color_format, true);

// If the integer and non-integer RTV formats are the same for a given abstract format we can save
// space in the descriptor heap by only allocating the non-integer descriptor and using it for
// the integer RTV too.
if (int_format != non_int_format)
{
if (!g_dx_context->GetRTVHeapManager().Allocate(&m_int_rtv_descriptor))
Expand Down
5 changes: 1 addition & 4 deletions Source/Core/VideoBackends/D3D12/DX12Texture.h
Expand Up @@ -75,10 +75,7 @@ class DXFramebuffer final : public AbstractFramebuffer
{
return m_render_targets_raw.data();
}
const D3D12_CPU_DESCRIPTOR_HANDLE* GetIntRTVDescriptorArray() const
{
return m_color_attachment ? &m_int_rtv_descriptor.cpu_handle : nullptr;
}
const D3D12_CPU_DESCRIPTOR_HANDLE* GetIntRTVDescriptorArray() const;
const D3D12_CPU_DESCRIPTOR_HANDLE* GetDSVDescriptorArray() const
{
return m_depth_attachment ? &m_dsv_descriptor.cpu_handle : nullptr;
Expand Down

0 comments on commit b0dc067

Please sign in to comment.