fix(runtime): isolate host worker MXCSR #7622
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7622"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:41:21Z.
What
Starts AnyPS5-owned native workers with host MXCSR 0x1f80 before their tasks. Linux threads created from guest execution contexts can otherwise inherit guest MXCSR 0x9fc0 and its FTZ/DAZ settings. The change covers current-main std::thread and std::jthread workers across runtime, AGC, VideoOut, shader cache, AvPlayer and libkernel code, the shader-registration pthread trampoline, and both Windows crash-diagnostic thread entrypoints. The focused helpers preserve the caller's MXCSR. Guest pthread execution remains governed by its separate guest-entry logic in #7565; this follows up on the host-worker question in #7594.
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:00:31Z.
Latest hosted run: conventions, eligibility, report, Linux/macOS Debug+Release register-context, Linux/macOS/Windows relinker, relinker ASAN, and both macOS write-watch jobs pass. The workflow skipped the full Linux and Windows app suites, so those results are not covered by this run.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T18:23:14Z.
Thanks for the jthread coverage, that part looks right. Full CI on f2a3f97021 fails to build on Linux and Windows at the shader disk cache key check:
Could you add
HostThread.hpptoshaderCacheKeySources(ShaderCacheVersion.cmake)?Two small optional extras while you're there: the
RefreshPoolmirror-refresh helpers (GuestBufferMemory.cpp) still start without the reset (no float math, so not required), and a debt line noting that threads started by third-party code while on a guest thread (SDL audio, driver-internal threads) still inherit guest MXCSR on Linux would make the boundary explicit.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:28:36Z.
Windows build of
f2a3f9702onmainc3591adf9(clean merge), WinLibs GCC 15.2.0 r7, Release,BUILD_TESTING=ON. It fails in two places:The shader cache key check stops the build:
This check runs on every host, so it probably fails on Linux as well once the project is configured.
host_thread_mxcsr_testsdoes not link with MinGW:The other executables in that block link a target that brings the runtime in.
host_thread_local_testslinkshost_thread_local_test_library, andwindows_backtrace_report_testslinkslibc. The new one links nothing.I didn't get further, so the MXCSR test itself has not run on Windows.
AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:34:26Z.
@MarcZX100 I followed up on both Windows failures. With the two changes below on
f2a3f9702(merged ontomainc3591adf9, together with #7629, #7630 and #7627), the full build succeeds and the new test passes.HostThread.hppadded toshaderCacheKeySources, next toHostThreadLocal.hpp.ANYPS5_MINGW_DWARF_EXCEPTIONS).__gxx_personality_v0then comes from AnyPS5'slibc(exception/Personality.cpp), not from MinGW'slibstdc++. A manualg++link of the two objects with the default-lstdc++fails the same way. So the test linkslibc, aswindows_backtrace_report_testsdoes, and on Windows gets thePATHto it like the otherlibctests.Results, Radeon 860M, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON:host_thread_mxcsrandhost_thread_localpass, 3 runs of 3.agc_*test on that build: 719 of 722 pass. The 3 failures don't come from this PR:agc_driver_depth_bounds_stateis #7627's missing WindowsPATH, andagc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gplfail the same way onmainhere.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:43:49Z.
Pushed
7aec3f58fto address the two reported build failures:HostThread.hppto the shader disk cache key inputs.host_thread_mxcsr_testswithlibcand prepend its directory toPATHon Windows.The changes match the focused patch reported by LeandroLP23. Their independent Windows 11 26300 / Radeon 860M / WinLibs GCC 15.2.0 Release run reports
host_thread_mxcsrandhost_thread_localpassing 3/3 each, and the full build succeeding. That run was on an equivalent merged tree before this commit; it has not yet run against this exact head.Local
git diff --checkpasses. The local conventions checker reports seven pre-existing baseline findings (one silent stub and six old revert subjects); no finding points to these two CMake edits. This host's full build remains blocked by the unrelated GCC dependent-template error inSrtDescriptorEvaluation.cpp. The prior PR CI had full Linux and Windows jobs skipped, so those are not presented as validation of this head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:54:50Z.
The updated head
7aec3f58fnow has green conventions, eligibility, report, register-context (Ubuntu Debug/Release and macOS Intel Debug/Release), relinker (Linux, Windows, macOS arm64/x86_64, ASan), and write-watch (macOS arm64/Intel) checks. Full Linux/Windows builds were skipped by path policy. The independent Radeon 860M run remains evidence from an equivalent merged tree before this exact head, as described above.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:37:16Z.
Review: COMMENTED
Checked the new test on macOS (x86-64 under Rosetta 2), head
7aec3f58f. Apple M2 Max, macOS 27.2, Apple clang 21. The full x86-64 tree from this head configures on macOS butlibcdoes not compile there (CLOCK_REALTIME_COARSE,st_mtiminGeneral.cpp; #7332 covers that), so I builtcore/libs/tests/HostThreadMxcsr.cppwith the PR'sHostThread.hppon its own (clang++ -arch x86_64 -std=c++20 -O2). The arm64 build does not includecore/libs.On macOS the test does not catch a missing reset:
SetHostMxcsr()calls removed fromStartHostThreadandStartHostJThread: also passes 5/5.0x9fc0instead of0x1f80, it throws as expected, so the check itself works.Under Rosetta 2 a new thread starts with the default MXCSR and does not inherit the creator's FTZ/DAZ. A plain probe shows the same for
std::threadandpthread_create: the caller is at0x9fc0, the new thread reads0x1f80(3/3). I have no Intel Mac to check native x86-64.So the inheritance this PR fixes does not happen here. On macOS the reset changes nothing for new threads, and
host_thread_mxcsronly works as a regression test on Linux. It may be worth saying that in Tested, or showing it failing on Linux without the reset.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:52:30Z.
Review: COMMENTED
Linux follow-up to my macOS note above: a full Linux build and suite run of
7aec3f58f, plus the mutation I suggested there. The hosted run skipped the Linux app suite, and the Linux runs so far covered only the focused test. On Linux the test does catch a missing reset.Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
7aec3f58fmerged ontomaina373e85e5(clean merge). Same commands on plainmainfor the baseline.f2a3f9702.host_thread_mxcsrandhost_thread_localpass 20/20 with--repeat until-fail:20. The 28 tests matchinghost_thread|pthread|mxcsrpass.ctest -E "^agc|gpu|vulkan|video_out" -j7): 745/746. The new test brings the count to 746, andmainis 745/745. The one failure waspr_overlap_tools. That test only exercisestools/pr_overlap.py, which this PR doesn't touch. It passed 3/3 on its own in the same merged tree, so I read it as a flake under-j7.VK_DRIVER_FILESpointing only atlvp_icd.json;ctest -R "^agc" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64" -j4): 732/732 with 50 skipped, the same asmain.SetHostMxcsr()emptied,host_thread_mxcsrfails 3/3 witha host worker inherited guest MXCSR. So on Linux a plainstd::threadstarted from a thread at 0x9fc0 really starts at 0x9fc0, unlike under Rosetta 2, and the test catches it.core(without tests,3rdpartyand the relinker) for workers that are still started directly. There is one:RefreshPoolinlibSceAgcDriver/Graphics/src/GuestBufferMemory.cpp(threads.emplace_back([this](std::stop_token token) { ... }), the mirror refresh helpers,std::vector<std::jthread>). It is created lazily byRefreshPool::Get(), so it inherits whatever MXCSR the first caller has. Its helpers onlymemcmp/memcpyblocks, so FTZ/DAZ has no effect on them today. It is the only launch I found outside the helpers, in case you want the coverage to be complete.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T07:24:45Z.
Rebase handoff, with one test-fixture extension — rebased onto current
main(all three commits, authorship unchanged). The conflict in the recompiler CMakeLists keptmain's dedup machinery plus yourHostThread.hppkey source — and theshader_cache_runtime_sourcestest fixture needed the matchingHostThread.hppstub added (it only createdHostThreadLocal.hpp, so the new key source made its configure step fail). Both included.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; the shader-cache runtime-sources test passes; full suite green apart from the four knownmainregressions (agc_driver_tessellation— Mesa #5444;agc_driver_bda_device— #7584;agc_driver_image_table_vouched_lookups— #7766;agc_driver_guest_memory_lifetime— #7784, which I bisected today to16473dbbein the #6499 family), none from this PR.To pick it up:
Head is
398b2576c.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T07:47:58Z.
@blawesom thanks for carrying this across the conflict. The CMake resolution is the right one: it keeps main's compiled-sources dedup and appends
HostThread.hpptoshaderCacheKeySources, whichShaderCacheVersion.cmakestill requires becauseShaderDiskCache.cppincludes it. The first two commits come through unchanged.One thing is missing from the pushed branch:
rebase/7622at398b2576cdoesn't contain theshader_cache_runtime_sourcesfixture stub. The last commit only touches the two CMakeLists files, andtools/tests/test_shader_cache_runtime_sources.pystill only writesHostThreadLocal.hpp. On398b2576cthat test fails at the fixture configure ("Shader disk cache key source does not exist", 11 failures). With this line added after theHostThreadLocal.hppwrite, it passes:My guess is that it's still uncommitted on your side. Could you push it to
rebase/7622?@MarcZX10 the
--ff-onlypickup won't work because this is a real rebase:398b2576cdoesn't contain your current head7aec3f58f. Once the stub is on blawesom's branch, adopting it would be:If you'd rather not force-push, merging
maininto your branch works too: it's the same single conflict incore/shader/recompiler/CMakeLists.txt, resolved the same way, plus the fixture line above. Either way, we'll run full CI on the new head before it goes on.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:00:02Z.
Thanks for catching this fixture omission. I verified the current PR head
597498066e15a50d38a94f827e61eb8c15cc1834includes theHostThread.hppfixture stub (FixtureHostThread) intools/tests/test_shader_cache_runtime_sources.py. The current-head workflow checks are all successful, including the relinker matrix; Linux/Windows full Build jobs are skipped by the workflow. The fixture fix is present in the latest commit.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T10:07:15Z.
Thanks for spotting the remaining direct
std::jthreadlaunch inRefreshPool. I now start those mirror-refresh helpers withLibc::StartHostJThread, preserving the stop-token callback and CPU pinning while setting the host MXCSR first. The workers currently only compare/copy bytes, but this makes the worker initialization invariant complete.\n\nI also merged currentmain, retaining its screenshot-aware frame-dump behavior while keepingLibc::StartHostThread. Validation on the updated tree:GuestBufferMemory.cppandVulkanDevice.cppcompile with the existing GCC 12 Release flags;HostThreadMxcsrwas freshly compiled and passed; conventions andgit diff --checkpass. Full platform CI is running for the updated head.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T14:05:00Z.
Windows check of
50c1efcf5, stacked with #7594 (9ebc10733) onmain1d4164552(clean merge; also merges cleanly ontod50ec76da).Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (driver 596.21), Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
BUILD_TESTING=ON. Built the named test targets,relinkerandlibs(not the fullalltarget). Thelibclink ofhost_thread_mxcsr_testsand the shader-cache key check both pass now.Tests
host_thread_mxcsr,host_thread_local,guest_pthread_startandguest_pthread_frame_chain: 3/3 each.shader_cache_runtime_sources, run directly:Ran 9 tests in 211.373s OK. Through ctest it hits its 180 s limit on my loaded host, and under load the fixture's 15 scmakeconfigure also times out.Negative control: the test does not detect the regression on Windows. I made
SetHostMxcsr()a no-op in the tree, so the helpers behave like a plainstd::thread, and rebuilthost_thread_mxcsr_tests: it still passes 3/3. A small probe shows why. With the caller at0x9fc0, a newstd::threadand a newCreateThreadthread both start at0x1f80, because Windows does not inherit MXCSR into new threads. So on Windows this PR changes no worker's MXCSR, and the test only guards Linux. That fits the PR description, but a reviewer reading the Windows CI result should know the test passes there either way.In running titles, I read
CONTEXT.MxCsrfrom every thread at 15 s and 40 s. With both PRs, the only FTZ/DAZ thread in Showcase (PPSA99005, 1 of 53) and Ping Pong (PPSA28319, 1 of 107) is the guest main thread (0x9fe1). Every host worker reads0x1f80plus sticky flags, the same as onmain. Four titles ran 60 s each, main vs PR: no new stop line, and noFAIL:,FATAL:orwhat(). RetroArch PPSA99169 ran 6 interleaved runs per side; details are in my #7594 comment.Two host workers are still unwrapped. They landed on
mainafter this PR was written:PerformanceTrace.hpp:347(worker = std::thread([this] { run(); });) andlibSceVideoOut/src/Telemetry.cpp:92(thread = std::jthread(...)). Both are diagnostic-only and matter only on Linux, but they are the same pattern.check_conventions.py --base origin/mainpasses andgit diff --checkis clean.Not checked: Linux (where the change has an effect), macOS, the full test suite and GPU tests.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-20T16:59:17Z.
First AMD-on-Linux (RADV) run of this PR. Head
50c1efcf5merged ontomain6bef96df7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at1736a3788: 1713/1714 with this PR, against 1712/1713 onmain. The one failure is the same on both, so this PR adds none:agc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: the PR's new entry,host_thread_mxcsr, runs and passes. No other entry is added, and none is skipped or removed. I also ranhost_thread_mxcsron its own with the Khronos validation layer: it passes and reports no VUID.GPUs tested: n/a (runtime change; suite run on the machine above)
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:48:06Z.
Thanks for the full RADV suite comparison. The PR adds the
host_thread_mxcsrentry and passes it with no validation-layer VUID; the one full-suite failure is also present on main, so your run shows no additional failure from this change on that setup.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:59:01Z.
@MarcZX10 thanks,
StartHostThread/StartHostJThreadcover the driver workers we were worried about, andHostThreadMxcsrpins the reset. We're testing this together with #7565, #7594 and #7532 on one tree. Four host threads on that tree still start with a plainstd::thread/std::jthread, so on Linux they inherit the creator's MXCSR:core/libs/prx/libc/src/Process.cpp(the exit drain thread)core/libs/prx/libSceVideoOut/src/Telemetry.cpp(the writerjthread)core/libs/prx/libSceAgcDriver/Execution/include/PerformanceTrace.hpp(TraceBenchWriter)core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp(the GPU progress watcher)None of them does much floating-point work, but switching them to the wrappers would make "every host worker starts at 0x1f80" true without exceptions. Could you include them here?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:01Z.
Review: COMMENTED
Replies checked — two re-added lines confirmed, library-portability fails on wasm64
The head re-adds two lines that main removed from
FrameDumpWriter::Enqueue, and the hosted library-portability job fails to compileHostThread.hppunder the wasm64 build.What I ran
b2a3a59a2370b899b3fda719d211bfba6723ef64(OPEN, unchanged from batch).gh apicomments and reviews on #7622, newer than 2026-10-30T01:32:26Z, excluding MarcZX10 and bots.gh pr view 7622 --json statusCheckRollup;gh api repos/boykopovar/AnyPS5/actions/jobs/124716526222/logs(saved and grepped).git show b2a3a59a:core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppand.../libc/include/HostThread.hpp; the same file on upstream/main.git merge-tree --write-tree upstream/main b2a3a59a(exit 0).Results
merge-treevs upstream/mainlibrary-portability(hosted)HostThread.hpp:15linuxSKIPPEDFindings
require(pixels.size() <= maxBytes - queuedBytes, ...)andif (!frameDumpOutput.Enabled_nid_no_patch()) return;are present after the wait atVulkanDevice.cppL263-L264. Main has neither there. Confirmed. With L264 in place, a screenshot is dropped when frame-dump output is off, because L259 exempts screenshots and L264 does not. Answer needed: remove both lines, so the hunk only changesstd::threadtoLibc::StartHostThread.library-portability: the job fails compilingFileEvent.cpp, which includesHostThread.hpp, withuse of undeclared identifier '_mm_setcsr'at L15 (SetHostMxcsr, L14-L16). The wasm64 target has no SSE intrinsics. Answer needed: guardSetHostMxcsrfor x86 only, or make the header x86-only.Sources
github.com/boykopovar/AnyPS5@b2a3a59a23/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp (L259-L264)github.com/boykopovar/AnyPS5@b2a3a59a23/core/libs/prx/libc/include/HostThread.hpp (L14-L16)Not verified