[Mesa-dev] [PATCH 2/4] radeonsi/nir: add get_num_of_component_info() helper

Timothy Arceri tarceri at itsqueeze.com
Mon Feb 11 03:43:59 UTC 2019


This will be reused in the following patch.
---
 src/gallium/drivers/radeonsi/si_shader_nir.c | 38 ++++++++++++--------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 5abda445e09..04e9e217306 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -51,6 +51,27 @@ static nir_variable* intrinsic_get_var(nir_intrinsic_instr *instr)
 	return nir_deref_instr_get_variable(nir_src_as_deref(instr->src[0]));
 }
 
+static void get_num_of_component_info(nir_variable *var, unsigned slot_idx,
+				      unsigned *num_comps, unsigned *first_comp)
+{
+	unsigned num_components = 4;
+	unsigned vector_elements = glsl_get_vector_elements(glsl_without_array(var->type));
+	if (vector_elements)
+		num_components = vector_elements;
+
+	*first_comp = var->data.location_frac;
+	if (glsl_type_is_64bit(glsl_without_array(var->type))) {
+		if (glsl_type_is_dual_slot(glsl_without_array(var->type)) && slot_idx % 2) {
+			num_components = (num_components * 2) - 4;
+			*first_comp = 0;
+		} else {
+			num_components = MIN2(num_components * 2, 4);
+		}
+	}
+
+	*num_comps = num_components;
+}
+
 static ubyte get_component_usagemask(unsigned first_comp,
 				     unsigned num_components)
 {
@@ -538,20 +559,9 @@ void si_nir_scan_shader(const struct nir_shader *nir,
 							     &semantic_name, &semantic_index);
 			}
 
-			unsigned num_components = 4;
-			unsigned vector_elements = glsl_get_vector_elements(glsl_without_array(variable->type));
-			if (vector_elements)
-				num_components = vector_elements;
-
-			unsigned component = variable->data.location_frac;
-			if (glsl_type_is_64bit(glsl_without_array(variable->type))) {
-				if (glsl_type_is_dual_slot(glsl_without_array(variable->type)) && k % 2) {
-					num_components = (num_components * 2) - 4;
-					component = 0;
-				} else {
-					num_components = MIN2(num_components * 2, 4);
-				}
-			}
+			unsigned num_components;
+			unsigned component;
+			get_num_of_component_info(variable, k, &num_components, &component);
 
 			ubyte usagemask = get_component_usagemask(component, num_components);
 
-- 
2.20.1



More information about the mesa-dev mailing list