shader: preserve length-prefixed record names in extraction #240

Merged
Vonsek merged 2 commits from upstream-pr/243 into main 2026-11-21 19:56:26 +00:00
Vonsek commented 2026-11-21 19:05:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:05:29Z.


Change

Add --length-prefixed-names for archives whose record names carry a one-byte length that includes the terminator. In this mode a matching printable length byte stays out of manifest names and output filenames. A matching prefix already present before the printable run takes precedence, so genuine leading punctuation survives.

The default keeps the full printable run. A prefixless 80-byte name beginning with P can be byte-identical to a 79-byte name preceded by the length byte P. The caller chooses the format when it is known.

Verification

Windows 11 build 26200.9974, Visual Studio Build Tools 2022 17.14.45, Python 3.12.10, CMake 3.31.6.

  • python -B tests/rdna2_tools_check.py -k test_extracted_names_round_trip_length_prefixed_records with the initial source-built fixture on f85723e: failed for 33-byte and 125-byte names because the manifest retained their printable prefixes.
  • out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -k test_ambiguous_length_prefix_requires_explicit_mode on the initial PR head a9948d4: reproduced the review report that default extraction removed the P from a prefixless 80-byte name. The opt-in switch was absent at that head.
  • out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -k test_ambiguous_length_prefix_requires_explicit_mode -k test_extracted_names_round_trip_length_prefixed_records: both tests passed at 3fe72f9.
  • cmake --preset dev and cmake --build --preset dev --target root_probe DualUav.cso triangle_ps.cso: configured and built source-owned shader and host fixtures in a fresh build directory.
  • ctest --preset dev --no-tests=error -R '^(rdna2_tools_check|compressed_scene_metadata|dxcontainer_part_offsets)$' -V: 3/3 passed at 3fe72f9. The existing optional LLVM subtest inside rdna2_tools_check skipped locally because the complete LLVM toolchain was unavailable. The other 18 Python tests passed.
  • git diff --check: passed.

Evidence and follow-up

The MIT-licensed regression builds its own archive envelopes. It tests both CLI modes on byte-identical input, verifying both manifest names and output filenames. In explicit mode the extracted names round-trip through pixel_aot.native_program. Further controls cover short names, genuine leading punctuation, the transition from printable length byte 126 to nonprintable 127, a 127-byte name, a legacy name without a recognized prefix, and a truncated record.

A read-only local metadata comparison captured 26,503 records. The default mode emitted the same names and stage counts as the prior extractor. With --length-prefixed-names enabled, 24,795 names lost exactly one byte matching the encoded length. In 191 of those entries, later name bytes also fit a shorter suffix length. The 1,377 distinct names shared by multiple records still require separate lookup context.

For the first 12 pixel manifest entries, enabling the option reduced missing-name errors from 7 to 0 and increased successful native lookups from 2 to 7. The other five lookups reported Expected one aligned, terminated program after name resolution. The comparison retained aggregate metadata only.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533154501 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:05:29Z. --- ## Change Add `--length-prefixed-names` for archives whose record names carry a one-byte length that includes the terminator. In this mode a matching printable length byte stays out of manifest names and output filenames. A matching prefix already present before the printable run takes precedence, so genuine leading punctuation survives. The default keeps the full printable run. A prefixless 80-byte name beginning with `P` can be byte-identical to a 79-byte name preceded by the length byte `P`. The caller chooses the format when it is known. ## Verification Windows 11 build 26200.9974, Visual Studio Build Tools 2022 17.14.45, Python 3.12.10, CMake 3.31.6. - `python -B tests/rdna2_tools_check.py -k test_extracted_names_round_trip_length_prefixed_records` with the initial source-built fixture on `f85723e`: failed for 33-byte and 125-byte names because the manifest retained their printable prefixes. - `out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -k test_ambiguous_length_prefix_requires_explicit_mode` on the initial PR head `a9948d4`: reproduced the review report that default extraction removed the `P` from a prefixless 80-byte name. The opt-in switch was absent at that head. - `out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -k test_ambiguous_length_prefix_requires_explicit_mode -k test_extracted_names_round_trip_length_prefixed_records`: both tests passed at `3fe72f9`. - `cmake --preset dev` and `cmake --build --preset dev --target root_probe DualUav.cso triangle_ps.cso`: configured and built source-owned shader and host fixtures in a fresh build directory. - `ctest --preset dev --no-tests=error -R '^(rdna2_tools_check|compressed_scene_metadata|dxcontainer_part_offsets)$' -V`: 3/3 passed at `3fe72f9`. The existing optional LLVM subtest inside `rdna2_tools_check` skipped locally because the complete LLVM toolchain was unavailable. The other 18 Python tests passed. - `git diff --check`: passed. ## Evidence and follow-up The MIT-licensed regression builds its own archive envelopes. It tests both CLI modes on byte-identical input, verifying both manifest names and output filenames. In explicit mode the extracted names round-trip through `pixel_aot.native_program`. Further controls cover short names, genuine leading punctuation, the transition from printable length byte 126 to nonprintable 127, a 127-byte name, a legacy name without a recognized prefix, and a truncated record. A read-only local metadata comparison captured 26,503 records. The default mode emitted the same names and stage counts as the prior extractor. With `--length-prefixed-names` enabled, 24,795 names lost exactly one byte matching the encoded length. In 191 of those entries, later name bytes also fit a shorter suffix length. The 1,377 distinct names shared by multiple records still require separate lookup context. For the first 12 pixel manifest entries, enabling the option reduced missing-name errors from 7 to 0 and increased successful native lookups from 2 to 7. The other five lookups reported `Expected one aligned, terminated program` after name resolution. The comparison retained aggregate metadata only. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted with Codex.
upstream-sync closed this pull request 2026-11-24 06:41:59 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:41:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:09:50Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9948d4d7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007563359 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#pullrequestreview-6007563359). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:09:50Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `a9948d4d7f` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
Vonsek commented 2026-11-24 06:41:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:13:42Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007599768 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#pullrequestreview-6007599768). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:13:42Z. **Review:** COMMENTED --- _No description provided._
Vonsek commented 2026-11-24 06:47:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:16:27Z.


