Commit Graph

347 Commits

Author SHA1 Message Date
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