Skip to content

Commit 65194cf

Browse files
authored
Add vector overloads for or and and (shader-slang#4529)
* Add vector overloads for or and and Closes shader-slang#4441 and shader-slang#4434 * Disable cuda checks which use unsupported bool vectors * Add tests for 4531
1 parent 388de5f commit 65194cf

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

source/slang/core.meta.slang

+45
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,51 @@ bool and(bool v0, bool v1)
22552255
return __and(v0, v1);
22562256
}
22572257

2258+
[__unsafeForceInlineEarly]
2259+
[OverloadRank(-10)]
2260+
__intrinsic_op($(kIROp_And))
2261+
vector<bool, N> and<let N : int>(vector<bool, N> v0, vector<bool, N> v1);
2262+
2263+
[__unsafeForceInlineEarly]
2264+
[OverloadRank(-10)]
2265+
vector<bool, N> and<let N : int>(bool b, vector<bool, N> v)
2266+
{
2267+
return and(vector<bool, N>(b), v);
2268+
}
2269+
2270+
[__unsafeForceInlineEarly]
2271+
[OverloadRank(-10)]
2272+
vector<bool, N> and<let N : int>(vector<bool, N> v, bool b)
2273+
{
2274+
return and(v, vector<bool, N>(b));
2275+
}
2276+
2277+
[__unsafeForceInlineEarly]
2278+
[OverloadRank(-10)]
2279+
bool or(bool v0, bool v1)
2280+
{
2281+
return __or(v0, v1);
2282+
}
2283+
2284+
[__unsafeForceInlineEarly]
2285+
[OverloadRank(-10)]
2286+
__intrinsic_op($(kIROp_Or))
2287+
vector<bool, N> or<let N : int>(vector<bool, N> v0, vector<bool, N> v1);
2288+
2289+
[__unsafeForceInlineEarly]
2290+
[OverloadRank(-10)]
2291+
vector<bool, N> or<let N : int>(bool b, vector<bool, N> v)
2292+
{
2293+
return or(vector<bool, N>(b), v);
2294+
}
2295+
2296+
[__unsafeForceInlineEarly]
2297+
[OverloadRank(-10)]
2298+
vector<bool, N> or<let N : int>(vector<bool, N> v, bool b)
2299+
{
2300+
return or(v, vector<bool, N>(b));
2301+
}
2302+
22582303
__generic<T : ILogical>
22592304
[__unsafeForceInlineEarly]
22602305
[OverloadRank(-10)]

tests/bugs/gh-4434.slang

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil
2+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk
3+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl
4+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu
5+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda
6+
7+
// CHECK: 1
8+
// CHECK-NEXT: 1
9+
// CHECK-NEXT: 1
10+
// CHECK-NEXT: 1
11+
12+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
13+
RWStructuredBuffer<uint> outputBuffer;
14+
15+
[numthreads(4, 1, 1)]
16+
void computeMain(uint tid : SV_GroupIndex)
17+
{
18+
bool a, b, c;
19+
c = and(a, b);
20+
21+
bool1 i, j, k;
22+
bool2 l, m, n;
23+
bool3 o, p, q;
24+
bool4 r, s, t;
25+
k = and(i, j);
26+
n = and(m, l);
27+
q = and(o, p);
28+
t = and(r, s);
29+
30+
k = !and(k, false);
31+
n = !and(n, false);
32+
q = !and(q, false);
33+
t = !and(t, false);
34+
35+
outputBuffer[tid] = all(k) && all(n) && all(q) && all(t);
36+
}

tests/bugs/gh-4441.slang

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil
2+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk
3+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl
4+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu
5+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda
6+
7+
// CHECK: 1
8+
// CHECK-NEXT: 1
9+
// CHECK-NEXT: 1
10+
// CHECK-NEXT: 1
11+
12+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
13+
RWStructuredBuffer<uint> outputBuffer;
14+
15+
[numthreads(4, 1, 1)]
16+
void computeMain(uint tid : SV_GroupIndex)
17+
{
18+
bool a, b, c;
19+
c = or(a, b);
20+
21+
bool1 i, j, k;
22+
bool2 l, m, n;
23+
bool3 o, p, q;
24+
bool4 r, s, t;
25+
k = or(i, j);
26+
n = or(m, l);
27+
q = or(o, p);
28+
t = or(r, s);
29+
30+
k = or(k, true);
31+
n = or(n, true);
32+
q = or(q, true);
33+
t = or(t, true);
34+
35+
outputBuffer[tid] = all(k) && all(n) && all(q) && all(t);
36+
}

tests/bugs/gh-4531.slang

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil
2+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk
3+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl
4+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu
5+
//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda
6+
7+
// CHECK: 1
8+
// CHECK-NEXT: 1
9+
// CHECK-NEXT: 1
10+
// CHECK-NEXT: 1
11+
12+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
13+
RWStructuredBuffer<uint> outputBuffer;
14+
15+
[numthreads(4, 1, 1)]
16+
void computeMain(uint tid : SV_GroupIndex)
17+
{
18+
vector<bool,4> k = true;
19+
outputBuffer[tid] = all(k);
20+
}

tests/bugs/gh-4533.slang

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ RWStructuredBuffer<uint> outputBuffer;
1616
void computeMain(uint tid : SV_GroupIndex)
1717
{
1818
vector<float,1> k = float1(tid);
19-
outputBuffer[tid] = all(k) && any(k) && bool(asint(k)) && bool(asuint(k));
19+
outputBuffer[tid] = all(k) && any(k) && bool(asint(k)) && bool(asuint(k)) && bool(sign(k));
2020
}

0 commit comments

Comments
 (0)