yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7dad68f86
master
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL 2//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly -DTARGET_SPIRV 3//TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl -DTARGET_HLSL 4//TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda -DTARGET_CUDA 5 6// not testing cpp due to missing impl 7//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP): -allow-glsl -stage compute -entry computeMain -target cpp -DTARGET_CPP 8 9//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl 10//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly 11//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-wgpu -compute -entry computeMain -allow-glsl -xslang -DWGPU -render-feature half 12 13// Not testing because CI runners may not support Metal's intrinsics. 14//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-metal -compute -entry computeMain -allow-glsl -xslang -DMETAL 15 16#version 430 17 18#if 1 \ 19 && !defined(TARGET_HLSL) \ 20 && !defined(TARGET_CUDA) 21// hlsl does not treat boolean types with subgroup.* as a logical operator 22// cuda is missing an implementation 23#define TEST_when_logical_operators_are_implemented 24#endif 25 26//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer 27buffer MyBlockName2 28{ 29 uint data[]; 30} outputBuffer; 31 32#define local_size_x_v 4 33layout(local_size_x = local_size_x_v) in; 34 35__generic<T : __BuiltinLogicalType> 36bool test1Logical() { 37 return true 38#if defined(TEST_when_logical_operators_are_implemented) 39 & subgroupExclusiveAnd(T(1)) == T(1) 40 & subgroupExclusiveOr(T(1)) == T(1) 41 & subgroupExclusiveXor(T(1)) == T(1) 42#endif // #if defined(TEST_when_logical_operators_are_implemented) 43 ; 44} 45 46__generic<T : __BuiltinLogicalType, let N : int> 47bool testVLogical() { 48 typealias gvec = vector<T, N>; 49 50 return true 51#if defined(TEST_when_logical_operators_are_implemented) 52 & subgroupExclusiveAnd(gvec(T(1))) == gvec(T(1)) 53 & subgroupExclusiveOr(gvec(T(1))) == gvec(T(1)) 54 & subgroupExclusiveXor(gvec(T(1))) == gvec(T(1)) 55#endif // #if defined(TEST_when_logical_operators_are_implemented) 56 ; 57} 58 59bool testLogical() { 60 return true 61 & test1Logical<int>() 62 & testVLogical<int, 2>() 63 & testVLogical<int, 3>() 64 & testVLogical<int, 4>() 65 & test1Logical<int8_t>() 66 & testVLogical<int8_t, 2>() 67 & testVLogical<int8_t, 3>() 68 & testVLogical<int8_t, 4>() 69 & test1Logical<int16_t>() 70 & testVLogical<int16_t, 2>() 71 & testVLogical<int16_t, 3>() 72 & testVLogical<int16_t, 4>() 73 & test1Logical<int64_t>() 74 & testVLogical<int64_t, 2>() 75 & testVLogical<int64_t, 3>() 76 & testVLogical<int64_t, 4>() 77 & test1Logical<uint>() 78 & testVLogical<uint, 2>() 79 & testVLogical<uint, 3>() 80 & testVLogical<uint, 4>() 81 & test1Logical<uint8_t>() 82 & testVLogical<uint8_t, 2>() 83 & testVLogical<uint8_t, 3>() 84 & testVLogical<uint8_t, 4>() 85 & test1Logical<uint16_t>() 86 & testVLogical<uint16_t, 2>() 87 & testVLogical<uint16_t, 3>() 88 & testVLogical<uint16_t, 4>() 89 & test1Logical<uint64_t>() 90 & testVLogical<uint64_t, 2>() 91 & testVLogical<uint64_t, 3>() 92 & testVLogical<uint64_t, 4>() 93 & test1Logical<bool>() 94 & testVLogical<bool, 2>() 95 & testVLogical<bool, 3>() 96 & testVLogical<bool, 4>() 97 ; 98} 99 100__generic<T : __BuiltinArithmeticType> 101bool test1Arithmetic() { 102 return true 103 & subgroupExclusiveAdd(T(1)) == T(3) 104 & subgroupExclusiveMul(T(1)) == T(1) 105 106 // WGSL and METAL does not support exclusive min/max. 107#if !defined(WGPU) && !defined(METAL) 108 & subgroupExclusiveMin(T(1)) == T(1) 109 & subgroupExclusiveMax(T(1)) == T(1) 110#endif 111 ; 112} 113__generic<T : __BuiltinArithmeticType, let N : int> 114bool testVArithmetic() { 115 typealias gvec = vector<T, N>; 116 117 return true 118 & subgroupExclusiveAdd(gvec(T(1))) == gvec(T(3)) 119 & subgroupExclusiveMul(gvec(T(1))) == gvec(T(1)) 120 121 // WGSL and METAL does not support exclusive min/max. 122#if !defined(WGPU) && !defined(METAL) 123 & subgroupExclusiveMin(gvec(T(1))) == gvec(T(1)) 124 & subgroupExclusiveMax(gvec(T(1))) == gvec(T(1)) 125#endif 126 ; 127} 128 129bool testArithmetic() { 130 return true 131 & test1Arithmetic<float>() 132 & testVArithmetic<float, 2>() 133 & testVArithmetic<float, 3>() 134 & testVArithmetic<float, 4>() 135 & test1Arithmetic<half>() 136 & testVArithmetic<half, 2>() 137 & testVArithmetic<half, 3>() 138 & testVArithmetic<half, 4>() 139 & test1Arithmetic<int>() 140 & testVArithmetic<int, 2>() 141 & testVArithmetic<int, 3>() 142 & testVArithmetic<int, 4>() 143 & test1Arithmetic<uint>() 144 & testVArithmetic<uint, 2>() 145 & testVArithmetic<uint, 3>() 146 & testVArithmetic<uint, 4>() 147 148 // Disabled on WGPU and Metal as these built-in types are not supported as of time of writing. 149#if !defined(WGPU) && !defined(METAL) 150 & test1Arithmetic<double>() // WARNING: intel GPU's lack FP64 support 151 & testVArithmetic<double, 2>() 152 & testVArithmetic<double, 3>() 153 & testVArithmetic<double, 4>() 154 & test1Arithmetic<int8_t>() 155 & testVArithmetic<int8_t, 2>() 156 & testVArithmetic<int8_t, 3>() 157 & testVArithmetic<int8_t, 4>() 158 & test1Arithmetic<int64_t>() 159 & testVArithmetic<int64_t, 2>() 160 & testVArithmetic<int64_t, 3>() 161 & testVArithmetic<int64_t, 4>() 162 & test1Arithmetic<uint8_t>() 163 & testVArithmetic<uint8_t, 2>() 164 & testVArithmetic<uint8_t, 3>() 165 & testVArithmetic<uint8_t, 4>() 166 & test1Arithmetic<uint64_t>() 167 & testVArithmetic<uint64_t, 2>() 168 & testVArithmetic<uint64_t, 3>() 169 & testVArithmetic<uint64_t, 4>() 170#endif 171 172 // Disabled on WGPU as these built-in types are not supported as of time of writing. 173#if !defined (WGPU) 174 & test1Arithmetic<int16_t>() 175 & testVArithmetic<int16_t, 2>() 176 & testVArithmetic<int16_t, 3>() 177 & testVArithmetic<int16_t, 4>() 178 & test1Arithmetic<uint16_t>() 179 & testVArithmetic<uint16_t, 2>() 180 & testVArithmetic<uint16_t, 3>() 181 & testVArithmetic<uint16_t, 4>() 182#endif 183 ; 184} 185 186[shader("compute")] 187void computeMain() 188{ 189 190 bool res0 = true 191 // WGSL and Metal does not support bitwise exclusive intrinsics. 192#if !defined(WGPU) && !defined(METAL) 193 & testLogical() 194#endif 195 ; 196 197 bool res1 = true 198 & testArithmetic() 199 ; 200 201 if (gl_LocalInvocationID.x == 3) { 202 // seperate so if there is an erroneous error the "major" 203 // tests are issolated into 2 branches without polluting the 204 // file with a bunch of individual test values 205 outputBuffer.data[0] = res0; 206 outputBuffer.data[1] = res1; 207 } 208 209 // CHECK_GLSL: void main( 210 // CHECK_SPV: OpEntryPoint 211 // CHECK_HLSL: void computeMain( 212 // CHECK_CUDA: void computeMain( 213 // CHECK_CPP: void _computeMain( 214 // BUF: 1 215 // BUF-NEXT: 1 216}