nir: Add helpers for lazy var creation.

This should make writing some lowering/meta code easier.  It also keeps
the num_inputs/outputs updated, when sometimes passes forgot to do so (for
example, nir_lower_input_attachments updated for one of the two vars it
creates).  The names of the variables change in many cases, but it's
probably nicer to see "VERT_ATTRIB_POS" than "in_0" or whatever.

I've only converted mesa core (compiler and GL), not all the driver meta
code.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22809>
This commit is contained in:
Emma Anholt
2023-05-02 15:40:51 -07:00
committed by Marge Bot
parent e31b7a3f9e
commit 0f25bb8283
19 changed files with 192 additions and 286 deletions

View File

@@ -52,24 +52,6 @@
* Run before nir_lower_io.
*/
static nir_variable *
get_texcoord(nir_shader *shader)
{
nir_variable *texcoord =
nir_find_variable_with_location(shader, nir_var_shader_in,
VARYING_SLOT_TEX0);
/* otherwise create it: */
if (texcoord == NULL) {
texcoord = nir_variable_create(shader,
nir_var_shader_in,
glsl_vec4_type(),
"gl_TexCoord");
texcoord->data.location = VARYING_SLOT_TEX0;
}
return texcoord;
}
static void
lower_bitmap(nir_shader *shader, nir_builder *b,
const nir_lower_bitmap_options *options)
@@ -78,7 +60,8 @@ lower_bitmap(nir_shader *shader, nir_builder *b,
nir_tex_instr *tex;
nir_ssa_def *cond;
texcoord = nir_load_var(b, get_texcoord(shader));
texcoord = nir_load_var(b, nir_get_variable_with_location(shader, nir_var_shader_in,
VARYING_SLOT_TEX0, glsl_vec4_type()));
const struct glsl_type *sampler2D =
glsl_sampler_type(GLSL_SAMPLER_DIM_2D, false, false, GLSL_TYPE_FLOAT);