summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2024-12-27 02:52:49 -0500
committerGitHub <noreply@github.com>2024-12-26 23:52:49 -0800
commit7cecc518e753a90d9b638e8dd1140730ab010ca7 (patch)
tree2d8769853421ffda8671e7d10b79e53f2e9c25f9 /tests
parent2ad1f8138771cef32b710f8c47d4c7beb3f4eab5 (diff)
Add packed 8bit builtin types (#5939)
* Add packed bytes builtin type * fix test
Diffstat (limited to 'tests')
-rw-r--r--tests/hlsl-intrinsic/packed/packed-types-error.slang21
-rw-r--r--tests/hlsl-intrinsic/packed/packed-types-warning.slang72
-rw-r--r--tests/hlsl-intrinsic/packed/packed-types.slang36
-rw-r--r--tests/hlsl-intrinsic/packed/packed-types.slang.expected.txt2
4 files changed, 131 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/packed/packed-types-error.slang b/tests/hlsl-intrinsic/packed/packed-types-error.slang
new file mode 100644
index 000000000..7034f50a9
--- /dev/null
+++ b/tests/hlsl-intrinsic/packed/packed-types-error.slang
@@ -0,0 +1,21 @@
+//TEST(compute):SIMPLE(filecheck=CHECK): -target spirv
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
+ uint8_t4_packed packedU1 = 0x0U;
+ uint8_t4_packed packedU2 = 0xFU;
+ int8_t4_packed packedS1 = 0xFU;
+ int8_t4_packed packedS2 = 0xFU;
+
+ // Arithmetic and logical (bitwise) operations are not supported on packed types.
+ // An attempt to overload these operators will fail during compilation due to ambiguity caused by multiple possible overloads.
+
+ // CHECK: error 39999: ambiguous call to '-' with arguments of type
+ uint8_t4_packed val1 = packedU1 - packedU2;
+ // CHECK: error 39999: ambiguous call to '*' with arguments of type
+ int8_t4_packed val2 = packedS1 * packedS2;
+ // CHECK: error 39999: ambiguous call to '&' with arguments of type
+ uint8_t4_packed val3 = packedU1 & packedS1;
+ // CHECK: error 39999: ambiguous call to '|' with arguments of type
+ int8_t4_packed val4 = packedU1 | packedS1;
+}
diff --git a/tests/hlsl-intrinsic/packed/packed-types-warning.slang b/tests/hlsl-intrinsic/packed/packed-types-warning.slang
new file mode 100644
index 000000000..0b46925a4
--- /dev/null
+++ b/tests/hlsl-intrinsic/packed/packed-types-warning.slang
@@ -0,0 +1,72 @@
+//TEST(compute):SIMPLE(filecheck=CHECK): -target spirv
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
+ uint8_t4_packed packedU = 0U;
+ int8_t4_packed packedS = 0xFU;
+ uint val1 = 0xFU;
+
+ //
+ // Implicit conversions between the packed types are not OK, they must be explicit.
+ //
+
+ // CHECK: warning 30081: implicit conversion from 'int8_t4_packed' to 'uint8_t4_packed' is not recommended
+ packedU = packedS;
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'int8_t4_packed' is not recommended
+ packedS = packedU;
+
+
+ // Implicit casting from 32 bit literals are OK.
+ packedU = 32U;
+ packedS = 32;
+
+ // Implicit casting from 64 bit literals are not OK.
+ // CHECK: warning 30081: implicit conversion from 'uint64_t' to 'uint8_t4_packed' is not recommended
+ packedU = 0xFFFFFFFFFFULL;
+ // CHECK: warning 30081: implicit conversion from 'int64_t' to 'uint8_t4_packed' is not recommended
+ packedU = 0xFFFFFFFFFFLL;
+
+ //
+ // Explicit casting from other builtin integer types are OK.
+ //
+ packedU = uint8_t4_packed(val1);
+ packedU = uint8_t4_packed(uint16_t(123));
+ val1 = uint(packedS);
+
+ //
+ // Implicit casting from other builtin integer types are not OK.
+ //
+
+ // CHECK: warning 30081: implicit conversion from 'uint' to 'uint8_t4_packed' is not recommended
+ packedU = val1;
+ // CHECK: warning 30081: implicit conversion from 'uint' to 'int8_t4_packed' is not recommended
+ packedS = val1;
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'uint' is not recommended
+ val1 = packedU;
+ // CHECK: warning 30081: implicit conversion from 'int8_t4_packed' to 'uint' is not recommended
+ val1 = packedS;
+
+ // CHECK: warning 30081: implicit conversion from 'uint8_t' to 'uint8_t4_packed' is not recommended
+ packedU = uint8_t(1);
+ // CHECK: warning 30081: implicit conversion from 'int64_t' to 'int8_t4_packed' is not recommended
+ packedS = int64_t(1);
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'uint64_t' is not recommended
+ uint64_t val2 = packedU;
+ // CHECK: warning 30081: implicit conversion from 'int8_t4_packed' to 'int16_t' is not recommended
+ int16_t val3 = packedS;
+
+ //
+ // Arithmetic and logical (bitwise) operations are not supported on packed types,
+ // but overload to integer types will be made and unrecommended conversion warnings
+ // should be thrown out.
+ //
+
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'int' is not recommended
+ packedU = uint8_t4_packed(packedU + 32);
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'int' is not recommended
+ packedU = uint8_t4_packed(packedU / 2);
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'int' is not recommended
+ packedU = uint8_t4_packed(packedU | 0xF);
+ // CHECK: warning 30081: implicit conversion from 'uint8_t4_packed' to 'int' is not recommended
+ packedU = uint8_t4_packed(packedU & 0x3);
+}
diff --git a/tests/hlsl-intrinsic/packed/packed-types.slang b/tests/hlsl-intrinsic/packed/packed-types.slang
new file mode 100644
index 000000000..0bbc6f404
--- /dev/null
+++ b/tests/hlsl-intrinsic/packed/packed-types.slang
@@ -0,0 +1,36 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -render-feature hardware-device
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile cs_6_6 -dx12 -use-dxil -shaderobj -render-feature hardware-device
+//TEST(compute):COMPARE_COMPUTE_EX:-metal -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -g0
+
+//TEST_INPUT:ubuffer(data=[0xD37A83FF], stride=4):name packedUArray
+StructuredBuffer<uint8_t4_packed> packedUArray;
+
+//TEST_INPUT:ubuffer(data=[0xDEADBEEF], stride=4):name packedSArray
+StructuredBuffer<int8_t4_packed> packedSArray;
+
+//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<uint8_t4_packed> outputBuffer;
+
+// Test type layout works.
+struct Custom {
+ uint8_t4_packed packedU;
+ uint3 other1;
+ int8_t4_packed packedS;
+ float other2;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
+ uint id = dispatchThreadID.x;
+
+ Custom val;
+ val.packedU = packedUArray[id];
+ val.packedS = packedSArray[id];
+
+ outputBuffer[id] = val.packedU;
+ outputBuffer[id + 1] = uint8_t4_packed(val.packedS);
+}
diff --git a/tests/hlsl-intrinsic/packed/packed-types.slang.expected.txt b/tests/hlsl-intrinsic/packed/packed-types.slang.expected.txt
new file mode 100644
index 000000000..a348b3dfd
--- /dev/null
+++ b/tests/hlsl-intrinsic/packed/packed-types.slang.expected.txt
@@ -0,0 +1,2 @@
+D37A83FF
+DEADBEEF