From 06e1ab6982df097727b74174d5b39a7f27c2dae3 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 22 May 2019 09:58:19 -0700 Subject: Translate .Load() to imageLoad() for Vulkan (#967) * Translate .Load() to imageLoad() for Vulkan We were already emitting calls to `imageLoad()` and `imageStore` when a `RWTexture*` was used with `operator[]`: ```hlsl RWTexture2D myTex; ... float value = myTex[xy]; // becomes an imageLoad myTex[xy] = value; // becomes an imageStore ``` However, we were *not* correctly handling the translation of an explicit `.Load()` operation: ```hlsl float value = myTex.Load(xy); ``` The `.Load()` operation was being translated to a GLSL `texelFetch` as it would be a for a `Texture2D`, and not to an `imageLoad()` as would make sense for a `RWTexture2D` (which becomes a GLSL `image2D`). This fix is confined to the stdlib, and is mostly a matter of emitting either `texelFetch` or `imageLoad` as the GLSL function name depending on the "access" of the resource type. It is messy code, but straightforward. One extra detail was that there had been logic to emit a `, 0` argument in the `texelFetch` calls in the non-read-only case, because `texelFetch` usualy requires an explicit mip-level argument and `.Load()` on a `RWTexture*` doesn't recieve an LOD parameter. This is a non-issue now that we are calling `imageLoad()` instead, because `imageLoad` doesn't need/want the extra argument. * fixup: change test baseline based on recent GLSL output changes * fixup: review feedback --- tests/cross-compile/image-load.slang | 19 +++++++++++++++++++ tests/cross-compile/image-load.slang.glsl | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/cross-compile/image-load.slang create mode 100644 tests/cross-compile/image-load.slang.glsl (limited to 'tests') diff --git a/tests/cross-compile/image-load.slang b/tests/cross-compile/image-load.slang new file mode 100644 index 000000000..7f125bd5a --- /dev/null +++ b/tests/cross-compile/image-load.slang @@ -0,0 +1,19 @@ +// image-load.slang + +// This test confirms that `.Load()` on a `RWTexure*` +// gets properly converted to a call to `imageLoad` +// and not just `texelFetch` as it would for a `Texture*`. + +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage compute + +struct Params +{ + RWTexture2DArray tex; +} + +ParameterBlock gParams; + +void main(uint3 tid : SV_DispatchThreadID) +{ + float f = gParams.tex.Load(int3(tid.xy, tid.z)); +} diff --git a/tests/cross-compile/image-load.slang.glsl b/tests/cross-compile/image-load.slang.glsl new file mode 100644 index 000000000..c7233c38c --- /dev/null +++ b/tests/cross-compile/image-load.slang.glsl @@ -0,0 +1,23 @@ +// image-load.slang.glsl +//TEST_IGNORE_FILE: + +#version 450 + +#extension GL_EXT_samplerless_texture_functions : require + +layout(r32f) +layout(binding = 0) +uniform image2DArray gParams_tex_0; + +layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +void main() +{ + float _S1 = imageLoad( + gParams_tex_0, + ivec3( + ivec2(gl_GlobalInvocationID.xy), + int(gl_GlobalInvocationID.z))).x; + + return; +} -- cgit v1.2.3