Commit Graph

39 Commits

Author SHA1 Message Date
157038f7b0 Merge pull request #1648 from xel1uz/fix/feature-scan-atomic-out
feature_scan: write --out atomically and keep the existing report on failure
2026-11-29 19:28:18 +01:00
7c2de8a936 pso_code_base_pairs: count PSOs by code-base stage (SHADER-CODEBASE-PAIRS)
docs/d3d12_vulkan.md §5.2 leaves the push-constant shape open and says to decide after measuring how many
real PSOs have two code-base stages; row 14 of the docs/boot.md checklist asks the same thing, and
tools/feature_scan.py's header says the pairing is in the executable, not in shaders.rpf. It is in shaders.rpf:
the pipeline library names a program per stage slot, and a stage's resource-layout blob ends with the HASH
digest of the container its code came from, so a stage joins to that program's `uses_code_base` in the
translation index through the container shader_carve.py carved.

The new tool reads the library, as an archive or as a saved library, joins
PSO -> stage slot -> program -> digest -> carved container -> spirv/index.json row, and prints counts only:
graphics PSOs by the number of code-base stages, those stages, the stage slots, the per-stage program counts
and the records it could not resolve. --out writes the same counts as JSON and refuses to name one of its own
inputs.

Measured on Xbox 1.0.2.1 (library 0x65F41EDD 930.048.020, 25,471 graphics records): no PSO has two code-base
stages. 25,027 have none and 444 exactly one - 343 MS, 60 PS, 41 VS - in a corpus of 13,383 VS+PS, 10,726
MS+PS, 1,336 MS, 24 VS and 2 VS+PS+slot 6; 21 records stay unknown because a stage's program is not in the
carve output. Its per-stage program counts (38 VS, 46 PS, 260 MS, 263 CS) are lower than the corpus's own
54 / 93 / 266 / 263: the library holds a second compiled form of 6,522 carved shaders and a program can serve
two slots.

So one 144-byte block with one code base at dwords 34-35 is enough for this package, and the runtime's refusal
of a pair where both stages read it can stand. docs/d3d12_vulkan.md §5.2 and its question 14, docs/boot.md
row 14 and docs/shader_library.md §4 and §6 say so; the stale pairing line in feature_scan.py's header is
corrected, and shader_library.py's header now says slot 6 is used by the 2 records that also have VS and PS.

tests/test_pso_code_base_pairs.py builds the library, the carve folder and both translation-index shapes from
bytes: 9 tests, no game data. The tool's __main__ block sets errors="replace" on stdout like every other tool,
which tests/test_tool_stdout_encoding.py checks. Also run: compileall, scripts/check_no_game_data.py,
test_shader_library.py (21) and test_text_write_line_endings.py (3). Whole-suite comparison, `python -I
scripts/run_semantic_tests.py tests -j 4` on Windows 11: plain 89d7dfcf5 reports 522 files, 8,099 tests, 42 files
failed; with this commit 523 files, 8,108 tests, 42 files failed - the two lists differ only by
test_run_wine_tests and test_build_batch_launch, which both pass alone on this machine and fail under -j 4 on a
loaded box. Those 42 are unchanged by this commit: 30 are pytest-based files that `python -I` cannot import and 6
more are script-style files the runner collects nothing from (ci.yml:87 runs both kinds elsewhere), plus the
Windows-only failures in test_world_names, test_bink_names, test_opus_tags, test_ci_registration and
test_mesh_alloc_single_writer. All of them are filed as findings on #14.

