1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-11 10:24:10 +01:00

[dxbc] Add DxbcModuleInfo struct

This will be required in the future to pass data from the
application to the shader compiler.
This commit is contained in:
Philip Rebohle 2018-06-23 17:14:35 +02:00
parent 5d1f00be34
commit 102591369e
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
11 changed files with 79 additions and 48 deletions

View File

@ -1073,16 +1073,18 @@ namespace dxvk {
InitReturnPtr(ppVertexShader); InitReturnPtr(ppVertexShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::VertexShader))) &moduleInfo, DxbcProgramType::VertexShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppVertexShader == nullptr) if (ppVertexShader == nullptr)
return S_FALSE; return S_FALSE;
*ppVertexShader = ref(new D3D11VertexShader( *ppVertexShader = ref(new D3D11VertexShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1095,16 +1097,18 @@ namespace dxvk {
InitReturnPtr(ppGeometryShader); InitReturnPtr(ppGeometryShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::GeometryShader))) &moduleInfo, DxbcProgramType::GeometryShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppGeometryShader == nullptr) if (ppGeometryShader == nullptr)
return S_FALSE; return S_FALSE;
*ppGeometryShader = ref(new D3D11GeometryShader( *ppGeometryShader = ref(new D3D11GeometryShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1136,16 +1140,18 @@ namespace dxvk {
InitReturnPtr(ppPixelShader); InitReturnPtr(ppPixelShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::PixelShader))) &moduleInfo, DxbcProgramType::PixelShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppPixelShader == nullptr) if (ppPixelShader == nullptr)
return S_FALSE; return S_FALSE;
*ppPixelShader = ref(new D3D11PixelShader( *ppPixelShader = ref(new D3D11PixelShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1158,16 +1164,18 @@ namespace dxvk {
InitReturnPtr(ppHullShader); InitReturnPtr(ppHullShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::HullShader))) &moduleInfo, DxbcProgramType::HullShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppHullShader == nullptr) if (ppHullShader == nullptr)
return S_FALSE; return S_FALSE;
*ppHullShader = ref(new D3D11HullShader( *ppHullShader = ref(new D3D11HullShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1180,16 +1188,18 @@ namespace dxvk {
InitReturnPtr(ppDomainShader); InitReturnPtr(ppDomainShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::DomainShader))) &moduleInfo, DxbcProgramType::DomainShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppDomainShader == nullptr) if (ppDomainShader == nullptr)
return S_FALSE; return S_FALSE;
*ppDomainShader = ref(new D3D11DomainShader( *ppDomainShader = ref(new D3D11DomainShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1202,16 +1212,18 @@ namespace dxvk {
InitReturnPtr(ppComputeShader); InitReturnPtr(ppComputeShader);
D3D11ShaderModule module; D3D11ShaderModule module;
DxbcModuleInfo moduleInfo;
moduleInfo.options = m_dxbcOptions;
if (FAILED(this->CreateShaderModule(&module, if (FAILED(this->CreateShaderModule(&module,
pShaderBytecode, BytecodeLength, pClassLinkage, pShaderBytecode, BytecodeLength, pClassLinkage,
DxbcProgramType::ComputeShader))) &moduleInfo, DxbcProgramType::ComputeShader)))
return E_INVALIDARG; return E_INVALIDARG;
if (ppComputeShader == nullptr) if (ppComputeShader == nullptr)
return S_FALSE; return S_FALSE;
*ppComputeShader = ref(new D3D11ComputeShader( *ppComputeShader = ref(new D3D11ComputeShader(this, module));
this, module));
return S_OK; return S_OK;
} }
@ -1838,13 +1850,14 @@ namespace dxvk {
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength, size_t BytecodeLength,
ID3D11ClassLinkage* pClassLinkage, ID3D11ClassLinkage* pClassLinkage,
const DxbcModuleInfo* pModuleInfo,
DxbcProgramType ProgramType) { DxbcProgramType ProgramType) {
if (pClassLinkage != nullptr) if (pClassLinkage != nullptr)
Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported"); Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported");
try { try {
*pShaderModule = m_shaderModules.GetShaderModule( *pShaderModule = m_shaderModules.GetShaderModule(
&m_dxbcOptions, pShaderBytecode, BytecodeLength, ProgramType); pModuleInfo, pShaderBytecode, BytecodeLength, ProgramType);
return S_OK; return S_OK;
} catch (const DxvkError& e) { } catch (const DxvkError& e) {
Logger::err(e.message()); Logger::err(e.message());

View File

@ -374,6 +374,7 @@ namespace dxvk {
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength, size_t BytecodeLength,
ID3D11ClassLinkage* pClassLinkage, ID3D11ClassLinkage* pClassLinkage,
const DxbcModuleInfo* pModuleInfo,
DxbcProgramType ProgramType); DxbcProgramType ProgramType);
void InitBuffer( void InitBuffer(

View File

@ -40,7 +40,7 @@ namespace dxvk {
D3D11ShaderModule::D3D11ShaderModule( D3D11ShaderModule::D3D11ShaderModule(
const D3D11ShaderKey* pShaderKey, const D3D11ShaderKey* pShaderKey,
const DxbcOptions* pDxbcOptions, const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength) size_t BytecodeLength)
: m_name(pShaderKey->GetName()) { : m_name(pShaderKey->GetName()) {
@ -62,7 +62,7 @@ namespace dxvk {
std::ios_base::binary | std::ios_base::trunc)); 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); m_shader->setDebugName(m_name);
if (dumpPath.size() != 0) { if (dumpPath.size() != 0) {
@ -92,7 +92,7 @@ namespace dxvk {
D3D11ShaderModule D3D11ShaderModuleSet::GetShaderModule( D3D11ShaderModule D3D11ShaderModuleSet::GetShaderModule(
const DxbcOptions* pDxbcOptions, const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength, size_t BytecodeLength,
DxbcProgramType ProgramType) { DxbcProgramType ProgramType) {
@ -108,7 +108,7 @@ namespace dxvk {
// 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.
D3D11ShaderModule module(&key, pDxbcOptions, pShaderBytecode, BytecodeLength); D3D11ShaderModule module(&key, pDxbcModuleInfo, pShaderBytecode, BytecodeLength);
// 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

View File

@ -70,7 +70,7 @@ namespace dxvk {
D3D11ShaderModule(); D3D11ShaderModule();
D3D11ShaderModule( D3D11ShaderModule(
const D3D11ShaderKey* pShaderKey, const D3D11ShaderKey* pShaderKey,
const DxbcOptions* pDxbcOptions, const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength); size_t BytecodeLength);
~D3D11ShaderModule(); ~D3D11ShaderModule();
@ -165,7 +165,7 @@ namespace dxvk {
~D3D11ShaderModuleSet(); ~D3D11ShaderModuleSet();
D3D11ShaderModule GetShaderModule( D3D11ShaderModule GetShaderModule(
const DxbcOptions* pDxbcOptions, const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode, const void* pShaderBytecode,
size_t BytecodeLength, size_t BytecodeLength,
DxbcProgramType ProgramType); DxbcProgramType ProgramType);

View File

@ -3,7 +3,7 @@
namespace dxvk { namespace dxvk {
DxbcAnalyzer::DxbcAnalyzer( DxbcAnalyzer::DxbcAnalyzer(
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const DxbcProgramVersion& version, const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn, const Rc<DxbcIsgn>& isgn,
const Rc<DxbcIsgn>& osgn, const Rc<DxbcIsgn>& osgn,

View File

@ -4,7 +4,7 @@
#include "dxbc_decoder.h" #include "dxbc_decoder.h"
#include "dxbc_defs.h" #include "dxbc_defs.h"
#include "dxbc_names.h" #include "dxbc_names.h"
#include "dxbc_options.h" #include "dxbc_modinfo.h"
#include "dxbc_util.h" #include "dxbc_util.h"
namespace dxvk { namespace dxvk {
@ -54,7 +54,7 @@ namespace dxvk {
public: public:
DxbcAnalyzer( DxbcAnalyzer(
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const DxbcProgramVersion& version, const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn, const Rc<DxbcIsgn>& isgn,
const Rc<DxbcIsgn>& osgn, const Rc<DxbcIsgn>& osgn,

View File

@ -10,16 +10,16 @@ namespace dxvk {
DxbcCompiler::DxbcCompiler( DxbcCompiler::DxbcCompiler(
const std::string& fileName, const std::string& fileName,
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const DxbcProgramVersion& version, const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn, const Rc<DxbcIsgn>& isgn,
const Rc<DxbcIsgn>& osgn, const Rc<DxbcIsgn>& osgn,
const DxbcAnalysisInfo& analysis) const DxbcAnalysisInfo& analysis)
: m_options (options), : m_moduleInfo(moduleInfo),
m_version (version), m_version (version),
m_isgn (isgn), m_isgn (isgn),
m_osgn (osgn), m_osgn (osgn),
m_analysis(&analysis) { m_analysis (&analysis) {
// Declare an entry point ID. We'll need it during the // Declare an entry point ID. We'll need it during the
// initialization phase where the execution mode is set. // initialization phase where the execution mode is set.
m_entryPointId = m_module.allocateId(); m_entryPointId = m_module.allocateId();
@ -791,7 +791,7 @@ namespace dxvk {
const bool isUav = ins.op == DxbcOpcode::DclUavTyped; const bool isUav = ins.op == DxbcOpcode::DclUavTyped;
if (isUav) { if (isUav) {
if (m_options.test(DxbcOption::UseStorageImageReadWithoutFormat)) if (m_moduleInfo.options.test(DxbcOption::UseStorageImageReadWithoutFormat))
m_module.enableCapability(spv::CapabilityStorageImageReadWithoutFormat); m_module.enableCapability(spv::CapabilityStorageImageReadWithoutFormat);
m_module.enableCapability(spv::CapabilityStorageImageWriteWithoutFormat); m_module.enableCapability(spv::CapabilityStorageImageWriteWithoutFormat);
} }
@ -852,7 +852,7 @@ namespace dxvk {
if (isUav) { if (isUav) {
if ((m_analysis->uavInfos[registerId].accessAtomicOp) if ((m_analysis->uavInfos[registerId].accessAtomicOp)
|| (m_analysis->uavInfos[registerId].accessTypedLoad || (m_analysis->uavInfos[registerId].accessTypedLoad
&& !m_options.test(DxbcOption::UseStorageImageReadWithoutFormat))) && !m_moduleInfo.options.test(DxbcOption::UseStorageImageReadWithoutFormat)))
imageFormat = getScalarImageFormat(sampledType); imageFormat = getScalarImageFormat(sampledType);
} }
@ -5834,7 +5834,7 @@ namespace dxvk {
// We may have to defer kill operations to the end of // We may have to defer kill operations to the end of
// the shader in order to keep derivatives correct. // 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_ps.killState = m_module.newVarInit(
m_module.defPointerType(m_module.defBoolType(), spv::StorageClassPrivate), m_module.defPointerType(m_module.defBoolType(), spv::StorageClassPrivate),
spv::StorageClassPrivate, m_module.constBool(false)); spv::StorageClassPrivate, m_module.constBool(false));

View File

@ -9,8 +9,8 @@
#include "dxbc_chunk_isgn.h" #include "dxbc_chunk_isgn.h"
#include "dxbc_decoder.h" #include "dxbc_decoder.h"
#include "dxbc_defs.h" #include "dxbc_defs.h"
#include "dxbc_modinfo.h"
#include "dxbc_names.h" #include "dxbc_names.h"
#include "dxbc_options.h"
#include "dxbc_util.h" #include "dxbc_util.h"
namespace dxvk { namespace dxvk {
@ -354,7 +354,7 @@ namespace dxvk {
DxbcCompiler( DxbcCompiler(
const std::string& fileName, const std::string& fileName,
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const DxbcProgramVersion& version, const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn, const Rc<DxbcIsgn>& isgn,
const Rc<DxbcIsgn>& osgn, const Rc<DxbcIsgn>& osgn,
@ -376,7 +376,7 @@ namespace dxvk {
private: private:
DxbcOptions m_options; DxbcModuleInfo m_moduleInfo;
DxbcProgramVersion m_version; DxbcProgramVersion m_version;
SpirvModule m_module; SpirvModule m_module;

17
src/dxbc/dxbc_modinfo.h Normal file
View File

@ -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;
};
}

View File

@ -42,14 +42,14 @@ namespace dxvk {
Rc<DxvkShader> DxbcModule::compile( Rc<DxvkShader> DxbcModule::compile(
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const std::string& fileName) const { const std::string& fileName) const {
if (m_shexChunk == nullptr) if (m_shexChunk == nullptr)
throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk"); throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk");
DxbcAnalysisInfo analysisInfo; DxbcAnalysisInfo analysisInfo;
DxbcAnalyzer analyzer(options, DxbcAnalyzer analyzer(moduleInfo,
m_shexChunk->version(), m_shexChunk->version(),
m_isgnChunk, m_osgnChunk, m_isgnChunk, m_osgnChunk,
analysisInfo); analysisInfo);
@ -57,7 +57,7 @@ namespace dxvk {
this->runAnalyzer(analyzer, m_shexChunk->slice()); this->runAnalyzer(analyzer, m_shexChunk->slice());
DxbcCompiler compiler( DxbcCompiler compiler(
fileName, options, fileName, moduleInfo,
m_shexChunk->version(), m_shexChunk->version(),
m_isgnChunk, m_osgnChunk, m_isgnChunk, m_osgnChunk,
analysisInfo); analysisInfo);

View File

@ -5,7 +5,7 @@
#include "dxbc_chunk_isgn.h" #include "dxbc_chunk_isgn.h"
#include "dxbc_chunk_shex.h" #include "dxbc_chunk_shex.h"
#include "dxbc_header.h" #include "dxbc_header.h"
#include "dxbc_options.h" #include "dxbc_modinfo.h"
#include "dxbc_reader.h" #include "dxbc_reader.h"
// References used for figuring out DXBC: // References used for figuring out DXBC:
@ -51,13 +51,13 @@ namespace dxvk {
/** /**
* \brief Compiles DXBC shader to SPIR-V module * \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 * \param [in] fileName File name, will be added to
* the compiled SPIR-V for debugging purposes. * the compiled SPIR-V for debugging purposes.
* \returns The compiled shader object * \returns The compiled shader object
*/ */
Rc<DxvkShader> compile( Rc<DxvkShader> compile(
const DxbcOptions& options, const DxbcModuleInfo& moduleInfo,
const std::string& fileName) const; const std::string& fileName) const;
private: private: