Merge pull request #223 from magumagu/d3d-cache-input-layout

D3DBackend: Don't recompute ID3D11InputLayout for different shaders.
This commit is contained in:
Tony Wasserka 2014-04-11 22:40:22 +02:00
commit 7563e8c6f3
1 changed files with 8 additions and 10 deletions

View File

@ -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");
}