diff options
| author | Yong He <yonghe@outlook.com> | 2024-11-21 14:07:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-21 14:07:23 -0800 |
| commit | fdf061e278720ec066a1fac8f1f35a22e817bf2d (patch) | |
| tree | db6cc05613afacdb9c67a26695355ff1b0086d79 /source/slang/slang-check-decl.cpp | |
| parent | dcc7c6f009afc0f55e79ced050b772ea9d3b25ae (diff) | |
Add datalayout for constant buffers. (#5608)
* Add datalayout for constant buffers.
* Fixes.
* Fix test.
* Fix glsl codegen.
* Update spirv-specific doc.
* Fix test.
* Fix binding in the presense of specialization constants.
* address comments.
* Add a test for constant buffer layout.
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 07d5dd1fa..251ce6a69 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -110,6 +110,7 @@ struct SemanticsDeclHeaderVisitor : public SemanticsDeclVisitorBase, void checkMeshOutputDecl(VarDeclBase* varDecl); void maybeApplyLayoutModifier(VarDeclBase* varDecl); void checkVarDeclCommon(VarDeclBase* varDecl); + void checkPushConstantBufferType(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { checkVarDeclCommon(varDecl); } @@ -1707,6 +1708,10 @@ void SemanticsDeclHeaderVisitor::maybeApplyLayoutModifier(VarDeclBase* varDecl) addModifier(varDecl, formatAttrib); } } + else + { + checkPushConstantBufferType(varDecl); + } } bool isSpecializationConstant(VarDeclBase* varDecl) @@ -1721,6 +1726,32 @@ bool isSpecializationConstant(VarDeclBase* varDecl) return false; } +void SemanticsDeclHeaderVisitor::checkPushConstantBufferType(VarDeclBase* varDecl) +{ + if (varDecl->findModifier<PushConstantAttribute>()) + { + // If we see a ConstantBuffer<T, DefaultLayout> parameter marked as "push_constant", we need + // to set its type to ConstantBuffer<T, Std430>. + if (auto cbufferType = as<ConstantBufferType>(varDecl->type)) + { + if (cbufferType->getLayoutType() == m_astBuilder->getDefaultLayoutType()) + { + varDecl->type.type = getConstantBufferType( + cbufferType->getElementType(), + m_astBuilder->getStd430LayoutType()); + } + } + else if (isGlobalShaderParameter(varDecl)) + { + // If this is a global variable with [vk::push_constant] attribute, + // we need to make sure to wrap it in a `ConstantBuffer`. + // + varDecl->type.type = + getConstantBufferType(varDecl->type, m_astBuilder->getStd430LayoutType()); + } + } +} + void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { // A variable that didn't have an explicit type written must @@ -1935,20 +1966,8 @@ void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) } } - if (as<NamespaceDeclBase>(varDecl->parentDecl)) { - // If this is a global variable with [vk::push_constant] attribute, - // we need to make sure to wrap it in a `ConstantBuffer`. - - if (!as<ConstantBufferType>(varDecl->type)) - { - if (varDecl->findModifier<PushConstantAttribute>()) - { - varDecl->type.type = m_astBuilder->getConstantBufferType(varDecl->type); - } - } - if (getModuleDecl(varDecl)->hasModifier<GLSLModuleModifier>()) { // If we are in GLSL compatiblity mode, we want to treat all global variables |
