From 651fc8b62e3acf07699e6d38165a27ff6a271b0b Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 19 Feb 2025 19:00:45 +0800 Subject: [PATCH] Handle pointer types when getting type cast style Closes https://github.com/shader-slang/slang/issues/6025 --- source/slang/slang-ir.cpp | 3 +++ tests/metal/simple-vertex-position.slang | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/metal/simple-vertex-position.slang diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 3a7ace37d4..11de0cf844 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3970,7 +3970,10 @@ static TypeCastStyle _getTypeStyleId(IRType* type) { return _getTypeStyleId(matrixType->getElementType()); } + // Try to simplify style if we can, otherwise just handle it unsimplified auto style = getTypeStyle(type->getOp()); + if (style == kIROp_Invalid) + style = type->getOp(); switch (style) { case kIROp_IntType: diff --git a/tests/metal/simple-vertex-position.slang b/tests/metal/simple-vertex-position.slang new file mode 100644 index 0000000000..f76e7fcd6a --- /dev/null +++ b/tests/metal/simple-vertex-position.slang @@ -0,0 +1,16 @@ +//TEST:SIMPLE(filecheck=METAL): -target metal -stage vertex -entry vertexMain +//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage vertex -entry vertexMain +//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry vertexMain +//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm -stage vertex -entry vertexMain + +//METAL: position +//METALLIB: @vertexMain + +//WGSL: @builtin(position) +//WGSLSPIRV: %vertexMain = OpFunction + +// Vertex Shader which writes to position +void vertexMain(out float4 position : SV_Position) +{ + position = float4(0.6, 0.1, 0.6, 0.33); +}