From 1859ca857f94a8ca489a49d8d5d885651c0cf1b3 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 7 May 2019 15:00:09 +0430 Subject: [PATCH] wined3d: Determine the ORM_BACKBUFFER depth/stencil format in wined3d_adapter_gl_create_context(). Instead of in wined3d_swapchain_cs_init(). Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/adapter_vk.c | 2 +- dlls/wined3d/context.c | 92 ++++++++++++++++++++++------------ dlls/wined3d/directx.c | 3 +- dlls/wined3d/swapchain.c | 27 +--------- dlls/wined3d/wined3d_private.h | 8 ++- 5 files changed, 68 insertions(+), 64 deletions(-) diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 5d9c1535bea..d2d0d3023e9 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -288,7 +288,7 @@ static void adapter_vk_destroy_device(struct wined3d_device *device) heap_free(device_vk); } -static BOOL adapter_vk_create_context(struct wined3d_context *context, const struct wined3d_format *ds_format) +static BOOL adapter_vk_create_context(struct wined3d_context *context) { return TRUE; } diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 0defbcc25a9..fdf7f9ccc65 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -1965,7 +1965,7 @@ static BOOL wined3d_context_init(struct wined3d_context *context, struct wined3d return TRUE; } -struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, const struct wined3d_format *ds_format) +struct wined3d_context *context_create(struct wined3d_swapchain *swapchain) { struct wined3d_device *device = swapchain->device; struct wined3d_context_gl *context_gl; @@ -1984,7 +1984,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, cons heap_free(context_gl); return NULL; } - if (!(device->adapter->adapter_ops->adapter_create_context(context, ds_format))) + if (!(device->adapter->adapter_ops->adapter_create_context(context))) { wined3d_release_dc(context->win_handle, context->hdc); heap_free(context_gl); @@ -2003,15 +2003,15 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, cons return context; } -BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, const struct wined3d_format *ds_format) +BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context) { + struct wined3d_swapchain *swapchain = context->swapchain; + const struct wined3d_format *color_format, *ds_format; struct wined3d_device *device = context->device; - const struct wined3d_format *color_format; const struct wined3d_d3d_info *d3d_info; const struct wined3d_gl_info *gl_info; struct wined3d_resource *target; unsigned int target_bind_flags; - BOOL aux_buffers = FALSE; HGLRC ctx, share_ctx; unsigned int i; @@ -2057,47 +2057,77 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, const st return FALSE; target = &context->current_rt.texture->resource; - color_format = target->format; target_bind_flags = target->bind_flags; - /* In case of ORM_BACKBUFFER, make sure to request an alpha component for - * X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */ if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) { - aux_buffers = TRUE; + static const enum wined3d_format_id ds_formats[] = + { + WINED3DFMT_D24_UNORM_S8_UINT, + WINED3DFMT_D32_UNORM, + WINED3DFMT_R24_UNORM_X8_TYPELESS, + WINED3DFMT_D16_UNORM, + WINED3DFMT_S1_UINT_D15_UNORM, + }; + color_format = target->format; + + /* In case of ORM_BACKBUFFER, make sure to request an alpha component for + * X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */ if (color_format->id == WINED3DFMT_B4G4R4X4_UNORM) color_format = wined3d_get_format(device->adapter, WINED3DFMT_B4G4R4A4_UNORM, target_bind_flags); else if (color_format->id == WINED3DFMT_B8G8R8X8_UNORM) color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags); + + /* DirectDraw supports 8bit paletted render targets and these are used by + * old games like StarCraft and C&C. Most modern hardware doesn't support + * 8bit natively so we perform some form of 8bit -> 32bit conversion. The + * conversion (ab)uses the alpha component for storing the palette index. + * For this reason we require a format with 8bit alpha, so request + * A8R8G8B8. */ + if (color_format->id == WINED3DFMT_P8_UINT) + color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags); + + /* Try to find a pixel format which matches our requirements. */ + if (!swapchain->ds_format) + { + for (i = 0; i < ARRAY_SIZE(ds_formats); ++i) + { + ds_format = wined3d_get_format(device->adapter, ds_formats[i], WINED3D_BIND_DEPTH_STENCIL); + if ((context->pixel_format = context_choose_pixel_format(device, + context->hdc, color_format, ds_format, TRUE))) + { + swapchain->ds_format = ds_format; + break; + } + + TRACE("Depth stencil format %s is not supported, trying next format.\n", + debug_d3dformat(ds_format->id)); + } + } + else + { + context->pixel_format = context_choose_pixel_format(device, + context->hdc, color_format, swapchain->ds_format, TRUE); + } } - - /* DirectDraw supports 8bit paletted render targets and these are used by - * old games like StarCraft and C&C. Most modern hardware doesn't support - * 8bit natively so we perform some form of 8bit -> 32bit conversion. The - * conversion (ab)uses the alpha component for storing the palette index. - * For this reason we require a format with 8bit alpha, so request - * A8R8G8B8. */ - if (color_format->id == WINED3DFMT_P8_UINT) - color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags); - - /* When using FBOs for off-screen rendering, we only use the drawable for - * presentation blits, and don't do any rendering to it. That means we - * don't need depth or stencil buffers, and can mostly ignore the render - * target format. This wouldn't necessarily be quite correct for 10bpc - * display modes, but we don't currently support those. - * Using the same format regardless of the color/depth/stencil targets - * makes it much less likely that different wined3d instances will set - * conflicting pixel formats. */ - if (wined3d_settings.offscreen_rendering_mode != ORM_BACKBUFFER) + else { + /* When using FBOs for off-screen rendering, we only use the drawable for + * presentation blits, and don't do any rendering to it. That means we + * don't need depth or stencil buffers, and can mostly ignore the render + * target format. This wouldn't necessarily be quite correct for 10bpc + * display modes, but we don't currently support those. + * Using the same format regardless of the color/depth/stencil targets + * makes it much less likely that different wined3d instances will set + * conflicting pixel formats. */ color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags); ds_format = wined3d_get_format(device->adapter, WINED3DFMT_UNKNOWN, WINED3D_BIND_DEPTH_STENCIL); + context->pixel_format = context_choose_pixel_format(device, + context->hdc, color_format, ds_format, FALSE); } - /* Try to find a pixel format which matches our requirements. */ - if (!(context->pixel_format = context_choose_pixel_format(device, - context->hdc, color_format, ds_format, aux_buffers))) + if (!context->pixel_format) return FALSE; context_enter(context); diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 1e86d990dcd..b2db18d2303 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -2258,8 +2258,7 @@ static void adapter_no3d_destroy_device(struct wined3d_device *device) heap_free(device); } -static BOOL wined3d_adapter_no3d_create_context(struct wined3d_context *context, - const struct wined3d_format *ds_format) +static BOOL wined3d_adapter_no3d_create_context(struct wined3d_context *context) { return TRUE; } diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index 7210682c45f..f47c1a44297 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -720,31 +720,8 @@ static void wined3d_swapchain_apply_sample_count_override(const struct wined3d_s static void wined3d_swapchain_cs_init(void *object) { struct wined3d_swapchain *swapchain = object; - const struct wined3d_adapter *adapter; - 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, - }; - - adapter = swapchain->device->adapter; - - /* 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(adapter, formats[i], WINED3D_BIND_DEPTH_STENCIL); - if ((swapchain->context[0] = context_create(swapchain, swapchain->ds_format))) - break; - TRACE("Depth stencil format %s is not supported, trying next format.\n", debug_d3dformat(formats[i])); - } - - if (!swapchain->context[0]) + if (!(swapchain->context[0] = context_create(swapchain))) { WARN("Failed to create context.\n"); return; @@ -1085,7 +1062,7 @@ static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain, GetCurrentThreadId()); - if (!(ctx = context_create(swapchain, swapchain->ds_format))) + if (!(ctx = context_create(swapchain))) { ERR("Failed to create a new context for the swapchain\n"); return NULL; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index fb44f7f913b..513fd3e4996 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2197,8 +2197,7 @@ void context_check_fbo_status(const struct wined3d_context *context, GLenum targ void context_copy_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *dst, GLenum dst_binding, const struct wined3d_bo_address *src, GLenum src_binding, size_t size) DECLSPEC_HIDDEN; -struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, - const struct wined3d_format *ds_format) DECLSPEC_HIDDEN; +struct wined3d_context *context_create(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN; void wined3d_context_destroy(struct wined3d_context *context) DECLSPEC_HIDDEN; void context_draw_shaded_quad(struct wined3d_context *context, struct wined3d_texture_gl *texture_gl, @@ -2713,7 +2712,7 @@ struct wined3d_adapter_ops BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count, struct wined3d_device_parent *device_parent, struct wined3d_device **device); void (*adapter_destroy_device)(struct wined3d_device *device); - BOOL (*adapter_create_context)(struct wined3d_context *context, const struct wined3d_format *ds_format); + BOOL (*adapter_create_context)(struct wined3d_context *context); void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps); BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter, const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format, @@ -2772,8 +2771,7 @@ static inline const struct wined3d_adapter_gl *wined3d_adapter_gl_const(const st struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal, unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN; -BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, - const struct wined3d_format *ds_format) DECLSPEC_HIDDEN; +BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context) DECLSPEC_HIDDEN; struct wined3d_adapter_vk {