From dab6cec1ed78a545c127adc0e8dbdf1f253f9132 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Thu, 9 Jan 2025 07:43:31 +0200 Subject: Add parentheses to make precedence explicit (#6030) * Add parentheses to make precedence explicit Add parentheses for a few cases that Dawn/Tint (WGSL compiler) complains about. Closes #6005. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- tests/wgsl/operator-precedence.slang | 45 +++++++++++++++++++++++ tests/wgsl/operator-precedence.slang.expected.txt | 20 ++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/wgsl/operator-precedence.slang create mode 100644 tests/wgsl/operator-precedence.slang.expected.txt (limited to 'tests') diff --git a/tests/wgsl/operator-precedence.slang b/tests/wgsl/operator-precedence.slang new file mode 100644 index 000000000..8e90991d6 --- /dev/null +++ b/tests/wgsl/operator-precedence.slang @@ -0,0 +1,45 @@ +//TEST(compute):COMPARE_COMPUTE:-shaderobj + +//TEST_INPUT:ubuffer(data=[3 7 8], stride=4):name=inputBuffer +RWStructuredBuffer inputBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + uint a = inputBuffer[0]; + uint b = inputBuffer[1]; + uint c = inputBuffer[2]; + + outputBuffer[0] = a+b ^ c; + outputBuffer[1] = a ^ b+c; + + outputBuffer[2] = a-b | c; + outputBuffer[3] = a | b-c; + + outputBuffer[4] = a+b & c; + outputBuffer[5] = a & b+c; + + outputBuffer[6] = a<>b | c; + outputBuffer[9] = a | b>>c; + + outputBuffer[10] = a<=c; + + outputBuffer[14] = a*b ^ c; + outputBuffer[15] = a ^ b*c; + + outputBuffer[16] = a/b | c; + outputBuffer[17] = a | b/c; + + outputBuffer[18] = a*b & c; + outputBuffer[19] = a & b*c; +} diff --git a/tests/wgsl/operator-precedence.slang.expected.txt b/tests/wgsl/operator-precedence.slang.expected.txt new file mode 100644 index 000000000..ba2e4b9ab --- /dev/null +++ b/tests/wgsl/operator-precedence.slang.expected.txt @@ -0,0 +1,20 @@ +2 +C +FFFFFFFC +FFFFFFFF +8 +3 +188 +703 +8 +3 +0 +0 +1 +0 +1D +3B +8 +3 +0 +0 -- cgit v1.2.3