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.
This commit is contained in:
baldurk
2019-05-02 11:29:24 +01:00
parent 87c4d529c0
commit 225e34c592
2 changed files with 35 additions and 18 deletions
+18 -9
View File
@@ -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
+17 -9
View File
@@ -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