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

Fix buffer updates going to the wrong cmd buffer if barriers were 0 #83736

Merged

Conversation

darksylinc
Copy link
Contributor

From what I could see only SSAO & SSIL were affected when they both call:

int zero[1] = { 0 };
RD::get_singleton()->buffer_update(ssao.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0);

int zero[1] = { 0 };
RD::get_singleton()->buffer_update(ssil.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0);

Also documented what setup_command_buffer & draw_command_buffer are for.

I placed breakpoints to see who calls buffer_update() with barriers = 0 and those two were the only calls.

@DarioSamo found this bug while working on Acyclic Render Graphs, but asked me to look deeper into it as he is occupied with the ARG.

Fortunately it doesn't seem like the damage is large:

  • When buffer_update calls _buffer_update with the wrong queue, buffer_update has the _THREAD_SAFE_METHOD_ macro
  • All the other functions that call _buffer_update directly also use the _THREAD_SAFE_METHOD_ macro.

So there are no race conditions on the CPU side.

As for the GPU side it's a little more horrible:

What Godot wanted to do:

  1. Execute SSAO (or SSIL).
  2. Reset the counter to 0 for the next frame.

What Godot ends up doing:

  1. Execute SSAO (or SSIL).
  2. Reset the counter to 0 "whenever you feel like". Before SSAO, during SSAO, after SSAO.

What most likely ends up happening most of the time:

  1. Reset the counter to 0 at the beginning of the frame.
  2. Execute SSAO (or SSIL).

With my fix, I had to add BARRIER_MASK_TRANSFER to compute_list_end so that the reset is guaranteed to happen after the compute work (though it could probably be moved far elsewhere, e.g. at the end of the frame).

@darksylinc darksylinc requested a review from a team as a code owner October 21, 2023 16:08
From what I could see only SSAO & SSIL were affected when they both
call:

int zero[1] = { 0 };
RD::get_singleton()->buffer_update(ssao.importance_map_load_counter, 0,
sizeof(uint32_t), &zero, 0);

int zero[1] = { 0 };
RD::get_singleton()->buffer_update(ssil.importance_map_load_counter, 0,
sizeof(uint32_t), &zero, 0);

Also documented what setup_command_buffer & draw_command_buffer are for.
@darksylinc darksylinc force-pushed the matias-broken_buffer_update branch from d1dd7e4 to c9ec1f7 Compare October 21, 2023 16:14
@AThousandShips AThousandShips added this to the 4.2 milestone Oct 21, 2023
@clayjohn clayjohn modified the milestones: 4.2, 4.3 Nov 13, 2023
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice to have this cleaned up.

Let's merge this early in the 4.3 dev cycle

@clayjohn clayjohn added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Nov 13, 2023
@akien-mga akien-mga merged commit 6f4da7a into godotengine:master Dec 4, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.2.1.

@YuriSizov YuriSizov removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants