native: read fixed-index samplers from the directly indexed sampler heap #3140
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3140"
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 JB2WIN on 2026-11-27T17:48:52Z.
Change
Target branch
main. Refs #3076, part of #2935 (item "Samplers"). Related: #1143.In slot 67 compute requests whose root sets both heap-indexing flags (0xc00), the entry SGPR after the resource heap holds the sampler heap base. Programs copy it into an even SGPR pair with a zero high word and load one sampler with
s_load_dwordx4(or two withs_load_dwordx8) at a 16-byte aligned immediate offset, then sample withimage_sample_lz/image_sample_l. The native translator left that SGPRunbound("direct descriptor address outside bound table"), andsampler_indexaccepted literal words only ("nonconstant sampler"). This is stage 1 of #3076: the translator side.src/gfx1013_compute_native.h/.cpp: sentinelcompute_sampler_heap(~0u - 1); under the existing 0xc00 condition the SGPR after the resource heap is{table, compute_sampler_heap}.sampler_indexreturnsSamplerRef {heap, index}: four literal words keep the static-sampler path; four contiguous words of one heap entry give a heap sampler; anything else stays "nonconstant sampler". For a heap sampler: gathers, comparison samplers and gradient samplers are refused with named reasons, so onlyimage_sample_landimage_sample_lzare translated.Emit::bindingrefuses a sampler-heap descriptor used as a resource; the HLSL path refuses sampler-heap reads.src/gfx1013_direct_compute.inl: loads from the sampler heap are refused, in order, for scalar buffer loads, SGPR offsets (a GPU-selected sampler), widths other thandwordx4/dwordx8, offsets that are not a multiple of 16, and entries above 2046 (2047 is the runtime fallback entry,translated_sampler_fallback). A heap sampler becomesSamplerDescriptorHeap[index].src/dxil_module.h:sampler_heap_handleemitscreateHandleFromHeap(i32 218, i32 <index>, i1 true, i1 false)+annotateHandle{14, 0}; module flag0x80000000. This is what DXC emits forSamplerDescriptorHeap[67]+SampleLevelin cs_6_6.ComputeViewKind::heap_sampler(one binding per program,required_bytes = 16 * (highest index + 1));src/direct_compute_cache.cppaccepts the kind with exactly that root value and keeps the old check for every other kind.format_compute_runtime_manifestwrites no manifest for it and the in-process route refuses it, so nothing reaches a run until stage 2.src/native_compute_pipeline.h/.cpp:sampler_heap_indexedadds root flag0x800(no0x400for a sampler-only program);bind()takes the shader-visible sampler heap as a new last parameter (existing callers unchanged).tools/startup/compile_dxil.cpp: reportssampler_heap span=<bytes>.Why this step: on a local start-up capture (counts only, 2,689 slot 67 requests), 1,830 sample or gather and 993 load at least one sampler from memory. On
mainthis is never the first refusal yet:compile_dxil --refusalsat36d2cbebis identical before and after this change. With the GPU-selected heap chain of #3023 applied locally (#3034, #3042, #3063, contract forced by an uncommitted switch), 130 requests stop first at such a sampler-heap load. This change removes that blocker. The compiled-count effect on that chain was not measured here, because the patch does not apply tocpp-migrationas is.Verification
Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), MSVC 14.51.36231, Windows SDK 10.0.26100 DXC. Developed on
main36d2cbeb, rebased onto8cf9be9band re-run there (numbers below are from the rebased branch unless noted).native_sampler_heap_hardware: passed, 69 assertions, about 3.5 s;_warpskips (77, no 32-lane waves)..c67requests (rootRootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED), DescriptorTable(SRV(t0), UAV(u0)), 7 user SGPRs). The test runs them on a 128-entry sampler heap built withdynamic_sampler(), sampling at a coordinate outside [0, 1], and compares every lane with a CPU model.dwordx8load, entries 67 (wrap) and 68 (clamp).image_sample_lwith LOD 1, where MaxLOD decides the mip.prepare_direct_computetwice on one cache: a miss, then a hit, with exactly oneheap_samplerbinding of the expected span in both.bind()without a sampler heap throws..cso:dwordx2,dwordx16, offset 0x438, index 2047, adwordx8load reaching 2047;image_gather4_lz,image_gather4_c_lz),image_sample_c_lz,image_sample_d;compile_dxil --requestspublishes.cs.csoand no.txt. The module's DXIL disassembly showscreateHandleFromHeap(i32 218, i32 67, i1 true, i1 false).36d2cbeb):compile_dxilbuilt at36d2cbebfails at the first compile of SAMPLE ("direct descriptor address outside bound table").off / 32: wrong heap span;0x800: pipeline creation fails;dwordx8read at the first one's offset.0x800plus aSamplerDescriptorHeapshader failsCreateComputePipelineStatewithE_INVALIDARG("root signature is missing the D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED flag");0x800create without a message.native_comparison_pso_warp,native_heap_handle_probe_warp,native_gather_lod_cs_warp,native_global_srv_heap_replay_warp,startup_compute_dispatch_native_warp, and the newnative_sampler_heap_warp). At36d2cbebthe set had 161 tests and 0 failures before the change and 163 / 0 after it.docs_linksandbidi_controlspass.Evidence and follow-up
clang -cc1as -triple amdgcn-amd-amdhsa -target-cpu gfx1013 -show-encoding). Fixtures are source-built.docs/experiments/native-sampler-heap.md):0x800are unchanged.dynamic_sampler()decoding and entry 2047 as the fallback, as the draw path already does for heap-indexed roots.Checklist
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:03:46Z.
LGTM! The fixed-index sampler heap reading is correctly implemented:
Key features:
Implementation notes:
This fixes sampler binding issues that were causing texture sampling problems in games using the native compute path.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T21:30:01Z.
Review: APPROVED
Independently reviewed
3732b33cintegrated overmaincf3df832(tree07a41281). The merge is clean andgit diff --cached --check origin/mainis clean.What I traced.
0xc00/next + 2 == usercondition, the SGPR after the resource heap becomes{table, compute_sampler_heap}.sampler_indexaccepts four literal words (unchanged static path) or four words of one 16-byte heap entry (aligned first offset,offset == first + 4j). Gather, comparison and implicit/gradient forms are refused before a binding is recorded. The HLSL route refuses both the heap SMEM read and a heap sampler.gfx1013_direct_compute.inlrun before the generici.op < 8 && !roottable path. The order is: buffer load, SGPR offset, width, 16-byte alignment, last entry ≤ 2046.createHandleFromHeap(i32 218, i32 <index>, i1 true, i1 false)+annotateHandle {14, 0}. Module flag0x80000000sits next to the existing0x40000000used forResourceDescriptorHeap.create_native_compute_pipelineskips it in the register count and adds root flag0x800.bind()sets both heaps (views first) or the sampler heap alone; the new parameter is last and defaulted, so the four existing test callers are unchanged.heap_sampleronly withroot_parameter == compute_sampler_heap.format_compute_runtime_manifestreturnsnulloptonroot_parameter >= 16(direct_compute_cache.cpp:746).d3d12_compute_dispatch.inl:226) throws for any kind other thanraw_vector_srv/raw_buffer_uav. So, as the description says, nothing reaches a run yet.0xfffff, like the rest of the file. A probe with offset bit 20 set (0xfa100430) is refused earlier ("unsupported scalar memory addressing"), so bit 20 cannot alias a positive entry.What I ran. Full
devandreleasebuilds, then in each preset:native_sampler_heap_hardwarepasses in Debug and Release/O2. SAMPLE, TWO, LOD and MIXED match the CPU model in all 32 lanes, every decoy changes the result, the cache misses then hits with one binding of 1088 / 1104 bytes,bind()without a sampler heap throws, and all 16 refusals and 3 controls match.native_sampler_heap_warpis a capability skip (77).native_cvt_f16_i16_hardware(AttributeError: module 'native_f16_alu_check' has no attribute 'SENTINEL'). It is unrelated to this change and is what #3190 fixes.native_comparison_pso_warp,native_heap_handle_probe_warp,native_gather_lod_cs_warp,native_global_srv_heap_replay_warp,native_sample_ssamp_warp,native_sampler_heap_warp,startup_compute_dispatch_native_warp.compile_dxilbuilt atmaincf3df832fails at the first compile of SAMPLE:native compute +0x20: direct descriptor address outside bound table.Mutants (each applied alone,
compile_dxilandnative_sampler_heaprebuilt indev,native_sampler_heap_hardwarerun, then restored and checked withgit diff --quiet):index + 1(31, 2, 103, 1000), expected(11, 22, 109, 1000)> 2046→> 2047idx2047heap_samplerlike the other kindsheap_sample_c_lzs.offset == first.offset + 4 * jdroppedNon-blocking. The surviving mutant is the check that the four sampler words come from one heap entry. A probe shows the gap:
s_load_dwordx4 s[12:15]at0x430(entry 67).s_load_dwordx4 s[28:31]at0x440(entry 68).s_mov_b32 s14, s30ands_mov_b32 s15, s31.image_sample_lzwiths[12:15].At
3732b33cthis is refused (+0x4c: nonconstant sampler). With the contiguity term dropped, it compiles as entry 67 (sampler_heap span=1088) and would sample with the wrong words 2–3. Adding this shape to the refusal list would pin that check.Verdict: approve on
3732b33c.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 build 26200, MSVC 14.52.37025, Windows SDK 10.0.28000.0 DXC, wave32, debug layer off.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass on3732b33c.This reply was AI-assisted.