Commit Graph
147 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 16a5046124 SoftGPU: Read bilinear CLUT and 8888 texels in vector lanes
The four-pixel bilinear sampler read its sixteen texels one at a time,
each with its CLUT lookup and index transform, and loaded them as
vectors afterwards. For CLUT4 and CLUT8 with a 32-bit palette and no
index shift (by far the most common), and for 8888, the texels are now
gathered in lanes: the index bytes, the nibble, the mask and start, then
the palette entries. CrossSIMD gets Vec4S32::Gather and GatherU8 for it,
one load per lane. LocoRoco executes 5.5% fewer instructions, Burnout 3%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 15:01:49 +02:00
Henrik RydgårdandClaude Opus 5.5 f02936575d SoftGPU: Multiply small lane values with 16-bit multiplies
SSE2 has no 32-bit lane multiply, so Vec4S32::Mul is emulated with two
pmuludq and shuffles, and the bilinear sampler spent a tenth of its time
there. The texel row offsets, the texture functions, fog and blending
only multiply values that fit 16 bits, which Mul16 does in one pmaddwd.
The bilinear lerp of two channels packed as 16-bit halves uses the new
MulHalves (pmullw), which multiplies both at once.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 13:44:48 +02:00
Henrik RydgårdandClaude Opus 5.5 ce47944216 SoftGPU: Gather a span's UV plane values in registers
GEUVSpan stored the four 64-bit plane values, and the reciprocal table's
entries, to arrays one by one and loaded them as vectors, a store
forwarding stall each time, which took most of its time on x86.
CrossSIMD gets LoadS64Low (the low halves of four 64-bit values) and
LoadPairs (four pairs of 32-bit values split into two vectors) to do it
without memory. Wipeout runs about 2% faster.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 13:44:48 +02:00
Henrik RydgårdandClaude Opus 5.5 1752a2e53b SoftGPU: Transform a vertex's screen position in vector lanes, without stalls
ReadVertex took the GE's viewport arithmetic one coordinate at a time,
with a reciprocal of w for each, and stored the position, the UVs and
the whole vertex in pieces that were then reloaded with wider loads,
each a store forwarding stall. x, y and z now go through one GERecip and
the four-lane multiply and add (the scalar path stays for non-finite
input and zero or denormal w), the position is loaded as a vector, and
the vertex is written straight into its destination.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 13:44:48 +02:00
Henrik RydgårdandClaude Opus 5.5 d9b36b7e46 CrossSIMD: Keep the C++ fallback's integer ops defined, like the SIMD ones
The fallback (which RISC-V uses) did its integer arithmetic in plain int,
where signed overflow and left shifts of negative values are undefined,
and converted out of range floats with a cast, which is undefined too:
RISC-V gives INT_MAX for NaN where SSE gives INT_MIN and NEON 0. With GCC
on RISC-V that broke GEUVSpanCore in the GEMath unit test. Now the
arithmetic wraps through uint32_t, like the SIMD instructions, and an out
of range or NaN conversion gives INT_MIN, like SSE.

Also skip GERowSum's zero terms before computing their shift, as their
exponent can be INT_MIN. Found with -fsanitize=undefined on the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:12:48 +02:00
Henrik RydgårdandClaude Opus 5.5 770dc0fe43 SoftGPU: Early depth test of staged spans in vector lanes
CheckDepthTestPassed4 only has an SSE path, so on ARM it compared lane by
lane. Adds Vec4S32::LoadU16 for the depth values.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 10:34:39 +02:00
Henrik RydgårdandClaude Opus 5.5 d24d420057 SoftGPU: Sample a span's four pixels in vector lanes
When the four pixels share their mip level (always, for a triangle's
span), their texel coordinates, clamping or wrapping and texel offsets
are computed in vector lanes, and only the texel and palette reads go
one by one. Adds Vec4S32::Min.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 10:34:39 +02:00
Henrik RydgårdandClaude Opus 5.5 49674c3f25 GEMath: Add GEDot3 and GENormalize4 on Vec4F32
GEDot3 forms one term per lane and sums across the lanes, about 1.5-2x
as fast as the scalar GEDot. Adds Vec4S32::GetLane.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 09:07:12 +02:00
Henrik RydgårdandClaude Opus 5.5 a9d8b6d3c5 GEMath: GERowSum4 takes its left operands as one vector
They're truncated to float24 with one AND, and their exponents, fractions
and signs worked out for all terms at once, each term then broadcasting its
lane (new CrossSIMD Vec4S32::SplatLane). The term count becomes a template
parameter so the lanes are constants. About 75-83 M transforms/s on an M1,
from 68; results unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 09:07:12 +02:00
Henrik RydgårdandClaude Opus 5.5 c4ce2e3635 SoftGPU: Use GERowSum4 for the transform's row sums
The four clip space rows of a vertex, the texture matrix's three, the world
normal's three, the vector to a light, and each row of the combined matrix
now take one GERowSum4 call. Same results (pspautotests, frametests and
the probe regression set unchanged).

