Files
sharpemu/src/SharpEmu.HLE/HostMainThread.cs
T
Miguel Cruz 864cbb0fa0 [AGC/Vulkan] Extend PS5 runtime and rendering compatibility (#216)
* [Core] Add POSIX native execution and PS5 SELF support

Extend the native backend, guest TLS, fixed-address memory, and loader paths needed by PS5 titles on Windows, Linux, and macOS. Keep workstation GC so high-core-count hosts do not reserve over fixed guest image bases.

* [HLE] Expand PS5 service and media compatibility

Add the kernel, threading, save-data, networking, audio, video-codec, font, dialog, and service exports required by newer PS5 software. Preserve every SysAbi NID currently registered by main while adding the compatibility surface used by ASTRO BOT.

* [AGC/Vulkan] Extend Gen5 shader and presentation support

Expand PM4 handling, Gen5 shader translation, MRT and packed export support, guest image tracking, depth initialization, texture aliasing, and Vulkan presentation. Add the performance overlay and address-filtered diagnostics used to validate ASTRO BOT with original shaders.

* [Core] Align static TLS reservation across hosts

* [Pad] Align primary user ID with UserService

* [Gpu] Preserve runtime scalar buffers across renderer seam

* [AGC] Restore omitted command helper exports

* [Vulkan] Reuse primary views for promoted MRT targets

* [Vulkan] Preserve scratch storage bindings in compute dispatches
2026-07-16 02:02:34 +03:00

79 lines
2.3 KiB
C#

// Copyright (C) 2026 SharpEmu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
using System.Collections.Concurrent;
namespace SharpEmu.HLE;
/// <summary>
/// Runs work on the real process main thread. macOS only allows AppKit (and
/// therefore GLFW windowing) on that thread, so the CLI moves emulation onto
/// a worker thread, parks the main thread in <see cref="Pump"/>, and the
/// video presenter posts its window loop here. On other platforms
/// <see cref="IsAvailable"/> stays false and nothing changes.
/// </summary>
public static class HostMainThread
{
private static readonly BlockingCollection<Action> _work = new();
private static Action? _shutdownRequestHandler;
public static bool IsAvailable { get; private set; }
/// <summary>
/// Registers a callback invoked by <see cref="Shutdown"/> so a
/// long-running posted work item (the presenter's window loop) can be
/// asked to return to the pump.
/// </summary>
public static void SetShutdownRequestHandler(Action handler) =>
_shutdownRequestHandler = handler;
/// <summary>Marks the pump as present. Call before guest code can run.</summary>
public static void Enable() => IsAvailable = true;
public static void Post(Action work)
{
try
{
_work.Add(work);
}
catch (InvalidOperationException)
{
// Shutdown already requested; the process is exiting.
}
}
/// <summary>
/// Services posted work on the calling (main) thread until
/// <see cref="Shutdown"/> is called and the queue drains.
/// </summary>
public static void Pump()
{
foreach (var work in _work.GetConsumingEnumerable())
{
try
{
work();
}
catch (Exception exception)
{
Console.Error.WriteLine($"[LOADER][ERROR] Main-thread work failed: {exception}");
}
}
}
public static void Shutdown()
{
IsAvailable = false;
try
{
_shutdownRequestHandler?.Invoke();
}
catch (Exception exception)
{
Console.Error.WriteLine($"[LOADER][WARN] Main-thread shutdown handler failed: {exception.Message}");
}
_work.CompleteAdding();
}
}