diff options
author | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2022-02-06 11:33:51 -0500 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-02-18 23:48:32 +0000 |
commit | 055c5a59f8dc7a7ba7b60772b2659f5f978ca7ce (patch) | |
tree | cc9c961567cd7a788e2d793eaa5ffbc7c746623c | |
parent | a822b7b6cceb4c893ea7fab679bc3b51552d119b (diff) |
agx: Round and clamp array indices
Conforming with the GLSL spec. Fixes:
dEQP-GLES3.functional.shaders.texture_functions.texture.sampler2darray_fixed_fragment
(and probably others)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14903>
-rw-r--r-- | src/asahi/compiler/agx_compile.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index ad0b030758c..1decc88170e 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -822,7 +822,13 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr) /* Array textures are indexed by a floating-point in NIR, but by an * integer in AGX. Convert the array index from float-to-int for array - * textures. The array index is the last source in NIR. + * textures. The array index is the last source in NIR. The conversion + * is according to the rule from 8.9 ("Texture Functions") of the GLSL + * ES 3.20 specification: + * + * max(0, min(d - 1, floor(layer + 0.5))) = + * max(0, min(d - 1, f32_to_u32(layer + 0.5))) = + * min(d - 1, f32_to_u32(layer + 0.5)) */ if (instr->is_array) { unsigned nr = nir_src_num_components(instr->src[i].src); @@ -831,10 +837,21 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr) for (unsigned i = 0; i < nr; ++i) channels[i] = agx_p_extract(b, index, i); - channels[nr - 1] = agx_convert(b, - agx_immediate(AGX_CONVERT_F_TO_S32), - channels[nr - 1], AGX_ROUND_RTZ); + agx_index layer = agx_fadd(b, channels[nr - 1], + agx_immediate_f(0.5f)); + agx_index d1 = agx_indexed_sysval(b->shader, + AGX_PUSH_ARRAY_SIZE_MINUS_1, AGX_SIZE_16, + instr->texture_index, 1); + + layer = agx_convert(b, agx_immediate(AGX_CONVERT_F_TO_U32), layer, + AGX_ROUND_RTZ); + layer = agx_mov(b, AGX_SIZE_16, layer); + + layer = agx_icmpsel(b, layer, d1, layer, d1, AGX_ICOND_ULT); + layer = agx_mov(b, AGX_SIZE_32, layer); + + channels[nr - 1] = layer; coords = agx_p_combine(b, channels[0], channels[1], channels[2], channels[3]); } else { coords = index; |