Fill the converter's static sampler table (black window on M1/M2, #26) #91

Manually merged
github merged 3 commits from github-bot/gh-91 into main 2026-11-26 18:09:26 +00:00 AGit
Owner

@⁠sys-skye on GitHub · 2026-11-26 14:22 UTC · original
sys-skye:t34-present → main · +632 −60 · 11 files · 3 commits · merged 2026-11-26 18:09 UTC

What this changes

Fixes #26 and #99: the black window on M1 and M2.

The problem

Apple's Metal Shader Converter does not build static samplers into the shader. For a root signature with static samplers, it adds one more entry to the top-level argument buffer, right after the root parameters: the address of a table of IRDescriptorTableEntry (sampler, 0, LOD bias), s0 first. IRRootSignatureGetResourceLocations lists it as a table with space and register 0xFFFFFFFF.

Nothing wrote that address, so a shader with an immediate sampler read its sampler through whatever bytes followed its parameters. On M1 and M2 (Apple7, Apple8) that samples zeros. The title's present pass samples the menu target with an immediate sampler, so it wrote (0, 0, 0, 0) and the window stayed black while the menus drew correctly underneath. Compute shaders with immediate samplers took the same path.

The change

  • victory-metal: when a render or compute pipeline is made, the backend makes each stage's static samplers from the D3D12 words. It covers filter, address modes, anisotropy, comparison, border colour and min/max LOD; the LOD bias goes in the table entry. It keeps them in a small table per stage. If the converter lays out no table for a layout, the pipeline is made without the fill. At bind time it writes the table's address at the offset the converter reports, and marks the table resident in that encoder (useResource, so it works in both residency modes).
  • Msc::locations: new. It returns the converter's layout of a RootLayout (IRRootSignatureGetResourceLocations). Root signature creation moved into one helper, shared with convert_with.
  • VICTORY_TRACE_PRESENT=<every>: new, off by default and documented in docs/native-host.md with the other target traces. It logs a draw into a texture the title has presented: its shaders, static samplers, root parameters, table entries (textures with how much of their memory is non-zero, constant and placed buffers with their first bytes). VICTORY_TRACE_TARGETS only reaches the first six draws with vertex buffers, never the present pass.

How it was tested

On an M2 Max (macOS 27.3) with Apple's Metal Shader Converter (/usr/local/lib, universal), on main at 8c47ddd; the branch also merges cleanly with 182c14f and passes the same checks there.

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 291 passed
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean (also with --all-features)
  • Ran the game (this fix on af380ca, before the rebases): past the title into the menus, and the window shows them; the frame presented at 71 s matches the UI target (mean colour). A tester confirmed it on an M2 Max in #99.

Also on arm64: cargo test -p victory-hle -p victory -p victory-gpu -p xtask 313 passed, cargo test -p victory-metal 26 passed (render 8/8), cargo xtask policy ok, tools/macos/tests/target-directory.sh passes, and each commit builds on its own. Windows cargo test was not run here (no Windows machine); clippy builds every test target for Windows.

New, in victory-metal/tests/render.rs:

  • a_static_sampler_samples_a_heap_texture uses a new dxc-compiled fixture, heap_ps (texture from ResourceDescriptorHeap[index], static sampler s0; its .dxil is added to the policy's list of test shaders compiled from our own HLSL). It runs point and anisotropic samplers, at heap index 3 and at 1,010,071 (the present's), in both residency modes. Without the fill it reads [0, 0, 0, 0]; with it, green.
  • the_static_sampler_table_follows_the_root_parameters pins the converter's layout: offset 16, 56, 0.
  • a_target_drawn_in_one_pass_is_sampled_by_the_next covers the present pattern through a descriptor table, in one submission.

Checklist

  • No game files, game code, disassembly listings or SDK files are included (heap_ps.dxil is compiled from our own heap_ps.hlsl and listed in xtask/src/policy.rs like the other test shaders)
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: this follows the converter's documented layout)
  • New diagnostics are behind a VICTORY_* variable and documented (VICTORY_TRACE_PRESENT, in docs/native-host.md)

Since the review

  • A layout with no static sampler table no longer fails pipeline creation; the fill is skipped.
  • VICTORY_TRACE_PRESENT is documented in docs/native-host.md.
  • graphics_args, used only by the macOS trace, is built on macOS only, so the Windows clippy gate passes.
  • Rebased onto current main with no merge commits. The static sampler code goes through msc(), and the shared root-signature helper destroys a refused signature's IRError, as main does.
  • 990e9bc on main binds a sampler for the host's final blit to the window (present.rs). This PR fixes the title's own shaders with static samplers, whose output was already zero before that blit. They don't overlap.
