Skip to content

Clear hybrid render targets before drawing#1572

Merged
waywardmonkeys merged 2 commits into
linebender:mainfrom
waywardmonkeys:hybrid-clear-stale-repro
Apr 15, 2026
Merged

Clear hybrid render targets before drawing#1572
waywardmonkeys merged 2 commits into
linebender:mainfrom
waywardmonkeys:hybrid-clear-stale-repro

Conversation

@waywardmonkeys
Copy link
Copy Markdown
Collaborator

@waywardmonkeys waywardmonkeys commented Apr 14, 2026

This clears the hybrid WGPU render target before normal scene rendering.

The previous behavior assumed that the target contents were either undefined or irrelevant, which is often true for fresh swapchain images. But Renderer::render accepts an arbitrary TextureView, and in practice it is also used with reused offscreen targets. In that case, transparent or otherwise untouched regions can retain pixels from an earlier frame.

This PR does two things:

  • adds a regression test that renders a full frame, resets the scene, then renders a smaller second frame into the same target
  • clears the user-surface render path before drawing so the second frame starts from transparent black

The atlas render path is left unchanged. This fix is only for the normal user-facing render target path.

@waywardmonkeys waywardmonkeys requested a review from LaurenzV April 14, 2026 11:12
@nicoburns
Copy link
Copy Markdown
Contributor

I've had bug reports for rendering "undefined buffer content" in Blitz (which in practice happened to be a stale render from another unrelated window!). But don't we want to allow for explicitly not clearing so that we can so incremental renders?

@waywardmonkeys
Copy link
Copy Markdown
Collaborator Author

WebGL clears in this case. This leads to wrong output when using it with compositor layers now.

@LaurenzV LaurenzV requested a review from taj-p April 14, 2026 12:58
@LaurenzV
Copy link
Copy Markdown
Collaborator

Gonna defer to Taj here.

Copy link
Copy Markdown
Contributor

@taj-p taj-p left a comment

Choose a reason for hiding this comment

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

This makes the WGPU implementation consistent with WebGL, which seems like a worthwhile thing to do!

Ultimately, I think it should be user configured (either a Load/Clear/DontCare enum) - we shouldn't be deciding whether a surface is cleared or not because, as Nico suggests, you could be building an incremental renderer (and it's expensive on low tier devices!).

@waywardmonkeys waywardmonkeys added this pull request to the merge queue Apr 15, 2026
@waywardmonkeys
Copy link
Copy Markdown
Collaborator Author

Ultimately, I think it should be user configured (either a Load/Clear/DontCare enum) - we shouldn't be deciding whether a surface is cleared or not because, as Nico suggests, you could be building an incremental renderer (and it's expensive on low tier devices!).

yep. There is a lot of API work to do across Hybrid, CPU, Classic, and Imaging to have a coherent and possibly consistent story.

Merged via the queue into linebender:main with commit 8afc1c6 Apr 15, 2026
17 checks passed
@waywardmonkeys waywardmonkeys deleted the hybrid-clear-stale-repro branch April 15, 2026 07:01
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.

4 participants