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/slang/slang-emit-spirv.cpp | |
| 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/slang/slang-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 50 |
1 files changed, 39 insertions, 11 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 { |
