wined3d: Send swapchain context creation through the command stream.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2017-03-01 07:14:52 +01:00 committed by Alexandre Julliard
parent 8952040a0e
commit 3b0e37a0f4
1 changed files with 45 additions and 41 deletions

View File

@ -782,6 +782,50 @@ static void wined3d_swapchain_apply_sample_count_override(const struct wined3d_s
*quality = 0;
}
static void wined3d_swapchain_cs_init(void *object)
{
struct wined3d_swapchain *swapchain = object;
const struct wined3d_gl_info *gl_info;
unsigned int i;
static const enum wined3d_format_id formats[] =
{
WINED3DFMT_D24_UNORM_S8_UINT,
WINED3DFMT_D32_UNORM,
WINED3DFMT_R24_UNORM_X8_TYPELESS,
WINED3DFMT_D16_UNORM,
WINED3DFMT_S1_UINT_D15_UNORM,
};
gl_info = &swapchain->device->adapter->gl_info;
/* Without ORM_FBO, switching the depth/stencil format is hard. Always
* request a depth/stencil buffer in the likely case it's needed later. */
for (i = 0; i < ARRAY_SIZE(formats); ++i)
{
swapchain->ds_format = wined3d_get_format(gl_info, formats[i], WINED3DUSAGE_DEPTHSTENCIL);
if ((swapchain->context[0] = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format)))
break;
TRACE("Depth stencil format %s is not supported, trying next format.\n", debug_d3dformat(formats[i]));
}
if (!swapchain->context[0])
{
WARN("Failed to create context.\n");
return;
}
swapchain->num_contexts = 1;
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
&& (!swapchain->desc.enable_auto_depth_stencil
|| swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id))
FIXME("Add OpenGL context recreation support.\n");
context_release(swapchain->context[0]);
swapchain_update_swap_interval(swapchain);
}
static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3d_device *device,
struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
{
@ -908,17 +952,6 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
if (!(device->wined3d->flags & WINED3D_NO3D))
{
static const enum wined3d_format_id formats[] =
{
WINED3DFMT_D24_UNORM_S8_UINT,
WINED3DFMT_D32_UNORM,
WINED3DFMT_R24_UNORM_X8_TYPELESS,
WINED3DFMT_D16_UNORM,
WINED3DFMT_S1_UINT_D15_UNORM
};
const struct wined3d_gl_info *gl_info = &adapter->gl_info;
swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
if (!swapchain->context)
{
@ -927,42 +960,13 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
goto err;
}
/* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate.
* You are able to add a depth + stencil surface at a later stage when you need it.
* In order to support this properly in WineD3D we need the ability to recreate the opengl context and
* drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new
* context, need torecreate shaders, textures and other resources.
*
* The context manager already takes care of the state problem and for the other tasks code from Reset
* can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now.
* Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
* time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
* issue needs to be fixed. */
for (i = 0; i < (sizeof(formats) / sizeof(*formats)); i++)
{
swapchain->ds_format = wined3d_get_format(gl_info, formats[i], WINED3DUSAGE_DEPTHSTENCIL);
swapchain->context[0] = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format);
if (swapchain->context[0]) break;
TRACE("Depth stencil format %s is not supported, trying next format\n",
debug_d3dformat(formats[i]));
}
wined3d_cs_init_object(device->cs, wined3d_swapchain_cs_init, swapchain);
if (!swapchain->context[0])
{
WARN("Failed to create context.\n");
hr = WINED3DERR_NOTAVAILABLE;
goto err;
}
swapchain->num_contexts = 1;
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
&& (!desc->enable_auto_depth_stencil
|| swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id))
{
FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n");
}
context_release(swapchain->context[0]);
swapchain_update_swap_interval(swapchain);
}
if (swapchain->desc.backbuffer_count > 0)