Commit Graph
416 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 91e9b73b45 softgpu: Interpolate lines to pixel centers, so the last pixel reaches v1
DrawLine weighted the endpoints by (steps - i) / steps with i running 0 to
steps - 1, which samples each pixel's leading edge. The last pixel therefore sat
a full step short of v1 and the end vertex's values were never used at all.

Visible in gpu/texmtx/prims, whose line strip ends exactly on the bottom-left
pixel: with normal-projected texgen that pixel should carry v3's texcoords
(texel 0, 255) and we produced (1, 254). Working the interpolation out by hand
against the hardware reference pins the correct parameter at (i + 0.5) / steps,
the pixel center - the same rule the triangle and sprite paths now use. Sampling
the endpoint itself is wrong too: that gives (0, 0), because t/q lands on exactly
256 and wraps.

Kept in halves so the color interpolation stays integer.

The textual half of gpu/texmtx/prims now matches the hardware reference exactly.
The test still fails on its screenshot comparison, whose MSE is unchanged to six
decimals - that's a different primitive type, not the lines.

317 pspautotests pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vd8ntC2brCUtCrDJMqLbs8
2026-08-29 13:08:02 +02:00
Henrik RydgårdandClaude Opus 5 d603396f30 softgpu: Fix subpixel rounding of negative screen coords, and a stale +1
Two leftovers from the sample point having been a sixteenth of a pixel off
center. They're one commit because they can't be separated: each was
compensating for the other, so applying either alone makes
gpu/filtering/precisionnearest3d fail. I tried both orderings.

1. DrawRectangle advanced ST to the first sample with (minX - entireX1 + 1).
   The +1 existed to make up for centerOff being 7 instead of 8; now that minX
   already sits at the pixel center it double-counts and pushes the texture
   coordinate a sixteenth of a texel too far. Only visible when that lands
   exactly on a texel boundary, which is what precisionnearest2d's offset-7 case
   constructs: the sprite spans x from -7/16, so u at pixel 0's center is 0.9375
   and should sample texel 0, but the extra sixteenth made it exactly 1.0.

2. Removing the +1 exposed the other one. ClipToScreenInternal used a plain
   (int) cast, which truncates toward zero - so once the region offset makes the
   value negative it rounds the opposite way from the positive case, and from
   the through-mode path that computes screenpos directly. The two disagreed by
   one subpixel for negative coordinates, which is why the 2D and 3D variants of
   the same test failed at different offsets, 7 and 8. floorf is what the +0.375
   nudge was always meant to pair with, and it makes both paths agree.

Now passing: gpu/filtering/precisionnearest2d, promoted to tests_good since it
passes on Vulkan too. precisionlinear2d and precisionlinear3d also start passing
on software but still fail on the hardware backends, so they stay in tests_next
with a comment saying so, as does gpu/primitives/continue from the last commit.

317 pspautotests pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vd8ntC2brCUtCrDJMqLbs8
2026-08-29 13:02:09 +02:00
Henrik RydgårdandClaude Opus 5 c9aac4f992 softgpu: Sample at actual pixel centers
TriangleEdge::Start's comment says "Start at pixel centers", but centerOff was
(SCREEN_SCALE_FACTOR / 2) - 1, i.e. 7 of 16 - a sixteenth of a pixel short of the
real center at 8. DrawRectangle and DrawPoint had the same off-by-one.

Found via gpu/texmtx/uvs, which draws a quad whose UVs span 0..2 across 256
pixels, so one texel is half a pixel and the error is exactly visible: the PSP
samples texel 2x+1 and we sampled 2x. The V axis happened to land a quarter texel
above an integer, so it rounded to the right answer and only U was visibly wrong,
which is what made this look asymmetric. Confirmed by logging the interpolated s/t
at the corner pixels: our sample point sat at pixel + 0.4375 rather than + 0.5.

Both hardware backends already pass that test, so this was softgpu-only.

Now passing and promoted to tests_good: gpu/texmtx/uvs and
gpu/filtering/precisionnearest3d, both of which also pass on Vulkan.
gpu/primitives/continue now passes on software too, but still fails on Vulkan, so
it stays in tests_next for now.

316 pspautotests pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vd8ntC2brCUtCrDJMqLbs8
2026-08-29 12:43:47 +02:00
Henrik RydgårdandClaude Opus 5 f41fe77643 softgpu: Truncate float->int conversions on SSE, like every other path
Vec4<float>::Cast<int>() used _mm_cvtps_epi32 under SSE, which rounds using
MXCSR's mode, while NEON's vcvtq_s32_f32 and the scalar (T2)x fallback both
truncate. Same split in Rasterizer's InterpolateI.

That's on depth interpolation, so the differing values are written to the depth
buffer and then compared - a one-LSB difference can flip a later GE_COMP_EQUAL
pass and change a whole surface's visibility, not just a shade. Following MXCSR
also meant anything that left a non-default rounding mode in the render thread
would have changed rasterized output.

