yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d979b5048
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type 2 3// CHECK: 123 4// CHECK-NEXT: 4567 5// CHECK-NEXT: 0 6// CHECK-NEXT: 0 7 8//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 9RWStructuredBuffer<uint> outputBuffer; 10 11struct S { 12 int foo : 8; 13 uint bar : 24; 14}; 15 16// Generates the equivalent of this: 17/* 18struct S { 19 int _backing; 20 21 property foo : int 22 { 23 // int foo : 8; 24 get 25 { 26 let backingWidth = 32; 27 let fooWidth = 8; 28 let topOfFoo = 8; 29 // Shift left and then right to sign-extend foo properly 30 return (int(_backing) << (backingWidth-topOfFoo)) >> (backingWidth-fooWidth); 31 } 32 [mutating] set(int x) 33 { 34 let fooMask = 0x000000FF; 35 let bottomOfFoo = 0; 36 _backing = int((_backing & ~fooMask) | ((int(x) << bottomOfFoo) & fooMask)); 37 } 38 } 39 40 // int bar : 24; 41 property bar : int 42 { 43 get 44 { 45 let backingWidth = 32; 46 let barWidth = 24; 47 let topOfBar = 32; 48 // Shift left and then right to sign-extend bar properly 49 return (uint(_backing) << (backingWidth-topOfBar)) >> (backingWidth-barWidth); 50 } 51 [mutating] set(int x) 52 { 53 let barMask = 0xFFFFFF00; 54 let bottomOfBar = 8; 55 _backing = int((_backing & ~barMask) | ((int(x) << bottomOfBar) & barMask)); 56 } 57 } 58}; 59*/ 60 61[numthreads(1, 1, 1)] 62void computeMain() 63{ 64 S s; 65 s.foo = 123; 66 s.bar = 4567; 67 outputBuffer[0] = s.foo; 68 outputBuffer[1] = s.bar; 69 70 s.foo = 0; 71 s.bar = 0; 72 outputBuffer[2] = s.foo; 73 outputBuffer[3] = s.bar; 74}