Request Shader Model 6.6 for non-pixel implicit texture samples #368

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

@⁠lex021 on GitHub · 2026-11-24 16:43 UTC · original
lex021:pr/compute-sampling-sm66 → main · +3 −0 · 1 files · 1 commits · open

Summary

Select Shader Model 6.6 when a compute, mesh, or amplification shader emits an implicit-derivative texture sample. DirectX Shader Compiler rejects those operations at earlier shader models. Pixel shaders and explicit-LOD samples retain their existing profile selection.

Validation

  • cargo test --offline --locked -p tombox-xshader --lib on Windows (116 passed, 3 ignored).
  • The upstream PR gate accepts this one-file change.
**@⁠lex021** on GitHub · 2026-11-24 16:43 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/368) `lex021:pr/compute-sampling-sm66` → `main` · +3 −0 · 1 files · 1 commits · open ## Summary Select Shader Model 6.6 when a compute, mesh, or amplification shader emits an implicit-derivative texture sample. DirectX Shader Compiler rejects those operations at earlier shader models. Pixel shaders and explicit-LOD samples retain their existing profile selection. ## Validation - `cargo test --offline --locked -p tombox-xshader --lib` on Windows (116 passed, 3 ignored). - The upstream PR gate accepts this one-file change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:20:31 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:51 UTC · original

Thanks. Could you add an exec test showing implicit-LOD sampling in a compute shader with a 2D thread group gives the RDNA2 quad results? Without it we cannot check the quad layout.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/368#issuecomment-7164388355) Thanks. Could you add an exec test showing implicit-LOD sampling in a compute shader with a 2D thread group gives the RDNA2 quad results? Without it we cannot check the quad layout.
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 14:53 UTC · original

@⁠omonkeyz, I was looking through open PRs for things I could test on RDNA2 hardware and saw your request here for the quad layout. So I measured which lanes RDNA2 uses for implicit derivatives in compute. The probe ran on a gfx1036 iGPU (Ryzen 5 9600X) with ROCm/HIP and raw wave32 kernels. That's RDNA2, not the console's gfx1013.

Probe

  • A compute kernel with image_sample (implicit LOD) on a 16x16 R32_FLOAT texture. It has 5 mips, point mip filter, and each texel holds mip * 1000 + y * 16 + x, so the result shows the mip that was picked.
  • Every thread samples at u = v = 0.53, so its derivatives are 0 and it gets mip 0. Each case adds 0.25 to u (or, in a second set, to v) in one thread p only. Any thread whose result moves off mip 0 used p for its derivatives.
  • Each thread also records v0, v1 and its lane.
  • Group shapes: (8,8), (4,4), (2,8), (16,4) and (32,2), .amdhsa_system_vgpr_workitem_id 1. Every thread p was perturbed, in u and in v.

Result

Identical for all five shapes:

  • Lane order. lane = (y·X + x) mod 32, with v0 = x and v1 = y. Threads go into waves in flat order, x fastest.
  • Quads. The derivative quad is always 4 consecutive lanes (lanes 4k to 4k+3), never a 2x2 block of (x, y). Perturbing a thread changed results only inside its own 4-lane group.
  • Coarse derivatives. Perturbing quad lane 0, 1 or 2 moved all four lanes to a higher mip. Perturbing lane 3 changed nothing. So image_sample uses ddx = lane 1 − lane 0 and ddy = lane 2 − lane 0 for the whole quad.

So in an (8,8) group, RDNA2's "vertical" neighbour of (x, y) is (x+2, y), not (x, y+1). In a D3D 2x2 quad, only the horizontal neighbours also share a hardware quad. The vertical and diagonal ones never do: that is 128 of the 192 ordered pairs in (8,8), and 32 of 48 in (4,4). (2,8) is the only shape here where the two layouts coincide.

What this means for this PR

The SM 6.6 derivatives spec (HLSL_SM_6_6_Derivatives.md in DirectX-Specs) uses 1D quads only when X is divisible by 4 and Y = Z = 1. For any group where X and Y are divisible by 2, it uses 2x2 quads of SV_GroupThreadID. In that mode it also says "no relation between the values of SV_GroupIndex and the return value of WaveGetLaneIndex() should be assumed". The translator keeps [numthreads(X, Y, Z)] and sets v0..v2 from SV_GroupThreadID. So with this change, a 2D group:

  • would take derivatives over 2x2 blocks, where RDNA2 uses 4-lane rows;
  • may also get a lane order that isn't flat, which matters to every wave op the translator emulates by lane.

One way to get the RDNA2 layout: when a compute shader has an implicit-derivative sample, declare [numthreads(X·Y·Z, 1, 1)] and rebuild v0 = i % X, v1 = (i / X) % Y, v2 = i / (X·Y) from SV_GroupIndex. D3D's 1D quads are then exactly lanes 4k to 4k+3 in flat order. That needs X·Y·Z divisible by 4, which D3D requires too; otherwise the shader would have to be refused. The same applies to mesh and amplification shaders.