Truncation is what two of the three paths already did, so SSE moves to match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vd8ntC2brCUtCrDJMqLbs8
2026-08-29 12:05:50 +02:00
Henrik RydgårdandClaude Opus 5 5a854a92fb softgpu: Fix two accumulator-vs-assignment bugs in non-SSE fallbacks
Rasterizer.cpp: the secondary color fallback does `prim_color[i] = ` where the
SSE and NEON branches add, so the base/texture color is thrown away and the
triangle renders as pure specular. Introduced by 250abe0d56 (Loongarch64 build
fixes) changing one character; the structurally identical block in DrawRectangle
still has the `+=`. Live on ARM32, LoongArch64, RISC-V64 and anything else that
isn't SSE2 or ARM64.

Lighting.cpp: IsLargerThanHalf's scalar path assigns instead of accumulating in
its loop, so it returns only `v[2] > 1` and ignores the other components, and the
NEON path computes a max where SSE computes a sum. All three disagreed. The
question being asked is "is this color factor non-zero" - the test this replaced
in fcc3b7684e was `!(colorFactor == ones)` - and since LightColorFactor produces
2*c+1, every component is >= 1 and the sum of four is >= 4, which is why the SSE
sum > 4 is the correct one. Made the other two match it.

Getting this wrong doesn't shift a shade, it enables or disables a whole light:
x86-32 and ARM64 were switching lights off that x86-64 left on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vd8ntC2brCUtCrDJMqLbs8
2026-08-29 11:55:23 +02:00
Henrik Rydgård 46d5fae342 VSH prep: Free up kernel memory by not storing the PPGe atlas in it 2026-08-19 18:45:52 +02:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård a317890c08 Remove the GPUDebugInterface class
Just a pointless extra layer in the class hiearchy, making it
unnecessarily hard to modify the interface.

Might as well hit GPUCommon directly.
2026-06-02 11:15:08 +02:00
Henrik Rydgård 250abe0d56 Loongarch64 build fixes 2026-05-25 15:41:24 +02:00
Henrik Rydgård a602be6ca4 Fix regression for line gouraud shading
Caused by a2abf94
2025-03-03 11:58:12 +01:00
Henrik Rydgård d5bfc1b5eb Finish up this cleanup (move _M_SSE compat define out of Common.h) 2024-12-19 16:23:20 +01:00
Henrik Rydgård 5326d87f9c Rename CrossSIMD to SIMDHeader, but also keep CrossSIMD.h (will have a future use) 2024-12-19 15:15:43 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +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
fp64 b0f71e08f4 Simplify projective texcoord calculation
As mentioned in https://github.com/hrydgard/ppsspp/issues/17613#issuecomment-1613583152 .
2023-07-03 10:59:09 -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
Unknown W. Brackets fedb92b0e9 softgpu: Ensure early depth test uses SIMD. 2023-06-25 10:18:21 -07:00
Henrik Rydgård 08d578dce9 Merge pull request #17618 from unknownbrackets/softgpu-opt-cast
Optimize casts in softgpu
2023-06-25 07:55:30 +02:00
Henrik Rydgård ec92675c5e Merge pull request #17619 from unknownbrackets/softgpu-opt-z
softgpu: Improve Z interpolation SIMD
2023-06-25 07:55:03 +02:00
Unknown W. Brackets d42642edd2 softgpu: Improve Z interpolation SIMD. 2023-06-24 22:17:11 -07:00
Unknown W. Brackets ae9d34370e softgpu: Move wsum_recip out of the triangle loop.
Seems like a small benefit, but not seeing any issues from this.
Noticed by fp64.
2023-06-24 12:38:05 -07:00
fp64 ab85c46161 Use _mm_movemask_ps for AnyMask
Probably very minor speed improvement, but it's rather neat.
2023-06-17 01:05:02 -04:00
Henrik Rydgård fc62d587c0 Fix whitespace issues 2023-04-02 16:36:39 +02:00
Герман Семенов 122b63b9a8 GPU: using if constexpr C++17 optimization 2023-04-02 16:36:37 +02:00
Henrik Rydgård ffb8a9be47 Fix another subtle NEON type mismatch.
Fixes #16777
2023-01-10 14:56:30 +01:00
Unknown W. Brackets e0ed080d8b softgpu: Use NEON more in triangle rasterization.
Some of these places weren't getting converted well.
2023-01-07 19:06:34 -08:00
Unknown W. Brackets 49f6c461ad Reporting: Fix some header includes.
Particularly in Common, avoid including Core/Reporting.h.
2022-12-27 14:58:20 -08:00
Unknown W. Brackets 87fb9eef37 softgpu: Remove std::function usage.
Wanted to avoid coupling these, but don't like the std::function
construct/destructs showing in profiles...
2022-12-06 19:15:57 -08:00
Henrik Rydgård e969f9cf8b Merge pull request #16502 from unknownbrackets/softgpu-opt
A few more softgpu optimizations for alpha blend/test
2022-12-05 09:35:36 +01:00
Unknown W. Brackets 07c276c32d softgpu: Fix double rectangle drawing at halfpixel.
There seems to be some odd behavior with the X start pos, but at least the
end pos should not be drawn twice when using 0.5 - 0.5.
2022-12-04 17:47:57 -08:00
Unknown W. Brackets d6750993d7 softgpu: Force alpha test when it could skip blend.
Blending is slow, and often games do effects like smoke, sun, etc. that
has a lot of zero alpha in them.  Many games do this with alpha testing
off, which is cheap compared to blending.
2022-12-04 16:36:45 -08:00
Unknown W. Brackets 2c90dafe64 softgpu: Force alpha test off in more scenarios.
Since we're already checking the CLUT, we can tell if it doesn't contain
zero alpha, in which case a != 0 test will never fail.  This is actually
pretty common, even when texture alpha is not always FF.
2022-12-04 16:30:12 -08:00
Unknown W. Brackets 00e76b11b6 softgpu: Optimize > non-zero alpha tests as well.
These are fairly common, especially in 3D games.
2022-12-03 12:55:38 -08:00
Unknown W. Brackets eb19e24399 softgpu: Skip non-zero alpha test if impossible. 2022-12-03 12:54:53 -08:00
Unknown W. Brackets adc94b1950 softgpu: Use CLUT to optimize out blending more.
This actually happens relatively often.
2022-12-03 12:44:02 -08:00
Unknown W. Brackets 204789a27f softgpu: Skip fog when no verts have fog. 2022-12-02 21:55:49 -08:00
Unknown W. Brackets 0c42e45e92 softgpu: Cleanup reapply logic.
This makes more sense to read.
2022-12-02 21:42:57 -08:00
Unknown W. Brackets 4d92533907 softgpu: Apply optimizations to states generically.
This is for optimizations we can only do when we know the vertex values.
2022-12-02 21:30:53 -08:00
Unknown W. Brackets 6bd0eec54d softgpu: Calc flags on state as we queue verts.
Might be some other ways, like doing this directly in a vertex reader.
Also am thinking about doing things regarding UVs or positions.

