From 4e9ee1dc80ce353640c1e2134249a1f93da9229a Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 Aug 2025 18:58:44 +0000 Subject: Fix Metal 8-bit vector type names: emit char/uchar instead of int8_t/uint8_t (#8223) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Metal backend was generating incorrect type names for 8-bit vector types, causing compilation failures when targeting Metal. According to the Metal specification, 8-bit vector types should be named `charN` and `ucharN` (e.g., `char2`, `uchar3`) rather than `int8_tN` and `uint8_tN`. ## Problem When compiling Slang code with 8-bit vector types for Metal, the compiler would emit: ```metal uint8_t2 _S8 = uint8_t2(uint8_t(0U), uint8_t(16U)); int8_t3 _S9 = int8_t3(int8_t(0), int8_t(16), int8_t(48)); ``` But the Metal compiler expects: ```metal uchar2 _S8 = uchar2(uint8_t(0U), uint8_t(16U)); char3 _S9 = char3(int8_t(0), int8_t(16), int8_t(48)); ``` This caused errors like: ``` error: unknown type name 'uint8_t2'; did you mean 'uint8_t'? ``` ## Solution Modified `MetalSourceEmitter::emitSimpleTypeImpl()` to emit the correct Metal-specific type names for 8-bit types: - `kIROp_Int8Type` now emits `char` instead of `int8_t` - `kIROp_UInt8Type` now emits `uchar` instead of `uint8_t` This change only affects the Metal backend and ensures that vector types like `int8_t2`, `uint8_t3`, etc. are correctly emitted as `char2`, `uchar3`, etc. ## Testing - Added a new test case `tests/metal/8bit-vector-types.slang` to verify the fix - Re-enabled the previously disabled Metal test in `tests/hlsl-intrinsic/countbits8.slang` - Updated `tests/metal/byte-address-buffer.slang` to expect the correct type names - Verified that existing Metal tests continue to pass Fixes #8211. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com> --- tests/metal/8bit-vector-types.slang | 24 ++++++++++++++++++++++++ tests/metal/byte-address-buffer.slang | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/metal/8bit-vector-types.slang (limited to 'tests/metal') diff --git a/tests/metal/8bit-vector-types.slang b/tests/metal/8bit-vector-types.slang new file mode 100644 index 000000000..8bfb65fc8 --- /dev/null +++ b/tests/metal/8bit-vector-types.slang @@ -0,0 +1,24 @@ +//TEST:SIMPLE(filecheck=CHECK): -target metal -stage compute -entry computeMain + +RWStructuredBuffer outputBuffer; + +uint8_t2 createUChar2() +{ + return uint8_t2(1, 2); +} + +int8_t2 createChar2() +{ + return int8_t2(3, 4); +} + +[numthreads(1, 1, 1)] +void computeMain() +{ + // CHECK: uchar2 + // CHECK: char2 + uint8_t2 u8v2 = createUChar2(); + int8_t2 i8v2 = createChar2(); + + outputBuffer[0] = u8v2.x + i8v2.x; +} \ No newline at end of file diff --git a/tests/metal/byte-address-buffer.slang b/tests/metal/byte-address-buffer.slang index 8514dafe6..c0fb6b6b2 100644 --- a/tests/metal/byte-address-buffer.slang +++ b/tests/metal/byte-address-buffer.slang @@ -18,7 +18,7 @@ struct TestStruct void main_kernel(uint3 tid: SV_DispatchThreadID) { // CHECK: uint [[WORD0:[a-zA-Z0-9_]+]] = as_type({{.*}}[(0U)>>2]); - // CHECK: uint8_t [[A:[a-zA-Z0-9_]+]] = uint8_t(([[WORD0]] >> 0U) & 255U); + // CHECK: uchar [[A:[a-zA-Z0-9_]+]] = uchar(([[WORD0]] >> 0U) & 255U); // CHECK: uint [[WORD1:[a-zA-Z0-9_]+]] = as_type({{.*}}[(0U)>>2]); // CHECK: half [[H:[a-zA-Z0-9_]+]] = as_type(ushort(([[WORD1]] >> 16U) & 65535U)); -- cgit v1.2.3