From 019a52fff0d1ac8979937deeec3cda1d01aabb73 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 23 Oct 2023 06:59:46 -0400 Subject: [PATCH] asahi: Clamp 8-bit integer RTs Fixes gl-3.0-render-integer. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_nir_lower_tilebuffer.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/asahi/lib/agx_nir_lower_tilebuffer.c b/src/asahi/lib/agx_nir_lower_tilebuffer.c index 763b3cf5967..20820a43ccf 100644 --- a/src/asahi/lib/agx_nir_lower_tilebuffer.c +++ b/src/asahi/lib/agx_nir_lower_tilebuffer.c @@ -3,8 +3,10 @@ * SPDX-License-Identifier: MIT */ +#include #include "compiler/agx_internal_formats.h" #include "compiler/glsl_types.h" +#include "util/format/u_format.h" #include "util/macros.h" #include "agx_nir_format_helpers.h" #include "agx_pack.h" @@ -57,6 +59,24 @@ store_tilebuffer(nir_builder *b, struct agx_tilebuffer_layout *tib, value = nir_f2f32(b, value); } + /* 8-bit formats must be clamped in software, so do so on store. Piglit + * gl-3.0-render-integer checks this. + */ + const struct util_format_description *desc = util_format_description(format); + unsigned c = util_format_get_first_non_void_channel(format); + + if (desc->channel[c].size == 8 && util_format_is_pure_integer(format)) { + assert(desc->is_array); + + value = nir_u2u16(b, value); + if (util_format_is_pure_sint(logical_format)) { + value = nir_iclamp(b, value, nir_imm_intN_t(b, INT8_MIN, 16), + nir_imm_intN_t(b, INT8_MAX, 16)); + } else { + value = nir_umin(b, value, nir_imm_intN_t(b, UINT8_MAX, 16)); + } + } + uint8_t offset_B = agx_tilebuffer_offset_B(tib, rt); nir_store_local_pixel_agx(b, value, nir_imm_intN_t(b, ALL_SAMPLES, 16), .base = offset_B, .write_mask = write_mask,