texture: keep what a GPU copy wrote from uploads asked for before it #47

Closed
github-bot wants to merge 1 commit from github-bot/gh-47 into main AGit
Owner

@⁠Unverifiedd on GitHub · 2026-11-30 22:55 UTC · original
Unverifiedd:keep-gpu-written → main · +644 −13 · 4 files · 1 commits · closed without merging

What it fixes

Graphical glitches (nicknamed "confetti") on people's faces, necks and shirts, which can stay for the whole session. It shows up most once decorations are baked (tattoos, prints, make-up). The cause is a race between a GPU copy and a texture upload from title memory.

The title records its command lists on many threads and submits them in its own order. A draw list recorded before a bake list, but submitted after it, still has a prelude upload pending for the baked decoration texture. That texture is BC3 256x256 with nine levels; its blocks are encoded on the GPU and copied in level by level. At that later submission, the upload copied title memory over what the bake's copies had just written. Title memory never receives a GPU copy's bytes, because on the console the copy writes that memory itself. So the decoration got whatever the memory held before: other textures and streaming data, decoded as BC3. The existing host_written shortcut in upload_from only covers lists recorded after the copy.

How it was pinned down: GPU read-backs of the BC3 encoder's input (the atlas level) and its output matched block for block, so the bake was right. The garbage came from an upload of the decoration texture's title memory that landed after the copy. Decoded as BC3, that memory reproduced the graphical glitch exactly.

What it does

  • Each list notes the subresources its copies and resolves write, as two atomics on the host copy (HostTexture::gpu_written, texture::GpuWritten). There is no table and no lock.
  • Once a list is submitted, those levels count as GPU-written for lists submitted after it. PreludeUpload::finish_refresh leaves those levels out of the upload.
  • The rule is per level. A texture streamed bigger has its small levels copied on the GPU from the smaller texture and its large levels read into memory, and those large levels are still uploaded. Skipping whole textures broke exactly that case: black blotches where a print should be.
  • The record-time shortcut that asks for no upload at all now applies once every level from the view's first is copied into. It no longer applies after any copy at all.
  • VICTORY_KEEP_GPU_WRITTEN=0 turns it all off, and does no work then.
  • Host copies with more than 64 subresources, and anything not marked by a copy or resolve, behave exactly as before.

Cost

Measured with the same commit, warm caches, the same machine and a similar spot:

median fps preparing ms/frame refresh ms/frame
without the fix 37.99 3.87 2.60
with an earlier version of the fix (global tables) 38.83 3.74 2.59

This version replaces those tables with per-texture atomics, so it costs less than the measured one. The upload is skipped about 20–40 times per play session, mostly while people stream in and their decorations are baked.

Tests

  • texture::gpu_written_tests: five tests of the level bits (the bake, a texture streamed bigger, layers and planes, long arrays, staging parts past the changed-levels mask).
  • resource::tests::what_the_host_copied_in_is_kept_from_an_upload_asked_for_earlier: reproduces the race on the host GPU through the title's own list and queue calls, then reads the texture back. It passes with the fix. Without it (the switch off and the test's early return removed), it reads the changed title memory (0x22) instead of what the copies wrote (0xaa).

All six pass on 37bb30f under Wine with the project's vkd3d and Mesa (RX 7900 XTX). The release build is clean, and cargo xtask policy reports 4 files ok.

Noticed while doing this, not changed here

  • copy_texture_region and resolve pass the title's subresource index unchanged to a host copy whose level 0 may be a later title level (copy.base), while views are translated. This may misplace copies into placed textures over 1024 texels, or into textures first viewed from a later level.
  • A host copy replaced by one with more levels loses what the GPU had copied into the old one, and the new one is not refilled from it.

🤖 Generated with Claude Code

