yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
92ee2927d
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -wgsl -shaderobj 2 3//TEST_INPUT:ubuffer(data=[1 0], stride=4):name inputBuffer 4//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer 5RWStructuredBuffer<int> inputBuffer; 6RWStructuredBuffer<int> outputBuffer; 7 8// Global bool constants to avoid constant folding 9static bool trueVal; 10static bool falseVal; 11 12struct matrixWrapper { 13 bool2x2 mat1 = bool2x2(falseVal, falseVal, falseVal, falseVal); 14 bool2x3 mat2 = bool2x3(trueVal, trueVal, falseVal, falseVal, falseVal, trueVal); 15} 16 17bool elementAnd(bool2x2 matrix) 18{ 19 return trueVal 20 && matrix[0][0] 21 && matrix[0][1] 22 && matrix[1][0] 23 && matrix[1][1]; 24} 25 26[numthreads(1, 1, 1)] 27void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 28{ 29 // Load true/false values from input buffer to avoid constant folding 30 trueVal = inputBuffer[0] != 0; 31 falseVal = inputBuffer[1] != 0; 32 33 // Test bool matrix construction 34 bool2x2 mat1 = bool2x2(trueVal, falseVal, falseVal, trueVal); 35 bool3x3 mat2 = bool3x3( 36 trueVal, falseVal, trueVal, 37 falseVal, trueVal, falseVal, 38 trueVal, falseVal, trueVal 39 ); 40 bool2x4 mat3 = bool2x4( 41 trueVal, falseVal, trueVal, falseVal, 42 trueVal, falseVal, trueVal, falseVal 43 ); 44 45 // Test bool matrix element access 46 bool val1 = mat1[0][0]; 47 bool val2 = mat2[2][1]; 48 49 // Test bool matrix row access 50 bool2 row = mat1[1]; 51 bool3 row3 = mat2[0]; 52 53 // Test logical operations 54 bool2x2 not_mat = !mat1; 55 bool2x2 and_mat = mat1 && bool2x2(trueVal, trueVal, falseVal, falseVal); 56 57 // Test element assignment 58 mat1[0][1] = trueVal; 59 mat2[1][2] = falseVal; 60 61 // Test passing bool matrices to functions 62 bool anded = elementAnd(mat1); 63 64 // Test structs with bool matrix fields 65 matrixWrapper wrapper = {}; 66 67 // Test any/all operations 68 bool2x2 all_true = bool2x2(trueVal, trueVal, trueVal, trueVal); 69 bool2x2 all_false = bool2x2(falseVal, falseVal, falseVal, falseVal); 70 bool2x2 mixed = bool2x2(trueVal, falseVal, trueVal, falseVal); 71 72 bool test_all_true = all(all_true); // all elements true -> true 73 bool test_all_false = all(all_false); // all elements false -> false 74 bool test_all_mixed = all(mixed); // some elements false -> false 75 bool test_any_true = any(all_true); // some elements true -> true 76 bool test_any_false = any(all_false); // no elements true -> false 77 bool test_any_mixed = any(mixed); // some elements true -> true 78 79 // Store results 80 outputBuffer[0] = val1; 81 // CHECK: 1 82 outputBuffer[1] = val2; 83 // CHECK-NEXT: 0 84 outputBuffer[2] = row.x; 85 // CHECK-NEXT: 0 86 outputBuffer[3] = row.y; 87 // CHECK-NEXT: 1 88 outputBuffer[4] = row3.y; 89 // CHECK-NEXT: 0 90 outputBuffer[5] = not_mat[0][0]; 91 // CHECK-NEXT: 0 92 outputBuffer[6] = and_mat[0][0]; 93 // CHECK-NEXT: 1 94 outputBuffer[7] = mat1[0][1]; 95 // CHECK-NEXT: 1 96 outputBuffer[8] = mat3[0][1]; 97 // CHECK-NEXT: 0 98 outputBuffer[9] = anded; 99 // CHECK-NEXT: 0 100 outputBuffer[10] = wrapper.mat1[0][0] || wrapper.mat2[0][0]; 101 // CHECK-NEXT: 1 102 outputBuffer[11] = test_all_true; 103 // CHECK-NEXT: 1 104 outputBuffer[12] = test_all_false; 105 // CHECK-NEXT: 0 106 outputBuffer[13] = test_all_mixed; 107 // CHECK-NEXT: 0 108 outputBuffer[14] = test_any_true; 109 // CHECK-NEXT: 1 110 outputBuffer[15] = test_any_false; 111 // CHECK-NEXT: 0 112 outputBuffer[16] = test_any_mixed; 113 // CHECK-NEXT: 1 114}