diff options
| author | 2021-02-24 05:21:30 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:22 -0400 | |
| commit | e87a502da2d5a8356a639d53c0a16a77890de4c7 (patch) | |
| tree | 00fd1a9a32c0334c49189098829b782a37533c46 /src/shader_recompiler/frontend/ir/structured_control_flow.cpp | |
| parent | shader: Implement more of XMAD and FFMA32I and fix XMAD.CBCC (diff) | |
| download | yuzu-e87a502da2d5a8356a639d53c0a16a77890de4c7.tar.gz yuzu-e87a502da2d5a8356a639d53c0a16a77890de4c7.tar.xz yuzu-e87a502da2d5a8356a639d53c0a16a77890de4c7.zip | |
shader: Fix control flow
Diffstat (limited to 'src/shader_recompiler/frontend/ir/structured_control_flow.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/structured_control_flow.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/shader_recompiler/frontend/ir/structured_control_flow.cpp b/src/shader_recompiler/frontend/ir/structured_control_flow.cpp index 032ac8fda..bfba55a7e 100644 --- a/src/shader_recompiler/frontend/ir/structured_control_flow.cpp +++ b/src/shader_recompiler/frontend/ir/structured_control_flow.cpp | |||
| @@ -329,7 +329,6 @@ private: | |||
| 329 | if (!sibling) { | 329 | if (!sibling) { |
| 330 | throw LogicError("Not siblings"); | 330 | throw LogicError("Not siblings"); |
| 331 | } | 331 | } |
| 332 | |||
| 333 | // goto_stmt and label_stmt are guaranteed to be siblings, eliminate | 332 | // goto_stmt and label_stmt are guaranteed to be siblings, eliminate |
| 334 | if (std::next(goto_stmt) == label_stmt) { | 333 | if (std::next(goto_stmt) == label_stmt) { |
| 335 | // Simply eliminate the goto if the label is next to it | 334 | // Simply eliminate the goto if the label is next to it |
| @@ -351,9 +350,14 @@ private: | |||
| 351 | const std::unordered_map labels_map{BuildLabels(blocks)}; | 350 | const std::unordered_map labels_map{BuildLabels(blocks)}; |
| 352 | Tree& root{root_stmt.children}; | 351 | Tree& root{root_stmt.children}; |
| 353 | auto insert_point{root.begin()}; | 352 | auto insert_point{root.begin()}; |
| 353 | // Skip all goto variables zero-initialization | ||
| 354 | std::advance(insert_point, labels_map.size()); | ||
| 355 | |||
| 354 | for (Block* const block : blocks) { | 356 | for (Block* const block : blocks) { |
| 355 | ++insert_point; // Skip label | 357 | // Skip label |
| 356 | ++insert_point; // Skip set variable | 358 | ++insert_point; |
| 359 | // Skip set variable | ||
| 360 | ++insert_point; | ||
| 357 | root.insert(insert_point, *pool.Create(block, &root_stmt)); | 361 | root.insert(insert_point, *pool.Create(block, &root_stmt)); |
| 358 | 362 | ||
| 359 | if (block->IsTerminationBlock()) { | 363 | if (block->IsTerminationBlock()) { |
| @@ -391,6 +395,7 @@ private: | |||
| 391 | labels_map.emplace(block, root.insert(root.end(), *label)); | 395 | labels_map.emplace(block, root.insert(root.end(), *label)); |
| 392 | Statement* const false_stmt{pool.Create(Identity{}, Condition{false})}; | 396 | Statement* const false_stmt{pool.Create(Identity{}, Condition{false})}; |
| 393 | root.push_back(*pool.Create(SetVariable{}, label_id, false_stmt, &root_stmt)); | 397 | root.push_back(*pool.Create(SetVariable{}, label_id, false_stmt, &root_stmt)); |
| 398 | root.push_front(*pool.Create(SetVariable{}, label_id, false_stmt, &root_stmt)); | ||
| 394 | ++label_id; | 399 | ++label_id; |
| 395 | } | 400 | } |
| 396 | return labels_map; | 401 | return labels_map; |
| @@ -457,10 +462,10 @@ private: | |||
| 457 | } | 462 | } |
| 458 | body.erase(goto_stmt); | 463 | body.erase(goto_stmt); |
| 459 | 464 | ||
| 460 | // Update nested if condition | ||
| 461 | switch (label_nested_stmt->type) { | 465 | switch (label_nested_stmt->type) { |
| 462 | case StatementType::If: | 466 | case StatementType::If: |
| 463 | label_nested_stmt->cond = pool.Create(Or{}, neg_var, label_nested_stmt->cond); | 467 | // Update nested if condition |
| 468 | label_nested_stmt->cond = pool.Create(Or{}, variable, label_nested_stmt->cond); | ||
| 464 | break; | 469 | break; |
| 465 | case StatementType::Loop: | 470 | case StatementType::Loop: |
| 466 | break; | 471 | break; |