[Mesa-dev] [PATCH 17/20] radeonsi: make si_shader_io_get_unique_index stricter

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


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

---
 src/gallium/drivers/radeonsi/si_shader.c        | 14 ++++----------
 src/gallium/drivers/radeonsi/si_state_shaders.c | 11 ++++++++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 514c23b..b250053 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -116,40 +116,34 @@ unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index)
 	case TGSI_SEMANTIC_POSITION:
 		return 0;
 	case TGSI_SEMANTIC_PSIZE:
 		return 1;
 	case TGSI_SEMANTIC_CLIPDIST:
 		assert(index <= 1);
 		return 2 + index;
 	case TGSI_SEMANTIC_GENERIC:
 		if (index <= 63-4)
 			return 4 + index;
-		else
-			/* same explanation as in the default statement,
-			 * the only user hitting this is st/nine.
-			 */
-			return 0;
+
+		assert(!"invalid generic index");
+		return 0;
 
 	/* patch indices are completely separate and thus start from 0 */
 	case TGSI_SEMANTIC_TESSOUTER:
 		return 0;
 	case TGSI_SEMANTIC_TESSINNER:
 		return 1;
 	case TGSI_SEMANTIC_PATCH:
 		return 2 + index;
 
 	default:
-		/* Don't fail here. The result of this function is only used
-		 * for LS, TCS, TES, and GS, where legacy GL semantics can't
-		 * occur, but this function is called for all vertex shaders
-		 * before it's known whether LS will be compiled or not.
-		 */
+		assert(!"invalid semantic name");
 		return 0;
 	}
 }
 
 /**
  * Get the value of a shader input parameter and extract a bitfield.
  */
 static LLVMValueRef unpack_param(struct si_shader_context *ctx,
 				 unsigned param, unsigned rshift,
 				 unsigned bitwidth)
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 1d116f6..d10084d 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1418,23 +1418,32 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
 			unsigned name = sel->info.output_semantic_name[i];
 			unsigned index = sel->info.output_semantic_index[i];
 
 			switch (name) {
 			case TGSI_SEMANTIC_TESSINNER:
 			case TGSI_SEMANTIC_TESSOUTER:
 			case TGSI_SEMANTIC_PATCH:
 				sel->patch_outputs_written |=
 					1llu << si_shader_io_get_unique_index(name, index);
 				break;
-			default:
+
+			case TGSI_SEMANTIC_GENERIC:
+				/* don't process indices the function can't handle */
+				if (index >= 60)
+					break;
+				/* fall through */
+			case TGSI_SEMANTIC_POSITION:
+			case TGSI_SEMANTIC_PSIZE:
+			case TGSI_SEMANTIC_CLIPDIST:
 				sel->outputs_written |=
 					1llu << si_shader_io_get_unique_index(name, index);
+				break;
 			}
 		}
 		sel->esgs_itemsize = util_last_bit64(sel->outputs_written) * 16;
 		break;
 
 	case PIPE_SHADER_FRAGMENT:
 		for (i = 0; i < 8; i++)
 			if (sel->info.colors_written & (1 << i))
 				sel->colors_written_4bit |= 0xf << (4 * i);
 
-- 
2.7.4



More information about the mesa-dev mailing list