Commit Graph

5 Commits

Author SHA1 Message Date
cd5ee11079 rdna2spirv(r9b): unconditional CS/MS LDS bounds, PS EarlyFragmentTests, mesh epilogue & PS quad swizzle
Round 9b translator fixes for rendering correctness and Mandy d3d12/ parity:

1. Unconditional CS & MS LDS OOB bounds (Mandy 21633b328 parity):
   - Record g.lds_declared from PSV0.shared for MS and RSRC2.LDS_SIZE for CS.
   - Whenever g.lds_declared > 0 (opt-out --no-lds-bounds), set
     g.lds_dwords = g.lds_bound = min(g.lds_declared, 16384) so every LDS
     read, write, sub-dword, wide, and atomic op goes through lds_access()
     (OOB reads return 0, OOB writes/atomics dropped instead of wrapping).

2. PS DB_SHADER_CONTROL bit 12 EarlyFragmentTests (Mandy f33940415/bf479a3cd):
   - Add fssm_header.db_shader_control() reading u32 at E + 0x138 (0x24C for
     rec = 0xB0; 3,023/12,101 corpus PS have bit 12 DEPTH_BEFORE_SHADER set).
   - Emit OpExecutionMode %main EarlyFragmentTests (opt-out --no-early-depth)
     and record early_depth in shader_meta when bit 12 is set and the PS does
     not export depth/stencil (no exp mrtz, DB_SHADER_CONTROL & 0x7 == 0, no
     OSG1 SV_Depth*/SV_StencilRef).

3. Defensive mesh epilogue & PS helper-lane quad swizzle:
   - MeshEXT and --mesh-compute epilogues explicitly write CullPrimitiveEXT =
     true (1) and (0, 0, 0) when %mli < %msp and !%ms_has_prim.
   - Lower quad-local ds_swizzle_b32 in PS via OpGroupNonUniformQuadBroadcast /
     OpGroupNonUniformQuadSwap (GroupNonUniformQuad capability) so Vulkan 2x2
     helper invocations participate on AMD RADV while EXEC-masked lanes still
     read 0.

Verified: compileall, check_no_game_data.py, 6,674/6,674 semantic tests (0
failures), 200/200 corpus slice (200/200 spirv-val), plus targeted LDS MS
(5/5), LDS CS (60/60), early-depth PS (120/120), and PS quad-swizzle (50/50)
corpus slices (100% spirv-val). AI-assisted.
2026-11-29 09:25:40 -05:00
9d731bc11e Merge origin/main into shader-309-wave64-lds-limit
Conflict in tools/rdna2spirv.py: both sides added a module function
before cs_dispatch_state (ds_const_extent, check_printed_encodings);
both kept. main's new ds_mskor path now goes through lds_access, so it
is bounds-checked like the other LDS accesses (test added), and the
mock Gen in main's new test_lds_atomic_minmax/xchg tests gains
lds_bound/lds_access/lds_atomic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:59:04 +01:00
ce7a34850e SHADER-309: bounds-check LDS past the RSRC2 allocation
RDNA2 LDS does not wrap: an access outside the allocation reads 0 and
its write is dropped (ISA 3.6.1, 3.6.6). The wrapped array aliased such
an access onto a valid word (review on #1882). When a program's
constant offsets reach past its RSRC2 allocation, or the array is shrunk
to fit the cap, the array is now the allocation and Gen.lds_access
checks every dword of every LDS access kind (reads, writes, sub-dword,
read2/write2, atomics, cmpst, wrxchg): out of range a read or an
atomic's old value is 0 and the write is skipped. Other shaders keep
the wrapped power-of-two array with no check. The constant-offset need
is now exact (offset + access width) instead of offset + 4 dwords.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:01:45 +01:00
759a90c42e SHADER-309: refuse an RSRC2 LDS allocation over the cap
translate() clips the LDS array to 16,384 dwords, so a native compute
shader whose RSRC2 LDS_SIZE allocates more than 64 KiB passed the cap
check with a cut array (review on #1882). The check now counts the LDS
at max(array, RSRC2 allocation) and refuses it. A need that comes only
from a constant ds offset keeps the clipped array: the +4-dword slack
makes an in-range b32 at offset 65,524 compute as 65,540 B, and a real
offset past 64 KiB is out of range on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:18:23 +01:00
4de870250e SHADER-309: keep compute workgroup memory under the limit
--wave64-emulate adds %x_buf (2L + 6W + 7 dwords) on top of the LDS
array, so a 64 KiB LDS made modules over maxComputeSharedMemorySize,
which spirv-val accepts and RADV dies on (#1721).

Translator: a 64 KiB hard cap (MAX_SHARED_BYTES, --max-shared-memory).
Over it, the pow2-rounded LDS array shrinks to the room left when the
program's need fits (indices wrap with OpUMod); otherwise the shader is
refused (Unsupported, with the byte counts). lds_bytes in index.json is
now the whole Workgroup total.

Runtime: the D3D12 shim's create_compute compares lds_bytes with the
device's maxComputeSharedMemorySize (32768 on AMD Windows and Intel)
and refuses the pipeline with a log line instead of creating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:49:23 +01:00