yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ff5e04f7f
master
1// simple-namespace.slang 2 3//TEST(compute):COMPARE_COMPUTE: -shaderobj 4 5// Test that simple `namespace` declarations work as expected 6// Test that the global scope operator `::` works as expected 7 8namespace A 9{ 10 static int num = 16; 11 struct X 12 { 13 int val; 14 15 int getVal() 16 { 17 return val; 18 } 19 } 20} 21 22namespace B 23{ 24 struct X 25 { 26 int head; 27 int tail; 28 29 int getHead() { return head; } 30 int getTail() { return tail; } 31 } 32 33 X makeX(int h, int t) 34 { 35 X result = { h, t }; 36 return result; 37 } 38} 39 40namespace A 41{ 42 X makeX(int v) 43 { 44 X result = { v }; 45 return result; 46 } 47} 48 49int test(int val) 50{ 51 A.X a = A::makeX(val); 52 // Use the global scope operator "::A::num" to access the static member of namespace A 53 // Test it with mul operator 54 int num = 16*::A::num; 55 B::X b = B.makeX(val*16, val*num); 56 57 return a.getVal() + b.getHead() + b.getTail(); 58} 59 60//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 61RWStructuredBuffer<int> outputBuffer; 62 63[numthreads(4, 1, 1)] 64void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 65{ 66 int tid = dispatchThreadID.x; 67 int inVal = tid; 68 int outVal = test(inVal); 69 outputBuffer[tid] = outVal; 70}