[Mesa-dev] [PATCH 1/5] st/glsl_to_tgsi: store num_tgsi_tokens in st_*_program

Timothy Arceri tarceri at itsqueeze.com
Fri Dec 8 09:57:35 UTC 2017


We will need this for ARB_get_program_binary binary support.
---
 src/mesa/state_tracker/st_program.c      | 21 ++++++++++++---------
 src/mesa/state_tracker/st_program.h      | 12 ++++++++++++
 src/mesa/state_tracker/st_shader_cache.c | 15 +++++++++------
 src/mesa/state_tracker/st_shader_cache.h |  3 +--
 4 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 05e6042f425..9f8bf5f76fd 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -527,27 +527,26 @@ st_translate_vertex_program(struct st_context *st,
                                         output_semantic_name,
                                         output_semantic_index);
 
    if (error) {
       debug_printf("%s: failed to translate Mesa program:\n", __func__);
       _mesa_print_program(&stvp->Base);
       debug_assert(0);
       return false;
    }
 
-   unsigned num_tokens;
-   stvp->tgsi.tokens = ureg_get_tokens(ureg, &num_tokens);
+   stvp->tgsi.tokens = ureg_get_tokens(ureg, &stvp->num_tgsi_tokens);
    ureg_destroy(ureg);
 
    if (stvp->glsl_to_tgsi) {
       stvp->glsl_to_tgsi = NULL;
-      st_store_tgsi_in_disk_cache(st, &stvp->Base, NULL, num_tokens);
+      st_store_tgsi_in_disk_cache(st, &stvp->Base, NULL);
    }
 
    return stvp->tgsi.tokens != NULL;
 }
 
 static struct st_vp_variant *
 st_create_vp_variant(struct st_context *st,
                      struct st_vertex_program *stvp,
                      const struct st_vp_variant_key *key)
 {
@@ -985,27 +984,26 @@ st_translate_fragment_program(struct st_context *st,
                                 inputMapping,
                                 input_semantic_name,
                                 input_semantic_index,
                                 interpMode,
                                 /* outputs */
                                 fs_num_outputs,
                                 outputMapping,
                                 fs_output_semantic_name,
                                 fs_output_semantic_index);
 
-   unsigned num_tokens;
-   stfp->tgsi.tokens = ureg_get_tokens(ureg, &num_tokens);
+   stfp->tgsi.tokens = ureg_get_tokens(ureg, &stfp->num_tgsi_tokens);
    ureg_destroy(ureg);
 
    if (stfp->glsl_to_tgsi) {
       stfp->glsl_to_tgsi = NULL;
-      st_store_tgsi_in_disk_cache(st, &stfp->Base, NULL, num_tokens);
+      st_store_tgsi_in_disk_cache(st, &stfp->Base, NULL);
    }
 
    return stfp->tgsi.tokens != NULL;
 }
 
 static struct st_fp_variant *
 st_create_fp_variant(struct st_context *st,
                      struct st_fragment_program *stfp,
                      const struct st_fp_variant_key *key)
 {
@@ -1393,29 +1391,34 @@ st_translate_program_common(struct st_context *st,
                         inputSlotToAttr,
                         input_semantic_name,
                         input_semantic_index,
                         NULL,
                         /* outputs */
                         num_outputs,
                         outputMapping,
                         output_semantic_name,
                         output_semantic_index);
 
-   unsigned num_tokens;
-   out_state->tokens = ureg_get_tokens(ureg, &num_tokens);
+   if (tgsi_processor == PIPE_SHADER_COMPUTE) {
+      struct st_compute_program *stcp = (struct st_compute_program *) prog;
+      out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
+   } else {
+      struct st_common_program *stcp = (struct st_common_program *) prog;
+      out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
+   }
    ureg_destroy(ureg);
 
    st_translate_stream_output_info(glsl_to_tgsi,
                                    outputMapping,
                                    &out_state->stream_output);
 
-   st_store_tgsi_in_disk_cache(st, prog, out_state, num_tokens);
+   st_store_tgsi_in_disk_cache(st, prog, out_state);
 
    if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
       _mesa_print_program(prog);
       debug_printf("\n");
    }
 
    if (ST_DEBUG & DEBUG_TGSI) {
       tgsi_dump(out_state->tokens, 0);
       debug_printf("\n");
    }
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 0e6c8e00c6e..a520ffbecb4 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -143,20 +143,23 @@ struct st_fragment_program
    struct gl_program Base;
    struct pipe_shader_state tgsi;
    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
    struct ati_fragment_shader *ati_fs;
    uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
 
    /* used when bypassing glsl_to_tgsi: */
    struct gl_shader_program *shader_program;
 
    struct st_fp_variant *variants;
+
+   /* Used by the shader cache and ARB_get_program_binary */
+   unsigned num_tgsi_tokens;
 };
 
 
 
 /** Vertex program variant key */
 struct st_vp_variant_key
 {
    struct st_context *st;          /**< variants are per-context */
    boolean passthrough_edgeflags;
 
@@ -215,20 +218,23 @@ struct st_vertex_program
 
    /** Maps VARYING_SLOT_x to slot */
    ubyte result_to_output[VARYING_SLOT_MAX];
 
    /** List of translated variants of this vertex program.
     */
    struct st_vp_variant *variants;
 
    /** SHA1 hash of linked tgsi shader program, used for on-disk cache */
    unsigned char sha1[20];
+
+   /* Used by the shader cache and ARB_get_program_binary */
+   unsigned num_tgsi_tokens;
 };
 
 
 
 /** Key shared by all shaders except VP, FP */
 struct st_basic_variant_key
 {
    struct st_context *st;          /**< variants are per-context */
 };
 
