From fdf061e278720ec066a1fac8f1f35a22e817bf2d Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 21 Nov 2024 14:07:23 -0800 Subject: 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. --- source/slang/slang-parameter-binding.cpp | 42 +++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 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 3621c6c00..e45eb4652 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -707,7 +707,7 @@ RefPtr getTypeLayoutForGlobalShaderParameter( // If the target doesn't support specialization constants, then we will // layout them as ordinary uniform data. specializationConstantRule = - rules->getConstantBufferRules(context->getTargetRequest()->getOptionSet()); + rules->getConstantBufferRules(context->getTargetRequest()->getOptionSet(), type); } return createTypeLayoutWith(layoutContext, specializationConstantRule, type); } @@ -718,7 +718,7 @@ RefPtr getTypeLayoutForGlobalShaderParameter( // shader parameter. return createTypeLayoutWith( layoutContext, - rules->getConstantBufferRules(context->getTargetRequest()->getOptionSet()), + rules->getConstantBufferRules(context->getTargetRequest()->getOptionSet(), type), type); } @@ -2421,11 +2421,21 @@ static RefPtr computeEntryPointParameterTypeLayout( // a uniform shader parameter passed via the implicitly-defined // constant buffer (e.g., the `$Params` constant buffer seen in fxc/dxc output). // - return createTypeLayoutWith( - context->layoutContext, - context->getRulesFamily()->getConstantBufferRules( - context->getTargetRequest()->getOptionSet()), - paramType); + LayoutRulesImpl* layoutRules = nullptr; + if (isKhronosTarget(context->getTargetRequest())) + { + // For Vulkan, entry point uniform parameters are laid out using push constant buffer + // rules (defaults to std430). + layoutRules = context->getRulesFamily()->getShaderStorageBufferRules( + context->getTargetProgram()->getOptionSet()); + } + else + { + layoutRules = context->getRulesFamily()->getConstantBufferRules( + context->getTargetRequest()->getOptionSet(), + paramType); + } + return createTypeLayoutWith(context->layoutContext, layoutRules, paramType); } else { @@ -2783,12 +2793,13 @@ static ParameterBindingAndKindInfo _allocateConstantBufferBinding(ParameterBindi UInt space = context->shared->defaultSpace; auto usedRangeSet = _getOrCreateUsedRangeSetForSpace(context, space); - auto layoutInfo = context->getRulesFamily() - ->getConstantBufferRules(context->getTargetRequest()->getOptionSet()) - ->GetObjectLayout( - ShaderParameterKind::ConstantBuffer, - context->layoutContext.objectLayoutOptions) - .getSimple(); + auto layoutInfo = + context->getRulesFamily() + ->getConstantBufferRules(context->getTargetRequest()->getOptionSet(), nullptr) + ->GetObjectLayout( + ShaderParameterKind::ConstantBuffer, + context->layoutContext.objectLayoutOptions) + .getSimple(); ParameterBindingAndKindInfo info; info.kind = layoutInfo.kind; @@ -2809,7 +2820,9 @@ static ParameterBindingAndKindInfo _assignConstantBufferBinding( auto usedRangeSet = _getOrCreateUsedRangeSetForSpace(context, space); auto layoutInfo = context->getRulesFamily() - ->getConstantBufferRules(context->getTargetRequest()->getOptionSet()) + ->getConstantBufferRules( + context->getTargetRequest()->getOptionSet(), + varLayout->typeLayout ? varLayout->typeLayout->getType() : nullptr) ->GetObjectLayout( ShaderParameterKind::ConstantBuffer, context->layoutContext.objectLayoutOptions) @@ -3786,6 +3799,7 @@ static bool _calcNeedsDefaultSpace(SharedParameterBindingContext& sharedContext) case LayoutResourceKind::RegisterSpace: case LayoutResourceKind::SubElementRegisterSpace: case LayoutResourceKind::PushConstantBuffer: + case LayoutResourceKind::SpecializationConstant: continue; case LayoutResourceKind::Uniform: { -- cgit v1.2.3