diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index ad89aaad5..f85e5e001 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -849,7 +849,8 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout if (scalar_branch && outer.contains_child) refuse(*scalar_branch,"mesh scalar branch crosses a nested SAVEEXEC region"); }; - struct Skip { unsigned start,end; Edge entry; bool per_lane; string guard, wave_guard; }; + // narrowed_from: the parent skip's guard, when this per-lane skip opened right after one CMPX narrowed it. + struct Skip { unsigned start,end; Edge entry; bool per_lane; string guard, wave_guard, narrowed_from{}; }; std::vector skip_parents; std::optional exec_skip; alu.check_graphics_read=[&](unsigned reg,const string &value) { @@ -1040,6 +1041,8 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout }; std::optional pending_saveexec_restore; unsigned pc = 0; + string last_name, carried_lane; // the last fully lowered instruction; a lane set carried to a parent skip close + unsigned last_end=~0u; while (pc < code.size()) { // All handled scalar branches are forward, so every predecessor is // available when we reach its target. Funnel arbitrary fan-in into @@ -1053,6 +1056,7 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout diamond_joined=false; // another path arrives between the join and the restore if (live) ir.body<<" br label %"<guard); - const bool retain=skip_parents.empty() && exec_skip->guard==lane_active && + // A nested skip that closed at this same instruction (see Skip::narrowed_from) leaves its + // narrowed mask in lane_active, but every register is exact again for the guard's lanes. + const bool guard_lanes=exec_skip->guard==lane_active || + (!carried_lane.empty() && carried_lane==exec_skip->guard); + carried_lane.clear(); + const bool retain=skip_parents.empty() && guard_lanes && !branch && forward.empty() && limit!=lane_limits.end(); merge_edges(exec_skip->entry,"mesh_empty"+tag,"mesh_done"+tag,retain ? limit->second : string{}); + const auto narrowed_from=exec_skip->per_lane && exec_skip->guard==lane_active ? + exec_skip->narrowed_from : string{}; exec_skip.reset(); if (!skip_parents.empty()) { exec_skip=std::move(skip_parents.back());skip_parents.pop_back(); - if (pc==exec_skip->end) return true; + if (pc==exec_skip->end) { carried_lane=narrowed_from; return true; } closed_nested_skip=true; } return false; @@ -1693,11 +1704,19 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout full_exec=false; wave_active.clear(); exec_value[0].clear();exec_value[1].clear(); } else if (i.name=="s_cbranch_execz" && !full_exec && !lane_active.empty() && !branch && i.target()>i.next && i.target()second==exec_skip->guard) narrowed_from=parent->second; + } if (exec_skip) { if (i.target()>exec_skip->end) refuse(pc,"overlapping mesh EXECZ exits"); skip_parents.push_back(std::move(*exec_skip)); } - exec_skip=Skip{pc,i.target(),save_edge(),wave_active.empty(),lane_active,wave_active}; + exec_skip=Skip{pc,i.target(),save_edge(),wave_active.empty(),lane_active,wave_active,narrowed_from}; ir.body<<" br i1 "<<(wave_active.empty() ? lane_active : wave_active)<<", label %mesh_work"<