diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2025-07-15 17:45:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-16 00:45:23 +0000 |
| commit | 223ccd40599ffcd74b409c7321f2264b93aec4bd (patch) | |
| tree | 4b3cdbc80428ec4667becce938fe5592e5c9c862 | |
| parent | 299eb0c889322a960d1907b6722ee1caf88475a4 (diff) | |
Fix Metal pointer type emission in entry point parameters (#7759)
* Fix Metal pointer type emission in entry point parameters
Add missing default case in Metal emitter's address space switch to
preserve pointer types. Previously, unrecognized address spaces would
fall through without emitting pointer syntax, causing uint64_t* to
become ulong instead of ulong constant*.
Fixes #7605, #6174
* Treat AddressSpace::UserPointer as Global in Metal
Also adding another test for `uniform` keyword
| -rw-r--r-- | source/slang/slang-emit-metal.cpp | 4 | ||||
| -rw-r--r-- | tests/metal/metal-pointer-params.slang | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp index 9232fc95d..d3b00d57d 100644 --- a/source/slang/slang-emit-metal.cpp +++ b/source/slang/slang-emit-metal.cpp @@ -1163,6 +1163,7 @@ void MetalSourceEmitter::emitSimpleTypeImpl(IRType* type) switch (ptrType->getAddressSpace()) { case AddressSpace::Global: + case AddressSpace::UserPointer: m_writer->emit(" device"); m_writer->emit("*"); break; @@ -1182,6 +1183,9 @@ void MetalSourceEmitter::emitSimpleTypeImpl(IRType* type) m_writer->emit(" object_data"); m_writer->emit("*"); break; + default: + SLANG_UNEXPECTED("Unknown addressspace encountered."); + break; } return; } diff --git a/tests/metal/metal-pointer-params.slang b/tests/metal/metal-pointer-params.slang new file mode 100644 index 000000000..6bb7114ee --- /dev/null +++ b/tests/metal/metal-pointer-params.slang @@ -0,0 +1,28 @@ +//TEST:SIMPLE(filecheck=CHECK): -target metal -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHK_AIR): -target metallib -stage compute -entry computeMain + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=8):out,name=outputBuffer +RWStructuredBuffer<uint64_t> outputBuffer; + +//CHECK: ulong{{.*}}device{{ *\*}} a +//CHECK-NEXT: long{{.*}}device{{ *\*}} b +//CHECK-NEXT: uint{{.*}}device{{ *\*}} c +//CHECK-NEXT: int{{.*}}device{{ *\*}} d +//CHECK-NEXT: float{{.*}}device{{ *\*}} e + +// "indirect_argument" means a pointer +//CHK_AIR: !"ulong", !"a{{[^"]*}}", !"air.indirect_argument" +//CHK_AIR: !"long", !"b{{[^"]*}}", !"air.indirect_argument" +//CHK_AIR: !"uint", !"c{{[^"]*}}", !"air.indirect_argument" +//CHK_AIR: !"int", !"d{{[^"]*}}", !"air.indirect_argument" +//CHK_AIR: !"float", !"e{{[^"]*}}", !"air.indirect_argument" + +[numthreads(1,1,1)] +void computeMain(uniform uint64_t* a, uniform int64_t* b, uniform uint32_t* c, uniform int32_t* d, uniform float* e) +{ + outputBuffer[0] = (uint64_t)(*a); + outputBuffer[1] = (uint64_t)(*b); + outputBuffer[2] = (uint64_t)(*c); + outputBuffer[3] = (uint64_t)(*d); + outputBuffer[4] = (uint64_t)(*e); +} |
