shader: lower v_and_or_b32 and v_cvt_f16_f32 in the mesh frontend #3745

Manually merged
github merged 1 commit from github-bot/gh-3743 into main 2026-12-02 01:54:24 +00:00 AGit
Owner

@⁠lambirou on GitHub · 2026-12-01 14:03 UTC · original
lambirou:codex/mesh-vector-alu → main · +162 −1 · 3 files · 1 commits · merged 2026-12-02 01:50 UTC

After the scalar bit operations, the forced slot 86 mesh path still refused
v_cvt_f16_f32 in 357 requests and v_and_or_b32 in 331, ahead of the
control-flow, heap-provenance and pixel blocks.

v_and_or_b32 (VOP3 0x371) joins the mesh vector list that already handles
v_or3_b32 and v_add3_u32, so it takes the three-source
alu_rules entry and lowers to (S0 & S1) | S2. The shared operand gate
still refuses abs, neg, clamp and omod. v_cvt_f16_f32 (VOP1 0x0A) joins
the same list and reuses the compute frontend's integer round-to-nearest-even
narrowing: the sign comes from bit 31, binary32 subnormals become signed
zeros, binary16 subnormals are kept, overflow including the 65520 tie gives
0x7c00, and a NaN keeps its quiet bit. The encoding goes into the low half
and the reaching destination value keeps the high half, so an unproven
destination still refuses and the merged word is not declared uniform.

Validation (Windows, Release; AMD Radeon RX 9060 XT for the hardware run):

  • cmake --build --preset release --target compile_dxil — 7/7 steps.
  • python -B tests/native_direct_mesh_check.py out\\build\\release\\compile_dxil.exe "<DXC dir>"
    — pass, including the v_and_or_b32 and v_cvt_f16_f32 programs and the
    unbound/unproven-source controls.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 pass.

Refs #3705

**@⁠lambirou** on GitHub · 2026-12-01 14:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3743) `lambirou:codex/mesh-vector-alu` → `main` · +162 −1 · 3 files · 1 commits · merged 2026-12-02 01:50 UTC After the scalar bit operations, the forced slot 86 mesh path still refused `v_cvt_f16_f32` in 357 requests and `v_and_or_b32` in 331, ahead of the control-flow, heap-provenance and pixel blocks. `v_and_or_b32` (VOP3 0x371) joins the mesh vector list that already handles `v_or3_b32` and `v_add3_u32`, so it takes the three-source `alu_rules` entry and lowers to `(S0 & S1) | S2`. The shared operand gate still refuses abs, neg, clamp and omod. `v_cvt_f16_f32` (VOP1 0x0A) joins the same list and reuses the compute frontend's integer round-to-nearest-even narrowing: the sign comes from bit 31, binary32 subnormals become signed zeros, binary16 subnormals are kept, overflow including the 65520 tie gives `0x7c00`, and a NaN keeps its quiet bit. The encoding goes into the low half and the reaching destination value keeps the high half, so an unproven destination still refuses and the merged word is not declared uniform. Validation (Windows, Release; AMD Radeon RX 9060 XT for the hardware run): - `cmake --build --preset release --target compile_dxil` — 7/7 steps. - `python -B tests/native_direct_mesh_check.py out\\build\\release\\compile_dxil.exe "<DXC dir>"` — pass, including the `v_and_or_b32` and `v_cvt_f16_f32` programs and the unbound/unproven-source controls. - `ctest --preset release --no-tests=error -R '^native_direct'` — 2/2 pass. Refs #3705
The title calls xmem.dll through a C ABI and does not catch C++ exceptions.
A failed allocation while recording a backing, a slab, the GPU mirror
vectors or a mapping batch unwound 0xe06d7363 into the title, ending the
run after 478 s.

Report the failure instead. section_for and SlabSlots::take_fresh return
false with ERROR_NOT_ENOUGH_MEMORY, the GPU mirror stays best-effort and
logs the skipped batch, and XMemMapPhysicalPages, its scatter form and
XMemFreePhysicalPages convert std::exception into a failed call. The
test-controls build injects the failure at both allocation sites; the new
xmem_mapped_pages_allocation test checks the error and the control mapping.
Removing the boundary catch makes the same test terminate with 0xe06d7363.

Tests: ctest --test-dir out/build/release -R '^xmem': 73 tests, 0 failed
(3 placeholder skips). Long runs on main: 29 fps, 1 446 textures, 341
.s57 mesh captures, past the previous 478 s crash point; the remaining
mesh refusal is the missing reviewed .mesh57-state profile, not an XMem
allocation.
Slot 57 and slot 86 mesh pipeline creations wrote each new key's request
parts (a probe, a temporary file and a rename each) under one lock before
they answered. A title that creates thousands of mesh pipelines then
waits on that file work one creation at a time.

Creations now copy the parts into a bounded queue and return; one thread
writes them in order (request_publisher.h). A key is queued once per
process and at most 64 MiB wait. X2W_SYNC_MESH_REQUESTS=1 restores the
inline writes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unload drain writes with its own writer (a temporary name of its
own, a rename, no cache index) from a directory read when the publisher
is made, and only once the writer thread has ended; while it still runs
the drain waits for it. Nothing is made at unload when no request was
queued. stop() ends and joins the thread (the destructor calls it), and
a request that could not be written forgets its key so it is accepted
again. The check covers the retry, the unload writer, a drain while the
thread runs and stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Another MSVC version resolves std::begin({...}) to the array overload and
rejects it (C2664), which failed the Windows build on CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
enqueue recorded the key before pushing the request. If the push threw, the key
stayed recorded, so a retry of the same key was counted as repeated and never
written. The catch now erases the key under the same lock.

The publisher test fails each allocation of an enqueue in turn and checks that
the drop is counted and that a retry of the same key is queued and written.
Without the rollback that case fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The request fixture enumerated the shader cache right after its dispatches.
With the background publisher a request can still be in flight then, so the
exact count of two requests and six files failed intermittently
(startup_mesh57_runtime_warp). It now waits, for at most 10 s, until both
.m57 ready markers exist and no part is still under its temporary name, then
runs the same byte and count checks. The async default is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adopt the existing committed desktop backing for a placed material view, refresh it from title memory at submit, and copy only changed runs. Keep the existing backing and its fences; a submitted GPU write stops refreshes. Add a source-built two-SRV fixture with range, token, stale, budget and mutant controls.

Refs #3640, #3638, #3545.
The mesh frontend narrowed EXEC only for v_cmpx_eq_u32, ne_u32 and lt_u32,
and for v_cmpx_gt_u32 only in the lane-linear count form. Mesh86 programs
also use v_cmpx_lg_f32, v_cmpx_gt_f32 and a per-lane v_cmpx_gt_u32.

They now get the same EXEC-only narrowing through the shared compare: lg is
an ordered fcmp one and gt_f32 an ordered ogt, so a NaN lane leaves EXEC,
and gt_u32 is icmp ugt. The count form of v_cmpx_gt_u32 is still matched
first. Float abs/neg, SDWA, DPP, clamp and omod stay refused.

Part of #3703.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console builder fills 32-byte records through the pointer command-list slot 148
returns and does not check it. A recording's first request creates a desktop upload page;
when CreateCommittedResource returned E_OUTOFMEMORY under memory pressure, the arena
returned an empty allocation and the builder's first store faulted at address 0.

A request that no page can back is now served from a bounded, process-wide CPU reserve:
the store lands in zeroed writable memory, the slice carries no desktop address, range and
translate keep refusing it, and slot 148 logs which case it took. The reserve is created
while an upload page still succeeds, so it cannot hide an out-of-memory run.

Refs #870
# Conflicts:
#	CMakePresets.json
Refs #3497

Refs #3724
The forced slot 86 mesh path refused 2 873 real title requests. The census
ordered the refusals s_bfe_i32 (458), s_not_b32 (433), v_rcp_iflag_f32 (145)
and s_brev_b32 (107).

- s_not_b32 (SOP1 0x07) and s_bfe_i32 (SOP2 0x28) join the mesh scalar
  branches and reuse the compute arithmetic(): D = ~S0, and the sign-extended
  field with the offset in S1[4:0] and the width in S1[22:16], zero for a zero
  width and the arithmetic shift kept at a width of 32 or more. Both write
  SCC = (D != 0).
- s_brev_b32 (SOP1 0x0B) lowers through the shared unary.i32 reverse and leaves
  SCC unchanged, as the compute frontend and the gfx2hlsl.py SOP1 table do.
- v_rcp_iflag_f32 (VOP1 0x2B) joins the vector list that already handles
  v_rcp_f32, so it takes the same 1.0 / x alu_rules entry.
- All three scalar forms refuse an EXEC or VCC destination.

tests/native_direct_mesh_check.py adds one source-built program per form that
exports the result through POS0.x and, for s_not_b32 and s_bfe_i32, the SCC
through POS0.y; s_brev_b32 is bracketed by a compare in both SCC states to show
the flag survives. Controls reject EXEC/VCC destinations and unbound sources.

Verified:
- cmake --preset release; cmake --build --preset release --target compile_dxil
  (17/17 steps, compile_dxil.exe linked)
- python -B tests/native_direct_mesh_check.py <compile_dxil.exe> <dxc dir>:
  exit 0, "mesh allocation, indexed outputs, group exchange and negative
  controls passed"
- ctest --preset release --no-tests=error -R '^native_direct'
  2/2 passed: native_direct_container 15.04 s, native_direct_mesh 11.75 s

Refs #3703
After the scalar bit operations, the forced slot 86 mesh path refused
v_cvt_f16_f32 in 357 requests and v_and_or_b32 in 331, ahead of the
control-flow, heap-provenance and pixel blocks.

- v_and_or_b32 (VOP3 0x371) joins the mesh vector list that already handles
  v_or3_b32 and v_add3_u32, so it takes the three-source alu_rules entry and
  lowers to (S0 & S1) | S2. The shared operand gate still refuses abs, neg,
  clamp and omod.
- v_cvt_f16_f32 (VOP1 0x0A) joins the same list and reuses the compute
  frontend's integer round-to-nearest-even narrowing: the sign comes from bit
  31, binary32 subnormals become signed zeros, binary16 subnormals are kept,
  overflow including the 65520 tie gives 0x7c00, and a NaN keeps its quiet bit.
  The encoding goes into the low half and the reaching destination value keeps
  the high half, as the compute frontend does, so an unproven destination still
  refuses and the merged word is not treated as uniform.

tests/native_direct_mesh_check.py adds source-built programs with the run
helper: v_and_or_b32 with s20 = 0x0000ffff and s21 = 0x00ff0000 exports
(and v0, 65535) | 0x00ff0000, and v_cvt_f16_f32 exports the narrowed word for
1.0f, 0.0f and -2.0f. Controls reject an unbound third source and an unproven
conversion source or destination.

Observed IR:
- %t8 = and i32 %v0, 65535 ; %t9 = or i32 %t8, 16711680
- v_cvt_f16_f32: lshr <bits>, 16 / and ... 32768 for the sign,
  and <bits>, 2147483647, lshr ... 23, and ... 8388607, the nearest-even
  narrowing with icmp ugt %exp, 142 -> 31744 and icmp ugt %mag, 2139095040 ->
  32256 | quiet bits, then or %narrow, %sign, and %destination, -65536 and the
  final or.

Verified:
- cmake --build --preset release --target compile_dxil (7/7 steps,
  compile_dxil.exe linked)
- python -B tests/native_direct_mesh_check.py <compile_dxil.exe> <dxc dir>:
  exit 0, "mesh allocation, indexed outputs, group exchange and negative
  controls passed"
- ctest --preset release --no-tests=error -R '^native_direct'
  2/2 passed: native_direct_container 15.04 s, native_direct_mesh 13.78 s
- python -B tests/docs_links_check.py: 210 files, 807 links

Refs #3703
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:06:43 +00:00
github-bot force-pushed github-bot/gh-3743 from 5cd059ee10 to 8bb4b063d1 2026-12-01 14:36:39 +00:00 Compare
github-bot force-pushed github-bot/gh-3743 from 8bb4b063d1 to baa40780b1 2026-12-01 14:42:40 +00:00 Compare
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 20:13 UTC · original · approved these changes

Reviewed baa40780 by reading the diff; not built or run.

