mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[d3d9] Reduce copying around of shader metadata at Create time
This commit is contained in:
parent
1274b7a8e7
commit
3e65c2bb87
@ -6043,7 +6043,7 @@ namespace dxvk {
|
|||||||
const DWORD* pShaderBytecode,
|
const DWORD* pShaderBytecode,
|
||||||
const DxsoModuleInfo* pModuleInfo) {
|
const DxsoModuleInfo* pModuleInfo) {
|
||||||
try {
|
try {
|
||||||
*pShaderModule = m_shaderModules->GetShaderModule(this,
|
m_shaderModules->GetShaderModule(this, pShaderModule,
|
||||||
ShaderStage, pModuleInfo, pShaderBytecode);
|
ShaderStage, pModuleInfo, pShaderBytecode);
|
||||||
|
|
||||||
return D3D_OK;
|
return D3D_OK;
|
||||||
|
@ -10,7 +10,7 @@ namespace dxvk {
|
|||||||
D3D9CommonShader::D3D9CommonShader(
|
D3D9CommonShader::D3D9CommonShader(
|
||||||
D3D9DeviceEx* pDevice,
|
D3D9DeviceEx* pDevice,
|
||||||
VkShaderStageFlagBits ShaderStage,
|
VkShaderStageFlagBits ShaderStage,
|
||||||
const Sha1Hash* pHash,
|
const DxvkShaderKey& Key,
|
||||||
const DxsoModuleInfo* pDxsoModuleInfo,
|
const DxsoModuleInfo* pDxsoModuleInfo,
|
||||||
const void* pShaderBytecode,
|
const void* pShaderBytecode,
|
||||||
const DxsoAnalysisInfo& AnalysisInfo,
|
const DxsoAnalysisInfo& AnalysisInfo,
|
||||||
@ -19,9 +19,7 @@ namespace dxvk {
|
|||||||
m_bytecode.resize(bytecodeLength);
|
m_bytecode.resize(bytecodeLength);
|
||||||
std::memcpy(m_bytecode.data(), pShaderBytecode, bytecodeLength);
|
std::memcpy(m_bytecode.data(), pShaderBytecode, bytecodeLength);
|
||||||
|
|
||||||
DxvkShaderKey shaderKey = { ShaderStage, *pHash };
|
const std::string name = Key.toString();
|
||||||
|
|
||||||
const std::string name = shaderKey.toString();
|
|
||||||
Logger::debug(str::format("Compiling shader ", name));
|
Logger::debug(str::format("Compiling shader ", name));
|
||||||
|
|
||||||
// If requested by the user, dump both the raw DXBC
|
// If requested by the user, dump both the raw DXBC
|
||||||
@ -57,7 +55,6 @@ namespace dxvk {
|
|||||||
const D3D9ConstantLayout& constantLayout = ShaderStage == VK_SHADER_STAGE_VERTEX_BIT
|
const D3D9ConstantLayout& constantLayout = ShaderStage == VK_SHADER_STAGE_VERTEX_BIT
|
||||||
? pDevice->GetVertexConstantLayout()
|
? pDevice->GetVertexConstantLayout()
|
||||||
: pDevice->GetPixelConstantLayout();
|
: pDevice->GetPixelConstantLayout();
|
||||||
|
|
||||||
m_shaders = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout);
|
m_shaders = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout);
|
||||||
m_isgn = pModule->isgn();
|
m_isgn = pModule->isgn();
|
||||||
m_usedSamplers = pModule->usedSamplers();
|
m_usedSamplers = pModule->usedSamplers();
|
||||||
@ -74,11 +71,11 @@ namespace dxvk {
|
|||||||
m_meta = pModule->meta();
|
m_meta = pModule->meta();
|
||||||
m_constants = pModule->constants();
|
m_constants = pModule->constants();
|
||||||
|
|
||||||
m_shaders[0]->setShaderKey(shaderKey);
|
m_shaders[0]->setShaderKey(Key);
|
||||||
|
|
||||||
if (m_shaders[1] != nullptr) {
|
if (m_shaders[1] != nullptr) {
|
||||||
// Lets lie about the shader key type for the state cache.
|
// Lets lie about the shader key type for the state cache.
|
||||||
m_shaders[1]->setShaderKey({ VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, *pHash });
|
m_shaders[1]->setShaderKey({ VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, Key.sha1() });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dumpPath.size() != 0) {
|
if (dumpPath.size() != 0) {
|
||||||
@ -96,8 +93,9 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
D3D9CommonShader D3D9ShaderModuleSet::GetShaderModule(
|
void D3D9ShaderModuleSet::GetShaderModule(
|
||||||
D3D9DeviceEx* pDevice,
|
D3D9DeviceEx* pDevice,
|
||||||
|
D3D9CommonShader* pShaderModule,
|
||||||
VkShaderStageFlagBits ShaderStage,
|
VkShaderStageFlagBits ShaderStage,
|
||||||
const DxsoModuleInfo* pDxbcModuleInfo,
|
const DxsoModuleInfo* pDxbcModuleInfo,
|
||||||
const void* pShaderBytecode) {
|
const void* pShaderBytecode) {
|
||||||
@ -114,23 +112,24 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxsoAnalysisInfo info = module.analyze();
|
DxsoAnalysisInfo info = module.analyze();
|
||||||
|
|
||||||
Sha1Hash hash = Sha1Hash::compute(
|
DxvkShaderKey lookupKey = DxvkShaderKey(
|
||||||
pShaderBytecode, info.bytecodeByteLength);
|
ShaderStage,
|
||||||
|
Sha1Hash::compute(pShaderBytecode, info.bytecodeByteLength));
|
||||||
DxvkShaderKey lookupKey = DxvkShaderKey(ShaderStage, hash);
|
|
||||||
|
|
||||||
// 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(lookupKey);
|
auto entry = m_modules.find(lookupKey);
|
||||||
if (entry != m_modules.end())
|
if (entry != m_modules.end()) {
|
||||||
return entry->second;
|
*pShaderModule = entry->second;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
D3D9CommonShader commonShader(
|
*pShaderModule = D3D9CommonShader(
|
||||||
pDevice, ShaderStage, &hash,
|
pDevice, ShaderStage, lookupKey,
|
||||||
pDxbcModuleInfo, pShaderBytecode,
|
pDxbcModuleInfo, pShaderBytecode,
|
||||||
info, &module);
|
info, &module);
|
||||||
|
|
||||||
@ -139,12 +138,12 @@ namespace dxvk {
|
|||||||
// that object instead and discard the newly created module.
|
// that object instead and discard the newly created module.
|
||||||
{ std::unique_lock<std::mutex> lock(m_mutex);
|
{ std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
auto status = m_modules.insert({ lookupKey, commonShader });
|
auto status = m_modules.insert({ lookupKey, *pShaderModule });
|
||||||
if (!status.second)
|
if (!status.second) {
|
||||||
return status.first->second;
|
*pShaderModule = status.first->second;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return commonShader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ namespace dxvk {
|
|||||||
D3D9CommonShader(
|
D3D9CommonShader(
|
||||||
D3D9DeviceEx* pDevice,
|
D3D9DeviceEx* pDevice,
|
||||||
VkShaderStageFlagBits ShaderStage,
|
VkShaderStageFlagBits ShaderStage,
|
||||||
const Sha1Hash* pHash,
|
const DxvkShaderKey& Key,
|
||||||
const DxsoModuleInfo* pDxbcModuleInfo,
|
const DxsoModuleInfo* pDxbcModuleInfo,
|
||||||
const void* pShaderBytecode,
|
const void* pShaderBytecode,
|
||||||
const DxsoAnalysisInfo& AnalysisInfo,
|
const DxsoAnalysisInfo& AnalysisInfo,
|
||||||
@ -170,8 +170,9 @@ namespace dxvk {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
D3D9CommonShader GetShaderModule(
|
void GetShaderModule(
|
||||||
D3D9DeviceEx* pDevice,
|
D3D9DeviceEx* pDevice,
|
||||||
|
D3D9CommonShader* pShaderModule,
|
||||||
VkShaderStageFlagBits ShaderStage,
|
VkShaderStageFlagBits ShaderStage,
|
||||||
const DxsoModuleInfo* pDxbcModuleInfo,
|
const DxsoModuleInfo* pDxbcModuleInfo,
|
||||||
const void* pShaderBytecode);
|
const void* pShaderBytecode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user