[PATCH 1/6] wined3d: Return a wined3d_stateblock from wined3d_device_begin_stateblock().

Zebediah Figura z.figura12 at gmail.com
Mon Sep 23 20:38:04 CDT 2019


And hold it locally in d3d[789].

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/d3d8/d3d8_private.h   |  5 +++--
 dlls/d3d8/device.c         | 17 ++++++++++++-----
 dlls/d3d9/d3d9_private.h   |  5 +++--
 dlls/d3d9/device.c         | 24 ++++++++++++++++--------
 dlls/ddraw/ddraw_private.h |  2 +-
 dlls/ddraw/device.c        | 13 +++++++++----
 dlls/ddraw/surface.c       |  7 +++++++
 dlls/wined3d/device.c      | 30 ++++++++++++++++--------------
 dlls/wined3d/wined3d.spec  |  4 ++--
 include/wine/wined3d.h     |  4 ++--
 10 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 1669ff74315..0d4d4faf898 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -126,12 +126,13 @@ struct d3d8_device
     DWORD sysmem_vb : 16; /* D3D8_MAX_STREAMS */
     DWORD sysmem_ib : 1;
     DWORD in_destruction : 1;
-    DWORD recording : 1;
-    DWORD padding : 13;
+    DWORD padding : 14;
 
     /* The d3d8 API supports only one implicit swapchain (no D3DCREATE_ADAPTERGROUP_DEVICE,
      * no GetSwapchain, GetBackBuffer doesn't accept a swapchain number). */
     struct wined3d_swapchain *implicit_swapchain;
+
+    struct wined3d_stateblock *recording;
 };
 
 HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index b5436241a9e..741218c9515 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -593,6 +593,9 @@ static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
         if (device->index_buffer)
             wined3d_buffer_decref(device->index_buffer);
 
+        if (device->recording)
+            wined3d_stateblock_decref(device->recording);
+
         wined3d_swapchain_decref(device->implicit_swapchain);
         wined3d_device_release_focus_window(device->wined3d_device);
         wined3d_device_decref(device->wined3d_device);
@@ -908,7 +911,9 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
     if (SUCCEEDED(hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
             NULL, reset_enum_callback, TRUE)))
     {
-        device->recording = FALSE;
+        if (device->recording)
+            wined3d_stateblock_decref(device->recording);
+        device->recording = NULL;
         present_parameters->BackBufferCount = swapchain_desc.backbuffer_count;
         implicit_swapchain = wined3d_swapchain_get_parent(device->implicit_swapchain);
         implicit_swapchain->swap_interval
@@ -1859,13 +1864,14 @@ static HRESULT WINAPI d3d8_device_GetRenderState(IDirect3DDevice8 *iface,
 static HRESULT WINAPI d3d8_device_BeginStateBlock(IDirect3DDevice8 *iface)
 {
     struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
+    struct wined3d_stateblock *stateblock;
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
-        device->recording = TRUE;
+    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device, &stateblock)))
+        device->recording = stateblock;
     wined3d_mutex_unlock();
 
     return hr;
@@ -1883,14 +1889,15 @@ static HRESULT WINAPI d3d8_device_EndStateBlock(IDirect3DDevice8 *iface, DWORD *
      * of memory later and cause locking problems)
      */
     wined3d_mutex_lock();
-    hr = wined3d_device_end_stateblock(device->wined3d_device, &stateblock);
+    hr = wined3d_device_end_stateblock(device->wined3d_device);
     if (FAILED(hr))
     {
         WARN("Failed to end the state block, %#x.\n", hr);
         wined3d_mutex_unlock();
         return hr;
     }
-    device->recording = FALSE;
+    stateblock = device->recording;
+    device->recording = NULL;
 
     *token = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
     wined3d_mutex_unlock();
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index a56bdb270b2..7c3d77c8a25 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -107,8 +107,7 @@ struct d3d9_device
     DWORD in_destruction : 1;
     DWORD in_scene : 1;
     DWORD has_vertex_declaration : 1;
-    DWORD recording : 1;
-    DWORD padding : 11;
+    DWORD padding : 12;
 
     DWORD auto_mipmaps; /* D3D9_MAX_TEXTURE_UNITS */
 
@@ -116,6 +115,8 @@ struct d3d9_device
 
     UINT implicit_swapchain_count;
     struct wined3d_swapchain **implicit_swapchains;
+
+    struct wined3d_stateblock *recording;
 };
 
 HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d,
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index dc3363bab8c..953bf4c5419 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -603,6 +603,9 @@ static ULONG WINAPI DECLSPEC_HOTPATCH d3d9_device_Release(IDirect3DDevice9Ex *if
         }
         heap_free(device->implicit_swapchains);
 
+        if (device->recording)
+            wined3d_stateblock_decref(device->recording);
+
         wined3d_device_release_focus_window(device->wined3d_device);
         wined3d_device_decref(device->wined3d_device);
         wined3d_mutex_unlock();
