Skip to content

runtime: bind table buffers, 2D texture inputs and texture outputs on the in-process compute route - #2993

Open
Leyukaka wants to merge 5 commits into
R0Y00:mainfrom
Leyukaka:native-bind
Open

Leyukaka wants to merge 5 commits into
R0Y00:mainfrom
Leyukaka:native-bind

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Part 2 of #2974 (step 3). It also covers half4_texture_uav, beyond the issue's list, because the offline formatter pairs it with texture_uav. Part of #2935. Target branch main. Builds on #2975: this branch contains its commits, so please merge #2975 first; I will rebase afterwards.

Change (src/startup_stubs/d3d12_compute_dispatch.inl): translate_compute_natively, the in-process route of #2958 (X2W_NATIVE_SHADERS), bound only raw_vector_srv and raw_buffer_uav. It now also fills the ComputeTranslation slots that the manifest reader fills for these kinds:

Binding Image dimension Same slot as the manifest line
buffer_srv - srv N buf table P OFF
texture_srv 1 (2D) srv N tex2d table P OFF
texture_uav, half4_texture_uav 0 / 1 / 5 / 2 uav N tex1d / tex2d / tex2da / tex3d float table P OFF channels 4
  • The kind and image-dimension rules are the ones format_compute_runtime_manifest uses, so both routes use the same slot for these kinds. The in-process route stays narrower: no samplers, no byte_window_srv, and array count 1 for every view.
  • The register-order, array-count, root-parameter and size checks are unchanged. Samplers and every other kind stay refused with the existing messages.
  • Not included: byte_window_srv, which the offline formatter also writes as srv N buf table. It can follow if wanted.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on #2975 (e18549ca) plus this commit.

  • startup_compute_dispatch_native_hardware passed with a new case: a scalar buffer read (buffer_srv) and a 2D image load (texture_srv) feed a 3D image store (texture_uav). The whole volume matches a CPU reference. The consumer gains a texture-volume-native-inputs mode that provides the buffer descriptor and the 2D SRV token.
  • Control: the same program with image_sample_lz in place of the load adds a sampler, is refused with "not translated natively: a sampler, ..." and leaves the volume untouched.
  • startup_compute_dispatch_native_warp exits 77 as before: WARP has no 32-lane waves, and the new case checks the refusal by that name with the volume untouched.
  • startup_compute_dispatch_texture_hardware and _warp still pass.
  • Not exercised on the in-process route: half4_texture_uav and the 1D, 2D and 2D-array outputs. They share the slot code with the 3D case. The code comment and docs/startup-runtime.md no longer limit the route to the kinds a fixture has run through.

Mutation checks, run by hand; each fails the hardware check:

  • leaving buffer_srv unbound (the buffer holds a value the store fixture never writes);
  • leaving texture_srv unbound;
  • mapping image dimension 2 to a 2D UAV instead of 3D.

AI-assisted.

…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.
…1D UAV fixture

After a published compute translation fails PSO creation, the stand-in
checks the adapter's wave capabilities (the same OPTIONS1 test the
native route uses) and logs "pipeline creation failed: the adapter has
no 32-lane waves" when they rule out a WaveSize(32) module. The texture
check skips the native 3D/1D dispatch cases on WARP only for that
reason; any other PSO failure fails it. Portable 3D and 1D cases
compile a cs_6_0 store with dxc and a hand-written manifest, so the
binding path is checked on WARP and hardware independently of the C++
compiler.

AI-assisted.
…ility beside it

A failed published compute PSO stays "pipeline creation failed". The
stand-in adds the adapter's 32-lane wave capability as observed:
"(adapter has no 32-lane waves)" or "(adapter wave capability query
failed)". The manifest records no wave size, so the runtime does not
claim the shader needed one. Only the texture check, whose native
modules declare WaveSize(32), skips its native cases on WARP for the
no-waves observation.

AI-assisted.
… the in-process compute route

translate_compute_natively (X2W_NATIVE_SHADERS) bound only raw_vector_srv
and raw_buffer_uav. It now also fills the ComputeTranslation slots the
manifest reader fills for buffer_srv (srv buf table), texture_srv with
a 2D image (srv tex2d table) and texture_uav/half4_texture_uav with a
1D, 2D, 2D array or 3D image (uav tex1d/tex2d/tex2da/tex3d float table
channels 4), with the same kind and image-dimension rules as
format_compute_runtime_manifest. Samplers and other kinds stay refused.

