Skip to content

NVN: preserve buffer-backed storage when upgrading texture usage - #97

Closed
Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/linear-texture-backing
Closed

Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/linear-texture-backing

Conversation

@Jpkovas

@Jpkovas Jpkovas commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

tex_upgrade() currently replaces a buffer-backed linear texture with a standalone texture when adding render-target or pixel-format-view usage. The initial pixels are copied, but subsequent GPU writes update the new allocation while the guest CPU mapping still reads the original pool buffer. This can produce black save thumbnails even after GPU completion.

The change recreates a buffer-backed texture over the same buffer, bufferOffset and bufferBytesPerRow. No copy is encoded when both textures share that storage. Standalone textures retain the existing slice/level copy path. Alignment requirements are unchanged.

The regression uses synthetic 160x90 RGBA8 and RGBA8 sRGB textures, 640-byte rows and a CPU/GPU cached pool. It exercises actual img_fit() conversion to an R32UI image and an NVN scaled sRGB copy from 320x180 into the linear destination, then reads through the guest CPU mapping.

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

On the pinned public main ebe75c9d5d34486f714678f850f0e74bbab398ac, the same test has four failures in 17 assertions. With this patch alone it passes 17/17 with Metal API Validation. Each pixel case checks all 14,400 pixels, and the scaled-copy case also checks that the destination still has its buffer backing. The observed minimum linear alignment on the test Mac is 16 bytes, so the 640-byte pitch is valid.

A separate combined iPhone build produced a new, nonblack 160x90 save thumbnail inside LM3. No game image, save, shader, binary or extracted input is included with this contribution. The isolated Metal regression is the proof for this change; the device observation is integration evidence.

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 672681f (cherry-picked onto main, authorship kept). Thanks! t_linear_readback fails 4 of 17 checks on the previous main and passes 17 of 17 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