midgard_block *last = list_last_entry(&ctx->blocks,
struct midgard_block, link);
- /* The last block must be empty (the exit block) */
- assert(list_empty(&last->instructions));
+ /* The last block must be empty logically but contains branch writeout
+ * for fragment shaders */
+
assert(last->nr_successors == 0);
return last;
midgard_opt_promote_fmov(ctx, ctx->current_block);
embedded_to_inline_constant(ctx);
- /* Append fragment shader epilogue (value writeout) */
- if (ctx->stage == MESA_SHADER_FRAGMENT) {
- if (block == nir_impl_last_block(ctx->func->impl)) {
- emit_fragment_epilogue(ctx);
- }
- }
-
/* Allow the next control flow to access us retroactively, for
* branching etc */
ctx->current_block = this_block;
struct midgard_block *end =
emit_block(ctx, func->impl->end_block);
+ if (ctx->stage == MESA_SHADER_FRAGMENT)
+ emit_fragment_epilogue(ctx);
+
midgard_block_add_successor(semi_end, end);
break; /* TODO: Multi-function shaders */