For the exec test you asked for, a case that separates the two layouts: an (8,8) group sampling at u = 0.53 + 0.25·y, v = 0.53 on a 16x16 texture with 5 mips.

  • RDNA2: each 4-lane quad lies in one row, so u is constant within it. The derivatives are 0 and every thread gets mip 0.
  • D3D 2x2 quads: ddy = 0.25, which is 4 texels, so mip 2.

That result doesn't depend on coarse vs fine, which D3D leaves open for implicit samples.

If it helps, I can send a PR on top of this one with the probe (in tools/rdna2-hwprobe/ next to mip_probe.py), a compute exec harness with a bound texture (the current compute harness has none), that test, and the flattening. @⁠lex021, if you'd rather do it in this PR, that's fine too.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 14:53 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/368#issuecomment-7165982068) @⁠omonkeyz, I was looking through open PRs for things I could test on RDNA2 hardware and saw your request here for the quad layout. So I measured which lanes RDNA2 uses for implicit derivatives in compute. The probe ran on a gfx1036 iGPU (Ryzen 5 9600X) with ROCm/HIP and raw wave32 kernels. That's RDNA2, not the console's gfx1013. ### Probe - A compute kernel with `image_sample` (implicit LOD) on a 16x16 R32_FLOAT texture. It has 5 mips, point mip filter, and each texel holds `mip * 1000 + y * 16 + x`, so the result shows the mip that was picked. - Every thread samples at u = v = 0.53, so its derivatives are 0 and it gets mip 0. Each case adds 0.25 to u (or, in a second set, to v) in one thread `p` only. Any thread whose result moves off mip 0 used `p` for its derivatives. - Each thread also records `v0`, `v1` and its lane. - Group shapes: (8,8), (4,4), (2,8), (16,4) and (32,2), `.amdhsa_system_vgpr_workitem_id 1`. Every thread `p` was perturbed, in u and in v. ### Result Identical for all five shapes: - **Lane order.** lane = (y·X + x) mod 32, with `v0` = x and `v1` = y. Threads go into waves in flat order, x fastest. - **Quads.** The derivative quad is always 4 consecutive lanes (lanes 4k to 4k+3), never a 2x2 block of (x, y). Perturbing a thread changed results only inside its own 4-lane group. - **Coarse derivatives.** Perturbing quad lane 0, 1 or 2 moved all four lanes to a higher mip. Perturbing lane 3 changed nothing. So `image_sample` uses ddx = lane 1 − lane 0 and ddy = lane 2 − lane 0 for the whole quad. So in an (8,8) group, RDNA2's "vertical" neighbour of (x, y) is (x+2, y), not (x, y+1). In a D3D 2x2 quad, only the horizontal neighbours also share a hardware quad. The vertical and diagonal ones never do: that is 128 of the 192 ordered pairs in (8,8), and 32 of 48 in (4,4). (2,8) is the only shape here where the two layouts coincide. ### What this means for this PR The SM 6.6 derivatives spec (`HLSL_SM_6_6_Derivatives.md` in DirectX-Specs) uses 1D quads only when X is divisible by 4 and Y = Z = 1. For any group where X and Y are divisible by 2, it uses 2x2 quads of `SV_GroupThreadID`. In that mode it also says "no relation between the values of SV_GroupIndex and the return value of WaveGetLaneIndex() should be assumed". The translator keeps `[numthreads(X, Y, Z)]` and sets `v0..v2` from `SV_GroupThreadID`. So with this change, a 2D group: - would take derivatives over 2x2 blocks, where RDNA2 uses 4-lane rows; - may also get a lane order that isn't flat, which matters to every wave op the translator emulates by lane. One way to get the RDNA2 layout: when a compute shader has an implicit-derivative sample, declare `[numthreads(X·Y·Z, 1, 1)]` and rebuild `v0 = i % X`, `v1 = (i / X) % Y`, `v2 = i / (X·Y)` from `SV_GroupIndex`. D3D's 1D quads are then exactly lanes 4k to 4k+3 in flat order. That needs X·Y·Z divisible by 4, which D3D requires too; otherwise the shader would have to be refused. The same applies to mesh and amplification shaders. For the exec test you asked for, a case that separates the two layouts: an (8,8) group sampling at u = 0.53 + 0.25·y, v = 0.53 on a 16x16 texture with 5 mips. - RDNA2: each 4-lane quad lies in one row, so u is constant within it. The derivatives are 0 and every thread gets mip 0. - D3D 2x2 quads: ddy = 0.25, which is 4 texels, so mip 2. That result doesn't depend on coarse vs fine, which D3D leaves open for implicit samples. If it helps, I can send a PR on top of this one with the probe (in `tools/rdna2-hwprobe/` next to `mip_probe.py`), a compute exec harness with a bound texture (the current compute harness has none), that test, and the flattening. @⁠lex021, if you'd rather do it in this PR, that's fine too. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/368/head:github-bot/gh-368'
git switch 'github-bot/gh-368'

Merge

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