@@ -257,40 +263,46 @@ struct st_common_program
    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
    uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
 
   /* used when bypassing glsl_to_tgsi: */
    struct gl_shader_program *shader_program;
 
    struct st_basic_variant *variants;
 
    /** SHA1 hash of linked tgsi shader program, used for on-disk cache */
    unsigned char sha1[20];
+
+   /* Used by the shader cache and ARB_get_program_binary */
+   unsigned num_tgsi_tokens;
 };
 
 
 /**
  * Derived from Mesa gl_program:
  */
 struct st_compute_program
 {
    struct gl_program Base;  /**< The Mesa compute program */
    struct pipe_compute_state tgsi;
    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
    uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
 
    /* used when bypassing glsl_to_tgsi: */
    struct gl_shader_program *shader_program;
 
    struct st_basic_variant *variants;
 
    /** SHA1 hash of linked tgsi shader program, used for on-disk cache */
    unsigned char sha1[20];
+
+   /* Used by the shader cache and ARB_get_program_binary */
+   unsigned num_tgsi_tokens;
 };
 
 
 static inline struct st_fragment_program *
 st_fragment_program( struct gl_program *fp )
 {
    return (struct st_fragment_program *)fp;
 }
 
 
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index a5e33133b3c..a9413fb0534 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -49,22 +49,21 @@ write_tgsi_to_cache(struct blob *blob, struct pipe_shader_state *tgsi,
    prog->driver_cache_blob = ralloc_size(NULL, blob->size);
    memcpy(prog->driver_cache_blob, blob->data, blob->size);
    prog->driver_cache_blob_size = blob->size;
 }
 
 /**
  * Store tgsi and any other required state in on-disk shader cache.
  */
 void
 st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
-                            struct pipe_shader_state *out_state,
-                            unsigned num_tokens)
+                            struct pipe_shader_state *out_state)
 {
    if (!st->ctx->Cache)
       return;
 
    /* Exit early when we are dealing with a ff shader with no source file to
     * generate a source from.
     */
    static const char zero[sizeof(prog->sh.data->sha1)] = {0};
    if (memcmp(prog->sh.data->sha1, zero, sizeof(prog->sh.data->sha1)) == 0)
       return;
@@ -76,38 +75,42 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
    case MESA_SHADER_VERTEX: {
       struct st_vertex_program *stvp = (struct st_vertex_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->result_to_output,
                        sizeof(stvp->result_to_output));
 
       write_stream_out_to_cache(&blob, &stvp->tgsi);
-      write_tgsi_to_cache(&blob, &stvp->tgsi, prog, num_tokens);
+      write_tgsi_to_cache(&blob, &stvp->tgsi, prog, stvp->num_tgsi_tokens);
       break;
    }
    case MESA_SHADER_TESS_CTRL:
    case MESA_SHADER_TESS_EVAL:
    case MESA_SHADER_GEOMETRY: {
+      struct st_common_program *stcp = (struct st_common_program *) prog;
+
       write_stream_out_to_cache(&blob, out_state);
-      write_tgsi_to_cache(&blob, out_state, prog, num_tokens);
+      write_tgsi_to_cache(&blob, out_state, prog, stcp->num_tgsi_tokens);
       break;
    }
    case MESA_SHADER_FRAGMENT: {
       struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
 
-      write_tgsi_to_cache(&blob, &stfp->tgsi, prog, num_tokens);
+      write_tgsi_to_cache(&blob, &stfp->tgsi, prog, stfp->num_tgsi_tokens);
       break;
    }
    case MESA_SHADER_COMPUTE: {
-      write_tgsi_to_cache(&blob, out_state, prog, num_tokens);
+      struct st_compute_program *stcp = (struct st_compute_program *) prog;
+
+      write_tgsi_to_cache(&blob, out_state, prog, stcp->num_tgsi_tokens);
       break;
    }
    default:
       unreachable("Unsupported stage");
    }
 
    if (st->ctx->_Shader->Flags & GLSL_CACHE_INFO) {
       fprintf(stderr, "putting %s tgsi_tokens in cache\n",
               _mesa_shader_stage_to_string(prog->info.stage));
    }
diff --git a/src/mesa/state_tracker/st_shader_cache.h b/src/mesa/state_tracker/st_shader_cache.h
index 090d7d85cc8..7644d437521 100644
--- a/src/mesa/state_tracker/st_shader_cache.h
+++ b/src/mesa/state_tracker/st_shader_cache.h
@@ -31,16 +31,15 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 bool
 st_load_tgsi_from_disk_cache(struct gl_context *ctx,
                              struct gl_shader_program *prog);
 
 void
 st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
-                            struct pipe_shader_state *out_state,
-                            unsigned num_tokens);
+                            struct pipe_shader_state *out_state);
 
 #ifdef __cplusplus
 }
 #endif
-- 
2.14.3



More information about the mesa-dev mailing list