Skip to content

compute: allow implicit-derivative image sampling in direct compute - #3255

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:compute-implicit-deriv
Nov 28, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:compute-implicit-deriv

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Part of #2935 and #3224. Target branch main.

Change (src/gfx1013_direct_compute.inl, src/dxil_module.h): direct compute accepts implicit-derivative image operations (image_sample, image_sample_b, image_sample_c, image_gather4, image_get_lod) when the guest group has a multiple of four threads. Other group sizes keep "implicit derivatives require a pixel stage".

  • The guest model the repository already uses (src/wave64_emulate.hlsli) treats a compute quad as four consecutive lanes, with ddx from lane ^ 1 and ddy from lane ^ 2. SM 6.6 forms its compute quads from four consecutive threads when numthreads is one-dimensional. For a 2D group it uses 2x2 blocks instead.
  • So a module that uses implicit derivatives declares numthreads(X*Y*Z, 1, 1). initialize() still rebuilds the guest x/y/z IDs from the logical lane index (wave rank * 32 + host lane) with the original shape. This relies on host lane order following thread order within a wave, which the test checks on the RTX only.
  • The wave64 split falls at lane 32, which is a quad boundary.
  • Such a module declares DXIL validator 1.8 (!dx.valver). Validator 1.6 rejects derivative operations in compute with "Function uses features incompatible with the shader stage (cs)". Every other module keeps 1.6, so no other output changes.
  • tests/native_direct_container_check.py keeps its refusal check on a six-thread group, and gains a group= argument for multi-dimensional fixtures.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, Release, on main 50e4f763 plus this commit.

  • New native_compute_implicit_lod_{controls,warp,hardware} covers (32,1,1) and (8,4,1) wave32 groups and (64,1,1) and (8,4,2) wave64 groups.
    • They sample a 32x8 three-mip texture with implicit LOD and with image_sample_l.
    • The readback is compared against the mip the guest's consecutive-lane quad selects.
    • In the 2D and 3D cases, the coordinates make the guest's vertical derivative (lane + 2) select mip 0, while a 2x2 quad (index + 8) would select mip 2.
  • Inbox WARP reports the capability skip ("requires SM 6.6, WaveOps, and a 32-lane wave"). On the RTX the hardware test passes.
  • With main's compile_dxil, the test stops at "implicit derivatives require a pixel stage".
  • The full native_|startup_compute|compile_dxil selection passes 416 of 417. native_scalar_lds_hardware fails as on main.

A limit of that test. If I remove the flattening and declare the guest's 2D numthreads, the test still passes on the RTX 5080. This driver does not appear to form 2x2 quads for 2D compute groups, so on this GPU the test cannot show that the flattening is needed. I kept the flattening because it is what SM 6.6 specifies for 2D groups. A driver that follows that rule would otherwise pair the wrong lanes. WARP cannot run this path here.

Measured with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests, base and change both on main 50e4f763.

AI-assisted.

@R0Y00 R0Y00 left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 0dc6383 on main f9286e7 (trial eebea2902a6b8194315ce5c4b7d17e8e6b36830a). Release /O2 compiler controls and the RTX readback passed. Inbox WARP returned 77. Extra source-built 4- and 12-thread single-wave groups also produced identical implicit/explicit readback. A 36-thread wave32 group still refuses at the existing partial-final-wave guard, before the complete-quad check.

Please document the accepted group shapes and lane-mapping assumption in the experiment notes. The SM 6.6 spec guarantees the matching position within each 1D quad. The current reconstruction also uses the wave rank and host lane for the full guest index. Please pin at least one sub-wave and one group with multiple guest waves, and keep the 36-thread refusal distinct from the incomplete-quad refusal.

The GPU fixture tests image_sample against explicit LOD. Separate compile probes for image_sample_b, image_sample_c and image_get_lod produced DXIL, but they do not prove the selected mip/compare/query result. Gather still refused with the test's sampler because it requires mip zero. Please either scope this PR to the readback-tested operation or add corresponding readbacks for the other paths it enables, using a mip-zero sampler for Gather and keeping a negative for an unsupported sampler.

