shader/vkback: LOD cross-fade 2x2 pixel dither (OMSetSampleMaskX) via PS discard, off #203

Open
github-bot wants to merge 4 commits from github-bot/gh-203 into main AGit
Owner

@⁠lordra9-svg on GitHub · 2026-12-02 10:51 UTC · original
lordra9-svg:fix/lod-dither → main · +252 −12 · 15 files · 4 commits · open

What

Implements the console's OMSetSampleMaskX 2x2 pixel dither for LOD cross-fades, as a pixel-shader discard. The dynamic per-sample Vulkan mask route is a proven no-op here (870 masked draws, all at sample count 1), so this adds the discard variant instead. Default off (VICTORY_LOD_DITHER=1).

Change

  • Decode list slot 0x470 (OMSetSampleMaskX) into the per-list mask (ListState.sample_mask, all-ones at reset).
  • victory-shader: with VICTORY_LOD_DITHER=1 (in translation_fingerprint), the PS entry reads a new host word USER_SAMPLE_MASK: slot (x & 1) | ((y & 1) << 1) from SV_Position (truncated pixel), discard when that bit is 0; inert for 0xFFFFFFFF. Complementary masks on the two LOD draws split pixels instead of both drawing every pixel.
  • vkback fills USER_SAMPLE_MASK per draw from the list mask; the dead EDS3 dynamic-sample-mask path is removed.

Verified

  • Discard is emitted: the on-arm DXIL lowers (dxil-spirv) to OpDemoteToHelperInvocation; off has none. Unit test counts the discard only when the switch is on; victory-shader 241 pass, vkback 168 pass, clippy clean, build exit 0.
  • Same-save F9 A/B (on vs off): RMSE 0.125, 6.5 % of pixels differ (the LOD fade dither); draw class 10.78 -> 10.99 ms, dispatch 26.59 -> 26.89, serialised 44.43 -> 44.88, fps flat (heavy scene). So it is picture-correct with no measured cost change.

Caveat

A discard disables early-Z for pixel programs when the switch is on (no per-draw pipeline variant yet); the cost is flat here because half the fragment work returns. Off by default: today's translation is unchanged. The victory-gpu/D3D12 path does not fill RootType::Other words, so the switch must not be enabled there.

**@⁠lordra9-svg** on GitHub · 2026-12-02 10:51 UTC · [original](https://github.com/vktory6/VKtory/pull/203) `lordra9-svg:fix/lod-dither` → `main` · +252 −12 · 15 files · 4 commits · open ## What Implements the console's `OMSetSampleMaskX` **2x2 pixel dither** for LOD cross-fades, as a pixel-shader `discard`. The dynamic per-sample Vulkan mask route is a proven no-op here (870 masked draws, all at sample count 1), so this adds the discard variant instead. Default **off** (`VICTORY_LOD_DITHER=1`). ## Change - Decode list slot 0x470 (`OMSetSampleMaskX`) into the per-list mask (`ListState.sample_mask`, all-ones at reset). - `victory-shader`: with `VICTORY_LOD_DITHER=1` (in `translation_fingerprint`), the PS entry reads a new host word `USER_SAMPLE_MASK`: slot `(x & 1) | ((y & 1) << 1)` from `SV_Position` (truncated pixel), `discard` when that bit is 0; inert for `0xFFFFFFFF`. Complementary masks on the two LOD draws split pixels instead of both drawing every pixel. - `vkback` fills `USER_SAMPLE_MASK` per draw from the list mask; the dead EDS3 dynamic-sample-mask path is removed. ## Verified - Discard is emitted: the on-arm DXIL lowers (dxil-spirv) to `OpDemoteToHelperInvocation`; off has none. Unit test counts the discard only when the switch is on; `victory-shader` 241 pass, vkback 168 pass, clippy clean, build exit 0. - Same-save F9 A/B (on vs off): **RMSE 0.125, 6.5 % of pixels differ** (the LOD fade dither); draw class 10.78 -> 10.99 ms, dispatch 26.59 -> 26.89, serialised 44.43 -> 44.88, fps flat (heavy scene). So it is picture-correct with no measured cost change. ## Caveat A `discard` disables early-Z for pixel programs when the switch is on (no per-draw pipeline variant yet); the cost is flat here because half the fragment work returns. Off by default: today's translation is unchanged. The `victory-gpu`/D3D12 path does not fill `RootType::Other` words, so the switch must not be enabled there.
The console's per-draw sample mask reaches vkback as a recorded SampleMask
event (new entry 50), rides the list state (all ones at reset), and every
draw sets vkCmdSetSampleMaskEXT when VK_EXT_extended_dynamic_state3's
sample-mask feature is enabled. Behind VKB_LOD_SAMPLE_MASK (default on;
0 = ignore 0x470 as before). The pipeline-state line now reports those
draws by sample count (masked_by_samples), which decides whether the masks
land on MSAA draws.

Owner: lod-sample-mask. Reason: two LODs cross-faded with complementary
2x2 masks both drew every pixel (double draw, z-fighting). Remove when the
A/B and D3D12 parity confirm it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 10:54:41 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 16:02 UTC · original

Thanks, this is the TASKS item "Per-pixel sample mask for LOD cross-fades", and the discard route plus the evidence that the dynamic mask was a no-op at sample count 1 make sense. One change, from a rule we added today (docs/AGENTS.md, "Deliberate is not correct"): a deviation from the console may stay only behind a toggle whose default is the accurate path. Here the accurate path is the dither, so please flip it: on by default, with VICTORY_LOD_DITHER=0 as the opt-out. That kind of opt-in performance switch needs no owner; it goes once it no longer helps on any hardware. Your A/B shows no fps change, so the early-Z cost doesn't argue against the default. A per-draw pipeline variant (discard only where the mask isn't all ones) would be a good follow-up. We'll run the picture gates on our side once it's flipped.

**@⁠vktory6** on GitHub · 2026-12-02 16:02 UTC · [original](https://github.com/vktory6/VKtory/pull/203#issuecomment-7351355107) Thanks, this is the TASKS item "Per-pixel sample mask for LOD cross-fades", and the discard route plus the evidence that the dynamic mask was a no-op at sample count 1 make sense. One change, from a rule we added today (docs/AGENTS.md, "Deliberate is not correct"): a deviation from the console may stay only behind a toggle whose **default is the accurate path**. Here the accurate path is the dither, so please flip it: on by default, with `VICTORY_LOD_DITHER=0` as the opt-out. That kind of opt-in performance switch needs no owner; it goes once it no longer helps on any hardware. Your A/B shows no fps change, so the early-Z cost doesn't argue against the default. A per-draw pipeline variant (discard only where the mask isn't all ones) would be a good follow-up. We'll run the picture gates on our side once it's flipped.
github-bot force-pushed github-bot/gh-203 from 5a84ae1e41 to 8d43c046d4 2026-12-02 18:49:16 +00:00 Compare
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 18:44 UTC · original

Thanks, the dither is on by default now, which was the ask. Three things are still left before it can merge, all from docs/AGENTS.md:

  1. Rule 4, the debt counts: oversize.txt goes up (lower.rs 13730 -> 13801, vkback lib.rs 4250 -> 4254), and a debt count is never raised. The dither prologue is a responsibility of its own, so it can go into its own file under emit/ (lower.rs then calls it). The lod_sample_mask_on switch can go too (point 2), which takes vkback lib.rs back under its count.
  2. Rules 2 and 36, one switch: VKB_LOD_SAMPLE_MASK and VICTORY_LOD_DITHER both turn off the same console behaviour. Please keep only VICTORY_LOD_DITHER as the opt-out. Slot 0x470 is then always decoded and carried, and with the switch at 0 the shader just doesn't use it.
  3. Rule 2, a value that doesn't parse: VICTORY_LOD_DITHER=foo currently means "on". A value other than 0/1 should stop the start instead.

After that we'll run the check (the translator changed, so that includes the whole-store diff and the validation run) and merge.

**@⁠vktory6** on GitHub · 2026-12-02 18:44 UTC · [original](https://github.com/vktory6/VKtory/pull/203#issuecomment-7355079401) Thanks, the dither is on by default now, which was the ask. Three things are still left before it can merge, all from docs/AGENTS.md: 1. **Rule 4, the debt counts:** `oversize.txt` goes up (lower.rs 13730 -> 13801, vkback lib.rs 4250 -> 4254), and a debt count is never raised. The dither prologue is a responsibility of its own, so it can go into its own file under `emit/` (lower.rs then calls it). The `lod_sample_mask_on` switch can go too (point 2), which takes vkback lib.rs back under its count. 2. **Rules 2 and 36, one switch:** `VKB_LOD_SAMPLE_MASK` and `VICTORY_LOD_DITHER` both turn off the same console behaviour. Please keep only `VICTORY_LOD_DITHER` as the opt-out. Slot 0x470 is then always decoded and carried, and with the switch at 0 the shader just doesn't use it. 3. **Rule 2, a value that doesn't parse:** `VICTORY_LOD_DITHER=foo` currently means "on". A value other than `0`/`1` should stop the start instead. After that we'll run the check (the translator changed, so that includes the whole-store diff and the validation run) and merge.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/record.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/lib.rs
  • greenfield/vicrec/src/event.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/203/head:github-bot/gh-203'
git switch 'github-bot/gh-203'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-203'
git switch 'github-bot/gh-203'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-203'
git switch 'github-bot/gh-203'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-203'
git switch 'main'
git merge --squash 'github-bot/gh-203'
git switch 'main'
git merge --ff-only 'github-bot/gh-203'
git switch 'main'
git merge 'github-bot/gh-203'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.