Skip to content

Commit

Permalink
[dxbc] Implement support for SV_PrimitiveID
Browse files Browse the repository at this point in the history
Fixes some geometry/tessellation shaders in The Witcher 3.
  • Loading branch information
doitsujin committed Apr 8, 2018
1 parent 83a0eda commit e38cc4a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
59 changes: 53 additions & 6 deletions src/dxbc/dxbc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ namespace dxvk {
"oDepthLe");
} break;

case DxbcOperandType::InputPrimitiveId: {
m_primitiveIdIn = emitNewBuiltinVariable({
{ DxbcScalarType::Uint32, 1, 0 },
spv::StorageClassInput },
spv::BuiltInPrimitiveId,
"vPrim");
} break;

case DxbcOperandType::InputDomainPoint: {
m_ds.builtinTessCoord = emitNewBuiltinVariable({
{ DxbcScalarType::Float32, 3, 0 },
Expand Down Expand Up @@ -4247,6 +4255,11 @@ namespace dxvk {
{ DxbcScalarType::Float32, 1 },
m_ps.builtinDepth };

case DxbcOperandType::InputPrimitiveId:
return DxbcRegisterPointer {
{ DxbcScalarType::Uint32, 1 },
m_primitiveIdIn };

case DxbcOperandType::InputDomainPoint:
return DxbcRegisterPointer {
{ DxbcScalarType::Float32, 3 },
Expand Down Expand Up @@ -5045,6 +5058,24 @@ namespace dxvk {
return result;
} break;

case DxbcSystemValue::PrimitiveId: {
if (m_primitiveIdIn == 0) {
m_module.enableCapability(spv::CapabilityGeometry);

m_primitiveIdIn = emitNewBuiltinVariable({
{ DxbcScalarType::Uint32, 1, 0 },
spv::StorageClassInput },
spv::BuiltInPrimitiveId,
"ps_primitive_id");
}

DxbcRegisterPointer ptrIn;
ptrIn.type = { DxbcScalarType::Uint32, 1 };
ptrIn.id = m_primitiveIdIn;

return emitValueLoad(ptrIn);
} break;

case DxbcSystemValue::SampleIndex: {
if (m_ps.builtinSampleId == 0) {
m_module.enableCapability(spv::CapabilitySampleRateShading);
Expand Down Expand Up @@ -5207,9 +5238,8 @@ namespace dxvk {
}

DxbcRegisterPointer ptr;
ptr.type.ctype = DxbcScalarType::Uint32;
ptr.type.ccount = 1;
ptr.id = m_gs.builtinLayer;
ptr.type = { DxbcScalarType::Uint32 };
ptr.id = m_gs.builtinLayer;

emitValueStore(
ptr, emitRegisterExtract(value, mask),
Expand All @@ -5228,9 +5258,26 @@ namespace dxvk {
}

DxbcRegisterPointer ptr;
ptr.type.ctype = DxbcScalarType::Uint32;
ptr.type.ccount = 1;
ptr.id = m_gs.builtinViewportId;
ptr.type = { DxbcScalarType::Uint32, 1};
ptr.id = m_gs.builtinViewportId;

emitValueStore(
ptr, emitRegisterExtract(value, mask),
DxbcRegMask(true, false, false, false));
} break;

case DxbcSystemValue::PrimitiveId: {
if (m_primitiveIdOut == 0) {
m_primitiveIdOut = emitNewBuiltinVariable({
{ DxbcScalarType::Uint32, 1, 0 },
spv::StorageClassOutput },
spv::BuiltInPrimitiveId,
"gs_primitive_id");
}

DxbcRegisterPointer ptr;
ptr.type = { DxbcScalarType::Uint32, 1};
ptr.id = m_primitiveIdOut;

emitValueStore(
ptr, emitRegisterExtract(value, mask),
Expand Down
7 changes: 3 additions & 4 deletions src/dxbc/dxbc_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ namespace dxvk {
uint32_t m_clipDistances = 0;
uint32_t m_cullDistances = 0;

uint32_t m_primitiveIdIn = 0;
uint32_t m_primitiveIdOut = 0;

//////////////////////////////////////////////////
// Immediate constant buffer. If defined, this is
// an array of four-component uint32 vectors.
Expand All @@ -412,10 +415,6 @@ namespace dxvk {
uint32_t m_uavCtrStructType = 0;
uint32_t m_uavCtrPointerType = 0;

////////////////////////////////
// Push constant block variable
uint32_t m_pushConstantBlock = 0;

///////////////////////////////////////////////////
// Entry point description - we'll need to declare
// the function ID and all input/output variables.
Expand Down

1 comment on commit e38cc4a

@pingubot
Copy link
Contributor

@pingubot pingubot commented on e38cc4a Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, this could also fix object tess in crysis 2, letme test

Please sign in to comment.