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: Metal MSAA resolve buffer #474

Merged
merged 2 commits into from
Apr 7, 2024
Merged

Conversation

Archez
Copy link
Contributor

@Archez Archez commented Apr 7, 2024

After implementing the framebuffer copying commands, I noticed that our MSAA resolve pattern for Metal was incorrect.

What we were doing before was ending the render encoder on the source framebuffer, then creating a blit encoder to copy the source buffers texture to the target buffers texture. This works for the case where the target is not the main window framebuffer and we re-draw the texture via ImGui (n64 mode, internal resolution != 1).

But in the case where the target framebuffer is the main window buffer (0), we were using LoadActionLoad to prevent clearing the frame buffer on the frame. However, the blit operation is performed after the main buffer render encoder is created. This means that the "Loaded" texture is actually the previous frames final result. So MSAA on Metal ended up being delayed by 1 frame and would potentially re-draw unwanted pixels.

To correct this, I have switched all the initial load actions to Clear. Then to properly handle the MSAA resolving for the main window buffer, I created a separate code path that is modeled after the framebuffer copy command. We end the render encoder and create the blit encoder on the target buffer instead of the source buffer. Then before we remake the render encoder, at this point we can change the load action to Load so that we retain the texture from the blit.

This ensures we are using the MSAA results for the correct frame without any previous frame re-draw artifacts.

@Kenix3 Kenix3 merged commit 6facfb5 into Kenix3:main Apr 7, 2024
4 checks passed
@Archez Archez deleted the fix-metal-msaa-resolve branch April 7, 2024 20:40
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

Successfully merging this pull request may close these issues.

2 participants