Commit Graph

79 Commits

Author SHA1 Message Date
Billy Laws
d893777262 Flush deferred draws before executing macro HLE and cleanup 2023-03-19 13:52:15 +00:00
Billy Laws
04f3fa4b7f Implement basic indirect draw macro HLE
This still requires usagetracker to avoid redundantly performing indirect draws when the memory isn't dirty, and to allow for using it with direct memory, but it's a start.
2023-03-19 13:52:15 +00:00
Billy Laws
acf118155d Submit an execution on invalidate{Sampler,TextureHeader}Cache accesses 2023-03-04 18:55:44 +00:00
Billy Laws
6ce5202b8e Add exceptions for some more unimplemented maxwell draw regs 2023-03-04 18:55:44 +00:00
Billy Laws
b3f7e990cc Allow for tying guest GPU sync operations to host GPU sync
This is necessary for the upcoming direct buffer support, as in order to use guest buffers directly without trapping we need to recreate any guest GPU sync on the host GPU. This avoids the guest thinking work is done that isn't and overwriting in-use buffer contents.
2023-01-08 19:30:52 +00:00
Billy Laws
be8cbabd97 Commonise maxwell3d texture code
This will be shared with the compute engine implementation.
2022-12-03 22:50:56 +00:00
Billy Laws
61e95c4b2c Commonise maxwell3d sampler code
This will be shared with the compute engine implementation, the only thing of note with this is that the binding register is now passed as a param since it is part of the compute QMD which can't be dirty tracked.
2022-12-03 22:50:56 +00:00
Billy Laws
c50852e546 Implement the draw(...)BeginEnd Maxwell3D draw registers
Used by guest Vulkan games and nouveau.
2022-11-02 17:46:07 +00:00
Billy Laws
c5ec484d9a Avoid redundantly passing executor in ctors when it's already in ChannelCtx 2022-11-02 17:46:07 +00:00
Billy Laws
e52dbf202f Pass more Maxwell3D registers into interconnect 2022-11-02 17:46:07 +00:00
Billy Laws
b72720e8db Finish off transform feedback implementation 2022-11-02 17:46:07 +00:00
Billy Laws
38aad21d29 Share single flag variable for Maxwell3D batch draw/constant buffer update
Slightly cheaper
2022-11-02 17:46:07 +00:00
Billy Laws
e1717ed811 Implement Maxwell samplers 2022-11-02 17:46:07 +00:00
Billy Laws
3404a3abdb Implement macro HLE for instanced draw macros
gm20b performs instanced draws by repeating draw methods for each instance, the code to detect this together with the cost of interpreting macros took up around 6% of GPFIFO time in Metro Kingdom. By detecting these specific macros and performing an instanced draw directly much of that cost can be avoided.
2022-11-02 17:46:07 +00:00
Billy Laws
2c1b40c9a8 Add some missed pipeline state members used by Hades 2022-11-02 17:46:07 +00:00
Billy Laws
e77e4891dc Tidy up Maxwell 3D regs a bit 2022-11-02 17:46:07 +00:00
Billy Laws
405d26fc22 Introduce Maxwell 3D shader state
Simple state holder that hashes the stored shader and reads it into a buffer
2022-11-02 17:46:07 +00:00
Billy Laws
6e55d4dcf4 Implement color blend pipeline state 2022-11-02 17:46:07 +00:00
Billy Laws
cb11662ea5 Implement depth stencil pipeline state 2022-11-02 17:46:07 +00:00
Billy Laws
690e96bce0 Implement rasterization pipeline state 2022-11-02 17:46:07 +00:00
Billy Laws
90cd6adb91 Implement tessellation pipeline state 2022-11-02 17:46:07 +00:00
Billy Laws
3649d4c779 Adapt Maxwell 3D engine to new interconnect code
Removes all usage of graphics_context.h from the codebase, exclusively using the new interconnect and its dirty tracking system. While porting the code a number of bugs were discovered such as not respecting the base instance or primitive type override, which have all been fixed. Currently only clears and constant buffer updates are implemented but due to the dirty state system allowing register handling on the interconnect end there shouldn't end up being many more changes.
2022-11-02 17:46:07 +00:00
Billy Laws
a6c49115f9 Rewrite all Maxwell 3D registers up to clears to match Nvidia docs
All the names are directly translated from Nvidia docs, with minimal conversions to enums/structs when appropriate. Not all registers have been rewritten, only those that are needed to implement clears and dynamic state, the rest will be added as they are used in the GPU rework.
2022-11-02 17:46:07 +00:00
Billy Laws
dccc86ea97 Implement transform feedback with VK_EXT_transform_feedback
Tested to work in Xenoblade Chronicles DE, the code handles both hades varying input and buffer setup.
2022-08-08 17:40:35 +01:00
Billy Laws
f52ea7bddb Make deferred draw and constant buffer updates reentrant-safe
At some point we will call Submit within draws or constant buffer updates, to avoid any infinite recursion mark draw/cbuf pending as false before performing any operation
2022-07-29 20:07:14 +01:00
Billy Laws
4149ab1067 Implement Maxwell 3D instanced draw support
In the Maxwell 3D engine, instanced draws are implemented by repeating the exact same draw in sequence with special flag set in vertexBeginGl. This flag allows either incrementing the instance counter or resetting it, since we need to supply an instance count to the host API we defer all draws until state changes occur. If there are no state changes between draws we can skip them and count the occurences to get the number of instances to draw.
2022-05-07 13:56:09 +01:00
Billy Laws
03594a081c Ensure correct flushing for batched constant buffer updates
Cbufs could be read by non-maxwell3D engines so force a flush when switching to them or before Execute.
2022-05-07 13:56:09 +01:00
PixelyIon
98c730a644 Implement linked TIC/TSC handle in Maxwell3D
Maxwell3D has a register for linking the TIC/TSC index in bindless texture handles, this is used by games to implement bindless combined texture-sampler handles.
2022-05-06 14:58:20 +05:30
PixelyIon
f9c052d1b7 Implement Maxwell3D Tessellation State
This implements all Maxwell3D registers and HLE Vulkan state for Tessellation including invalidation of the TCS (Tessellation Control Shader) state during state changes.
2022-04-24 13:23:00 +05:30
Billy Laws
32fe01e145 Implement batch constant buffer updates
Avoids spamming the driver with hundreds of cbuf updates per frame by batching all consecutive updates into one.
2022-04-17 00:35:00 +01:00
Billy Laws
feb179fcff Implement primitive restart support
Maxwell3D also supports using an arbitrary restart index value however no games are known to use this so leave it for now.
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
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
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
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
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
40a3887695 Implement Maxwell3D Viewport Y Swizzle & Lower-Left Origin 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
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
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
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
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
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
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
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
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