From 225e34c592d2599026cf27ca0d8dc7169bede108 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 2 May 2019 11:29:24 +0100 Subject: [PATCH] Fetch D3DCompiler on demand rather than at dll init * This incurs a bit of a load-time hit that might not be needed until later. --- renderdoc/driver/d3d11/d3d11_shader_cache.cpp | 27 ++++++++++++------- renderdoc/driver/d3d12/d3d12_shader_cache.cpp | 26 +++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_shader_cache.cpp b/renderdoc/driver/d3d11/d3d11_shader_cache.cpp index dcbcfc232..4b44ac12b 100644 --- a/renderdoc/driver/d3d11/d3d11_shader_cache.cpp +++ b/renderdoc/driver/d3d11/d3d11_shader_cache.cpp @@ -34,25 +34,34 @@ typedef HRESULT(WINAPI *pD3DCreateBlob)(SIZE_T Size, ID3DBlob **ppBlob); struct D3DBlobShaderCallbacks { - D3DBlobShaderCallbacks() + pD3DCreateBlob GetCreateBlob() const { - HMODULE d3dcompiler = GetD3DCompiler(); + static pD3DCreateBlob blobCreate = NULL; - if(d3dcompiler == NULL) - RDCFATAL("Can't get handle to d3dcompiler_??.dll"); + if(!blobCreate) + { + HMODULE d3dcompiler = GetD3DCompiler(); - m_BlobCreate = (pD3DCreateBlob)GetProcAddress(d3dcompiler, "D3DCreateBlob"); + if(d3dcompiler == NULL) + RDCFATAL("Can't get handle to d3dcompiler_??.dll"); - if(m_BlobCreate == NULL) - RDCFATAL("d3dcompiler.dll doesn't contain D3DCreateBlob"); + blobCreate = (pD3DCreateBlob)GetProcAddress(d3dcompiler, "D3DCreateBlob"); + + if(blobCreate == NULL) + RDCFATAL("d3dcompiler.dll doesn't contain D3DCreateBlob"); + } + + return blobCreate; } bool Create(uint32_t size, byte *data, ID3DBlob **ret) const { RDCASSERT(ret); + pD3DCreateBlob blobCreate = GetCreateBlob(); + *ret = NULL; - HRESULT hr = m_BlobCreate((SIZE_T)size, ret); + HRESULT hr = blobCreate((SIZE_T)size, ret); if(FAILED(hr)) { @@ -68,7 +77,7 @@ struct D3DBlobShaderCallbacks void Destroy(ID3DBlob *blob) const { blob->Release(); } uint32_t GetSize(ID3DBlob *blob) const { return (uint32_t)blob->GetBufferSize(); } const byte *GetData(ID3DBlob *blob) const { return (const byte *)blob->GetBufferPointer(); } - pD3DCreateBlob m_BlobCreate; + pD3DCreateBlob m_BlobCreate = NULL; } D3D11ShaderCacheCallbacks; struct EmbeddedD3D11Includer : public ID3DInclude diff --git a/renderdoc/driver/d3d12/d3d12_shader_cache.cpp b/renderdoc/driver/d3d12/d3d12_shader_cache.cpp index fc4a8512d..6c9987989 100644 --- a/renderdoc/driver/d3d12/d3d12_shader_cache.cpp +++ b/renderdoc/driver/d3d12/d3d12_shader_cache.cpp @@ -32,25 +32,34 @@ typedef HRESULT(WINAPI *pD3DCreateBlob)(SIZE_T Size, ID3DBlob **ppBlob); struct D3D12BlobShaderCallbacks { - D3D12BlobShaderCallbacks() + pD3DCreateBlob GetCreateBlob() const { - HMODULE d3dcompiler = GetD3DCompiler(); + static pD3DCreateBlob blobCreate = NULL; - if(d3dcompiler == NULL) - RDCFATAL("Can't get handle to d3dcompiler_??.dll"); + if(!blobCreate) + { + HMODULE d3dcompiler = GetD3DCompiler(); - m_BlobCreate = (pD3DCreateBlob)GetProcAddress(d3dcompiler, "D3DCreateBlob"); + if(d3dcompiler == NULL) + RDCFATAL("Can't get handle to d3dcompiler_??.dll"); - if(m_BlobCreate == NULL) - RDCFATAL("d3dcompiler.dll doesn't contain D3DCreateBlob"); + blobCreate = (pD3DCreateBlob)GetProcAddress(d3dcompiler, "D3DCreateBlob"); + + if(blobCreate == NULL) + RDCFATAL("d3dcompiler.dll doesn't contain D3DCreateBlob"); + } + + return blobCreate; } bool Create(uint32_t size, byte *data, ID3DBlob **ret) const { RDCASSERT(ret); + pD3DCreateBlob blobCreate = GetCreateBlob(); + *ret = NULL; - HRESULT hr = m_BlobCreate((SIZE_T)size, ret); + HRESULT hr = blobCreate((SIZE_T)size, ret); if(FAILED(hr)) { @@ -67,7 +76,6 @@ struct D3D12BlobShaderCallbacks void Destroy(ID3DBlob *blob) const { blob->Release(); } uint32_t GetSize(ID3DBlob *blob) const { return (uint32_t)blob->GetBufferSize(); } const byte *GetData(ID3DBlob *blob) const { return (const byte *)blob->GetBufferPointer(); } - pD3DCreateBlob m_BlobCreate; } D3D12ShaderCacheCallbacks; struct EmbeddedD3D12Includer : public ID3DInclude