This will be reused in a following patch.
---
 src/gallium/drivers/radeonsi/si_shader_nir.c | 46 ++++++++++++--------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c 
b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 7554f5b9f8b..5abda445e09 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -51,6 +51,32 @@ static nir_variable* intrinsic_get_var(nir_intrinsic_instr 
*instr)
        return nir_deref_instr_get_variable(nir_src_as_deref(instr->src[0]));
 }
 
+static ubyte get_component_usagemask(unsigned first_comp,
+                                    unsigned num_components)
+{
+       ubyte usagemask = 0;
+       for (unsigned i = first_comp; i < num_components + first_comp; i++) {
+               switch (i) {
+               case 0:
+                       usagemask |= TGSI_WRITEMASK_X;
+                       break;
+               case 1:
+                       usagemask |= TGSI_WRITEMASK_Y;
+                       break;
+               case 2:
+                       usagemask |= TGSI_WRITEMASK_Z;
+                       break;
+               case 3:
+                       usagemask |= TGSI_WRITEMASK_W;
+                       break;
+               default:
+                       unreachable("error calculating component index");
+               }
+       }
+
+       return usagemask;
+}
+
 static void scan_instruction(struct tgsi_shader_info *info,
                             nir_instr *instr)
 {
@@ -527,25 +553,7 @@ void si_nir_scan_shader(const struct nir_shader *nir,
                                }
                        }
 
-                       ubyte usagemask = 0;
-                       for (unsigned j = component; j < num_components + 
component; j++) {
-                               switch (j) {
-                               case 0:
-                                       usagemask |= TGSI_WRITEMASK_X;
-                                       break;
-                               case 1:
-                                       usagemask |= TGSI_WRITEMASK_Y;
-                                       break;
-                               case 2:
-                                       usagemask |= TGSI_WRITEMASK_Z;
-                                       break;
-                               case 3:
-                                       usagemask |= TGSI_WRITEMASK_W;
-                                       break;
-                               default:
-                                       unreachable("error calculating 
component index");
-                               }
-                       }
+                       ubyte usagemask = get_component_usagemask(component, 
num_components);
 
                        unsigned gs_out_streams;
                        if (variable->data.stream & (1u << 31)) {
-- 
2.20.1

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to