Skip to content

runtime: bind constant static samplers on the in-process compute route - #3154

Open
Not-Saii wants to merge 2 commits into
R0Y00:mainfrom
Not-Saii:claude/native-compute-static-samplers-13b9d3
Open

Not-Saii wants to merge 2 commits into
R0Y00:mainfrom
Not-Saii:claude/native-compute-static-samplers-13b9d3

Conversation

@Not-Saii

@Not-Saii Not-Saii commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

Target branch main. Fixes #3149. Part of #2935 (item "Samplers") and #3074 (stage 5). Follow-up to #3075 / #3083, which covers the published-manifest route.

No longer depends on #3049. Since #3241, main itself accepts a 2D texture input and a 3D float texture output on the in-process route, which is all this fixture needs. The branch is now two commits on main at f5a6f6ba (af6045df change and fixture, 93582447 docs). The earlier heads (f4836244, 82117f07, 876bb210) were stacked on #3049.

With X2W_NATIVE_SHADERS set, translate_compute_natively (src/startup_stubs/d3d12_compute_dispatch.inl) refuses every program with a sampler, so a natively translated compute program that samples falls back to gfx2hlsl.py. The C++ compiler already resolves a sampler whose four words are constants into a ComputeSampler. This change binds them:

  • program.samplers fills the route's TranslatedSamplers in register order, and the existing create_translated_root / decode_statics create the static samplers. A comparison sampler is bound as smpc; any other with explicit_lod as smpl, with the descriptor's MIN_LOD and MAX_LOD. This is the choice format_graphics_runtime_manifest makes (cmp ? smpc : lod ? smpl : smp).
  • The texture of a comparison sample (comparison_texture_srv, 2D) binds like a plain 2D texture input. Without this a comparison sampler is unreachable ("view kind 11 is not bound").
  • A natively bound 2D texture input now sets slot.srv_dimension. On main it stays unset, and the dispatch path then takes the input for a described 1D, 2D-array or 3D view and refuses the Dispatch with "an input texture view is not 3D". So on main a natively translated program cannot read a 2D texture at all; the third mutation below shows it.
  • A refused native translation clears its samplers, so a published <key>.txt read next numbers its sampler lines from 0. This follows from the manifest reader's index check; no run exercises it.
  • The capacity refusal now reads "more entry values, inputs or outputs than the dispatch path binds".

