diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-08-26 18:58:44 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-26 18:58:44 +0000 |
| commit | 4e9ee1dc80ce353640c1e2134249a1f93da9229a (patch) | |
| tree | f42b72d090e88304c2792052a225e1cfaa05bcb9 /tests/hlsl-intrinsic | |
| parent | 0b87355f946b9a0f8b7fa9225369dade3d5bf84a (diff) | |
Fix Metal 8-bit vector type names: emit char/uchar instead of int8_t/uint8_t (#8223)
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.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 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>
Diffstat (limited to 'tests/hlsl-intrinsic')
| -rw-r--r-- | tests/hlsl-intrinsic/countbits8.slang | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/hlsl-intrinsic/countbits8.slang b/tests/hlsl-intrinsic/countbits8.slang index 0426b5682..c73d815a5 100644 --- a/tests/hlsl-intrinsic/countbits8.slang +++ b/tests/hlsl-intrinsic/countbits8.slang @@ -1,8 +1,8 @@ //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -cpu //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -vk -compute //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -cuda -compute -//TODO: metal is currently failing even with emulation, investigate. -//DISABLE_TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -mtl -compute -profile metallib_2_4 +//TODO: metal was previously failing but should work now after fixing vector type names +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -mtl -compute -profile metallib_2_4 // Not testing the following: // -dx12/hlsl, No support for uint8_t with hlsl // -wgpu, only has 32-bit support |
