From 22f1b04a99a587bcc3a20d19f2db0eb657cb4789 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 18 Jun 2024 10:52:51 -0500 Subject: [PATCH] nir/format_convert: Assert that UNORM formats are <= 16 bits Reviewed-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- src/compiler/nir/nir_format_convert.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_format_convert.c b/src/compiler/nir/nir_format_convert.c index 7bc871dfed2..8bd25ff5005 100644 --- a/src/compiler/nir/nir_format_convert.c +++ b/src/compiler/nir/nir_format_convert.c @@ -199,7 +199,11 @@ _nir_format_norm_factor(nir_builder *b, const unsigned *bits, nir_const_value factor[NIR_MAX_VEC_COMPONENTS]; memset(factor, 0, sizeof(factor)); for (unsigned i = 0; i < num_components; i++) { - assert(bits[i] <= 32); + /* A 16-bit float only has 23 bits of mantissa. This isn't enough to + * convert 24 or 32-bit UNORM/SNORM accurately. For that, we would need + * fp64 or some sort of fixed-point math. + */ + assert(bits[i] <= 16); factor[i].f32 = (1ull << (bits[i] - is_signed)) - 1; } return nir_build_imm(b, num_components, 32, factor);