Commit Graph

969 Commits

Author SHA1 Message Date
lynxnb
873ed641ea Stub nfp::IUser::ListDevices and nfp::IUser::GetState 2022-04-14 14:14:52 +05:30
lynxnb
7d518cba2b Stub am::ICommonStateGetter::IsVrModeEnabled 2022-04-14 14:14:52 +05:30
Robin Kertels
594f061b21 Implement SSBOs
Co-authored-by: Billy Laws <blaws05@gmail.com>
2022-04-14 14:14:52 +05:30
Billy Laws
82d2a9ab56 Unify engine related macros to avoid excessive code duplication 2022-04-14 14:14:52 +05:30
Billy Laws
ae41ddf4f0 Implement a skeleton compute engine
The Kepler compute engine is used to run compute jobs encapsulated in to QMDs on the GPU, this commit doesn't implement compute itself but adds the register and QMD structs that will be needed for it in the future.
2022-04-14 14:14:52 +05:30
Billy Laws
0298a7b1f6 Implement the actual inline to memory engine on subch 2
Used mostly by OGL games for copying stuff around.
2022-04-14 14:14:52 +05:30
Billy Laws
ba7111d33a Add maxwell3d I2M support 2022-04-14 14:14:52 +05:30
Billy Laws
8c73b62b2c Implement basic inline2memory engine support
Not currently used by anything but will be used by both compute, 3D and its own engine in the future. Block linear copies are currently unsupported.
2022-04-14 14:14:52 +05:30
Billy Laws
5c387f5c5a Fixup depth mode init value to allow ignoring redundant calls 2022-04-14 14:14:52 +05:30
PixelyIon
7a5c771f44 Rework GPU BufferView to have handle-like semantics
We wanted views to extend the lifetime of the underlying buffers and at the same time preserve all views until the destruction of the buffer to prevent recreation which might be costly in the future when we need `VkBufferView`s of the buffer but also require a centralized list of all views for recreation of the buffer. It also removes the inconsistency between `BufferView*` being returned in `GetXView` in `GraphicsContext`.
2022-04-14 14:14:52 +05:30
Billy Laws
fae5332f20 Disable descriptor aliasing on Adreno to workaround shader compiler bug
Alised descriptor sets are incorrectly interpreted by the shader compiler causing it to bugger up LLVM function argument types and crash

Co-authored-by: PixelyIon <pixelyion@protonmail.com>
2022-04-14 14:14:52 +05:30
Billy Laws
fc2c123ae2 Implement GPU depthMode register
This controls the depth range used by the shader, hades already has support for the necessary patching so we only need to pass the current mode over to it and it'll do the necessary work.
2022-04-14 14:14:52 +05:30
Billy Laws
7e088ca465 Fix constbuf updates to actually increment the write offset
Uses the register directly now as when we modify it we want the changes to be visible from macros too.
2022-04-14 14:14:52 +05:30
PixelyIon
d2f3479610 Use eB5G6R5UnormPack16 VkFormat for B5G6R5Unorm and R5G6B5Unorm
Using `eB5G6R5UnormPack16` (with a swizzle for `R5G6B5Unorm`) removes the need for `VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` when those formats are aliased which happens in Sonic Mania among other titles.
2022-04-14 14:14:52 +05:30
PixelyIon
24d7066d8b Add quirk to avoid VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT on Adreno GPUs
Adreno GPUs have significant performance penalties from usage of `VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` which require disabling UBWC and on Turnip, forces linear tiling. As a result, it's been made an optional quirk which doesn't supply the flag in `VkImageCreateInfo` and logs a warning if a view with a different Vulkan format from the original image is created.
2022-04-14 14:14:52 +05:30
PixelyIon
731d06010d Set eMutableFormat in Texture Image Creation
We often need to alias the underlying data as multiple Vulkan formats which requires the `eMutableFormat` bit to be set in `VkImageCreateInfo`, without doing this there'll be validation layer errors and potentially GPU bugs.
2022-04-14 14:14:52 +05:30
PixelyIon
dafcfa68ca Transition texture layout to eGeneral after creation
As we no longer set the layout to general inside the Texture constructor, yet, we need it to be set prior to the image being used as an attachment. We need to transition the layout to `eGeneral` after creation of the texture object.
2022-04-14 14:14:52 +05:30
MK73DS
647cb07dc8 Stub functions in IAccountServiceForApplication:
- GetUserCount
- InitializeApplicationInfo
- IsUserAccountSwitchLocked
2022-04-14 14:14:52 +05:30
PixelyIon
730bf504f8 Correct Adreno texture binding quirk
We incorrectly determined an Adreno driver bug to require padding between binding slots but the real issue was not supporting consecutive binding writes for `VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER` and was fixed by the padding slot unintentionally requiring individual writes. The quirk has now been corrected to explicitly specify this as the bug and the solution is more apt.
2022-04-14 14:14:52 +05:30
PixelyIon
da8cb48933 Fix Interval Map GetAlignedRecursiveRange lookup bug
Any lookups done using `GetAlignedRecursiveRange` incorrectly added intervals in the exclusive interval entry lookups as the condition for adding them was the reverse of what it should've been due to a last minute refactor, it led to graphical glitches and crashes. This has been fixed and the lookups should return the correct results.
2022-04-14 14:14:52 +05:30
PixelyIon
f2faa74707 Fix crashes due to SEGV_ACCERR check
On certain devices, accesses to a protected memory region can return `si_code` as non-`SEGV_ACCERR` values, this leads to a crash as we only pass access violations to the trap handler and would lead to not doing so on those devices which would then result in going to the crash handler.
2022-04-14 14:14:52 +05:30
PixelyIon
77e2797219 Delete expired weak_ptrs for Texture/Buffer views
A large amount of Texture/Buffer views would expire before reuse could occur in `Texture::GetView`/`Buffer::GetView`. These can lead to a substantial memory allocation given enough time and they are now deleted during the lookup while iterating on all entries.

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

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

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

