[PATCH 5/7] wined3d: Don't enumerate sub-resources in wined3d_device_reset().

Henri Verbeet hverbeet at codeweavers.com
Wed Apr 20 12:29:13 CDT 2016


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/d3d8/device.c             | 54 +++++++++++++++++-------------------------
 dlls/d3d9/device.c             | 54 +++++++++++++++++-------------------------
 dlls/wined3d/context.c         |  8 +++----
 dlls/wined3d/device.c          | 19 ++++++++-------
 dlls/wined3d/resource.c        |  2 +-
 dlls/wined3d/surface.c         |  2 +-
 dlls/wined3d/texture.c         | 15 ++++++++----
 dlls/wined3d/view.c            |  4 ++--
 dlls/wined3d/wined3d.spec      |  1 +
 dlls/wined3d/wined3d_private.h |  4 ++--
 include/wine/wined3d.h         |  1 +
 11 files changed, 77 insertions(+), 87 deletions(-)

diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 154d817..36a2b12 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -613,44 +613,34 @@ static HRESULT WINAPI d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8 *if
 static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
 {
     struct wined3d_resource_desc desc;
+    IDirect3DBaseTexture8 *texture;
+    struct d3d8_surface *surface;
+    IUnknown *parent;
 
     wined3d_resource_get_desc(resource, &desc);
-    if (desc.pool == WINED3D_POOL_DEFAULT)
-    {
-        struct d3d8_surface *surface;
-
-        if (desc.resource_type == WINED3D_RTYPE_TEXTURE_2D)
-        {
-            IUnknown *parent = wined3d_resource_get_parent(resource);
-            IDirect3DBaseTexture8 *texture;
-
-            if (SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture8, (void **)&texture)))
-            {
-                IDirect3DBaseTexture8_Release(texture);
-                WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
-                return D3DERR_DEVICELOST;
-            }
-
-            return D3D_OK;
-        }
-
-        if (desc.resource_type != WINED3D_RTYPE_SURFACE)
-        {
-            WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
-            return D3DERR_DEVICELOST;
-        }
+    if (desc.pool != WINED3D_POOL_DEFAULT)
+        return D3D_OK;
 
-        surface = wined3d_resource_get_parent(resource);
-        if (surface->resource.refcount)
-        {
-            WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
-            return D3DERR_DEVICELOST;
-        }
+    if (desc.resource_type != WINED3D_RTYPE_TEXTURE_2D)
+    {
+        WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
+        return D3DERR_DEVICELOST;
+    }
 
-        WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
+    parent = wined3d_resource_get_parent(resource);
+    if (parent && SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture8, (void **)&texture)))
+    {
+        IDirect3DBaseTexture8_Release(texture);
+        WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
+        return D3DERR_DEVICELOST;
     }
 
-    return D3D_OK;
+    surface = wined3d_texture_get_sub_resource_parent(wined3d_texture_from_resource(resource), 0);
+    if (!surface->resource.refcount)
+        return D3D_OK;
+
+    WARN("Surface %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface);
+    return D3DERR_DEVICELOST;
 }
 
 static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index bd9f935..f6bf664 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -605,44 +605,34 @@ static UINT WINAPI d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
 static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
 {
     struct wined3d_resource_desc desc;
+    IDirect3DBaseTexture9 *texture;
+    struct d3d9_surface *surface;
+    IUnknown *parent;
 
     wined3d_resource_get_desc(resource, &desc);
-    if (desc.pool == WINED3D_POOL_DEFAULT)
-    {
-        struct d3d9_surface *surface;
-
-        if (desc.resource_type == WINED3D_RTYPE_TEXTURE_2D)
-        {
-            IUnknown *parent = wined3d_resource_get_parent(resource);
-            IDirect3DBaseTexture9 *texture;
-
-            if (SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture9, (void **)&texture)))
-            {
-                IDirect3DBaseTexture9_Release(texture);
-                WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
-                return D3DERR_INVALIDCALL;
-            }
-
-            return D3D_OK;
-        }
-
-        if (desc.resource_type != WINED3D_RTYPE_SURFACE)
-        {
-            WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
-            return D3DERR_INVALIDCALL;
-        }
+    if (desc.pool != WINED3D_POOL_DEFAULT)
+        return D3D_OK;
 
-        surface = wined3d_resource_get_parent(resource);
-        if (surface->resource.refcount)
-        {
-            WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
-            return D3DERR_INVALIDCALL;
-        }
+    if (desc.resource_type != WINED3D_RTYPE_TEXTURE_2D)
+    {
+        WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
+        return D3DERR_INVALIDCALL;
+    }
 
-        WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
+    parent = wined3d_resource_get_parent(resource);
+    if (parent && SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture9, (void **)&texture)))
+    {
+        IDirect3DBaseTexture9_Release(texture);
+        WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
+        return D3DERR_INVALIDCALL;
     }
 
-    return D3D_OK;
+    surface = wined3d_texture_get_sub_resource_parent(wined3d_texture_from_resource(resource), 0);
+    if (!surface->resource.refcount)
+        return D3D_OK;
+
+    WARN("Surface %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface);
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT d3d9_device_get_swapchains(struct d3d9_device *device)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 07ddf1c..6cda974 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -353,7 +353,7 @@ static inline DWORD context_generate_rt_mask_from_resource(struct wined3d_resour
         return 0;
     }
 
-    return (1u << 31) | wined3d_texture_get_gl_buffer(wined3d_texture_from_resource(resource));
+    return (1u << 31) | wined3d_texture_get_gl_buffer(texture_from_resource(resource));
 }
 
 static inline void context_set_fbo_key_for_surface(const struct wined3d_context *context,
@@ -884,7 +884,7 @@ void context_resource_released(const struct wined3d_device *device,
     {
         case WINED3D_RTYPE_TEXTURE_2D:
         case WINED3D_RTYPE_TEXTURE_3D:
-            texture = wined3d_texture_from_resource(resource);
+            texture = texture_from_resource(resource);
 
             for (i = 0; i < device->context_count; ++i)
             {
@@ -3265,7 +3265,7 @@ static void context_load_shader_resources(struct wined3d_context *context, const
             if (view->resource->type == WINED3D_RTYPE_BUFFER)
                 buffer_internal_preload(buffer_from_resource(view->resource), context, state);
             else
-                wined3d_texture_load(wined3d_texture_from_resource(view->resource), context, FALSE);
+                wined3d_texture_load(texture_from_resource(view->resource), context, FALSE);
         }
     }
 }
@@ -3337,7 +3337,7 @@ static void context_bind_shader_resources(struct wined3d_context *context, const
                 continue;
             }
 
-            texture = wined3d_texture_from_resource(view->resource);
+            texture = texture_from_resource(view->resource);
             context_active_texture(context, gl_info, shader_types[i].base_idx + entry->bind_idx);
             wined3d_texture_bind(texture, context, FALSE);
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index de8af34..c44e911 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -413,7 +413,7 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c
                 continue;
             }
 
-            texture = wined3d_texture_from_resource(rtv->resource);
+            texture = texture_from_resource(rtv->resource);
             wined3d_texture_validate_location(texture, rtv->sub_resource_idx, rtv->resource->draw_binding);
             wined3d_texture_invalidate_location(texture, rtv->sub_resource_idx, ~rtv->resource->draw_binding);
         }
@@ -2039,7 +2039,7 @@ static void resolve_depth_buffer(struct wined3d_state *state)
 
     SetRect(&dst_rect, 0, 0, dst_texture->resource.width, dst_texture->resource.height);
     SetRect(&src_rect, 0, 0, src_view->width, src_view->height);
-    wined3d_texture_blt(dst_texture, 0, &dst_rect, wined3d_texture_from_resource(src_view->resource),
+    wined3d_texture_blt(dst_texture, 0, &dst_rect, texture_from_resource(src_view->resource),
             src_view->sub_resource_idx, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
 }
 
@@ -3913,8 +3913,8 @@ void CDECL wined3d_device_copy_resource(struct wined3d_device *device,
         return;
     }
 
-    dst_texture = wined3d_texture_from_resource(dst_resource);
-    src_texture = wined3d_texture_from_resource(src_resource);
+    dst_texture = texture_from_resource(dst_resource);
+    src_texture = texture_from_resource(src_resource);
 
     if (src_texture->layer_count != dst_texture->layer_count
             || src_texture->level_count != dst_texture->level_count)
@@ -4034,8 +4034,8 @@ HRESULT CDECL wined3d_device_copy_sub_resource_region(struct wined3d_device *dev
         return WINED3DERR_INVALIDCALL;
     }
 
-    dst_texture = wined3d_texture_from_resource(dst_resource);
-    src_texture = wined3d_texture_from_resource(src_resource);
+    dst_texture = texture_from_resource(dst_resource);
+    src_texture = texture_from_resource(src_resource);
 
     if (src_box)
     {
@@ -4099,7 +4099,7 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
         return;
     }
 
-    texture = wined3d_texture_from_resource(resource);
+    texture = texture_from_resource(resource);
     if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
     {
         WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
@@ -4695,6 +4695,9 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
     {
         LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
         {
+            if (resource->type == WINED3D_RTYPE_SURFACE || resource->type == WINED3D_RTYPE_VOLUME)
+                continue;
+
             TRACE("Enumerating resource %p.\n", resource);
             if (FAILED(hr = callback(resource)))
                 return hr;
@@ -5037,7 +5040,7 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso
         case WINED3D_RTYPE_TEXTURE_3D:
             for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
             {
-                struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
+                struct wined3d_texture *texture = texture_from_resource(resource);
 
                 if (device->state.textures[i] == texture)
                 {
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 423d162..be7dfb4 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -414,7 +414,7 @@ BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
         return TRUE;
 
     /* Not on a swapchain - must be offscreen */
-    if (!(swapchain = wined3d_texture_from_resource(resource)->swapchain))
+    if (!(swapchain = texture_from_resource(resource)->swapchain))
         return TRUE;
 
     /* The front buffer is always onscreen */
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 44d442b..493c835 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3945,7 +3945,7 @@ static HRESULT cpu_blit_color_fill(struct wined3d_device *device, struct wined3d
     struct wined3d_blt_fx fx;
 
     fx.fill_color = wined3d_format_convert_from_float(view->format, color);
-    return surface_cpu_blt(wined3d_texture_from_resource(view->resource), view->sub_resource_idx,
+    return surface_cpu_blt(texture_from_resource(view->resource), view->sub_resource_idx,
             &box, NULL, 0, &src_box, WINED3D_BLT_COLOR_FILL, &fx, WINED3D_TEXF_POINT);
 }
 
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 2d92c83..6bf83b9 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1447,19 +1447,24 @@ static const struct wined3d_texture_ops texture2d_ops =
     texture2d_cleanup_sub_resources,
 };
 
+struct wined3d_texture *wined3d_texture_from_resource(struct wined3d_resource *resource)
+{
+    return texture_from_resource(resource);
+}
+
 static ULONG texture_resource_incref(struct wined3d_resource *resource)
 {
-    return wined3d_texture_incref(wined3d_texture_from_resource(resource));
+    return wined3d_texture_incref(texture_from_resource(resource));
 }
 
 static ULONG texture_resource_decref(struct wined3d_resource *resource)
 {
-    return wined3d_texture_decref(wined3d_texture_from_resource(resource));
+    return wined3d_texture_decref(texture_from_resource(resource));
 }
 
 static void wined3d_texture_unload(struct wined3d_resource *resource)
 {
-    struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
+    struct wined3d_texture *texture = texture_from_resource(resource);
     UINT sub_count = texture->level_count * texture->layer_count;
     struct wined3d_device *device = resource->device;
     const struct wined3d_gl_info *gl_info;
@@ -1537,7 +1542,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
     TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
             resource, sub_resource_idx, map_desc, debug_box(box), flags);
 
-    texture = wined3d_texture_from_resource(resource);
+    texture = texture_from_resource(resource);
     if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
         return E_INVALIDARG;
 
@@ -1684,7 +1689,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
 
     TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
 
-    texture = wined3d_texture_from_resource(resource);
+    texture = texture_from_resource(resource);
     if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
         return E_INVALIDARG;
 
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index 29b370f..4417293 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -67,7 +67,7 @@ void * CDECL wined3d_rendertarget_view_get_sub_resource_parent(const struct wine
     if (view->resource->type == WINED3D_RTYPE_BUFFER)
         return wined3d_buffer_get_parent(buffer_from_resource(view->resource));
 
-    texture = wined3d_texture_from_resource(view->resource);
+    texture = texture_from_resource(view->resource);
 
     return wined3d_resource_get_parent(texture->sub_resources[view->sub_resource_idx].resource);
 }
@@ -108,7 +108,7 @@ static HRESULT wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *
     }
     else
     {
-        struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
+        struct wined3d_texture *texture = texture_from_resource(resource);
 
         if (desc->u.texture.level_idx >= texture->level_count
                 || desc->u.texture.layer_idx >= texture->layer_count
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 9b6bed9..e219611 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -243,6 +243,7 @@
 @ cdecl wined3d_texture_blt(ptr long ptr ptr long ptr long ptr long)
 @ cdecl wined3d_texture_create(ptr ptr long long ptr ptr ptr ptr)
 @ cdecl wined3d_texture_decref(ptr)
+@ cdecl wined3d_texture_from_resource(ptr)
 @ cdecl wined3d_texture_generate_mipmaps(ptr)
 @ cdecl wined3d_texture_get_autogen_filter_type(ptr)
 @ cdecl wined3d_texture_get_dc(ptr long ptr)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 2118a14..351584e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2514,7 +2514,7 @@ struct wined3d_texture
     } sub_resources[1];
 };
 
-static inline struct wined3d_texture *wined3d_texture_from_resource(struct wined3d_resource *resource)
+static inline struct wined3d_texture *texture_from_resource(struct wined3d_resource *resource)
 {
     return CONTAINING_RECORD(resource, struct wined3d_texture, resource);
 }
@@ -3027,7 +3027,7 @@ static inline struct wined3d_surface *wined3d_rendertarget_view_get_surface(
     if (!view || view->resource->type != WINED3D_RTYPE_TEXTURE_2D)
         return NULL;
 
-    texture = wined3d_texture_from_resource(view->resource);
+    texture = texture_from_resource(view->resource);
 
     return texture->sub_resources[view->sub_resource_idx].u.surface;
 }
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index cf2715c..e9c8cb9 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2450,6 +2450,7 @@ HRESULT __cdecl wined3d_texture_blt(struct wined3d_texture *dst_texture, unsigne
 HRESULT __cdecl wined3d_texture_create(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
         UINT level_count, DWORD flags, const struct wined3d_sub_resource_data *data, void *parent,
         const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
+struct wined3d_texture * __cdecl wined3d_texture_from_resource(struct wined3d_resource *resource);
 ULONG __cdecl wined3d_texture_decref(struct wined3d_texture *texture);
 void __cdecl wined3d_texture_generate_mipmaps(struct wined3d_texture *texture);
 enum wined3d_texture_filter_type __cdecl wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture);
-- 
2.1.4




More information about the wine-patches mailing list