yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4ae6e9d8b
master
1// struct-inheritance.slang 2 3//TEST(compute):COMPARE_COMPUTE: -shaderobj 4//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj 5 6// Test that we can define a `struct` type 7// that inherits from another `struct`. 8 9#pragma warning(disable:30816) 10 11struct Base 12{ 13 int a; 14 15 int tweakBase(int val) { return val ^ a; } 16} 17 18struct Derived : Base 19{ 20 int b; 21 22 int tweakDerived(int val) { return tweakBase(val) + b; } 23} 24 25int tweak(Base b, int v) 26{ 27 return b.tweakBase(v); 28} 29 30//TEST_INPUT:cbuffer(data=[1 2]):name=C 31cbuffer C 32{ 33 int x; 34 int y; 35} 36 37int test(int val) 38{ 39 Derived d;// = { x, y }; 40 d.a = x; 41 d.b = y; 42 43 int result = 0; 44 result = result*16 + d.a; 45 result = result*16 + d.tweakBase(val); 46 result = result*16 + tweak(d, val); 47 result = result*16 + d.tweakDerived(val); 48 return result; 49} 50 51//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 52RWStructuredBuffer<int> outputBuffer; 53 54[numthreads(4, 1, 1)] 55void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 56{ 57 int tid = dispatchThreadID.x; 58 int inVal = tid; 59 int outVal = test(inVal); 60 outputBuffer[tid] = outVal; 61}