```
GPFIFO <-> MME <-> Maxwell3D
    ^        ^---> Fermi2D
    X------------> I2M
    X------------> MaxwellComputeB
    X--Flush-----> MaxwellDMA
```
2022-04-14 14:14:52 +05:30
Billy Laws
8d5463ef28 Drop engine base class usage from GPFIFO
This class does nothing since we made stopped GPFIFO submits from using
virtual functions so it can be dropped.
2022-04-14 14:14:52 +05:30
PixelyIon
41aad83c33 Tie Shader ObjectPool Lifetime to Shader Program
Shader programs allocate instructions and blocks within an `ObjectPool`, there was a global pool prior that was never reaped aside from on destruction. This led to a leak where the pool would contain resources from shader programs that had been deleted, to avert this the pools are now tied to shader programs.
2022-04-14 14:14:52 +05:30
PixelyIon
e747de37cf Implement Blocklinear TIC Type 2022-04-14 14:14:52 +05:30
PixelyIon
723189a948 Calculate Blocklinear Texture Aligned Size Correctly
The size of blocklinear textures did not consider alignment to Block/ROB boundaries before, it is aligned to them now. Incorrect sizes led to textures not being aliased correctly due to different size calculations for GraphicBufferProducer surfaces and Maxwell3D color RTs.
2022-04-14 14:14:52 +05:30
Billy Laws
95685b8207 Avoid iterator invalidation segfault when unregistering a syncpt waiter
erase invalidated `it` leading to a potential segfault if the GPU was very far behind, bail out early to avoid that since there can only be one occurence at most in the buffer anyway.
2022-04-14 14:14:52 +05:30
Billy Laws
e7bfd93541 Implement BC7 format support
Used by ARMS
2022-04-14 14:14:52 +05:30
Billy Laws
99652c5eda Support partially mapped cbufs
Buggy games sometimes supply an incorrect cbuf size so limit buffers to the first unmapped region.
2022-04-14 14:14:52 +05:30
PixelyIon
6a6f51ea84 Implement Maxwell3D Depth/Stencil State
Implements the entirety of Maxwell3D Depth/Stencil state for both faces including compare/write masks and reference value. Maxwell3D register `stencilTwoSideEnable` is ignored as its behavior is unknown and could mean the same behavior for both stencils or the back facing stencil being disabled as a result of this it is unimplemented.
2022-04-14 14:14:52 +05:30
PixelyIon
9f5c3d8ecd Force Textures to be Optimal on Host GPU
We don't respect the host subresource layout in synchronizing linear textures from the guest to the host when mapped to memory directly, this leads to texture corruption and while the real fix would involve respecting the host subresource layout, this has been deferred for later as real world performance advantages/disadvantages associated with this change can be observed more carefully to determine if it's worth it.
2022-04-14 14:14:52 +05:30
Billy Laws
ab4962c4e4 Implement additional texture formats, including BCn
BCeNabler is required for BCn textures, the pre-swizzled formats will be removed when arbitary swizzle support is added later.
2022-04-14 14:14:52 +05:30
Billy Laws
600b94505c Fix A2R10G10B10 render target format
This was wrongly described as R10G10B10A2 in the enum when it's actually A2R10G10B10, a format natively supported in Vulkan with just a swizzle.
2022-04-14 14:14:52 +05:30
Billy Laws
175ba11f07 Integrate BCeNabler support into QuirkManager
Allows using BCn format textures on devices where they are unsupported by the driver.
2022-04-14 14:14:52 +05:30
Billy Laws
47d920d91e Make GPU private static functions file-local 2022-04-14 14:14:52 +05:30
PixelyIon
edd51c3dfa Fix Color RT Disabling Bug
Color RTs are disabled by setting their format as `None`, it was removed while transitioning to macros and resulted in a missing format exception. It has been readded as several applications depend on this behavior.
2022-04-14 14:14:52 +05:30
PixelyIon
a2285669b3 Use static vector for shader bytecode to prevent constant reallocation
Using `std::vector` for shader bytecode led to a lot of reallocation due to constant resizing, switching over the static vector allows for a single static allocation of the maximum possible guest shader size (1 MiB) to be done for every stage resulting in a 6 MiB preallocation which is unnoticeable given the total memory overhead of running a Switch application.
2022-04-14 14:14:52 +05:30
PixelyIon
21a6866def Fix Maxwell3D Blend Enum Conversion Bugs
The `OneMinusSourceAlpha` blending factor was converted to `eOneMinusSrcColor` rather than `eOneMinusSrcAlpha` leading to incorrect blending behavior in certain titles. A similar issue with the order of `MinimumGL`/`MaximumGL` and `SubtractGL`/`ReverseSubtractGL` being the opposite of what it should've been, both of these issues have been fixed.
2022-04-14 14:14:52 +05:30
PixelyIon
0a506088f4 Fix NextSubpassNode Subpass Index Bug
`NextSubpassNode` didn't increment `subpassIndex` which runs commands with the wrong subpass index resulting in them accessing invalid attachments or other bugs that may arise from using the wrong subpass.
2022-04-14 14:14:52 +05:30
PixelyIon
defbfe8f78 Serialize Maxwell3D Draw State for Subpass
All Maxwell3D state was passed by reference to the draw command lambda, this would break if there was more than one pass or the state was changed in any way before execution. All state has now been serialized by value into the draw command lambda capture, retaining state regardless of mutations of the class state.
2022-04-14 14:14:52 +05:30
PixelyIon
934130b3e6 Remove Implicit Command Executor Resource Attachment
Any usage of a resource in a command now requires attaching that resource externally and will not be implicitly attached on usage, this makes attaching of resources consistent and allows for more lax locking requirements on resources as they can be locked while attaching and don't need to be for any commands, it also avoids redundantly attaching a resource in certain cases.
2022-04-14 14:14:52 +05:30
PixelyIon
f0e9c42097 Fix Fence Cycle Double Insertion Lifetime Bug
If an object is attached to a `FenceCycle` twice then it would cause `FenceCycleDependency::next` to be overwritten and lead to destruction of dependencies prior to the fence being signaled causing usage of deleted resources. This commit fixes this by tracking what fence cycle a dependency is currently attached to and doesn't reattach if it's already attached to the current fence cycle.
2022-04-14 14:14:52 +05:30
PixelyIon
6a831f6ed7 Add VK_EXT_shader_demote_to_helper_invocation Quirk
An assumption was hardcoded into `Shader::Profile` regarding devices supporting demotion of shader invocations to helpers. This assumption wasn't backed by enabling the `VK_EXT_shader_demote_to_helper_invocation` extension via a quirk leading to assertions when it was used by the shader compiler, a quirk has now been added for the extension and is supplied to the shader compiler accordingly.
2022-04-14 14:14:52 +05:30
Billy Laws
3ff8075151 Move vertex and RT format conv to macros and fill them fully in
Makes the format conversions easier to read and shorter, and adds in
some new formats needed to complete the RT table properly.
2022-04-14 14:14:52 +05:30
PixelyIon
98b366c1f5 Fix Texture Synchronization Bug
Fixes texture corruption due to incorrect synchronization, the barrier would not enforce waiting till the texture was entirely rendered causing an incomplete texture to be downloaded which lead to rendering bugs for certain GPUs including ARM's Mali GPUs.
2022-04-14 14:14:52 +05:30
PixelyIon
aea40e6496 Fix enabledFeature2 Unlinking Assertion Bug
A bug caused an assertion if both `VK_EXT_custom_border_color` and `VK_EXT_vertex_attribute_divisor` due to mistakenly unlinking `PhysicalDeviceVertexAttributeDivisorFeaturesEXT` instead of `PhysicalDeviceCustomBorderColorFeaturesEXT` when `VK_EXT_custom_border_color` isn't supported which would potentially lead to unlinking the same structure twice and cause the assertion.
2022-04-14 14:14:52 +05:30
Billy Laws
68f31c3688 Use macros for defining texture formats and their conversions
Avoids the need to repeat all the possible component types for each texture format while also making them simpler to add and easier to read.
2022-04-14 14:14:52 +05:30
PixelyIon
bc29b23972 Implement CPU-only Maxwell3D Inline Constant Buffer Updates
Implements inline constant buffer updates that are written to the CPU copy of the buffer rather than generating an actual inline buffer write, this works for TIC/TSC index updates but won't work when the buffer is expected to actually be updated inline with regard to sequence rather than just as a buffer upload prior to rendering. 

GPU-sided constant buffer updates will be implemented later with optimizations for updating an entire range by handling GPFIFO `Inc`/`NonInc`directly and submitting it as a host inline buffer update.
2022-04-14 14:14:52 +05:30
PixelyIon
08f29f7da4 Make ActiveDescriptorSet movable and non-copyable
There should only ever be a single instance of a `ActiveDescriptorSet` that tracks the lifetime of a descriptor set as the destructor is responsible for freeing the descriptor set.

There are cases where a new object inheriting the descriptor set needs to be created in these cases we need to have move semantics and make the destructor of the prior object inert, this allows for moving to the new object without any side effects. If the copy constructor was used in these cases the older object would free the set on its destruction which would lead to the set being invalid on existing instances which is incorrect behavior and would likely lead to driver crashes.
2022-04-14 14:14:52 +05:30
PixelyIon
bb14af4f7a Implement Maxwell3D Sampled Textures
The descriptor sets should now contain a combined image and sampler handle for any sampled textures in the guest shader from the supplied offset into the texture constant buffer.

Note: Games tend to rely on inline constant buffer updates for writing the texture constant buffer and due to it not being implemented, the value will be read as 0 which is incorrect.
2022-04-14 14:14:52 +05:30
PixelyIon
d9a9e52350 Use ConstantBuffer instead of BufferView for Shader Constant Buffers
We want read semantics inside the constant buffer object via the mappings to avoid a pointless GPU VMM mapping lookup. It is a fairly frequent operation so this is necessary, the ability to write directly will be added in the future as well.
2022-04-14 14:14:52 +05:30
PixelyIon
adb0a16873 Implement Maxwell 3D Textures
Implements parsing for the Maxwell 3D TIC pool and conversion of a TIC into a `GuestTexture`, support is limited to pitch-linear RGB565/A8R8G8B8 textures at the moment but will be extended as games utilize more formats and layouts. Support for 1D buffers is also omitted at the moment since they need special handling with them effectively being treated as buffers in Vulkan rather than images.
2022-04-14 14:14:52 +05:30
PixelyIon
a7b90e7825 Change Texture Pitch Unit to Bytes from Pixels
The pitch of the texture should always be supplied in terms of bytes as it denotes alignment on a byte boundary rather than a pixel one, it is also always utilized in terms of bytes rather than pixels so this avoids an unnecessary conversion.

