st/mesa: add state validation for compute shaders
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 5 Jan 2016 22:53:30 +0000 (23:53 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Sat, 13 Feb 2016 15:01:01 +0000 (16:01 +0100)
This binds atomics, constants, samplers, ssbos, textures and ubos.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_atom_atomicbuf.c
src/mesa/state_tracker/st_atom_constbuf.c
src/mesa/state_tracker/st_atom_sampler.c
src/mesa/state_tracker/st_atom_storagebuf.c
src/mesa/state_tracker/st_atom_texture.c

index 3427a92972f061d3b08e845cea964fba904671bd..8a04d747b13e872fc2a1b008a4bb446e0c6852cb 100644 (file)
@@ -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,
 };
 
 
index ef33645eaa792b28b270d0881ad5faf071f3d02f..ac1aae8e6c2a39fc5666f5df24208fb03c0e656a 100644 (file)
@@ -72,26 +72,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;
 
index 1c30d1fb701ac7b0dc9e084af21b5411998ff173..d83c39606404c57309f403bcb1e18f185768415c 100644 (file)
@@ -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
+};
index 66811d29c290172ef40160ffbcfc2ab751ac8183..407dfd31c80b8bae879f6123e8a14524f9aeee8e 100644 (file)
@@ -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
+};
index 94231cf1946f2975b4217f0314516d2f512cf003..82dcf5ee0cadd08101ca4178f9041715ca3513d4 100644 (file)
@@ -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]);
+   }
 }
 
 
index f165cc3e0a18b80f58e36d611dec292a103de131..37b4c4d256d385d4a9a687984e1c44c0baabbb7e 100644 (file)
@@ -194,3 +194,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
+};
index 3e3775200a8cf040ecb96c3621c73a439a82569d..b4e6f9b639adf49225e6d01ca445f0129847ca12 100644 (file)
@@ -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 */
+};