[dxbc] Implemented user-defined shader interface

This commit is contained in:
Philip Rebohle 2017-12-08 12:59:08 +01:00
parent 26dc8e2dd8
commit e3533fb634
4 changed files with 74 additions and 2 deletions

View File

@ -19,6 +19,19 @@ namespace dxvk {
spv::FunctionControlMaskNone);
m_module.opLabel(m_module.allocateId());
// Declare user input block
m_psIn = m_module.newVar(
m_module.defPointerType(
m_module.defArrayType(
m_module.defVectorType(
m_module.defFloatType(32), 4),
m_module.constu32(32)),
spv::StorageClassInput),
spv::StorageClassInput);
m_entryPointInterfaces.push_back(m_psIn);
m_module.decorateLocation(m_psIn, 0);
m_module.setDebugName(m_psIn, "ps_in");
// Declare outputs based on the input signature
for (auto e = osgn->begin(); e != osgn->end(); e++) {
if (e->systemValue == DxbcSystemValue::None) {
@ -154,7 +167,14 @@ namespace dxvk {
void DxbcPsCodeGen::prepareSvInputs() {
for (uint32_t i = 0; i < m_vRegs.size(); i++) {
if (m_vRegs.at(i).valueId != 0) {
this->regStore(
m_vRegs.at(i),
this->regLoad(this->getPsInPtr(i)),
DxbcComponentMask(true, true, true, true));
}
}
}
@ -172,4 +192,18 @@ namespace dxvk {
}
}
DxbcPointer DxbcPsCodeGen::getPsInPtr(uint32_t id) {
const uint32_t memberId = m_module.constu32(id);
DxbcPointer result;
result.type = DxbcPointerType(
DxbcValueType(DxbcScalarType::Float32, 4),
spv::StorageClassInput);
result.valueId = m_module.opAccessChain(
this->defPointerType(result.type),
m_psIn, 1, &memberId);
return result;
}
}

View File

@ -49,6 +49,8 @@ namespace dxvk {
void prepareSvInputs();
void prepareSvOutputs();
DxbcPointer getPsInPtr(uint32_t id);
};
}

View File

@ -25,6 +25,19 @@ namespace dxvk {
m_entryPointInterfaces.push_back(m_vsPerVertex);
m_module.setDebugName(m_vsPerVertex, "vs_per_vertex");
// Declare per-vertex user output block
m_vsOut = m_module.newVar(
m_module.defPointerType(
m_module.defArrayType(
m_module.defVectorType(
m_module.defFloatType(32), 4),
m_module.constu32(32)),
spv::StorageClassOutput),
spv::StorageClassOutput);
m_entryPointInterfaces.push_back(m_vsOut);
m_module.decorateLocation(m_vsOut, 0);
m_module.setDebugName(m_vsOut, "vs_out");
// Declare vertex inputs based on the input signature
for (auto e = isgn->begin(); e != isgn->end(); e++) {
if (e->systemValue == DxbcSystemValue::None) {
@ -172,7 +185,14 @@ namespace dxvk {
void DxbcVsCodeGen::prepareSvOutputs() {
// TODO add user-defined shader outputs
for (uint32_t i = 0; i < m_oRegs.size(); i++) {
if (m_oRegs.at(i).valueId != 0) {
this->regStore(
this->getVsOutPtr(i),
this->regLoad(m_oRegs.at(i)),
DxbcComponentMask(true, true, true, true));
}
}
for (const auto& mapping : m_svOut) {
DxbcValue srcValue = this->regLoad(m_oRegs.at(mapping.regId));
@ -200,4 +220,18 @@ namespace dxvk {
return result;
}
DxbcPointer DxbcVsCodeGen::getVsOutPtr(uint32_t id) {
const uint32_t memberId = m_module.constu32(id);
DxbcPointer result;
result.type = DxbcPointerType(
DxbcValueType(DxbcScalarType::Float32, 4),
spv::StorageClassOutput);
result.valueId = m_module.opAccessChain(
this->defPointerType(result.type),
m_vsOut, 1, &memberId);
return result;
}
}

View File

@ -53,6 +53,8 @@ namespace dxvk {
DxbcPointer ptrBuiltInPosition();
DxbcPointer getVsOutPtr(uint32_t id);
};
}