[Mesa-dev] [PATCH 14/17] st/mesa: add state validation for compute shaders

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


This binds atomics, constants, samplers, ssbos, textures and ubos.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/mesa/state_tracker/st_atom.c            |  6 ++++
 src/mesa/state_tracker/st_atom.h            |  5 ++++
 src/mesa/state_tracker/st_atom_atomicbuf.c  | 18 +++++++++++
 src/mesa/state_tracker/st_atom_constbuf.c   | 46 ++++++++++++++++++++++++++++-
 src/mesa/state_tracker/st_atom_sampler.c    |  8 +++++
 src/mesa/state_tracker/st_atom_storagebuf.c | 21 +++++++++++++
 src/mesa/state_tracker/st_atom_texture.c    | 26 ++++++++++++++++
 7 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index 496128e..6822bdc 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -99,6 +99,12 @@ static const struct st_tracked_state *render_atoms[] =
 static const struct st_tracked_state *compute_atoms[] =
 {
    &st_update_cp,
+   &st_update_compute_texture,
+   &st_update_sampler, /* depends on update_compute_texture for swizzle */
+   &st_update_cs_constants,
+   &st_bind_cs_ubos,
+   &st_bind_cs_atomics,
+   &st_bind_cs_ssbos,
 };
 
 
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index 2bbc451..8ecca91 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -71,26 +71,31 @@ extern const struct st_tracked_state st_update_vertex_texture;
 extern const struct st_tracked_state st_update_geometry_texture;
 extern const struct st_tracked_state st_update_tessctrl_texture;
 extern const struct st_tracked_state st_update_tesseval_texture;
+extern const struct st_tracked_state st_update_compute_texture;
 extern const struct st_tracked_state st_update_fs_constants;
 extern const struct st_tracked_state st_update_gs_constants;
 extern const struct st_tracked_state st_update_tes_constants;
 extern const struct st_tracked_state st_update_tcs_constants;
 extern const struct st_tracked_state st_update_vs_constants;
+extern const struct st_tracked_state st_update_cs_constants;
 extern const struct st_tracked_state st_bind_fs_ubos;
 extern const struct st_tracked_state st_bind_vs_ubos;
 extern const struct st_tracked_state st_bind_gs_ubos;
 extern const struct st_tracked_state st_bind_tcs_ubos;
 extern const struct st_tracked_state st_bind_tes_ubos;
+extern const struct st_tracked_state st_bind_cs_ubos;
 extern const struct st_tracked_state st_bind_fs_atomics;
 extern const struct st_tracked_state st_bind_vs_atomics;
 extern const struct st_tracked_state st_bind_gs_atomics;
 extern const struct st_tracked_state st_bind_tcs_atomics;
 extern const struct st_tracked_state st_bind_tes_atomics;
+extern const struct st_tracked_state st_bind_cs_atomics;
 extern const struct st_tracked_state st_bind_fs_ssbos;
 extern const struct st_tracked_state st_bind_vs_ssbos;
 extern const struct st_tracked_state st_bind_gs_ssbos;
 extern const struct st_tracked_state st_bind_tcs_ssbos;
 extern const struct st_tracked_state st_bind_tes_ssbos;
+extern const struct st_tracked_state st_bind_cs_ssbos;
 extern const struct st_tracked_state st_update_pixel_transfer;
 extern const struct st_tracked_state st_update_tess;
 
diff --git a/src/mesa/state_tracker/st_atom_atomicbuf.c b/src/mesa/state_tracker/st_atom_atomicbuf.c
index 5b8baf5..03498d2 100644
--- a/src/mesa/state_tracker/st_atom_atomicbuf.c
+++ b/src/mesa/state_tracker/st_atom_atomicbuf.c
@@ -156,3 +156,21 @@ const struct st_tracked_state st_bind_tes_atomics = {
    },
    bind_tes_atomics
 };
