Skip to content

mesh_compute_vs: a bad mesh_compute layout names the field, and writes nothing - #5121

Open
SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/mesh-compute-vs-layout-errors
Open

SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/mesh-compute-vs-layout-errors

Conversation

@SebSilent

@SebSilent SebSilent commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: claiming: tools/mesh_compute_vs.py (self-sourced, no tracker row)

Depends on: #2528 (same file, same two functions and the same test file; #2528 sits CONFLICTING behind #2046, so this is the one to merge first)

What and why

mesh_compute_vs.py reads the mesh_compute layout out of a folder's index.json and hands it straight to vs_spvasm, which indexes it as if it were its own layout() output: layout["params"][0], layout["max_vertices"], clip_offset, f16_halves. A layout with a field missing, a field of the wrong type (params: {"0": [16]}), or a index.json that is not an object at all escaped main's RuntimeError handler as a bare traceback:

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'

Two things made that worse than an ugly message. The .spvasm was opened for write before the assembly was generated, so a bad entry left a zero-length file where the previous run's good shader used to be. And write_for_index worked through the entries one at a time, so a bad entry third out of five did it after two files had already been rewritten.

check_layout() now reads the layout the way vs_spvasm needs it (param offsets keyed by int location, distance offsets only where there are distances, f16_halves as locations paired with 2) and raises LayoutError, a RuntimeError, naming the entry and the field, so the tool prints its own one ERROR: line and exits 1 like it does for every other bad input. write_for_index assembles every shader before opening any output, so a bad entry writes nothing at all. vs_spvasm also accepts f16_halves keyed by int location, which is what a caller that read the field back out of index.json has, since json.dumps turns {"0": [1, 2]} into {0: [1, 2]}.

No new exit code and no message format of its own: the check reuses vs_spvasm's own reads, so the field it names is the field that would have crashed.

Tested

Synthetic fixtures only, no game data anywhere.

  • python3 -m unittest tests.test_mesh_compute_vs: 24 tests OK (the 12 existing, untouched, plus 12 new).
  • Red before: the same test file against tools/mesh_compute_vs.py from origin/main (3faac55) gives Ran 24 tests ... FAILED (errors=17), including the TypeError: int() argument ... not 'list' above.
  • Real CLI on a folder whose index.json has params: {"0": [16]}: stderr is ERROR: ms_a.mesh_compute params location 0: expected an integer, got [16], exit 1, and ms_a.mesh_vs.spvasm still holds the text from the previous run. A good layout still builds; with spirv-as and spirv-val on PATH the .spv comes out and the run exits 0.
  • python3 -m compileall -q tools tests: clean.
  • Neighbouring suites for regressions: tests.test_make_game_wave64 38 OK, tests.test_wave64_pipeline_audit 14 OK. tests.test_make_game_argparse has one failure (SubprocessCliSmokeTest.test_find_flag_executes_without_error) and tests.test_pc_tail_ubo / tests.test_mesh_compute need pytest, which is not installed here; all three behave identically on pristine origin/main, checked in a copy of this tree with only the tool restored.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • Not a new translator rule, so no contract-table change is needed. A valid layout emits the same spvasm as before, and test_a_checked_layout_builds_the_same_shader asserts that for each field the check rejects.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 0f1096bef on Windows 11: pytest tests/test_mesh_compute_vs.py -q -> 24 passed, 10 subtests passed; git diff --check clean.

mesh_compute_vs now names the layout field that prevents a shader from being built (rather than a generic failure) and writes no output in that case; the added cases cover each invalid field and the successful translation. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — pass (CPU only, synthetic layouts, no game files).

Environment: Windows 11, CPython 3.15.2.

  • python -I tests/test_mesh_compute_vs.py → 24/24 on the PR head
  • Negative control: same suite against main's tools/mesh_compute_vs.py → 17 errors — a bad mesh_compute layout reports nothing on the parent, names the field and its expected shape on the head

AI-assisted (Devin).

@nanyoudegege

Copy link
Copy Markdown

At 0f1096bef, the truthiness check in write_for_index skips an explicit "mesh_compute": {} before check_layout sees it. In a mixed index with a valid ms_a entry and an empty layout on ms_b, the code can replace ms_a.mesh_vs.spvasm and return normally while ms_b.mesh_vs.spvasm is left stale or missing. The translator omits the key when there is no mesh-compute layout, so the omitted key and an empty object need not be treated the same.

Could the planner skip only the omitted key, and extend test_one_bad_entry_writes_nothing to check that an explicit empty object errors before either existing output is changed? A separate omitted-key control would cover the intentional skip. I checked the validation gate and file-write ordering in a standalone synthetic model on cloud Linux, not an end-to-end shader run. No game files. AI-assisted.

@SebSilent

Copy link
Copy Markdown
Contributor Author

Good catch, fixed in 4fd3d99. The skip is now if lay is None so only the translator's omitted key is skipped; an explicit {} (or any non-object) reaches check_layout and raises a LayoutError naming the entry before any output is opened, so a valid ms_a can't be rewritten while ms_b goes unchecked.

Added the two tests you asked for: an explicit empty layout in a mixed index errors with both ms_a and ms_b .spvasm left byte-for-byte unchanged, and a separate omitted-key control that still skips ms_b and writes ms_a. Red before (the empty object raised nothing), green after; full suite 26 OK on Linux Python 3.14.10.

