How many texture re-uploads bring the same bytes the image already holds? Nothing in the renderer compares them #1608

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

Type: performance · Area: renderer, texture upload, memory sync · Part of: #1493

TL;DR

A texture is re-uploaded when its guest pages were marked written, whatever bytes were written. If the game, or the host for it, writes the same bytes again, the capture still copies them and the renderer still uploads them. The open pull request #1576 stops the host from marking identical copies; this issue asks what is left after it and whether a content check in the capture is worth its cost. We propose a sampled counter first, and no renderer change until it shows a number.

Breakdown

  • Who it affects: players in scenes where the game rewrites big textures every few frames. The cost would be upload bandwidth and a slow frame when many come in one frame, not a steady rate.
  • What is wrong, by reading: dirtiness is decided by write generation alone. No code compares what was written with what the image already holds.
  • What we propose: a sampled counter: at every Nth re-upload, hash the bytes about to be staged and compare with a hash kept from the same texture's previous upload; report how many bytes were equal. Run it on main with and without #1576.
  • What does not change: which writes mark pages, the capture, the upload path, until the counter says it is worth it.
  • What we do not claim: any gain. The figures we have seen are an outside audit's, from a fork and from another port's notes.
  • How we would prove it: the counter first. A change only if the equal share is large after #1576, then a paired timing after a null pair.

Evidence

Code on forge/main at 430eef4f2:

  • gpu/vk/vk_texture.cpp:2034-2063, texture_dirty: the dirty ranges of a texture come from memory_written_runs (write generations), and for a texture in a virtual pool from a walk of the GPU mappings. No content is read.
  • :3024: a texture that was uploaded and has no dirty range returns. Otherwise the dirty ranges go to upload at :3114.
  • :1574-1594, upload: bytes and time per upload route are already counted (UpStat), so bytes uploaded per frame are known. None counts bytes whose content equals what the image holds.
  • gpu/vk/vk_memory.cpp:1402-1412 and :1675-1700: the capture keeps a shadow copy of each page a texture's storage covers and compares live bytes with it for another purpose (st_differed). A page equal to its copy is therefore cheap to detect at the capture, but nothing uses the answer.
  • #1576 (open, work in progress, opened today): the host compares packaged texture data before writing it and leaves out identical copies in its memcpy and memmove from 4 KB up. Its description reports about 76,000 copies and 970 MB left out in a Market run, and a texture initialised with the same data up to 77 times. That removes a cause on the host side.
  • #1223 (open): a re-upload of only the part a GPU write covered. #750 (open): a GPU-written texture re-uploaded every present on a Deck. Both are different causes of the same symptom.

The fork's claim, not ours: an outside audit of a fork says that after a tour the game rewrote large block-compressed textures every few frames with identical bytes, that a content check in the capture and a hash per unit of the image cut the uploads sharply, and quotes frame rate gains. Those figures come from comments in the fork's source, measured on a lab PC and partly on another port. We use none of them.

Proposed change

  1. A sampled counter, no behaviour change: for every Nth re-upload keep a hash of the staged bytes with the texture and compare with the previous one. Report bytes uploaded, bytes found equal, and the textures involved, once per 600 presents. Any hash will do; we pick our own and measure its cost in the same run.
  2. Only if the equal share is large after #1576: skip a page at the capture when its bytes equal the shadow's last copy (the compare already exists), so it is not treated as a write. This keeps the rest of the model as it is.
  3. Only after that, and only if still large: a hash per unit of the image (a row of blocks or a layer) so only the changed units upload. This is the larger step and interacts with the state machine proposed for slice a; it is not part of this issue's first pass.
  4. A page that flips between two versions (A, B, A) is a policy question for the shadow, not for this issue.

How we would test it

  • Game-free, written first: the comparison rule as a pure function. Pages equal to the shadow's last copy are not writes; pages that differ are; a page that returns to an older version counts as a write; an empty capture changes nothing. This cannot pass on main because the rule does not exist.
  • In the game: the sampled counter on a long route, any GPU, main with #1576 against main without it where possible. First answer: what share of re-uploaded bytes is equal?
  • Only then, if a change is made: paired timings of the replay's upload time and of frames over twice the target, after a main-against-main pair, per the gates in #1493.
  • No speed claim is made now.
  • #1493, track B, slices a and e: whether a write with identical bytes is a change is a rule the memory model has to state.
  • #1576 (open): the host side of the same symptom. #1223, #750 (open): other causes of re-uploads.
  • #1553 (merged): capture reuse and reads from the submission snapshot, in the same area.
  • The issue about torn re-uploads (to be linked): the same capture and shadow, a different question.

New on this forge; not opened on GitHub.