@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067899746 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#issuecomment-7067899746). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:16:27Z. --- @codex review
chatgpt-codex-connector[bot commented 2026-11-24 06:47:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:19:52Z.


Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 3fe72f9bd1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067941589 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#issuecomment-7067941589). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:19:52Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Keep them coming! **Reviewed commit:** `3fe72f9bd1` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:47:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:05:41Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:19:53.586160Z 3fe72f9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067756050 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#issuecomment-7067756050). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:05:41Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3fe72f9bd10498661c4d696485a0283889ef3df8","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T19:19:53.586160Z">2026-11-21T19:19:53.586160Z</relative-time> | `3fe72f9` | Manual request | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:09:50Z.

Code review location: tools/extract_shaders.py; line 172

@@ -163,7 +164,13 @@ def extract_shaders(
                 if len(program) < 24:
                     continue
 
-                record_name = match.group().decode("ascii", "replace")
+                name = match.group()
+                # The length includes the terminator. A printable length byte can join the name's run.
+                if name[0] == len(name):
+                    name_start = match.start()
+                    if name_start == scan_start or data[name_start - 1] != len(name) + 1:
+                        name = name[1:]

P2 Badge Preserve legacy names that resemble a printable length prefix

For a prefixless record named b"PS_" + b"L" * 77, the printable run is 80 bytes and its first byte is also 80 (P). This condition therefore removes the genuine P, silently changing both the manifest name and output filename to S_.... I reproduced this using envelope(code, name)[1:], the same legacy format retained by the new test: the parent preserves the name, while this commit truncates it. Disambiguate prefixed records from the legacy fallback before removing the first byte; byte-length equality alone also matches legitimate names.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654500392 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#discussion_r4654500392). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:09:50Z. **Code review location:** `tools/extract_shaders.py`; line 172 ~~~~diff @@ -163,7 +164,13 @@ def extract_shaders( if len(program) < 24: continue - record_name = match.group().decode("ascii", "replace") + name = match.group() + # The length includes the terminator. A printable length byte can join the name's run. + if name[0] == len(name): + name_start = match.start() + if name_start == scan_start or data[name_start - 1] != len(name) + 1: + name = name[1:] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve legacy names that resemble a printable length prefix** For a prefixless record named `b"PS_" + b"L" * 77`, the printable run is 80 bytes and its first byte is also 80 (`P`). This condition therefore removes the genuine `P`, silently changing both the manifest name and output filename to `S_...`. I reproduced this using `envelope(code, name)[1:]`, the same legacy format retained by the new test: the parent preserves the name, while this commit truncates it. Disambiguate prefixed records from the legacy fallback before removing the first byte; byte-length equality alone also matches legitimate names. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Vonsek commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:13:42Z.

Code review location: tools/extract_shaders.py; line 172

@@ -163,7 +164,13 @@ def extract_shaders(
                 if len(program) < 24:
                     continue
 
-                record_name = match.group().decode("ascii", "replace")
+                name = match.group()
+                # The length includes the terminator. A printable length byte can join the name's run.
+                if name[0] == len(name):
+                    name_start = match.start()
+                    if name_start == scan_start or data[name_start - 1] != len(name) + 1:
+                        name = name[1:]

The reproducer is valid. The 80-byte prefixless PS_… record and the 79-byte S_… record prefixed by P are byte-identical. Commit 3fe72f9 keeps the old printable-run interpretation by default and adds --length-prefixed-names for callers who know the archive format. The new CLI regression feeds both modes the same bytes and checks the manifest names, filenames, and synthetic payload. Both targeted tests and all three focused CTests passed locally. A guarded metadata comparison also confirmed the default emitted the same 26,503 names as the previous extractor.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654522846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/243#discussion_r4654522846). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:13:42Z. **Code review location:** `tools/extract_shaders.py`; line 172 ~~~~diff @@ -163,7 +164,13 @@ def extract_shaders( if len(program) < 24: continue - record_name = match.group().decode("ascii", "replace") + name = match.group() + # The length includes the terminator. A printable length byte can join the name's run. + if name[0] == len(name): + name_start = match.start() + if name_start == scan_start or data[name_start - 1] != len(name) + 1: + name = name[1:] ~~~~ --- The reproducer is valid. The 80-byte prefixless `PS_…` record and the 79-byte `S_…` record prefixed by `P` are byte-identical. Commit `3fe72f9` keeps the old printable-run interpretation by default and adds `--length-prefixed-names` for callers who know the archive format. The new CLI regression feeds both modes the same bytes and checks the manifest names, filenames, and synthetic payload. Both targeted tests and all three focused CTests passed locally. A guarded metadata comparison also confirmed the default emitted the same 26,503 names as the previous extractor.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!240
No description provided.