From 10e17ab423ba84856eb7411ce04d38989ac70a58 Mon Sep 17 00:00:00 2001
From: riperiperi <rhy3756547@hotmail.com>
Date: Sun, 18 Jul 2021 15:45:50 +0100
Subject: 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.
---
 Ryujinx.Graphics.OpenGL/Image/TextureView.cs | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

(limited to 'Ryujinx.Graphics.OpenGL/Image/TextureView.cs')

diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
index 770e99a0..5e7b5f22 100644
--- a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
@@ -121,7 +121,31 @@ namespace Ryujinx.Graphics.OpenGL.Image
 
         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)
-- 
cgit v1.2.3-70-g09d2