yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeAdd legalization for 0-sized arrays. (#7327)2d7106640

master
1.4 KiB64 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk
3
4interface IVertex
5{
6    property float3 position{get;}
7    property Optional<float3> normal{get;}
8    property Optional<float3> color{get;}
9}
10
11struct Vertex<bool hasNormal, bool hasColor> : IVertex
12{
13    private float3 m_position;
14    private Conditional<float3, hasNormal> m_normal;
15    private Conditional<float3, hasColor> m_color;
16
17    __init(float3 position, float3 normal, float3 color)
18    {
19        m_position = position;
20        m_normal = normal;
21        m_color = color;
22    }
23
24    property float3 position
25    {
26        get { return m_position; }
27    }
28    property Optional<float3> normal
29    {
30        get { return m_normal; }
31    }
32    property Optional<float3> color
33    {
34        get { return m_color; }
35    }
36}
37
38//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
39RWStructuredBuffer<int> outputBuffer;
40
41void test<V:IVertex>(V vert)
42{
43    // CHECK: 0
44    // CHECK: 0
45    // CHECK: 1
46    // CHECK: 3
47    if (let normal = vert.normal)
48    {
49         outputBuffer[0] = 1;
50         outputBuffer[1] = (int)normal.x;
51    }
52
53    if (let color = vert.color)
54    {
55        outputBuffer[2] = 1;
56        outputBuffer[3] = (int)color.x;
57    }
58}
59
60[numthreads(1,1,1)]
61void computeMain()
62{
63    test<Vertex<false, true>>(Vertex<false, true>(1.0, 2.0, 3.0));
64}