Note: GBP stride unit was assumed to be pixels earlier but is likely bytes which is why there are no changes to the supplied value there, if this is not the case it'll be fixed in the future
2022-04-14 14:14:52 +05:30
PixelyIon
a9aa16798f Add -fsigned-bitfields for defined bitfield int behavior
We want consistent behavior between signed `int`s in bitfields and outside of bitfields, the `-fsigned-bitfields` flag enforces this behavior.
2022-04-14 14:14:52 +05:30
PixelyIon
87c8dc94d2 Implement Maxwell3D Samplers
Maxwell3D `TextureSamplerControl` (TSC) are fully converted into Vulkan samplers with extension backing for all aspects that require them (border color/reduction mode) and approximations where Vulkan doesn't support certain functionality (sampler address mode) alongside cases where extensions may not be present (border color).
2022-04-14 14:14:52 +05:30
PixelyIon
e48a7d7009 Fix Mapping Caching For Maxwell 3D Buffers
Code involving caching of mappings was copied from `RenderTarget` without much consideration for applicability in buffers, the reason for caching mappings in RTs was that the view may be invalidated by more than the IOVA/Size being changed but this doesn't hold true for buffers generally so invalidation can only be on the view level with the mappings being looked up every time since the invalidation would likely change them.
2022-04-14 14:14:52 +05:30
PixelyIon
ff27dce24c Implement ObjectHash for hashing trivial objects in maps
`std::hash` doesn't have a generic template where it can be utilized for arbitrary trivial objects and implementing this might result in conflicts with other types. To fix this a generic templated hash is now provided as a utility structure, that can be utilized directly in hash-based containers such as `unordered_map`.
2022-04-14 14:14:52 +05:30
PixelyIon
97cfcba0da Add Nullability for Optional Semantics to span
Nullability allow for optional semantics where a span may be explicitly invalidated with `nullptr` being used as a sentinel value for it and a boolean operator that allows trivial checking for if the span is valid or not.
2022-04-14 14:14:52 +05:30
PixelyIon
c11962e8e4 Implement Maxwell3D Bindless Texture Constant Buffer Index
The index of the constant buffer with bindless texture descriptors is now retrieved from Maxwell3D register state and passed to the shader compiler.
2022-04-14 14:14:52 +05:30
PixelyIon
1c3f62b7b4 Implement Maxwell3D Indexed Drawing 2022-04-14 14:14:52 +05:30
PixelyIon
23cdfe2139 Implement Maxwell3D Index Buffers
Adds support for index buffers including U8 index buffers via the `VK_EXT_index_type_uint8` extension which has been added as an optional quirk but an exception will be thrown if the guest utilizes it but the host doesn't support it.
2022-04-14 14:14:52 +05:30
PixelyIon
a4041364e1 Address CR comments
Note: CR comments regarding `ShaderSet` and `PipelineStages` will be addressed at a later date with a common class for associative enum arrays.
2022-04-14 14:14:52 +05:30
PixelyIon
e1e14e781f Support Dual Vertex Shader Programs
Add support for parsing and combining `VertexA` and `VertexB` programs into a single vertex pipeline program prior to compilation, atomic reparsing and combining is supported to only reparse the stage that was modified and recombine once at most within a single pipeline compilation.
2022-04-14 14:14:52 +05:30
PixelyIon
974cf03c18 Add Atomic Pipeline Stage Invalidation
Atomically invalidate pipeline stages as runtime information that pertains to them changes rather than never recompiling pipelines on runtime information being updated resulting in out of date pipelines or recompiling all pipelines on any runtime information updates.
2022-04-14 14:14:52 +05:30
PixelyIon
5414db8411 Rework Maxwell3D Shader/Pipeline Stages Compilation with UBO support
Shader compilation is now broken into shader program parsing and pipeline shader compilation which will allow for supporting dual vertex shaders and more atomic invalidation depending on runtime state limiting the amount of work that is redone. 

