Commit Graph
82 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 c32a01965b SoftGPU: Multiply light colors with 16-bit multiplies
The light color products went through Vec4<int>'s multiply, a 32-bit
lane multiply that SSE2 emulates, though their factors are at most 10
bits. MulSmall uses CrossSIMD's Mul16 where Vec4<int> has a register.

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 d6f045aad9 SoftGPU: Add the diffuse light without branching on its factor
N.L changes sign from vertex to vertex, so the branch on it was mispredicted a lot. A factor that isn't
positive scales the color to 0, so the term can always be added. Vertex reading about 6% faster in
Tekken 6.

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 d272703721 SoftGPU: Keep the vertex position, normal and light vectors as Vec4F32
The position is read once as (x, y, z, 1) for the clip, fog, texgen and
light vector rows, and lighting works on Vec4F32 throughout, without
going through arrays. Each light's constant term, its position minus
the world translation, is computed once per state instead of per
vertex. The texture matrix rows are now prepared with the transform
state, so loading that matrix dirties it.

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 dcaa4d5f16 GPU: Saturate the lighting pow's exponent below 512, as the GE does
The GE keeps the specular and spot exponents to 5 significant bits,
truncated, and from 512 up (infinity and NaN included) uses 496. Only
the specular one was truncated, and neither saturated. A huge or NaN
exponent overflowed pspPow's bits: highlights wrong on every backend,
and on D3D11, where the overflowing float to int conversion gives a
NaN, black (Everybody's Golf, #22418). With the exponent clamped, t
stays in range for every base the backends produce.

Measured, now bit exact in the software renderer and within 4 levels
on Vulkan.

Fixes #22418

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:32:24 -06:00
Henrik RydgårdandClaude Opus 5.5 0274b10e4c SoftGPU: Fix the portable check for a light color that contributes
IsLargerThanHalf's non-SIMD loop assigned instead of or-ing, so only blue
counted: a yellow or red light gave no diffuse or specular on riscv64 and
loongarch64 (gpu/commands/light, gpu/exact/lighting and curves failed
there). The NEON version took a channel of 1 for none; it now agrees with
SSE, which counts any channel above zero.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 16:07:19 -06:00
Henrik RydgårdandClaude Opus 5.5 b684bacbc4 SoftGPU: An inf or NaN spot direction acts as the largest value of its sign
NaN and +inf directions light like (1, 1, 1), -NaN and -inf like (-1, -1, -1)
(gpu/commands/light).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 5aa0faa340 SoftGPU: A directional light with a zero direction gives no diffuse
It used (0, 0, 1) instead, lighting everything facing the camera. The PSP
leaves the direction zero: no diffuse, and specular from the eye vector
alone (gpu/probe exp164). ULJM05302 has such a light on its cars, and the
Yu-Gi-Oh (ULJM05940) replay becomes exact.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 7df47b336b SoftGPU: Light vectors as one matrix row from the model position
The GE never forms a world position for lighting: the vector to a point
or spot light is the light position minus the world translation, minus
the model position times the world matrix, summed like a matrix row.
gpu/probe exp153-158 (point lights 0.02-20 units away, spot exponents up
to 40, game-like world matrices; exp153 is a Syphon Filter vertex) are
exact, and Syphon Filter (#13568) becomes exact.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 6050c6fe02 SoftGPU: Light with the unnormalized normal, GE shade mapping
Found by the probe regression run on the first lighting probes:

- The normal stays as the world matrix leaves it, and N.L and N.H are
  scaled by its GE reciprocal length, like the spot direction. Exact with
  scaled, sheared and rotated world matrices (gpu/probe exp3).
- A negative factor (a spot pointing away with cutoff -1) scales the light
  by 0 instead of subtracting (exp3, exp4).
- Shade mapping UVs use the same GE arithmetic as lighting (exp2-4).
- The half vector uses the GE's add.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 32c41a3417 SoftGPU: Gather the GE arithmetic in GEMath.h
The float24 truncations, reciprocal and rsqrt tables, GE adder and row sums,
the setup reciprocal for planes, the mip log2, texture coordinate precision,
the lighting pow and color scaling, and the antialiased line alpha, from
TransformUnit, Rasterizer and Lighting, so they can be unit tested. No
behavior change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 467e8ef34a SoftGPU: Floor the exact pow product
The GE's pow multiplies the exponent and the float's bits exactly and floors,
instead of a rounded float multiply, which mattered for e = 1.1 (gpu/probe
exp102). The hardware backends keep the float version.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 583ba4c8ed SoftGPU: Attenuate with the squared length the GE already has
The quadratic attenuation term is the light vector's squared length from its
normalization, not d * d (gpu/probe exp63 and exp100: point and spot
attenuation now exact).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 c6d345f2fd SoftGPU: Compute spot lights like the GE
The spot direction isn't normalized: its dot with the light vector is scaled
by the direction's rsqrt. And attenuation and spot scale the light's colors
as separate 8-bit factors rather than one product (gpu/probe exp97-100, exact
on all spot jobs).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:43 -06:00
Henrik RydgårdandClaude Opus 5.5 cfaa7a0d55 SoftGPU: Normalize, dot and transform normals like the GE
The GE normalizes with its own reciprocal square root, a 2 x 128 segment
table like its reciprocal's (measured on gpu/probe exp69), and sums dot
products and the world matrix rows like clip space rows. Used for normals,
light vectors, the half vector, the normalized normal texgen source, and the
world position. Bit exact on exp61, exp64 and exp69; point light attenuation
is 99.9%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:42 -06:00
Henrik RydgårdandClaude Opus 5.5 92e813b53e SoftGPU: Scale specular and attenuated light like diffuse
Specular uses the same 8-bit factor expansion as diffuse, and attenuation
(with the spot factor) is a second 8-bit factor applied after it, also to
ambient. Exact on gpu/probe exp63 for specular, 99.5% for point lights (the
attenuation's own precision is not matched).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:42 -06:00
Henrik RydgårdandClaude Opus 5.5 eb5fad4e10 SoftGPU: Scale diffuse light like the GE
The light and material colors first make an 8-bit product, and N.L becomes an
8-bit s = floor(256 * f), which is expanded like a color before the second
multiply: ((2x + 1) * (2s + 1)) >> 10. Bit exact on gpu/probe exp61-62, apart
from N.L itself being about 2^-15 high on the PSP with a scaled world matrix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 15:09:42 -06:00
Henrik RydgårdandClaude Opus 5.5 a6849661ba Shade mapping: Use the light vector as lighting sees it
Environment map S and T are (N.L + 1) / 2 with L the light's vector as
lighting uses it: from the vertex to the light for point and spot lights,
a zero vector staying zero, and the half vector for a light that does
specular. Whether lighting or the light is enabled still doesn't matter
(gpu/lighting/shademap).

The vertex shader ID now carries the type and computation of the shade
mapping lights (the ubershader reads them from u_lightControl), so both
shader caches get a new version.

Fixes the hair shine in iDOLM@STER SP (#12376).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 15:47:16 -06:00
Henrik RydgårdandClaude Opus 5.5 6f6d3e2a81 Lighting: Take the specular viewer direction from the view matrix
The viewer is at infinity along view space +z, so in world space, where
lighting happens, it's the view matrix's third column rather than
(0,0,1): turning the camera moves the highlights (gpu/lighting/specular).
The shaders read it from u_view.

In a Need for Speed Carbon frame replayed on a PSP, this and the pow
bring the error of the cars from MSE 957 to 120 (Vulkan).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 15:47:16 -06:00
Henrik RydgårdandClaude Opus 5.5 d7a96875fb Lighting: Use the GE's approximate pow for specular, diffuse and spot
The GE computes these powers as exp2(e * log2(x)), with log2 and exp2
each a straight line between powers of two (Mitchell's approximation),
and only uses the top 4 bits of the specular coefficient's mantissa.
Through a highlight's falloff a true pow is 10-30 steps of 255 brighter
at the exponents games use. Measured in gpu/lighting/specular.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 15:47:16 -06:00
Henrik Rydgård e93c80db4e Cleaning up our SIMD header includes, using the new header 2024-12-19 16:08:48 +01:00
Herman Semenov ca94de8d4b [GPU/Common/DX9/GLES/Software] Object out of scope optimization for better codegeneration (lower level scope) 2023-12-20 12:34:34 +03:00
Henrik Rydgård 9a7579f8fa Typo fix, fixes #18038 2023-09-06 17:10:17 +02:00
Unknown W. Brackets d6a5e84db5 softgpu: Fix worldpos skipping.
Oops, was reversed.  We need worldpos for non-directional lights.
2023-07-16 10:59:44 -07:00
Unknown W. Brackets 47c29e0874 sopftgpu: Disable lights if all else disabled.
Tiny gain, but seeing it happen so might as well.
2023-07-16 10:31:58 -07:00
Unknown W. Brackets d5b4c98f96 softgpu: Reduce some non-SIMD lighting math.
Small perf improvement for vertex/lighting heavy (i.e. 3D) scenes.
2023-07-16 10:31:44 -07:00
fp64 f133739cd0 Replace some signed divison in SoftGPU
This also adds a few bitwise operations to Vec4<int> and further
SIMDifies it.
Also, fixes unrelated warning.
2023-06-29 16:43:21 -04:00
fp64 436b49c4f2 Streamline x86 SSE workaround
Seems clearer than using #ifdef's at each site. Also rationale
is clearly spelled out, one 'Go to definition' away from any instance.
2023-06-27 00:30:01 -04:00
Henrik Rydgård 5b4fa06b00 Revert Dot33 on 32-bit x86 only. See #17584 2023-06-16 23:43:33 +02:00
fp64 f0d844a5a3 Convert Dot33 to SSE2
Simpler, lower requirements, and doesn't seem to hurt speed. See #17571.
2023-06-14 22:02:50 -04:00
Unknown W. Brackets a7fa37d114 softgpu: Use SIMD more for dot products. 2023-06-12 19:54:32 -07:00
Unknown W. Brackets 0490ad0039 softgpu: Add NEON variants as well. 2023-04-16 13:09:56 -07:00
Unknown W. Brackets 860fc176d8 softgpu: Use more SSE in lighting. 2023-04-16 11:59:57 -07:00
Unknown W. Brackets 2868495cf8 softgpu: Use SSE for lighting ceil if available.
Tiny optimization, helps only a little.
2023-04-16 11:13:43 -07:00
Unknown W. Brackets b5206df04f softgpu: Calc worldnormal a bit less often.
This is clearer anyway.
2023-04-16 10:16:32 -07:00
Unknown W. Brackets 1215714240 softgpu: Use NEON for lighting. 2023-01-07 19:06:35 -08:00
Unknown W. Brackets f1b5cbf993 softgpu: Fix lighting with 0 exp.
Broken in #15317.  Fixes Kratos scene demo.
2023-01-02 11:42:52 -08:00
Unknown W. Brackets a7b7bf7826 Global: Set many read-only params as const.
This makes what they do and which args to use clearer, if nothing else.
2022-12-10 21:13:36 -08:00
Unknown W. Brackets 8a6e8066bf softgpu: Store vertex colors as packed RGBA8.
No need to keep it expanded at 4x the space for both colors.
2022-09-11 18:41:06 -07:00
Unknown W. Brackets 2479d52202 Global: Reduce includes of common headers.
In many places, string, map, or Common.h were included but not needed.
2022-01-30 16:35:33 -08:00
Unknown W. Brackets 76f9103e97 softgpu: Add a table and initial dirty flags.
Not actually using the dirty flags to skip state, but have moved to
Execute_* functions and everything else like other graphics backends.
2022-01-23 08:08:40 -08:00
Unknown W. Brackets 7218fbbe97 softgpu: Guide more SSE light factor handling.
Missed these others in computed state.  Helps mostly to do this inside
Process().
2022-01-17 06:25:52 -08:00
Unknown W. Brackets fcc3b7684e softgpu: Use SSE in lighting param computation.
The compiler couldn't figure this out.  Halves time in this func.
2022-01-16 21:31:53 -08:00
Unknown W. Brackets 2797e035df softgpu: Precompute lighting parameters.
In many cases, games use lighting just for diffuse or something, this
helps skip what's not needed too.  Good improvement in a scene from a
Naruto game.
2022-01-16 11:27:53 -08:00
Unknown W. Brackets d6a8cb2a0e softgpu: Stop storing normal/worldnormal/worldpos.
This is only needed for lighting, which is applied right away.

This improves perf just simply from less data being copied.
2022-01-14 20:32:18 -08:00
Unknown W. Brackets ce8a49b1c1 softgpu: Retain floats in diffuse/specular.
This seems to be a bit more accurate.  Color blending seems correct now,
but the factors and especially pow results are off.

Also, normalize normal to 0, 0, 1, which seems to match results better.
2022-01-06 21:52:31 -08:00
Unknown W. Brackets bd354164bc softgpu: Cleanup -NAN and diffuse factor. 2022-01-06 21:52:27 -08:00
Unknown W. Brackets 537e357741 softgpu: Correct NAN spotlight exponent/direction. 2022-01-06 21:19:48 -08:00
Unknown W. Brackets b86bdc9456 softgpu: Correct handling of NAN attenuation. 2022-01-06 21:19:47 -08:00