From c356d3ac2956671b6cb7af667d8b35c7ba8b75a7 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 29 Jan 2025 07:55:39 +0800 Subject: Allow requiring glsl language extensions on structs (#6173) * Allow requiring glsl language extensions on structs * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- source/slang/slang-emit-c-like.cpp | 8 ++++---- source/slang/slang-lower-to-ir.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 98bddad9b..180ef9909 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3722,10 +3722,6 @@ void CLikeSourceEmitter::emitSimpleFuncImpl(IRFunc* func) emitEntryPointAttributes(func, entryPointDecor); } - // Deal with required features/capabilities of the function - // - handleRequiredCapabilitiesImpl(func); - emitFunctionPreambleImpl(func); emitFuncDecorations(func); @@ -4885,6 +4881,10 @@ void CLikeSourceEmitter::emitGlobalInstImpl(IRInst* inst) { m_writer->advanceToSourceLocation(inst->sourceLoc); + // Deal with required features/capabilities of the global inst + // + handleRequiredCapabilitiesImpl(inst); + switch (inst->getOp()) { case kIROp_GlobalHashedStringLiterals: diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 76b8e38e9..ba6b3413d 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -9101,6 +9101,7 @@ struct DeclLoweringVisitor : DeclVisitor subBuilder->addAutoDiffBuiltinDecoration(irAggType); } + addTargetRequirementDecorations(irAggType, decl); return LoweredValInfo::simple(finalFinishedVal); } @@ -9774,6 +9775,36 @@ struct DeclLoweringVisitor : DeclVisitor } } + void addTargetRequirementDecorations(IRInst* inst, Decl* decl) + { + // If this declaration requires certain GLSL extension (or a particular GLSL version) + // for it to be usable, then declare that here. Similarly for SPIR-V or CUDA + // + // TODO: We should wrap this an `SpecializedForTargetModifier` together into a single + // case for enumerating the "capabilities" that a declaration requires. + // + for (auto extensionMod : decl->getModifiersOfType()) + { + getBuilder()->addRequireGLSLExtensionDecoration( + inst, + extensionMod->extensionNameToken.getContent()); + } + for (auto versionMod : decl->getModifiersOfType()) + { + getBuilder()->addRequireGLSLVersionDecoration( + inst, + Int(getIntegerLiteralValue(versionMod->versionNumberToken))); + } + for (auto versionMod : decl->getModifiersOfType()) + { + getBuilder()->addRequireSPIRVVersionDecoration(inst, versionMod->version); + } + for (auto versionMod : decl->getModifiersOfType()) + { + getBuilder()->addRequireCUDASMVersionDecoration(inst, versionMod->version); + } + } + void addBitFieldAccessorDecorations(IRInst* irFunc, Decl* decl) { // If this is an accessor and the parent is describing some bitfield, @@ -10340,6 +10371,8 @@ struct DeclLoweringVisitor : DeclVisitor addCatchAllIntrinsicDecorationIfNeeded(irFunc, decl); + addTargetRequirementDecorations(irFunc, decl); + bool isInline = false; addBitFieldAccessorDecorations(irFunc, decl); -- cgit v1.2.3