Commit Graph
49255 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 79ccfa8fc7 Common: Share one non-Windows time implementation, fix the fallback
The fallback (Switch, BSDs, anything not Windows/Linux/Android/Apple) mixed
clocks: time_now_d() read the wall clock with gettimeofday, time_now_raw()
and Instant a monotonic one, from_time_raw() didn't subtract the start time,
and time_to_unix_utc() added the timestamp to the current time instead of
the start time.

Now every non-Windows platform shares the same code, built on time_now_raw()
and time_now_unix_utc(). Those two use clock_gettime where we know it's there
and std::chrono's steady_clock/system_clock elsewhere. Instant stores a
single nanosecond timestamp, and time_to_unix_utc() (which was missing on
Linux/Android/Apple) is start time plus timestamp, like on Windows.

The time origin is now set in TimeInit() rather than lazily on the first
time_now_d(), which raced between threads. iOS never called TimeInit(), so
it does now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 14:17:52 +02:00
Henrik Rydgård c6070aed52 Merge pull request #22659 from hrydgard/metal-backend
Metal rendering backend
2026-10-19 13:59:22 +02:00
Henrik RydgårdandClaude Opus 5.5 ae9a0c47e7 Metal: MSAA
Like the Vulkan backend: a multisampled framebuffer has multisampled
color and depth textures that are drawn to and kept between passes, and
each pass resolves them into the ordinary ones (depth and stencil to
sample 0), which textures, copies and readbacks use.
BindFramebufferSamplesAsTexture binds the samples, for the shared code's
sample 0 copies. Copies between multisampled framebuffers copy the
samples too, both depth and stencil, since Metal can't copy one plane of
a multisampled texture.

Also skips empty draws, which Metal doesn't allow.

With 4x MSAA, 1012 of the 1061 frame dumps are identical to Vulkan's.
Most of the rest differ at edges because programmable blending blends
each sample with its own color. In Resistance: Retribution, the sample 0
copy for a palette lookup matches the render without MSAA here, and
Vulkan's doesn't.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:48:12 +02:00
Henrik Rydgård 85e6653d02 Merge pull request #22658 from hrydgard/remove-vertex-texture-leftovers
Remove even more leftovers from hardware tessellation
2026-10-19 12:34:46 +02:00
Henrik RydgårdandClaude Opus 5.5 b0552deb35 docs: Describe the Metal backend as built
Replaces the feasibility study written before it existed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:28:15 +02:00
Henrik RydgårdandClaude Opus 5.5 71ed8421ec Metal: End the shader cache in a checksum, like the Vulkan and GL ones
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:07:52 +02:00
Henrik RydgårdandClaude Opus 5.5 c3f5a4f534 Metal: Cleanups from a review of the backend
- Remove what nothing used: the vertex texture and sampler commands,
  the byte-upload setters, and some unused render manager members.
- thin3d pushes its uniform buffer once for both shader stages.
- Build the thin3d depth/stencil cache key from bytes, so memcmp
  doesn't compare padding.
- Only create the upload command buffer when there are uploads.
- Compare copy destinations by their base texture when merging passes,
  like the textures the passes read.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:07:52 +02:00
Henrik Rydgård 2bf01a8a00 Merge pull request #22656 from hrydgard/imdebugger-symbol-callstack-tools
ImDebugger: Symbol and callstack tools, stack walk fixes
2026-10-19 12:05:54 +02:00
Henrik Rydgård 99adff60f2 Merge pull request #22657 from hrydgard/game-browser-restore-focus
Fixes for keyboard directory navigation on the games tab
2026-10-19 12:05:39 +02:00
Henrik RydgårdandClaude Opus 5.5 b2fc4a80fe Metal: Leave the backend out of the libretro cores
They get their graphics context from the frontend, so they compiled and
linked the Metal backend without being able to use it. Adds
PPSSPP_API_METAL, like PPSSPP_API_D3D11, for the code that only exists
with it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:05:14 +02:00
Henrik RydgårdandClaude Opus 5.5 987a904cff Metal: Fail backbuffer readbacks until something draws to it
Headless renders to an offscreen backbuffer that nothing ever draws to,
so the GE debugger's screenshot read uninitialized memory. Fail the
readback instead, like headless Vulkan (which has no backbuffer), so the
debugger falls back to the displayed PSP framebuffer.

