From: Zebediah Figura Subject: [PATCH 1/7] wined3d: Return a wined3d_stateblock from wined3d_device_begin_stateblock(). Message-Id: <20190622152923.26892-1-z.figura12@gmail.com> Date: Sat, 22 Jun 2019 10:29:16 -0500 And hold it locally in d3d[789]. Signed-off-by: Zebediah Figura --- dlls/d3d8/d3d8_private.h | 5 +++-- dlls/d3d8/device.c | 14 +++++++++----- dlls/d3d9/d3d9_private.h | 5 +++-- dlls/d3d9/device.c | 21 +++++++++++++-------- dlls/ddraw/ddraw_private.h | 2 +- dlls/ddraw/device.c | 10 ++++++---- dlls/wined3d/device.c | 30 ++++++++++++++++-------------- dlls/wined3d/wined3d.spec | 4 ++-- include/wine/wined3d.h | 4 ++-- 9 files changed, 55 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 e57e01e42ba..efea4708fda 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -911,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 @@ -1862,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; @@ -1886,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 8ee521b14b0..c01e3997808 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -108,8 +108,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 */ @@ -117,6 +116,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 9fbdcebf075..9d05771c5d1 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -995,7 +995,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); @@ -2350,13 +2352,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; @@ -2372,14 +2375,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 b228f3ec355..6bdc7c789fa 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -350,7 +350,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 cdf4de8f95d..2c0b85d9a47 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -5625,6 +5625,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); @@ -5636,8 +5637,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); @@ -5695,7 +5696,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); @@ -5703,7 +5704,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/wined3d/device.c b/dlls/wined3d/device.c index d35a0648c9c..612278d5d56 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4178,49 +4178,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 59f99c91e07..9b4f4792f5d 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 abef3f0ad02..27776385313 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2231,7 +2231,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, @@ -2267,7 +2267,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.21.0