1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d11] Refactor shader module creation

This commit is contained in:
Philip Rebohle 2019-10-21 12:09:53 +02:00
parent 9444162ca6
commit ddf010479d
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 98 additions and 66 deletions

View File

@ -721,13 +721,15 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_VERTEX_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage,
&moduleInfo)))
return E_INVALIDARG;
&moduleInfo);
if (ppVertexShader == nullptr)
if (FAILED(hr))
return hr;
if (!ppVertexShader)
return S_FALSE;
*ppVertexShader = ref(new D3D11VertexShader(this, module));
@ -751,13 +753,15 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage,
&moduleInfo)))
return E_INVALIDARG;
&moduleInfo);
if (ppGeometryShader == nullptr)
if (FAILED(hr))
return hr;
if (!ppGeometryShader)
return S_FALSE;
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
@ -851,13 +855,15 @@ namespace dxvk {
moduleInfo.tess = nullptr;
moduleInfo.xfb = &xfb;
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage,
&moduleInfo)))
&moduleInfo);
if (FAILED(hr))
return E_INVALIDARG;
if (ppGeometryShader == nullptr)
if (!ppGeometryShader)
return S_FALSE;
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
@ -881,13 +887,16 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_FRAGMENT_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage,
&moduleInfo)))
return E_INVALIDARG;
&moduleInfo);
if (ppPixelShader == nullptr)
if (FAILED(hr))
return hr;
if (!ppPixelShader)
return S_FALSE;
*ppPixelShader = ref(new D3D11PixelShader(this, module));
@ -917,12 +926,14 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo)))
return E_INVALIDARG;
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo);
if (ppHullShader == nullptr)
if (FAILED(hr))
return hr;
if (!ppHullShader)
return S_FALSE;
*ppHullShader = ref(new D3D11HullShader(this, module));
@ -946,10 +957,12 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo)))
return E_INVALIDARG;
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo);
if (FAILED(hr))
return hr;
if (ppDomainShader == nullptr)
return S_FALSE;
@ -975,13 +988,15 @@ namespace dxvk {
Sha1Hash hash = Sha1Hash::compute(
pShaderBytecode, BytecodeLength);
if (FAILED(this->CreateShaderModule(&module,
HRESULT hr = CreateShaderModule(&module,
DxvkShaderKey(VK_SHADER_STAGE_COMPUTE_BIT, hash),
pShaderBytecode, BytecodeLength, pClassLinkage,
&moduleInfo)))
return E_INVALIDARG;
&moduleInfo);
if (ppComputeShader == nullptr)
if (FAILED(hr))
return hr;
if (!ppComputeShader)
return S_FALSE;
*ppComputeShader = ref(new D3D11ComputeShader(this, module));
@ -2025,14 +2040,17 @@ namespace dxvk {
if (pClassLinkage != nullptr)
Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported");
try {
*pShaderModule = m_shaderModules.GetShaderModule(this,
&ShaderKey, pModuleInfo, pShaderBytecode, BytecodeLength);
D3D11CommonShader commonShader;
HRESULT hr = m_shaderModules.GetShaderModule(this,
&ShaderKey, pModuleInfo, pShaderBytecode, BytecodeLength,
&commonShader);
if (FAILED(hr))
return hr;
*pShaderModule = std::move(commonShader);
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
return E_INVALIDARG;
}
}

View File

@ -79,24 +79,34 @@ namespace dxvk {
D3D11ShaderModuleSet::~D3D11ShaderModuleSet() { }
D3D11CommonShader D3D11ShaderModuleSet::GetShaderModule(
HRESULT D3D11ShaderModuleSet::GetShaderModule(
D3D11Device* pDevice,
const DxvkShaderKey* pShaderKey,
const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode,
size_t BytecodeLength) {
size_t BytecodeLength,
D3D11CommonShader* pShader) {
// Use the shader's unique key for the lookup
{ std::unique_lock<std::mutex> lock(m_mutex);
auto entry = m_modules.find(*pShaderKey);
if (entry != m_modules.end())
return entry->second;
if (entry != m_modules.end()) {
*pShader = entry->second;
return S_OK;
}
}
// This shader has not been compiled yet, so we have to create a
// new module. This takes a while, so we won't lock the structure.
D3D11CommonShader module(pDevice, pShaderKey,
D3D11CommonShader module;
try {
module = D3D11CommonShader(pDevice, pShaderKey,
pDxbcModuleInfo, pShaderBytecode, BytecodeLength);
} catch (const DxvkError& e) {
Logger::err(e.message());
return E_INVALIDARG;
}
// Insert the new module into the lookup table. If another thread
// has compiled the same shader in the meantime, we should return
@ -104,11 +114,14 @@ namespace dxvk {
{ std::unique_lock<std::mutex> lock(m_mutex);
auto status = m_modules.insert({ *pShaderKey, module });
if (!status.second)
return status.first->second;
if (!status.second) {
*pShader = status.first->second;
return S_OK;
}
}
return module;
*pShader = std::move(module);
return S_OK;
}
}

View File

@ -140,12 +140,13 @@ namespace dxvk {
D3D11ShaderModuleSet();
~D3D11ShaderModuleSet();
D3D11CommonShader GetShaderModule(
HRESULT GetShaderModule(
D3D11Device* pDevice,
const DxvkShaderKey* pShaderKey,
const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode,
size_t BytecodeLength);
size_t BytecodeLength,
D3D11CommonShader* pShader);
private: