i965: Store image_param in brw_context instead of prog_data
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 29 Sep 2017 02:04:31 +0000 (19:04 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 13 Oct 2017 05:39:30 +0000 (22:39 -0700)
This burns an extra 10k of memory or so in the case where you don't have
any images.  However, if you have several shaders which use images, this
should be much less memory.  It also gets rid of a part of prog_data
that really has nothing to do with the compiler.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
14 files changed:
src/intel/compiler/brw_compiler.h
src/intel/vulkan/anv_pipeline_cache.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_cs.c
src/mesa/drivers/dri/i965/brw_curbe.c
src/mesa/drivers/dri/i965/brw_gs.c
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_tcs.c
src/mesa/drivers/dri/i965/brw_tes.c
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/gen6_constant_state.c

index f2f9be750a0620c445879ccbb9ed83995d49de23..94fe63e46f1e8af6e437e744d324d042145b9c95 100644 (file)
@@ -574,7 +574,6 @@ struct brw_stage_prog_data {
 
    GLuint nr_params;       /**< number of float params/constants */
    GLuint nr_pull_params;
-   unsigned nr_image_params;
 
    unsigned curb_read_length;
    unsigned total_scratch;
@@ -596,9 +595,6 @@ struct brw_stage_prog_data {
     */
    uint32_t *param;
    uint32_t *pull_param;
-
-   /** Image metadata passed to the shader as uniforms. */
-   struct brw_image_param *image_param;
 };
 
 static inline void
index f782d04fbe69ffda30edb32cc1abfba6e278b27c..ad9c810f1f475e1e692440831507ac121025162d 100644 (file)
@@ -37,7 +37,7 @@ anv_shader_bin_create(struct anv_device *device,
    struct anv_shader_bin *shader;
    struct anv_shader_bin_key *key;
    struct brw_stage_prog_data *prog_data;
-   const union gl_constant_value **prog_data_param;
+   uint32_t *prog_data_param;
    struct anv_pipeline_binding *surface_to_descriptor, *sampler_to_descriptor;
 
    ANV_MULTIALLOC(ma);
@@ -169,9 +169,7 @@ anv_shader_bin_create_from_blob(struct anv_device *device,
  *
  * - Review prog_data struct for size and cacheability: struct
  *   brw_stage_prog_data has binding_table which uses a lot of uint32_t for 8
- *   bit quantities etc; param, pull_param, and image_params are pointers, we
- *   just need the compation map. use bit fields for all bools, eg
- *   dual_src_blend.
+ *   bit quantities etc; use bit fields for all bools, eg dual_src_blend.
  */
 
 static uint32_t
index dea35ee04f6b55c1f76448deef55c0e4a2d07102..272197f1e2fadfd5167d08fcf59132911294bda5 100644 (file)
@@ -580,6 +580,8 @@ struct brw_stage_state
    uint32_t sampler_count;
    uint32_t sampler_offset;
 
+   struct brw_image_param image_param[BRW_MAX_IMAGES];
+
    /** Need to re-emit 3DSTATE_CONSTANT_XS? */
    bool push_constants_dirty;
 };
index 68fca098f76179ac4b63d34db07c54cae8c1094e..0c505b3e505d1bdcfc3414529da978383da60940 100644 (file)
@@ -91,11 +91,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
    param_count += 2 * ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits;
    prog_data.base.param = rzalloc_array(NULL, uint32_t, param_count);
    prog_data.base.pull_param = rzalloc_array(NULL, uint32_t, param_count);
-   prog_data.base.image_param =
-      rzalloc_array(NULL, struct brw_image_param,
-                    cp->program.info.num_images);
    prog_data.base.nr_params = param_count;
-   prog_data.base.nr_image_params = cp->program.info.num_images;
 
    brw_nir_setup_glsl_uniforms(cp->program.nir, &cp->program,&prog_data.base,
                                true);
index 9a9c6d08a0f5774010aa75fac4f73a5a1bd0356c..c747110e31013241d3254fe5e7aa19dac4d0d2bd 100644 (file)
@@ -227,7 +227,7 @@ brw_upload_constant_buffer(struct brw_context *brw)
       GLuint offset = brw->curbe.wm_start * 16;
 
       /* BRW_NEW_FS_PROG_DATA | _NEW_PROGRAM_CONSTANTS: copy uniform values */
-      brw_populate_constant_data(brw, fp, brw->wm.base.prog_data, &buf[offset],
+      brw_populate_constant_data(brw, fp, &brw->wm.base, &buf[offset],
                                  brw->wm.base.prog_data->param,
                                  brw->wm.base.prog_data->nr_params);
    }
@@ -268,7 +268,7 @@ brw_upload_constant_buffer(struct brw_context *brw)
       GLuint offset = brw->curbe.vs_start * 16;
 
       /* BRW_NEW_VS_PROG_DATA | _NEW_PROGRAM_CONSTANTS: copy uniform values */
-      brw_populate_constant_data(brw, vp, brw->vs.base.prog_data, &buf[offset],
+      brw_populate_constant_data(brw, vp, &brw->vs.base, &buf[offset],
                                  brw->vs.base.prog_data->param,
                                  brw->vs.base.prog_data->nr_params);
    }
index c040665a3b611d98f11f0434e2bdb5db7b8be680..917742a592286b91e0eccd9f7139842b2402b2cb 100644 (file)
@@ -101,11 +101,7 @@ brw_codegen_gs_prog(struct brw_context *brw,
 
    prog_data.base.base.param = rzalloc_array(NULL, uint32_t, param_count);
    prog_data.base.base.pull_param = rzalloc_array(NULL, uint32_t, param_count);
-   prog_data.base.base.image_param =
-      rzalloc_array(NULL, struct brw_image_param,
-                    gp->program.info.num_images);
    prog_data.base.base.nr_params = param_count;
-   prog_data.base.base.nr_image_params = gp->program.info.num_images;
 
    brw_nir_setup_glsl_uniforms(gp->program.nir, &gp->program,
                                &prog_data.base.base,
index c11ac871e58e7c43b60a5f92f26ea06a319005c1..f88977fb723292c4870203c9ac2453b22793a788 100644 (file)
@@ -618,7 +618,6 @@ brw_stage_prog_data_free(const void *p)
 
    ralloc_free(prog_data->param);
    ralloc_free(prog_data->pull_param);
-   ralloc_free(prog_data->image_param);
 }
 
 void
index 64acc1d9bf7de710117e259370ba37989feadfd5..8db354cf232da0af5f7a3e15a24004cb79cac582 100644 (file)
@@ -237,7 +237,7 @@ void brw_emit_sampler_state(struct brw_context *brw,
 void
 brw_populate_constant_data(struct brw_context *brw,
                            const struct gl_program *prog,
-                           const struct brw_stage_prog_data *prog_data,
+                           const struct brw_stage_state *stage_state,
                            void *dst,
                            const uint32_t *param,
                            unsigned nr_params);
index 272545453a4e39e81c1d7250bec50230f0a8e8c2..8fd7364a1b1df6aac8bdb81697d605752a4dfdda 100644 (file)
@@ -196,11 +196,6 @@ brw_codegen_tcs_prog(struct brw_context *brw, struct brw_program *tcp,
       brw_assign_common_binding_table_offsets(devinfo, &tcp->program,
                                               &prog_data.base.base, 0);
 
-      prog_data.base.base.image_param =
-         rzalloc_array(NULL, struct brw_image_param,
-                       tcp->program.info.num_images);
-      prog_data.base.base.nr_image_params = tcp->program.info.num_images;
-
       brw_nir_setup_glsl_uniforms(nir, &tcp->program, &prog_data.base.base,
                                   compiler->scalar_stage[MESA_SHADER_TESS_CTRL]);
       brw_nir_analyze_ubo_ranges(compiler, tcp->program.nir,
index 7ee925b0891dd2e91b7c95e8b81e32dc6e46ee26..763207f71728d61fd8b4c49edbb5d4cf3b8ab857 100644 (file)
@@ -92,11 +92,7 @@ brw_codegen_tes_prog(struct brw_context *brw,
 
    prog_data.base.base.param = rzalloc_array(NULL, uint32_t, param_count);
    prog_data.base.base.pull_param = rzalloc_array(NULL, uint32_t, param_count);
-   prog_data.base.base.image_param =
-      rzalloc_array(NULL, struct brw_image_param,
-                    tep->program.info.num_images);
    prog_data.base.base.nr_params = param_count;
-   prog_data.base.base.nr_image_params = tep->program.info.num_images;
 
    brw_nir_setup_glsl_uniforms(nir, &tep->program, &prog_data.base.base,
                                compiler->scalar_stage[MESA_SHADER_TESS_EVAL]);
index 9dd812e1981f17b3a4446eb12a22be087e4ad326..8672d1ec1806223c306aa2e8e63c2439ed5817d4 100644 (file)
@@ -184,8 +184,6 @@ brw_codegen_vs_prog(struct brw_context *brw,
     */
    int param_count = vp->program.nir->num_uniforms / 4;
 
-   prog_data.base.base.nr_image_params = vp->program.info.num_images;
-
    /* vec4_visitor::setup_uniform_clipplane_values() also uploads user clip
     * planes as uniforms.
     */
@@ -193,9 +191,6 @@ brw_codegen_vs_prog(struct brw_context *brw,
 
    stage_prog_data->param = rzalloc_array(NULL, uint32_t, param_count);
    stage_prog_data->pull_param = rzalloc_array(NULL, uint32_t, param_count);
-   stage_prog_data->image_param =
-      rzalloc_array(NULL, struct brw_image_param,
-                    stage_prog_data->nr_image_params);
    stage_prog_data->nr_params = param_count;
 
    if (!vp->program.is_arb_asm) {
index ddafa52619885d23f869efe79e2e4c6864140eae..6f2f6f224ceb855b45d20f9a15ff0bbe30ebb51f 100644 (file)
@@ -150,14 +150,10 @@ brw_codegen_wm_prog(struct brw_context *brw,
     * by the state cache.
     */
    int param_count = fp->program.nir->num_uniforms / 4;
-   prog_data.base.nr_image_params = fp->program.info.num_images;
    /* The backend also sometimes adds params for texture size. */
    param_count += 2 * ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
    prog_data.base.param = rzalloc_array(NULL, uint32_t, param_count);
    prog_data.base.pull_param = rzalloc_array(NULL, uint32_t, param_count);
-   prog_data.base.image_param =
-      rzalloc_array(NULL, struct brw_image_param,
-                    prog_data.base.nr_image_params);
    prog_data.base.nr_params = param_count;
 
    if (!fp->program.is_arb_asm) {
index b62d1e22a129e6f0eba0723b42cc43ec9b664e76..f4e9cf48c6a6687f8296eb586e08501e31e45860 100644 (file)
@@ -1630,7 +1630,7 @@ brw_upload_image_surfaces(struct brw_context *brw,
          update_image_surface(brw, u, prog->sh.ImageAccess[i],
                               surf_idx,
                               &stage_state->surf_offset[surf_idx],
-                              &prog_data->image_param[i]);
+                              &stage_state->image_param[i]);
       }
 
       brw->ctx.NewDriverState |= BRW_NEW_SURFACES;
index 93a12c706ffa9559f3444ebc711f702ec1d28ef4..eb9e29187c411aa8fb247924d0b79a3a41082bce 100644 (file)
@@ -38,7 +38,7 @@ f_as_u32(float f)
 static uint32_t
 brw_param_value(struct brw_context *brw,
                 const struct gl_program *prog,
-                const struct brw_stage_prog_data *prog_data,
+                const struct brw_stage_state *stage_state,
                 uint32_t param)
 {
    struct gl_context *ctx = &brw->ctx;
@@ -80,9 +80,8 @@ brw_param_value(struct brw_context *brw,
    case BRW_PARAM_DOMAIN_IMAGE: {
       unsigned idx = BRW_PARAM_IMAGE_IDX(param);
       unsigned offset = BRW_PARAM_IMAGE_OFFSET(param);
-      assert(idx < prog_data->nr_image_params);
-      assert(offset < sizeof(struct brw_image_param));
-      return ((uint32_t *)&prog_data->image_param[idx])[offset];
+      assert(offset < ARRAY_SIZE(stage_state->image_param));
+      return ((uint32_t *)&stage_state->image_param[idx])[offset];
    }
 
    default:
@@ -94,14 +93,14 @@ brw_param_value(struct brw_context *brw,
 void
 brw_populate_constant_data(struct brw_context *brw,
                            const struct gl_program *prog,
-                           const struct brw_stage_prog_data *prog_data,
+                           const struct brw_stage_state *stage_state,
                            void *void_dst,
                            const uint32_t *param,
                            unsigned nr_params)
 {
    uint32_t *dst = void_dst;
    for (unsigned i = 0; i < nr_params; i++)
-      dst[i] = brw_param_value(brw, prog, prog_data, param[i]);
+      dst[i] = brw_param_value(brw, prog, stage_state, param[i]);
 }
 
 
@@ -159,7 +158,7 @@ gen6_upload_push_constants(struct brw_context *brw,
        * side effect of dereferencing uniforms, so _NEW_PROGRAM_CONSTANTS
        * wouldn't be set for them.
        */
-      brw_populate_constant_data(brw, prog, prog_data, param,
+      brw_populate_constant_data(brw, prog, stage_state, param,
                                  prog_data->param,
                                  prog_data->nr_params);
 
@@ -246,7 +245,7 @@ brw_upload_pull_constants(struct brw_context *brw,
 
    STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
 
-   brw_populate_constant_data(brw, prog, prog_data, constants,
+   brw_populate_constant_data(brw, prog, stage_state, constants,
                               prog_data->pull_param,
                               prog_data->nr_pull_params);
 
@@ -312,7 +311,7 @@ brw_upload_cs_push_constants(struct brw_context *brw,
       for (unsigned i = 0;
            i < cs_prog_data->push.cross_thread.dwords;
            i++) {
-         param_copy[i] = brw_param_value(brw, prog, prog_data,
+         param_copy[i] = brw_param_value(brw, prog, stage_state,
                                          prog_data->param[i]);
       }
    }
@@ -325,7 +324,7 @@ brw_upload_cs_push_constants(struct brw_context *brw,
          unsigned src = cs_prog_data->push.cross_thread.dwords;
          for ( ; src < prog_data->nr_params; src++, dst++) {
             if (src != cs_prog_data->thread_local_id_index) {
-               param[dst] = brw_param_value(brw, prog, prog_data,
+               param[dst] = brw_param_value(brw, prog, stage_state,
                                             prog_data->param[src]);
             } else {
                param[dst] = t * cs_prog_data->simd_size;