diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-30 12:03:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 12:03:23 -0700 |
| commit | de83628070614ec37349c9f334ed72a54a6889da (patch) | |
| tree | bc97f74013a073fc958b75e68089696e14d71412 /source/slang/slang-parameter-binding.cpp | |
| parent | f428a058ea48535a323c32d206ebc7e551c3c3e9 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-parameter-binding.cpp')
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
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<TypeLayout> 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<HLSLStaticModifier>()) - return nullptr; - - // HLSL `groupshared` modifier indicates "thread-group local" - if(varDecl->hasModifier<HLSLGroupSharedModifier>()) - return nullptr; + if (varDecl->hasModifier<SpecializationConstantAttribute>() || + varDecl->hasModifier<VkConstantIdAttribute>()) + { + 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<Decl> varDecl2(varDecl); - // Try to find `constant_id` binding - if(!findLayoutArg<GLSLConstantIDLayoutModifier>(varDecl2, &info[kResInfo].semanticInfo.index)) + if (auto layoutAttr = varDecl.getDecl()->findModifier<VkConstantIdAttribute>()) + info[kResInfo].semanticInfo.index = layoutAttr->location; + else return; } |