**Type:** performance · **Area:** renderer, texture upload, memory sync · **Part of:** #1493 ## TL;DR A texture is re-uploaded when its guest pages were marked written, whatever bytes were written. If the game, or the host for it, writes the same bytes again, the capture still copies them and the renderer still uploads them. The open pull request #1576 stops the host from marking identical copies; this issue asks what is left after it and whether a content check in the capture is worth its cost. We propose a sampled counter first, and no renderer change until it shows a number. ## Breakdown - **Who it affects:** players in scenes where the game rewrites big textures every few frames. The cost would be upload bandwidth and a slow frame when many come in one frame, not a steady rate. - **What is wrong, by reading:** dirtiness is decided by write generation alone. No code compares what was written with what the image already holds. - **What we propose:** a sampled counter: at every Nth re-upload, hash the bytes about to be staged and compare with a hash kept from the same texture's previous upload; report how many bytes were equal. Run it on main with and without #1576. - **What does not change:** which writes mark pages, the capture, the upload path, until the counter says it is worth it. - **What we do not claim:** any gain. The figures we have seen are an outside audit's, from a fork and from another port's notes. - **How we would prove it:** the counter first. A change only if the equal share is large after #1576, then a paired timing after a null pair. ## Evidence Code on `forge/main` at `430eef4f2`: - `gpu/vk/vk_texture.cpp:2034-2063`, `texture_dirty`: the dirty ranges of a texture come from `memory_written_runs` (write generations), and for a texture in a virtual pool from a walk of the GPU mappings. No content is read. - `:3024`: a texture that was uploaded and has no dirty range returns. Otherwise the dirty ranges go to `upload` at `:3114`. - `:1574-1594`, `upload`: bytes and time per upload route are already counted (`UpStat`), so bytes uploaded per frame are known. None counts bytes whose content equals what the image holds. - `gpu/vk/vk_memory.cpp:1402-1412` and `:1675-1700`: the capture keeps a shadow copy of each page a texture's storage covers and compares live bytes with it for another purpose (`st_differed`). A page equal to its copy is therefore cheap to detect at the capture, but nothing uses the answer. - #1576 (open, work in progress, opened today): the host compares packaged texture data before writing it and leaves out identical copies in its `memcpy` and `memmove` from 4 KB up. Its description reports about 76,000 copies and 970 MB left out in a Market run, and a texture initialised with the same data up to 77 times. That removes a cause on the host side. - #1223 (open): a re-upload of only the part a GPU write covered. #750 (open): a GPU-written texture re-uploaded every present on a Deck. Both are different causes of the same symptom. The fork's claim, not ours: an outside audit of a fork says that after a tour the game rewrote large block-compressed textures every few frames with identical bytes, that a content check in the capture and a hash per unit of the image cut the uploads sharply, and quotes frame rate gains. Those figures come from comments in the fork's source, measured on a lab PC and partly on another port. We use none of them. ## Proposed change 1. A sampled counter, no behaviour change: for every Nth re-upload keep a hash of the staged bytes with the texture and compare with the previous one. Report bytes uploaded, bytes found equal, and the textures involved, once per 600 presents. Any hash will do; we pick our own and measure its cost in the same run. 2. Only if the equal share is large after #1576: skip a page at the capture when its bytes equal the shadow's last copy (the compare already exists), so it is not treated as a write. This keeps the rest of the model as it is. 3. Only after that, and only if still large: a hash per unit of the image (a row of blocks or a layer) so only the changed units upload. This is the larger step and interacts with the state machine proposed for slice a; it is not part of this issue's first pass. 4. A page that flips between two versions (A, B, A) is a policy question for the shadow, not for this issue. ## How we would test it - Game-free, written first: the comparison rule as a pure function. Pages equal to the shadow's last copy are not writes; pages that differ are; a page that returns to an older version counts as a write; an empty capture changes nothing. This cannot pass on main because the rule does not exist. - In the game: the sampled counter on a long route, any GPU, main with #1576 against main without it where possible. First answer: what share of re-uploaded bytes is equal? - Only then, if a change is made: paired timings of the replay's upload time and of frames over twice the target, after a main-against-main pair, per the gates in #1493. - No speed claim is made now. ## Related - #1493, track B, slices a and e: whether a write with identical bytes is a change is a rule the memory model has to state. - #1576 (open): the host side of the same symptom. #1223, #750 (open): other causes of re-uploads. - #1553 (merged): capture reuse and reads from the submission snapshot, in the same area. - The issue about torn re-uploads (to be linked): the same capture and shadow, a different question. New on this forge; not opened on GitHub.
Collaborator

Possibly related, for context:

  • issue #1493 Renderer rewrite — Parent renderer rewrite, includes memory and texture rules
  • PR #1576 WIP: perf: less game work a frame in Castle Town (registers as locals, vector rewrites, unchanged texture data left alone) — Open PR avoids identical host copies being marked as writes; issue investigates remaining redundant uploads
  • issue #1607 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 — Same capture/shadow area, but concerns torn captures rather than unchanged bytes
  • PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Open PR reduces GPU-write re-uploaded regions, a distinct source of excess upload bytes
  • PR #1281 perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open PR hashes ASTC texture content for reuse, but not to suppress unchanged re-uploads
Possibly related, for context: - issue #1493 Renderer rewrite — Parent renderer rewrite, includes memory and texture rules - PR #1576 WIP: perf: less game work a frame in Castle Town (registers as locals, vector rewrites, unchanged texture data left alone) — Open PR avoids identical host copies being marked as writes; issue investigates remaining redundant uploads - issue #1607 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 — Same capture/shadow area, but concerns torn captures rather than unchanged bytes - PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Open PR reduces GPU-write re-uploaded regions, a distinct source of excess upload bytes - PR #1281 perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open PR hashes ASTC texture content for reuse, but not to suppress unchanged re-uploads
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#1608
No description provided.