aboutsummaryrefslogtreecommitdiff
path: root/src/core/device_memory_manager.inc
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #235 from CloudP4bbs/pr/asid-guardJonas29 hours1-0/+5
|\ | | | | core: do not index registered_processes with an unregistered ASID
| * core: do not index registered_processes with an unregistered ASIDPaulo Rossatto2 days1-0/+5
| |
* | Merge remote-tracking branch 'origin/fix/cold-hint-uploaded-memory' into ↵Takoroka2 days1-0/+44
|\ \ | | | | | | | | | test/linux-all-prs
| * | texture_cache: mark guest memory textures were uploaded from coldTakoroka3 days1-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Once a texture is uploaded the host GPU has its own copy, and the guest rarely reads that memory again, but it stayed in the emulator's working set. Every 600 frames the guest ranges of images uploaded since (64 KiB or more, not GPU-written or sparse) are marked cold through HostMemory::HintCold, backing and CPU view, from a low-priority worker, so the OS pages them out before anything else when it needs RAM. Their contents stay; using them brings them back. Mario Kart World's title screen at ~10 minutes: game memory in RAM 4.8-5.5 -> 3.6 GB, the emulator's real RAM 10.6-11.9 -> 9.4 GB, frames over 100 ms not worse. (cherry picked from commit ea36b2c5ca352f8c8cdcc829a2d3bde9bdc06ece)
* | | nx2: count a mapped sparse tile as writtenTakoroka3 days1-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With remap support Mario Kart World fills nine world-sized masks (R8 16384x16384, RG16 and R16 8192x8192, one sparse region each) in its own memory and then maps them in through 216. Nothing writes them through the sparse region, so its blocks stayed unwritten and the texture cache kept the images over them without memory, reading zero: the static world (roads, buildings, rocks, trees) rendered unlit while karts and cars were lit. Without remap support the game never maps them and lights the world without them. A tile map now counts its blocks as written and invalidates the caches over the tile, so those images get memory and load what the game mapped. That costs the masks' full size in device memory (about 2.9 GB in Mario Kart World), which is what they need until the texture cache can back single images tile by tile. DeviceMemoryManager::Unmap no longer needs its flag to keep the caches.
* | | nx2: map and unmap sparse texture tiles (nx2:gpu 216)Takoroka3 days1-2/+4
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Switch 2 games commit and release the memory behind sparse textures by remapping tiles: nvnMemoryPoolMapVirtual goes through NvRm's remap into nn::gpu::sdk::ExecuteSparseMapRequests, nx2:gpu sub-session command 216, a batch of 40-byte requests. A map points a tile at the game's own GPU-accessible memory (the handle sub 101 returned, plus an offset), an unmap makes it read zero again; the sparse region itself never has memory. NvRm only remaps when the GPU characteristics report NVGPU_GPU_FLAGS_SUPPORT_REMAP (bit 35). Without it every remap failed before reaching the server, so Mario Kart World streamed its terrain into unmapped sparse memory and each 4 MiB block it touched got memory that was never freed (2.5 GB after 10 minutes, still growing). Report the flag (EDEN_NX2_SPARSE_REMAP=0 leaves it out) and serve 216: - Sparse regions: a tile's device pages show the game's memory, or are unmapped, in GPU thread order, without invalidating the caches over them; the region keeps its GPU mapping, so the texture cache keeps its images. A region the game maps tiles into gets no more blocks (writes outside its tiles are dropped, as on the console), gives back the blocks it already had, and marks a block written when the GPU first writes it, so array layers it only maps tiles into get no memory or uploads. - GPU-only regions (214 without the sparse flag): the game also sends 216 for its render targets and, with remap support, for two texture arrays (5.8 GB and 1.4 GB). Regions whose memory another GPU-only region maps (render-target groups) keep the memory 214 gave them: applied, the texture cache flushed and re-uploaded the overlapping render targets every frame. Regions 214 backs as they are written keep their blocks too, since the texture cache reads an image's memory in full when it uploads it, which makes the game's pages resident on the host (about 1 GB more 150 s in). The rest get the game's memory the way 211 maps it, so writes through the game's own address reach the same device pages; an unmap points the range back at the region's own memory. Mario Kart World, 10 minutes: no sparse blocks backed (2.5 GB before), 24.6 presents a second instead of 19.3. 216 totals are logged every 30 s.
* | Gpu buffer readback to cpu. Fixing visible glitches such as missing ↵néo Luigi3 days1-0/+32
|/ | | | | | collision on some object, but can extend to more. Assisted-by: Claude Opus 5.5 (debugging & implementation)
* core: end device page runs where pages are unmapped or mapped againTakoroka4 days1-0/+21
| | | | | | | | | | | | | | | | | | WalkBlock copies a run of physically contiguous device pages at once, using each page's continuity_tracker. Unmap left the counts as they were, Map without tracking did not touch them, and the pages before a changed range kept counting into it. A read starting on such a page then copied the host memory that followed the old mapping, or, starting on an unmapped page, zero-filled the whole old run, mapped pages after it included. Splatoon Raiders lost its dialogue text this way: the glyph vertex shader reads its corner table from constant buffer 1 (the program's constants, at device 0x5617d700), and the buffer cache uploaded the range from 0x5617c000, an unmapped page still counted as the start of a long run, so the table reached the GPU as zeros and every glyph sampled one empty texel. Unmap and Map now reset the counts of their pages (Map recounts them when tracking) and cut the runs of the pages before them at the range start.
* nx2: give sparse regions memory only where the GPU writesTakoroka5 days1-16/+28
| | | | | | | | | | | | | | | | | | | | | | nx2:gpu 214 regions with the sparse flag (word 7 bit 0x200) are Mario Kart World's terrain texture arrays and layer pools, 170 MB to 5.8 GB, mostly empty. Backed whole they ran the graphics pool dry (26 "could not allocate" per session, later regions without memory), and backing a block at a time made the texture cache rebuild the 1.45 GB arrays each time a block was mapped. A sparse region now gets a device (SMMU) range of its own when it is created, mapped for the GPU at once, so its GPU mapping never changes. Before a GPU-side write lands in it (WriteBlock, Write<T>), the 4 MiB blocks it touches get memory, cleared, behind their device pages. Unbacked device pages read zero and drop writes instead of crashing, and the unmapped-device-access errors are logged 16 times, not once per page. nx2:gpu 215 releases the device range and the blocks after the GPU is done with them. The log reports GPU-only memory in use and its peak. Mario Kart World, 180 s: no allocation failures; ~2.8 GB of terrain blocks get memory instead of 6.5 GB of whole regions, next to 3 GB of ordinary GPU-only regions. Terrain renders as before.
* core: per-thread device memory translation cacheTakoroka5 days1-12/+14
| | | | | | | | | | DeviceMemoryManager kept one four-entry page translation cache for every thread. Map (on a guest service thread, e.g. nx2:gpu 211 job mappings) cleared it while the GPU thread was between its null check of an entry and the copy from it: the GPU thread then read from address 0 plus the page offset. Title 1 crashed this way in about half of its 150 s test runs (BindHostGraphicsUniformBuffer -> ReadBlockUnsafe, fault at 0x600). Each thread now keeps its own cache, which Map and Unmap invalidate through a generation counter. 0 crashes in 6 runs after.
* Revert "Import experimental NS2 support and accumulated GPU fixes"Takoroka6 days1-2/+1
| | | | | This reverts commit 535b676970. The Switch 2 support comes from the nx2 work instead, merged next.
* Import experimental NS2 support and accumulated GPU fixesyumekiru6 days1-1/+2
| | | | | | | | | | | Bring the NS2 patch and local follow-up fixes onto Eglantine master. Includes native graphics services, instruction translation, syncpoint cancellation acknowledgement, texture handling and diagnostics. Experimental checkpoint; not ready to merge. The original Eden build passed, but this rebased branch has not been built or tested. Assisted-by: OpenAI Codex (implementation, debugging, tests and PR preparation)
* [common/core/dynarmic] Optimize page table allocations (#4219)Exverge2026-09-091-27/+22
| | | | | | | | | | | | | | Reduces the page entries from 32 bytes to 8 and rewrites `VirtualBuffer` to be more efficient in memory usage and specifically for large zero regions. The page table will now only reserve 1GiB instead of 4GiB and of this memory it should only use at most ~8MiB. This PR has the side effect of using Eden on Windows on low memory systems much more plausible since it would previously require ~10GiB of committable memory at front (despite using ~5-6 at most, inadvertently stalling other processes) where as now it should only require around the amount that it'll actually use. Co-authored-by: Lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4219 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: lizzie <lizzie@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
* [fmt] use {#:x} instead of 0x{:#x} (#4170)lizzie2026-07-251-4/+4
| | | | | | | | | | continuation of #309 but applying to even more files than before :) also makes them lowercase because `0xfafafa` is better as `0XFAFAFA` Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4170 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: Maufeat <sahyno1996@gmail.com>
* [core/device_memory_manager] use more pointer/iterator stable std::vector<> ↵lizzie2026-07-071-9/+13
| | | | | | | | | | | | instead of deque<> for multi address scatter/gather (#4098) this SHOULD fix a specific issue where a deque can be reallocated causing spurious crashes Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4098 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
* [core] coalesce tracking entries for GPU (#3677)lizzie2026-03-081-48/+31
| | | | | | | | | | | | | I think I may have attempted this before, but I doubt it. Anyways this should reduce virtual buffers from 3 to just 1, also improved access times :) Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3677 Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
* [texture_cache, buffer_cache] Added TLS handling + changed command queue for ↵lizzie2026-02-201-1/+43
| | | | | | | | | | | | | | | | | | | | GPU threading. (#3579) (Merge of #3495 + #3108) This PR works around to simplify math operations on hot pointers inside the access and requests to the cache of buffers and texture cache, removing previous logic of indirection and replaced by a PoD approach. This will ensure less CPU times spended on the same request and flow directly into another chain of the render, in the same way, command queue currently uses an internal mutex that constraints the flow of data within the GPU threads, we're moving over a single command, I verified to keep using mutexes instead of internal mutex + mutex per operation, which are resolved by themselves. In simplier words, this aims to improve performance on those games and devices where the waits for next orders on GPU commands were heavier than a single verification. Co-Authored-by: @CamilleLaVey Co-Authored-by: @Lizzie Co-authored-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3579 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
* [core] Fix range batching using nil ranges (#3349)lizzie2026-01-191-1/+1
| | | | | | | | | | | this fixes mario rabbids flickering at start Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3349 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
* [tests] fix compile+linking issues with PlayTime (#3345)lizzie2026-01-191-2/+2
| | | | | | | | | | | | | fixes linking + comp issues but not the test themselves, who have now became invalid Signed-off-by: lizzie <lizzie@eden-emu.dev> Co-authored-by: DraVee <caiooliveirafarias0@gmail.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3345 Reviewed-by: DraVee <dravee@eden-emu.dev> Reviewed-by: Maufeat <sahyno1996@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
* [buffer_cache] Add batching support for memory tracker updates (#3288)CamilleLaVey2026-01-181-2/+49
| | | | | | | | | | I added a batching/ coalescing of ranges in WordManager to reduce calls per pages in UpdatePagesCachedCount, also a test to verify if FlushCachedWrites coalesced (reduces callings to UpdatePagesCachedCount) callings and register each of them to inspect them. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3288 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: DraVee <dravee@eden-emu.dev> Co-authored-by: CamilleLaVey <camillelavey99@gmail.com> Co-committed-by: CamilleLaVey <camillelavey99@gmail.com>
* revert [vk] Fast UBO: fix tracking, resize heuristics, add debug guard ↵CamilleLaVey2025-10-091-26/+0
| | | | | | | | | | | | | | | | | | (#2695) (#2706) revert [vk] Fast UBO: fix tracking, resize heuristics, add debug guard (#2695) Well, stuff showed up after testing phase, that showed us this change break SMO and some mods after being merged directly into master, we will keep stuying why happens this and add a better handling later. Co-authored-by: Ribbit <ribbit@placeholder.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2695 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: Ribbit <ribbit@eden-emu.dev> Co-committed-by: Ribbit <ribbit@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2706 Co-authored-by: CamilleLaVey <camillelavey99@gmail.com> Co-committed-by: CamilleLaVey <camillelavey99@gmail.com>
* [vk] Fast UBO: fix tracking, resize heuristics, add debug guard (#2695)Ribbit2025-10-081-0/+26
| | | | | | | | Co-authored-by: Ribbit <ribbit@placeholder.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2695 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: Ribbit <ribbit@eden-emu.dev> Co-committed-by: Ribbit <ribbit@eden-emu.dev>
* [cmake] enable clang-cl and WoA builds (#348)lizzie2025-09-091-1/+1
| | | | | | | | | | | | | | Compilation and CMake fixes for both Windows on ARM and clang-cl, meaning Windows can now be built on both MSVC and clang on both amd64 and aarch64. Compiling on clang is *dramatically* faster so this should be useful for CI. Co-authored-by: crueter <crueter@eden-emu.dev> Co-authored-by: crueter <crueter@crueter.xyz> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/348 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
* Merge pull request #13000 from liamwhite/skip-null-memoryNarr the Reg2024-02-221-4/+8
|\ | | | | device_memory_manager: skip unregistered interfaces on invalidate
| * device_memory_manager: skip unregistered interfaces on invalidateLiam2024-02-121-4/+8
| |
* | scope_exit: Make constexprFearlessTobi2024-02-191-2/+2
|/ | | | | Allows the use of the macro in constexpr-contexts. Also avoids some potential problems when nesting braces inside it.
* SMMU: Ensure the backing address range matches the currentFernando Sahmkow2024-02-071-0/+7
|
* Device Memory Manager: ensure raster protection only within mapped device ↵Fernando Sahmkow2024-01-311-17/+23
| | | | addresses.
* DeviceMemory: Make counter types configurableFernando Sahmkow2024-01-311-9/+9
|
* smmu: use new range mutex construction for protecting countersLiam2024-01-311-10/+1
|
* device_memory_manager: fix ScratchBuffer indexingLiam2024-01-221-3/+2
|
* device_memory_manager: use unique_lock for updateLiam2024-01-181-14/+8
|
* nvdrv: use static typing for SessionId, smmu Asid typesLiam2024-01-181-14/+14
|
* SMMU: Fix Right Shift UB.Fernando Sahmkow2024-01-181-2/+2
|
* SMMU: Fix 8Gb layout.Fernando Sahmkow2024-01-181-5/+5
|
* Core: Clang format and other small issues.Fernando Sahmkow2024-01-181-15/+35
|
* SMMU: Add continuity tracking optimization.Fernando Sahmkow2024-01-181-3/+49
|
* SMMU: Simplify and remove old code.Fernando Sahmkow2024-01-181-62/+7
|
* SMMU: Add Android compatibilityFernando Sahmkow2024-01-181-5/+2
|
* GPU-SMMU: Estimate game leak and preallocate device region.Fernando Sahmkow2024-01-181-4/+4
|
* SMMU: Fix Unregister on MultiAddressFernando Sahmkow2024-01-181-1/+1
|
* SMMU: Implement physical memory mirroringFernando Sahmkow2024-01-181-3/+151
|
* SMMU: Initial adaptation to video_core.Fernando Sahmkow2024-01-181-8/+64
|
* SMMU: Implement backing CPU page protect/unprotectFernando Sahmkow2024-01-181-5/+77
|
* Core: Initial implementation of device memory mappingFernando Sahmkow2024-01-181-0/+304