radv: add set_output_usage_mask() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 30 Aug 2018 07:35:41 +0000 (09:35 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 31 Aug 2018 15:34:41 +0000 (17:34 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_shader_info.c

index a45c847c46c0b5d5e19bab42afb9c622d477135b..5925fd924c8bdd624e8b23a7a03e17bb63c74d73 100644 (file)
@@ -114,6 +114,26 @@ gather_intrinsic_load_deref_info(const nir_shader *nir,
        }
 }
 
+static void
+set_output_usage_mask(const nir_shader *nir, const nir_intrinsic_instr *instr,
+                     uint8_t *output_usage_mask)
+{
+       nir_deref_instr *deref_instr =
+               nir_instr_as_deref(instr->src[0].ssa->parent_instr);
+       nir_variable *var = nir_deref_instr_get_variable(deref_instr);
+       unsigned attrib_count = glsl_count_attribute_slots(var->type, false);
+       unsigned idx = var->data.location;
+       unsigned comp = var->data.location_frac;
+       unsigned const_offset = 0;
+
+       get_deref_offset(deref_instr, &const_offset);
+
+       for (unsigned i = 0; i < attrib_count; i++) {
+               output_usage_mask[idx + i + const_offset] |=
+                       instr->const_index[0] << comp;
+       }
+}
+
 static void
 gather_intrinsic_store_deref_info(const nir_shader *nir,
                                const nir_intrinsic_instr *instr,
@@ -122,31 +142,20 @@ gather_intrinsic_store_deref_info(const nir_shader *nir,
        nir_variable *var = nir_deref_instr_get_variable(nir_instr_as_deref(instr->src[0].ssa->parent_instr));
 
        if (var->data.mode == nir_var_shader_out) {
-               unsigned attrib_count = glsl_count_attribute_slots(var->type, false);
                unsigned idx = var->data.location;
-               unsigned comp = var->data.location_frac;
-               unsigned const_offset = 0;
-
-               get_deref_offset(nir_instr_as_deref(instr->src[0].ssa->parent_instr), &const_offset);
 
                switch (nir->info.stage) {
                case MESA_SHADER_VERTEX:
-                       for (unsigned i = 0; i < attrib_count; i++) {
-                               info->vs.output_usage_mask[idx + i + const_offset] |=
-                                       instr->const_index[0] << comp;
-                       }
+                       set_output_usage_mask(nir, instr,
+                                             info->vs.output_usage_mask);
                        break;
                case MESA_SHADER_GEOMETRY:
-                       for (unsigned i = 0; i < attrib_count; i++) {
-                               info->gs.output_usage_mask[idx + i + const_offset] |=
-                                       instr->const_index[0] << comp;
-                       }
+                       set_output_usage_mask(nir, instr,
+                                             info->gs.output_usage_mask);
                        break;
                case MESA_SHADER_TESS_EVAL:
-                       for (unsigned i = 0; i < attrib_count; i++) {
-                               info->tes.output_usage_mask[idx + i + const_offset] |=
-                                       instr->const_index[0] << comp;
-                       }
+                       set_output_usage_mask(nir, instr,
+                                             info->tes.output_usage_mask);
                        break;
                case MESA_SHADER_TESS_CTRL: {
                        unsigned param = shader_io_get_unique_index(idx);