@@ -993,7 +996,9 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
 
         if (!extended)
         {
-            device->recording = FALSE;
+            if (device->recording)
+                wined3d_stateblock_decref(device->recording);
+            device->recording = NULL;
             device->auto_mipmaps = 0;
             wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE,
                     !!swapchain_desc.enable_auto_depth_stencil);
@@ -2348,13 +2353,14 @@ static HRESULT WINAPI d3d9_device_CreateStateBlock(IDirect3DDevice9Ex *iface,
 static HRESULT WINAPI d3d9_device_BeginStateBlock(IDirect3DDevice9Ex *iface)
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
+    struct wined3d_stateblock *stateblock;
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
-        device->recording = TRUE;
+    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device, &stateblock)))
+        device->recording = stateblock;
     wined3d_mutex_unlock();
 
     return hr;
@@ -2370,14 +2376,16 @@ static HRESULT WINAPI d3d9_device_EndStateBlock(IDirect3DDevice9Ex *iface, IDire
     TRACE("iface %p, stateblock %p.\n", iface, stateblock);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_end_stateblock(device->wined3d_device, &wined3d_stateblock);
-    wined3d_mutex_unlock();
+    hr = wined3d_device_end_stateblock(device->wined3d_device);
     if (FAILED(hr))
     {
-       WARN("Failed to end the state block, hr %#x.\n", hr);
-       return hr;
+        wined3d_mutex_unlock();
+        WARN("Failed to end the stateblock, hr %#x.\n", hr);
+        return hr;
     }
-    device->recording = FALSE;
+    wined3d_stateblock = device->recording;
+    device->recording = NULL;
+    wined3d_mutex_unlock();
 
     if (!(object = heap_alloc_zero(sizeof(*object))))
     {
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 11861f2a129..771b2a44d17 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -351,7 +351,7 @@ struct d3d_device
 
     struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES];
 
-    BOOL recording;
+    struct wined3d_stateblock *recording;
 };
 
 HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface,
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 690332dbdca..43e5d0aa920 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -245,6 +245,9 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
 
         wined3d_device_set_rendertarget_view(This->wined3d_device, 0, NULL, FALSE);
 
+        if (This->recording)
+            wined3d_stateblock_decref(This->recording);
+
         /* Release the wined3d device. This won't destroy it. */
         if (!wined3d_device_decref(This->wined3d_device))
             ERR("The wined3d device (%p) was destroyed unexpectedly.\n", This->wined3d_device);
@@ -5604,6 +5607,7 @@ static HRESULT WINAPI d3d_device7_GetLight_FPUPreserve(IDirect3DDevice7 *iface,
 static HRESULT d3d_device7_BeginStateBlock(IDirect3DDevice7 *iface)
 {
     struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
+    struct wined3d_stateblock *stateblock;
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
@@ -5615,8 +5619,8 @@ static HRESULT d3d_device7_BeginStateBlock(IDirect3DDevice7 *iface)
         WARN("Trying to begin a stateblock while recording, returning D3DERR_INBEGINSTATEBLOCK.\n");
         return D3DERR_INBEGINSTATEBLOCK;
     }
-    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
-        device->recording = TRUE;
+    if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device, &stateblock)))
+        device->recording = stateblock;
     wined3d_mutex_unlock();
 
     return hr_ddraw_from_wined3d(hr);
@@ -5674,7 +5678,7 @@ static HRESULT d3d_device7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *statebl
         WARN("Trying to end a stateblock, but no stateblock is being recorded.\n");
         return D3DERR_NOTINBEGINSTATEBLOCK;
     }
-    hr = wined3d_device_end_stateblock(device->wined3d_device, &wined3d_sb);
+    hr = wined3d_device_end_stateblock(device->wined3d_device);
     if (FAILED(hr))
     {
         WARN("Failed to end stateblock, hr %#x.\n", hr);
@@ -5682,7 +5686,8 @@ static HRESULT d3d_device7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *statebl
         *stateblock = 0;
         return hr_ddraw_from_wined3d(hr);
     }
-    device->recording = FALSE;
+    wined3d_sb = device->recording;
+    device->recording = NULL;
 
     h = ddraw_allocate_handle(&device->handle_table, wined3d_sb, DDRAW_HANDLE_STATEBLOCK);
     if (h == DDRAW_INVALID_HANDLE)
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 59af556560b..6c27d8c26c6 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -6076,6 +6076,13 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
                 return hr_ddraw_from_wined3d(hr);
             }
 
+            if (ddraw->d3ddevice)
+            {
+                if (ddraw->d3ddevice->recording)
+                    wined3d_stateblock_decref(ddraw->d3ddevice->recording);
+                ddraw->d3ddevice->recording = NULL;
+            }
+
             wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_ZENABLE,
                     !!swapchain_desc.enable_auto_depth_stencil);
         }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 62341290ffa..eecd05ae0c6 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4070,49 +4070,51 @@ HRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *devic
     return wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
 }
 
-HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device)
+HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device,
+        struct wined3d_stateblock **stateblock)
 {
-    struct wined3d_stateblock *stateblock;
+    struct wined3d_stateblock *object;
     HRESULT hr;
 
     TRACE("device %p.\n", device);
 
     if (device->recording)
+    {
+        *stateblock = NULL;
         return WINED3DERR_INVALIDCALL;
+    }
 
-    hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock);
+    hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &object);
     if (FAILED(hr))
         return hr;
 
-    device->recording = stateblock;
-    device->update_stateblock_state = &stateblock->stateblock_state;
+    device->recording = object;
+    device->update_stateblock_state = &object->stateblock_state;
+    *stateblock = object;
 
-    TRACE("Recording stateblock %p.\n", stateblock);
+    TRACE("Recording stateblock %p.\n", *stateblock);
 
     return WINED3D_OK;
 }
 
-HRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device,
-        struct wined3d_stateblock **stateblock)
+HRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device)
 {
-    struct wined3d_stateblock *object = device->recording;
+    struct wined3d_stateblock *stateblock = device->recording;
 
-    TRACE("device %p, stateblock %p.\n", device, stateblock);
+    TRACE("device %p.\n", device);
 
     if (!device->recording)
     {
         WARN("Not recording.\n");
-        *stateblock = NULL;
         return WINED3DERR_INVALIDCALL;
     }
 
-    stateblock_init_contained_states(object);
+    stateblock_init_contained_states(stateblock);
 
-    *stateblock = object;
     device->recording = NULL;
     device->update_stateblock_state = &device->stateblock_state;
 
-    TRACE("Returning stateblock %p.\n", *stateblock);
+    TRACE("Ending stateblock %p.\n", stateblock);
 
     return WINED3D_OK;
 }
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index edd4a70d979..947bff7cb0d 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -37,7 +37,7 @@
 
 @ cdecl wined3d_device_acquire_focus_window(ptr ptr)
 @ cdecl wined3d_device_begin_scene(ptr)
-@ cdecl wined3d_device_begin_stateblock(ptr)
+@ cdecl wined3d_device_begin_stateblock(ptr ptr)
 @ cdecl wined3d_device_clear(ptr long ptr long ptr float long)
 @ cdecl wined3d_device_clear_rendertarget_view(ptr ptr ptr long ptr float long)
 @ cdecl wined3d_device_clear_unordered_access_view_uint(ptr ptr ptr)
@@ -55,7 +55,7 @@
 @ cdecl wined3d_device_draw_primitive_instanced(ptr long long long long)
 @ cdecl wined3d_device_draw_primitive_instanced_indirect(ptr ptr long)
 @ cdecl wined3d_device_end_scene(ptr)
-@ cdecl wined3d_device_end_stateblock(ptr ptr)
+@ cdecl wined3d_device_end_stateblock(ptr)
 @ cdecl wined3d_device_evict_managed_resources(ptr)
 @ cdecl wined3d_device_get_available_texture_mem(ptr)
 @ cdecl wined3d_device_get_base_vertex_index(ptr)
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 3e46c23c145..ee28ab1bb94 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2228,7 +2228,7 @@ ULONG __cdecl wined3d_buffer_incref(struct wined3d_buffer *buffer);
 
 HRESULT __cdecl wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window);
 HRESULT __cdecl wined3d_device_begin_scene(struct wined3d_device *device);
-HRESULT __cdecl wined3d_device_begin_stateblock(struct wined3d_device *device);
+HRESULT __cdecl wined3d_device_begin_stateblock(struct wined3d_device *device, struct wined3d_stateblock **stateblock);
 HRESULT __cdecl wined3d_device_clear(struct wined3d_device *device, DWORD rect_count, const RECT *rects, DWORD flags,
         const struct wined3d_color *color, float z, DWORD stencil);
 HRESULT __cdecl wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
@@ -2264,7 +2264,7 @@ void __cdecl wined3d_device_draw_primitive_instanced(struct wined3d_device *devi
 void __cdecl wined3d_device_draw_primitive_instanced_indirect(struct wined3d_device *device,
         struct wined3d_buffer *buffer, unsigned int offset);
 HRESULT __cdecl wined3d_device_end_scene(struct wined3d_device *device);
-HRESULT __cdecl wined3d_device_end_stateblock(struct wined3d_device *device, struct wined3d_stateblock **stateblock);
+HRESULT __cdecl wined3d_device_end_stateblock(struct wined3d_device *device);
 void __cdecl wined3d_device_evict_managed_resources(struct wined3d_device *device);
 UINT __cdecl wined3d_device_get_available_texture_mem(const struct wined3d_device *device);
 INT __cdecl wined3d_device_get_base_vertex_index(const struct wined3d_device *device);
-- 
2.23.0




More information about the wine-devel mailing list