All the GE debugger buffers (screenshot, render color/depth/stencil,
texture, CLUT) now read back the same as Vulkan's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 b2e6113f21 Metal: Hardware texture scaling
Runs the same compute shaders as the Vulkan backend, translated to MSL,
in the upload command buffer: levels decode unscaled into the push
buffer and get scaled into a view of the level. Push constants go in a
buffer of their own. Multipass shaders (NNEDI3) use scratch textures
that live for the frame.

Shaders with a constant buffer (only the smiley test shader) aren't
supported.

All the texture shaders give the same result as Vulkan's on LocoRoco
and God of War savestates.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 55109b39fb TextureCacheVulkan: Move the texture scaling upload shader and passes to common
So the Metal backend can use them too. No functional change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 0978a3e363 PostShaders: Rename videoAA.fsh's texture2d() helpers
On Metal (and Vulkan through MoltenVK), SPIRV-Cross keeps the function
name, which collides with Metal's texture2d type, so the shader failed
to compile and the screen went black.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 fe24def528 Metal: Generate mipmaps at max quality filtering
Like the Vulkan backend, with "Auto Max Quality" texture filtering give
textures up to 256x256 a full mip chain, generating the levels the game
didn't supply with a blit. Mipmapping is now controlled by the
sampler's LOD clamps alone, as on Vulkan, so the mip filter is always
set.

With max quality on, the frame dumps that change are the same 829 on
both backends, and match Vulkan's to within 41 pixels.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 fb2311099a Metal: Leave room after push buffer allocations
The vertex decoder can write past the end of its output, so a draw
decoded into the last bytes of a push buffer block wrote into unmapped
memory and crashed, now and then, in DrawEngineMetal::Flush. Keep 256
bytes free after each allocation, like the Vulkan backend's push pool.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 957579d9d0 Metal: Keep 16-bit textures 16-bit on Apple GPUs
Like the Vulkan backend, upload the decoder's 5650, 5551 and 4444
pixels as they are, in B5G6R5Unorm, BGR5A1Unorm and ABGR4Unorm with a
swizzle (Metal names packed channels from the lowest bits up, the PSP
stores red lowest), instead of expanding them to 8888. Halves the
decoding writes and memory for those textures.

It also makes Everybody's Golf's dump identical to Vulkan's, which
already sampled these at 16 bits.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 51d775cb97 Metal: Compile shaders and pipelines in the background, and cache them
Pipeline states are created on compile threads, along with the shader
functions they need, which compile once on first use. Draws record a
handle to the pipeline state, and the render thread waits for it if it
gets there first, as with Vulkan, so the emu thread never waits for a
compile. Translation to MSL stays synchronous, as recording needs the
texture masks it produces.

Each game's shader IDs and pipeline keys are saved to a
<discID>.mtlshadercache, and recreated while the game boots. macOS's own
Metal cache then makes them quick: Wipeout Pure's 36 pipelines took
25 ms, or 260 ms with an empty Metal cache, instead of stalls during
play.

Cold Wipeout Pure, 5 emulated seconds from a savestate: 3.0 s before,
1.6 s with the background compiles alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 27edb50409 Config: Don't reset a saved Metal backend to the default
The range check predates GPUBackend::METAL (4), so the setting was lost
on every load, and the app came back up on Vulkan.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 6a668eed27 Metal: Use programmable blending for shader blending
On Apple GPUs, the fragment shader reads the framebuffer directly
([[color(0)]]) instead of blending against a copy of it. The Vulkan GLSL
generator path for this was already there apart from the input
declaration: SPIRV-Cross turns the subpassInput into framebuffer fetch.
The Vulkan backend never sets the fetch bit.

