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

Manually merged
github merged 2 commits from github-bot/gh-239 into main 2026-11-27 03:33:10 +00:00 AGit
Owner

@⁠ShadyUnderLight on GitHub · 2026-11-27 03:09 UTC · original
ShadyUnderLight:fix/blend-targets → main · +180 −23 · 9 files · 2 commits · merged 2026-11-27 03:29 UTC

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
**@⁠ShadyUnderLight** on GitHub · 2026-11-27 03:09 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/239) `ShadyUnderLight:fix/blend-targets` → `main` · +180 −23 · 9 files · 2 commits · merged 2026-11-27 03:29 UTC ## 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
A target whose blend names SRC1_* or INV_SRC1_* factors takes two of the pixel
shader's outputs into one target, so the shader writes one output more than the
pipeline has targets. Metal spells that [[color(0) index(1)]], which its
converter only emits when IRCompilerSetDualSourceBlendingConfiguration enables
it. Without it Metal refuses the pipeline ("Fragment shader does not write to
render target color(0), index(1) that is required for blending") and drops every
draw with it: two pipelines at the world frame in every run, whose pixel shaders
write targets 0 and 1 into one Rgba16Float target.

Which pipelines are dual-source is decided per pipeline (state::dual_source: one
more shader output than targets, in order, and target 0's blend reads it), and
the conversion cache keeps an entry of its own for that case, so conversions of
every other shader stay warm.
The logger colours every line even when it writes a file, and macOS's sed has
no \x1b escape (it matches a literal "x1b"), so the timestamp pattern never
matched and every summary read "lines 0, log span 0.0s, last frame 0". The
escape is built with printf now, and the self-test's log wears the colours, so
it fails without the strip.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:11:03 +00:00
github manually merged commit 76c001af91 into main 2026-11-27 03:33:10 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 03:29 UTC · original · approved these changes

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

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 03:29 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/239#pullrequestreview-6083077091) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.