AI-assisted (Tacit).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 0f1096b an explicit empty mesh_compute object bypasses check_layout. Placing it in the final entry returned 0 and published earlier entries. Distinguish a missing key from an empty object before publication; add a regression for this case. The wrong-type vertex_stride control did preserve all earlier files. Five valid cached entries (three distinct layouts) produced byte-identical modules across head, parent and #2528; all 15 validated. Windows CPU, AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 4fd3d99 the real CLI rejected an explicit empty layout before publishing any output. All four existing output hashes survived and an empty destination stayed empty. Omitting the key still skipped that entry, and valid cached output was byte-identical. This resolves my previous finding.

AI-assisted independent review.

@SebSilent

Copy link
Copy Markdown
Contributor Author

@kacper-serewis that empty-object bypass is already fixed at the current head 4fd3d99 (your review tested the parent 0f1096b). The skip is now if lay is None, so only the translator's omitted key is skipped; an explicit "mesh_compute": {} goes through check_layout and errors. There's a regression for exactly your case: test_an_explicit_empty_layout_errors_before_any_output_changes puts a valid entry first and an empty {} last, and checks it errors before any earlier file is published. Suite is 26 OK on Linux Python 3.14.10. Mind re-reviewing against 4fd3d99?

AI-assisted (Tacit).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 4fd3d99 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_mesh_compute_vs.py -> Ran 26 tests, OK (skipped=2)
  • Negative control (tool file swapped to upstream/main): FAILED (errors=18)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kotekompotek

Copy link
Copy Markdown

Independent Windows CPU verification on 4fd3d992:

  • python -m pytest tests/test_mesh_compute_vs.py --basetemp D:\temp\pytest_tmp -q: 24 passed, 2 skipped in 0.94s

SebSilent added 2 commits November 23, 2026 10:40
Pointing the tool at a folder whose index.json has a "mesh_compute" entry with a
missing or non-integer field died as a bare KeyError/TypeError traceback, and
because the .spvasm was opened for write before the assembly was generated, it
left a zero-length file where a good shader from the previous run used to be.

check_layout() reads the layout the way vs_spvasm needs it (param offsets keyed
by int location, distance offsets only when there are distances) and raises
LayoutError, a RuntimeError, so main prints one ERROR line naming the entry and
the field. write_for_index now assembles every shader before opening any output,
so a bad entry writes nothing at all.

vs_spvasm also accepts f16_halves keyed by int location, which is what a caller
that read the field back out of index.json has.
…ot a skip

write_for_index skipped any falsy mesh_compute value, so an explicit {} was
treated like the translator's omitted key. In a mixed index that let a valid
ms_a be rewritten while ms_b's empty layout went unchecked and its .spvasm
stayed stale. Skip only the omitted key (None); an explicit {} (or any
non-object) now reaches check_layout and raises a LayoutError naming the
entry before any output is opened.

Tests: an explicit empty layout errors before either existing .spvasm changes,
and an omitted-key control still skips. Red before (no error raised), green after.

AI-assisted (Tacit).
@SebSilent
SebSilent force-pushed the fix/mesh-compute-vs-layout-errors branch from 4fd3d99 to 57899f7 Compare November 23, 2026 13:41
@SebSilent

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (57899f7). Main had independently hardened write_for_index (broad except + a preservation test), so I merged the two: kept check_layout's field naming, the empty {} rejection and the collect-then-write preservation, and adopted main's error wording (invalid JSON / expected a shader index object / layout for 'name') plus its RecursionError catch. Main's new test_invalid_index_leaves_existing_assembly_untouched passes alongside the existing cases. Full suite 27 OK, Linux Python 3.14.10. compileall + diff --check clean.

AI-assisted (Tacit).

@nnonno91

Copy link
Copy Markdown

AI-assisted verification of 57899f7 on Windows 11 (build 26200), CPython 3.14.5. python -I tests/test_mesh_compute_vs.py -v passed 25 tests. Two assembly/validation tests skipped because spirv-as and spirv-val were unavailable on PATH.

The damaged-index tests verified that an invalid layout identifies the field and preserves existing output. I also compared assembly text against 1cc6e3c for three valid synthetic layouts (basic, clip/cull distances, and paired f16 inputs). All three matched exactly.

@bobcatchris

Copy link
Copy Markdown
Contributor

Independent macOS code read and test run at head 57899f7 (Apple M2, Python 3.13.18). An absent mesh_compute index key remains a skip, but an explicit empty object is now an error naming the field, so a malformed index can't silently produce a pass-through VS with no real layout. pytest -q tests/test_mesh_compute_vs.py: 27 passed, 13 subtests passed, 0 failed. No issue found; synthetic index only.

AI-assisted.

@antoinecaputo

Copy link
Copy Markdown

Tested 57899f7 on macOS / CPython 3.14.7: pass — python -I tests/test_mesh_compute_vs.py 27 tests OK (2 skipped: no spirv-as/val here), compileall clean. Differential over 12 valid-layout cases (incl. f16 halves and write_for_index): output byte-identical to main. The PR's test file against main's tool: 18 red — the field/value is not named, and main overwrites the first entry's previous .spvasm before the second raises (the partial-update bug, reproduced by hand). Review notes, all minor: the wrapped message names the entry twice (tools/mesh_compute_vs.py:324-325); a missing params key says "got NoneType" where the INT_FIELDS say "no params"; a 3-element f16_halves pair passes check_layout and dies later as a plain ValueError in vs_spvasm (:231). AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants