summaryrefslogtreecommitdiff
path: root/src/panfrost/midgard
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>2020-11-04 08:37:55 -0500
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>2020-11-04 11:21:28 -0500
commit42319c562642100a2c5d07dd8522f63e6ea6f0fb (patch)
tree58d03741368a3d5feba9ffd2015dff3e17620733 /src/panfrost/midgard
parentdfaa4c51fbab842ad280a199e5bce87a2bcc2fcd (diff)
pan/mdg: Move writeout lowering to common panfrost
These will be used in the Bifrost compiler, albeit for a slightly different purpose. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7446>
Diffstat (limited to 'src/panfrost/midgard')
-rw-r--r--src/panfrost/midgard/compiler.h4
-rw-r--r--src/panfrost/midgard/midgard_compile.c229
2 files changed, 2 insertions, 231 deletions
diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 74a3532ab3c..03f463a4646 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -71,10 +71,6 @@ typedef struct midgard_branch {
};
} midgard_branch;
-#define PAN_WRITEOUT_C 1
-#define PAN_WRITEOUT_Z 2
-#define PAN_WRITEOUT_S 4
-
/* Generic in-memory data type repesenting a single logical instruction, rather
* than a single instruction group. This is the preferred form for code gen.
* Multiple midgard_insturctions will later be combined during scheduling,
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index 8c64151fb91..4c1fd438a23 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -210,231 +210,6 @@ midgard_nir_lower_fdot2(nir_shader *shader)
NULL);
}
-/* Midgard can write all of color, depth and stencil in a single writeout
- * operation, so we merge depth/stencil stores with color stores.
- * If there are no color stores, we add a write to the "depth RT".
- */
-static bool
-midgard_nir_lower_zs_store(nir_shader *nir)
-{
- if (nir->info.stage != MESA_SHADER_FRAGMENT)
- return false;
-
- nir_variable *z_var = NULL, *s_var = NULL;
-
- nir_foreach_shader_out_variable(var, nir) {
- if (var->data.location == FRAG_RESULT_DEPTH)
- z_var = var;
- else if (var->data.location == FRAG_RESULT_STENCIL)
- s_var = var;
- }
-
- if (!z_var && !s_var)
- return false;
-
- bool progress = false;
-
- nir_foreach_function(function, nir) {
- if (!function->impl) continue;
-
- nir_intrinsic_instr *z_store = NULL, *s_store = NULL;
-
- nir_foreach_block(block, function->impl) {
- nir_foreach_instr_safe(instr, block) {
- if (instr->type != nir_instr_type_intrinsic)
- continue;
-
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- if (intr->intrinsic != nir_intrinsic_store_output)
- continue;
-
- if (z_var && nir_intrinsic_base(intr) == z_var->data.driver_location) {
- assert(!z_store);
- z_store = intr;
- }
-
- if (s_var && nir_intrinsic_base(intr) == s_var->data.driver_location) {
- assert(!s_store);
- s_store = intr;
- }
- }
- }
-
- if (!z_store && !s_store) continue;
-
- bool replaced = false;
-
- nir_foreach_block(block, function->impl) {
- nir_foreach_instr_safe(instr, block) {
- if (instr->type != nir_instr_type_intrinsic)
- continue;
-
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- if (intr->intrinsic != nir_intrinsic_store_output)
- continue;
-
- const nir_variable *var = nir_find_variable_with_driver_location(nir, nir_var_shader_out, nir_intrinsic_base(intr));
- assert(var);
-
- if (var->data.location != FRAG_RESULT_COLOR &&
- var->data.location < FRAG_RESULT_DATA0)
- continue;
-
- if (var->data.index)
- continue;
-
- assert(nir_src_is_const(intr->src[1]) && "no indirect outputs");
-
- nir_builder b;
- nir_builder_init(&b, function->impl);
-
- assert(!z_store || z_store->instr.block == instr->block);
- assert(!s_store || s_store->instr.block == instr->block);
- b.cursor = nir_after_block_before_jump(instr->block);
-
- nir_intrinsic_instr *combined_store;
- combined_store = nir_intrinsic_instr_create(b.shader, nir_intrinsic_store_combined_output_pan);
-
- combined_store->num_components = intr->src[0].ssa->num_components;
-
- nir_intrinsic_set_base(combined_store, nir_intrinsic_base(intr));
-
- unsigned writeout = PAN_WRITEOUT_C;
- if (z_store)
- writeout |= PAN_WRITEOUT_Z;
- if (s_store)
- writeout |= PAN_WRITEOUT_S;
-
- nir_intrinsic_set_component(combined_store, writeout);
-
- struct nir_ssa_def *zero = nir_imm_int(&b, 0);
-
- struct nir_ssa_def *src[4] = {
- intr->src[0].ssa,
- intr->src[1].ssa,
- z_store ? z_store->src[0].ssa : zero,
- s_store ? s_store->src[0].ssa : zero,
- };
-
- for (int i = 0; i < 4; ++i)
- combined_store->src[i] = nir_src_for_ssa(src[i]);
-
- nir_builder_instr_insert(&b, &combined_store->instr);
-
- nir_instr_remove(instr);
-
- replaced = true;
- }
- }
-
- /* Insert a store to the depth RT (0xff) if needed */
- if (!replaced) {
- nir_builder b;
- nir_builder_init(&b, function->impl);
-
- nir_block *block = NULL;
- if (z_store && s_store)
- assert(z_store->instr.block == s_store->instr.block);
-
- if (z_store)
- block = z_store->instr.block;
- else
- block = s_store->instr.block;
-
- b.cursor = nir_after_block_before_jump(block);
-
- nir_intrinsic_instr *combined_store;
- combined_store = nir_intrinsic_instr_create(b.shader, nir_intrinsic_store_combined_output_pan);
-
- combined_store->num_components = 4;
-
- unsigned base;
- if (z_store)
- base = nir_intrinsic_base(z_store);
- else
- base = nir_intrinsic_base(s_store);
- nir_intrinsic_set_base(combined_store, base);
-
- unsigned writeout = 0;
- if (z_store)
- writeout |= PAN_WRITEOUT_Z;
- if (s_store)
- writeout |= PAN_WRITEOUT_S;
-
- nir_intrinsic_set_component(combined_store, writeout);
-
- struct nir_ssa_def *zero = nir_imm_int(&b, 0);
-
- struct nir_ssa_def *src[4] = {
- nir_imm_vec4(&b, 0, 0, 0, 0),
- zero,
- z_store ? z_store->src[0].ssa : zero,
- s_store ? s_store->src[0].ssa : zero,
- };
-
- for (int i = 0; i < 4; ++i)
- combined_store->src[i] = nir_src_for_ssa(src[i]);
-
- nir_builder_instr_insert(&b, &combined_store->instr);
- }
-
- if (z_store)
- nir_instr_remove(&z_store->instr);
-
- if (s_store)
- nir_instr_remove(&s_store->instr);
-
- nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);
- progress = true;
- }
-
- return progress;
-}
-
-/* Real writeout stores, which break execution, need to be moved to after
- * dual-source stores, which are just standard register writes. */
-static bool
-midgard_nir_reorder_writeout(nir_shader *nir)
-{
- bool progress = false;
-
- nir_foreach_function(function, nir) {
- if (!function->impl) continue;
-
- nir_foreach_block(block, function->impl) {
- nir_instr *last_writeout = NULL;
-
- nir_foreach_instr_reverse_safe(instr, block) {
- if (instr->type != nir_instr_type_intrinsic)
- continue;
-
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- if (intr->intrinsic != nir_intrinsic_store_output)
- continue;
-
- const nir_variable *var = nir_find_variable_with_driver_location(nir, nir_var_shader_out, nir_intrinsic_base(intr));
-
- if (var->data.index) {
- if (!last_writeout)
- last_writeout = instr;
- continue;
- }
-
- if (!last_writeout)
- continue;
-
- /* This is a real store, so move it to after dual-source stores */
- exec_node_remove(&instr->node);
- exec_node_insert_after(&last_writeout->node, &instr->node);
-
- progress = true;
- }
- }
- }
-
- return progress;
-}
-
static bool
mdg_is_64(const nir_instr *instr, const void *_unused)
{
@@ -2988,13 +2763,13 @@ midgard_compile_shader_nir(void *mem_ctx, nir_shader *nir,
NIR_PASS_V(nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
glsl_type_size, 0);
NIR_PASS_V(nir, nir_lower_ssbo);
- NIR_PASS_V(nir, midgard_nir_lower_zs_store);
+ NIR_PASS_V(nir, pan_nir_lower_zs_store);
/* Optimisation passes */
optimise_nir(nir, ctx->quirks, inputs->is_blend);
- NIR_PASS_V(nir, midgard_nir_reorder_writeout);
+ NIR_PASS_V(nir, pan_nir_reorder_writeout);
if ((midgard_debug & MIDGARD_DBG_SHADERS) && !nir->info.internal) {
nir_print_shader(nir, stdout);