diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-07-05 21:09:13 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-05 21:09:13 +0800 |
| commit | 65194cf0a926267839ff56e47c1a1eb14e2b0977 (patch) | |
| tree | 40604c6bcb555c8e1e53d35e7d013f40c5964827 | |
| parent | 388de5f68ebef556f9addcf36685109d2524ee4e (diff) | |
Add vector overloads for or and and (#4529)
* Add vector overloads for or and and
Closes #4441 and #4434
* Disable cuda checks which use unsupported bool vectors
* Add tests for 4531
| -rw-r--r-- | source/slang/core.meta.slang | 45 | ||||
| -rw-r--r-- | tests/bugs/gh-4434.slang | 36 | ||||
| -rw-r--r-- | tests/bugs/gh-4441.slang | 36 | ||||
| -rw-r--r-- | tests/bugs/gh-4531.slang | 20 | ||||
| -rw-r--r-- | tests/bugs/gh-4533.slang | 2 |
5 files changed, 138 insertions, 1 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 631c09d19..a8badc05a 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -2255,6 +2255,51 @@ bool and(bool v0, bool v1) return __and(v0, v1); } +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +__intrinsic_op($(kIROp_And)) +vector<bool, N> and<let N : int>(vector<bool, N> v0, vector<bool, N> v1); + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +vector<bool, N> and<let N : int>(bool b, vector<bool, N> v) +{ + return and(vector<bool, N>(b), v); +} + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +vector<bool, N> and<let N : int>(vector<bool, N> v, bool b) +{ + return and(v, vector<bool, N>(b)); +} + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +bool or(bool v0, bool v1) +{ + return __or(v0, v1); +} + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +__intrinsic_op($(kIROp_Or)) +vector<bool, N> or<let N : int>(vector<bool, N> v0, vector<bool, N> v1); + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +vector<bool, N> or<let N : int>(bool b, vector<bool, N> v) +{ + return or(vector<bool, N>(b), v); +} + +[__unsafeForceInlineEarly] +[OverloadRank(-10)] +vector<bool, N> or<let N : int>(vector<bool, N> v, bool b) +{ + return or(v, vector<bool, N>(b)); +} + __generic<T : ILogical> [__unsafeForceInlineEarly] [OverloadRank(-10)] diff --git a/tests/bugs/gh-4434.slang b/tests/bugs/gh-4434.slang new file mode 100644 index 000000000..975226008 --- /dev/null +++ b/tests/bugs/gh-4434.slang @@ -0,0 +1,36 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda + +// CHECK: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<uint> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + bool a, b, c; + c = and(a, b); + + bool1 i, j, k; + bool2 l, m, n; + bool3 o, p, q; + bool4 r, s, t; + k = and(i, j); + n = and(m, l); + q = and(o, p); + t = and(r, s); + + k = !and(k, false); + n = !and(n, false); + q = !and(q, false); + t = !and(t, false); + + outputBuffer[tid] = all(k) && all(n) && all(q) && all(t); +} diff --git a/tests/bugs/gh-4441.slang b/tests/bugs/gh-4441.slang new file mode 100644 index 000000000..59d577c8d --- /dev/null +++ b/tests/bugs/gh-4441.slang @@ -0,0 +1,36 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda + +// CHECK: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<uint> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + bool a, b, c; + c = or(a, b); + + bool1 i, j, k; + bool2 l, m, n; + bool3 o, p, q; + bool4 r, s, t; + k = or(i, j); + n = or(m, l); + q = or(o, p); + t = or(r, s); + + k = or(k, true); + n = or(n, true); + q = or(q, true); + t = or(t, true); + + outputBuffer[tid] = all(k) && all(n) && all(q) && all(t); +} diff --git a/tests/bugs/gh-4531.slang b/tests/bugs/gh-4531.slang new file mode 100644 index 000000000..e84c4713f --- /dev/null +++ b/tests/bugs/gh-4531.slang @@ -0,0 +1,20 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu +//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda + +// CHECK: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<uint> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + vector<bool,4> k = true; + outputBuffer[tid] = all(k); +} diff --git a/tests/bugs/gh-4533.slang b/tests/bugs/gh-4533.slang index 3ee27996b..a483c89b9 100644 --- a/tests/bugs/gh-4533.slang +++ b/tests/bugs/gh-4533.slang @@ -16,5 +16,5 @@ RWStructuredBuffer<uint> outputBuffer; void computeMain(uint tid : SV_GroupIndex) { vector<float,1> k = float1(tid); - outputBuffer[tid] = all(k) && any(k) && bool(asint(k)) && bool(asuint(k)); + outputBuffer[tid] = all(k) && any(k) && bool(asint(k)) && bool(asuint(k)) && bool(sign(k)); } |
