From 2d7106640addf0ac88e0a5462117cd90b13a5e73 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 4 Jun 2025 13:07:11 -0700 Subject: Add legalization for 0-sized arrays. (#7327) * Add legalization for 0-sized arrays. * Allow 0-sized arrays in the front-end. * More tests. * Add `Conditional` type to core module. * Update toc. * Fix wording. * Update test. --- tests/language-feature/0-array.slang | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/language-feature/0-array.slang (limited to 'tests/language-feature/0-array.slang') diff --git a/tests/language-feature/0-array.slang b/tests/language-feature/0-array.slang new file mode 100644 index 000000000..7379faace --- /dev/null +++ b/tests/language-feature/0-array.slang @@ -0,0 +1,64 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk + +interface IVertex +{ + property float3 position{get;} + property Optional normal{get;} + property Optional color{get;} +} + +struct Vertex : IVertex +{ + private float3 m_position; + private float3 m_normal[hasNormal]; + private float3 m_color[hasColor]; + + __init(float3 position, float3 normal, float3 color) + { + m_position = position; + if (hasNormal) m_normal[0] = normal; + if (hasColor) m_color[0] = color; + } + + property float3 position + { + get { return m_position; } + } + property Optional normal + { + get { if (hasNormal) return m_normal[0]; else return none; } + } + property Optional color + { + get { if (hasColor) return m_color[0]; else return none; } + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +void test(V vert) +{ + // CHECK: 0 + // CHECK: 0 + // CHECK: 1 + // CHECK: 3 + if (let normal = vert.normal) + { + outputBuffer[0] = 1; + outputBuffer[1] = (int)normal.x; + } + + if (let color = vert.color) + { + outputBuffer[2] = 1; + outputBuffer[3] = (int)color.x; + } +} + +[numthreads(1,1,1)] +void computeMain() +{ + test>(Vertex(1.0, 2.0, 3.0)); +} \ No newline at end of file -- cgit v1.2.3