From 521651d1064a42feb9d21fc1799479619ce50729 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 28 May 2021 01:01:51 -0400 Subject: [PATCH] st/mesa: remove st_vertex_program::input_to_index It's the same as a prefix bitcount of inputs_read. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/state_tracker/st_atom_array.c | 11 ++++------- src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +- src/mesa/state_tracker/st_program.c | 24 +++++++++++++++++------- src/mesa/state_tracker/st_program.h | 5 +---- src/mesa/state_tracker/st_shader_cache.c | 4 ---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c index 1b1d463..38e7823 100644 --- a/src/mesa/state_tracker/st_atom_array.c +++ b/src/mesa/state_tracker/st_atom_array.c @@ -82,7 +82,6 @@ setup_arrays(struct st_context *st, const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO; const GLbitfield inputs_read = vp_variant->vert_attrib_mask; const GLbitfield dual_slot_inputs = vp->Base.Base.DualSlotInputs; - const ubyte *input_to_index = vp->input_to_index; /* Process attribute array data. */ GLbitfield mask = inputs_read & _mesa_draw_array_bits(ctx); @@ -119,7 +118,7 @@ setup_arrays(struct st_context *st, init_velement(velements->velems, &attrib->Format, 0, binding->InstanceDivisor, bufidx, dual_slot_inputs & BITFIELD_BIT(attr), - input_to_index[attr]); + util_bitcount(inputs_read & BITFIELD_MASK(attr))); } return; } @@ -161,7 +160,7 @@ setup_arrays(struct st_context *st, init_velement(velements->velems, &attrib->Format, off, binding->InstanceDivisor, bufidx, dual_slot_inputs & BITFIELD_BIT(attr), - input_to_index[attr]); + util_bitcount(inputs_read & BITFIELD_MASK(attr))); } while (attrmask); } } @@ -198,7 +197,6 @@ st_setup_current(struct st_context *st, /* Process values that should have better been uniforms in the application */ GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx); if (curmask) { - const ubyte *input_to_index = vp->input_to_index; /* For each attribute, upload the maximum possible size. */ GLubyte data[VERT_ATTRIB_MAX * sizeof(GLdouble) * 4]; GLubyte *cursor = data; @@ -218,7 +216,7 @@ st_setup_current(struct st_context *st, init_velement(velements->velems, &attrib->Format, cursor - data, 0, bufidx, dual_slot_inputs & BITFIELD_BIT(attr), - input_to_index[attr]); + util_bitcount(inputs_read & BITFIELD_MASK(attr))); cursor += alignment; } while (curmask); @@ -256,7 +254,6 @@ st_setup_current_user(struct st_context *st, struct gl_context *ctx = st->ctx; const GLbitfield inputs_read = vp_variant->vert_attrib_mask; const GLbitfield dual_slot_inputs = vp->Base.Base.DualSlotInputs; - const ubyte *input_to_index = vp->input_to_index; /* Process values that should have better been uniforms in the application */ GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx); @@ -269,7 +266,7 @@ st_setup_current_user(struct st_context *st, init_velement(velements->velems, &attrib->Format, 0, 0, bufidx, dual_slot_inputs & BITFIELD_BIT(attr), - input_to_index[attr]); + util_bitcount(inputs_read & BITFIELD_MASK(attr))); vbuffer[bufidx].is_user_buffer = true; vbuffer[bufidx].buffer.user = attrib->Ptr; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 303dc08..182644b 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -921,7 +921,7 @@ st_link_nir(struct gl_context *ctx, /* Initialize st_vertex_program members. */ if (shader->Stage == MESA_SHADER_VERTEX) - st_prepare_vertex_program(stp); + st_prepare_vertex_program(stp, NULL); /* Get pipe_stream_output_info. */ if (shader->Stage == MESA_SHADER_VERTEX || diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index aaa9b59..25e2eca 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -414,14 +414,20 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog, return nir; } +/** + * Prepare st_vertex_program info. + * + * attrib_to_index is an optional mapping from a vertex attrib to a shader + * input index. + */ void -st_prepare_vertex_program(struct st_program *stp) +st_prepare_vertex_program(struct st_program *stp, uint8_t *out_attrib_to_index) { struct st_vertex_program *stvp = (struct st_vertex_program *)stp; + uint8_t attrib_to_index[VERT_ATTRIB_MAX] = {0}; stvp->num_inputs = 0; stvp->vert_attrib_mask = 0; - memset(stvp->input_to_index, ~0, sizeof(stvp->input_to_index)); memset(stvp->result_to_output, ~0, sizeof(stvp->result_to_output)); /* Determine number of inputs, the mappings between VERT_ATTRIB_x @@ -429,14 +435,14 @@ st_prepare_vertex_program(struct st_program *stp) */ for (unsigned attr = 0; attr < VERT_ATTRIB_MAX; attr++) { if ((stp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) { - stvp->input_to_index[attr] = stvp->num_inputs; + attrib_to_index[attr] = stvp->num_inputs; stvp->vert_attrib_mask |= BITFIELD_BIT(attr); stvp->num_inputs++; } } /* pre-setup potentially unused edgeflag input */ - stvp->input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs; + attrib_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs; /* Compute mapping of vertex program outputs to slots. */ unsigned num_outputs = 0; @@ -446,6 +452,9 @@ st_prepare_vertex_program(struct st_program *stp) } /* pre-setup potentially unused edgeflag output */ stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs; + + if (out_attrib_to_index) + memcpy(out_attrib_to_index, attrib_to_index, sizeof(attrib_to_index)); } void @@ -608,11 +617,12 @@ st_translate_vertex_program(struct st_context *st, MESA_SHADER_VERTEX); stp->Base.info = stp->Base.nir->info; - st_prepare_vertex_program(stp); + st_prepare_vertex_program(stp, NULL); return true; } - st_prepare_vertex_program(stp); + uint8_t input_to_index[VERT_ATTRIB_MAX]; + st_prepare_vertex_program(stp, input_to_index); /* Get semantic names and indices. */ for (attr = 0; attr < VARYING_SLOT_MAX; attr++) { @@ -650,7 +660,7 @@ st_translate_vertex_program(struct st_context *st, &stp->Base, /* inputs */ stvp->num_inputs, - stvp->input_to_index, + input_to_index, NULL, /* inputSlotToAttr */ NULL, /* input semantic name */ NULL, /* input semantic index */ diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 66e1656..af8c32f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -282,10 +282,7 @@ struct st_vertex_program struct st_program Base; uint32_t vert_attrib_mask; /**< mask of sourced vertex attribs */ - ubyte num_inputs; - /** Map a vertex attrib to a gallium vertex element index. */ - ubyte input_to_index[VERT_ATTRIB_MAX]; /** Maps VARYING_SLOT_x to slot */ ubyte result_to_output[VARYING_SLOT_MAX]; @@ -357,7 +354,7 @@ extern void st_finalize_nir_before_variants(struct nir_shader *nir); extern void -st_prepare_vertex_program(struct st_program *stvp); +st_prepare_vertex_program(struct st_program *stvp, uint8_t *attrib_to_index); extern void st_translate_stream_output_info(struct gl_program *prog); diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c index 72c7cfa..a69e137 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -101,8 +101,6 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog, blob_write_uint32(&blob, stvp->num_inputs); blob_write_uint32(&blob, stvp->vert_attrib_mask); - blob_write_bytes(&blob, stvp->input_to_index, - sizeof(stvp->input_to_index)); blob_write_bytes(&blob, stvp->result_to_output, sizeof(stvp->result_to_output)); } @@ -198,8 +196,6 @@ st_deserialise_ir_program(struct gl_context *ctx, struct st_vertex_program *stvp = (struct st_vertex_program *)stp; stvp->num_inputs = blob_read_uint32(&blob_reader); stvp->vert_attrib_mask = blob_read_uint32(&blob_reader); - blob_copy_bytes(&blob_reader, (uint8_t *) stvp->input_to_index, - sizeof(stvp->input_to_index)); blob_copy_bytes(&blob_reader, (uint8_t *) stvp->result_to_output, sizeof(stvp->result_to_output)); } -- 2.7.4