Ryujinx/Ryujinx.Graphics.Texture
riperiperi bf77d1cab9
GPU: Pass SpanOrArray for Texture SetData to avoid copy (#3745)
* GPU: Pass SpanOrArray for Texture SetData to avoid copy

Texture data is often converted before upload, meaning that an array was allocated to perform the conversion into. However, the backend SetData methods were being passed a Span of that data, and the Multithreaded layer does `ToArray()` on it so that it can be stored for later! This method can't extract the original array, so it creates a copy.

This PR changes the type passed for textures to a new ref struct called SpanOrArray, which is backed by either a ReadOnlySpan or an array. The benefit here is that we can have a ToArray method that doesn't copy if it is originally backed by an array.

This will also avoid a copy when running the ASTC decoder.

On NieR this was taking 38% of texture upload time, which it does a _lot_ of when you move between areas, so there should be a 1.6x performance boost when strictly uploading textures. No doubt this will also improve texture streaming performance in UE4 games, and maybe a small reduction with video playback.

From the numbers, it's probably possible to improve the upload rate by a further 1.6x by performing layout conversion on GPU. I'm not sure if we could improve it further than that - multithreading conversion on CPU would probably result in memory bottleneck.

This doesn't extend to buffers, since we don't convert their data on the GPU emulator side.

* Remove implicit cast to array.
2022-10-08 12:04:47 -03:00
..
Astc Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
Encoders Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
Utils Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
BC6Decoder.cs Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
BC7Decoder.cs Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
BCnDecoder.cs Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
BCnEncoder.cs Vulkan backend (#2518) 2022-07-31 18:26:06 -03:00
BlockLinearConstants.cs Initial work 2020-01-09 02:13:00 +01:00
BlockLinearLayout.cs Use BitOperations methods and delete now unused BitUtils methods (#3134) 2022-02-18 02:35:23 +01:00
Bpp12Pixel.cs Optimize texture format conversion, and MethodCopyBuffer (#1274) 2020-06-13 19:31:06 -03:00
LayoutConverter.cs GPU: Pass SpanOrArray for Texture SetData to avoid copy (#3745) 2022-10-08 12:04:47 -03:00
OffsetCalculator.cs Account for negative strides on DMA copy (#2623) 2021-09-11 22:54:18 +02:00
PixelConverter.cs Add support for the R4G4 texture format (#2956) 2021-12-30 17:10:54 +01:00
Region.cs Avoid deleting textures when their data does not overlap. (#2601) 2021-08-29 16:22:13 -03:00
Ryujinx.Graphics.Texture.csproj infra: Migrate to .NET 6 (#2829) 2021-11-28 21:24:17 +01:00
Size.cs Removed unused usings. (#3593) 2022-08-18 18:04:54 +02:00
SizeCalculator.cs Texture Sync, incompatible overlap handling, data flush improvements. (#2971) 2022-01-09 13:28:48 -03:00
SizeInfo.cs Texture Sync, incompatible overlap handling, data flush improvements. (#2971) 2022-01-09 13:28:48 -03:00