Bindings are now properly handled allowing for bound UBOs to be converted to the appropriate host UBO as designated by the shader compiler by creating Vulkan Descriptor Sets that match it.
2022-04-14 14:14:52 +05:30
PixelyIon
055d315048 Seperate Maxwell3D Stages into Shader/Pipeline
We need this to make the distinction between a shader and pipeline stage in as shader programs are bound at a different rate than that of pipeline stage resources such as UBO.
2022-04-14 14:14:52 +05:30
PixelyIon
492dd47218 Implement Vulkan Descriptor Set Allocator
A fixed descriptor set allocator which manages the size of the pool with automatic reallocations when any allocations run out of descriptors.
2022-04-14 14:14:52 +05:30
PixelyIon
9af9f1d41a Implement Maxwell3D Constant Buffer Selector
The Constant Buffer Selector is used to point to a constant buffer that will be bound to a shader stage or updated with inline data.
2022-04-14 14:14:52 +05:30
PixelyIon
afa34e320a Retain Shader Binding State Across Stages
An instance of `Shader::Backend::Bindings` must be retained across all stages for correct emission of bindings, which is now done inside `GraphicsContext::GetShaderStages`.
2022-04-14 14:14:52 +05:30
PixelyIon
550d12b7fa Set Shader Runtime Generic Vertex Attribute Types Correctly
The vertex attribute types supplied prior were just the default which is `Float`, this works for some cases but will entirely break if the attribute type isn't a float. The attribute types are now set correctly.
2022-04-14 14:14:52 +05:30
PixelyIon
a2de6b9255 Fix Maxwell3D vertexEndGl Register Offset
The offset was set to 0x586 which is the location of `vertexBeginGl`, it's been corrected now and set to 0x585.
2022-04-14 14:14:52 +05:30
Billy Laws
5815cda7a7 Update Vulkan-Hpp to v1.2.202 2022-04-14 14:14:52 +05:30
PixelyIon
bd6cd0056c Support Multi-Aspect Copy in Texture::CopyIntoStagingBuffer
Only copying a single aspect was supported by `CopyIntoStagingBuffer` earlier due to not supplying a `VkBufferImageCopy` for each aspect separately, this has now been done with Color/Depth/Stencil aspects having their own `VkBufferImageCopy` for the `VkCmdCopyImageToBuffer` command.
2022-04-14 14:14:52 +05:30
PixelyIon
daff17c776 Order TextureView Definition Correctly
The definition of the `TextureView` class was spread across `texture.cpp` and has now been moved to the top of the file above the other half of the definition.
2022-04-14 14:14:52 +05:30
PixelyIon
189b9533f2 Disable Vertex Buffers With 0 as IOVAs
A buffer with 0 as the start/end IOVA should be invalid as there shouldn't be any mappings at 0 in GPU VA, titles such as Puyo Puyo Tetris configure the Vertex Buffer with 0 IOVAs which leads to a segmentation fault without this exception.
2022-04-14 14:14:52 +05:30
PixelyIon
cfeb8098db Attach TextureView/BufferView Lifetime to FenceCycle
The lifetime of a texture and buffer view is now bound by the `FenceCycle` in `CommandExecutor`, this ensures that a `VkImageView` isn't destroyed prior to usage leading to UB.
2022-04-14 14:14:52 +05:30
PixelyIon
34fc1e32b8 Remove Textures from RenderPassNode::Storage
The lifetime of all textures bound to a RenderPass alongside syncing of textures is already handled by `CommandExecutor` and doesn't need to be redundantly handled by `RenderPassNode`. It's been removed as a result of this.
2022-04-14 14:14:52 +05:30
PixelyIon
45c7a89fc3 Cleanup BufferView/TextureView Locking Code
Renames the variable to be neater and less confusing alongside adding comments for `try_lock()` to make the goal of the function more apparent.
2022-04-14 14:14:52 +05:30
PixelyIon
7776ef2cd0 Support Depth/Stencil RT in Draw
Adds the depth/stencil RT as an attachment for the draw but with `VkPipelineDepthStencilStateCreateInfo` stubbed out, it'll not function correctly and the contents will not be what the guest expects them to be.
2022-04-14 14:14:52 +05:30
PixelyIon
525850ae09 Stub VkPipelineDepthStencilStateCreateInfo
Maxwell3D Depth State is composed of several registers and will be implemented at a later date, for the time being it's been stubbed.
2022-04-14 14:14:52 +05:30
PixelyIon
9e63ecf05d Implement Maxwell3D Depth/Stencil Clears
Support for clearing the depth/stencil RT has been added as its own function via either optimized `VkAttachmentLoadOp`-based clears or `vkCmdClearAttachments`. A bit of cleanup has also been done for color RT clears with the lambda for the slow-path purely calling the command rather than creating the parameter structures.
2022-04-14 14:14:52 +05:30
PixelyIon
bf89f96bf5 Implement Optimized LoadOp Clears for Depth/Stencil Attachments
Implements `AddClearDepthStencilSubpass` in `CommandExecutor` which is similar to `ClearColorAttachment` in that it uses `VK_ATTACHMENT_LOAD_OP_CLEAR` for the clear which is far more efficient than using `VK_ATTACHMENT_LOAD_OP_LOAD` then doing the clear.
2022-04-14 14:14:52 +05:30
PixelyIon
6f6413f02d Fix VkSubpassDependency for Depth/Stencil Attachments
The stage/access mask for `VkSubpassDependency` were hardcoded to only be valid for color attachments earlier, this has now been fixed by branching based on the format aspect.
2022-04-14 14:14:52 +05:30
PixelyIon
aa32f6b017 Add Depth/Stencil Format Support to Texture
Sets `VkImageUsageFlags` correctly rather than hardcoding it for color attachments and adds multiple `VkBufferImageCopy` to `VkCmdCopyBufferToImage` for Color/Depth/Stencil aspects of an image.
2022-04-14 14:14:52 +05:30
PixelyIon
68c990c041 Implement Maxwell3D Depth/Stencil Render Target
Support the Maxwell3D Depth RT for Z-buffering, this just creates an equivalent `RenderTarget` object with no support on the API-user side (IE: `Draw` and `ClearBuffers`).
2022-04-14 14:14:52 +05:30
PixelyIon
2a8bcc60c7 Make Render Targets Abstract for Color/Depth RTs
This prefixes all RT functions that deal with color RTs with `Color` and abstracts out common functions that will be used for both color and depth RTs. All common Maxwell3D structures are also moved out of the `ColorRenderTarget` (`RenderTarget` previously) structure.
2022-04-14 14:14:52 +05:30
PixelyIon
b0f084ae32 Implement Shader Compiler Input Topology
Sets the input toplogy in the runtime information for the shader compiler correctly based on the Maxwell3D input topology.
2022-04-14 14:14:52 +05:30
PixelyIon
7a63ad7d3d Implement VkPipelineCache for host pipeline caching
To allow for caching of pipelines on the host a `VkPipelineCache` has been added, it is entirely in-memory and is not flushed to the disk which'll be done in the future alongside caching guest shaders to further avoid translation where possible.
2022-04-14 14:14:52 +05:30
PixelyIon
4dcf12c4c0 Implement Maxwell3D Draws
Uses all Maxwell3D state converted into Vulkan state to do an equivalent draw on the host GPU, it sets up RT/Vertex Buffer/Vertex Attribute/Shader state and creates a stubbed out `VkPipelineLayout` for the draw. Any descriptor state isn't currently handled and is yet to be implemented, currently there's no Vulkan pipeline cache supplied which will be implemented subsequently.
2022-04-14 14:14:52 +05:30
PixelyIon
57b0d6a2fb Stub VkPipelineMultisampleStateCreateInfo
Multisampling will be worked on later and for the time being is being safely stubbed by setting the sample count to 1.
2022-04-14 14:14:52 +05:30
PixelyIon
56b3a01a59 Track VkRenderPass and Subpass Index for Subpass Function Nodes
We require a handle to the current renderpass and the index of the subpass in certain cases, this is now tracked by the `CommandExecutor` and passed in as a parameter to `NextSubpassFunctionNode` and the newly-introduced `SubpassFunctionNode`.
2022-04-14 14:14:52 +05:30
PixelyIon
cb7f68b98d Allow Attaching Texture/Buffers to CommandExecutor
Switch from `SubmitWithCycle` to manually allocating the active command buffer to tag dependencies with the `FenceCycle` that prevents them from being mutated prior to execution. This new paradigm could also allow eager recording of commands with only submission being deferred.
2022-04-14 14:14:52 +05:30
PixelyIon
aeea3e6f66 Allow manual allocation of ActiveCommandBuffer
`CommandScheduler` API users can now directly allocate an active command buffer that they need to manage alongside its fence, this can allow for more efficient recording as it doesn't need to be immediately submitted after, it can also allow attaching objects to a `FenceCycle` prior to submission that can be useful for locking resources.
2022-04-14 14:14:52 +05:30
PixelyIon
8989305637 Implement Host Vertex Buffer Translation
Uses the buffer cache to retrieve an equivalent host vertex buffer for a corresponding guest vertex buffer.
2022-04-14 14:14:52 +05:30
PixelyIon
b6ba770a27 Implement Maxwell3D Shader Compilation
Compiles shaders supplied by the guest with caching and automatic invalidation, the size of the shader is also automatically determined by looking for `BRA $` instructions which cause an infloop, it should be noted that we have a maximum shader bytecode size, any shader above this size will not be supported.
2022-04-14 14:14:52 +05:30
PixelyIon
08afda6ac4 Implement Graphics Shader Compilation in ShaderManager
Graphics shaders can now be compiled using the shader compiler and emit SPIR-V that can be used on the host. The binding state isn't currently handled alongside constant buffers and textures support in `GraphicsEnvironment` yet.
2022-04-14 14:14:52 +05:30
PixelyIon
353ca8ec84 Fix Viewport X/Y Translation
The operands of the subtraction in the X/Y translation calculation were the wrong way around which led to negative translations that would translate the viewport off the screen.
2022-04-14 14:14:52 +05:30
PixelyIon
f06a12170f Set Default Color Write Mask to RGBA
The default color write mask should mask no channels and write all of them and should be mutated to mask out certain channels as required by the guest.
2022-04-14 14:14:52 +05:30
PixelyIon
23faf1370c Use Static Arrays for Vertex Buffer Bindings & Attributes
We cannot statically construct the vertex buffer/attribute arrays for Vulkan due to inactive attributes or buffers which isn't possible on Vulkan, we also cannot just change the count dynamically as there might be disabled buffers or attributes in the middle. We just have a `static_array` which should dynamically be filled in with buffer binding/attribute Vulkan structures before submission.
2022-04-14 14:14:52 +05:30
PixelyIon
8652edb07b Make GuestBuffer format-less
Buffers generally don't have formats that are fundamentally associated with them unless they're texel buffers, if that is the case it can be manually set in `BufferView`.
2022-04-14 14:14:52 +05:30
PixelyIon
03314ec7d2 Introduce BufferManager
The Buffer Manager handles mapping of guest buffers to host buffer views with automatic handling of sub-buffers and eventually supporting recreation of overlapping buffers to create a single larger buffer.
2022-04-14 14:14:52 +05:30
PixelyIon
bde61d72cc Introduce Buffer and BufferView
Implements infrastructure for using guest buffers on the host for rendering, a `BufferManager` is still missing which'd handle mapping from guest buffers to host buffers and will be subsequently committed. It should be noted that `BufferView` is also disconnected from `Buffer` and shared for every instance with the same properties like `TextureView` is now.
2022-04-14 14:14:52 +05:30
PixelyIon
6eda1777c5 Rework TextureView to be disconnected from Texture
We want `TextureView`(s) to be disconnected from the backing on the host and instead represent a specific texture on the guest with a backing that can change depending on mapping of new textures which'd invalidate the backing but should now be automatically repointed to an appropriate new backing. This approach also requires locking of the backing to function as it is mutable till it has been locked or the backing has an attached `FenceCycle` that hasn't been signaled which will be added for `CommandExecutor` in a subsequent commit.
2022-04-14 14:14:52 +05:30
PixelyIon
82916657fb Only Enable Shader Compiler Debug Mode in Debug Builds
Sets properties that relate to debugging in `Shader::Settings` to `true` only for debug builds while leaving them disabled for release builds.
2022-04-14 14:14:52 +05:30
PixelyIon
b09f28c0ba Implement Missing Shader Compiler Quirks
Introduces the `supportsShaderViewportIndexLayer` quirk and sets `Shader::Profile::support_int64_atomics` depending on if the `supportsAtomicInt64` quirk is available.
2022-04-14 14:14:52 +05:30
PixelyIon
f3e81094a2 Implement Shader Compiler Property Quirks
Introduces the `floatControls`, `supportsSubgroupVote` and `subgroupSize` quirks for the shader compiler which are based on Vulkan `PhysicalDevice` properties.
2022-04-14 14:14:52 +05:30
PixelyIon
51c4df24b5 Switch from VK_VERSION_* to VK_API_VERSION_* macros
Vulkan has officially deprecated `VK_VERSION_*` macros for versioning as it has introduced the variant into the version. It should however be `0` for the Vulkan APi and doesn't need to be printed.
2022-04-14 14:14:52 +05:30
PixelyIon
0588a525b4 Implement Shader Compiler Extension/Feature Quirks
Introduces several quirks for optional features used by the shader compiler which are now reported in the `Shader::HostTranslateInfo` and `Shader::Profile` structure. There are still property-related quirks for the shader compiler which haven't been implemented in this commit.
2022-04-14 14:14:52 +05:30
PixelyIon
8f3887c56a Create memory::Buffer & Implement StagingBuffer as derivative
A `Buffer` class was created to hold any generic Vulkan buffer object with `span` semantics, `StagingBuffer` was implemented atop it as a wrapper for `Buffer` that inherits from `FenceCycleDependency` and can be used as such.
2022-04-14 14:14:52 +05:30
PixelyIon
a55aca76c6 Rename TextureView::backing to TextureView::texture
It was determined that `backing` wasn't a very descriptive name and that it conflicted with the texture's own backing, the name was changed to `texture` to make it more apparent that it was specifically the `Texture` object backing the view.
2022-04-14 14:14:52 +05:30
PixelyIon
482c573b81 Introduce FlatMemoryManager::ReadTill for scanning semantics
A memory manager function to read into a vector till it satisfies the supplied function or hits an early stop condition like hitting the end of vector or reaching an unmapped region. This can be used to efficiently scan for values in GPU VA.
2022-04-14 14:14:52 +05:30
PixelyIon
31c4f1ca4e Unlink VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT when disabled
When `VK_EXT_vertex_attribute_divisor` is not available, `VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT` is unlinked from the device enabled feature list as it is undefined behavior to link a structure provided by an extension without enabling that extension.
2022-04-14 14:14:52 +05:30
PixelyIon
7df2670ece Fix QuirkManager's EXT_SET_V macro bug
`EXT_SET_V` would enable the extension regardless of if it was actually the correct extension or if the version was high enough as long as the hash matched.

