Commit Graph
9873 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 a007976258 softgpu: Truncate, don't round, in the linear sampler JIT
Jit_GetTexelCoordsQuad converted s*w*256 with CVTPS2DQ, which rounds. The C++
reference casts with (int), and the nearest JIT paths use CVTTPS2DQ - the quad
path just never got converted when the others did. The JIT's sample point sat up
to 1/512 texel further along than the interpreter's, so roughly one pixel in
sixteen picked a different frac_u/frac_v, and at exact texel boundaries a
different texel.

That mismatch is visible wherever the two paths coexist: x86-64 desktop runs the
JIT, 32-bit x86 and UWP have no sampler JIT at all, and even within one x86-64
session the first draws with a new SamplerID run the C++ path while later ones
run the JIT. CVTPS2DQ also honors MXCSR's rounding mode, so anything that left a
non-default mode in the render thread would have changed rasterized output.

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årdandClaude Opus 5 74dd222ea3 softgpu: Fix unsigned wrap in BinDirtyRange::Expand and an OOB write in ClearDirty
Expand did `height += ((int)base - (int)newBase) / (stride * bpp)`. The right
operand is unsigned, so when newBase was above base the negative difference
converted to ~4 billion before the division and height wrapped. After that,
HasPendingWrite()'s `start >= base + height * strideBytes` early-out was taken
for every query, so the binner stopped noticing that a draw textures from the
framebuffer it's writing - skipping the flush and leaving maxTasks_ high, which
makes a self-sampling draw depend on which worker thread got there first.

Reachable without exotic state: scissor changes mark BINNER_RANGE dirty without
forcing a flush, so drawing with the scissor top at y=0 and then moving it down
is enough. Handle both directions explicitly instead.

