[Mesa-dev] [PATCH 11/17] st/mesa: add conversion for compute shaders

Samuel Pitoiset samuel.pitoiset at gmail.com
Sun Jan 24 13:09:46 PST 2016


The size of shared variables needs to be stored in gl_compute_program
in order to set up pipe_compute_state::req_local_mem. According to the
spec, there are no predefined inputs nor any fixed-function outputs.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/mesa/main/mtypes.h                     |  5 +++++
 src/mesa/main/shaderapi.c                  |  1 +
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  8 ++++++++
 src/mesa/state_tracker/st_program.c        | 19 ++++++++++++++++++-
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 3376549..dc6409a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2033,6 +2033,11 @@ struct gl_compute_program
     * Size specified using local_size_{x,y,z}.
     */
    unsigned LocalSize[3];
+
+   /**
+    * Size of shared variables accessed by the compute shader.
+    */
+   unsigned SharedSize;
 };
 
 
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index a988f41..7f19e67 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -2124,6 +2124,7 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
       int i;
       for (i = 0; i < 3; i++)
          dst_cp->LocalSize[i] = src->Comp.LocalSize[i];
+      dst_cp->SharedSize = src->Comp.SharedSize;
       break;
    }
    default:
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ed8778f..af8a662 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5608,6 +5608,8 @@ st_translate_program(
          t->inputs[i] = ureg_DECL_vs_input(ureg, i);
       }
       break;
+   case TGSI_PROCESSOR_COMPUTE:
+      break;
    default:
       assert(0);
    }
@@ -5617,6 +5619,7 @@ st_translate_program(
     */
    switch (procType) {
    case TGSI_PROCESSOR_FRAGMENT:
+   case TGSI_PROCESSOR_COMPUTE:
       break;
    case TGSI_PROCESSOR_GEOMETRY:
    case TGSI_PROCESSOR_TESS_EVAL:
@@ -6083,6 +6086,7 @@ get_mesa_program(struct gl_context *ctx,
    struct st_geometry_program *stgp;
    struct st_tessctrl_program *sttcp;
    struct st_tesseval_program *sttep;
+   struct st_compute_program *stcp;
 
    switch (shader->Type) {
    case GL_VERTEX_SHADER:
@@ -6105,6 +6109,10 @@ get_mesa_program(struct gl_context *ctx,
       sttep = (struct st_tesseval_program *)prog;
       sttep->glsl_to_tgsi = v;
       break;
+   case GL_COMPUTE_SHADER:
+      stcp = (struct st_compute_program *)prog;
+      stcp->glsl_to_tgsi = v;
+      break;
    default:
       assert(!"should not be reached");
       return NULL;
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 07d9b62..848fc46 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1590,7 +1590,24 @@ bool
 st_translate_compute_program(struct st_context *st,
                              struct st_compute_program *stcp)
 {
-   return false; /* will be updated in the next commit */
+   struct ureg_program *ureg;
+   struct pipe_shader_state prog;
+
+   ureg = ureg_create_with_screen(TGSI_PROCESSOR_COMPUTE, st->pipe->screen);
+   if (ureg == NULL)
+      return false;
+
+   st_translate_program_common(st, &stcp->Base.Base, stcp->glsl_to_tgsi, ureg,
+                               TGSI_PROCESSOR_COMPUTE, &prog);
+
+   stcp->tgsi.prog = prog.tokens;
+   stcp->tgsi.req_local_mem = stcp->Base.SharedSize;
+   stcp->tgsi.req_private_mem = 0;
+   stcp->tgsi.req_input_mem = 0;
+
+   free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
+   stcp->glsl_to_tgsi = NULL;
+   return true;
 }
 
 
-- 
2.6.4



More information about the mesa-dev mailing list