**@⁠Unverifiedd** on GitHub · 2026-11-30 22:55 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/47) `Unverifiedd:keep-gpu-written` → `main` · +644 −13 · 4 files · 1 commits · closed without merging ## What it fixes Graphical glitches (nicknamed "confetti") on people's faces, necks and shirts, which can stay for the whole session. It shows up most once decorations are baked (tattoos, prints, make-up). The cause is a race between a GPU copy and a texture upload from title memory. The title records its command lists on many threads and submits them in its own order. A draw list recorded *before* a bake list, but submitted *after* it, still has a prelude upload pending for the baked decoration texture. That texture is BC3 256x256 with nine levels; its blocks are encoded on the GPU and copied in level by level. At that later submission, the upload copied title memory over what the bake's copies had just written. Title memory never receives a GPU copy's bytes, because on the console the copy writes that memory itself. So the decoration got whatever the memory held before: other textures and streaming data, decoded as BC3. The existing `host_written` shortcut in `upload_from` only covers lists *recorded* after the copy. How it was pinned down: GPU read-backs of the BC3 encoder's input (the atlas level) and its output matched block for block, so the bake was right. The garbage came from an upload of the decoration texture's title memory that landed after the copy. Decoded as BC3, that memory reproduced the graphical glitch exactly. ## What it does - Each list notes the subresources its copies and resolves write, as two atomics on the host copy (`HostTexture::gpu_written`, `texture::GpuWritten`). There is no table and no lock. - Once a list is submitted, those levels count as GPU-written for lists submitted after it. `PreludeUpload::finish_refresh` leaves those levels out of the upload. - The rule is **per level**. A texture streamed bigger has its small levels copied on the GPU from the smaller texture and its large levels read into memory, and those large levels are still uploaded. Skipping whole textures broke exactly that case: black blotches where a print should be. - The record-time shortcut that asks for no upload at all now applies once every level from the view's first is copied into. It no longer applies after any copy at all. - `VICTORY_KEEP_GPU_WRITTEN=0` turns it all off, and does no work then. - Host copies with more than 64 subresources, and anything not marked by a copy or resolve, behave exactly as before. ## Cost Measured with the same commit, warm caches, the same machine and a similar spot: | | median fps | preparing ms/frame | refresh ms/frame | |---|---|---|---| | without the fix | 37.99 | 3.87 | 2.60 | | with an earlier version of the fix (global tables) | 38.83 | 3.74 | 2.59 | This version replaces those tables with per-texture atomics, so it costs less than the measured one. The upload is skipped about 20–40 times per play session, mostly while people stream in and their decorations are baked. ## Tests - `texture::gpu_written_tests`: five tests of the level bits (the bake, a texture streamed bigger, layers and planes, long arrays, staging parts past the changed-levels mask). - `resource::tests::what_the_host_copied_in_is_kept_from_an_upload_asked_for_earlier`: reproduces the race on the host GPU through the title's own list and queue calls, then reads the texture back. It passes with the fix. Without it (the switch off and the test's early return removed), it reads the changed title memory (`0x22`) instead of what the copies wrote (`0xaa`). All six pass on `37bb30f` under Wine with the project's vkd3d and Mesa (RX 7900 XTX). The release build is clean, and `cargo xtask policy` reports 4 files ok. ## Noticed while doing this, not changed here - `copy_texture_region` and `resolve` pass the title's subresource index unchanged to a host copy whose level 0 may be a later title level (`copy.base`), while views are translated. This may misplace copies into placed textures over 1024 texels, or into textures first viewed from a later level. - A host copy replaced by one with more levels loses what the GPU had copied into the old one, and the new one is not refilled from it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A list recorded before a copy into a title texture and submitted after it
still uploaded that texture from title memory at its submission, over what
the copy had written. Title memory never gets a GPU copy's bytes (on the
console the copy writes that memory). People's baked decorations (BC3
256x256, nine levels, encoded on the GPU and copied in level by level) got
whatever the memory held before: graphical glitches (nicknamed "confetti")
on faces, necks and shirts, which can stay for the whole session.

Each list now notes the subresources its copies and resolves write, on the
host copy itself (two atomics, no table or lock). Once that list is
submitted, the uploads of lists submitted after it leave those levels out;
the other levels still come from title memory (a texture streamed bigger has
its small levels copied on the card and its large ones read into memory).
The record-time shortcut that asks for no upload at all applies once every
level from the view's first is copied into. VICTORY_KEEP_GPU_WRITTEN=0 turns
it off.

Tests: texture::gpu_written_tests (the level bits) and
resource::tests::what_the_host_copied_in_is_kept_from_an_upload_asked_for_earlier
(the race on the host GPU through the title's own list and queue calls; it
fails without the fix).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 07:42:10 +00:00
Author
Owner

@⁠Fran-co-F on GitHub · 2026-12-01 14:02 UTC · original · edited 2026-12-01 14:06 UTC

A data point from an RX 9070 XT (RADV, CachyOS, GE-Proton11-14, 2560x1440):

  • Plain 37bb30f, ray tracing off: a character's face in an office cutscene had the coloured "confetti" noise.
  • 37bb30f + this PR + #45 #44 #43 #38 #31, ray tracing on: the face was clean when I replayed that cutscene.

Before:
1-confetti-37bb30f
After:
4-cara-ok-con-47

That fits this fix, but it isn't an A/B of this PR alone: the other five PRs and ray tracing changed too.