ClearDirty was missing the bounds clamp its twin MarkDirty has. start is masked
to [0, 2047] but bytes isn't bounded - IsVRAMAddress accepts the whole mirrored
8MB window - so a large guest framebuffer near the top of VRAM runs the loop off
the end of vramDirty_[2048] and writes into whatever follows it. Only active with
frameskip enabled, but then it runs every flip.

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årdandClaude Opus 5 f901105bd9 softgpu: Fix NAND logic op in the pixel JIT, and two blend/stencil issues
The jitted GE_LOGIC_NAND ANDed into temp1Reg, which is uninitialized at that
point and whose result is never read - leaving just the NOT, i.e. COPY_INVERTED
rather than ~(new & old). Every bit where new is 1 and old is 0 came out
inverted. It differed between x86-64 (which has the pixel JIT) and ARM64/UWP/x86
(which don't), and even within one x86-64 run, since GetSingleFunc falls back to
the C++ path when it has to queue a compile.

Subtractive blending clamped to 0 on SSE and in the JIT (PSUBUSW) but not on
NEON (vqsubq saturates at INT_MIN) or the generic path. Normally invisible
because ToRGB() clamps at the end - except the caller adds the dither value in
between, so an underflowing dithered pixel came out up to 7/255 brighter on x86
than on ARM64. Clamp in all paths.

stencil << 24 is signed overflow for stencil >= 128, which is the common case,
not an edge case. Cast to u32 - SetPixelStencil already does this correctly.

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å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 14338534e7 Improve some memory address checking functions 2026-08-19 18:40:01 +02:00
Henrik Rydgård cd5cf87120 Fix performance bug in IRJit when using rewind states 2026-08-18 14:31:13 +02:00
Henrik Rydgård fbfcb8925e Merge pull request #22099 from n00mkrad/softgpu-dither-opt
Allow disabling dithering when using software rendering
2026-08-17 12:47:57 +02:00
nmkd 8e9a8b8d76 Allow disabling dithering when using software rendering 2026-08-16 15:27:41 +02:00
Henrik Rydgård 5cffcd34ad Get rid of the confusing old USING_WIN_UI define. Make a more clear system property for headless. 2026-08-16 12:19:41 +02:00
Henrik Rydgård 2096179dce Drive-by code cleanup 2026-08-15 18:31:20 +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 e9a3449ede More MIPSState * plumbing (manual) 2026-08-12 14:02:19 +02:00
Henrik Rydgård 4d8a5d74e7 Merge pull request #22086 from hrydgard/read-u32-more
Some fixes to Claude's paranoia, more memory access function cleanup
2026-08-11 23:52:17 +02:00
Henrik Rydgård e062c90bf7 Try to fix the test difference (basically by replicating an old misfeature of headless...) 2026-08-11 22:36:47 +02:00
Henrik Rydgård a44c2c0bde Replace System_SendDebugOutput with a registered callback
I normally try to avoid registrations when not needed, but in this case
only headless uses this, so it's motivated.
2026-08-11 22:36:47 +02:00
Henrik Rydgård 5198317e24 Back out some excessive checking in the latest changes. Change TOOD: to TODO: . 2026-08-11 22:27:44 +02:00
Henrik Rydgård 0596ee97f6 More memory access cleanup 2026-08-11 20:14:01 +02:00
Henrik Rydgård 4f8859d0ec Centralize a disassembly utility function between the debuggers 2026-08-11 09:08:52 +02:00
Henrik Rydgård 2be4d995f2 More Read_U32 cleanup 2026-08-10 11:23:23 +02:00
Henrik RydgårdandClaude Sonnet 5 b322b0621c ReplacedTexture: fix stack OOB write from ZIM mip array contract
LoadZIMPtr() writes width[]/height[]/image[] as arrays (one entry per
mip level, up to ZIM_MAX_MIP_LEVELS) whenever the file has
ZIM_HAS_MIPS set, per its documented contract - but this caller passed
plain scalar locals. A texture-replacement .zim file with that flag
set caused multiple out-of-bounds stack writes. Now passes properly
sized arrays and only uses level 0, matching the existing "we don't
support ZIM mips yet" behavior. Also fixes a pre-existing leak of
image[0] on the "changed since header read" error path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:02 +02:00
Henrik Rydgård b6e7cb915a Texture cache management: include w and h in more log messages for context 2026-08-09 19:03:08 +02:00
Henrik Rydgård 459f4473af Fix crash in GE debugger
Fixes #22027
2026-08-07 23:49:30 +02:00
Henrik Rydgård 0324c7a912 Windows buildfix 2026-08-05 00:15:56 +02:00
Henrik Rydgård de7989ae56 Add TextureReplacer unit test; make replacer testable standalone
Add unittest/TestTextureReplacer which creates a fictive texture pack
(textures.ini with readable invented hashes plus real PNG files), loads
it via the replacer, and verifies lookups, filtering, hashranges, mip
levels, and missing/ignored entries.

To make the replacer runnable outside the emulator:
- The constructor now accepts a null DrawContext (formats just default
  to unsupported).
- FindReplacement/FindFiltering use the replaceEnabled_ member instead
  of the global config.
- Added TextureReplacer::LoadPackForTesting() to load an ini from a
  path directly.
2026-08-03 18:55:33 +02:00
Henrik Rydgård 0049b19fbf Fix OOB in texture replacer mip mixing and non-DXT texture decode
Vuln 17: ReplacedTexture::LoadLevelData let a KTX2/DDS file at a higher
mip level resize the shared data_ vector to its own (attacker-controlled)
mip count, so data_[mipLevel + i] indexed out of bounds and the KTX2
branch resized a different element than it wrote to. Disallow mixing
image formats across mip levels, cap the container mip count, and resize
the same element that is used as the transcode destination.

Vuln 18: DecodeTextureLevel only validated the start address for
non-DXT textures, so guest-controlled w/h/bufw could drive reads past
mapped RAM. Validate the needed range like the DXT path does and clamp
the height; ReadIndexedTex now takes the clamped w/h.
2026-08-01 13:16:22 +02:00
Henrik Rydgård 5e6a051952 Fix path traversal in texture pack filenames; use HasPathTraversal in savestate migration
Texture pack filenames/aliases from textures.ini were used to build read
and write paths with no '..' check, letting a malicious pack read or
write files outside the pack directory.

- LoadIniValues rejects entries with a parent dir component via
  HasParentDirComponent.
- ReplacedTexture::Prepare skips such filenames as defense in depth.
- PSPLoaders savestate migration now uses the shared HasPathTraversal
  helper instead of inline separator checks.
2026-08-01 13:16:22 +02:00
Henrik Rydgård 10a5d2f810 OpenGL: Improve checks for fragment shader float precision.
Fixes #22001 (although there may be other artifacts).
2026-07-30 10:03:15 +02:00
Henrik Rydgård 3eb056ad86 Move Common/GraphicsContext.h to Common/GPU/GraphicsContext.h 2026-07-26 13:58:17 +02:00
Henrik Rydgård a6e4d691ef Merge pull request #21973 from hrydgard/more-cmake-cleanup
Clean up the CMake files, matching the project structure of the MSVC build
2026-07-24 23:55:27 +02:00
Henrik Rydgård 2a79257551 Merge pull request #21667 from dsprogrammingprojects/Texture-Replacement-Double-Wildcard
Texture replacement addition for Address Only case
2026-07-24 21:40:02 +02:00
Henrik RydgårdandClaude Sonnet 5 abe6786ae1 Rename core to Core and extract it and GPU into their own CMakeLists.txt
Mirrors the earlier Common extraction. The old "core" target folded in
all of GPU/ (~200 files) plus a few ext/ files wholesale; Windows
already treats GPU as its own project (GPU.vcxproj), so GPU/CMakeLists.txt
splits that out too. GPU has a genuine two-way dependency with Core
(Core/System.cpp calls GPU_Init(), GPU/* calls back into Core for
Memory/Config/CoreTiming/etc), so GPU is a CMake OBJECT library: its
object files are always included wherever consumed instead of being
lazily pulled from an archive, avoiding the GNU ld single-pass
archive-ordering problem a two-way STATIC dependency would hit.

Also fixed a few library misattributions discovered while tracing what
each file actually uses:
- GlslangLibs (glslang/spirv-cross) moved from Core to Common, since
  it's Common/GPU/ShaderTranslation.cpp and VulkanContext.cpp that
  call into it directly. It only worked before because Core happened
  to always be linked after Common.
- ZSTD and OPENGL_LIBRARIES/X11_LIBRARIES moved from Core to GPU,
  matching where they're actually called (GPU/Debugger/Record.cpp and
  Playback.cpp for ZSTD, GPU/GLES for raw gl*() calls).
- GPU also needs Ext::Snappy directly (Playback.cpp calls
  snappy_uncompress) and the libretro-common include dir under
  LIBRETRO, both previously inherited for free by accident.

Also fixed USE_DISCORD's add_compile_definitions ordering: it was
being defined after ppsspp_ui's add_library call, so the UI target
never actually saw it on non-MSVC platforms.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PSNaZnHCjmryS3ziVN9gZU
2026-07-24 20:16:07 +02:00
Henrik Rydgård 240a974e95 Remove direct dependency from Core to MacCameraHelper.mm 2026-07-24 12:06:15 +02:00
Henrik Rydgård 6442742f00 Fix issue with insufficient zeroing of VulkanPipelineKey 2026-07-24 12:06:15 +02:00
Henrik Rydgård 986eee7ef3 Remove the global variable "useEmuThread", add some VK error checking for compute shader compiles 2026-07-18 23:45:27 +02:00
Henrik Rydgård 1c918729d0 Merge pull request #21938 from hrydgard/screenshot-testing-improvements
Headless build: Preparations for framedump screenshot testing
2026-07-18 20:07:08 +02:00
Henrik Rydgård 3fd9b42f95 Fix playback of framedumps for headless 2026-07-18 19:09:46 +02:00
Henrik Rydgård 2931e9e5d2 TextureReplacer: We don't need to check for files that are missing from the alias list. 2026-07-18 18:00:54 +02:00
Henrik Rydgård 53c57bf95f Minor cleanups in replacer 2026-07-18 18:00:54 +02:00
Henrik Rydgård d7c8d6bd80 Clean up cachekey handling in texture replacer 2026-07-18 18:00:51 +02:00
Henrik Rydgård 0b39cde3a3 LookupWildCard: Remove a redundant argument and a constant template argument 2026-07-18 17:55:04 +02:00
Henrik Rydgård 90d922226f Correct maxSeenV handling 2026-07-18 12:31:01 +02:00
Henrik Rydgård 63331fd6d1 Remove DeleteTexture function, only made the code less clear 2026-07-18 12:08:50 +02:00
Henrik Rydgård ee1314f803 Add new TexCache logging channel 2026-07-18 11:57:56 +02:00
Henrik Rydgård f3a5b2dd18 Correct bugs in the secondary texture cache 2026-07-18 11:57:48 +02:00
Henrik Rydgård cff09041c9 Completely rework the flow in TextureCacheCommon::ApplyTexture 2026-07-18 11:57:48 +02:00
Henrik Rydgård b9b2b2b61e Reindent some code, do checks in a more logical order 2026-07-18 11:57:48 +02:00
Henrik Rydgård 1ffdc52111 Remove another "next" variable, cleanup 2026-07-18 11:57:48 +02:00
Henrik Rydgård 3b58242063 More cleanup 2026-07-16 20:54:58 +02:00
Henrik Rydgård ff89e4da4d Simplify 2026-07-16 20:38:27 +02:00