Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
1c4c8ae
[GPU] Recognize the Demon's Souls pattern copy shader as a bounded copy
par274 Nov 13, 2026
d3842f1
[GPU] Raise the host word copy limit to 16 MiB
par274 Nov 13, 2026
c395013
[Diagnostics] Name the writing program in target writer traces
par274 Nov 13, 2026
90d306c
[GPU] Check image bytes exactly before a kernel store lands over GPU …
par274 Nov 13, 2026
052a5dc
[GPU] Separate the kernel write stream check from posting
par274 Nov 13, 2026
b13a980
[GPU] Post owned store data without copying it again
par274 Nov 13, 2026
681e89d
[GPU] Read the command queue depth from the environment
par274 Nov 13, 2026
a7ef0c0
[GPU] Index queued stores by page for overlay reads
par274 Nov 13, 2026
e14d25c
[Diagnostics] Count posted word copies and their refusals
par274 Nov 13, 2026
61e9ec8
[GPU] Post a bounded word copy as a store at its stream position
par274 Nov 13, 2026
5d4937c
[GPU] Consume bounded copy dispatches on the stream thread
par274 Nov 13, 2026
12e2f9b
[GPU] Report the kind of a pending write between two stream positions
par274 Nov 13, 2026
e2337a5
[Diagnostics] Name the pending write kind that sends a draw to the st…
par274 Nov 13, 2026
7cf0ac5
[GPU/HLE] Wolverine: shader calls, bindless heap, translator and pipe…
Im-Usif Nov 15, 2026
871cdda
[ShaderPrewarm] Leave the load address out of a compute record's iden…
par274 Nov 16, 2026
ee107d6
[GPU] Validate a stage's remembered textures under one image cache lock
par274 Nov 15, 2026
8ab70b3
[GPU] Check stage memo freshness with one lock per stage
par274 Nov 15, 2026
617fa82
[GPU] Share the native color clear registration check
par274 Nov 15, 2026
4caad68
[GPU] Take the write lock only when a native color clear registration…
par274 Nov 15, 2026
cd359a6
[GPU] Skip zeroing the native color clear scan buffer
par274 Nov 15, 2026
9e1eed2
[GPU] Read guest memory without the store lock when the page has no p…
par274 Nov 15, 2026
20bf3ea
[GPU] Keep images used this frame when a render worker resolves an ov…
par274 Nov 15, 2026
db54bff
[GPU] Stop a render worker slice at a repeated image lookup failure
par274 Nov 15, 2026
fdf15e7
[GPU] Queue a slice's rest chunks through one helper
par274 Nov 15, 2026
575d26b
[GPU] Hand the rest of a stolen slice to the render workers
par274 Nov 15, 2026
9ed271e
[GPU] Read the slice lookahead per render worker from the environment
par274 Nov 15, 2026
7e14183
[GPU] Reset a draw record's resolve and copy fields only after those …
par274 Nov 15, 2026
9aaf246
[GPU] Expose the image request comparison
par274 Nov 15, 2026
5ef1071
[GPU] Repeat draw targets that resolve to the same attachments
par274 Nov 15, 2026
1e26b9e
[Diagnostics] Count metadata changes by call site
par274 Nov 15, 2026
c816ac8
[Diagnostics] Log the command queue depth and slice lookahead per ren…
par274 Nov 15, 2026
99744f8
[GPU] Capture a draw's bindings for a replay of the next item
par274 Nov 15, 2026
9c72a85
[GPU] Replay a draw that repeats the previous item's resources
par274 Nov 15, 2026
31add4d
[Diagnostics] Report why a host refuses a draw replay
par274 Nov 15, 2026
68be9f7
[ShaderCompiler] Order a materialization level's reads by base and of…
par274 Nov 16, 2026
cb74b13
[GPU] Remember a resolve's last clean page for direct reads
par274 Nov 16, 2026
7f70b2c
[GPU] Read a resolve's remembered clean page without the read checks
par274 Nov 16, 2026
6da4b2d
[ShaderCompiler] Read a level's runs in their static order
par274 Nov 16, 2026
45675c5
[ShaderCompiler] Bound a computed device-address read offset by its o…
par274 Nov 16, 2026
378d87d
[ShaderCompiler] Mark a plan whose device-address reads are all bounded
par274 Nov 16, 2026
e894cad
[GPU] Carry a plan's bounded device-address reads into its program info
par274 Nov 16, 2026
8d7c9c2
[GPU] Skip the device-address sweep for programs whose reads are all …
par274 Nov 16, 2026
15bbe82
[GPU] Hold a clean read slice use on its registered buffer
par274 Nov 16, 2026
7da2dda
[Diagnostics] Report bounded device-address preparations and held sli…
par274 Nov 16, 2026
41038b8
[GPU] Compare a stage's inputs without its thread limits
par274 Nov 16, 2026
89c6599
[GPU] Replay a dispatch's bound state for the next dispatch of its pi…
par274 Nov 16, 2026
f32fb55
[Diagnostics] Report dispatch replays and their misses
par274 Nov 16, 2026
85c6af6
fix tests
par274 Nov 16, 2026
f484338
[AGC/Loader/GPU/Kernel] Super Meat Boy 3D: AGC exports, red-zone patc…
Im-Usif Nov 16, 2026
80a1be6
[GPU] Proven memo ticks
par274 Nov 17, 2026
e95bfad
[Kernel] Add high-resolution sleep support for Windows and Linux
par274 Nov 17, 2026
ab92008
[ShaderCompiler] Honor early depth tests and preserve inactive image …
par274 Nov 18, 2026
99f9fe9
[GPU/ShaderCompiler/Images] Ghost of Yōtei: boots to the world and re…
Kuaryn Nov 18, 2026
ce320fe
fix(playgo): read playgo.pgm when the sidecar metadata lists no chunk…
foufouadi Nov 18, 2026
0f071bd
[SpirvTranslator] A program counter read keeps thread-addressed LDS i…
Kuaryn Nov 19, 2026
b4b4ab4
[GPU] Avoid replaying metadata clears after a rendering scope break
par274 Nov 19, 2026
a29a6be
[GPU] Keep bindless heap views resident across guest frames
par274 Nov 19, 2026
f1af467
[GPU] Keep a growing texture heap in one bindless heap view (#1152)
Im-Usif Nov 19, 2026
82ead82
Merge upstream f1af467a6 into main
xnetcat Nov 19, 2026
78c2cb8
[GPU] Index the command thread's queued items by page for stream reads
xnetcat Nov 19, 2026
c2575cd
[Metal] Record end-of-pipe landings, deferred labels included
xnetcat Nov 19, 2026
94d0346
[Shader] Count vertex and instance ids from the draw's bases and stor…
xnetcat Nov 19, 2026
bf2056a
[Tests] Pin a store after a copy landing after the copied bytes on Metal
xnetcat Nov 19, 2026
687dccc
[Metal] Take a draw's stencil operations from its dynamic state
xnetcat Nov 19, 2026
d6de7e9
[Shader] Read storage image store channel maps from shader data in MSL
xnetcat Nov 19, 2026
84c862a
[Docs] Document SHARPEMU_RUNTIME_IMAGE_SWIZZLE for the Metal build
xnetcat Nov 19, 2026
1a42bcc
[Shader] Read lanes a fragment simdgroup never launched through the g…
xnetcat Nov 19, 2026
5b1d809
[Metal] Post a bounded word copy as a command-processor store at its …
xnetcat Nov 19, 2026
96cd941
[Shader] Number hull instances from zero and narrow fma_mix NaNs to 0…
xnetcat Nov 19, 2026
fdbf8da
[Metal] Decode the narrow integer and UNORM 11_11_10 render targets u…
xnetcat Nov 19, 2026
5c769d9
[Tests] Check that every returning buffer atomic out of range returns…
xnetcat Nov 19, 2026
828b0a8
[Metal] Wait for a draw's graphics pipeline outside the pipeline cach…
xnetcat Nov 19, 2026
9472553
[Docs] Document the Metal host port switches
xnetcat Nov 19, 2026
03bf458
Merge port/f1af467a6-host: Metal host ports for upstream f1af467a6
xnetcat Nov 19, 2026
274609d
Merge port/f1af467a6-msl: MSL translator ports for upstream f1af467a6
xnetcat Nov 19, 2026
457d364
[Metal] Take upstream's resident-mip textures in the image cache
xnetcat Nov 19, 2026
68dfc25
[Metal] Replay repeated draws and dispatches on the Metal host
xnetcat Nov 19, 2026
905117c
[Tests] Scene tests for Metal draw and dispatch replay
xnetcat Nov 19, 2026
603d7a5
[GpuRemote] Test that the GPU host gets the replay switches
xnetcat Nov 19, 2026
0d3f4c1
[Docs] Document SHARPEMU_DRAW_REPLAY and SHARPEMU_DISPATCH_REPLAY on …
xnetcat Nov 19, 2026
ca8aba5
[Shader] Bound each selected component of a literal formatted load, w…
xnetcat Nov 19, 2026
1d6d6d7
[Shader] Carry a non-indexed mesh draw's first vertex as its base vertex
xnetcat Nov 19, 2026
7c8cded
[Tests] Pin formatted stores through a run-time V# and D16_HI_X store…
xnetcat Nov 19, 2026
dc2b1b8
[Shader] Load a BVH node only when every 64-byte unit of it is mapped
xnetcat Nov 19, 2026
caa5a3a
[Tests] Read a plain 2D texture through an array instruction via Meta…
xnetcat Nov 19, 2026
4ec43b9
[Metal] Keep the low bits of an integer image store, as a signed imag…
xnetcat Nov 19, 2026
ea911a9
[Metal] Refuse a device-address range past the address space, and tes…
xnetcat Nov 19, 2026
e51d104
[Metal] Break the replay item chain on relay commands, not on batch s…
xnetcat Nov 20, 2026
1311c9d
Merge port/f1af467a6-msl2: MSL follow-up ports for upstream f1af467a6
xnetcat Nov 20, 2026
57be1d2
[GPU] Mirror the kernel's PRT apertures and AMM area into the GPU pro…
xnetcat Nov 20, 2026
922e964
[Metal] Bind the null texture for a bindless entry over unmapped memory
xnetcat Nov 20, 2026
377b1e4
[GPU] Take the managed-write lease only once a GPU claimant registered
xnetcat Nov 20, 2026
b62946b
[Metal] Refuse a posted word copy only over an image's bytes
xnetcat Nov 20, 2026
0e20232
[Tests] Skip the replay scenes when the engine's replay switches are off
xnetcat Nov 20, 2026
8ae70b3
Merge port/f1af467a6-mips: resident-mip images, PRT mirror and host l…
xnetcat Nov 20, 2026
c877134
[Tests] Give the slow linked compile test a record threshold a loaded…
xnetcat Nov 20, 2026
914817e
[Shader] Read bindless heap image and sampler records in MSL
xnetcat Nov 20, 2026
47a6f51
[Metal] Resolve bindless heap records on the Metal host
xnetcat Nov 20, 2026
2ebc2b1
[Tests] Bindless heap scenes on the Metal host
xnetcat Nov 20, 2026
93ba888
[Tests] Dispose a compile gate after the rig whose compiler threads w…
xnetcat Nov 20, 2026
075e677
Merge port/f1af467a6-replay: draw and dispatch replay on the Metal ho…
xnetcat Nov 20, 2026
7b73575
[GPU] Share BindlessHeapViewTable with Metal as a public contract
xnetcat Nov 20, 2026
ca4b60a
[Metal] Keep translated shaders in the game's translation disk cache
xnetcat Nov 20, 2026
d3375c4
[Tests] Cover the Metal translation cache payload, its sessions and i…
xnetcat Nov 20, 2026
989d2dd
[Metal] Name the translation folder through a public entry, not a new…
xnetcat Nov 20, 2026
68fe8c7
Merge port/f1af467a6-heap: the bindless heap on Metal for upstream f1…
xnetcat Nov 20, 2026
f0ec145
[Metal] Refuse replay capture for a program that reads the bindless heap
xnetcat Nov 20, 2026
0c1ab88
Merge port/f1af467a6-tcache: per-game translation and analysis caches…
xnetcat Nov 20, 2026
ac5ff88
[Tests] Pin that a backend with its own mesh pipelines never takes up…
xnetcat Nov 20, 2026
65bfec9
[Tests] Pin the GPU launch of an automatic amplified mesh draw agains…
xnetcat Nov 20, 2026
fb1cdf3
[Tests] Pin Metal's amplified mesh sizing against upstream's primitiv…
xnetcat Nov 20, 2026
13c8cb3
[Shader] Step the stand-in shader clock 2^32 + 1 per read, and say wh…
xnetcat Nov 20, 2026
7d69099
Merge port/f1af467a6-mesh: tests pinning Metal's equivalent of upstre…
xnetcat Nov 20, 2026
e521592
[Metal] Hand out the compute compile in flight (GetComputePipelineCom…
xnetcat Nov 20, 2026
6136998
Merge port/f1af467a6-caps: shader clock step and compute compile comp…
xnetcat Nov 20, 2026
9dc27ba
[Shader] Lower linked shader calls and call records to MSL
xnetcat Nov 20, 2026
652fb01
[Metal] Answer stable image descriptor limits from the device's argum…
xnetcat Nov 20, 2026
9acbbf5
[Metal] Prepare call records, marks and faults for linked shader calls
xnetcat Nov 20, 2026
3d977d2
[Shader] Reduce wave32 DPP row scans read at lanes 15/31 over the sim…
xnetcat Nov 20, 2026
4075926
[Tests] Stable image bindings on Metal: budget, one-pipeline scene, p…
xnetcat Nov 20, 2026
1ad2b43
[Metal] Answer PixelSubgroupArithmetic from the device, behind SHARPE…
xnetcat Nov 20, 2026
f4f51f7
[GPU] Hold a dispatch while its linked program links or translates, a…
xnetcat Nov 20, 2026
1e64961
[Metal] Read a call record's integer image through its element's nume…
xnetcat Nov 20, 2026
bcb7f60
[Metal] Make an unlinked shader call fatal under SHARPEMU_STRICT_COMP…
xnetcat Nov 20, 2026
bcd00b7
Merge port/f1af467a6-limits: stable image bindings on Metal for upstr…
xnetcat Nov 20, 2026
1778c85
[Metal] Prewarm linked programs under the host's bindless heap policy
xnetcat Nov 20, 2026
dce819b
[Metal] Follow upstream's call-mark relink for run-time call records,…
xnetcat Nov 20, 2026
6d9205d
Merge port/f1af467a6-subgroup: pixel subgroup reductions on Metal for…
xnetcat Nov 20, 2026
3b1c554
[Shader] Share the bodies of a callee's per-record copies at a call s…
xnetcat Nov 20, 2026
2b329c8
[Metal] Prewarm linked records after every other compute, never held,…
xnetcat Nov 20, 2026
a1759b3
Merge branch 'sync/upstream-f1af467a6' into port/f1af467a6-calls
xnetcat Nov 20, 2026
25b28b5
Merge port/f1af467a6-calls: linked shader calls and call records on M…
xnetcat Nov 20, 2026
193db58
[Shader] Keep the low bits of every integer image store, not only tho…
xnetcat Nov 20, 2026
3e2f723
[Metal] Count compute prewarm records of the other image binding poli…
xnetcat Nov 20, 2026
4550b28
[Metal] Keep a colour target rendered past its 1x1 level to its chain
xnetcat Nov 20, 2026
b30ab2b
[Metal] Read a bindless heap view's records in runs when comparing th…
xnetcat Nov 20, 2026
8962dea
[Shader] Mark a heap record once per block in MSL, as the SPIR-V tran…
xnetcat Nov 20, 2026
f2f9d8d
[Tests] Heap scene tests: bulk reads on and off, pixel stage, depth c…
xnetcat Nov 20, 2026
09b950a
Merge port/f1af467a6-left: integer store widths, colour targets past …
xnetcat Nov 20, 2026
536cd8b
[GPU] Give the provider's ahead and retry resolutions their interface…
xnetcat Nov 20, 2026
c2abc04
[Metal] Read a posted word copy's pending bytes ahead of the worker a…
xnetcat Nov 20, 2026
5db98d5
[Metal] Take a posted word copy as a host store only when the GPU is …
xnetcat Nov 20, 2026
565323e
[GPU] Order an overlap-marked dispatch after the ones beside it when …
xnetcat Nov 20, 2026
8947929
Merge fix/sync-f1af467a6-ds-render-thread: posted word copies without…
xnetcat Nov 20, 2026
434bf25
[Docs] Describe the posted word copy store class, overlay reads and d…
xnetcat Nov 20, 2026
2f40030
[GPU] Refuse a write guard's GPU-owned predicate word and order marke…
xnetcat Nov 20, 2026
ccd7c32
[Shader] Keep a plan with device-descriptor tables on the interpreted…
xnetcat Nov 20, 2026
10d456b
[GPU] Keep marked dispatches whose shared buffer bytes both sides onl…
xnetcat Nov 20, 2026
32a7bbf
[GPU] Treat an image a marked dispatch only stores to as written, not…
xnetcat Nov 20, 2026
528a568
Merge fix/sync-f1af467a6-ds-overlap: write-guard predicate reads refu…
xnetcat Nov 20, 2026
36fc1b9
Merge fix/sync-f1af467a6-gta-step-cap: plans with device-descriptor t…
xnetcat Nov 20, 2026
c89a163
[Docs] Describe the overlap narrowing switches and the write-guard re…
xnetcat Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 36 additions & 0 deletions docs/macos/configuration.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docs/sharpemu-gui-undocumented-env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ result filters, mutex warning sampling, and diagnostic selection.
| Group | Variables |
| --- | --- |
| Behavior switches | 19 |
| GPU and Vulkan | 61 |
| GPU and Vulkan | 63 |
| GnmMode | 4 (plus 2 shared switches listed below; trophy key also exposed in GUI) |
| Audio and video | 6 |
| Input | 5 |
Expand Down Expand Up @@ -235,11 +235,13 @@ These variables change the GPU path or the Vulkan presenter.
| `SHARPEMU_FORCE_TITLE_VERTEX_OUTPUTS_ONE` | `1` | Vertex export targets 32 to 35 write the vector (1, 1, 1, 1). This applies only to the vertex shader at guest address 0x0000000500780000. Default is off. | `Gen5SpirvTranslator.cs` |
| `SHARPEMU_GPU_BACKEND` | `vulkan` or `metal` | Optional assertion of the guest GPU backend. Each host has exactly one backend (Metal on macOS, Vulkan on Windows and Linux); any other value stops startup with an error. | `GuestGpu.cs` |
| `SHARPEMU_GPU_WAIT_SPIN_US` | number (microseconds) | Sets how long a wait for GPU work polls before it blocks. A short poll saves the wake-up delay when the GPU finishes soon. `0` blocks at once. The default is 150. | `GpuWaitSpin.cs` |
| `SHARPEMU_GRAPHICS_PIPELINE_LIBRARY` | `0` | `0` builds every graphics pipeline whole, with one descriptor set. By default, on a device that links `VK_EXT_graphics_pipeline_library` parts fast, the vertex input, vertex stage, pixel stage and color outputs compile once as separate parts and each pipeline links them: the vertex set is pushed, the bindless heap is set 1 and the pixel set comes from a descriptor pool. Render workers take pixel sets from their own pools, which return when the slice's submission completes. Enabling the extension changes the device, so the driver may compile every pipeline again after a change. | `VulkanVideoPresenter.PipelineLibraries.cs`, `VulkanVideoPresenter.Device.Setup.cs` |
| `SHARPEMU_GRAPHICS_SUBGROUPS` | `0` or `1` | Set `1` to use native Vulkan subgroup operations in graphics shaders. Set `0` to use the fallback path. When unset, the presenter uses them only if the subgroup size is 32 and the vertex and fragment stages support subgroups. | `VulkanVideoPresenter.cs`, `VulkanVideoPresenter.Device.Setup.cs` |
| `SHARPEMU_IMAGE_LOOKUP_MEMO` | `0` | `0` turns off the image lookup memo. The default keeps the result of each image lookup that found an image with the same backing, and gives it again for the same request until an image is registered or removed. | `GuestImageCache.Lookup.cs` |
| `SHARPEMU_OCCLUSION_GPU_DUMPS` | `0` | `0` turns off GPU copies of pending occlusion results. By default, later GPU buffer reads receive these results without waiting for CPU publication. Guest memory publication remains ordered in both modes. | `VulkanVideoPresenter.Occlusion.cs`, `VulkanOcclusionQueries.GpuResults.cs` |
| `SHARPEMU_MARK_PIXEL_PCS` | list of `pc:register` pairs | Makes the SPIR-V pixel shader write the float value 1.0 to a shader register when execution reaches the given instruction PC. Use decimal numbers, a register below 256, and a comma between pairs. It has an effect only for the shader address in `SHARPEMU_CAPTURE_PIXEL_VGPR_ADDRESS`. | `Gen5SpirvTranslator.cs` |
| `SHARPEMU_MAX_GUEST_WORK_PER_RENDER` | number | Sets the maximum number of guest command stream slices that the Vulkan presenter runs in one render pass. The default is 1024, or 256 on macOS. The value must be more than 0. | `VulkanVideoPresenter.cs`, `VulkanVideoPresenter.CommandStream.cs` |
| `SHARPEMU_READBACK_LINEAR_IMAGES` | `0` | `0` turns off the readback of linear images. By default, a linear storage image or color target that the GPU writes is copied back to guest memory when its work completes, so a CPU thread that waits for a GPU-filled image, such as an occlusion buffer whose sentinel it wrote, continues. An image is read back in the frame the GPU first writes it, and in the frame the CPU stores into it and the next one; an image only the GPU writes is not read back again every frame. A GnmMode target that is tiled in guest memory but laid out linear on the host is never read back, because its host bytes do not follow the guest's layout. The log names the first 16 images read back (`linear image readback`). | `VulkanVideoPresenter.Scheduler.cs`, `GuestImageCache.Tracking.cs`, `HostLayoutTargets.cs` |
| `SHARPEMU_RENDERDOC_CAPTURE_TIMEOUT_SECONDS` | number (seconds) | Set the maximum time for a RenderDoc frame capture. The emulator discards a capture that does not end in this time. The range is 1 to 120. The default is 15. | `RenderDocCapture.cs` |
| `SHARPEMU_RENDERDOC_DLL` | path | Set the path of the RenderDoc library file. The emulator tries this path first. When unset or when the load fails, it searches the default library name and the known install paths. | `RenderDocCapture.cs` |
| `SHARPEMU_RENDERDOC_WAIT` | number (seconds) or `enter` | Set to make the emulator wait before it starts Vulkan, so that you can attach RenderDoc. `enter` waits until you press Enter. A number waits that many seconds, from 1 to 300. Other text waits 15 seconds. | `VulkanVideoPresenter.Device.Setup.cs` |
Expand Down
1 change: 1 addition & 0 deletions scripts/ps5_names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115733,6 +115733,7 @@ _sceLibcFree
_sceLibcGetMallocParam
_sceLibcInitialize
_sceLibcInternal
_sceLibcInternalThreadAtexit
_sceLibcLockFinalize
_sceLibcLockInitialize
_sceLibcMalloc
Expand Down
3 changes: 3 additions & 0 deletions src/SharpEmu.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ private static readonly (string Name, string Value)[] ServerGarbageCollector =
("DOTNET_gcServer", "1"),
("DOTNET_GCHeapCount", "4"),
("DOTNET_GCNoAffinitize", "1"),
// Guest memory keeps the machine's memory load above the GC's high-memory thresholds, where it runs a blocking
// compacting generation-2 collection of most of a second every few seconds. The value is hexadecimal (99 percent).
("DOTNET_GCHighMemPercent", "63"),
];
private const int ATTACH_PARENT_PROCESS = -1;
private const int STD_INPUT_HANDLE = -10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,17 @@ private unsafe static bool TryResolveGpuFault(EXCEPTION_RECORD* exceptionRecord)
&& GuestGpuMemoryHook.TryResolveFault(kind, exceptionRecord->ExceptionInformation[1]);
}