A separate problem remains: in another scene, a face still turns black for a moment, even with this PR in the build. It also happens on plain 37bb30f, so it doesn't come from this PR. Details in #69.

AI use: Claude Code (Claude Opus 5.5) made the builds and wrote this. I played the sessions and compared the images.

**@⁠Fran-co-F** on GitHub · 2026-12-01 14:02 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/47#issuecomment-7313609636) · edited 2026-12-01 14:06 UTC A data point from an RX 9070 XT (RADV, CachyOS, GE-Proton11-14, 2560x1440): - **Plain `37bb30f`, ray tracing off:** a character's face in an office cutscene had the coloured "confetti" noise. - **`37bb30f` + this PR + #45 #44 #43 #38 #31, ray tracing on:** the face was clean when I replayed that cutscene. Before: <img width="2000" height="1125" alt="1-confetti-37bb30f" src="https://github.com/user-attachments/assets/80eb18a4-cd50-427f-9a6c-9899cde85d44" /> After: <img width="2000" height="1125" alt="4-cara-ok-con-47" src="https://github.com/user-attachments/assets/290e02a7-401b-4c27-9c2c-364d3de0f4e8" /> That fits this fix, but it isn't an A/B of this PR alone: the other five PRs and ray tracing changed too. A separate problem remains: in another scene, a face still turns black for a moment, even with this PR in the build. It also happens on plain `37bb30f`, so it doesn't come from this PR. Details in #69. **AI use:** Claude Code (Claude Opus 5.5) made the builds and wrote this. I played the sessions and compared the images.
Author
Owner

@⁠BlueCatsz on GitHub · 2026-12-01 16:03 UTC · original

Tested #47 on CachyOS + RX 9070 XT 16 GB as part of a combined local stack (main 37bb30f + #44 + #47 + #67 + #31 + #43 + opt-in VICTORY_AMBIENT_RT, with VICTORY_POOL_MOVE=1 and VICTORY_PLACED_COPIED=1).

  • Environment: Ryzen 7 5800X3D, 32 GB DDR4, RX 9070 XT (RADV GFX1201, Mesa 26.3.1 + #44/#43 mesa.patch), CachyOS (kernel 7.3.6), proton-cachyos-slr + RB-tree wineserver, Series X (1706x960 -> 2560x1440, HW RT on, FG off).
  • Observed Result: Before adding #47 + #67, NPCs in the opening indoor corridor scenes reliably developed rainbow/confetti corruption on baked arm/skin textures. With #47 + #67 active together, those arm/skin artifacts did not occur across an entire session from the opening scenes into the open world (0 crashes, 0 device loss, 0 dropped draws). (Note: #47 and #67 were tested together rather than in isolation.)
**@⁠BlueCatsz** on GitHub · 2026-12-01 16:03 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/47#issuecomment-7316966190) Tested #47 on CachyOS + RX 9070 XT 16 GB as part of a combined local stack (`main` `37bb30f` + #44 + #47 + #67 + #31 + #43 + opt-in `VICTORY_AMBIENT_RT`, with `VICTORY_POOL_MOVE=1` and `VICTORY_PLACED_COPIED=1`). - **Environment:** Ryzen 7 5800X3D, 32 GB DDR4, RX 9070 XT (RADV GFX1201, Mesa `26.3.1` + #44/#43 `mesa.patch`), CachyOS (kernel `7.3.6`), `proton-cachyos-slr` + RB-tree `wineserver`, Series X (`1706x960 -> 2560x1440`, HW RT on, FG off). - **Observed Result:** Before adding #47 + #67, NPCs in the opening indoor corridor scenes reliably developed rainbow/confetti corruption on baked arm/skin textures. With #47 + #67 active together, those arm/skin artifacts did not occur across an entire session from the opening scenes into the open world (`0` crashes, `0` device loss, `0` dropped draws). *(Note: #47 and #67 were tested together rather than in isolation.)*
Author
Owner

@⁠YaBulochka on GitHub · 2026-12-01 16:23 UTC · original

This fixes the confetti here, but it tears character meshes on RDNA3 — worth knowing before it reaches an 8 GB card.

Setup. RX 7600 XT 8 GB (RDNA3), Ryzen 5 9600X, 30 GB, RADV 26.3.1, GE-Proton11-16, series-s, VICTORY_FSR_HOST=1, VICTORY_OUTPUT=1920x1080, VICTORY_BVH_HARDWARE=0, ray tracing otherwise on. Merged on top of 4cea493 (our branch with #51/#52/#58/#60/#63 and three local switches: VICTORY_SHADER_OPT=0xffffffff, VICTORY_LOW_MEMORY=0, VICTORY_PROCESS_PRIORITY=high). Its own line shows up as expected: uploads over textures the host GPU wrote since they were asked for are left out.

What happens. With the fix merged, characters' meshes start tearing: triangles stretching between limbs and the ground, pieces of arms and torsos left behind, most visible on people close to the camera. The confetti on shirts and necks is gone in the same runs. Reverting the merge (git reset to the same tree without the four commits) and rebuilding brings the meshes back intact and the confetti back with them, so it is the fix and not a scene.

Not ruled out. Only one save, one scene (city, close to the camera, on foot and in a car), one build, two runs each way. The tearing could be specific to 8 GB: the per-level rule leaves uploads out, and on a card where levels are streamed out and back constantly the levels a mesh bind depends on may be the ones skipped.

Happy to run whatever diagnostic you point at, or to repeat on a switch that turns only part of it on, since VICTORY_KEEP_GPU_WRITTEN is all-or-nothing today.

No game files, screenshots or captures included.

**@⁠YaBulochka** on GitHub · 2026-12-01 16:23 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/47#issuecomment-7317518495) This fixes the confetti here, but it tears character meshes on RDNA3 — worth knowing before it reaches an 8 GB card. **Setup.** RX 7600 XT 8 GB (RDNA3), Ryzen 5 9600X, 30 GB, RADV 26.3.1, GE-Proton11-16, `series-s`, `VICTORY_FSR_HOST=1`, `VICTORY_OUTPUT=1920x1080`, `VICTORY_BVH_HARDWARE=0`, ray tracing otherwise on. Merged on top of `4cea493` (our branch with #51/#52/#58/#60/#63 and three local switches: `VICTORY_SHADER_OPT=0xffffffff`, `VICTORY_LOW_MEMORY=0`, `VICTORY_PROCESS_PRIORITY=high`). Its own line shows up as expected: `uploads over textures the host GPU wrote since they were asked for are left out`. **What happens.** With the fix merged, characters' meshes start tearing: triangles stretching between limbs and the ground, pieces of arms and torsos left behind, most visible on people close to the camera. The confetti on shirts and necks is gone in the same runs. Reverting the merge (`git reset` to the same tree without the four commits) and rebuilding brings the meshes back intact and the confetti back with them, so it is the fix and not a scene. **Not ruled out.** Only one save, one scene (city, close to the camera, on foot and in a car), one build, two runs each way. The tearing could be specific to 8 GB: the per-level rule leaves uploads out, and on a card where levels are streamed out and back constantly the levels a mesh bind depends on may be the ones skipped. Happy to run whatever diagnostic you point at, or to repeat on a switch that turns only part of it on, since `VICTORY_KEEP_GPU_WRITTEN` is all-or-nothing today. No game files, screenshots or captures included.
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:03 UTC · original · edited 2026-12-05 11:24 UTC

As I read it, this is already in main: main carries this change verbatim. Your commit 1eac332 has the same patch-id (2c999946…) as main's dbd059f — same subject, same author, same 4 files +644/−13 — and main then built on it (LateView/twin_copy calling note_gpu_written, exactly as the hook was asked for).

VICTORY_KEEP_GPU_WRITTEN is documented in both docs/SETTINGS.md and run.conf.default on main, so it is not an undocumented escape hatch either. The only caveat that survives is the >64-subresource limit of the GpuWritten whole-word bitmask in crates/victory-gpu/src/texture.rs, which main already accepts.

Nothing to land — the branch is now a stale fork of code you own. Take the credit in git log.

Whether it still has work of its own is the maintainer's call, not mine.

**@⁠Luxuride** on GitHub · 2026-12-04 12:03 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/47#issuecomment-7410913424) · edited 2026-12-05 11:24 UTC As I read it, this is already in `main`: main carries this change verbatim. Your commit `1eac332` has the same patch-id (`2c999946…`) as main's `dbd059f` — same subject, same author, same 4 files +644/−13 — and main then built on it (`LateView`/`twin_copy` calling `note_gpu_written`, exactly as the hook was asked for). `VICTORY_KEEP_GPU_WRITTEN` is documented in both `docs/SETTINGS.md` and `run.conf.default` on main, so it is not an undocumented escape hatch either. The only caveat that survives is the >64-subresource limit of the `GpuWritten` whole-word bitmask in `crates/victory-gpu/src/texture.rs`, which main already accepts. Nothing to land — the branch is now a stale fork of code you own. Take the credit in `git log`. Whether it still has work of its own is the maintainer's call, not mine.
github-bot closed this pull request 2026-12-05 17:31:45 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.