GERowSum4 scales its result by adding to the exponent instead of
multiplying, and CrossSIMD gets a Vec4S32::Max for the largest lsb. About
68 M transforms/s against 26 for four scalar GERowSums on an M1 (a pure
NEON version with per-lane shifts did about 79); replaying the frametest
dumps gets only about 1% faster, up to 11% on Taiko no Tatsujin.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 02:57:09 +02:00
Henrik RydgårdandClaude Opus 5.5 802b52d875 CrossSIMD: Add an arithmetic Vec4S32::Shr and Vec4S32FromBits
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 19:00:19 +02:00
Henrik RydgårdandClaude Opus 5.5 84b674f4d8 CrossSIMD: Add MulAdd and Vec4S32FromF32Round
MulAdd is fused on ARM64 and LoongArch, which always have it. Rounding to
nearest is a single instruction on every ISA except ARM32.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 18:12:10 +02:00
Henrik RydgårdandClaude Opus 5.5 c23cd3c64f CrossSIMD: Add RecipSqrt, Select and Vec4F32FromBits
RecipSqrt is exact (sqrt and divide) except on ARM32, which has no vector
divide and refines vrsqrte with two Newton steps.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 18:11:07 +02:00
Henrik RydgårdandClaude Fable 5.1 fc9dbf5ff5 FPU: saturate float-to-int in the interpreters
The C cast is undefined past the int32 range, and x86 makes it INT_MIN, so
round/trunc/ceil/floor/cvt.w.s of anything from 2^31 up gave 0x80000000 on
x86 hosts while the PSP saturates to 0x7fffffff (cpu/fpu/roundmode). Route
all of them through SaturatedFloatToInt, which also covers NaN and inf, and
drop the special cases that did.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-22 14:25:41 -06:00
Henrik RydgårdandClaude Opus 5 320cfd7741 CrossSIMD: fill in the scalar fallback, fix two LSX bugs
LoadConvertU8, StoreConvertToU8 and LoadTranspose existed in the SSE2,
NEON and LSX implementations but not in the scalar one, so anything using
them wouldn't build on a target without SIMD.

The two LSX bugs were found by the new CrossSIMD unit test, run under
qemu-loongarch64:

- Vec4F32::operator[] had a switch with no breaks, so every index fell
  through to the default and returned lane 3.
- StoreConvertToU8 narrowed with the logical (unsigned) saturating shifts,
  which turn a negative value into a huge unsigned one and saturate it to
  255. It should clamp to 0, as the packs/packus pair in the SSE version
  does. Narrow signed->signed and then signed->unsigned instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-19 12:35:09 -06:00
Henrik RydgårdandClaude Opus 5 8e3b4245c2 CrossSIMD: fix the scalar fallback, which nothing compiled until now
The riscv64 cross build is the first target to take the non-SIMD path,
and it didn't compile:

- LoadF24x4 called LoadR24x3_One, which doesn't exist. It should shift
  all four lanes, like the SSE/NEON/LSX versions do.
- isnan/isinf were unqualified, and <cmath> wasn't included.
- WithLane3From and AnyCompareBitsSet were missing entirely.

LoadF24x3_One also left lane 3 as zero, where all three SIMD versions set
it to 1.0f - a behavioural bug that would only have shown up once someone
ran this path.

