[dxbc] Implemented Hull Shader fork/join phase invocations

This commit is contained in:
Philip Rebohle 2018-03-01 12:08:06 +01:00
parent 868e55ede7
commit 0916115086
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
5 changed files with 127 additions and 57 deletions

View File

@ -88,6 +88,9 @@ namespace dxvk {
case DxbcInstClass::HullShaderPhase: case DxbcInstClass::HullShaderPhase:
return this->emitHullShaderPhase(ins); return this->emitHullShaderPhase(ins);
case DxbcInstClass::HullShaderInstCnt:
return this->emitHullShaderInstCnt(ins);
case DxbcInstClass::Interpolate: case DxbcInstClass::Interpolate:
return this->emitInterpolate(ins); return this->emitInterpolate(ins);
@ -482,8 +485,18 @@ namespace dxvk {
case DxbcOperandType::InputForkInstanceId: case DxbcOperandType::InputForkInstanceId:
case DxbcOperandType::InputJoinInstanceId: { case DxbcOperandType::InputJoinInstanceId: {
// Nothing to do here, as these are part of the auto phase = this->getCurrentHsForkJoinPhase();
// function signature for the fork and join phases.
phase->instanceIdPtr = m_module.newVar(
m_module.defPointerType(
m_module.defIntType(32, 0),
spv::StorageClassFunction),
spv::StorageClassFunction);
m_module.opStore(phase->instanceIdPtr, phase->instanceId);
m_module.setDebugName(phase->instanceIdPtr,
ins.dst[0].type == DxbcOperandType::InputForkInstanceId
? "vForkInstanceId" : "vJoinInstanceId");
} break; } break;
default: default:
@ -2267,6 +2280,11 @@ namespace dxvk {
} }
void DxbcCompiler::emitHullShaderInstCnt(const DxbcShaderInstruction& ins) {
this->getCurrentHsForkJoinPhase()->instanceCount = ins.imm[0].u32;
}
void DxbcCompiler::emitHullShaderPhase(const DxbcShaderInstruction& ins) { void DxbcCompiler::emitHullShaderPhase(const DxbcShaderInstruction& ins) {
switch (ins.op) { switch (ins.op) {
case DxbcOpcode::HsDecls: { case DxbcOpcode::HsDecls: {
@ -3954,12 +3972,12 @@ namespace dxvk {
case DxbcOperandType::InputForkInstanceId: case DxbcOperandType::InputForkInstanceId:
return DxbcRegisterPointer { return DxbcRegisterPointer {
{ DxbcScalarType::Uint32, 1 }, { DxbcScalarType::Uint32, 1 },
m_hs.forkPhases.at(m_hs.currPhaseId).builtinInstanceId }; m_hs.forkPhases.at(m_hs.currPhaseId).instanceIdPtr };
case DxbcOperandType::InputJoinInstanceId: case DxbcOperandType::InputJoinInstanceId:
return DxbcRegisterPointer { return DxbcRegisterPointer {
{ DxbcScalarType::Uint32, 1 }, { DxbcScalarType::Uint32, 1 },
m_hs.joinPhases.at(m_hs.currPhaseId).builtinInstanceId }; m_hs.joinPhases.at(m_hs.currPhaseId).instanceIdPtr };
default: default:
throw DxvkError(str::format( throw DxvkError(str::format(
@ -5016,7 +5034,13 @@ namespace dxvk {
void DxbcCompiler::emitHsFinalize() { void DxbcCompiler::emitHsFinalize() {
// TODO implement this->emitHsControlPointPhase(m_hs.cpPhase);
for (const auto& phase : m_hs.forkPhases)
this->emitHsForkJoinPhase(phase);
for (const auto& phase : m_hs.joinPhases)
this->emitHsForkJoinPhase(phase);
} }
@ -5052,6 +5076,22 @@ namespace dxvk {
} }
void DxbcCompiler::emitHsControlPointPhase(
const DxbcCompilerHsControlPointPhase& phase) {
}
void DxbcCompiler::emitHsForkJoinPhase(
const DxbcCompilerHsForkJoinPhase& phase) {
for (uint32_t i = 0; i < phase.instanceCount; i++) {
const uint32_t counterId = m_module.constu32(i);
m_module.opFunctionCall(m_module.defVoidType(),
phase.functionId, 1, &counterId);
}
}
void DxbcCompiler::emitDclInputArray(uint32_t vertexCount) { void DxbcCompiler::emitDclInputArray(uint32_t vertexCount) {
DxbcArrayType info; DxbcArrayType info;
info.ctype = DxbcScalarType::Float32; info.ctype = DxbcScalarType::Float32;
@ -5102,9 +5142,7 @@ namespace dxvk {
DxbcCompilerHsForkJoinPhase DxbcCompiler::emitNewHullShaderForkJoinPhase() { DxbcCompilerHsForkJoinPhase DxbcCompiler::emitNewHullShaderForkJoinPhase() {
uint32_t argTypeId = m_module.defPointerType( uint32_t argTypeId = m_module.defIntType(32, 0);
m_module.defIntType(32, 0),
spv::StorageClassFunction);
uint32_t funTypeId = m_module.defFunctionType( uint32_t funTypeId = m_module.defFunctionType(
m_module.defVoidType(), 1, &argTypeId); m_module.defVoidType(), 1, &argTypeId);
@ -5117,8 +5155,8 @@ namespace dxvk {
m_module.opLabel(m_module.allocateId()); m_module.opLabel(m_module.allocateId());
DxbcCompilerHsForkJoinPhase result; DxbcCompilerHsForkJoinPhase result;
result.functionId = funId; result.functionId = funId;
result.builtinInstanceId = argId; result.instanceId = argId;
return result; return result;
} }
@ -5334,4 +5372,13 @@ namespace dxvk {
return typeId; return typeId;
} }
DxbcCompilerHsForkJoinPhase* DxbcCompiler::getCurrentHsForkJoinPhase() {
switch (m_hs.currPhaseType) {
case DxbcCompilerHsPhase::Fork: return &m_hs.forkPhases.at(m_hs.currPhaseId);
case DxbcCompilerHsPhase::Join: return &m_hs.joinPhases.at(m_hs.currPhaseId);
default: return nullptr;
}
}
} }

View File

@ -160,8 +160,9 @@ namespace dxvk {
*/ */
struct DxbcCompilerHsForkJoinPhase { struct DxbcCompilerHsForkJoinPhase {
uint32_t functionId = 0; uint32_t functionId = 0;
uint32_t instanceCount = 0; uint32_t instanceCount = 1;
uint32_t builtinInstanceId = 0; uint32_t instanceId = 0;
uint32_t instanceIdPtr = 0;
}; };
@ -530,6 +531,9 @@ namespace dxvk {
void emitHullShaderPhase( void emitHullShaderPhase(
const DxbcShaderInstruction& ins); const DxbcShaderInstruction& ins);
void emitHullShaderInstCnt(
const DxbcShaderInstruction& ins);
void emitInterpolate( void emitInterpolate(
const DxbcShaderInstruction& ins); const DxbcShaderInstruction& ins);
@ -831,6 +835,14 @@ namespace dxvk {
void emitPsFinalize(); void emitPsFinalize();
void emitCsFinalize(); void emitCsFinalize();
///////////////////////////////
// Hull shader phase methods
void emitHsControlPointPhase(
const DxbcCompilerHsControlPointPhase& phase);
void emitHsForkJoinPhase(
const DxbcCompilerHsForkJoinPhase& phase);
////////////// //////////////
// Misc stuff // Misc stuff
void emitDclInputArray( void emitDclInputArray(
@ -891,7 +903,7 @@ namespace dxvk {
uint32_t getPerVertexBlockId(); uint32_t getPerVertexBlockId();
uint32_t getPushConstantBlockId(); DxbcCompilerHsForkJoinPhase* getCurrentHsForkJoinPhase();
}; };

View File

@ -728,9 +728,13 @@ namespace dxvk {
/* DclHsMaxTessFactor */ /* DclHsMaxTessFactor */
{ }, { },
/* DclHsForkPhaseInstanceCount */ /* DclHsForkPhaseInstanceCount */
{ }, { 1, DxbcInstClass::HullShaderInstCnt, {
{ DxbcOperandKind::Imm32, DxbcScalarType::Uint32 },
} },
/* DclHsJoinPhaseInstanceCount */ /* DclHsJoinPhaseInstanceCount */
{ }, { 1, DxbcInstClass::HullShaderInstCnt, {
{ DxbcOperandKind::Imm32, DxbcScalarType::Uint32 },
} },
/* DclThreadGroup */ /* DclThreadGroup */
{ 3, DxbcInstClass::Declaration, { { 3, DxbcInstClass::Declaration, {
{ DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 },

View File

@ -28,39 +28,40 @@ namespace dxvk {
* new instructions easier. * new instructions easier.
*/ */
enum class DxbcInstClass { enum class DxbcInstClass {
Declaration, ///< Interface or resource declaration Declaration, ///< Interface or resource declaration
CustomData, ///< Immediate constant buffer CustomData, ///< Immediate constant buffer
ControlFlow, ///< Control flow instructions ControlFlow, ///< Control flow instructions
GeometryEmit, ///< Special geometry shader instructions GeometryEmit, ///< Special geometry shader instructions
Atomic, ///< Atomic operations Atomic, ///< Atomic operations
AtomicCounter, ///< Atomic counter operations AtomicCounter, ///< Atomic counter operations
Barrier, ///< Execution or memory barrier Barrier, ///< Execution or memory barrier
BitExtract, ///< Bit field extract operations BitExtract, ///< Bit field extract operations
BitInsert, ///< Bit field insert operations BitInsert, ///< Bit field insert operations
BufferQuery, ///< Buffer query instruction BufferQuery, ///< Buffer query instruction
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 HullShaderPhase, ///< Hull shader phase declaration
Interpolate, ///< Input attribute interpolation HullShaderInstCnt, ///< Hull shader phase instance count
TextureQuery, ///< Texture query instruction Interpolate, ///< Input attribute interpolation
TextureQueryLod, ///< Texture LOD query instruction TextureQuery, ///< Texture query instruction
TextureQueryMs, ///< Multisample texture query TextureQueryLod, ///< Texture LOD query instruction
TextureFetch, ///< Texture fetch instruction TextureQueryMs, ///< Multisample texture query
TextureGather, ///< Texture gather instruction TextureFetch, ///< Texture fetch instruction
TextureSample, ///< Texture sampling instruction TextureGather, ///< Texture gather instruction
TypedUavLoad, ///< Typed UAV load TextureSample, ///< Texture sampling instruction
TypedUavStore, ///< Typed UAV store TypedUavLoad, ///< Typed UAV load
VectorAlu, ///< Component-wise vector instructions TypedUavStore, ///< Typed UAV store
VectorCmov, ///< Component-wise conditional move VectorAlu, ///< Component-wise vector instructions
VectorCmp, ///< Component-wise vector comparison VectorCmov, ///< Component-wise conditional move
VectorDeriv, ///< Vector derivatives VectorCmp, ///< Component-wise vector comparison
VectorDot, ///< Dot product instruction VectorDeriv, ///< Vector derivatives
VectorIdiv, ///< Component-wise integer division VectorDot, ///< Dot product instruction
VectorImul, ///< Component-wise integer multiplication VectorIdiv, ///< Component-wise integer division
VectorShift, ///< Bit shift operations on vectors VectorImul, ///< Component-wise integer multiplication
VectorSinCos, ///< Sine and Cosine instruction VectorShift, ///< Bit shift operations on vectors
Undefined, ///< Instruction code not defined VectorSinCos, ///< Sine and Cosine instruction
Undefined, ///< Instruction code not defined
}; };
/** /**

View File

@ -547,10 +547,13 @@ namespace dxvk {
spv::StorageClass storageClass) { spv::StorageClass storageClass) {
uint32_t resultId = this->allocateId(); uint32_t resultId = this->allocateId();
m_variables.putIns (spv::OpVariable, 4); auto& code = storageClass != spv::StorageClassFunction
m_variables.putWord (pointerType); ? m_variables : m_code;
m_variables.putWord (resultId);
m_variables.putWord (storageClass); code.putIns (spv::OpVariable, 4);
code.putWord (pointerType);
code.putWord (resultId);
code.putWord (storageClass);
return resultId; return resultId;
} }
@ -561,11 +564,14 @@ namespace dxvk {
uint32_t initialValue) { uint32_t initialValue) {
uint32_t resultId = this->allocateId(); uint32_t resultId = this->allocateId();
m_variables.putIns (spv::OpVariable, 5); auto& code = storageClass != spv::StorageClassFunction
m_variables.putWord (pointerType); ? m_variables : m_code;
m_variables.putWord (resultId);
m_variables.putWord (storageClass); code.putIns (spv::OpVariable, 5);
m_variables.putWord (initialValue); code.putWord (pointerType);
code.putWord (resultId);
code.putWord (storageClass);
code.putWord (initialValue);
return resultId; return resultId;
} }