Henri Verbeet : wined3d: Unbind stateblock resources in wined3d_device_uninit_3d().

Alexandre Julliard julliard at winehq.org
Wed Dec 7 13:57:12 CST 2011


Module: wine
Branch: master
Commit: 3f455832a338cde9190af9d2c0228aeca09a44d3
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3f455832a338cde9190af9d2c0228aeca09a44d3

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Tue Dec  6 22:57:44 2011 +0100

wined3d: Unbind stateblock resources in wined3d_device_uninit_3d().

---

 dlls/wined3d/device.c          |   14 ++----
 dlls/wined3d/stateblock.c      |   89 +++++++++++++++++++++++----------------
 dlls/wined3d/wined3d_private.h |    1 +
 3 files changed, 57 insertions(+), 47 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 068fb7f..8bdec45 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1427,6 +1427,8 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
     if (device->logo_surface)
         wined3d_surface_decref(device->logo_surface);
 
+    stateblock_unbind_resources(device->stateBlock);
+
     /* Unload resources */
     LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
     {
@@ -5412,20 +5414,12 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
     struct wined3d_display_mode mode;
     BOOL DisplayModeChanged = FALSE;
     BOOL update_desc = FALSE;
-    unsigned int i;
     HRESULT hr;
 
     TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
 
-    wined3d_device_set_index_buffer(device, NULL, WINED3DFMT_UNKNOWN);
-    for (i = 0; i < MAX_STREAMS; ++i)
-    {
-        wined3d_device_set_stream_source(device, i, NULL, 0, 0);
-    }
-    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
-    {
-        wined3d_device_set_texture(device, i, NULL);
-    }
+    stateblock_unbind_resources(device->stateBlock);
+
     if (device->onscreen_depth_stencil)
     {
         wined3d_surface_decref(device->onscreen_depth_stencil);
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index cf83e94..401aa69 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -466,54 +466,69 @@ ULONG CDECL wined3d_stateblock_incref(struct wined3d_stateblock *stateblock)
     return refcount;
 }
 
-ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
+void stateblock_unbind_resources(struct wined3d_stateblock *stateblock)
 {
-    ULONG refcount = InterlockedDecrement(&stateblock->ref);
-
-    TRACE("%p decreasing refcount to %u\n", stateblock, refcount);
+    struct wined3d_state *state = &stateblock->state;
+    struct wined3d_vertex_declaration *decl;
+    struct wined3d_texture *texture;
+    struct wined3d_buffer *buffer;
+    struct wined3d_shader *shader;
+    unsigned int i;
 
-    if (!refcount)
+    if ((decl = state->vertex_declaration))
     {
-        struct wined3d_buffer *buffer;
-        int counter;
-
-        if (stateblock->state.vertex_declaration)
-            wined3d_vertex_declaration_decref(stateblock->state.vertex_declaration);
-
-        for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++)
-        {
-            struct wined3d_texture *texture = stateblock->state.textures[counter];
-            if (texture)
-            {
-                stateblock->state.textures[counter] = NULL;
-                wined3d_texture_decref(texture);
-            }
-        }
+        state->vertex_declaration = NULL;
+        wined3d_vertex_declaration_decref(decl);
+    }
 
-        for (counter = 0; counter < MAX_STREAMS; ++counter)
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
+    {
+        if ((texture = state->textures[i]))
         {
-            buffer = stateblock->state.streams[counter].buffer;
-            if (buffer)
-            {
-                stateblock->state.streams[counter].buffer = NULL;
-                if (wined3d_buffer_decref(buffer))
-                {
-                    WARN("Buffer %p still referenced by stateblock, stream %u.\n", buffer, counter);
-                }
-            }
+            state->textures[i] = NULL;
+            wined3d_texture_decref(texture);
         }
+    }
 
-        buffer = stateblock->state.index_buffer;
-        if (buffer)
+    for (i = 0; i < MAX_STREAMS; ++i)
+    {
+        if ((buffer = state->streams[i].buffer))
         {
-            stateblock->state.index_buffer = NULL;
+            state->streams[i].buffer = NULL;
             wined3d_buffer_decref(buffer);
         }
+    }
 
-        if (stateblock->state.vertex_shader)
-            wined3d_shader_decref(stateblock->state.vertex_shader);
-        if (stateblock->state.pixel_shader)
-            wined3d_shader_decref(stateblock->state.pixel_shader);
+    if ((buffer = state->index_buffer))
+    {
+        state->index_buffer = NULL;
+        wined3d_buffer_decref(buffer);
+    }
+
+    if ((shader = state->vertex_shader))
+    {
+        state->vertex_shader = NULL;
+        wined3d_shader_decref(shader);
+    }
+
+    if ((shader = state->pixel_shader))
+    {
+        state->pixel_shader = NULL;
+        wined3d_shader_decref(shader);
+    }
+}
+
+ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
+{
+    ULONG refcount = InterlockedDecrement(&stateblock->ref);
+
+    TRACE("%p decreasing refcount to %u\n", stateblock, refcount);
+
+    if (!refcount)
+    {
+        int counter;
+
+        stateblock_unbind_resources(stateblock);
 
         for (counter = 0; counter < LIGHTMAP_SIZE; ++counter)
         {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 31ea597..fece53a 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2331,6 +2331,7 @@ struct wined3d_stateblock
 
 void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
 void stateblock_init_default_state(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
+void stateblock_unbind_resources(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
 
 /* Direct3D terminology with little modifications. We do not have an issued state
  * because only the driver knows about it, but we have a created state because d3d




More information about the wine-cvs mailing list