st/mesa: remove st_compute_program in favor of st_common_program
authorMarek Olšák <marek.olsak@amd.com>
Mon, 30 Sep 2019 21:06:45 +0000 (17:06 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 17 Oct 2019 00:10:47 +0000 (20:10 -0400)
The conversion from pipe_shader_state to pipe_compute_state is done
at the end.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom_constbuf.c
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h
src/mesa/state_tracker/st_shader_cache.c

index 49f79ad9d49a0df1d46ccb8ef738b2aafd24ddbb..74fe54625440af0b7d154d8eee9bfafcd74fac41 100644 (file)
@@ -219,14 +219,14 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
       break;
 
    case ST_PIPELINE_COMPUTE: {
-      struct st_compute_program *old_cp = st->cp;
+      struct st_common_program *old_cp = st->cp;
       struct gl_program *new_cp = ctx->ComputeProgram._Current;
 
       if (new_cp != &old_cp->Base) {
          if (old_cp)
             st->dirty |= old_cp->affected_states;
          assert(new_cp);
-         st->dirty |= st_compute_program(new_cp)->affected_states;
+         st->dirty |= st_common_program(new_cp)->affected_states;
       }
 
       st->compute_shader_may_be_dirty = false;
index fa147b8968849db6aac7316b7ca5610b9a400a9a..eabd854459a62a1d08ad95ed79dfda72781bb432 100644 (file)
@@ -188,7 +188,7 @@ st_update_tes_constants(struct st_context *st)
 void
 st_update_cs_constants(struct st_context *st)
 {
-   struct st_compute_program *cp = st->cp;
+   struct st_common_program *cp = st->cp;
 
    if (cp)
       st_upload_constants(st, &cp->Base);
index f9c61c055cc18248611f9a4efae94899d7ad00e5..52294f6da6e2c62fe4381f18aa36aa1f225538ab 100644 (file)
@@ -301,7 +301,7 @@ st_update_tep(struct st_context *st)
 void
 st_update_cp( struct st_context *st )
 {
-   struct st_compute_program *stcp;
+   struct st_common_program *stcp;
 
    if (!st->ctx->ComputeProgram._Current) {
       cso_set_compute_shader_handle(st->cso_context, NULL);
@@ -309,7 +309,7 @@ st_update_cp( struct st_context *st )
       return;
    }
 
-   stcp = st_compute_program(st->ctx->ComputeProgram._Current);
+   stcp = st_common_program(st->ctx->ComputeProgram._Current);
    assert(stcp->Base.Target == GL_COMPUTE_PROGRAM_NV);
 
    void *shader;
@@ -318,6 +318,7 @@ st_update_cp( struct st_context *st )
       shader = stcp->variants->driver_shader;
    } else {
       shader = st_get_cp_variant(st, &stcp->tgsi,
+                                 stcp->Base.info.cs.shared_size,
                                  &stcp->variants)->driver_shader;
    }
 
index 9ca1ada109d5fa776e2de9a04f0ccdd23ed3d5c3..5070268a616b80b3aaa52b76a0ceb8bfb412e462 100644 (file)
@@ -71,16 +71,12 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id,
    }
    case GL_TESS_CONTROL_PROGRAM_NV:
    case GL_TESS_EVALUATION_PROGRAM_NV:
-   case GL_GEOMETRY_PROGRAM_NV: {
+   case GL_GEOMETRY_PROGRAM_NV:
+   case GL_COMPUTE_PROGRAM_NV: {
       struct st_common_program *prog = rzalloc(NULL,
                                                struct st_common_program);
       return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
-   case GL_COMPUTE_PROGRAM_NV: {
-      struct st_compute_program *prog = rzalloc(NULL,
-                                                struct st_compute_program);
-      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
-   }
    default:
       assert(0);
       return NULL;
@@ -109,6 +105,7 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
    case GL_TESS_CONTROL_PROGRAM_NV:
    case GL_TESS_EVALUATION_PROGRAM_NV:
    case GL_GEOMETRY_PROGRAM_NV:
+   case GL_COMPUTE_PROGRAM_NV:
       {
          struct st_common_program *p = st_common_program(prog);
 
@@ -129,17 +126,6 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
             free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
       }
       break;
-   case GL_COMPUTE_PROGRAM_NV:
-      {
-         struct st_compute_program *stcp =
-            (struct st_compute_program *) prog;
-
-         st_release_cp_variants(st, stcp);
-
-         if (stcp->glsl_to_tgsi)
-            free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
-      }
-      break;
    default:
       assert(0); /* problem */
    }
@@ -223,10 +209,10 @@ st_program_string_notify( struct gl_context *ctx,
          st->dirty |= sttep->affected_states;
    }
    else if (target == GL_COMPUTE_PROGRAM_NV) {
-      struct st_compute_program *stcp =
-         (struct st_compute_program *) prog;
+      struct st_common_program *stcp =
+         (struct st_common_program *) prog;
 
-      st_release_cp_variants(st, stcp);
+      st_release_basic_variants(st, stcp);
       if (!st_translate_compute_program(st, stcp))
          return false;
 
@@ -292,13 +278,10 @@ st_get_shader_program_completion_status(struct gl_context *ctx,
       case MESA_SHADER_TESS_CTRL:
       case MESA_SHADER_TESS_EVAL:
       case MESA_SHADER_GEOMETRY:
+      case MESA_SHADER_COMPUTE:
          if (st_common_program(linked->Program)->variants)
             sh = st_common_program(linked->Program)->variants->driver_shader;
          break;
-      case MESA_SHADER_COMPUTE:
-         if (st_compute_program(linked->Program)->variants)
-            sh = st_compute_program(linked->Program)->variants->driver_shader;
-         break;
       }
 
       unsigned type = pipe_shader_type_from_mesa(i);
index 163f996d64c5602bb08a02657aa74f7f61adca3d..545d56996fb126ea70a307ef7da5d5fea819e3c8 100644 (file)
@@ -147,8 +147,8 @@ st_get_active_states(struct gl_context *ctx)
       st_common_program(ctx->GeometryProgram._Current);
    struct st_fragment_program *fp =
       st_fragment_program(ctx->FragmentProgram._Current);
-   struct st_compute_program *cp =
-      st_compute_program(ctx->ComputeProgram._Current);
+   struct st_common_program *cp =
+      st_common_program(ctx->ComputeProgram._Current);
    uint64_t active_shader_states = 0;
 
    if (vp)
index 1142e0f71bd32d4e882d27b80ca7883be5c7d3ca..0a14ef9b98c81ba9010c6c38dba356bdb6e86e71 100644 (file)
@@ -233,7 +233,7 @@ struct st_context
    struct st_common_program *gp;  /**< Currently bound geometry program */
    struct st_common_program *tcp; /**< Currently bound tess control program */
    struct st_common_program *tep; /**< Currently bound tess eval program */
-   struct st_compute_program *cp;   /**< Currently bound compute program */
+   struct st_common_program *cp;   /**< Currently bound compute program */
 
    struct st_vp_variant *vp_variant;
 
index dc6429f5671973147a03f790f57a5f3bfa65ab84..f34ed7fa6a62b5b38f8b5233f803b5f8c578b95d 100644 (file)
@@ -504,7 +504,6 @@ set_st_program(struct gl_program *prog,
    struct st_vertex_program *stvp;
    struct st_common_program *stp;
    struct st_fragment_program *stfp;
-   struct st_compute_program *stcp;
 
    switch (prog->info.stage) {
    case MESA_SHADER_VERTEX:
@@ -516,6 +515,7 @@ set_st_program(struct gl_program *prog,
    case MESA_SHADER_GEOMETRY:
    case MESA_SHADER_TESS_CTRL:
    case MESA_SHADER_TESS_EVAL:
+   case MESA_SHADER_COMPUTE:
       stp = (struct st_common_program *)prog;
       stp->shader_program = shader_program;
       stp->tgsi.type = PIPE_SHADER_IR_NIR;
@@ -527,12 +527,6 @@ set_st_program(struct gl_program *prog,
       stfp->tgsi.type = PIPE_SHADER_IR_NIR;
       stfp->tgsi.ir.nir = nir;
       break;
-   case MESA_SHADER_COMPUTE:
-      stcp = (struct st_compute_program *)prog;
-      stcp->shader_program = shader_program;
-      stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
-      stcp->tgsi.prog = nir;
-      break;
    default:
       unreachable("unknown shader stage");
    }
index 1e9138ac1d43f3a76c133152cca70f0df5036e8d..9c7b00922c4ddbbeeca4f964fa1ff7dc2d4a37e3 100644 (file)
@@ -7311,7 +7311,6 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    struct st_vertex_program *stvp;
    struct st_fragment_program *stfp;
    struct st_common_program *stp;
-   struct st_compute_program *stcp;
 
    switch (shader->Stage) {
    case MESA_SHADER_VERTEX:
@@ -7325,13 +7324,10 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    case MESA_SHADER_TESS_CTRL:
    case MESA_SHADER_TESS_EVAL:
    case MESA_SHADER_GEOMETRY:
+   case MESA_SHADER_COMPUTE:
       stp = st_common_program(prog);
       stp->glsl_to_tgsi = v;
       break;
-   case MESA_SHADER_COMPUTE:
-      stcp = (struct st_compute_program *)prog;
-      stcp->glsl_to_tgsi = v;
-      break;
    default:
       assert(!"should not be reached");
       return NULL;
index 73a2bf3d280e875f518e3fb2be8a3b662cecda65..4e36d3387da1ff56d0a900d579a793cd2fdb4ed9 100644 (file)
@@ -188,7 +188,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       break;
 
    case MESA_SHADER_COMPUTE:
-      states = &((struct st_compute_program*)prog)->affected_states;
+      states = &((struct st_common_program*)prog)->affected_states;
 
       *states = ST_NEW_CS_STATE;
 
@@ -210,8 +210,10 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
 static void
 delete_ir(struct pipe_shader_state *ir)
 {
-   if (ir->tokens)
+   if (ir->tokens) {
       ureg_free_tokens(ir->tokens);
+      ir->tokens = NULL;
+   }
 
    /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on
     * it has resulted in the driver taking ownership of the NIR.  Those
@@ -385,43 +387,6 @@ st_release_basic_variants(struct st_context *st, struct st_common_program *p)
 }
 
 
-/**
- * Free all variants of a compute program.
- */
-void
-st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
-{
-   struct st_basic_variant **variants = &stcp->variants;
-   struct st_basic_variant *v;
-
-   for (v = *variants; v; ) {
-      struct st_basic_variant *next = v->next;
-      delete_basic_variant(st, v, stcp->Base.Target);
-      v = next;
-   }
-
-   *variants = NULL;
-
-   if (stcp->tgsi.prog) {
-      switch (stcp->tgsi.ir_type) {
-      case PIPE_SHADER_IR_TGSI:
-         ureg_free_tokens(stcp->tgsi.prog);
-         stcp->tgsi.prog = NULL;
-         break;
-      case PIPE_SHADER_IR_NIR:
-         /* pipe driver took ownership of prog */
-         break;
-      case PIPE_SHADER_IR_NATIVE:
-         /* ??? */
-         stcp->tgsi.prog = NULL;
-         break;
-      case PIPE_SHADER_IR_NIR_SERIALIZED:
-         unreachable("serialized nirs aren't passed through st/mesa");
-         break;
-      }
-   }
-}
-
 /**
  * Translate ARB (asm) program to NIR
  */
@@ -1556,14 +1521,9 @@ st_translate_program_common(struct st_context *st,
                         output_semantic_name,
                         output_semantic_index);
 
-   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);
-      stcp->tgsi.prog = out_state->tokens;
-   } else {
-      struct st_common_program *stcp = (struct st_common_program *) prog;
-      out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
-   }
+   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(prog->sh.LinkedTransformFeedback,
@@ -1833,17 +1793,14 @@ st_translate_tesseval_program(struct st_context *st,
  */
 bool
 st_translate_compute_program(struct st_context *st,
-                             struct st_compute_program *stcp)
+                             struct st_common_program *stcp)
 {
    struct ureg_program *ureg;
-   struct pipe_shader_state prog;
-
-   stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
 
    if (stcp->shader_program) {
       /* no compute variants: */
       st_finalize_nir(st, &stcp->Base, stcp->shader_program,
-                      (struct nir_shader *) stcp->tgsi.prog);
+                      (struct nir_shader *) stcp->tgsi.ir.nir);
       st_store_ir_in_disk_cache(st, &stcp->Base, true);
       return true;
    }
@@ -1853,11 +1810,7 @@ st_translate_compute_program(struct st_context *st,
       return false;
 
    st_translate_program_common(st, &stcp->Base, stcp->glsl_to_tgsi, ureg,
-                               PIPE_SHADER_COMPUTE, &prog);
-
-   stcp->tgsi.ir_type = PIPE_SHADER_IR_TGSI;
-   stcp->tgsi.req_private_mem = 0;
-   stcp->tgsi.req_input_mem = 0;
+                               PIPE_SHADER_COMPUTE, &stcp->tgsi);
 
    free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
    stcp->glsl_to_tgsi = NULL;
@@ -1870,7 +1823,8 @@ st_translate_compute_program(struct st_context *st,
  */
 struct st_basic_variant *
 st_get_cp_variant(struct st_context *st,
-                  struct pipe_compute_state *tgsi,
+                  struct pipe_shader_state *tgsi,
+                  unsigned shared_size,
                   struct st_basic_variant **variants)
 {
    struct pipe_context *pipe = st->pipe;
@@ -1894,9 +1848,16 @@ st_get_cp_variant(struct st_context *st,
       v = CALLOC_STRUCT(st_basic_variant);
       if (v) {
          /* fill in new variant */
-         struct pipe_compute_state cs = *tgsi;
-         if (tgsi->ir_type == PIPE_SHADER_IR_NIR)
-            cs.prog = nir_shader_clone(NULL, tgsi->prog);
+         struct pipe_compute_state cs = {0};
+
+         cs.ir_type = tgsi->type;
+         cs.req_local_mem = shared_size;
+
+         if (tgsi->type == PIPE_SHADER_IR_NIR)
+            cs.prog = nir_shader_clone(NULL, tgsi->ir.nir);
+         else
+            cs.prog = tgsi->tokens;
+
          v->driver_shader = pipe->create_compute_state(pipe, &cs);
          v->key = key;
 
@@ -1968,13 +1929,9 @@ destroy_program_variants(struct st_context *st, struct gl_program *target)
    case GL_COMPUTE_PROGRAM_NV:
       {
          struct st_common_program *p = st_common_program(target);
-         struct st_compute_program *cp = (struct st_compute_program*)target;
-         struct st_basic_variant **variants =
-            target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
-                                                      &p->variants;
-         struct st_basic_variant *v, **prevPtr = variants;
+         struct st_basic_variant *v, **prevPtr = &p->variants;
 
-         for (v = *variants; v; ) {
+         for (v = p->variants; v; ) {
             struct st_basic_variant *next = v->next;
             if (v->key.st == st) {
                /* unlink from list */
@@ -2155,8 +2112,8 @@ st_precompile_shader_variant(struct st_context *st,
    }
 
    case GL_COMPUTE_PROGRAM_NV: {
-      struct st_compute_program *p = (struct st_compute_program *)prog;
-      st_get_cp_variant(st, &p->tgsi, &p->variants);
+      struct st_common_program *p = (struct st_common_program *)prog;
+      st_get_cp_variant(st, &p->tgsi, prog->info.cs.shared_size, &p->variants);
       break;
    }
 
index 4b0fcff96a78de90285140e4d8ae1638f720141d..a337f529348d63bec733981c02c7286e5285b2ea 100644 (file)
@@ -314,29 +314,6 @@ struct st_common_program
 };
 
 
-/**
- * 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 )
 {
@@ -351,15 +328,9 @@ st_vertex_program( struct gl_program *vp )
 }
 
 static inline struct st_common_program *
-st_common_program( struct gl_program *gp )
-{
-   return (struct st_common_program *)gp;
-}
-
-static inline struct st_compute_program *
-st_compute_program( struct gl_program *cp )
+st_common_program( struct gl_program *cp )
 {
-   return (struct st_compute_program *)cp;
+   return (struct st_common_program *)cp;
 }
 
 static inline void
@@ -394,8 +365,8 @@ st_reference_prog(struct st_context *st,
 
 static inline void
 st_reference_compprog(struct st_context *st,
-                      struct st_compute_program **ptr,
-                      struct st_compute_program *prog)
+                      struct st_common_program **ptr,
+                      struct st_common_program *prog)
 {
    _mesa_reference_program(st->ctx,
                            (struct gl_program **) ptr,
@@ -428,7 +399,8 @@ st_get_fp_variant(struct st_context *st,
 
 extern struct st_basic_variant *
 st_get_cp_variant(struct st_context *st,
-                  struct pipe_compute_state *tgsi,
+                  struct pipe_shader_state *tgsi,
+                  unsigned shared_size,
                   struct st_basic_variant **variants);
 
 extern struct st_basic_variant *
@@ -445,10 +417,6 @@ extern void
 st_release_fp_variants( struct st_context *st,
                         struct st_fragment_program *stfp );
 
-extern void
-st_release_cp_variants(struct st_context *st,
-                        struct st_compute_program *stcp);
-
 extern void
 st_release_basic_variants(struct st_context *st, struct st_common_program *p);
 
@@ -477,7 +445,7 @@ st_translate_tesseval_program(struct st_context *st,
 
 extern bool
 st_translate_compute_program(struct st_context *st,
-                             struct st_compute_program *stcp);
+                             struct st_common_program *stcp);
 
 extern void
 st_print_current_vertex_program(void);
index 7bb36b609c945d0d115439f2ff4599a2b9dea24b..901918eb7b29962494371ed3c8491b2a302c9a0e 100644 (file)
@@ -104,7 +104,8 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
    }
    case MESA_SHADER_TESS_CTRL:
    case MESA_SHADER_TESS_EVAL:
-   case MESA_SHADER_GEOMETRY: {
+   case MESA_SHADER_GEOMETRY:
+   case MESA_SHADER_COMPUTE: {
       struct st_common_program *stcp = (struct st_common_program *) prog;
 
       if (prog->info.stage == MESA_SHADER_TESS_EVAL ||
@@ -128,16 +129,6 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
                              stfp->num_tgsi_tokens);
       break;
    }
-   case MESA_SHADER_COMPUTE: {
-      struct st_compute_program *stcp = (struct st_compute_program *) prog;
-
-      if (nir)
-         write_nir_to_cache(&blob, prog);
-      else
-         write_tgsi_to_cache(&blob, stcp->tgsi.prog, prog,
-                             stcp->num_tgsi_tokens);
-      break;
-   }
    default:
       unreachable("Unsupported stage");
    }
@@ -319,25 +310,20 @@ st_deserialise_ir_program(struct gl_context *ctx,
       break;
    }
    case MESA_SHADER_COMPUTE: {
-      struct st_compute_program *stcp = (struct st_compute_program *) prog;
+      struct st_common_program *stcp = (struct st_common_program *) prog;
 
-      st_release_cp_variants(st, stcp);
+      st_release_basic_variants(st, stcp);
 
       if (nir) {
-         stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
+         stcp->tgsi.type = PIPE_SHADER_IR_NIR;
+         stcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
          stcp->shader_program = shProg;
-         stcp->tgsi.prog = nir_deserialize(NULL, options, &blob_reader);
-         prog->nir = (nir_shader *) stcp->tgsi.prog;
+         prog->nir = (nir_shader *) stcp->tgsi.ir.nir;
       } else {
-         read_tgsi_from_cache(&blob_reader,
-                              (const struct tgsi_token**) &stcp->tgsi.prog,
+         read_tgsi_from_cache(&blob_reader, &stcp->tgsi.tokens,
                               &stcp->num_tgsi_tokens);
       }
 
-      stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
-      stcp->tgsi.req_private_mem = 0;
-      stcp->tgsi.req_input_mem = 0;
-
       if (st->cp == stcp)
          st->dirty |= stcp->affected_states;