i965: Shrink stage_prog_data param array length
authorJordan Justen <jordan.l.justen@intel.com>
Sun, 29 May 2016 00:57:31 +0000 (17:57 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Sun, 29 May 2016 16:59:55 +0000 (09:59 -0700)
It appears we were over-allocating these arrays.

Previously we would use nir->num_uniforms directly for scalar
programs, and multiply it by 4 for vec4 programs.

Instead we should have been dividing by 4 in both cases to convert
from bytes to a gl_constant_value count. The size of gl_constant_value
is 4 bytes.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_cs.c
src/mesa/drivers/dri/i965/brw_gs.c
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

index 0ab9ebdab3c3a9e984c66e13ca1aee1cb021097b..a9cbde9f07c7446bb48b7f819f330695f3eccc95 100644 (file)
@@ -91,7 +91,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
     * prog_data associated with the compiled program, and which will be freed
     * by the state cache.
     */
-   int param_count = cp->program.Base.nir->num_uniforms;
+   int param_count = cp->program.Base.nir->num_uniforms / 4;
 
    /* The backend also sometimes adds params for texture size. */
    param_count += 2 * ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits;
index 8f5dcf359e960bd13594ef1e805ddc6ab2910a2a..7ead182da6c185b2a73c68cdf73516b61961620b 100644 (file)
@@ -119,9 +119,7 @@ brw_codegen_gs_prog(struct brw_context *brw,
     */
    struct gl_shader *gs = prog->_LinkedShaders[MESA_SHADER_GEOMETRY];
    struct brw_shader *bgs = (struct brw_shader *) gs;
-   int param_count = gp->program.Base.nir->num_uniforms;
-   if (!compiler->scalar_stage[MESA_SHADER_GEOMETRY])
-      param_count *= 4;
+   int param_count = gp->program.Base.nir->num_uniforms / 4;
 
    prog_data.base.base.param =
       rzalloc_array(NULL, const gl_constant_value *, param_count);
index 9589fa5edeb7e0005b76e8d483e5287a06c70a50..5a514ef21e917552385ba1936007f65d223292ff 100644 (file)
@@ -199,9 +199,7 @@ brw_codegen_tcs_prog(struct brw_context *brw,
     */
    struct gl_shader *tcs = shader_prog ?
       shader_prog->_LinkedShaders[MESA_SHADER_TESS_CTRL] : NULL;
-   int param_count = nir->num_uniforms;
-   if (!compiler->scalar_stage[MESA_SHADER_TESS_CTRL])
-      param_count *= 4;
+   int param_count = nir->num_uniforms / 4;
 
    prog_data.base.base.param =
       rzalloc_array(NULL, const gl_constant_value *, param_count);
index b7f1677caec4a4a083cbd57f0feaaa42b089be6a..a4cd4daaddef22d05934ff5710276ce1b52f7b22 100644 (file)
@@ -151,9 +151,7 @@ brw_codegen_tes_prog(struct brw_context *brw,
     * every uniform is a float which gets padded to the size of a vec4.
     */
    struct gl_shader *tes = shader_prog->_LinkedShaders[MESA_SHADER_TESS_EVAL];
-   int param_count = nir->num_uniforms;
-   if (!compiler->scalar_stage[MESA_SHADER_TESS_EVAL])
-      param_count *= 4;
+   int param_count = nir->num_uniforms / 4;
 
    prog_data.base.base.param =
       rzalloc_array(NULL, const gl_constant_value *, param_count);
index 2478e62c18067280677088f554f47edcdfc853d7..abf03b1fb7a013dbddeeb5a1dbb4f0ee8b9b4ce4 100644 (file)
@@ -80,9 +80,7 @@ brw_codegen_vs_prog(struct brw_context *brw,
     * prog_data associated with the compiled program, and which will be freed
     * by the state cache.
     */
-   int param_count = vp->program.Base.nir->num_uniforms;
-   if (!compiler->scalar_stage[MESA_SHADER_VERTEX])
-      param_count *= 4;
+   int param_count = vp->program.Base.nir->num_uniforms / 4;
 
    if (vs)
       prog_data.base.base.nr_image_params = vs->base.NumImages;
index 1943d08ab66cde700b2b2a1b76098ecd30d46fab..c9c5d5e443e88353b159527d56452fe682efcce0 100644 (file)
@@ -97,7 +97,7 @@ brw_codegen_wm_prog(struct brw_context *brw,
     * prog_data associated with the compiled program, and which will be freed
     * by the state cache.
     */
-   int param_count = fp->program.Base.nir->num_uniforms;
+   int param_count = fp->program.Base.nir->num_uniforms / 4;
    if (fs)
       prog_data.base.nr_image_params = fs->base.NumImages;
    /* The backend also sometimes adds params for texture size. */