mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 14:52:11 +01:00
[d3d11] Refactor shader module creation
This commit is contained in:
parent
9444162ca6
commit
ddf010479d
@ -721,13 +721,15 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_VERTEX_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_VERTEX_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage,
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
||||||
&moduleInfo)))
|
&moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (ppVertexShader == nullptr)
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if (!ppVertexShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppVertexShader = ref(new D3D11VertexShader(this, module));
|
*ppVertexShader = ref(new D3D11VertexShader(this, module));
|
||||||
@ -751,13 +753,15 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage,
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
||||||
&moduleInfo)))
|
&moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (ppGeometryShader == nullptr)
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if (!ppGeometryShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
|
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
|
||||||
@ -851,13 +855,15 @@ namespace dxvk {
|
|||||||
moduleInfo.tess = nullptr;
|
moduleInfo.tess = nullptr;
|
||||||
moduleInfo.xfb = &xfb;
|
moduleInfo.xfb = &xfb;
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_GEOMETRY_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage,
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
||||||
&moduleInfo)))
|
&moduleInfo);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
if (ppGeometryShader == nullptr)
|
if (!ppGeometryShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
|
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
|
||||||
@ -881,13 +887,16 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
|
||||||
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_FRAGMENT_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_FRAGMENT_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage,
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
||||||
&moduleInfo)))
|
&moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (ppPixelShader == nullptr)
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if (!ppPixelShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppPixelShader = ref(new D3D11PixelShader(this, module));
|
*ppPixelShader = ref(new D3D11PixelShader(this, module));
|
||||||
@ -917,12 +926,14 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo)))
|
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (ppHullShader == nullptr)
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if (!ppHullShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppHullShader = ref(new D3D11HullShader(this, module));
|
*ppHullShader = ref(new D3D11HullShader(this, module));
|
||||||
@ -946,10 +957,12 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo)))
|
pShaderBytecode, BytecodeLength, pClassLinkage, &moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
if (ppDomainShader == nullptr)
|
if (ppDomainShader == nullptr)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
@ -975,13 +988,15 @@ namespace dxvk {
|
|||||||
Sha1Hash hash = Sha1Hash::compute(
|
Sha1Hash hash = Sha1Hash::compute(
|
||||||
pShaderBytecode, BytecodeLength);
|
pShaderBytecode, BytecodeLength);
|
||||||
|
|
||||||
if (FAILED(this->CreateShaderModule(&module,
|
HRESULT hr = CreateShaderModule(&module,
|
||||||
DxvkShaderKey(VK_SHADER_STAGE_COMPUTE_BIT, hash),
|
DxvkShaderKey(VK_SHADER_STAGE_COMPUTE_BIT, hash),
|
||||||
pShaderBytecode, BytecodeLength, pClassLinkage,
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
||||||
&moduleInfo)))
|
&moduleInfo);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (ppComputeShader == nullptr)
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if (!ppComputeShader)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
*ppComputeShader = ref(new D3D11ComputeShader(this, module));
|
*ppComputeShader = ref(new D3D11ComputeShader(this, module));
|
||||||
@ -2025,14 +2040,17 @@ namespace dxvk {
|
|||||||
if (pClassLinkage != nullptr)
|
if (pClassLinkage != nullptr)
|
||||||
Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported");
|
Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported");
|
||||||
|
|
||||||
try {
|
D3D11CommonShader commonShader;
|
||||||
*pShaderModule = m_shaderModules.GetShaderModule(this,
|
|
||||||
&ShaderKey, pModuleInfo, pShaderBytecode, BytecodeLength);
|
HRESULT hr = m_shaderModules.GetShaderModule(this,
|
||||||
|
&ShaderKey, pModuleInfo, pShaderBytecode, BytecodeLength,
|
||||||
|
&commonShader);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
*pShaderModule = std::move(commonShader);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
|
||||||
Logger::err(e.message());
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,24 +79,34 @@ namespace dxvk {
|
|||||||
D3D11ShaderModuleSet::~D3D11ShaderModuleSet() { }
|
D3D11ShaderModuleSet::~D3D11ShaderModuleSet() { }
|
||||||
|
|
||||||
|
|
||||||
D3D11CommonShader D3D11ShaderModuleSet::GetShaderModule(
|
HRESULT D3D11ShaderModuleSet::GetShaderModule(
|
||||||
D3D11Device* pDevice,
|
D3D11Device* pDevice,
|
||||||
const DxvkShaderKey* pShaderKey,
|
const DxvkShaderKey* pShaderKey,
|
||||||
const DxbcModuleInfo* pDxbcModuleInfo,
|
const DxbcModuleInfo* pDxbcModuleInfo,
|
||||||
const void* pShaderBytecode,
|
const void* pShaderBytecode,
|
||||||
size_t BytecodeLength) {
|
size_t BytecodeLength,
|
||||||
|
D3D11CommonShader* pShader) {
|
||||||
// Use the shader's unique key for the lookup
|
// Use the shader's unique key for the lookup
|
||||||
{ std::unique_lock<std::mutex> lock(m_mutex);
|
{ std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
auto entry = m_modules.find(*pShaderKey);
|
auto entry = m_modules.find(*pShaderKey);
|
||||||
if (entry != m_modules.end())
|
if (entry != m_modules.end()) {
|
||||||
return entry->second;
|
*pShader = entry->second;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This shader has not been compiled yet, so we have to create a
|
// 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.
|
// 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);
|
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
|
// Insert the new module into the lookup table. If another thread
|
||||||
// has compiled the same shader in the meantime, we should return
|
// 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);
|
{ std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
auto status = m_modules.insert({ *pShaderKey, module });
|
auto status = m_modules.insert({ *pShaderKey, module });
|
||||||
if (!status.second)
|
if (!status.second) {
|
||||||
return status.first->second;
|
*pShader = status.first->second;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return module;
|
*pShader = std::move(module);
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,12 +140,13 @@ namespace dxvk {
|
|||||||
D3D11ShaderModuleSet();
|
D3D11ShaderModuleSet();
|
||||||
~D3D11ShaderModuleSet();
|
~D3D11ShaderModuleSet();
|
||||||
|
|
||||||
D3D11CommonShader GetShaderModule(
|
HRESULT GetShaderModule(
|
||||||
D3D11Device* pDevice,
|
D3D11Device* pDevice,
|
||||||
const DxvkShaderKey* pShaderKey,
|
const DxvkShaderKey* pShaderKey,
|
||||||
const DxbcModuleInfo* pDxbcModuleInfo,
|
const DxbcModuleInfo* pDxbcModuleInfo,
|
||||||
const void* pShaderBytecode,
|
const void* pShaderBytecode,
|
||||||
size_t BytecodeLength);
|
size_t BytecodeLength,
|
||||||
|
D3D11CommonShader* pShader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user