[PATCH v3 2/8] wined3d: Implement readback from 2D array textures using glGet[Compressed]TexImage().

Józef Kucia jkucia at codeweavers.com
Wed Apr 20 04:42:18 CDT 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
Version 3: Removed read_from_framebuffer() "optimization".
---
 dlls/wined3d/surface.c | 86 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 68 insertions(+), 18 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index fc6c2f7..d6ee678 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -857,14 +857,19 @@ static const struct wined3d_resource_ops surface_resource_ops =
 /* This call just downloads data, the caller is responsible for binding the
  * correct texture. */
 /* Context activation is done by the caller. */
-static void surface_download_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
+static void surface_download_data(struct wined3d_surface *surface, struct wined3d_context *context,
         DWORD dst_location)
 {
+    unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct wined3d_texture *texture = surface->container;
     const struct wined3d_format *format = texture->resource.format;
+    struct wined3d_texture_sub_resource *sub_resource;
     unsigned int dst_row_pitch, dst_slice_pitch;
     unsigned int src_row_pitch, src_slice_pitch;
+    unsigned int sub_resource_size;
     struct wined3d_bo_address data;
+    BYTE *temporary_mem = NULL;
     void *mem;
 
     /* Only support read back of converted P8 surfaces. */
@@ -874,7 +879,31 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
         return;
     }
 
-    wined3d_texture_get_memory(texture, surface_get_sub_resource_idx(surface), &data, dst_location);
+    sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
+    sub_resource_size = sub_resource->resource->size;
+
+    if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
+    {
+        /* We don't expect to ever need to emulate NP2 textures when we have EXT_texture_array. */
+        if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
+        {
+            FIXME("Cannot download surface %p, level %u, layer %u.\n",
+                    surface, surface->texture_level, surface->texture_layer);
+            return;
+        }
+
+        WARN_(d3d_perf)("Downloading all miplevel layers to get the surface data for a single sub-resource.\n");
+
+        if (!(temporary_mem = HeapAlloc(GetProcessHeap(), 0, texture->layer_count * sub_resource_size)))
+        {
+            ERR("Out of memory.\n");
+            return;
+        }
+    }
+
+    wined3d_texture_bind_and_dirtify(texture, context, !(sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB));
+
+    wined3d_texture_get_memory(texture, sub_resource_idx, &data, dst_location);
 
     if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
     {
@@ -883,22 +912,31 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
                 wined3d_texture_get_level_pow2_width(texture, surface->texture_level),
                 wined3d_texture_get_level_pow2_height(texture, surface->texture_level),
                 &src_row_pitch, &src_slice_pitch);
-        mem = HeapAlloc(GetProcessHeap(), 0, src_slice_pitch);
+        if (!(temporary_mem = HeapAlloc(GetProcessHeap(), 0, src_slice_pitch)))
+        {
+            ERR("Out of memory.\n");
+            return;
+        }
 
         if (data.buffer_object)
             ERR("NP2 emulated texture uses PBO unexpectedly.\n");
         if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
             ERR("Unexpected compressed format for NP2 emulated texture.\n");
     }
-    else
+
+    if (temporary_mem)
     {
-        mem = data.addr;
+        mem = temporary_mem;
     }
-
-    if (data.buffer_object)
+    else if (data.buffer_object)
     {
         GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
         checkGLcall("glBindBuffer");
+        mem = data.addr;
+    }
+    else
+    {
+        mem = data.addr;
     }
 
     if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
@@ -919,12 +957,6 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
         checkGLcall("glGetTexImage");
     }
 
-    if (data.buffer_object)
-    {
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
-        checkGLcall("glBindBuffer");
-    }
-
     if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
     {
         const BYTE *src_data;
@@ -985,9 +1017,30 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
             src_data += src_row_pitch;
             dst_data += dst_row_pitch;
         }
+    }
+    else if (temporary_mem)
+    {
+        void *src_data = temporary_mem + surface->texture_layer * sub_resource_size;
+        if (data.buffer_object)
+        {
+            GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
+            checkGLcall("glBindBuffer");
+            GL_EXTCALL(glBufferSubData(GL_PIXEL_PACK_BUFFER, 0, sub_resource_size, src_data));
+            checkGLcall("glBufferSubData");
+        }
+        else
+        {
+            memcpy(data.addr, src_data, sub_resource_size);
+        }
+    }
 
-        HeapFree(GetProcessHeap(), 0, mem);
+    if (data.buffer_object)
+    {
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
+        checkGLcall("glBindBuffer");
     }
+
+    HeapFree(GetProcessHeap(), 0, temporary_mem);
 }
 
 /* This call just uploads data, the caller is responsible for binding the
@@ -2793,7 +2846,6 @@ static void surface_copy_simple_location(struct wined3d_surface *surface, DWORD
 static void surface_load_sysmem(struct wined3d_surface *surface,
         struct wined3d_context *context, DWORD dst_location)
 {
-    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct wined3d_texture_sub_resource *sub_resource;
 
     wined3d_surface_prepare(surface, context, dst_location);
@@ -2813,9 +2865,7 @@ static void surface_load_sysmem(struct wined3d_surface *surface,
     {
         struct wined3d_texture *texture = surface->container;
 
-        wined3d_texture_bind_and_dirtify(texture, context,
-                !(sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB));
-        surface_download_data(surface, gl_info, dst_location);
+        surface_download_data(surface, context, dst_location);
         ++texture->download_count;
 
         return;
-- 
2.4.10




More information about the wine-patches mailing list