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

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


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
Version 2: Rebased.
---
 dlls/wined3d/surface.c | 83 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 20 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 0c8f671..a0d877c 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -972,14 +972,18 @@ error:
 
 /* Context activation is done by the caller. */
 static void surface_download_data(struct wined3d_surface *surface, struct wined3d_context *context,
-        DWORD src_locations, DWORD dst_location)
+        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. */
@@ -989,10 +993,13 @@ static void surface_download_data(struct wined3d_surface *surface, struct wined3
         return;
     }
 
+    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)
     {
         /* Try to avoid using glGetTexImage() for layered textures. */
-        if ((texture->resource.draw_binding & src_locations)
+        if ((texture->resource.draw_binding & sub_resource->locations)
                 && !(texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
                 && !(texture->resource.format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
         {
@@ -1000,14 +1007,26 @@ static void surface_download_data(struct wined3d_surface *surface, struct wined3
             return;
         }
 
-        FIXME("Cannot download surface %p, level %u, layer %u.\n",
-                surface, surface->texture_level, surface->texture_layer);
-        return;
+        /* 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, !(src_locations & WINED3D_LOCATION_TEXTURE_RGB));
+    wined3d_texture_bind_and_dirtify(texture, context, !(sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB));
 
-    wined3d_texture_get_memory(texture, surface_get_sub_resource_idx(surface), &data, dst_location);
+    wined3d_texture_get_memory(texture, sub_resource_idx, &data, dst_location);
 
     if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
     {
@@ -1016,22 +1035,31 @@ static void surface_download_data(struct wined3d_surface *surface, struct wined3
                 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)
@@ -1052,12 +1080,6 @@ static void surface_download_data(struct wined3d_surface *surface, struct wined3
         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;
@@ -1118,9 +1140,30 @@ static void surface_download_data(struct wined3d_surface *surface, struct wined3
             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
@@ -2829,7 +2872,7 @@ static void surface_load_sysmem(struct wined3d_surface *surface,
     {
         struct wined3d_texture *texture = surface->container;
 
-        surface_download_data(surface, context, sub_resource->locations, dst_location);
+        surface_download_data(surface, context, dst_location);
         ++texture->download_count;
 
         return;
-- 
2.4.10




More information about the wine-patches mailing list