Fill the converter's static sampler table (black window on M1/M2, #26) #91
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/91"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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),s0first.IRRootSignatureGetResourceLocationslists it as a table with space and register0xFFFFFFFF.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 aRootLayout(IRRootSignatureGetResourceLocations). Root signature creation moved into one helper, shared withconvert_with.VICTORY_TRACE_PRESENT=<every>: new, off by default and documented indocs/native-host.mdwith 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_TARGETSonly 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), onmainat8c47ddd; the branch also merges cleanly with182c14fand passes the same checks there.cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 291 passedcargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean (also with--all-features)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 xtask313 passed,cargo test -p victory-metal26 passed (render 8/8),cargo xtask policyok,tools/macos/tests/target-directory.shpasses, and each commit builds on its own. Windowscargo testwas 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_textureuses a new dxc-compiled fixture,heap_ps(texture fromResourceDescriptorHeap[index], static samplers0; its.dxilis 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_parameterspins the converter's layout: offset 16, 56, 0.a_target_drawn_in_one_pass_is_sampled_by_the_nextcovers the present pattern through a descriptor table, in one submission.Checklist
heap_ps.dxilis compiled from our ownheap_ps.hlsland listed inxtask/src/policy.rslike the other test shaders)VICTORY_*variable and documented (VICTORY_TRACE_PRESENT, in docs/native-host.md)Since the review
VICTORY_TRACE_PRESENTis documented indocs/native-host.md.graphics_args, used only by the macOS trace, is built on macOS only, so the Windows clippy gate passes.mainwith no merge commits. The static sampler code goes throughmsc(), and the shared root-signature helper destroys a refused signature'sIRError, asmaindoes.990e9bconmainbinds 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.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.
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):
No CI has run on this branch either. This is the fix for #26 and #99, so it is worth getting in quickly.
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.rsandrender.rs. The root-signature and static-sampler code overlaps the new disk shader cache and themsc()changes. Could you rebase onto main? It's still the fix we want for #26 and #99.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: Noneafter #116, which went in the same batch (b6f15be). This should fix #26.