Mesa (master): radeonsi: Handle NULL sampler views getting passed in by the state tracker.

Michel Dänzer daenzer at kemper.freedesktop.org
Tue Aug 21 13:43:17 UTC 2012


Module: Mesa
Branch: master
Commit: 1a25ebe3ce95a6a4aef7c844dbe95909976b68da
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1a25ebe3ce95a6a4aef7c844dbe95909976b68da

Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Tue Aug 21 13:48:18 2012 +0200

radeonsi: Handle NULL sampler views getting passed in by the state tracker.

Don't dereference NULL pointers, and if all views are NULL, don't generate an
invalid PM4 packet which locks up the GPU.

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
Reviewed-by: Christian König <christian.koenig at amd.com>

---

 src/gallium/drivers/radeonsi/radeonsi_pm4.c |    7 +++++++
 src/gallium/drivers/radeonsi/si_state.c     |   12 +++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/radeonsi_pm4.c b/src/gallium/drivers/radeonsi/radeonsi_pm4.c
index 3c53ce2..8268f91 100644
--- a/src/gallium/drivers/radeonsi/radeonsi_pm4.c
+++ b/src/gallium/drivers/radeonsi/radeonsi_pm4.c
@@ -109,6 +109,13 @@ void si_pm4_sh_data_add(struct si_pm4_state *state, uint32_t dw)
 void si_pm4_sh_data_end(struct si_pm4_state *state, unsigned reg)
 {
 	unsigned offs = state->last_pm4 + 1;
+
+	/* Bail if no data was added */
+	if (state->ndw == offs) {
+		state->ndw--;
+		return;
+	}
+
 	si_pm4_cmd_end(state, false);
 
 	si_pm4_cmd_begin(state, PKT3_SET_SH_REG_OFFSET);
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index 11acb73..9a9a250 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -1971,16 +1971,18 @@ static void si_set_ps_sampler_view(struct pipe_context *ctx, unsigned count,
 
 	si_pm4_sh_data_begin(pm4);
 	for (i = 0; i < count; i++) {
-		struct r600_resource_texture *tex = (void *)resource[i]->base.texture;
-
 		pipe_sampler_view_reference(
 			(struct pipe_sampler_view **)&rctx->ps_samplers.views[i],
 			views[i]);
 
-		si_pm4_add_bo(pm4, &tex->resource, RADEON_USAGE_READ);
+		if (views[i]) {
+			struct r600_resource_texture *tex = (void *)resource[i]->base.texture;
+
+			si_pm4_add_bo(pm4, &tex->resource, RADEON_USAGE_READ);
 
-		for (j = 0; j < Elements(resource[i]->state); ++j) {
-			si_pm4_sh_data_add(pm4, resource[i]->state[j]);
+			for (j = 0; j < Elements(resource[i]->state); ++j) {
+				si_pm4_sh_data_add(pm4, resource[i]->state[j]);
+			}
 		}
 	}
 




More information about the mesa-commit mailing list