diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-08 15:13:08 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-08 15:13:08 -0800 |
| commit | 6f8a20688e0c4b989db152b4d06aeab04fac0567 (patch) | |
| tree | def602768da1b1ef1606bc1d5116eb44832f8332 /source | |
| parent | 5afe9709aab2ceb499e3ba279ebce4b311037837 (diff) | |
[SPIRV] fix code gen for `SV_Coverage`. (#3718)
* [SPIRV] fix code gen for `SV_Coverage`.
* Fix #3714, #3699.
* Fix.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 50 | ||||
| -rw-r--r-- | source/slang/slang-ir-glsl-legalize.cpp | 15 | ||||
| -rw-r--r-- | source/slang/slang-ir-spirv-legalize.cpp | 2 |
3 files changed, 51 insertions, 16 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 1b5747621..1a661920a 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3461,17 +3461,6 @@ struct SPIRVEmitContext varInst, builtinVal ); - - if (storageClass == SpvStorageClassInput || - storageClass == SpvStorageClassOutput) - { - switch (builtinVal) - { - case SpvBuiltInPrimitiveId: - _maybeEmitInterpolationModifierDecoration(IRInterpolationMode::NoInterpolation, varInst); - break; - } - } m_builtinGlobalVars[key] = varInst; return varInst; } @@ -5740,6 +5729,22 @@ struct SPIRVEmitContext } }; +bool isInstUsedInStage(SPIRVEmitContext& context, IRInst* inst, Stage s) +{ + auto* referencingEntryPoints = context.m_referencingEntryPoints.tryGetValue(inst); + if (!referencingEntryPoints) + return false; + for (auto entryPoint : *referencingEntryPoints) + { + if (auto entryPointDecor = entryPoint->findDecoration<IREntryPointDecoration>()) + { + if (entryPointDecor->getProfile().getStage() == s) + return true; + } + } + return false; +} + SlangResult emitSPIRVFromIR( CodeGenContext* codeGenContext, IRModule* irModule, @@ -5804,6 +5809,29 @@ SlangResult emitSPIRVFromIR( context.ensureInst(irEntryPoint); } + // Declare integral input builtins as Flat if necessary. + for (auto globalInst : context.m_irModule->getGlobalInsts()) + { + if (globalInst->getOp() != kIROp_GlobalVar && + globalInst->getOp() != kIROp_GlobalParam) + continue; + auto spvVar = context.m_mapIRInstToSpvInst.tryGetValue(globalInst); + if (!spvVar) + continue; + auto ptrType = as<IRPtrType>(globalInst->getDataType()); + if (!ptrType) + continue; + auto addrSpace = ptrType->getAddressSpace(); + if (addrSpace == SpvStorageClassInput) + { + if (isIntegralScalarOrCompositeType(ptrType->getValueType())) + { + if (isInstUsedInStage(context, globalInst, Stage::Fragment)) + context._maybeEmitInterpolationModifierDecoration(IRInterpolationMode::NoInterpolation, *spvVar); + } + } + } + // Move forward delcared pointers to the end. do { diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index ca9367ea0..d2d09f45a 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -637,12 +637,13 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( if( kind == LayoutResourceKind::VaryingInput ) { - name = "gl_SampleMaskIn[0]"; + name = "gl_SampleMaskIn"; } else { - name = "gl_SampleMask[0]"; + name = "gl_SampleMask"; } + arrayIndex = 0; } else if(semanticName == "sv_innercoverage") { @@ -891,6 +892,7 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( // name = "gl_PositionPerViewNV[1]"; + arrayIndex = 1; // shared->requiresCopyGLPositionToPositionPerView = true; } @@ -1594,7 +1596,12 @@ ScalarizedVal adaptType( return adaptType(builder, loaded, toType, fromType); } break; - + case ScalarizedVal::Flavor::arrayIndex: + { + auto element = builder->emitElementExtract(val.irValue, as<ScalarizedArrayIndexValImpl>(val.impl)->index); + return adaptType(builder, element, toType, fromType); + } + break; default: SLANG_UNEXPECTED("unimplemented"); UNREACHABLE_RETURN(ScalarizedVal()); @@ -1788,7 +1795,7 @@ ScalarizedVal getSubscriptVal( resultAdapter->val = getSubscriptVal( builder, - elementType, + inputAdapter->actualType, inputAdapter->val, indexVal); return ScalarizedVal::typeAdapter(resultAdapter); diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index 5589510ed..b387a67f6 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -1934,7 +1934,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase // After legalizing the control flow, we need to sort our blocks to ensure this is true. sortBlocksInFunc(func); } - + if (isInlinableGlobalInst(globalInst)) { for (auto use = globalInst->firstUse; use; use = use->nextUse) |
