From 102591369e95ced8ff482aa69bea7078945288fb Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 23 Jun 2018 17:14:35 +0200 Subject: [PATCH] [dxbc] Add DxbcModuleInfo struct This will be required in the future to pass data from the application to the shader compiler. --- src/d3d11/d3d11_device.cpp | 51 ++++++++++++++++++++++++-------------- src/d3d11/d3d11_device.h | 1 + src/d3d11/d3d11_shader.cpp | 8 +++--- src/d3d11/d3d11_shader.h | 4 +-- src/dxbc/dxbc_analysis.cpp | 2 +- src/dxbc/dxbc_analysis.h | 4 +-- src/dxbc/dxbc_compiler.cpp | 18 +++++++------- src/dxbc/dxbc_compiler.h | 6 ++--- src/dxbc/dxbc_modinfo.h | 17 +++++++++++++ src/dxbc/dxbc_module.cpp | 8 +++--- src/dxbc/dxbc_module.h | 8 +++--- 11 files changed, 79 insertions(+), 48 deletions(-) create mode 100644 src/dxbc/dxbc_modinfo.h diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 46e52712..fa07b636 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1072,17 +1072,19 @@ namespace dxvk { ID3D11VertexShader** ppVertexShader) { InitReturnPtr(ppVertexShader); D3D11ShaderModule module; + + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::VertexShader))) + &moduleInfo, DxbcProgramType::VertexShader))) return E_INVALIDARG; if (ppVertexShader == nullptr) return S_FALSE; - *ppVertexShader = ref(new D3D11VertexShader( - this, module)); + *ppVertexShader = ref(new D3D11VertexShader(this, module)); return S_OK; } @@ -1095,16 +1097,18 @@ namespace dxvk { InitReturnPtr(ppGeometryShader); D3D11ShaderModule module; + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; + if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::GeometryShader))) + &moduleInfo, DxbcProgramType::GeometryShader))) return E_INVALIDARG; if (ppGeometryShader == nullptr) return S_FALSE; - *ppGeometryShader = ref(new D3D11GeometryShader( - this, module)); + *ppGeometryShader = ref(new D3D11GeometryShader(this, module)); return S_OK; } @@ -1136,16 +1140,18 @@ namespace dxvk { InitReturnPtr(ppPixelShader); D3D11ShaderModule module; + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; + if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::PixelShader))) + &moduleInfo, DxbcProgramType::PixelShader))) return E_INVALIDARG; if (ppPixelShader == nullptr) return S_FALSE; - *ppPixelShader = ref(new D3D11PixelShader( - this, module)); + *ppPixelShader = ref(new D3D11PixelShader(this, module)); return S_OK; } @@ -1158,16 +1164,18 @@ namespace dxvk { InitReturnPtr(ppHullShader); D3D11ShaderModule module; + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; + if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::HullShader))) + &moduleInfo, DxbcProgramType::HullShader))) return E_INVALIDARG; if (ppHullShader == nullptr) return S_FALSE; - *ppHullShader = ref(new D3D11HullShader( - this, module)); + *ppHullShader = ref(new D3D11HullShader(this, module)); return S_OK; } @@ -1180,16 +1188,18 @@ namespace dxvk { InitReturnPtr(ppDomainShader); D3D11ShaderModule module; + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; + if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::DomainShader))) + &moduleInfo, DxbcProgramType::DomainShader))) return E_INVALIDARG; if (ppDomainShader == nullptr) return S_FALSE; - *ppDomainShader = ref(new D3D11DomainShader( - this, module)); + *ppDomainShader = ref(new D3D11DomainShader(this, module)); return S_OK; } @@ -1202,16 +1212,18 @@ namespace dxvk { InitReturnPtr(ppComputeShader); D3D11ShaderModule module; + DxbcModuleInfo moduleInfo; + moduleInfo.options = m_dxbcOptions; + if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, - DxbcProgramType::ComputeShader))) + &moduleInfo, DxbcProgramType::ComputeShader))) return E_INVALIDARG; if (ppComputeShader == nullptr) return S_FALSE; - *ppComputeShader = ref(new D3D11ComputeShader( - this, module)); + *ppComputeShader = ref(new D3D11ComputeShader(this, module)); return S_OK; } @@ -1838,13 +1850,14 @@ namespace dxvk { const void* pShaderBytecode, size_t BytecodeLength, ID3D11ClassLinkage* pClassLinkage, + const DxbcModuleInfo* pModuleInfo, DxbcProgramType ProgramType) { if (pClassLinkage != nullptr) Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported"); try { *pShaderModule = m_shaderModules.GetShaderModule( - &m_dxbcOptions, pShaderBytecode, BytecodeLength, ProgramType); + pModuleInfo, pShaderBytecode, BytecodeLength, ProgramType); return S_OK; } catch (const DxvkError& e) { Logger::err(e.message()); diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index 1f52456e..9128a876 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -374,6 +374,7 @@ namespace dxvk { const void* pShaderBytecode, size_t BytecodeLength, ID3D11ClassLinkage* pClassLinkage, + const DxbcModuleInfo* pModuleInfo, DxbcProgramType ProgramType); void InitBuffer( diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index 375aad76..5a09db08 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -40,7 +40,7 @@ namespace dxvk { D3D11ShaderModule::D3D11ShaderModule( const D3D11ShaderKey* pShaderKey, - const DxbcOptions* pDxbcOptions, + const DxbcModuleInfo* pDxbcModuleInfo, const void* pShaderBytecode, size_t BytecodeLength) : m_name(pShaderKey->GetName()) { @@ -62,7 +62,7 @@ namespace dxvk { std::ios_base::binary | std::ios_base::trunc)); } - m_shader = module.compile(*pDxbcOptions, m_name); + m_shader = module.compile(*pDxbcModuleInfo, m_name); m_shader->setDebugName(m_name); if (dumpPath.size() != 0) { @@ -92,7 +92,7 @@ namespace dxvk { D3D11ShaderModule D3D11ShaderModuleSet::GetShaderModule( - const DxbcOptions* pDxbcOptions, + const DxbcModuleInfo* pDxbcModuleInfo, const void* pShaderBytecode, size_t BytecodeLength, DxbcProgramType ProgramType) { @@ -108,7 +108,7 @@ namespace dxvk { // 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. - D3D11ShaderModule module(&key, pDxbcOptions, pShaderBytecode, BytecodeLength); + D3D11ShaderModule module(&key, pDxbcModuleInfo, pShaderBytecode, BytecodeLength); // Insert the new module into the lookup table. If another thread // has compiled the same shader in the meantime, we should return diff --git a/src/d3d11/d3d11_shader.h b/src/d3d11/d3d11_shader.h index 5679fd9a..92126ac2 100644 --- a/src/d3d11/d3d11_shader.h +++ b/src/d3d11/d3d11_shader.h @@ -70,7 +70,7 @@ namespace dxvk { D3D11ShaderModule(); D3D11ShaderModule( const D3D11ShaderKey* pShaderKey, - const DxbcOptions* pDxbcOptions, + const DxbcModuleInfo* pDxbcModuleInfo, const void* pShaderBytecode, size_t BytecodeLength); ~D3D11ShaderModule(); @@ -165,7 +165,7 @@ namespace dxvk { ~D3D11ShaderModuleSet(); D3D11ShaderModule GetShaderModule( - const DxbcOptions* pDxbcOptions, + const DxbcModuleInfo* pDxbcModuleInfo, const void* pShaderBytecode, size_t BytecodeLength, DxbcProgramType ProgramType); diff --git a/src/dxbc/dxbc_analysis.cpp b/src/dxbc/dxbc_analysis.cpp index a230da97..dcbfdd1e 100644 --- a/src/dxbc/dxbc_analysis.cpp +++ b/src/dxbc/dxbc_analysis.cpp @@ -3,7 +3,7 @@ namespace dxvk { DxbcAnalyzer::DxbcAnalyzer( - const DxbcOptions& options, + const DxbcModuleInfo& moduleInfo, const DxbcProgramVersion& version, const Rc& isgn, const Rc& osgn, diff --git a/src/dxbc/dxbc_analysis.h b/src/dxbc/dxbc_analysis.h index 5059ae84..1b37fcdd 100644 --- a/src/dxbc/dxbc_analysis.h +++ b/src/dxbc/dxbc_analysis.h @@ -4,7 +4,7 @@ #include "dxbc_decoder.h" #include "dxbc_defs.h" #include "dxbc_names.h" -#include "dxbc_options.h" +#include "dxbc_modinfo.h" #include "dxbc_util.h" namespace dxvk { @@ -54,7 +54,7 @@ namespace dxvk { public: DxbcAnalyzer( - const DxbcOptions& options, + const DxbcModuleInfo& moduleInfo, const DxbcProgramVersion& version, const Rc& isgn, const Rc& osgn, diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 80d7d2fd..91858662 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -10,16 +10,16 @@ namespace dxvk { DxbcCompiler::DxbcCompiler( const std::string& fileName, - const DxbcOptions& options, + const DxbcModuleInfo& moduleInfo, const DxbcProgramVersion& version, const Rc& isgn, const Rc& osgn, const DxbcAnalysisInfo& analysis) - : m_options (options), - m_version (version), - m_isgn (isgn), - m_osgn (osgn), - m_analysis(&analysis) { + : m_moduleInfo(moduleInfo), + m_version (version), + m_isgn (isgn), + m_osgn (osgn), + m_analysis (&analysis) { // Declare an entry point ID. We'll need it during the // initialization phase where the execution mode is set. m_entryPointId = m_module.allocateId(); @@ -791,7 +791,7 @@ namespace dxvk { const bool isUav = ins.op == DxbcOpcode::DclUavTyped; if (isUav) { - if (m_options.test(DxbcOption::UseStorageImageReadWithoutFormat)) + if (m_moduleInfo.options.test(DxbcOption::UseStorageImageReadWithoutFormat)) m_module.enableCapability(spv::CapabilityStorageImageReadWithoutFormat); m_module.enableCapability(spv::CapabilityStorageImageWriteWithoutFormat); } @@ -852,7 +852,7 @@ namespace dxvk { if (isUav) { if ((m_analysis->uavInfos[registerId].accessAtomicOp) || (m_analysis->uavInfos[registerId].accessTypedLoad - && !m_options.test(DxbcOption::UseStorageImageReadWithoutFormat))) + && !m_moduleInfo.options.test(DxbcOption::UseStorageImageReadWithoutFormat))) imageFormat = getScalarImageFormat(sampledType); } @@ -5834,7 +5834,7 @@ namespace dxvk { // We may have to defer kill operations to the end of // the shader in order to keep derivatives correct. - if (m_analysis->usesKill && m_analysis->usesDerivatives && m_options.test(DxbcOption::DeferKill)) { + if (m_analysis->usesKill && m_analysis->usesDerivatives && m_moduleInfo.options.test(DxbcOption::DeferKill)) { m_ps.killState = m_module.newVarInit( m_module.defPointerType(m_module.defBoolType(), spv::StorageClassPrivate), spv::StorageClassPrivate, m_module.constBool(false)); diff --git a/src/dxbc/dxbc_compiler.h b/src/dxbc/dxbc_compiler.h index 5fb150f9..7cc678da 100644 --- a/src/dxbc/dxbc_compiler.h +++ b/src/dxbc/dxbc_compiler.h @@ -9,8 +9,8 @@ #include "dxbc_chunk_isgn.h" #include "dxbc_decoder.h" #include "dxbc_defs.h" +#include "dxbc_modinfo.h" #include "dxbc_names.h" -#include "dxbc_options.h" #include "dxbc_util.h" namespace dxvk { @@ -354,7 +354,7 @@ namespace dxvk { DxbcCompiler( const std::string& fileName, - const DxbcOptions& options, + const DxbcModuleInfo& moduleInfo, const DxbcProgramVersion& version, const Rc& isgn, const Rc& osgn, @@ -376,7 +376,7 @@ namespace dxvk { private: - DxbcOptions m_options; + DxbcModuleInfo m_moduleInfo; DxbcProgramVersion m_version; SpirvModule m_module; diff --git a/src/dxbc/dxbc_modinfo.h b/src/dxbc/dxbc_modinfo.h new file mode 100644 index 00000000..a82fe50b --- /dev/null +++ b/src/dxbc/dxbc_modinfo.h @@ -0,0 +1,17 @@ +#pragma once + +#include "dxbc_options.h" + +namespace dxvk { + + /** + * \brief Shader module info + * + * Stores information which may affect shader compilation. + * This data can be supplied by the client API implementation. + */ + struct DxbcModuleInfo { + DxbcOptions options; + }; + +} \ No newline at end of file diff --git a/src/dxbc/dxbc_module.cpp b/src/dxbc/dxbc_module.cpp index 4ac55266..6b51227a 100644 --- a/src/dxbc/dxbc_module.cpp +++ b/src/dxbc/dxbc_module.cpp @@ -42,14 +42,14 @@ namespace dxvk { Rc DxbcModule::compile( - const DxbcOptions& options, - const std::string& fileName) const { + const DxbcModuleInfo& moduleInfo, + const std::string& fileName) const { if (m_shexChunk == nullptr) throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk"); DxbcAnalysisInfo analysisInfo; - DxbcAnalyzer analyzer(options, + DxbcAnalyzer analyzer(moduleInfo, m_shexChunk->version(), m_isgnChunk, m_osgnChunk, analysisInfo); @@ -57,7 +57,7 @@ namespace dxvk { this->runAnalyzer(analyzer, m_shexChunk->slice()); DxbcCompiler compiler( - fileName, options, + fileName, moduleInfo, m_shexChunk->version(), m_isgnChunk, m_osgnChunk, analysisInfo); diff --git a/src/dxbc/dxbc_module.h b/src/dxbc/dxbc_module.h index 1c3bfa30..2fd15800 100644 --- a/src/dxbc/dxbc_module.h +++ b/src/dxbc/dxbc_module.h @@ -5,7 +5,7 @@ #include "dxbc_chunk_isgn.h" #include "dxbc_chunk_shex.h" #include "dxbc_header.h" -#include "dxbc_options.h" +#include "dxbc_modinfo.h" #include "dxbc_reader.h" // References used for figuring out DXBC: @@ -51,14 +51,14 @@ namespace dxvk { /** * \brief Compiles DXBC shader to SPIR-V module * - * \param [in] options DXBC compiler options + * \param [in] moduleInfo DXBC module info * \param [in] fileName File name, will be added to * the compiled SPIR-V for debugging purposes. * \returns The compiled shader object */ Rc compile( - const DxbcOptions& options, - const std::string& fileName) const; + const DxbcModuleInfo& moduleInfo, + const std::string& fileName) const; private: