A texture re-upload reads a capture that may have been taken while the game was still writing the texture, and nothing tells it from a finished one #1607

Open
opened 2026-11-18 15:43:49 +00:00 by mooki · 1 comment
Member

Type: correctness · Area: renderer, memory sync (capture and texture upload) · Part of: #1493

TL;DR

A texture's re-upload reads its storage from the copies the submit-time capture took. If the game's threads were still writing the texture when the capture ran, the copy holds a mix of old and new bytes, and the upload puts that on the GPU for a frame. The renderer already compares the live pages with the copy when it reads them, and counts the pages that differ, but nothing acts on it. We propose to export that count first, and if it shows up, to hold a large re-upload back for a frame when its pages were rewritten since the capture.

Breakdown

  • Who it affects: players in busy scenes where the game streams or moves large block-compressed textures from the CPU. The effect would be one wrong frame of a texture. If the half-written data decodes to very large colours, bloom can spread it over the picture.
  • What is wrong, by reading: the capture is a per-submit copy of the pages the CPU wrote. It cannot know whether the game finished writing a texture. The upload trusts the copy.
  • What we propose: first, a per-frame figure for pages read as submitted that differ from live memory, split by whether the page belongs to a texture being uploaded. If it is non-trivial in a long run, a pure rule: a large re-upload whose pages changed since the capture waits one frame, at most a few frames in a row, and never for a texture the CPU rewrites every frame.
  • What does not change: first uploads, small textures, GPU-written textures, the capture itself.
  • What we do not claim: that this happens on Longshot. No report on the forge names this cause and we have not reproduced it.
  • How we would prove it: the count first. If it is zero on every rig the issue closes. Otherwise a fixture for the rule and a flash count over a long route, main against the change, after a null pair.

Evidence

Code on forge/main at 430eef4f2:

  • gpu/vk/vk_memory.cpp:1675-1700, memory_as_submitted: for pages that have a copy in the shadow it overlays the copy on the live bytes, and compares them with memcmp (:1691), counting the pages that differ in st_differed. It logs every 2000 reads: "texture storage read as submitted (... pages from the copies, ... of them rewritten in guest memory since their submit ...)" (:1697).
  • :1402-1412 and :1468: the shadow holds each guest page as the last capture took it; a texture's storage joins the capture after its first upload (gpu/vk/vk_texture.cpp:3137, memory_note_texture_upload).
  • gpu/vk/vk_texture.cpp:3024 (no dirty range, no upload) and :3114 (the upload): nothing there or in the upload reads st_differed, or any other signal that the pages changed after the capture.
  • Merged #1553 (today) changed boundary reads and capture reuse in the same area; this reading is of main after it.

The fork's claim, not ours: an outside audit of a fork reports that in the fork's long tours a burst of large block-compressed uploads was followed by a frame in which nearly every pixel changed, that it traced this to part-written texture data decoding to large finite colours that bloom spread over the picture, and that holding such a re-upload back one frame removed it. Its counts come from its own lab and we have no log of ours that shows it.

Proposed change

  1. Export the counter we already have. Per present: pages read as submitted, pages that differed from live, and how many of the differing pages lie in a texture that was uploaded this frame. One line with the other renderer lines. No behaviour changes.
  2. If the figure is non-trivial: a pure rule in a header. Inputs: the texture's size, whether it was uploaded before, whether any of its pages differ from live, how many frames in a row it has been held back, and whether it was rewritten in each of the last several frames. Output: upload now, or keep the old image and upload from the next capture.
  3. The rule never holds back a first upload, a texture below a size threshold, a texture rewritten every frame (a movie, an animation), or a texture for more than a small number of frames in a row.
  4. The thresholds are chosen from the counter's data on our rigs, not from the fork's.

How we would test it

  • Game-free, written first, so it cannot pass on main: a fixture for the rule. A small texture is never held; a large one with differing pages is held once and then uploaded; the third consecutive hold is refused; a texture rewritten every frame is uploaded as before; a first upload is never held. There is no such rule on main, so the fixture has nothing to pass against.
  • In the game, step one: the counter on a long route (several areas, then back to the first), any GPU. A table of pages differing per present and the textures involved. The first question is whether it is ever above zero for textures being uploaded.
  • In the game, step two, only if step one finds something: the project's flash scan of captured frames over the same route, main against the change, after a main-against-main pair. A count of flashes, not a speed figure.
  • No speed claim is made. The rule costs a frame of staleness for a texture, so a picture comparison matters more than a timing.
  • #1493, track B and slices a and e: the capture's rules are not written down; this is one missing rule.
  • #1034 (open): the write-mark audit. #1339 (open): late pages found when a capture is taken, a different late-page case. #1553 (merged): capture reuse and boundary reads.
  • The issue about re-uploads that bring identical bytes (to be linked): the same capture and shadow, a different question.
  • #944 and #1162 (open): a failed upload being tried again, which touches the same upload function.

New on this forge; not opened on GitHub.

**Type:** correctness · **Area:** renderer, memory sync (capture and texture upload) · **Part of:** #1493 ## TL;DR A texture's re-upload reads its storage from the copies the submit-time capture took. If the game's threads were still writing the texture when the capture ran, the copy holds a mix of old and new bytes, and the upload puts that on the GPU for a frame. The renderer already compares the live pages with the copy when it reads them, and counts the pages that differ, but nothing acts on it. We propose to export that count first, and if it shows up, to hold a large re-upload back for a frame when its pages were rewritten since the capture. ## Breakdown - **Who it affects:** players in busy scenes where the game streams or moves large block-compressed textures from the CPU. The effect would be one wrong frame of a texture. If the half-written data decodes to very large colours, bloom can spread it over the picture. - **What is wrong, by reading:** the capture is a per-submit copy of the pages the CPU wrote. It cannot know whether the game finished writing a texture. The upload trusts the copy. - **What we propose:** first, a per-frame figure for pages read as submitted that differ from live memory, split by whether the page belongs to a texture being uploaded. If it is non-trivial in a long run, a pure rule: a large re-upload whose pages changed since the capture waits one frame, at most a few frames in a row, and never for a texture the CPU rewrites every frame. - **What does not change:** first uploads, small textures, GPU-written textures, the capture itself. - **What we do not claim:** that this happens on Longshot. No report on the forge names this cause and we have not reproduced it. - **How we would prove it:** the count first. If it is zero on every rig the issue closes. Otherwise a fixture for the rule and a flash count over a long route, main against the change, after a null pair. ## Evidence Code on `forge/main` at `430eef4f2`: - `gpu/vk/vk_memory.cpp:1675-1700`, `memory_as_submitted`: for pages that have a copy in the shadow it overlays the copy on the live bytes, and compares them with `memcmp` (`:1691`), counting the pages that differ in `st_differed`. It logs every 2000 reads: "texture storage read as submitted (... pages from the copies, ... of them rewritten in guest memory since their submit ...)" (`:1697`). - `:1402-1412` and `:1468`: the shadow holds each guest page as the last capture took it; a texture's storage joins the capture after its first upload (`gpu/vk/vk_texture.cpp:3137`, `memory_note_texture_upload`). - `gpu/vk/vk_texture.cpp:3024` (no dirty range, no upload) and `:3114` (the upload): nothing there or in the upload reads `st_differed`, or any other signal that the pages changed after the capture. - Merged #1553 (today) changed boundary reads and capture reuse in the same area; this reading is of main after it. The fork's claim, not ours: an outside audit of a fork reports that in the fork's long tours a burst of large block-compressed uploads was followed by a frame in which nearly every pixel changed, that it traced this to part-written texture data decoding to large finite colours that bloom spread over the picture, and that holding such a re-upload back one frame removed it. Its counts come from its own lab and we have no log of ours that shows it. ## Proposed change 1. Export the counter we already have. Per present: pages read as submitted, pages that differed from live, and how many of the differing pages lie in a texture that was uploaded this frame. One line with the other renderer lines. No behaviour changes. 2. If the figure is non-trivial: a pure rule in a header. Inputs: the texture's size, whether it was uploaded before, whether any of its pages differ from live, how many frames in a row it has been held back, and whether it was rewritten in each of the last several frames. Output: upload now, or keep the old image and upload from the next capture. 3. The rule never holds back a first upload, a texture below a size threshold, a texture rewritten every frame (a movie, an animation), or a texture for more than a small number of frames in a row. 4. The thresholds are chosen from the counter's data on our rigs, not from the fork's. ## How we would test it - Game-free, written first, so it cannot pass on main: a fixture for the rule. A small texture is never held; a large one with differing pages is held once and then uploaded; the third consecutive hold is refused; a texture rewritten every frame is uploaded as before; a first upload is never held. There is no such rule on main, so the fixture has nothing to pass against. - In the game, step one: the counter on a long route (several areas, then back to the first), any GPU. A table of pages differing per present and the textures involved. The first question is whether it is ever above zero for textures being uploaded. - In the game, step two, only if step one finds something: the project's flash scan of captured frames over the same route, main against the change, after a main-against-main pair. A count of flashes, not a speed figure. - No speed claim is made. The rule costs a frame of staleness for a texture, so a picture comparison matters more than a timing. ## Related - #1493, track B and slices a and e: the capture's rules are not written down; this is one missing rule. - #1034 (open): the write-mark audit. #1339 (open): late pages found when a capture is taken, a different late-page case. #1553 (merged): capture reuse and boundary reads. - The issue about re-uploads that bring identical bytes (to be linked): the same capture and shadow, a different question. - #944 and #1162 (open): a failed upload being tried again, which touches the same upload function. New on this forge; not opened on GitHub.
Collaborator

Possibly related, for context:

  • issue #1608 How many texture re-uploads bring the same bytes the image already holds? Nothing in the renderer compares them — Related texture-upload issue; explicitly distinguishes identical-byte re-uploads from potentially torn capture data.
  • issue #1493 Renderer rewrite — Parent renderer rewrite, including memory-sync capture rules.
  • PR #1553 perf(runtime): reduce Market frame stalls and Vulkan capture overhead — Merged capture-reuse and submission-snapshot read changes in the same code area.
Possibly related, for context: - issue #1608 How many texture re-uploads bring the same bytes the image already holds? Nothing in the renderer compares them — Related texture-upload issue; explicitly distinguishes identical-byte re-uploads from potentially torn capture data. - issue #1493 Renderer rewrite — Parent renderer rewrite, including memory-sync capture rules. - PR #1553 perf(runtime): reduce Market frame stalls and Vulkan capture overhead — Merged capture-reuse and submission-snapshot read changes in the same code area.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot#1607
No description provided.