Shaders: declared resources and constants of every program and effect (shader-bindings) #147

Manually merged
github merged 1 commit from gh-pr/147/head into gh-pr/147/base 2026-11-26 20:13:16 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 13:02 UTC · original
holdmysocks:claude/shader-bindings → master · +466 −0 · 4 files · 1 commits · merged 2026-11-24 13:15 UTC

What

A reader for the reflection tables in the uncompressed part of shaders.rpf, and a command to print them: sixng shader-bindings [EFFECT_REGEX] [--programs]. The layout was worked out from the data; the code is our own and decodes no shader code.

  • Programs: six counted sections (vertex or mesh, pixel, geometry, two empty, compute). Each program record is followed by a table of the resources it declares (kind, register index, name hash) and the members of its constant buffers (name hash, type, byte offset).
  • Effects (a material's shader): one table for the whole effect with the material's textures (slot in the material's texture list, array or not), the material constant buffer with every parameter's offset, and the samplers by name.
  • A texture record has two name hashes: the shader variable (SpecTexture) and the material parameter (speculartex).

Checked on the game data

  • All 24,804 program records parse one after the other with no gap: 11,018 + 10,944 + 195 + 0 + 0 + 2,647, and the effect count follows directly.
  • 910 of the 910 stated effects are found; 878 have a table (the other 32 are stubs without programs).
  • A constant buffer's member count and size agree with its members' offsets on the cases looked at (standard, weapon, a compute program).
  • Known textures land where earlier work put them: standard has diffusetex, speculartex2, tintpalettetex, an array, speculartex, bumptex in slots 0 to 5.
  • Runs in about 2 s. cargo test -p sixng-core: 153 passed (one new, on a synthetic file).

What this answers for SIX-95, and what it does not

  • Per shader, the list of declared textures, samplers and constant buffers with their indices, matched to parameter hashes: done.
  • Naming the unnamed texture parameters: not possible from these tables. They hold hashes only. Of 139 material texture parameters 48 have no name; for 47 of them the variable hash equals the parameter hash. The tables add the slot, array or not, and the effects that use each one (the command's summary lists all 48).
  • Material textures are not bound to registers. A material passes a list of texture indices and the slot is the position in that list, so register bindings cannot identify them.
  • How the multilayer, tint, stitch and dirt inputs combine is in the shader code, not in these tables. Not done here.

Not decoded

  • The reported pipeline cache layout (header, graphics and compute pipeline records, metadata and code directories) matches what was measured earlier, but this PR does not read the cache.
  • The first part of an effect record (render states, technique and pass tables) and the 140-byte block after each program.
  • Effect records have no length field that was understood: the next record is found by trying positions (the header must parse with program numbers in range and a name table must end exactly there). It finds 910 of 910 here; another build of the game could behave differently.
  • Resource kinds other than texture, sampler, constant buffer and read-write texture are printed as kind_xx; member types other than float vectors and 4x4 matrices as type_xx. The meaning of the scope flags 0x40 and 0x02 is not pinned.
**@⁠holdmysocks** on GitHub · 2026-11-24 13:02 UTC · [original](https://github.com/holdmysocks/SixNG/pull/147) `holdmysocks:claude/shader-bindings` → `master` · +466 −0 · 4 files · 1 commits · merged 2026-11-24 13:15 UTC ## What A reader for the reflection tables in the uncompressed part of `shaders.rpf`, and a command to print them: `sixng shader-bindings [EFFECT_REGEX] [--programs]`. The layout was worked out from the data; the code is our own and decodes no shader code. - **Programs**: six counted sections (vertex or mesh, pixel, geometry, two empty, compute). Each program record is followed by a table of the resources it declares (kind, register index, name hash) and the members of its constant buffers (name hash, type, byte offset). - **Effects** (a material's shader): one table for the whole effect with the material's textures (slot in the material's texture list, array or not), the material constant buffer with every parameter's offset, and the samplers by name. - A texture record has two name hashes: the shader variable (`SpecTexture`) and the material parameter (`speculartex`). ## Checked on the game data - All 24,804 program records parse one after the other with no gap: 11,018 + 10,944 + 195 + 0 + 0 + 2,647, and the effect count follows directly. - 910 of the 910 stated effects are found; 878 have a table (the other 32 are stubs without programs). - A constant buffer's member count and size agree with its members' offsets on the cases looked at (`standard`, `weapon`, a compute program). - Known textures land where earlier work put them: `standard` has `diffusetex`, `speculartex2`, `tintpalettetex`, an array, `speculartex`, `bumptex` in slots 0 to 5. - Runs in about 2 s. `cargo test -p sixng-core`: 153 passed (one new, on a synthetic file). ## What this answers for SIX-95, and what it does not - Per shader, the list of declared textures, samplers and constant buffers with their indices, matched to parameter hashes: **done**. - **Naming the unnamed texture parameters: not possible from these tables.** They hold hashes only. Of 139 material texture parameters 48 have no name; for 47 of them the variable hash equals the parameter hash. The tables add the slot, array or not, and the effects that use each one (the command's summary lists all 48). - Material textures are **not bound to registers**. A material passes a list of texture indices and the slot is the position in that list, so register bindings cannot identify them. - How the multilayer, tint, stitch and dirt inputs combine is in the shader code, not in these tables. Not done here. ## Not decoded - The reported pipeline cache layout (header, graphics and compute pipeline records, metadata and code directories) matches what was measured earlier, but this PR does not read the cache. - The first part of an effect record (render states, technique and pass tables) and the 140-byte block after each program. - Effect records have no length field that was understood: the next record is found by trying positions (the header must parse with program numbers in range and a name table must end exactly there). It finds 910 of 910 here; another build of the game could behave differently. - Resource kinds other than texture, sampler, constant buffer and read-write texture are printed as `kind_xx`; member types other than float vectors and 4x4 matrices as `type_xx`. The meaning of the scope flags 0x40 and 0x02 is not pinned.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:13:16 +00:00
github manually merged commit 4f6b47a06d into gh-pr/147/base 2026-11-26 20:13:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.