diff options
| author | Ronan <ro.cailleau@gmail.com> | 2025-10-08 11:19:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-08 09:19:13 +0000 |
| commit | 1300678a36bf8d7081647aef3e2a37dbd496aaf5 (patch) | |
| tree | 01c7cbf78aefccd9de9e9e2f56e77c1d145765a9 /tests | |
| parent | 54e1d02715747ee81585bfd23e96a1f4956dbf66 (diff) | |
`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`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/gh-8512-2.slang | 40 | ||||
| -rw-r--r-- | tests/bugs/gh-8512.slang | 39 |
2 files changed, 79 insertions, 0 deletions
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 <Scalar : __BuiltinFloatingPointType, int Mode> +struct Spectrum +{ + static const int Samples = Mode & 0xFF; + typealias VecT = vector<Scalar, Samples>; + VecT data; + + static const bool IsRGB = (Mode & 0x100) != 0; + + __generic <Float : __BuiltinFloatingPointType> + __init(vector<Float, Samples> v) + { + this.data = VecT(v); + } + + static This MakeFromRGB<Float : __BuiltinFloatingPointType>(vector<Float, 3> rgb) + { + if(IsRGB) + { + return (Spectrum<Scalar, 0x103>(rgb) as This).value; + } + else + { + return {}; + } + } +} + +static const int DefaultMode = 0x103; +typealias Spec = Spectrum<float, DefaultMode>; + +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 <Scalar : __BuiltinFloatingPointType, int Mode> +struct Spectrum +{ + static const int Samples = Mode & 0xFF; + typealias VecT = vector<Scalar, Samples>; + VecT data; + + static const bool IsRGB = (Mode & 0x100) != 0; + + __generic <Float : __BuiltinFloatingPointType> + __init(vector<Float, Samples> v) + { + this.data = VecT(v); + } + + static This MakeFromRGB<Float : __BuiltinFloatingPointType>(vector<Float, 3> rgb) + { + if(IsRGB) + { + return (Spectrum<Scalar, 0x103>(rgb) as This).value; + } + else + { + return {}; + } + } +} + +static const int DefaultMode = 0x103; +typealias Spec = Spectrum<float, DefaultMode>; + +[shader("vertex")] +Spec main(float3 vertex_color : COLOR0) : COLOR0 +{ + return Spec::MakeFromRGB(vertex_color); +} |
