Skip to content

NVN: materialize pending clears before texture-to-buffer copies - #98

Closed
Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/clear-before-readback
Closed

Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/clear-before-readback

Conversation

@Jpkovas

@Jpkovas Jpkovas commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

A recorded render-target clear with no draw can remain pending when CopyTextureToBuffer is replayed. The copy reads the old texture contents, and the clear reaches the GPU later at submission commit. Waiting on the recorded fence therefore does not repair the already-copied bytes.

Call rp_flush() before resolving and copying the source, matching the existing texture-to-texture path. The runtime change is one line.

The regression records an 8x4 constant RGBA clear, a texture-to-buffer copy with a 64-byte row stride and a fence. It requires 32 literal [51,102,153,255] pixels and untouched padding. A subsequent CPU ReadTexels check and GPU success/fence checks are also included.

make -C dm/gfx/tests GAME=0100DCA0064A6000 t_readback
MTL_DEBUG_LAYER=1 dm/gfx/tests/t_readback

On public main ebe75c9d5d34486f714678f850f0e74bbab398ac, the new test fails one of six assertions. With this patch alone, all six pass with Metal API Validation. No game data or translated game shader is needed.

This is independent of the separate buffer-backed tex_upgrade() coherence defect. Both were found during the thumbnail investigation, but their regressions and runtime changes are deliberately separate.

seedds added a commit that referenced this pull request Oct 24, 2026
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Merged into main as cd0e61c (cherry-picked onto main, authorship kept). Thanks! t_readback fails 1 of 6 checks on the previous main and passes 6 of 6 with the change (MTL_DEBUG_LAYER=1). Its binary is now in dm/gfx/tests/.gitignore (ea3ed86).

@seedds seedds closed this Oct 24, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
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