Co-authored-by: Billy Laws <blaws05@gmail.com>
2022-04-14 14:14:52 +05:30
PixelyIon
e9ed771b48 Check for supportsMultipleViewports feature before usage
If the host only supports a single viewport then we set `viewportCount` and `scissorCount` in `VkPipelineViewportStateCreateInfo` to 1.
2022-04-14 14:14:52 +05:30
PixelyIon
3e45006d14 Make shaderImageGatherExtended a required VkDevice feature
`shaderImageGatherExtended` is required by the shader compiler, to avoid complications associated with making it optional and considering that it's supported by the vast majority of Vulkan mobile devices, it was made a mandatory feature.
2022-04-14 14:14:52 +05:30
PixelyIon
ece2785582 Introduce ShaderManager with Proxy Shader Compiler Logger/Settings
This class will be entirely responsible for any interop with the shader compiler, it is also responsible for caching and compilation of shaders in itself.
2022-04-14 14:14:52 +05:30
PixelyIon
89e9a41a86 Implement VkPipelineViewportStateCreateInfo
"Viewport Transforms" and "Viewport Scissors"  were combined into one section to reflect their state in Vulkan correctly like all other sections.
2022-04-14 14:14:52 +05:30
PixelyIon
38119e21d4 Implement Vulkan-Supported Maxwell3D Primitive Topologies
Any primitive topologies that are directly supported by Vulkan were implemented but the rest were not and will be implemented with conversions as they are used by applications, they are:
* LineLoop
* QuadList
* QuadStrip
* Polygon
2022-04-14 14:14:52 +05:30
PixelyIon
138f884159 Implement Maxwell3D Vertex Attributes
Translates all Maxwell3D vertex attributes to Vulkan with the exception of `isConstant` which causes the vertex attribute to return a constant value `(0,0,0,X)` which was trivial in OpenGL with `glDisableVertexAttribArray` and `glVertexAttrib4(..., 0, 0, 0, 1)` but we don't have access to this in Vulkan and might need to depend on undefined behavior or manually emulate it in a shader. This'll be revisited in the future after checking host GPU behavior.
2022-04-14 14:14:52 +05:30
PixelyIon
4b9f99bb27 Make ENUM_STRING function static
`ENUM_STRING` can be used inside a `class`/`struct`/`union` for `enum`s contained within them. Making the function `static` allows doing this and doesn't require supplying a `this` pointer of the enclosing class for usage.
2022-04-14 14:14:52 +05:30
PixelyIon
c2a6da6431 Implement Maxwell3D Vertex Buffer Limit
Sets the end of VBOs based on the `vertexArrayLimits` register array which provides an IOVA to the end of the VBO.
2022-04-14 14:14:52 +05:30
PixelyIon
d8890f13e1 Explicitly make default case break for Maxwell3D::HandleMethod
This being made implicit removes any confusion that all cases would need to be implemented and explicitly define that the CF should continue onto the 2nd switch-case when it cannot find any matches in the first one.
2022-04-14 14:14:52 +05:30
PixelyIon
612f324e78 Implement Maxwell3D Vertex Buffer Instance Rate
Implements the `isVertexInputRatePerInstance` register array which controls if the vertex input rate is either per-vertex or per-instance. This works in conjunction with the vertex attribute divisor for per-instance attribute repetition of attributes.
2022-04-14 14:14:52 +05:30
PixelyIon
476c070c7a Fix Minor Maxwell3D Register Ordering Issues
We order all registers in ascending order, a few registers namely `colorLogicOp`, `colorWriteMask`, `clearBuffers` and `depthBiasClamp` were erroneously not following this order which has now been fixed.
2022-04-14 14:14:52 +05:30
PixelyIon
32de7e5150 Use decltype over typeof globally
We inconsistently utilized `typeof` and `decltype` all over the codebase, this has now been fixed by uniformly using `decltype` as `typeof` is a GCC extension and not in the C++ standard alongside having the hidden side effect of removing references from the determined type.
2022-04-14 14:14:52 +05:30
PixelyIon
841ee9fc15 Check for vertexAttributeInstanceRateZeroDivisor feature before usage
Check for `vertexAttributeInstanceRateZeroDivisor` in `VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT` when the Maxwell3D register corresponding to the vertex attribute divisor is set to 0. If it isn't then it logs a warning and sets the value anyway which could result in UB since the only alternative is an exception that stops emulation which might not be optimal if the game mostly works fine without this, we will add a user-facing warning when we intentionally allow UB like this in the future.
2022-04-14 14:14:52 +05:30
PixelyIon
c3895a8197 Support VkPhysicalDeviceFeatures2 Extensions
Implement the infrastructure to depend on `VkPhysicalDeviceFeatures2` extended feature structures which can be utilized to retrieve the specifics of features from extensions. It is implemented in the form of `vk::StructureChain` with `vk::PhysicalDeviceFeatures2` that can be extended with any extension feature structures.
2022-04-14 14:14:52 +05:30
PixelyIon
ff5515d4d1 Implement Maxwell3D Vertex Buffer Bindings
This implements everything in Maxwell3D vertex buffer bindings including vertex attribute divisors which require the extension `VK_EXT_vertex_attribute_divisor` to emulate them correctly, this has been implemented in the form of of a quirk. It is dynamically enabled/disabled based on if the host GPU supports it and a warning is provided when it is used by the guest but the host GPU doesn't support it.
2022-04-14 14:14:52 +05:30
PixelyIon
d163e4ffa6 Introduce IOVA union for flipped words of IOVAs in GraphicsContext
The Maxwell3D `Address` class follows the big-endian register ordering for addresses while on the host we consume them in little-endian, the `IOVA` class is the host equivalent to the `Address` class with implicitly flipped 32-bit register ordering. It shares implicit decomposition semantics from `Address` due to similar requirements with a minor difference of being returned by reference rather than value as we want to have value setting semantics with implicit decomposition while we don't for `Address`.
2022-04-14 14:14:52 +05:30
PixelyIon
73646c4da8 Implicitly decompose Address into u64
The semantics of implicitly decomposing the `Address` class into a `u64` were determined to be appropriate for the class. As it is an integer type this effectively retains all semantics from using an integer directly for the most part.
2022-04-14 14:14:52 +05:30
PixelyIon
48d0b41f16 Implement Maxwell3D Common/Independent Color Write Mask
Maxwell3D supports both independent and common color write masks like color blending but for common color write masks rather than having register state specifically for it, the state from RT 0 is extended to all RTs. It should be noted that color write masks are included in blending state for Vulkan while being entirely independent from each other for Maxwell, it forces us to use the `independentBlend` feature even when we are doing common blending unless the color write mask is common as well but to simplify all this logic the feature was made required as it supported by effectively all targeted devices.
2022-04-14 14:14:52 +05:30
PixelyIon
92809f8a78 Implement Maxwell3D Independent/Common Color Blending
Maxwell3D supports independent blending which has different blending per-RT and common blending which has the same blending for all RTs. There is a register determining which mode to utilize and we simply have two arrays of `VkPipelineColorBlendAttachmentState` for the RTs that we toggle between to make the transition between them extremely cheap.
2022-04-14 14:14:52 +05:30
PixelyIon
2ceb6465e8 Make independentBlend a required VkDevice feature
Independent blending is supported by effectively every Vulkan 1.1 Android GPU, it gives us the ability to architecture Maxwell3D blending emulation better as we can avoid additional checks for independent blending state and having a fallback path for when the host doesn't support the feature.
2022-04-14 14:14:52 +05:30
PixelyIon
cd737fbdd8 Add Required VkDevice Features
A prior commit added the ability to utilize features with quirks but this implements the ability to require a feature be present on the host or an exception will be thrown. It allows us to make useful assumptions that result in a better architecture in certain cases.
2022-04-14 14:14:52 +05:30
PixelyIon
081d3277c1 Enable Quirk + Required VkDevice Extensions
Implements the infrastructure required to enable optional extensions set in `QuirkManager` alongside the required extensions in the `GPU` class. All extensions should be correctly resolved now and according to what the device supports.
2022-04-14 14:14:52 +05:30
PixelyIon
6099b1ead5 Fix Maxwell3D Register lineWidthAliased Offset
The offset was incorrectly set to `0x4D` rather than `0x4ED` which is what it should be. This would've led to bugs in line width determination and likely broken any aliased line rendering entirely.
2022-04-14 14:14:52 +05:30
PixelyIon
51659e1329 Enable VkDevice Features Selectively
We selectively enable GPU features that we require as enabling all of them might result in extra driver overhead in certain circumstances. Setting them is handled by `QuirkManager` with the new `FEAT_SET` function that ties a quirk with a feature.
2022-04-14 14:14:52 +05:30
PixelyIon
ec378814aa Stub Maxwell3D Alpha Testing
We stub alpha testing as it doesn't exist in Vulkan and few titles use it, it can be emulated in the future using a shader patch with manually discarding fragments failing the alpha test function but this'll be added in later as it isn't high priority at the moment and has associated overhead with it so other options might be explored at the time.
2022-04-14 14:14:52 +05:30
PixelyIon
83ec99fa48 Print GPU Quirks At Startup
It is essential to know what quirks a certain GPU may have to debug an issue, these are now printed at startup into the log alongside all other GPU information. A new `QuirkManager::Summary` function was implemented to provide this functionality.
2022-04-14 14:14:52 +05:30
PixelyIon
01eb16e59a Implement Maxwell3D Color Logic Operations
Implements a basic part of Vulkan blending state which are color logic operations applied on the framebuffer after running the fragment shader. It is an optional feature in Vulkan and not supported on any mobile GPU vendor aside from ImgTec/NVIDIA by default.
2022-04-14 14:14:52 +05:30
PixelyIon
662935c35d Attempt Flushing Logger During Fatal Signals
Any signals that lead to exception handling being triggered now attempt to flush all logs given that the log mutex is unoccupied, this is to mostly help logs be more complete when exiting isn't graceful.
2022-04-14 14:14:52 +05:30
PixelyIon
586bee2c59 Remove Maxwell3D Zero Initialization Calls
A lot of calls in Maxwell3D register initialization ended up setting the register to 0 which should be implicit behavior and most calls would be eliminated by the redundancy check which had to be manually disabled. It was determined to be better to move this responsibility to the called function to initialize to state equivalent to the corresponding register being 0. All initialization calls with the argument as 0 have been removed now due to this, it was the vast majority of calls.
2022-04-14 14:14:52 +05:30
PixelyIon
49cc0964e2 Initialize Maxwell3D Registers Correctly
Maxwell3D Registers weren't initialized to the correct values prior, this commit fixes that by doing `HandleMethod` calls with all the register values being initialized. This is in contrast to the registers being set without calling the methods in `GraphicsContext` or otherwise resulting in bugs.
2022-04-14 14:14:52 +05:30
PixelyIon
ea87b8878c Implement B8G8R8A8{Unorm/Srgb} RT Format
Needed by Maxwell3D Register Initialization
2022-04-14 14:14:52 +05:30
PixelyIon
69e7d8b574 Remove Vulkan to Skyline Format Conversion Function
The function `GetFormat` was seemingly no longer required due to us never converting from a Vulkan format to a Skyline format, most conversions only went from Skyline to Vulkan and were generally lossy due to certain formats being missing in Vulkan and approximated using channel swizzles. As a result of this, it was pointless to maintain and has now been removed.
2022-04-14 14:14:52 +05:30
PixelyIon
5ed26fef23 Implement Maxwell3D Rasterizer State
Maxwell3D registers relevant to the Vulkan Rasterizer state have been implemented aside from certain features such as per-face polygon modes that cannot be implemented due to Vulkan limitations. A quirk was utilized to dynamically support the provoking vertex being the last vertex as opposed to the first as well.
2022-04-14 14:14:52 +05:30
PixelyIon
8ef225a37d Introduce QuirkManager for runtime GPU quirk tracking
We require a way to track certain host GPU features that are optional such as Vulkan extensions, this is what the `QuirkManager` class does as it checks for all quirks and holds them allowing other components to branch based off these quirks.
2022-04-14 14:14:52 +05:30
PixelyIon
8803616673 Reorder GraphicsContext Members
All members are now placed at the start of sections they are relevant to rather than  at the start of the class.
2022-04-14 14:14:52 +05:30
PixelyIon
107d337d77 Fix MacroInterpreter::MethodAddress Bitfield Padding
Due to compiler alignment issues, the bitfield member `increment` of `MacroInterpreter::MethodAddress` was mistakenly padded and moved to the next byte. This has now been fixed by making its type `u16` like the member prior to it to prevent natural alignment from kicking in.
2022-04-14 14:14:52 +05:30
PixelyIon
26966287c7 Implement Maxwell3D Shader Program Registers
This commit added basic shader program registers, they simply track the address a shader is pointed to at the moment. No parsing of the shader program is done within them.
2022-04-14 14:14:52 +05:30
PixelyIon
93ea919c8f Fix warnings from NVRESULT due to unused lambda capture
A previously used `this` capture is no longer used since the introduction of the static logger.
2022-04-14 14:14:52 +05:30
lynxnb
092dcb18c8 Stub ectx:w and ectx:aw Glue services 2022-02-06 21:57:38 +05:30
lynxnb
6913a90361 Use the new log file name & ext for every logger context 2021-11-11 16:32:19 +01:00
lynxnb
5cd1f01690 Refactor all logger calls 2021-11-11 16:13:24 +01:00
lynxnb
769e6c933d Make Logger class static and introduce LoggerContext
A thread local LoggerContext is now used to hold the output file stream instead of the `Logger` class. Before doing any logging operations, a LoggerContext must be initialized.
This commit will not build successfully on purpose.
2021-11-11 16:13:24 +01:00
Billy Laws
d88b08d986 Address PR feedback 2021-11-10 21:35:36 +05:30
Billy Laws
1b453c04ca Remove completed nvmap TODO
Pins have been implemented so the to-do is no longer needed.
2021-11-10 21:35:36 +05:30
Billy Laws
d2d181725f Remove unused virtEnd variable in FlatMemoryManager::{Read, Write} 2021-11-10 21:35:36 +05:30
Billy Laws
60fbfad4bc Add virtual dtors to time service code 2021-11-10 21:35:36 +05:30
Billy Laws
ef10d3d394 Use semantic wrapping where appropriate for class initialiser lists 2021-11-10 21:35:36 +05:30
Billy Laws
6b33268d85 Remove unused gm20b EngineID enum 2021-11-10 21:35:36 +05:30
Billy Laws
73896c2e6b Fixup nvdrv channel types to follow naming conventions 2021-11-10 21:35:36 +05:30
Billy Laws
ad900aba7a s/Host1X/Host1x/ as per Nvidia naming 2021-11-10 21:35:36 +05:30
Billy Laws
dbfb1cfe20 Fully implement the nvdrv Host1xChannel::Submit operation
This pushes a set of command buffers into the Host1x command FIFO allocated for the channel, returning fence thresholds that can be waited on for completion,
2021-11-10 21:35:36 +05:30
Billy Laws
baefb0fe93 Implement the Host1x command FIFO together with barebones Host1x classes
The Host1x block of the TX1 supports 14 separate channels to which commands can be issued, these all run asynchronously so are emulated the same way as GPU channels with one FIFO emulation thread each. The command FIFO itself is very similar to the GPFIFO found in the GPU however there are some differences, mainly the introduction of classes (similar to engines) and the Mask opcode (which allows writing to a specific set of offsets much more efficiently).

There is an internal Host1x class which functions similar to the GPFIFO class in the GPU, handling general operations such as syncpoint waits, this is accessed via the simple method interface. Other channels such as NVDEC and VIC are behind the 'Tegra Host Interface' (THI) in HW, this abstracts out the classes internal details and provides a uniform method interface ontop of the Host1x method one. We emulate the THI as a templated wrapper for the underlying class.

Syncpoint increments in Host1x are different to GPU, the THI allows submitting increment requests that will be queued up and only be applied after a specific condition in the associated engine is met; however the option to for immediate increments is also available.
2021-11-10 21:35:36 +05:30
Billy Laws
2494cafee8 Cleanup GPFIFO comments and make Run() private 2021-11-10 21:35:36 +05:30
Billy Laws
2577658fc7 Avoid GetPointer on nvmap handles where they would be accessed via SMMU
GetPointer sets the sharedMemMapped flag, which should only be set if
other userspace processes have the handle mapped.
2021-11-10 21:35:36 +05:30
Billy Laws
fd0420443c Add template utils for constructing all elements in an std::array
This avoids the excessive repetition needed for the case where array
members have no default constructor.

eg:
```c++
std::array<Type, 10> channels{util::MakeFilledArray<Type, 10>(typeConstructorArg, <...>)};
```
2021-11-10 21:35:36 +05:30
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
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
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
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
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
Billy Laws
70d1b4994c Enable Wconversion and fix warnings produced 2021-10-26 11:41:24 +01:00
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
PixelyIon
9b9bf8d300 Introduce ThreadLocal Class + Fix Several GPU Bugs
* Fix `AddClearColorSubpass` bug where it would not generate a `VkCmdNextSubpass` when an attachment clear was utilized
* Fix `AddSubpass` bug where the Depth Stencil texture would not be synced
* Respect `VkCommandPool` external synchronization requirements by making it thread-local with a custom RAII wrapper
* Fix linear RT width calculation as it's provided in terms of bytes rather than format units
* Fix `AllocateStagingBuffer` bug where it would not supply `eTransferDst` as a usage flag
* Fix `AllocateMappedImage` where `VkMemoryPropertyFlags` were not respected resulting in non-`eHostVisible` memory being utilized
* Change feature requirement in `AndroidManifest.xml` to Vulkan 1.1 from OGL 3.1 as this was incorrect
2021-10-16 12:13:30 +01:00
Billy Laws
eb25f60033 Implement multichannel support for GPU
Allows the execution of multiple channels at the same time, with locking
being performed on the host GPU scheduler layer, address spaces can be
bound to one or more channels.
2021-10-16 12:13:30 +01:00
PixelyIon
b762d1df23 Introduce Texture Always Sync + Wait on GPU Execution + More RT Formats
Infrastructure for always syncing textures has been introduced now, they will be synced prior to and after every execution. This does considerably reduce the performance alongside waiting on GPU execution to finish but it will be partially recouped once conditional syncing is performed.
2021-10-16 12:13:30 +01:00
PixelyIon
f8acc1e131 Improve Shared Fonts + Fix AM PopLaunchParameter & Choreographer Bug
* Move Shared Font TTFs to AAsset storage + Support external shared font loading from `/data/data/skyline.emu/data/fonts`
* Fix bug in `IApplicationFunctions::PopLaunchParameter` caused by ignoring `LaunchParameterKind`
* Fix bug with Choreographer causing it to be awoken and exit prior to the destruction of `PresentationEngine`
* Fix bug with `IDirectory::Read` where it used `inputBuf` for the output buffer rather than `outputBuf`
* Improve `GetFunctionStackTrace` logs when `dli_sname` or `dli_fname` are missing
* Support more RT Formats
2021-10-16 12:13:30 +01:00
PixelyIon
95a08627e5 Subpass Support + More RT Formats + Fix FenceCycle Cyclic Dependencies
Support for subpasses was added by reworking attachment reuse code to account for preserved attachments and subpass dependencies. A lot of RT formats were also added to allow SMO to boot up entirely, it should be noted that it doesn't render anything. 

