summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Kristian Arntzen <post@arntzen-software.no>2023-01-12 17:48:00 +0100
committerGitHub <noreply@github.com>2023-01-12 17:48:00 +0100
commit88c6b49959b7aaaaf105d1a11c67c50ed3623232 (patch)
tree53eb68f213bb8836a41e15c5212d5755793545df
parenta08522739581579b7bb4e94a126f5e933115b233 (diff)
parent1047c13d40a2fccd5198ad8992618af2dab0303f (diff)
downloadSPIRV-Cross-88c6b49959b7aaaaf105d1a11c67c50ed3623232.tar.gz
SPIRV-Cross-88c6b49959b7aaaaf105d1a11c67c50ed3623232.tar.bz2
SPIRV-Cross-88c6b49959b7aaaaf105d1a11c67c50ed3623232.zip
Merge pull request #2085 from KhronosGroup/fix-2075
GLSL: Handle textureGatherOffsets properly.
-rw-r--r--reference/shaders-no-opt/frag/texture-gather-offsets.frag12
-rw-r--r--shaders-no-opt/frag/texture-gather-offsets.frag14
-rw-r--r--spirv_glsl.cpp18
-rw-r--r--spirv_glsl.hpp2
-rw-r--r--spirv_msl.cpp23
5 files changed, 44 insertions, 25 deletions
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 5d13208e..4b22d47e 100644
--- a/spirv_glsl.cpp
+++ b/spirv_glsl.cpp
@@ -7299,8 +7299,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;
@@ -7692,13 +7698,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);