Mesa (9.1): r600g: Correctly initialize the shader key, v2

Andreas Boll ab at kemper.freedesktop.org
Tue Jun 11 15:39:56 UTC 2013


Module: Mesa
Branch: 9.1
Commit: 2a802bc4356b64ddafa8406bd7218049c7b859ac
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2a802bc4356b64ddafa8406bd7218049c7b859ac

Author: Lauri Kasanen <cand at gmx.com>
Date:   Fri May  3 16:55:49 2013 +0300

r600g: Correctly initialize the shader key, v2

Assigning a struct only copies the members - any padding is left as is.

Thus this code:

struct foo_t foo;
foo = bar;

leaves the padding of foo intact, ie uninitialized random garbage.

This patch fixes constant shader recompiles by initializing the struct
to zero. For completeness, memcpy is used to copy the key to the shader
struct.

NOTE: This is a candidate for the stable branches.

Signed-off-by: Lauri Kasanen <cand at gmx.com>
Reviewed-by: Marek Olšák <maraeo at gmail.com>
Signed-off-by: Andreas Boll <andreas.boll.dev at gmail.com>
(cherry picked from commit e495d88453076a4fe552502d66d6a3869ab70e4a)

---

 src/gallium/drivers/r600/r600_state_common.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index f0e9de3..e67de7c 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -720,6 +720,7 @@ static int r600_shader_select(struct pipe_context *ctx,
 	struct r600_pipe_shader * shader = NULL;
 	int r;
 
+	memset(&key, 0, sizeof(key));
 	key = r600_shader_selector_key(ctx, sel);
 
 	/* Check if we don't need to change anything.
@@ -766,7 +767,7 @@ static int r600_shader_select(struct pipe_context *ctx,
 			key = r600_shader_selector_key(ctx, sel);
 		}
 
-		shader->key = key;
+		memcpy(&shader->key, &key, sizeof(key));
 		sel->num_shaders++;
 	}
 




More information about the mesa-commit mailing list