**@⁠sys-skye** on GitHub · 2026-11-26 14:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91) `sys-skye:t34-present` → `main` · +632 −60 · 11 files · 3 commits · merged 2026-11-26 18:09 UTC ## What this changes Fixes #26 and #99: the black window on M1 and M2. ### The problem Apple's Metal Shader Converter does not build static samplers into the shader. For a root signature with static samplers, it adds one more entry to the top-level argument buffer, right after the root parameters: the address of a table of `IRDescriptorTableEntry` (sampler, 0, LOD bias), `s0` first. `IRRootSignatureGetResourceLocations` lists it as a table with space and register `0xFFFFFFFF`. Nothing wrote that address, so a shader with an immediate sampler read its sampler through whatever bytes followed its parameters. On M1 and M2 (Apple7, Apple8) that samples zeros. The title's present pass samples the menu target with an immediate sampler, so it wrote (0, 0, 0, 0) and the window stayed black while the menus drew correctly underneath. Compute shaders with immediate samplers took the same path. ### The change - **`victory-metal`:** when a render or compute pipeline is made, the backend makes each stage's static samplers from the D3D12 words. It covers filter, address modes, anisotropy, comparison, border colour and min/max LOD; the LOD bias goes in the table entry. It keeps them in a small table per stage. If the converter lays out no table for a layout, the pipeline is made without the fill. At bind time it writes the table's address at the offset the converter reports, and marks the table resident in that encoder (`useResource`, so it works in both residency modes). - **`Msc::locations`:** new. It returns the converter's layout of a `RootLayout` (`IRRootSignatureGetResourceLocations`). Root signature creation moved into one helper, shared with `convert_with`. - **`VICTORY_TRACE_PRESENT=<every>`:** new, off by default and documented in `docs/native-host.md` with the other target traces. It logs a draw into a texture the title has presented: its shaders, static samplers, root parameters, table entries (textures with how much of their memory is non-zero, constant and placed buffers with their first bytes). `VICTORY_TRACE_TARGETS` only reaches the first six draws with vertex buffers, never the present pass. ## How it was tested On an M2 Max (macOS 27.3) with Apple's Metal Shader Converter (`/usr/local/lib`, universal), on `main` at `8c47ddd`; the branch also merges cleanly with `182c14f` and passes the same checks there. - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: 291 passed - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: clean (also with `--all-features`) - [x] Ran the game (this fix on `af380ca`, before the rebases): past the title into the menus, and the window shows them; the frame presented at 71 s matches the UI target (mean colour). A tester confirmed it on an M2 Max in #99. Also on arm64: `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` 313 passed, `cargo test -p victory-metal` 26 passed (render 8/8), `cargo xtask policy` ok, `tools/macos/tests/target-directory.sh` passes, and each commit builds on its own. Windows `cargo test` was not run here (no Windows machine); clippy builds every test target for Windows. New, in `victory-metal/tests/render.rs`: - `a_static_sampler_samples_a_heap_texture` uses a new dxc-compiled fixture, `heap_ps` (texture from `ResourceDescriptorHeap[index]`, static sampler `s0`; its `.dxil` is added to the policy's list of test shaders compiled from our own HLSL). It runs point and anisotropic samplers, at heap index 3 and at 1,010,071 (the present's), in both residency modes. Without the fill it reads `[0, 0, 0, 0]`; with it, green. - `the_static_sampler_table_follows_the_root_parameters` pins the converter's layout: offset 16, 56, 0. - `a_target_drawn_in_one_pass_is_sampled_by_the_next` covers the present pattern through a descriptor table, in one submission. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included (`heap_ps.dxil` is compiled from our own `heap_ps.hlsl` and listed in `xtask/src/policy.rs` like the other test shaders) - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: this follows the converter's documented layout) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (`VICTORY_TRACE_PRESENT`, in docs/native-host.md) ## Since the review - A layout with no static sampler table no longer fails pipeline creation; the fill is skipped. - `VICTORY_TRACE_PRESENT` is documented in `docs/native-host.md`. - `graphics_args`, used only by the macOS trace, is built on macOS only, so the Windows clippy gate passes. - Rebased onto current `main` with no merge commits. The static sampler code goes through `msc()`, and the shared root-signature helper destroys a refused signature's `IRError`, as `main` does. - `990e9bc` on `main` binds a sampler for the host's final blit to the window (`present.rs`). This PR fixes the title's own shaders with static samplers, whose output was already zero before that blit. They don't overlap.
VICTORY_TRACE_PRESENT=<every> logs a draw into a texture the title has
presented: its shaders, static samplers, root parameters, table entries
(textures with how much of their memory is non-zero, constant and placed
buffers with their first bytes). VICTORY_TRACE_TARGETS only reaches the
first six draws with vertex buffers, never the present pass (issue #26).

The new render test draws a target in one pass and samples it through a
descriptor table in the next, in one submission, in both residency modes.
It passes on an M2 Max (Apple8), so the black present there is not this
backend pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apple's Metal Shader Converter does not build static samplers into the
shader. It lays out one more entry in the top-level argument buffer, right
after the root parameters: the address of a table of IRDescriptorTableEntry
(sampler, 0, LOD bias), s0 first. Nothing wrote that address, so a shader
with an immediate sampler read its sampler through whatever bytes followed
the parameters. On M1 and M2 (Apple7, Apple8) that sampled zeros: the
title's present pass, which samples the menu target with an immediate
sampler, wrote (0, 0, 0, 0) and the window stayed black while the menus
drew correctly underneath. Compute shaders with immediate samplers were
affected the same way.

The backend now makes each stage's static samplers when it makes the
pipeline (filter, address modes, anisotropy, comparison, border colour and
LOD clamps from the D3D12 words), keeps them in a small table, writes the
table's address at the offset the converter reports
(IRRootSignatureGetResourceLocations, new Msc::locations), and makes the
table resident in every encoder that binds it.

Tests, on an M2 Max: a pixel shader sampling a heap texture with a static
sampler (a new fixture, heap_ps) read [0, 0, 0, 0] before and the expected
colour now, with point and anisotropic samplers, at a small heap index and
at 1,010,071, in both residency modes. Another test pins where the
converter puts the table. In the title, the frame presented at 71 s went
from all zeros to the menus (mean colour equal to the menu target's).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:46 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 14:55 UTC · original · requested changes

Thanks, this fixes the real cause of the black window (a tester confirmed it on M2 Max in #99). Two things before merge: document the new VICTORY_TRACE_PRESENT switch in docs/native-host.md as the repo rules require, and don't fail pipeline creation when the converter lays out no sampler table; skip the fill instead.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#pullrequestreview-6076254075) · **requested changes** Thanks, this fixes the real cause of the black window (a tester confirmed it on M2 Max in #99). Two things before merge: document the new VICTORY_TRACE_PRESENT switch in docs/native-host.md as the repo rules require, and don't fail pipeline creation when the converter lays out no sampler table; skip the fill instead.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:03 UTC · original · requested changes

Still open from the last review (the only new commit is a merge of main):

  • Document VICTORY_TRACE_PRESENT in docs/native-host.md; the PR changes no docs file.
  • When the converter lays out no sampler table, skip the fill instead of failing pipeline creation.
    No CI has run on this branch either. This is the fix for #26 and #99, so it is worth getting in quickly.
**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#pullrequestreview-6077225100) · **requested changes** Still open from the last review (the only new commit is a merge of main): - Document VICTORY_TRACE_PRESENT in docs/native-host.md; the PR changes no docs file. - When the converter lays out no sampler table, skip the fill instead of failing pipeline creation. No CI has run on this branch either. This is the fix for #26 and #99, so it is worth getting in quickly.
github-bot force-pushed github-bot/gh-91 from a48e2cadab to de17dba5ac 2026-11-26 17:03:55 +00:00 Compare
github-bot force-pushed github-bot/gh-91 from de17dba5ac to 0dda7e11b7 2026-11-26 17:09:44 +00:00 Compare
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 17:08 UTC · original

This now conflicts with main in metal.rs, msc.rs and render.rs. The root-signature and static-sampler code overlaps the new disk shader cache and the msc() changes. Could you rebase onto main? It's still the fix we want for #26 and #99.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 17:08 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#issuecomment-7198564587) This now conflicts with main in `metal.rs`, `msc.rs` and `render.rs`. The root-signature and static-sampler code overlaps the new disk shader cache and the `msc()` changes. Could you rebase onto main? It's still the fix we want for #26 and #99.
github-bot force-pushed github-bot/gh-91 from 0dda7e11b7 to 517d52d308 2026-11-26 17:21:19 +00:00 Compare
github manually merged commit 80e53d63d8 into main 2026-11-26 18:09:26 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 18:09 UTC · original

Merged, thanks. Both review points are addressed. Your two new render tests needed count: None after #116, which went in the same batch (b6f15be). This should fix #26.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 18:09 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#issuecomment-7200124868) Merged, thanks. Both review points are addressed. Your two new render tests needed `count: None` after #116, which went in the same batch (b6f15be). This should fix #26.
This discussion has been locked. Commenting is limited to contributors.
No description provided.