yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
cfef0c6f6
master
1// struct-bit-cast.slang 2 3//TEST(compute):COMPARE_COMPUTE: -shaderobj 4 5// Test that bit_cast works for bit-reinterpreting one struct type as another. 6 7struct Foo 8{ 9 uint a; 10 float b; 11 float2 fvec; 12} 13 14struct Inner 15{ 16 int v; 17 uint s; 18} 19 20struct Bar 21{ 22 int u; 23 Inner i; 24 uint t; 25} 26 27int test0(int val) 28{ 29 Bar b; 30 b.u = val; 31 b.i.v = asint(2.0f); 32 b.i.s = asuint(1.25); 33 b.t = asuint(0.25); 34 Foo f = bit_cast<Foo, Bar>(b); 35 return int(f.a) + (int)f.b + int(float(f.fvec.x / f.fvec.y)); // val + 2 + 5 36} 37 38struct Smaller 39{ 40 int s; 41} 42 43struct Larger 44{ 45 int x, y; 46} 47 48int test1() 49{ 50 return 1; 51} 52 53 54//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 55RWStructuredBuffer<int> outputBuffer; 56 57[numthreads(4, 1, 1)] 58void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 59{ 60 int tid = dispatchThreadID.x; 61 int inVal = tid; 62 int outVal = test0(inVal) + test1(); 63 outputBuffer[tid] = outVal; 64}