radv: gather more info about push constants
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 5 Feb 2019 19:21:58 +0000 (20:21 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 12 Feb 2019 16:25:34 +0000 (17:25 +0100)
This is needed in order to inline some push constants when possible.
This also adds a new helper for initializing the pass.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_nir_to_llvm.c
src/amd/vulkan/radv_private.h
src/amd/vulkan/radv_shader.h
src/amd/vulkan/radv_shader_info.c

index 7f74678d5f1ffde97f3fdb9dd0f100d20badbe74..dbeae2aafde3b0eb2cb4584ebab7c8a68c157412 100644 (file)
@@ -3439,6 +3439,8 @@ LLVMModuleRef ac_translate_nir_to_llvm(struct ac_llvm_compiler *ac_llvm,
 
        memset(shader_info, 0, sizeof(*shader_info));
 
+       radv_nir_shader_info_init(&shader_info->info);
+
        for(int i = 0; i < shader_count; ++i)
                radv_nir_shader_info_pass(shaders[i], options, &shader_info->info);
 
index d4a9e9f0e9553f004e4db13320d9ab067d0938fc..1e38a12a2a77603aa098028a67074f7b1c7de393 100644 (file)
@@ -1951,6 +1951,8 @@ void radv_nir_shader_info_pass(const struct nir_shader *nir,
                               const struct radv_nir_compiler_options *options,
                               struct radv_shader_info *info);
 
+void radv_nir_shader_info_init(struct radv_shader_info *info);
+
 struct radeon_winsys_sem;
 
 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType)                \
index b67cd2b4f158ddedd9e47dccd6abda12ec0d2dad..92886188459e16a17758484ab0fc218b9cabe977 100644 (file)
@@ -162,6 +162,10 @@ struct radv_streamout_info {
 
 struct radv_shader_info {
        bool loads_push_constants;
+       uint8_t min_push_constant_used;
+       uint8_t max_push_constant_used;
+       bool has_only_32bit_push_constants;
+       bool has_indirect_push_constants;
        uint32_t desc_set_used_mask;
        bool needs_multiview_view_index;
        bool uses_invocation_id;
index e17b0e54e6903044d2261d8090600680ea2ecb54..bece7b20f024aa891b8cee2fb1507060ae1dde77 100644 (file)
@@ -190,6 +190,33 @@ gather_intrinsic_store_deref_info(const nir_shader *nir,
        }
 }
 
+static void
+gather_push_constant_info(const nir_shader *nir,
+                         const nir_intrinsic_instr *instr,
+                         struct radv_shader_info *info)
+{
+       nir_const_value *cval = nir_src_as_const_value(instr->src[0]);
+       int base = nir_intrinsic_base(instr);
+       int range = nir_intrinsic_range(instr);
+
+       if (!cval) {
+               info->has_indirect_push_constants = true;
+       } else {
+               uint32_t min = base + cval->u32[0];
+               uint32_t max = min + instr->num_components * 4;
+
+               info->max_push_constant_used =
+                       MAX2(max, info->max_push_constant_used);
+               info->min_push_constant_used =
+                       MIN2(min, info->min_push_constant_used);
+       }
+
+       if (instr->dest.ssa.bit_size != 32)
+               info->has_only_32bit_push_constants = false;
+
+       info->loads_push_constants = true;
+}
+
 static void
 gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
                      struct radv_shader_info *info)
@@ -243,7 +270,7 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
                info->uses_prim_id = true;
                break;
        case nir_intrinsic_load_push_constant:
-               info->loads_push_constants = true;
+               gather_push_constant_info(nir, instr, info);
                break;
        case nir_intrinsic_vulkan_resource_index:
                info->desc_set_used_mask |= (1 << nir_intrinsic_desc_set(instr));
@@ -504,6 +531,14 @@ gather_xfb_info(const nir_shader *nir, struct radv_shader_info *info)
        ralloc_free(xfb);
 }
 
+void
+radv_nir_shader_info_init(struct radv_shader_info *info)
+{
+       /* Assume that shaders only have 32-bit push constants by default. */
+       info->min_push_constant_used = UINT8_MAX;
+       info->has_only_32bit_push_constants = true;
+}
+
 void
 radv_nir_shader_info_pass(const struct nir_shader *nir,
                          const struct radv_nir_compiler_options *options,