Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested loops do not restore aL register with nested loops #86

Open
Wunkolo opened this issue Apr 22, 2024 · 0 comments
Open

Nested loops do not restore aL register with nested loops #86

Wunkolo opened this issue Apr 22, 2024 · 0 comments

Comments

@Wunkolo
Copy link
Contributor

Wunkolo commented Apr 22, 2024

Issue

Issue revealed in the shader unit-tests in #72, the shader-interpreter does not correctly handle nested loops properly. Specifically the aL(loop counter) register is not properly incremented and restored for the parent-loop.

1: -------------------------------------------------------------------------------
1: Nested Loop - ShaderInterpreterTest
1: -------------------------------------------------------------------------------
1: /__w/citra/citra/src/tests/video_core/shader/shader_jit_compiler.cpp:636
1: ...............................................................................
1: 
1: /__w/citra/citra/src/tests/video_core/shader/shader_jit_compiler.cpp:669: FAILED:
1:   REQUIRE( shader_unit.address_registers[2] == expected_aL )
1: with expansion:
1:   0 == 5

The top-most loop can end or break but multiple loops may need to be iterated at the same program counter, this is currently not handled.

if (!loop_stack.empty() &&
(loop_stack.back().end_address == old_program_counter 1 || is_break)) {
auto& loop = loop_stack.back();
state.address_registers[2] = loop.address_increment;
if (!is_break && loop.loop_downcounter--) {
program_counter = loop.entry_address;
} else {
program_counter = loop.end_address;
// Only restore previous value if there is a surrounding LOOP scope.
if (loop_stack.size() > 1)
state.address_registers[2] = loop.previous_aL;
loop_stack.pop_back();
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant