From de83628070614ec37349c9f334ed72a54a6889da Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 30 Aug 2024 12:03:23 -0700 Subject: Support specialization constants. (#4963) * Support specialization constants. * Fix. * Fix. * Fix. * Fix. * Make sure specialization constants have names. * Clean up and support the dxc [vk::constant_id] syntax. * Fix. * Fix. * Fix. --- source/slang/slang-parameter-binding.cpp | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'source/slang/slang-parameter-binding.cpp') diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 6f8504a31..115ccc55e 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -703,20 +703,21 @@ RefPtr getTypeLayoutForGlobalShaderParameter( type); } - // TODO: The cases below for detecting globals that aren't actually - // shader parameters should be redundant now that the semantic - // checking logic is responsible for populating the list of - // parameters on a `Program`. We should be able to clean up - // the code by removing these two cases, and the related null - // pointer checks in the code that calls this. - - // HLSL `static` modifier indicates "thread local" - if(varDecl->hasModifier()) - return nullptr; - - // HLSL `groupshared` modifier indicates "thread-group local" - if(varDecl->hasModifier()) - return nullptr; + if (varDecl->hasModifier() || + varDecl->hasModifier()) + { + auto specializationConstantRule = rules->getSpecializationConstantRules(); + if (!specializationConstantRule) + { + // If the target doesn't support specialization constants, then we will + // layout them as ordinary uniform data. + specializationConstantRule = rules->getConstantBufferRules(context->getTargetRequest()->getOptionSet()); + } + return createTypeLayoutWith( + layoutContext, + specializationConstantRule, + type); + } // TODO(tfoley): there may be other cases that we need to handle here @@ -1143,10 +1144,10 @@ static void addExplicitParameterBindings_GLSL( else if(auto foundSpecializationConstant = typeLayout->FindResourceInfo(LayoutResourceKind::SpecializationConstant)) { info[kResInfo].resInfo = foundSpecializationConstant; - DeclRef varDecl2(varDecl); - // Try to find `constant_id` binding - if(!findLayoutArg(varDecl2, &info[kResInfo].semanticInfo.index)) + if (auto layoutAttr = varDecl.getDecl()->findModifier()) + info[kResInfo].semanticInfo.index = layoutAttr->location; + else return; } -- cgit v1.2.3