In RDNA2 shaders, constant calculations and scalar descriptor bounds checking
occur frequently across compute and graphics stages.
- Fold constant scalar ALU operations (s_and_b32, s_or_b32, s_xor_b32, s_not_b32,
s_lshl_b32, s_lshr_b32, s_mul_i32) into immediate constants and constant SCC
writes at translate time, eliminating runtime OpBitwise*, OpShift*, OpNot, and OpIMul.
- In s_buffer_load (SMEM), evaluate limit = NUM_RECORDS * stride at compile time
when descriptor words 1 and 2 are known in sgpr_imm, eliminating 6 runtime SPIR-V
instructions (OpBitFieldUExtract, OpUConvert, OpIMul, OpIEqual, OpSelect).
- When offset and limit are constants, fold per-dword bounds statically: in-range
dwords emit straight-line OpAccessChain and OpLoad without branch diamonds
(OpSelectionMerge, OpBranchConditional, OpPhi), and out-of-range dwords emit
constant zero without issuing memory loads.
- When scalar load offset is passed via an SGPR with known literal, fold into
immediate constant without runtime OpBitwiseAnd, OpUConvert, and OpIAdd.
- Updated docs/design.md with static bounds folding behavior.
- Added tests in tests/semantic/test_scalar_alu_and_smem_folding.py covering all cases.
Clamping only the last page's granule made it smaller than the previous
page's when the trim target fell before that page started: a 27-packet
real-libopus fixture declared 24,000 frames but decoded 24,960, and the
Ogg granule went 24,960 -> 24,000. Emit the EOS page at the first packet
that reaches pre_skip + length and drop the remaining padding packets.
Also require +0x0C to agree with the interleaved +0 count before using
it, and clamp an oversized pre-skip to the stream length so the final
granule never falls below it.
Measured on real streams: with pre-skip 0, the 5%/10% attack point is
312 samples (30 streams from four banks, median 312; the 10% point ranges
278..868, none near 1920), so the default is measured, not just assumed
from libopus. 20 real streams at 48 and 32 kHz now decode to exactly
their declared counts.
In RDNA2 shaders, constant calculations and scalar descriptor bounds checking
occur frequently across compute and graphics stages.
- Fold constant scalar ALU operations (s_and_b32, s_or_b32, s_xor_b32, s_not_b32,
s_lshl_b32, s_lshr_b32, s_mul_i32) into immediate constants and constant SCC
writes at translate time, eliminating runtime OpBitwise*, OpShift*, OpNot, and OpIMul.
- In s_buffer_load (SMEM), evaluate limit = NUM_RECORDS * stride at compile time
when descriptor words 1 and 2 are known in sgpr_imm, eliminating 6 runtime SPIR-V
instructions (OpBitFieldUExtract, OpUConvert, OpIMul, OpIEqual, OpSelect).
- When offset and limit are constants, fold per-dword bounds statically: in-range
dwords emit straight-line OpAccessChain and OpLoad without branch diamonds
(OpSelectionMerge, OpBranchConditional, OpPhi), and out-of-range dwords emit
constant zero without issuing memory loads.
- When scalar load offset is passed via an SGPR with known literal, fold into
immediate constant without runtime OpBitwiseAnd, OpUConvert, and OpIAdd.
- Updated docs/design.md with static bounds folding behavior.
- Added tests in tests/semantic/test_scalar_alu_and_smem_folding.py covering all cases.
#1283 reduced the angle in turns with Fract. For a negative argument Fract is
1 - |x|, which rounds in binary32: sin(-2**-26 turns) became +0 and the
absolute error was up to ~1.7e-7 at -0.1 turns. x - RoundEven(x) is exact in
binary32 for every finite x and keeps the angle in [-pi, pi]. The change is
inside turn_angle (shared by the f32 and f16 forms), with the variable names
of the line that test_mutations.py anchors on kept.
- tests/semantic/test_alu_sincos.py: f32/f16 against sin/cos(2*pi*x) in
double, tiny arguments (fails on main), whole turns of either sign (+0, as
measured on an RX 6800 by shelbykb2), +-0, inf/NaN, modifiers.
- runtime/test/shaders/cs_w32_sincos.asm: wave32 GPU regression guard
(tolerance 1e-3, the driver Sin is only good to 2^-11), registered in
check.py and run_gpu_tests.py.
- docs/design.md: contract row with the RX 6800 measurement and what is not
matched (half/quarter turns, the small-x constant, inf/NaN words).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Raw kernels through the hardware oracle on a gfx1036 iGPU (AMD Windows driver
32.0.21044.64, HIP backend), 1,385 programs in wave32 and wave64, identical
words in both:
- an omod on an f16 result (v_add/mul/fma/fmac/cvt/exp/rcp_f16) acts only with
IEEE 0 and denorm_mode_16_64 = 0; omod comes before clamp; clamp gives +0
for -0 and, with DX10_CLAMP 1, for a NaN;
- v_fma_mix* operands: a float inline constant is f32 or the f16 constant
(zero high half) by op_sel_hi, an integer constant its 32-bit integer;
denormals follow the mode of their own width; NaN payloads are kept;
- v_fma_mixlo/mixhi_f16 round once (fma_mix_probe --oracle hw, 7 of 7 ties);
- v_exp_f16 / v_log_f16 repeat gfx1031's sweep counts exactly.
The translator is compared word for word and differs in five ways, listed
in docs/shader_validation.md; none is fixed here. Docs only. AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From @Rainmaker33's review of #1653: VK_LOADER_LAYERS_DISABLE didn't
remove RTSS on their machine because the terminal was elevated, and the
loader ignores that variable with administrator rights (VK_LOADER_DEBUG=all
says so); a layer's own disable_environment switch still works there. The
STORAGE message also needs RivaTuner Statistics Server itself running.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
x_memory_order cut a round at buffer/image accesses that conflict within a
segment, but left s_load/s_buffer_load out, so a buffer_store and a later
scalar load of the same address shared a segment and the half of the
emulated wave in the other subgroup could load before this half stored.
valu_fuzz --family mem --emulate showed it as lanes 32-63 reading the fill
pattern. A scalar load now counts as a buffer read (RAW and WAR start a new
round); loads alone still share one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Expose SDL3's gyroscope and accelerometer through the GameInput shim:
- gameinput_abi.h: GameInputMotionAccuracy, GameInputMotionInfo and
GameInputMotionState with the v0 layouts (Microsoft's public docs),
size asserts included.
- The shim enables both sensors when a pad with them is opened, reads
the latest sample each poll, and reports GameInputKindMotion plus a
GameInputMotionInfo on such pads. GetMotionState returns the state as
signed fractions of the motionInfo maxima (2 g accel, 2000 deg/s
gyro, the shim's choice since SDL exposes no sensor range; VERIFY).
All-zero accel means no sample yet, so readings before the device's
first sample carry no motion. Magnetic field and orientation stay
zero and Unknown: SDL has no compass and nothing synthesises a
quaternion. Pads with sensors stream a reading every ~8 ms so motion
is not stuck at the last button event; other pads keep the old
change-driven behaviour.
- GetCurrentReading and GetNextReading with a device filter now reject
kinds the device does not support (READING_NOT_FOUND), matching the
v0 docs and the device-less path, so a motion query on a plain pad
fails instead of returning a reading without motion.
- gameinput_test: a virtual pad with SDL sensors covers kind/motionInfo
presence, no-motion-before-first-sample, normalisation, accuracy
values, the +-1 clamp, the cadence, and the plain-pad rejection.
gameinput_probe prints the live accel and gyro fractions.
- docs/gameinput.md: a Motion section, the API table, and VERIFY notes
for the chosen maxima and the unprovided members.
Tested: gameinput_test 185/185 and ctest 90/90 (RelWithDebInfo) on
Windows 11 Pro 10.0.26200; SDL3 3.4.20 via -DLEONIDA_SDL3_FETCH=ON.
Follows: #660. AI-assisted (ZCode agent).
Swap VGPR[D + M0[25:16]] and VGPR[S0 + M0[9:0]] (GFX10 VOP1 104), the
fields v_movrelsd_2_b32 uses: both read before either is written,
inactive lanes keep both, a self-swap keeps the register. The range check
against the VGPR allocation is not modelled, as for v_movrel*.
tests/semantic/test_alu_swaprel.py covers the fields, ignored M0 bits and
a self-swap. docs/design.md row added.
A lane-mask SGPR (a saved EXEC, a v_cmp result) holds only this lane's bit in
the translation, so the dynamic load in s_movrels_b32/b64 copied that bit as
data: with EXEC saved as 5, s_movrels then s_bcnt1 gave 32 where the ISA
gives 2. For every SGPR lane_masks.py marks as a mask at the instruction, the
whole wave's mask word is collected (wave_mask, as for s_bcnt1) and selected
when the index lands on it. D then holds the mask as data, which is what
lane_masks.py already assumes for an s_movrels destination.
tests/semantic/test_salu_movrels_lane_mask.py runs the finding's listing and
two more (M0 hitting a mask between data words; the b64 pair of a saved EXEC
in wave64) on every lane of a workgroup.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vk_sync_validation_selftest records two vkCmdCopyBuffer into the same
bytes on vk_test_device.h's device. With LEONIDA_VK_VALIDATION=1 the
write-after-write hazard must be reported, and the same copies with a
transfer -> transfer barrier must not be. Without validation, or without
a Vulkan device, it exits 77 (ctest skip).
Synchronization validation can be off although the tests ask for it,
for example with VK_KHRONOS_VALIDATION_VALIDATE_SYNC=false, and every
other GPU test then reports 0 validation errors without having been
checked. This test fails in that case, and with the Khronos layer
missing. docs/testing.md gets a row in its known problems.
No runtime code changes, no game files. AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to #1570, which took the `neg` half of SHADER-260 and left `abs`
refused. `abs` is the ISA's absolute value of the operand: a clear of the
sign bit, on the 16-bit half the operand contributes and applied before
`neg` (which #1570 emits as a bit 15 flip). The instruction already moved
each half unchanged, so the translator emitted nothing for `abs` and threw
`Unsupported("v_pack_b32_f16 abs modifier")` for any shader that used it.
Emit the clear instead: OpBitwiseAnd 0x7FFF on the selected half, before
the `neg` xor. No hardware run of this instruction with `abs` exists, so
the docs row says the rule is ISA-derived and unmeasured rather than
quoting a measurement.
Tests: exact-bit CPU cases in tests/semantic/test_pack_b32_f16_mods.py and
tests/test_values.py (both halves, op_sel, an sNaN payload, neg+abs order),
the interpreter-run GPU fixture ps_f16_pack_mods with its words derived
from the rule, and the row in docs/design.md.
SHADER-260, Depends on: #1570
Reflect actual binary user-defined inputs and outputs. Audit stage pairs and chains by location, component, type, and per-primitive domain. Handle arrays used for invocation indexing and explicit maintenance4 matching. Add batch reports, inspection, and standard-library regression tests.
Tested on Linux with synthetic modules and Mesa llvmpipe. VS+PS and VS+GS+PS fixtures draw 4096 expected pixels each. Vulkan validation and the auditor agree on the missing Location 5, Component 2 of a negative case. Mesh+PS fixtures pass spirv-val and the interface check. AI-assisted.
A bitwise op works on each bit alone, so one 32-bit LDS atomic per dword
leaves the memory a 64-bit atomic would, without Int64 atomics on
Workgroup memory (optional in Vulkan). The _rtn_ pair is two reads and
can be torn by a concurrent 64-bit op on the same element; the memory
result is exact. The carrying 64-bit LDS atomics stay Unsupported.
tests/semantic/test_lds_bitwise_b64.py runs all six forms in the
interpreter (offsets, vdst aliasing the data, seeded values).
docs/design.md row added.
Since #1489 the layer binds the device's bindless set at every dispatch as well as at every draw, but only the
draw has a test (d3d12_m2_textured_test): d3d12_compute_test takes the binding-free index entry on purpose, and
d3d12_descriptor_test samples through set 0 with a Vulkan pipeline of its own.
This test covers the compute bind point through D3D12 alone: a compute PSO whose index entry lists set-0
bindings, two SRVs, bytes no view was made for, and a wrapping and a clamping sampler. Four dispatches of
test/glsl/cs_set0_sample.comp (GLSL written to the translator's contract) load the T# and the S# from the
descriptor tables, find them in the hash table and sample: the two textures texel for texel, the fallback image
for the unknown bytes, and the right edge with the clamping sampler. A device without the bindless set refuses
the PSO. Registered with ctest like its neighbours (exit 77 is a skip).
With the vkCmdBindDescriptorSets call of the compute bind point removed from replay, this test fails
(VUID-vkCmdDispatch-None-08600, on llvmpipe).
Checked with a mingw-w64 build under Wine on llvmpipe, an RDNA2 integrated GPU and an RX 7900 XTX (RADV), with
the validation layer: exact, no validation errors. Not built with MSVC.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both rows still said "Not GPU-verified", so their D and SCC columns were
readings of the ISA pseudocode with no silicon behind them. Each instruction
was run as a raw wave32 kernel on an RX 7900 XTX (gfx1100) and the measured
words, including the quad numbering that decides which D bits a quadmask
sets and the "SCC = D != 0 over both dwords" rule of the bitwise ops, are
now in the row.
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
AMD's Windows shader compiler for RDNA2 crashes (access violation in
vkCreateComputePipelines) on many --wave64-emulate compute shaders with LDS
(#857). auto turns emulation on when any device is 32-wide, so an Intel iGPU
next to an RX 6000 card gets emulated modules, and the runtime then runs them on
the RX 6000.
tools/vk_subgroup_info.py now reports vendor_id, device_id, driver_id and
rdna2_amd_windows for the runtime's GPU (RDNA2 by PCI device ID, AMD proprietary
driver). auto leaves emulation off when that GPU is one and runs wave64
natively; on and off are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/f32_fuzz.py gains v_rcp_iflag_f32, sharing v_rcp_f32's model (bit-identical on gfx1030 per design.md);
clamp and omod are what is new. On the integrated GPU of a Ryzen 7 9800X3D (gfx1036, AMD driver 32.0.13036.4,
Windows HIP launcher), seeds 1 to 6:
- full sweep on main 41f44826: 38,858 programs, 28,671 match, 0 mismatch, 56 known deviation, the same in
every column as the Linux libdrm run on gfx1036; the negative control catches all six wrong models.
- --ops v_rcp_iflag_f32: 6,552 programs, 5,971 match, 0 mismatch, 35 omod_neg_zero deviations.
design.md's output-modifier row no longer says RDNA2 is unmeasured; shader_validation.md records both runs.
Tested: tests/test_f32_fuzz.py, f32_fuzz --self-test, tests/semantic (1,338 tests), compileall. AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>