Resource labels: name GPU resources with content hashes #1309

Open
opened 2026-11-26 13:36:53 +00:00 by github-bot · 3 comments
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 13:34 UTC · original

Suggestion from the discussion below, kept here so the issue states the current plan.

Label = kind + content hash (+ size). No game knowledge inside the label. The source archive name and the offset are not always known at upload time, so they are not inputs.

The hash lives in the D3D compatibility layer, where GPU resources are uploaded and downloaded, independent of game code. The Victory-side code only ever sees content; anything game-specific has to come from outside.

Names come from an external table, keyed by (kind, hash):

  • an RPF-side export (textures, vertex/index buffers) that maps hash -> asset name. Kept outside Victory, e.g. an rpf explorer fork that can export these.
  • Victory's own shader RPF handling, keyed before DXIL translation, so the key sees RDNA2 structures rather than our translator's output.

Unrecognised hashes are a diagnostic, not a failure. A resource we cannot name is likely either generated at runtime or corrupted on the CPU -> GPU upload path, so it should surface as its own counter rather than being silently skipped.

Second consumer: texture downscaling for lower memory usage - an allow/deny list keyed by the same content hash. That is the argument for making the hash canonical rather than per-feature.

Open questions:

  1. Hash choice (xxh3-64 vs truncated blake3). Once tables exist it cannot change without a table version, so it has to be decided up front.
  2. For shaders: key on the container bytes as read from the RPF, or on the pre-translation input we hand to the translator? The first survives translator changes; the second matches what we actually compile. They will diverge.

Acceptance (revised):

  1. A labeler that takes (kind, bytes) and produces a stable label - unit tested, no GPU needed.
  2. A table format, a loader and a lookup - unit tested.
  3. An unrecognised-resource counter and a report.
  4. One PIX/RenderDoc capture showing the labels, once hardware is available.
**@⁠liuycsbxbxn** on GitHub · 2026-11-26 13:34 UTC · [original](https://github.com/fxceless/victory-fork/issues/1309) Suggestion from the discussion below, kept here so the issue states the current plan. **Label = kind + content hash (+ size). No game knowledge inside the label.** The source archive name and the offset are not always known at upload time, so they are not inputs. **The hash lives in the D3D compatibility layer**, where GPU resources are uploaded and downloaded, independent of game code. The Victory-side code only ever sees content; anything game-specific has to come from outside. **Names come from an external table**, keyed by (kind, hash): - an RPF-side export (textures, vertex/index buffers) that maps hash -> asset name. Kept outside Victory, e.g. an rpf explorer fork that can export these. - Victory's own shader RPF handling, keyed **before DXIL translation**, so the key sees RDNA2 structures rather than our translator's output. **Unrecognised hashes are a diagnostic, not a failure.** A resource we cannot name is likely either generated at runtime or corrupted on the CPU -> GPU upload path, so it should surface as its own counter rather than being silently skipped. **Second consumer:** texture downscaling for lower memory usage - an allow/deny list keyed by the same content hash. That is the argument for making the hash canonical rather than per-feature. Open questions: 1. Hash choice (xxh3-64 vs truncated blake3). Once tables exist it cannot change without a table version, so it has to be decided up front. 2. For shaders: key on the container bytes as read from the RPF, or on the pre-translation input we hand to the translator? The first survives translator changes; the second matches what we actually compile. They will diverge. Acceptance (revised): 1. A labeler that takes (kind, bytes) and produces a stable label - unit tested, no GPU needed. 2. A table format, a loader and a lookup - unit tested. 3. An unrecognised-resource counter and a report. 4. One PIX/RenderDoc capture showing the labels, once hardware is available.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:36:53 +00:00
Author
Owner

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

re 1:

A helper that builds a label from (kind, hash prefix, source archive name, offset) and is used at upload for textures, buffers and shader/pipeline objects.

I don't think the source-archive name etc. are always known.

This hashing would have to live in the D3D compatibility layer where GPU resources are uploaded / downloaded, independent of the game-code.
So the portion in VIctory would only have access to the content but not to any game-specific knowledge (unless further stack analysis was added, but even then tracking sources for the game data would be difficult).

The proposal is to exclusively hash the buffer content (and lookup the name from a hashmap).

The hashmap would be built from things such as:

  • Tools like rpf explorers (which require a fork/feature enhancements to allow such export) to associate things like texture or mesh vertex/index buffers with their actual name from the game resource files. Doing all this parsing within VIctory might be out of VIctory scope.
  • VIctory has its own rpf handling for shaders which could be used to create a hashtable on the shader inputs before DXIL translation.

More motivation:

Knowing the resource name at runtime (outside of D3D12) might be helpful when analyzing UMA emulation or shader bugs.

Another example would be texture downscaling to lower memory usage: by identifying the corresponding game resource using the content hash, there could be a allow/denylist for texture downscaling.
So while this debug labelling is obviously a slow/debug feature, a faster variant could be designed if it's deemed useful (which can be figured out by doing the slow content hashing).


If such a change in VIctory is unwanted, a script for handling PIX or RenderDoc (traces or API) could be made to hash the content in those tools and to find and assign names then. However, for things like shaders, a lot of the original information would already be lost (as traces would work on VIctory DXIL rather than hashing RDNA2 structures, so hashtables would need to update with VIctory code changes).

The idea for this came from my previous work on an original Xbox emulator (which also uses UMA). There, we successfully used GL debug labels to communicate CPU side addresses of GL resources initially to ease debugging. Later I also added content hashes for testing hacks/workarounds in specific games - it had led to many compatibility and performance related improvements by providing context about the games intent. Dynamicly generated and broken resources were also identifieable (as unrecognized resources likely got corrupted along the CPU -> GPU upload path or they were generated on the fly).

**@⁠JayFoxRox** on GitHub · 2026-11-26 17:27 UTC · [original](https://github.com/fxceless/victory-fork/issues/1309#issuecomment-7199054574) re 1: > A helper that builds a label from (kind, hash prefix, source archive name, offset) and is used at upload for textures, buffers and shader/pipeline objects. I don't think the source-archive name etc. are always known. This hashing would have to live in the D3D compatibility layer where GPU resources are uploaded / downloaded, independent of the game-code. So the portion in VIctory would only have access to the content but not to any game-specific knowledge (unless further stack analysis was added, but even then tracking sources for the game data would be difficult). The proposal is to exclusively hash the buffer content (and lookup the name from a hashmap). The hashmap would be built from things such as: - Tools like rpf explorers (which require a fork/feature enhancements to allow such export) to associate things like texture or mesh vertex/index buffers with their actual name from the game resource files. Doing all this parsing within VIctory might be out of VIctory scope. - VIctory has its own rpf handling for shaders which could be used to create a hashtable on the shader inputs before DXIL translation. --- More motivation: Knowing the resource name at runtime (outside of D3D12) might be helpful when analyzing UMA emulation or shader bugs. Another example would be texture downscaling to lower memory usage: by identifying the corresponding game resource using the content hash, there could be a allow/denylist for texture downscaling. So while this debug labelling is obviously a slow/debug feature, a faster variant could be designed if it's deemed useful (which can be figured out by doing the slow content hashing). --- If such a change in VIctory is unwanted, a script for handling PIX or RenderDoc (traces or API) could be made to hash the content in those tools and to find and assign names then. However, for things like shaders, a lot of the original information would already be lost (as traces would work on VIctory DXIL rather than hashing RDNA2 structures, so hashtables would need to update with VIctory code changes). The idea for this came from my previous work on an original Xbox emulator (which also uses UMA). There, we successfully used GL debug labels to communicate CPU side addresses of GL resources initially to ease debugging. Later I also added content hashes for testing hacks/workarounds in specific games - it had led to many compatibility and performance related improvements by providing context about the games intent. Dynamicly generated and broken resources were also identifieable (as unrecognized resources likely got corrupted along the CPU -> GPU upload path or they were generated on the fly).
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 17:30 UTC · original

Agreed on all three constraints: drop the archive name and offset from the label, keep the hashing in the compatibility layer where upload/download happens, and resolve names from a table instead of trying to know them. Let me restate the scope that follows, so we are arguing about the same thing:

  • Label content: kind + content hash only (plus size, which is free at upload). No game knowledge inside the label.
  • Two table producers: (a) an RPF-side export (textures, vertex/index buffers) that maps hash -> asset name, kept outside Victory; (b) Victory's own shader RPF handling, keyed before DXIL translation, so the hash still sees RDNA2 structures rather than our translator's output.
  • Unrecognised hashes are the interesting bucket, not a failure. Per your Xbox experience, a resource we cannot name is likely either generated at runtime or corrupted on the upload path, so it is worth surfacing as its own diagnostic counter rather than hiding it.
  • The texture-downscaling allow/deny list is a good second consumer of the same table, and it is the argument for making the hash canonical rather than per-feature.

Two questions before I prototype anything:

  1. Hash choice: something stable across machines and cheap enough to run on every upload (xxh3-64, or truncated blake3)? Since the table is generated offline, the only hard requirement is that we never change the hash later without a version bump in the table.
  2. For shaders: should the key be the RDNA2 container bytes as read from the RPF, or the pre-translation input we hand to the translator? The first survives translator changes, the second captures what we actually compile - they will diverge.

If that shape is right, the part I can build and test without a card is the labeler, the table lookup and the unrecognised-resource report.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 17:30 UTC · [original](https://github.com/fxceless/victory-fork/issues/1309#issuecomment-7199147724) Agreed on all three constraints: drop the archive name and offset from the label, keep the hashing in the compatibility layer where upload/download happens, and resolve names from a table instead of trying to know them. Let me restate the scope that follows, so we are arguing about the same thing: - Label content: kind + content hash only (plus size, which is free at upload). No game knowledge inside the label. - Two table producers: (a) an RPF-side export (textures, vertex/index buffers) that maps hash -> asset name, kept outside Victory; (b) Victory's own shader RPF handling, keyed before DXIL translation, so the hash still sees RDNA2 structures rather than our translator's output. - Unrecognised hashes are the interesting bucket, not a failure. Per your Xbox experience, a resource we cannot name is likely either generated at runtime or corrupted on the upload path, so it is worth surfacing as its own diagnostic counter rather than hiding it. - The texture-downscaling allow/deny list is a good second consumer of the same table, and it is the argument for making the hash canonical rather than per-feature. Two questions before I prototype anything: 1. Hash choice: something stable across machines and cheap enough to run on every upload (xxh3-64, or truncated blake3)? Since the table is generated offline, the only hard requirement is that we never change the hash later without a version bump in the table. 2. For shaders: should the key be the RDNA2 container bytes as read from the RPF, or the pre-translation input we hand to the translator? The first survives translator changes, the second captures what we actually compile - they will diverge. If that shape is right, the part I can build and test without a card is the labeler, the table lookup and the unrecognised-resource report.
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 17:56 UTC · original

Prototype is up for the CPU side: 26 tests, green, no warnings. A labeler, an XXH64 behind a ContentHasher trait, a text table with version/algo headers, and an unrecognised-resource report.

Three things I made concrete that you may want to push back on:

  • the lookup key is (kind, hash) and not size, so a downscaled texture keeps its identity - which is what the downscaling allow/deny list needs.
  • the table carries its algorithm name and version, and loading fails if the hasher disagrees. A hash change that silently turns into "everything is unrecognised" is the worst failure mode here, because it looks like every resource is dynamic.
  • unrecognised entries are aggregated per (kind, hash) and reported hottest first, so "generated at runtime" and "corrupted on the upload path" can be told apart by count and by whether the hash is stable across runs.

XXH64 is a placeholder behind the trait, so your call on xxh3-64 vs truncated blake3 is a one-file change plus a table version bump. Still waiting on that and on which shader bytes to key on before I wire anything into the upload path.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 17:56 UTC · [original](https://github.com/fxceless/victory-fork/issues/1309#issuecomment-7199871708) Prototype is up for the CPU side: 26 tests, green, no warnings. A labeler, an XXH64 behind a ContentHasher trait, a text table with version/algo headers, and an unrecognised-resource report. Three things I made concrete that you may want to push back on: - the lookup key is (kind, hash) and not size, so a downscaled texture keeps its identity - which is what the downscaling allow/deny list needs. - the table carries its algorithm name and version, and loading fails if the hasher disagrees. A hash change that silently turns into "everything is unrecognised" is the worst failure mode here, because it looks like every resource is dynamic. - unrecognised entries are aggregated per (kind, hash) and reported hottest first, so "generated at runtime" and "corrupted on the upload path" can be told apart by count and by whether the hash is stable across runs. XXH64 is a placeholder behind the trait, so your call on xxh3-64 vs truncated blake3 is a one-file change plus a table version bump. Still waiting on that and on which shader bytes to key on before I wire anything into the upload path.
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#1309
No description provided.