diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 9e48f048a..e8c28b6f7 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -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 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()); + } + } + } \ No newline at end of file diff --git a/src/dxbc/dxbc_compiler.h b/src/dxbc/dxbc_compiler.h index 91d39e810..3500491c4 100644 --- a/src/dxbc/dxbc_compiler.h +++ b/src/dxbc/dxbc_compiler.h @@ -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 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); + }; } \ No newline at end of file diff --git a/src/dxbc/dxbc_decoder.h b/src/dxbc/dxbc_decoder.h index 762019065..909fc325f 100644 --- a/src/dxbc/dxbc_decoder.h +++ b/src/dxbc/dxbc_decoder.h @@ -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); } diff --git a/src/spirv/spirv_module.cpp b/src/spirv/spirv_module.cpp index 388eaae07..5cb9b14df 100644 --- a/src/spirv/spirv_module.cpp +++ b/src/spirv/spirv_module.cpp @@ -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 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, diff --git a/src/spirv/spirv_module.h b/src/spirv/spirv_module.h index 4a3376332..446dfafb5 100644 --- a/src/spirv/spirv_module.h +++ b/src/spirv/spirv_module.h @@ -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,