Skip to content

Add option to set the depth-buffer-clear position counting from the last one - #431

Open
microdee wants to merge 4 commits into
crosire:mainfrom
microdee:feature/count-depth-clears-from-last
Open

Add option to set the depth-buffer-clear position counting from the last one#431
microdee wants to merge 4 commits into
crosire:mainfrom
microdee:feature/count-depth-clears-from-last

Conversation

@microdee

Copy link
Copy Markdown

This PR gives a tool for Source games to help with correctly copying the depth-buffer there. There are well known problems with reliably getting the depth buffer in Source games:

  • Rendering the GUI clears the depth buffer
  • The same depth-buffer is used several times to render 3D skybox or render-targets
  • The statistical methods may incorrectly determine to copy the 3D skybox content if both draw-call-count and vertex count are higher than the main scene.

To get around all that I introduced the option to manually set the copy-depth-before-clear position counting from the last clear operation, since the count of the UI depth-buffer clears are much more stable than the depth-buffer-clears done during actual rendering.

Depth buffer without this fix:

2026-07-13_15-37-39.mp4

Depth buffer with this fix:

2026-07-13_15-41-05.mp4

Another example:

2026-07-13_16-09-53.mp4

Unfortunately since we rely on data from previous frame (the number of depth-buffer-clears in one frame) there may be flickering if the clear operations change often, but in Source games at least it's barely noticeable.

@crosire

crosire commented Aug 1, 2026

Copy link
Copy Markdown
Owner

This Source Engine case is theoretically already supposed to be addressed by the "Choose last clear operation with high number of draw calls" option (see also b1effa7). However I see in the videos that the option is not shown here, presumably because the condition for showing it is too restrictive (sorted_item_list.size() == 1, but there are two items here). Could you try by removing that sorted_item_list.size() == 1 condition and enabling the option, to see if it has the same effect? Based on the statistics I'm seeing in the second window, I suspect it should.

crosire added a commit that referenced this pull request Aug 2, 2026
@microdee

microdee commented Aug 2, 2026

Copy link
Copy Markdown
Author

Oh! I'm going to try with that commit, thanks for pointing it out, do you remember what was the reason to restrict "Choose last clear operation with high number of draw calls" like that in the first place?

@microdee

microdee commented Aug 2, 2026

Copy link
Copy Markdown
Author

While it's indeed more stable with "Choose last clear operation with high number of draw calls" it can still fail in circumstances when the 3D skybox is a lot busier than the actual foreground:

Screenshot 2026-08-02 191008

Whereas counting from last clear solves this situation as well

Screenshot 2026-08-02 191119

The results are the same if I check "Copy depth buffer before fullscreen draw calls"

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