Skip to content

startup: bind pixel-stage UAVs from the title's descriptor table - #2448

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
roansystemlabs:startup/1996-pixel-uav
Nov 26, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
roansystemlabs:startup/1996-pixel-uav

Conversation

@roansystemlabs

@roansystemlabs roansystemlabs commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1996 (item F). Follow-up of #2155; also the "Pixel-stage UAV binding" line of #2274.

Change

The runtime now binds the image a translated pixel program stores to. Before this, load_translation dropped every translation with a uav line: first with "pixel-stage UAVs are not bound yet", and since #2059 by refusing every x2w-manifest 2 manifest and every uav line.

  • load_translation reads uav N tex2d table P O, the line tools/startup/gfx2hlsl.py writes for a pixel-stage image_store. Only that form is read: a view qualifier (float, uint, sint) or a channels field, as in the compute line on main (uav N tex2d float table P O channels 4), is refused.
  • Version 2 manifests (the ones gfx2hlsl writes when a program stores) are read again. shader: lower buffer_store_dwordx3 in gfx2hlsl (Part of #1723) #2059's guard is kept in another form: every uav line is either bound or refused by name, so the vertex-stage buffer line (uav N raw table P O) still keeps its translation from being used and no store is skipped silently. Other manifest versions stay refused. The offline vertex-store note in docs/experiments.md now says this instead of "refuses version 2 manifests".
  • The translated root signature gets a UAV range u0.. after the SRVs in its view table (create_translated_root and sampler_root_parameter in translated_sampler_bindings.h, both already on main, take the view count).
  • At draw time the view is made from the unordered-access view the title created at that table entry (view token, slot 19 record), on mip 0 of a 2D texture, and the texture is moved to UNORDERED_ACCESS for the draw.
  • As asked on help wanted: GPU translation, part 1 (pixel shaders) #1996, the binding is self-contained in d3d12_draw.inl (read_pixel_uav_line, pixel_uav_view, resolve_pixel_uavs); no new shared header. Pass keeps the last accepted render and depth targets (bound_targets, bound_depth) so the draw can compare them; the existing trace_targets are filled only while the red-producer diagnostic is on.

Refused by name, with nothing bound in place of the view:

  • when the manifest is loaded (the translation is not used): another image kind, a buffer line (uav N raw table P O, the vertex-stage store of shader: lower buffer_store_dwordx3 in gfx2hlsl (Part of #1723) #2059, or the older uav N table P O), a view qualifier, another source, an extra field such as channels, a view index out of order, more than eight views;
  • at draw time (the draw is not translated): no table at the parameter, an entry outside the bound table, an entry without a view, an entry that is not an unordered-access view, a resource without ALLOW_UNORDERED_ACCESS, an array, 3D, 1D or multisampled resource, a view of another dimension, mip or plane, an integer, sRGB or non-colour format, a format without typed UAV store on the device, and a texture that is also an SRV, a render target or the depth texture of the same draw. These checks run before any view of the draw is written or any texture changes state.
  • Indirect draws (slot 61) refuse a translation with a uav line, counted in the startup: wire per-reason refusal census into translated indirect draws #2333 census as unsupported_resource_or_entry.

Out of scope: compute UAVs (#2274 B) and barriers between draws that write and read the same texture.

Verification

Commit 1247a2895 on fbe249f68 (rebased; the previous head was e1d5a997b on b442b57fb). git merge-tree with today's main (f02ebd669) is clean. Windows 11 (10.0.26200), MSVC 14.44, NVIDIA GeForce RTX 3070 driver 32.0.16.2101, and WARP 10.0.26100.9818, debug layer on.

cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_pixel_uav_' -V
ctest --preset dev --no-tests=error -R '^startup_'

What the 21 cases check (tests/startup_pixel_uav_check.py, each case its own process):

  • Drawn: the table names texture A (an explicit 2D view) or texture B (a view created without a description). Texel (1, 2) of mip 0 of that texture holds 1.0, 2.0, 3.0, 4.0. Every other word of the four textures, both mips (320 words), keeps its sentinel.
  • Refused, each with its logged reason and every word unchanged: table entry without a view, an SRV entry, a texture without ALLOW_UNORDERED_ACCESS, a R32G32B32A32_UINT view, a view of mip 1, a one-slice 2D-array view, an entry outside the bound table, no table, the texture also bound as an SRV, the texture also bound as the draw's render target (a fifth texture with both flags, bound through list slot 50), and seven other manifest lines (including the compute form with float and channels 4).
  • Exec: the two v_cmpx variants from startup: lower pixel-stage image_store to a typed UAV store #2155 through the runtime. Exec on writes the texel; exec off leaves it.

Negative controls:

  • Exec guard (in the test): the exec-off shader recompiled with the guard removed from the store must write the texel, and the check reports texel_mismatch texture A mip 0 texel (1, 2) word 0: got 3f800000, expected c0000024 on both adapters.
  • Mutants of the runtime, rebuilt and run locally on both adapters, not part of the PR:
    • swapped table entry (the view read 32 bytes further on): cases a and b fail with the texel still at its sentinel;
    • ALLOW_UNORDERED_ACCESS check removed: no-ua fails, the debug layer reports IDs 340 and 524 and the device is removed (0x887a0001);
    • mip 1 bound instead of mip 0: cases a and b fail (the store at (1, 2) falls outside the 2x2 mip and mip 0 keeps its sentinel);
    • render/depth target check removed: target fails, the debug layer reports ID 538 (the render target is in UNORDERED_ACCESS at the draw).
    • The four mutants and the fail-first run were made on an earlier base. Since then the change differs only in the indirect refusal line (the startup: wire per-reason refusal census into translated indirect draws #2333 census code); the rebase onto b442b57fb added the manifest-version and raw line handling described above (covered by the a.buffer-line case), and the rebase onto fbe249f68 changed only conflict context (docs wording from the compute image store, and the environment-variable list in startup_stream_consumer.cpp).
  • Fail-first on main: the same test fails on every case (including target), and the log shows stores to an image (uav 0 tex2d table 0 0); pixel-stage UAVs are not bound yet, translation not used.
  • Without the debug layer (X2W_PIXEL_UAV_NO_DEBUG=1, as on a machine without it) the cases still run and report debug layer: absent; the zero-error requirement applies only when the layer is on.

Evidence and follow-up

  • The pixel program is the hand-assembled one from startup: lower pixel-stage image_store to a typed UAV store #2155 (tests/startup_pixel_image_store_check.py, no bytes from any retail software). I assembled its source and the two v_cmpx variants with clang 15.0.7 (--target=amdgcn-amd-amdhsa -mcpu=gfx1013) and extracted .text with llvm-objcopy 15: all three match the recorded words (64, 68 and 68 bytes). That is the reassembly startup: lower pixel-stage image_store to a typed UAV store #2155 could not run; it is not part of the CI test.
  • tests/startup_pixel_uav.cpp (a startup_stream_consumer mode) creates the textures through device slot 127, the views through slots 18, 19 and 20 and the table through list slot 36, so the draw goes through the same path as a title.
  • The title's descriptor stride differs by adapter (64 bytes on WARP, 32 on the RTX 3070); the test does not depend on it.
  • Stage of the store: the graphics manifest does not name the stage of a uav line. On main op_image_store accepts only pixel and compute stages, and compute writes its own manifest (stage cs, uav N tex2d float … channels 4, not read by load_translation), so in a graphics manifest only the pixel stage writes a tex2d line; a vertex-stage store is always a raw line (op_buffer_store_vs), which is refused here. The view table is visible to all stages, so the binding does not depend on the stage either. If a later change lets another graphics stage store to an image, the manifest should carry the stage.
  • Retired textures (startup: release retired slot-133 title-memory textures and track slot-18 SRV reuse (slice 2) #2468): the bound texture is not retire_hold-ed like a sampled one, because retire_classify already keeps every resource with ALLOW_UNORDERED_ACCESS (which this binding requires) out of the retire class.
  • Overlap: shader: lower buffer_store_dwordx3 in gfx2hlsl (Part of #1723) #2059 (merged) refused every version 2 manifest so that its offline vertex buffer stores never run. This change reads version 2 for the pixel tex2d line and refuses its uav N raw table P O line by name, so those stores still never run; the a.buffer-line case checks that refusal on both adapters. The draft Integrate mesh translation, D3D12 rendering and memory handling #2603 binds the same pixel uav line in d3d12_draw.inl in another layout; the overlap is described in a comment on this PR.
  • Not tested: AMD and Intel GPUs, console hardware, a title's own resources (whether they carry ALLOW_UNORDERED_ACCESS decides how often this binds), indirect draws with a uav line (refused, no fixture), resources the runtime creates by title address (refused by name, no fixture), and a UAV of the bound depth texture (refused by name with the render-target check, no fixture).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of head e1d5a99 (Linux-side read, no Windows run by me).

What I checked

  • Manifest: x2w-manifest 2 is accepted and every uav line is either bound (uav N tex2d table P O) or refused by name at load time. Raw/buffer views, qualifiers, extra fields, out-of-order index and more than 8 views all keep the old "translation not used" behavior.
  • Binding (resolve_pixel_uavs): all refusals happen before any view or state change is recorded. Slot 19 (UAV) is required, mip/plane/array/MSAA/format/typed-store support are checked, and a texture that is also a render target, depth target or SRV of the same draw is refused. Indirect draws with UAVs are refused.
  • Root signature: the SRV range and the UAV range share one table, with the UAV range offset by the SRV count. sampler_root_parameter(views) and the draw-time descriptor math use srvs + uavs consistently. Existing callers of create_translated_root keep the default uavs = 0, so their layout is unchanged.
  • bound_targets / bound_depth are copied from the same local array the existing trace code copies (8 entries), so no new out-of-range read.
  • Test: tests/startup_pixel_uav_check.py + tests/startup_pixel_uav.cpp draw through the real runtime on D3D12 and read back every word of four textures (both mips), so it guards the stored texel, the untouched words, each named refusal, and the exec on/off cases with a control. It is wired into CTest per backend and added to the existing startup_stream_consumer binary rather than a new one.
  • Overlap: #2155 (merged) added the lowering; this is the runtime half of the same item. No open PR touches the same code (#2399 is compute-only).
  • Scope: runtime + docs + tests, no .github/launcher/hooks.

Commands run (Linux, in a review worktree at the head SHA)

  • git diff --check origin/main...HEAD : clean
  • python3 tests/docs_links_check.py : passed (19 files, 465 links)
  • python3 tests/bidi_controls_check.py : passed (1727 files)

Not verified by me

  • The new test needs Windows/WARP, so I could not run it or mutate the runtime code here. The PR's CI shows "Build and test on Windows" SUCCESS on this head; the author posted no separate Win2025 results comment, and the /O2 job was skipped.
  • The branch is 24 commits behind main; I did not update it (that would change the head SHA).

No blocking findings.

AI-assisted; commands listed were executed locally.

@Makto94

Makto94 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Hardware run and Windows 11 MSVC build at head e1d5a997.

Environment: Windows 11 Pro build 26300.9974, Debug (dev preset), MSVC toolset 14.44.35207 (cl 19.44.35230.0), driver 32.0.16.2101. The hardware test prints adapter=NVIDIA GeForce RTX 3070 Ti driver=32.0.16.2101 with debug layer: on, errors: 0 in every case. The runs were serial (-j1). The PR body reports an RTX 3070 run on the same driver version; this run used an RTX 3070 Ti.

Build: cmake --build --preset dev exited 0 (this PR changes C++ in src/startup_stubs/ and tests/, so the build was rerun at this head).

Tests:

  • ctest --preset dev --no-tests=error -j1 -R '^startup_pixel_uav_' -E hardware -V: 1/1 passed (startup_pixel_uav_warp).
  • ctest --preset dev --no-tests=error -j1 -R '^startup_pixel_uav_' -N lists one hardware test, startup_pixel_uav_hardware.
  • ctest --preset dev --no-tests=error -j1 -R '^(startup_pixel_uav_hardware)$' -V: 1/1 passed. 0 capability skips (77).

The hardware test prints hardware: 21 cases and the exec guard control:

  • Drawn, texel (1, 2) written and every other word unchanged: a (texture A) and b (texture B). a.exec-on is drawn with the texel written; a.exec-off is drawn with every word unchanged.
  • 17 cases refused with every word unchanged, each with its logged reason: missing, srv, no-ua, uint, mip1, array, out-of-range, no-table, srv-and-uav, target, and the manifest lines a.float-line, a.compute-line, a.tex2da-line, a.buffer-line, a.uint-line, a.channels-field, a.second-view.
  • Control: control exec guard removed: fails as expected (texel_mismatch texture A mip 0 texel (1, 2) word 0: got 3f800000, expected c0000024).

The WARP run (adapter=Microsoft Basic Render Driver, driver 10.0.26100.9818) prints the same 21 cases with the same outcomes and reasons, the same control failure, and debug layer: on, errors: 0 in every case. The descriptor stride printed is 32 on the RTX and 64 on WARP, as the PR body describes.

On the PR so far: the review of e1d5a997 says "The new test needs Windows/WARP, so I could not run it or mutate the runtime code here", and the PR body lists "Release preset: not run". I found no NVIDIA run from anyone other than the author on this head.

Not covered by this run: NVIDIA only (RTX 3070 Ti); no AMD or Intel GPU; no Release build; the wider ctest -R '^startup_' suite was not run; the four runtime mutants in the PR body (swapped table entry, ALLOW_UNORDERED_ACCESS check removed, mip 1 instead of mip 0, render/depth target check removed) were not rerun here; the fail-first run on main was not repeated.

Refs R0Y00#1996 (item F). load_translation reads the 'uav N tex2d table P O'
line that gfx2hlsl.py writes for a pixel-stage image_store instead of
dropping the translation. The translated root signature gets a UAV range
after the SRVs in its view table, and each draw makes the view from the
unordered-access view the title created at that table entry, on mip 0 of a
2D texture. Version 2 manifests (the ones with uav lines) are read again;
each uav line is bound or refused by name, and the raw buffer line of the
vertex-stage stores (R0Y00#2059) stays refused.

Refused by name, nothing bound in place of the view: other line forms
(including a view qualifier or a channels field, as in the compute line)
when the manifest is loaded; at draw time no table, an entry outside the
table, an entry without a view, a view that is not a UAV, a resource
without ALLOW_UNORDERED_ACCESS, other resource or view dimensions, mips and
planes, integer, sRGB and non-colour formats, no typed UAV store, and a
texture that is also an SRV, a render target or the depth texture of the
draw. These checks run before any view of the draw is written. Indirect
draws refuse a translation with a uav line.

tests/startup_pixel_uav_check.py draws the source-built program of R0Y00#2155
through the runtime and reads back every word of four sentinel textures.

AI-assisted.
@roansystemlabs

Copy link
Copy Markdown
Contributor Author

@denn0x, a heads-up on overlap with your draft #2603, checked by diffing both heads (#2448 1247a289, rebased on fbe249f6; #2603 8634f27b); no runtime comparison yet.

Both PRs bind pixel-stage uav N tex2d table P O views in d3d12_draw.inl, so they meet in the same places:

One thing that may matter for #2603 itself: at 8634f27b, load_translation still refuses any manifest other than x2w-manifest 1, while its gfx2hlsl.py writes x2w-manifest 2 for every pixel program with a stored image. startup_draw_uav_check.py (mode tex) appends the uav line to a version-1 manifest, so it passes, but a translator-written pixel store would be refused before bind_uav_texture. #2448 accepts version 2 for this reason, and still refuses the vertex-stage raw line of #2059 by name.

#2448 is small (10 files), has a hardware run from @Makto94 on the previous head e1d5a997, and its tests were re-run on WARP and an RTX 3070 after the rebase. Either way works for us:

No rush, just say which you prefer.

AI-assisted.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Update for the conflict with main (head a9f01aa).

What I added:

  • Merged origin/main into the branch (no rebase). One conflict in src/startup_stubs/translated_sampler_bindings.h: main already has the uavs parameter and the UAV range in create_translated_root. I kept main's range code and the PR's sampler_root_parameter(views) change.
  • After the merge, startup_pixel_uav_{warp,hardware} failed in the no-ua case. Since runtime: give unknown-dimension views a default view and skip mismatched ones #2649 the device records no view for a UAV over a resource without ALLOW_UNORDERED_ACCESS, so the draw is still refused with every word unchanged, but now with the reason table entry holds no view. I updated that one expected reason in tests/startup_pixel_uav_check.py.

Commands executed:

  • python3 tests/startup_pixel_uav_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check on Linux: ok.
  • Win2025 WARP, dev and release builds of startup_stream_consumer and the sampler checks, then ctest ^startup_(pixel_uav|translated_sampler_bindings|sampler_comparison|frame_copy|d16_srv|mubuf_descriptor|address_volume_srv): 13/13 passed in dev and 13/13 in release (incl. startup_pixel_uav_warp and _hardware on WARP).

AI-assisted; commands listed were executed locally.

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.

3 participants