Shaders: read both databases and parse effect records in sequence #239

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

@⁠holdmysocks on GitHub · 2026-11-25 03:10 UTC · original
holdmysocks:claude/shader-second-db → master · +453 −154 · 3 files · 1 commits · merged 2026-11-25 03:31 UTC

What

shaders.rpf holds two shader databases and SixNG read only the first. This reads both, and reads each effect record field by field instead of searching for its parts.

  • Second database: 1,699 programs (500 vertex, 1,157 pixel, 42 compute) and 22 effects (the immediate-mode and image-filter ones).
  • Count fix: 24,804 + 1,699 = 26,503 programs. 26,503 is the number of program records the archive holds; the old 24,804 was the first database only. Effects go from 910 to 932.
  • Database header: magic, a 64-bit id, the shared parameter blocks (33 and 3) and a shared variable table (488 and 299 resources).
  • Effect record, in sequence: loaded size, program lists, 0x50 bytes, four state tables (rasterizer 16 bytes an item, depth-stencil 24, blend 0x44, sampler 0x24), techniques, passes, a u32 list, the effect's variable table, a second sized block, the parameter blocks (stored in the record, or a reference to a shared block by key), names.
  • Pass state bits: byte 10 says which states a pass sets (1 rasterizer, 2 depth-stencil, 4 blend, 8 stencil reference); bytes 6 to 9 hold the three indices and the reference.
  • An effect's program numbers count within its own database (Shaders::program).
  • sixng shader-bindings prints the databases, each effect's states and blocks, and each pass's state indices. The parameter index version is bumped so cached copies rebuild with the 22 new effects.

Checked (one install)

  • Both databases walk from the magic to the end of the last effect with no gap: 910 of 910 and 22 of 22 effects read.
  • The size each effect states for itself equals the size worked out from its parts: 932 of 932.
  • Pass state indices: in range when the bit is set, zero when clear, over all 28,798 passes.
  • Shared block references: 3,247, all resolve to a block of the same database (10,432 blocks are stored in the records).
  • Every program of every effect is named by at least one pass (912 effects with programs, 25,037 techniques).
  • Pipeline cache join with both databases: 19,595 of 26,503 programs are a stage of some pipeline (953 from the second database); 316,224 read records, none unmatched.
  • Unit tests: a synthetic archive with two databases, a false magic between them, a cut record and an archive with no database.

Not decoded

  • The fields inside a rasterizer, depth-stencil, blend or sampler item (printed as raw bytes), and whether they agree with the pipeline cache.
  • The 0x50 bytes before the state tables, the u32 list after the passes, the second sized block, the contents of the parameter blocks, the high byte of the block count.
  • A pass's last eight bytes, its bit 0x10 in byte 10, and byte 11.
  • The kind byte of a program (values 50, 60, 64, 65, 66 read as a shader model times ten; not checked against anything).
  • The 140-byte block after each program, as before.

cargo clippy and the full test suite were not run locally; only the two shader reader tests and a type-check of the CLI.

**@⁠holdmysocks** on GitHub · 2026-11-25 03:10 UTC · [original](https://github.com/holdmysocks/SixNG/pull/239) `holdmysocks:claude/shader-second-db` → `master` · +453 −154 · 3 files · 1 commits · merged 2026-11-25 03:31 UTC ## What `shaders.rpf` holds two shader databases and SixNG read only the first. This reads both, and reads each effect record field by field instead of searching for its parts. - **Second database**: 1,699 programs (500 vertex, 1,157 pixel, 42 compute) and 22 effects (the immediate-mode and image-filter ones). - **Count fix**: 24,804 + 1,699 = 26,503 programs. 26,503 is the number of program records the archive holds; the old 24,804 was the first database only. Effects go from 910 to 932. - **Database header**: magic, a 64-bit id, the shared parameter blocks (33 and 3) and a shared variable table (488 and 299 resources). - **Effect record, in sequence**: loaded size, program lists, 0x50 bytes, four state tables (rasterizer 16 bytes an item, depth-stencil 24, blend 0x44, sampler 0x24), techniques, passes, a `u32` list, the effect's variable table, a second sized block, the parameter blocks (stored in the record, or a reference to a shared block by key), names. - **Pass state bits**: byte 10 says which states a pass sets (1 rasterizer, 2 depth-stencil, 4 blend, 8 stencil reference); bytes 6 to 9 hold the three indices and the reference. - An effect's program numbers count within its own database (`Shaders::program`). - `sixng shader-bindings` prints the databases, each effect's states and blocks, and each pass's state indices. The parameter index version is bumped so cached copies rebuild with the 22 new effects. ## Checked (one install) - Both databases walk from the magic to the end of the last effect with no gap: 910 of 910 and 22 of 22 effects read. - The size each effect states for itself equals the size worked out from its parts: 932 of 932. - Pass state indices: in range when the bit is set, zero when clear, over all 28,798 passes. - Shared block references: 3,247, all resolve to a block of the same database (10,432 blocks are stored in the records). - Every program of every effect is named by at least one pass (912 effects with programs, 25,037 techniques). - Pipeline cache join with both databases: 19,595 of 26,503 programs are a stage of some pipeline (953 from the second database); 316,224 read records, none unmatched. - Unit tests: a synthetic archive with two databases, a false magic between them, a cut record and an archive with no database. ## Not decoded - The fields inside a rasterizer, depth-stencil, blend or sampler item (printed as raw bytes), and whether they agree with the pipeline cache. - The 0x50 bytes before the state tables, the `u32` list after the passes, the second sized block, the contents of the parameter blocks, the high byte of the block count. - A pass's last eight bytes, its bit 0x10 in byte 10, and byte 11. - The kind byte of a program (values 50, 60, 64, 65, 66 read as a shader model times ten; not checked against anything). - The 140-byte block after each program, as before. `cargo clippy` and the full test suite were not run locally; only the two shader reader tests and a type-check of the CLI.
shaders.rpf holds two shader databases; only the first was read. The
second adds 1,699 programs and 22 effects (26,503 programs and 932
effects in all).

Effect records are now read field by field instead of being searched
for: the state tables, techniques, passes, the effect's table, the
parameter blocks (stored or shared by key) and the names. A pass gives
the rasterizer, depth-stencil and blend state it sets and its stencil
reference. The database header (shared blocks and a shared table) is
read too.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:20:38 +00:00
github manually merged commit 9973cc90db into gh-pr/239/base 2026-11-26 20:20:40 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.