Skip to content

Commit

Permalink
[spirv] Account for unreachable continue blocks
Browse files Browse the repository at this point in the history
Fixes code gen in the following pattern encountered in Black Ops 3:

loop
  break
endloop

We cannot eliminate the loop since we have to adhere to structured
control flow rules, which might be broken if the code inside the
loop was non-trivial.
  • Loading branch information
doitsujin committed Sep 4, 2024
1 parent 427e706 commit d0ea5a4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/spirv/spirv_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3973,9 +3973,18 @@ namespace dxvk {
branches.insert({ blockId, ins.arg(i) });
} break;

case spv::OpSelectionMerge:
case spv::OpSelectionMerge: {
mergeBlocks.insert(ins.arg(1));
} break;

case spv::OpLoopMerge: {
mergeBlocks.insert(ins.arg(1));

// It is possible for the continue block to be unreachable in
// practice, but we still need to emit it if we are not going
// to eliminate this loop. Since the current block dominates
// the loop, use it to keep the continue block intact.
branches.insert({ blockId, ins.arg(2) });
} break;

default:;
Expand Down

0 comments on commit d0ea5a4

Please sign in to comment.