yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
5c672cef1
master
1// WGSL supports "textureSample()" only in fragment shader 2//TEST:SIMPLE(filecheck=WGSL): -stage fragment -entry fragMain -target wgsl 3 4//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer 5RWStructuredBuffer<int> outputBuffer; 6 7//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_f32v3 8Texture1D<float3> t1D_f32v3; 9//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32v3 10Texture2D<float3> t2D_f32v3; 11//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_f32v3 12Texture3D<float3> t3D_f32v3; 13//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32v3 14TextureCube<float3> tCube_f32v3; 15//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_f32v3 16Texture1DArray<float3> t1DArray_f32v3; 17//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32v3 18Texture2DArray<float3> t2DArray_f32v3; 19//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32v3 20TextureCubeArray<float3> tCubeArray_f32v3; 21 22//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_f32v4 23Texture1D<float4> t1D_f32v4; 24//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32v4 25Texture2D<float4> t2D_f32v4; 26//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_f32v4 27Texture3D<float4> t3D_f32v4; 28//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32v4 29TextureCube<float4> tCube_f32v4; 30 31//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_f32v4 32Texture1DArray<float4> t1DArray_f32v4; 33//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32v4 34Texture2DArray<float4> t2DArray_f32v4; 35//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32v4 36TextureCubeArray<float4> tCubeArray_f32v4; 37 38//TEST_INPUT: Texture2D(size=4, content = zero):name d2D 39DepthTexture2D d2D; 40//TEST_INPUT: TextureCube(size=4, content = zero):name dCube 41DepthTextureCube dCube; 42//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name d2DArray 43DepthTexture2DArray d2DArray; 44//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name dCubeArray 45DepthTextureCubeArray dCubeArray; 46 47//TEST_INPUT: Sampler:name samplerState 48SamplerState samplerState; 49//TEST_INPUT: Sampler:name shadowSampler 50SamplerComparisonState shadowSampler; 51 52bool TEST_texture<T>( 53 Texture1D<T> t1D, 54 Texture2D<T> t2D, 55 Texture3D<T> t3D, 56 TextureCube<T> tCube, 57 Texture1DArray<T> t1DArray, 58 Texture2DArray<T> t2DArray, 59 TextureCubeArray<T> tCubeArray 60) where T:ITexelElement, IArithmetic 61{ 62 // WGSL-LABEL: TEST_texture 63 typealias Tvn = T; 64 typealias Tv4 = vector<T.Element,4>; 65 66 float u = 0; 67 float u2 = 0.5; 68 constexpr const float ddx = 0.0f; 69 constexpr const float ddy = 0.0f; 70 71 uint width = 0, height = 0, depth = 0; 72 uint elements = 0; 73 74 bool voidResult = true; 75 76 // ====================== 77 // void GetDimensions() 78 // ====================== 79 80 // WGSL: textureDimensions({{\(*}}t1D 81 t1D.GetDimensions(width); 82 voidResult = voidResult && (uint(4) == width); 83 84 // WGSL: textureDimensions({{\(*}}t2D 85 t2D.GetDimensions(width, height); 86 voidResult = voidResult && (uint(4) == width); 87 voidResult = voidResult && (uint(4) == height); 88 89 // WGSL: textureDimensions({{\(*}}t3D 90 t3D.GetDimensions(width, height, depth); 91 voidResult = voidResult && (uint(4) == width); 92 voidResult = voidResult && (uint(4) == height); 93 voidResult = voidResult && (uint(4) == depth); 94 95 // WGSL: textureDimensions({{\(*}}tCube 96 tCube.GetDimensions(width, height); 97 voidResult = voidResult && (uint(4) == width); 98 voidResult = voidResult && (uint(4) == height); 99 100 // WGSL: textureDimensions({{\(*}}t1DArray 101 t1DArray.GetDimensions(width, elements); 102 voidResult = voidResult && (uint(4) == width); 103 voidResult = voidResult && (uint(2) == elements); 104 105 // WGSL: textureDimensions({{\(*}}t2DArray 106 t2DArray.GetDimensions(width, height, elements); 107 voidResult = voidResult && (uint(4) == width); 108 voidResult = voidResult && (uint(4) == height); 109 voidResult = voidResult && (uint(2) == elements); 110 111 // WGSL: textureDimensions({{\(*}}tCubeArray 112 tCubeArray.GetDimensions(width, height, elements); 113 voidResult = voidResult && (uint(4) == width); 114 voidResult = voidResult && (uint(4) == height); 115 voidResult = voidResult && (uint(2) == elements); 116 117 bool result = voidResult 118 // =============================== 119 // float CalculateLevelOfDetail() 120 // =============================== 121 // WGSL doesn't have a way to calculate mip-map level for the given coordinate 122 123 // ======================================== 124 // float CalculateLevelOfDetailUnclamped() 125 // ======================================== 126 // WGSL doesn't have a way to calculate mip-map level for the given coordinate 127 128 // =========== 129 // T Sample() 130 // https://www.w3.org/TR/WGSL/#texturesample 131 // =========== 132 133 // WGSL: textureSample({{\(*}}t1D 134 && all(Tvn(T.Element(0)) == t1D.Sample(samplerState, u)) 135 136 // WGSL: textureSample({{\(*}}t2D 137 && all(Tvn(T.Element(0)) == t2D.Sample(samplerState, float2(u, u))) 138 139 // WGSL: textureSample({{\(*}}t3D 140 && all(Tvn(T.Element(0)) == t3D.Sample(samplerState, float3(u, u, u))) 141 142 // WGSL: textureSample({{\(*}}tCube 143 && all(Tvn(T.Element(0)) == tCube.Sample(samplerState, normalize(float3(u, 1 - u, u)))) 144 145 // WGSL doesn't support textureSample for 1d_array and 3d_array; only 2d and cube 146 147 // WGSL: textureSample({{\(*}}t2DArray 148 && all(Tvn(T.Element(0)) == t2DArray.Sample(samplerState, float3(u, u, 0))) 149 150 // WGSL: textureSample({{\(*}}tCubeArray 151 && all(Tvn(T.Element(0)) == tCubeArray.Sample(samplerState, float4(normalize(float3(u, 1 - u, u)), 0))) 152 153 // Offset variant 154 155 // WGSL: textureSample({{\(*}}t1D 156 && all(Tvn(T.Element(0)) == t1D.Sample(samplerState, u, 1)) 157 158 // WGSL: textureSample({{\(*}}t2D 159 && all(Tvn(T.Element(0)) == t2D.Sample(samplerState, float2(u, u), int2(1, 1))) 160 161 // WGSL: textureSample({{\(*}}t3D 162 && all(Tvn(T.Element(0)) == t3D.Sample(samplerState, float3(u, u, u), int3(1, 1, 1))) 163 164 // WGSL doesn't support offset variant for cube and cube_array 165 166 // WGSL: textureSample({{\(*}}t2DArray 167 && all(Tvn(T.Element(0)) == t2DArray.Sample(samplerState, float3(u, u, 0), int2(1, 1))) 168 169 // Clamp variant 170 // WGSL doesn't support clamp variants for `textureSample()` 171 172 // =============== 173 // T SampleBias() 174 // https://www.w3.org/TR/WGSL/#texturesamplebias 175 // =============== 176 177 // WGSL doesn't support Bias for 1D texture 178 179 // WGSL: textureSampleBias({{\(*}}t2D 180 && all(Tvn(T.Element(0)) == t2D.SampleBias(samplerState, float2(u, u), float(-1))) 181 182 // WGSL: textureSampleBias({{\(*}}t3D 183 && all(Tvn(T.Element(0)) == t3D.SampleBias(samplerState, float3(u, u, u), float(-1))) 184 185 // WGSL: textureSampleBias({{\(*}}tCube 186 && all(Tvn(T.Element(0)) == tCube.SampleBias(samplerState, normalize(float3(u, 1 - u, u)), float(-1))) 187 188 // WGSL: textureSampleBias({{\(*}}t2DArray 189 && all(Tvn(T.Element(0)) == t2DArray.SampleBias(samplerState, float3(u, u, 0), float(-1))) 190 191 // WGSL: textureSampleBias({{\(*}}tCubeArray 192 && all(Tvn(T.Element(0)) == tCubeArray.SampleBias(samplerState, float4(normalize(float3(u, 1 - u, u)), 0), float(-1))) 193 194 // Offset variant 195 196 // WGSL: textureSampleBias({{\(*}}t2D 197 && all(Tvn(T.Element(0)) == t2D.SampleBias(samplerState, float2(u, u), float(-1), int2(1, 1))) 198 199 // WGSL: textureSampleBias({{\(*}}t3D 200 && all(Tvn(T.Element(0)) == t3D.SampleBias(samplerState, float3(u, u, u), float(-1), int3(1, 1, 1))) 201 202 // WGSL: textureSampleBias({{\(*}}t2DArray 203 && all(Tvn(T.Element(0)) == t2DArray.SampleBias(samplerState, float3(u, u, 0), float(-1), int2(1, 1))) 204 205 // =================================== 206 // T SampleLevel() 207 // https://www.w3.org/TR/WGSL/#texturesamplelevel 208 // =================================== 209 210 // WGSL doesn't support textureSampleLevel for 1D texture 211 212 // WGSL: textureSampleLevel({{\(*}}t2D 213 && all(Tvn(T.Element(0)) == t2D.SampleLevel(samplerState, float2(u, u), 0)) 214 215 // WGSL: textureSampleLevel({{\(*}}t3D 216 && all(Tvn(T.Element(0)) == t3D.SampleLevel(samplerState, float3(u, u, u), 0)) 217 218 // WGSL: textureSampleLevel({{\(*}}tCube 219 && all(Tvn(T.Element(0)) == tCube.SampleLevel(samplerState, normalize(float3(u, 1 - u, u)), 0)) 220 221 // WGSL: textureSampleLevel({{\(*}}t2DArray 222 && all(Tvn(T.Element(0)) == t2DArray.SampleLevel(samplerState, float3(u, u, 0), 0)) 223 224 // WGSL: textureSampleLevel({{\(*}}tCubeArray 225 && all(Tvn(T.Element(0)) == tCubeArray.SampleLevel(samplerState, float4(normalize(float3(u, 1 - u, u)), 0), 0)) 226 227 // Offset variant 228 229 // WGSL: textureSampleLevel({{\(*}}t2D 230 && all(Tvn(T.Element(0)) == t2D.SampleLevel(samplerState, float2(u, u), 0, int2(1, 1))) 231 232 // WGSL: textureSampleLevel({{\(*}}t3D 233 && all(Tvn(T.Element(0)) == t3D.SampleLevel(samplerState, float3(u, u, u), 0, int3(1, 1, 1))) 234 235 // WGSL: textureSampleLevel({{\(*}}t2DArray 236 && all(Tvn(T.Element(0)) == t2DArray.SampleLevel(samplerState, float3(u, u, 0), 0, int2(1, 1))) 237 238 // ================== 239 // float SampleCmp() 240 // https://www.w3.org/TR/WGSL/#texturesamplecompare 241 // ================== 242 243 // WGSL: textureSampleCompare({{\(*}}d2D 244 && float(0) == d2D.SampleCmp(shadowSampler, float2(u, u), 0) 245 246 // WGSL: textureSampleCompare({{\(*}}d2DArray 247 && float(0) == d2DArray.SampleCmp(shadowSampler, float3(u, u, 0), 0) 248 249 // WGSL: textureSampleCompare({{\(*}}dCube 250 && float(0) == dCube.SampleCmp(shadowSampler, normalize(float3(u, 1 - u, u)), 0) 251 252 // WGSL: textureSampleCompare({{\(*}}dCubeArray 253 && float(0) == dCubeArray.SampleCmp(shadowSampler, float4(normalize(float3(u, 1 - u, u)), 0), 0) 254 255 // Offset variant 256 257 // WGSL doesn't support the offset variant for cube and cube_array 258 259 // WGSL: textureSampleCompare({{\(*}}d2D 260 && float(0) == d2D.SampleCmp(shadowSampler, float2(u2, u), 0, int2(0, 0)) 261 262 // WGSL: textureSampleCompare({{\(*}}d2DArray 263 && float(0) == d2DArray.SampleCmp(shadowSampler, float3(u2, u, u), 0, int2(0, 0)) 264 265 // =================================== 266 // float SampleCmpLevelZero() 267 // https://www.w3.org/TR/WGSL/#texturesamplecomparelevel 268 // =================================== 269 270 // WGSL: textureSampleCompareLevel({{\(*}}d2D 271 && float(0) == d2D.SampleCmpLevelZero(shadowSampler, float2(u, u), 0) 272 273 // WGSL: textureSampleCompareLevel({{\(*}}d2DArray 274 && float(0) == d2DArray.SampleCmpLevelZero(shadowSampler, float3(u, u, 0), 0) 275 276 // WGSL: textureSampleCompareLevel({{\(*}}dCube 277 && float(0) == dCube.SampleCmpLevelZero(shadowSampler, normalize(float3(u, 1 - u, u)), 0) 278 279 // WGSL: textureSampleCompareLevel({{\(*}}dCubeArray 280 && float(0) == dCubeArray.SampleCmpLevelZero(shadowSampler, float4(normalize(float3(u, 1-u, u)), 0), 0) 281 282 // Offset variant 283 284 // WGSL: textureSampleCompareLevel({{\(*}}d2D 285 && float(0) == d2D.SampleCmpLevelZero(shadowSampler, float2(u2, u), 0, int2(0, 0)) 286 287 // WGSL: textureSampleCompareLevel({{\(*}}d2DArray 288 && float(0) == d2DArray.SampleCmpLevelZero(shadowSampler, float3(u2, u, u), 0, int2(0, 0)) 289 290 // ===================================== 291 // T SampleGrad() 292 // https://www.w3.org/TR/WGSL/#texturesamplegrad 293 // ===================================== 294 295 // WGSL doesn't support textureSampleGrad for 1D textures 296 297 // WGSL: textureSampleGrad({{\(*}}t2D 298 && all(Tvn(T.Element(0)) == t2D.SampleGrad(samplerState, float2(u, u), float2(ddx, ddx), float2(ddy, ddy))) 299 300 // WGSL: textureSampleGrad({{\(*}}t3D 301 && all(Tvn(T.Element(0)) == t3D.SampleGrad(samplerState, float3(u, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy))) 302 303 // WGSL: textureSampleGrad({{\(*}}tCube 304 && all(Tvn(T.Element(0)) == tCube.SampleGrad(samplerState, normalize(float3(u, 1 - u, u)), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy))) 305 306 // WGSL: textureSampleGrad({{\(*}}t2DArray 307 && all(Tvn(T.Element(0)) == t2DArray.SampleGrad(samplerState, float3(u, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy))) 308 309 // WGSL: textureSampleGrad({{\(*}}tCubeArray 310 && all(Tvn(T.Element(0)) == tCubeArray.SampleGrad(samplerState, float4(normalize(float3(u, 1 - u, u)), 0), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy))) 311 312 // Offset variant 313 314 // WGSL: textureSampleGrad({{\(*}}t2D 315 && all(Tvn(T.Element(0)) == t2D.SampleGrad(samplerState, float2(u2, u), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0))) 316 317 // WGSL: textureSampleGrad({{\(*}}t3D 318 && all(Tvn(T.Element(0)) == t3D.SampleGrad(samplerState, float3(u2, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy), int3(0, 0, 0))) 319 320 // WGSL: textureSampleGrad({{\(*}}t2DArray 321 && all(Tvn(T.Element(0)) == t2DArray.SampleGrad(samplerState, float3(u2, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0))) 322 ; 323 324 return result; 325} 326 327void fragMain() 328{ 329 bool result = true 330 && TEST_texture<float3>( 331 t1D_f32v3, 332 t2D_f32v3, 333 t3D_f32v3, 334 tCube_f32v3, 335 t1DArray_f32v3, 336 t2DArray_f32v3, 337 tCubeArray_f32v3) 338 && TEST_texture<float4>( 339 t1D_f32v4, 340 t2D_f32v4, 341 t3D_f32v4, 342 tCube_f32v4, 343 t1DArray_f32v4, 344 t2DArray_f32v4, 345 tCubeArray_f32v4) 346 ; 347 348 outputBuffer[0] = int(result); 349}