Reconsider GPU hasher for GPU side page change detection #1355

Open
opened 2026-11-26 17:59:05 +00:00 by github-bot · 2 comments
Owner

@⁠JayFoxRox on GitHub · 2026-11-26 17:55 UTC · original

I've mentioned the hasher in #1273 and this was split into issue #1306 where the GPU hasher only had a minor mention.
However, my overall criticism of the GPU hasher system was lost, so I'm additionally creating this issue.


There's a GPU hasher in VIctory which hashes GPU pages on (what are assumed to be) free GPU compute resources.
It's a cool idea and it was done because the developers system had leftover GPU compute resources.

However, on other machines this might not hold true and there might not be spare GPU compute.
It also doesn't consider the effects on VRAM memory bandwidth / overall performance impact.

Instead, identifiying the root cause of the GPU side changes (= which GPU shader modified them and why?) could help to only run the hasher on GPU resources which are potentially modified OR to let the shader itself communicate wether (and which) resources got updated (something like a resource-dirty flag).

This could happen by shader analysis, learning shader behaviour(by observing runtime behaviour, which might be faulty approach as rare cases could remain undetected) or potentially other means.

With #1306 there is also another alternative where GPU resources would only be hashed on demand if and when the CPU tries to read from them. However, this could be potentially also be replaced by shader analysis / identifying if it's just poor CPU code which tries to read static GPU resources (comparable to accidental read on write-combine) or actually necessary (read on a resource which might have changed due to some GPU behaviour / shader execution).

**@⁠JayFoxRox** on GitHub · 2026-11-26 17:55 UTC · [original](https://github.com/fxceless/victory-fork/issues/1355) I've mentioned the hasher in #1273 and this was split into issue #1306 where the GPU hasher only had a minor mention. However, my overall criticism of the GPU hasher system was lost, so I'm additionally creating this issue. --- There's a GPU hasher in VIctory which hashes GPU pages on (what are assumed to be) free GPU compute resources. It's a cool idea and it was done because the developers system had leftover GPU compute resources. However, on other machines this might not hold true and there might not be spare GPU compute. It also doesn't consider the effects on VRAM memory bandwidth / overall performance impact. Instead, identifiying the root cause of the GPU side changes (= which GPU shader modified them and why?) could help to only run the hasher on GPU resources which are potentially modified OR to let the shader itself communicate wether (and which) resources got updated (something like a resource-dirty flag). This could happen by shader analysis, learning shader behaviour(by observing runtime behaviour, which might be faulty approach as rare cases could remain undetected) or potentially other means. With #1306 there is also another alternative where GPU resources would only be hashed on demand if and when the CPU tries to read from them. However, this could be potentially also be replaced by shader analysis / identifying if it's just poor CPU code which tries to read static GPU resources (comparable to accidental read on write-combine) or actually necessary (read on a resource which might have changed due to some GPU behaviour / shader execution).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:59:05 +00:00
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 19:00 UTC · original

Agreed on the criticism, and I would rather turn it into a measurement than an argument, because the arithmetic decides it either way.

The cheap numbers, and which of them need a card:

  1. How many GPU pages does the CPU actually read per frame? No card needed - that is the guard-page side, and my recorder already counts fault sites per frame. If that number is small, then hashing on demand (#1306) wins on arithmetic alone, regardless of how cheap the hasher looks on one machine.
  2. How many distinct shader -> resource write relationships exist? No card needed either: that is static analysis of the shader inputs we already parse in the RPF path. It bounds how many "dirty flag" sites a shader-side solution would touch.
  3. What does the hasher actually cost in VRAM bandwidth? This one needs a card. The useful form is not an average but a distribution: same workload, pool hashed vs not hashed, compare p99 frame time and the streaming stalls. An average will hide exactly the stalls that the hasher causes, which is what the "leftover compute" assumption gets wrong.

One more thing the hasher assumption understates: "free compute" competes with whatever else wants the async queue at the same time, and that contention shows up as tail latency rather than throughput. So a hasher that looks free in an average can still be the reason a texture arrived a frame late.

If you want, I can make the recorder report "pages read but unchanged" as a separate bucket - that is the number that says whether #1306 is a real optimisation or just avoids a fault that would not have mattered. It is the same recorder, one more counter.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 19:00 UTC · [original](https://github.com/fxceless/victory-fork/issues/1355#issuecomment-7201091929) Agreed on the criticism, and I would rather turn it into a measurement than an argument, because the arithmetic decides it either way. The cheap numbers, and which of them need a card: 1. How many GPU pages does the CPU actually read per frame? No card needed - that is the guard-page side, and my recorder already counts fault sites per frame. If that number is small, then hashing on demand (#1306) wins on arithmetic alone, regardless of how cheap the hasher looks on one machine. 2. How many distinct shader -> resource write relationships exist? No card needed either: that is static analysis of the shader inputs we already parse in the RPF path. It bounds how many "dirty flag" sites a shader-side solution would touch. 3. What does the hasher actually cost in VRAM bandwidth? This one needs a card. The useful form is not an average but a distribution: same workload, pool hashed vs not hashed, compare p99 frame time and the streaming stalls. An average will hide exactly the stalls that the hasher causes, which is what the "leftover compute" assumption gets wrong. One more thing the hasher assumption understates: "free compute" competes with whatever else wants the async queue at the same time, and that contention shows up as tail latency rather than throughput. So a hasher that looks free in an average can still be the reason a texture arrived a frame late. If you want, I can make the recorder report "pages read but unchanged" as a separate bucket - that is the number that says whether #1306 is a real optimisation or just avoids a fault that would not have mattered. It is the same recorder, one more counter.
Author
Owner

@⁠JayFoxRox on GitHub · 2026-11-26 19:34 UTC · original

re 1. Also note that hashing on demand might cause latency, hence the idea to do static analysis (for shaders to mark resources dirty themselves) OR always load pages but only when actually necessary (which is suitable if the current code finds that pages are almost always updated anyway = no need to check through hash). Remember that there might be readbacks which shouldn't be necessary / don't need any download (like accidental write-combine read on static resource) which would be excluded [1].
re 2. Yes.
re 3. You can't measure this easily. You'd only have the measurement on your developer machine (or user submitted results if measurement code lives in VIctory and results get crowdsourced) but the ultimate goal is to distribute this project to end users who won't submit measurements (in particular if there game runs so slow that they don't see point in submitting). In fact, supporting lower end machines is also a goal, so we have to assume that there's no spare GPU compute or VRAM bandwidth available (as you also implied in one of your paragraphs re async queue).

"pages read but unchanged" would be a poor metric for deciding about #1306, because that is about removing the overhead to even reach the code where such a metric would be recorded (it's useful independent of wether the fault matters, unless that number is 0.. in which case the fault handler is useless).

  • The metric for #1306 should be how often the page fault handler runs, because reaching it (CPU exception / kernel round-trip) is very expensive. #1306 and #1307 are basically no-brainers (unless the handlers trigger very rarely, which would be unexpected, but even then there's a latency argument).
  • The metric for GPU hasher is the GPU -> CPU transfer frequency / probability. If it was a very high percentage then no hashing (or alternative to it, like proposed in this issue, like shader analysis) is necessary: because overhead of hashing would be more expensive then downloading unconditionally. Otherwise (expected), try things like shader analysis / page dirty flags controlled by shader to replace GPU hasher to separate static and dynamic (and potentially modified) resources.

Footnotes:
[1] This also affects your "pages read but unchanged" measurement - it must be a per-page-read-code-location measurement, potentially even respecting the call stack OR a per-resource/associated-with-shared-X thing. It's certainly not trivial to formulate the actual scope.

**@⁠JayFoxRox** on GitHub · 2026-11-26 19:34 UTC · [original](https://github.com/fxceless/victory-fork/issues/1355#issuecomment-7201737075) re 1. Also note that hashing on demand might cause latency, hence the idea to do static analysis (for shaders to mark resources dirty themselves) OR always load pages but only when actually necessary (which is suitable if the current code finds that pages are almost always updated anyway = no need to check through hash). Remember that there might be readbacks which shouldn't be necessary / don't need any download (like accidental write-combine read on static resource) which would be excluded [1]. re 2. Yes. re 3. You can't measure this easily. You'd only have the measurement on your developer machine (or user submitted results if measurement code lives in VIctory and results get crowdsourced) but the ultimate goal is to distribute this project to end users who won't submit measurements (in particular if there game runs so slow that they don't see point in submitting). In fact, supporting lower end machines is also a goal, so we have to assume that there's no spare GPU compute *or* VRAM bandwidth available (as you also implied in one of your paragraphs re async queue). "pages read but unchanged" would be a poor metric for deciding about #1306, because that is about removing the overhead to even reach the code where such a metric would be recorded (it's useful independent of wether the fault matters, unless that number is 0.. in which case the fault handler is useless). - The metric for #1306 should be how often the page fault handler runs, because reaching it (CPU exception / kernel round-trip) is very expensive. #1306 and #1307 are basically no-brainers (unless the handlers trigger very rarely, which would be unexpected, but even then there's a latency argument). - The metric for GPU hasher is the GPU -> CPU transfer frequency / probability. If it was a very high percentage then no hashing (or alternative to it, like proposed in this issue, like shader analysis) is necessary: because overhead of hashing would be more expensive then downloading unconditionally. Otherwise (expected), try things like shader analysis / page dirty flags controlled by shader to replace GPU hasher to separate static and dynamic (and potentially modified) resources. **Footnotes:** [1] *This also affects your "pages read but unchanged" measurement - it must be a per-page-read-code-location measurement, potentially even respecting the call stack OR a per-resource/associated-with-shared-X thing. It's certainly not trivial to formulate the actual scope.*
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
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
github/fxceless--victory-fork#1355
No description provided.