st/mesa: Make the input_to_index array available.
authorMathias Fröhlich <mathias.froehlich@web.de>
Sun, 1 Apr 2018 18:18:36 +0000 (20:18 +0200)
committerMathias Fröhlich <Mathias.Froehlich@gmx.net>
Thu, 10 May 2018 05:06:15 +0000 (07:06 +0200)
The input_to_index array is already available internally
when preparing vertex programs. Store the map in
struct st_vertex_program.
Also store the bitmask of mesa vertex processing inputs in
struct st_vp_variant.

Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h
src/mesa/state_tracker/st_shader_cache.c

index fe72ddaf2c0aa0d14cad456f05de8de6172ca8d8..f256e2e862550f9279c2c77dade85616273325d9 100644 (file)
@@ -388,11 +388,11 @@ st_translate_vertex_program(struct st_context *st,
    enum pipe_error error;
    unsigned num_outputs = 0;
    unsigned attr;
-   ubyte input_to_index[VERT_ATTRIB_MAX] = {0};
    ubyte output_semantic_name[VARYING_SLOT_MAX] = {0};
    ubyte output_semantic_index[VARYING_SLOT_MAX] = {0};
 
    stvp->num_inputs = 0;
+   memset(stvp->input_to_index, ~0, sizeof(stvp->input_to_index));
 
    if (stvp->Base.arb.IsPositionInvariant)
       _mesa_insert_mvp_code(st->ctx, &stvp->Base);
@@ -403,7 +403,7 @@ st_translate_vertex_program(struct st_context *st,
     */
    for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
       if ((stvp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
-         input_to_index[attr] = stvp->num_inputs;
+         stvp->input_to_index[attr] = stvp->num_inputs;
          stvp->index_to_input[stvp->num_inputs] = attr;
          stvp->num_inputs++;
          if ((stvp->Base.info.vs.double_inputs_read &
@@ -415,7 +415,7 @@ st_translate_vertex_program(struct st_context *st,
       }
    }
    /* bit of a hack, presetup potentially unused edgeflag input */
-   input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs;
+   stvp->input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs;
    stvp->index_to_input[stvp->num_inputs] = VERT_ATTRIB_EDGEFLAG;
 
    /* Compute mapping of vertex program outputs to slots.
@@ -495,7 +495,7 @@ st_translate_vertex_program(struct st_context *st,
                                    &stvp->Base,
                                    /* inputs */
                                    stvp->num_inputs,
-                                   input_to_index,
+                                   stvp->input_to_index,
                                    NULL, /* inputSlotToAttr */
                                    NULL, /* input semantic name */
                                    NULL, /* input semantic index */
@@ -518,7 +518,7 @@ st_translate_vertex_program(struct st_context *st,
                                         &stvp->Base,
                                         /* inputs */
                                         stvp->num_inputs,
-                                        input_to_index,
+                                        stvp->input_to_index,
                                         NULL, /* input semantic name */
                                         NULL, /* input semantic index */
                                         NULL,
@@ -598,6 +598,13 @@ st_create_vp_variant(struct st_context *st,
          fprintf(stderr, "mesa: cannot emulate deprecated features\n");
    }
 
+   for (unsigned index = 0; index < vpv->num_inputs; ++index) {
+      unsigned attr = stvp->index_to_input[index];
+      if (attr == ST_DOUBLE_ATTRIB_PLACEHOLDER)
+         continue;
+      vpv->vert_attrib_mask |= 1u << attr;
+   }
+
    if (ST_DEBUG & DEBUG_TGSI) {
       tgsi_dump(vpv->tgsi.tokens, 0);
       debug_printf("\n");
index a520ffbecb4852c611531168ee0ed9427c886949..f67ea5eb2087cccde456eb314d40b75e02fc0f02 100644 (file)
@@ -196,6 +196,9 @@ struct st_vp_variant
 
    /** similar to that in st_vertex_program, but with edgeflags info too */
    GLuint num_inputs;
+
+   /** Bitfield of VERT_BIT_* bits of mesa vertex processing inputs */
+   GLbitfield vert_attrib_mask;
 };
 
 
@@ -215,6 +218,8 @@ struct st_vertex_program
    /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
    ubyte index_to_input[PIPE_MAX_ATTRIBS];
    ubyte num_inputs;
+   /** Reverse mapping of the above */
+   ubyte input_to_index[VERT_ATTRIB_MAX];
 
    /** Maps VARYING_SLOT_x to slot */
    ubyte result_to_output[VARYING_SLOT_MAX];
index 3ca3fef1df2aad10c7ce7f1a12655259ffb862d0..17f84180cae3b395a81e8daf267c6032fbcd7e1b 100644 (file)
@@ -84,6 +84,8 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
       blob_write_uint32(&blob, stvp->num_inputs);
       blob_write_bytes(&blob, stvp->index_to_input,
                        sizeof(stvp->index_to_input));
+      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));
 
@@ -206,6 +208,8 @@ st_deserialise_ir_program(struct gl_context *ctx,
       stvp->num_inputs = blob_read_uint32(&blob_reader);
       blob_copy_bytes(&blob_reader, (uint8_t *) stvp->index_to_input,
                       sizeof(stvp->index_to_input));
+      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));