Commit Graph

520 Commits

Author SHA1 Message Date
sspacelynx
06674b3d07 hwopus decoder service implementation 2021-07-19 02:07:12 +05:30
PixelyIon
b533801bbe Fix Scheduler Core Migration Deadlock
Encountered in 不如帰大乱 when `HOS-3` is awoken at the same time as `HOS-0` called `SvcSetThreadCoreMask` resulting in a deadlock where `HOS-0` owns `HOS-3`'s `coreMigrationMutex` while `HOS-3` owns the core mutex with the both of them attempting to lock the other mutex
2021-07-12 21:27:49 +05:30
PixelyIon
dba99ce542 Implement IApplicationDisplayService::ConvertScalingMode
Utilized by アイリス魔法学園
2021-07-12 21:27:49 +05:30
PixelyIon
1ad5ea6867 Move Mbed TLS to submodule + Update Java Libraries
We've moved from using an AAR for Mbed TLS to a submodule as the AAR was packaged manually and used from a local repository which ended up being very hacky and resulted in Linter errors, it could also not be updated with ease as it would need to be repackaged. All of these issues have been solved by moving to a git submodule tied to the official Mbed TLS GitHub repository.
2021-07-12 21:27:49 +05:30
PixelyIon
ec1da1b3f5 Address CR Comments + Increase minSdkVersion to 29 (Android 10) 2021-07-12 21:27:49 +05:30
PixelyIon
19be9f4b66 Support Sticky Transforms + Minor Formatting Fixes
Sticky transforms have been stubbed, as they are on HOS/Android. Certain titles like Xenoblade Chronicles end up setting the sticky transform even if it doesn't do anything, as a result of this we cannot throw an exception for it and stub it without an exception (Aside from the cases where the value isn't recognized).
2021-07-12 21:27:49 +05:30
PixelyIon
9f967862bd Implement additional IGraphicBufferProducer transactions
The following GraphicBufferProducer transactions were implemented:
* `SetBufferCount`
* `DetachBuffer`
* `DetachNextBuffer`
* `AttachBuffer`
It should be noted that `preallocatedBufferCount` (previously `hasBufferCount`) and `activeSlotCount` were adapted accordingly with how they were effectively the same value as all active buffers were preallocated prior but now there can be a non-preallocated active slot. 
Additionally, a bug has been fixed where `SetPreallocatedBuffer` has the graphic buffer as an optional argument whereas it was treated as a mandatory argument prior and could lead to a SEGFAULT if an application were to not pass in a buffer.
2021-07-12 21:27:49 +05:30
PixelyIon
0d6d90c4cd Implement SvcUnmapSharedMemory + Remove Redundant [[unlikely]] 2021-07-12 21:27:49 +05:30
PixelyIon
f1433ad0d9 Rework VI + IHOSBinder
VI/IHOSBinder suffered from major inaccuracies in their function due to being quickly thrown together initially with little concern for accuracy, this has now been fixed with them being substantially more accurate now.
2021-07-12 21:27:49 +05:30
PixelyIon
ca4744c603 Improve ENUM_STRING + Fix Host1X Syncpoints
`ENUM_STRING` now has a unified implementation in <common/macros.h> with a documented format and can be used throughout the codebase. 

A major performance regression was added in the Host1X Syncpoint revamp as it did a syscall if there were any waiters during `Increment` even if they would just be woken up and go back to sleep as the threshold wasn't hit. It has now been optimized to only do a wake if any waiting thread needs to be awoken. 

There was also a bug concerning increment where it would perform actions corresponding to the previous increment rather than the current one which has also been fixed.
2021-07-12 21:27:49 +05:30
PixelyIon
6595670a5d Rework Performance Statistics
We used instantaneous values for FPS previously which led to a lot of variation in it and the inability to determine a proper FPS value due to constant fluctuations. All FPS values are now averaged to allow reading out a stable value and a deviation statistic has been added for the frame-time to judge judder and frame-pacing which allows for a significantly better measure of overall performance. The formatting for all the floating-point numbers is now fixed-point to prevent shifting of position due to decimal digits becoming 0.
2021-07-12 21:27:49 +05:30
PixelyIon
ce804254ab Support Swap Interval + Cropping + Transforms and more for QueueBuffer
Support for the following parameters was added to `QueueBuffer`:
* Earliest Present Timestamp
* Swap Interval
* Crop
* Scaling Mode
* Transform
* Frame ID (Not returned to guest yet)
We utilize ANativeWindow APIs directly to achieve all of this in an efficient manner since HWC will be used directly for it, we do plan to introduce Vulkan equivalents for all of these operations later down the line for a port to non-Android platforms.
2021-07-12 21:27:49 +05:30
PixelyIon
2e8ce2cbaf Update C++ Libraries 2021-07-12 21:27:49 +05:30
PixelyIon
6854e07356 Replace LogActivity with "Share Logs" + Add Timestamp to Logger 2021-07-12 21:27:49 +05:30
PixelyIon
e511e158e3 Implement Display Settings + Attach Texture to FenceCycle 2021-07-12 21:27:49 +05:30
PixelyIon
b2bb855a02 Revamp Host1X Syncpoint + Address Review Comments 2021-07-12 21:27:49 +05:30
PixelyIon
216e5cee81 Separate Guest and Host Presentation + AChoreographer V-Sync Event
We had issues when combining host and guest presentation since certain configurations in guest presentation such as double buffering were very unoptimal for the host and would significantly affect the FPS. As a result of this, we've now made host presentation have its own presentation textures which are copied into from the guest at presentation time, allowing us to change parameters of the host presentation independently of the guest.

We've implemented the infrastructure for this which includes being able to create images from host GPU memory using VMA, an optimized linear texture sync and a method to do on-GPU texture-to-texture copies.

