Skip to content

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

Open
Leyukaka wants to merge 2 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-physical
Open

Leyukaka wants to merge 2 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-physical

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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, 3D or cube texture.

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, and #3792 touches direct_compute_cache.cpp. 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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.
@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (f365f12) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants