Repository navigation
Conversation
… skip stub-written buffers The cursor-advancing native stubs (fixed packets, sceAgcCbSetShRegisterRangeDirect, sceAgcCbSetShRegistersDirect; upstream #1196) append in guest context without the stripe lock or the writer table that upstream 99f9fe9 added. A buffer written only through them has no writer, or a stale one, so a Push/PopMarker from another guest thread was not skipped and reserved space at the cursor the stub was about to store past. Each such stub now stores (buffer, guest TLS base from the host TLS slot) in a host table after its stores (one cache line per slot, 9 instructions, no branch). A marker refuses a buffer whose slot names another thread (logged, counted); an ordinary export clears the slot as it takes the buffer over. SHARPEMU_AGC_STUB_WRITER=0 turns it off. Tests: the marker decision (red without the AgcExports check), the emitted record decoded on any host, and on x64 the stubs leaving the record (red without it).
📦 Build artifacts —
|
| Platform | Download |
|---|---|
| macOS (osx-x64) | sharpemu-osx-x64-e24f1a8 |
| macOS app bundle (osx-x64) | sharpemu-osx-x64-app-e24f1a8 |
From build run #573. Downloads require a GitHub login and expire after 90 days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting
Please read our contribution guidelines before opening a pull request:
➡️ CONTRIBUTING.md
By opening this pull request, you confirm that you have read and agree to follow the contribution guidelines.
Upstream 99f9fe9 (merged here in the 2026-11-21 sync) serializes HLE appends to one AGC command buffer under a striped lock and remembers each buffer's last ordinary writer, so a Push/PopMarker from another guest thread is skipped instead of reserving space inside the writer's packet. The native packet stubs from upstream #1196 (identical in this fork) append in guest context: the fixed-packet stubs (register direct and indirect setters, index setters, DrawIndexAuto, DrawIndexOffset, DrawIndex, DrawIndexIndirect, DrawIndirect, CbDispatch), sceAgcCbSetShRegisterRangeDirect and sceAgcCbSetShRegistersDirect advance the cursor themselves, take no lock and never reach the writer table. A buffer written only through them has no writer, or a stale one naming the marker's thread, so that marker was not skipped. The patcher, payload-address and CreatePrimState stubs do not move a cursor and are unchanged.
Each cursor-advancing stub now records (buffer, guest TLS base read from the host TLS slot the backend binds per guest thread) in a 256-slot host table, one cache line per slot, after its stores: 9 instructions, no branch. A marker refuses a buffer whose slot names another thread (logged for the first 4, counted); an ordinary export clears the slot when it takes the buffer over, as it already takes over from an export writer. Ordinary appends racing each other are not changed: the console's builders are lock-free guest code, so that would be a race in the game itself.
SHARPEMU_AGC_STUB_WRITER=0turns the record off (documented in docs/macos/configuration.md).Testing
No game was run. The cost on the Demon's Souls hot path has not been measured.
AgcCommandBufferConcurrencyTests.PushMarker_FromAnotherThread_IsSkippedOnABufferANativeStubWroteLastcovers a stub-only buffer, the writer's own marker, a handoff through an ordinary export, and a stale writer table. It fails without the AgcExports check (thread B's marker lands at the cursor A's stub just published) and passes with it.AgcPacketStubTests.TheWriterRecordIsTheTableStoreOfTheCallingThreadsTlsBaseBeforeTheFastPathReturnsdecodes the emitted record and checks that it comes before every fast-path ret of the three stub kinds. It runs on any host.AgcPacketStubTests.ACursorAdvancingStubRecordsItsBufferAndTheCallingThreadInTheWriterTableruns only on an x64 testhost. It executes the stubs and checks the table slot, and fails when the record is not emitted.dotnet test SharpEmu.slnx -c Releaseon arm64: 0 failed. x64 (Rosetta) Libs subset Cpu|Kernel|Pthread|Loader|Agc: 3642 passed, 1 failed (GuestTsc_ReadAndFrequencyDescribeTheSameClock, a clock-ratio timing test that measured 1.18 under load). It passed 5 of 5 times run alone.uvx reuse lintpasses.Checklist
By submitting this pull request, you confirm that:
CONTRIBUTING.md.N/A.N/A).