We've also moved to driving the V-Sync event using AChoreographer on its on thread in this PR, which more accurately encapsulates HOS behavior and allows games such as ARMS to boot as they depend on the V-Sync event being signalled even when the game isn't presenting.
2021-07-12 21:27:49 +05:30
PixelyIon
36547cd5dc Redesign Texture Class + Improve Presentation Engine
This commit reworks the `Texture` class to include a Vulkan Image backing that can be optionally owning or non-owning and swapped in with consideration for Vulkan image layout, it also adds CPU-sided synchronization for the texture objects with FenceCycle. It also makes the appropriate changes to `PresentationEngine` and `GraphicBufferProducer` to work with the new `Texture` class while setting the groundwork for supporting swapchain recreation. It also fixes a log in `IpcResponse` and improves the display mode selection algorithm by further weighing refresh rate.
2021-07-12 21:27:49 +05:30
PixelyIon
b2132fd7aa Implement Fence Cycle, Memory Manager and Command Scheduler
Implements a wrapper over fences to track a single cycle of activation, implement a Vulkan memory manager that wraps the Vulkan-Memory-Allocator library and a command scheduler for scheduling Vulkan command buffers
2021-07-12 21:27:49 +05:30
PixelyIon
d8025e7178 Rework GraphicBufferProducer
This commit makes GraphicBufferProducer significantly more accurate by matching the behavior of AOSP alongside mirroring the tweaks made by Nintendo. 

It eliminates a lot of the magic structures and enumerations used prior and replaces them with the correct values from AOSP or HOS. 

There was a lot of functional inaccuracy as well which was fixed, we emulate the exact subset of HOS behavior that we need to. A lot of the intermediate layers such as GraphicBufferConsumer or Gralloc/Sync are not emulated as they're pointless abstractions here.
2021-07-12 21:27:49 +05:30
PixelyIon
795472004e Presentation Engine Vulkan Surface + Swapchain Initialization
This commit adds in VkSurface/VkSwapchain initialization and recreation. It also adapts GraphicsBuffferProducer and Texture to fit in with those changes but it doesn't yet implement presenting those buffers nor uploading guest buffers onto the host.
2021-07-12 21:27:49 +05:30
PixelyIon
9a09a4e815 Extend VkQueue Allocation Code
The VkQueue allocation code is rewritten to iterate through all queue families to look for an appropriate queue now
2021-07-12 21:27:49 +05:30
PixelyIon
2143b43068 Vulkan PhysicalDevice + Device Initialization + Report Accurate Version
Vulkan Device initialization is handled now, it supports required extensions but support for optional extensions/features/properties will come in later when we require those. In addition, we now correctly report the version of Skyline to Vulkan which can be accessed from debugging tools. 

There's also a minor change regarding the search pattern for `SkylineLibraries` which now only searches in headers of libraries and it also explicitly excludes the redundant `vulkan.hpp` from the `Vulkan-Headers` repository.
2021-07-12 21:27:49 +05:30
PixelyIon
8ceed74371 Vulkan Instance + Validation Layer + Debug Report Initialization
The GPU class has been extended in this for Vulkan initialization, this is done to the point of initializing the instance alongside loading in `VK_LAYER_KHRONOS_validation` which is also now packed into all Debug APKs for Skyline. In addition, `VK_EXT_debug_report` is also initialized and it's output is piped directly into the Logger. 

A minor change regarding the type of the `Fps` and `Frametime` globals was changed to `skyline::i32`s which is a more suitable type due to those having a smaller chance of overflowing while being signed as Java doesn't have unsigned integral types.
2021-07-12 21:27:49 +05:30
Billy Laws
5be7860cf7 Fixup validity check in mmnv IRequest::Get
Fixes a random crash in SMO when launching the game for the first time.
2021-06-27 14:47:52 +01:00
Billy Laws
100cff7692 Address feedback 2021-06-20 14:18:40 +01:00
Billy Laws
b87f451746 Handle empty core queues in Scheduler::UpdatePriority
If the queue is empty then begin() == end() leading to
ArmPreemptionTimer being called on an unscheduled thread.
2021-06-20 14:18:40 +01:00
Billy Laws
d57883705d Avoid aligning BSS and .data individually and instead align as one
As both of these are in the same memory segment they have no individual
alignment requirements, this created a bug in
にゃんらぶ~私の恋の見つけ方~ where the data segment would be larger
than the game expected and invalid command line arguments would be read.
2021-06-20 14:18:40 +01:00
Billy Laws
e1ca24d35f Stub IParentalControlService::Initialize
This is used in newer SDKs in favour of initialising on creation with
IParentalControlServiceFactory::CreateServiceOld.
2021-06-20 14:18:40 +01:00
Billy Laws
af5ee96b9a Ensure that threads are ready before their preemption timer can be
armed.

It was discovered during testing of 'Hatsune Miku Project DIVA: Mega Mix'
that if a thread was starting while preemption was being enabled a NULL
pointer dereference could occur in the timer_settime call as
timer_create may not have been called yet.
2021-06-20 14:18:40 +01:00
Billy Laws
a7dc69223b Implement mmnv::IRequest for media module clock control
This is used by games before calling into nvdec in order to clock up the
HW module, it can also be used to request a RAM frequency. Since we
obviously don't emulate the hardware down to this level a basic stub
that provides the correct reponses is enough.