Verdict: approve. Both ops join the mesh VALU list and lower through the shared ALU, with uniformity handled correctly. No MUST.

  • Overlap with #3668. #3668 (Kawiu, open) also adds v_cvt_f16_f32 to this list. It goes through the same shared narrowing (gfx1013_direct_compute.inl:2102), so the behaviour is identical and only the list entry is duplicated. Whichever lands second can drop its entry on rebase. v_and_or_b32 here, and v_cvt_f32_f16 plus the two CMPX forms in #3668, are not duplicated. For context: on main + #3762, six slot 86 programs from our own capture now stop first at v_cvt_f16_f32, so either PR clears that wall for them.
  • Rebase. The branch is on e1161e43, and only tests/native_direct_mesh_check.py conflicts with main 158ef794, where both sides appended cases. The source hunk merges cleanly.
  • Checked, no finding:
    • Source counts. v_and_or_b32 has an alu_rules entry of arity 3, so a result is uniform only when all three sources are. v_cvt_f16_f32 has no rule and is not in the hard-coded arity lists, so sources is 0 and the merged word is never declared uniform. That matches the new comment, since the high half comes from the destination.
    • Modifiers. Abs, neg, clamp and omod still go through the shared operand gate, so they refuse as before.

Tests:

  • v-and-or-b32 traces (S0 & S1) | S2 to the export, and -unproven refuses an unbound source.
  • The v_cvt_f16_f32 cases match the NaN/infinity select chain of the narrowing and export the low half.
  • -unproven-source and -unproven-destination pin both refusals. The second covers the kept high half.

CI ran native_direct_mesh (pr preset filter) green at this head, on the old base.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 20:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3743#pullrequestreview-6139258103) · **approved these changes** Reviewed `baa40780` by reading the diff; not built or run. **Verdict: approve.** Both ops join the mesh VALU list and lower through the shared ALU, with uniformity handled correctly. No MUST. - **Overlap with #3668.** #3668 (Kawiu, open) also adds `v_cvt_f16_f32` to this list. It goes through the same shared narrowing (`gfx1013_direct_compute.inl:2102`), so the behaviour is identical and only the list entry is duplicated. Whichever lands second can drop its entry on rebase. `v_and_or_b32` here, and `v_cvt_f32_f16` plus the two CMPX forms in #3668, are not duplicated. For context: on `main` + #3762, six slot 86 programs from our own capture now stop first at `v_cvt_f16_f32`, so either PR clears that wall for them. - **Rebase.** The branch is on `e1161e43`, and only `tests/native_direct_mesh_check.py` conflicts with `main` `158ef794`, where both sides appended cases. The source hunk merges cleanly. - Checked, no finding: - **Source counts.** `v_and_or_b32` has an `alu_rules` entry of arity 3, so a result is uniform only when all three sources are. `v_cvt_f16_f32` has no rule and is not in the hard-coded arity lists, so `sources` is 0 and the merged word is never declared uniform. That matches the new comment, since the high half comes from the destination. - **Modifiers.** Abs, neg, clamp and omod still go through the shared operand gate, so they refuse as before. Tests: - `v-and-or-b32` traces `(S0 & S1) | S2` to the export, and `-unproven` refuses an unbound source. - The `v_cvt_f16_f32` cases match the NaN/infinity select chain of the narrowing and export the low half. - `-unproven-source` and `-unproven-destination` pin both refusals. The second covers the kept high half. CI ran `native_direct_mesh` (pr preset filter) green at this head, on the old base.
github-bot force-pushed github-bot/gh-3743 from baa40780b1 to 816ab82107 2026-12-01 23:07:15 +00:00 Compare
Author
Owner

@⁠lambirou on GitHub · 2026-12-01 23:02 UTC · original

Rebased onto origin/main 158ef794 after #3764, resolving the native_direct_mesh_check.py helper conflict by keeping both assert_export_column and the _sop2/_sopc/_sop1_literal helpers.

Head 816ab821. Validation:

  • cmake --build --preset release --target compile_dxil — 17/17.
  • python -B tests/native_direct_mesh_check.py ... — pass.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 passed.

AI-assisted.

**@⁠lambirou** on GitHub · 2026-12-01 23:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3743#issuecomment-7328710519) Rebased onto `origin/main` `158ef794` after #3764, resolving the `native_direct_mesh_check.py` helper conflict by keeping both `assert_export_column` and the `_sop2`/`_sopc`/`_sop1_literal` helpers. Head `816ab821`. Validation: - `cmake --build --preset release --target compile_dxil` — 17/17. - `python -B tests/native_direct_mesh_check.py ...` — pass. - `ctest --preset release --no-tests=error -R '^native_direct'` — 2/2 passed. AI-assisted.
github manually merged commit 6dade96dfe into main 2026-12-02 01:54:24 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.