runtime: bind constant static samplers on the in-process compute route #3154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3154"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-27T18:51:27Z.
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,
mainitself 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 onmainatf5a6f6ba(af6045dfchange and fixture,93582447docs). The earlier heads (f4836244,82117f07,876bb210) were stacked on #3049.With
X2W_NATIVE_SHADERSset,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 togfx2hlsl.py. The C++ compiler already resolves a sampler whose four words are constants into aComputeSampler. This change binds them:program.samplersfills the route'sTranslatedSamplersin register order, and the existingcreate_translated_root/decode_staticscreate the static samplers. A comparison sampler is bound assmpc; any other withexplicit_lodassmpl, with the descriptor's MIN_LOD and MAX_LOD. This is the choiceformat_graphics_runtime_manifestmakes (cmp ? smpc : lod ? smpl : smp).comparison_texture_srv, 2D) binds like a plain 2D texture input. Without this a comparison sampler is unreachable ("view kind 11 is not bound").slot.srv_dimension. Onmainit 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 onmaina natively translated program cannot read a 2D texture at all; the third mutation below shows it.<key>.txtread next numbers its sampler lines from 0. This follows from the manifest reader's index check; no run exercises it.Points that differ from the plan in #3149 (see the comments there):
explicit_lodon every sampler it emits, so this route produces no plainsmpsampler. The conversion keeps the case; the fixture cannot cover it.translate_compute("nonconstant sampler") before the stand-in binds anything, so the sampler clause is dropped from the message, not split off.heap_samplerview 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.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.prpreset, which does not include these tests.Mutations, each applied alone to
d3d12_compute_dispatch.inlataf6045df, with the stand-in rebuilt andstartup_compute_dispatch_native_hardwarererun:main(f5a6f6ba)not translated natively: view kind 11 is not bound for a natively translated programnot translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path bindsDispatch(2, 1, 1) refused: an input texture view is not 3Dlod_limitsalways falsesampled: word 2049 got=bf000080 expected=bf000000 (32 words differ)comparisonalways falsesampled: word 2051 got=bf000080 expected=00000000 (16 words differ)sampled: word 2049 got=bf000080 expected=bf000000 (56 words differ)Evidence and follow-up
tests/startup_compute_dispatch_native_check.pyand the consumer modetexture-volume-native-sampled(the existing 3D float store plus a sampled input texture). Instruction words are hand-encoded and checked against thegfx2hlsldecoder inside the test. The guest root with two SRV records and one UAV record follows the table layout #3049's fixture uses.image_sample_lz(wrap),image_sample_lwith LOD 1.25 under a [0, 0] clamp (mirror),image_sample_lwith LOD 0 under a [1, 1] clamp, andimage_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.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.Checklist
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T23:55:24Z.
Review of
f4836244: Binds constant static samplers on the in-process compute route.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T07:39:41Z.
Thanks for this. I reviewed head
82117f07and a trial merge of it into currentmain(c3204a9c). The sampler binding itself looks sound to me. Outside pixel stages, compute comparisons are level-zero only, because op 40 is refused withimplicit derivatives require a pixel stage.first_sampleris set only inlower_graphics, so compute sampler i is register i, asdecode_staticsexpects. The src diff afterc3e3073eadds no DXIL opcodes.Two things need fixing before this can land:
git merge-tree --write-tree origin/main 82117f07exits 1 with conflicts insrc/startup_stubs/d3d12_compute_dispatch.inl(3 hunks) andtests/startup_stream_consumer.cpp(1 hunk). In the view loop,main(#3243) now binds texture outputs throughexact_texture_uav_channelsandslot.channels. #3049'stexture_output/dimensionswitch and this PR'scomparison_texture_srvinput need to be merged into that by hand, then rebuilt and rerun against both fixtures. The PR also carries #3049, whichgh pr view 3049 --json state,mergeablereports asOPEN CONFLICTING. The cleanest route may be to land or rebase #3049 first, then rebase this PR onto it.the native route left ['revision.txt'] in the cache. On the trial merge, #3231 fixes step 1 (p.name not in ('native', 'revision.txt')). But the two asserts that #3049 adds at the end oftable_viewsandtexture_outputsstill readassert all(p.name.startswith('req_') or p.name == 'native' for p in cache.iterdir()), andgit grep -nfinds both in the merged tree. The stand-in writesrevision.txtonce 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 #3049, should fix it.Non-blocking:
smpcassmpis 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 withcomparisonforced false and one withprogram.samplersreversed, each with its debug-layer output.startup-compute-native-samplers.md) and the body say "#3228 changes the step 1 assertion". #3228 was closed without merging; the fix onmainis #3231 (38129ba3).36a17075before the rebase. Rerunning the hardware test and the mutations on the final head would bring the evidence up to date.ctest --preset pr(100% tests passed out of 69), and its log has 0startup_compute_dispatch_nativelines. 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.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-28T11:33:38Z.
Thanks for the review. The head is now
876bb210; the body is updated to match.main, so this branch carries my own merge of1356e232intomainatee3347d3(553be4b0). In the view loop,main's exact-width outputs (exact_texture_uav_channels,slot.channels) and #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 setsslot.srv_dimension, which the dispatch path reads since #3306. Without it the input is refused as "not 3D". If #3049 resolves its conflicts differently, I will rebase onto it again.revision.txt.94f2c8bcadds the exception to the two assertions that closetable_viewsandtexture_outputs. #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 sevennative_image_store_exact_width_hardware_*cases formain's side of the merged loop and bothstartup_compute_dispatch_texture_*hardwaretests. The command is in the body.On the non-blocking points:
comparisonforced false givesword 2051 got=bf000080 expected=00000000 (16 words differ), and reversed samplers giveword 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.c8f0f702; the table in the body is from that run.prpreset does not run this route. The body says so.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-28T17:35:02Z.
Update: the head is now
93582447, and this PR no longer carries #3049.#3241 rewrote the binding loop in
translate_compute_nativelyagain, andmainnow 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 onmainatf5a6f6baand ported the fixture: step 5 of the check has its own table root setup, and the consumer mode sits on top ofmain's volume store mode. The body is rewritten to match.One thing came out of that: on
maina natively bound 2D texture input never setsslot.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, includingcomparisonforced false and reversed samplers.The
revision.txtcommit 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.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T00:11:09Z.
Review: APPROVED
Review of
93582447: diff read againstmain51472392, into which it merges cleanly, plus a build of this head merged withmain8ecd30fein an offline Windows Sandbox (RTX 5080 vGPU).Checked against
main:program.samplers.decode_staticsandnative_compute_pipeline.cpp:58number them the same way.srv_dimensionfix is needed. Onmain, an input slot withD3D12_SRV_DIMENSION_UNKNOWNgoes down the non-2D branch of the dispatch path (d3d12_compute_dispatch.inl:687-697), so every described 2D view is refused there.comparison_texture_srvis the kindgfx1013_direct_compute.inlgives a non-cube compare sample, andimage_dimension == 1limits it to 2D.Non-blocking:
tr.samplers = {};(d3d12_compute_dispatch.inl:295); the body says no run exercises it. The samplers are pushed before the wave-size check, so a refusal on an adapter without 32-lane waves keeps them. If a published<key>.txtwithsmp*lines is read after that, its line 0 failsi == tr.samplers.statics.size()and the translation is refused as "a sampler that is not a plain static one". On the no-waves path of step 5, publishing a translation for the sampled program and checking that it runs would cover the line.lod_limits = explicit_lod && !comparisonfollows the manifest writer (direct_compute_cache.cpp:1120-1121).native_compute_pipeline.cpp:58passesexplicit_lodfor comparison samplers too. The two give the same result here only because comparisons sample level 0 and MIN_LOD is 0.Not covered: CI's
prpreset does not runstartup_compute_dispatch_native_*, and WARP exits 77. In the Sandbox buildstartup_compute_dispatch_native_hardwarepassed, and failed withtr.samplers.comparison.push_back(sampler.comparison);changed totr.samplers.comparison.push_back(false);ind3d12_compute_dispatch.inl.Verdict: approve.