shader: check physical descriptor table reads of raw fixed stages at draw time #3823

Manually merged
github merged 4 commits from github-bot/gh-3821 into gh-pr/3821/base 2026-12-02 17:16:34 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-12-02 03:32 UTC · original
Leyukaka:scene-pr-physical → main · +310 −29 · 11 files · 4 commits · merged 2026-12-02 16:45 UTC

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:

  • a fixed-size buffer or texture read from a table slot past the declared ranges of a resource table;
  • a texture read from a slot that the root signature declares as a CBV.

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 #3821 (EXECZ/WQM), because its tests use the root_signature() and TABLE_ROOT helpers added there. Only the last two commits belong to this PR. I will rebase it onto main once 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:

  • the parameter is a resource table, not a sampler table;
  • the slot is past the declared extent, or inside a CBV range;
  • the binding is a single element;
  • it is a buffer read of a fixed size (no dynamic scalar load, at most 16 MiB), or a 1D, 2D, 2D-array or 3D texture (the formatter emits no cube view).

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 one tablecheck <srv index> <required bytes> line per marked binding (0 bytes 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 every tablecheck line is well formed and refers to a table SRV. A pipeline with marked bindings then draws only if:

  • the draw is direct (not indirect), the guest pipeline's own root signature is active, and the parameter is a descriptor table;
  • the heap offset is inside the guest heap;
  • for a buffer read, a known CBV record covers the required span. Exactly that span is copied;
  • for a texture read, a materialized, typed SRV record is present whose view dimension matches the shader. It must be single-sampled, with a format that is not typeless, depth or integer, and it must not alias a target the draw writes.

If a condition fails, the draw is refused and nothing is substituted. The refusal is recorded with a named reason (physical_table_root_refused or physical_table_view_refused, for example missing typed texture SRV record or missing CBV record or insufficient CBV span).

Related open work: #3820 and #3100 also touch d3d12_draw.inl. The ComputeViewBinding cache visitor from #3794 (merged) now also carries dynamic_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. #3774 filters descriptor history for diagnostics and does not overlap in behaviour.

Old cached pairs are not reused: X2W_NATIVE_SHADER_REVISION hashes direct_compute_cache.cpp and gfx1013_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_dxil needs DXC_BIN_DIR. GPU tests were run serially.

cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^(native_direct_container|native_fixed_graphics_psi1|startup_native_slot57_packed_position_(warp|hardware)|startup_address_srv_(warp|hardware)|startup_stream_draw_(warp|hardware))$"

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 with tablecheck 0 32;
  • cbv-range-texture: version 4 with tablecheck 0 0;
  • srv-range-texture and ordinary-table-slot: the ordinary binding, without a tablecheck line;
  • still refused: 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:

  • drawn with the expected pixels: a texture SRV at the physical slot, a CBV at the physical slot, a texture SRV in a slot declared as a CBV;
  • refused, with the target left at its clear value: a heap shorter than the read, the wrong descriptor kind in the slot, a CBV span that is too short, a valid texture record just past the end of the guest heap, a texture SRV where the shader reads a buffer, a CBV where the shader reads a texture.

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_srv and startup_stream_draw are 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 resource no 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

  • One reviewable behaviour, in two commits: reads past the declared ranges, then texture reads in CBV ranges.
  • Negative controls are included for the new fixtures.
  • No guest files, dumps, distribution links or secrets.
**@⁠Leyukaka** on GitHub · 2026-12-02 03:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821) `Leyukaka:scene-pr-physical` → `main` · +310 −29 · 11 files · 4 commits · merged 2026-12-02 16:45 UTC ## 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`: - a fixed-size buffer or texture read from a table slot past the declared ranges of a resource table; - a texture read from a slot that the root signature declares as a CBV. 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 #3821 (EXECZ/WQM), because its tests use the `root_signature()` and `TABLE_ROOT` helpers added there. Only the last two commits belong to this PR. I will rebase it onto `main` once 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: - the parameter is a resource table, not a sampler table; - the slot is past the declared extent, or inside a CBV range; - the binding is a single element; - it is a buffer read of a fixed size (no dynamic scalar load, at most 16 MiB), or a 1D, 2D, 2D-array or 3D texture (the formatter emits no cube view). 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 one `tablecheck <srv index> <required bytes>` line per marked binding (`0` bytes 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 every `tablecheck` line is well formed and refers to a table SRV. A pipeline with marked bindings then draws only if: - the draw is direct (not indirect), the guest pipeline's own root signature is active, and the parameter is a descriptor table; - the heap offset is inside the guest heap; - for a buffer read, a known CBV record covers the required span. Exactly that span is copied; - for a texture read, a materialized, typed SRV record is present whose view dimension matches the shader. It must be single-sampled, with a format that is not typeless, depth or integer, and it must not alias a target the draw writes. If a condition fails, the draw is refused and nothing is substituted. The refusal is recorded with a named reason (`physical_table_root_refused` or `physical_table_view_refused`, for example `missing typed texture SRV record` or `missing CBV record or insufficient CBV span`). Related open work: #3820 and #3100 also touch `d3d12_draw.inl`. The `ComputeViewBinding` cache visitor from #3794 (merged) now also carries `dynamic_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. #3774 filters descriptor history for diagnostics and does not overlap in behaviour. Old cached pairs are not reused: `X2W_NATIVE_SHADER_REVISION` hashes `direct_compute_cache.cpp` and `gfx1013_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_dxil` needs `DXC_BIN_DIR`. GPU tests were run serially. ``` cmake --build --preset dev ctest --preset dev --no-tests=error -R "^(native_direct_container|native_fixed_graphics_psi1|startup_native_slot57_packed_position_(warp|hardware)|startup_address_srv_(warp|hardware)|startup_stream_draw_(warp|hardware))$" ``` 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 with `tablecheck 0 32`; - `cbv-range-texture`: version 4 with `tablecheck 0 0`; - `srv-range-texture` and `ordinary-table-slot`: the ordinary binding, without a `tablecheck` line; - still refused: `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: - drawn with the expected pixels: a texture SRV at the physical slot, a CBV at the physical slot, a texture SRV in a slot declared as a CBV; - refused, with the target left at its clear value: a heap shorter than the read, the wrong descriptor kind in the slot, a CBV span that is too short, a valid texture record just past the end of the guest heap, a texture SRV where the shader reads a buffer, a CBV where the shader reads a texture. 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_srv` and `startup_stream_draw` are 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 resource` no 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 - [x] One reviewable behaviour, in two commits: reads past the declared ranges, then texture reads in CBV ranges. - [x] Negative controls are included for the new fixtures. - [x] No guest files, dumps, distribution links or secrets.
Flatten a CMPX/EXECZ split inside whole-quad mode whose two arms partition the WQM mask and rejoin at entry coverage, so implicit samples still see all four quad coordinates. Lanes outside each arm keep their previous VGPR values. Speculative reads in the arms are limited to fixed-offset table and buffer loads and to samples with a fixed descriptor and constant sampler.
A raw fixed stage reads its descriptor table at physical byte offsets. A
fixed-size buffer or texture read past the declared ranges of a resource table
is no longer refused at translation: the manifest (version 4) marks it with a
`tablecheck` line. At draw time the runtime requires a direct draw with the
guest pipeline's root signature, a descriptor table parameter, and, at that
heap offset, either a CBV record covering the required span or a typed texture
SRV of the shader's dimension that does not alias a written target. Otherwise
the draw is refused with a named reason.

The slot 57 fixture can now bind the stream root signature and a position
texture (X2W_TEST_SLOT57_POSITION_TEXTURE) to exercise the accepted and
refused cases, including a span past the heap end and a texture in a buffer
slot.
The declared range type does not reach a raw fixed stage. A texture read from
a slot that the root signature declares as a CBV now takes the same physical
table check: the draw requires a typed texture SRV record of the shader's
dimension at that heap offset. Textures in UAV ranges and buffers outside CBV
and SRV ranges stay refused.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 03:35:21 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 05:16 UTC · original · reviewed

Thanks for documenting the stack. #3821 has now landed by squash. Please rebase #3823 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.

**@⁠R0Y00** on GitHub · 2026-12-02 05:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6145157111) · **reviewed** Thanks for documenting the stack. #3821 has now landed by squash. Please rebase #3823 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.
github-bot force-pushed github-bot/gh-3821 from 959b6ffa98 to c72d70f17e 2026-12-02 06:53:53 +00:00 Compare
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-02 06:53 UTC · original

Rebased onto main (f365f125b) now that #3821 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 #3794: this PR adds ComputeViewBinding::dynamic_scalar_load, and #3794'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.

**@⁠Leyukaka** on GitHub · 2026-12-02 06:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#issuecomment-7337527345) Rebased onto `main` (f365f125b) now that #3821 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 #3794: this PR adds `ComputeViewBinding::dynamic_scalar_load`, and #3794'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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 09:02 UTC · original · requested changes

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 e3876780 the trial merge is textually clean, but cmake --build --preset dev --target compile_dxil fails with MSVC C3448 at src/direct_compute_cache.cpp:108. The #3794 ComputeViewBinding cache visitor binds ten fields; this PR adds dynamic_scalar_load as an eleventh. Please rebase, include that bool in both the structured binding and tuple, and set it to true in 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.

