yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
69cb6e8f3
master
1// buffer-layout.slang 2 3// This test mirrors `tests/compute/buffer-layout.slang`, and it meant 4// to confirm that our reflection logic correctly reports the offsets 5// that the compute test sees in practice. 6 7//TEST:REFLECTION:-stage compute -entry main -target hlsl -no-codegen 8//TEST:REFLECTION:-stage compute -entry main -target spirv -no-codegen 9 10struct A 11{ 12 float x; 13 float y; 14} 15 16struct S 17{ 18 // The first field in a struct isn't going to be that 19 // interesting, because it will always get offset zero, 20 // so we just use this to establish a poorly-aligned 21 // starting point for the next field. 22 // 23 // offset size alignment 24 // 25 // 0 4 4 26 // 27 float z; 28 29 // The `std140` and D3D constant buffer ruless both 30 // ensure a minimum of 16-byte alignment on `struct` 31 // types, but differ in that D3D does not round up 32 // the total size of a type to its alignment. 33 // 34 // The `std430` and structured buffer rules don't 35 // perform any over-alignment on `struct` types and 36 // instead align them using the "natural" rules one 37 // might expect of, e.g., a C compiler. 38 // 39 // offset size alignment 40 // 41 // cbuffer 16 8 16 42 // std140 16 16 16 43 // 44 // struct 4 8 4 45 // std430 4 8 4 46 // 47 A a; 48 49 // Now we insert an ordinary `int` field just as 50 // a way to probe the offset so far. 51 // 52 // offset size alignment 53 // 54 // cbuffer 24 4 4 55 // std140 32 4 4 56 // 57 // struct 12 4 4 58 // std430 12 4 4 59 // 60 int b; 61 62 // As our next stress-test case, we will insert an 63 // array with elements that aren't a multiple of 64 // 16 bytes in size. 65 // 66 // The contant/uniform buffer rules will set the 67 // array stride to a multiple of 16 bytes in this case. 68 // The only difference between D3D rules and `std140` 69 // here is that D3D does not round up the size to 70 // the alignment. 71 // 72 // The structured/std430 rules don't do anything 73 // to over-align an array, so it is laid out relatively 74 // naturally, but note that D3D still follows its rule 75 // of not letting a vector "straddle" a 16-byte boundary, 76 // even if it doesn't bump up the alignment of 77 // vector types. 78 // 79 // offset size alignment 80 // 81 // cbuffer 32 24 16 82 // std140 48 32 32 83 // 84 // struct 16 16 4 85 // std430 16 16 8 86 // 87 float2 c[2]; 88 89 // Now we put in one more ordinary `int` field 90 // just to probe the offset computed so far. 91 // offset size alignment 92 // 93 // cbuffer 56 4 4 94 // std140 80 4 4 95 // 96 // struct 32 4 4 97 // std430 32 4 4 98 // 99 int d; 100} 101 102ConstantBuffer<S> cb; 103RWStructuredBuffer<S> sb; 104 105[numthreads(1, 1, 1)] 106void main( 107 uint3 dispatchThreadID : SV_DispatchThreadID) 108{ 109}