`FenceCycle` had a cyclic dependency which broke clean exit, we now utilize `std::weak_ptr<FenceCycle>` inside the `Texture` object. A minor fix for broken stack traces was also made caused by supplying a `nullptr` C-string to libfmt when a symbol was unresolved which caused an `abort` due to invocation of `strlen` with it.
2021-10-16 12:13:30 +01:00
PixelyIon
239d2625e2 Introduce CommandExecutor + Implement ClearBuffers + More RT Formats
This commit introduces the `CommandExecutor` which is responsible for creating and orchestrating a Vulkan command graph comprising of `CommandNode`s that construct all the objects required for rendering. As a result of the infrastructure provided by `CommandExecutor`, `ClearBuffers` could be implemented and be appropriately utilized.

A bug regarding scissors was also determined and fixed in the PR, the extent of them were previously inaccurate and this has now been fixed.

Note: We don't synchronize any textures from the guest for now as this would override the contents on the host, this'll be fixed with the appropriate write tracking but it also results in a black screen for anything that writes to FB
2021-10-05 01:13:22 +05:30
PixelyIon
3879d573d5 Fix Command Buffer Allocation & FenceCycle
This commit fixes a major issue with command buffer allocation which would result in only being able to utilize a command buffer slot on the 2nd attempt to use it after it's freed, this would lead to a significantly larger amount of command buffers being created than necessary. It also fixes an issue with the command buffers not being reset after they were utilized which results in UB eventually.

Another issue was fixed with `FenceCycle` where all dependencies are only destroyed on destruction of the `FenceCycle` itself rather than the function where the `VkFence` was found to be signalled.
2021-10-05 01:13:22 +05:30
PixelyIon
bee28aaf0d Validation Layer Filter + Fix Texture, GPU & PresentationEngine bugs
This commit implements a filter by type for any validation layer output, this allows filtering out any logs which may be unnecessary and additionally triggering a breakpoint as required. 

An issue concerning the `NDEBUG` flag never being set was fixed, it's now supplied as a release compiler flag. The issue can manifest itself by always relying on a validation layer even though it shouldn't on release, this is why the validation layer was mistakenly disabled entirely previously by using `#ifndef` rather than `#ifdef`.

An issue with the initial layout of a texture being supplied as neither `VK_IMAGE_LAYOUT_UNDEFINED` or `VK_IMAGE_LAYOUT_PREINITIALIZED` was fixed, these cases are now handled by transitioning to those layouts after creating the image rather than supplying it within `initialLayout`.

Another issue was fixed regarding not maintaining a transformation after a surface has been destroyed and recreated existed and manifested itself when the user would go out of the app and come back in, they would see the surface having an identity transformation rather than the desired one.
2021-10-05 01:13:22 +05:30
PixelyIon
54908afc44 Texture GMMU Address Resolution + Refactor Maxwell3D::CallMethod
Fixes bugs with the Texture Manager lookup, fixes `RenderTarget` address extraction (`low`/`high` were flipped prior), refactors `Maxwell3D::CallMethod` to utilize a case for the register being modified + preventing redundant method calls when no new value is being written to the register, and fixes the behavior of shadow RAM which was broken previously and would lead to incorrect arguments being utilized for methods.
2021-10-05 01:13:22 +05:30
PixelyIon
270f2db1d2 Initial Texture Manager Implementation + Maxwell3D Render Target
Implement the groundwork for the texture manager to be able to report basic overlaps and be extended to support more in the future. The Maxwell3D registers `RenderTargetControl`, `RenderTarget` and a stub for `ClearBuffers` were implemented. 

A lot of changes were also made to `GuestTexture`/`Texture` for supporting mipmapping and multiple array layers alongside significant architectural changes to `GuestTexture` effectively disconnecting it from `Texture` with it no longer being a parent rather an object that can be used to create a `Texture` object.

