From 1047c13d40a2fccd5198ad8992618af2dab0303f Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 12 Jan 2023 16:24:49 +0100 Subject: GLSL: Handle textureGatherOffsets properly. We forgot to pass down the offset ID, clean up coffset vs offset jank while we're at it. --- .../frag/texture-gather-offsets.frag | 12 +++++++++++ shaders-no-opt/frag/texture-gather-offsets.frag | 14 +++++++++++++ spirv_glsl.cpp | 18 ++++++++--------- spirv_glsl.hpp | 2 +- spirv_msl.cpp | 23 ++++++++-------------- 5 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 reference/shaders-no-opt/frag/texture-gather-offsets.frag create mode 100644 shaders-no-opt/frag/texture-gather-offsets.frag diff --git a/reference/shaders-no-opt/frag/texture-gather-offsets.frag b/reference/shaders-no-opt/frag/texture-gather-offsets.frag new file mode 100644 index 00000000..36409dd3 --- /dev/null +++ b/reference/shaders-no-opt/frag/texture-gather-offsets.frag @@ -0,0 +1,12 @@ +#version 460 + +layout(binding = 0) uniform sampler2D Image0; + +layout(location = 0) out vec4 outColor; +layout(location = 0) in vec2 inUv; + +void main() +{ + outColor = textureGatherOffsets(Image0, inUv, ivec2[](ivec2(0), ivec2(1, 0), ivec2(1), ivec2(0, 1))); +} + diff --git a/shaders-no-opt/frag/texture-gather-offsets.frag b/shaders-no-opt/frag/texture-gather-offsets.frag new file mode 100644 index 00000000..52d79097 --- /dev/null +++ b/shaders-no-opt/frag/texture-gather-offsets.frag @@ -0,0 +1,14 @@ +#version 460 core +#extension GL_ARB_separate_shader_objects : enable + +layout(location = 0) in vec2 inUv; + +layout(location = 0) out vec4 outColor; + +layout(set=0, binding=0) uniform sampler2D Image0; + +void main(void) +{ + const ivec2 offs[4] = {ivec2(0,0), ivec2(1,0), ivec2(1,1), ivec2(0,1)}; + outColor = textureGatherOffsets(Image0, inUv, offs); +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 6ec2c7a6..f64af2ed 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -7290,8 +7290,14 @@ std::string CompilerGLSL::to_texture_op(const Instruction &i, bool sparse, bool args.grad_x = grad_x; args.grad_y = grad_y; args.lod = lod; - args.coffset = coffset; - args.offset = offset; + + if (coffsets) + args.offset = coffsets; + else if (coffset) + args.offset = coffset; + else + args.offset = offset; + args.bias = bias; args.component = comp; args.sample = sample; @@ -7683,13 +7689,7 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool farg_str += ", 0"; } - if (args.coffset) - { - forward = forward && should_forward(args.coffset); - farg_str += ", "; - farg_str += bitcast_expression(SPIRType::Int, args.coffset); - } - else if (args.offset) + if (args.offset) { forward = forward && should_forward(args.offset); farg_str += ", "; diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index c3f2bfc8..4dcde554 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -448,7 +448,7 @@ protected: TextureFunctionArguments() = default; TextureFunctionBaseArguments base; uint32_t coord = 0, coord_components = 0, dref = 0; - uint32_t grad_x = 0, grad_y = 0, lod = 0, coffset = 0, offset = 0; + uint32_t grad_x = 0, grad_y = 0, lod = 0, offset = 0; uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0; bool nonuniform_expression = false; }; diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 38d22891..0e67fa1a 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -10701,25 +10701,24 @@ string CompilerMSL::to_function_args(const TextureFunctionArguments &args, bool break; } - if (args.base.is_fetch && (args.offset || args.coffset)) + if (args.base.is_fetch && args.offset) { - uint32_t offset_expr = args.offset ? args.offset : args.coffset; // Fetch offsets must be applied directly to the coordinate. - forward = forward && should_forward(offset_expr); - auto &type = expression_type(offset_expr); + forward = forward && should_forward(args.offset); + auto &type = expression_type(args.offset); if (imgtype.image.dim == Dim1D && msl_options.texture_1D_as_2D) { if (type.basetype != SPIRType::UInt) - tex_coords += join(" + uint2(", bitcast_expression(SPIRType::UInt, offset_expr), ", 0)"); + tex_coords += join(" + uint2(", bitcast_expression(SPIRType::UInt, args.offset), ", 0)"); else - tex_coords += join(" + uint2(", to_enclosed_expression(offset_expr), ", 0)"); + tex_coords += join(" + uint2(", to_enclosed_expression(args.offset), ", 0)"); } else { if (type.basetype != SPIRType::UInt) - tex_coords += " + " + bitcast_expression(SPIRType::UInt, offset_expr); + tex_coords += " + " + bitcast_expression(SPIRType::UInt, args.offset); else - tex_coords += " + " + to_enclosed_expression(offset_expr); + tex_coords += " + " + to_enclosed_expression(args.offset); } } @@ -10923,13 +10922,7 @@ string CompilerMSL::to_function_args(const TextureFunctionArguments &args, bool // Add offsets string offset_expr; const SPIRType *offset_type = nullptr; - if (args.coffset && !args.base.is_fetch) - { - forward = forward && should_forward(args.coffset); - offset_expr = to_expression(args.coffset); - offset_type = &expression_type(args.coffset); - } - else if (args.offset && !args.base.is_fetch) + if (args.offset && !args.base.is_fetch) { forward = forward && should_forward(args.offset); offset_expr = to_expression(args.offset); -- cgit v1.2.3