From 8a406fe05526676fcaedd54e956b87d45ac8738a Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 29 Nov 2022 14:26:44 -0600 Subject: [PATCH] nir: Fix builder usage in lower_mediump_vars() In our handling of load_deref, we were calling builder helpers to create conversions and then adjusting the destination bit size of the load. We should adjust the bit size first because the builder sometimes looks at the bit sizes of SSA values passed in as arguments. Even though it's not strictly necessary, adjust the store_deref case as well to make it fully symmetric with the load_deref case. Reviewed-by: Emma Anholt Part-of: --- src/compiler/nir/nir_lower_mediump.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/nir/nir_lower_mediump.c b/src/compiler/nir/nir_lower_mediump.c index 7f870a6b3b1..877bb305d9f 100644 --- a/src/compiler/nir/nir_lower_mediump.c +++ b/src/compiler/nir/nir_lower_mediump.c @@ -456,9 +456,13 @@ nir_lower_mediump_vars_impl(nir_function_impl *impl, nir_variable_mode modes, break; nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]); - nir_ssa_def *replace = NULL; + if (glsl_get_bit_size(deref->type) != 16) + break; + + intrin->dest.ssa.bit_size = 16; b.cursor = nir_after_instr(&intrin->instr); + nir_ssa_def *replace = NULL; switch (glsl_get_base_type(deref->type)) { case GLSL_TYPE_FLOAT16: replace = nir_f2f32(&b, &intrin->dest.ssa); @@ -470,12 +474,9 @@ nir_lower_mediump_vars_impl(nir_function_impl *impl, nir_variable_mode modes, replace = nir_u2u32(&b, &intrin->dest.ssa); break; default: - break; + unreachable("Invalid 16-bit type"); } - if (!replace) - break; - intrin->dest.ssa.bit_size = 16; nir_ssa_def_rewrite_uses_after(&intrin->dest.ssa, replace, replace->parent_instr); @@ -488,8 +489,11 @@ nir_lower_mediump_vars_impl(nir_function_impl *impl, nir_variable_mode modes, if (data->bit_size != 32) break; - b.cursor = nir_before_instr(&intrin->instr); nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]); + if (glsl_get_bit_size(deref->type) != 16) + break; + + b.cursor = nir_before_instr(&intrin->instr); nir_ssa_def *replace = NULL; switch (glsl_get_base_type(deref->type)) { case GLSL_TYPE_FLOAT16: @@ -500,10 +504,8 @@ nir_lower_mediump_vars_impl(nir_function_impl *impl, nir_variable_mode modes, replace = nir_i2imp(&b, data); break; default: - break; + unreachable("Invalid 16-bit type"); } - if (!replace) - break; nir_instr_rewrite_src(&intrin->instr, &intrin->src[1], nir_src_for_ssa(replace));