Copy dependency for multisample and non-multisample textures #3382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On the GPU, there are cases where we know that a texture is multisampled, and there are some cases that we don't know, the cases where we don't know, we have an overlap at the same address of a multisample texture, with a width and height that is equal to the multisample width and height multiplied by the amount of samples in X and Y respectively. Since multisample and non-multisample textures are not considered "compatible" in any API, most of those cases are not handled. Currently, there are a few tricks used to make some cases work. 2D engine blit source textures wil get multisample textures from the cache if it can find one at the requested address. Notably, the cases where a texture on the pool accessed from a shader does not have a multisample type on the texture descriptor is not handled right now, which causes problems on a few games using the Vulkan and OpenGL APIs on the Switch.
This change allows non-multisample texture at the same memory region as a multisample one to inherit the multisample texture data, rather than just reading garbage from memory. The main complication doing this is that APIs does not support doing pretty much anything with multisample textures other than rendering or accessing from shaders, so the solution I found here was using blits to "resolve" the multisample texture to a intermmediate texture, then upscale the intermmediate to the final texture. It should be fine if the intention is downscaling it later anyway, even if a bit inefficient. Another possible solution would be doing the copy with a compute shader, using images, but that has other issues too.
This change also allowed the case I added before to allow matching multisample <-> non-multisample textures with different but compatible formats to be removed. Since they are considered copy compatible now, the texture will still correctly inherit the data, but the old approach was slightly more efficient (it creates one view and does one copy, rather than creating a new copy dependant texture and doing one copy (it's actually 2 blits, as explained above) every time it is accessed after modification, plus the actual copy, so I can add it back if desired. I removed it mostly to make the code simpler and since only 1 game seems to trigger this case so far, and it doesn't do it enough for perf to be an issue.
This change fixes black screen on Perky Little Things.
Before:
After:
It also fixes the 3D sections on Genkai Tokki Moero Crystal H.
Before (from gamedb):
After:
It is still not rendering correctly due to another issue that is completely unrelated to this, so I will fix in another PR. But at least this change allows it to render at all.
I recommend testing this on games that uses multisampling, to ensure they did not regress.