From 76d7c1eb9cf9fa86a7cb8351096086bf9b5e29a1 Mon Sep 17 00:00:00 2001 From: magumagu Date: Fri, 28 Mar 2014 15:56:51 -0700 Subject: [PATCH] D3DBackend: Don't recompute ID3D11Layout. CreateInputLayout requires a shader as an input, but it only cares about the signature; we don't need to recompute it for different shaders with the same inputs. --- .../VideoBackends/D3D/NativeVertexFormat.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp index 60ded71f7f..be59a2ac8c 100644 --- a/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp @@ -16,12 +16,11 @@ class D3DVertexFormat : public NativeVertexFormat D3D11_INPUT_ELEMENT_DESC m_elems[32]; UINT m_num_elems; - DX11::D3DBlob* m_vs_bytecode; ID3D11InputLayout* m_layout; public: - D3DVertexFormat() : m_num_elems(0), m_vs_bytecode(nullptr), m_layout(nullptr) {} - ~D3DVertexFormat() { SAFE_RELEASE(m_vs_bytecode); SAFE_RELEASE(m_layout); } + D3DVertexFormat() : m_num_elems(0), m_layout(nullptr) {} + ~D3DVertexFormat() { SAFE_RELEASE(m_layout); } void Initialize(const PortableVertexDeclaration &_vtx_decl); void SetupVertexPointers(); @@ -127,15 +126,14 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) void D3DVertexFormat::SetupVertexPointers() { - if (m_vs_bytecode != DX11::VertexShaderCache::GetActiveShaderBytecode()) + if (!m_layout) { - SAFE_RELEASE(m_vs_bytecode); - SAFE_RELEASE(m_layout); + // CreateInputLayout requires a shader input, but it only looks at the + // signature of the shader, so we don't need to recompute it if the shader + // changes. + D3DBlob* vs_bytecode = DX11::VertexShaderCache::GetActiveShaderBytecode(); - m_vs_bytecode = DX11::VertexShaderCache::GetActiveShaderBytecode(); - m_vs_bytecode->AddRef(); - - HRESULT hr = DX11::D3D::device->CreateInputLayout(m_elems, m_num_elems, m_vs_bytecode->Data(), m_vs_bytecode->Size(), &m_layout); + HRESULT hr = DX11::D3D::device->CreateInputLayout(m_elems, m_num_elems, vs_bytecode->Data(), vs_bytecode->Size(), &m_layout); if (FAILED(hr)) PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__); DX11::D3D::SetDebugObjectName((ID3D11DeviceChild*)m_layout, "input layout used to emulate the GX pipeline"); }