Points that differ from the plan in #3149 (see the comments there):

  • The direct compute path sets explicit_lod on every sampler it emits, so this route produces no plain smp sampler. The conversion keeps the case; the fixture cannot cover it.
  • The route keeps no sampler refusal of its own. Sampler words that are not constants are refused inside translate_compute ("nonconstant sampler") before the stand-in binds anything, so the sampler clause is dropped from the message, not split off.
  • The sampler heap is untouched (native: read sampler descriptors from the directly indexed sampler heap #3076). Since native: read fixed-index samplers from the directly indexed sampler heap #3140 a fixed-index sampler of the directly indexed sampler heap reaches the route as a heap_sampler view and is refused by the view-kind message. This is read from the code and was not run.

Verification

Environment: Windows 11 build 26300.9974, NVIDIA GeForce RTX 4090 (driver 32.0.16.1088), MSVC 14.44.35207, Windows SDK 10.0.26100 DXC, Debug build, D3D12 debug layer enabled. Commit af6045df.

.\tools\dev.ps1
cmake --build --preset dev --target d3d12_xs_shim startup_stream_consumer compile_dxil
ctest --preset dev --no-tests=error -V -R '^(startup_compute_dispatch_native_(hardware|warp)|native_image_store_exact_width_hardware_(r|rg|rgb|array|volume|rgba|sparse)|startup_compute_dispatch_texture_hardware|startup_compute_descriptor_scc_hardware)$'
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py

11 tests selected: 10 passed, 1 capability skip, 0 failed.

  • startup_compute_dispatch_native_hardware: PASS (5.4 s). The four sampled channels match the CPU model in all 6,144 volume words, the memory sampler control leaves the volume untouched, and the other steps pass. No debug-layer error message.
  • native_image_store_exact_width_hardware_{r,rg,rgb,array,volume,rgba,sparse}: PASS (7 tests, the same binding loop).
  • startup_compute_dispatch_texture_hardware: PASS (shares the consumer's texture modes).
  • startup_compute_descriptor_scc_hardware: PASS.
  • startup_compute_dispatch_native_warp: capability skip (77), not a pass. The Microsoft Basic Render Driver 10.0.26100.9818 reports no 32-lane waves. Before it exits, the check confirms the sampled program is refused by that reason with the volume untouched, and the memory sampler control is refused with "nonconstant sampler".
  • docs_links: 157 Markdown files and 682 links checked. bidi_controls: no bidirectional controls.
  • Not run: the rest of the suite. Only the three targets above were rebuilt. The Windows CI job runs the pr preset, which does not include these tests.

Mutations, each applied alone to d3d12_compute_dispatch.inl at af6045df, with the stand-in rebuilt and startup_compute_dispatch_native_hardware rerun:

Mutation Result
The file as on main (f5a6f6ba) FAIL: not translated natively: view kind 11 is not bound for a natively translated program
Only the sampler check restored FAIL: not translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path binds
The 2D input dimension left unset FAIL: Dispatch(2, 1, 1) refused: an input texture view is not 3D
lod_limits always false FAIL: sampled: word 2049 got=bf000080 expected=bf000000 (32 words differ)
comparison always false FAIL: sampled: word 2051 got=bf000080 expected=00000000 (16 words differ)
Samplers bound in reverse register order FAIL: sampled: word 2049 got=bf000080 expected=bf000000 (56 words differ)
Restored PASS

Evidence and follow-up

  • The fixture is source-built: step 5 of tests/startup_compute_dispatch_native_check.py and the consumer mode texture-volume-native-sampled (the existing 3D float store plus a sampled input texture). Instruction words are hand-encoded and checked against the gfx2hlsl decoder inside the test. The guest root with two SRV records and one UAV record follows the table layout runtime: bind native compute table buffers and texture views #3049's fixture uses.
  • One program samples a 2x1 R32_FLOAT texture with a 1x1 second mip four times: image_sample_lz (wrap), image_sample_l with LOD 1.25 under a [0, 0] clamp (mirror), image_sample_l with LOD 0 under a [1, 1] clamp, and image_sample_c_lz (LESS). U and the reference double with the global X, so a row covers both texels, three address modes and both comparison results. The CPU model decodes the address mode, the LOD limits and the comparison from the sampler words.
  • Control: native compute: bind constant static samplers on the in-process route #3149 planned a heap-loaded sampler. The control loads the first sampler's words from the descriptor table instead, because a sampler-heap sampler needs a root with both heap-indexing flags and is refused by the view-kind message, which does not name samplers. The table-loaded words are refused with "nonconstant sampler" and the output stays untouched.
  • Limits (also in docs/experiments/startup-compute-native-samplers.md): constant sampler words only; one texture format with point filters; no plain sampler; one adapter in a Debug build; no start-up run used the switch. A comparison sampler is bound without LOD limits, as on the published route. The compute path compares at level zero and the compiler requires MIN_LOD 0, so the limits cannot change the result.
  • runtime: bind native compute table buffers and texture views #3049 will conflict with this in the binding loop and the check; whichever lands second needs a small rebase.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

@KelboLive

Copy link
Copy Markdown
Contributor

Review of f4836244: Binds constant static samplers on the in-process compute route.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for this. I reviewed head 82117f07 and a trial merge of it into current main (c3204a9c). The sampler binding itself looks sound to me. Outside pixel stages, compute comparisons are level-zero only, because op 40 is refused with implicit derivatives require a pixel stage. first_sampler is set only in lower_graphics, so compute sampler i is register i, as decode_statics expects. The src diff after c3e3073e adds no DXIL opcodes.

Two things need fixing before this can land:

  1. It doesn't merge, and one conflict is semantic. git merge-tree --write-tree origin/main 82117f07 exits 1 with conflicts in src/startup_stubs/d3d12_compute_dispatch.inl (3 hunks) and tests/startup_stream_consumer.cpp (1 hunk). In the view loop, main (compute: store prefix-mask images at their exact width in direct compute #3243) now binds texture outputs through exact_texture_uav_channels and slot.channels. runtime: bind native compute table buffers and texture views #3049's texture_output/dimension switch and this PR's comparison_texture_srv input need to be merged into that by hand, then rebuilt and rerun against both fixtures. The PR also carries runtime: bind native compute table buffers and texture views #3049, which gh pr view 3049 --json state,mergeable reports as OPEN CONFLICTING. The cleanest route may be to land or rebase runtime: bind native compute table buffers and texture views #3049 first, then rebase this PR onto it.
  2. The registered check still fails after the merge. As the body says, step 1 fails with the native route left ['revision.txt'] in the cache. On the trial merge, tests: ignore the shader cache revision stamp in two exact-set checks #3231 fixes step 1 (p.name not in ('native', 'revision.txt')). But the two asserts that runtime: bind native compute table buffers and texture views #3049 adds at the end of table_views and texture_outputs still read assert all(p.name.startswith('req_') or p.name == 'native' for p in cache.iterdir()), and git grep -n finds both in the merged tree. The stand-in writes revision.txt once per process (d3d12_draw.inl: "revision.txt names this runtime's revisions"), so the check would still fail after the sampler step. Adding the same exception to both asserts, here or in runtime: bind native compute table buffers and texture views #3049, should fix it.

Non-blocking:

  • The body notes that no mutation covers the comparison flag or the sampler register order. In D3D12, binding smpc as smp is undefined, so a wrong flag may not show up as a wrong value. After the rebase, two hardware runs would show whether the fixture catches either: one with comparison forced false and one with program.samplers reversed, each with its debug-layer output.
  • The doc (startup-compute-native-samplers.md) and the body say "Allow the revision marker in the native Dispatch cache check #3228 changes the step 1 assertion". Allow the revision marker in the native Dispatch cache check #3228 was closed without merging; the fix on main is tests: ignore the shader cache revision stamp in two exact-set checks #3231 (38129ba3).
  • The mutation table ran on 36a17075 before the rebase. Rerunning the hardware test and the mutations on the final head would bring the evidence up to date.
  • All three CI jobs pass, but the Windows job runs ctest --preset pr (100% tests passed out of 69), and its log has 0 startup_compute_dispatch_native lines. So CI doesn't exercise this route.

Environment: Linux, git objects, a trial merge and pure-Python probes only. I did no build, WARP or GPU run.

This comment was AI-assisted.

@Not-Saii
Not-Saii force-pushed the claude/native-compute-static-samplers-13b9d3 branch from 82117f0 to 876bb21 Compare November 28, 2026 11:32
@Not-Saii

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The head is now 876bb210; the body is updated to match.

  1. Conflicts. runtime: bind native compute table buffers and texture views #3049 still conflicts with main, so this branch carries my own merge of 1356e232 into main at ee3347d3 (553be4b0). In the view loop, main's exact-width outputs (exact_texture_uav_channels, slot.channels) and runtime: bind native compute table buffers and texture views #3049's four-channel float outputs, 2D texture inputs and scalar buffers are both kept, each with its own dimension mapping. One line is new to both sides: a 2D texture input sets slot.srv_dimension, which the dispatch path reads since runtime: bind 1D, 2D-array and 3D texture SRVs for published native compute #3306. Without it the input is refused as "not 3D". If runtime: bind native compute table buffers and texture views #3049 resolves its conflicts differently, I will rebase onto it again.
  2. revision.txt. 94f2c8bc adds the exception to the two assertions that close table_views and texture_outputs. runtime: bind native compute table buffers and texture views #3049 can take that commit or make the same edit.

Rerun on the RTX 4090 (driver 32.0.16.1088, Debug, debug layer on), 12 tests selected: 11 passed, 1 capability skip (startup_compute_dispatch_native_warp, 77), 0 failed. The set includes the seven native_image_store_exact_width_hardware_* cases for main's side of the merged loop and both startup_compute_dispatch_texture_*hardware tests. The command is in the body.

On the non-blocking points:

  • Comparison flag and register order. Both mutations were run and both fail by readback: comparison forced false gives word 2051 got=bf000080 expected=00000000 (16 words differ), and reversed samplers give word 2049 got=bf000080 expected=bf000000 (56 words differ). The log tail the check prints on failure holds no debug-layer message for either, so the layer is not what detects the wrong flag here.
  • Allow the revision marker in the native Dispatch cache check #3228. Fixed: the note and the body now cite tests: ignore the shader cache revision stamp in two exact-set checks #3231.
  • Evidence on the final head. The hardware test and all five mutations were rerun at c8f0f702; the table in the body is from that run.
  • CI. Agreed, the pr preset does not run this route. The body says so.

AI-assisted.

Not-Saii and others added 2 commits November 28, 2026 16:26
translate_compute_natively refused every program with a sampler. The C++
compiler already resolves constant sampler words into ComputeSampler
entries, so they now fill the route's TranslatedSamplers in register
order and the existing root signature code creates the static samplers:
a comparison sampler as smpc, any other with explicit_lod as smpl, the
choice format_graphics_runtime_manifest makes. A comparison sample's 2D
texture (comparison_texture_srv) binds like a plain texture input. A
refused native translation clears the samplers so a published manifest
read next numbers its sampler lines from 0.

A natively bound 2D texture input now sets slot.srv_dimension. The
dispatch path treats any other value as a described 1D, 2D-array or 3D
view and refused the input as "not 3D".

Sampler words that are not constants (a sampler read from memory) are
refused by the compiler before this code runs, so the route itself no
longer has a sampler refusal; the capacity message drops that clause.

startup_compute_dispatch_native_check.py gains step 5: four samples of a
two-mip 2x1 R32_FLOAT texture (new consumer mode
texture-volume-native-sampled) through four constant samplers: wrap,
mirror under a MAX_LOD clamp, clamp under a MIN_LOD clamp, and a LESS
comparison. Every stored word is compared with a CPU model of the sampler
words. A sampler loaded from the table stays refused with the volume
untouched.

Refs R0Y00#3149

AI-assisted.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
docs/experiments/startup-compute-native-samplers.md describes what
translate_compute_natively binds for a constant sampler, the four-sampler
fixture and its memory sampler control, the hardware results on an RTX
4090, the WARP capability skip and six mutations of the change.
docs/startup-runtime.md and the route note no longer list every sampler
among the refusals.

Refs R0Y00#3149

AI-assisted.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@Not-Saii
Not-Saii force-pushed the claude/native-compute-static-samplers-13b9d3 branch from 876bb21 to 9358244 Compare November 28, 2026 17:35
@Not-Saii

Copy link
Copy Markdown
Contributor Author

Update: the head is now 93582447, and this PR no longer carries #3049.

#3241 rewrote the binding loop in translate_compute_natively again, and main now accepts a 2D texture input and a 3D float output on this route by itself. That is all the fixture needs, so I rebuilt the change as two commits directly on main at f5a6f6ba and ported the fixture: step 5 of the check has its own table root setup, and the consumer mode sits on top of main's volume store mode. The body is rewritten to match.

One thing came out of that: on main a natively bound 2D texture input never sets slot.srv_dimension, and the dispatch path then refuses it with "an input texture view is not 3D". This PR sets it. With that line removed the fixture fails with exactly that refusal.

Rerun on the RTX 4090 (driver 32.0.16.1088, Debug, debug layer on), 11 tests selected: 10 passed, 1 capability skip (startup_compute_dispatch_native_warp, 77), 0 failed. All six mutations fail as listed in the body, including comparison forced false and reversed samplers.

The revision.txt commit is gone from this branch because #3049's two assertions are no longer in it. #3049 still needs that exception when it is refreshed.

AI-assisted.

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.

native compute: bind constant static samplers on the in-process route

3 participants