fix(gpu): declare dual-source blending to the Metal converter #239

Merged
ShadyUnderLight merged 2 commits from upstream-pr/239 into main 2026-11-27 03:29:48 +00:00
ShadyUnderLight commented 2026-11-27 03:09:53 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ShadyUnderLight on 2026-11-27T03:09:53Z.


What this changes

Two pixel pipelines at the first world frame were refused by Metal Shader Converter on every run:

Fragment shader does not write to render target color(0), index(1) that is required for blending

Both pipelines blend with the pixel shader's second output (SRC1_* factors in CB_BLEND), so the shader writes two SV_Targets for a single Rgba16Float attachment. Metal spells that as [[color(0) index(1)]], and the converter only emits it when IRCompilerSetDualSourceBlendingConfiguration enables dual-source blending for that shader. Without it the pipeline is refused and every draw that uses it is dropped, so those surfaces never appear.

  • state::pixel_targets reads the SV_Target indices and write masks from the pixel shader's OSG1 part.
  • state::dual_source decides per pipeline: one more shader output than colour targets, indices 0..n in order, and target 0's blend reading the second source.
  • RenderPipelineDesc::dual_source carries that to msc::convert_with, which sets the converter option before compiling. The option is looked up with dlsym; a converter without it keeps its previous behaviour.
  • The conversion cache only prefixes dual-source conversions with an extra key part, so existing single-source entries stay warm.
  • docs/native-host.md records the rule next to the blend-register notes.

The branch carries one tooling commit as well, kept separate: tools/macos/run-summary.sh stripped colours with s/\x1b\[...m//g, which BSD sed reads as a literal x1b, so no timestamp ever matched and every summary printed lines 0 / last frame 0. The escape is built with printf now, and the self-test's synthetic log carries colours, so it fails without the strip.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory — 369 passed, 0 failed
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings — clean
  • Ran the game: headless (run-native.sh --headless --seconds 170), same build, before and after

Before: two pipelines refused per run (vertex 55ccb5c3c932717d + pixel c2979cccbbac7e8c, vertex 62148192acfb1bb1 + pixel aa9cb047b21b22b1), both guessed as color: [Rgba16Float], depth: D32FloatS8.

After: no refusals of that kind in the whole run, and the first pipeline builds. The second now stops at a different, pre-existing check — Fragment input(s) 'user(half10)' mismatching vertex shader output type(s) or not written by vertex shader — which it could not reach while the pipeline was refused. That is a mismatch between the vertex output and pixel input signatures and is not addressed here.

Unit tests cover the decision matrix and each of the four factors on its own. run-summary.sh --self-test passes, and a real log now summarises to lines 2110, log span 111.0s, last frame 2116 instead of zeros.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented — none added
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5520505614 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/239). Originally posted by [ShadyUnderLight](https://github.com/ShadyUnderLight) on 2026-11-27T03:09:53Z. --- ## What this changes Two pixel pipelines at the first world frame were refused by Metal Shader Converter on every run: ``` Fragment shader does not write to render target color(0), index(1) that is required for blending ``` Both pipelines blend with the pixel shader's second output (`SRC1_*` factors in `CB_BLEND`), so the shader writes two `SV_Target`s for a single `Rgba16Float` attachment. Metal spells that as `[[color(0) index(1)]]`, and the converter only emits it when `IRCompilerSetDualSourceBlendingConfiguration` enables dual-source blending for that shader. Without it the pipeline is refused and every draw that uses it is dropped, so those surfaces never appear. - `state::pixel_targets` reads the `SV_Target` indices and write masks from the pixel shader's `OSG1` part. - `state::dual_source` decides per pipeline: one more shader output than colour targets, indices `0..n` in order, and target 0's blend reading the second source. - `RenderPipelineDesc::dual_source` carries that to `msc::convert_with`, which sets the converter option before compiling. The option is looked up with `dlsym`; a converter without it keeps its previous behaviour. - The conversion cache only prefixes dual-source conversions with an extra key part, so existing single-source entries stay warm. - `docs/native-host.md` records the rule next to the blend-register notes. The branch carries one tooling commit as well, kept separate: `tools/macos/run-summary.sh` stripped colours with `s/\x1b\[...m//g`, which BSD sed reads as a literal `x1b`, so no timestamp ever matched and every summary printed `lines 0 / last frame 0`. The escape is built with `printf` now, and the self-test's synthetic log carries colours, so it fails without the strip. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory` — 369 passed, 0 failed - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` — clean - [x] Ran the game: headless (`run-native.sh --headless --seconds 170`), same build, before and after Before: two pipelines refused per run (`vertex 55ccb5c3c932717d` + `pixel c2979cccbbac7e8c`, `vertex 62148192acfb1bb1` + `pixel aa9cb047b21b22b1`), both guessed as `color: [Rgba16Float]`, `depth: D32FloatS8`. After: no refusals of that kind in the whole run, and the first pipeline builds. The second now stops at a different, pre-existing check — `Fragment input(s) 'user(half10)' mismatching vertex shader output type(s) or not written by vertex shader` — which it could not reach while the pipeline was refused. That is a mismatch between the vertex output and pixel input signatures and is not addressed here. Unit tests cover the decision matrix and each of the four factors on its own. `run-summary.sh --self-test` passes, and a real log now summarises to `lines 2110, log span 111.0s, last frame 2116` instead of zeros. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented — none added
LakshanSivakumar commented 2026-11-27 03:29:44 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T03:29:44Z.

Review: APPROVED


Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6083077091 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/239#pullrequestreview-6083077091). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T03:29:44Z. **Review:** APPROVED --- Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
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
LakshanSivakumar/Native-Victory-macOS!239
No description provided.