**@⁠R0Y00** on GitHub · 2026-12-02 09:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6147605280) · **requested changes** 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 `e3876780` the trial merge is textually clean, but `cmake --build --preset dev --target compile_dxil` fails with MSVC C3448 at `src/direct_compute_cache.cpp:108`. The #3794 `ComputeViewBinding` cache visitor binds ten fields; this PR adds `dynamic_scalar_load` as an eleventh. Please rebase, include that bool in both the structured binding and tuple, and set it to `true` in 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.
github-bot force-pushed github-bot/gh-3821 from c72d70f17e to d68e7f3a07 2026-12-02 09:58:02 +00:00 Compare
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-02 09:53 UTC · original

Thanks. Rebased onto main and fixed in d68e7f3a0: dynamic_scalar_load is now in both the structured binding and the tuple of the ComputeViewBinding cache visitor, and the cache round-trip control sets it to true (it also checks that the comparison sees the flag). A new physical-cbv-dynamic-offset case 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, plus native_direct_cache_controls, passes on the new head with WARP and hardware.

**@⁠Leyukaka** on GitHub · 2026-12-02 09:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#issuecomment-7341644707) Thanks. Rebased onto `main` and fixed in `d68e7f3a0`: `dynamic_scalar_load` is now in both the structured binding and the tuple of the `ComputeViewBinding` cache visitor, and the cache round-trip control sets it to `true` (it also checks that the comparison sees the flag). A new `physical-cbv-dynamic-offset` case 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, plus `native_direct_cache_controls`, passes on the new head with WARP and hardware.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 10:10 UTC · original · reviewed

d68e7f3a builds and passes native_direct_cache_controls and native_fixed_graphics_psi1. The new cache visitor and equality/round-trip controls cover dynamic_scalar_load. I reproduced the remaining native_direct_mesh failure on plain main. Applying only the fixture change from #3853 locally made native_direct_mesh pass on this exact head. Once #3853 lands, please sync main so the required Windows check runs on that combination.

**@⁠R0Y00** on GitHub · 2026-12-02 10:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6148749670) · **reviewed** `d68e7f3a` builds and passes `native_direct_cache_controls` and `native_fixed_graphics_psi1`. The new cache visitor and equality/round-trip controls cover `dynamic_scalar_load`. I reproduced the remaining `native_direct_mesh` failure on plain main. Applying only the fixture change from #3853 locally made `native_direct_mesh` pass on this exact head. Once #3853 lands, please sync main so the required Windows check runs on that combination.
github-bot changed target branch from main to gh-pr/3821/base 2026-12-02 17:16:32 +00:00
github manually merged commit 15a5299006 into gh-pr/3821/base 2026-12-02 17:16:34 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 16:44 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-12-02 16:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6155138916) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.