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

Merged
sys-skye merged 3 commits from upstream-pr/91 into main 2026-11-26 18:09:23 +00:00
sys-skye commented 2026-11-26 14:22:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by sys-skye on 2026-11-26T14:22:14Z.


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5511740512 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91). Originally posted by [sys-skye](https://github.com/sys-skye) on 2026-11-26T14:22:14Z. --- ## 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.
LakshanSivakumar commented 2026-11-26 14:55:01 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T14:55:01Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6076254075 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#pullrequestreview-6076254075). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T14:55:01Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-26 16:03:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:03:56Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077225100 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#pullrequestreview-6077225100). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:03:56Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-26 17:08:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:08:45Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198564587 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#issuecomment-7198564587). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:08:45Z. --- 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 commented 2026-11-26 18:09:46 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T18:09:46Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7200124868 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/91#issuecomment-7200124868). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T18:09:46Z. --- 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.
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!91
No description provided.