[Mesa-dev] [PATCH 2/3] ac/shader: scan if vertex shaders need base_vertex or start_instance

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Jan 29 11:39:59 UTC 2018


Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/common/ac_shader_info.c | 35 ++++++++++++++++++++++++++++++++---
 src/amd/common/ac_shader_info.h |  2 ++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/amd/common/ac_shader_info.c b/src/amd/common/ac_shader_info.c
index d771cd250d..749e13f350 100644
--- a/src/amd/common/ac_shader_info.c
+++ b/src/amd/common/ac_shader_info.c
@@ -44,6 +44,12 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
 	case nir_intrinsic_load_instance_id:
 		info->vs.needs_instance_id = true;
 		break;
+	case nir_intrinsic_load_base_instance:
+		info->vs.needs_start_instance = true;
+		break;
+	case nir_intrinsic_load_base_vertex:
+		info->vs.needs_base_vertex = true;
+		break;
 	case nir_intrinsic_load_num_work_groups:
 		info->cs.uses_grid_size = true;
 		break;
@@ -167,12 +173,35 @@ gather_info_block(const nir_shader *nir, const nir_block *block,
 }
 
 static void
-gather_info_input_decl(const nir_shader *nir, const nir_variable *var,
+gather_info_input_decl_vs(const nir_shader *nir,
+			  const struct ac_nir_compiler_options *options,
+			  const nir_variable *var,
+			  struct ac_shader_info *info)
+{
+	unsigned attrib_count = glsl_count_attribute_slots(var->type, true);
+	int index = var->data.location - VERT_ATTRIB_GENERIC0;
+	int idx = var->data.location;
+
+	for (unsigned i = 0; i < attrib_count; ++i, ++idx) {
+		if (options->key.vs.instance_rate_inputs & (1u << (index + i))) {
+			info->vs.needs_start_instance = true;
+		} else {
+			info->vs.needs_base_vertex = true;
+		}
+	}
+
+	info->vs.has_vertex_buffers = true;
+}
+
+static void
+gather_info_input_decl(const nir_shader *nir,
+		       const struct ac_nir_compiler_options *options,
+		       const nir_variable *var,
 		       struct ac_shader_info *info)
 {
 	switch (nir->info.stage) {
 	case MESA_SHADER_VERTEX:
-		info->vs.has_vertex_buffers = true;
+		gather_info_input_decl_vs(nir, options, var, info);
 		break;
 	default:
 		break;
@@ -191,7 +220,7 @@ ac_nir_shader_info_pass(const struct nir_shader *nir,
 		info->loads_push_constants = true;
 
 	nir_foreach_variable(variable, &nir->inputs)
-		gather_info_input_decl(nir, variable, info);
+		gather_info_input_decl(nir, options, variable, info);
 
 	nir_foreach_block(block, func->impl) {
 		gather_info_block(nir, block, info);
diff --git a/src/amd/common/ac_shader_info.h b/src/amd/common/ac_shader_info.h
index 59b749576a..e5c5ccf953 100644
--- a/src/amd/common/ac_shader_info.h
+++ b/src/amd/common/ac_shader_info.h
@@ -37,6 +37,8 @@ struct ac_shader_info {
 		bool has_vertex_buffers; /* needs vertex buffers and base/start */
 		bool needs_draw_id;
 		bool needs_instance_id;
+		bool needs_start_instance;
+		bool needs_base_vertex;
 	} vs;
 	struct {
 		bool force_persample;
-- 
2.16.1



More information about the mesa-dev mailing list