Reading the framebuffer as it is also sees earlier triangles of the same
draw, like the PSP does, where the copy only had what was there before
the draw. Of the dumps in ppsspp-framedumps whose output changes, all
ten with a PSP capture got closer to it, Tenchu's from about 10000
differing pixels to 900. Ridge Racer runs about 6% faster.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 327b5dd558 Metal: Wait for the GPU before freeing caches on device loss
DeviceLost frees the draw engine's depth stencil states and samplers
right away, while the render thread could still be replaying commands
that use them. Caught by the validation layer on shutdown.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 9514e02037 Metal: Encode on a render thread, and merge render passes
The render manager now records commands on the emu thread, keeping all
of its decisions there (lazy passes, clear merging, redundant state),
and they're encoded on a render thread, or inline when
bRenderMultiThreading is off, as in the Vulkan backend.

Before encoding, passes to the same framebuffer are merged across
independent work, by the rules of VulkanQueueRunner's render pass merge.
God of War alternates with block transfers to other framebuffers, and
went from about 41 to 18 render passes a frame, which more than halved
its GPU time.

Passes where nothing tests or writes depth or stencil leave the
attachment unloaded and unstored, like the Vulkan backend, which
doesn't attach depth then.

On the eight benchmark states, Metal now uses 4-13% less CPU than
Vulkan, with wall times from 6% faster to 4% slower.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 51a90c8336 Metal: Cut ARC traffic and redundant bindings from the draw path
Draws use an unretained encoder pointer and pipeline struct pointers
instead of passing ObjC objects around (each return goes through
autorelease and retain), and only bind the texture slots the fragment
shader uses. Brings the emu thread's retain/release work down to 0.6%,
and instruction counts 2-11% below Vulkan's on the benchmark states.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 330be6c29a Metal: Don't let command buffers retain resources
Resources that the GPU may still use are now released through the render
manager's per-frame list, freed once the frame's work completes, instead
of command buffers retaining everything that's bound.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 042e320559 Metal: Hook up the backend on iOS
The view controller creates a Metal context when that's the configured
backend, and the backbuffer gets its size from the layer's bounds, as the
drawable size isn't set up yet when the surface is created.

Also pass --options the process was launched with (from Xcode or
devicectl) on to the command line parser, so --graphics=metal works.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 4793d21e5d Metal: Add the GPU backend
GPU/Metal, modelled on GPU/Vulkan since the shaders are the same Vulkan
GLSL, translated to MSL. Drawing goes through the render manager's state
setters, so it shares encoders with thin3d.

thin3d fixes found along the way:
- Binding the framebuffer that's already the target continues the pass,
  applying clears and ignoring DontCare, like VulkanRenderManager.
- Separate depth or stencil copies, through a buffer, so the stencil
  survives a framebuffer resize (Need for Speed Shift).
- Stencil export, so stencil uploads take one pass.

Out of the 1061 dumps in ppsspp-framedumps, 1058 render identically to
Vulkan (two of the others are bad dumps), as do the eight benchmark
savestates.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 8d7ce57fa8 Metal: Hook up the backend on Mac, with the null GPU for now
Selectable with --graphics=metal, the backend choice in settings and the
Mac menu bar. SDL creates a Metal view for it, and headless renders
offscreen. Games run on the null GPU until there's a GPU/Metal.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 16ed2ad55a Metal: Add a thin3d backend (WIP, not hooked up yet)
thin3d on Metal, plus a small render manager that owns frames, command
buffers, lazily started render passes and a per-frame push buffer.

Shaders are the same Vulkan GLSL the Vulkan backend gets, translated to
MSL through glslang and SPIRV-Cross, with the Vulkan binding numbers as
Metal buffer/texture indices. flip_vert_y makes Metal's clip space match
Vulkan's, so everything else follows the Vulkan conventions.

