summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-02-28 16:23:29 -0500
committerGitHub <noreply@github.com>2025-02-28 13:23:29 -0800
commitefbfa7832afff7e6285713086259abda2456ed55 (patch)
treed5a94eb66867d7f9dc01e4c1a25502443bf71040 /tests
parent618b4c7657f539e66f032cd40554798bc0d68f6d (diff)
Add Slang-specific intrinsics for integer pack/unpack (#6459)
* update hlsl meta * update test * use slang syntax in meta file * improve meta file * fix pack clamp u8 * remove builtin packed types, use typealias instead * fix wgsl pack clamp * fix formatting --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/hlsl-intrinsic/packed/pack-unpack.slang157
-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
5 files changed, 134 insertions, 154 deletions
diff --git a/tests/hlsl-intrinsic/packed/pack-unpack.slang b/tests/hlsl-intrinsic/packed/pack-unpack.slang
index b20e69fa8..0b9490ee4 100644
--- a/tests/hlsl-intrinsic/packed/pack-unpack.slang
+++ b/tests/hlsl-intrinsic/packed/pack-unpack.slang
@@ -9,6 +9,18 @@
// Debug info for inlining errors can be given out, so disable them for this test.
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -g0
+//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -render-feature hardware-device -xslang -DUSE_SLANG_SYNTAX
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile cs_6_6 -dx12 -use-dxil -shaderobj -render-feature hardware-device -xslang -DUSE_SLANG_SYNTAX
+//TEST(compute):COMPARE_COMPUTE_EX:-metal -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
+
+// 16 bit variants are not supported by WGSL.
+//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj -xslang -DWGSL -xslang -DUSE_SLANG_SYNTAX
+// Debug info for inlining errors can be given out, so disable them for this test.
+//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -g0 -xslang -DUSE_SLANG_SYNTAX
+
+
//TEST_INPUT:ubuffer(data=[0xD37A83FF], stride=4):name unpackTestBuffer
StructuredBuffer<uint32_t> unpackTestBuffer;
@@ -27,17 +39,125 @@ StructuredBuffer<int32_t4> packClampSTestBuffer;
//TEST_INPUT:ubuffer(data=[0 0 0 0 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<uint> outputBuffer;
+uint32_t4 __unpack_u8u32(uint value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return unpackUint4x8ToUint32(value);
+#else
+ return unpack_u8u32(uint8_t4_packed(value));
+#endif
+}
+
+uint16_t4 __unpack_u8u16(uint value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return unpackUint4x8ToUint16(value);
+#else
+ return unpack_u8u16(uint8_t4_packed(value));
+#endif
+}
+
+int32_t4 __unpack_s8s32(uint value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return unpackInt4x8ToInt32(value);
+#else
+ return unpack_s8s32(int8_t4_packed(value));
+#endif
+}
+
+int16_t4 __unpack_s8s16(uint value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return unpackInt4x8ToInt16(value);
+#else
+ return unpack_s8s16(int8_t4_packed(value));
+#endif
+}
+
+uint __pack_u8(uint32_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packUint4x8(value);
+#else
+ return uint(pack_u8(value));
+#endif
+}
+
+uint __pack_u8(uint16_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packUint4x8(value);
+#else
+ return uint(pack_u8(value));
+#endif
+}
+
+uint __pack_s8(int32_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packInt4x8(value);
+#else
+ return uint(pack_s8(value));
+#endif
+}
+
+uint __pack_s8(int16_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packInt4x8(value);
+#else
+ return uint(pack_s8(value));
+#endif
+}
+
+uint __pack_clamp_u8(int32_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packUint4x8Clamp(value);
+#else
+ return uint(pack_clamp_u8(value));
+#endif
+}
+
+uint __pack_clamp_u8(int16_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packUint4x8Clamp(value);
+#else
+ return uint(pack_clamp_u8(value));
+#endif
+}
+
+uint __pack_clamp_s8(int32_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packInt4x8Clamp(value);
+#else
+ return uint(pack_clamp_s8(value));
+#endif
+}
+
+uint __pack_clamp_s8(int16_t4 value)
+{
+#if defined(USE_SLANG_SYNTAX)
+ return packInt4x8Clamp(value);
+#else
+ return uint(pack_clamp_s8(value));
+#endif
+}
+
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
- const uint8_t4_packed unpackTestValue = uint8_t4_packed(unpackTestBuffer[0]);
+ const uint unpackTestValue = unpackTestBuffer[0];
uint index = 0;
/*
* Unpack without sign extension.
*/
- uint32_t4 unpackedU32 = unpack_u8u32(unpackTestValue);
+ uint32_t4 unpackedU32 = __unpack_u8u32(unpackTestValue);
// 0xFF
outputBuffer[index++] = uint(unpackedU32.x);
// 0x83
@@ -48,7 +168,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
outputBuffer[index++] = uint(unpackedU32.w);
#if !defined(WGSL)
- uint16_t4 unpackedU16 = unpack_u8u16(unpackTestValue);
+ uint16_t4 unpackedU16 = __unpack_u8u16(unpackTestValue);
// 0xFF
outputBuffer[index++] = uint(unpackedU16.x);
// 0x83
@@ -67,7 +187,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
/*
* Unpack with sign extension.
*/
- int32_t4 unpackedS32 = unpack_s8s32(int8_t4_packed(unpackTestValue));
+ int32_t4 unpackedS32 = __unpack_s8s32(unpackTestValue);
// 0xFFFFFFFF
outputBuffer[index++] = uint(unpackedS32.x);
// 0xFFFFFF83
@@ -78,7 +198,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
outputBuffer[index++] = uint(unpackedS32.w);
#if !defined(WGSL)
- int16_t4 unpackedS16 = unpack_s8s16(int8_t4_packed(unpackTestValue));
+ int16_t4 unpackedS16 = __unpack_s8s16(unpackTestValue);
// 0xFFFFFFFF
outputBuffer[index++] = uint(unpackedS16.x);
// 0xFFFFFF83
@@ -100,22 +220,17 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
*/
uint32_t4 packU32TestValues = packTestBuffer[0];
int32_t4 packS32TestValues = packU32TestValues;
- uint8_t4_packed packU32Result = pack_u8(packU32TestValues);
- int8_t4_packed packS32Result = pack_s8(packS32TestValues);
// 0xD4236A3F
- outputBuffer[index++] = uint(packU32Result);
- outputBuffer[index++] = uint(packS32Result);
+ outputBuffer[index++] = __pack_u8(packU32TestValues);
+ outputBuffer[index++] = __pack_s8(packS32TestValues);
#if !defined(WGSL)
uint16_t4 packU16TestValues = int16_t4(int16_t(packU32TestValues.x), int16_t(packU32TestValues.y),
int16_t(packU32TestValues.z), int16_t(packU32TestValues.w));
int16_t4 packS16TestValues = packU16TestValues;
- uint8_t4_packed packU16Result = pack_u8(packU16TestValues);
- int8_t4_packed packS16Result = pack_s8(packS16TestValues);
-
- outputBuffer[index++] = uint(packU16Result);
- outputBuffer[index++] = uint(packS16Result);
+ outputBuffer[index++] = __pack_u8(packU16TestValues);
+ outputBuffer[index++] = __pack_s8(packS16TestValues);
#else
outputBuffer[index++] = 0xD4236A3F;
outputBuffer[index++] = 0xD4236A3F;
@@ -123,17 +238,15 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
/*
* Pack with unsigned clamping.
- */
+ */
int32_t4 packClampU32TestValues = packClampUTestBuffer[0];
- uint8_t4_packed packClampU32Result = pack_clamp_u8(packClampU32TestValues);
// 0xFEFFFF05
- outputBuffer[index++] = uint(packClampU32Result);
+ outputBuffer[index++] = __pack_clamp_u8(packClampU32TestValues);
#if !defined(WGSL)
int16_t4 packClampU16TestValues = int16_t4(int16_t(packClampU32TestValues.x), int16_t(packClampU32TestValues.y),
int16_t(packClampU32TestValues.z), int16_t(packClampU32TestValues.w));
- uint8_t4_packed packClampU16Result = pack_clamp_u8(packClampU16TestValues);
- outputBuffer[index++] = uint(packClampU16Result);
+ outputBuffer[index++] = __pack_clamp_u8(packClampU16TestValues);
#else
outputBuffer[index++] = 0xFEFFFF05;
#endif
@@ -142,15 +255,13 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
* Pack with signed clamping
*/
int32_t4 packClampS32TestValues = packClampSTestBuffer[0];
- int8_t4_packed packClampS32Result = pack_clamp_s8(packClampS32TestValues);
// 0x81807FFF
- outputBuffer[index++] = uint(packClampS32Result);
+ outputBuffer[index++] = __pack_clamp_s8(packClampS32TestValues);
#if !defined(WGSL)
int16_t4 packClampS16TestValues = int16_t4(int16_t(packClampS32TestValues.x), int16_t(packClampS32TestValues.y),
int16_t(packClampS32TestValues.z), int16_t(packClampS32TestValues.w));
- int8_t4_packed packClampS16Result = pack_clamp_s8(packClampS16TestValues);
- outputBuffer[index++] = uint(packClampS16Result);
+ outputBuffer[index++] = __pack_clamp_s8(packClampS16TestValues);
#else
outputBuffer[index++] = 0x81807FFF;
#endif
diff --git a/tests/hlsl-intrinsic/packed/packed-types-error.slang b/tests/hlsl-intrinsic/packed/packed-types-error.slang
deleted file mode 100644
index 7034f50a9..000000000
--- a/tests/hlsl-intrinsic/packed/packed-types-error.slang
+++ /dev/null
@@ -1,21 +0,0 @@
-//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
deleted file mode 100644
index 0b46925a4..000000000
--- a/tests/hlsl-intrinsic/packed/packed-types-warning.slang
+++ /dev/null
@@ -1,72 +0,0 @@
-//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
deleted file mode 100644
index 0bbc6f404..000000000
--- a/tests/hlsl-intrinsic/packed/packed-types.slang
+++ /dev/null
@@ -1,36 +0,0 @@
-//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
deleted file mode 100644
index a348b3dfd..000000000
--- a/tests/hlsl-intrinsic/packed/packed-types.slang.expected.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-D37A83FF
-DEADBEEF