The native check gains a case where a scalar buffer read and a 2D
image load feed a 3D image store, compared with a CPU reference; the
same program with a sample instead of the load must be refused with
the volume untouched.

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.

Good extension of the in-process compute route — the unified UAV dimension dispatch table, the manifest parsing unification (%15s format), and the wave-32 capability tracking are all clean.

Findings

✅ What works well

  • format_compute_runtime_manifest switch: Replacing the image_dimension == 1 || image_dimension == 5 guard with a switch over 0/1/2/5 mapping to tex1d/tex2d/tex3d/tex2da generalizes cleanly to all existing dimensions. The default: return std::nullopt catches unsupported values.
  • Manifest parsing unification: %15s captures the dimension name string for all UAV types, then uav_dimension() lambda maps it. This replaces two separate sscanf patterns with one — a real simplification.
  • ComputeTranslation::uavs field rename: bool array → D3D12_UAV_DIMENSION uav_dimension is a meaningful upgrade: the old code only expressed "is this 2D array?", but the new code carries the full dimension enum, which is exactly what CreateUnorderedAccessView needs.
  • volume_uav_range_error helper: Validates view.MipSlice < resource.MipLevels and FirstWSlice/WSize against the mip slice depth. The (std::max)(1u, UINT{depth} >> (std::min)(view.MipSlice, 15u)) depth computation matches D3D12 mip level math.
  • Wave capability tracking: adapter_32_lane_waves() checks D3D12_FEATURE_D3D12_OPTIONS1.WaveOps, WaveLaneCountMin and WaveLaneCountMax — correct. The return values (-1 for query fail, 0 for no 32-lane, 1 for yes) cleanly propagate into the refusal message.
  • Doc update to startup-runtime.md: Accurately reflects the expanded set: buffer_srv, raw_vector_srv, raw_buffer_uav, texture_srv (1D/2D), texture_uav / half4_texture_uav (1D/2D/2D-array/3D).

⚠️ Issues / observations

  1. uav_dimension() lambda scope: The lambda is defined inside load_compute_translation and captures nothing. It uses std::strcmp which is available via <cstring>. The lambda is called immediately after definition, so its scope is fine. However, consider whether this would benefit from being a static helper or a member function of ComputeTranslation if the pattern is reused for SRV dimension lookup (which currently uses sscanf("srv %u tex2d table ...") with a hardcoded "tex2d" string).

  2. Mip slice depth computation: (std::max)(1u, UINT{resource.DepthOrArraySize} >> (std::min)(view.MipSlice, 15u)) — the >> (std::min)(view.MipSlice, 15u) handles MipSlice >= 16 by capping the shift at 15, which gives depth=1 for very large mip slices. This prevents undefined behavior from shifting by ≥32 bits. Good defensive code.

  3. volume_uav_range_error return for WSize == 0: When view.WSize == 0, the condition !view.WSize triggers early return with a non-null error. This means "WSize must be nonzero" is enforced. Is this the intended behavior, or should 0 mean "full extent" (matching D3D12 semantics where D3D12_TEX3D_UAV::WSize of 0 means the full remaining depth)? If 0 should mean full, the check needs adjustment. If 0 is intentionally refused, add a comment explaining why.

  4. half4_texture_uav slot code sharing: The PR mentions that half4_texture_uav shares slot code with texture_uav in the formatter. The switch in format_compute_runtime_manifest maps half4_texture_uav to the same tex* strings as texture_uav. This is correct if both kinds produce the same UAV dimension values at runtime. Verify that half4_texture_uav indeed sets image_dimension to one of 0/1/2/5 and not a distinct value.

  5. CMake texture_native_args variable: The unset(texture_native_args) before the conditional is good practice to avoid leaking from previous test definitions. However, if compile_dxil or its DLLs are not found, ${texture_native_args} is empty but the variable still exists (as empty). ${adapter} ${texture_native_args} would expand to just ${adapter} — correct, but consider using if(texture_native_args) in the next add_test call for clarity.

Recommendation

With the one important question around WSize == 0 semantics (item 3), this is ready to land. Otherwise well-structured and well-tested.

🏷 Long-term: if the in-process route expands further (samplers, byte_window_srv, typed views), consider whether the refusal message pattern ("not translated natively: ...") could be generalized into a dedicated error classification instead of accumulating string literals.

@Leyukaka

Copy link
Copy Markdown
Contributor Author

