Commit Graph

574 Commits

Author SHA1 Message Date
Billy Laws
34bf413661 Fix bitmask check for event IDs > 32 in Ctrl::SyncpointFreeEventBatch
Doing 1 << 32 would result in an integer overflow rather than the desired behaviour of checking a bit, make 1 64 bit to present that.
2021-11-10 21:34:30 +05:30
Billy Laws
debab7c9c7 Implement nvmap handle pinning/unpinning
nvmap allows mapping handles into the SMMU address space through 'pins'. These are refcounted mappings that are lazily freed when required due to AS space running out. Nvidia implements this by using several MRU lists of handles in order to choose which ones to free and which ones to keep, however as we are unlikely to even run into the case of not having enough address space a naive queue approach works fine. This pin infrastructure is used by nvdrv's host1x channel implementation in order to handle mapping of both command and data buffers for submit.
2021-11-10 21:34:30 +05:30
Billy Laws
a0c57256cc Hookup FlatMemoryManager for SMMU into SoC
The SMMU is used to control the mappings of peripherals such as the VIC
and NVDEC.
2021-11-10 21:34:30 +05:30
Billy Laws
97dc053ffd Move FlatAllocator allocation error handling to the caller
This is a prerequisite for nvmap SMMU memory management, which only frees the memory handles refer to if an allocation fails.
2021-11-10 21:34:30 +05:30
Billy Laws
04e5237ec1 Stub host1x channel devices and IOCTLs
host1x channels are generally similar to GPU channels however there is only one channel for each specific class (like a GPU engine) and an address space is shared between them all.

This PR implements the simple IOCTLs with the larger ones that will depend on changes outside of nvdrv being left for future commits. This is enough to partly run oss-nvjpeg.
2021-11-10 21:34:30 +05:30
Billy Laws
5087d3dc2a Reserve host1x channel syncpoints 2021-11-10 21:34:30 +05:30
Billy Laws
b0a5dab0f7 Support passing additional constructor arguments to nvdrv devices
Needed for host1x channels which use the same class for multiple types.
2021-11-10 21:34:30 +05:30
Billy Laws
eb6f052873 Fixup GpuChannel::SetNvmapFd to take an FD rather than an nvmap handle 2021-11-10 21:34:30 +05:30
Billy Laws
386a3447a8 Introduce variable sized span support to nvdrv deserialisation
The element containing the size first needs to be saved to a save slot with Save<T, slotId>, it can then be read back later as the size of a span with SlotSizeSpan<T, slotId>. This is needed to support the Host1XChannel Submit IOCTL.
2021-11-10 21:34:30 +05:30
Billy Laws
6eeaa343f8 Avoid crash when passing unallocated syncpoint IDs to EventWait 2021-11-10 21:34:30 +05:30
PixelyIon
fbfad21f03 Migrate Maxwell3D::Registers to OffsetMember
Maxwell3D registers were primarily written with absolute offsets and ended up being fairly messy due to attempting to emulate this using struct relative positioning resulting in a lot of pointless padding members. This has now been improved by utilizing `OffsetMember` to directly use offsets resulting in much neater code.
2021-11-10 21:31:45 +05:30
PixelyIon
69761389ff Extend OffsetMember with direct operator=/operator[]
It was found to be semantically advantageous to directly pass-through certain operators such as the assignment (`=`) and array index (`[]`) operators. These would require a dereference prior to their usage otherwise but now can be directly used.
2021-11-10 21:30:02 +05:30
Billy Laws
cc7b2a0ab8 Introduce OffsetMember for offset-based union members
The offset of a member in a structure was determined by its relative position and compiler alignment. This is unoptimal for larger structures such as those found in GPU Engines that are primarily named by offset rather than relative positioning and end up requiring a massive amount of padding to function as is. A solution to this problem was simply to supply member offsets directly which can be done by using `OffsetMember` alongside a `union`.
2021-11-10 21:17:31 +05:30
PixelyIon
fb476567ff Introduce JniString as C++ wrapper over jstring
We used to manually call JNI UTF-8 string allocation and deallocation functions when utilizing a `jstring` but this could be erroneous and is just inconvenient. All of this has now been consolidated into an class `JniString` which is a wrapper around `std::string` and creates a copy of the contents of the `jstring` in its constructor and passes them into the `std::string` constructor.
2021-11-09 21:18:47 +05:30
PixelyIon
79ceb2cf23 Improve Vulkan Texture Synchronization
The Vulkan Pipeline Barriers were unoptimal and incorrect to some degree prior as we purely synchronized images and not staging buffers. This has now been fixed and improved in general with more relevant synchronization.
2021-11-09 21:08:03 +05:30
PixelyIon
bed9fbf5e7 Fix EmulationActivity.vibrateDevice assert due to null Vibrator
`EmulationActivity.vibrateDevice` would assert when a `null` Vibrator is provided due to one not being set in the controller configuration. This has now been fixed by the code not playing a vibration when a vibration device isn't selected.
2021-11-01 00:28:11 +05:30
PixelyIon
414c0104c3 Rework Joy-Con Vibration Conversion
The guest -> host vibration conversion code was entirely broken as it didn't set the vibration `start`/`end` timestamps correctly for a cycle nor did it subtract from the `totalAmplitude` (`currentAmplitude` now) when it a cycle ended due to an incorrect `if` statement and contents. It would just end up saturating the amplitude as much as possible by adding more and more to `totalAmplitude` on every cycle while never subtracting which is entirely wrong and led to a very noticeable drop in amplitude when a vibration was repeated.

