[Mesa-dev] [PATCH] i965: Initialize grf_used in fs_visitor::emit_repclear_shader().

Kenneth Graunke kenneth at whitecape.org
Mon Oct 13 17:12:37 PDT 2014

fs_visitor::grf_used is used to calculate prog_data->reg_blocks_16,
which was getting populated with an uninitialized value.  Normally,
grf_used is set by the register allocator, but emit_repclear_shader
bypasses that; it must set grf_used directly.

This bug was well hidden: reg_blocks and reg_blocks_16 are unused on
Gen6+.  However, when uploading programs, we look for an existing entry
in the cache.  If we find a potential hit, we memcmp the two prog_data
structures, including the uninitialized reg_blocks_16 field.  Of course,
this only happens if we upload the repclear shader twice - which only
happens if the precompile guesses the program key incorrectly.

On Gen6+, precompile guesses the program key for the repclear shader
correctly, so this bug ought to remain untriggered.  However, on Gen5,
we make more mistakes when guessing the key, which is how I spotted the
bug.  It is reproducible on Haswell by making precompile choose daft
values for fields.

Cc: Jason Ekstrand <jason at jlekstrand.net>
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
 src/mesa/drivers/dri/i965/brw_fs.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8d470f2..8d9e63f 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2614,6 +2614,8 @@ fs_visitor::emit_repclear_shader()
+   grf_used = 0;

More information about the mesa-dev mailing list