diff --git a/src/amd/compiler/aco_insert_waitcnt.cpp b/src/amd/compiler/aco_insert_waitcnt.cpp index 71d073965f8..6e292a9bb72 100644 --- a/src/amd/compiler/aco_insert_waitcnt.cpp +++ b/src/amd/compiler/aco_insert_waitcnt.cpp @@ -1082,6 +1082,12 @@ handle_block(Program* program, Block& block, wait_ctx& ctx) } } + /* For last block of a program which has succeed shader part, wait all memory ops done + * before go to next shader part. + */ + if (block.kind & block_kind_end_with_regs) + force_waitcnt(ctx, queued_imm); + if (!queued_imm.empty()) emit_waitcnt(ctx, new_instructions, queued_imm); if (!queued_delay.empty()) @@ -1153,11 +1159,6 @@ insert_wait_states(Program* program) in_ctx[current.index] = ctx; } - if (current.instructions.empty()) { - out_ctx[current.index] = std::move(ctx); - continue; - } - loop_progress = std::max(loop_progress, current.loop_nest_depth); done[current.index] = true; diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp index 480ea19dd58..edadca72bb9 100644 --- a/src/amd/compiler/aco_lower_to_hw_instr.cpp +++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp @@ -3065,6 +3065,12 @@ lower_to_hw_instr(Program* program) Builder bld(program, end_with_regs_block); bld.sopp(aco_opcode::s_branch, exit_block->index); + + /* For insert waitcnt pass to add waitcnt in exit block, otherwise waitcnt will be added + * after the s_branch which won't be executed. + */ + end_with_regs_block->kind &= ~block_kind_end_with_regs; + exit_block->kind |= block_kind_end_with_regs; } }