Claimed in the coordination issue as SHADER-CODEBASE-PAIRS (issue #14, comment 7146787349). AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:04:41 -05:00
362b854007 feature_scan: write --out atomically and keep the old report on failure
Write JSON to a same-directory temporary file and replace the report only after serialization succeeds. On write failure, keep the existing report and remove the temporary file; preserve the current error message and exit code.

Evidence (run from /home/hampa/work/leonida-feature-scan):

Tests:
- Original: git checkout upstream/main -- tools/feature_scan.py && /home/hampa/work/.venv/bin/python -m pytest tests/test_feature_scan.py -q -> rc 1; 1 failed, 15 passed. The existing report was empty instead of the 23-byte sentinel.
- Fixed: git checkout HEAD -- tools/feature_scan.py && /home/hampa/work/.venv/bin/python -m pytest tests/test_feature_scan.py -q -> rc 0; 16 passed.

File-size-limit reproduction (synthetic shaders only):
- Setup: mkdir -p /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/shaders/dxbc /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/out; python3 -c 'import json,sys; json.dump([{"stage":"synthetic_stage_"+str(i)+"_"+("x"*80)} for i in range(40)], open(sys.argv[1],"w"))' /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/shaders/dxbc/index.json; printf '{"previous": "sentinel report"}\\n' > /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/out/report.json
- Before: bash -c 'ulimit -f 1; python3 -I -B tools/feature_scan.py "$1" --out "$2" >/dev/null' _ /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/shaders /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/out/report.json -> rc 2; report 32 bytes before, 1024 bytes after (old contents replaced by partial JSON).
- After: bash -c 'trap "" XFSZ; ulimit -f 1; python3 -I -B tools/feature_scan.py "$1" --out "$2" >/dev/null' _ /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/shaders /home/hampa/.hermes/profiles/mikuling/cache/scratch/feature-scan-ulimit1.hlUt9B/out/report.json -> rc 2; report 32 bytes before and after, with no temp file remaining.
2026-11-25 07:58:47 +01:00
772efbb17a feature_scan: ask report_paths for the report-path guard 2026-11-24 21:25:13 +01:00
19240dbcd3 Count only JSON true for SPIR-V code-base use 2026-11-23 16:23:49 -03:00
50c398d9f1 docs: point feature_scan at its --help usage line (#6542)
Squash-merged after diff review of PR #6542
2026-11-23 12:49:32 -06:00
775287b7da Count distinct FSSM payloads in G-buffer census cohorts (#6726)
Squash-merged after diff review of PR #6726
2026-11-23 10:50:58 -06:00
d239fd8556 tools: accept UTF-8 BOM JSON inputs in ten utilities (#6779)
Squash-merged after diff review of PR #6779 - tools: fix BOM-prefixed JSON inputs in 10 utilities (batch 01)
2026-11-23 09:56:38 -06:00
e5012d4379 Merge pull request #4579 from Lucas
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:16:06 -05:00
cae4e87be3 feature_scan: protect the corpus index from hard-linked report paths 2026-11-22 22:10:27 -05:00
3ae8e1e27b feature_scan: reject report paths that resolve into the corpus 2026-11-22 21:42:51 -05:00
d657527348 Tools: distinguish InnerCoverage metadata absence from unknown 2026-11-22 21:50:33 -04:00
663a238009 Merge pull request #3185 from Marco Luzzaro 2026-11-22 15:15:31 -05:00
08751b06f3 Merge pull request #2959 from Kal0s-design 2026-11-22 15:13:35 -05:00
3aab8eda2b Report feature scan output write errors 2026-11-22 20:38:17 +01:00
0ea2dd6d5c feature_scan: scan the listings in sorted order
scan_disasm followed os.listdir, and its report keeps its keys in the order
they are first seen (wave_mma_ops, ordered_or_gws_ops and the per-stage
counts). The same folder therefore gave a different JSON file on NTFS (name
order) and on ext4 (hash order), against the rule that the same input gives
the same bytes on every platform.

Sort the listing. The test builds two hand-written listings and forces the
listing order both ways; it fails on the old code and passes now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 19:55:21 +01:00
bf785cc204 fix(tools): invalidate permutation selectors on carry writes
A carry or scale flag can overwrite a known scalar selector through the second destination, inflating the feature scan counts.
2026-11-22 18:20:29 +01:00
23c6147946 Merge pull request #1811 from Vonsek 2026-11-22 09:48:23 -05:00
364d9a465a feature_scan: INVALID is modelled; d3d12_vulkan.md answers open question 16
A literal V# word 3 with FORMAT 0 (an unbound descriptor) reads 0 on the
hardware and in the translator, so it is not listed as a format the
translator lacks. Row 16 gets the counts over the 1.0.2.1 corpus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:23:28 +01:00
0fc69a771b feature_scan: answer open question 16 (UAV counters, typed buffer formats)
PSV0 resource bindings give the structured UAVs with a counter and the
typed buffer SRVs/UAVs; the listings give the MTBUF instruction formats
and, for MUBUF *_format ops, where V# word 3 comes from in the access's
basic block (literal, scalar load, computed, an earlier block or a
shader input). Formats are checked against rdna2spirv.Gen.FORMATS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:23:28 +01:00
ec9b6cf22b tools: text reports are written with LF line ends on every platform (BUILD-468)
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.

AI-assisted (Claude), on behalf of dev-ewann.
2026-11-22 14:20:30 +00:00
d92a395e10 feature_scan: refuse a --out inside the shader corpus it reads
`feature_scan.py <shaders> --out <shaders>/dxbc/index.json` wrote the report
over the corpus index and printed the counts with exit 0, so the next run of
the same command failed with "is not a shader list" and the shaders stage of
make_game.py had to be run again. A scanned .dxbc, a listing in dxbc/disasm
and the spirv/index.json the scan reads had the same problem.

--out is now checked against those inputs before anything is read: one line
and exit 2 naming the path, and nothing is written. Report paths outside the
shader folders are unchanged, including the missing-folder creation.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-22 06:44:57 -06:00
89cf18645e Merge pull request #1428 from Dominik 2026-11-22 06:38:01 -05:00
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00:00
7e7415618d feature_scan.py: keep invalid index fields from aborting the scan 2026-11-22 12:14:32 +01:00
e6e1694ca3 feature_scan: report malformed index shapes without a traceback 2026-11-22 03:26:52 -06:00
1b47daac4f Merge pull request #1092 from bbareth 2026-11-22 02:09:04 -05:00
523d79d63d feature_scan.py: shader variants that share an original name keep their own stages
main() built stage_of from the file stems, then overwrote it with the
original shader names. Two variants with the same original name but
different stages (same.dxbc as gs, same~1.dxbc as ms) both took the last
one's stage, so the disassembly counts gave {'ms': 2}. File stems now win;
original names are only a fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 07:52:57 +01:00
ef54f9e61b feature_scan, turing_atlas: create the --out folder instead of losing the run
Both tools opened --out with a bare open(..., "w"), so a path whose parent does
not exist threw FileNotFoundError after the whole scan or the whole compile run
had already finished (#934 is the same defect in hashdict.py). awc_manifest.py
and the other tools create the parent first; these two now do the same.

Tests: the existing CLI fixtures run each tool with --out inside a nested folder
that does not exist, and assert a clean exit and the file landing there. Both
fail without the change: feature_scan reports "FAIL --out creates a missing
folder", turing_atlas raises the FileNotFoundError the fix removes.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-21 23:19:04 -06:00
ff650ecefd feature_scan.py: count v_perm_b32 selector byte classes and document corpus counts 2026-11-22 02:50:50 +00:00
e5e35ef6e8 feature_scan.py: a missing or unreadable shaders folder is one line
main() opened <shaders>/dxbc/index.json straight away, so a mistyped
path, a file, a work folder whose shaders stage hasn't run, a broken
index.json and one that isn't a list all ended in tracebacks
(FileNotFoundError, NotADirectoryError, JSONDecodeError,
AttributeError). Each now prints one line naming the path, and what to
run when the index is missing, and exits 2 before --out is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:45:43 +01:00
c6194c7495 feature_scan.py: check DXBC part bounds before counting features 2026-11-22 00:59:52 +01:00
7356096650 Merge pull request #397 from Rayhan Robin 2026-11-21 18:43:25 -05:00
cdaaebcac0 Tools: report a short OSG1 signature instead of aborting feature_scan
streams() read `count` 32-byte elements at `first` without checking the part
length, so a truncated OSG1 raised struct.error out of scan_dxbc and killed the
whole count-only scan. Treat a signature whose element table does not fit (or
whose first element overlaps the 8-byte count/offset header) as carrying no
stream information, matching the existing len(sig) < 8 case. Well-formed
signatures are read exactly as before.

Synthetic regression test in tests/test_feature_scan.py: it fails on
unmodified main with struct.error and passes with the fix; a work folder with
one truncated OSG1 still prints the summary and keeps the real stream-1 count.
No game data, no GPU. Full CPU suite: 1559 passed, 150 skipped, 1 xfailed;
semantic suite: 423 passed; compileall and --help clean.

New BUILD item claimed in #374. AI-assisted (OpenCode).
2026-11-21 17:34:45 -06:00
186d8793cd feature_scan: say which DS counter ops the ordered/GWS group includes
AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:39:19 +01:00
e8a07da4ff feature_scan: count s_getpc_b64 kept for code-embedded data per stage; d3d12_vulkan.md: answer §8.2 #10, per-stage counts for #14, tiled resources for #18
AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:38:02 +01:00
321635899b Tools: feature_scan.py, a corpus scan for D3D12-layer features (SHADER-16)
Counts, from what the shaders stage leaves in <work>/shaders, the features docs/d3d12_vulkan.md
§8.2 #10 and #14 ask about: the DXIL program kind of every shader (hull, domain, amplification),
the SFI0 D3D_SHADER_REQUIRES_* flags (values from the Windows SDK's d3d12shader.h, among them
WAVE_MMA and SHADING_RATE), output-signature streams other than 0, native v_mfma/v_wmma and
GDS/ordered-count instructions in the disassembly, and uses_code_base per stage from
spirv/index.json. Prints counts only. tests/test_feature_scan.py checks it on a synthetic work
folder (hand-built DXBC parts, listings and index).

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:37:43 +01:00
052cc571d0 feature_scan: count s_getpc_b64 kept for code-embedded data per stage; d3d12_vulkan.md: answer §8.2 #10, per-stage counts for #14, tiled resources for #18
AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:12:07 +01:00
409f702bbb Tools: feature_scan.py, a corpus scan for D3D12-layer features (SHADER-16)
Counts, from what the shaders stage leaves in <work>/shaders, the features docs/d3d12_vulkan.md
§8.2 #10 and #14 ask about: the DXIL program kind of every shader (hull, domain, amplification),
the SFI0 D3D_SHADER_REQUIRES_* flags (values from the Windows SDK's d3d12shader.h, among them
WAVE_MMA and SHADING_RATE), output-signature streams other than 0, native v_mfma/v_wmma and
GDS/ordered-count instructions in the disassembly, and uses_code_base per stage from
spirv/index.json. Prints counts only. tests/test_feature_scan.py checks it on a synthetic work
folder (hand-built DXBC parts, listings and index).

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:10:38 +01:00