From ef3552d9cbde0c06ddc77150b8ab68674d8422d3 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:46:32 -0700 Subject: Feature/wgsl intrinsic texture gather (#5141) This PR implements the texture gather functions for WGSL. The pattern was very similar to how Metal was implemented. Before copy and paste from the Metal implementation, I had to clean up the Metal implementation to make it more readable and maintainable. Gather functions are available only for 2D and 3D textures. Their `array` and `depth` variants may or may not be supported depending on the target. `static_assert` ensures that Gather functions are available only for 2D and 3D textures. Removed incorrect use of "$p" argument for targeting GLSL. --- tests/wgsl/texture-sampler-less.slang | 8 ++++++-- tests/wgsl/texture.slang | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/wgsl/texture-sampler-less.slang b/tests/wgsl/texture-sampler-less.slang index 1a6cb5341..893e867b7 100644 --- a/tests/wgsl/texture-sampler-less.slang +++ b/tests/wgsl/texture-sampler-less.slang @@ -311,23 +311,27 @@ bool TEST_texture( // https://www.w3.org/TR/WGSL/#texturegather // ================================== -#if 0 + // WGSL: textureGather({{.*}}t2D && all(Tv4(T(0)) == t2D.Gather(float2(u, u))) + // WGSL: textureGather({{.*}}tCube && all(Tv4(T(0)) == tCube.Gather(normalize(float3(u, 1 - u, u)))) + // WGSL: textureGather({{.*}}t2DArray && all(Tv4(T(0)) == t2DArray.Gather(float3(u, u, 0))) + // WGSL: textureGather({{.*}}tCubeArray && all(Tv4(T(0)) == tCubeArray.Gather(float4(normalize(float3(u, 1 - u, u)), 0))) #if TEST_WHEN_CONSTEXPR_WORKS_FOR_OFFSET // Offset variant + // W-GSL: textureGather({{.*}}t2D && all(Tv4(T(0)) == t2D.Gather(float2(u2, u), int2(0, 0))) + // W-GSL: textureGather({{.*}}t2DArray && all(Tv4(T(0)) == t2DArray.Gather(float3(u2, u, 0), int2(0, 0))) #endif // #if TEST_WHEN_CONSTEXPR_WORKS_FOR_OFFSET -#endif // ===================================== // T SampleGrad() diff --git a/tests/wgsl/texture.slang b/tests/wgsl/texture.slang index 999555a55..af39cf52a 100644 --- a/tests/wgsl/texture.slang +++ b/tests/wgsl/texture.slang @@ -346,21 +346,25 @@ bool TEST_texture( // https://www.w3.org/TR/WGSL/#texturegather // ================================== -#if 0 + // WGSL: textureGather({{.*}}t2D && all(Tv4(T(0)) == t2D.Gather(samplerState, float2(u, u))) + // WGSL: textureGather({{.*}}tCube && all(Tv4(T(0)) == tCube.Gather(samplerState, normalize(float3(u, 1 - u, u)))) + // WGSL: textureGather({{.*}}t2DArray && all(Tv4(T(0)) == t2DArray.Gather(samplerState, float3(u, u, 0))) + // WGSL: textureGather({{.*}}tCubeArray && all(Tv4(T(0)) == tCubeArray.Gather(samplerState, float4(normalize(float3(u, 1 - u, u)), 0))) // Offset variant + // WGSL: textureGather({{.*}}t2D && all(Tv4(T(0)) == t2D.Gather(samplerState, float2(u2, u), int2(0, 0))) + // WGSL: textureGather({{.*}}t2DArray && all(Tv4(T(0)) == t2DArray.Gather(samplerState, float3(u2, u, 0), int2(0, 0))) -#endif // ===================================== // T SampleGrad() -- cgit v1.2.3