rdna2spirv: mesh shader pos1 misc export writes Layer and ViewportIndex per primitive (OLD-9893) #1197

Merged
ambroseautomation merged 3 commits from upstream-pr/1197 into main 2026-11-25 03:12:44 +00:00
ambroseautomation commented 2026-11-24 20:01:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T20:01:27Z.


Claimed in the coordination issue as: OLD-9893 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142685828)

What and why

Carries forward old-pr/9893 (draft #162, original commit author tedin7 preserved; indexed in #17), rebased cleanly onto current main.

Implements per-primitive Layer and ViewportIndex mesh shader outputs from exp pos1 misc vector exports in tools/rdna2spirv.py:

  • When OSG1 declares SV_RenderTargetArrayIndex (Layer) and/or SV_ViewportArrayIndex (ViewportIndex), decodes z[10:0] (Layer) and (z >> 16) & 0xF (ViewportIndex) from exp pos1 into %ms_layer / %ms_viewport and writes them into per-primitive members of %ms_cull_blk (BuiltIn Layer, BuiltIn ViewportIndex, PerPrimitiveEXT), emitting OpCapability ShaderLayer / OpCapability ShaderViewportIndex and reporting shaderOutputLayer / shaderOutputViewportIndex in shader metadata.
  • Adds 3 unit tests in tests/test_translate.py: test_ms_misc_pos1_exports_layer_and_viewport_per_primitive, test_ms_misc_pos1_layer_only_has_no_viewport_member, and test_ms_without_misc_outputs_keeps_plain_primitive_block.

Tested

  • Executed all 3 new tests/test_translate.py functions directly via rdna2spirv.translate and verified SPIR-V binary assembly via spirv_asm.assemble (no llvm-mc/spirv-val installed on host): 3/3 PASS.
  • python -I scripts/run_semantic_tests.py tests/semantic: 470 files, 6,168 tests, 0 files failed.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_translate.py: exit 0 (no game data).

GPUs tested: n/a (CPU SPIR-V interpreter semantic suite + in-process spirv_asm assembly on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (extends existing mesh shader pos1 export lowering)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479393142 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1197). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T20:01:27Z. --- Claimed in the coordination issue as: OLD-9893 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142685828) ### What and why Carries forward `old-pr/9893` (draft #162, original commit author `tedin7` preserved; indexed in #17), rebased cleanly onto current `main`. Implements per-primitive `Layer` and `ViewportIndex` mesh shader outputs from `exp pos1` misc vector exports in `tools/rdna2spirv.py`: - When `OSG1` declares `SV_RenderTargetArrayIndex` (`Layer`) and/or `SV_ViewportArrayIndex` (`ViewportIndex`), decodes `z[10:0]` (`Layer`) and `(z >> 16) & 0xF` (`ViewportIndex`) from `exp pos1` into `%ms_layer` / `%ms_viewport` and writes them into per-primitive members of `%ms_cull_blk` (`BuiltIn Layer`, `BuiltIn ViewportIndex`, `PerPrimitiveEXT`), emitting `OpCapability ShaderLayer` / `OpCapability ShaderViewportIndex` and reporting `shaderOutputLayer` / `shaderOutputViewportIndex` in shader metadata. - Adds 3 unit tests in `tests/test_translate.py`: `test_ms_misc_pos1_exports_layer_and_viewport_per_primitive`, `test_ms_misc_pos1_layer_only_has_no_viewport_member`, and `test_ms_without_misc_outputs_keeps_plain_primitive_block`. ### Tested - Executed all 3 new `tests/test_translate.py` functions directly via `rdna2spirv.translate` and verified SPIR-V binary assembly via `spirv_asm.assemble` (no `llvm-mc`/`spirv-val` installed on host): 3/3 PASS. - `python -I scripts/run_semantic_tests.py tests/semantic`: 470 files, 6,168 tests, 0 files failed. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_translate.py`: exit 0 (no game data). GPUs tested: n/a (CPU SPIR-V interpreter semantic suite + in-process `spirv_asm` assembly on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (extends existing mesh shader `pos1` export lowering)
Deedlyy commented 2026-11-24 20:07:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:07:52Z.


Recommendation: [MERGE]

Reasoning: Carries #162: mesh shaders decode Layer and ViewportIndex from the exp pos1 misc export and write them as per-primitive outputs when OSG1 declares them. Focused translator change with a translate test. No independent GPU run yet, but the change only takes effect when the outputs are declared. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143083502 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1197#issuecomment-7143083502). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:07:52Z. --- **Recommendation:** [MERGE] **Reasoning:** Carries #162: mesh shaders decode `Layer` and `ViewportIndex` from the `exp pos1` misc export and write them as per-primitive outputs when `OSG1` declares them. Focused translator change with a translate test. No independent GPU run yet, but the change only takes effect when the outputs are declared. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 4/10
aslan2142 commented 2026-11-25 03:12:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T03:12:47Z.


Merged, after merging main into it. Thanks.

  • Claim: OLD-9893, valid, before this PR; the only claim for the item.
  • One docs commit added before merging: the contract row for the rule, in the "Mesh shaders" row of docs/design.md. It states one open point as a hypothesis: each lane writes the primitive with its own index, which is exact when the value is the same for all vertices of a primitive; whether the hardware takes the provoking vertex's value instead is not measured.
  • On the maintainer's own shader corpus (counts only): none of the 1,906 mesh shaders that export pos1 writes Layer or ViewportIndex under this translation, so the game's mesh shaders only gain three unused declarations each.
  • Next: #1203 (OLD-9921) depends on this; its one conflict with it, in mesh_export, is resolved next by keeping both: the misc-vector return first, then the compressed components.
  • Checked on main b07b9ecb0 + e950f8582: the semantic suite passes (487 files, 6,279 tests, 0 files failed); test_translate (pytest; 2 failing as on main) pass; the 14 docs and writer tests pass; check_no_game_data.py is clean on the 3 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7151699379 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1197#issuecomment-7151699379). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T03:12:47Z. --- Merged, after merging `main` into it. Thanks. - **Claim:** `OLD-9893`, valid, before this PR; the only claim for the item. - **One docs commit added before merging:** the contract row for the rule, in the "Mesh shaders" row of `docs/design.md`. It states one open point as a hypothesis: each lane writes the primitive with its own index, which is exact when the value is the same for all vertices of a primitive; whether the hardware takes the provoking vertex's value instead is not measured. - **On the maintainer's own shader corpus (counts only):** none of the 1,906 mesh shaders that export `pos1` writes `Layer` or `ViewportIndex` under this translation, so the game's mesh shaders only gain three unused declarations each. - **Next:** #1203 (`OLD-9921`) depends on this; its one conflict with it, in `mesh_export`, is resolved next by keeping both: the misc-vector return first, then the compressed components. - **Checked on `main` `b07b9ecb0` + `e950f8582`:** the semantic suite passes (487 files, 6,279 tests, 0 files failed); `test_translate (pytest; 2 failing as on main)` pass; the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 3 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
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
ProjectLeonida/mandy!1197
No description provided.