[Mesa-dev] [PATCH 25/42] i965/mesa/st: eliminate gl_compute_program

Timothy Arceri timothy.arceri at collabora.com
Wed Oct 19 23:09:42 UTC 2016


---
 src/mesa/drivers/dri/i965/brw_context.h   |  6 +++---
 src/mesa/drivers/dri/i965/brw_cs.c        | 22 ++++++++++------------
 src/mesa/drivers/dri/i965/brw_program.c   |  2 +-
 src/mesa/drivers/dri/i965/gen7_cs_state.c |  4 ++--
 src/mesa/main/mtypes.h                    | 21 ++-------------------
 src/mesa/main/state.c                     | 10 +++++-----
 src/mesa/program/program.c                |  7 ++-----
 src/mesa/program/program.h                | 21 ---------------------
 src/mesa/state_tracker/st_atom.c          |  2 +-
 src/mesa/state_tracker/st_atom_constbuf.c |  2 +-
 src/mesa/state_tracker/st_atom_sampler.c  |  2 +-
 src/mesa/state_tracker/st_atom_shader.c   |  2 +-
 src/mesa/state_tracker/st_atom_texture.c  |  2 +-
 src/mesa/state_tracker/st_cb_program.c    |  2 +-
 src/mesa/state_tracker/st_program.c       |  6 +++---
 src/mesa/state_tracker/st_program.h       |  6 +++---
 16 files changed, 37 insertions(+), 80 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index c1d6e08..e190d53 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -365,7 +365,7 @@ struct brw_fragment_program {
 
 /** Subclass of Mesa compute program */
 struct brw_compute_program {
-   struct gl_compute_program program;
+   struct gl_program program;
    unsigned id;  /**< serial no. to identify compute progs, never re-used */
 };
 
@@ -1011,7 +1011,7 @@ struct brw_context
    const struct gl_program *tess_ctrl_program;
    const struct gl_program *tess_eval_program;
    const struct gl_fragment_program *fragment_program;
-   const struct gl_compute_program *compute_program;
+   const struct gl_program *compute_program;
 
    /**
     * Number of samples in ctx->DrawBuffer, updated by BRW_NEW_NUM_SAMPLES so
@@ -1760,7 +1760,7 @@ brw_fragment_program_const(const struct gl_fragment_program *p)
 }
 
 static inline struct brw_compute_program *
-brw_compute_program(struct gl_compute_program *p)
+brw_compute_program(struct gl_program *p)
 {
    return (struct brw_compute_program *) p;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_cs.c b/src/mesa/drivers/dri/i965/brw_cs.c
index e7dcf47..799a9b4 100644
--- a/src/mesa/drivers/dri/i965/brw_cs.c
+++ b/src/mesa/drivers/dri/i965/brw_cs.c
@@ -85,14 +85,13 @@ brw_codegen_cs_prog(struct brw_context *brw,
       prog_data.base.total_shared = prog->Comp.SharedSize;
    }
 
-   assign_cs_binding_table_offsets(devinfo, prog,
-                                   &cp->program.Base, &prog_data);
+   assign_cs_binding_table_offsets(devinfo, prog, &cp->program, &prog_data);
 
    /* Allocate the references to the uniforms that will end up in the
     * prog_data associated with the compiled program, and which will be freed
     * by the state cache.
     */
-   int param_count = cp->program.Base.nir->num_uniforms / 4;
+   int param_count = cp->program.nir->num_uniforms / 4;
 
    /* The backend also sometimes add a param for the thread local id. */
    prog_data.thread_local_id_index = param_count++;
@@ -108,7 +107,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
    prog_data.base.nr_params = param_count;
    prog_data.base.nr_image_params = cs->base.NumImages;
 
-   brw_nir_setup_glsl_uniforms(cp->program.Base.nir, prog, &cp->program.Base,
+   brw_nir_setup_glsl_uniforms(cp->program.nir, prog, &cp->program,
                                &prog_data.base, true);
 
    if (unlikely(brw->perf_debug)) {
@@ -118,16 +117,16 @@ brw_codegen_cs_prog(struct brw_context *brw,
    }
 
    if (unlikely(INTEL_DEBUG & DEBUG_CS))
-      brw_dump_ir("compute", prog, &cs->base, &cp->program.Base);
+      brw_dump_ir("compute", prog, &cs->base, &cp->program);
 
    int st_index = -1;
    if (INTEL_DEBUG & DEBUG_SHADER_TIME)
-      st_index = brw_get_shader_time_index(brw, prog, &cp->program.Base, ST_CS);
+      st_index = brw_get_shader_time_index(brw, prog, &cp->program, ST_CS);
 
    char *error_str;
-   program = brw_compile_cs(brw->screen->compiler, brw, mem_ctx,
-                            key, &prog_data, cp->program.Base.nir,
-                            st_index, &program_size, &error_str);
+   program = brw_compile_cs(brw->screen->compiler, brw, mem_ctx, key,
+                            &prog_data, cp->program.nir, st_index,
+                            &program_size, &error_str);
    if (program == NULL) {
       prog->LinkStatus = false;
       ralloc_strcat(&prog->InfoLog, error_str);
@@ -221,7 +220,7 @@ brw_upload_cs_prog(struct brw_context *brw)
       return;
 
    brw->cs.base.sampler_count =
-      util_last_bit(ctx->ComputeProgram._Current->Base.SamplersUsed);
+      util_last_bit(ctx->ComputeProgram._Current->SamplersUsed);
 
    brw_cs_populate_key(brw, &key);
 
@@ -247,8 +246,7 @@ brw_cs_precompile(struct gl_context *ctx,
    struct brw_context *brw = brw_context(ctx);
    struct brw_cs_prog_key key;
 
-   struct gl_compute_program *cp = (struct gl_compute_program *) prog;
-   struct brw_compute_program *bcp = brw_compute_program(cp);
+   struct brw_compute_program *bcp = brw_compute_program(prog);
 
    memset(&key, 0, sizeof(key));
    key.program_string_id = bcp->id;
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 6804f31..7516baf 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -190,7 +190,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
          prog->id = get_new_program_id(brw->screen);
 
-         return _mesa_init_gl_program(&prog->program.Base, target, id);
+         return _mesa_init_gl_program(&prog->program, target, id);
       } else {
          return NULL;
       }
diff --git a/src/mesa/drivers/dri/i965/gen7_cs_state.c b/src/mesa/drivers/dri/i965/gen7_cs_state.c
index f0743fc..3533ac9 100644
--- a/src/mesa/drivers/dri/i965/gen7_cs_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_cs_state.c
@@ -289,7 +289,7 @@ gen7_upload_cs_push_constants(struct brw_context *brw)
          brw_cs_prog_data(brw->cs.base.prog_data);
 
       _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_COMPUTE);
-      brw_upload_cs_push_constants(brw, &cp->program.Base, cs_prog_data,
+      brw_upload_cs_push_constants(brw, &cp->program, cs_prog_data,
                                    stage_state, AUB_TRACE_WM_CONSTANTS);
    }
 }
@@ -324,7 +324,7 @@ brw_upload_cs_pull_constants(struct brw_context *brw)
 
    _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_COMPUTE);
    /* _NEW_PROGRAM_CONSTANTS */
-   brw_upload_pull_constants(brw, BRW_NEW_SURFACES, &cp->program.Base,
+   brw_upload_pull_constants(brw, BRW_NEW_SURFACES, &cp->program,
                              stage_state, prog_data);
 }
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 4b54983..75c9bae 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2025,23 +2025,6 @@ struct gl_fragment_program
 };
 
 
-/** Compute program object */
-struct gl_compute_program
-{
-   struct gl_program Base;   /**< base class */
-
-   /**
-    * Size specified using local_size_{x,y,z}.
-    */
-   unsigned LocalSize[3];
-
-   /**
-    * Size of shared variables accessed by the compute shader.
-    */
-   unsigned SharedSize;
-};
-
-
 /**
  * State common to vertex and fragment programs.
  */
@@ -2154,7 +2137,7 @@ struct gl_compute_program_state
    /** Currently enabled and valid program (including internal programs
     * and compiled shader programs).
     */
-   struct gl_compute_program *_Current;
+   struct gl_program *_Current;
 };
 
 
@@ -2781,7 +2764,7 @@ struct gl_shader_program
    } Vert;
 
    /**
-    * Compute shader state - copied into gl_compute_program by
+    * Compute shader state - copied into gl_program by
     * _mesa_copy_linked_program_data().
     */
    struct {
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index b09b3fe..2f810b4 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -112,7 +112,7 @@ update_program(struct gl_context *ctx)
    const struct gl_program *prevGP = ctx->GeometryProgram._Current;
    const struct gl_program *prevTCP = ctx->TessCtrlProgram._Current;
    const struct gl_program *prevTEP = ctx->TessEvalProgram._Current;
-   const struct gl_compute_program *prevCP = ctx->ComputeProgram._Current;
+   const struct gl_program *prevCP = ctx->ComputeProgram._Current;
    GLbitfield new_state = 0x0;
 
    /*
@@ -245,11 +245,11 @@ update_program(struct gl_context *ctx)
    if (csProg && csProg->LinkStatus
        && csProg->_LinkedShaders[MESA_SHADER_COMPUTE]) {
       /* Use GLSL compute shader */
-      _mesa_reference_compprog(ctx, &ctx->ComputeProgram._Current,
-                               gl_compute_program(csProg->_LinkedShaders[MESA_SHADER_COMPUTE]->Program));
+      _mesa_reference_program(ctx, &ctx->ComputeProgram._Current,
+                              csProg->_LinkedShaders[MESA_SHADER_COMPUTE]->Program);
    } else {
       /* no compute program */
-      _mesa_reference_compprog(ctx, &ctx->ComputeProgram._Current, NULL);
+      _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, NULL);
    }
 
    /* Let the driver know what's happening:
@@ -298,7 +298,7 @@ update_program(struct gl_context *ctx)
       new_state |= _NEW_PROGRAM;
       if (ctx->Driver.BindProgram) {
          ctx->Driver.BindProgram(ctx, GL_COMPUTE_PROGRAM_NV,
-                                 (struct gl_program *) ctx->ComputeProgram._Current);
+                                 ctx->ComputeProgram._Current);
       }
    }
 
diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index a72e6a1..61cc6fe 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -222,14 +222,11 @@ _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id)
    case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
    case GL_GEOMETRY_PROGRAM_NV:
    case GL_TESS_CONTROL_PROGRAM_NV:
-   case GL_TESS_EVALUATION_PROGRAM_NV: {
+   case GL_TESS_EVALUATION_PROGRAM_NV:
+   case GL_COMPUTE_PROGRAM_NV: {
       struct gl_program *prog = CALLOC_STRUCT(gl_program);
       return _mesa_init_gl_program(prog, target, id);
    }
-   case GL_COMPUTE_PROGRAM_NV: {
-      struct gl_compute_program *prog = CALLOC_STRUCT(gl_compute_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
-   }
    default:
       _mesa_problem(ctx, "bad target in _mesa_new_program");
       return NULL;
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index 5f322da..defeb2f 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -98,15 +98,6 @@ _mesa_reference_fragprog(struct gl_context *ctx,
                            (struct gl_program *) prog);
 }
 
-static inline void
-_mesa_reference_compprog(struct gl_context *ctx,
-                         struct gl_compute_program **ptr,
-                         struct gl_compute_program *prog)
-{
-   _mesa_reference_program(ctx, (struct gl_program **) ptr,
-                           (struct gl_program *) prog);
-}
-
 extern  GLboolean
 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
 
@@ -187,18 +178,6 @@ gl_fragment_program_const(const struct gl_program *prog)
    return (const struct gl_fragment_program *) prog;
 }
 
-static inline struct gl_compute_program *
-gl_compute_program(struct gl_program *prog)
-{
-   return (struct gl_compute_program *) prog;
-}
-
-static inline const struct gl_compute_program *
-gl_compute_program_const(const struct gl_program *prog)
-{
-   return (const struct gl_compute_program *) prog;
-}
-
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index 573615e..a86cffc 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -178,7 +178,7 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
 
    case ST_PIPELINE_COMPUTE: {
       struct st_compute_program *old_cp = st->cp;
-      struct gl_compute_program *new_cp = ctx->ComputeProgram._Current;
+      struct gl_program *new_cp = ctx->ComputeProgram._Current;
 
       if (new_cp != &old_cp->Base) {
          if (old_cp)
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index bc9a156..31d1ef4 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -229,7 +229,7 @@ static void update_cs_constants(struct st_context *st )
    struct gl_program_parameter_list *params;
 
    if (cp) {
-      params = cp->Base.Base.Parameters;
+      params = cp->Base.Parameters;
       st_upload_constants( st, params, MESA_SHADER_COMPUTE );
    }
 }
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 91baa59..a7174f8 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -360,7 +360,7 @@ update_samplers(struct st_context *st)
    if (ctx->ComputeProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_COMPUTE,
-                             &ctx->ComputeProgram._Current->Base,
+                             ctx->ComputeProgram._Current,
                              ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits,
                              st->state.samplers[PIPE_SHADER_COMPUTE],
                              &st->state.num_samplers[PIPE_SHADER_COMPUTE]);
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 554e342..1c3be08 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -312,7 +312,7 @@ update_cp( struct st_context *st )
    }
 
    stcp = st_compute_program(st->ctx->ComputeProgram._Current);
-   assert(stcp->Base.Base.Target == GL_COMPUTE_PROGRAM_NV);
+   assert(stcp->Base.Target == GL_COMPUTE_PROGRAM_NV);
 
    st->cp_variant = st_get_cp_variant(st, &stcp->tgsi, &stcp->variants);
 
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index e4257dd..ea263ab 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -285,7 +285,7 @@ update_compute_textures(struct st_context *st)
    if (ctx->ComputeProgram._Current) {
       update_textures(st,
                       MESA_SHADER_COMPUTE,
-                      &ctx->ComputeProgram._Current->Base,
+                      ctx->ComputeProgram._Current,
                       ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits,
                       st->state.sampler_views[PIPE_SHADER_COMPUTE],
                       &st->state.num_sampler_views[PIPE_SHADER_COMPUTE]);
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index fb0bdd2..d0478ca 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -79,7 +79,7 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id)
    }
    case GL_COMPUTE_PROGRAM_NV: {
       struct st_compute_program *prog = ST_CALLOC_STRUCT(st_compute_program);
-      return _mesa_init_gl_program(&prog->Base.Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id);
    }
    default:
       assert(0);
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 2e58f07..55cf572 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -211,7 +211,7 @@ st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
 
    for (v = *variants; v; ) {
       struct st_basic_variant *next = v->next;
-      delete_basic_variant(st, v, stcp->Base.Base.Target);
+      delete_basic_variant(st, v, stcp->Base.Target);
       v = next;
    }
 
@@ -1681,12 +1681,12 @@ st_translate_compute_program(struct st_context *st,
    if (ureg == NULL)
       return false;
 
-   st_translate_program_common(st, &stcp->Base.Base, stcp->glsl_to_tgsi, ureg,
+   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.prog = prog.tokens;
-   stcp->tgsi.req_local_mem = stcp->Base.Base.info.cs.shared_size;
+   stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
    stcp->tgsi.req_private_mem = 0;
    stcp->tgsi.req_input_mem = 0;
 
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 0263c8e..deb7009 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -288,11 +288,11 @@ struct st_tesseval_program
 
 
 /**
- * Derived from Mesa gl_compute_program:
+ * Derived from Mesa gl_program:
  */
 struct st_compute_program
 {
-   struct gl_compute_program Base;  /**< The Mesa 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 */
@@ -333,7 +333,7 @@ st_tesseval_program( struct gl_program *tep )
 }
 
 static inline struct st_compute_program *
-st_compute_program( struct gl_compute_program *cp )
+st_compute_program( struct gl_program *cp )
 {
    return (struct st_compute_program *)cp;
 }
-- 
2.7.4



More information about the mesa-dev mailing list