[Mesa-dev] [PATCH 15/21] r600g: if pixel shader is NULL, bind a dummy one

Marek Olšák maraeo at gmail.com
Wed Feb 29 08:53:08 PST 2012


---
 src/gallium/drivers/r600/r600_pipe.c         |   10 ++++++++++
 src/gallium/drivers/r600/r600_pipe.h         |    4 ++++
 src/gallium/drivers/r600/r600_state_common.c |   21 ++++++++++++++-------
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 3f03f2a..db1bf0e 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -37,6 +37,7 @@
 #include "util/u_pack_color.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
+#include "util/u_simple_shaders.h"
 #include "util/u_upload_mgr.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
@@ -191,6 +192,9 @@ static void r600_destroy_context(struct pipe_context *context)
 {
 	struct r600_context *rctx = (struct r600_context *)context;
 
+	if (rctx->dummy_pixel_shader) {
+		rctx->context.delete_fs_state(&rctx->context, rctx->dummy_pixel_shader);
+	}
 	if (rctx->custom_dsa_flush) {
 		rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush);
 	}
@@ -313,6 +317,12 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void
 	if (rctx->chip_class == R600)
 		r600_set_max_scissor(rctx);
 
+	rctx->dummy_pixel_shader =
+		util_make_fragment_cloneinput_shader(&rctx->context, 0,
+						     TGSI_SEMANTIC_GENERIC,
+						     TGSI_INTERPOLATE_CONSTANT);
+	rctx->context.bind_fs_state(&rctx->context, rctx->dummy_pixel_shader);
+
 	return &rctx->context;
 
 fail:
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index de73bd8..08441d1 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -350,6 +350,10 @@ struct r600_context {
 	 * These track the current scissor state. */
 	bool			scissor_enable;
 	struct pipe_scissor_state scissor_state;
+
+	/* With rasterizer discard, there doesn't have to be a pixel shader.
+	 * In that case, we bind this one: */
+	void			*dummy_pixel_shader;
 };
 
 static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 2f643cf..9b8a229 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -461,14 +461,18 @@ void r600_bind_ps_shader(struct pipe_context *ctx, void *state)
 {
 	struct r600_context *rctx = (struct r600_context *)ctx;
 
+	if (!state) {
+		state = rctx->dummy_pixel_shader;
+	}
+
 	rctx->ps_shader = (struct r600_pipe_shader *)state;
-	if (state) {
-		r600_inval_shader_cache(rctx);
-		r600_context_pipe_state_set(rctx, &rctx->ps_shader->rstate);
 
-		rctx->cb_color_control &= C_028808_MULTIWRITE_ENABLE;
-		rctx->cb_color_control |= S_028808_MULTIWRITE_ENABLE(!!rctx->ps_shader->shader.fs_write_all);
-	}
+	r600_inval_shader_cache(rctx);
+	r600_context_pipe_state_set(rctx, &rctx->ps_shader->rstate);
+
+	rctx->cb_color_control &= C_028808_MULTIWRITE_ENABLE;
+	rctx->cb_color_control |= S_028808_MULTIWRITE_ENABLE(!!rctx->ps_shader->shader.fs_write_all);
+
 	if (rctx->ps_shader && rctx->vs_shader) {
 		r600_adjust_gprs(rctx);
 	}
@@ -808,11 +812,14 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo)
 	if ((!info.count && (info.indexed || !info.count_from_stream_output)) ||
 	    (info.indexed && !rctx->vbuf_mgr->index_buffer.buffer) ||
 	    !r600_conv_pipe_prim(info.mode, &prim)) {
+		assert(0);
 		return;
 	}
 
-	if (!rctx->ps_shader || !rctx->vs_shader)
+	if (!rctx->vs_shader) {
+		assert(0);
 		return;
+	}
 
 	r600_update_derived_state(rctx);
 
-- 
1.7.5.4



More information about the mesa-dev mailing list