Skip to content

BUILD-1587: Preserve grouped SPIR-V decorations during optimization - #5165

Open
Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/optimizer-group-decorations
Open

Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/optimizer-group-decorations

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem

The standalone SPIR-V optimizer can delete a value while leaving that ID in an OpGroupDecorate application. The resulting module fails validation. Group-decorated live values also lack the protection already given to directly decorated values. Direct OpDecorate and OpName cleanup additionally misses legal tab-separated instructions.

Changes

  • Include group targets when collecting decorated values.
  • Remove deleted targets from group applications and drop applications that have no targets left.
  • Preserve live targets, group definitions, member annotations, and comments on retained applications.
  • Recognize direct decorations and names regardless of spaces versus tabs.
  • Let the CPU test interpreter accept the corresponding annotation-only header instructions.

The regression suite includes an equivalent grouping of decorations from an actual synthetic translation. This does not claim that the translator currently emits decoration groups or that this was observed in a game corpus.

Validation

Base: upstream/main 3faac55.

  • Six new test methods cover 14 complete synthetic modules, with raw and optimized SPIR-V validation and exact CPU output checks. Vulkan SDK 1.4.363.0 spirv-as and spirv-val were active.
  • The new tests against the unchanged base optimizer produce 11 failing cases, all from the expected undefined IDs. The fixed branch passes all 15 optimizer tests.
  • Semantic negative-control test: 1 passed. Value-semantics tests: 39 passed.
  • Full compileall, CLI help, text-line-ending tests (3), and git diff --check passed.
  • Independent local review reran all six new methods with the SDK validators.
  • Integration with SHADER-885: preserve instructions with quoted SPIR-V comments #5064 and BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150: all 24 optimizer tests passed together. These changes apply without conflicts.

CPU-only validation; no GPU or game-file testing. All inputs are synthetic.

Coordination: BUILD-1587, claimed in #5032 (comment) and continued on #5156. Tab-separated annotation cleanup was recorded in #5032 (comment).

AI-assisted: yes.

@Atomic258

Copy link
Copy Markdown
Contributor

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

Environment: Windows 11, CPython 3.15.2.

  • python -I tests/test_spirv_opt_decorations.py → 6/6 on the head — grouped decoration targets now survive the optimizer pass (the GROUP-Decorate/ member-merge cases included)

AI-assisted (Devin).

@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 62bfda4b9 on Windows 11: pytest tests/test_spirv_opt_decorations.py -q -> 6 passed, 11 subtests passed; git diff --check clean.

The SPIR-V optimizer now keeps the targets of grouped decorations (a multi-target OpDecorate/OpMemberDecorate group) instead of dropping the group when it rewrites one member; the added cases cover a grouped decoration with several targets, the single-target form and the unchanged path. No blocking issue.

@Kev-Ball

Copy link
Copy Markdown

Retail-derived validation at 62bfda4b on CachyOS, CPU only. The patched optimizer produced Vulkan 1.2-valid output for 33/33 modules after equivalent regrouping of existing NoContraction decorations. The parent passed 14/33 on the same inputs. A failing compute case on the parent reported an undefined ID after optimization.

I selected eight retail listings per stage at evenly spaced ranks by unoptimized module size, including the smallest and largest, and translated them with this head and wave64 emulation. Of the 40, 33 had at least two direct NoContraction targets. I replaced only those annotations with a decoration group covering precisely the original IDs. The direct and grouped input modules all passed validation before optimization.

Stage Grouped inputs Parent valid Head valid
Compute 6 0 6
Geometry 8 8 8
Mesh 8 3 8
Pixel 6 2 6
Vertex 5 1 5

For reachability, I separately walked instruction boundaries in all 26,503 unoptimized SPIR-V binaries from my existing 1.0.2.1 translation at 690b9711 with wave64 emulation. Every module contained direct decorations; none contained OpDecorationGroup, OpGroupDecorate, or OpGroupMemberDecorate. A synthetic positive control registered all three opcodes. The 19 validation recoveries above required deliberately regrouped input. This run checked module validity only. 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 62bfda4 the scratch integration with #5064 and #5150 passed all 24 optimizer tests. A two-group control preserved both live decorations, removed the dead target, passed Vulkan 1.2 validation, and preserved four interpreter output words. Both builds produced identical assembly for all 32 cached modules. Those modules had no grouped decorations.

AI-assisted independent review.

@TurboSosiska304

Copy link
Copy Markdown

Checked 62bfda4 on Linux / Python 3.14.10 (CPU only):

  • python3 -I tests/test_spirv_opt_decorations.py -> 6 passed, 11 subtests passed;
  • negative control with main's tools/spirv_opt.py: 11 failed, 4 passed, 2 subtests passed — the grouped-decoration cases are pinned to the change;
  • full semantic suite (the PR also touches spirv_mini_interp.py): 6245 tests, 3 failures + 2 errors.

The five failures are not from this PR. I ran the same suite on main 3faac55 and got the identical set: test_loop_ballot_barrier.py in the emulate=True paths — AssertionError: 'emulated wave64 structured' != 'emulated wave64 rounds' and NotImplementedError: Unsupported SPIR-V op OpFunctionCall — which is tracked in #3995 / #4808 / #5024 (main has been red there since the structured wave64 emulation landed). Everything else in the suite passes with the PR applied.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 62bfda4 on Windows Server 2022, CPython 3.13.12, CPU-only: pass

  • python -I tests/test_spirv_opt_decorations.py: 6/6 OK
  • Negative control: fails against main's tools/spirv_opt.py (11 subtest failures)
  • git diff --check clean; python -m compileall -q on changed Python files: exit 0

No game files, no GPU. AI-assisted (Devin).

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.

6 participants