Before this, all samplers instance were leaking on exit because the
dispose method was never getting called.
This fix this issue by making TextureBindingsManager disposable and
calling the dispose method in the TextureManager.
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Compare aligned size for largest mip level when considering sampler resize
When selecting a texture that's a view for a sampler resize, we should take care that resizing it doesn't change the aligned size of any larger mip levels.
This PR covers two cases:
- When creating a view of the texture, we check that the aligned size of the view shifted up to level 0 still matches the aligned size of the container. If it does not, a copy dependency is created rather than resizing.
- When searching for a texture for sampler, textures that do _not_ match our aligned size when both are shifted up by its base level are not considered an exact match, as resizing the found texture will cause the mip 0 aligned size to change. It will create a copy dependency view instead.
Fixes graphical errors and crashes (on flush) in various Unity games that use render-to-texture.
* Move shared code to its own method.
* Pass CbufSlot when getting info from the texture descriptor
Fixes some issues with bindless textures, when CbufSlot is not equal to the current TextureBufferIndex.
Specifically fixes a random chance of full screen colour flickering in Super Mario Party.
* Apply suggestions from code review
Oops
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Improve linear texture compatibility rules
Fixes an issue where small or width-aligned (rather than byte aligned) textures would fail to create a view of existing data. Creates a copy dependency as size change may be risky.
* Minor cleanup
* Remove Size Change for Copy Depenedencies
The copy to the target (potentially different sized) texture can properly deal with cropping by itself.
* Move StrideAlignment and GobAlignment into Constants
* Improve Buffer Textures and flush Image Stores
Fixes a number of issues with buffer textures:
- Reworked Buffer Textures to create their buffers in the TextureManager, then bind them with the BufferManager later.
- Fixes an issue where a buffer texture's buffer could be invalidated after it is bound, but before use.
- Fixed width unpacking for large buffer textures. The width is now 32-bit rather than 16.
- Force buffer textures to be rebound whenever any buffer is created, as using the handle id wasn't reliable, and the cost of binding isn't too high.
Fixes vertex explosions and flickering animations in UE4 games.
* Set ImageStore flag... for ImageStore.
* Check the offset and size.
* Improve handling for unmapped GPU resources
- Fixed a memory tracking bug that would set protection on empty PTEs
- When a texture's memory is (partially) unmapped, all pool references are forcibly removed and the texture must be rediscovered to draw with it. This will also force the texture discovery to always compare the texture's range for a match.
- RegionHandles now know if they are unmapped, and automatically unset their dirty flag when unmapped.
- Partial texture sync now loads only the region of texture that has been modified. Unmapped memory tracking handles cause dirty flags for a texture group handle to be ignored.
This greatly improves the emulator's stability for newer UE4 games.
* Address feedback, fix MultiRange slice
Fixed an issue where the size of the multi-range slice would be miscalculated.
* Update Ryujinx.Memory/Range/MultiRange.cs (feedback)
Co-authored-by: Mary <thog@protonmail.com>
Co-authored-by: Mary <thog@protonmail.com>
* Initial implementation (3d tex mips broken)
This works rather well for most games, just need to fix 3d texture mips.
* Cleanup
* Address feedback
* Copy Dependencies and various other fixes
* Fix layer/level offset for copy from view<->view.
* Remove dirty flag from dependency
The dirty flag behaviour is not needed - DeferredCopy is all we need.
* Fix tracking mip slices.
* Propagate granularity (fix astral chain)
* Address Feedback pt 1
* Save slice sizes as part of SizeInfo
* Fix nits
* Fix disposing multiple dependencies causing a crash
This list is obviously modified when removing dependencies, so create a copy of it.
* Support for resources on non-contiguous GPU memory regions
* Implement MultiRange physical addresses, only used with a single range for now
* Actually use non-contiguous ranges
* GetPhysicalRegions fixes
* Documentation and remove Address property from TextureInfo
* Finish implementing GetWritableRegion
* Fix typo
* Implement TreeMap from scratch.
Begin implementation of MemoryBlockManager
* Implement GetFreePosition using MemoryBlocks
* Implementation of Memory Management using a Tree.
Still some issues to work around, but promising thus far.
* Resolved invalid mapping issue.
Performance appears promising.
* Add tick metrics
* Use the logger instead
* Use debug loggin instead of info.
* Remove unnecessary code. Add descriptions of added functions.
* Improve memory allocation even further. As well as improve speed of position fetching.
* Add TreeDictionary to Ryujinx Commons
Removed Unnecessary Usigns
* Add a Performance Profiler + Improve ReserveFixed
* Begin transition to allocation in nvdrv
* Create singleton nvmemallocator
* Moved Allocation into Nv Related Files
As requested by gdkchan, any allocation of memory has been moved into the driver files.
Mapping remains in the GPU MemoryManager.
* Remove unnecessary usings
* Add missing descriptions
* Correct descriptions
* Fix formatting.
* Remove unnecessary whitespace
* Formatting / Convention Updates
* Changes / Fixes
Made syntax and convention changes as requested by gdkchan.
Fixed an issue where IsRegionUsed would return the wrong boolean.
Fixed an issue where GetFreePosition was asked for an address instead of a size.
* Undo commenting of Assert in shader cache
* Update Ryujinx.Common/Collections/TreeDictionary.cs
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Resolved many suggestions
* Implement Improved TreeDictionary
Based off of Pseudo code and custom implementations.
* Rename _set to _dictionary
* Remove unused code
* Remove unused code.
* Remove unnecessary MapLow function.
* Resolve data-structure based issues
* Make adjustments to memory management.
Deactive de-allocation for now, it causes more harm than good.
* Minor refactorings + Re-implement deallocation
Also cleaned up unnecessary code.
* Add Tests for TreeDictionary
* Update data structure to properly balance the tree
* Experimental Implementation:
1. Reduce Time to Next Node to O(1) Runtime
2. Reduce While Loop Ct To 2 (In Most Cases)
* Address issues w/ Deallocating Memory
* Final Build
+ Fully Implement Dictionary Interface for new Data Structure
+ Cover All Memory Allocation Edge Cases, particularly w/ Games that De-Allocate a lot.
* Minor Corrections
Give TreeDictionary its own count (do not depend on inner dictionary)
Properly remove adjacent allocations
* Add AsList
* Fix bug where internal dictionary wasn't being updated w/ new node for overwritten key.
* Address comments in review.
* Fix issue where block wouldn't break out (Fixes UE4 issues)
* Update descriptions
* Update descriptions
* Reduce Node visibility to protect TreeDictionary Integrity + Remove usage of struct.
* Update tests to use new TreeDictionary implementation.
* Remove usage of dictionary in TreeDictionary
* Refactoring / Renaming
* Remove unneeded memoryblock class.
* Add space for while
* Add space for if
* Formatting / descriptions
* Clarified some descriptions
* Reduce visibility of memory allocator
* Edit method names to make more sense as memory blocks are no longer in use.
* Make names consistent.
* Protect against npe when sucessorof is called against keys that don't exist. (Not in use by memory manager, this is for other prs that might use this data structure)
* Possible edge-case resolve
* Update Ryujinx.Common/Collections/TreeDictionary.cs
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Update Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Reduce # of unnecessary duplicate variables / Reduce visibility of variables only internally used.
* Rename count to _count
* Update Description of Add method.
* Fix copypasta
* Address comments
* Address comments
* Remove whitespace
* Address comments, condense variables.
* Consolidate vars
* Fix whitespace.
* Nit
* Fix exception msg
* Fix arrayIndex check
* Fix arrayIndex check + indexer
* Remove whitespace from cast
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
* Allow copy destination to have a different scale from source
Will result in more scaled copy destinations, but allows scaling in some games that copy textures to the output framebuffer.
* Support copying multiple levels/layers
Uses glFramebufferTextureLayer to copy multiple layers, copies levels individually (and scales the regions).
Remove CopyArrayScaled, since the backend copy handles it now.
* shader cache: Fix invalid virtual address clean up
This fix an issue causing the virtual address of texture descriptors to
not be cleaned up when caching and instead cleaning texture format and swizzle.
This should fix duplicate high duplication in the cache for certain
games and possible texture corruption issues.
**THIS WILL INVALIDATE ALL SHADER CACHE LEVELS CONSIDERING THE NATURE OF THE ISSUE**
* shader cache: Address gdk's comment
Here come Salieri, my implementation of a disk shader cache!
"I'm sure you know why I named it that."
"It doesn't really mean anything."
This implementation collects shaders at runtime and cache them to be later compiled when starting a game.
* Size hints for copy regions and viewport dimensions to avoid data loss
* Reword comment.
* Use info for the rule rather than calculating aligned size.
* Reorder min/max, remove spaces
* WIP Range Tracking
- Texture invalidation seems to have large problems
- Buffer/Pool invalidation may have problems
- Mirror memory tracking puts an additional `add` in compiled code, we likely just want to make HLE access slower if this is the final solution.
- Native project is in the messiest possible location.
- [HACK] JIT memory access always uses native "fast" path
- [HACK] Trying some things with texture invalidation and views.
It works :)
Still a few hacks, messy things, slow things
More work in progress stuff (also move to memory project)
Quite a bit faster now.
- Unmapping GPU VA and CPU VA will now correctly update write tracking regions, and invalidate textures for the former.
- The Virtual range list is now non-overlapping like the physical one.
- Fixed some bugs where regions could leak.
- Introduced a weird bug that I still need to track down (consistent invalid buffer in MK8 ribbon road)
Move some stuff.
I think we'll eventually just put the dll and so for this in a nuget package.
Fix rebase.
[WIP] MultiRegionHandle variable size ranges
- Avoid reprotecting regions that change often (needs some tweaking)
- There's still a bug in buffers, somehow.
- Might want different api for minimum granularity
Fix rebase issue
Commit everything needed for software only tracking.
Remove native components.
Remove more native stuff.
Cleanup
Use a separate window for the background context, update opentk. (fixes linux)
Some experimental changes
Should get things working up to scratch - still need to try some things with flush/modification and res scale.
Include address with the region action.
Initial work to make range tracking work
Still a ton of bugs
Fix some issues with the new stuff.
* Fix texture flush instability
There's still some weird behaviour, but it's much improved without this. (textures with cpu modified data were flushing over it)
* Find the destination texture for Buffer->Texture full copy
Greatly improves performance for nvdec videos (with range tracking)
* Further improve texture tracking
* Disable Memory Tracking for view parents
This is a temporary approach to better match behaviour on master (where invalidations would be soaked up by views, rather than trigger twice)
The assumption is that when views are created to a texture, they will cover all of its data anyways. Of course, this can easily be improved in future.
* Introduce some tracking tests.
WIP
* Complete base tests.
* Add more tests for multiregion, fix existing test.
* Cleanup Part 1
* Remove unnecessary code from memory tracking
* Fix some inconsistencies with 3D texture rule.
* Add dispose tests.
* Use a background thread for the background context.
Rather than setting and unsetting a context as current, doing the work on a dedicated thread with signals seems to be a bit faster.
Also nerf the multithreading test a bit.
* Copy to texture with matching alignment
This extends the copy to work for some videos with unusual size, such as tutorial videos in SMO. It will only occur if the destination texture already exists at XCount size.
* Track reads for buffer copies. Synchronize new buffers before copying overlaps.
* Remove old texture flushing mechanisms.
Range tracking all the way, baby.
* Wake the background thread when disposing.
Avoids a deadlock when games are closed.
* Address Feedback 1
* Separate TextureCopy instance for background thread
Also `BackgroundContextWorker.InBackground` for a more sensible idenfifier for if we're in a background thread.
* Add missing XML docs.
* Address Feedback
* Maybe I should start drinking coffee.
* Some more feedback.
* Remove flush warning, Refocus window after making background context