[Mesa-dev] [PATCH] radeonsi/gfx9: fix crash building monolithic merged ES-GS shader

Nicolai Hähnle nhaehnle at gmail.com
Wed Jul 12 13:54:20 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Forwarding from the ES prolog to the ES just barely exceeds the current
maximum array size when 16 vertex attributes are used. Give it a decent
bump to account for merged shaders having up to 32 user SGPRs.

Fixes a crash in GL45-CTS.multi_bind.draw_bind_vertex_buffers.

Cc: mesa-stable at lists.freedesktop.org
---
 src/gallium/drivers/radeonsi/si_shader.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 349e57b..4c0cda5 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -5885,23 +5885,25 @@ static void si_build_gs_prolog_function(struct si_shader_context *ctx,
  * runs them in sequence to form a monolithic shader.
  */
 static void si_build_wrapper_function(struct si_shader_context *ctx,
 				      LLVMValueRef *parts,
 				      unsigned num_parts,
 				      unsigned main_part,
 				      unsigned next_shader_first_part)
 {
 	struct gallivm_state *gallivm = &ctx->gallivm;
 	LLVMBuilderRef builder = ctx->gallivm.builder;
-	/* PS epilog has one arg per color component */
-	LLVMTypeRef param_types[48];
-	LLVMValueRef initial[48], out[48];
+	/* PS epilog has one arg per color component; gfx9 merged shader
+	 * prologs need to forward 32 user SGPRs.
+	 */
+	LLVMTypeRef param_types[64];
+	LLVMValueRef initial[64], out[64];
 	LLVMTypeRef function_type;
 	unsigned num_params;
 	unsigned num_out, initial_num_out;
 	MAYBE_UNUSED unsigned num_out_sgpr; /* used in debug checks */
 	MAYBE_UNUSED unsigned initial_num_out_sgpr; /* used in debug checks */
 	unsigned num_sgprs, num_vgprs;
 	unsigned last_sgpr_param;
 	unsigned gprs;
 	struct lp_build_if_state if_state;
 
@@ -6107,20 +6109,21 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
 
 		if (LLVMGetTypeKind(ret_type) != LLVMVoidTypeKind) {
 			assert(LLVMGetTypeKind(ret_type) == LLVMStructTypeKind);
 
 			unsigned ret_size = LLVMCountStructElementTypes(ret_type);
 
 			for (unsigned i = 0; i < ret_size; ++i) {
 				LLVMValueRef val =
 					LLVMBuildExtractValue(builder, ret, i, "");
 
+				assert(num_out < ARRAY_SIZE(out));
 				out[num_out++] = val;
 
 				if (LLVMTypeOf(val) == ctx->i32) {
 					assert(num_out_sgpr + 1 == num_out);
 					num_out_sgpr = num_out;
 				}
 			}
 		}
 	}
 
-- 
2.9.3



More information about the mesa-dev mailing list