It's been entirely reworked to fix all the issues listed above and remove a lot of code that had no understandable purpose. More comments have also been added to the code to make it more readable with better variable and function naming alongside it.
2021-11-01 00:28:11 +05:30
PixelyIon
96027f0f09 Build libraries with -Ofast for debug builds
To offset some of the performance overhead of using debug builds, we now optimize all libraries using `-Ofast` while building Skyline itself with `-O0`.
2021-10-31 16:05:08 +05:30
PixelyIon
4b80e1f91c Use libcxx from LLVM Project submodule
The version of libcxx shipped with Android NDK is fairly outdated and doesn't contain several features we desire such as C++ 20 ranges. This has been fixed by using libcxx directly from the LLVM Project which has been added as a submodule and can be updated independently of NDK.
2021-10-31 16:04:44 +05:30
PixelyIon
82154f3ef6 Upgrade AGP to 7.1.0-beta01 & NDK to 24.0.7856742
We've moved to using a beta AGP as `7.0.2` is breaks `clangd` and other C++ features on Beta/Canary Android Studio. NDK was additionally updated with `mbedtls` to fix warnings caused by it alongside some other minor fixes to code for newer versions of libcxx.

The new AGP has a bug where it does not look for executables specified in `android_gradle_build.json` in `PATH` that includes `ninja` which is provided by the `ninja-build` package on the system rather than Android SDK's CMake on GitHub Actions (Ubuntu 20.04). This has been fixed by symlinking `/usr/bin/ninja` to the project root which is searched in for the `ninja` executable.
2021-10-31 15:50:15 +05:30
PixelyIon
962d8dc4c8 Return immediately for non-joining KProcess::Kills when already killed
Locking `KProcess::threadMutex` when a process is being killed by another thread with `join` can lead to the non-joining killer effectively joining as it's waiting on the joining killer to relinquish the mutex. This has been fixed by having an atomic boolean tracking if the process has already been killed and if it has, immediately returning prior to locking the mutex for any non-joining killers.
2021-10-31 15:45:10 +05:30
Billy Laws
6f59cba68d Adds bounds checks to resampler to avoid OOB reads
Resampling would sometimes perform an OOB read into `inputBuffer` due it not containing enough data to calculate corresponding the output sample, this has been fixed by introducing bounds checking to ensure that the buffer has enough data.
2021-10-29 21:46:51 +05:30
PixelyIon
9e3b7a75b2 Use finishAffinity instead of finishAndRemoveTask
The method used to finish (`finishAndRemoveTask`) an activity prior to going back to `MainActivity` or restarting the process led to the process prematurely exiting entirely and would result in it not being restarted or another activity not being launched. This has now been fixed by utilizing `finishAffinity` in its place which correctly only ends the activities with the same affinity as the caller.
2021-10-29 21:20:04 +05:30
PixelyIon
9f5ab13858 Implement R16G16{Unorm/Sint/Uint} RT Formats
Utilized in "The Touryst"
2021-10-29 20:21:58 +05:30
PixelyIon
afebf77544 Zero-Initialize GuestTexture Members
Members of `GuestTexture` were apparently not being initialized and this led to UB since they would be read as random values. Titles such as Super Mario Odyssey avoided setting `baseArrayLayer` which led to it being left at the default value which was completely random and this would lead to crashes. This commit fixes this by initializing said values correctly.
2021-10-27 22:49:45 +05:30
PixelyIon
a0921f8261 Implement R16G16B16A16Snorm/R16G16B16A16Sint RT Formats
Utilized in "The Touryst"
2021-10-27 22:49:45 +05:30
PixelyIon
df64ff5d14 Zero-Fill IAudioRenderer::RequestUpdate Output Buffer
Some titles don't clear the output buffer prior to submission, as the service is expected to fill all of it in, our audren implementation is incomplete and doesn't end up doing this leaving the contents of the buffer to be undefined leading to UB in the form of SEGFAULTs or the application throwing a fatal error. This has been patched over by 0-filling the buffer which is a sane default value for the fields that aren't filled in albeit not a replacement for a proper audren implementation.
2021-10-27 16:18:20 +05:30
PixelyIon
1f3519e6e3 Fix Logger Message OOB Access
Certain titles can submit logs where the last field is one off by the buffer end, the logger loop now considers this and terminates if there isn't enough data left to read the field type and length.
2021-10-26 21:59:47 +05:30
PixelyIon
645183c903 Fix OOB Vibration Array Access in VibrateDevice
Access to the `vibrations` field in `vibrations[3].period` could lead to UB, this has been replaced with a proper check which adds up the period over all vibrations instead. A minor cleanup with variable names and explicit types for integer arithmetic has also been done.
2021-10-26 21:57:28 +05:30
PixelyIon
cfdb2abf9e Fix Non-builtin Uncached Vibrator Getter
If a non-builtin vibrator was attempted to be fetched, it'd insert it in the vibrator cache and return directly as opposed to playing the vibration on it prior to returning. This has now been fixed, the value is both put into the cache and the vibration is played on it.
2021-10-26 21:54:33 +05:30
PixelyIon
dc3f7f1ab4 Fix Incorrect Scissor Extent
The decomposition from `texture::Dimension` to `vk::Rect2D` was somehow implicit and completely incorrect resulting in wrong conversion with undefined values. It's now been fixed by explicitly setting `vk::Rect2D::extent` to `scissor` specifically.
2021-10-26 20:08:53 +05:30
PixelyIon
a60f238479 Fix GPU::DebugCallback Type String Extraction
The second parameter of `std::string_view::substr` was assumed to be an end position (similar to `std::span`) rather than `count` which it is. As a result of this, it was entirely broken but only held together by a constant factor being subtracted from it which was derived by trial and error. It's now been fixed by returning a count rather than the absolute position.
2021-10-26 20:08:35 +05:30
PixelyIon
10ed5bf418 Silence errors from libraries
Library headers would produce errors that are out of our control and as a result of that, we just want to ignore this. This is possible by including the offending headers as system headers, compilers don't emit any warnings arising from them. This was extended to all libraries rather than just those which currently emitted warnings for consistency's sake.
2021-10-26 20:08:18 +05:30
Billy Laws
70d1b4994c Enable Wconversion and fix warnings produced 2021-10-26 11:41:24 +01:00
PixelyIon
315d2dc26c Update NDK to 23.1.7779620 2021-10-26 10:46:36 +05:30
PixelyIon
661396fc97 Resume EmulationActivity when launcher icon is used
Fix a bug where attempting to launch Skyline from the launcher while emulation was in progress would result in `MainActivity` launching rather than `EmulationActivity`. We always want `EmulationActivity` to stay on top of the stack and be launched whenever Skyline is resumed, no other activity should be able to run in parallel to `EmulationActivity` in any user-accessible manner.
2021-10-26 10:46:36 +05:30
PixelyIon
39e924aec8 Resume rather than relaunch when same shortcut is used 2021-10-26 10:46:36 +05:30
Billy Laws
1e7347bf72 Use semantic wrapping for nvdrv where appropriate 2021-10-26 10:46:36 +05:30
PixelyIon
830a800d9e Consolidate AddAttachment Loops + Rename Renderpass -> RenderPass 2021-10-26 10:46:36 +05:30
PixelyIon
92a21ea616 Cleanup & Use C++ Concepts in utils.h 2021-10-26 10:46:36 +05:30
PixelyIon
ea2626bcc6 Address CR Comments 2021-10-26 10:46:36 +05:30
PixelyIon
1d532628cb Null-Check Optional NACP before extracting application title
Not doing this can lead to the NACP being filled with invalid data and led to crashes on homebrew titles like SpaceNX.
2021-10-26 10:46:36 +05:30
PixelyIon
c8821c7313 Update nvdrv perms to 11.0.0+ & Implement nvdrv:a service
`nvdrv:a` (For Applets) is used by some older homebrew such as SpaceNX which don't fall back to `nvdrv` (For Applications).
2021-10-26 10:46:36 +05:30
PixelyIon
3b4bbd2b38 Switch to using exceptions for guest exiting
Guest-driven exiting could cause objects left on the heap due to a `std::longjmp` from high up in the host call stack, this has been fixed by introducing `ExitException` which implicitly unrolls the stack with the exception handling mechanism.
2021-10-26 10:46:36 +05:30
PixelyIon
eff5711c49 Split monolithic common.h into smaller chunks
* Resolves dependency cycles in some components
* Allows for easier navigation of certain components like `span` which were especially large
* Some imports have been moved from `common.h` into their own files due to their infrequency
2021-10-26 10:46:36 +05:30
PixelyIon
1d57bab08f Revamp LicenseDialog + Update Licenses + Stop Bintray Usage
* Update licenses for dependent projects
* Add copyright notices (as provided)
* Revamp styling for `LicenseDialog` 
* Fix invisible `PreferenceDialog` buttons in Settings
* Consolidating color variables into `colorPrimary`, `backgroundColor` and `backgroundColorVariant`
* Use `com.google.android.flexbox:flexbox:3.0.0` (Google Maven) rather than `com.google.android:flexbox:2.0.1` (Bintray)
2021-10-26 10:46:36 +05:30
PixelyIon
bbf28d1942 Improve Clean Exit + Audio Pausing + Improve System Language Setting
* Clean Exiting was improved by implementing a robust system for when to abandon clean exiting and simply restart the process alongside moving clean exiting to the background when the application is quit by using the back button
* Audio is now automatically paused whenever the application is moved to the background and automatically resumed when it's brought to the foreground
* The system language setting had several errors and inconsistencies which have now been fixed, it's been brought more in line with HOS language (Albeit not entirely due to no region setting in Skyline)
* Fix a bug with `ThreadLocal` where the atomic `list` pointer was uninitialized resulting in a `SEGFAULT` during the destructor
2021-10-26 10:46:36 +05:30
PixelyIon
a7548c79a0 Android 12 Support + Update Libraries + Include Khronos Validation Layer
* Fix handling `SA_EXPOSE_TAGBITS` bit being set in Android 12 `sigaction`
* Fix CMake bug using `CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE` when not supported causing `-fuse-ld=gold` to be emitted as a linker flag
* Support using `VIBRATOR_MANAGER_SERVICE` rather than `VIBRATOR_SERVICE` on Android 12
* Optimize Imports for Kotlin code
* Move away from deprecated APIs in Kotlin or explicitly mark where it's not possible
* Update SDK, NDK and libraries
* Enable Gradle Configuration Cache
2021-10-26 10:46:36 +05:30
Billy Laws
b7d0f2fafa Implement support for pushbuffer methods split across multiple GpEntries
These are used heavily in OpenGL games, which now, together with the
previous syncpoint changes, work perfectly. The actual implementation is
rather novel as rather than using a per-class state machine for all
methods we only use it for those that are known to be split across
GpEntry boundaries, as a result only a single bounds check is added to
the hot path of contiguous method execution and the performance loss is
negligible.
2021-10-16 12:13:30 +01:00
Billy Laws
fc017e1e95 Implement pre-wait and post-increment syncpoint operations in submit
These are used by both OpenGL and Vulkan games as opposed to including
the operations inside the main commandbuffer.
2021-10-16 12:13:30 +01:00