Commit Graph

354 Commits

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