And hold it locally in d3d[789].
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/d3d8/d3d8_private.h | 5 +++-- dlls/d3d8/device.c | 13 ++++++++----- dlls/d3d9/d3d9_private.h | 5 +++-- dlls/d3d9/device.c | 20 ++++++++++++-------- dlls/ddraw/ddraw_private.h | 2 ++ dlls/ddraw/device.c | 11 +++++++++-- dlls/wined3d/device.c | 30 ++++++++++++++++-------------- dlls/wined3d/wined3d.spec | 4 ++-- include/wine/wined3d.h | 4 ++-- 9 files changed, 57 insertions(+), 37 deletions(-)
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index 7c44f07c5e..888a643582 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 d3d8_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 d367f4200c..abb6ae3e02 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -907,7 +907,8 @@ 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; + wined3d_stateblock_decref(device->recording); + device->recording = NULL; present_parameters->BackBufferCount = swapchain_desc.backbuffer_count; device->implicit_swapchain->swap_interval = wined3dswapinterval_from_d3d(present_parameters->FullScreen_PresentationInterval); @@ -1857,13 +1858,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; @@ -1881,14 +1883,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 3fe0376e5c..2c959057e7 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 d3d9_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 6cc3f180b0..1edfa375ca 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -990,7 +990,8 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (!extended) { - device->recording = FALSE; + 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); @@ -2333,13 +2334,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; @@ -2355,14 +2357,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 77e2866272..cb63e197fc 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -346,6 +346,8 @@ struct d3d_device D3DMATRIXHANDLE world, proj, view;
struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES]; + + 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 d2f11c1dab..c9b7dc93e4 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -5643,14 +5643,18 @@ 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);
wined3d_mutex_lock(); - hr = wined3d_device_begin_stateblock(device->wined3d_device); + hr = wined3d_device_begin_stateblock(device->wined3d_device, &stateblock); wined3d_mutex_unlock();
+ if (SUCCEEDED(hr)) + device->recording = stateblock; + return hr_ddraw_from_wined3d(hr); }
@@ -5701,7 +5705,7 @@ static HRESULT d3d_device7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *statebl
wined3d_mutex_lock();
- 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); @@ -5710,6 +5714,9 @@ static HRESULT d3d_device7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *statebl return hr_ddraw_from_wined3d(hr); }
+ 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 f02dcdd39d..7520d43d90 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3621,49 +3621,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 75b9fe12c6..ac87f01f50 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -35,7 +35,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) @@ -53,7 +53,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 07329024fe..9bd71878f0 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2223,7 +2223,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, @@ -2259,7 +2259,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);