st/mesa/glsl/i965: move ImageUnits and ImageAccess fields to gl_program
authorTimothy Arceri <timothy.arceri@collabora.com>
Fri, 4 Nov 2016 09:02:21 +0000 (20:02 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Fri, 6 Jan 2017 00:21:40 +0000 (11:21 +1100)
Having it here rather than in gl_linked_shader allows us to simplify
the code.

Also it is error prone to depend on the gl_linked_shader for programs
in current use because a failed linking attempt will free infomation
about the current program. In i965 we could be trying to recompile
a shader variant but may have lost some required fields.

We drop the memset on ImageUnits because gl_program is already
created using rzalloc().

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
12 files changed:
src/compiler/glsl/link_uniform_initializers.cpp
src/compiler/glsl/link_uniforms.cpp
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_gs_surface_state.c
src/mesa/drivers/dri/i965/brw_tcs_surface_state.c
src/mesa/drivers/dri/i965/brw_tes_surface_state.c
src/mesa/drivers/dri/i965/brw_vs_surface_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/main/mtypes.h
src/mesa/main/uniform_query.cpp
src/mesa/state_tracker/st_atom_image.c

index 93340baf61f4f46091b7387c4f6acdbb5dd6c080..6f05a3a8098c8c7ab45cbb71fa65711579ebb71e 100644 (file)
@@ -141,9 +141,10 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
                     storage->opaque[sh].active) {
                for (unsigned i = 0; i < elements; i++) {
                   const unsigned index = storage->opaque[sh].index + i;
-                  if (index >= ARRAY_SIZE(shader->ImageUnits))
+                  if (index >= ARRAY_SIZE(shader->Program->sh.ImageUnits))
                      break;
-                  shader->ImageUnits[index] = storage->storage[i].i;
+                  shader->Program->sh.ImageUnits[index] =
+                     storage->storage[i].i;
                }
             }
          }
index 256afa32fb6008a8026ca92736e782395eb2054e..cd00837cca929a351932b39b0f7a9a08f7802e4e 100644 (file)
@@ -613,7 +613,7 @@ private:
          this->next_image += MAX2(1, uniform->array_elements);
 
          for (unsigned i = first; i < MIN2(next_image, MAX_IMAGE_UNIFORMS); i++)
-            prog->_LinkedShaders[shader_type]->ImageAccess[i] = access;
+            prog->_LinkedShaders[shader_type]->Program->sh.ImageAccess[i] = access;
       }
    }
 
@@ -1308,7 +1308,6 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
        *     types cannot have initializers."
        */
       memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits));
-      memset(sh->ImageUnits, 0, sizeof(sh->ImageUnits));
 
       link_update_uniform_buffer_variables(sh, i);
 