private static readonly bool GuestAllocatorHoleRecoveryDisabled = string.Equals(
Environment.GetEnvironmentVariable("SHARPEMU_DISABLE_GUEST_ALLOCATOR_HOLE_RECOVERY"),
"1",
StringComparison.Ordinal);

private unsafe static bool TryRecoverGuestAllocatorHole(
EXCEPTION_RECORD* exceptionRecord,
void* contextRecord,
ulong rip)
{
if (string.Equals(
Environment.GetEnvironmentVariable("SHARPEMU_DISABLE_GUEST_ALLOCATOR_HOLE_RECOVERY"),
"1",
StringComparison.Ordinal) ||
if (GuestAllocatorHoleRecoveryDisabled ||
exceptionRecord->NumberParameters < 2 ||
exceptionRecord->ExceptionInformation[0] != 0 ||
exceptionRecord->ExceptionInformation[1] != 8 ||
Expand Down
46 changes: 36 additions & 10 deletions src/SharpEmu.Core/Cpu/Native/DirectExecutionBackend.FastPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,21 @@ void EmitRealtimeIntoStack()
return code;
}

/// <summary>
/// With r10 = cursor end minus cursor (bytes), leaves r10 = the available dwords exactly as
/// <c>AgcExports.GetRemainingCommandDwords</c> computes them before the reserve: the signed byte
/// distance divided by four (toward zero), truncated to 32 bits. An end below the cursor (a null
/// end) therefore still has room, as titles rely on. Uses r11; changes the flags.
/// </summary>
private static void EmitAgcAvailableDwords(List<byte> code)
{
code.AddRange([0x4D, 0x8D, 0x5A, 0x03]); // lea r11, [r10+3]
code.AddRange([0x4D, 0x85, 0xD2]); // test r10, r10
code.AddRange([0x4D, 0x0F, 0x48, 0xD3]); // cmovs r10, r11 a negative span rounds toward zero
code.AddRange([0x49, 0xC1, 0xFA, 0x02]); // sar r10, 2
code.AddRange([0x45, 0x89, 0xD2]); // mov r10d, r10d truncated to 32 bits
}

/// <summary>
/// An sceAgc builder that appends one fixed-shape packet, as guest-side code: with the command
/// buffer in RDI it reads the cursor, the end and the reserve, declines (jumps to the import's
Expand Down Expand Up @@ -708,11 +723,7 @@ void EmitBranchToSlowPath(byte shortOpcode)
Emit(0x48, 0x8B, 0x47, CursorUpOffset); // mov rax, [rdi+0x10] cursor
Emit(0x4C, 0x8B, 0x57, CursorDownOffset); // mov r10, [rdi+0x18] end
Emit(0x49, 0x29, 0xC2); // sub r10, rax
EmitBranchToSlowPath(0x72); // jb slow: end below the cursor
Emit(0x49, 0xC1, 0xEA, 0x02); // shr r10, 2 available dwords
Emit(0x41, 0xBB); EmitImm32(0xFFFF_FFFFu); // mov r11d, 0xFFFFFFFF
Emit(0x4D, 0x39, 0xDA); // cmp r10, r11
EmitBranchToSlowPath(0x77); // ja slow: the export clamps the span to 32 bits
EmitAgcAvailableDwords(code); // r10 = available dwords, as the export truncates them
Emit(0x44, 0x8B, 0x5F, ReservedDwordsOffset); // mov r11d, [rdi+0x30] reserve
Emit(0x49, 0x83, 0xC3, checked((byte)spec.SizeDwords)); // add r11, size
Emit(0x4D, 0x39, 0xDA); // cmp r10, r11
Expand Down Expand Up @@ -761,6 +772,20 @@ void EmitModifierSlot(SharpEmu.Libs.Agc.AgcModifierSgprSlot slot)
Emit(0xF7, (byte)(0xC0 | (source & 7))); EmitImm32(slot.EnableMask);
Emit(0x74, 0);
var disabledFixup = code.Count - 1;
var vgprFixup = -1;
if (slot.DisableMask != 0)
{
// test reg32, disableMask / jnz disabled (the values come in VGPRs: no slot)
if (source >= 8)
{
Emit(0x41);
}

Emit(0xF7, (byte)(0xC0 | (source & 7))); EmitImm32(slot.DisableMask);
Emit(0x75, 0);
vgprFixup = code.Count - 1;
}

if (slot.FieldShift < 0)
{
Emit(0x41, 0xBA); EmitImm32(1); // mov r10d, 1
Expand All @@ -786,6 +811,11 @@ void EmitModifierSlot(SharpEmu.Libs.Agc.AgcModifierSgprSlot slot)

Emit(0xEB, 0x06); // jmp done
code[disabledFixup] = checked((byte)(code.Count - (disabledFixup + 1)));
if (vgprFixup >= 0)
{
code[vgprFixup] = checked((byte)(code.Count - (vgprFixup + 1)));
}

Emit(0x41, 0xBA); EmitImm32(slot.Disabled); // disabled: mov r10d, imm32
if (slot.ShiftLeft != 0)
{
Expand Down Expand Up @@ -996,11 +1026,7 @@ void EmitLoopBack(int target)
Emit(0x48, 0x8B, 0x47, CursorUpOffset); // mov rax, [rdi+0x10] cursor
Emit(0x4C, 0x8B, 0x57, CursorDownOffset); // mov r10, [rdi+0x18] end
Emit(0x49, 0x29, 0xC2); // sub r10, rax
EmitBranchToSlowPath(0x72); // jb slow
Emit(0x49, 0xC1, 0xEA, 0x02); // shr r10, 2 available dwords
Emit(0x41, 0xBB); EmitImm32(0xFFFF_FFFFu); // mov r11d, 0xFFFFFFFF
Emit(0x4D, 0x39, 0xDA); // cmp r10, r11
EmitBranchToSlowPath(0x77); // ja slow
EmitAgcAvailableDwords(code); // r10 = available dwords, as the export truncates them
Emit(0x44, 0x8B, 0x5F, ReservedDwordsOffset); // mov r11d, [rdi+0x30] reserve
if (range)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,12 @@ private bool ShouldLogImportResult(in ImportStubEntry entry, OrbisGen2Result res
// and deciding used to cost thirteen eagerly evaluated string comparisons
// against the NID. The one code each of those imports expects is resolved
// at stub setup, so the decision is now a single integer compare.
if (resultValue != entry.ExpectedBenignResult)
// sceSaveDataConvert reports a save directory that is missing or already in the current format; titles
// then mount it as usual. Two codes, so it stays outside the one-code table; the code is compared first.
var expectedSaveDataNoConversion =
(resultValue == unchecked((int)0x809F0008) || resultValue == unchecked((int)0x809F001E)) &&
string.Equals(nid, "2mfSRGdshtk", StringComparison.Ordinal);
if (resultValue != entry.ExpectedBenignResult && !expectedSaveDataNoConversion)
{
return ShouldSampleImportResult(nid, resultValue, out mutexOccurrence);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpEmu.Core/Loader/GuestRedZonePatcher.Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SharpEmu.Core.Loader;

internal static partial class GuestRedZonePatcher
{
private const int PatchCacheVersion = 1;
private const int PatchCacheVersion = 2;
private const int MaximumPatchCacheBytes = 32 << 20;
private sealed record CachedSite(ulong Offset, int Length, bool TerminalBranch);
private sealed record CachedPlan(int Version, string Key, PatchResult Scan, CachedSite[] Sites);
Expand Down
Loading
Loading