Skip to content

Conversation

@marcocondrache
Copy link
Contributor

@marcocondrache marcocondrache commented Dec 13, 2025

This PR partially addresses #8043 on macOS

Still a WIP

The current renderer relies on the painter’s algorithm for draw ordering, which results in significant overdraw. Large portions of the frame are shaded multiple times even though only the frontmost fragments are visible, increasing GPU and CPU usage

This change enables depth testing and adjusts rendering to rely on depth buffering rather than strict back-to-front ordering. This allows the GPU to discard occluded fragments earlier in the pipeline, reducing unnecessary work.

Ref: https://developer.apple.com/documentation/metal/calculating-primitive-visibility-using-depth-testing

Release Notes:

  • Reduced gpu and battery usage due to overdrawing

Signed-off-by: Marco Mihai Condrache <[email protected]>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 13, 2025
@github-project-automation github-project-automation bot moved this to Community Champion PRs in Quality Week – December 2025 Dec 13, 2025
Signed-off-by: Marco Mihai Condrache <[email protected]>
Signed-off-by: Marco Mihai Condrache <[email protected]>
Signed-off-by: Marco Mihai Condrache <[email protected]>
Signed-off-by: Marco Mihai Condrache <[email protected]>
Signed-off-by: Marco Mihai Condrache <[email protected]>
Signed-off-by: Marco Mihai Condrache <[email protected]>
@HigherOrderLogic
Copy link

Hi, I got to this PR through the linked issue.

My 2 cents: shouldnt this be solved with a more general solution such as damage tracking and re-rendering only the changed part. I think that option would be much more performant, and also work on other platforms such as Linux.

@marcocondrache
Copy link
Contributor Author

marcocondrache commented Dec 13, 2025

@HigherOrderLogic Damage tracking and depth testing solve orthogonal problems:

  • Depth testing reduces overdraw within a single frame. When you have overlapping elements each layer would write to the same pixels. Depth testing lets the gpu discard fragments behind already-rendered content
  • Damage tracking reduces repainting across frames. It avoids redrawing unchanged regions but doesn't help with overdraw within the regions that do need redrawing.

Issue #8043 specifically reports overdraw per frame (and overlapping elements), this is exactly what depth testing addresses. Even with perfect damage tracking, the same overdraw would occur within the damaged regions.

Both optimizations are complementary and valuable, I can try to implement damage tracking separately to further improve performance. This PR focuses on the overdraw problem specifically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants