From 1300678a36bf8d7081647aef3e2a37dbd496aaf5 Mon Sep 17 00:00:00 2001 From: Ronan Date: Wed, 8 Oct 2025 11:19:13 +0200 Subject: `ExprLoweringVisitorBase::getDefaultVal(Type*)` use `MakeVector/MatrixFromScalar` (#8512) - Allows using `Vector/Matrix` type with yet unresolved dimensions - Simpler implementation and in-line with default `Array` - Added `test/bugs/gh-8512.slang` --- tests/bugs/gh-8512-2.slang | 40 ++++++++++++++++++++++++++++++++++++++++ tests/bugs/gh-8512.slang | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/bugs/gh-8512-2.slang create mode 100644 tests/bugs/gh-8512.slang (limited to 'tests/bugs') diff --git a/tests/bugs/gh-8512-2.slang b/tests/bugs/gh-8512-2.slang new file mode 100644 index 000000000..4c51af696 --- /dev/null +++ b/tests/bugs/gh-8512-2.slang @@ -0,0 +1,40 @@ +//TEST:INTERPRET(filecheck=ICHECK): + +__generic +struct Spectrum +{ + static const int Samples = Mode & 0xFF; + typealias VecT = vector; + VecT data; + + static const bool IsRGB = (Mode & 0x100) != 0; + + __generic + __init(vector v) + { + this.data = VecT(v); + } + + static This MakeFromRGB(vector rgb) + { + if(IsRGB) + { + return (Spectrum(rgb) as This).value; + } + else + { + return {}; + } + } +} + +static const int DefaultMode = 0x103; +typealias Spec = Spectrum; + +void main() +{ + float3 color = {1, 2, 3}; + let spec = Spec::MakeFromRGB(color); + // ICHECK: (1, 2, 3) + printf("(%.0f, %.0f, %.0f)", spec.data[0], spec.data[1], spec.data[2]); +} diff --git a/tests/bugs/gh-8512.slang b/tests/bugs/gh-8512.slang new file mode 100644 index 000000000..e94d95719 --- /dev/null +++ b/tests/bugs/gh-8512.slang @@ -0,0 +1,39 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv +// CHECK: OpEntryPoint + +__generic +struct Spectrum +{ + static const int Samples = Mode & 0xFF; + typealias VecT = vector; + VecT data; + + static const bool IsRGB = (Mode & 0x100) != 0; + + __generic + __init(vector v) + { + this.data = VecT(v); + } + + static This MakeFromRGB(vector rgb) + { + if(IsRGB) + { + return (Spectrum(rgb) as This).value; + } + else + { + return {}; + } + } +} + +static const int DefaultMode = 0x103; +typealias Spec = Spectrum; + +[shader("vertex")] +Spec main(float3 vertex_color : COLOR0) : COLOR0 +{ + return Spec::MakeFromRGB(vertex_color); +} -- cgit v1.2.3