diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-05-30 17:16:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-31 00:16:59 +0000 |
| commit | da5cf478c6be06c9e6c20917a7d472cbdcb624e3 (patch) | |
| tree | 7be790c85547c86b92fff80fa9340c89d71a167e /tests | |
| parent | 3ca27faa23a92124f26875a6f00bcfc3a1c6431e (diff) | |
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<float> InputTyped;
[require(cpp_cuda_glsl_hlsl_metal_spirv)]
RWBuffer<float> 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<float> InputTyped;
^~~~~~~~~~
.\tests\wgsl_no_buffer.slang(4): error 36108: 'OutputTyped' has dependencies that are not compatible on the required target 'wgsl'.
RWBuffer<float> 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>
Diffstat (limited to 'tests')
5 files changed, 65 insertions, 1 deletions
diff --git a/tests/bugs/gh-3429.slang b/tests/bugs/gh-3429.slang index c9b49e5f4..115ebdb06 100644 --- a/tests/bugs/gh-3429.slang +++ b/tests/bugs/gh-3429.slang @@ -14,7 +14,8 @@ struct PushConstants bool bufferHasOnlyOneElement; }; -[[vk::push_constant]] ConstantBuffer<PushConstants> gPushConstants; +[[vk::push_constant]] +ConstantBuffer<PushConstants> gPushConstants; float loadDataConditionTrue() { diff --git a/tests/language-feature/capability/var-capability-incompatible.slang b/tests/language-feature/capability/var-capability-incompatible.slang new file mode 100644 index 000000000..89378f6b3 --- /dev/null +++ b/tests/language-feature/capability/var-capability-incompatible.slang @@ -0,0 +1,19 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv +[require(hlsl)] +struct MyType +{} + +//CHECK: ([[# @LINE+2]]): error 36107 +[numthreads(1,1,1)] +void f1() +{ + MyType t; // compile to spirv should result error here. +} + +ConstantBuffer<MyType> t2; +//CHECK: ([[# @LINE+2]]): error 36107 +[numthreads(1,1,1)] +void f2() // compile to spirv should result error here. +{ + ConstantBuffer<MyType> t3 = t2; +} diff --git a/tests/language-feature/capability/var-capability-wgsl-2.slang b/tests/language-feature/capability/var-capability-wgsl-2.slang new file mode 100644 index 000000000..4fb259ea6 --- /dev/null +++ b/tests/language-feature/capability/var-capability-wgsl-2.slang @@ -0,0 +1,15 @@ +//TEST:SIMPLE(filecheck=CHECK_IGNORE_CAPS): -target wgsl -entry Main -stage compute + +//CHECK_IGNORE_CAPS-NOT: error 36107 +[require(cpp_cuda_glsl_hlsl_metal_spirv)] +struct inputWrapper { + RWBuffer<float> InputTyped; +}; + +inputWrapper input; + +[numthreads(64, 1, 1)] +void Main(uint3 DTid : SV_DispatchThreadID) +{ + // We should not see an error here, because the inputWrapper is not referenced. +}
\ No newline at end of file diff --git a/tests/language-feature/capability/var-capability-wgsl.slang b/tests/language-feature/capability/var-capability-wgsl.slang new file mode 100644 index 000000000..2a67cc6e2 --- /dev/null +++ b/tests/language-feature/capability/var-capability-wgsl.slang @@ -0,0 +1,15 @@ +//TEST:SIMPLE(filecheck=CHECK): -target wgsl -entry Main -stage compute +//TEST:SIMPLE(filecheck=CHECK_IGNORE_CAPS): -target wgsl -entry Main -stage compute -ignore-capabilities + +[require(cpp_cuda_glsl_hlsl_metal_spirv)] +Buffer<float> InputTyped; +[require(cpp_cuda_glsl_hlsl_metal_spirv)] +RWBuffer<float> OutputTyped; + +//CHECK: ([[# @LINE+3]]): error 36107 +//CHECK_IGNORE_CAPS-NOT: error 36107 +[numthreads(64, 1, 1)] +void Main(uint3 DTid : SV_DispatchThreadID) +{ + OutputTyped[DTid.x] = InputTyped[DTid.x]; +}
\ No newline at end of file diff --git a/tests/language-feature/capability/var-implicit-capability-wgsl.slang b/tests/language-feature/capability/var-implicit-capability-wgsl.slang new file mode 100644 index 000000000..56aa4157d --- /dev/null +++ b/tests/language-feature/capability/var-implicit-capability-wgsl.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=CHECK): -target wgsl -entry Main -stage compute +//TEST:SIMPLE(filecheck=CHECK_IGNORE_CAPS): -target wgsl -entry Main -stage compute -ignore-capabilities + + +Buffer<float> InputTyped; +RWBuffer<float> OutputTyped; + +//CHECK: ([[# @LINE+3]]): error 36107 +//CHECK_IGNORE_CAPS-NOT: error 36107 +[numthreads(64, 1, 1)] +void Main(uint3 DTid : SV_DispatchThreadID) +{ + OutputTyped[DTid.x] = InputTyped[DTid.x]; +}
\ No newline at end of file |