Adds GPUBackend::METAL (4) and builds the files on Apple platforms. Not
yet selectable: the SDL window setup, the UI choice and the GPU core
come next.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:22 +02:00
Henrik RydgårdandClaude Opus 5.5 e666ab49de Remove leftovers from hardware tessellation
Nothing reads from textures or storage buffers in vertex shaders since
hardware tessellation was removed. Drop what was left for it: the
vertexTexture flag of VulkanTexture::EndCreate (always false), the
STORAGE_BUFFER_VERTEX binding type, GL's maxVertexTextureUnits, and the
tesselationShaderSupported cap, which nothing read (and which was always
false, since the feature was never enabled).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 12:02:10 +02:00
Henrik RydgårdandClaude Opus 5.5 b0382ed91a Game browser: Backspace goes up a directory, Windows raw input flags key repeats
With no type-to-search active, Backspace goes to the parent directory. Never
on a repeat, so holding it doesn't climb to the root. Not every platform
flags repeats, so the browser also tracks whether it's held.

Windows raw input now flags auto-repeated key downs as IS_REPEAT, like
Android and UWP, and forgets the held keys it releases on losing focus. The
UI drops OS repeats of a key it's already repeating itself, so held arrows
don't double up (they were dropped before too, a step later).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:36:30 +02:00
Henrik RydgårdandClaude Opus 5.5 193dd01c32 Game browser: Entering a directory focuses its first entry
A subdirectory or game rather than "..", which only gets the focus in an
empty directory.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:25:16 +02:00
Henrik RydgårdandClaude Opus 5.5 c61adac77f Game browser: Going up a directory focuses the one you came out of
Refresh already focused a game it was asked to. Now it does the same for
directories, and keeps the request until a listing that was still loading
has arrived. UI::ScrollFocusedViewIntoView scrolls the focused view into
sight once it's been laid out, since SetFocus alone doesn't scroll.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:22:44 +02:00
Henrik RydgårdandClaude Opus 5.5 35e9b88d8a ImDebugger: Stronger selection and current thread colors
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:15:57 +02:00
Henrik RydgårdandClaude Opus 5.5 8ed0c8692c ImDebugger: Clickable addresses in the Threads window, highlight the current thread
A selectable spanning all columns took the clicks of the addresses after it,
unless it allows overlap. Same fix for the Atrac, utility module and symbol
module tables, which have a checkbox or clickable address after one. The
current thread's row gets a green tint.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:14:15 +02:00
Henrik RydgårdandClaude Opus 5.5 6c0400d8db Stack walk: Don't take an early return for the end of the previous function
With no symbol, a jr ra above pc ends the scan for a leaf's entry. But when ra
points between that jr ra and pc, it's stale from a call this function made,
so the jr ra is an early return of its own, and the scan carries on to its
prologue.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:10:47 +02:00
Henrik RydgårdandClaude Opus 5.5 d49767d7b7 ImDebugger: Add Merge into previous function
What Remove function used to do, for when MIPSAnalyst splits a function in
two.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:07:25 +02:00
Henrik RydgårdandClaude Opus 5.5 5d8be91258 ImDebugger: Make Remove function plain like Delete symbol, show the symbol selection
Remove function in the disassembly merged the function into the previous one,
so its code showed up again under that name. Both now just remove it.

The symbol list's selection color was translucent blue on the list box's blue
background, so it gets the opaque one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:04:57 +02:00
Henrik RydgårdandClaude Opus 5.5 024bed6065 Stack walk: Report a function's symbol start as its entry, not its prologue
The scan for the prologue took the addiu sp as the entry, which is past the
start when the function does something first (a lui, a move).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 11:04:57 +02:00
Henrik RydgårdandClaude Opus 5.5 2cfbbc001d ImDebugger: Symbol deletion, select in symbol list, callstack thread choice
- Symbol list: "Delete symbol" in the context menu, which leaves the code
  without a function (useful to test stack walks with missing symbols).
