diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-08-29 06:05:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-28 15:05:26 -0700 |
| commit | 508dc3a95de50de4a4d07d0a72a18e40d55b0e2e (patch) | |
| tree | 7487232f5c0db0dd607e2a91b539f6a592789b06 /tests | |
| parent | 06f7ef354cdde4cf8e8797d8853ed2d9c3208b5b (diff) | |
Allow bitwise or expressions and numeric literals in spirv_asm blocks (#3157)
* Add -spirv-core-grammar option to load alternate spirv defs
Also embed a version to use by default
* Use perfect hash for spv op lookup
* Neaten perfect hash embedding
* Refactor spirv grammar lookup in preperation for more kinds of lookups
* Load spirv capability list from spec
* Add all SPIR-V enums to lookup table
* regenerate vs projects
* appease msvc
* Use string slices for spir-v core grammar lookups
* wiggle
* comment
* Add OpInfo for spv ops
* regenerate vs projects
* Embed op names
* Add min/max operand counts and enum categories to spirv info
* neaten
* Operand kinds for spirv ops
* Store and embed all information relating to spirv enums and qualifiers
* Use SPIR-V spec to position instructions in spirv_asm blocks
* Neaten spir-v info embedding
* Neaten perfect hash embedding
* Add assignment syntax to spirv_asm snippets
* Better errors for spirv_asm parser
* Add warning for too many operands in spirv asm
* squash warnings
* neaten
* test wiggle
* Lookup enums for spirv
* Put OpCapability and OpExtension in the correct place for spirv_asm blocks
* Tests for OpCapability and OpExtension
* ci wiggle
* Add expected failure
* Allow raising immediate values to constant ids where necessary in spirv_asm blocks
* Allow bitwise or expressions and numeric literals in spirv_asm blocks
* test numeric literals
* Fix memory issues.
* fix.
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
10 files changed, 265 insertions, 1 deletions
diff --git a/tests/expected-failure.txt b/tests/expected-failure.txt index d5934a3c5..e57fe6bc2 100644 --- a/tests/expected-failure.txt +++ b/tests/expected-failure.txt @@ -6,6 +6,7 @@ tests/bugs/byte-address-buffer-interlocked-add-f32.slang (vk) tests/bugs/gh-3075.slang.2 (vk) tests/bugs/ray-query-in-generic.slang.1 (vk) tests/bugs/vec-compare.slang.2 (vk) +tests/compute/buffer-layout.slang.2 (vk) tests/compute/half-rw-texture-convert.slang.4 (vk) tests/compute/half-rw-texture-convert2.slang.4 (vk) tests/compute/half-vector-compare.slang.1 (vk) @@ -66,4 +67,4 @@ tests/slang-extension/atomic-min-max-u64-byte-address-buffer.slang.4 (vk) tests/slang-extension/cas-int64-byte-address-buffer.slang.4 (vk) tests/slang-extension/exchange-int64-byte-address-buffer.slang.4 (vk) tests/slang-extension/realtime-clock.slang.2 (vk) -tests/type/texture-sampler/texture-sampler-2d.slang (vk)
\ No newline at end of file +tests/type/texture-sampler/texture-sampler-2d.slang (vk) diff --git a/tests/language-feature/spirv-asm/assignment-syntax.slang b/tests/language-feature/spirv-asm/assignment-syntax.slang new file mode 100644 index 000000000..a511cd92a --- /dev/null +++ b/tests/language-feature/spirv-asm/assignment-syntax.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK: 2 +// CHECK-NEXT: 4 +// CHECK-NEXT: 6 +// CHECK-NEXT: 8 + +// +// This test tests a basic application of the spirv_asm block's assignment syntax +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + %two = OpConstant $$int 2; + result = OpIMul $$int $n %two; + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/debug-instruction.slang b/tests/language-feature/spirv-asm/debug-instruction.slang new file mode 100644 index 000000000..4c25189de --- /dev/null +++ b/tests/language-feature/spirv-asm/debug-instruction.slang @@ -0,0 +1,29 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):-emit-spirv-directly -target spirv-asm -entry computeMain -stage compute + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK: ; Debug Information +// CHECK-NOT: ; Annotations +// CHECK: OpName %{{[a-zA-Z]+}} "INTEGERRRRRRRRRRRRRRRRRRRRR" +// CHECK: ; Annotations + +// +// This test tests that OpName is put in the correct location in the generated spriv +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + spirv_asm + { + OpName $$int "INTEGERRRRRRRRRRRRRRRRRRRRR" + }; + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + OpConstant $$int %two 2; + OpIMul $$int result $n %two + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/enum-lookup.slang b/tests/language-feature/spirv-asm/enum-lookup.slang new file mode 100644 index 000000000..ac4d8e2dd --- /dev/null +++ b/tests/language-feature/spirv-asm/enum-lookup.slang @@ -0,0 +1,26 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK: 2 +// CHECK-NEXT: 4 +// CHECK-NEXT: 6 +// CHECK-NEXT: 8 + +// +// This tests that we can look up a type qualified enum in a spirv block +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + // MemorySemanticsAcquire happens to have value 0x2 + %two : $$int = OpConstant MemorySemanticsAcquire; + result : $$int = OpIMul $n %two + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/id-wrap.slang b/tests/language-feature/spirv-asm/id-wrap.slang new file mode 100644 index 000000000..178ce344e --- /dev/null +++ b/tests/language-feature/spirv-asm/id-wrap.slang @@ -0,0 +1,38 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK: 2 +// CHECK-NEXT: 4 +// CHECK-NEXT: 6 +// CHECK-NEXT: 8 + +// +// This test tests that we correctly wrap constants in ids when required and +// can look up names through that wrapped operand kind +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + OpConstant $$int %two 2; + // A dummy barrier, this tests that we can look up these names without + // their Scope and MemorySemantics prefixes, and correctly wrap them in + // OpConstant. + OpMemoryBarrier Invocation + // Test that an unqualified enum works + AcquireRelease + // Test that a decimal integer literal works + | 64 + // Test that a hex integer literal works + | 0x800 + // Test that an explicit scope works + | MemorySemanticsAtomicCounterMemory; + OpIMul $$int result $n %two + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/opcapability.slang b/tests/language-feature/spirv-asm/opcapability.slang new file mode 100644 index 000000000..7bc9934d7 --- /dev/null +++ b/tests/language-feature/spirv-asm/opcapability.slang @@ -0,0 +1,28 @@ +//TEST:SIMPLE(filecheck=CHECK):-emit-spirv-directly -target spirv-asm -entry computeMain -stage compute + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK-NOT: ; Annotations +// CHECK: OpCapability Matrix +// CHECK: ; Annotations + +// +// This test tests that we can look up unscoped enums based on context, and +// position OpCapability correctly +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + // We should be able to look this up directly, without having to + // specify CapabilityMatrix or anything + OpCapability Matrix; + OpConstant $$int %two 2; + OpIMul $$int result $n %two + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/opextension.slang b/tests/language-feature/spirv-asm/opextension.slang new file mode 100644 index 000000000..da46423a7 --- /dev/null +++ b/tests/language-feature/spirv-asm/opextension.slang @@ -0,0 +1,25 @@ +//TEST:SIMPLE(filecheck=CHECK):-emit-spirv-directly -target spirv-asm -entry computeMain -stage compute + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK-NOT: ; Annotations +// CHECK: OpExtension "SPV_KHR_vulkan_memory_model" +// CHECK: ; Annotations + +// +// This test tests that we can position OpExtension correctly +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + OpExtension "SPV_KHR_vulkan_memory_model"; + OpConstant $$int %two 2; + OpIMul $$int result $n %two + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/too-many-operands.slang b/tests/language-feature/spirv-asm/too-many-operands.slang new file mode 100644 index 000000000..219448699 --- /dev/null +++ b/tests/language-feature/spirv-asm/too-many-operands.slang @@ -0,0 +1,26 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +RWStructuredBuffer<float> buf; + +// +// This test checks that we correctly diagnose passing too many operands to a spriv inst +// +void foo(const int constParam) +{ + spirv_asm + { + // Make sure we diagnose the first offending operand + OpLoad + %a + %b + %c + %d + %e + // CHECK: too-many-operands.slang([[#@LINE-1]]): warning 29104: too many operands for OpLoad (expected max 4), did you forget a semicolon? + %f; + + %r : $$int = OpIAdd %r %r // oops, I forgot the semicolon + OpNop + // CHECK: too-many-operands.slang([[#@LINE-1]]): warning 29104: too many operands for OpIAdd (expected max 4), did you forget a semicolon? + }; +} diff --git a/tests/language-feature/spirv-asm/typed-assignment-syntax.slang b/tests/language-feature/spirv-asm/typed-assignment-syntax.slang new file mode 100644 index 000000000..5e449686e --- /dev/null +++ b/tests/language-feature/spirv-asm/typed-assignment-syntax.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// CHECK: 2 +// CHECK-NEXT: 4 +// CHECK-NEXT: 6 +// CHECK-NEXT: 8 + +// +// This test tests a basic application of the spirv_asm block's typed assignment syntax +// +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int i = dispatchThreadID.x; + int n = outputBuffer[i]; + int r = spirv_asm + { + %two : $$int = OpConstant 2; + result : $$int = OpIMul $n %two; + }; + outputBuffer[i] = r; +} diff --git a/tests/language-feature/spirv-asm/wrong-assignment-opcode.slang b/tests/language-feature/spirv-asm/wrong-assignment-opcode.slang new file mode 100644 index 000000000..4afbb0417 --- /dev/null +++ b/tests/language-feature/spirv-asm/wrong-assignment-opcode.slang @@ -0,0 +1,41 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +RWStructuredBuffer<float> buf; + +// +// This test checks that we correctly diagnose trying to use the assignment and +// typed assignment syntax with operands with no result type or id. +// +// By virtue of these tests being in the same file, we also check the error +// recovery for the asm block parser. +// +int foo(const int constParam) +{ + // Doesn't have a result type + spirv_asm + { + %bar : %wrong = OpTypeInt 32 0 + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 29104: cannot use this 'x : <type> = OpTypeInt...' syntax because OpTypeInt does not have a <result-type-id> operand + + }; + + // Doesn't have a result value + spirv_asm + { + %foo = OpStore 1 2; + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 29104: cannot use this 'x = OpStore...' syntax because OpStore does not have a <result-id> operand + }; + + // garbage + spirv_asm + { + %foo =; + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 20003: unexpected ';' + %foo :; + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 20003: unexpected ';' + %foo : bar; + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 20001: unexpected ';', expected '=' + %foo : bar =; + // CHECK: wrong-assignment-opcode.slang([[#@LINE-1]]): error 20003: unexpected ';' + }; +} |
