yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2d7106640
master
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 float3 m_normal[hasNormal]; 15 private float3 m_color[hasColor]; 16 17 __init(float3 position, float3 normal, float3 color) 18 { 19 m_position = position; 20 if (hasNormal) m_normal[0] = normal; 21 if (hasColor) m_color[0] = color; 22 } 23 24 property float3 position 25 { 26 get { return m_position; } 27 } 28 property Optional<float3> normal 29 { 30 get { if (hasNormal) return m_normal[0]; else return none; } 31 } 32 property Optional<float3> color 33 { 34 get { if (hasColor) return m_color[0]; else return none; } 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}