i965: Set nr_params to the number of uniform components in the VS/GS path.
authorFrancisco Jerez <currojerez@riseup.net>
Thu, 22 Jan 2015 15:08:23 +0000 (17:08 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Fri, 20 Mar 2015 14:55:36 +0000 (16:55 +0200)
Both do_vs_prog and do_gs_prog initialize brw_stage_prog_data::nr_params to
the number of uniform *vectors* required by the shader rather than the number
of uniform components, contradicting the comment.  This is inconsistent with
what the state upload code and scalar path expect but it happens to work until
Gen8 because vec4_visitor interprets it as a number of vectors on construction
and later on overwrites its original value with the number of uniform
components referenced by the shader.

Also there's no need to add the number of samplers, they're not actually
passed in as uniforms.

Fixes a memory corruption issue on BDW with SIMD8 VS.

Cc: "10.5" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_gs.c
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/drivers/dri/i965/brw_vs.c

index efcff090818ce63a420ad3351ddd5bac5e63cd1c..45c157a468e92ca4a501703765595ea2cf5d7a5a 100644 (file)
@@ -69,11 +69,7 @@ do_gs_prog(struct brw_context *brw,
       rzalloc_array(NULL, const gl_constant_value *, param_count);
    c.prog_data.base.base.pull_param =
       rzalloc_array(NULL, const gl_constant_value *, param_count);
-   /* Setting nr_params here NOT to the size of the param and pull_param
-    * arrays, but to the number of uniform components vec4_visitor
-    * needs. vec4_visitor::setup_uniforms() will set it back to a proper value.
-    */
-   c.prog_data.base.base.nr_params = ALIGN(param_count, 4) / 4 + gs->num_samplers;
+   c.prog_data.base.base.nr_params = param_count;
 
    if (brw->gen >= 7) {
       if (gp->program.OutputType == GL_POINTS) {
index d5c6e9b5741c14e09fa49f8580bdfb61da5bd0b7..05bda43bb2be8128af794f9062b8ac6cef66494c 100644 (file)
@@ -3671,7 +3671,8 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
     */
    this->uniform_array_size = 1;
    if (prog_data) {
-      this->uniform_array_size = MAX2(stage_prog_data->nr_params, 1);
+      this->uniform_array_size =
+         MAX2(DIV_ROUND_UP(stage_prog_data->nr_params, 4), 1);
    }
 
    this->uniform_size = rzalloc_array(mem_ctx, int, this->uniform_array_size);
index 2aefd35832c335e011abbbd9e6e191de777942b2..ba2c23d44059d54d1c8611c58883ad03948fa5e0 100644 (file)
@@ -241,15 +241,7 @@ do_vs_prog(struct brw_context *brw,
       rzalloc_array(NULL, const gl_constant_value *, param_count);
    stage_prog_data->pull_param =
       rzalloc_array(NULL, const gl_constant_value *, param_count);
-
-   /* Setting nr_params here NOT to the size of the param and pull_param
-    * arrays, but to the number of uniform components vec4_visitor
-    * needs. vec4_visitor::setup_uniforms() will set it back to a proper value.
-    */
-   stage_prog_data->nr_params = ALIGN(param_count, 4) / 4;
-   if (vs) {
-      stage_prog_data->nr_params += vs->num_samplers;
-   }
+   stage_prog_data->nr_params = param_count;
 
    GLbitfield64 outputs_written = vp->program.Base.OutputsWritten;
    prog_data.inputs_read = vp->program.Base.InputsRead;