asahi: Clamp 8-bit integer RTs

Fixes gl-3.0-render-integer.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26056>
This commit is contained in:
Alyssa Rosenzweig 2023-10-23 06:59:46 -04:00 committed by Marge Bot
parent 8d9d9d0207
commit 019a52fff0

View file

@ -3,8 +3,10 @@
* SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#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,