[Mesa-dev] [PATCH 13/20] radeonsi: simplify checking for monolithic compilation

Marek Olšák maraeo at gmail.com
Wed Nov 16 18:38:36 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/drivers/radeonsi/si_compute.c       | 1 +
 src/gallium/drivers/radeonsi/si_shader.c        | 9 +--------
 src/gallium/drivers/radeonsi/si_shader.h        | 1 +
 src/gallium/drivers/radeonsi/si_state_shaders.c | 6 ++++++
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c
index f1887bb..90674f3 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -118,20 +118,21 @@ static void *si_create_compute_state(
 			return NULL;
 		}
 
 		tgsi_scan_shader(cso->prog, &sel.info);
 		sel.type = PIPE_SHADER_COMPUTE;
 		sel.local_size = cso->req_local_mem;
 
 		p_atomic_inc(&sscreen->b.num_shaders_created);
 
 		program->shader.selector = &sel;
+		program->shader.is_monolithic = true;
 
 		if (si_shader_create(sscreen, sctx->tm, &program->shader,
 		                     &sctx->b.debug)) {
 			FREE(sel.tokens);
 			FREE(program);
 			return NULL;
 		}
 
 		scratch_enabled = shader->config.scratch_bytes_per_wave > 0;
 
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index c7028de..cd436f7 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -8126,28 +8126,21 @@ int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
 	struct si_shader_selector *sel = shader->selector;
 	struct si_shader *mainp = sel->main_shader_part;
 	int r;
 
 	/* LS, ES, VS are compiled on demand if the main part hasn't been
 	 * compiled for that stage.
 	 *
 	 * Vertex shaders are compiled on demand when a vertex fetch
 	 * workaround must be applied.
 	 */
-	if (!mainp ||
-	    shader->key.as_es != mainp->key.as_es ||
-	    shader->key.as_ls != mainp->key.as_ls ||
-	    (sel->type == PIPE_SHADER_VERTEX &&
-	     shader->key.mono.vs.fix_fetch) ||
-	    (sel->type == PIPE_SHADER_TESS_CTRL &&
-	     shader->key.mono.tcs.inputs_to_copy) ||
-	    sel->type == PIPE_SHADER_COMPUTE) {
+	if (shader->is_monolithic) {
 		/* Monolithic shader (compiled as a whole, has many variants,
 		 * may take a long time to compile).
 		 */
 		r = si_compile_tgsi_shader(sscreen, tm, shader, true, debug);
 		if (r)
 			return r;
 	} else {
 		/* The shader consists of 2-3 parts:
 		 *
 		 * - the middle part is the user shader, it has 1 variant only
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index bed22c1..2ed0cb7 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -477,20 +477,21 @@ struct si_shader {
 	struct si_shader_selector	*selector;
 	struct si_shader		*next_variant;
 
 	struct si_shader_part		*prolog;
 	struct si_shader_part		*epilog;
 
 	struct si_pm4_state		*pm4;
 	struct r600_resource		*bo;
 	struct r600_resource		*scratch_bo;
 	struct si_shader_key		key;
+	bool				is_monolithic;
 	bool				is_binary_shared;
 	bool				is_gs_copy_shader;
 
 	/* The following data is all that's needed for binary shaders. */
 	struct radeon_shader_binary	binary;
 	struct si_shader_config		config;
 	struct si_shader_info		info;
 
 	/* Shader key + LLVM IR + disassembly + statistics.
 	 * Generated for debug contexts only.
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 3323d3c..9df8f47 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1017,20 +1017,21 @@ static inline void si_shader_selector_key(struct pipe_context *ctx,
 
 /* Select the hw shader variant depending on the current state. */
 static int si_shader_select_with_key(struct si_screen *sscreen,
 				     struct si_shader_ctx_state *state,
 				     struct si_shader_key *key,
 				     LLVMTargetMachineRef tm,
 				     struct pipe_debug_callback *debug,
 				     bool wait,
 				     bool is_debug_context)
 {
+	static const struct si_shader_key zeroed;
 	struct si_shader_selector *sel = state->cso;
 	struct si_shader *current = state->current;
 	struct si_shader *iter, *shader = NULL;
 	int r;
 
 	/* Check if we don't need to change anything.
 	 * This path is also used for most shaders that don't need multiple
 	 * variants, it will cost just a computation of the key and this
 	 * test. */
 	if (likely(current && memcmp(&current->key, key, sizeof(*key)) == 0))
@@ -1057,20 +1058,25 @@ static int si_shader_select_with_key(struct si_screen *sscreen,
 	}
 
 	/* Build a new shader. */
 	shader = CALLOC_STRUCT(si_shader);
 	if (!shader) {
 		pipe_mutex_unlock(sel->mutex);
 		return -ENOMEM;
 	}
 	shader->selector = sel;
 	shader->key = *key;
+	shader->is_monolithic =
+		!sel->main_shader_part ||
+		sel->main_shader_part->key.as_ls != key->as_ls ||
+		sel->main_shader_part->key.as_es != key->as_es ||
+		memcmp(&key->mono, &zeroed.mono, sizeof(key->mono)) != 0;
 
 	r = si_shader_create(sscreen, tm, shader, debug);
 	if (unlikely(r)) {
 		R600_ERR("Failed to build shader variant (type=%u) %d\n",
 			 sel->type, r);
 		FREE(shader);
 		pipe_mutex_unlock(sel->mutex);
 		return r;
 	}
 
-- 
2.7.4



More information about the mesa-dev mailing list