gpu: Title::make_render drops ps_binding when a pixel shader needs only view_addresses, leaving fragment buffer(2) bound to vertex arguments #414

Closed
opened 2026-11-27 17:13:19 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 17:11 UTC · original

Bug

In crates/victory-gpu/src/native/shaders.rs (Title::make_render), ps_layout includes RootParam::Srv { register: 1, space: MEMORY_SPACE } whenever ps_full.view_addresses is true (Binding::layout), so Metal Shader Converter compiles the fragment shader reading a 64-bit GPU buffer pointer for view_addresses (t1, space3) at offset 0 of the fragment top-level argument buffer (buffer(2)).

However, two lines below, ps_binding is filtered with:

let ps_binding = ps_full
    .filter(|b| b.memory || b.dwords > 0 || !b.views.is_empty());

missing b.view_addresses.

When a pixel shader indexes ResourceDescriptorHeap directly (s2, or an interpolated heap index in a waterfall loop, as in the 45 pixel shaders noted in #411) and queries texture dimensions or buffer metadata via view_addresses without user-data dwords, root views, or the pool page table (b.view_addresses && !b.memory && b.dwords == 0 && b.views.is_empty()):

  1. ps_binding is dropped to None.
  2. NativeHost::prep (Cmd::Draw) never calls view_address_args for the pixel stage: heap.addresses is neither built nor made resident in p.bufs, and p.ps_root remains None.
  3. Metal::bind_root_render (fragment.unwrap_or(root)) binds the vertex shader's root bytes (or nothing, leaving stale fragment bytes at buffer(2)) as the fragment argument buffer, so the fragment shader dereferences the vertex stage's first 8 bytes as a 64-bit GPU pointer for t1 — faulting the GPU (#79) or reading bogus dimensions (#258).

Fix

  • Include b.view_addresses in Title::make_render's ps_binding filter (b.memory || b.view_addresses || b.dwords > 0 || !b.views.is_empty()), matching every condition that adds root parameters in Binding::layout.
  • Add a Metal GPU render test where the vertex shader binds arbitrary non-pointer root constants (0xDEAD_BEEF) while a pixel shader with dwords == 0 queries an image's dimensions from ResourceDescriptorHeap via view_addresses, asserting the rendered texels match the texture's width and height with 0 GPU faults.

Refs #79, #258, #306, #411

**@⁠Sheffy007** on GitHub · 2026-11-27 17:11 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/410) ## Bug In `crates/victory-gpu/src/native/shaders.rs` (`Title::make_render`), `ps_layout` includes `RootParam::Srv { register: 1, space: MEMORY_SPACE }` whenever `ps_full.view_addresses` is `true` (`Binding::layout`), so Metal Shader Converter compiles the fragment shader reading a 64-bit GPU buffer pointer for `view_addresses` (`t1, space3`) at offset `0` of the fragment top-level argument buffer (`buffer(2)`). However, two lines below, `ps_binding` is filtered with: ```rust let ps_binding = ps_full .filter(|b| b.memory || b.dwords > 0 || !b.views.is_empty()); ``` missing `b.view_addresses`. When a pixel shader indexes `ResourceDescriptorHeap` directly (`s2`, or an interpolated heap index in a waterfall loop, as in the 45 pixel shaders noted in #411) and queries texture dimensions or buffer metadata via `view_addresses` without user-data dwords, root views, or the pool page table (`b.view_addresses && !b.memory && b.dwords == 0 && b.views.is_empty()`): 1. `ps_binding` is dropped to `None`. 2. `NativeHost::prep` (`Cmd::Draw`) never calls `view_address_args` for the pixel stage: `heap.addresses` is neither built nor made resident in `p.bufs`, and `p.ps_root` remains `None`. 3. `Metal::bind_root_render` (`fragment.unwrap_or(root)`) binds the **vertex shader's** `root` bytes (or nothing, leaving stale fragment bytes at `buffer(2)`) as the fragment argument buffer, so the fragment shader dereferences the vertex stage's first 8 bytes as a 64-bit GPU pointer for `t1` — faulting the GPU (#79) or reading bogus dimensions (#258). ## Fix - Include `b.view_addresses` in `Title::make_render`'s `ps_binding` filter (`b.memory || b.view_addresses || b.dwords > 0 || !b.views.is_empty()`), matching every condition that adds root parameters in `Binding::layout`. - Add a Metal GPU render test where the vertex shader binds arbitrary non-pointer root constants (`0xDEAD_BEEF`) while a pixel shader with `dwords == 0` queries an image's dimensions from `ResourceDescriptorHeap` via `view_addresses`, asserting the rendered texels match the texture's width and height with 0 GPU faults. Refs #79, #258, #306, #411
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:13:19 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 17:11 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-27 17:11 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/410#issuecomment-7224133391) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 17:11 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #410 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 17:11 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/410#issuecomment-7224137146) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #410` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.