1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 10:54:16 +01:00

[dxbc] Implemented temporary register declarations

This commit is contained in:
Philip Rebohle 2017-10-26 16:32:10 +02:00
parent 200da4cf60
commit f5ad024f5d
5 changed files with 73 additions and 8 deletions

View File

@ -8,6 +8,13 @@ namespace dxvk {
this->declareCapabilities();
this->declareMemoryModel();
m_typeVoid = m_module.defVoidType();
m_typeFunction = m_module.defFunctionType(m_typeVoid, 0, nullptr);
m_module.functionBegin(m_typeVoid,
m_entryPointId, m_typeFunction,
spv::FunctionControlMaskNone);
}
@ -20,12 +27,16 @@ namespace dxvk {
const DxbcOpcodeToken token = ins.token();
switch (token.opcode()) {
case DxbcOpcode::DclTemps: {
this->dclTemps(ins.arg(0));
} return true;
case DxbcOpcode::DclThreadGroup: {
m_module.setLocalSize(
m_entryPointId,
ins.getArgWord(0),
ins.getArgWord(1),
ins.getArgWord(2));
ins.arg(0),
ins.arg(1),
ins.arg(2));
} return true;
default:
@ -37,6 +48,8 @@ namespace dxvk {
Rc<DxvkShader> DxbcCompiler::finalize() {
m_module.functionEnd();
return new DxvkShader(m_version.shaderStage(),
m_module.compile(), 0, nullptr);
}
@ -67,4 +80,22 @@ namespace dxvk {
spv::MemoryModelGLSL450);
}
void DxbcCompiler::dclTemps(uint32_t n) {
// Temporaries are treated as untyped 4x32-bit vectors.
uint32_t u32Type = m_module.defIntType(32, 0);
uint32_t regType = m_module.defVectorType(u32Type, 4);
uint32_t ptrType = m_module.defPointerType(regType, spv::StorageClassPrivate);
for (uint32_t i = 0; i < n; i++) {
DxbcRegTypeR reg;
reg.varType = regType;
reg.ptrType = ptrType;
reg.varId = m_module.newVar(ptrType, spv::StorageClassPrivate);
m_rRegs.push_back(reg);
m_module.setDebugName(reg.varId,
str::format("r", i).c_str());
}
}
}

View File

@ -6,6 +6,12 @@
namespace dxvk {
struct DxbcRegTypeR {
uint32_t varType;
uint32_t ptrType;
uint32_t varId;
};
/**
* \brief DXBC to SPIR-V compiler
*
@ -43,11 +49,18 @@ namespace dxvk {
DxbcProgramVersion m_version;
SpirvModule m_module;
std::vector<DxbcRegTypeR> m_rRegs;
uint32_t m_entryPointId = 0;
uint32_t m_typeVoid = 0;
uint32_t m_typeFunction = 0;
void declareCapabilities();
void declareMemoryModel();
void dclTemps(uint32_t n);
};
}

View File

@ -415,7 +415,7 @@ namespace dxvk {
* \param [in] idx Argument word index
* \returns The word at the given index
*/
uint32_t getArgWord(uint32_t idx) const {
uint32_t arg(uint32_t idx) const {
return m_args.getWord(idx);
}
@ -425,7 +425,7 @@ namespace dxvk {
* \param [in] idx Argument word index
* \returns The operand object
*/
DxbcOperand getOperand(uint32_t idx) const {
DxbcOperand operand(uint32_t idx) const {
return DxbcOperand(m_args + idx);
}

View File

@ -55,7 +55,9 @@ namespace dxvk {
void SpirvModule::setMemoryModel(
spv::AddressingModel addressModel,
spv::MemoryModel memoryModel) {
m_memoryModel.putIns (spv::OpMemoryModel, 3);
m_memoryModel.putWord (addressModel);
m_memoryModel.putWord (memoryModel);
}
@ -77,7 +79,9 @@ namespace dxvk {
void SpirvModule::setDebugName(
uint32_t expressionId,
const char* debugName) {
m_debugNames.putIns (spv::OpName, 2 + m_debugNames.strLen(debugName));
m_debugNames.putWord(expressionId);
m_debugNames.putStr (debugName);
}
@ -286,8 +290,8 @@ namespace dxvk {
uint32_t variableType,
spv::StorageClass storageClass) {
std::array<uint32_t, 2> args = {
variableType,
storageClass,
variableType,
};
return this->defType(spv::OpTypePointer,
@ -295,6 +299,19 @@ namespace dxvk {
}
uint32_t SpirvModule::newVar(
uint32_t pointerType,
spv::StorageClass storageClass) {
uint32_t resultId = this->allocateId();
m_variables.putIns (spv::OpVariable, 4);
m_variables.putWord (pointerType);
m_variables.putWord (resultId);
m_variables.putWord (storageClass);
return resultId;
}
void SpirvModule::functionBegin(
uint32_t returnType,
uint32_t functionId,

View File

@ -115,6 +115,10 @@ namespace dxvk {
uint32_t variableType,
spv::StorageClass storageClass);
uint32_t newVar(
uint32_t pointerType,
spv::StorageClass storageClass);
void functionBegin(
uint32_t returnType,
uint32_t functionId,