Commit Graph

984 Commits

Author SHA1 Message Date
PixelyIon
624df92616 Change AddNonGraphicsPass to AddOutsideRpCommand
The terminology "Non-Graphics pass" was deemed to be fairly inaccurate since it simply covered all Vulkan commands (not "passes") outside the render-pass scope, these may be graphical operations such as blits and therefore it is more accurate to use the new terminology of "Outside-RenderPass command" due to the lack of such an implication while being consistent with the Vulkan specification.
2022-04-14 15:20:22 +05:30
Billy Laws
a31332e35f Align Maxwell 3D macro newline slashes 2022-04-14 14:14:52 +05:30
Billy Laws
d79635772f Implement support for GPU-side constant buffer updating
Previously constant buffer updates would be handled on the CPU and only the end result would be synced to the GPU before execute. This caused issues as if the constant buffer contents was changed between each draw in a renderpass (e.g. text rendering) the draws themselves would only see the final resulting constant buffer. Fix this by updating cbufs on the GPU/CPU seperately, only ever syncing them back at the start or after a guest side CPU write, at the moment only a single word is updated at a time however this can be optimised in the future to batch all consecutive updates into one large one.
2022-04-14 14:14:52 +05:30
Robin Kertels
036faedabd Implement a way to run non-graphics passes with command executor
These commands will end the current renderpass and run on their own, this is useful for compute, blits etc.
2022-04-14 14:14:52 +05:30
Billy Laws
feb179fcff Implement primitive restart support
Maxwell3D also supports using an arbitrary restart index value however no games are known to use this so leave it for now.
2022-04-14 14:14:52 +05:30
Billy Laws
3f3acc31d8 Rework swizzle infrastructure to support arbritary format swizzles
This is required to support R4G4B4A4 which has no directly corresponding Vulkan format.

Co-authored-by: Lunar-Pixel <lunarn452@gmail.com>
2022-04-14 14:14:52 +05:30
PixelyIon
6f85a66151 Implement host-only Buffers
We require certain buffers to only be on the host while being accessible through the same abstractions as a guest buffer as they must be interchangeable in usage.
2022-04-14 14:14:52 +05:30
Billy Laws
2c697ec36a Determine depth/stencil texture aspect based off of image swizzle
Required since we can't have a non-rt image with both a depth/stencil aspect at the same time according to vk spec.
2022-04-14 14:14:52 +05:30
PixelyIon
1878e582ad Add ScopedStackBlocker to RomFile.populate
We needed to block stack frame lookups past JNI code as Java doesn't follow the ARMv8 frame pointer ABI which leads to invalid pointer dereferences. Any JNI function that throws or handles exceptions must do this now or it may lead to a `SIGSEGV`.
2022-04-14 14:14:52 +05:30
Billy Laws
68e693d9f4 Fix DMA Engine debug logs to not crash emu
Address causes some type issues when printing directly so explicitly cast to u64 first to prevent them.
2022-04-14 14:14:52 +05:30
Billy Laws
8eaca87de8 Use an empty host texture in place of invalid TIC entries on guest
Some games may pass empty TICs as inputs to shaders while not actually using them within the shader. Create an empty texture and pass this in instead when we hit this case, the nullDescriptor feature could be used but it's not supported by all devices so we chose to do it this way instead.
2022-04-14 14:14:52 +05:30
PixelyIon
41b98c7daa Add stack tracing to skyline::exception
Skyline's `exception` class now stores a list of all stack frames during the invocation of the exception. These can later be parsed by the exception handler to generate a human-readable stack trace. To assist with more complete stack traces, `-fno-omit-frame-pointer` is now passed on debug builds which forces the inclusion of frames on function calls.
2022-04-14 14:14:52 +05:30
PixelyIon
cd8fa66326 Fix NCE Destruction
NCE is implicitly depended on by the `GPU` class due to the NCE Memory Trapping API so the destruction of it must take place after the destruction of the `GPU` class. Additionally, to prevent bugs the NCE destructor must set `staticNce` to `nullptr` as the signal handler will potentially access a destroyed instance of NCE otherwise.
2022-04-14 14:14:52 +05:30
Billy Laws
815f1f4067 Add support for sRGB TIC textures
Without this sRGB textures would be interpreted as RGB leading to colours being slighly off. The sRGB flag isn't stored as part of format word so we reuse the _pad_ field of it to store the flag for the switch case.
2022-04-14 14:14:52 +05:30
Billy Laws
1ba4abf950 Add Astc{6x6,8x8} and R4G4B4A4 image formats 2022-04-14 14:14:52 +05:30
MCredstoner2004
dec0571eee Infrastructure for applets to be implemented
This removes a stub for an applet and implements several applet related service calls.
2022-04-14 14:14:52 +05:30
PixelyIon
164d4852fa Sleep-loop rather than abort during termination
We don't want to actually exit the process as it'll automatically be restarted gracefully due to a timeout after being unable to exit within a fixed duration so we just want to infinite sleep during termination. This should fix issues where exiting any game would cause the app to force close after some time as exception signal handling would fail in the background, the app should stay open now and automatically restart itself when another game is loaded in.
2022-04-14 14:14:52 +05:30
PixelyIon
ea00f1bb82 Flush emulation logs after exceptions
A lot of logs are incomplete due to being unable to flush inside the signal handler, now we flush after any exceptions so that there is a guarantee of any exceptions being logged as this is crucial for proper debugging.
2022-04-14 14:14:52 +05:30
PixelyIon
62ba180550 Use R5G6B5 as Vulkan swapchain format rather than B5G6R5
B5G6R5 isn't generally supported by the swapchain and the format is used for R5G6B5 with swapped R/B channels to avoid aliasing so we reverse that by using R5G6B5 as the underlying Vulkan format for the swapchain which should be automatically handled by the driver for any copies from B5G6R5 textures and the data representation should be the same as B5G6R5 with swapped R/B channels so not reporting the correct texture::Format should be fine.
2022-04-14 14:14:52 +05:30
MK73DS
e54f86e923 Fix IApplicationFunctions::GetDisplayVersion id
(https://switchbrew.org/wiki/Applet_Manager_services#IApplicationFunctions)
2022-04-14 14:14:52 +05:30
Billy Laws
77cf33b643 Trigger command executor before DMA copies
DMA copies can use textures currently in active use on the GPU as dst/src so Execute before to prevent a deadlock
2022-04-14 14:14:52 +05:30
Billy Laws
dbbc5704d2 Implement DMA engine Block Linear->Linear copies 2022-04-14 14:14:52 +05:30
Billy Laws
3e4e8de1d2 Implement primitive Linear->Block Linear DMA engine copies
Slightly inaccurate and misses some features but good enough for most games, should be revisted later.
2022-04-14 14:14:52 +05:30
Billy Laws
3c26921d54 Implement the Maxwell DMA engine
The DMA engine is used to perform DMA buffer/texture copies directly on the GPU. It can deswizzle arbritary regions of input textures, perform component remapping and swizzle into output textures.
This impl only supports 1D buffer copies, 2D ones will come later.
2022-04-14 14:14:52 +05:30
Billy Laws
3df76e84c3 Stub IRequest::GetAppletInfo in nifm 2022-04-14 14:14:52 +05:30
Billy Laws
6c5f9941ad Stub additional IAddOnContentManager functions
Used mainly by UE4 games
2022-04-14 14:14:52 +05:30
Billy Laws
486a835d0a Use guest texture view type to determine the underlying image type
If we have a Nx1x1 image then determining the type from dimensions will result in a 1D image being created thus preventing us from creating a 2D view. By using the image view type we can avoid this for textures from TICs since we know in advance how they will be used
2022-04-14 14:14:52 +05:30
Billy Laws
05966f34e5 Stub a pair of ISelfController functions
Both used by SMO, SetScreenShotPermission and SetAlbumImageOrientation
2022-04-14 14:14:52 +05:30
Billy Laws
fe37d7c9be Implement ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled 2022-04-14 14:14:52 +05:30
Billy Laws
9813f9f8dc Implement ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent 2022-04-14 14:14:52 +05:30
Billy Laws
7e7c0252ca Implement IApplicationFunctions::GetDisplayVersion 2022-04-14 14:14:52 +05:30
Billy Laws
b1f10865a0 Attach depth RT to command executor before draws
This enforces that the depth RT outlives the draw, without this the depth RT could be freed while in active use by command executor leading to UAFs and crashes.
2022-04-14 14:14:52 +05:30
Billy Laws
0182fabc50 Stub {Set,Get}NpadHandheldActivationMode in HID 2022-04-14 14:14:52 +05:30
Billy Laws
2e197cead5 Support D32S8_Float_Uint_Unorm_Unorm depth/stencil format 2022-04-14 14:14:52 +05:30
Billy Laws
7717a86fb1 Implement VMM region->region copies
Required by the DMA engine, a simple memcpy doesn't work since the buffers could span multiple blocks.
2022-04-14 14:14:52 +05:30
Billy Laws
af90d4f977 Implement audren Surround->Stereo downmixing 2022-04-14 14:14:52 +05:30
PixelyIon
ad0005f398 Remove guard-page from main thread stack
This was erroneously included while migrating from older code where stack creation was entirely handled with host constructs such as `mmap` directly to using `KPrivateMemory` to manage it, we would create a guard page with `mprotect` that the guest was unaware about and would cause a segfault when a guest accessed the extents of the stack as reported to the guest.
2022-04-14 14:14:52 +05:30
PixelyIon
de81d28b1d Implement SVC GetThreadContext3
A partial implementation of the `GetThreadContext3` SVC, we cannot return the whole thread context as the kernel only stores the registers we need according to the ARMv8 ABI convention and so far usages of this SVC do not require the unavailable registers but all future usage must be monitored and potentially require extending the amount of saved registers.
2022-04-14 14:14:52 +05:30
PixelyIon
b706aa3463 Implement SVC SetThreadActivity
This SVC can pause/resume a thread, it is used by engines like Unity to pause a thread during a GC world stop.
2022-04-14 14:14:52 +05:30
PixelyIon
36a7ad06bd Use built-in vibrator by default for controller #0
The vibration device had to be set manually prior which led to it generally not being set at all even though a user might want vibration, this commit fixes that by making controller #0 use the built-in vibrator by default.
2022-04-14 14:14:52 +05:30
lynxnb
69ba4f8abb Swap out boostorg/boost for skyline-emu/boost 2022-04-14 14:14:52 +05:30
PixelyIon
b45437b78b Move Skyline internal files to external directory
Any Skyline files that should have been user-accessible were moved from `/data/data/skyline.emu/files` to `/sdcard/Android/data/skyline.emu/files` as the former directory is entirely private and cannot be accessed without either adb or root. This made retrieving certain data such as saves or loading custom driver shared objects extremely hard to do while this can be trivially done now.
2022-04-14 14:14:52 +05:30
Billy Laws
e5e20f39c9 Implement a simple constant buffer cache
In some games such as SMO thousands of constant buffers are bound per frame which was causing an unreasonable number of lookups in both vmm and the buffer manager. Work around this by introducing a simple hashmap based cache, eviction is currently unsupported but not really necessary yet due to the small size of the buffers in the cache.
2022-04-14 14:14:52 +05:30
PixelyIon
cb2614f80e Handle host accesses for NCE Memory Trapping API
We cannot ignore accesses from the host to a region protected by the NCE Memory Trapping API, there's often access to regions which have overlap with a protected region unintentionally and those accesses need to be handled correctly rather than leading to a crash. This is done by implementing an additional signal handler `NCE::HostSignalHandler` to lookup any potential traps on a `SIGSEGV` and handle them correctly or when there isn't a corresponding trap raise a `SIGTRAP` when debugger is connected or delegate to `signal::ExceptionalSignalHandler` when it isn't.
2022-04-14 14:14:52 +05:30
PixelyIon
b04a0c386a Page out RW-trapped memory in NCE Memory Trapping
To cut down memory usage we now page out memory that is RW trapped via the NCE memory trapping API, the callbacks are supposed to page in the memory. This behavior is backed up by Texture/Buffer syncing which would read the host copies of data and write it to the guest, by paging the corresponding data on the guest we're avoiding redundant memory usage.
2022-04-14 14:14:52 +05:30
PixelyIon
344c5f2a62 Implement RAII wrapper over file descriptors
The `FileDescriptor` class is a RAII wrapper over FDs which handles their lifetimes alongside other C++ semantics such as moving and copying. It has been used in `skyline::kernel::MemoryManager` to handle the lifetime of the ashmem FD correctly, it wasn't being destroyed earlier which can result in leaking FDs across runs.
2022-04-14 14:14:52 +05:30
PixelyIon
7ce2a903a1 Update LLVM + Oboe
Initially this commit was only intended to update LLVM but due to a compilation error  on latest LLVM libcxx due to the C++ stdlib header `<algorithm>` being a transitive dependency that is no longer transitively included on the latest LLVM libcxx (as of https://reviews.llvm.org/D119667), this required changes in Skyline and Oboe which were done in https://github.com/google/oboe/pull/1521 and the submodule has been updated to include those changes.
2022-04-14 14:14:52 +05:30
Billy Laws
c549788377 Update shader compiler 2022-04-14 14:14:52 +05:30
Billy Laws
01c027b9f6 Fix GetBlockLinearLayerSize to avoid incorrectly calculating a zero size 2022-04-14 14:14:52 +05:30
PixelyIon
c84badb498 Update NDK (25.0.8221429) + Gradle (7.4.1) + Build Tools (33.0.0) 2022-04-14 14:14:52 +05:30
lynxnb
08e24915d8 Add support for drawing inside the display cutout areas 2022-04-14 14:14:52 +05:30
MK73DS
6e929e6f6a Stub ICommonStateGetter::SetCpuBoostMode
This makes Metroid Dread boot
2022-04-14 14:14:52 +05:30
Billy Laws
d033ff2478 Fix draws when no colour RTs and only depth is bound 2022-04-14 14:14:52 +05:30
Billy Laws
d137051833 Add basic support for 3d/cubemap textures
These are mostly used in 3D games like SMO, support is still quite basic and synchronising block linear 3D texture will crash in most cases due to them being unimplemented.
2022-04-14 14:14:52 +05:30
Billy Laws
bcc00216b7 Fix incorrect Bc2/3 block sizes 2022-04-14 14:14:52 +05:30
PixelyIon
7e9b0fec77 Increase reported audren revision to 11
Some games crash due to requiring an `audren` version greater than 7. The `audren` version can be increased without any issues as `audren` is stubbed and therefore the reported version doesn't matter.
2022-04-14 14:14:52 +05:30
PixelyIon
e294fa8c91 Add subpass limit quirk to fix Adreno driver bug
Older Adreno proprietary drivers (5xx and below) will segfault while destroying the renderpass and associated objects if more than 64 subpasses are within a renderpass due to internal driver implementation details. This commit introduces checks to automatically break up a renderpass when that limit is hit.
2022-04-14 14:14:52 +05:30
PixelyIon
65d5a3bce5 Align all Buffers to page boundary
We have support for overlapping buffers which allows us to merge a lot of smaller buffers located on a single page into a single larger buffer which allows for better performance. It additionally ensures that all host buffers match the alignment guarantees of the guest and adequately fulfill host alignment requirements.
2022-04-14 14:14:52 +05:30
PixelyIon
cb1ec9a7f4 Rework BufferManager, Buffer and BufferView
This commit encapsulates a complex sequence of cascading changes in the process of supporting overlaps for buffers:
* We determined that it is impossible to resolve overlaps with multiple intervals per buffer within the constraints of each overlap being a contiguous view, support for multiple intervals was therefore dropped. The older buffer manager code was entirely reworked to be simpler due to only handling one interval per buffer with code now being based off `IntervalMap` but tailored specifically for buffers.
* During overlap resolution, the problem of how existing views into the buffer being recreated would be updated, it had to be replaced with a larger buffer that could contain all overlaps and all existing views would need to be repointed to it. This was addressed by a buffer owning all views to itself, we could automatically recalculate the offset of all views and update the buffers with it.
* We still needed to update usage of existing views which was done by handling all access (such as inside a recorded draw) to buffer view properties via `BufferView::RegisterUsage` which dispatches a callback with the view and the corresponding backing buffer. This callback can be stored and called during overlap resolution with the new buffer.
* We had issues with lifetime of the buffer with the handle-like semantics of `BufferView` introduced in the last buffer-related commit, if we updated the view to be owned by a new buffer we'd need to extend the lifetime of the new buffer not the older one and the only way to do this was a proxy owner object `BufferDelegate` which holds a shared pointer to the real `Buffer` which in-turn holds a pointer to all `BufferDelegate` objects to update on repointing. A `BufferView` is effectively just a wrapper around `std::shared_ptr<BufferDelegate>` with more favorable semantics but generally just forwarding calls.
It should be additionally noted that to support usage of `RegisterUsage` the code around buffers in `GraphicsContext` was refactored to defer truly binding till the recording phase.
2022-04-14 14:14:52 +05:30
PixelyIon
a6781b38f4 Clear syncBuffers after CommandExecutor execution
Due to an oversight, we weren't clearing the list of buffers that needed to be synced after every execution which led to them building up. Due to the relatively cheap synchronization of buffers and only doing so on faults this wasn't caught until now, it does depress the framerate significantly over time due to the size of the list growing to be in the range of 100k buffer views depending on the title.
2022-04-14 14:14:52 +05:30
kaikecarlos
49c0ba1207 Implement IAccountServiceForApplication::IsUserRegistrationRequestPermitted 2022-04-14 14:14:52 +05:30
kaikecarlos
e8cc760b10 Implement IHidServer Functions
Add GetVibrationDeviceInfo and StartSixAxisSensor
2022-04-14 14:14:52 +05:30
kaikecarlos
9f51664b1d Stub IRS Service 2022-04-14 14:14:52 +05:30
lynxnb
707c0cc0af Stub aocsrv::IAddOnContentManager::ListAddOnContent 2022-04-14 14:14:52 +05:30
lynxnb
873ed641ea Stub nfp::IUser::ListDevices and nfp::IUser::GetState 2022-04-14 14:14:52 +05:30
lynxnb
7d518cba2b Stub am::ICommonStateGetter::IsVrModeEnabled 2022-04-14 14:14:52 +05:30
Billy Laws
c55e1a135e Update adrenotools 2022-04-14 14:14:52 +05:30
Robin Kertels
594f061b21 Implement SSBOs
Co-authored-by: Billy Laws <blaws05@gmail.com>
2022-04-14 14:14:52 +05:30
Billy Laws
82d2a9ab56 Unify engine related macros to avoid excessive code duplication 2022-04-14 14:14:52 +05:30
Billy Laws
ae41ddf4f0 Implement a skeleton compute engine
The Kepler compute engine is used to run compute jobs encapsulated in to QMDs on the GPU, this commit doesn't implement compute itself but adds the register and QMD structs that will be needed for it in the future.
2022-04-14 14:14:52 +05:30
Billy Laws
0298a7b1f6 Implement the actual inline to memory engine on subch 2
Used mostly by OGL games for copying stuff around.
2022-04-14 14:14:52 +05:30
Billy Laws
ba7111d33a Add maxwell3d I2M support 2022-04-14 14:14:52 +05:30
Billy Laws
8c73b62b2c Implement basic inline2memory engine support
Not currently used by anything but will be used by both compute, 3D and its own engine in the future. Block linear copies are currently unsupported.
2022-04-14 14:14:52 +05:30
Billy Laws
5c387f5c5a Fixup depth mode init value to allow ignoring redundant calls 2022-04-14 14:14:52 +05:30
PixelyIon
7a5c771f44 Rework GPU BufferView to have handle-like semantics
We wanted views to extend the lifetime of the underlying buffers and at the same time preserve all views until the destruction of the buffer to prevent recreation which might be costly in the future when we need `VkBufferView`s of the buffer but also require a centralized list of all views for recreation of the buffer. It also removes the inconsistency between `BufferView*` being returned in `GetXView` in `GraphicsContext`.
2022-04-14 14:14:52 +05:30
Billy Laws
fae5332f20 Disable descriptor aliasing on Adreno to workaround shader compiler bug
Alised descriptor sets are incorrectly interpreted by the shader compiler causing it to bugger up LLVM function argument types and crash

Co-authored-by: PixelyIon <pixelyion@protonmail.com>
2022-04-14 14:14:52 +05:30
Billy Laws
fc2c123ae2 Implement GPU depthMode register
This controls the depth range used by the shader, hades already has support for the necessary patching so we only need to pass the current mode over to it and it'll do the necessary work.
2022-04-14 14:14:52 +05:30
Billy Laws
7e088ca465 Fix constbuf updates to actually increment the write offset
Uses the register directly now as when we modify it we want the changes to be visible from macros too.
2022-04-14 14:14:52 +05:30
PixelyIon
d2f3479610 Use eB5G6R5UnormPack16 VkFormat for B5G6R5Unorm and R5G6B5Unorm
Using `eB5G6R5UnormPack16` (with a swizzle for `R5G6B5Unorm`) removes the need for `VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` when those formats are aliased which happens in Sonic Mania among other titles.
2022-04-14 14:14:52 +05:30
PixelyIon
24d7066d8b Add quirk to avoid VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT on Adreno GPUs
Adreno GPUs have significant performance penalties from usage of `VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` which require disabling UBWC and on Turnip, forces linear tiling. As a result, it's been made an optional quirk which doesn't supply the flag in `VkImageCreateInfo` and logs a warning if a view with a different Vulkan format from the original image is created.
2022-04-14 14:14:52 +05:30
PixelyIon
731d06010d Set eMutableFormat in Texture Image Creation
We often need to alias the underlying data as multiple Vulkan formats which requires the `eMutableFormat` bit to be set in `VkImageCreateInfo`, without doing this there'll be validation layer errors and potentially GPU bugs.
2022-04-14 14:14:52 +05:30
PixelyIon
dafcfa68ca Transition texture layout to eGeneral after creation
As we no longer set the layout to general inside the Texture constructor, yet, we need it to be set prior to the image being used as an attachment. We need to transition the layout to `eGeneral` after creation of the texture object.
2022-04-14 14:14:52 +05:30
PixelyIon
5dea15632c Add Controller Setup Guide
A setup guide for controllers that goes through every available button/stick sequentially and opens up a corresponding dialog to map them.
2022-04-14 14:14:52 +05:30
PixelyIon
e2cae74425 Fix RecyclerView height in CoordinatorLayout for non touch-mode
Any `RecyclerView`s with an app bar in a `CoordinatorLayout` would end up going off-screen due to the layout behavior implementing an offset by using a transform which would not correctly handle focusing on off-screen objects. This has now been fixed by manually adjusting height to be clipped to what is visible on the screen.
2022-04-14 14:14:52 +05:30
PixelyIon
3ae62c7fcc Collapse appBarLayout on appList focus
We collapse the app bar when the focus is on the app list which only occurs while using a controller, this is required as the app bar will never be collapsed otherwise. It also removes the older code to work around the limitation on `View.FOCUS_DOWN` by collapsing only when the end of the list was reached.
2022-04-14 14:14:52 +05:30
PixelyIon
3e4ec7323b Tweak grid compact items
Removes card elevation as it visually conflicts with the scrim, this also makes the scrim a bit darker to emphasize the text and slightly reduces the border radius.
2022-04-14 14:14:52 +05:30
PixelyIon
1d984b6de3 Add padding to end of app_list
A small amount of padding at the end of `app_list` to signify that the end of the list has been reached was added.
2022-04-14 14:14:52 +05:30
PixelyIon
bac7c526ef Make layout selectable for grid items
The entire layout is now selectable for grid items rather than just the card, this greatly increases the visibility of the selection when not in touch mode as the contrast of a darken effect on the icon can be minimal depending on how dark the icon already is.
2022-04-14 14:14:52 +05:30
PixelyIon
1d070e6332 Close InputStream after usage in KeyReader
The `InputStream` would not be closed after reading the key file in `KeyReader#import`, it's now wrapped with `use{ }` which handles closing the stream after usage.
2022-04-14 14:14:52 +05:30
MK73DS
647cb07dc8 Stub functions in IAccountServiceForApplication:
- GetUserCount
- InitializeApplicationInfo
- IsUserAccountSwitchLocked
2022-04-14 14:14:52 +05:30
PixelyIon
b41d8b7997 Use Surface#setFrameRate for suggesting display refresh rate
Setting the refresh rate via the Display API's`preferredDisplayModeId` is an outdated method to do it on Android 11 and above, we now use `Surface#setFrameRate` alongside it to suggest a refresh rate for the display.
2022-04-14 14:14:52 +05:30
PixelyIon
730bf504f8 Correct Adreno texture binding quirk
We incorrectly determined an Adreno driver bug to require padding between binding slots but the real issue was not supporting consecutive binding writes for `VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER` and was fixed by the padding slot unintentionally requiring individual writes. The quirk has now been corrected to explicitly specify this as the bug and the solution is more apt.
2022-04-14 14:14:52 +05:30
PixelyIon
da8cb48933 Fix Interval Map GetAlignedRecursiveRange lookup bug
Any lookups done using `GetAlignedRecursiveRange` incorrectly added intervals in the exclusive interval entry lookups as the condition for adding them was the reverse of what it should've been due to a last minute refactor, it led to graphical glitches and crashes. This has been fixed and the lookups should return the correct results.
2022-04-14 14:14:52 +05:30
PixelyIon
f2faa74707 Fix crashes due to SEGV_ACCERR check
On certain devices, accesses to a protected memory region can return `si_code` as non-`SEGV_ACCERR` values, this leads to a crash as we only pass access violations to the trap handler and would lead to not doing so on those devices which would then result in going to the crash handler.
2022-04-14 14:14:52 +05:30
PixelyIon
62c16fa73e Upgrade Gradle (7.4), AGP (7.1.2) and Kotlin Dependencies 2022-04-14 14:14:52 +05:30
PixelyIon
77e2797219 Delete expired weak_ptrs for Texture/Buffer views
A large amount of Texture/Buffer views would expire before reuse could occur in `Texture::GetView`/`Buffer::GetView`. These can lead to a substantial memory allocation given enough time and they are now deleted during the lookup while iterating on all entries.

It should be noted that there are a lot of duplicate views that don't live long enough to be reused and the ultimate solution here is to make those views live long enough to be reused.
2022-04-14 14:14:52 +05:30
PixelyIon
881bb969c4 Implement access-driven Buffer synchronization
Similar to constant redundant synchronization for textures, there is a lot of redundant synchronization of buffers. Albeit, buffer synchronization is far cheaper than texture synchronization it still has associated costs which have now been reduced by only synchronizing on access.
2022-04-14 14:14:52 +05:30
PixelyIon
7532eaf050 Attach Texture to Cycle in Texture::TransitionLayout
Not doing so could result in the texture being destroyed before the completion of a transition and lead to undefined behavior.
2022-04-14 14:14:52 +05:30
PixelyIon
3268b3779a Implement access-driven Texture synchronization
There was a lot of redundant synchronization of textures to and from host constantly as we were not aware of guest memory access, this has now been averted by tracking any memory accesses to the texture memory using the NCE Memory Trapping API and synchronizing only when required.
2022-04-14 14:14:52 +05:30
PixelyIon
3e33d49faf Implement NCE Memory Trapping API
An API for trapping accesses to guest memory and performing callbacks based on those accesses alongside managing protection of the memory. This is a fundamental building block for avoiding redundant synchronization of resources from the guest and host.

Note: All accesses are treated as write accesses at the moment, support for picking up read accesses will be implemented later
2022-04-14 14:14:52 +05:30
PixelyIon
08510d75b0 Implement Interval Map
An interval map is a crucial piece of infrastructure required for memory faulting to track any regions that have an associated callback and their protection. Additionally, efficient page-aligned lookups with semantics optimal for memory faulting are also a requirement and the ability to associate multiple regions with a single callback/protection entry rather than doing so on a per-region basis as we deal with split-mapping resources.
2022-04-14 14:14:52 +05:30
PixelyIon
5c9e42e384 Use mirror mappings for Textures and Buffers
This is a prerequisite to memory trapping as we need to write to the mirror to avoid a race condition with external threads writing to a texture/buffer while we do so ourselves for the sync on a read/write, it also avoids an additional `mprotect` to `-WX`/`RWX` on a read access.

An additional advantage for textures especially is that we now support split-mapping textures due to laying them out in a contiguous mirror and they will not require costly algorithmic changes. Buffers should also benefit from not needing to iterate over every region when they are split into multiple mappings.
2022-04-14 14:14:52 +05:30
PixelyIon
577a67babd Support mirrors of multiple non-contiguous memory regions
`CreateMirror` is limited to creating a mirror of a single contiguous region which does not work when creating a contiguous mirror of multiple non-contiguous regions. To support this functionality, `CreateMirrors` which expects a list of page-aligned regions and maps them into a contiguous mirror.
2022-04-14 14:14:52 +05:30
PixelyIon
e35ab6d1e0 Move to mapping guest AS as shared memory
We want to create arbitrary mirrors in the guest address space and to make this possible, we map the entire address space as a shared memory file. A mirror is mapped by using `mmap` with the offset into the guest address space.
2022-04-14 14:14:52 +05:30
Billy Laws
a5dd961f01 Add support for batched method sending
Important for constbuf updates which would be very slow if done one at a
time.
2022-04-14 14:14:52 +05:30
Robin Kertels
43879e2476 Round up when calculating size of compressed texture in bytes 2022-04-14 14:14:52 +05:30
Robin Kertels
d889550e84 Don't set COLOR_ATTACHMENT_BIT for compressed formats.
The better solution would be to only set this for formats that support
it on original HW but this will get rid of the validation errors for now.
2022-04-14 14:14:52 +05:30
Robin Kertels
82296ac5b8 Use buffer size instead of allocation size for Buffer constructor
Fixes a validation error.
2022-04-14 14:14:52 +05:30
Robin Kertels
752245c3c8 Enable provoking vertex feature 2022-04-14 14:14:52 +05:30
Robin Kertels
dd45d054e7 Enable shaderDrawParameters 2022-04-14 14:14:52 +05:30
Billy Laws
737ff840a5 Update adrenotools for BTI 2022-04-14 14:14:52 +05:30
Billy Laws
7e16c1f989 Heavily optimise GPFIFO command dispatch to reduce redundant checks
Previously for methods with count > 1 the subchannel and engine would be looked up for each part of the method rather than only doing so at the start. Each call also needed to be looked up to see if it touched a macro or GPFIFO method. Fix this by doing checks outside of the main dispatch loop with templated helper lambdas to avoid needing to repeat lots of code. Maxwell3D is the only subchannel with a fast path for now but more can be added later if needed.
2022-04-14 14:14:52 +05:30
Billy Laws
b4927d0138 Add support for turnip and driver file redirection via libadrenotools 2022-04-14 14:14:52 +05:30
Billy Laws
dd91d063a5 Pass native library dir to OS + reorder OS init order so paths are first
This is required for integrating libadrenotools, which needs access to
library and app directories in the GPU class constructor.
2022-04-14 14:14:52 +05:30
Billy Laws
900d00a876 Update tzcode with missed bugfix 2022-04-14 14:14:52 +05:30
Billy Laws
011de98940 Rework formats to support passing through guest swizzle values
Almost every Maxwell format now directly corresponds to a Vulkan format. This allows formats to be passed through and the swizzle used directly from guest (with some extra swizzle handling for edge cases) thus saving the need to explicitly support each swizzle combination which is adds a lot of code bloat. The format header is additionally reordered with line breaks to separate formats by their bits-per-block.
2022-04-14 14:14:52 +05:30
Billy Laws
6f17d1351f Fixup ordering for B10G11R11Float texture format 2022-04-14 14:14:52 +05:30
Billy Laws
78238d550a Add 6 channel downmixing support for Audout
The specific attenuations used for each channel are taken from Ryujinx.
2022-04-14 14:14:52 +05:30
Billy Laws
2e1a1a965d Fixup AudioTrack locking 2022-04-14 14:14:52 +05:30
PixelyIon
727f83e969 Fix Incorrect Vertex Binding Divisor State Submission
We always submit pipeline divisor descriptions regardless of binding input rate being vertex rather than instance. This is invalid behavior and has been fixed by only submitting binding descriptors when the input rate is per-instance.
2022-04-14 14:14:52 +05:30
PixelyIon
9f7e80cf8f Fix Adreno Texture Sampler Binding Bug
Adreno proprietary drivers suffer from a bug where `VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER` requires 2 descriptor slots rather than one, we add a padding slot to fix this issue. `QuirkManager` was introduced to handle per-vendor/per-device errata and allow enabling this on Adreno proprietary drivers specifically as to not affect the performance of other devices.
2022-04-14 14:14:52 +05:30
PixelyIon
ddb2ba8a1b Rename QuirkManager to TraitManager
Quirk terminology was deemed to be inappropriate for describing the features/extensions of a device. It has been replaced with traits which is far more fitting but quirks will be used as a terminology for errata in devices.
2022-04-14 14:14:52 +05:30
PixelyIon
0b2ce6a8f3 Fix Texture Handle Offset Calculation
The texture handle offset calculation involved an incorrect shift by descriptor size which was found to be unnecessary and would result in an invalid handle that had the wrong TIC/TSC index and caused broken rendering.
2022-04-14 14:14:52 +05:30
PixelyIon
aa57ec6d55 Destroy CommandExecutor Nodes Before Waiting on Execution
`nodes` and `syncTextures` were cleared after waiting on the `CommandExecutor` fence rather than before, this wasted execution time after the wait for something that could be performed prior to the wait.
2022-04-14 14:14:52 +05:30
PixelyIon
90a1b3348c Implement D24S8 + R11G11B10 Formats 2022-04-14 14:14:52 +05:30
PixelyIon
bd718175ce Enable VK_KHR_uniform_buffer_standard_layout when available
We now attempt to enable `VK_KHR_uniform_buffer_standard_layout` when present as lax UBO layout significantly reduces complexity. If a device doesn't support this extension, we still assume that the device supports it implicitly as this has proven to be true across all major mobile GPU vendors regardless of the driver version but enabling this prevents validation layer errors.
2022-04-14 14:14:52 +05:30
PixelyIon
22ce531e6f Force Memory Barrier at VkRenderPass Start
We depend on past commands to have completed execution in a renderpass, a subpass dependency on all graphics stages from `VK_SUBPASS_EXTERNAL` to subpass #0 is used to enforce this. Nvidia and Adreno proprietary drivers implicitly do this but Turnip or Mali drivers require this or they execute out of order.
2022-04-14 14:14:52 +05:30
PixelyIon
35fde2cd0b Rework Blocklinear Texture Deswizzling
Blocklinear texture decoding was broken for padding blocks and would incorrectly decode them resulting in major texture corruption for any textures with their widths not aligned to 64 bytes. This has now been fixed with neater code which avoids redundant repetition of any code using lambdas and functions where necessary.
2022-04-14 14:14:52 +05:30
PixelyIon
043be4d8f7 Implement Maxwell3D Two-Side Stencil Toggle
Stencil operations are configurable to be the same for both sides or have independent stencil state for both sides. It is controlled via the previously unimplemented `stencilTwoSideEnable`.
2022-04-14 14:14:52 +05:30
PixelyIon
80ae7b255a Implement Maxwell3D Front Face Flip 2022-04-14 14:14:52 +05:30
PixelyIon
40a3887695 Implement Maxwell3D Viewport Y Swizzle & Lower-Left Origin 2022-04-14 14:14:52 +05:30
Billy Laws
3be30e68c3 Add D16 depth format and ZF32 TIC format
Used by One Piece Unlimited World Red
2022-04-14 14:14:52 +05:30
Billy Laws
be007c4ccc Fixup texture swizzling to actually function
Before this we were not applying the supplied swizzles, will be
superseeded in the future by using guest swizzle values.
2022-04-14 14:14:52 +05:30
Billy Laws
6e48460c0d Add BC2/3 format support 2022-04-14 14:14:52 +05:30
Billy Laws
2253bc3151 Reorder GPU quirks member to prevent it constructing after device init 2022-04-14 14:14:52 +05:30
Billy Laws
62db21fb78 Rework GPFIFO method distribution and macros to support multiple engines
Fermi2D supports macros in addition to Maxwell3D, these both share code memory. To support this we rework the macro interpreter to support passing in a target engine and abstract the communications out into an interface that can be implemented by applicable engines.

```
GPFIFO <-> MME <-> Maxwell3D
    ^        ^---> Fermi2D
    X------------> I2M
    X------------> MaxwellComputeB
    X--Flush-----> MaxwellDMA
```
2022-04-14 14:14:52 +05:30
Billy Laws
8d5463ef28 Drop engine base class usage from GPFIFO
This class does nothing since we made stopped GPFIFO submits from using
virtual functions so it can be dropped.
2022-04-14 14:14:52 +05:30
Billy Laws
4378658cbc Update BCeNabler to support ---X .text devices 2022-04-14 14:14:52 +05:30
PixelyIon
41aad83c33 Tie Shader ObjectPool Lifetime to Shader Program
Shader programs allocate instructions and blocks within an `ObjectPool`, there was a global pool prior that was never reaped aside from on destruction. This led to a leak where the pool would contain resources from shader programs that had been deleted, to avert this the pools are now tied to shader programs.
2022-04-14 14:14:52 +05:30
PixelyIon
e747de37cf Implement Blocklinear TIC Type 2022-04-14 14:14:52 +05:30
PixelyIon
723189a948 Calculate Blocklinear Texture Aligned Size Correctly
The size of blocklinear textures did not consider alignment to Block/ROB boundaries before, it is aligned to them now. Incorrect sizes led to textures not being aliased correctly due to different size calculations for GraphicBufferProducer surfaces and Maxwell3D color RTs.
2022-04-14 14:14:52 +05:30
Billy Laws
95685b8207 Avoid iterator invalidation segfault when unregistering a syncpt waiter
erase invalidated `it` leading to a potential segfault if the GPU was very far behind, bail out early to avoid that since there can only be one occurence at most in the buffer anyway.
2022-04-14 14:14:52 +05:30
Billy Laws
e7bfd93541 Implement BC7 format support
Used by ARMS
2022-04-14 14:14:52 +05:30
Billy Laws
99652c5eda Support partially mapped cbufs
Buggy games sometimes supply an incorrect cbuf size so limit buffers to the first unmapped region.
2022-04-14 14:14:52 +05:30
PixelyIon
6a6f51ea84 Implement Maxwell3D Depth/Stencil State
Implements the entirety of Maxwell3D Depth/Stencil state for both faces including compare/write masks and reference value. Maxwell3D register `stencilTwoSideEnable` is ignored as its behavior is unknown and could mean the same behavior for both stencils or the back facing stencil being disabled as a result of this it is unimplemented.
2022-04-14 14:14:52 +05:30
PixelyIon
9f5c3d8ecd Force Textures to be Optimal on Host GPU
We don't respect the host subresource layout in synchronizing linear textures from the guest to the host when mapped to memory directly, this leads to texture corruption and while the real fix would involve respecting the host subresource layout, this has been deferred for later as real world performance advantages/disadvantages associated with this change can be observed more carefully to determine if it's worth it.
2022-04-14 14:14:52 +05:30
Billy Laws
ab4962c4e4 Implement additional texture formats, including BCn
BCeNabler is required for BCn textures, the pre-swizzled formats will be removed when arbitary swizzle support is added later.
2022-04-14 14:14:52 +05:30
Billy Laws
600b94505c Fix A2R10G10B10 render target format
This was wrongly described as R10G10B10A2 in the enum when it's actually A2R10G10B10, a format natively supported in Vulkan with just a swizzle.
2022-04-14 14:14:52 +05:30
Billy Laws
175ba11f07 Integrate BCeNabler support into QuirkManager
Allows using BCn format textures on devices where they are unsupported by the driver.
2022-04-14 14:14:52 +05:30
Billy Laws
47d920d91e Make GPU private static functions file-local 2022-04-14 14:14:52 +05:30