Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DMA linear texture copy fast path #3496

Merged
merged 2 commits into from
Jul 28, 2022
Merged

Conversation

gdkchan
Copy link
Member

@gdkchan gdkchan commented Jul 28, 2022

FindTexture tries to find an existing texture that matches the copy parameters, if found we try to write the data into the texture directly which is more efficient. However, FindTexture was also matching textures that have a height higher than the copy height. This causes problems because linear strided -> linear conversion expects data to be at least as large as the texture itself, and in this case it won't be causing an exception.

The fix here is making FindTexture only match linear textures with exactly the copy height. In addition to that, I removed the RegionY parameter because it is not used for linear copies, only block linear ones (that's an incorrect assumption that was made in the past and corrected, but I missed that code). Since after this only two fields from DmaTexture were accessed, I decided to stop passing the whole struct and just pass those 2 parameters to the function, which is more efficient.

Fixes crash in SD Gundam Battle Alliance Demo with the following exception:

Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Ryujinx.Graphics.Texture.LayoutConverter.ConvertLinearStridedToLinear(Int32 width, Int32 height, Int32 blockWidth, Int32 blockHeight, Int32 lineSize, Int32 stride, Int32 bytesPerPixel, ReadOnlySpan`1 data) in F:\Ryujinx\Ryujinx.Graphics.Texture\LayoutConverter.cs:line 272
   at Ryujinx.Graphics.Gpu.Engine.Dma.DmaClass.DmaCopy(Int32 argument) in F:\Ryujinx\Ryujinx.Graphics.Gpu\Engine\Dma\DmaClass.cs:line 331
   at Ryujinx.Graphics.Gpu.Engine.Dma.DmaClass.LaunchDma(Int32 argument) in F:\Ryujinx\Ryujinx.Graphics.Gpu\Engine\Dma\DmaClass.cs:line 450
   at Ryujinx.Graphics.Gpu.Engine.GPFifo.GPFifoProcessor.Send(UInt64 gpuVa, Int32 offset, Int32 argument, Int32 subChannel, Boolean isLastCall) in F:\Ryujinx\Ryujinx.Graphics.Gpu\Engine\GPFifo\GPFifoProcessor.cs:line 213
   at Ryujinx.Graphics.Gpu.Engine.GPFifo.GPFifoProcessor.Process(UInt64 baseGpuVa, ReadOnlySpan`1 commandBuffer) in F:\Ryujinx\Ryujinx.Graphics.Gpu\Engine\GPFifo\GPFifoProcessor.cs:line 95
   at Ryujinx.Graphics.Gpu.Engine.GPFifo.GPFifoDevice.DispatchCalls() in F:\Ryujinx\Ryujinx.Graphics.Gpu\Engine\GPFifo\GPFifoDevice.cs:line 188
   at Ryujinx.Ui.RendererWidgetBase.<Render>b__71_0() in F:\Ryujinx\Ryujinx\Ui\RendererWidgetBase.cs:line 394
   at Ryujinx.Graphics.GAL.Multithreading.ThreadedRenderer.<>c__DisplayClass48_0.<RunLoop>b__0() in F:\Ryujinx\Ryujinx.Graphics.GAL\Multithreading\ThreadedRenderer.cs:line 100
   at System.Threading.Thread.StartCallback()

For the record, at that time it was trying to write 256x25 data into a 64x29 RGBA8Srgb texture. With this fix, it tries to write it into a 64x25 texture.

image

@gdkchan gdkchan added gpu Related to Ryujinx.Graphics fix Fix something labels Jul 28, 2022
@marysaka marysaka requested a review from riperiperi July 28, 2022 06:36
Copy link
Contributor

@marysaka marysaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Ryujinx.Graphics.Gpu/Engine/Dma/DmaClass.cs Outdated Show resolved Hide resolved
@gdkchan gdkchan merged commit 37b6e08 into Ryujinx:master Jul 28, 2022
@gdkchan gdkchan deleted the fix-dma-linear branch July 28, 2022 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something gpu Related to Ryujinx.Graphics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants