From 3d81b3eb82c31dc44607651b89ed6927d964c723 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 12 Mar 2020 20:42:45 +0100 Subject: [PATCH] [d3d10] Create variable reflection objects on demand --- src/d3d10/d3d10_reflection.cpp | 19 +++++++++++-------- src/d3d10/d3d10_reflection.h | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/d3d10/d3d10_reflection.cpp b/src/d3d10/d3d10_reflection.cpp index 731b86fc..0d3432dc 100644 --- a/src/d3d10/d3d10_reflection.cpp +++ b/src/d3d10/d3d10_reflection.cpp @@ -102,11 +102,7 @@ namespace dxvk { D3D10ShaderReflectionConstantBuffer::D3D10ShaderReflectionConstantBuffer( ID3D11ShaderReflectionConstantBuffer* d3d11) : m_d3d11(d3d11) { - D3D11_SHADER_BUFFER_DESC d3d11Desc; - m_d3d11->GetDesc(&d3d11Desc); - for (uint32_t i = 0; i < d3d11Desc.Variables; i++) - m_variables.emplace_back(m_d3d11->GetVariableByIndex(i)); } @@ -146,12 +142,19 @@ namespace dxvk { ID3D10ShaderReflectionVariable* D3D10ShaderReflectionConstantBuffer::FindVariable( ID3D11ShaderReflectionVariable* pVariable) { - for (size_t i = 0; i < m_variables.size(); i++) { - if (m_variables[i].GetD3D11Iface() == pVariable) - return &m_variables[i]; + if (!pVariable) + return nullptr; + + auto entry = m_variables.find(pVariable); + + if (entry == m_variables.end()) { + entry = m_variables.emplace( + std::piecewise_construct, + std::forward_as_tuple(pVariable), + std::forward_as_tuple(pVariable)).first; } - return nullptr; + return &entry->second; } diff --git a/src/d3d10/d3d10_reflection.h b/src/d3d10/d3d10_reflection.h index d4821a3b..14bc0efd 100644 --- a/src/d3d10/d3d10_reflection.h +++ b/src/d3d10/d3d10_reflection.h @@ -98,7 +98,9 @@ namespace dxvk { ID3D11ShaderReflectionConstantBuffer* m_d3d11; - std::vector m_variables; + std::unordered_map< + ID3D11ShaderReflectionVariable*, + D3D10ShaderReflectionVariable> m_variables; ID3D10ShaderReflectionVariable* FindVariable( ID3D11ShaderReflectionVariable* pVariable);