Skip to content

startup: lower compute image_store to 1D and 3D texture UAVs (Part of #2022) - #2902

Merged
R0Y00 merged 4 commits into
R0Y00:mainfrom
Leyukaka:img3d1d-store
Nov 27, 2026
Merged

R0Y00 merged 4 commits into
R0Y00:mainfrom
Leyukaka:img3d1d-store

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2022 (claim). The runtime half takes over the tex3d/tex1d part of the "Texture UAVs" item in #2274 (NiiRoZz), as announced there.

Translator (tools/startup/gfx2hlsl.py): a compute image_store with dmask:0xf lowers to:

  • RWTexture3D<float4> on SQ_RSRC_IMG_3D, with a three-component address given as a VGPR tuple or an NSA list;
  • RWTexture1D<float4> on SQ_RSRC_IMG_1D, with one component.

It is accepted on the same terms as the 2D path: format, unorm, data registers, fixed table descriptor. The manifest names the output uav N tex3d|tex1d float table P O channels 4. Partial dmasks (with or without d16) and 1D/3D stores in the pixel stage stay refused.

Runtime (src/startup_stubs/d3d12_compute_dispatch.inl, d3d12_xs_device.cpp):

  • Dispatch parses tex1d and tex3d outputs. The slot's array flag becomes a UAV dimension, and 2D and 2D-array behave as before.
  • The title's own view description is kept. Dispatch checks the view and resource dimensions, the mip and, for 3D, the W range against the depth at that mip (WSize all ones selects the remaining slices).
  • Device slot 19 now records a 3D UAV whose mip or W selection is outside the resource, or a 1D UAV whose mip is, as refused instead of creating it (when the descriptor holds no live view, as for the existing refusal of a resource without unordered access), so Dispatch reports that reason.
  • Refused requests are retried by --pending (and by the first --watch pass), so the compute cache revision is unchanged (as in shader: lower image_store on SQ_RSRC_IMG_2D_ARRAY in gfx2hlsl #2744).

Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100, on main 6ee878d8 plus this commit):

  • New tests/startup_gfx2hlsl_image_store_3d1d_check.py: ok. It checks:
    • the decoded and assembled store words;
    • the emitted HLSL and manifest line for the 3D tuple, 3D NSA and 1D forms;
    • refusals for the pixel stage, a wrong address width, and partial dmasks with and without d16.
  • tests/startup_compute_dispatch_texture_check.py <startup_stream_consumer> <dxc> warp and hardware: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. New cases:
    • 3D tuple and 3D NSA: a source-built dispatch writes mip 1 of a 3D texture through a view starting at W slice 1. All 6,144 words match the CPU reference.
    • 1D: writes mip 1 of a 1D texture. All 128 words match.
    • Refusals: a 2D view in place of either kind, an out-of-range W selection and a 1D view one past the last mip are refused with the texels unchanged.
  • Also ok: startup_compute_image_store_check, startup_compute_image_store_d16_check, startup_gfx2hlsl_compute_check, startup_pixel_image_store_check, startup_translator_check, startup_gfx2hlsl_refusals_check, startup_compute_request_offline_check, docs_links_check, bidi_controls_check.

Mutation checks, run by hand:

  • dropping the third address component, mapping 1D to 2D, and allowing 1D/3D in the pixel stage each fail the translator check;
  • skipping the W-range check, or dropping the 1D mip check before the created test (runtime, rebuilt), fails the WARP dispatch check.

Measured on a local capture (counts and instruction shape only):

  • Census: at main b505c32, 291 requests translate. With this branch on 6ee878d8 (b505c32..6ee878d8 does not touch gfx2hlsl.py), 317 translate and no image_store on SQ_RSRC_IMG_3D|1D refusal remains.
  • Start-up run: in a 600 s run at 6ee878d8, three compute pipelines dispatch with no translation 16,798, 687 and 687 times. Their first refusal is this store. With this branch all three translate and compile with DXC. Their manifests use only forms the runtime binds: raw buffers, one 2D texture input and the new 3D or 1D output.

Prior art in the offline tools/compute_store_aot.py: 3D stores (#1649) and the 1D slice (#1545).

AI-assisted.

A compute image_store with dmask 0xf on SQ_RSRC_IMG_3D or
SQ_RSRC_IMG_1D now lowers to a store into RWTexture3D<float4> (a
three-component address, as a VGPR tuple or an NSA list) or
RWTexture1D<float4> (one component), on the same terms as the 2D path:
format, unorm, data registers and the fixed table descriptor. The
manifest names the output uav N tex3d|tex1d. Partial dmasks, d16 with a
partial dmask and 1D/3D stores in the pixel stage stay refused.

At Dispatch the runtime parses tex1d and tex3d outputs, keeps the
title's own view description, and checks the view and resource
dimensions, the mip and, for 3D, the W range against the depth at that
mip. Slot 19 records a 3D view with an out-of-range W selection as
refused instead of creating it, so Dispatch reports that reason.

Refused requests are retried by --pending, so the compute cache
revision is unchanged.

AI-assisted.
… view

Device slot 19 checked only 3D views before calling the desktop
CreateUnorderedAccessView, so a 1D view whose mip is outside the
resource reached D3D12 with an invalid description, and Dispatch
reported the mip reason only if that view was recorded as created.
Slot 19 now records such a 1D view as refused, and Dispatch checks the
1D mip before the created test, as it does for 3D. The dispatch check
adds a texture-line-bad-mip case.

Found in an independent review. AI-assisted.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR #2902 — Review Notes

✅ What looks good

1. Translator is clean and conservative (tools/startup/gfx2hlsl.py)

  • The shapes dictionary approach is nice — it keeps 2D/2D-array for all stages and adds 1D/3D only for compute (self.kind == 'cs')
  • Pixel stage correctly still refuses 1D/3D with the updated supported string
  • Refused error messages updated: 'only 2D images' → 'only 1D, 2D, 2D-array and 3D images'

2. Runtime validation is thorough (d3d12_compute_dispatch.inl)

  • The volume_uav_range_error() helper correctly validates:
    • 3D mip vs resource mip levels
    • 3D W-range: FirstWSlice >= depth, WSize == 0, or WSize > remaining slices
    • Also handles the special WSize == ~0u case (selects remaining slices)
  • 1D validation checks mip against resource.MipLevels
  • Distinguishes between resource/view dimension mismatch and range errors

3. Tests are well-designed

  • startup_gfx2hlsl_image_store_3d1d_check.py covers 3 forms: volume (3D tuple address), volume-nsa (3D NSA), line (1D scalar address)
  • Mutation checks: dropping 3rd coordinate, mapping 1D to 2D, partial dmasks
  • The dispatch test correctly checks:
    • Mip-one readback with correct expected values
    • Refusals for 2D-view-in-place-of-3D, out-of-range W, 1D-view past last mip
    • Refused dispatch leaves texels sentinel-unchanged

4. Documentation is clear

  • New docs/experiments/startup-compute-volume-line-uav.md explains the feature
  • startup-runtime.md update fits the existing pattern

⚠️ Issues to consider

1. Code duplication: volume_uav_range_error() exists in two files

This function appears in both d3d12_compute_dispatch.inl (for manifest loading) and d3d12_xs_device.cpp (for slot-19 view creation). Maintenance risk — consider consolidating into a shared utility or making it inline/static accessible to both translation units.

2. The startup_compute_image_store_d16_check.py deletion shows the test no longer refuses 3D in the d16 path. Is this intentional — does the d16 path support 3D as well, or was the old refusal test simply removed because it's no longer relevant? If it's intentional, a brief comment would help future maintainers.

🏷 Recommendations

Priority Action
Medium Check that the volume_uav_range_error() duplication doesn't need consolidation
Low Consider adding a test case where WSize == ~0u (selects remaining slices) for the 3D case
Info The census data at the end is useful — 291→317 translated, 0 refusals remaining

Overall verdict

Clean, well-tested PR. The translator and runtime changes are conservative (refusals when expected), the mutation checks validate correctness, and the documentation matches the code. Ready for merge pending the duplicate function check.

The d16 path with dmask 0xf unpacks two data registers into the four
channels, low half first, for 3D and 1D images as it does for 2D. The
3D/1D check now asserts that store for the tuple, NSA and 1D forms.

AI-assisted.
@Leyukaka

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  1. volume_uav_range_error() has a single definition, in src/startup_stubs/d3d12_compute_dispatch.inl. d3d12_xs_device.cpp includes that file (#include "startup_stubs/d3d12_compute_dispatch.inl") before slot 19 calls it, so both callers are in the same translation unit and share the one definition.
  2. The removed lines in startup_compute_image_store_d16_check.py were a control asserting that a d16 store to a 3D image is refused with only 2D images. That is intentional: with the full mask, d16 now takes the same packed-half path for 3D and 1D as for 2D, and partial masks, with or without d16, stay refused. You are right that nothing checked the accepted case, so I added it in 4d99af0: tests/startup_gfx2hlsl_image_store_3d1d_check.py now asserts the d16 full-mask store for the tuple, NSA and 1D forms. A mutant that drops the f16tof32 unpack fails it.

AI-assisted.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What works

  1. Clear feature progression: this PR correctly extends the 2D
    image_store path to 1D and 3D, part of the tracked #2022 effort.
    Translator lowering is clean -- full-channel (dmask:0xf) stores on
    both dimensions are lowered with proper address computation (VGPR
    tuple for 3D, scalar uint or NSA list for 1D).
  2. Good design choice replacing the array bool with
    uav_dimension = D3D12_UAV_DIMENSION_ enum in
    ComputeTranslation. This removes ambiguity for 1D where array
    previously had no meaning.
  3. Test coverage is thorough: volume (3D VGPR tuple),
    volume-nsa (3D NSA list), and line (1D) forms are all tested,
    with readback verification against a CPU reference.
  4. The volume_uav_range_error() in d3d12_compute_dispatch.inl is
    correct -- it checks MipSlice against MipLevels and validates
    FirstWSlice/WSize for the 3D case, using the same pattern as the
    existing resource-type checks in view_slot().

Issues

  1. In d3d12_compute_dispatch.inl, the uav_dimension lambda
    recognizes tex1d/tex2d/tex2da/tex3d in the manifest output line.
    The if constexpr path in dispatch uses the dimension to choose
    the correct resource desc (e.g., DepthOrArraySize for 3D). Verify
    that the manifest for 1D UAVs doesn't accidentally set arrays when
    the title expects a contiguous 1D view.
  2. The volume_uav_range_error function is defined inside a
    const char* block -- make sure this placement is intentional and
    not accidentally scoped to a local function or if block.
  3. Updated startup_compute_image_store_check.py now expects
    only 1D, 2D, 2D-array and 3D images as the refusal reason for
    cube. This is an API-visible change to the refusal message --
    ensure any downstream consumers parse the message string or match
    by keyword, not by exact equality.

Recommendations

  • Consider adding a test for a mismatched 3D W range (wrote beyond
    the slice window) in addition to the out-of-range slice test.
  • The 1D validation only checks MipSlice. Consider future-proofing
    with WSize validation in case 1D views are extended later.
  • The volume_uav_range_error function might benefit from a
    comment noting that WSize of all ones means 'remaining slices'.

Overall

Solid, well-scoped feature extension. The design is clean, test
coverage is good, and the array -> uav_dimension refactor is
a welcome improvement. Approvable after the message-matching concern
is confirmed (issue 3).

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

Integration check for 4d99af0e: current main 6aa59440 conflicts in docs/startup-runtime.md, src/startup_stubs/d3d12_compute_dispatch.inl, and tools/startup/gfx2hlsl.py. A separate merge trial with #2975 conflicts in tests/startup_compute_dispatch_texture_check.py. Please keep the existing root-SRV and manifest-retry paths when updating this PR. The Python translator/offline and native C++ fixtures can share the accepted shape while retaining their separate compiler routes and WARP capability reporting.

# Conflicts:
#	docs/startup-runtime.md
#	src/startup_stubs/d3d12_compute_dispatch.inl
#	tools/startup/gfx2hlsl.py
@Leyukaka

Copy link
Copy Markdown
Contributor Author

Merged main 6aa59440 into this PR and resolved the three conflicts:

After the merge, ctest -R "startup_compute|startup_pixel_image_store|startup_manifest_retry|image_store|compute_root_srv|startup_gfx2hlsl_compute" passed 235 of 235 (Release, RTX 5080 and WARP). This merge does not resolve the conflicts with #2975 (based on cpp-migration). Its branch conflicts with this one in tests/startup_compute_dispatch_texture_check.py, and with main in d3d12_compute_dispatch.inl. Both come up when main is merged into cpp-migration once the two PRs have landed. I will resolve them then, keeping both the Python and the compile_dxil routes in the test.

AI-assisted.

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

Independent integration review of ea94c5a4 on current main 98e4a2ee (83776998 locally). The earlier three conflicts are resolved. The reconciled code retains the root-SRV and manifest-retry paths and the existing 2D/2D-array and partial pixel-store behavior.

I rebuilt startup_stream_consumer and d3d12_xs_shim in both dev and release (/O2). In each preset, ctest --preset <preset> --no-tests=error -R '^(startup_compute_dispatch_texture_(warp|hardware)|startup_gfx2hlsl_image_store_3d1d|startup_compute_image_store(_d16)?|startup_compute_root_srv_dispatch_(warp|hardware))$' passed all seven tests in two invocations, with no skips. The texture cases checked the 1D/3D mip-one readback plus the wrong-view, bad-W and bad-mip refusals. The root-SRV cases retained the nonzero-offset readback and rejection controls. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, D3D12 debug layer enabled for the GPU fixtures.

Hosted Windows, Linux Python and gfx1013 fixture checks are green. The hosted /O2 job skipped and local /O2 passed. As discussed, keep the two compiler routes when reconciling the shared texture fixture with #2975 on cpp-migration. I also found overlap with #2882 in the texture fixture and stream consumer. I will record the required reconciliation on that PR.

@R0Y00
R0Y00 merged commit f520469 into R0Y00:main Nov 27, 2026
5 checks passed
sydney-0o pushed a commit to sydney-0o/Xbox2Windows that referenced this pull request Nov 27, 2026
…e manifest (R0Y00#2974)

The stand-in's manifest reader and Dispatch path took only 2D and 2D
array output textures, so a compute program storing to a 3D or 1D image
could not run on cpp-migration. The runtime half of R0Y00#2902 (open on main)
is taken here unchanged: `uav N tex3d|tex1d float table P OFF channels
C` lines, TEXTURE3D/TEXTURE1D UAV views from the title's view record,
and the mip and W range checks, also for slot 19. For the offline route,
format_compute_runtime_manifest now writes those lines for 3D and 1D
texture UAVs, so compile_dxil publishes a manifest the runtime accepts.

AI-assisted.

(cherry picked from commit fb53abd)
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