Only use persistent buffers to flush on NVIDIA and Windows+AMD (#2489)

It seems like this method of flushing data is much slower on Mesa drivers, and slightly slower on Intel Windows. Have not tested Intel Mesa, but I'm assuming it is the same as AMD.

This also adds vendor detection for AMD on Unix, which counted as "Unknown" before.
This commit is contained in:
riperiperi 2021-07-18 15:45:50 +01:00 committed by GitHub
parent b8ad676fb8
commit 10e17ab423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 14 deletions

View File

@ -20,7 +20,8 @@ namespace Ryujinx.Graphics.OpenGL
public enum GpuVendor public enum GpuVendor
{ {
Unknown, Unknown,
Amd, AmdWindows,
AmdUnix,
IntelWindows, IntelWindows,
IntelUnix, IntelUnix,
Nvidia Nvidia
@ -28,10 +29,15 @@ namespace Ryujinx.Graphics.OpenGL
private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor); private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor);
private static bool _isAMD => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.AmdUnix;
private static bool _isIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix;
public static GpuVendor Vendor => _gpuVendor.Value; public static GpuVendor Vendor => _gpuVendor.Value;
private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy)); private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia;
public static bool SupportsAstcCompression => _supportsAstcCompression.Value; public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
public static bool SupportsImageLoadFormatted => _supportsImageLoadFormatted.Value; public static bool SupportsImageLoadFormatted => _supportsImageLoadFormatted.Value;
public static bool SupportsParallelShaderCompile => _supportsParallelShaderCompile.Value; public static bool SupportsParallelShaderCompile => _supportsParallelShaderCompile.Value;
@ -41,9 +47,9 @@ namespace Ryujinx.Graphics.OpenGL
public static bool SupportsTextureShadowLod => _supportsTextureShadowLod.Value; public static bool SupportsTextureShadowLod => _supportsTextureShadowLod.Value;
public static bool SupportsViewportSwizzle => _supportsViewportSwizzle.Value; public static bool SupportsViewportSwizzle => _supportsViewportSwizzle.Value;
public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.Amd && _gpuVendor.Value != GpuVendor.IntelWindows; public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.AmdWindows && _gpuVendor.Value != GpuVendor.IntelWindows;
public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia; public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.Amd || _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix; public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _isIntel;
public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value; public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value; public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
@ -86,7 +92,11 @@ namespace Ryujinx.Graphics.OpenGL
} }
else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.") else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.")
{ {
return GpuVendor.Amd; return GpuVendor.AmdWindows;
}
else if (vendor == "amd" || vendor == "x.org")
{
return GpuVendor.AmdUnix;
} }
else else
{ {

View File

@ -121,7 +121,31 @@ namespace Ryujinx.Graphics.OpenGL.Image
public byte[] GetData() public byte[] GetData()
{ {
return _renderer.PersistentBuffers.Default.GetTextureData(this); int size = 0;
for (int level = 0; level < Info.Levels; level++)
{
size += Info.GetMipSize(level);
}
if (HwCapabilities.UsePersistentBufferForFlush)
{
return _renderer.PersistentBuffers.Default.GetTextureData(this, size);
}
else
{
byte[] data = new byte[size];
unsafe
{
fixed (byte* ptr = data)
{
WriteTo((IntPtr)ptr);
}
}
return data;
}
} }
public void WriteToPbo(int offset, bool forceBgra) public void WriteToPbo(int offset, bool forceBgra)

View File

@ -63,15 +63,8 @@ namespace Ryujinx.Graphics.OpenGL
GL.DeleteSync(sync); GL.DeleteSync(sync);
} }
public byte[] GetTextureData(TextureView view) public byte[] GetTextureData(TextureView view, int size)
{ {
int size = 0;
for (int level = 0; level < view.Info.Levels; level++)
{
size += view.Info.GetMipSize(level);
}
EnsureBuffer(size); EnsureBuffer(size);
GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyBufferHandle); GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyBufferHandle);

View File

@ -92,9 +92,16 @@ namespace Ryujinx.Graphics.OpenGL
} }
public byte[] GetBufferData(BufferHandle buffer, int offset, int size) public byte[] GetBufferData(BufferHandle buffer, int offset, int size)
{
if (HwCapabilities.UsePersistentBufferForFlush)
{ {
return PersistentBuffers.Default.GetBufferData(buffer, offset, size); return PersistentBuffers.Default.GetBufferData(buffer, offset, size);
} }
else
{
return Buffer.GetData(buffer, offset, size);
}
}
public Capabilities GetCapabilities() public Capabilities GetCapabilities()
{ {