summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRhys Perry <pendingchaos02@gmail.com>2021-01-13 15:50:52 +0000
committerMarge Bot <eric+marge@anholt.net>2021-06-21 15:13:05 +0000
commitea68d4a676260d9c45dfbe0cb8de8e40869b5523 (patch)
tree49afcbe4060c74c269cbefa2e275f973ce7d6a5e
parent7144f338025e1f4db4d01cf79e1d9bda218fea0d (diff)
nir/propagate_invariant: add invariant_prim option
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11035>
-rw-r--r--src/amd/vulkan/radv_shader.c30
-rw-r--r--src/broadcom/vulkan/v3dv_pipeline.c2
-rw-r--r--src/compiler/nir/nir.h2
-rw-r--r--src/compiler/nir/nir_propagate_invariant.c26
-rw-r--r--src/freedreno/vulkan/tu_shader.c2
-rw-r--r--src/intel/vulkan/anv_pipeline.c2
6 files changed, 31 insertions, 33 deletions
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index f6f0fc27a03..2355e55545b 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -241,28 +241,6 @@ radv_compiler_debug(void *private_data, enum radv_compiler_debug_level level, co
&debug_data->module->base, 0, 0, "radv", message);
}
-static void
-mark_geom_invariant(nir_shader *nir)
-{
- nir_foreach_shader_out_variable(var, nir)
- {
- switch (var->data.location) {
- case VARYING_SLOT_POS:
- case VARYING_SLOT_PSIZ:
- case VARYING_SLOT_CLIP_DIST0:
- case VARYING_SLOT_CLIP_DIST1:
- case VARYING_SLOT_CULL_DIST0:
- case VARYING_SLOT_CULL_DIST1:
- case VARYING_SLOT_TESS_LEVEL_OUTER:
- case VARYING_SLOT_TESS_LEVEL_INNER:
- var->data.invariant = true;
- break;
- default:
- break;
- }
- }
-}
-
static nir_ssa_def *
convert_pointer_to_64(nir_builder *b, const struct radv_physical_device *pdev, nir_ssa_def *ptr)
{
@@ -560,12 +538,8 @@ radv_shader_compile_to_nir(struct radv_device *device, struct vk_shader_module *
NIR_PASS_V(nir, nir_lower_global_vars_to_local);
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
- if (device->instance->debug_flags & RADV_DEBUG_INVARIANT_GEOM &&
- stage != MESA_SHADER_FRAGMENT) {
- mark_geom_invariant(nir);
- }
-
- NIR_PASS_V(nir, nir_propagate_invariant);
+ NIR_PASS_V(nir, nir_propagate_invariant,
+ device->instance->debug_flags & RADV_DEBUG_INVARIANT_GEOM);
NIR_PASS_V(nir, nir_lower_system_values);
NIR_PASS_V(nir, nir_lower_compute_system_values, NULL);
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c
index 96ac00ccdf9..621c62e8f34 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -362,7 +362,7 @@ preprocess_nir(nir_shader *nir,
nir_var_shader_out | nir_var_system_value | nir_var_mem_shared,
NULL);
- NIR_PASS_V(nir, nir_propagate_invariant);
+ NIR_PASS_V(nir, nir_propagate_invariant, false);
NIR_PASS_V(nir, nir_lower_io_to_temporaries,
nir_shader_get_entrypoint(nir), true, false);
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 47a88fdb6d3..66aad033447 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4317,7 +4317,7 @@ void nir_inline_uniforms(nir_shader *shader, unsigned num_uniforms,
const uint32_t *uniform_values,
const uint16_t *uniform_dw_offsets);
-bool nir_propagate_invariant(nir_shader *shader);
+bool nir_propagate_invariant(nir_shader *shader, bool invariant_prim);
void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, nir_shader *shader);
void nir_lower_deref_copy_instr(struct nir_builder *b,
diff --git a/src/compiler/nir/nir_propagate_invariant.c b/src/compiler/nir/nir_propagate_invariant.c
index afe0098158b..c5664bf701b 100644
--- a/src/compiler/nir/nir_propagate_invariant.c
+++ b/src/compiler/nir/nir_propagate_invariant.c
@@ -188,12 +188,36 @@ propagate_invariant_impl(nir_function_impl *impl, struct set *invariants)
return progress;
}
+/* If invariant_prim=true, this pass considers all geometry-affecting
+ * outputs as invariant. Doing this works around a common class of application
+ * bugs appearing as flickering.
+ */
bool
-nir_propagate_invariant(nir_shader *shader)
+nir_propagate_invariant(nir_shader *shader, bool invariant_prim)
{
/* Hash set of invariant things */
struct set *invariants = _mesa_pointer_set_create(NULL);
+ if (shader->info.stage != MESA_SHADER_FRAGMENT && invariant_prim) {
+ nir_foreach_shader_out_variable(var, shader) {
+ switch (var->data.location) {
+ case VARYING_SLOT_POS:
+ case VARYING_SLOT_PSIZ:
+ case VARYING_SLOT_CLIP_DIST0:
+ case VARYING_SLOT_CLIP_DIST1:
+ case VARYING_SLOT_CULL_DIST0:
+ case VARYING_SLOT_CULL_DIST1:
+ case VARYING_SLOT_TESS_LEVEL_OUTER:
+ case VARYING_SLOT_TESS_LEVEL_INNER:
+ if (!var->data.invariant)
+ _mesa_set_add(invariants, var);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
bool progress = false;
nir_foreach_function(function, shader) {
if (function->impl && propagate_invariant_impl(function->impl, invariants))
diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c
index 967bd4357f3..cfd110e0531 100644
--- a/src/freedreno/vulkan/tu_shader.c
+++ b/src/freedreno/vulkan/tu_shader.c
@@ -168,7 +168,7 @@ tu_spirv_to_nir(struct tu_device *dev,
nir_var_shader_in | nir_var_shader_out | nir_var_system_value | nir_var_mem_shared,
NULL);
- NIR_PASS_V(nir, nir_propagate_invariant);
+ NIR_PASS_V(nir, nir_propagate_invariant, false);
NIR_PASS_V(nir, nir_lower_global_vars_to_local);
NIR_PASS_V(nir, nir_split_var_copies);
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 35d90f77ee2..663be210793 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -248,7 +248,7 @@ anv_shader_compile_to_nir(struct anv_device *device,
nir_var_shader_in | nir_var_shader_out | nir_var_system_value,
NULL);
- NIR_PASS_V(nir, nir_propagate_invariant);
+ NIR_PASS_V(nir, nir_propagate_invariant, false);
NIR_PASS_V(nir, nir_lower_io_to_temporaries,
nir_shader_get_entrypoint(nir), true, false);