- Disassembly context menu: "Select in symbol list" selects the function in
  the list without moving the disassembly, clearing a filter that hides it.
- Callstacks: a thread selector (following the current thread by default, with
  a Current button), selectable frames, double-click to show the frame in the
  disassembly, and a context menu to show or copy frames.
- Threads: "Show callstack", "Go to PC" and "Go to entry" in the context menu.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:56:05 +02:00
Henrik Rydgård d44f0129b1 Merge pull request #22654 from hrydgard/fix-android-crashes
Fix Android crashes and ANRs from the 1.20.5-beta1 Play reports
2026-10-19 10:53:52 +02:00
Henrik Rydgård c800c7e333 Merge pull request #22655 from hrydgard/debugger-fixes
Debugger: savestate request fixes, event queue fix, wsdbg error exit
2026-10-19 10:53:38 +02:00
Henrik RydgårdandClaude Opus 5.5 4bfeb59fcd Debugger: Add wait to game.state.load/save
With wait: true, respond once the savestate operation has finished (with its
message), or with an error if it failed or was dropped without running.
Otherwise a client only learns the operation was queued.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:10:25 +02:00
Henrik RydgårdandClaude Opus 5.5 681a60b3ca Debugger: Fail game.state.load/save when the savestate is refused
SaveState::Load and Save silently drop the operation when the network or
achievements hardcore mode forbids it, but the debugger still answered as if
it had been queued. Return whether it was, and check the boot state in the
same CPU-thread call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:07:30 +02:00
Henrik RydgårdandClaude Opus 5.5 b000d557e2 Debugger: Never drop stepping and game events when the queue is full
A log-only breakpoint in a hot loop fills the per-connection queue, and the
cap then also discarded the cpu.stepping that followed, so the client never
heard that the CPU stopped. Only cap breakpoint hits.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:05:43 +02:00
Henrik RydgårdandClaude Opus 5.5 d5e29d1a89 wsdbg: Exit non-zero when the debugger answers with an error
One-shot mode and --sync treated any reply carrying the request's ticket as
success, so a rejected memory write or resume looked like it worked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:05:17 +02:00
Henrik Rydgård 1fb3d535d9 Merge pull request #22642 from hrydgard/cwcheat-malformed
CwCheat: Ignore invisible characters, and show parse errors
2026-10-19 10:01:40 +02:00
Henrik Rydgård b21a83ced9 Merge pull request #22639 from hrydgard/vulkan-pipeline-cache-validate
Shader caches: Add a checksum to the Vulkan and GL cache files
2026-10-19 10:01:14 +02:00
Henrik RydgårdandClaude Opus 5.5 d3f33d96d3 Create the GPU on the main thread during boot
The loader thread now only loads the game. PSP_InitUpdate creates the GPU on
the thread that owns the graphics device, so device loss can't race the
creation, and the device-lost flag and the GPU init on libretro's separate
path are gone. Vulkan loads its shader cache without waiting for the
pipelines, and PSP_InitUpdate keeps the boot in Booting until they're
created. Exiting during boot joins the loader thread in PSP_Shutdown.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 09:26:15 +02:00
Henrik RydgårdandClaude Opus 5.5 1cf65ab6a4 Clarify comments from the crash fixes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 09:10:03 +02:00
Henrik RydgårdandClaude Opus 5.5 b5982e1b84 Android: Don't block the main thread on a game boot when losing the surface
EmuScreen::deviceLost waited for the boot thread to finish, so that it
wouldn't create the GPU on a lost device. With the main thread joining the
render thread on surfaceDestroyed, backgrounding the app during a slow boot
(like the firmware auto-install from the disc) caused ANRs.

Instead, the boot thread now skips creating the GPU if the device is lost,
and PSP_InitUpdate creates it once rendering resumes, as on libretro.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:47:49 +02:00