Commit Graph

635 Commits

Author SHA1 Message Date
IndecisiveTurtle
f3e2d985f7 Review comments and some cleanup 2025-07-15 13:11:06 +03:00
IndecisiveTurtle
3b0d08c730 shader_recompiler: Implement guest barycentrics 2025-07-15 03:22:29 +03:00
TheTurtle
00f4eeddaf
renderer_vulkan: Handle more miscellaneous GPU settings (#3241)
* renderer_vulkan: Respect provoking vertex setting

* renderer_vulkan: Handle rasterization discard

* renderer_vulkan: Implement logic ops

* renderer_vulkan: Properly implement depth clamp and clip

* renderer_vulkan: Handle line width

* Fix build

* vk_pipeline_cache: Don't check depth clamp without a depth buffer

* liverpool: Fix line control offset

* vk_pipeline_cache: Don't run search if depth clamp is disabled

* vk_pipeline_cache: Allow using viewport range when it's more restrictive then depth clamp

* liverpool: Disable depth clip when near and far planes have different setting

* vk_graphics_pipeline: Move warning to pipeline

* vk_pipeline_cache: Revert viewport check and remove log

* vk_graphics_pipeline: Enable depth clamp when depth clip is disabled and extension is not supported

Without the depth clip extension depth clipping is controlled by depth clamping
2025-07-14 21:23:18 +03:00
TheTurtle
399a725343
shader_recompiler: Replace buffer pulling with attribute divisor for instance step rates (#3238)
* shader_recompiler: Replace buffer pulling with attribute divisor for instance step rates

* flatten_extended_userdata: Remove special step rate buffer handling

* Review comments

* spirv_emit_context: Name all instance rate attribs properly

* spirv: Merge ReadConstBuffer again

template function only has 1 user now

* attribute: Add missing attributes

* translate: Reimplement step rate instance id

* Resolve validation warnings

* shader_recompiler: Separate vertex inputs from LS stage, cleanup tess
2025-07-14 00:32:02 +03:00
TheTurtle
b403e1be33
vk_rasterizer: Set render area to max when no framebuffers are bound (#3227) 2025-07-10 22:14:02 +03:00
TheTurtle
27cbd6647f
shader_recompiler: Reorganize data share operations and implement GDS bit (#3222)
* shader_recompiler: Reorganize data share operations and implement GDS bit

* Review comments
2025-07-10 13:38:50 +03:00
TheTurtle
7d4b875ee3
Random fixes (#3216)
* buffer_cache: Handle inline data to flexible memory

* control_flow: Fix single instruction scopes edge case

Fixes the following pattern

v_cmpx_gt_u32 cond
buffer_store_dword value
.LABEL:

Before
buffer[index] = value;

After
if (cond)
{
    buffer[index] = value;
}

* vector_memory: Handle soffset when offen is false

When offen is not used we can substitute the offset argument with soffset and have it handled correctly

* scalar_alu: Handle sharp moves with S_MOV_B64

This fixes unable to track sharp errors when this pattern is used in a shader

* emulator: Add log

* video_core: Bump binary info search range and buffer num
2025-07-09 17:00:06 +03:00
TheTurtle
2d1a2982df
buffer_cache: Bring back upload batching and temporary buffer (#3211)
* buffer_cache: Bring back upload batching and temporary buffer

Because that PR fused the write and read protections under a single function call, it was a requirement to move the actual memory copy part inside the lambda to perform it before the read protection kicks in. However on certain large data transfers it had potential for data corruption. If, for example, an upload had two copies, a 400MB and a 300MB one, the first one would fit in the staging buffer, very likely with an induced stall. However the second one wouldn't have space to fit alongside the other data, but it's also small enough for the buffer to fit it, so the staging buffer would cause a flush and wait to copy it, overwriting the previous transfer.

To address this the upload function has been reworked to allow for batching like previously but with the new locking behavior. Also the condition to use temporary buffers has been expanded to also include cases when staging buffer will stall, which should increase performance a little in some cases.

* buffer_cache: Move buffer barriers and copy outside of lock range
2025-07-08 10:32:39 +03:00
TheTurtle
7fedbd52e0
texture_cache: Async download of GPU modified linear images (#3204)
* texture_cache: Async download of GPU modified linear images

* liverpool: Back to less submits

* texture_cache: Don't download depth images

* config: Add option for linear image readback
2025-07-07 16:23:20 +03:00
squidbus
70eef0de90
texture_cache: Change depth resolve new image back to max of resources. (#3205) 2025-07-07 13:03:19 +03:00
georgemoralis
4f99f304e6
Revert "Avoid clearing depth on partial HTILE writes (#3167)" (#3190)
This reverts commit 59dd73492b.
2025-07-04 09:57:01 +03:00
TheTurtle
b22da77f9a
buffer_cache: Fix various thread races on data upload and invalidation (#3186)
* buffer_cache: Fix various thread races on data upload and invalidation

* memory_tracker: Improve locking more on invalidation

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
2025-07-03 22:36:01 +02:00
TheTurtle
48460d1cbe
vector_alu: Improve handling of mbcnt append/consume patterns (#3184)
* vector_alu: Improve handling of mbcnt append/consume patterns

The existing implementation was written to handle a single pattern of mbcnt before the DS_APPEND instruction

v_mbcnt_hi_u32_b32 vX, exec_hi, 0
v_mbcnt_lo_u32_b32 vX, exec_lo, vX
ds_append       vY offset:4 gds
v_add_i32       vX, vcc, vY, vX

In this case however the DS_APPEND is before the mbcnt pattern

ds_append       vX gds
v_mbcnt_hi_u32_b32 vY, exec_hi, vX
v_mbcnt_lo_u32_b32 vZ, exec_lo, vY

The mbcnt instructions are always in pairs of hi/lo and in general are quite flexible. But they assume the subgroup size is 64 so they are not recompiled literally. Together with DS_APPEND they are used to derive a unique per thread index in a buffer (different from using thread_id as order could be random). DS_APPEND instruction works on per subgroup level, by adding number of active threads of subgroup to the GDS counter, essentially giving a multiple-of-64 base index to all threads. Then each thread executes the mbcnt pair which returns the number of active threads with id less than the itself and adds it with the base.

The recompiler translates DS_APPEND into an atomic increment of a storage buffer counter, which already gives the desired unique index, so this pattern is a no-op. On main it was set to zero as per the first pattern to avoid altering the DS_APPEND result. The new handling passes through the initial value of the pattern instead, which has the same effect but works on either case.

* vk_rasterizer: Always sync DMA buffers
2025-07-03 13:19:38 +03:00
Lander Gallastegi
efa7093f34
Use shared_first_mutex (#3179) 2025-07-02 16:54:14 +03:00
TheTurtle
0594dac405
Readbacks proof of concept rebased (#3178)
* Readbacks proof of concept

* liverpool: Use span for acb too

* config: Add readbacks config option

* config: Log readbacks
2025-07-01 23:41:00 +03:00
Marcin Mikołajczyk
1757dfaf5a
buffer_atomic_imax_x2 (#3130)
* buffer_atomic_imax_x2

* Define Int64Atomics SPIR-V capability
2025-06-29 16:16:47 -07:00
TheTurtle
59dd73492b
Avoid clearing depth on partial HTILE writes (#3167)
* vk_rasterizer: Avoid full depth clear in case of partial HTILE update

* resource_tracking: Mark image as written when its used with atomics
2025-06-29 00:53:14 +03:00
Lander Gallastegi
9f37ede336
video_core: Page manager and memory tracker improvenets (#3155)
* I don't know what to put here

* clang-format

* clang-format 2.0

* Deadlock free locking

* Por boost range lock implementation

* clang-format
2025-06-26 18:38:53 +02:00
TheTurtle
a49b13fe66
shader_recompiler: Optimize general case of buffer addressing (#3159)
* shader_recompiler: Simplify dma types

Only U32 is needed for S_LOAD_DWORD

* shader_recompiler: Perform address shift on IR level

Buffer instructions now expect address in the data unit they work on. Doing the shift on IR level will allow us to optimize some operations away on common case

* shader_recompiler: Optimize common buffer access pattern

* emit_spirv: Use 32-bit integer ops for fault buffer

Not many GPUs have 8-bit bitwise or operations so that would probably require some overhead to emulate from the driver

* resource_tracking_pass: Fix texel buffer shift
2025-06-26 12:14:36 +03:00
Lander Gallastegi
be12305f65
video_core: Page manager/region manager optimization (#3070)
* Bit array test

* Some corrections

* Fix AVX path on SetRange

* Finish bitArray

* Batched protect progress

* Inclusion fix

* Last logic fixes for BitArray

* Page manager: batch protect, masked ranges

* Page manager bitarray

* clang-format

* Fix out of bounds read

* clang

* clang

* Lock during callbacks

* Rename untracked to writeable

* Construct and mask in one step

* Sync on region mutex for thw whole protection

This is a temporary workarround until a fix is found for the page manager having issues when multiple threads update the same page at the same time.

* Bring back the gpu masking until properly handled

* Sync page manager protections

* clang-format

* Rename and fixups

* I fucked up clang-formatting one more time...

* kek
2025-06-20 13:00:23 +03:00
Marcin Mikołajczyk
423254692a
Implement buffer atomic fmin/fmax instructions (#3123) 2025-06-19 17:37:29 -07:00
Marcin Mikołajczyk
612f340292
Log improper image format uses (#3105) 2025-06-19 14:36:50 -07:00
Marcin Mikołajczyk
21d14abaee
Enable sampleRateShading (#3107) 2025-06-16 23:24:38 +03:00
TheTurtle
c27f45c8c0
texture_cache: Implement color to multisampled depth blit pass (#3103) 2025-06-16 14:39:46 +03:00
TheTurtle
34d0d85c15
buffer_cache: Bump device local staging buffer size (#3088) 2025-06-12 13:05:25 +03:00
TheTurtle
dedf6de2ac
texture_cache: Implement color<->depth copies (#3079)
* texture_cache: Implement color to depth copies and vise versa

* ir_passes: Adjust shared memory barrier pass to cover more cases

* texture_cache: Remove unused code

* review comment
2025-06-11 01:34:37 -07:00
TheTurtle
e0c930f2d8
shader_recompiler: Cleanup fragment attribute handling (#3076)
* image: Take minimum of mip levels

Avoids validation error

* texture_cache: Update depth target image

Avoids using undefined depth target in rendering

* shader_recompiler: Cleanup fragment attribute handling
2025-06-10 18:57:16 +03:00
squidbus
e2b726382e
vulkan: Fix two validation errors introduced by shared memory changes. (#3074) 2025-06-09 19:48:20 -07:00
Marcin Mikołajczyk
217d32b502
Handle DS_READ_U16, DS_WRITE_B16, DS_ADD_U64 (#3007)
* Handle DS_READ_U16 & DS_WRITE_B16

* Refactor DS translation

* Translate DS_ADD_U64

* format

* Fix RingAccessElimination after changing WriteShared64 type

* Simplify bounds checking in generated SPIR-V
2025-06-09 22:03:38 +03:00
mailwl
046cf50412
PM4 type 2 in acb (#3047)
* Stub PM4 type 0

* fix command size

* revert command size to actual

* return unreachable for PM4t0

* remove skipping command body
2025-06-09 01:27:37 -07:00
TheTurtle
d7051f15f4
texture_cache: Basic handling of partially resident images (#3066)
* texture_cache: Avoid gpu tracking assert on sparse image

At the moment just take the easy way of creating the entire image normally and uploading unmapped subresources are zero

* tile_manager: Downgrade assert to error

* fix macos
2025-06-09 01:26:10 -07:00
TheTurtle
12f4a8f073
tile_manager: Downgrade assert to error (#3067) 2025-06-09 09:35:43 +03:00
TheTurtle
c20d02dd40
shader_recompiler: Better handling of geometry shader scenario G (#3064) 2025-06-08 17:31:51 -07:00
squidbus
ae2053c487 fix: Disable eBlockTexelViewCompatible on MoltenVK 2025-06-08 15:41:58 -07:00
TheTurtle
14b082f5ea
buffer_cache: Inline data to cpu unless gpu modified (#3061) 2025-06-08 15:28:00 -07:00
TheTurtle
ce42eccc9d
texture_cache: Handle compressed views of uncompressed images (#3056)
* pixel_format: Remove unused tables, refactor

* host_compatibilty: Cleanup and support uncompressed views of compressed formats

* texture_cache: Handle compressed views of uncompressed images

* tile_manager: Bump max supported mips to 16

Fixes a crash during start

* oops

* texture_cache: Fix order of format compat check
2025-06-08 23:09:08 +03:00
TheTurtle
8ffcfc87bd
shader_recompiler: Implement linear interpolation support (#3055) 2025-06-08 22:46:34 +03:00
TheTurtle
a07a6bb9d3
buffer_cache: Better image search for buffer validation (#3057) 2025-06-08 22:14:09 +03:00
TheTurtle
952cef5a15
shader_recompiler: Implement dual source blending (#3054) 2025-06-08 21:38:58 +03:00
Mahmoud Adel
2bc199a41b
black image error fix (#3051) 2025-06-08 11:33:08 -07:00
Marcin Mikołajczyk
91d29459fb
Implement PM4CondExec (#3046) 2025-06-05 20:19:05 -07:00
Marcin Mikołajczyk
d4fbeea085
Stub PM4 COPY_DATA opcode (#3032) 2025-06-04 17:00:11 -07:00
Marcin Mikołajczyk
4019319d92
Provide custom border color to samplers (#3014) 2025-05-30 12:04:31 -07:00
Marcin Mikołajczyk
139a253edc
Stub PM4 0x8E opcode (#2998) 2025-05-27 12:09:03 -07:00
Lander Gallastegi
10d09ac977
Added back the "Attempted to track non-GPU memory" assert. (#2980)
* Fix log message

* Add non-GPU memory assert back
2025-05-24 01:48:40 +03:00
squidbus
e5c6c88835
texture_cache: Handle overlap with equal address and different tiling mode (#2981) 2025-05-23 10:56:46 -07:00
Marcin Mikołajczyk
e518a7062c
Fix image extent in buffer copy to image (#2961) 2025-05-22 12:17:34 -07:00
Lander Gallastegi
f9bbde9c79
video_core: Implement DMA. (#2819)
* Import memory

* 64K pages and fix memory mapping

* Queue coverage

* Buffer syncing, faulted readback adn BDA in Buffer

* Base DMA implementation

* Preparations for implementing SPV DMA access

* Base impl (pending 16K pages and getbuffersize)

* 16K pages and stack overflow fix

* clang-format

* clang-format but for real this time

* Try to fix macOS build

* Correct decltype

* Add testing log

* Fix stride and patch phi node blocks

* No need to check if it is a deleted buffer

* Clang format once more

* Offset in bytes

* Removed host buffers (may do it in another PR)

Also some random barrier fixes

* Add IR dumping from my read-const branch

* clang-format

* Correct size insteed of end

* Fix incorrect assert

* Possible fix for NieR deadlock

* Copy to avoid deadlock

* Use 2 mutexes insteed of copy

* Attempt to range sync error

* Revert "Attempt to range sync error"

This reverts commit dd287b48682b50f215680bb0956e39c2809bf3fe.

* Fix size truncated when syncing range

And memory barrier

* Some fixes (and async testing (doesn't work))

* Use compute to parse fault buffer

* Process faults on submit

* Only sync in the first time we see a readconst

Thsi is partialy wrong. We need to save the state into the submission context itself, not the rasterizer since we can yield and process another sumission (if im not understanding wrong).

* Use spec const and 32 bit atomic

* 32 bit counter

* Fix store_index

* Better sync (WIP, breaks PR now)

* Fixes for better sync

* Better sync

* Remove memory coveragte logic

* Point sirit to upstream

* Less waiting and barriers

* Correctly checkout moltenvk

* Bring back applying pending operations in wait

* Sync the whole buffer insteed of only the range

* Implement recursive shared/scoped locks

* Iterators

* Faster syncing with ranges

* Some alignment fixes

* fixed clang format

* Fix clang-format again

* Port page_manager from readbacks-poc

* clang-format

* Defer memory protect

* Remove RENDERER_TRACE

* Experiment: only sync on first readconst

* Added profiling (will be removed)

* Don't sync entire buffers

* Added logging for testing

* Updated temporary workaround to use 4k pages

* clang.-format

* Cleanup part 1

* Make ReadConst a SPIR-V function

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
2025-05-22 21:00:15 +03:00
squidbus
3f949d2b6c
amdgpu: Handle 32-bit Unorm formats. (#2974) 2025-05-22 03:16:20 -07:00
squidbus
99eaba7c96
liverpool: Lower SetQueueReg to warning log. (#2930) 2025-05-13 16:08:25 -07:00