ctest --test-dir <release-build> --no-tests=error --output-on-failure -j 1 -R "^native_compute_implicit_lod_(controls|hardware|warp)$"

Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, inbox WARP 10.0.26100.9818, D3D12 debug layer enabled on both adapters.

Additional RTX readback: 96-thread wave32 and 128-thread wave64 also matched in both the implicit and explicit cases.

image_sample, image_sample_b, image_sample_c, image_gather4 and
image_get_lod no longer refuse in direct compute when the guest group
has a multiple of four threads. The guest model treats a compute quad
as four consecutive lanes (ddx from lane ^ 1, ddy from lane ^ 2), so a module
that uses implicit derivatives declares numthreads(X*Y*Z, 1, 1), where
SM 6.6 forms quads from four consecutive threads; the guest x/y/z IDs
are still rebuilt from the logical lane index (wave rank * 32 + host
lane) with the original shape.
Such a module also declares DXIL validator 1.8, which accepts
derivative operations in compute; every other module keeps 1.6.
Groups that are not a multiple of four stay refused.

New test native_compute_implicit_lod (controls, WARP, hardware):
(32,1,1), (8,4,1), (64,1,1) and (8,4,2) groups sample a three-mip
texture with implicit LOD and with image_sample_l, and compare against
the mip the guest quad selects. native_direct_container keeps its
refusal check on a six-thread group.
…ation

Document the accepted group shapes and the lane-mapping assumption in
docs/experiments/native-compute-implicit-derivatives.md.

native_compute_implicit_lod adds (4,1,1) and (12,1,1) sub-wave groups
and (96,1,1) wave32 and (128,1,1) wave64 multi-wave groups, and keeps
the 36-thread "partial final wave in multi-wave group" refusal distinct
from the 6-thread incomplete-quad refusal. It now reads back
image_sample_b (bias +1 selects the next mip, matching image_sample_l
at that LOD), image_sample_c (LESS against a depth mip chain at the
implicit LOD), image_get_lod (clamped and unclamped LOD) and
image_gather4 with a sampler fixed to mip zero (matching
image_gather4_l at LOD 0), and keeps the refusal for implicit gather
with a sampler that is not fixed to mip zero. compute_check gains a
scalar R32_FLOAT comparison case and a mip-zero static sampler for
those cases.
@Leyukaka
Leyukaka force-pushed the compute-implicit-deriv branch from 0dc6383 to 346da2b Compare November 28, 2026 03:01
@Leyukaka

Copy link
Copy Markdown
Collaborator Author

Thanks for the review and the extra readbacks. Pushed 346da2ba, rebased on main c827d8ba, which addresses each point:

  • Experiment note. docs/experiments/native-compute-implicit-derivatives.md covers:
    • the accepted group shapes;
    • the flattened numthreads, and validator 1.8 only for these modules;
    • the lane mapping: a guest quad is four consecutive guest lanes, and the guest index is rebuilt as host wave rank * 32 + host lane;
    • the SM 6.6 "1D quads" guarantee, plus the assumption that host lane order follows thread order within a wave, across quads.
      It is linked from docs/experiments.md.
  • Group shapes. native_compute_implicit_lod adds:
    • the (4,1,1) and (12,1,1) sub-wave groups;
    • the (96,1,1) wave32 and (128,1,1) wave64 multi-wave groups.
      It keeps the earlier 32- and 64-thread shapes, including (8,4,1) and (8,4,2). The controls check two distinct refusals: the 36-thread wave32 group stops at "partial final wave in multi-wave group", and the 6-thread group stops at "implicit derivatives require a pixel stage".
  • Readbacks for every enabled operation. Each one is checked against a CPU reference:
    • image_sample_b: bias +1 selects mip 2, the same as image_sample_l at LOD 2;
    • image_sample_c: LESS against a depth mip chain, at the implicit LOD 1;
    • image_get_lod: the clamped and unclamped LOD;
    • image_gather4: with a sampler fixed to mip zero, it returns the four mip-0 taps, the same as image_gather4_l at LOD 0.
      The refusal for implicit Gather with a constant sampler that is not fixed to mip zero stays as a negative. compute_check gains a scalar R32_FLOAT comparison case and a mip-zero static sampler, both used only by these cases.

