shader: check physical descriptor table reads of raw fixed stages at draw time #3821
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3821"
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 Leyukaka on 2026-12-02T03:32:20Z.
Problem
A raw fixed graphics stage (a PSI1 pair without reflection) reads its descriptor table at the byte offsets compiled into the shader. The declared ranges of the root signature do not reach such a stage, so two reads that the shader really performs are refused at translation with
graphics descriptor range does not cover resource:Translation cannot decide whether such a read is valid. That depends on what the guest has written at that heap offset when the draw is issued.
Change
This PR is stacked on #3819 (EXECZ/WQM), because its tests use the
root_signature()andTABLE_ROOThelpers added there. Only the last two commits belong to this PR. I will rebase it ontomainonce that one lands.Translation (
src/direct_compute_cache.cpp,src/gfx1013_compute_native.h). For a raw fixed stage only, a binding that the declared ranges do not cover keeps the shader's own byte offset and is marked for a draw-time check when all of these hold:Everything else keeps the refusal: non-fixed entries, sampler tables, textures in UAV ranges, and buffers in UAV ranges.
Shared interface: the graphics manifest. A pair with at least one marked binding is written as
x2w-manifest 4, with onetablecheck <srv index> <required bytes>line per marked binding (0bytes for a texture). Pairs without marked bindings keep their current manifest version and content. The cached pair payload gains one leading word for the mark set.Draw time (
src/startup_stubs/d3d12_draw.inl). The runtime accepts version 4 only if everytablecheckline is well formed and refers to a table SRV. A pipeline with marked bindings then draws only if:If a condition fails, the draw is refused and nothing is substituted. The refusal is recorded with a named reason (
physical_table_root_refusedorphysical_table_view_refused, for examplemissing typed texture SRV recordormissing CBV record or insufficient CBV span).Related open work: #3818 and #3100 also touch
d3d12_draw.inl. TheComputeViewBindingcache visitor from #3792 (merged) now also carriesdynamic_scalar_load. As far as I can see none of them changes the table range check or the manifest version, so I expect textual rebases only. #3772 filters descriptor history for diagnostics and does not overlap in behaviour.Old cached pairs are not reused:
X2W_NATIVE_SHADER_REVISIONhashesdirect_compute_cache.cppandgfx1013_compute_native.h, so the pair cache keys change with this patch.A scalar buffer load whose SOFFSET is an SGPR has no fixed bound, so such a binding stays refused when it lies outside the declared ranges.
Validation
Windows, MSVC.
compile_dxilneedsDXC_BIN_DIR. GPU tests were run serially.These tests pass on WARP and on a hardware adapter on the exact head of this PR, and a 300 s run of a guest application on it showed no device loss.
Translation cases in
tests/native_fixed_graphics_psi1_check.py:physical-cbv, cold and cached: manifest version 4 withtablecheck 0 32;cbv-range-texture: version 4 withtablecheck 0 0;srv-range-textureandordinary-table-slot: the ordinary binding, without atablecheckline;physical-cbv-no-fixed-entry,physical-cbv-sampler-table,uav-range-texture,uav-range-buffer.Draw cases in
tests/startup_native_slot57_packed_position_check.py. Each one compares the rendered pixels and requires that the debug layer reports no error or corruption:To drive these cases, the slot 57 fixture can now bind the stream root signature and a position texture (
X2W_TEST_SLOT57_POSITION_TEXTURE).startup_address_srvandstartup_stream_draware in the filter because they share that harness. The fixtures are hand-assembled instruction words and generated root signatures written for these tests.Beyond the fixtures: in a run of a guest application,
graphics descriptor range does not cover resourceno longer appeared for the pipelines that had it. That is a local observation. The public fixtures verify the manifest contract and the accept and refuse decisions listed above, not that run.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:16:15Z.
Review: COMMENTED
Thanks for documenting the stack. #3819 has now landed by squash. Please rebase #3821 onto current main so the review diff contains only the physical-table changes, then rerun the listed manifest, WARP and hardware controls on the rebased head. The v4 manifest links compiler output to the draw path, so the next review will check both sides of that contract.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T06:53:34Z.
Rebased onto
main(f365f125b) now that #3819 has merged; only the two commits of this PR remain. The CTest selection from the description passes again on WARP and on hardware on the new head.Heads-up on an interaction with #3792: this PR adds
ComputeViewBinding::dynamic_scalar_load, and #3792's cache visitor names every field of that struct in a structured binding. The two merge cleanly as text, but the second one to merge will not compile until the field is added to that visitor and its fixture; I will push the follow-up as soon as the first one lands.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T09:02:17Z.
Review: CHANGES_REQUESTED
On the standalone head, the seven manifest and runtime checks passed in Windows Debug, including WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) on Windows 11 26300.9974 with the debug layer enabled for the physical table readbacks. On current main
e3876780the trial merge is textually clean, butcmake --build --preset dev --target compile_dxilfails with MSVC C3448 atsrc/direct_compute_cache.cpp:108. The #3792ComputeViewBindingcache visitor binds ten fields; this PR addsdynamic_scalar_loadas an eleventh. Please rebase, include that bool in both the structured binding and tuple, and set it totruein a cache round-trip control. A cold/warm refusal for a dynamic scalar offset would protect the new restriction. Also align the description's supported dimension list with the formatter, which currently emits 1D, 2D, 2D-array and 3D.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T09:53:34Z.
Thanks. Rebased onto
mainand fixed ind68e7f3a0:dynamic_scalar_loadis now in both the structured binding and the tuple of theComputeViewBindingcache visitor, and the cache round-trip control sets it totrue(it also checks that the comparison sees the flag). A newphysical-cbv-dynamic-offsetcase reads a slot past the declared ranges with an SGPR SOFFSET and is refused with the same reason on two consecutive compiles against the same cache directory. One caveat: a refused pair is never published to the pair cache, so the second compile repeats the translation and does not read a cached entry. The description now lists 1D, 2D, 2D-array and 3D. The selection from the description, plusnative_direct_cache_controls, passes on the new head with WARP and hardware.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T10:10:29Z.
Review: COMMENTED
d68e7f3abuilds and passesnative_direct_cache_controlsandnative_fixed_graphics_psi1. The new cache visitor and equality/round-trip controls coverdynamic_scalar_load. I reproduced the remainingnative_direct_meshfailure on plain main. Applying only the fixture change from #3851 locally madenative_direct_meshpass on this exact head. Once #3851 lands, please sync main so the required Windows check runs on that combination.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T16:44:09Z.
Review: APPROVED
Re-reviewed
15a52990. The earlier constexpr/MSVC failure is gone and the cache read visitor, equality and round-trip tests exercise the dynamic scalar load. Independent Windows 11 build 26300, MSVC Debug:ctest --preset dev --no-tests=error -j 1 -V -R '^(native_direct_cache_(controls|key_controls)|native_fixed_graphics_psi1|startup_address_srv_(warp|hardware)|startup_native_slot57_packed_position_(warp|hardware))$'passed 7/7. The packed-position readback and physical-table/bounds refusals passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with the debug layer enabled.