Verified by flipping TEST_FALLBACK in the header: the whole tree builds,
and with the scalar path in use the unit tests and pspautotests both pass
in full (342/342, software renderer, which leans on this code heavily).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-19 12:19:24 -06:00
Henrik Rydgård ae14ebb6ac IRWriter: Remove the confusing and inefficient AddConstant 2026-08-15 18:31:20 +02:00
Henrik RydgårdandClaude Sonnet 5 be3b417461 expression_parser: bound token length to fix stack buffer overflow
initPostfixExpression() filled a fixed char subStr[256] with no bound
check while tokenizing numeric literals and identifiers. A 256+ char
token in a debugger expression (breakpoint condition, watch,
memory.search) - settable over the network via the WebSocket debugger
- smashed the stack. Now bails out with an error once the token
reaches the buffer size.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-10 01:00:28 +02:00
Henrik Rydgård 676724ee5e Libretro buildfix submitted by boardsofcanada
Don't actually understand how this is an issue, but it seems like a fine
change anyway.
2026-06-19 22:54:31 +02:00
Henrik Rydgård 54d5c1d5e3 Improve some initialization in CrossSIMD.h. Add comments about CLUT variants 2026-06-09 10:15:08 +02:00
Henrik Rydgård f65b3f7a6b Fix LoadU8Norm in CrossSIMD
Caused breakage in the previous PR.
2026-06-08 23:06:41 +02:00
Henrik Rydgård 61a2d78930 Buildfix 2026-06-04 14:02:12 +02:00
Henrik Rydgård 195455a7f4 Break out VertexReader, prepare VertexReader for CrossSIMD use in software transform 2026-06-04 12:45:17 +02:00
Henrik Rydgård c697496364 Other fixes 2026-06-04 11:24:15 +02:00
Henrik Rydgård 1cc0062120 Add Dot3 and Dot4 instructions to Vec4F32 2026-06-04 11:24:15 +02:00
Henrik Rydgård bf196aded6 Fix critical bug in LoadS8Norm for SSE 2026-06-03 15:21:53 +02:00
Henrik Rydgård 7f4c51c141 Merge pull request #21752 from hrydgard/clean-nans-sw
Clean out NaNs and INFs from PosFloat vertex coordinates
2026-06-03 10:38:13 +02:00
Henrik Rydgård bb573e6e0c Well, it builds, but doesn't work yet. 2026-06-02 12:33:53 +02:00
Henrik Rydgård d904b7e0f0 Loongarch type casting fixes, remove redundant code, buildfix 2026-06-02 10:52:39 +02:00
Henrik Rydgård e6185ba6bb Clean out NaNs and INFs from vertex coordinates
This enables a behavior seen on the real PSP where 0 * NaN == 0 in the
GPU (NOTE: This means the vertex transform pipeline).

However, this
doesn't touch INFs unfortunately, and we need to modify those too...

This, together with #21715, finally fixes #20204 .
2026-06-02 10:52:39 +02:00
Henrik Rydgård 2a5c2fa477 Check if the viewport transform matches the clip space. If so we can skip the near clip plane. 2026-05-30 19:07:59 +02:00
Henrik Rydgård 328e1b681c More CrossSIMD ops 2026-05-28 10:56:33 +02:00
Henrik Rydgård 82a888fd8e Reimplement the fast culling using CrossSIMD 2026-05-25 18:16:34 +02:00
Henrik Rydgård ef78791f5d Add some more required functions to CrossSIMD 2026-05-25 18:16:31 +02:00
Henrik Rydgård 250abe0d56 Loongarch64 build fixes 2026-05-25 15:41:24 +02:00
Henrik Rydgård 8b6951c803 Apply vldi fix 2026-05-25 15:40:22 +02:00
copilot-swe-agent[bot]andhrydgard c05e1cfd3c Address LSX CrossSIMD review feedback
Agent-Logs-Url: https://github.com/hrydgard/ppsspp/sessions/6187ce4f-6c64-4b50-b82c-49799ea8cfd2

Co-authored-by: hrydgard <130929+hrydgard@users.noreply.github.com>
2026-05-25 15:40:22 +02:00
Henrik Rydgård 37f6fda9c9 Add a CrossSIMD loongarch64 LSX implementation. Note: This is untested! 2026-05-25 15:40:22 +02:00
Henrik Rydgård 2eca0123f1 Correct culling in case of some weird viewport setups 2026-05-23 14:49:17 +02:00
Henrik Rydgård 0387cc4497 Remove a confusing operator overload from Lin::Vec3 2026-05-19 16:33:45 +02:00
Henrik Rydgård 85de7fdc50 Add new flag that will simplify the GL path 2026-05-14 22:20:35 +02:00
Henrik Rydgård eb476d522e Rename FocusDirection to FocusMove, make into enum class 2026-04-14 18:17:54 -06:00
Henrik Rydgård 1cc2b7233a Fix some minor visual UI issues
See #21223
2026-02-15 19:57:56 +01:00
Henrik Rydgård 31dc48c815 Add a unit test to mat4 x mat4 2026-01-31 13:11:02 +01:00
Henrik Rydgård 7d987cd78b Make fast_matrix_mul_4x4 inlineable 2026-01-30 14:10:32 +01:00
Eric Warmenhoven 58eaf56c5e libretro: build fix
gcc9 and the version of msvc19 that the libretro builders use don't
have _mm_storeu_si32. Using _m_cvtsi128_si32 followed by memcpy is
picked up by compilers that support _mm_storeu_si32 as being the same
and they generate the same assembly, so this is no harm to them.
2026-01-28 00:15:35 -05:00
Henrik Rydgård 47f6b9975e Optimize the color alpha computation for color morph 2026-01-20 13:51:24 +01:00
Henrik Rydgård 3378faca5e Optimize morph code (non-JIT vertex decoders) 2026-01-20 13:51:24 +01:00
Henrik Rydgård a8f89e1544 Correct rounding in StoreConvertToU8, correct Vec4F32::Store3. 2026-01-20 13:51:24 +01:00
Henrik Rydgård 3d20251500 Game background in menus: Crop to fit instead of stretch to fit. Generally looks better, I think. 2025-11-15 20:44:14 +01:00