From da5cf478c6be06c9e6c20917a7d472cbdcb624e3 Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Fri, 30 May 2025 17:16:59 -0700 Subject: Add check for the variable requirement (#6677) * Add check for the variable requirement This change adds the capability check for the variables requirement. With this check, the shader ``` [require(cpp_cuda_glsl_hlsl_metal_spirv)] Buffer InputTyped; [require(cpp_cuda_glsl_hlsl_metal_spirv)] RWBuffer OutputTyped; ``` will issue error if targeting to WSGL e.g. `.\build\Debug\bin\slangc .\tests\wgsl_no_buffer.slang -o wgsl_no_buffer.txt -target wgsl -entry Main -stage compute` .\tests\wgsl_no_buffer.slang(2): error 36108: 'InputTyped' has dependencies that are not compatible on the required target 'wgsl'. Buffer InputTyped; ^~~~~~~~~~ .\tests\wgsl_no_buffer.slang(4): error 36108: 'OutputTyped' has dependencies that are not compatible on the required target 'wgsl'. RWBuffer OutputTyped; ^~~~~~~~~~~ Fixes #6304 * Add var capability tests * Do capability checks for global var only * Add inferredCapabilityRequirements to var capability check * Add requirement to the intrinsic types Buffer/RWBuffer * format code * Update capabliity test * use DefaultDataLayout as default data layout * Use visitMemberExpr to check the capabilities * Update the cap tests to match the error messages * update test to use the ScalarDataLayout for hlsl target * Update tests check condition to use error number only * Add default push_constant data layout type --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-parser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 9eb8c1391..439959827 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -4976,8 +4976,9 @@ static DeclBase* ParseDeclWithModifiers( }; if (AdvanceIf(parser, "buffer")) { - decl = as( - parseGLSLShaderStorageBufferDecl(parser, getLayoutArg("Std430DataLayout"))); + decl = as(parseGLSLShaderStorageBufferDecl( + parser, + getLayoutArg("DefaultDataLayout"))); break; } else if (auto mod = findPotentialGLSLInterfaceBlockModifier(parser, modifiers)) -- cgit v1.2.3