+
+static void
+bind_cs_atomics(struct st_context *st)
+{
+   struct gl_shader_program *prog =
+      st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
+
+   st_bind_atomics(st, prog, PIPE_SHADER_COMPUTE);
+}
+
+const struct st_tracked_state st_bind_cs_atomics = {
+   "st_bind_cs_atomics",
+   {
+      0,
+      ST_NEW_COMPUTE_PROGRAM | ST_NEW_ATOMIC_BUFFER,
+   },
+   bind_cs_atomics
+};
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 66811d2..407dfd3 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -61,7 +61,8 @@ void st_upload_constants( struct st_context *st,
           shader_type == PIPE_SHADER_FRAGMENT ||
           shader_type == PIPE_SHADER_GEOMETRY ||
           shader_type == PIPE_SHADER_TESS_CTRL ||
-          shader_type == PIPE_SHADER_TESS_EVAL);
+          shader_type == PIPE_SHADER_TESS_EVAL ||
+          shader_type == PIPE_SHADER_COMPUTE);
 
    /* update constants */
    if (params && params->NumParameters) {
@@ -226,6 +227,28 @@ const struct st_tracked_state st_update_tes_constants = {
    update_tes_constants					/* update */
 };
 
+/* Compute shader:
+ */
+static void update_cs_constants(struct st_context *st )
+{
+   struct st_compute_program *cp = st->cp;
+   struct gl_program_parameter_list *params;
+
+   if (cp) {
+      params = cp->Base.Base.Parameters;
+      st_upload_constants( st, params, PIPE_SHADER_COMPUTE );
+   }
+}
+
+const struct st_tracked_state st_update_cs_constants = {
+   "st_update_cs_constants",				/* name */
+   {							/* dirty */
+      _NEW_PROGRAM_CONSTANTS,                           /* mesa */
+      ST_NEW_COMPUTE_PROGRAM,				/* st */
+   },
+   update_cs_constants					/* update */
+};
+
 static void st_bind_ubos(struct st_context *st,
                            struct gl_shader *shader,
                            unsigned shader_type)
@@ -363,3 +386,24 @@ const struct st_tracked_state st_bind_tes_ubos = {
    },
    bind_tes_ubos
 };
+
+static void bind_cs_ubos(struct st_context *st)
+{
+   struct gl_shader_program *prog =
+      st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
+
+   if (!prog)
+      return;
+
+   st_bind_ubos(st, prog->_LinkedShaders[MESA_SHADER_COMPUTE],
+                PIPE_SHADER_COMPUTE);
+}
+
+const struct st_tracked_state st_bind_cs_ubos = {
+   "st_bind_cs_ubos",
+   {
+      0,
+      ST_NEW_COMPUTE_PROGRAM | ST_NEW_UNIFORM_BUFFER,
+   },
+   bind_cs_ubos
+};
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 94231cf..82dcf5e 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -321,6 +321,14 @@ update_samplers(struct st_context *st)
                              st->state.samplers[PIPE_SHADER_TESS_EVAL],
                              &st->state.num_samplers[PIPE_SHADER_TESS_EVAL]);
    }
+   if (ctx->ComputeProgram._Current) {
+      update_shader_samplers(st,
+                             PIPE_SHADER_COMPUTE,
+                             &ctx->ComputeProgram._Current->Base,
+                             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_storagebuf.c b/src/mesa/state_tracker/st_atom_storagebuf.c
index 9f3565c..2d61724 100644
--- a/src/mesa/state_tracker/st_atom_storagebuf.c
+++ b/src/mesa/state_tracker/st_atom_storagebuf.c
@@ -192,3 +192,24 @@ const struct st_tracked_state st_bind_tes_ssbos = {
    },
    bind_tes_ssbos
 };
+
+static void bind_cs_ssbos(struct st_context *st)
+{
+   struct gl_shader_program *prog =
+      st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
+
+   if (!prog)
+      return;
+
+   st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_COMPUTE],
+                 PIPE_SHADER_COMPUTE);
+}
+
+const struct st_tracked_state st_bind_cs_ssbos = {
+   "st_bind_cs_ssbos",
+   {
+      0,
+      ST_NEW_COMPUTE_PROGRAM | ST_NEW_STORAGE_BUFFER,
+   },
+   bind_cs_ssbos
+};
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 3e37752..b4e6f9b 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -534,6 +534,22 @@ update_tesseval_textures(struct st_context *st)
 }
 
 
+static void
+update_compute_textures(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
+
+   if (ctx->ComputeProgram._Current) {
+      update_textures(st,
+                      MESA_SHADER_COMPUTE,
+                      &ctx->ComputeProgram._Current->Base,
+                      ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits,
+                      st->state.sampler_views[PIPE_SHADER_COMPUTE],
+                      &st->state.num_sampler_views[PIPE_SHADER_COMPUTE]);
+   }
+}
+
+
 const struct st_tracked_state st_update_fragment_texture = {
    "st_update_texture",					/* name */
    {							/* dirty */
@@ -582,3 +598,13 @@ const struct st_tracked_state st_update_tesseval_texture = {
    },
    update_tesseval_textures				/* update */
 };
+
+
+const struct st_tracked_state st_update_compute_texture = {
+   "st_update_compute_texture",			/* name */
+   {							/* dirty */
+      _NEW_TEXTURE,					/* mesa */
+      ST_NEW_COMPUTE_PROGRAM | ST_NEW_SAMPLER_VIEWS,	/* st */
+   },
+   update_compute_textures				/* update */
+};
-- 
2.6.4



More information about the mesa-dev mailing list