yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
93f5d13fc
master
1// column-major-with-row-major-operations.slang 2 3// Metal/CPP/CUDA do not deal with packing currently, different results will occur. 4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -xslang -DTARGET_WITHOUT_PACKING 5//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -xslang -DTARGET_WITHOUT_PACKING 6 7//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -emit-spirv-via-glsl 8//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute 9//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute 10//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-mtl -compute 11 12 13// CPP/CUDA due to natural layout rules will recieve the following ROW matrix: 14// {1,2,3} 15// {0,4,5} 16// {6,0,7} 17 18// GLSL/SPIRV/HLSL/Metal with cbuffer layout rules will recieve the following ROW/COL matrix: 19// {1,2,3} 20// {4,5,6} 21// {7,8,9} 22 23//TEST_INPUT:cbuffer(data=[1.0 2.0 3.0 0.0 4.0 5.0 6.0 0.0 7.0 8.0 9.0 0.0]):name matrixTestCBuf1 24ConstantBuffer<row_major float3x3> matrixTestCBuf1; 25 26// CPP/Metal/CUDA due to not having memory packing will recieve the following COL matrix post-transpose: 27// {1,0,6} 28// {2,4,0} 29// {3,5,7} 30 31//TEST_INPUT:cbuffer(data=[1.0 2.0 3.0 0.0 4.0 5.0 6.0 0.0 7.0 8.0 9.0 0.0]):name matrixTestCBuf2 32ConstantBuffer<column_major float3x3> matrixTestCBuf2; 33 34//TEST_INPUT:cbuffer(data=[1.0 2.0 3.0 0.0 4.0 5.0 6.0 0.0]):name NeedsPadding 35cbuffer NeedsPadding 36{ 37 float3 data1; 38 float3 data2; 39}; 40 41//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output 42RWStructuredBuffer<uint> output; 43 44bool floatCheck(float data, float valueToCheckFor) 45{ 46 return data < (valueToCheckFor + 0.001) && data > valueToCheckFor - 0.001; 47} 48 49[numthreads(1, 1, 1)] 50void computeMain(uint3 tid : SV_DispatchThreadID) 51{ 52 float3x3 matrixTest1; 53 matrixTest1 = matrixTestCBuf1; 54 55 float3x3 matrixTest2; 56 matrixTest2 = matrixTestCBuf2; 57 58 output[0] = uint(true 59#ifdef TARGET_WITHOUT_PACKING 60 && floatCheck(matrixTest1[0][0], 1) 61 && floatCheck(matrixTest1[0][1], 2) 62 && floatCheck(matrixTest1[0][2], 3) 63 && floatCheck(matrixTest1[1][0], 0) 64 && floatCheck(matrixTest1[1][1], 4) 65 && floatCheck(matrixTest1[1][2], 5) 66 && floatCheck(matrixTest1[2][0], 6) 67 && floatCheck(matrixTest1[2][1], 0) 68 && floatCheck(matrixTest1[2][2], 7) 69 70 && floatCheck(matrixTest2[0][0], 1) 71 && floatCheck(matrixTest2[0][1], 0) 72 && floatCheck(matrixTest2[0][2], 6) 73 && floatCheck(matrixTest2[1][0], 2) 74 && floatCheck(matrixTest2[1][1], 4) 75 && floatCheck(matrixTest2[1][2], 0) 76 && floatCheck(matrixTest2[2][0], 3) 77 && floatCheck(matrixTest2[2][1], 5) 78 && floatCheck(matrixTest2[2][2], 7) 79 80 && floatCheck(data1[0], 1) 81 && floatCheck(data1[1], 2) 82 && floatCheck(data1[2], 3) 83 && floatCheck(data2[0], 0) 84 && floatCheck(data2[1], 4) 85 && floatCheck(data2[2], 5) 86#else 87 && floatCheck(matrixTest1[0][0], 1) 88 && floatCheck(matrixTest1[0][1], 2) 89 && floatCheck(matrixTest1[0][2], 3) 90 && floatCheck(matrixTest1[1][0], 4) 91 && floatCheck(matrixTest1[1][1], 5) 92 && floatCheck(matrixTest1[1][2], 6) 93 && floatCheck(matrixTest1[2][0], 7) 94 && floatCheck(matrixTest1[2][1], 8) 95 && floatCheck(matrixTest1[2][2], 9) 96 97 && floatCheck(matrixTest2[0][0], 1) 98 && floatCheck(matrixTest2[0][1], 4) 99 && floatCheck(matrixTest2[0][2], 7) 100 && floatCheck(matrixTest2[1][0], 2) 101 && floatCheck(matrixTest2[1][1], 5) 102 && floatCheck(matrixTest2[1][2], 8) 103 && floatCheck(matrixTest2[2][0], 3) 104 && floatCheck(matrixTest2[2][1], 6) 105 && floatCheck(matrixTest2[2][2], 9) 106 107 && floatCheck(data1[0], 1) 108 && floatCheck(data1[1], 2) 109 && floatCheck(data1[2], 3) 110 && floatCheck(data2[0], 4) 111 && floatCheck(data2[1], 5) 112 && floatCheck(data2[2], 6) 113#endif 114 ); 115 //BUF: 1 116}