shader: lower computed buffer descriptors in mesh shaders, dynamic root-descriptor counts, and VGPR-spilled descriptor phis #556

Open
opened 2026-11-28 03:31:20 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 03:28 UTC · original

Problem

Several classes of valid descriptors still fail in victory_shader::resource as "a descriptor neither loaded nor built" or "a buffer descriptor built around a computed address" (Refs #258, #525):

  1. Mesh shaders (HwStage::Ms) drop computed_buffers: emit::translate_with passes computed_buffers = true for guessed graphics containers (which include mesh-style vertex programs whose native.stage is HwStage::Ms), and victory-metal already binds the zero-copy page-table SRVs and argument buffer on the mesh stage (bind_root_render). However, resource::track_graphics restricts t.computed_buffers to HwStage::Vs | HwStage::Ps | HwStage::Cs, forcing computed_buffers = false for every HwStage::Ms program. In addition, the structure::killing retry in emit::emit_fast drops native.stage == HwStage::Cs from its computed_buffers flag.
  2. Root descriptors (RootType::Descriptor) with dynamic num_records: When computed_buffers is enabled and a 4-dword V# buffer descriptor [lo, hi, w2, w3] is built around a RootType::Descriptor address (slot != VERTEX_TABLE) with a runtime w2 (num_records), Tracer::classify skips Source::BuiltMemory (which checked address.param == MEMORY only) and skips Source::Built (which requires Term::Const(w2)), falling through to "a descriptor neither loaded nor built". In compute shaders (HwStage::Cs), Lower::new also needs root_memory set when Source::BuiltMemory is present so Lower::user exposes the root descriptor's 64-bit title address.
  3. Scalar ALU constant expressions in sampler / V# control dwords: Descriptor control words (w3) or immediate sampler dwords formed by constant scalar ALU chains (s_or_b32, s_and_b32, s_bfi_b32, s_bitset*, shifts, etc.) stay Term::Value after copy propagation and fail Term::Const checks in Tracer::classify.
  4. Descriptors chosen across control flow while spilled to VGPR lanes: Commit 75c5b97a (#404) handled VGPR-spilled descriptors when all phi edges spill the same origin, but when two uniform control-flow arms spill different descriptors into the same scratch VGPR lanes (v_writelane_b32) and restore them after the join (v_readlane_b32), Tracer::phi only checks SGPR phis and refuses the restored descriptor as "a descriptor neither loaded nor built".

Proposed Fix

  • Include HwStage::Ms in t.computed_buffers in resource::track_graphics, and keep computed_buffers consistent in emit_fast's structure::killing retry.
  • Emit Source::BuiltMemory when computed_buffers is enabled and a V# buffer descriptor is built around a non-VERTEX_TABLE RootType::Descriptor with a runtime num_records (w2), and set root_memory in Lower::new when Source::BuiltMemory is used.
  • Fold pure constant scalar ALU dwords when classifying Source::Constant and Source::Built / Source::BuiltMemory dwords.
  • Follow v_readlane_b32 of constant scratch VGPR lanes across VGPR phi joins in Tracer::phi and Tracer::collect_descriptor_loads.
  • Add unit tests in victory-shader and an end-to-end Metal GPU value test in victory-gpu (mesh_tests) verifying a mesh shader reading Pool memory through a computed V# buffer descriptor with runtime num_records bounds.
**@⁠Sheffy007** on GitHub · 2026-11-28 03:28 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/552) ## Problem Several classes of valid descriptors still fail in `victory_shader::resource` as `"a descriptor neither loaded nor built"` or `"a buffer descriptor built around a computed address"` (Refs #258, #525): 1. **Mesh shaders (`HwStage::Ms`) drop `computed_buffers`:** `emit::translate_with` passes `computed_buffers = true` for guessed graphics containers (which include mesh-style vertex programs whose `native.stage` is `HwStage::Ms`), and `victory-metal` already binds the zero-copy page-table SRVs and argument buffer on the mesh stage (`bind_root_render`). However, `resource::track_graphics` restricts `t.computed_buffers` to `HwStage::Vs | HwStage::Ps | HwStage::Cs`, forcing `computed_buffers = false` for every `HwStage::Ms` program. In addition, the `structure::killing` retry in `emit::emit_fast` drops `native.stage == HwStage::Cs` from its `computed_buffers` flag. 2. **Root descriptors (`RootType::Descriptor`) with dynamic `num_records`:** When `computed_buffers` is enabled and a 4-dword V# buffer descriptor `[lo, hi, w2, w3]` is built around a `RootType::Descriptor` address (`slot != VERTEX_TABLE`) with a runtime `w2` (`num_records`), `Tracer::classify` skips `Source::BuiltMemory` (which checked `address.param == MEMORY` only) and skips `Source::Built` (which requires `Term::Const(w2)`), falling through to `"a descriptor neither loaded nor built"`. In compute shaders (`HwStage::Cs`), `Lower::new` also needs `root_memory` set when `Source::BuiltMemory` is present so `Lower::user` exposes the root descriptor's 64-bit title address. 3. **Scalar ALU constant expressions in sampler / V# control dwords:** Descriptor control words (`w3`) or immediate sampler dwords formed by constant scalar ALU chains (`s_or_b32`, `s_and_b32`, `s_bfi_b32`, `s_bitset*`, shifts, etc.) stay `Term::Value` after copy propagation and fail `Term::Const` checks in `Tracer::classify`. 4. **Descriptors chosen across control flow while spilled to VGPR lanes:** Commit `75c5b97a` (#404) handled VGPR-spilled descriptors when all phi edges spill the same origin, but when two uniform control-flow arms spill *different* descriptors into the same scratch VGPR lanes (`v_writelane_b32`) and restore them after the join (`v_readlane_b32`), `Tracer::phi` only checks SGPR phis and refuses the restored descriptor as `"a descriptor neither loaded nor built"`. ## Proposed Fix - Include `HwStage::Ms` in `t.computed_buffers` in `resource::track_graphics`, and keep `computed_buffers` consistent in `emit_fast`'s `structure::killing` retry. - Emit `Source::BuiltMemory` when `computed_buffers` is enabled and a V# buffer descriptor is built around a non-`VERTEX_TABLE` `RootType::Descriptor` with a runtime `num_records` (`w2`), and set `root_memory` in `Lower::new` when `Source::BuiltMemory` is used. - Fold pure constant scalar ALU dwords when classifying `Source::Constant` and `Source::Built` / `Source::BuiltMemory` dwords. - Follow `v_readlane_b32` of constant scratch VGPR lanes across VGPR `phi` joins in `Tracer::phi` and `Tracer::collect_descriptor_loads`. - Add unit tests in `victory-shader` and an end-to-end Metal GPU value test in `victory-gpu` (`mesh_tests`) verifying a mesh shader reading `Pool` memory through a computed V# buffer descriptor with runtime `num_records` bounds.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:31:20 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 03:28 UTC · original

/claim

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

@⁠github-actions[bot] on GitHub · 2026-11-28 03:29 UTC · original

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

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