wined3d: Return a wined3d_stateblock from wined3d_device_begin_stateblock().

And hold it locally in d3d[789].

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-09-25 23:05:39 -05:00 committed by Alexandre Julliard
parent 71ab74a11f
commit 7360e7d488
10 changed files with 86 additions and 53 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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,

View File

@ -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))
{
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))))
{

View File

@ -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,

View File

@ -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)

View File

@ -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);
}

View File

@ -4070,49 +4070,53 @@ 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)
return WINED3DERR_INVALIDCALL;
hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock);
if (FAILED(hr))
return hr;
device->recording = stateblock;
device->update_stateblock_state = &stateblock->stateblock_state;
TRACE("Recording stateblock %p.\n", stateblock);
return WINED3D_OK;
}
HRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device,
struct wined3d_stateblock **stateblock)
{
struct wined3d_stateblock *object = device->recording;
TRACE("device %p, stateblock %p.\n", device, stateblock);
if (!device->recording)
{
WARN("Not recording.\n");
*stateblock = NULL;
return WINED3DERR_INVALIDCALL;
}
stateblock_init_contained_states(object);
hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &object);
if (FAILED(hr))
return hr;
device->recording = object;
device->update_stateblock_state = &object->stateblock_state;
wined3d_stateblock_incref(object);
*stateblock = object;
TRACE("Recording stateblock %p.\n", *stateblock);
return WINED3D_OK;
}
HRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device)
{
struct wined3d_stateblock *stateblock = device->recording;
TRACE("device %p.\n", device);
if (!device->recording)
{
WARN("Not recording.\n");
return WINED3DERR_INVALIDCALL;
}
stateblock_init_contained_states(stateblock);
wined3d_stateblock_decref(device->recording);
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;
}

View File

@ -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)

View File

@ -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);