startup: apply sampler heap entries' MIN_LOD and MAX_LOD #2279
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2287"
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 roansystemlabs on 2026-11-25T10:09:25Z.
Fixes #2221.
Change
Item 1 of #2221, the runtime decoder side.
dynamic_sampler()insrc/startup_stubs/translated_sampler_bindings.hbuilds the stand-in's sampler table from the title's own heap words. Until now it setMinLOD = 0and an unboundedMaxLOD, so a heap entry's LOD clamp was dropped. It now passeslod_limits = truetodecode_sampler(), reusing the LOD lines that #2051 added forsmplmanifest lines. No new decoding is introduced.MIN_LODis sampler word 1 bits 11:0 andMAX_LODis bits 23:12. Both are unsigned 4.8, so each field is divided by 256.min lodat descriptor bits 43:32, described as u4.8 in resource view space, andmax lodat 55:44.src/amd/registers/gfx10-rsrc.json(SQ_IMG_SAMP_WORD1:MIN_LOD[0, 11],MAX_LOD[12, 23],PERF_MIP[24, 27],PERF_Z[28, 31]).radv_sampler.cencodes both fields withradv_float_to_ufixed(x, 8).smpline (MinLOD = 0, unboundedMaxLOD) and ansmplline (limits carried): #2051 forimage_sample_b, #2265 for constant samplers ofimage_sample,_land_lz.smpsampler, as before. It has no title words to decode.border_sampler()also goes throughdynamic_sampler(), but it is not a title descriptor: its word 1 is 0 by construction, not a clamp. It therefore keeps the full mip range, as onmain. It is used for missing, out-of-range, unreadable or invalid entries and for the reserved entry 2047.decode_sampler()now says thatdynamic_sampler()always sets the flag. The comment intests/mesh_heap_sampler_draw.cpp(#2220) no longer says that the decoder ignores the fields; its local decode is kept.#2221 is closed by three changes:
ComparisonFunc, warning 1361) landed in #2228;Since #2265, the translator logs once per module that a heap sampler's
MIN_LOD,MAX_LODand LOD bias are not validated (#2221). That line stays accurate after this change, which is why it is untouched here:MipLODBiasstays 0).If you prefer the line to point elsewhere once #2221 is closed, that is a one-line translator follow-up.
Verification
Commit
db3c8255, on77a204d6. Windows 11 build 26200, MSVC 14.44,devpreset (Debug), D3D12 debug layer enabled. Adapters: NVIDIA GeForce RTX 3070 (10de:2484, driver 32.0.16.2101) and WARP 10.0.26100.9818.New
startup_sampler_lod_{warp,hardware}(offscreen_check <adapter> --startup-sampler-lod). The test uses the production code path end to end:smpheap 2048 1 fallback 2047andsmpc 0 0x1012 0x100000 0x0 0x0go throughTranslatedSamplers::read_manifest_line();create_translated_root()builds the root signature;snapshot_samplers(),create_sampler_snapshot_heap()anddynamic_sampler().The two heap entries differ only in word 1:
MIN_LOD2 (0x00fff200);MAX_LOD1 (0x00100000).Words 0, 2 and 3 are the same: clamp-to-last-texel in X and Y, point filters. A source-built pixel shader (
tests/startup_sampler_lod.hlsl, compiled with DXCvs_6_0/ps_6_0at build time) reads an 8×8R32_FLOATtexture with four mips, where every texel of mip m holds0.125 + 0.25·m. Each draw writes one pixel, usingSampleLevelat an explicit LOD:_dropped_controlMIN_LOD2)MAX_LOD1)smpc(LESS)smpc(LESS)startup_sampler_lod_dropped_{warp,hardware}decode the same words, then resetMinLOD/MaxLODto 0 andD3D12_FLOAT32_MAX, the values heap entries had before this change. The control must then read mip 0 for probe 0 and mip 3 for probe 2. It passes only on the exact linewrong_mip=2 unexpected=0, and it passed on both adapters.smpcsampler keepsComparisonFunc = LESS(Filter = 0x80). This is checked on the CPU, and on the GPU by probes 4 and 5:ALWAYSwould read 1 for both andNEVERwould read 0 for both.3089406b, with the new tests andmain's header:startup_sampler_lod_{warp,hardware}failed withmismatches=2(probe 0 read mip 0, probe 2 read mip 3);startup_translated_sampler_bindingsfailed on every table-entry LOD range;f277710e, before #2228, everystartup_sampler_lod_*run reporteddebug_warnings=1024, all of them 1361 (1024 is where the debug layer's stored-message count stops), with and without this change.mainafter #2228 the count isdebug_errors=0 debug_warnings=0, with and without this change.startup_translated_sampler_bindingsnow expects the decoded range for table entries and for thesmplpath, an unbounded range forsmpstatics, and an unbounded range for the border fallback. The new cases are:MIN_LODaboveMAX_LODthrough);PERF_MIP/PERF_Zset, which is ignored.Not run:
MIN_LODaboveMAX_LODon a device (it is passed through as decoded and checked only without a device);releasepreset;R32_FLOATcapability skip path, which never triggers here because both adapters report the capabilities.The test does not depend on the debug layer: it reports warnings but does not require any.
Evidence and follow-up
The test generates its own fixture: the sampler words and texel values are written in
tests/startup_sampler_lod.cpp, and the shader is intests/startup_sampler_lod.hlsl. Both are under the repository license. The draw uses whole-level LODs, so it does not depend on how point mip filtering rounds a fractional LOD; the device-free check covers the fractional values.tests/mesh_heap_sampler_draw.cpp(#2220) still appliesMinLOD/MaxLODitself afterdynamic_sampler(). It now sets the same values, so that local decode could be dropped in a follow-up if wanted.Checklist
docs/startup-runtime.md).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:11:02Z.
Review: COMMENTED
Review of head
db3c825565b4b27abd7cd3301d92ce1a92e3cad1(comment only).Scope / overlap. #2265 (static sampler
lod_limitsforsmpl,image_sample_b, constant-samplerimage_sample/_l/_lz) is already inorigin/main. This PR does not redo it. It reuses thedecode_sampler(..., lod_limits=true)path from #2265 and turns it on for sampler-heap entries (dynamic_sampler,src/startup_stubs/translated_sampler_bindings.h:185-190). No overlap in files or logic beyond that shared call. Titles and bodies are neutral and clean-room (the Mesa gfx10 register layout is cited in the existing comment).Logic.
MIN_LOD= word1[11:0],MAX_LOD= word1[23:12], unsigned 4.8 fixed point, so/256. Matches the decoder from #2265.border_sampler()resetsMaxLODtoD3D12_FLOAT32_MAX(translated_sampler_bindings.h:193-199). This is needed because the synthetic fallback has word1 = 0, which would otherwise clamp it to mip 0. The reserved fallback intests/startup_sampler_heap.cpp:74copiesborder_sampler(), so it keeps the full range. Good.docs/startup-runtime.md, but it will change any title that leaves word1 at 0 on a mipped texture.Findings.
CMakeLists.txt/tests/startup_sampler_lod.cpp: the fixture uses entries withMIN_LOD2 andMAX_LOD1 (MinLOD > MaxLOD). D3D12 documentsMinLOD <= MaxLODforD3D12_SAMPLER_DESC, and the debug layer reports a violation. WARP accepts it, but a hardware adapter may not behave the same. The_hardwarevariant of the test therefore does not prove the same thing as_warp. Consider clampingMinLOD = min(MinLOD, MaxLOD)in the decoder (and testing it), or use a valid pair for the hardware-run assertions. If the inverted pair is a deliberate hardware-semantics probe, say so in the doc line.docs/startup-runtime.mdline wraps oddly ("...at explicit LODs; a / staticsmpcsampler..."). Cosmetic.Checks run locally (Linux).
git diff --stat origin/main...HEAD: 9 files, +340/-9.python3 tests/docs_links_check.py-> pass (18 files, 435 links).python3 tests/bidi_controls_check.py-> pass (1568 files).git diff --check origin/main...HEAD-> clean.decode_sampler(words, 0, false, true)tofalseindynamic_sampler. No Linux check fails, because all touched tests (startup_sampler_lod_*,startup_translated_sampler_bindings_check,mesh_heap_sampler_draw) are D3D12/Windows only. So the kill of this mutation depends on the Windows jobs (the_dropped_control and the WARP readback). Reverted withgit checkout -- ..startup_sampler_lod_{warp,hardware}andstartup_translated_sampler_bindings*are green there before Ready.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T10:45:05Z.
Thanks for the careful review, @tedin7. The doc line was ambiguous, and that is on us: "(
MIN_LOD2,MAX_LOD1)" named one field from each of two entries. The draw usesMIN_LOD2 withMAX_LOD4095/256, andMIN_LOD0 withMAX_LOD1. So noMinLOD > MaxLODsampler reached D3D12 in_warpor_hardware. The only inverted pair (1.75/1.25) was a device-free decode case.Agreed that D3D12 requires
MinLOD <= MaxLOD. For the record, I wrote a standalone probe on WARP and an RTX 3070. Creating a heap sampler and a static sampler with (1.75, 1.25) logged no debug-layer message, whileMaxAnisotropy17 in the same probe was reported. That covers creation only, not a draw. I did not add a clamp in the decoder: the RDNA 2 ISA (§8.2.7, table 46) defines the fields but not what the sampler does with min > max, so a clamp would pick a behaviour we have no source for.Since #2287 was already merged, the changes are in #2298:
MinLODis aboveMaxLOD;On that head, the sampler LOD tests pass on WARP and the RTX 3070 with
debug_errors=0 debug_warnings=0in every draw. The full commands are in #2298.AI-assisted.