Thanks for the review. On item 3: refusing WSize == 0 is intended.

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 Release /O2 run at 917c124dfa3ee0c6ce735286ffc1617dec851b01, on Windows 11 build 26200.9974 with SDK 10.0.26100. The RTX 4060 Laptop (32.0.16.1656) passed startup_compute_dispatch_native_hardware: the scalar table buffer and 2D SRV fed the 3D output and all 6,144 words matched, with the sampler refusal control and no debug-layer error. Both startup_compute_dispatch_texture_* entries passed. startup_compute_dispatch_native_warp failed with consumer exit 2173, not a capability skip, on WARP 10.0.26100.9818. I reproduced it running only table_views: with the D3D12 debug layer enabled, the last log is creation of the 1×1 input resource and the child exits before the expected no-wave refusal. With the layer disabled, both isolated refusal cases complete. Please preserve the debug-layer path and investigate the input view setup before treating WARP as 77. Git confirms #2975 e18549ca is an ancestor of this head; please land it first and retest this PR after rebasing.

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

Follow-up on 917c124d. Independent Debug (dev, embedded /Z7 to work around the local PDB toolchain) reproduced the Release result: texture/WARP and both hardware entries passed, while native/WARP exited 2173. A direct descriptor query measured CBV/SRV/UAV increments of 64 bytes on this WARP versus 32 on the RTX 4060 Laptop. The new consumer writes the input SRV at fixed cpu + 32. In a local fixture-only probe, using slot 15's increment for the two descriptor creation handles changed Release native/WARP from failure to the expected 77, with the debug layer still enabled. Separately, I set Texture3D.WSize=0 in the native volume fixture on RTX: native translation succeeded, Dispatch refused, and all 6,144 words retained their sentinels. Please carry both cases into the fixture. The in-process 1D and 2D-array descriptor paths and half4 output still lack direct readback. Targeted cases for those branches matter more than duplicating the full dimension/format matrix; published/offline coverage does not exercise their native binding path.

…ture; add zero-W, 1D, 2D-array and half4 native cases

The texture-volume-native-inputs mode created its SRV and UAV at fixed
32-byte offsets, which is mid-descriptor on adapters with a wider
CBV/SRV/UAV increment (64 bytes on WARP). It now queries the increment
(device slot 15) for the creation handles. On a wider heap the 32-byte
tokens are copied into a packed table at the guest byte offsets the
program reads, and that table's base is bound.

The native check gains a Texture3D.WSize = 0 control (translated
natively, Dispatch refused, output untouched) and in-process readbacks
for a 1D float output, a 2D-array output on a non-zero layer and a
half4 (D16) output, each against a CPU reference.

AI-assisted.
@Leyukaka

Copy link
Copy Markdown
Contributor Author

Thanks for finding the stride. Both cases and the targeted readbacks are in the new commit.

Descriptor increment. The fixture now queries the CBV/SRV/UAV increment (device slot 15) and creates the SRV and UAV at cpu + 1 * increment and cpu + 2 * increment.

  • Slots 18 and 19 write a 32-byte token at the stride-aligned title handle.
  • The translated Dispatch reads the table at the literal guest byte offsets the manifest names (0, 32 and 64).
  • So with a 32-byte increment nothing moves. With a wider one, the fixture copies the tokens into a packed region of the same heap, at those guest offsets, and binds that region's base.
  • X2W_D3D12_DEBUG stays set for every case; no debug-layer code changed.

New cases in startup_compute_dispatch_native_check.py, against a CPU reference or the untouched sentinels:

Case Checked
Texture3D.WSize = 0 translated natively, Dispatch refused with "an output 3D texture W range is outside the mip", all 6,144 words untouched
1D float output (image dimension 0) all 128 words
2D-array output (dimension 5), relative layer 1 all 6,144 words
half4 output (D16 store, round to nearest even) all 1,024 halves

On adapters without 32-lane waves, each case checks the no-wave refusal with the output untouched.

Results. The setup was Windows 11 with an RTX 5080 and DXC from the Windows SDK 10.0.26100.

  • Hardware: native passed with all new cases; texture passed.
  • WARP: native exits 77 after the refusals; texture passed.
  • This machine has no D3D12 SDK layers, so I could not reproduce the debug-layer exit 2173 or confirm the fix under the layer here. Your probe covers that.
  • I did not measure the increment of my local WARP. The packed-table path of the native-inputs mode is not exercised past the no-wave refusal on any adapter I have: WARP has no 32-lane waves, and the hardware has a 32-byte increment.
  • Three manual mutants each fail the hardware check:
    • accepting WSize == 0;
    • mapping image dimension 5 to a 2D UAV;
    • leaving half4_texture_uav unbound.

