diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir-glsl-legalize.cpp | 34 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.h | 7 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 15 |
3 files changed, 53 insertions, 3 deletions
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index ae30184c8..be222c87f 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -1285,6 +1285,36 @@ ScalarizedVal createSimpleGLSLGlobalVarying( declarator, &systemValueInfoStorage); + { + + auto systemSemantic = inVarLayout->findAttr<IRSystemValueSemanticAttr>(); + // Validate the system value, convert to a regular parameter if this is not a valid system value for a given target. + if (systemSemantic && isSPIRV(codeGenContext->getTargetFormat()) && systemSemantic->getName().caseInsensitiveEquals(UnownedStringSlice("sv_instanceid")) + && ((stage == Stage::Fragment) || (stage == Stage::Vertex && inVarLayout->usesResourceKind(LayoutResourceKind::VaryingOutput)))) + { + ShortList<IRInst*> newOperands; + auto opCount = inVarLayout->getOperandCount(); + newOperands.reserveOverflowBuffer(opCount); + for (UInt i = 0; i < opCount; ++i) + { + auto op = inVarLayout->getOperand(i); + if (op == systemSemantic) + continue; + newOperands.add(op); + } + + auto newVarLayout = builder->emitIntrinsicInst( + inVarLayout->getFullType(), + inVarLayout->getOp(), + newOperands.getCount(), + newOperands.getArrayView().getBuffer()); + + newVarLayout->sourceLoc = inVarLayout->sourceLoc; + + inVarLayout->replaceUsesWith(newVarLayout); + } + } + IRType* type = inType; IRType* peeledRequiredType = nullptr; @@ -2570,9 +2600,7 @@ static void legalizeMeshOutputParam( // // First, collect the subset of outputs being used - const bool isSPIRV = codeGenContext->getTargetFormat() == CodeGenTarget::SPIRV - || codeGenContext->getTargetFormat() == CodeGenTarget::SPIRVAssembly; - if(!isSPIRV) + if(!isSPIRV(codeGenContext->getTargetFormat())) { auto isMeshOutputBuiltin = [](IRInst* g) { diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h index 03a45746d..d78ceaaf8 100644 --- a/source/slang/slang-ir-util.h +++ b/source/slang/slang-ir-util.h @@ -338,6 +338,13 @@ void verifyComputeDerivativeGroupModifiers( bool linearAttr, IRNumThreadsDecoration* numThreadsDecor); + +inline bool isSPIRV(CodeGenTarget codeGenTarget) +{ + return codeGenTarget == CodeGenTarget::SPIRV + || codeGenTarget == CodeGenTarget::SPIRVAssembly; +} + } #endif diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index bce9b5d05..ca0de9802 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -4,6 +4,7 @@ #include "slang-lookup.h" #include "slang-compiler.h" #include "slang-type-layout.h" +#include "slang-ir-util.h" #include "../compiler-core/slang-artifact-desc-util.h" @@ -1640,6 +1641,20 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( type, kEntryPointParameterDirection_Output); } + else if (isSPIRV(context->getTargetRequest()->getTarget()) + && ( + (state.directionMask & kEntryPointParameterDirection_Input && state.stage == Stage::Fragment) + || (state.directionMask & kEntryPointParameterDirection_Output && state.stage == Stage::Vertex) + ) + && sn == "sv_instanceid" + ) + { + // This fragment-shader-input/vertex-shader-output is effectively not a system semantic for SPIR-V, + typeLayout = getSimpleVaryingParameterTypeLayout( + context->layoutContext, + type, + state.directionMask); + } else { // For a system-value parameter (that didn't match the |
