yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d58243d90
master
1//TEST(compute):SIMPLE(filecheck=SPIRV):-target spirv-asm -entry computeMain -stage compute 2//TEST(compute):SIMPLE(filecheck=SPIRV_BL):-target spirv-asm -entry computeMain -stage compute -DBLOCK_LOAD 3 4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -render-feature cooperative-matrix-tensor-addressing 5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -render-feature cooperative-matrix-tensor-addressing -Xslang -DRW 6 7//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK_BL):-vk -output-using-type -emit-spirv-directly -render-feature cooperative-matrix-block-loads -Xslang -DBLOCK_LOAD 8//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK_BL):-vk -output-using-type -emit-spirv-directly -render-feature cooperative-matrix-block-loads -Xslang -DBLOCK_LOAD -Xslang -DRW 9 10//CHECK: 0 11//CHECK-NEXT: 0 12//CHECK-NEXT: 0 13//CHECK-NEXT: 0 14//CHECK-NEXT: 5 15//CHECK-NEXT: 6 16//CHECK-NEXT: 0 17//CHECK-NEXT: 0 18//CHECK-NEXT: 9 19 20//CHECK_BL: 0 21//CHECK_BL-NEXT: 0 22//CHECK_BL-NEXT: 0 23//CHECK_BL-NEXT: 0 24//CHECK_BL-NEXT: 7 25//CHECK_BL-NEXT: C 26//CHECK_BL-NEXT: 0 27//CHECK_BL-NEXT: 0 28//CHECK_BL-NEXT: C 29//CHECK_BL-NEXT: 11 30//CHECK_BL-NEXT: 0 31//CHECK_BL-NEXT: 0 32 33//TEST_INPUT:ubuffer(data=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24], stride=4, count=256),name=buf 34 35#if defined(RW) 36 RWByteAddressBuffer inputBuffer; 37#else // #if defined(RW) 38 ByteAddressBuffer inputBuffer; 39#endif // #else // #if defined(RW) 40 41//TEST_INPUT:ubuffer(stride=4, count=256):out,name=outputBuffer 42RWByteAddressBuffer outputBuffer; 43 44using namespace linalg; 45 46typealias CoopMatType = CoopMat<int32_t, MemoryScope.Subgroup, 16, 16, CoopMatMatrixUse.MatrixAccumulator>; 47 48int32_t decodeFunc(uint32_t* encoded, uint32_t blockCoord[2], uint32_t coordInBlock[2]) 49{ 50 uint32_t coord = blockCoord[1] * 4 + blockCoord[0]; 51 uint32_t mask = (0xff << (coordInBlock[0] * 8)); 52 return int32_t(encoded[coord] & mask) + 1; 53} 54 55[numthreads(32, 1, 1)] 56void computeMain() 57{ 58 //SPIRV: = OpCreateTensorLayoutNV % 59 TensorLayout<2, CoopMatClampMode.Undefined> tl; 60 61 //SPIRV: = OpTensorLayoutSetDimensionNV % 62 let tl1 = tl.Dimension(32, 16); 63 64 //SPIRV: = OpTensorLayoutSetStrideNV % 65 let tl2 = tl1.Stride(4, 1); 66 67 //SPIRV: = OpTensorLayoutSliceNV % 68 let tl3 = tl2.Slice(4, 24, 0, 16); 69 70 //SPIRV: = OpTensorLayoutSetClampValueNV % 71 let tl4 = tl3.ClampValue(CoopMatClampMode.Repeat); 72 73 //SPIRV: = OpTensorLayoutSetBlockSizeNV % 74 let tl5 = tl4.BlockSize(4, 8); 75 76#if defined(BLOCK_LOAD) 77 //SPIRV_BL: = OpCooperativeMatrixLoadTensorNV %{{.*}} DecodeFunc % 78 let mat = CoopMatType.Load<uint32_t>(inputBuffer, 0, tl5, decodeFunc); 79 80#else // #if defined(BLOCK_LOAD) 81 //SPIRV: = OpCooperativeMatrixLoadTensorNV %{{.*}} None 82 let mat = CoopMatType.Load(inputBuffer, 0, tl5); 83 84#endif // #else // #if defined(BLOCK_LOAD) 85 86 //SPIRV:OpCooperativeMatrixStoreTensorNV %{{.*}} None 87 mat.Store(outputBuffer, 0, tl5); 88}