[Mesa-dev] [PATCH 1/2] ac/shader: gather more push constant info
Dave Airlie
airlied at gmail.com
Thu Jan 11 03:03:34 UTC 2018
From: Dave Airlie <airlied at redhat.com>
This gathers the min/max push consts used, and whether
the shader uses indirect push constants.
It also adds an init function to handle the combined
shaders.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/amd/common/ac_nir_to_llvm.c | 2 ++
src/amd/common/ac_shader_info.c | 25 ++++++++++++++++++++++++-
src/amd/common/ac_shader_info.h | 7 ++++++-
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 5885c70ef8..c00220a9c3 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -6649,6 +6649,8 @@ LLVMModuleRef ac_translate_nir_to_llvm(LLVMTargetMachineRef tm,
memset(shader_info, 0, sizeof(*shader_info));
+ ac_nir_shader_info_init(&shader_info->info);
+
for(int i = 0; i < shader_count; ++i)
ac_nir_shader_info_pass(shaders[i], options, &shader_info->info);
diff --git a/src/amd/common/ac_shader_info.c b/src/amd/common/ac_shader_info.c
index 443980c7d1..18fa9e1c94 100644
--- a/src/amd/common/ac_shader_info.c
+++ b/src/amd/common/ac_shader_info.c
@@ -29,6 +29,22 @@ static void mark_sampler_desc(nir_variable *var, struct ac_shader_info *info)
info->desc_set_used_mask = (1 << var->data.descriptor_set);
}
+static void
+gather_push_constant_info(nir_intrinsic_instr *instr, struct ac_shader_info *info)
+{
+ nir_const_value *cval = nir_src_as_const_value(instr->src[0]);
+ info->has_indirect_push_constants |= cval ? false : true;
+
+ int base = nir_intrinsic_base(instr);
+ int range = nir_intrinsic_range(instr);
+ if (base + range > info->max_push_constant_used)
+ info->max_push_constant_used = base + range;
+ if (base < info->min_push_constant_used)
+ info->min_push_constant_used = base;
+
+ info->loads_push_constants = true;
+}
+
static void
gather_intrinsic_info(nir_intrinsic_instr *instr, struct ac_shader_info *info)
{
@@ -77,7 +93,7 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, struct ac_shader_info *info)
info->uses_prim_id = true;
break;
case nir_intrinsic_load_push_constant:
- info->loads_push_constants = true;
+ gather_push_constant_info(instr, info);
break;
case nir_intrinsic_vulkan_resource_index:
info->desc_set_used_mask |= (1 << nir_intrinsic_desc_set(instr));
@@ -150,6 +166,12 @@ gather_info_input_decl(nir_shader *nir,
}
}
+void
+ac_nir_shader_info_init(struct ac_shader_info *info)
+{
+ info->min_push_constant_used = -1;
+}
+
void
ac_nir_shader_info_pass(struct nir_shader *nir,
const struct ac_nir_compiler_options *options,
@@ -157,6 +179,7 @@ ac_nir_shader_info_pass(struct nir_shader *nir,
{
struct nir_function *func = (struct nir_function *)exec_list_get_head(&nir->functions);
+
if (options->layout->dynamic_offset_count)
info->loads_push_constants = true;
diff --git a/src/amd/common/ac_shader_info.h b/src/amd/common/ac_shader_info.h
index 9c9a8473a4..e35cde0ca9 100644
--- a/src/amd/common/ac_shader_info.h
+++ b/src/amd/common/ac_shader_info.h
@@ -28,8 +28,11 @@ struct nir_shader;
struct ac_nir_compiler_options;
struct ac_shader_info {
- bool loads_push_constants;
uint32_t desc_set_used_mask;
+ uint8_t min_push_constant_used;
+ uint8_t max_push_constant_used;
+ bool has_indirect_push_constants;
+ bool loads_push_constants;
bool needs_multiview_view_index;
bool uses_invocation_id;
bool uses_prim_id;
@@ -59,4 +62,6 @@ ac_nir_shader_info_pass(struct nir_shader *nir,
const struct ac_nir_compiler_options *options,
struct ac_shader_info *info);
+void
+ac_nir_shader_info_init(struct ac_shader_info *info);
#endif
--
2.14.3
More information about the mesa-dev
mailing list