Note: Support for fragmented CPU mappings hasn't been added for texture synchronization yet
2021-10-05 01:13:22 +05:30
PixelyIon
8cba1edf6d Introduce Boost as a submodule + Minor Fixes
Utilize Boost Container's `small_vector` for optimizing allocations, fix certain implicit casting issues and make `ILogger` not output an additional newline in the log when the application supplies one at the end of the log
2021-10-05 01:13:22 +05:30
PixelyIon
190fde110f Introduce GraphicContext and Implement Viewport Transform + Scissors 2021-10-05 01:13:22 +05:30
PixelyIon
bc378ad135 Fix GraphicBufferProducer Format Bug
The format provided in `GraphicBuffer` can be misleading and is supplied as `None` by the Deko3D Swapchain, it instead supplies the real format in the `NvGraphicHandle` which we now utilize instead of the one in `GraphicBuffer`.
2021-10-05 01:13:22 +05:30
PixelyIon
18cf0b82d6 Fix KTransferMemory Destruction Behavior + Add Missing SVC Handle Logs
KTransferMemory needs to be reset to RW on destruction unlike KSharedMemory which is simply freed on destruction, not emulating this behavior accurately leads to `deko_examples` from `switch-examples` to lead to a SEGFAULT on selecting an example as it expects the memory to be R/W while it ends up being freed instead
2021-10-05 01:13:22 +05:30
Billy Laws
192459f726 Adjust AS block end predecessors to successors after reuse as end 2021-10-04 20:29:02 +01:00
PixelyIon
d45193874e Fix NvDrv CloseDevice Bug
The unique pointer to a device in the map was simply reset rather than deleting the entry from the map, this resulted in the device not being properly closed and when the device was reopened then the `emplace` was a NOP as the entry already existed. This resulted in a `nullptr` dereference down the line when an application attempted to issue an IOCTL to a device that was previously closed and reopened. This is known to occur in Deko3D as it recreates the context when loading an example which includes closing and reopening devices.
2021-10-03 18:02:32 +05:30
Billy Laws
7a5ca19c0b Fix improper VMM error check in unmap 2021-10-01 20:58:22 +01:00
Billy Laws
4eff515c55 Add support for IOCTL3 CtrlGpu calls missed in refactor 2021-10-01 20:57:59 +01:00
PixelyIon
02bcf98b8c Fix NvDrv Bugs + NACP Parsing Bug
A hotfix for a nvdrv bug where an IOCTL with no input/output buffers would crash and a major `nvmap` bug which broke the `FromId` IOCTL as it didn't write back the handle ID, another minor bug existed in `nvhost` where the `ZCullGetInfo` IOCTL was `INOUT` rather than `OUT`.

A bug with NACPs was also fixed caused by incorrect padding for the `NacpData` structure which resulted in the `saveDataOwnerId` member being read incorrectly and as a result the save data folder being incorrect.

Co-authored-by: artem8086 <artemsvyatoha@gmail.com>
2021-10-02 00:15:53 +05:30
lynxnb
afc3dda1ee Reintroduce LanguageCode alias type 2021-09-30 02:19:19 +05:30
lynxnb
c6d91c552b Address CR 2021-09-30 02:19:19 +05:30
lynxnb
0077833667 Support game icon selection based on language 2021-09-30 02:19:19 +05:30
lynxnb
01ce09183b Rework common languages
Swapped out the usages of frozen constexpr unordered maps for switch statements, which are very likely to be turned into jump tables given the nature of the enums used, resulting in better performance than a map
2021-09-30 02:19:19 +05:30
sspacelynx
4d20d7a4d0 Address CR + Code formatting 2021-09-30 02:19:19 +05:30
sspacelynx
ca97517d81 Rework GetDesiredLanguage + Remove LanguageCode alias type 2021-09-30 02:19:19 +05:30
sspacelynx
fdc7e1238a Implement language support for rom loaders 2021-09-30 02:19:19 +05:30
sspacelynx
3c5509e52a Update available languages to those post 10.1.0
Brazilian Portuguese has been added in firmware version 10.1.0
2021-09-30 02:19:19 +05:30
sspacelynx
3fffde3061 Rework OS to allow passing a language 2021-09-30 02:19:19 +05:30
Billy Laws
a4a6511177 Address feedback 2021-09-30 02:11:19 +05:30
Billy Laws
a18f1aa889 Address feedback 2021-09-30 02:11:19 +05:30
Billy Laws
8db2cf29f2 Implement AsGpu::FreeSpace and clean up locking and debug prints 2021-09-30 02:11:19 +05:30
Billy Laws
d3dc0bddc4 Cleanup IStorageAccessor validation code 2021-09-30 02:11:19 +05:30
Billy Laws
39faa739b9 Optimise GPFIFO command processing for higher throughput
Using a u32 for the loop index prevents masking on all increments,
giving a moderate performance increase.

Passing methods as u32 parameters and stopping subChannel being passed
gives quite a significant increase when combined with the inlining
allowed by subchannel based engine selection.
2021-09-30 02:11:19 +05:30
Billy Laws
3d538a29da Misc code cleanup and more comments in AS map 2021-09-30 02:11:19 +05:30
Billy Laws
30d41252f7 Use IPC raw data size to calculate C Buffer offset
Some games don't have a u16 size array, the code for this is also kinda
pointless when we can use the raw data size too.
2021-09-30 02:11:19 +05:30
Billy Laws
d03b288db6 NEEDS CLEANUP: Reimplement GPU VMM and rewrite nvdrv VM impl 2021-09-30 02:11:19 +05:30
Billy Laws
020aa0e43a Add support for Ioctl2/3 and improve debug logging 2021-09-30 02:11:19 +05:30
Billy Laws
9bda574a4e Move nvhost-ctrl-gpu to new device API 2021-09-30 02:11:19 +05:30
Billy Laws
39492d9365 Move nvhost-gpu to new device API
The implementation of GPU channels and Host1X channels will be split up
as it allows a much cleaner implementation and less undefined behaviour
potential.
2021-09-30 02:11:19 +05:30
Billy Laws
3d4f7d9b44 Move nvhost-as-gpu to new device API 2021-09-30 02:11:19 +05:30
Billy Laws
1149158198 Make GraphicBufferProducer use the new nvmap API 2021-09-30 02:11:19 +05:30
Billy Laws
c97f5a9315 Entirely rewrite nvmap to separate global and per device state.
This will be required later for NVDEC/SMMU support and fixes many
significant issues in the previous implementation.
Based off of my 2.0.0/12.0.0 nvdrv REs.
2021-09-30 02:11:19 +05:30
Billy Laws
78356fa789 Migrate syncpoint management over to the new device API
The syncpoint manager has beeen given convinience functions for fences
which remove the need to access the raw id/threshold most of the time
and various accuracy fixes and cleanups to match HOS 12.0.0 have also
been done.
2021-09-30 02:11:19 +05:30
Billy Laws
a19bf973b1 Rework the nvdrv core for accuracy and support new deserialisation
Devices will need to be moved over in order to support this new
interface, IOCTL2/3 support will be added in a later commit.
2021-09-30 02:11:19 +05:30
Billy Laws
db2abe2290 Use concepts for Backing::Read over enable_if 2021-09-30 02:11:19 +05:30
Billy Laws
3340c74332 Implement efficient template based IOCTL deserialisation
This moves IOCTLs from frozen to a template based parser, this allows
IOCTL lookup to be performed much more optimally and some IOCTLs to be
inlined.
2021-09-30 02:11:19 +05:30
Billy Laws
75a67dcfa5 Allow supplying a custom ResultValue result type and optimise span
This allows PosixResultValue to be created easily.
2021-09-30 02:11:19 +05:30
Billy Laws
3d3c13f90c Add common PosixResult and PosixResultValue types
Many services like bsd and nvdrv use these to represent the result
values of functions so add a common type for these as an alternative to
the macros.
2021-09-30 02:11:19 +05:30
sspacelynx
14dc42b991 Add IntegerFor template class + Update GenerateUuidV4 2021-09-22 06:24:05 +05:30
sspacelynx
ea3c7301b1 Make UUID::GenerateUuidV4 use util::GetRandomBytes 2021-09-22 06:24:05 +05:30
sspacelynx
10d43c88c9 csrng service implementation
Implements the 'csrng:' service using C++ <random>'s Mersenne Twister, this does make it insecure for cryptographic purposes but it is pointless to attempt to do this regardless as we cannot ensure that the guest will run in a secure environment which cannot be mutated by an attacker. Used by Prison Princess, Pokemon Cafe Mix, Paint your Pet and more.
2021-09-22 06:24:05 +05:30
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