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

Merged
Leyukaka merged 4 commits from upstream-pr/3821 into main 2026-12-02 16:45:01 +00:00
Leyukaka commented 2026-12-02 03:32:20 +00:00 (Migrated from github.com)

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:

  • 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 #3819 (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: #3818 and #3100 also touch d3d12_draw.inl. The ComputeViewBinding cache visitor from #3792 (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. #3772 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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5599278794 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821). Originally posted by [Leyukaka](https://github.com/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`: - 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 #3819 (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: #3818 and #3100 also touch `d3d12_draw.inl`. The `ComputeViewBinding` cache visitor from #3792 (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. #3772 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.
R0Y00 commented 2026-12-02 05:16:15 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145157111 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6145157111). Originally posted by [R0Y00](https://github.com/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.
Leyukaka commented 2026-12-02 06:53:34 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7337527345 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#issuecomment-7337527345). Originally posted by [Leyukaka](https://github.com/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.
R0Y00 commented 2026-12-02 09:02:17 +00:00 (Migrated from github.com)

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 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 #3792 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6147605280 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6147605280). Originally posted by [R0Y00](https://github.com/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 `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 #3792 `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.
Leyukaka commented 2026-12-02 09:53:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T09:53:34Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7341644707 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#issuecomment-7341644707). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T09:53:34Z. --- 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.
R0Y00 commented 2026-12-02 10:10:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T10:10:29Z.

Review: COMMENTED


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 #3851 locally made native_direct_mesh pass on this exact head. Once #3851 lands, please sync main so the required Windows check runs on that combination.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148749670 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6148749670). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T10:10:29Z. **Review:** COMMENTED --- `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 #3851 locally made `native_direct_mesh` pass on this exact head. Once #3851 lands, please sync main so the required Windows check runs on that combination.
R0Y00 commented 2026-12-02 16:44:09 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6155138916 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3821#pullrequestreview-6155138916). Originally posted by [R0Y00](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3821
No description provided.