From 41fde4b836dbab627f8643a5002b2b6dd0417211 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 25 Jan 2019 12:02:50 -0800 Subject: Fix GLSL translation of several Texture* operations (#800) A user found that the `Texture2D.Load(...)` operation was not being compiled to GLSL properly, such that it returned a `vec4` instead of the expected `vec2`. The GLSL texture-related functions always return (and take) 4-component vectors, and we already have infrastructure in `emit.cpp` for recognizing a `$z` operator in the GLSL intrinsic definition to stand in for an appropriate swizzle based on teh number of components in the texture result type. This change just adds that `$z` operator to the GLSL code for several more texture operations (including `Load()`) that are defined on a `Texture*` and that return `T`. This change doesn't try to add additional GLSL translations for texture-related operations (e.g., additional variations like `SampleCmp` that we have defined in the stdlib but not given GLSL translations for). That work still needs to be done. --- tests/cross-compile/texture-load.slang | 21 ++++++++++++++ tests/cross-compile/texture-load.slang.glsl | 44 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/cross-compile/texture-load.slang create mode 100644 tests/cross-compile/texture-load.slang.glsl (limited to 'tests') diff --git a/tests/cross-compile/texture-load.slang b/tests/cross-compile/texture-load.slang new file mode 100644 index 000000000..71f22b13a --- /dev/null +++ b/tests/cross-compile/texture-load.slang @@ -0,0 +1,21 @@ +// texture-load.slang + +// Confirm that texture `Load` operations yield the +// expected type when compiled to SPIR-V. + +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage compute + +Texture2D inputTexture; +RWTexture2D outputTexture; + +cbuffer C +{ + int2 pos; +} + +[numthreads(16, 16, 1)] +void main(uint2 pixelIndex : SV_DispatchThreadID) +{ + float2 tmp = inputTexture.Load(int3(pos,0)); + outputTexture[pos] = tmp; +} diff --git a/tests/cross-compile/texture-load.slang.glsl b/tests/cross-compile/texture-load.slang.glsl new file mode 100644 index 000000000..23646db91 --- /dev/null +++ b/tests/cross-compile/texture-load.slang.glsl @@ -0,0 +1,44 @@ +// texture-load.slang.glsl +//TEST_IGNORE_FILE: + +#version 450 + +layout(row_major) uniform; +layout(row_major) buffer; + +#extension GL_EXT_samplerless_texture_functions : require + +struct SLANG_ParameterGroup_C_0 +{ + ivec2 pos_0; +}; + +layout(binding = 2) +layout(std140) +uniform _S1 +{ + SLANG_ParameterGroup_C_0 _data; +} C_0; + +layout(binding = 0) +uniform texture2D inputTexture_0; + +layout(rg32f) +layout(binding = 1) +uniform image2D outputTexture_0; + +layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; +void main() +{ + vec2 tmp_0 = texelFetch( + inputTexture_0, + ivec3(C_0._data.pos_0, 0).xy, + ivec3(C_0._data.pos_0, 0).z).xy; + + imageStore( + outputTexture_0, + ivec2(uvec2(C_0._data.pos_0)), + vec4(tmp_0, float(0), float(0))); + + return; +} -- cgit v1.2.3