index 032b5ec16aac7d85e578303023f2f1afedb74959..0b9d2a05bf65f19343da6cf2a6bcb8109e86b54a 100644 (file)
@@ -280,7 +280,8 @@ intel_update_state(struct gl_context * ctx, GLuint new_state)
 
       if (unlikely(shader && shader->Program->info.num_images)) {
          for (unsigned j = 0; j < shader->Program->info.num_images; j++) {
-            struct gl_image_unit *u = &ctx->ImageUnits[shader->ImageUnits[j]];
+            struct gl_image_unit *u =
+               &ctx->ImageUnits[shader->Program->sh.ImageUnits[j]];
             tex_obj = intel_texture_object(u->TexObj);
 
             if (tex_obj && tex_obj->mt) {
index 113974badc8979d4eeeaf1cd9c3dab25a70ef892..628840e7cf34f9bb63cd86b5b8292c484f12cf72 100644 (file)
@@ -1465,7 +1465,6 @@ void brw_upload_abo_surfaces(struct brw_context *brw,
                              struct brw_stage_state *stage_state,
                              struct brw_stage_prog_data *prog_data);
 void brw_upload_image_surfaces(struct brw_context *brw,
-                               struct gl_linked_shader *shader,
                                const struct gl_program *prog,
                                struct brw_stage_state *stage_state,
                                struct brw_stage_prog_data *prog_data);
index cf56acfd99a758cdde190fbf5659f48f76d8a7a2..e2ef222b08c2ba824a40cac3168872afab7e3698 100644 (file)
@@ -122,16 +122,13 @@ const struct brw_tracked_state brw_gs_abo_surfaces = {
 static void
 brw_upload_gs_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_GEOMETRY_PROGRAM */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
    const struct gl_program *gp = brw->geometry_program;
 
-   if (gp && prog) {
+   if (gp) {
       /* BRW_NEW_GS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
-                                gp, &brw->gs.base, brw->gs.base.prog_data);
+      brw_upload_image_surfaces(brw, gp, &brw->gs.base,
+                                brw->gs.base.prog_data);
    }
 }
 
index b2d075fe6bf9cbc18267be317aa565d5fd82211f..16f0bd2f96ee1e6736be2f9ce66b70f879035100 100644 (file)
@@ -123,16 +123,13 @@ const struct brw_tracked_state brw_tcs_abo_surfaces = {
 static void
 brw_upload_tcs_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_TESS_PROGRAMS */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
    const struct gl_program *tcp = brw->tess_ctrl_program;
 
-   if (tcp && prog) {
+   if (tcp) {
       /* BRW_NEW_TCS_PROG_DATA, BRW_NEW_IMAGE_UNITS */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
-                                tcp, &brw->tcs.base, brw->tcs.base.prog_data);
+      brw_upload_image_surfaces(brw, tcp, &brw->tcs.base,
+                                brw->tcs.base.prog_data);
    }
 }
 
index a3516834ce4277e2c28457f797604f4fa5c71698..f74d86961e2ca63a96504d4b00bb8143cae297be 100644 (file)
@@ -123,16 +123,13 @@ const struct brw_tracked_state brw_tes_abo_surfaces = {
 static void
 brw_upload_tes_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_TESS_PROGRAMS */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
    const struct gl_program *tep = brw->tess_eval_program;
 
-   if (tep && prog) {
+   if (tep) {
       /* BRW_NEW_TES_PROG_DATA, BRW_NEW_IMAGE_UNITS */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
-                                tep, &brw->tes.base, brw->tes.base.prog_data);
+      brw_upload_image_surfaces(brw, tep, &brw->tes.base,
+                                brw->tes.base.prog_data);
    }
 }
 
index 7bc7b77e9cfc1a3f42c979ef80548ce30112dd33..6c349f400eca0f28917e390ef94fa265ca81d04a 100644 (file)
@@ -188,16 +188,13 @@ const struct brw_tracked_state brw_vs_abo_surfaces = {
 static void
 brw_upload_vs_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_VERTEX_PROGRAM */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
    const struct gl_program *vp = brw->vertex_program;
 
-   if (vp && prog) {
+   if (vp) {
       /* BRW_NEW_VS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_VERTEX],
-                                vp, &brw->vs.base, brw->vs.base.prog_data);
+      brw_upload_image_surfaces(brw, vp, &brw->vs.base,
+                                brw->vs.base.prog_data);
    }
 }
 
index 6c44381be139b9bf8afec1711a34a58e2c3fc6b5..34fec7e7d946bd943a4636a68e3545c85b826dd8 100644 (file)
@@ -1564,16 +1564,13 @@ const struct brw_tracked_state brw_cs_abo_surfaces = {
 static void
 brw_upload_cs_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* _NEW_PROGRAM */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
    const struct gl_program *cp = brw->compute_program;
 
-   if (cp && prog) {
+   if (cp) {
       /* BRW_NEW_CS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_COMPUTE],
-                                cp, &brw->cs.base, brw->cs.base.prog_data);
+      brw_upload_image_surfaces(brw, cp, &brw->cs.base,
+                                brw->cs.base.prog_data);
    }
 }
 
@@ -1780,7 +1777,6 @@ update_image_surface(struct brw_context *brw,
 
 void
 brw_upload_image_surfaces(struct brw_context *brw,
-                          struct gl_linked_shader *shader,
                           const struct gl_program *prog,
                           struct brw_stage_state *stage_state,
                           struct brw_stage_prog_data *prog_data)
@@ -1788,12 +1784,12 @@ brw_upload_image_surfaces(struct brw_context *brw,
    assert(prog);
    struct gl_context *ctx = &brw->ctx;
 
-   if (prog->info.num_images && shader) {
+   if (prog->info.num_images) {
       for (unsigned i = 0; i < prog->info.num_images; i++) {
-         struct gl_image_unit *u = &ctx->ImageUnits[shader->ImageUnits[i]];
+         struct gl_image_unit *u = &ctx->ImageUnits[prog->sh.ImageUnits[i]];
          const unsigned surf_idx = prog_data->binding_table.image_start + i;
 
-         update_image_surface(brw, u, shader->ImageAccess[i],
+         update_image_surface(brw, u, prog->sh.ImageAccess[i],
                               surf_idx,
                               &stage_state->surf_offset[surf_idx],
                               &prog_data->image_param[i]);
@@ -1811,15 +1807,13 @@ brw_upload_image_surfaces(struct brw_context *brw,
 static void
 brw_upload_wm_image_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_FRAGMENT_PROGRAM */
-   struct gl_shader_program *prog = ctx->_Shader->_CurrentFragmentProgram;
    const struct gl_program *wm = brw->fragment_program;
 
-   if (wm && prog) {
+   if (wm) {
       /* BRW_NEW_FS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
-      brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
-                                wm, &brw->wm.base, brw->wm.base.prog_data);
+      brw_upload_image_surfaces(brw, wm, &brw->wm.base,
+                                brw->wm.base.prog_data);
    }
 }
 
index 2693a8068c0a63f410a235de70390c8eeec5ab21..fa14c87a2c0c406735088afe33669a36d8ecb2e2 100644 (file)
@@ -1980,6 +1980,25 @@ struct gl_program
          GLuint MaxSubroutineFunctionIndex;
          struct gl_subroutine_function *SubroutineFunctions;
 
+         /**
+          * Map from image uniform index to image unit (set by glUniform1i())
+          *
+          * An image uniform index is associated with each image uniform by
+          * the linker.  The image index associated with each uniform is
+          * stored in the \c gl_uniform_storage::image field.
+          */
+         GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
+
+         /**
+          * Access qualifier specified in the shader for each image uniform
+          * index.  Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
+          * GL_READ_WRITE.
+          *
+          * It may be different, though only more strict than the value of
+          * \c gl_image_unit::Access for the corresponding image unit.
+          */
+         GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
+
          union {
             struct {
                /**
@@ -2374,29 +2393,10 @@ struct gl_linked_shader
    struct exec_list *fragdata_arrays;
    struct glsl_symbol_table *symbols;
 
-   /**
-    * Map from image uniform index to image unit (set by glUniform1i())
-    *
-    * An image uniform index is associated with each image uniform by
-    * the linker.  The image index associated with each uniform is
-    * stored in the \c gl_uniform_storage::image field.
-    */
-   GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
-
-   /**
-    * Access qualifier specified in the shader for each image uniform
-    * index.  Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
-    * GL_READ_WRITE.
-    *
-    * It may be different, though only more strict than the value of
-    * \c gl_image_unit::Access for the corresponding image unit.
-    */
-   GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
-
    /**
     * Number of image uniforms defined in the shader.  It specifies
     * the number of valid elements in the \c ImageUnits and \c
-    * ImageAccess arrays above.
+    * ImageAccess arrays.
     */
    GLuint NumImages;
 
index 3108d348d6fa90f88137c97cae6ef1419a331504..ec6d27748449cc4787f8cf35a715957fcd8cb771 100644 (file)
@@ -908,7 +908,7 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
             struct gl_linked_shader *sh = shProg->_LinkedShaders[i];
 
             for (int j = 0; j < count; j++)
-               sh->ImageUnits[uni->opaque[i].index + offset + j] =
+               sh->Program->sh.ImageUnits[uni->opaque[i].index + offset + j] =
                   ((GLint *) values)[j];
          }
       }
index a7b7371bfee1ba255bd1b54159163206b37024db..b30006a143c9ab58ff36d283672a31f913160dfa 100644 (file)
@@ -58,7 +58,8 @@ st_bind_images(struct st_context *st, struct gl_linked_shader *shader,
    c = &st->ctx->Const.Program[shader->Stage];
 
    for (i = 0; i < shader->NumImages; i++) {
-      struct gl_image_unit *u = &st->ctx->ImageUnits[shader->ImageUnits[i]];
+      struct gl_image_unit *u =
+         &st->ctx->ImageUnits[shader->Program->sh.ImageUnits[i]];
       struct st_texture_object *stObj = st_texture_object(u->TexObj);
       struct pipe_image_view *img = &images[i];