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

[dxbc] Implemented Hull shader function declarations

This commit is contained in:
Philip Rebohle 2018-03-01 09:26:17 +01:00
parent d0db88ee62
commit d185977918
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
5 changed files with 92 additions and 5 deletions

View File

@ -85,6 +85,9 @@ namespace dxvk {
case DxbcInstClass::GeometryEmit: case DxbcInstClass::GeometryEmit:
return this->emitGeometryEmit(ins); return this->emitGeometryEmit(ins);
case DxbcInstClass::HullShaderPhase:
return this->emitHullShaderPhase(ins);
case DxbcInstClass::Interpolate: case DxbcInstClass::Interpolate:
return this->emitInterpolate(ins); return this->emitInterpolate(ins);
@ -477,6 +480,12 @@ namespace dxvk {
"oDepthLe"); "oDepthLe");
} break; } break;
case DxbcOperandType::InputForkInstanceId:
case DxbcOperandType::InputJoinInstanceId: {
// Nothing to do here, as these are part of the
// function signature for the fork and join phases.
} break;
default: default:
Logger::err(str::format( Logger::err(str::format(
"DxbcCompiler: Unsupported operand type declaration: ", "DxbcCompiler: Unsupported operand type declaration: ",
@ -2258,6 +2267,45 @@ namespace dxvk {
} }
void DxbcCompiler::emitHullShaderPhase(const DxbcShaderInstruction& ins) {
switch (ins.op) {
case DxbcOpcode::HsDecls: {
if (m_hs.currPhaseType != DxbcCompilerHsPhase::None)
Logger::err("DXBC: HsDecls not the first phase in hull shader");
m_hs.currPhaseType = DxbcCompilerHsPhase::Decl;
} break;
case DxbcOpcode::HsForkPhase: {
auto phase = this->emitNewHullShaderForkJoinPhase();
m_hs.forkPhases.push_back(phase);
m_hs.currPhaseType = DxbcCompilerHsPhase::Fork;
m_hs.currPhaseId = m_hs.forkPhases.size() - 1;
m_module.setDebugName(phase.functionId,
str::format("hs_fork_", m_hs.currPhaseId).c_str());
} break;
case DxbcOpcode::HsJoinPhase: {
auto phase = this->emitNewHullShaderForkJoinPhase();
m_hs.joinPhases.push_back(phase);
m_hs.currPhaseType = DxbcCompilerHsPhase::Join;
m_hs.currPhaseId = m_hs.joinPhases.size() - 1;
m_module.setDebugName(phase.functionId,
str::format("hs_join_", m_hs.currPhaseId).c_str());
} break;
default:
Logger::warn(str::format(
"DxbcCompiler: Unhandled instruction: ",
ins.op));
}
}
void DxbcCompiler::emitInterpolate(const DxbcShaderInstruction& ins) { void DxbcCompiler::emitInterpolate(const DxbcShaderInstruction& ins) {
// The SPIR-V instructions operate on input variable pointers, // The SPIR-V instructions operate on input variable pointers,
// which are all declared as four-component float vectors. // which are all declared as four-component float vectors.
@ -3880,6 +3928,16 @@ namespace dxvk {
return DxbcRegisterPointer { return DxbcRegisterPointer {
{ DxbcScalarType::Float32, 1 }, { DxbcScalarType::Float32, 1 },
m_ps.builtinDepth }; m_ps.builtinDepth };
case DxbcOperandType::InputForkInstanceId:
return DxbcRegisterPointer {
{ DxbcScalarType::Uint32, 1 },
m_hs.forkPhases.at(m_hs.currPhaseId).builtinInstanceId };
case DxbcOperandType::InputJoinInstanceId:
return DxbcRegisterPointer {
{ DxbcScalarType::Uint32, 1 },
m_hs.joinPhases.at(m_hs.currPhaseId).builtinInstanceId };
default: default:
throw DxvkError(str::format( throw DxvkError(str::format(
@ -5021,6 +5079,28 @@ namespace dxvk {
} }
DxbcCompilerHsForkJoinPhase DxbcCompiler::emitNewHullShaderForkJoinPhase() {
uint32_t argTypeId = m_module.defPointerType(
m_module.defIntType(32, 0),
spv::StorageClassFunction);
uint32_t funTypeId = m_module.defFunctionType(
m_module.defVoidType(), 1, &argTypeId);
uint32_t funId = m_module.allocateId();
m_module.functionBegin(m_module.defVoidType(),
funId, funTypeId, spv::FunctionControlMaskNone);
uint32_t argId = m_module.functionParameter(argTypeId);
m_module.opLabel(m_module.allocateId());
DxbcCompilerHsForkJoinPhase result;
result.functionId = funId;
result.builtinInstanceId = argId;
return result;
}
uint32_t DxbcCompiler::emitNewVariable(const DxbcRegisterInfo& info) { uint32_t DxbcCompiler::emitNewVariable(const DxbcRegisterInfo& info) {
const uint32_t ptrTypeId = this->getPointerTypeId(info); const uint32_t ptrTypeId = this->getPointerTypeId(info);
return m_module.newVar(ptrTypeId, info.sclass); return m_module.newVar(ptrTypeId, info.sclass);

View File

@ -527,6 +527,9 @@ namespace dxvk {
void emitConvertFloat16( void emitConvertFloat16(
const DxbcShaderInstruction& ins); const DxbcShaderInstruction& ins);
void emitHullShaderPhase(
const DxbcShaderInstruction& ins);
void emitInterpolate( void emitInterpolate(
const DxbcShaderInstruction& ins); const DxbcShaderInstruction& ins);
@ -833,6 +836,8 @@ namespace dxvk {
uint32_t vertexCount, uint32_t vertexCount,
const char* varName); const char* varName);
DxbcCompilerHsForkJoinPhase emitNewHullShaderForkJoinPhase();
/////////////////////////////// ///////////////////////////////
// Variable definition methods // Variable definition methods
uint32_t emitNewVariable( uint32_t emitNewVariable(

View File

@ -562,13 +562,13 @@ namespace dxvk {
/* Reserved1 */ /* Reserved1 */
{ }, { },
/* HsDecls */ /* HsDecls */
{ }, { 0, DxbcInstClass::HullShaderPhase },
/* HsControlPointPhase */ /* HsControlPointPhase */
{ }, { 0, DxbcInstClass::HullShaderPhase },
/* HsForkPhase */ /* HsForkPhase */
{ }, { 0, DxbcInstClass::HullShaderPhase },
/* HsJoinPhase */ /* HsJoinPhase */
{ }, { 0, DxbcInstClass::HullShaderPhase },
/* EmitStream */ /* EmitStream */
{ 1, DxbcInstClass::GeometryEmit, { { 1, DxbcInstClass::GeometryEmit, {
{ DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 },

View File

@ -41,6 +41,7 @@ namespace dxvk {
BufferLoad, ///< Structured or raw buffer load BufferLoad, ///< Structured or raw buffer load
BufferStore, ///< Structured or raw buffer store BufferStore, ///< Structured or raw buffer store
ConvertFloat16, ///< 16-bit float packing/unpacking ConvertFloat16, ///< 16-bit float packing/unpacking
HullShaderPhase, ///< Hull shader phase declaration
Interpolate, ///< Input attribute interpolation Interpolate, ///< Input attribute interpolation
TextureQuery, ///< Texture query instruction TextureQuery, ///< Texture query instruction
TextureQueryLod, ///< Texture LOD query instruction TextureQueryLod, ///< Texture LOD query instruction

View File

@ -2752,7 +2752,8 @@ namespace dxvk {
// we can use the code buffer to look up type IDs as // we can use the code buffer to look up type IDs as
// well. Result IDs are always stored as argument 1. // well. Result IDs are always stored as argument 1.
for (auto ins : m_typeConstDefs) { for (auto ins : m_typeConstDefs) {
bool match = ins.opCode() == op; bool match = ins.opCode() == op
&& ins.length() == 2 + argCount;
for (uint32_t i = 0; i < argCount && match; i++) for (uint32_t i = 0; i < argCount && match; i++)
match &= ins.arg(2 + i) == argIds[i]; match &= ins.arg(2 + i) == argIds[i];