Consolidated Stability, Graphics, Audio and Memory Fixes (71 PRs) #2465
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2465
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2465/head"
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?
@RecknockT on GitHub · 2026-11-20 17:37 UTC · original
RecknockT:master→main· +60637 −21340 · 198 files · 344 commits · closed without mergingOverview
This consolidated pull request bundles and resolves 71 open community improvements, bug fixes, and performance optimizations that have been vetted, conflict-resolved, and verified on modern Windows/Vulkan environments (including games like ASTRO BOT, GTA V, Demon's Souls, Uncharted, and Call of Duty: BO2).
All changes have been cleanly integrated into a single cohesive branch without regressions, adapting legacy PRs to the latest upstream codebase.
🎮 Major Subsystems & Highlights
1. Graphics, Shaders & Texture Cache
2. Kernel, Concurrencia & Memoria
3. Audio & Video Playback
4. Filesystem, Libs & OS Integration
:,<,>, etc.) in guest save filenames so games like Arcade Spirits can create and load save data (#907).getenv/setenv(#2452),getpeername/sceNetGetpeername(#2129),sceHttp2AbortRequest(#2139), and 14Agc::GetSizeentrypoints (#2441).🧪 Verification
clang-cl(C++20) + Ninja on Windows 11.Only /app0/sce_module/libc.prx was loaded automatically. Other bundled modules the executable imports from, such as libSceNpCppWebApi.prx in Astro Bot (PPSA21564), were never loaded unless the game requested them, so their functions were bound to stubs returning 0 ("Unresolved import stub called: ...[NpCppWebApi_v1]"). Load sce_module/<module name>.prx for every module the executable imports, next to libc, and start them after libc. A bundled PRX is named after the module it exports (libc.prx exports libc, libSceNpCppWebApi.prx exports libSceNpCppWebApi). HLE symbols still take precedence when resolving.With the console language set to Chinese, some in-game text showed up as "??". This is not an encoding bug: libFont draws '?' on purpose for any character it cannot find in the font. Root cause: - The game opens the PS5 system font sets (SC/TC/JP/KR) through FontOpenFontSet. Those fonts don't exist on the host, so libFont falls back to Roboto (3rdparty/tracy), which only has Latin glyphs. - stb_supported_codepoint() replaced every code point missing from the font with '?'. - The font format check only accepted .ttf/.otf, so TrueType collections (.ttc), which most Windows CJK fonts are (e.g. msyh.ttc), were rejected. - FontGetKerning() returned FONT_ERROR_NO_SUPPORT_CODE for any character missing from the primary face, including CJK characters. The system overlay already merges a per-language CJK font through AddSystemFontFallbacks(), so it is not changed here. Changes: - Add Common::FindCjkFontFiles(locale) (src/common/systemFonts.{h,cpp}). It tries KYTY_CJK_FONT first, then the installed system CJK fonts, ordered by the console locale so shared Han characters use the regional glyph forms: zh-Hans prefers Microsoft YaHei, zh-Hant Microsoft JhengHei, ja-JP Yu Gothic/Meiryo, ko-KR Malgun Gothic. macOS (PingFang, Hiragino, Apple SD Gothic Neo) and Linux (Noto Sans CJK, WenQuanYi, Droid Sans Fallback) paths are included too. - libFont: accept .ttc files and load face 0 through stbtt_GetFontOffsetForIndex(). - libFont: add resolve_stb_glyph(), which picks the face per character: the font's own face first, then the host CJK fallback, and '?' only if neither has the glyph. Glyph metrics and bitmaps are computed with the face that was actually picked, using its own em scale. - libFont: FontGetKerning() returns OK with zero kerning when a character is drawn from the CJK fallback face, instead of FONT_ERROR_NO_SUPPORT_CODE. - libFont: log which CJK fallback font is used, or warn when none is found. Testing: this is the same change, on the same base commit (1a053f9e), that was built successfully and verified in Astro Bot with the console language set to Chinese: text that used to show as "??" renders correctly. This checkout has not been built or tested separately.906d2556into shader/cmp-class-ranges 53ee5f392fTrails in the Sky 1st Chapter stopped at startup with "unsupported sampler control: 0x10000009". That control is the sampler voice peak meter (SamplerVoicePeakMeterParam {enableFlag, reserved}), which comes after setup, waveform blocks/address/offset, exit loop, pitch, envelope, distortion and user FX in the sampler control order; the controls already handled (0, 1, 4, 5, 0xa) match that order. While the meter is enabled, each render records the largest absolute sample of the voice after its filters, and the sampler voice state reports it as peak_height. It is 0 while the meter is off or the voice renders nothing. The rack's peak-meter block count is not used: the peak covers only the last render. The game now runs past startup at a steady 60 fps in a 90-second run. TestPeakMeter covers enabling, per-render peaks, running out of data and disabling. Co-Authored-By: Claude Opus 5.5 <[email protected]>589bd14a9into fix/guest-reserve-retry d5c9575cfe8dbee8635) into shader/minmax-int-order 21b1a57dc2Kyty does not draw message dialogs, so a game's error message stayed invisible. Ghost of Yotei opens one ("Unable to launch: missing base entitlement") and then waits behind its loading spinner. Co-Authored-By: Claude Opus 5.5 <[email protected]>ImageSubresources ordered {levels, layers} lexicographically, so the texture cache treated 11 levels x 1 layer as covering 9 levels x 2 layers. ResolveOverlap then skipped the growth branch and exited with "unresolvable equal-address image overlap" (#774), and the depth overlap and FindImage checks kept a backing that lacked a requested layer. Replace the order with Contains, true only when both the level and the layer counts cover the request. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit f255e675bc2ed3372fdf4e943781dd1faab581ce) (cherry picked from commit 4297034a5f4193d7305dd25568abb0db8f283d57)Draws bind the same ranges again and again, unchanged. In a 60-frame capture of the memory tracker calls in Demon's Souls' heaviest outdoor area, the GPU thread made about 33,000 ForEachUploadRange calls a frame. Most of them repeated an identical call with no state change in the range's 4 MiB regions in between. One 112 MiB buffer that dispatches bind as writable was marked GPU-dirty again about 1,700 times a frame, each time walking 28 regions under their locks. Each tracker region now counts the changes of its dirty bits (a generation, bumped under its lock). ForEachUploadRange remembers per thread the sum of its range's region generations as it leaves them. An identical later call with the same sum would find nothing to upload and change nothing, so it only runs the upload callback. Generations only grow, so an equal sum means no region changed. Replaying the capture against the tracker with real page protection and upload copies (a replay tool kept out of this change), three runs of each build on an i7-14700KF: before after GPU thread's tracker calls 2.83-2.87 ms 1.53-1.56 ms a frame whole replay 4.32-4.38 ms 2.97-3.05 ms a frame Both builds upload the same 22.8 MiB a frame and make the same 2,769 protection calls a frame, with equal checksums over every upload range and protection change. TestRepeatedUploadSkip covers CPU writes, GPU unmarks, downloads and a new tracker over the same range; removing the bump in ChangeState fails it.@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original · edited 2026-11-21 00:01 UTC
Walkthrough
The pull request updates build workflows and adds configuration options. It changes GPU submission, cache synchronization, image handling, shader compilation, memory mapping, and guest-library behavior. It also adds host file and font support, loader and pthread changes, and new tests across these areas.
Suggested reviewers:
nmzik,mrbigbritchesChange: Bug fix
Pre-merge checks:
4
Full details: Title check
Explanation
The title, "Consolidated Stability, Graphics, Audio and Memory Fixes (71 PRs)", is partially related to the changeset. It names real areas the changes touch: graphics, audio, memory, and stability fixes. It is overly broad, though. It does not name the main changes, and the changeset also covers filesystem, libc, network, shader recompiler, and kernel work. It does not describe a single primary change.
Full details: Description check
Explanation
The description lists the bundled improvements by subsystem, including HTile and depth handling, texture cache, shader recompiler, kernel and memory, AvPlayer video decode, AudioOut2 and NGS2, Windows filename encoding, CJK fonts, libc, network, and Agc entrypoints. These match the file changes in the raw summary. It also gives verification notes. The description is related to the changeset.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@ -357,2 +370,3 @@const auto source_aspect =FullAspectMask(source.backing.format) & ~vk::ImageAspectFlagBits::eStencil;stencil ? vk::ImageAspectFlags {vk::ImageAspectFlagBits::eStencil}: FullAspectMask(source.backing.format) & ~vk::ImageAspectFlagBits::eStencil;@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Preserve stencil in default copies of S8 images.
When both images use
eS8Uint,TextureCache::CopyImageselects the direct path and calls this function withstencil=false. Lines 372 and 375 then remove the only available aspect. The copy regions select no stencil data, so the copy cannot preserve the image contents. Vulkan requires the regions to specify image aspects. (docs.vulkan.org)Use
PrimaryAspectfor both default selectors. This preserves stencil-only copies and keeps the existing color and depth behavior.@ -76,0 +124,4 @@::fflush(stdout);if (window != nullptr) {SDL_SetWindowTitle(window, ("Kyty - " + text).c_str());@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Keep window-title updates on the main thread.
Both warm-up passes call
ReportShaderProgressfrom helper threads.ParallelForjoins those helpers before returning. (raw.githubusercontent.com)SDL requires
SDL_SetWindowTitleto run on the main thread. (raw.githubusercontent.com) On Windows, the backend callsSetWindowText, which sends a synchronous window message. A helper can wait for the window thread while holdingprogress_mutex. If the main thread waits for that mutex or joins the helper, warm-up cannot finish. (raw.githubusercontent.com)Keep helper progress updates console-only. Set the window title before and after the parallel passes, or update it through a main-thread progress loop.
@ -1005,1 +1088,4 @@state.ps_input_info.ps_sample_mask_export_enable);// In place: the guest converts its depth buffer into a color view of the same memory. Finding// the color image replaces the depth image with a copy of its data, which is the whole copy.if (color.desc.info.data.address == depth.desc.info.data.address) {@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Check subresource identity before skipping the copy.
The same base address can contain different selected array layers. With depth layer 1 selected and color layer 0 selected, both one-layer views pass the guards above.
FindImagepreserves corresponding layers during replacement; it does not copy depth layer 1 into color layer 0. This branch then returns without that transfer. (raw.githubusercontent.com)Limit this shortcut to the same physical subresource. For different layers, preserve the source and perform the selected-layer copy.
@ -79,1 +79,3 @@{Prospero::BufferFormat::k9_9_9_5Float, vk::Format::eE5B9G9R9UfloatPack32},// RGB9E5 is not renderable on NVIDIA; B10G11R11 is a renderable 32-bit HDR stand-in.// Guest-uploaded RGB9E5 texel data will decode wrong; add a shader-side pack if colors break.{Prospero::BufferFormat::k9_9_9_5Float, vk::Format::eB10G11R11UfloatPack32},@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Guest RGB9E5 textures will sample with wrong colors.
The lookup maps
k9_9_9_5FloattoeB10G11R11UfloatPack32for every caller. Guest RGB9E5 texel data is not converted, so it can be interpreted as B10G11R11 during sampling. This affects sampled-only textures, not only render targets. The code comment already states this decode mismatch.Preserve the guest RGB9E5 meaning for uploads. Either convert the texel data to the host format before upload, or keep the native
eE5B9G9R9UfloatPack32format for guest uploads and use the B10G11R11 substitute only for render targets. The inspected source does not establish which option fits the renderer, so no code change is proposed here.@ -349,1 +347,3 @@inline constexpr uint32_t ImageHeapKindShift = 20u;inline constexpr uint32_t ImageHeapSet = 1u;inline constexpr uint32_t ImageHeapKindShift = 20u;inline constexpr uint32_t ImageHeapCapacity = 1u << ImageHeapKindShift;@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Keep heap descriptor capacity within device limits.
This changes the allocated heap from 65,536 to 1,048,576 descriptors. On a device with a 500,000-descriptor limit,
ImageHeapnow exits during unconditionalRenderContextconstruction, before any guest image is allocated. The former capacity passed this check. Vulkan permits that device limit. (raw.githubusercontent.com)Separate the resident descriptor capacity from the 20-bit encoding capacity. Use a device-supported capacity consistently for host allocation and emitted image arrays.
@ -229,6 +294,7 @@ void KernelEventFlagPrivate::Cancel(uint64_t bits, int* num_waiting_threads) {while (m_waiting_threads > 0) {m_mutex.Unlock();Common::Thread::SleepMicro(10);LibKernel::KernelDispatchPendingSignalForCurrentThread();@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Nested
SetorClearfrom a signal handler can deadlockCancel.Cancelsets the flag toCanceledand then dispatches pending signals on its own thread (line 297). A guest handler that callsSetorClearon the same flag waits at line 246 until the status returns toSet.Cancelrestores that status only after the handler returns (line 301). Releasingm_mutexdoes not break this cycle, and the cycle does not depend on the waiter count. The waiting thread can exit, andCancelstill never returns.The fix must preserve one of these behaviors:
Cancelmust not run guest handlers while the flag isCanceled, or a reentrantSetorClearfrom the canceling thread must not block on theCanceledstate. The choice between these options is left to the author.@ -405,3 +497,1 @@static_cast<int>(mounted_name.size()), mounted_name.data());}return p.dir / native_rel_path;return p.dir / Common::PathFromUtf8(EncodeHostFilename(rel_path));@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Preserve existing Windows files with literal percent escapes.
Before this change, a guest could open an existing
save%3A.datby that name. The new resolver looks forsave%253A.datand returnsENOENTif it is absent. The directory listing also reports the original file assave:.dat.Add a migration or a per-directory mapping that preserves the identity of existing files. Test a directory containing both spellings. An encoded-first lookup with a literal fallback cannot disambiguate both files on its own.
@ -861,0 +1162,4 @@const auto end = addr + size;while (addr < end) {VirtualRanges::Range range {};if (!g_virtual_ranges->Query(addr, 0, &range)) {@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Take the state lock shared inside the recoverable-destination probe.
The probe walks
g_virtual_rangesthroughQuerywithout holdingg_memory_state_mutex. Mapping writers modify that tree under the exclusive state lock, for example in theAdd,Remove, andReplaceSpanpaths. The probe runs on the file-read path after a partial read fault. Such a fault can occur during a mapping replacement, so the traversal can race with node insertion, erase, or rebalancing. Rebalancing can affect nodes outside the read destination, so a non-overlapping edit does not prevent the race.The lock policy at
src/kernel/memory.cpp:196-198requires readers outside a memory operation to take the state lock shared.ClampRangeSizealready follows this pattern. Take the same lock in the probe for the duration of its traversal:Suggested fix
@ -902,10 +1250,20 @@ private:if (info.State == MEM_FREE && reserve_end > reserve_start &&reserve_end - reserve_start > MinimumRegionSize) {@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Reject an empty required region on Windows.
If Region 2 contains only free gaps of 16 MiB or less, the loop reserves nothing and still completes.
ReserveRemainingGuestRegionsmarks phase two complete. The self-tests can pass using Regions 0 and 1, but extended-memory mappings later fail the ownership check.Track successful reservations per region and fail phase two if a required region has none. The POSIX paths already reject this condition. Preserve the existing success path when every region has usable reserved space.
@ -3108,0 +3336,4 @@const auto mask = 1ull << static_cast<uint32_t>(signum);thread->pending_signal_mask.fetch_or(mask);if (thread->almost_done || thread->free) {thread->pending_signal_mask.fetch_and(~mask);@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Prevent a rejected signal from clearing a new thread's pending signal.
A sender can set signal 30 for thread A, see
almost_done, and pause before clearing the bit. If A joins and its record is reused for B, a second sender can successfully queue signal 30 for B. The first sender then clears B's signal before B takes it.Make the lifecycle check and pending-mask update atomic with respect to record recycling. A rejected send must leave the new worker's mask unchanged. A send to a live worker must still set its pending bit.
@ -766,0 +776,4 @@}// TrueType collections (.ttc) store a table of faces; use the first one.const int offset = stbtt_GetFontOffsetForIndex(data, 0);@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Require the full collection header before reading the first face offset.
init_stb_infoaccepts a 12-bytettcfbuffer.stbtt_GetFontOffsetForIndexthen reads the face-0 offset at bytes 12 to 15 without a length check. For a collection with at least one face, that read exceeds the buffer. Theoffset >= sizecheck runs too late to prevent it. Require 16 bytes for collections before calling the helper. Plain-font input keeps its current path.Suggested fix
Committable suggestion
@ -665,0 +754,4 @@AudioOut2::AudioOut2PortHandle port = 0;Check(AudioOut2::AudioOut2PortCreate(context, AsParam(¶m), &port) == OK,"port create failed");uint32_t pcm[512]{};@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original
Allocate a complete stereo PCM grain.
When
deviceis true,SetPcmcopies 4096 bytes for 512 stereo float frames. This array contains only 2048 bytes. The copy reads beyond the stack array and can fail under a memory sanitizer. Usefloat pcm[512 * 2]{}to preserve the intended silent input. (raw.githubusercontent.com)@ -0,0 +133,4 @@Common::Singleton<Loader::RuntimeLinker>::Instance();Libs::LibKernel::Initialize();Libs::LibKernel::PthreadInitSelfForMainThread();TestPriorities();@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original · edited 2026-11-20 21:30 UTC
Initialize the guest memory lifecycle in this test entrypoint.
maininitializes configuration and logging, but notLibs::LibKernel::Memory::Lifecycle. Each worker callsCreateThreadTlsinRunThreadbefore it runs guest code. That path callsAllocateRuntimeMemory, which uses memory globals created only duringMemory::Initialize. The new test can therefore fail when it creates its workers. Initialize the lifecycle after logging and before the runtime linker. The sibling tests use the same order.Suggested fix
✅ Addressed in commits
d6dc67dto2577e26@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original · reviewed
Actionable comments posted: 15
0f7a734b-55a5-4c54-9b6e-a1adbcc899e3Reviewing files that changed from the base of the PR and between
a1fc5ae438and135901b88c..github/workflows/build.ymlCMakeLists.txtsrc/common/debugCounters.hsrc/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/common/gpuStall.cppsrc/common/gpuStall.hsrc/common/parallelFor.hsrc/common/platform/sysFileIO.hsrc/common/platform/sysLinuxFileIO.cppsrc/common/platform/sysWindowsFileIO.cppsrc/common/systemFonts.cppsrc/common/systemFonts.hsrc/common/threads.cppsrc/common/threads.hsrc/emulator.cppsrc/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hsrc/graphics/guest_gpu/pm4.cppsrc/graphics/guest_gpu/pm4.hsrc/graphics/guest_gpu/tile.cppsrc/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/rangeSet.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/streamBuffer.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/commandScheduler.cppsrc/graphics/host_gpu/renderer/commandScheduler.hsrc/graphics/host_gpu/renderer/depthRenderTarget.cppsrc/graphics/host_gpu/renderer/image/image.cppsrc/graphics/host_gpu/renderer/image/image.hsrc/graphics/host_gpu/renderer/image/imageInfo.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/image/tiler.cppsrc/graphics/host_gpu/renderer/image/tiler.hsrc/graphics/host_gpu/renderer/meshSlices.hsrc/graphics/host_gpu/renderer/pipeline/descriptorHeap.cppsrc/graphics/host_gpu/renderer/pipeline/descriptorHeap.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/imageHeap.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/pipeline/pipelineSerialization.cppsrc/graphics/host_gpu/renderer/pipeline/shaders.cppsrc/graphics/host_gpu/renderer/rayTracing.cppsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/host_gpu/renderer/renderPssr.cppsrc/graphics/host_gpu/shaders/gpu_mesh_indirect.tasksrc/graphics/host_gpu/shaders/gpu_tiler_color_clear.compsrc/graphics/host_gpu/vulkanCommon.cppsrc/graphics/presentation/performanceOverlay.cppsrc/graphics/presentation/window/hostInput.cppsrc/graphics/presentation/window/hostInput.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/presentation/window/window.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ShaderRecompiler.hsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/Serialize.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/Value.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cppsrc/graphics/shader/shader.cppsrc/kernel/eventFlag.cppsrc/kernel/fileSystem.cppsrc/kernel/fileSystem.hsrc/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.incsrc/kernel/pthread.cppsrc/kernel/pthread.hsrc/kernel/semaphore.cppsrc/libs/agc.cppsrc/libs/agc.hsrc/libs/audio.cppsrc/libs/audio3d.cppsrc/libs/avPlayer.cppsrc/libs/dialog.cppsrc/libs/dialog.hsrc/libs/guestPrintf.cppsrc/libs/libAgcDriver.cppsrc/libs/libAudio2.cppsrc/libs/libC.cppsrc/libs/libCes.cppsrc/libs/libFont.cppsrc/libs/libKernel.cppsrc/libs/libNet.cppsrc/libs/libRtc.cppsrc/libs/network.cppsrc/libs/network.hsrc/libs/ngs2.cppsrc/loader/guestInstructionPatcher.cppsrc/loader/guestInstructionPatcher.hsrc/loader/runtimeLinker.cppsrc/loader/runtimeLinker.hsrc/main.cpptests/ArchiveFileTests.cpptests/AudioOut2PortTests.cpptests/AudioOutTimingTests.cpptests/AvPlayerFileTests.cpptests/CesTests.cpptests/GpuStallTests.cpptests/GuestInstructionPatchScanTests.cpptests/GuestPrintfTests.cpptests/Http2AbortRequestTests.cpptests/KernelFileSystemTests.cpptests/LibCEnvironmentTests.cpptests/Ngs2SamplerTests.cpptests/PthreadPriorityTests.cpptests/ResourceMaterializationTests.cpptests/ResourceTrackingTests.cpptests/RtcFormatTests.cpptests/SaveDataDialogTests.cpptests/ShaderRecompilerComputeTests.cpptests/ShaderVertexMetadataTests.cpptests/VirtualMemoryAllocationTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-20 17:58 UTC · original · reviewed
Actionable comments posted: 13
0f7a734b-55a5-4c54-9b6e-a1adbcc899e3Reviewing files that changed from the base of the PR and between
a1fc5ae438and135901b88c..github/workflows/build.ymlCMakeLists.txtsrc/common/debugCounters.hsrc/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/common/gpuStall.cppsrc/common/gpuStall.hsrc/common/parallelFor.hsrc/common/platform/sysFileIO.hsrc/common/platform/sysLinuxFileIO.cppsrc/common/platform/sysWindowsFileIO.cppsrc/common/systemFonts.cppsrc/common/systemFonts.hsrc/common/threads.cppsrc/common/threads.hsrc/emulator.cppsrc/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hsrc/graphics/guest_gpu/pm4.cppsrc/graphics/guest_gpu/pm4.hsrc/graphics/guest_gpu/tile.cppsrc/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/rangeSet.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/streamBuffer.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/commandScheduler.cppsrc/graphics/host_gpu/renderer/commandScheduler.hsrc/graphics/host_gpu/renderer/depthRenderTarget.cppsrc/graphics/host_gpu/renderer/image/image.cppsrc/graphics/host_gpu/renderer/image/image.hsrc/graphics/host_gpu/renderer/image/imageInfo.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/image/tiler.cppsrc/graphics/host_gpu/renderer/image/tiler.hsrc/graphics/host_gpu/renderer/meshSlices.hsrc/graphics/host_gpu/renderer/pipeline/descriptorHeap.cppsrc/graphics/host_gpu/renderer/pipeline/descriptorHeap.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/imageHeap.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/pipeline/pipelineSerialization.cppsrc/graphics/host_gpu/renderer/pipeline/shaders.cppsrc/graphics/host_gpu/renderer/rayTracing.cppsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/host_gpu/renderer/renderPssr.cppsrc/graphics/host_gpu/shaders/gpu_mesh_indirect.tasksrc/graphics/host_gpu/shaders/gpu_tiler_color_clear.compsrc/graphics/host_gpu/vulkanCommon.cppsrc/graphics/presentation/performanceOverlay.cppsrc/graphics/presentation/window/hostInput.cppsrc/graphics/presentation/window/hostInput.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/presentation/window/window.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ShaderRecompiler.hsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/Serialize.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/Value.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cppsrc/graphics/shader/shader.cppsrc/kernel/eventFlag.cppsrc/kernel/fileSystem.cppsrc/kernel/fileSystem.hsrc/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.incsrc/kernel/pthread.cppsrc/kernel/pthread.hsrc/kernel/semaphore.cppsrc/libs/agc.cppsrc/libs/agc.hsrc/libs/audio.cppsrc/libs/audio3d.cppsrc/libs/avPlayer.cppsrc/libs/dialog.cppsrc/libs/dialog.hsrc/libs/guestPrintf.cppsrc/libs/libAgcDriver.cppsrc/libs/libAudio2.cppsrc/libs/libC.cppsrc/libs/libCes.cppsrc/libs/libFont.cppsrc/libs/libKernel.cppsrc/libs/libNet.cppsrc/libs/libRtc.cppsrc/libs/network.cppsrc/libs/network.hsrc/libs/ngs2.cppsrc/loader/guestInstructionPatcher.cppsrc/loader/guestInstructionPatcher.hsrc/loader/runtimeLinker.cppsrc/loader/runtimeLinker.hsrc/main.cpptests/ArchiveFileTests.cpptests/AudioOut2PortTests.cpptests/AudioOutTimingTests.cpptests/AvPlayerFileTests.cpptests/CesTests.cpptests/GpuStallTests.cpptests/GuestInstructionPatchScanTests.cpptests/GuestPrintfTests.cpptests/Http2AbortRequestTests.cpptests/KernelFileSystemTests.cpptests/LibCEnvironmentTests.cpptests/Ngs2SamplerTests.cpptests/PthreadPriorityTests.cpptests/ResourceMaterializationTests.cpptests/ResourceTrackingTests.cpptests/RtcFormatTests.cpptests/SaveDataDialogTests.cpptests/ShaderRecompilerComputeTests.cpptests/ShaderVertexMetadataTests.cpptests/VirtualMemoryAllocationTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -45,0 +55,4 @@m_owner.store(std::this_thread::get_id(), std::memory_order_relaxed);}void Unlock() {m_owner.store({}, std::memory_order_relaxed);@coderabbitai[bot] on GitHub · 2026-11-20 19:15 UTC · original
Keep the owner until the final recursive unlock.
Mutexexplicitly supports recursive locking. WithLock(); TryLock(); Unlock();, the thread still owns one level of the underlying mutex, but this store clearsm_owner.IsHeldByCurrentThread()then incorrectly returns false. Recursive ownership ends only after all acquisition levels are released. (ece.uvic.ca)This can bypass the supplied
EmergencyShutdownsame-thread guard. Track recursion depth for successfulLockandTryLockcalls. Clearm_owneronly when the depth reaches zero. Preserve the existing single-acquisition behavior.@ -77,2 +92,4 @@uint64_t generations = 0;Iterate<true>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {if (!is_written && !manager->IsModified<DirtySource::Cpu>(offset, bytes)) {generations += manager->Generation();@coderabbitai[bot] on GitHub · 2026-11-20 19:15 UTC · original
Capture the clean state and generation under the same lock.
If a CPU invalidation occurs after Line 94 reads a clean page but before Line 95 reads its generation, this branch records the new generation without processing the dirty page. CPU invalidation can change that state under the region lock. (raw.githubusercontent.com)
The next identical call then matches the memo and skips the required upload. Without memoization, that call would detect the dirty page.
Hold
manager->lockacross the clean-state check and generation capture. This preserves the unchanged-page result and prevents a concurrent invalidation from being recorded as already processed.@coderabbitai[bot] on GitHub · 2026-11-20 19:15 UTC · original · edited 2026-11-20 19:40 UTC
On
tests/MemoryTrackerTests.cppline 429 (outdated):Use the supplied Allocate signature.
Line 429 passes two arguments, but the local helper at Line 263 accepts only
uint64_t pages. This prevents the test executable from compiling against the supplied interface. UseAllocate(2), as the neighboring tests do.✅ Addressed in commits
8fc3ff3to b56e901@coderabbitai[bot] on GitHub · 2026-11-20 19:15 UTC · original · reviewed
Actionable comments posted: 3
721c94b2-2ee2-4ea1-a1e3-56049d84aec3Reviewing files that changed from the base of the PR and between
8958064dadand 7d2b333b010751005297d315ac93a707cf6e1679.CMakeLists.txtsrc/common/threads.cppsrc/common/threads.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/regionManager.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineSerialization.cppsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/libs/agc.cppsrc/libs/agc.htests/MemoryTrackerTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -274,6 +323,14 @@ PageManager::PageManager(): m_impl(std::make_unique<Impl>()) {}PageManager::~PageManager() = default;uint64_t PageManager::GetPageSize() const {@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · edited 2026-11-20 21:30 UTC
Declare
GetPageSizeinPageManager, or remove its definition.PageManagerinsrc/graphics/host_gpu/pageManager.hdoes not declareGetPageSize. The out-of-class definition atsrc/graphics/host_gpu/pageManager.cpp:326therefore names a member that does not exist. The compiler rejects this in every build that compilespageManager.cpp.Add
uint64_t GetPageSize() const;to the public section ofPageManager. If the method is not needed, remove the definition atpageManager.cpp:326instead.✅ Addressed in commits
d6dc67dto2577e26@ -119,0 +248,4 @@return address < end;}const auto first_boundary = Common::AlignUp(begin, TRACKER_PAGE_SIZE);return first_boundary < end && first_boundary < address + size;@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
Dirty the image when a sequential write overwrites its head bytes.
SequentialWriteReachesImagereturnsfalsefor a write that starts before the image and ends inside the image's first tracker page. The bytes from the image start through the write end are still overwritten.InvalidateCpuAliasesthen untracks the image head without marking the image CPU dirty. The fill and copy paths inbufferCache.cppwrite the new bytes to guest memory without updating the native image. Sampling that GPU-written image can return the old texels for those bytes.The sequential path must mark the image CPU dirty when the write overlaps any image byte. The ordinary
Overlapspath already does this. Apply the same rule here, or update the native image from the written bytes. Keep the other sequential cases unchanged.@ -71,0 +92,4 @@// Suspends a range, or unmaps it like UnmapNow once shutdown has begun.void SuspendNow(uint64_t vaddr, uint64_t size);[[nodiscard]] bool NeedsUnmapDrain(uint64_t vaddr, uint64_t size);[[nodiscard]] bool IsUnmapDrainRedundant(uint64_t vaddr, uint64_t size);@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · edited 2026-11-20 21:30 UTC
Restore the
WaitWriteBacksmember declaration.renderContext.cppdefinesRenderContext::WaitWriteBacksat Line 87.HandleFaultandInvalidateMemorystill call it. The class no longer declares the member, so this translation unit cannot compile. Restore[[nodiscard]] bool WaitWriteBacks(uint64_t vaddr, uint64_t size);in the private section.✅ Addressed in commits
d6dc67dto2577e26@ -1190,0 +1560,4 @@#if defined(KYTY_VIRTUAL_MEMORY_ALLOCATION_TESTS)if (g_test_fail_next_physical_memory_map) {g_test_fail_next_physical_memory_map = false;return false;@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
Return a recoverable error for the injected map failure.
RunRemapFailedAfterViewexpects the map to return an error and leave the address usable for a retry. This hook returnsfalseafter the host view is installed, but the check at Line 2741 terminates instead of returning to the test. Roll back the new view and preserve the prior reservation before returning an error. LetResumeCandidateScopecancel the exposed candidate so the next map uses the normal path.@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
On
src/kernel/memory.cppline 1564 (outdated):Declare or remove
m_mutexinPhysicalMemory::Map. The identifier does not resolve.PhysicalMemorydeclares nom_mutexmember, and it has no base class that could provide one.memory.handmemoryAddressSpace.incdeclare no such member either. TheCommon::LockGuard lock(m_mutex);at line 1564 therefore fails to compile in any build that includes this file.Fix this in one of two ways:
PhysicalMemoryand use it form_mappingsandm_physical.Map.Before you choose, confirm which lock protects these structures. Do not acquire a lock that the caller already holds, because a non-recursive mutex deadlocks when acquired twice.
@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · edited 2026-11-20 21:30 UTC
On
src/kernel/memory.cppline 2182 (outdated):Keep the unmap bookkeeping inside
UnmapMemoryOwner.This brace ends the function before
g_virtual_ranges->Remove. The remaining statements are at namespace scope and cannot usevaddr,len, orrange. Remove the extra brace so a successful unmap updates the virtual range and pool accounting before the function returns.✅ Addressed in commits
d6dc67dto2577e26@ -2285,3 +2727,1 @@if (g_guest_address_space->MapBacking(target, len, direct_memory_start, mode,&shared_failure)) {out_addr = target;if (MapBackingForGuest(target, len, direct_memory_start, mode, &shared_failure)) {@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
Do not wait for GPU cache cancels while
g_memory_state_mutexis held exclusively.MapBackingForGuestruns under the exclusiveg_memory_state_mutexlock (src/kernel/memory.cpp:2729-2737). When a new physical mapping overlaps a suspended entry, that entry's cancel runs throughCancelSuspendedWhereandCancelGpuRange(memory.cpp:1028-1041,255).RenderContext::CancelSuspendedMemoryrequires the GPU thread (renderContext.cpp:150-152). The guest thread therefore waits on the GPU thread while it holds the lock.The GPU thread can reach
ClampRangeSizewhile it records a draw (renderDraw.cpp:715,descriptors.cpp:844). When a request misses the lock-free fast path,ClampRangeSizetakes a shared lock ong_memory_state_mutex(memory.cpp:1104). If the guest thread holds that lock exclusively, neither thread can proceed. The guest thread waits for the cancel, and the GPU thread waits for the lock.The stated lock contract at
memory.cpp:430-432forbids a graphics call under this lock. Cancels that a map triggers must run after the state lock is released. The change must keep the table and virtual-range state consistent while the GPU cache cancel runs outside the lock. The exact split is not prescribed here.@ -2323,0 +2765,4 @@// Resuming happens here, after the view exists and before the guest call returns. Between the// view and this point watched pages are not protected, which is why it must not be later.if (!ResumeSuspendedGpuRange(out_addr, len, static_cast<uint64_t>(direct_memory_start))) {@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
Protect retained cache entries before exposing a writable remap.
A second guest thread can store through the fresh view after
MapBackingForGuestsucceeds but beforeResumeMemoryrestores page protection. The store does not fault, so the GPU can reuse buffer bytes from before the store. Returning from the mapping call only after protection is restored does not protect other threads during that interval. Either expose the view with the required tracking protection already in place or invalidate retained bytes for remaps that expose an untracked writable view.@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · edited 2026-11-20 21:31 UTC
On
src/kernel/memory.cppline 3723 (outdated):Keep the pool commit in scope and return
ENOMEMonly on allocation failure.The closing brace puts
mappingsout of scope before the backing-map loop, so the code cannot compile. The extra return also exits after a successfulAllocate, which has already recorded ownership. Remove the extra return and keep the mapping and virtual-range updates inside the state-lock block. Leave GPU notification and callbacks outside that block.✅ Addressed in commits
d6dc67dto2577e26@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · edited 2026-11-20 21:31 UTC
On
src/kernel/memory.cppline 3728 (outdated):Cancel suspended GPU caches before pool commit maps physical pages.
The pool commit maps each allocated fragment with a direct
MapBackingcall. UnlikeMapBackingForGuest, this path does not cancel suspended GPU entries whose physical range overlaps the new view. After a direct allocation is released, its physical blocks return to the physical allocator, but its suspended entry still records the old physical offset. Pool allocation can then return those pages. A CPU write through the pooled view can change them. Releasing the pool and remapping the original direct range exactly can then resume the cache with stale bytes.Route the pool commit through the same physical-overlap cancellation that
MapBackingForGuestperforms, before the new view is exposed. TheMapBackingForGuestcomment states that cancellation runs while no address-space lock is held, because it can wait on the GPU. Keep the pool path consistent with that, so the cancellation does not run underg_memory_state_mutex.✅ Addressed in commits
d6dc67dto2577e26@ -3413,0 +4786,4 @@TestFailNextPhysicalMemoryUnmap();} else {TestFailGuestBackingStoreUnmapAfter(0);}@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original
Connect the release failure hooks to the unmap operations.
TestFailGuestBackingStoreUnmapAfter(0)andTestFailNextPhysicalMemoryUnmap()set injection state, but neither unmap implementation reads it. The checked release therefore returnsOKfor this valid mapping.CheckFailedstops the suite before it checks cancellation or restored data. Connect each hook at its intended stage and make the checked release return an error after restoring any view it already removed. Keep the release without injection successful. (raw.githubusercontent.com)@coderabbitai[bot] on GitHub · 2026-11-20 19:52 UTC · original · reviewed
Actionable comments posted: 11
a705a295-e41b-4323-8b89-144463633f2cReviewing files that changed from the base of the PR and between 7d2b333b010751005297d315ac93a707cf6e1679 and b56e9015c74b275912ab8237091f01d3ddcda726.
CMakeLists.txtsrc/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/common/threads.hsrc/graphics/host_gpu/pageManager.cppsrc/graphics/host_gpu/pageManager.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/kernel/memory.cppsrc/kernel/memory.hsrc/main.cpptests/MemoryTrackerTests.cpptests/PageManagerTests.cpptests/ShaderRecompilerComputeTests.cpptests/VirtualMemoryAllocationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -39,0 +46,4 @@// A clear code is key << ColorClearKeyShift, so the code bits below the shift are always clear// in the DCC (0x00, 0x20, 0x40, 0x80 and 0xc0) and CMask (0x00) codes DecodeColorClear accepts.// The steady state code 0xff has them set, so it skips the decode.constexpr uint32_t ColorClearKeyShift = 5;@coderabbitai[bot] on GitHub · 2026-11-20 21:45 UTC · original
Admit
0x10before the low-bit rejection in the CPU color-clear filter.MaterializeColorClearskips any code with low bits set, so a slice filled with the accepted0x10register-clear code never clears. The GPU predicate path already maps0x10to the0x20slot, so only the CPU filter needs the change. The byte comparison must still use the originalcodevalue.Suggested fix
@ -952,0 +1318,4 @@namespace Counters = Common::DebugCounters;const auto& info = image.info;const auto first = range.address - info.data.address;const auto rounded = RoundRefreshRange(info, first, first + range.size);@coderabbitai[bot] on GitHub · 2026-11-20 21:45 UTC · original
Keep the linear partial refresh from overwriting image texels outside the marked buffer range.
RoundRefreshRangewidens the marked range to 4-byte boundaries. For a sub-word storage-buffer write, the widened window includes bytes that the buffer write did not mark. The image still owns those texels:InvalidateBufferWritekeepsgpu_modset and documents the image as newer outside the range.RefreshLinearRangethen copies buffer or guest bytes over them. An R8 image with a one-byte marked range at its base can have three neighboring texels replaced with stale data.The linear path must copy only the marked bytes, at the granularity the upload permits, or otherwise keep the neighboring image texels unchanged. The tiled path in
PlanTiledRefreshuses the same rounding and can carry the widened window into its merge. Choose the granularity change in one place so both paths share the rule.@ -3216,0 +3704,4 @@// Validation precedes the first backing map; failing after it is an emulator fault.for (const auto& mapping: mappings) {auto failure_reason = GuestBackingStore::FailureReason::None;if (!MapBackingForGuest(mapping.vaddr, mapping.size, mapping.phys_addr, mode,@coderabbitai[bot] on GitHub · 2026-11-20 21:45 UTC · original
Hold the state lock while installing pooled backing views.
MapBackingForGuestreachesGuestAddressSpace::MapBackingwithoutg_memory_state_mutex. A GPU thread inProtectTransientcan hold the shared lock and traversem_mappedwhile the pool commit inserts into that tree. The operation lock does not protect that reader.Cancel suspended overlaps before taking the exclusive state lock. Then hold the state lock across the backing maps and virtual-range publication.
@ -141,0 +143,4 @@int UnmapAmmMemory(uint64_t vaddr, size_t size);bool TryWriteBacking(uint64_t vaddr, const void* data, uint64_t size);bool TryReadBacking(uint64_t vaddr, void* data, uint64_t size);// Reads one byte from each of count addresses spaced stride apart under one lock. Returns@coderabbitai[bot] on GitHub · 2026-11-20 21:45 UTC · original
Hold the state lock across the strided read so one sample sees one mapping generation.
TryReadBackingStridedreads each entry with a separateLoadPagecall and takes no lock.StorePageswrites entries without a lock. If a mapping is replaced between two samples, the call can returntruewith bytes from two backing generations. The header atsrc/kernel/memory.h:146says the read happens under one lock, but the implementation does not take one.Take the shared state lock once in the free-function forwarder, so the lock covers the whole loop. Writers that hold the exclusive lock then block until the read finishes. Take the lock in one place only, because nested shared locks on the same mutex can deadlock. Confirm that no caller already holds
g_memory_state_mutexwhen it reaches this function.Suggested fix
@coderabbitai[bot] on GitHub · 2026-11-20 21:45 UTC · original · reviewed
Actionable comments posted: 4
2cc2351d-4f96-4e97-b66a-e975ddc9e3e4Reviewing files that changed from the base of the PR and between b56e9015c74b275912ab8237091f01d3ddcda726 and
2577e26e25.CMakeLists.txtsrc/common/debugCounters.hsrc/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/pageManager.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/commandScheduler.cppsrc/graphics/host_gpu/renderer/commandScheduler.hsrc/graphics/host_gpu/renderer/image/image.hsrc/graphics/host_gpu/renderer/image/refreshRegions.cppsrc/graphics/host_gpu/renderer/image/refreshRegions.hsrc/graphics/host_gpu/renderer/image/tiler.cppsrc/graphics/host_gpu/renderer/image/tiler.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/imageHeap.cppsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/host_gpu/renderer/submitCadence.hsrc/graphics/host_gpu/shaders/gpu_tiler_common.incsrc/graphics/host_gpu/shaders/gpu_tiler_depth.compsrc/graphics/host_gpu/shaders/gpu_tiler_prt.compsrc/graphics/host_gpu/shaders/gpu_tiler_prt_3d.compsrc/graphics/host_gpu/shaders/gpu_tiler_render_target.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard256.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard4.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard4_3d.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard64.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard64_3d.compsrc/graphics/presentation/window/swapchain.cppsrc/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.incsrc/main.cpptests/PthreadPriorityTests.cpptests/ShaderRecompilerComputeTests.cpptests/VirtualMemoryAllocationTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Pull request closed