Lower implicit 2D compute samples to quad gradients on Metal #568

Open
github-bot wants to merge 1 commit from github-bot/gh-564 into main AGit
Owner

@⁠fruvs on GitHub · 2026-11-28 05:15 UTC · original
fruvs:codex/metal-compute-texture-gradients → main · +185 −1 · 2 files · 1 commits · open

Problem

Apple Metal Shader Converter rejects dx.op.sample.f32 in multidimensional compute threadgroups with IR error 7. The native host then drops the dispatch.

Change

For implicit 2D texture samples in 8×4×1, 8×8×1 and 4×4×2 groups on the 32-lane native target, read neighboring coordinates within each 2×2 tile and pass the resulting X and Y gradients to sampleGrad. All three lanes needed for a coarse gradient fit in one host wave for these shapes. This retains mip selection instead of forcing level zero. The D3D12 path and other shapes keep their existing lowering.

Verification

  • On the M5 Pro, the new synthetic test fails with IR error 7 on upstream main at 2f4d81e0 and passes with this change.
  • The fixture gives three mips distinct R32Float values and checks GPU readback for every lane in all three group shapes. It exercises X-only and Y-only footprint changes and all three mips.
  • The native shader test group passed 7 tests. The shader library suite passed 420 tests with 3 ignored.

The fixture verifies Metal output against explicit mip expectations. Console-hardware parity for divergent sampling remains open.

Shader Model 6.6 derivative and sampling rules

**@⁠fruvs** on GitHub · 2026-11-28 05:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/564) `fruvs:codex/metal-compute-texture-gradients` → `main` · +185 −1 · 2 files · 1 commits · open ## Problem Apple Metal Shader Converter rejects `dx.op.sample.f32` in multidimensional compute threadgroups with IR error 7. The native host then drops the dispatch. ## Change For implicit 2D texture samples in 8×4×1, 8×8×1 and 4×4×2 groups on the 32-lane native target, read neighboring coordinates within each 2×2 tile and pass the resulting X and Y gradients to `sampleGrad`. All three lanes needed for a coarse gradient fit in one host wave for these shapes. This retains mip selection instead of forcing level zero. The D3D12 path and other shapes keep their existing lowering. ## Verification - On the M5 Pro, the new synthetic test fails with IR error 7 on upstream main at `2f4d81e0` and passes with this change. - The fixture gives three mips distinct R32Float values and checks GPU readback for every lane in all three group shapes. It exercises X-only and Y-only footprint changes and all three mips. - The native shader test group passed 7 tests. The shader library suite passed 420 tests with 3 ignored. The fixture verifies Metal output against explicit mip expectations. Console-hardware parity for divergent sampling remains open. [Shader Model 6.6 derivative and sampling rules](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Derivatives.html)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:17:42 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 17:12 UTC · original · approved these changes

Read the diff: implicit 2D sample.f32 in the listed compute group shapes is lowered to a 2x2-tile neighbor read feeding sampleGrad (X/Y gradients), keeping mip selection — 43 lines in lower.rs plus 142 lines of tests. Verified on the head 49e9b1f1: the new shader_tests (incl. a_2d_compute_sample_selects_the_mip_from_both_quad_gradients across the 8x4x1 / 8x8x1 / 4x4x2 shapes and wave64) pass under the darwin target (7/7 shader_tests), and the workspace windows clippy with -D warnings is clean. Approving.

**@⁠AnastasisKon** on GitHub · 2026-11-28 17:12 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/564#pullrequestreview-6099219346) · **approved these changes** Read the diff: implicit 2D `sample.f32` in the listed compute group shapes is lowered to a 2x2-tile neighbor read feeding `sampleGrad` (X/Y gradients), keeping mip selection — 43 lines in `lower.rs` plus 142 lines of tests. Verified on the head 49e9b1f1: the new `shader_tests` (incl. `a_2d_compute_sample_selects_the_mip_from_both_quad_gradients` across the 8x4x1 / 8x8x1 / 4x4x2 shapes and wave64) pass under the darwin target (7/7 shader_tests), and the workspace windows clippy with `-D warnings` is clean. Approving.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/568/head:github-bot/gh-564'
git switch 'github-bot/gh-564'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-564'
git switch 'github-bot/gh-564'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-564'
git switch 'github-bot/gh-564'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-564'
git switch 'main'
git merge --squash 'github-bot/gh-564'
git switch 'main'
git merge --ff-only 'github-bot/gh-564'
git switch 'main'
git merge 'github-bot/gh-564'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.