Skip to content

Split wave32 geometry: refuse prefix counts over a mask - #44

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
grahamster2:fix/wave32-mask-prefix-count
Nov 22, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
grahamster2:fix/wave32-mask-prefix-count

Conversation

@grahamster2

Copy link
Copy Markdown
Collaborator

Summary

The split wave32 form of a logical wave64 (geometry mode on adapters without 64-lane waves, e.g. NVIDIA, since #14) gives each native half only its own word of EXEC, VCC and v_cmp results. geometry_wave32_hazards refuses the cross-half operations, but it had no rule for v_mbcnt_lo/hi over a mask. For lanes 32..63, v_mbcnt_lo of exec_lo / vcc_lo / a v_cmp SGPR pair then counts 0 instead of the active lanes of 0..31, so a compaction index or prefix count is silently wrong.

  • v_mbcnt_* whose SRC0 is not an inline constant or literal is now a hazard ("prefix count over a whole-wave mask"). The lane-index idiom (v_mbcnt of -1) stays accepted.
  • A VOP3 v_cmp into an SGPR pair is a mask too, in geometry_wave32_hazards and in mesh_wave's taint. So s_bcnt / s_ff1 / s_flbit of one of its 32-bit words, and an s_cmp of such a word that a branch reads, are refused like the 64-bit forms.

Emission is unchanged.

Test

gpu_geometry_wave32_prefix_count_over_a_mask: an ES computes VCC (lanes with lane & 3 != 0) and s[10:11] (lanes below 40), then v_mbcnt over VCC, over s[10:11] and over EXEC after s_and_saveexec, and stores the three counts. It runs the compute pass only (runner::dispatch), so an adapter without mesh shaders can run it too. If the split translation is refused, the test passes. If it translates, the output must equal a CPU wave64 reference. The native translation must always succeed, and on a wave64 adapter it also runs and is checked against the reference.

Before the fix, on both an RTX 3080 (wave 32) and a Radeon RDNA2 iGPU (forced to the split form), lanes 0..31 were right and lanes 32..63 counted only their own half, e.g. got / want for [VCC, s[10:11], EXEC]:

lane got want
33 0, 1, 0 24, 33, 24
43 8, 8, 8 32, 40, 32
63 23, 8, 23 47, 40, 47

After the fix, it passes on both, and the native wave64 run on the iGPU matches the CPU reference. geometry_wave32_rejects_cross_half_operations and a new mesh_wave unit test cover the new rules.

cargo test --workspace --release --no-fail-fast on the RTX 3080 with XCL_SAMPLE_RPF set to a retail shaders.rpf: lib 328 passed, 0 failed. gpu_pso_e2e gives 4 / 6, the same 2 mesh failures as on main (wave64 MS on a 32-lane adapter, #39 / #42). retail_es_gs_voxelize_geometry_mode and retail_gs_pipeline_through_the_hook still pass, and the first of them uses the split path there. All 195 ES+GS pairs of that pack pass geometry_wave32_hazards before and after, so the new rule refuses no retail program.

Open question

The v_mbcnt rule refuses any non-constant SRC0, including an SGPR that only holds a constant. That fails closed like the other rules. A taint-based version is possible if you'd prefer it. #39 will need the same check for the mesh path, so this rule would apply there too.

The split form of a logical wave64 (adapters without 64-lane waves) gives
each native half only its own word of EXEC, VCC and v_cmp results. A
v_mbcnt over such a mask then counted 0 for the other half: in lanes
32..63 a compaction index or prefix count missed the active lanes of
0..31 (an ES counting the lanes of a v_cmp got 0..23 instead of 24..47
there on the RTX 3080).

geometry_wave32_hazards now refuses v_mbcnt whose SRC0 is not a constant
(the lane-index idiom, v_mbcnt of -1, stays accepted). A VOP3 v_cmp into
an SGPR pair is a mask too, in the scan and in mesh_wave's taint, so
s_bcnt / s_ff1 / s_flbit of one of its words and an s_cmp of a word that
a branch reads are refused like the 64-bit forms.
@ivall

ivall commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks, merged! On an RX 9070 (native wave64) all tests pass, gpu_pso_e2e too with a retail shaders.rpf (6 / 6). It changes nothing there, as expected. The v_mbcnt table is a nice catch.

vincentes added a commit to vincentes/xcl-wasm that referenced this pull request Nov 24, 2026
The null device becomes `win::d3d12x`, a device that does the memory side
of D3D12.X for real and still renders nothing:

- Unified memory, as on the console: a resource's GPU address is its
  address in the title's address space. Committed resources and heaps get
  graphics memory, placed resources lie in their heap, and
  CreatePlacedResourceX (xcl-dev#44) puts one on memory the title allocated; Map
  returns that address. Read-back buffers up to 64 MiB come from the
  fourth 4 GiB of the region, where XCL's Windows runtime keeps them.
- Command lists record; a queue runs what it is given, in order, at every
  turn of the scheduler (`pump`): buffer copies, the console's memory
  commands (CopyMemoryToMemoryX xcl-dev#60, FillMemoryWith32BitValueX xcl-dev#61,
  Write32 / 64BitValue…X xcl-dev#69 / xcl-dev#70 / xcl-dev#89 with the GPU timestamp) and
  Wait32 / 64BitValueX (xcl-dev#71 / xcl-dev#72), which hold the queue until another
  thread writes the value. KickoffX (xcl-dev#93) starts a list before it is
  closed. A fence moves, and its events are signalled, when the queue
  gets to its Signal.
- The console's layouts: device extensions from slot 44
  (CreateCommandQueueX, CreateCommandListX with the DMA engine's own list
  interface, page pools, pipeline-state creation as objects, …), the
  graphics command list's console slots, AllocateUploadMemory (xcl-dev#148).
- CheckFeatureSupport zeroes the whole structure; a raytracing
  acceleration structure view writes the console's descriptor words.

Draws, pipelines, other views, PresentX and the frame clock do nothing
or are missing. Dev builds optimise `xcl-emu` (the title test: 37 s →
3.3 s).

Measured on macOS (aarch64): the test title passes 40 of its checks (9 of
D3D12.X's 16); the 6 that fail before it aborts in its XG texture check
need HLSL compilation and rendering, the frame clock, or DirectStorage.
`cargo test -p xcl-guest`: 38 passed, 0 failed (the title test now checks
every check by name; the staged tree was built and tested apart from
the working tree). Inside the wasm64 module (1.2 MB, Node 24) the same
run takes 4.4 s: 115 M instructions, most of them the 80 MiB upload check.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
vincentes added a commit to vincentes/xcl-wasm that referenced this pull request Nov 24, 2026
…nsole

- `xcl::hle::xg` (the console's texture layout: planes, mips, the GFX10
  tiling) now builds on every target: only its COM glue is Windows code.
  Its three unit tests run off Windows too.
- `win::xg`: `XGCreateTextureComputer` on the guest, answering from that
  model: the resource layout structure, size and alignment, mip and texel
  offsets, CopyIntoSubresource / CopyFromSubresource on title memory.
  GetResourceTiling (xcl-dev#10) is not there.
- The software D3D12.X device lays textures out the same way: a texture
  resource takes what the console's layout of it takes;
  CopyTextureRegion (whole subresources) untiles into a buffer's placed
  footprint, tiles from one, or copies between textures;
  GetCopyableFootprints places a texture's subresources as D3D12 does;
  PresentX untiles the back buffer into the frame's rows.

Measured on macOS (aarch64): the test title runs to its end, 43 of its 50
checks pass ("a texture in title memory (XG layout, xcl-dev#44) follows CPU
writes", "a texture in a streaming pool gets its texels once pages are
mapped in" and "committed textures … a readback buffer still gets
coherent memory" are new). The 7 that fail: 4 compile HLSL and render,
DirectStorage (in work by another agent), Media Foundation, XAudio2.
On the staged tree in a separate copy: `cargo test -p xcl --lib`: 136
passed; `cargo test -p xcl-guest`: 47 passed; `cargo +nightly check -p
xcl --target x86_64-pc-windows-gnu --all-targets`: no errors; the wasm64
smoke test (1.31 MB, Node 24): 43 pass, 7 fail, 5.4 s.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
theaustinayers pushed a commit that referenced this pull request Nov 24, 2026
…ites

`pc_resource_desc` takes ALLOW_UNORDERED_ACCESS from a depth buffer the
console also lets shaders write (the PC refuses ALLOW_DEPTH_STENCIL with
ALLOW_UNORDERED_ACCESS). Only CreatePlacedResourceX (#44) moved such a
resource's initial state off UNORDERED_ACCESS as well (to DEPTH_WRITE).
The other paths that create a resource of the converted description
only masked the state with PC_RESOURCE_STATES: the committed fallback of
CreateCommittedResource (#27 / #76 / #127, reached without unified
memory or when its coherent window is full), the PC-way retry and the
committed fallback of CreatePlacedResource (#29), and its memory-of-its-
own path for textures larger on the PC. A console texture with flags
DEPTH_STENCIL | UNORDERED_ACCESS created in UNORDERED_ACCESS was then
asked for in a state D3D12 refuses for a resource without the UAV flag
(E_INVALIDARG; the #29 own-memory path fell back to COMMON).

`device_x::pc_initial_state` does both steps; #44 uses it with no change
in behaviour, and the four other sites use it with the console flags
(or the PC description's, which keep ALLOW_DEPTH_STENCIL).

Tests: a unit test of the helper; a GPU test placing a 256x256 D16
depth+UAV texture in UNORDERED_ACCESS as XCL now does (not run here).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@grahamster2
grahamster2 deleted the fix/wave32-mask-prefix-count branch November 26, 2026 06:11
oni-swr added a commit to oni-swr/xcl that referenced this pull request Nov 26, 2026
A shared stand-in (`standin::shell`) is a Rust object, not a D3D12Core
pipeline. Device xcl-dev#34 MakeResident and xcl-dev#35 Evict keep the PC layout for
console code and had no override, so a stand-in pipeline in the title's
object array reached the driver as `*mut Shell`.

Both are overridden now. Microsoft's MakeResident / Evict support
residency changes on descriptor heaps, heaps, committed resources and
query heaps only; a pipeline state is ID3D12Pageable but not among them,
so the pipeline behind a stand-in is no valid entry either. Each shell
is left out of the array: the driver gets the other objects in order, in
a copy (the title's array is left as it is), and its HRESULT is returned
as it is. A call with stand-ins only returns S_OK without a driver call.
Arrays without a stand-in (empty, null, supported objects) go as they are.
Nothing builds or waits for a lazy pipeline.

The other entry points named in xcl-dev#2455 are not reachable by title code on
main: device xcl-dev#46 SetResidencyPriority and xcl-dev#51 EnqueueMakeResident are
console extensions there (a logged S_OK stub), xcl-dev#44 is the console's
CreatePlacedResourceX (no native pipeline library for StorePipeline),
and xcl-dev#12 CreateCommandList goes to `create_command_list_pc`, which
resolves the initial pipeline.

Fixes xcl-dev#2455

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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