From 140ca7e5d72323a4685b5043dbac272931b055bb Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Sat, 27 Jul 2024 18:27:03 +1000 Subject: [PATCH] glsl: fix glsl to nir support for lower precision builtins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we switch to the full nir based glsl linker in an upcomming merge request this is required for existing tests from 8fcf8e7fd401 to continue to pass, this is because they never exercised glsl to nir so the missing support went unnoticed. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11456 Fixes: 8fcf8e7fd401 ("glsl: lower builtins to mediump that ignore precision of certain parameters ") Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 9a3334f7393..f37451ab039 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -1730,10 +1730,24 @@ nir_visitor::visit(ir_expression *ir) case ir_binop_interpolate_at_sample: { ir_dereference *deref = ir->operands[0]->as_dereference(); ir_swizzle *swizzle = NULL; + ir_expression *precision_op = NULL; if (!deref) { - swizzle = ir->operands[0]->as_swizzle(); - assert(swizzle); - deref = swizzle->val->as_dereference(); + precision_op = ir->operands[0]->as_expression(); + if (precision_op) { + /* For some builtins precision is lowered to mediump for certain + * parameters that ignore precision. For example for Interpolation + * and Bitfield functions. + */ + assert(precision_op->operation == ir_unop_f2fmp); + deref = precision_op->operands[0]->as_dereference(); + } + + if (!deref) { + swizzle = ir->operands[0]->as_swizzle(); + assert(swizzle); + deref = swizzle->val->as_dereference(); + } + assert(deref); } @@ -1775,6 +1789,10 @@ nir_visitor::visit(ir_expression *ir) swizzle->type->vector_elements); } + if (precision_op) { + result = nir_build_alu(&b, nir_op_f2fmp, result, NULL, NULL, NULL); + } + return; }