Fixes a crash on first level of Super Mario Odyssey.
2021-06-20 14:18:40 +01:00
Billy Laws
54d39fbaa7 Fix backtrace format string so it properly handles SVC names
This was missed when we moved over to printing SVC names rather than
numbers.
2021-06-20 14:18:40 +01:00
Billy Laws
99a839d669 Check the mutex tag in MutexLock if the given handle isn't found
Makes sure the correct error is reported as HOS only reports
InvalidHandle if the tag matches.
2021-06-20 14:18:40 +01:00
Billy Laws
476bb65f37 Stub GetAccumulatedSuspendedTickValue and fix call misnumbering
This is used by some more recent games like Hatsune Miku: Project DIVA
MegaMix!
2021-06-20 14:18:40 +01:00
Billy Laws
22c83006a3 Stub application copyright image AM calls
These are used on HOS to control the screenshot overlay image for
developer copyrights.
2021-06-20 14:18:40 +01:00
Billy Laws
6f9189e8f9 Reimplement GetPseudoDeviceId to be more accurate
Now returns a valid V5 UUID and uses the game's seed from control.nacp
for generation.
2021-06-20 14:18:40 +01:00
Billy Laws
d4b13c34ee Fixup broken SetTimeslice nvdrv ioctl that was missed in conversion 2021-06-20 14:18:40 +01:00
PixelyIon
0c29f982d5 Replace skyline-emu/VkHpp with KhronosGroup/Vulkan-Hpp
We used a custom version of Vulkan-Hpp which split the files a lot prior to avoid any developers needing to manually set IDE settings for IntelliJ to work but this wasn't practical due to how it required modifications to Vulkan-Hpp's generator which would make maintenance extremely difficult. It was determined that we should just add the requirement for changing the IDE settings and use Vulkan-Hpp directly.
2021-06-17 20:30:22 +05:30
PixelyIon
8056b80073 Address CR Comments (#151) + Fix SvcWaitSynchronization Trace
An RAII scoped trace was used for SvcWaitSynchronization but it was placed within a condition scope which led to an incorrect lifetime for the traces. Minor changes regarding the CR not affecting functionality were made aside from that.
2021-03-25 22:57:26 +05:30
PixelyIon
3f7373209a Move Guest GPU into SoC Directory
We decided to restructure Skyline to draw a layer of separation between guest and host GPU. We're reserving the `gpu` namespace and directory for purely host GPU and creating a new `soc` directory and namespace for emulation of parts of the X1 SoC which is currently limited to guest GPU but will be expanded to contain components like the audio DSP down the line.
2021-03-25 22:57:26 +05:30
PixelyIon
0ea6d9bee5 Address CR Comments (#150)
Correct a single grammatical error
2021-03-23 02:40:02 +05:30
PixelyIon
f983b701c8 Fix BT Audio Stuttering Issues
This fixes audio stuttering which occurred on certain BT audio devices by requesting an exclusive stream from Oboe alongside a low-latency stream.

Co-authored-by: Billy Laws <blaws05@gmail.com>
2021-03-23 02:40:02 +05:30
PixelyIon
ae68009f9b Extend Perfetto Tracing
Add Tracing for SVCs, Services, NVDRV, and Synchronization Primitives. In addition, fix `TRACE_EVENT_END("guest")` being emitted when a signal is received while being in the guest rather than host which would cause an exception. This commit also disables warnings for the Perfetto library as we do not control fixing them.
2021-03-23 02:40:02 +05:30
PixelyIon
df3427a8c0 Extend SVC table with names
This extend a descriptor table for the SVCs with names for every SVC alongside their function pointer. The names are then used for logging and eventually tracing.
2021-03-23 02:40:02 +05:30
PixelyIon
6eea38cca9 Optimize NvDevice Function Lookup
This essentially optimizes NvDevice in the same way services were, refer to the last commit for details
2021-03-23 02:40:02 +05:30
PixelyIon
33f1a3e1b3 Optimize Service Function Lookup
This moves from using std::function with a this pointer binding (which would likely cause a heap allocation) to returning the this pointer in a structure which implements operator() to do the call with it. It also moves to using const char* for strings from std::string_view which was pointless in this scenario due to it's usage being limited to being a C-string for the most part, it also integrates the class name directly into the string which allows us to avoid runtime string concatenation in libfmt and RTTI for finding the class name.
2021-03-23 02:40:02 +05:30
PixelyIon
2b4a094cd8 Logger Function Prefix Support 2021-03-23 02:40:02 +05:30
Billy Laws
6c6e665569 Implement Perfetto Tracing
This commit implements tracing Skyline using https://perfetto.dev/ for SVCs, IPC, Scheduler and Presentation
2021-03-23 02:40:02 +05:30
PixelyIon
1155394d58 Improve KMemory + Fix Service Implementation Warning
* Improve KMemory Comments
* Add parameter prefix 'p-' to `KPrivateMemory::UpdatePermission`
* Fix the missing trailing double quote in missing service prints, this was due to `stringName` being padded with extra 0s
2021-03-23 02:40:02 +05:30
Billy Laws
d8d4b4c9e0 Address review feedback 2021-03-21 18:56:31 +05:30
Billy Laws
74cd0bc2c3 Various timesrv cleanups and comments
Mainly just adapts the rest of time to add some things missed in the
initial commit as they required TZ, everything else is just renames from
switchbrew and comments.
2021-03-21 18:56:31 +05:30
Billy Laws
ba418976b0 Implement full timezone service support
This serves as an extension to the initial time commit and combined
they provide a complete implementation of everything application facing
in time.

psc:ITimeZoneService and glue:ITimeZoneService are used to convert
between POSIX and calendar times according to the device location.
Timezone binaries are used during the conversion, details of them can
be read about in the previous commit.

This is based off my own glue RE and Thog's time RE.
2021-03-21 18:56:31 +05:30
Billy Laws
34cb0b49e8 Implement the entirety of time services
This reimplements our time backend to be significantly more accurate to
the real PSC and provides complete implementations for every time IPC
allowing many newer games to work properly.

Time is unique in its use of glue services, the core sysmodule is fully
isolated and doesn't interface with any other services. Glue is instead
used where that is needed (e.g. for fetching settings), this distinction
is also present in our implementation.

Another unique feature of time is its global state, as time is
calibrated from the start of the service its state cannot be lost as
that would result in the application offsetting time incorrectly
whenever it closed a session.

A large proportion of this is based off of Thog's 9.0.0 PSC reversing.
2021-03-21 18:56:31 +05:30
Billy Laws
63c54207d2 Add AndroidAsset{Backing,FileSystem} for accessing built-in assets
These only implement the subset of VFS needed for time, implementing
more is difficult due to some issues in the AAsset API which make
support quite ugly. The abstract asset filesystem can be accessed by
services through the OS class allowing other implementations to be used
in the future.
2021-03-21 18:56:31 +05:30
Billy Laws
a0f6cc161c Add a UUID struct for holding and generating RFC4122 UUIDs
Time uses UUIDs for clock identification.
2021-03-21 18:56:31 +05:30
Billy Laws
937e3d6f68 Add endiannes swapping helper functions
Avoid using compiler functions manually to create a cleaner interface,
and allow swapping the endianness of arbritary lengths.
2021-03-21 18:56:31 +05:30
Billy Laws
def9f96b02 Add a ResultValue helper class to simplify result handling
This is a very common usecase for result handling and allows much
cleaner code.
2021-03-21 18:56:31 +05:30
PixelyIon
e90dd672af Fix Clock Rescaling Bug (Introduced in #135)
There was a mistake in the code-style refactor where the signature in the instruction encoding of `MRS` was set to `0xD54` instead of `0xD53` which would cause a SIGILL (Illegal Instruction) for devices which had their HW timer frequency equivalent to the Switch (19.2MHz) as a modified `MRS` would be deployed there. This issue should not affect devices which perform clock rescaling as the `MRS` instruction there is encoded by the assembler.
2021-03-10 15:13:57 +05:30
sspacelynx
75b769ca1d Add NSP ticket extraction support 2021-03-07 23:16:36 +05:30
sspacelynx
77d8d1bee1 Add support for XCI titlekey decryption 2021-03-07 22:55:59 +05:30
sspacelynx
666df1eb43 Add XCI file format support 2021-03-07 22:55:59 +05:30
Billy Laws
a8dafc10e0 Fix backing read size check
I buggered this one up and broke all reads during the refactor, so fix
that.
2021-03-06 20:29:55 +05:30
Billy Laws
6390561f0f Fixup VFS error checking
Many users of VFS didn't check for nullptr or 0 results leading to
various potential issues, to mitigate this introduce error checking to
VFS by default. The original variants can still be used through the
*Unchecked family of functions.
2021-03-06 18:58:04 +05:30
Billy Laws
00d0586d1f Correctly set size in CtrEncryptedBacking
This bug caused crashes with the improved error checking.
2021-03-06 18:58:04 +05:30
Billy Laws
5f942e2dff Split VFS implementations from API
This allows better validation and simplified default argument handling.
Could also be useful in the future when we switch to proper VFS error
reporting.
2021-03-06 18:58:04 +05:30
Billy Laws
48acb6d369 Address a bunch of issues detected by clang-tidy 2021-03-06 18:58:04 +05:30
Billy Laws
9d5138bef1 Support Ioctl3 without the inline output buffer
This is used by Project Diva for GET_VA_REGIONS
2021-03-05 23:54:32 +05:30
Billy Laws
c489da610e Add locking to GPU VMM and fix a few codestyle issues
As VMM can be accessed by nvdrv and the GPFIFO thread at the same
time locking is needed to prevent races.
2021-03-05 23:54:32 +05:30
Billy Laws
c1aec00ed1 Rework GPFIFO pushing to optimise performance and accuracy
* Pushbuffer data is now stored in a member buffer to avoid reallocating
  it for each pushbuffer which hampered performance before.
* Don't prefetch pushbuffers as it puts unnecessary load on the guest
  thread that is better suited for the GPFIFO thread.
* Clean up some misc code to avoid pointless casts of a 4 byte object
  and handle GPFIFO control opcodes.
2021-03-05 23:54:32 +05:30
Billy Laws
78cdb1eeb4 Add locking to nvhost-ctrl syncpoint events and sync with switchbrew
NvHostEvents were renamed to SyncpointEvents which is a much clearer
name that more accurately describes them. Locking is needed as IOCTLs
can be called asynchronously and so event registration and signalling
can race.
2021-03-05 23:54:32 +05:30
PixelyIon
c282276b74 Address CR Comments 2 (#132) + Fix Several Scheduler Bugs
The following scheduler bugs were fixed:
* It was assumed that all non-cooperative `Rotate` calls were from a preemptive yield and changed the state of `KThread::isPreempted` incorrectly which could lead to UB, an example of a scenario with it would be:
* * Preemptive thread A gets a signal to yield from cooperative thread B due to it being ready to schedule and higher priority
* * A complies with this request but there's an assumption that the signal was actually from it's preemption timer therefore it doesn't reset it (As it isn't required if the timer was responsible for the signal)
* * A receives the actual preemption signal a while later, causing UB as the signal handler is invoked twice
* `Scheduler::UpdatePriority`
* * A check for `currentIt == core->queue.begin()` existed which caused an incorrect early return 
* * The preemption timer was armed correctly when a priority transition from cooperative priority -> preemption priority occurred but not disarmed when a transition from preemption priority -> cooperative priority occurred
* * The timer was unnecessarily disarmed in the case of updating the priority of a non-running thread, this isn't as much a bug as it is just pointless
* Priority inheritance in `KProcess::MutexLock` is fundamentally broken as it performs UB with `waitThread` being accessed prior to being assigned
* When a thread sets its own priority using  `SvcSetThreadCoreMask` and its current core is no longer in the affinity mask, it wouldn't actually move to the new thread until the next time the thread is load balanced
2021-03-05 14:55:34 +05:30
PixelyIon
fe5061a8e0 Address CR Comments (#132) + Change Core Migration API
This addresses all CR comments including more codebase-wide changes arising from certain review comments like proper usage of its/it's and consistent contraction of it is into it's. 

An overhaul was made to the presentation and formatting of `KThread.h` and `LoadBalance` works has been superseded by `GetOptimalCoreForThread` which can be used alongside `InsertThread` or `MigrateToCore`. It makes the API far more atomic and neater. This was a major point of contention for the design prior, it's simplified some code and potentially improved performance.
2021-03-05 14:55:34 +05:30
PixelyIon
0ea02f2d56 Fix Non-Cooperative Core Migration + Fix yieldWithCoreMigration + Improve Mutex Locking in ConditionalVariableWait
The case of a thread not being in the core queue during a non-cooperative core affinity change would break things as the thread was non-conditionally removed and inserted, this has been fixed by adding a check to see if the thread exists in the core's queue prior to migration. In addition, `yieldWithCoreMigration` was broken by the previous commit as the fallthrough was intentional and removing it cause core migration without a yield which led to breakage in certain circumstances. The mutex locking logic was also improved in `ConditionalVariableWait` to use atomics in a more effective manner with less atomic operations being performed overall.
2021-03-05 14:55:34 +05:30
PixelyIon
0233916489 Increase Code Region Size to 4GiB
The code region's size was previously set at the same value as it is for 36-bit ASes, this value is inadequate for certain larger games and needed to be expanded. We've chosen 4GiB as the new value which should easily encompass all Switch games.
2021-03-05 14:55:34 +05:30
PixelyIon
11c5f50d37 Use likelihood attributes in NCE + Fix System Version + SVC improvements
The SVCs improvements are as follows:
* Make SVC logs more concise for:
* * `SleepThread`
* * `ClearEvent`
* * `CloseHandle`
* * `ResetSignal`
* * `WaitSynchronization` (Special case for single handle)
* * `ArbitrateLock`
* * `ArbitrateUnlock`
* * `WaitProcessWideKeyAtomic`
* * `SignalProcessWideKey`
* Fix unintentional fallthrough into `yieldWithoutCoreMigration` from `yieldWithCoreMigration` in `SleepThread`
* Return `result::InvalidState` when an unsignalled handle is reset in `ResetSignal`
* Return `Result{}` (Success) in `CancelSynchronization`
* Do not return `result::InvalidCurrentMemory` in `ArbitrateLock` as it's not a failure condition
* Make `count` in `WaitProcessWideKeyAtomic` a `i32` from a `u32`, zero and all negative values result in waking all waiters
2021-03-05 14:55:34 +05:30
PixelyIon
1884d98163 Implement Address Arbiter
The entirety of the address arbiter is implemented in this commit, all three arbitration types: `WaitIfLessThan`, `DecrementAndWaitIfLessThan` and `WaitIfEqual`, and all three signal types: `Signal`, `SignalAndIncrementIfEqual` and `SignalAndModifyBasedOnWaitingThreadCountIfEqual` have been implemented. 
This allows any application which uses levent (Light Events) to function which includes titles such as ARMS.
2021-03-05 14:55:34 +05:30
PixelyIon
20bdda6a63 Support Core Migration for Running External Thread
We did not support migration of threads which were running in a non-cooperative manner, this was partially due to the dependence on per-core conditional variables rather than per-thread which made this harder to do programmatically. This has been fixed by moving to per-thread cvars and therefore the limitation can be removed, this feature is used by Unity games.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
861d7e9eb2 Fix SvcClearEvent resetting behaviour
SvcClearEvent previously set the `signalled` flag directly rather than
calling `ResetSignal`, which skipped the locking necessary to make it
globally visible. Switch it to use `ResetSignal` to fix this.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
a621408b9c Move to using ASCII separators for Logger
We've moved to using RS and GS from ASCII as delimiters rather than
'\n' and '|', this allows more robust parsing and increases the
readability of the log files
2021-03-05 14:55:34 +05:30
◱ PixelyIon
31db70f1d4 Lock decryption in CtrEncryptedBacking
This prevents a race where two threads could read at the same time and
end up using the wrong IV leading to garbage data being read. This
caused crashes in several games including Celeste.
2021-03-05 14:55:34 +05:30
Billy Laws
ce0e032255 Avoid constantly signalling audren DSP done event
This was causing a significant amount of sched thrashing and pinning a
core to 100% as games constantly updated audren, now change it to only
signal on buffer release.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
7e7a792dc5 Use per-thread scheduler condvars and clean up AS filters
Per-thread condvars previously caused issues due to an audren bug, now
that's fixed they have a clear performance benefit.
2021-03-05 14:55:34 +05:30
PixelyIon
2bbf526419 Fix Logger Settings + Use Java 8 + Update Kotlin + Extract Native SOs 2021-03-05 14:55:34 +05:30
◱ PixelyIon
80302cf1ad Update NDK, Gradle and dependencies + Improve Settings API + Migrate to PugiXML 2021-03-05 14:55:34 +05:30
◱ PixelyIon
1f48fdd4a5 Fix Thread Insertion Optimization + Revert Per-Thread Scheduler Conditions 2021-03-05 14:55:34 +05:30
◱ PixelyIon
d5d133372f Fix Clean Exiting + Optimize Core Queues + Optimize Thread Insertion + Implement HID SendVibrationValue 2021-03-05 14:55:34 +05:30
◱ PixelyIon
98b1fd9056 Optimize Scheduler/IPC/HID + Fix Various Bugs
* Optimize Scheduler With Per-Thread Scheduler Conditions
* Optimize IPC by yielding
* Optimize HID Vibration
* Fix Priority Inheritance
* Fix `KThread` Start/Kill/Signal Races 
* Fix `YieldPending` Races in `StartThread` & `SvcHandler` 
* Fix POSIX Time -> NN CalendarTime Conversion 
* Fix HID `TouchScreen`/`NPad` Activation
2021-03-05 14:55:34 +05:30
◱ PixelyIon
ef52e22cef Improve Synchronization SVCs + Fix TLS Page Allocation Race + Fix KProcess::GetHandle<KObject> 2021-03-05 14:55:34 +05:30
◱ PixelyIon
ebadc1d1e1 Generate Stack Traces + More Robust Terminate Handler + Exit Process on Signal in Guest 2021-03-05 14:55:34 +05:30
◱ PixelyIon
14dbb5305a Fix Priority Queue + Cooperative Yielding + Conditional Variable Timeouts 2021-03-05 14:55:34 +05:30
◱ PixelyIon
33bbfb9fb7 Implement Conditional Variables 2021-03-05 14:55:34 +05:30
◱ PixelyIon
7079f11add Implement PI-Mutexes + Optimize InsertThread 2021-03-05 14:55:34 +05:30
◱ PixelyIon
7ba7cd2394 Support Priority & Affinity Mask Changes 2021-03-05 14:55:34 +05:30
◱ PixelyIon
f41bcd1e22 Implement Preemptive Scheduling 2021-03-05 14:55:34 +05:30
◱ PixelyIon
cf000f5750 Implement Cooperative Scheduling With Load Balancing 2021-03-05 14:55:34 +05:30
◱ PixelyIon
8564edcb16 Address CR Comments #2 2020-11-23 11:44:43 +05:30
◱ PixelyIon
fbf9f06244 Address CR Comments + Fix Clock Rescaling 2020-11-22 23:56:17 +05:30
◱ PixelyIon
a3dd759a1c Fix Circular Queue Destructor + Memory Infos + Improve Priority Documentation 2020-11-22 23:56:17 +05:30
Billy Laws
7167393e3c Only initialise maxEntry for active input devices
This caused the menus in Sonic Mania to be nonfunctional, futhermore,
default init is not ran for the input structs so the default max
definition in CommonHeader never actually applied.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
bc5c094860 Fix CircularQueue + NPDM ACI0 & Kernel Capability Parsing 2020-11-22 23:56:17 +05:30
◱ PixelyIon
a5927c5c7b Fix Native-Initiated Exiting 2020-11-22 23:56:17 +05:30
◱ PixelyIon
d155e9cd71 Complete Exceptional Signal Handler Implementation + Fix More Destruction Behavior 2020-11-22 23:56:17 +05:30
Billy Laws
8bf08ed66f Fix CircularQueue and improve debug logging + exefs loading
CircularQueue was looping around too early resulting in the wrong
pushbuffers being used. The debug logging is useful for interpreting the
GPU method call logs.

Exefs loading was changed to check if an NSO exists before trying to
read it, preventing exceptions that get annoying while debugging.
2020-11-22 23:56:17 +05:30
Billy Laws
c161ef0cac Various accuracy improvements in services
* 'Fix' memory accounting to not measure reserved regions
* Fix some copy bugs introduced by switch to span
* Correct remap the behaviour of Modify so it actually works
2020-11-22 23:56:17 +05:30
Billy Laws
c7e5202042 Rework GPU VMM variable naming 2020-11-22 23:56:17 +05:30
Billy Laws
4c9d453008 Update formatter config for new AS and reformat 2020-11-22 23:56:17 +05:30
◱ PixelyIon
668f623256 Implement Exceptional Signal Handler + Fix Destruction Behavior
An exceptional signal handler allows us to convert an OS signal into a C++ exception, this allows us to alleviate a lot of crashes that would otherwise occur from signals being thrown during execution of games and be able to handle them gracefully.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
3cde568c51 Run Guest on Main Emulator Thread + Remove Mutex/GroupMutex + Introduce PresentationEngine 2020-11-22 23:56:17 +05:30
◱ PixelyIon
779884edcf Introduce TID to Logger + Fix VMM Bug + Fix NSO Backtrace + Improve Logger 2020-11-22 23:56:17 +05:30
Billy Laws
39f0345ac7 Fix bugs introduced by refactoring
GPU VMM was mistakenly checking the alignment of the PA rather than the
VA and NvMap::Free was not accounting for the handle index starting from
one.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
c65c91e1bc Implement NPDM, Core Mask SVCs + Fix VMM bug + Introduce Verbose Log Level 2020-11-22 23:56:17 +05:30
◱ PixelyIon
324381908b Implement SvcMap/UnmapPhysicalMemory + Fix W-Register Writing + Improve Accuracy of SvcGetInfo 2020-11-22 23:56:17 +05:30
◱ PixelyIon
657beea070 JVM Auto-Attach + Fix Thread Exiting + Fix Thread Signal Handler 2020-11-22 23:56:17 +05:30
◱ PixelyIon
6f2cd41470 Move .patch to start of executable (Pre-Patching) 2020-11-22 23:56:17 +05:30
◱ PixelyIon
369bd469f6 Dynamic Guest Memory Base Allocation 2020-11-22 23:56:17 +05:30
◱ PixelyIon
cffbfc8034 Skip Saving Callee-Saved Registers + Fix GetMemoryObject 2020-11-22 23:56:17 +05:30
Billy Laws
31efb5e930 Correct an NSO loader bug and use the correct address space extents 2020-11-22 23:56:17 +05:30
Billy Laws
17feb68eb5 Fix audren voice sample copying 2020-11-22 23:56:17 +05:30
◱ PixelyIon
745ea19f42 Use u64s for FmtCast + Remove Functional Casts + Fix VMM Bugs 2020-11-22 23:56:17 +05:30
◱ PixelyIon
1db76dee1e NCE3: In-Process Guest Execution 2020-11-22 23:56:17 +05:30
◱ PixelyIon
90127740f0 Rework NCE/KThread/KProcess + Remove Guest Process 2020-11-22 23:56:17 +05:30
◱ PixelyIon
878cb24389 Make fmt::ptr implicit for raw pointers + Update Submodules 2020-11-22 23:56:17 +05:30
◱ PixelyIon
02f3e37c4f Remove KProcess Memory Functions 2020-11-22 23:56:17 +05:30
◱ PixelyIon
60e82e6af0 Rework VMM + Adapt KMemory Objects to be in-process
Note: This commit isn't functional on it's own, it will require the rest of NCE3 to work
2020-11-22 23:56:17 +05:30
Billy Laws
85d5dd3619
Extend NvServices and implement IDirectory (#107)
* Fix alignment handling in NvHostAsGpu::AllocSpace

* Implement Ioctl{2,3} ioctls

These were added in HOS 3.0.0 in order to ease handling ioctl buffers.

* Introduce support for GPU address space remapping

* Fix nvdrv and am service bugs

Syncpoints are supposed to be allocated from ID 1, they were allocated
at 0 before. The ioctl functions were also missing from the service map

* Fix friend:u service name

* Stub NVGPU_IOCTL_CHANNEL_SET_TIMESLICE

* Stub IManagerForApplication::CheckAvailability

* Add OsFileSystem Directory support and add a size field to directory entries

The size field will be needed by the incoming HOS IDirectory support.

* Implement support for IDirectory

This is used by applications to list the contents of a directory.

* Address feedback
2020-11-03 15:10:42 +05:30
◱ PixelyIon
7ad86ec46f Improve span::as_string and other minor fixes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
97ac45d83b Update Logger to use NDK Logger APIs + Improve Backing API + Fix FDSAN issues 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4070686897 Refactor Comments + Other Minor Fixes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
429af1990a Equal -> Brace Initializer + Remove Constexpr Auto for Integers 2020-10-02 15:28:48 +00:00
◱ PixelyIon
2764bd7c96 Use Vector for Kernel Handles + Remove Redundant Includes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
20559c5dca Introduce Custom Span Class + IPC Buffer -> Span 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4d6ae9aa26 Constexpr Maps for Service Functions 2020-10-02 15:28:48 +00:00
◱ PixelyIon
157c54f918 Implement a few HID Functions + Fix FAB handler 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4970e58999 Address CR Comments (#102) 2020-09-20 20:07:33 +00:00
◱ PixelyIon
bb2c31264d Implement IOCTL2 & IOCTL3 2020-09-20 20:07:33 +00:00
◱ PixelyIon
a5fece8020 NVDRV IOCTL Refactor
Buffer -> Span + All buffers as arguments + Return -> NvStatus + Print Service Names + Function Names
2020-09-20 20:07:33 +00:00
◱ PixelyIon
70d67ef563 Constexpr Maps for NvDevice IOCTLs 2020-09-20 20:07:33 +00:00
◱ PixelyIon
20253a9573 Improve NvDevice Registration + Access 2020-09-20 20:07:33 +00:00
◱ PixelyIon
4cc3a3b2e8 Move NVDRV + IHOSBinder Internals to Discrete Components + Fix Lint 2020-09-20 20:07:33 +00:00
◱ PixelyIon
5f0073dd87 Fix Surface Deswizzling OOB writes + Fix PL README 2020-09-20 20:07:33 +00:00
Willi Ye
4076d84efc
NCA decryption (#99)
* NCA decryption
* Remove unnecessary new lines
* Remove loader error dialog
* Always show ROMs
* Address CRs
* Add subtitle padding in grid mode
2020-09-14 19:23:40 +05:30
◱ PixelyIon
65019375ca Implement Guest Touch-Screen Support 2020-09-08 12:55:33 +00:00
Billy Laws
89718804d0 Refactor service functions to return result codes 2020-09-06 19:12:18 +00:00
Billy Laws
74a150dff1 Rework service API to be cleaner with significantly less boilerplate
This patch reduces the burden of adding services significantly, rather
than having to create an enum entry and add strings in the constructor
it will all be determined at runtime through RTTI. A macro is also used
in the service creation case to reduce clutter.
2020-09-06 19:12:18 +00:00
◱ PixelyIon
21e2c826a1 Improve Accuracy of Vibration + Unify Translation + Add Comments 2020-09-06 15:31:20 +00:00
◱ PixelyIon
1a58a2e967 Implement Rumble Support for Controllers and Device Vibrators 2020-09-06 15:31:20 +00:00
Billy Laws
d8ccdd723e
Refactor Audio + Fix NV Bugs (#92)
* Fix NvHostCtrl:EventSignal event ID parsing
* Divide the audout buffer length by the sample size
* Correct audout channel quantity handling
* A few bugfixes for audio tracks
* * Correctly lock in CheckReleasedBuffers and only call the callback once
* * Check if the identifier queue is empty before accessing it's iterator
* Refactor audio to better fit the codestyle
* Explictly specify reference when using GetReference
* Fix CheckReleasedBuffers
2020-08-21 18:58:47 +05:30
◱ PixelyIon
7290a80c3e Move to Callback for Input Initialization + ConditionalVariable for Surface 2020-08-21 11:48:29 +00:00
◱ PixelyIon
07c2f2d891 Significantly Improve Accuracy of HID
This commit significantly increases the accuracy of the prior HID code due to testing on the Switch. It is now fully accurate in all supported scenarios, them being assignment mode, orientation, color writes and system properties. In addition, review comments were addressed and fixed in the PR.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
ee2fdbdf6a Fix Joy-Con Pair Crash + Implement More HID Service Functions
This fixes a Joy-Con Pair bug which caused a crash when a partner device was set to none while being set as a partner. In addition, the following HID service functions were implemented:
* GetSupportedNpadStyleSet
* ActivateNpadWithRevision
* GetNpadJoyHoldType
* AcquireNpadStyleSetUpdateEventHandle
2020-08-21 11:48:29 +00:00
◱ PixelyIon
6a931b95b0 Implement C++ Support for Controller Configuration
This commit adds support to the C++ end of things for controller configuration. It isn't targeting being 1:1 to HOS for controller assignment but is rather based on intuition of how things should be.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
75d485a9a7 Addition of Controller Configuration UI
This commit adds in the UI for Controller Configuration to Settings, in addition to introducing the storage and loading of aforementioned configurations to a file that can be saved/loaded at runtime. This commit also fixes updating of individual fields in Settings when changed from an external activity.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
102f26d08e Refactor C++ Input
This commit refactors the C++ end of Input so it'll be in line with the rest of the codebase and be ready for the extension with multiple players and controller configuration.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
5fec7eefd0 Refactor HID Shared Memory
This commit refactors and reorders a lot of the HID Shared Memory from the previous commits to be in line with the rest of the codebase.
2020-08-21 11:48:29 +00:00
Billy Laws
b167abcdb7 Initial Kotlin Input Implementation
This commit contains the Kotlin side of the initial Input implementation, this is based on the work done in the `hid` branch in `bylaws/skyline`.
Co-authored-by: ◱ PixelyIon <pixelyion@protonmail.com>
2020-08-21 11:48:29 +00:00
Billy Laws
0219eda2db Initial C++ Input Implementation
This commit contains the C++ side of the initial Input implementation, this is based on the work done in the `hid` branch in `bylaws/skyline`.
Co-authored-by: ◱ PixelyIon <pixelyion@protonmail.com>
2020-08-21 11:48:29 +00:00
Billy Laws
817d37600e Convert all make all hex uppercase according to codestyle 2020-08-15 10:21:41 +00:00
Billy Laws
e5264f7762 Address review comments 2020-08-15 10:21:41 +00:00
Billy Laws
ae131502c6 Fix reservation in GPU VMM
Rather than reserving a region so it *can* be used by MapAllocate
reserved actually prevents a region from being used by MapAllocate.
2020-08-15 10:21:41 +00:00
Billy Laws
ade8a711fb Format code and misc cleanup 2020-08-15 10:21:41 +00:00
Billy Laws
fcae5d54da Switch NvHostCtrlGpu to use QueryEvent 2020-08-15 10:21:41 +00:00
Billy Laws
cf60869fac Stub INotificationService 2020-08-15 10:21:41 +00:00
Billy Laws
9d90cd877c Stub IFile:Flush 2020-08-15 10:21:41 +00:00
Billy Laws
c69efed2ad Implement GetAccumulatedSuspendedTickChangedEvent 2020-08-15 10:21:41 +00:00
Billy Laws
6c9e0a943c Add some IApplicationFunctions calls used by newer games 2020-08-15 10:21:41 +00:00
Billy Laws
9e39cbaf7b Implement GetBase in IProfile 2020-08-15 10:21:41 +00:00
Billy Laws
dc6da8303e Add support for listing users in account services 2020-08-15 10:21:41 +00:00
Billy Laws
cae270a174 Use nvhost fences in IHOSBinderDriver 2020-08-15 10:21:41 +00:00
Billy Laws
94d1b40faf Add an empty ISslContext service 2020-08-15 10:21:41 +00:00
Billy Laws
7503496bb0 Implement the basis of the Maxwell 3D engine together with a macro
interpreter.

The Maxwell 3D engine handles all 3D rendering, currently only non
rendering related methods are implemented. Macros are small pieces of
code that run on the GPU and allow methods to be quickly called for
things like instanced drawing.
2020-08-15 10:21:41 +00:00
Billy Laws
68d5a48df1 Implement syncpoints and nvhost events and fix an nvmap bug
These are used to allow the CPU to synchronise with the GPU as it
reaches specific points in its command stream.

Also fixes an nvmap bug where a struct was incorrect.
2020-08-15 10:21:41 +00:00
Billy Laws
ed3ff862f6 Extend GPU VMM with unmapping/remapping support + code cleanup 2020-08-15 10:21:41 +00:00
Billy Laws
cf468c20e2 Extend the GPFIFO implementation with support for engines and fix a few
bugs

An engine is effectively a HW block in the GPU, the main one is the
Maxwell 3D which is used for 3D graphics. Engines can be bound to
individual subchannels and then methods within them can be called
through pushbuffers.

The engine side of the GPFIO is also included, it currently does nothing
but will need to be extended in the future with semaphores.
2020-08-15 10:21:41 +00:00
Billy Laws
9fd0dd848b Add support for processing GP Entries and the pushbuffers they contain
This is the backbone of the GPU, in the future this will be expanded to
support calling into engines.
2020-08-15 10:21:41 +00:00
Billy Laws
8dc9a10324 Implement the host side of host1x syncpoints
This will be extended in the future to support interfacing with the GPU.
2020-08-15 10:21:41 +00:00
Billy Laws
3c5cc33a34 Minor bug fixes in GPU VMM and add support for reading 2020-08-15 10:21:41 +00:00
Billy Laws
78712712c7 Fix a few bugs in CreateStrayLayer 2020-08-15 10:21:41 +00:00
Billy Laws
6edf89b538
Initial Savedata Implementation (#75)
* Rework VFS to support creating and writing files and introduce OsFileSystem
OsFileSystem abstracts a directory on the device using the filesystem API.
This also introduces GetEntryType and changes FileExists to use it.

* Implement the Horizon FileSystem APIs using our VFS framework
Horizon provides access to files through its IFileSystem class, we can
closely map this to our vfs::FileSystem class.

* Add support for creating application savedata
This implements basic savedata creation using the OsFileSystem API. The
data is stored in Skyline's private directory is stored in the same
format as yuzu.
2020-08-09 01:08:51 +05:30
Willi Ye
392a1ac437 account: Remove unnecessary null termination 2020-07-21 18:29:45 +00:00
Willi Ye
1f282af87e More code style aligning
* Null terminate nickname array and correct character limit in settings perference
2020-07-21 18:29:45 +00:00
Willi Ye
93da9f2826 Align code style with project
* Return correct error code for invalid user
* Always return first icon color
2020-07-21 18:29:45 +00:00
Willi Ye
ffb9e743dd Add profile service to support custom usernames 2020-07-21 18:29:45 +00:00
Billy Laws
b23779bda1 Implement a block based GPU virtual memory manager
The GPU has it's own seperate address space to the CPU. It is able to
address 40 bit addresses and accesses the system memory. A sorted vector
has been used to store blocks as insertions are not very frequent.
2020-07-17 16:21:34 +00:00
Billy Laws
80e7b82bad Fix the LUT shift in the audio resampler
We do not need to shift back as we use a struct to hold the LUT entries.
2020-07-17 14:30:53 +00:00
Billy Laws
a3a2cb682e Truncate service names to 8 chars maximum 2020-07-17 14:30:53 +00:00
Billy Laws
8684e20a29 Treat GetAudioDeviceServiceWithRevisionInfo as GetAudioDeviceService 2020-07-17 14:30:53 +00:00
Billy Laws
3734599615 Extend the IAudioController implementation with volume stubs
This is used by ARMS.
2020-07-17 14:30:53 +00:00
Billy Laws
4cd7502df2 Implement post 4.0.0 language list features in ISettingsServer 2020-07-17 14:30:53 +00:00
Billy Laws
d1c1fa214c Stub (un)lockExit in ISelfController 2020-07-17 14:30:53 +00:00
Billy Laws
c2fadffe60 Extend time services with support for the steady clock
The steady clock has a fixed timepoint that can not change while an
application is running.
2020-07-17 14:30:53 +00:00
Billy Laws
e3313ae731 Use the device sample rate when creating an audio track in audren 2020-07-17 14:30:53 +00:00
Willi Ye
c69e72a12e services: Add missing audio functions
* Those are needed to run playtone and audren from switch homebrew examples
2020-07-13 21:14:57 +01:00
Billy Laws
6548d4914d Implement IAudioDevice for accessing audio output properties
This is used by Super Mario Odyssey in its init routine.
2020-07-09 18:42:36 +00:00
Billy Laws
f71b54b901 Stub SetRestartMessageEnabled in ISelfController
This is used by Super Mario Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
2b4adee213 Stub gameplay recording and save data checking functions
Gameplay recording does not need to be emulated and EnsureSaveData isn't
necessary for proper save data support.
2020-07-09 18:42:36 +00:00
Billy Laws
2e60b5e60d Stub play reporting services 2020-07-09 18:42:36 +00:00
Billy Laws
378e494d82 Add an empty ssl service implementation
This stubs a single function that is needed for SMO's init.
2020-07-09 18:42:36 +00:00
Billy Laws
a2c6a2a4ff Add a base socket (bsd) services implementation
This stubs enough to pass SMO's socket init.
2020-07-09 18:42:36 +00:00
Billy Laws
2aefb4ae84 Implement network interface services
nifm:u is used by applications to enable a connection to the network.
2020-07-09 18:42:36 +00:00
Billy Laws
7102fa910e Implement nfp services 2020-07-09 18:42:36 +00:00