1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-08 10:46:09 +01:00
dxvk/src/dxbc/dxbc_compiler.cpp

81 lines
2.0 KiB
C++
Raw Normal View History

#include "dxbc_compiler.h"
namespace dxvk {
DxbcCompiler::DxbcCompiler(DxbcProgramVersion version)
: m_version(version) {
m_entryPointId = m_counter.nextId();
this->declareCapabilities();
this->declareMemoryModel();
}
DxbcCompiler::~DxbcCompiler() {
}
2017-10-25 13:49:13 +02:00
bool DxbcCompiler::processInstruction(const DxbcInstruction& ins) {
const DxbcOpcodeToken token = ins.token();
2017-10-22 23:13:29 +02:00
2017-10-25 13:49:13 +02:00
switch (token.opcode()) {
case DxbcOpcode::DclThreadGroup: {
m_spvEntryPoints.setLocalSize(
m_entryPointId,
ins.getArgWord(0),
ins.getArgWord(1),
ins.getArgWord(2));
} return true;
default:
Logger::err(str::format("DXBC: unhandled instruction: ",
static_cast<uint32_t>(token.opcode())));
return false;
}
}
Rc<DxvkShader> DxbcCompiler::finalize() {
SpirvCodeBuffer codeBuffer;
codeBuffer.putHeader(m_counter.numIds());
2017-10-17 13:02:57 +02:00
codeBuffer.append(m_spvCapabilities.code());
codeBuffer.append(m_spvEntryPoints.code());
2017-10-25 13:49:13 +02:00
codeBuffer.append(m_spvDebugInfo.code());
codeBuffer.append(m_spvDecorations.code());
2017-10-17 13:02:57 +02:00
codeBuffer.append(m_spvTypeInfo.code());
2017-10-25 13:49:13 +02:00
codeBuffer.append(m_spvConstants.code());
codeBuffer.append(m_spvVariables.code());
2017-10-17 13:02:57 +02:00
codeBuffer.append(m_spvCode);
2017-10-17 13:02:57 +02:00
return new DxvkShader(m_version.shaderStage(),
std::move(codeBuffer), 0, nullptr);
}
void DxbcCompiler::declareCapabilities() {
m_spvCapabilities.enable(spv::CapabilityShader);
switch (m_version.type()) {
case DxbcProgramType::GeometryShader:
m_spvCapabilities.enable(spv::CapabilityGeometry);
break;
case DxbcProgramType::HullShader:
case DxbcProgramType::DomainShader:
m_spvCapabilities.enable(spv::CapabilityTessellation);
break;
default:
break;
}
}
void DxbcCompiler::declareMemoryModel() {
m_spvEntryPoints.setMemoryModel(
spv::AddressingModelLogical,
spv::MemoryModelGLSL450);
}
}