Results:

  • On an NVIDIA GeForce RTX 5080 (Windows 11, Release, driver 32.0.16.2101), native_compute_implicit_lod_controls and _hardware pass. Inbox WARP reports the capability skip.
  • ctest -R "native_|startup_compute|compile_dxil|compute_" passes on a full build, except native_scalar_lds_hardware, which fails as on main.
  • Mutation checks by hand:
    • forcing the bias to 0.0 fails the bias-plus-one readback;
    • swapping the clamped and unclamped image_get_lod outputs fails the get-lod readback.

AI-assisted.

Copy link
Copy Markdown

I checked the distinction in your experiment note. Swapping two intact four-thread quads within one host wave keeps each lane's within-quad position but changes eight reconstructed guest indices. That is a CPU counterexample to the weaker assumption, independent of whether a specific GPU ever uses that layout. I opened a pinned AMD replay in PortBridge for your new 346da2ba head, including the 6-thread and 36-thread refusal controls. If an independent run comes back, I’ll link its exact case results here.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes at 346da2ba answer the earlier review. The docs now spell out the desktop quad-lane ordering assumption. The launch bounds and shape controls cover partial and multiple waves, and the fixture checks sample, bias, comparison, clamped/unclamped LOD queries, and gather separately. The deliberately distinct values make the output controls sensitive to selecting the wrong mip.

I built the integration tree 8178cd9f on main 0637fced. Debug and Release /O2 each had 3 passes and one WARP capability skip:

ctest --test-dir out/b/<configuration> --no-tests=error --output-on-failure -j 1 -R '^(native_compute_implicit_lod_(controls|warp|hardware)|native_direct_container)$'

I then rebuilt against main 9872074a (tree 3ae3518f). Release /O2 passed the derivative controls and hardware value checks plus both adjacent MIMG cache-flag hardware cases. WARP still returned a capability skip.

ctest --test-dir out/b/release --no-tests=error --output-on-failure -j 1 -R '^(native_compute_implicit_lod_(controls|warp|hardware)|native_image_cache_flags_(ps_hardware|cs_hardware))$'

Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818 and DXC 10.0.26100.0. Hosted Windows CI is green. Hardware readbacks verify the tested adapter.

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

There is now a physical AMD result for the lane-order assumption. The RX 9060 XT report on #3241 reproduces the same failure on unmodified main a44e1f95 and the refreshed compiler stack 4a007912. For the (8,4,1) case, native_compute_implicit_lod_hardware expected 0x3f800000 and read 0x3f948000. RX 9060 XT driver 32.0.32029.2010, Windows 11 build 26300. The published 1D cases and compile controls passed on that adapter. Our independent RTX 4060 run passed the hardware fixture.

This gives the existing AMD replay a pinned main failure to compare against. Please preserve the (8,4,1) reproducer and compare the actual per-thread index mapping and the explicit-LOD control before attributing the mismatch.

Copy link
Copy Markdown

I recorded lambirou’s AMD result in the existing PortBridge replay. The old fixture can stop on the first mismatch before it runs explicit LOD. This test-only patch applies to a44e1f95 and prints separate implicit and explicit results for the same (8,4,1) case. A CPU check injected a failure in the first arm and confirmed the other arm still runs and the overall test stays failing. The reported word is 1.16015625, outside the fixture’s three solid mip colours, so I would keep sampler and coordinate behaviour open alongside lane order.

If you or your agent are already rerunning the AMD case, two labelled lines and the (12,1,1) control in #159 would answer the next question. The commands and precise revision are ready to reuse.

Copy link
Copy Markdown
Contributor

I opened #3299 with a test-only vertical ramp and a DXIL group-dimensions check. On RTX 4070 and app-local WARP, implicit and explicit LOD each match all eight group cases. An independent HLSL spatial control changes all 32 mip results on both adapters.

The (8,4,1) case is still the useful AMD retest. If you have time to rerun it on RX 9060 XT, the implicit and explicit readbacks from #3299 would show whether the original fractional value persists with zero horizontal derivative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants