From 0ea2bad74d563a2478be12b4034b980cf9f2fcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Tue, 28 May 2024 16:14:46 +0200 Subject: [PATCH] nir/lower_io: Add option to implement mediump as 32-bit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For drivers that don't lower mediump shader inputs / outputs to 16-bit, it's better to ignore the mediump flag completely, letting mediump inputs / outputs work like normal 32-bit IO. Signed-off-by: Timur Kristóf Reviewed-by: Georg Lehmann Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir.h | 7 +++++++ src/compiler/nir/nir_lower_io.c | 22 +++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 407021cf4a5..ddfa9b84d2d 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3657,6 +3657,13 @@ typedef enum { nir_io_16bit_input_output_support = BITFIELD_BIT(2), + /** + * Implement mediump inputs and outputs as normal 32-bit IO. + * Causes the mediump flag to be not set for IO semantics, essentially + * destroying any mediump-related IO information in the shader. + */ + nir_io_mediump_is_32bit = BITFIELD_BIT(3), + /* Options affecting the GLSL compiler are below. */ /** diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 5ca5166b07f..fd88a98a6ce 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -272,6 +272,16 @@ get_io_offset(nir_builder *b, nir_deref_instr *deref, return offset; } +static bool +is_medium_precision(const nir_shader *shader, const nir_variable *var) +{ + if (shader->options->io_options & nir_io_mediump_is_32bit) + return false; + + return var->data.precision == GLSL_PRECISION_MEDIUM || + var->data.precision == GLSL_PRECISION_LOW; +} + static nir_def * emit_load(struct lower_io_state *state, nir_def *array_index, nir_variable *var, nir_def *offset, @@ -351,9 +361,7 @@ emit_load(struct lower_io_state *state, semantics.location = var->data.location; semantics.num_slots = get_number_of_slots(state, var); semantics.fb_fetch_output = var->data.fb_fetch_output; - semantics.medium_precision = - var->data.precision == GLSL_PRECISION_MEDIUM || - var->data.precision == GLSL_PRECISION_LOW; + semantics.medium_precision = is_medium_precision(b->shader, var); semantics.high_dvec2 = high_dvec2; semantics.per_primitive = var->data.per_primitive; /* "per_vertex" is misnamed. It means "explicit interpolation with @@ -503,9 +511,7 @@ emit_store(struct lower_io_state *state, nir_def *data, semantics.num_slots = get_number_of_slots(state, var); semantics.dual_source_blend_index = var->data.index; semantics.gs_streams = gs_streams; - semantics.medium_precision = - var->data.precision == GLSL_PRECISION_MEDIUM || - var->data.precision == GLSL_PRECISION_LOW; + semantics.medium_precision = is_medium_precision(b->shader, var); semantics.per_view = var->data.per_view; semantics.invariant = var->data.invariant; @@ -631,9 +637,7 @@ lower_interpolate_at(nir_intrinsic_instr *intrin, struct lower_io_state *state, nir_io_semantics semantics = { 0 }; semantics.location = var->data.location; semantics.num_slots = get_number_of_slots(state, var); - semantics.medium_precision = - var->data.precision == GLSL_PRECISION_MEDIUM || - var->data.precision == GLSL_PRECISION_LOW; + semantics.medium_precision = is_medium_precision(b->shader, var); nir_def *load = nir_load_interpolated_input(&state->builder,