Commit Graph

705 Commits

Author SHA1 Message Date
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
032866c9b1 Allow Injecting External Vulkan Layers
Set `com.android.graphics.injectLayers.enable` to allow injection of external Vulkan layers which is done by GPU debuggers such as RenderDoc.
2022-04-14 14:14:52 +05:30
PixelyIon
b97e06f617 Update Vulkan Validation Layer to 1.2.198.0 SDK release 2022-04-14 14:14:52 +05:30
PixelyIon
e8d92a6858 Update Shader Compiler
Update to 2c295a067d
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
def9cedbee Add yuzu Shader Compiler as a submodule
We plan to use our fork of yuzu's shader compiler for GPU shader compilation so it's been added as a submodule.
2022-04-14 14:14:52 +05:30
PixelyIon
746af4cb4c Add Sirit as a submodule
We require Sirit as it is a dependency for yuzu's shader compiler where it uses it to emit SPIR-V in an easy and efficient manner.
2022-04-14 14:14:52 +05:30
PixelyIon
dbc94f36d3 Add Range v3 as a submodule
We want to utilize features from C++ 20 ranges but they haven't been entirely implemented in libc++ so in the meantime we use the reference implementation for it which is Ranges v3.
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