GLSL: Handle textureGatherOffsets properly.

We forgot to pass down the offset ID, clean up coffset vs offset jank
while we're at it.
This commit is contained in:
Hans-Kristian Arntzen 2023-01-12 16:24:49 +01:00
parent 38cd214007
commit 1047c13d40
5 changed files with 44 additions and 25 deletions

View File

@ -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)));
}

View File

@ -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);
}

View File

@ -7290,8 +7290,14 @@ std::string CompilerGLSL::to_texture_op(const Instruction &i, bool sparse, bool
args.grad_x = grad_x; args.grad_x = grad_x;
args.grad_y = grad_y; args.grad_y = grad_y;
args.lod = lod; 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.bias = bias;
args.component = comp; args.component = comp;
args.sample = sample; args.sample = sample;
@ -7683,13 +7689,7 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool
farg_str += ", 0"; farg_str += ", 0";
} }
if (args.coffset) if (args.offset)
{
forward = forward && should_forward(args.coffset);
farg_str += ", ";
farg_str += bitcast_expression(SPIRType::Int, args.coffset);
}
else if (args.offset)
{ {
forward = forward && should_forward(args.offset); forward = forward && should_forward(args.offset);
farg_str += ", "; farg_str += ", ";

View File

@ -448,7 +448,7 @@ protected:
TextureFunctionArguments() = default; TextureFunctionArguments() = default;
TextureFunctionBaseArguments base; TextureFunctionBaseArguments base;
uint32_t coord = 0, coord_components = 0, dref = 0; 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; uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0;
bool nonuniform_expression = false; bool nonuniform_expression = false;
}; };

View File

@ -10701,25 +10701,24 @@ string CompilerMSL::to_function_args(const TextureFunctionArguments &args, bool
break; 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. // Fetch offsets must be applied directly to the coordinate.
forward = forward && should_forward(offset_expr); forward = forward && should_forward(args.offset);
auto &type = expression_type(offset_expr); auto &type = expression_type(args.offset);
if (imgtype.image.dim == Dim1D && msl_options.texture_1D_as_2D) if (imgtype.image.dim == Dim1D && msl_options.texture_1D_as_2D)
{ {
if (type.basetype != SPIRType::UInt) 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 else
tex_coords += join(" + uint2(", to_enclosed_expression(offset_expr), ", 0)"); tex_coords += join(" + uint2(", to_enclosed_expression(args.offset), ", 0)");
} }
else else
{ {
if (type.basetype != SPIRType::UInt) if (type.basetype != SPIRType::UInt)
tex_coords += " + " + bitcast_expression(SPIRType::UInt, offset_expr); tex_coords += " + " + bitcast_expression(SPIRType::UInt, args.offset);
else 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 // Add offsets
string offset_expr; string offset_expr;
const SPIRType *offset_type = nullptr; const SPIRType *offset_type = nullptr;
if (args.coffset && !args.base.is_fetch) if (args.offset && !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)
{ {
forward = forward && should_forward(args.offset); forward = forward && should_forward(args.offset);
offset_expr = to_expression(args.offset); offset_expr = to_expression(args.offset);