From aba7b0831cea97c06ae78c9395f1760078423d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 1 Jun 2025 19:06:32 -0400 Subject: [PATCH] nir: add shader_info::prev_stage When lowering mediump to 16 bits, this will allow drivers to enable the lowering only for certain pairs of stages, e.g. a driver can lower mediump for VS->FS, but not GS->FS. This could also be useful for other things. Reviewed-by: Timothy Arceri Part-of: --- src/compiler/nir/nir.c | 5 +++-- src/compiler/nir/nir_print.c | 2 ++ src/compiler/shader_info.h | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index f3a32256a63..feeb0f4d432 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -216,9 +216,10 @@ nir_shader_create(void *mem_ctx, } else { shader->info.stage = stage; - /* Assume there is no known next stage, this is the case for - * nir_builder_init_simple_shaders for example. + /* Assume there is no known prev/next stage, this is the case for + * nir_builder_init_simple_shader for example. */ + shader->info.prev_stage = MESA_SHADER_NONE; shader->info.next_stage = MESA_SHADER_NONE; } diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 90c6acfddf1..d55dded461b 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -2623,6 +2623,8 @@ print_shader_info(const struct shader_info *info, FILE *fp) info->workgroup_size_variable ? " (variable)" : ""); } + if (info->prev_stage != MESA_SHADER_NONE) + fprintf(fp, "prev_stage: %s\n", gl_shader_stage_name(info->prev_stage)); if (info->next_stage != MESA_SHADER_NONE) fprintf(fp, "next_stage: %s\n", gl_shader_stage_name(info->next_stage)); diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index a88be726d27..4dfbb90373d 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -52,9 +52,10 @@ typedef struct shader_info { /** The shader stage, such as MESA_SHADER_VERTEX. */ gl_shader_stage stage:8; - /** The shader stage in a non SSO linked program that follows this stage, - * such as MESA_SHADER_FRAGMENT. - */ + /* If the shader is linked, this is the previous shader, else MESA_SHADER_NONE. */ + gl_shader_stage prev_stage:8; + + /* If the shader is linked, this is the next shader, else MESA_SHADER_NONE. */ gl_shader_stage next_stage:8; /* Number of textures used by this shader */