wined3d: Make the adapter responsible for initialising and de-initialising 3D.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2019-05-07 15:00:08 +04:30 committed by Alexandre Julliard
parent 9a373586a3
commit 4499251461
5 changed files with 77 additions and 51 deletions

View File

@ -4234,6 +4234,15 @@ static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter_gl *adapter_gl,
}
}
static void adapter_gl_destroy(struct wined3d_adapter *adapter)
{
struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl(adapter);
heap_free(adapter_gl->pixel_formats);
wined3d_adapter_cleanup(adapter);
heap_free(adapter_gl);
}
static HRESULT adapter_gl_create_device(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
enum wined3d_device_type device_type, HWND focus_window, unsigned int flags, BYTE surface_alignment,
const enum wined3d_feature_level *levels, unsigned int level_count,
@ -4523,13 +4532,26 @@ static BOOL adapter_gl_check_format(const struct wined3d_adapter *adapter,
return FALSE;
}
static void adapter_gl_destroy(struct wined3d_adapter *adapter)
static HRESULT adapter_gl_init_3d(struct wined3d_device *device)
{
struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl(adapter);
TRACE("device %p.\n", device);
heap_free(adapter_gl->pixel_formats);
wined3d_adapter_cleanup(adapter);
heap_free(adapter_gl);
wined3d_cs_init_object(device->cs, wined3d_device_create_primary_opengl_context_cs, device);
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
if (!device->swapchains[0]->num_contexts)
return E_FAIL;
device->d3d_initialized = TRUE;
return WINED3D_OK;
}
static void adapter_gl_uninit_3d(struct wined3d_device *device)
{
TRACE("device %p.\n", device);
wined3d_cs_destroy_object(device->cs, wined3d_device_delete_opengl_contexts_cs, device);
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
}
static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
@ -4540,6 +4562,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
wined3d_adapter_gl_create_context,
adapter_gl_get_wined3d_caps,
adapter_gl_check_format,
adapter_gl_init_3d,
adapter_gl_uninit_3d,
};
static BOOL wined3d_adapter_gl_init(struct wined3d_adapter_gl *adapter_gl,

View File

@ -398,6 +398,18 @@ static BOOL adapter_vk_check_format(const struct wined3d_adapter *adapter,
return TRUE;
}
static HRESULT adapter_vk_init_3d(struct wined3d_device *device)
{
TRACE("device %p.\n", device);
return WINED3D_OK;
}
static void adapter_vk_uninit_3d(struct wined3d_device *device)
{
TRACE("device %p.\n", device);
}
static const struct wined3d_adapter_ops wined3d_adapter_vk_ops =
{
adapter_vk_destroy,
@ -406,6 +418,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_vk_ops =
adapter_vk_create_context,
adapter_vk_get_wined3d_caps,
adapter_vk_check_format,
adapter_vk_init_3d,
adapter_vk_uninit_3d,
};
static unsigned int wined3d_get_wine_vk_version(void)

View File

@ -1009,7 +1009,7 @@ static void device_init_swapchain_state(struct wined3d_device *device, struct wi
wined3d_device_set_depth_stencil_view(device, ds_enable ? device->auto_depth_stencil_view : NULL);
}
static void wined3d_device_delete_opengl_contexts_cs(void *object)
void wined3d_device_delete_opengl_contexts_cs(void *object)
{
struct wined3d_resource *resource, *cursor;
struct wined3d_device *device = object;
@ -1043,13 +1043,7 @@ static void wined3d_device_delete_opengl_contexts_cs(void *object)
}
}
static void wined3d_device_delete_opengl_contexts(struct wined3d_device *device)
{
wined3d_cs_destroy_object(device->cs, wined3d_device_delete_opengl_contexts_cs, device);
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
}
static void wined3d_device_create_primary_opengl_context_cs(void *object)
void wined3d_device_create_primary_opengl_context_cs(void *object)
{
struct wined3d_device *device = object;
struct wined3d_swapchain *swapchain;
@ -1084,16 +1078,6 @@ static void wined3d_device_create_primary_opengl_context_cs(void *object)
context_release(context);
}
static HRESULT wined3d_device_create_primary_opengl_context(struct wined3d_device *device)
{
wined3d_cs_init_object(device->cs, wined3d_device_create_primary_opengl_context_cs, device);
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
if (!device->swapchains[0]->num_contexts)
return E_FAIL;
return WINED3D_OK;
}
HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
{
static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f};
@ -1136,24 +1120,8 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str
device->swapchains[0] = swapchain;
memset(device->fb.render_targets, 0, sizeof(device->fb.render_targets));
if (device->wined3d->flags & WINED3D_NO3D)
{
if (!(device->blitter = wined3d_cpu_blitter_create()))
{
ERR("Failed to create CPU blitter.\n");
heap_free(device->swapchains);
device->swapchain_count = 0;
hr = E_FAIL;
goto err_out;
}
}
else
{
if (FAILED(hr = wined3d_device_create_primary_opengl_context(device)))
goto err_out;
device->d3d_initialized = TRUE;
}
if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device)))
goto err_out;
device_init_swapchain_state(device, swapchain);
@ -1231,10 +1199,7 @@ void wined3d_device_uninit_3d(struct wined3d_device *device)
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
if (no3d)
device->blitter->ops->blitter_destroy(device->blitter, NULL);
else
wined3d_device_delete_opengl_contexts(device);
device->adapter->adapter_ops->adapter_uninit_3d(device);
if ((view = device->fb.depth_stencil))
{
@ -5066,7 +5031,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
state_cleanup(&device->state);
if (device->d3d_initialized)
wined3d_device_delete_opengl_contexts(device);
device->adapter->adapter_ops->adapter_uninit_3d(device);
memset(&device->state, 0, sizeof(device->state));
state_init(&device->state, &device->fb, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
@ -5097,11 +5062,8 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
wined3d_cs_emit_set_scissor_rects(device->cs, 1, state->scissor_rects);
}
if (device->d3d_initialized)
{
if (reset_state)
hr = wined3d_device_create_primary_opengl_context(device);
}
if (device->d3d_initialized && reset_state)
hr = device->adapter->adapter_ops->adapter_init_3d(device);
/* All done. There is no need to reload resources or shaders, this will happen automatically on the
* first use

View File

@ -2275,6 +2275,26 @@ static BOOL adapter_no3d_check_format(const struct wined3d_adapter *adapter,
return TRUE;
}
static HRESULT adapter_no3d_init_3d(struct wined3d_device *device)
{
TRACE("device %p.\n", device);
if (!(device->blitter = wined3d_cpu_blitter_create()))
{
ERR("Failed to create CPU blitter.\n");
return E_FAIL;
}
return WINED3D_OK;
}
static void adapter_no3d_uninit_3d(struct wined3d_device *device)
{
TRACE("device %p.\n", device);
device->blitter->ops->blitter_destroy(device->blitter, NULL);
}
static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
{
adapter_no3d_destroy,
@ -2283,6 +2303,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
wined3d_adapter_no3d_create_context,
adapter_no3d_get_wined3d_caps,
adapter_no3d_check_format,
adapter_no3d_init_3d,
adapter_no3d_uninit_3d,
};
static void wined3d_adapter_no3d_init_d3d_info(struct wined3d_adapter *adapter, unsigned int wined3d_creation_flags)

View File

@ -2718,6 +2718,8 @@ struct wined3d_adapter_ops
BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
const struct wined3d_format *ds_format);
HRESULT (*adapter_init_3d)(struct wined3d_device *device);
void (*adapter_uninit_3d)(struct wined3d_device *device);
};
/* The adapter structure */
@ -3192,6 +3194,8 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c
const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
void wined3d_device_create_primary_opengl_context_cs(void *object) DECLSPEC_HIDDEN;
void wined3d_device_delete_opengl_contexts_cs(void *object) DECLSPEC_HIDDEN;
HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,