Flags not yet used, keeping separate for perf checks.
2022-12-02 21:28:50 -08:00
Unknown W. Brackets a04b7cf3b3 softgpu: Force shading flag off in clearMode.
Probably fixes a line shading bug, and clearer anyway.
2022-12-02 21:20:59 -08:00
Unknown W. Brackets 33abbca464 softgpu: Optimize out texture proj for UVs.
Seen in NFS Most Wanted 5-1-0.
2022-12-01 23:13:20 -08:00
Unknown W. Brackets a1f6a40d10 softgpu: Interpolate Z for 3D lines.
Important for Me & My Katamari, see #16131.
2022-12-01 14:39:19 -08:00
Unknown W. Brackets 4d06400548 softgpu: Fix compile hazard while running.
This prevents any clearing of cache while other threads may be using
previously cached funcs, and avoids wx exclusive hazards.
2022-11-20 12:04:02 -08:00
Unknown W. Brackets ce51942508 softgpu: Correct WX-exclusive platform hazards.
Should mainly affect BSD at this point.
2022-11-20 10:55:35 -08:00
Unknown W. Brackets d8716b5d90 softgpu: Fix off-by-one rendering after half-pixel.
If the X is after a half-pixel offset, the first pixel we draw is the next
one.  This wasn't being accounted for properly in one place.
2022-11-13 10:22:09 -08:00
Unknown W. Brackets 79b1d1d35f softgpu: Better approximate slope mip level mode (#16276)
* samplerjit: Remove unused x/y parameters.

Still need to tune the accuracy of filtering, but those were not the
right way.

* softgpu: Better approximate slope mip level mode.

This isn't exactly right, but it's closer.

* softgpu: Calculate auto from largest difference.

Direction shouldn't matter.
2022-10-23 10:15:43 +02:00
Unknown W. Brackets 7eb7bd5141 softgpu: Correct linear interp for uneven positions.
Can't round to the pixel when calculating the S/T deltas.
This fixes issues in Wipeout (#16131) and Call of Duty bloom.
2022-10-16 18:57:55 -07:00
Unknown W. Brackets 9d6de98ed9 softgpu: Correct drawing outside TL of rectangle.
If the start coordinate was something like 51.75, we were incorrectly
drawing to 51.  This can be seen in the Metal Slug intro (#15755.)
2022-10-16 18:46:38 -07:00
Unknown W. Brackets dc90a5a851 softgpu: Avoid projecting textures in common case.
Several games appear to intentionally set the matrix flat.
2022-09-29 22:31:49 -07:00
Unknown W. Brackets 23af9be9f4 softgpu: Handle rectangle texture projection. 2022-09-26 18:44:39 -07:00