Order agreed: #2975 first, then I will rebase this PR and retest.

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. Comprehensive expansion of the in-process compute route (#2958) to
    bind buffer_srv, texture_srv (2D), texture_uav (1D, 2D, 2D-array,
    3D) alongside the existing raw_vector_srv and raw_buffer_uav.
    The manifest formatter correctly maps image_dimension values to tex1d
    /tex2d/tex2da/tex3d output keywords in direct_compute_cache.cpp.
  2. volume_uav_range_error() correctly checks 3D UAV mip slice against
    MipLevels and W range against depth -- the first 16-refusal path will
    log proper reasons instead of silent failures.
  3. view_slot() changes: the renamed record_refused_uav flag and the new
    1D UAV mip slice check at slot 19 add consistency between creation and
    dispatch refusal paths.
  4. Clean build-dependency handling in CMakeLists.txt: the texture_native
    test now passes compile_dxil and DXC bin dir as extra args when
    available.

Issues

  1. ComputeTranslation struct changes: array member renamed to
    uav_dimension with type D3D12_UAV_DIMENSION. The old array flag
    for 2D-array was used in specific paths. This rename should be verified
    against all callers -- the diff doesn't show every reference.
  2. build on the dependency on #2975 (the PR title says this builds on
    #2975; reviewers should review #2975 first or be aware of that
    dependency).
  3. volume_uav_range_error() for 3D uses resource.DepthOrArraySize
    shifted by the mip slice, but for 3D resources the mip slice can go
    up to 15 (the (std::min)(view.MipSlice, 15u) handles that).
    This is correct. However, the ~0u case for WSize means 'full depth
    minus first_w_slice' -- this is the standard default in most UAV
    descs and is handled correctly.

Recommendations

  • Verify all existing uses of the array field in
    d3d12_compute_dispatch.inl were migrated to the uav_dimension field.
  • Consider adding a specific test for the 1D UAV mip slice refusal at
    the view creation (slot 19) path.

Overall

Well-scoped expansion of the native compute route with proper manifest
mapping and refusal reasons. The 3D UAV range validation is correct.
Approvable after verifying the array->uav_dimension migration.

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

Reviewed a5d118336bc18f44eb5d2bc8ae8f253bebd5bd91. Exact-head Debug and Release /O2 runs of ctest --preset <dev|release> --no-tests=error -V -R '^startup_compute_dispatch_(texture|native)_(warp|hardware)$' each gave 3 passes and one explicit WARP capability skip (77). Windows 11 26200.9974, SDK 10.0.26100, Microsoft WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The debug layer stayed enabled. WARP now reaches the wave32 refusal with sentinels intact. RTX matched all words for the table-buffer/2D-SRV-fed 3D store, 128 values for 1D, 6,144 for the 2D array, and 1,024 half values for the packed D16 case. The sampler and WSize=0 controls left the volume unchanged. The packed-table path on wider heaps is covered by WARP descriptor creation and portable dispatch; a native wide-increment success run is still unavailable. #2975 e18549ca remains an ancestor. Please land it first, then rebase #2993 and rerun the focused suite before merging.

@R0Y00
R0Y00 changed the base branch from cpp-migration to main November 27, 2026 11:09
sydney-0o added a commit to sydney-0o/Xbox2Windows that referenced this pull request Nov 27, 2026
@R0Y00

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Retargeted to main. The current head is stacked on #2975. It merged cleanly on top of my local #2975/main integration, and the synthetic Debug dispatch and root-SRV regressions gave five passes and one WARP capability skip. #3049 now carries both changes on main. Please coordinate there before rebasing this branch separately. Keep the WSize=0 sentinel check, 1D/2D-array/D16 readbacks and the WARP capability result when comparing candidates.

@sydney-0o

Copy link
Copy Markdown
Contributor

I opened PR #3049 on main with the remaining #2975 manifest work and the in-process bindings from this PR. The empty-cache native dispatch fixture passed on a GTX 1080 Ti with app-local Agility SDK 1.620.2, including mixed buffer/2D texture inputs, 1D/2D-array/3D stores, the packed-half store and the zero-W and sampler refusal controls. The original commits retain your authorship.

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.

4 participants