summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-08-26 18:58:44 +0000
committerGitHub <noreply@github.com>2025-08-26 18:58:44 +0000
commit4e9ee1dc80ce353640c1e2134249a1f93da9229a (patch)
treef42b72d090e88304c2792052a225e1cfaa05bcb9 /source/slang
parent0b87355f946b9a0f8b7fa9225369dade3d5bf84a (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 'source/slang')
-rw-r--r--source/slang/slang-emit-metal.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp
index 9858e51a1..b19e85044 100644
--- a/source/slang/slang-emit-metal.cpp
+++ b/source/slang/slang-emit-metal.cpp
@@ -1071,9 +1071,7 @@ void MetalSourceEmitter::emitSimpleTypeImpl(IRType* type)
{
case kIROp_VoidType:
case kIROp_BoolType:
- case kIROp_Int8Type:
case kIROp_IntType:
- case kIROp_UInt8Type:
case kIROp_UIntType:
case kIROp_FloatType:
case kIROp_HalfType:
@@ -1081,6 +1079,12 @@ void MetalSourceEmitter::emitSimpleTypeImpl(IRType* type)
m_writer->emit(getDefaultBuiltinTypeName(type->getOp()));
return;
}
+ case kIROp_Int8Type:
+ m_writer->emit("char");
+ return;
+ case kIROp_UInt8Type:
+ m_writer->emit("uchar");
+ return;
case kIROp_Int64Type:
m_writer->emit("long");
return;