ReactOS 0.4.17-dev-966-gf06eace
swapchain.c File Reference
#include "wined3d_private.h"
#include "wined3d_gl.h"
#include "wined3d_vk.h"
Include dependency graph for swapchain.c:

Go to the source code of this file.

Classes

struct  wined3d_window_state
 

Macros

#define WINED3D_WINDOW_TOPMOST_TIMER_ID   0x4242
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d)
 
 WINE_DECLARE_DEBUG_CHANNEL (d3d_perf)
 
void wined3d_swapchain_cleanup (struct wined3d_swapchain *swapchain)
 
void wined3d_swapchain_gl_cleanup (struct wined3d_swapchain_gl *swapchain_gl)
 
static void wined3d_swapchain_vk_destroy_vulkan_swapchain (struct wined3d_swapchain_vk *swapchain_vk)
 
static void wined3d_swapchain_vk_destroy_object (void *object)
 
void wined3d_swapchain_vk_cleanup (struct wined3d_swapchain_vk *swapchain_vk)
 
ULONG CDECL wined3d_swapchain_incref (struct wined3d_swapchain *swapchain)
 
ULONG CDECL wined3d_swapchain_decref (struct wined3d_swapchain *swapchain)
 
void *CDECL wined3d_swapchain_get_parent (const struct wined3d_swapchain *swapchain)
 
void CDECL wined3d_swapchain_set_window (struct wined3d_swapchain *swapchain, HWND window)
 
HRESULT CDECL wined3d_swapchain_present (struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags)
 
HRESULT CDECL wined3d_swapchain_get_front_buffer_data (const struct wined3d_swapchain *swapchain, struct wined3d_texture *dst_texture, unsigned int sub_resource_idx)
 
struct wined3d_texture *CDECL wined3d_swapchain_get_back_buffer (const struct wined3d_swapchain *swapchain, UINT back_buffer_idx)
 
struct wined3d_texture *CDECL wined3d_swapchain_get_front_buffer (const struct wined3d_swapchain *swapchain)
 
struct wined3d_output * wined3d_swapchain_get_output (const struct wined3d_swapchain *swapchain)
 
HRESULT CDECL wined3d_swapchain_get_raster_status (const struct wined3d_swapchain *swapchain, struct wined3d_raster_status *raster_status)
 
struct wined3d_swapchain_state *CDECL wined3d_swapchain_get_state (struct wined3d_swapchain *swapchain)
 
HRESULT CDECL wined3d_swapchain_get_display_mode (const struct wined3d_swapchain *swapchain, struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
 
struct wined3d_device *CDECL wined3d_swapchain_get_device (const struct wined3d_swapchain *swapchain)
 
void CDECL wined3d_swapchain_get_desc (const struct wined3d_swapchain *swapchain, struct wined3d_swapchain_desc *desc)
 
HRESULT CDECL wined3d_swapchain_set_gamma_ramp (const struct wined3d_swapchain *swapchain, uint32_t flags, const struct wined3d_gamma_ramp *ramp)
 
void CDECL wined3d_swapchain_set_palette (struct wined3d_swapchain *swapchain, struct wined3d_palette *palette)
 
HRESULT CDECL wined3d_swapchain_get_gamma_ramp (const struct wined3d_swapchain *swapchain, struct wined3d_gamma_ramp *ramp)
 
static void swapchain_blit_gdi (struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
 
static void swapchain_blit (const struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
 
static void swapchain_gl_set_swap_interval (struct wined3d_swapchain *swapchain, struct wined3d_context_gl *context_gl, unsigned int swap_interval)
 
static void wined3d_swapchain_gl_rotate (struct wined3d_swapchain *swapchain, struct wined3d_context *context)
 
static bool swapchain_present_is_partial_copy (struct wined3d_swapchain *swapchain, const RECT *dst_rect)
 
static void swapchain_gl_present (struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
 
static void swapchain_frontbuffer_updated (struct wined3d_swapchain *swapchain)
 
static bool wined3d_swapchain_vk_present_mode_supported (struct wined3d_swapchain_vk *swapchain_vk, VkPresentModeKHR vk_present_mode)
 
static VkFormat get_swapchain_fallback_format (VkFormat vk_format)
 
static VkFormat wined3d_swapchain_vk_select_vk_format (struct wined3d_swapchain_vk *swapchain_vk, VkSurfaceKHR vk_surface)
 
static bool wined3d_swapchain_vk_create_vulkan_swapchain_images (struct wined3d_swapchain_vk *swapchain_vk, VkSwapchainKHR vk_swapchain)
 
static HRESULT wined3d_swapchain_vk_create_vulkan_swapchain (struct wined3d_swapchain_vk *swapchain_vk)
 
static HRESULT wined3d_swapchain_vk_recreate (struct wined3d_swapchain_vk *swapchain_vk)
 
static void wined3d_swapchain_vk_set_swap_interval (struct wined3d_swapchain_vk *swapchain_vk, unsigned int swap_interval)
 
static VkResult wined3d_swapchain_vk_blit (struct wined3d_swapchain_vk *swapchain_vk, struct wined3d_context_vk *context_vk, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval)
 
static void wined3d_swapchain_vk_rotate (struct wined3d_swapchain *swapchain, struct wined3d_context_vk *context_vk)
 
static void swapchain_vk_present (struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
 
static void swapchain_gdi_frontbuffer_updated (struct wined3d_swapchain *swapchain)
 
static void swapchain_gdi_present (struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
 
static void wined3d_swapchain_apply_sample_count_override (const struct wined3d_swapchain *swapchain, enum wined3d_format_id format_id, enum wined3d_multisample_type *type, unsigned int *quality)
 
void swapchain_set_max_frame_latency (struct wined3d_swapchain *swapchain, const struct wined3d_device *device)
 
static enum wined3d_format_id adapter_format_from_backbuffer_format (const struct wined3d_adapter *adapter, enum wined3d_format_id format_id)
 
static HRESULT wined3d_swapchain_state_init (struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *desc, HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state_parent *parent)
 
static HRESULT swapchain_create_texture (struct wined3d_swapchain *swapchain, bool front, bool depth, struct wined3d_texture **texture)
 
static HRESULT wined3d_swapchain_init (struct wined3d_swapchain *swapchain, struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_swapchain_ops *swapchain_ops)
 
HRESULT wined3d_swapchain_no3d_init (struct wined3d_swapchain *swapchain_no3d, struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT wined3d_swapchain_gl_init (struct wined3d_swapchain_gl *swapchain_gl, struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT wined3d_swapchain_vk_init (struct wined3d_swapchain_vk *swapchain_vk, struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT CDECL wined3d_swapchain_create (struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain)
 
static struct wined3d_context_gl * wined3d_swapchain_gl_create_context (struct wined3d_swapchain_gl *swapchain_gl)
 
struct wined3d_context_gl * wined3d_swapchain_gl_get_context (struct wined3d_swapchain_gl *swapchain_gl)
 
void swapchain_update_draw_bindings (struct wined3d_swapchain *swapchain)
 
void wined3d_swapchain_activate (struct wined3d_swapchain *swapchain, BOOL activate)
 
HRESULT CDECL wined3d_swapchain_resize_buffers (struct wined3d_swapchain *swapchain, unsigned int buffer_count, unsigned int width, unsigned int height, enum wined3d_format_id format_id, enum wined3d_multisample_type multisample_type, unsigned int multisample_quality)
 
static HRESULT wined3d_swapchain_state_set_display_mode (struct wined3d_swapchain_state *state, struct wined3d_output *output, struct wined3d_display_mode *mode)
 
HRESULT CDECL wined3d_swapchain_state_resize_target (struct wined3d_swapchain_state *state, const struct wined3d_display_mode *mode)
 
static LONG fullscreen_style (LONG style)
 
static LONG fullscreen_exstyle (LONG exstyle)
 
static void CALLBACK topmost_timer_proc (HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
 
static DWORD WINAPI set_window_state_thread (void *ctx)
 
static void set_window_state (struct wined3d_window_state *s)
 
HRESULT wined3d_swapchain_state_setup_fullscreen (struct wined3d_swapchain_state *state, HWND window, int x, int y, int width, int height)
 
void wined3d_swapchain_state_restore_from_fullscreen (struct wined3d_swapchain_state *state, HWND window, const RECT *window_rect)
 
HRESULT CDECL wined3d_swapchain_state_set_fullscreen (struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode)
 
BOOL CDECL wined3d_swapchain_state_is_windowed (const struct wined3d_swapchain_state *state)
 
void CDECL wined3d_swapchain_state_get_size (const struct wined3d_swapchain_state *state, unsigned int *width, unsigned int *height)
 
void CDECL wined3d_swapchain_state_destroy (struct wined3d_swapchain_state *state)
 
HRESULT CDECL wined3d_swapchain_state_create (const struct wined3d_swapchain_desc *desc, HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state_parent *state_parent, struct wined3d_swapchain_state **state)
 

Variables

static const struct wined3d_swapchain_ops swapchain_gl_ops
 
static const struct wined3d_swapchain_ops swapchain_vk_ops
 
static const struct wined3d_swapchain_ops swapchain_no3d_ops
 

Macro Definition Documentation

◆ WINED3D_WINDOW_TOPMOST_TIMER_ID

#define WINED3D_WINDOW_TOPMOST_TIMER_ID   0x4242

Definition at line 2157 of file swapchain.c.

Function Documentation

◆ adapter_format_from_backbuffer_format()

static enum wined3d_format_id adapter_format_from_backbuffer_format ( const struct wined3d_adapter *  adapter,
enum wined3d_format_id  format_id 
)
static

Definition at line 1380 of file swapchain.c.

1382{
1383 const struct wined3d_format *backbuffer_format;
1384
1386 return pixelformat_for_depth(backbuffer_format->byte_count * CHAR_BIT);
1387}
const struct wined3d_format * wined3d_get_format(const struct wined3d_adapter *adapter, enum wined3d_format_id format_id, unsigned int bind_flags)
Definition: utils.c:4428
enum wined3d_format_id pixelformat_for_depth(DWORD depth)
Definition: utils.c:6067
#define CHAR_BIT
Definition: cabinet.h:45
return adapter
static UINT format_id
Definition: clipboard.c:1455
#define WINED3D_BIND_RENDER_TARGET
Definition: wined3d.h:914

Referenced by wined3d_swapchain_state_init(), and wined3d_swapchain_state_set_fullscreen().

◆ fullscreen_exstyle()

static LONG fullscreen_exstyle ( LONG  exstyle)
static

Definition at line 2137 of file swapchain.c.

2138{
2139 /* Filter out window decorations. */
2140 exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
2141
2142 return exstyle;
2143}
#define WS_EX_WINDOWEDGE
Definition: winuser.h:407
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384

Referenced by wined3d_swapchain_state_restore_from_fullscreen(), and wined3d_swapchain_state_setup_fullscreen().

◆ fullscreen_style()

static LONG fullscreen_style ( LONG  style)
static

Definition at line 2128 of file swapchain.c.

2129{
2130 /* Make sure the window is managed, otherwise we won't get keyboard input. */
2133
2134 return style;
2135}
#define WS_CAPTION
Definition: pedump.c:624
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_POPUP
Definition: pedump.c:616
#define WS_THICKFRAME
Definition: pedump.c:630
Definition: style.c:91

Referenced by wined3d_swapchain_state_restore_from_fullscreen(), and wined3d_swapchain_state_setup_fullscreen().

◆ get_swapchain_fallback_format()

static VkFormat get_swapchain_fallback_format ( VkFormat  vk_format)
static

Definition at line 707 of file swapchain.c.

708{
709 switch (vk_format)
710 {
717 default:
718 WARN("Unhandled format %#x.\n", vk_format);
719 return VK_FORMAT_UNDEFINED;
720 }
721}
#define WARN(fmt,...)
Definition: precomp.h:61
@ VK_FORMAT_R8G8B8A8_SRGB
Definition: vulkan.h:2859
@ VK_FORMAT_B8G8R8A8_UNORM
Definition: vulkan.h:2860
@ VK_FORMAT_A2B10G10R10_UNORM_PACK32
Definition: vulkan.h:2880
@ VK_FORMAT_B8G8R8A8_SRGB
Definition: vulkan.h:2866
@ VK_FORMAT_R8G8B8A8_UNORM
Definition: vulkan.h:2853
@ VK_FORMAT_UNDEFINED
Definition: vulkan.h:2816
@ VK_FORMAT_R16G16B16A16_SFLOAT
Definition: vulkan.h:2913

◆ set_window_state()

static void set_window_state ( struct wined3d_window_state *  s)
static

Definition at line 2188 of file swapchain.c.

2189{
2190 static const UINT timeout = 1500;
2191 DWORD window_tid = GetWindowThreadProcessId(s->window, NULL);
2193 HANDLE thread;
2194
2195 TRACE("Window %p belongs to thread %#lx.\n", s->window, window_tid);
2196 /* If the window belongs to a different thread, modifying the style and/or
2197 * position can potentially deadlock if that thread isn't processing
2198 * messages. */
2199 if (window_tid == tid)
2200 {
2201 /* Deus Ex: Game of the Year Edition removes WS_EX_TOPMOST after changing resolutions in
2202 * exclusive fullscreen mode. Tests show that WS_EX_TOPMOST will be restored when a ~1.5s
2203 * timer times out */
2204 if (s->register_topmost_timer)
2205 {
2206 if (s->set_topmost_timer)
2208 else
2210 }
2211
2213 }
2214 else if ((thread = CreateThread(NULL, 0, set_window_state_thread, s, 0, NULL)))
2215 {
2216 SetThreadDescription(thread, L"wined3d_set_window_state");
2218 }
2219 else
2220 {
2221 ERR("Failed to create thread.\n");
2222 }
2223}
HRESULT WINAPI DECLSPEC_HOTPATCH SetThreadDescription(_In_ HANDLE hThread, _In_ PCWSTR lpThreadDescription)
#define ERR(fmt,...)
Definition: precomp.h:57
static HANDLE thread
Definition: service.c:33
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble s
Definition: gl.h:2039
unsigned int UINT
Definition: sysinfo.c:13
static TfClientId tid
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dhcpd.h:248
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
#define WINED3D_WINDOW_TOPMOST_TIMER_ID
Definition: swapchain.c:2157
static void CALLBACK topmost_timer_proc(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
Definition: swapchain.c:2159
static DWORD WINAPI set_window_state_thread(void *ctx)
Definition: swapchain.c:2167

Referenced by wined3d_swapchain_state_restore_from_fullscreen(), and wined3d_swapchain_state_setup_fullscreen().

◆ set_window_state_thread()

static DWORD WINAPI set_window_state_thread ( void *  ctx)
static

Definition at line 2167 of file swapchain.c.

2168{
2169 struct wined3d_window_state *s = ctx;
2170 bool filter;
2171
2173
2174 if (s->set_style)
2175 {
2176 SetWindowLongW(s->window, GWL_STYLE, s->style);
2177 SetWindowLongW(s->window, GWL_EXSTYLE, s->exstyle);
2178 }
2179 SetWindowPos(s->window, s->window_pos_after, s->x, s->y, s->width, s->height, s->flags);
2180
2182
2183 free(s);
2184
2185 return 0;
2186}
#define free
Definition: debug_ros.c:5
#define TRUE
Definition: types.h:120
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
#define GWL_STYLE
Definition: winuser.h:863
#define GWL_EXSTYLE
Definition: winuser.h:862
Definition: filter.c:165
BOOL wined3d_filter_messages(HWND window, BOOL filter)
Definition: wined3d_main.c:605

Referenced by set_window_state().

◆ swapchain_blit()

static void swapchain_blit ( const struct wined3d_swapchain *  swapchain,
struct wined3d_context *  context,
const RECT *  src_rect,
const RECT *  dst_rect 
)
static

Definition at line 466 of file swapchain.c.

468{
469 struct wined3d_texture *texture = swapchain->back_buffers[0];
470 struct wined3d_device *device = swapchain->device;
473
474 TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
475 swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
476
477 if ((src_rect->right - src_rect->left == dst_rect->right - dst_rect->left
478 && src_rect->bottom - src_rect->top == dst_rect->bottom - dst_rect->top)
479 || is_complex_fixup(texture->resource.format->color_fixup))
481 else
483
485 if (texture->resource.multisample_type)
487
489 device->blitter->ops->blitter_blit(device->blitter, WINED3D_BLIT_OP_COLOR_BLIT, context, texture, 0,
490 location, src_rect, texture, 0, WINED3D_LOCATION_DRAWABLE, dst_rect, NULL, filter, NULL);
492}
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
void wined3d_texture_invalidate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
Definition: texture.c:702
void wined3d_texture_validate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
Definition: texture.c:678
GLenum GLuint texture
Definition: glext.h:6295
#define location(file, line)
Definition: kmtest.h:18
long bottom
Definition: dcommon.idl:29
long right
Definition: dcommon.idl:29
long left
Definition: dcommon.idl:29
long top
Definition: dcommon.idl:29
Definition: http.c:7252
Definition: devices.h:37
struct wined3d_device * device
struct wined3d_swapchain * swapchain
wined3d_texture_filter_type
Definition: wined3d.h:704
@ WINED3D_TEXF_NONE
Definition: wined3d.h:705
@ WINED3D_TEXF_LINEAR
Definition: wined3d.h:707
static BOOL is_complex_fixup(struct color_fixup_desc fixup)
#define WINED3D_LOCATION_RB_RESOLVED
#define WINED3D_LOCATION_TEXTURE_RGB
#define WINED3D_LOCATION_DRAWABLE
@ WINED3D_BLIT_OP_COLOR_BLIT

Referenced by swapchain_gl_present().

◆ swapchain_blit_gdi()

static void swapchain_blit_gdi ( struct wined3d_swapchain *  swapchain,
struct wined3d_context *  context,
const RECT *  src_rect,
const RECT *  dst_rect 
)
static

Definition at line 399 of file swapchain.c.

401{
402 struct wined3d_texture *back_buffer = swapchain->back_buffers[0];
403 D3DKMT_DESTROYDCFROMMEMORY destroy_desc;
404 D3DKMT_CREATEDCFROMMEMORY create_desc;
405 const struct wined3d_format *format;
406 unsigned int row_pitch, slice_pitch;
407 HDC src_dc, dst_dc;
410
411 static unsigned int once;
412
413 TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
414 swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
415
416 if (!once++)
417 FIXME("Using GDI present.\n");
418
419 format = back_buffer->resource.format;
420 if (!format->ddi_format)
421 {
422 WARN("Cannot create a DC for format %s.\n", debug_d3dformat(format->id));
423 return;
424 }
425
427 wined3d_texture_get_pitch(back_buffer, 0, &row_pitch, &slice_pitch);
428
429 create_desc.pMemory = back_buffer->resource.heap_memory;
430 create_desc.Format = format->ddi_format;
431 create_desc.Width = wined3d_texture_get_level_width(back_buffer, 0);
432 create_desc.Height = wined3d_texture_get_level_height(back_buffer, 0);
433 create_desc.Pitch = row_pitch;
434 create_desc.hDeviceDc = CreateCompatibleDC(NULL);
435 create_desc.pColorTable = NULL;
436
437 status = D3DKMTCreateDCFromMemory(&create_desc);
438 DeleteDC(create_desc.hDeviceDc);
439 if (status)
440 {
441 WARN("Failed to create DC, status %#lx.\n", status);
442 return;
443 }
444
445 src_dc = create_desc.hDc;
446 bitmap = create_desc.hBitmap;
447
448 TRACE("Created source DC %p, bitmap %p for backbuffer %p.\n", src_dc, bitmap, back_buffer);
449
450 if (!(dst_dc = GetDCEx(swapchain->win_handle, 0, DCX_USESTYLE | DCX_CACHE)))
451 ERR("Failed to get destination DC.\n");
452
453 if (!StretchBlt(dst_dc, dst_rect->left, dst_rect->top, dst_rect->right - dst_rect->left,
454 dst_rect->bottom - dst_rect->top, src_dc, src_rect->left, src_rect->top,
455 src_rect->right - src_rect->left, src_rect->bottom - src_rect->top, SRCCOPY))
456 ERR("Failed to blit.\n");
457
458 ReleaseDC(swapchain->win_handle, dst_dc);
459 destroy_desc.hDc = src_dc;
460 destroy_desc.hBitmap = bitmap;
461 if ((status = D3DKMTDestroyDCFromMemory(&destroy_desc)))
462 ERR("Failed to destroy src dc, status %#lx.\n", status);
463}
#define DCX_USESTYLE
Definition: GetDCEx.c:10
LONG NTSTATUS
Definition: precomp.h:26
#define FIXME(fmt,...)
Definition: precomp.h:53
BOOL wined3d_texture_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:770
void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: texture.c:1697
const char * debug_d3dformat(enum wined3d_format_id format_id)
Definition: utils.c:4605
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define DCX_CACHE
Definition: winuser.h:2150
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
PALETTEENTRY * pColorTable
Definition: d3dkmthk.h:167
Definition: uimain.c:89
Definition: ps.c:97
struct wined3d_resource resource
NTSTATUS WINAPI D3DKMTDestroyDCFromMemory(const D3DKMT_DESTROYDCFROMMEMORY *desc)
NTSTATUS WINAPI D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY *desc)
static unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture, unsigned int level)
#define WINED3D_LOCATION_SYSMEM
static unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture, unsigned int level)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define SRCCOPY
Definition: wingdi.h:333
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by swapchain_gl_present(), and swapchain_vk_present().

◆ swapchain_create_texture()

static HRESULT swapchain_create_texture ( struct wined3d_swapchain *  swapchain,
bool  front,
bool  depth,
struct wined3d_texture **  texture 
)
static

Definition at line 1456 of file swapchain.c.

1458{
1459 const struct wined3d_swapchain_desc *swapchain_desc = &swapchain->state.desc;
1460 struct wined3d_device *device = swapchain->device;
1461 struct wined3d_resource_desc texture_desc;
1462 uint32_t texture_flags = 0;
1463 HRESULT hr;
1464
1465 texture_desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1466 texture_desc.format = depth ? swapchain_desc->auto_depth_stencil_format : swapchain_desc->backbuffer_format;
1467 texture_desc.multisample_type = swapchain_desc->multisample_type;
1468 texture_desc.multisample_quality = swapchain_desc->multisample_quality;
1469 texture_desc.usage = 0;
1470 if (!depth && (device->wined3d->flags & WINED3D_NO3D))
1471 texture_desc.usage |= WINED3DUSAGE_OWNDC;
1472 if (device->wined3d->flags & WINED3D_NO3D)
1473 texture_desc.access = WINED3D_RESOURCE_ACCESS_CPU;
1474 else
1475 texture_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
1476 if (!depth && (swapchain_desc->flags & WINED3D_SWAPCHAIN_LOCKABLE_BACKBUFFER))
1478 texture_desc.width = swapchain_desc->backbuffer_width;
1479 texture_desc.height = swapchain_desc->backbuffer_height;
1480 texture_desc.depth = 1;
1481 texture_desc.size = 0;
1482
1483 if (front)
1484 texture_desc.bind_flags = 0;
1485 else if (depth)
1486 texture_desc.bind_flags = WINED3D_BIND_DEPTH_STENCIL;
1487 else
1488 texture_desc.bind_flags = swapchain_desc->backbuffer_bind_flags;
1489
1490 if (swapchain_desc->flags & WINED3D_SWAPCHAIN_GDI_COMPATIBLE)
1491 texture_flags |= WINED3D_TEXTURE_CREATE_GET_DC;
1492
1493 if (FAILED(hr = wined3d_texture_create(device, &texture_desc, 1, 1,
1494 texture_flags, NULL, NULL, &wined3d_null_parent_ops, texture)))
1495 {
1496 WARN("Failed to create texture, hr %#lx.\n", hr);
1497 return hr;
1498 }
1499
1500 if (!depth)
1502
1503 return S_OK;
1504}
HRESULT hr
Definition: delayimp.cpp:582
UINT32 uint32_t
Definition: types.h:75
HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, uint32_t flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
Definition: texture.c:4158
void wined3d_texture_set_swapchain(struct wined3d_texture *texture, struct wined3d_swapchain *swapchain)
Definition: texture.c:1263
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
static struct address_cache * front
Definition: rpcb_clnt.c:83
unsigned int multisample_quality
Definition: wined3d.h:1778
unsigned int backbuffer_height
Definition: wined3d.h:1773
enum wined3d_multisample_type multisample_type
Definition: wined3d.h:1777
enum wined3d_format_id auto_depth_stencil_format
Definition: wined3d.h:1783
unsigned int backbuffer_width
Definition: wined3d.h:1772
enum wined3d_format_id backbuffer_format
Definition: wined3d.h:1774
unsigned int backbuffer_bind_flags
Definition: wined3d.h:1776
struct wined3d_swapchain_state state
const struct wined3d_parent_ops wined3d_null_parent_ops
Definition: directx.c:3472
#define WINED3D_NO3D
Definition: wined3d.h:1323
#define WINED3DUSAGE_OWNDC
Definition: wined3d.h:935
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:51
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:52
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:720
#define WINED3D_SWAPCHAIN_GDI_COMPATIBLE
Definition: wined3d.h:900
#define WINED3D_SWAPCHAIN_LOCKABLE_BACKBUFFER
Definition: wined3d.h:891
#define WINED3D_BIND_DEPTH_STENCIL
Definition: wined3d.h:915
#define WINED3D_RESOURCE_ACCESS_MAP_R
Definition: wined3d.h:53
#define WINED3D_TEXTURE_CREATE_GET_DC
Definition: wined3d.h:1565
#define WINED3D_RESOURCE_ACCESS_MAP_W
Definition: wined3d.h:54

Referenced by wined3d_swapchain_init(), and wined3d_swapchain_resize_buffers().

◆ swapchain_frontbuffer_updated()

static void swapchain_frontbuffer_updated ( struct wined3d_swapchain *  swapchain)
static

Definition at line 643 of file swapchain.c.

644{
645 struct wined3d_texture *front_buffer = swapchain->front_buffer;
646 struct wined3d_context *context;
647
648 context = context_acquire(swapchain->device, front_buffer, 0);
649 wined3d_texture_load_location(front_buffer, 0, context, front_buffer->resource.draw_binding);
651 SetRectEmpty(&swapchain->front_buffer_update);
652}
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)
struct wined3d_swapchain * swapchain
static void context_release(struct wined3d_context *context)
static struct wined3d_context * context_acquire(struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)

◆ swapchain_gdi_frontbuffer_updated()

static void swapchain_gdi_frontbuffer_updated ( struct wined3d_swapchain *  swapchain)
static

Definition at line 1274 of file swapchain.c.

1275{
1276 struct wined3d_dc_info *front;
1277 POINT offset = {0, 0};
1278 HDC src_dc, dst_dc;
1279 RECT draw_rect;
1280 HWND window;
1281
1282 TRACE("swapchain %p.\n", swapchain);
1283
1284 front = &swapchain->front_buffer->dc_info[0];
1285 if (swapchain->palette)
1286 wined3d_palette_apply_to_dc(swapchain->palette, front->dc);
1287
1288 if (swapchain->front_buffer->resource.map_count)
1289 ERR("Trying to blit a mapped surface.\n");
1290
1291 TRACE("Copying surface %p to screen.\n", front);
1292
1293 src_dc = front->dc;
1294 window = swapchain->win_handle;
1295 dst_dc = GetDCEx(window, 0, DCX_CLIPSIBLINGS | DCX_CACHE);
1296
1297 /* Front buffer coordinates are screen coordinates. Map them to the
1298 * destination window if not fullscreened. */
1299 if (swapchain->state.desc.windowed)
1301
1302 TRACE("offset %s.\n", wine_dbgstr_point(&offset));
1303
1304 SetRect(&draw_rect, 0, 0, swapchain->front_buffer->resource.width,
1305 swapchain->front_buffer->resource.height);
1306 IntersectRect(&draw_rect, &draw_rect, &swapchain->front_buffer_update);
1307
1308 BitBlt(dst_dc, draw_rect.left - offset.x, draw_rect.top - offset.y,
1309 draw_rect.right - draw_rect.left, draw_rect.bottom - draw_rect.top,
1310 src_dc, draw_rect.left, draw_rect.top, SRCCOPY);
1311 ReleaseDC(window, dst_dc);
1312
1313 SetRectEmpty(&swapchain->front_buffer_update);
1314}
static const char * wine_dbgstr_point(const POINT *ppt)
Definition: atltest.h:138
void CDECL wined3d_palette_apply_to_dc(const struct wined3d_palette *palette, HDC dc)
Definition: palette.c:91
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Height *Stride) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Stride)
Definition: common.c:42
GLintptr offset
Definition: glext.h:5920
static IHTMLWindow2 * window
Definition: events.c:77
#define DCX_CLIPSIBLINGS
Definition: winuser.h:2152
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
Definition: dcommon.idl:28
struct wined3d_palette * palette
struct wined3d_texture * front_buffer

Referenced by swapchain_gdi_present().

◆ swapchain_gdi_present()

static void swapchain_gdi_present ( struct wined3d_swapchain *  swapchain,
const RECT *  src_rect,
const RECT *  dst_rect,
unsigned int  swap_interval,
uint32_t  flags 
)
static

Definition at line 1316 of file swapchain.c.

1318{
1319 struct wined3d_dc_info *front, *back;
1321 void *data;
1322 HDC dc;
1323
1324 front = &swapchain->front_buffer->dc_info[0];
1325 back = &swapchain->back_buffers[0]->dc_info[0];
1326
1327 /* Flip the surface data. */
1328 dc = front->dc;
1329 bitmap = front->bitmap;
1330 data = swapchain->front_buffer->resource.heap_memory;
1331
1332 front->dc = back->dc;
1333 front->bitmap = back->bitmap;
1334 swapchain->front_buffer->resource.heap_memory = swapchain->back_buffers[0]->resource.heap_memory;
1335
1336 back->dc = dc;
1337 back->bitmap = bitmap;
1338 swapchain->back_buffers[0]->resource.heap_memory = data;
1339
1340 SetRect(&swapchain->front_buffer_update, 0, 0,
1341 swapchain->front_buffer->resource.width,
1342 swapchain->front_buffer->resource.height);
1344}
HDC dc
Definition: cylfrac.c:34
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
struct wined3d_texture ** back_buffers
static void swapchain_gdi_frontbuffer_updated(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:1274

◆ swapchain_gl_present()

static void swapchain_gl_present ( struct wined3d_swapchain *  swapchain,
const RECT *  src_rect,
const RECT *  dst_rect,
unsigned int  swap_interval,
uint32_t  flags 
)
static

Definition at line 583 of file swapchain.c.

585{
586 struct wined3d_texture *back_buffer = swapchain->back_buffers[0];
588 const struct wined3d_gl_info *gl_info;
589 struct wined3d_context_gl *context_gl;
590 struct wined3d_context *context;
591
592 context = context_acquire(swapchain->device, swapchain->front_buffer, 0);
593 context_gl = wined3d_context_gl(context);
594 if (!context_gl->valid)
595 {
597 WARN("Invalid context, skipping present.\n");
598 return;
599 }
600
601 TRACE("Presenting DC %p.\n", context_gl->dc);
602
603 pixel_format = &wined3d_adapter_gl(swapchain->device->adapter)->pixel_formats[context_gl->pixel_format];
604 if (context_gl->dc == wined3d_device_gl(swapchain->device)->backup_dc
605 || (pixel_format->swap_method != WGL_SWAP_COPY_ARB
607 {
608 swapchain_blit_gdi(swapchain, context, src_rect, dst_rect);
609 }
610 else
611 {
612 gl_info = context_gl->gl_info;
613
614 swapchain_gl_set_swap_interval(swapchain, context_gl, swap_interval);
615
616 wined3d_texture_load_location(back_buffer, 0, context, back_buffer->resource.draw_binding);
617
618 swapchain_blit(swapchain, context, src_rect, dst_rect);
619
620 if (swapchain->device->context_count > 1)
621 {
622 WARN_(d3d_perf)("Multiple contexts, calling glFinish() to enforce ordering.\n");
623 gl_info->gl_ops.gl.p_glFinish();
624 }
625
626 /* call wglSwapBuffers through the gl table to avoid confusing the Steam overlay */
627 gl_info->gl_ops.wgl.p_wglSwapBuffers(context_gl->dc);
628 }
629
630 if (context->d3d_info->fences)
632
634
635 TRACE("SwapBuffers called, Starting new frame\n");
636
639
641}
void wined3d_context_gl_submit_command_fence(struct wined3d_context_gl *context_gl)
Definition: context_gl.c:2653
#define WARN_(ch,...)
Definition: debug.h:157
struct wined3d_pixel_format * pixel_formats
Definition: wined3d_gl.h:802
const struct wined3d_gl_info * gl_info
Definition: wined3d_gl.h:603
struct opengl_funcs gl_ops
Definition: wined3d_gl.h:353
#define WGL_SWAP_COPY_ARB
Definition: wgl.h:5200
static void swapchain_blit(const struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
Definition: swapchain.c:466
static void swapchain_blit_gdi(struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
Definition: swapchain.c:399
static void wined3d_swapchain_gl_rotate(struct wined3d_swapchain *swapchain, struct wined3d_context *context)
Definition: swapchain.c:516
static void swapchain_gl_set_swap_interval(struct wined3d_swapchain *swapchain, struct wined3d_context_gl *context_gl, unsigned int swap_interval)
Definition: swapchain.c:494
static bool swapchain_present_is_partial_copy(struct wined3d_swapchain *swapchain, const RECT *dst_rect)
Definition: swapchain.c:562

◆ swapchain_gl_set_swap_interval()

static void swapchain_gl_set_swap_interval ( struct wined3d_swapchain *  swapchain,
struct wined3d_context_gl *  context_gl,
unsigned int  swap_interval 
)
static

Definition at line 494 of file swapchain.c.

496{
497 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
498
499 swap_interval = swap_interval <= 4 ? swap_interval : 1;
500 if (swapchain->swap_interval == swap_interval)
501 return;
502
503 swapchain->swap_interval = swap_interval;
504
505 if (!gl_info->supported[WGL_EXT_SWAP_CONTROL])
506 return;
507
508 if (!GL_EXTCALL(wglSwapIntervalEXT(swap_interval)))
509 {
510 ERR("Failed to set swap interval %u for context %p, last error %#lx.\n",
511 swap_interval, context_gl, GetLastError());
512 }
513}
BOOL supported[WINED3D_GL_EXT_COUNT]
Definition: wined3d_gl.h:347
unsigned int swap_interval
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
@ WGL_EXT_SWAP_CONTROL
Definition: wined3d_gl.h:227
#define GL_EXTCALL(f)
Definition: wined3d_gl.h:360

Referenced by swapchain_gl_present().

◆ swapchain_present_is_partial_copy()

static bool swapchain_present_is_partial_copy ( struct wined3d_swapchain *  swapchain,
const RECT *  dst_rect 
)
static

Definition at line 562 of file swapchain.c.

563{
564 enum wined3d_swap_effect swap_effect = swapchain->state.desc.swap_effect;
565 RECT client_rect;
566 unsigned int t;
567
568 if (swap_effect != WINED3D_SWAP_EFFECT_COPY && swap_effect != WINED3D_SWAP_EFFECT_COPY_VSYNC)
569 return false;
570
571 GetClientRect(swapchain->win_handle, &client_rect);
572
573 t = client_rect.right - client_rect.left;
574 if ((dst_rect->left && dst_rect->right) || abs(dst_rect->right - dst_rect->left) != t)
575 return true;
576 t = client_rect.bottom - client_rect.top;
577 if ((dst_rect->top && dst_rect->bottom) || abs(dst_rect->bottom - dst_rect->top) != t)
578 return true;
579
580 return false;
581}
#define abs(i)
Definition: fconv.c:206
GLdouble GLdouble t
Definition: gl.h:2047
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
wined3d_swap_effect
Definition: wined3d.h:533
@ WINED3D_SWAP_EFFECT_COPY
Definition: wined3d.h:538
@ WINED3D_SWAP_EFFECT_COPY_VSYNC
Definition: wined3d.h:539

Referenced by swapchain_gl_present(), and swapchain_vk_present().

◆ swapchain_set_max_frame_latency()

void swapchain_set_max_frame_latency ( struct wined3d_swapchain *  swapchain,
const struct wined3d_device *  device 
)

Definition at line 1374 of file swapchain.c.

1375{
1376 /* Subtract 1 for the implicit OpenGL latency. */
1377 swapchain->max_frame_latency = device->max_frame_latency >= 2 ? device->max_frame_latency - 1 : 1;
1378}
unsigned int max_frame_latency

Referenced by wined3d_device_set_max_frame_latency(), and wined3d_swapchain_init().

◆ swapchain_update_draw_bindings()

void swapchain_update_draw_bindings ( struct wined3d_swapchain *  swapchain)

Definition at line 1814 of file swapchain.c.

1815{
1816 UINT i;
1817
1819
1820 for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
1821 {
1822 wined3d_resource_update_draw_binding(&swapchain->back_buffers[i]->resource);
1823 }
1824}
void wined3d_resource_update_draw_binding(struct wined3d_resource *resource)
Definition: resource.c:425
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by wined3d_swapchain_resize_buffers().

◆ swapchain_vk_present()

static void swapchain_vk_present ( struct wined3d_swapchain *  swapchain,
const RECT *  src_rect,
const RECT *  dst_rect,
unsigned int  swap_interval,
uint32_t  flags 
)
static

Definition at line 1222 of file swapchain.c.

1224{
1225 struct wined3d_swapchain_vk *swapchain_vk = wined3d_swapchain_vk(swapchain);
1226 struct wined3d_texture *back_buffer = swapchain->back_buffers[0];
1227 struct wined3d_context_vk *context_vk;
1228 VkResult vr;
1229 HRESULT hr;
1230
1231 context_vk = wined3d_context_vk(context_acquire(swapchain->device, back_buffer, 0));
1232
1233 if (!swapchain_vk->vk_swapchain || swapchain_present_is_partial_copy(swapchain, dst_rect))
1234 {
1235 swapchain_blit_gdi(swapchain, &context_vk->c, src_rect, dst_rect);
1236 }
1237 else
1238 {
1239 wined3d_texture_load_location(back_buffer, 0, &context_vk->c, back_buffer->resource.draw_binding);
1240
1241 if ((vr = wined3d_swapchain_vk_blit(swapchain_vk, context_vk, src_rect, dst_rect, swap_interval)))
1242 {
1244 {
1245 if (FAILED(hr = wined3d_swapchain_vk_recreate(swapchain_vk)))
1246 ERR("Failed to recreate swapchain, hr %#lx.\n", hr);
1248 swapchain_vk, context_vk, src_rect, dst_rect, swap_interval)))
1249 ERR("Failed to blit image, vr %s.\n", wined3d_debug_vkresult(vr));
1250 }
1251 else
1252 {
1253 ERR("Failed to blit image, vr %s.\n", wined3d_debug_vkresult(vr));
1254 }
1255 }
1256 }
1257
1258 wined3d_swapchain_vk_rotate(swapchain, context_vk);
1259
1262
1263 TRACE("Starting new frame.\n");
1264
1265 context_release(&context_vk->c);
1266}
const char * wined3d_debug_vkresult(VkResult vr)
Definition: utils.c:5463
struct wined3d_context c
Definition: wined3d_vk.h:588
VkSwapchainKHR vk_swapchain
Definition: wined3d_vk.h:1055
VkResult
Definition: vulkan.h:4639
@ VK_SUBOPTIMAL_KHR
Definition: vulkan.h:4678
@ VK_ERROR_OUT_OF_DATE_KHR
Definition: vulkan.h:4656
static VkResult wined3d_swapchain_vk_blit(struct wined3d_swapchain_vk *swapchain_vk, struct wined3d_context_vk *context_vk, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval)
Definition: swapchain.c:1039
static void wined3d_swapchain_vk_rotate(struct wined3d_swapchain *swapchain, struct wined3d_context_vk *context_vk)
Definition: swapchain.c:1167
static HRESULT wined3d_swapchain_vk_recreate(struct wined3d_swapchain_vk *swapchain_vk)
Definition: swapchain.c:1013

◆ topmost_timer_proc()

static void CALLBACK topmost_timer_proc ( HWND  hwnd,
UINT  msg,
UINT_PTR  id,
DWORD  time 
)
static

Definition at line 2159 of file swapchain.c.

2160{
2163
2165}
#define WS_EX_TOPMOST
Definition: pedump.c:647
#define SWP_NOACTIVATE
Definition: winuser.h:1253
#define HWND_TOPMOST
Definition: winuser.h:1219
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
#define SWP_NOMOVE
Definition: winuser.h:1255
#define SWP_NOSIZE
Definition: winuser.h:1256
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by set_window_state().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( d3d_perf  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_swapchain_activate()

void wined3d_swapchain_activate ( struct wined3d_swapchain *  swapchain,
BOOL  activate 
)

Definition at line 1826 of file swapchain.c.

1827{
1828 struct wined3d_device *device = swapchain->device;
1829 HWND window = swapchain->state.device_window;
1830 struct wined3d_output_desc output_desc;
1831 unsigned int screensaver_active;
1832 struct wined3d_output *output;
1833 BOOL focus_messages, filter;
1834 HRESULT hr;
1835
1836 /* This code is not protected by the wined3d mutex, so it may run while
1837 * wined3d_device_reset is active. Testing on Windows shows that changing
1838 * focus during resets and resetting during focus change events causes
1839 * the application to crash with an invalid memory access. */
1840
1841 if (!(focus_messages = device->wined3d->flags & WINED3D_FOCUS_MESSAGES))
1843
1844 if (activate)
1845 {
1846 SystemParametersInfoW(SPI_GETSCREENSAVEACTIVE, 0, &screensaver_active, 0);
1847 if ((device->restore_screensaver = !!screensaver_active))
1849
1850 if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES))
1851 {
1852 /* The d3d versions do not agree on the exact messages here. D3d8 restores
1853 * the window but leaves the size untouched, d3d9 sets the size on an
1854 * invisible window, generates messages but doesn't change the window
1855 * properties. The implementation follows d3d9.
1856 *
1857 * Guild Wars 1 wants a WINDOWPOSCHANGED message on the device window to
1858 * resume drawing after a focus loss. */
1859 output = wined3d_swapchain_get_output(swapchain);
1860 if (!output)
1861 {
1862 ERR("Failed to get output from swapchain %p.\n", swapchain);
1863 return;
1864 }
1865
1866 if (SUCCEEDED(hr = wined3d_output_get_desc(output, &output_desc)))
1867 SetWindowPos(window, NULL, output_desc.desktop_rect.left,
1868 output_desc.desktop_rect.top, swapchain->state.desc.backbuffer_width,
1869 swapchain->state.desc.backbuffer_height, SWP_NOACTIVATE | SWP_NOZORDER);
1870 else
1871 ERR("Failed to get output description, hr %#lx.\n", hr);
1872 }
1873
1874 if (device->wined3d->flags & WINED3D_RESTORE_MODE_ON_ACTIVATE)
1875 {
1876 output = wined3d_swapchain_get_output(swapchain);
1877 if (!output)
1878 {
1879 ERR("Failed to get output from swapchain %p.\n", swapchain);
1880 return;
1881 }
1882
1884 &swapchain->state.d3d_mode)))
1885 ERR("Failed to set display mode, hr %#lx.\n", hr);
1886 }
1887
1888 if (swapchain == device->swapchains[0])
1889 device->device_parent->ops->activate(device->device_parent, TRUE);
1890 }
1891 else
1892 {
1893 if (device->restore_screensaver)
1894 {
1896 device->restore_screensaver = FALSE;
1897 }
1898
1900 ERR("Failed to restore display modes, hr %#lx.\n", hr);
1901
1902 swapchain->reapply_mode = TRUE;
1903
1904 /* Some DDraw apps (Deus Ex: GOTY, and presumably all UT 1 based games) destroy the device
1905 * during window minimization. Do our housekeeping now, as the device may not exist after
1906 * the ShowWindow call.
1907 *
1908 * In d3d9, the device is marked lost after the window is minimized. If we find an app
1909 * that needs this behavior (e.g. because it calls TestCooperativeLevel in the window proc)
1910 * we'll have to control this via a create flag. Note that the device and swapchain are not
1911 * safe to access after the ShowWindow call. */
1912 if (swapchain == device->swapchains[0])
1913 device->device_parent->ops->activate(device->device_parent, FALSE);
1914
1915 if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES) && IsWindowVisible(window))
1917 }
1918
1919 if (!focus_messages)
1921}
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SUCCEEDED(hr)
Definition: intsafe.h:50
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SW_MINIMIZE
Definition: winuser.h:787
#define SPI_SETSCREENSAVEACTIVE
Definition: winuser.h:1377
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
#define SWP_NOZORDER
Definition: winuser.h:1258
BOOL WINAPI IsWindowVisible(_In_ HWND)
#define SPI_GETSCREENSAVEACTIVE
Definition: winuser.h:1376
HRESULT CDECL wined3d_output_set_display_mode(struct wined3d_output *output, const struct wined3d_display_mode *mode)
Definition: directx.c:1693
HRESULT CDECL wined3d_restore_display_modes(struct wined3d *wined3d)
Definition: directx.c:1618
HRESULT CDECL wined3d_output_get_desc(const struct wined3d_output *output, struct wined3d_output_desc *desc)
Definition: directx.c:1256
struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain)
Definition: swapchain.c:287
#define WINED3D_RESTORE_MODE_ON_ACTIVATE
Definition: wined3d.h:1325
#define WINED3DCREATE_NOWINDOWCHANGES
Definition: wined3d.h:1029
#define WINED3D_FOCUS_MESSAGES
Definition: wined3d.h:1326

Referenced by device_process_message().

◆ wined3d_swapchain_apply_sample_count_override()

static void wined3d_swapchain_apply_sample_count_override ( const struct wined3d_swapchain *  swapchain,
enum wined3d_format_id  format_id,
enum wined3d_multisample_type *  type,
unsigned int *  quality 
)
static

Definition at line 1352 of file swapchain.c.

1354{
1355 const struct wined3d_adapter *adapter;
1356 const struct wined3d_format *format;
1358
1360 return;
1361
1362 adapter = swapchain->device->adapter;
1364 return;
1365
1366 if ((t = min(wined3d_settings.sample_count, adapter->d3d_info.limits.sample_count)))
1367 while (!(format->multisample_types & 1u << (t - 1)))
1368 ++t;
1369 TRACE("Using sample count %u.\n", t);
1370 *type = t;
1371 *quality = 0;
1372}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
int quality
Definition: jpeglib.h:994
#define min(a, b)
Definition: monoChain.cc:55
unsigned int sample_count
wined3d_multisample_type
Definition: wined3d.h:572

Referenced by wined3d_swapchain_init(), and wined3d_swapchain_resize_buffers().

◆ wined3d_swapchain_cleanup()

void wined3d_swapchain_cleanup ( struct wined3d_swapchain *  swapchain)

Definition at line 30 of file swapchain.c.

31{
32 HRESULT hr;
33 UINT i;
34
35 TRACE("Destroying swapchain %p.\n", swapchain);
36
38 wined3d_swapchain_set_gamma_ramp(swapchain, 0, &swapchain->orig_gamma);
39
40 /* Release the swapchain's draw buffers. Make sure swapchain->back_buffers[0]
41 * is the last buffer to be destroyed, FindContext() depends on that. */
42 if (swapchain->front_buffer)
43 {
46 WARN("Something's still holding the front buffer (%p).\n", swapchain->front_buffer);
47 swapchain->front_buffer = NULL;
48 }
49
50 if (swapchain->back_buffers)
51 {
52 i = swapchain->state.desc.backbuffer_count;
53
54 while (i--)
55 {
57 if (wined3d_texture_decref(swapchain->back_buffers[i]))
58 WARN("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
59 }
60 free(swapchain->back_buffers);
61 swapchain->back_buffers = NULL;
62 }
63
64 /* Restore the screen resolution if we rendered in fullscreen.
65 * This will restore the screen resolution to what it was before creating
66 * the swapchain. In case of d3d8 and d3d9 this will be the original
67 * desktop resolution. In case of d3d7 this will be a NOP because ddraw
68 * sets the resolution before starting up Direct3D, thus orig_width and
69 * orig_height will be equal to the modes in the presentation params. */
70 if (!swapchain->state.desc.windowed)
71 {
72 if (swapchain->state.desc.auto_restore_display_mode)
73 {
74 if (FAILED(hr = wined3d_restore_display_modes(swapchain->device->wined3d)))
75 ERR("Failed to restore display mode, hr %#lx.\n", hr);
76
77 if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
78 {
80 swapchain->state.device_window, &swapchain->state.original_window_rect);
82 }
83 }
84 else
85 {
86 wined3d_swapchain_state_restore_from_fullscreen(&swapchain->state, swapchain->state.device_window, NULL);
87 }
88 }
89}
void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
Definition: device.c:1154
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
Definition: texture.c:1606
struct wined3d_gamma_ramp orig_gamma
HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *swapchain, uint32_t flags, const struct wined3d_gamma_ramp *ramp)
Definition: swapchain.c:353
void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state, HWND window, const RECT *window_rect)
Definition: swapchain.c:2275
#define WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT
Definition: wined3d.h:899
void wined3d_swapchain_state_cleanup(struct wined3d_swapchain_state *state)
Definition: wined3d_main.c:942

Referenced by adapter_no3d_destroy_swapchain(), wined3d_swapchain_gl_cleanup(), and wined3d_swapchain_vk_cleanup().

◆ wined3d_swapchain_create()

HRESULT CDECL wined3d_swapchain_create ( struct wined3d_device *  device,
const struct wined3d_swapchain_desc *  desc,
struct wined3d_swapchain_state_parent *  state_parent,
void *  parent,
const struct wined3d_parent_ops *  parent_ops,
struct wined3d_swapchain **  swapchain 
)

Definition at line 1732 of file swapchain.c.

1736{
1737 struct wined3d_swapchain *object;
1738 HRESULT hr;
1739
1740 if (FAILED(hr = device->adapter->adapter_ops->adapter_create_swapchain(device,
1741 desc, state_parent, parent, parent_ops, &object)))
1742 return hr;
1743
1744 if (desc->flags & WINED3D_SWAPCHAIN_IMPLICIT)
1745 {
1748 {
1750 device->adapter->adapter_ops->adapter_destroy_swapchain(object);
1752 return hr;
1753 }
1755 }
1756
1757 *swapchain = object;
1758
1759 return hr;
1760}
HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
Definition: device.c:1537
r parent
Definition: btrfs.c:3010
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
const struct wined3d_parent_ops * parent_ops
#define WINED3D_SWAPCHAIN_IMPLICIT
Definition: wined3d.h:901
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
static void wined3d_cs_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
@ WINED3D_CS_QUEUE_DEFAULT

Referenced by d3d11_swapchain_init(), ddraw_attach_d3d_device(), dxgi_device_init(), and swapchain_init().

◆ wined3d_swapchain_decref()

ULONG CDECL wined3d_swapchain_decref ( struct wined3d_swapchain *  swapchain)

Definition at line 144 of file swapchain.c.

145{
146 unsigned int refcount = InterlockedDecrement(&swapchain->ref);
147
148 TRACE("%p decreasing refcount to %u.\n", swapchain, refcount);
149
150 if (!refcount)
151 {
152 struct wined3d_device *device;
153
155
156 device = swapchain->device;
157 if (device->swapchain_count && device->swapchains[0] == swapchain)
160
161 swapchain->parent_ops->wined3d_object_destroyed(swapchain->parent);
162 swapchain->device->adapter->adapter_ops->adapter_destroy_swapchain(swapchain);
163
165 }
166
167 return refcount;
168}
#define InterlockedDecrement
Definition: armddk.h:52
void wined3d_device_uninit_3d(struct wined3d_device *device)
Definition: device.c:1662

Referenced by d3d11_swapchain_init(), d3d11_swapchain_Release(), d3d11_texture2d_Release(), d3d8_device_Release(), d3d8_surface_Release(), d3d8_swapchain_Release(), d3d9_device_Release(), d3d9_device_reset(), d3d9_surface_Release(), d3d9_swapchain_Release(), ddraw_attach_d3d_device(), ddraw_destroy_swapchain(), device_init(), and dxgi_device_Release().

◆ wined3d_swapchain_get_back_buffer()

struct wined3d_texture *CDECL wined3d_swapchain_get_back_buffer ( const struct wined3d_swapchain *  swapchain,
UINT  back_buffer_idx 
)

Definition at line 256 of file swapchain.c.

258{
259 TRACE("swapchain %p, back_buffer_idx %u.\n",
260 swapchain, back_buffer_idx);
261
262 /* Return invalid if there is no backbuffer array, otherwise it will
263 * crash when ddraw is used (there swapchain->back_buffers is always
264 * NULL). We need this because this function is called from
265 * stateblock_init_default_state() to get the default scissorrect
266 * dimensions. */
267 if (!swapchain->back_buffers || back_buffer_idx >= swapchain->state.desc.backbuffer_count)
268 {
269 WARN("Invalid back buffer index.\n");
270 /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it
271 * here in wined3d to avoid problems in other libs. */
272 return NULL;
273 }
274
275 TRACE("Returning back buffer %p.\n", swapchain->back_buffers[back_buffer_idx]);
276
277 return swapchain->back_buffers[back_buffer_idx];
278}

Referenced by d3d11_swapchain_create_d3d11_textures(), d3d11_swapchain_GetBuffer(), d3d11_swapchain_ResizeBuffers(), d3d8_device_GetBackBuffer(), d3d8_device_Reset(), d3d8_swapchain_create(), d3d8_swapchain_GetBackBuffer(), d3d9_device_reset(), d3d9_swapchain_create(), d3d9_swapchain_GetBackBuffer(), ddraw_surface_update_frontbuffer(), and dxgi_resource_GetUsage().

◆ wined3d_swapchain_get_desc()

◆ wined3d_swapchain_get_device()

struct wined3d_device *CDECL wined3d_swapchain_get_device ( const struct wined3d_swapchain *  swapchain)

Definition at line 338 of file swapchain.c.

339{
340 TRACE("swapchain %p.\n", swapchain);
341
342 return swapchain->device;
343}

◆ wined3d_swapchain_get_display_mode()

HRESULT CDECL wined3d_swapchain_get_display_mode ( const struct wined3d_swapchain *  swapchain,
struct wined3d_display_mode *  mode,
enum wined3d_display_rotation *  rotation 
)

Definition at line 316 of file swapchain.c.

318{
319 struct wined3d_output *output;
320 HRESULT hr;
321
322 TRACE("swapchain %p, mode %p, rotation %p.\n", swapchain, mode, rotation);
323
324 if (!(output = wined3d_swapchain_get_output(swapchain)))
325 {
326 ERR("Failed to get output from swapchain %p.\n", swapchain);
327 return E_FAIL;
328 }
329
330 hr = wined3d_output_get_display_mode(output, mode, rotation);
331
332 TRACE("Returning w %u, h %u, refresh rate %u, format %s.\n",
333 mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id));
334
335 return hr;
336}
#define E_FAIL
Definition: ddrawi.h:102
GLenum mode
Definition: glext.h:6217
HRESULT CDECL wined3d_output_get_display_mode(const struct wined3d_output *output, struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
Definition: directx.c:1515

Referenced by d3d9_swapchain_GetDisplayMode(), d3d9_swapchain_GetDisplayModeEx(), ddraw_surface7_Restore(), and wined3d_device_get_display_mode().

◆ wined3d_swapchain_get_front_buffer()

struct wined3d_texture *CDECL wined3d_swapchain_get_front_buffer ( const struct wined3d_swapchain *  swapchain)

Definition at line 280 of file swapchain.c.

281{
282 TRACE("swapchain %p.\n", swapchain);
283
284 return swapchain->front_buffer;
285}

Referenced by ddraw_surface_update_frontbuffer().

◆ wined3d_swapchain_get_front_buffer_data()

HRESULT CDECL wined3d_swapchain_get_front_buffer_data ( const struct wined3d_swapchain *  swapchain,
struct wined3d_texture *  dst_texture,
unsigned int  sub_resource_idx 
)

Definition at line 235 of file swapchain.c.

237{
238 RECT src_rect, dst_rect;
239
240 TRACE("swapchain %p, dst_texture %p, sub_resource_idx %u.\n", swapchain, dst_texture, sub_resource_idx);
241
242 SetRect(&src_rect, 0, 0, swapchain->front_buffer->resource.width, swapchain->front_buffer->resource.height);
243 dst_rect = src_rect;
244
245 if (swapchain->state.desc.windowed)
246 {
247 MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2);
248 FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n",
249 wine_dbgstr_rect(&dst_rect));
250 }
251
252 return wined3d_device_context_blt(&swapchain->device->cs->c, dst_texture, sub_resource_idx, &dst_rect,
253 swapchain->front_buffer, 0, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
254}
HRESULT CDECL wined3d_device_context_blt(struct wined3d_device_context *context, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, const RECT *dst_rect, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, const RECT *src_rect, unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
Definition: texture.c:3854
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
@ WINED3D_TEXF_POINT
Definition: wined3d.h:706

Referenced by d3d8_device_GetFrontBuffer(), d3d9_device_GetFrontBufferData(), and d3d9_swapchain_GetFrontBufferData().

◆ wined3d_swapchain_get_gamma_ramp()

HRESULT CDECL wined3d_swapchain_get_gamma_ramp ( const struct wined3d_swapchain *  swapchain,
struct wined3d_gamma_ramp *  ramp 
)

Definition at line 381 of file swapchain.c.

383{
384 struct wined3d_output *output;
385
386 TRACE("swapchain %p, ramp %p.\n", swapchain, ramp);
387
388 if (!(output = wined3d_swapchain_get_output(swapchain)))
389 {
390 ERR("Failed to get output from swapchain %p.\n", swapchain);
391 return E_FAIL;
392 }
393
394 return wined3d_output_get_gamma_ramp(output, ramp);
395}
static const BYTE ramp[17]
Definition: dib.c:2957
HRESULT wined3d_output_get_gamma_ramp(struct wined3d_output *output, struct wined3d_gamma_ramp *ramp)
Definition: directx.c:1772

Referenced by wined3d_device_get_gamma_ramp(), and wined3d_swapchain_init().

◆ wined3d_swapchain_get_output()

struct wined3d_output * wined3d_swapchain_get_output ( const struct wined3d_swapchain *  swapchain)

Definition at line 287 of file swapchain.c.

288{
289 TRACE("swapchain %p.\n", swapchain);
290
291 return swapchain->state.desc.output;
292}

Referenced by wined3d_swapchain_activate(), wined3d_swapchain_get_display_mode(), wined3d_swapchain_get_gamma_ramp(), wined3d_swapchain_get_raster_status(), and wined3d_swapchain_set_gamma_ramp().

◆ wined3d_swapchain_get_parent()

void *CDECL wined3d_swapchain_get_parent ( const struct wined3d_swapchain *  swapchain)

Definition at line 170 of file swapchain.c.

171{
172 TRACE("swapchain %p.\n", swapchain);
173
174 return swapchain->parent;
175}

Referenced by d3d8_device_Present(), d3d8_device_Reset(), d3d9_device_GetBackBuffer(), d3d9_device_GetSwapChain(), d3d9_device_Present(), d3d9_device_PresentEx(), and d3d9_device_reset().

◆ wined3d_swapchain_get_raster_status()

HRESULT CDECL wined3d_swapchain_get_raster_status ( const struct wined3d_swapchain *  swapchain,
struct wined3d_raster_status *  raster_status 
)

Definition at line 294 of file swapchain.c.

296{
297 struct wined3d_output *output;
298
299 TRACE("swapchain %p, raster_status %p.\n", swapchain, raster_status);
300
301 output = wined3d_swapchain_get_output(swapchain);
302 if (!output)
303 {
304 ERR("Failed to get output from swapchain %p.\n", swapchain);
305 return E_FAIL;
306 }
307
308 return wined3d_output_get_raster_status(output, raster_status);
309}
HRESULT CDECL wined3d_output_get_raster_status(const struct wined3d_output *output, struct wined3d_raster_status *raster_status)
Definition: directx.c:1814

Referenced by d3d9_swapchain_GetRasterStatus(), and wined3d_device_get_raster_status().

◆ wined3d_swapchain_get_state()

struct wined3d_swapchain_state *CDECL wined3d_swapchain_get_state ( struct wined3d_swapchain *  swapchain)

Definition at line 311 of file swapchain.c.

312{
313 return &swapchain->state;
314}

Referenced by d3d11_swapchain_init(), d3d11_swapchain_ResizeTarget(), and d3d11_swapchain_SetFullscreenState().

◆ wined3d_swapchain_gl_cleanup()

void wined3d_swapchain_gl_cleanup ( struct wined3d_swapchain_gl *  swapchain_gl)

Definition at line 91 of file swapchain.c.

92{
93 wined3d_swapchain_cleanup(&swapchain_gl->s);
94}
struct wined3d_swapchain s
Definition: wined3d_gl.h:1126
void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:30

Referenced by adapter_gl_destroy_swapchain().

◆ wined3d_swapchain_gl_create_context()

static struct wined3d_context_gl * wined3d_swapchain_gl_create_context ( struct wined3d_swapchain_gl *  swapchain_gl)
static

Definition at line 1762 of file swapchain.c.

1763{
1764 struct wined3d_device *device = swapchain_gl->s.device;
1765 struct wined3d_context_gl *context_gl;
1766
1767 TRACE("Creating a new context for swapchain %p, thread %lu.\n", swapchain_gl, GetCurrentThreadId());
1768
1770
1771 if (!(context_gl = calloc(1, sizeof(*context_gl))))
1772 {
1773 ERR("Failed to allocate context memory.\n");
1774 return NULL;
1775 }
1776
1777 if (FAILED(wined3d_context_gl_init(context_gl, swapchain_gl)))
1778 {
1779 WARN("Failed to initialise context.\n");
1780 free(context_gl);
1781 return NULL;
1782 }
1783
1784 if (!device_context_add(device, &context_gl->c))
1785 {
1786 ERR("Failed to add the newly created context to the context list.\n");
1787 wined3d_context_gl_destroy(context_gl);
1788 return NULL;
1789 }
1790
1791 TRACE("Created context %p.\n", context_gl);
1792
1793 context_release(&context_gl->c);
1794
1795 return context_gl;
1796}
HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wined3d_swapchain_gl *swapchain_gl)
Definition: context_gl.c:2032
void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl)
Definition: context_gl.c:2308
BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context)
Definition: device.c:84
#define calloc
Definition: rosglue.h:14
struct wined3d_context c
Definition: wined3d_gl.h:601
static void wined3d_from_cs(const struct wined3d_cs *cs)

Referenced by wined3d_swapchain_gl_get_context().

◆ wined3d_swapchain_gl_get_context()

struct wined3d_context_gl * wined3d_swapchain_gl_get_context ( struct wined3d_swapchain_gl *  swapchain_gl)

Definition at line 1798 of file swapchain.c.

1799{
1800 struct wined3d_device *device = swapchain_gl->s.device;
1802 unsigned int i;
1803
1804 for (i = 0; i < device->context_count; ++i)
1805 {
1806 if (wined3d_context_gl(device->contexts[i])->tid == tid)
1807 return wined3d_context_gl(device->contexts[i]);
1808 }
1809
1810 /* Create a new context for the thread. */
1811 return wined3d_swapchain_gl_create_context(swapchain_gl);
1812}
static struct wined3d_context_gl * wined3d_swapchain_gl_create_context(struct wined3d_swapchain_gl *swapchain_gl)
Definition: swapchain.c:1762

Referenced by wined3d_context_gl_acquire().

◆ wined3d_swapchain_gl_init()

HRESULT wined3d_swapchain_gl_init ( struct wined3d_swapchain_gl *  swapchain_gl,
struct wined3d_device *  device,
const struct wined3d_swapchain_desc *  desc,
struct wined3d_swapchain_state_parent *  state_parent,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 1696 of file swapchain.c.

1699{
1700 TRACE("swapchain_gl %p, device %p, desc %p, state_parent %p, parent %p, parent_ops %p.\n",
1701 swapchain_gl, device, desc, state_parent, parent, parent_ops);
1702
1703 return wined3d_swapchain_init(&swapchain_gl->s, device, desc, state_parent, parent,
1704 parent_ops, &swapchain_gl_ops);
1705}
static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_swapchain_ops *swapchain_ops)
Definition: swapchain.c:1506
static const struct wined3d_swapchain_ops swapchain_gl_ops
Definition: swapchain.c:654

Referenced by adapter_gl_create_swapchain().

◆ wined3d_swapchain_gl_rotate()

static void wined3d_swapchain_gl_rotate ( struct wined3d_swapchain *  swapchain,
struct wined3d_context *  context 
)
static

Definition at line 516 of file swapchain.c.

517{
518 struct wined3d_texture_sub_resource *sub_resource;
519 struct wined3d_texture_gl *texture, *texture_prev;
520 struct gl_texture tex0;
521 GLuint rb0;
522 DWORD locations0;
523 unsigned int i;
524 static const DWORD supported_locations = WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_RB_MULTISAMPLE;
525
526 if (swapchain->state.desc.backbuffer_count < 2)
527 return;
528
529 texture_prev = wined3d_texture_gl(swapchain->back_buffers[0]);
530
531 /* Back buffer 0 is already in the draw binding. */
532 tex0 = texture_prev->texture_rgb;
533 rb0 = texture_prev->rb_multisample;
534 locations0 = texture_prev->t.sub_resources[0].locations;
535
536 for (i = 1; i < swapchain->state.desc.backbuffer_count; ++i)
537 {
539 sub_resource = &texture->t.sub_resources[0];
540
541 if (!(sub_resource->locations & supported_locations))
542 wined3d_texture_load_location(&texture->t, 0, context, texture->t.resource.draw_binding);
543
544 texture_prev->texture_rgb = texture->texture_rgb;
545 texture_prev->rb_multisample = texture->rb_multisample;
546
547 wined3d_texture_validate_location(&texture_prev->t, 0, sub_resource->locations & supported_locations);
548 wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(sub_resource->locations & supported_locations));
549
550 texture_prev = texture;
551 }
552
553 texture_prev->texture_rgb = tex0;
554 texture_prev->rb_multisample = rb0;
555
556 wined3d_texture_validate_location(&texture_prev->t, 0, locations0 & supported_locations);
557 wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(locations0 & supported_locations));
558
560}
void device_invalidate_state(const struct wined3d_device *device, unsigned int state_id)
Definition: device.c:5565
unsigned int GLuint
Definition: gl.h:159
struct wined3d_texture t
Definition: wined3d_gl.h:941
#define WINED3D_LOCATION_RB_MULTISAMPLE
#define STATE_FRAMEBUFFER

Referenced by swapchain_gl_present().

◆ wined3d_swapchain_incref()

ULONG CDECL wined3d_swapchain_incref ( struct wined3d_swapchain *  swapchain)

Definition at line 135 of file swapchain.c.

136{
137 unsigned int refcount = InterlockedIncrement(&swapchain->ref);
138
139 TRACE("%p increasing refcount to %u.\n", swapchain, refcount);
140
141 return refcount;
142}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by d3d11_swapchain_AddRef(), d3d11_texture2d_AddRef(), d3d8_surface_AddRef(), d3d8_swapchain_AddRef(), d3d9_surface_AddRef(), d3d9_swapchain_AddRef(), d3d_texture2d_create(), ddraw_create_swapchain(), and device_init().

◆ wined3d_swapchain_init()

static HRESULT wined3d_swapchain_init ( struct wined3d_swapchain *  swapchain,
struct wined3d_device *  device,
const struct wined3d_swapchain_desc *  desc,
struct wined3d_swapchain_state_parent *  state_parent,
void *  parent,
const struct wined3d_parent_ops *  parent_ops,
const struct wined3d_swapchain_ops *  swapchain_ops 
)
static

Definition at line 1506 of file swapchain.c.

1510{
1511 struct wined3d_output_desc output_desc;
1512 BOOL displaymode_set = FALSE;
1513 HRESULT hr = E_FAIL;
1514 unsigned int i;
1515 HWND window;
1516
1518
1519 if (desc->backbuffer_count > 1)
1520 {
1521 FIXME("The application requested more than one back buffer, this is not properly supported.\n"
1522 "Please configure the application to use double buffering (1 back buffer) if possible.\n");
1523 }
1524
1525 if (desc->swap_effect != WINED3D_SWAP_EFFECT_DISCARD
1526 && desc->swap_effect != WINED3D_SWAP_EFFECT_SEQUENTIAL
1527 && desc->swap_effect != WINED3D_SWAP_EFFECT_COPY)
1528 FIXME("Unimplemented swap effect %#x.\n", desc->swap_effect);
1529
1530 window = desc->device_window ? desc->device_window : device->create_parms.focus_window;
1531 TRACE("Using target window %p.\n", window);
1532
1533 if (FAILED(hr = wined3d_swapchain_state_init(&swapchain->state, desc, window, device->wined3d, state_parent)))
1534 {
1535 ERR("Failed to initialise swapchain state, hr %#lx.\n", hr);
1537 return hr;
1538 }
1539
1540 swapchain->swapchain_ops = swapchain_ops;
1541 swapchain->device = device;
1542 swapchain->parent = parent;
1543 swapchain->parent_ops = parent_ops;
1544 swapchain->ref = 1;
1545 swapchain->win_handle = window;
1548
1549 if (!swapchain->state.desc.windowed)
1550 {
1551 if (FAILED(hr = wined3d_output_get_desc(desc->output, &output_desc)))
1552 {
1553 ERR("Failed to get output description, hr %#lx.\n", hr);
1554 goto err;
1555 }
1556
1558 output_desc.desktop_rect.left, output_desc.desktop_rect.top, desc->backbuffer_width,
1559 desc->backbuffer_height);
1560 }
1561 wined3d_swapchain_apply_sample_count_override(swapchain, swapchain->state.desc.backbuffer_format,
1562 &swapchain->state.desc.multisample_type, &swapchain->state.desc.multisample_quality);
1563
1564 TRACE("Creating front buffer.\n");
1565
1566 if (FAILED(hr = swapchain_create_texture(swapchain, true, false, &swapchain->front_buffer)))
1567 {
1568 WARN("Failed to create front buffer, hr %#lx.\n", hr);
1569 goto err;
1570 }
1571
1572 if (!(device->wined3d->flags & WINED3D_NO3D))
1573 {
1576 }
1577
1578 /* MSDN says we're only allowed a single fullscreen swapchain per device,
1579 * so we should really check to see if there is a fullscreen swapchain
1580 * already. Does a single head count as full screen? */
1581 if (!desc->windowed && desc->flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
1582 {
1583 /* Change the display settings */
1585 &swapchain->state.d3d_mode)))
1586 {
1587 WARN("Failed to set display mode, hr %#lx.\n", hr);
1588 goto err;
1589 }
1590 displaymode_set = TRUE;
1591 }
1592
1593 if (swapchain->state.desc.backbuffer_count > 0)
1594 {
1595 if (!(swapchain->back_buffers = calloc(swapchain->state.desc.backbuffer_count,
1596 sizeof(*swapchain->back_buffers))))
1597 {
1598 ERR("Failed to allocate backbuffer array memory.\n");
1599 hr = E_OUTOFMEMORY;
1600 goto err;
1601 }
1602
1603 for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
1604 {
1605 TRACE("Creating back buffer %u.\n", i);
1606 if (FAILED(hr = swapchain_create_texture(swapchain, false, false, &swapchain->back_buffers[i])))
1607 {
1608 WARN("Failed to create back buffer %u, hr %#lx.\n", i, hr);
1609 swapchain->state.desc.backbuffer_count = i;
1610 goto err;
1611 }
1612 }
1613 }
1614
1615 /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
1616 if (desc->enable_auto_depth_stencil)
1617 {
1618 TRACE("Creating depth/stencil buffer.\n");
1619 if (!device->auto_depth_stencil_view)
1620 {
1621 struct wined3d_view_desc desc;
1622 struct wined3d_texture *ds;
1623
1624 if (FAILED(hr = swapchain_create_texture(swapchain, false, true, &ds)))
1625 {
1626 WARN("Failed to create the auto depth/stencil surface, hr %#lx.\n", hr);
1627 goto err;
1628 }
1629
1630 desc.format_id = ds->resource.format->id;
1631 desc.flags = 0;
1632 desc.u.texture.level_idx = 0;
1633 desc.u.texture.level_count = 1;
1634 desc.u.texture.layer_idx = 0;
1635 desc.u.texture.layer_count = 1;
1637 &device->auto_depth_stencil_view);
1639 if (FAILED(hr))
1640 {
1641 ERR("Failed to create rendertarget view, hr %#lx.\n", hr);
1642 goto err;
1643 }
1644 }
1645 }
1646
1648
1650
1651 return WINED3D_OK;
1652
1653err:
1654 if (displaymode_set)
1655 {
1657 ERR("Failed to restore display mode.\n");
1658 }
1659
1660 if (swapchain->back_buffers)
1661 {
1662 for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
1663 {
1664 if (swapchain->back_buffers[i])
1665 {
1667 wined3d_texture_decref(swapchain->back_buffers[i]);
1668 }
1669 }
1670 free(swapchain->back_buffers);
1671 }
1672
1673 if (swapchain->front_buffer)
1674 {
1676 wined3d_texture_decref(swapchain->front_buffer);
1677 }
1678
1681
1682 return hr;
1683}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HRESULT CDECL wined3d_rendertarget_view_create(const struct wined3d_view_desc *desc, struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_rendertarget_view **view)
Definition: view.c:933
#define ds
Definition: i386-dis.c:443
#define err(...)
const struct wined3d_swapchain_ops * swapchain_ops
static void wined3d_swapchain_apply_sample_count_override(const struct wined3d_swapchain *swapchain, enum wined3d_format_id format_id, enum wined3d_multisample_type *type, unsigned int *quality)
Definition: swapchain.c:1352
HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state, HWND window, int x, int y, int width, int height)
Definition: swapchain.c:2225
static HRESULT swapchain_create_texture(struct wined3d_swapchain *swapchain, bool front, bool depth, struct wined3d_texture **texture)
Definition: swapchain.c:1456
HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain, struct wined3d_gamma_ramp *ramp)
Definition: swapchain.c:381
void swapchain_set_max_frame_latency(struct wined3d_swapchain *swapchain, const struct wined3d_device *device)
Definition: swapchain.c:1374
static HRESULT wined3d_swapchain_state_init(struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *desc, HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state_parent *parent)
Definition: swapchain.c:1389
@ WINED3D_SWAP_INTERVAL_DEFAULT
Definition: wined3d.h:550
#define WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
Definition: wined3d.h:897
#define WINED3D_OK
Definition: wined3d.h:33
@ WINED3D_SWAP_EFFECT_SEQUENTIAL
Definition: wined3d.h:535
@ WINED3D_SWAP_EFFECT_DISCARD
Definition: wined3d.h:534

Referenced by wined3d_swapchain_gl_init(), wined3d_swapchain_no3d_init(), and wined3d_swapchain_vk_init().

◆ wined3d_swapchain_no3d_init()

HRESULT wined3d_swapchain_no3d_init ( struct wined3d_swapchain *  swapchain_no3d,
struct wined3d_device *  device,
const struct wined3d_swapchain_desc *  desc,
struct wined3d_swapchain_state_parent *  state_parent,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 1685 of file swapchain.c.

1688{
1689 TRACE("swapchain_no3d %p, device %p, desc %p, state_parent %p, parent %p, parent_ops %p.\n",
1690 swapchain_no3d, device, desc, state_parent, parent, parent_ops);
1691
1692 return wined3d_swapchain_init(swapchain_no3d, device, desc, state_parent, parent, parent_ops,
1694}
static const struct wined3d_swapchain_ops swapchain_no3d_ops
Definition: swapchain.c:1346

Referenced by adapter_no3d_create_swapchain().

◆ wined3d_swapchain_present()

HRESULT CDECL wined3d_swapchain_present ( struct wined3d_swapchain *  swapchain,
const RECT *  src_rect,
const RECT *  dst_rect,
HWND  dst_window_override,
unsigned int  swap_interval,
uint32_t  flags 
)

Definition at line 192 of file swapchain.c.

195{
196 RECT s, d;
197
198 TRACE("swapchain %p, src_rect %s, dst_rect %s, dst_window_override %p, swap_interval %u, flags %#x.\n",
199 swapchain, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
200 dst_window_override, swap_interval, flags);
201
202 if (flags)
203 FIXME("Ignoring flags %#x.\n", flags);
204
206
207 if (!swapchain->back_buffers)
208 {
209 WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL.\n");
212 }
213
214 if (!src_rect)
215 {
216 SetRect(&s, 0, 0, swapchain->state.desc.backbuffer_width,
217 swapchain->state.desc.backbuffer_height);
218 src_rect = &s;
219 }
220
221 if (!dst_rect)
222 {
223 GetClientRect(swapchain->win_handle, &d);
224 dst_rect = &d;
225 }
226
227 wined3d_cs_emit_present(swapchain->device->cs, swapchain, src_rect,
228 dst_rect, dst_window_override, swap_interval, flags);
229
231
232 return WINED3D_OK;
233}
void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags)
Definition: cs.c:748
GLbitfield flags
Definition: glext.h:7161
#define d
Definition: ke_i.h:81
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:44

Referenced by d3d11_swapchain_present(), d3d8_swapchain_Present(), d3d9_device_Present(), d3d9_device_PresentEx(), d3d9_swapchain_Present(), ddraw_surface_update_frontbuffer(), and texture2d_blt().

◆ wined3d_swapchain_resize_buffers()

HRESULT CDECL wined3d_swapchain_resize_buffers ( struct wined3d_swapchain *  swapchain,
unsigned int  buffer_count,
unsigned int  width,
unsigned int  height,
enum wined3d_format_id  format_id,
enum wined3d_multisample_type  multisample_type,
unsigned int  multisample_quality 
)

Definition at line 1923 of file swapchain.c.

1926{
1927 struct wined3d_swapchain_desc *desc = &swapchain->state.desc;
1928 bool recreate = false;
1929
1930 TRACE("swapchain %p, buffer_count %u, width %u, height %u, format %s, "
1931 "multisample_type %#x, multisample_quality %#x.\n",
1934
1936
1937 if (buffer_count && buffer_count != desc->backbuffer_count)
1938 FIXME("Cannot change the back buffer count yet.\n");
1939
1941
1942 if (!width || !height)
1943 {
1944 RECT client_rect;
1945
1946 /* The application is requesting that either the swapchain width or
1947 * height be set to the corresponding dimension in the window's
1948 * client rect. */
1949
1950 if (!GetClientRect(swapchain->state.device_window, &client_rect))
1951 {
1952 ERR("Failed to get client rect, last error %#lx.\n", GetLastError());
1954 }
1955
1956 if (!width)
1957 width = client_rect.right;
1958
1959 if (!height)
1960 height = client_rect.bottom;
1961 }
1962
1963 if (width != desc->backbuffer_width || height != desc->backbuffer_height)
1964 {
1965 desc->backbuffer_width = width;
1966 desc->backbuffer_height = height;
1967 recreate = true;
1968 }
1969
1971 {
1972 if (!desc->windowed)
1974 format_id = swapchain->state.original_mode.format_id;
1975 }
1976
1977 if (format_id != desc->backbuffer_format)
1978 {
1979 desc->backbuffer_format = format_id;
1980 recreate = true;
1981 }
1982
1983 if (multisample_type != desc->multisample_type
1984 || multisample_quality != desc->multisample_quality)
1985 {
1986 desc->multisample_type = multisample_type;
1987 desc->multisample_quality = multisample_quality;
1988 recreate = true;
1989 }
1990
1991 if (recreate)
1992 {
1993 struct wined3d_texture *new_texture;
1994 HRESULT hr;
1995 UINT i;
1996
1997 TRACE("Recreating swapchain textures.\n");
1998
1999 if (FAILED(hr = swapchain_create_texture(swapchain, true, false, &new_texture)))
2000 return hr;
2002 if (wined3d_texture_decref(swapchain->front_buffer))
2003 ERR("Something's still holding the front buffer (%p).\n", swapchain->front_buffer);
2004 swapchain->front_buffer = new_texture;
2005
2006 if (!(swapchain->device->wined3d->flags & WINED3D_NO3D))
2007 {
2010 }
2011
2012 for (i = 0; i < desc->backbuffer_count; ++i)
2013 {
2014 if (FAILED(hr = swapchain_create_texture(swapchain, false, false, &new_texture)))
2015 return hr;
2017 if (wined3d_texture_decref(swapchain->back_buffers[i]))
2018 ERR("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
2019 swapchain->back_buffers[i] = new_texture;
2020 }
2021 }
2022
2024
2025 return WINED3D_OK;
2026}
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:1814
@ WINED3DFMT_UNKNOWN
Definition: wined3d.h:127
size_t const buffer_count
Definition: xtoa.cpp:36

Referenced by d3d11_swapchain_ResizeBuffers(), ddraw7_SetDisplayMode(), and wined3d_device_reset().

◆ wined3d_swapchain_set_gamma_ramp()

HRESULT CDECL wined3d_swapchain_set_gamma_ramp ( const struct wined3d_swapchain *  swapchain,
uint32_t  flags,
const struct wined3d_gamma_ramp *  ramp 
)

Definition at line 353 of file swapchain.c.

355{
356 struct wined3d_output *output;
357
358 TRACE("swapchain %p, flags %#x, ramp %p.\n", swapchain, flags, ramp);
359
360 if (flags)
361 FIXME("Ignoring flags %#x.\n", flags);
362
363 if (!(output = wined3d_swapchain_get_output(swapchain)))
364 {
365 ERR("Failed to get output from swapchain %p.\n", swapchain);
366 return E_FAIL;
367 }
368
369 return wined3d_output_set_gamma_ramp(output, ramp);
370}
HRESULT CDECL wined3d_output_set_gamma_ramp(struct wined3d_output *output, const struct wined3d_gamma_ramp *ramp)
Definition: directx.c:1759

Referenced by wined3d_device_set_gamma_ramp(), and wined3d_swapchain_cleanup().

◆ wined3d_swapchain_set_palette()

void CDECL wined3d_swapchain_set_palette ( struct wined3d_swapchain *  swapchain,
struct wined3d_palette *  palette 
)

Definition at line 372 of file swapchain.c.

373{
374 TRACE("swapchain %p, palette %p.\n", swapchain, palette);
375
377
378 swapchain->palette = palette;
379}
static HPALETTE palette
Definition: clipboard.c:1457

Referenced by ddraw_create_swapchain(), and ddraw_surface_set_palette().

◆ wined3d_swapchain_set_window()

void CDECL wined3d_swapchain_set_window ( struct wined3d_swapchain *  swapchain,
HWND  window 
)

Definition at line 177 of file swapchain.c.

178{
179 if (!window)
180 window = swapchain->state.device_window;
181 if (window == swapchain->win_handle)
182 return;
183
184 TRACE("Setting swapchain %p window from %p to %p.\n",
185 swapchain, swapchain->win_handle, window);
186
188
189 swapchain->win_handle = window;
190}

Referenced by ddraw_surface7_SetClipper(), wined3d_cs_exec_present(), and wined3d_device_reset().

◆ wined3d_swapchain_state_create()

HRESULT CDECL wined3d_swapchain_state_create ( const struct wined3d_swapchain_desc *  desc,
HWND  window,
struct wined3d *  wined3d,
struct wined3d_swapchain_state_parent *  state_parent,
struct wined3d_swapchain_state **  state 
)

Definition at line 2473 of file swapchain.c.

2476{
2477 struct wined3d_swapchain_state *s;
2478 HRESULT hr;
2479
2480 TRACE("desc %p, window %p, wined3d %p, state %p.\n", desc, window, wined3d, state);
2481
2482 if (!(s = calloc(1, sizeof(*s))))
2483 return E_OUTOFMEMORY;
2484
2485 if (FAILED(hr = wined3d_swapchain_state_init(s, desc, window, wined3d, state_parent)))
2486 {
2487 free(s);
2488 return hr;
2489 }
2490
2491 *state = s;
2492
2493 return hr;
2494}
static int state
Definition: maze.c:121

Referenced by d3d12_swapchain_init().

◆ wined3d_swapchain_state_destroy()

void CDECL wined3d_swapchain_state_destroy ( struct wined3d_swapchain_state *  state)

Definition at line 2467 of file swapchain.c.

2468{
2470 free(state);
2471}

Referenced by d3d12_swapchain_destroy(), and d3d12_swapchain_init().

◆ wined3d_swapchain_state_get_size()

void CDECL wined3d_swapchain_state_get_size ( const struct wined3d_swapchain_state *  state,
unsigned int *  width,
unsigned int *  height 
)

Definition at line 2458 of file swapchain.c.

2460{
2461 TRACE("state %p.\n", state);
2462
2463 *width = state->desc.backbuffer_width;
2464 *height = state->desc.backbuffer_height;
2465}

Referenced by d3d11_swapchain_init(), and d3d12_swapchain_init().

◆ wined3d_swapchain_state_init()

static HRESULT wined3d_swapchain_state_init ( struct wined3d_swapchain_state *  state,
const struct wined3d_swapchain_desc *  desc,
HWND  window,
struct wined3d *  wined3d,
struct wined3d_swapchain_state_parent *  parent 
)
static

Definition at line 1389 of file swapchain.c.

1392{
1393 HRESULT hr;
1394
1395 state->desc = *desc;
1396
1397 if (FAILED(hr = wined3d_output_get_display_mode(desc->output, &state->original_mode, NULL)))
1398 {
1399 ERR("Failed to get current display mode, hr %#lx.\n", hr);
1400 return hr;
1401 }
1402
1403 if (state->desc.windowed)
1404 {
1405 RECT client_rect;
1406
1407 GetClientRect(window, &client_rect);
1408 TRACE("Client rect %s.\n", wine_dbgstr_rect(&client_rect));
1409
1410 if (!state->desc.backbuffer_width)
1411 {
1412 state->desc.backbuffer_width = client_rect.right ? client_rect.right : 8;
1413 TRACE("Updating width to %u.\n", state->desc.backbuffer_width);
1414 }
1415 if (!state->desc.backbuffer_height)
1416 {
1417 state->desc.backbuffer_height = client_rect.bottom ? client_rect.bottom : 8;
1418 TRACE("Updating height to %u.\n", state->desc.backbuffer_height);
1419 }
1420
1421 if (state->desc.backbuffer_format == WINED3DFMT_UNKNOWN)
1422 {
1423 state->desc.backbuffer_format = state->original_mode.format_id;
1424 TRACE("Updating format to %s.\n", debug_d3dformat(state->original_mode.format_id));
1425 }
1426 }
1427 else
1428 {
1430 {
1431 state->d3d_mode.width = desc->backbuffer_width;
1432 state->d3d_mode.height = desc->backbuffer_height;
1433 state->d3d_mode.format_id = adapter_format_from_backbuffer_format(desc->output->adapter,
1434 desc->backbuffer_format);
1435 state->d3d_mode.refresh_rate = desc->refresh_rate;
1436 state->d3d_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
1437 }
1438 else
1439 {
1440 state->d3d_mode = state->original_mode;
1441 }
1442 }
1443
1444 GetWindowRect(window, &state->original_window_rect);
1445 state->wined3d = wined3d;
1446 state->device_window = window;
1447 state->desc.device_window = window;
1448 state->parent = parent;
1449
1452
1453 return hr;
1454}
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
static enum wined3d_format_id adapter_format_from_backbuffer_format(const struct wined3d_adapter *adapter, enum wined3d_format_id format_id)
Definition: swapchain.c:1380
#define WINED3D_SWAPCHAIN_REGISTER_STATE
Definition: wined3d.h:902
@ WINED3D_SCANLINE_ORDERING_UNKNOWN
Definition: wined3d.h:825
void wined3d_swapchain_state_register(struct wined3d_swapchain_state *state)
Definition: wined3d_main.c:868

Referenced by wined3d_swapchain_init(), and wined3d_swapchain_state_create().

◆ wined3d_swapchain_state_is_windowed()

BOOL CDECL wined3d_swapchain_state_is_windowed ( const struct wined3d_swapchain_state *  state)

Definition at line 2451 of file swapchain.c.

2452{
2453 TRACE("state %p.\n", state);
2454
2455 return state->desc.windowed;
2456}

Referenced by d3d12_swapchain_GetDesc(), d3d12_swapchain_GetFullscreenDesc(), and d3d12_swapchain_GetFullscreenState().

◆ wined3d_swapchain_state_resize_target()

HRESULT CDECL wined3d_swapchain_state_resize_target ( struct wined3d_swapchain_state *  state,
const struct wined3d_display_mode *  mode 
)

Definition at line 2065 of file swapchain.c.

2067{
2068 struct wined3d_display_mode actual_mode;
2069 struct wined3d_output_desc output_desc;
2070 RECT original_window_rect, window_rect;
2071 int x, y, width, height;
2072 HWND window;
2073 HRESULT hr;
2074
2075 TRACE("state %p, mode %p.\n", state, mode);
2076
2078
2079 window = state->device_window;
2080
2081 if (state->desc.windowed)
2082 {
2083 SetRect(&window_rect, 0, 0, mode->width, mode->height);
2084 AdjustWindowRectEx(&window_rect,
2087 GetWindowRect(window, &original_window_rect);
2088
2089 x = original_window_rect.left;
2090 y = original_window_rect.top;
2091 width = window_rect.right - window_rect.left;
2092 height = window_rect.bottom - window_rect.top;
2093 }
2094 else
2095 {
2097 {
2098 actual_mode = *mode;
2100 &actual_mode)))
2101 {
2102 ERR("Failed to set display mode, hr %#lx.\n", hr);
2104 return hr;
2105 }
2106 }
2107
2108 if (FAILED(hr = wined3d_output_get_desc(state->desc.output, &output_desc)))
2109 {
2110 ERR("Failed to get output description, hr %#lx.\n", hr);
2112 return hr;
2113 }
2114
2115 x = output_desc.desktop_rect.left;
2116 y = output_desc.desktop_rect.top;
2117 width = output_desc.desktop_rect.right - output_desc.desktop_rect.left;
2118 height = output_desc.desktop_rect.bottom - output_desc.desktop_rect.top;
2119 }
2120
2122
2124
2125 return WINED3D_OK;
2126}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
BOOL WINAPI AdjustWindowRectEx(_Inout_ LPRECT, _In_ DWORD, _In_ BOOL, _In_ DWORD)
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
static HRESULT wined3d_swapchain_state_set_display_mode(struct wined3d_swapchain_state *state, struct wined3d_output *output, struct wined3d_display_mode *mode)
Definition: swapchain.c:2028

Referenced by dxgi_swapchain_resize_target().

◆ wined3d_swapchain_state_restore_from_fullscreen()

void wined3d_swapchain_state_restore_from_fullscreen ( struct wined3d_swapchain_state *  state,
HWND  window,
const RECT *  window_rect 
)

Definition at line 2275 of file swapchain.c.

2277{
2278 struct wined3d_window_state *s;
2280
2281 if (!state->style && !state->exstyle)
2282 return;
2283
2284 if (!(s = malloc(sizeof(*s))))
2285 return;
2286
2287 s->window = window;
2288 s->window_pos_after = NULL;
2290
2292 && !(state->desc.flags & WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES))
2293 {
2294 s->window_pos_after = (state->exstyle & WS_EX_TOPMOST) ? HWND_TOPMOST : HWND_NOTOPMOST;
2295 s->flags |= (state->style & WS_VISIBLE) ? SWP_SHOWWINDOW : SWP_HIDEWINDOW;
2296 s->flags &= ~SWP_NOZORDER;
2297 }
2298
2301
2302 /* These flags are set by wined3d_device_setup_fullscreen_window, not the
2303 * application, and we want to ignore them in the test below, since it's
2304 * not the application's fault that they changed. Additionally, we want to
2305 * preserve the current status of these flags (i.e. don't restore them) to
2306 * more closely emulate the behavior of Direct3D, which leaves these flags
2307 * alone when returning to windowed mode. */
2308 state->style ^= (state->style ^ style) & WS_VISIBLE;
2309 state->exstyle ^= (state->exstyle ^ exstyle) & WS_EX_TOPMOST;
2310
2311 TRACE("Restoring window style of window %p to %08lx, %08lx.\n",
2312 window, state->style, state->exstyle);
2313
2314 s->style = state->style;
2315 s->exstyle = state->exstyle;
2316 /* Only restore the style if the application didn't modify it during the
2317 * fullscreen phase. Some applications change it before calling Reset()
2318 * when switching between windowed and fullscreen modes (HL2), some
2319 * depend on the original style (Eve Online). */
2320 s->set_style = style == fullscreen_style(state->style) && exstyle == fullscreen_exstyle(state->exstyle);
2321 s->register_topmost_timer = !!(state->desc.flags & WINED3D_SWAPCHAIN_REGISTER_TOPMOST_TIMER);
2322 s->set_topmost_timer = false;
2323
2324 if (window_rect)
2325 {
2326 s->x = window_rect->left;
2327 s->y = window_rect->top;
2328 s->width = window_rect->right - window_rect->left;
2329 s->height = window_rect->bottom - window_rect->top;
2330 }
2331 else
2332 {
2333 s->x = s->y = s->width = s->height = 0;
2334 s->flags |= (SWP_NOMOVE | SWP_NOSIZE);
2335 }
2336
2338
2339 /* Delete the old values. */
2340 state->style = 0;
2341 state->exstyle = 0;
2342}
#define malloc
Definition: debug_ros.c:4
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
#define SWP_FRAMECHANGED
Definition: winuser.h:1251
#define SWP_SHOWWINDOW
Definition: winuser.h:1259
#define SWP_HIDEWINDOW
Definition: winuser.h:1252
#define HWND_NOTOPMOST
Definition: winuser.h:1217
static void set_window_state(struct wined3d_window_state *s)
Definition: swapchain.c:2188
static LONG fullscreen_style(LONG style)
Definition: swapchain.c:2128
static LONG fullscreen_exstyle(LONG exstyle)
Definition: swapchain.c:2137
#define WINED3D_SWAPCHAIN_REGISTER_TOPMOST_TIMER
Definition: wined3d.h:905
#define WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE
Definition: wined3d.h:904
#define WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES
Definition: wined3d.h:903

Referenced by wined3d_swapchain_cleanup(), and wined3d_swapchain_state_set_fullscreen().

◆ wined3d_swapchain_state_set_display_mode()

static HRESULT wined3d_swapchain_state_set_display_mode ( struct wined3d_swapchain_state *  state,
struct wined3d_output *  output,
struct wined3d_display_mode *  mode 
)
static

Definition at line 2028 of file swapchain.c.

2030{
2031 HRESULT hr;
2032
2034 {
2036 {
2037 WARN("Failed to find closest matching mode, hr %#lx.\n", hr);
2038 }
2039 }
2040
2041 if (output != state->desc.output)
2042 {
2044 {
2045 WARN("Failed to restore display modes, hr %#lx.\n", hr);
2046 return hr;
2047 }
2048
2049 if (FAILED(hr = wined3d_output_get_display_mode(output, &state->original_mode, NULL)))
2050 {
2051 WARN("Failed to get current display mode, hr %#lx.\n", hr);
2052 return hr;
2053 }
2054 }
2055
2057 {
2058 WARN("Failed to set display mode, hr %#lx.\n", hr);
2060 }
2061
2062 return WINED3D_OK;
2063}
HRESULT CDECL wined3d_output_find_closest_matching_mode(struct wined3d_output *output, struct wined3d_display_mode *mode)
Definition: directx.c:1409
#define WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE
Definition: wined3d.h:898

Referenced by wined3d_swapchain_state_resize_target(), and wined3d_swapchain_state_set_fullscreen().

◆ wined3d_swapchain_state_set_fullscreen()

HRESULT CDECL wined3d_swapchain_state_set_fullscreen ( struct wined3d_swapchain_state *  state,
const struct wined3d_swapchain_desc *  swapchain_desc,
const struct wined3d_display_mode *  mode 
)

Definition at line 2344 of file swapchain.c.

2347{
2348 struct wined3d_display_mode actual_mode;
2349 struct wined3d_output_desc output_desc;
2350 BOOL windowed = state->desc.windowed;
2351 HRESULT hr;
2352
2353 TRACE("state %p, swapchain_desc %p, mode %p.\n", state, swapchain_desc, mode);
2354
2356 {
2357 if (mode)
2358 {
2359 actual_mode = *mode;
2361 &actual_mode)))
2362 return hr;
2363 }
2364 else
2365 {
2366 if (!swapchain_desc->windowed)
2367 {
2368 actual_mode.width = swapchain_desc->backbuffer_width;
2369 actual_mode.height = swapchain_desc->backbuffer_height;
2370 actual_mode.refresh_rate = swapchain_desc->refresh_rate;
2371 actual_mode.format_id = adapter_format_from_backbuffer_format(swapchain_desc->output->adapter,
2372 swapchain_desc->backbuffer_format);
2373 actual_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
2375 &actual_mode)))
2376 return hr;
2377 }
2378 else
2379 {
2381 {
2382 WARN("Failed to restore display modes for all outputs, hr %#lx.\n", hr);
2383 return hr;
2384 }
2385 }
2386 }
2387 }
2388 else
2389 {
2390 if (mode)
2391 WARN("WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH is not set, ignoring mode.\n");
2392
2393 if (FAILED(hr = wined3d_output_get_display_mode(swapchain_desc->output, &actual_mode,
2394 NULL)))
2395 {
2396 ERR("Failed to get display mode, hr %#lx.\n", hr);
2398 }
2399 }
2400
2401 if (!swapchain_desc->windowed)
2402 {
2403 unsigned int width = actual_mode.width;
2404 unsigned int height = actual_mode.height;
2405
2406 if (FAILED(hr = wined3d_output_get_desc(swapchain_desc->output, &output_desc)))
2407 {
2408 ERR("Failed to get output description, hr %#lx.\n", hr);
2409 return hr;
2410 }
2411
2412 if (state->desc.windowed)
2413 {
2414 /* Switch from windowed to fullscreen */
2416 output_desc.desktop_rect.left, output_desc.desktop_rect.top, width, height)))
2417 return hr;
2418 }
2419 else
2420 {
2421 HWND window = state->device_window;
2422 BOOL filter;
2423
2424 /* Fullscreen -> fullscreen mode change */
2426 MoveWindow(window, output_desc.desktop_rect.left, output_desc.desktop_rect.top, width,
2427 height, TRUE);
2430 }
2431 state->d3d_mode = actual_mode;
2432 }
2433 else if (!state->desc.windowed)
2434 {
2435 /* Fullscreen -> windowed switch */
2436 RECT *window_rect = NULL;
2438 window_rect = &state->original_window_rect;
2439 wined3d_swapchain_state_restore_from_fullscreen(state, state->device_window, window_rect);
2440 }
2441
2442 state->desc.output = swapchain_desc->output;
2443 state->desc.windowed = swapchain_desc->windowed;
2444
2445 if (windowed != state->desc.windowed)
2446 state->parent->ops->windowed_state_changed(state->parent, state->desc.windowed);
2447
2448 return WINED3D_OK;
2449}
#define SW_SHOW
Definition: winuser.h:786
struct wined3d_output * output
Definition: wined3d.h:1771
unsigned int refresh_rate
Definition: wined3d.h:1785

Referenced by d3d11_swapchain_init(), d3d11_swapchain_SetFullscreenState(), d3d12_swapchain_init(), d3d12_swapchain_SetFullscreenState(), wined3d_device_reset(), and wined3d_hook_proc().

◆ wined3d_swapchain_state_setup_fullscreen()

HRESULT wined3d_swapchain_state_setup_fullscreen ( struct wined3d_swapchain_state *  state,
HWND  window,
int  x,
int  y,
int  width,
int  height 
)

Definition at line 2225 of file swapchain.c.

2227{
2228 struct wined3d_window_state *s;
2229
2230 TRACE("Setting up window %p for fullscreen mode.\n", window);
2231
2232 if (!IsWindow(window))
2233 {
2234 WARN("%p is not a valid window.\n", window);
2236 }
2237
2238 if (!(s = malloc(sizeof(*s))))
2239 return E_OUTOFMEMORY;
2240 s->window = window;
2241 s->window_pos_after = HWND_TOPMOST;
2242 s->x = x;
2243 s->y = y;
2244 s->width = width;
2245 s->height = height;
2246
2247 if (state->style || state->exstyle)
2248 {
2249 ERR("Changing the window style for window %p, but another style (%08lx, %08lx) is already stored.\n",
2250 window, state->style, state->exstyle);
2251 }
2252
2255 s->flags |= SWP_NOZORDER;
2256 else
2257 s->flags |= SWP_SHOWWINDOW;
2258
2261
2262 s->style = fullscreen_style(state->style);
2263 s->exstyle = fullscreen_exstyle(state->exstyle);
2264 s->set_style = true;
2265 s->register_topmost_timer = !!(state->desc.flags & WINED3D_SWAPCHAIN_REGISTER_TOPMOST_TIMER);
2266 s->set_topmost_timer = true;
2267
2268 TRACE("Old style was %08lx, %08lx, setting to %08lx, %08lx.\n",
2269 state->style, state->exstyle, s->style, s->exstyle);
2270
2272 return WINED3D_OK;
2273}
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define WINED3DERR_NOTAVAILABLE
Definition: wined3d.h:42

Referenced by wined3d_device_reset(), wined3d_swapchain_init(), and wined3d_swapchain_state_set_fullscreen().

◆ wined3d_swapchain_vk_blit()

static VkResult wined3d_swapchain_vk_blit ( struct wined3d_swapchain_vk *  swapchain_vk,
struct wined3d_context_vk *  context_vk,
const RECT *  src_rect,
const RECT *  dst_rect,
unsigned int  swap_interval 
)
static

Definition at line 1039 of file swapchain.c.

1041{
1042 struct wined3d_texture_vk *back_buffer_vk = wined3d_texture_vk(swapchain_vk->s.back_buffers[0]);
1043 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
1044 const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
1045 const struct wined3d_vk_info *vk_info = context_vk->vk_info;
1046 VkCommandBuffer vk_command_buffer;
1047 VkImageSubresourceRange vk_range;
1048 VkPresentInfoKHR present_desc;
1049 unsigned int present_idx;
1050 VkImageLayout vk_layout;
1051 uint32_t image_idx;
1052 RECT dst_rect_tmp;
1053 VkImageBlit blit;
1055 VkResult vr;
1056
1058
1059 TRACE("swapchain_vk %p, context_vk %p, src_rect %s, dst_rect %s, swap_interval %u.\n",
1060 swapchain_vk, context_vk, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), swap_interval);
1061
1062 wined3d_swapchain_vk_set_swap_interval(swapchain_vk, swap_interval);
1063
1064 present_idx = swapchain_vk->current++ % swapchain_vk->image_count;
1065 wined3d_context_vk_wait_command_buffer(context_vk, swapchain_vk->vk_semaphores[present_idx].command_buffer_id);
1066 if ((vr = VK_CALL(vkAcquireNextImageKHR(device_vk->vk_device, swapchain_vk->vk_swapchain, UINT64_MAX,
1067 swapchain_vk->vk_semaphores[present_idx].available, VK_NULL_HANDLE, &image_idx))) < 0)
1068 {
1069 WARN("Failed to acquire image, vr %s.\n", wined3d_debug_vkresult(vr));
1070 return vr;
1071 }
1072
1073 if (dst_rect->right > swapchain_vk->width || dst_rect->bottom > swapchain_vk->height)
1074 {
1075 dst_rect_tmp = *dst_rect;
1076 if (dst_rect->right > swapchain_vk->width)
1077 dst_rect_tmp.right = swapchain_vk->width;
1078 if (dst_rect->bottom > swapchain_vk->height)
1079 dst_rect_tmp.bottom = swapchain_vk->height;
1080 dst_rect = &dst_rect_tmp;
1081 }
1082 filter = src_rect->right - src_rect->left != dst_rect->right - dst_rect->left
1083 || src_rect->bottom - src_rect->top != dst_rect->bottom - dst_rect->top
1085 vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk);
1086
1088
1090 vk_range.baseMipLevel = 0;
1091 vk_range.levelCount = 1;
1092 vk_range.baseArrayLayer = 0;
1093 vk_range.layerCount = 1;
1094
1095 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
1097 vk_access_mask_from_bind_flags(back_buffer_vk->t.resource.bind_flags),
1100 back_buffer_vk->image.vk_image, &vk_range);
1101
1102 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
1106 swapchain_vk->vk_images[image_idx], &vk_range);
1107
1108 blit.srcSubresource.aspectMask = vk_range.aspectMask;
1109 blit.srcSubresource.mipLevel = vk_range.baseMipLevel;
1111 blit.srcSubresource.layerCount = vk_range.layerCount;
1112 blit.srcOffsets[0].x = src_rect->left;
1113 blit.srcOffsets[0].y = src_rect->top;
1114 blit.srcOffsets[0].z = 0;
1115 blit.srcOffsets[1].x = src_rect->right;
1116 blit.srcOffsets[1].y = src_rect->bottom;
1117 blit.srcOffsets[1].z = 1;
1118 blit.dstSubresource = blit.srcSubresource;
1119 blit.dstOffsets[0].x = dst_rect->left;
1120 blit.dstOffsets[0].y = dst_rect->top;
1121 blit.dstOffsets[0].z = 0;
1122 blit.dstOffsets[1].x = dst_rect->right;
1123 blit.dstOffsets[1].y = dst_rect->bottom;
1124 blit.dstOffsets[1].z = 1;
1125 VK_CALL(vkCmdBlitImage(vk_command_buffer,
1126 back_buffer_vk->image.vk_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1127 swapchain_vk->vk_images[image_idx], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1128 1, &blit, filter));
1129
1130 wined3d_context_vk_reference_texture(context_vk, back_buffer_vk);
1131 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
1135 swapchain_vk->vk_images[image_idx], &vk_range);
1136
1137 if (desc->swap_effect == WINED3D_SWAP_EFFECT_DISCARD || desc->swap_effect == WINED3D_SWAP_EFFECT_FLIP_DISCARD)
1138 vk_layout = VK_IMAGE_LAYOUT_UNDEFINED;
1139 else
1141 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
1144 vk_access_mask_from_bind_flags(back_buffer_vk->t.resource.bind_flags),
1145 vk_layout, back_buffer_vk->layout,
1146 back_buffer_vk->image.vk_image, &vk_range);
1147 back_buffer_vk->bind_mask = 0;
1148
1149 swapchain_vk->vk_semaphores[present_idx].command_buffer_id = context_vk->current_command_buffer.id;
1151 1, &swapchain_vk->vk_semaphores[present_idx].available, &wait_stage,
1152 1, &swapchain_vk->vk_semaphores[present_idx].presentable);
1153
1155 present_desc.pNext = NULL;
1156 present_desc.waitSemaphoreCount = 1;
1157 present_desc.pWaitSemaphores = &swapchain_vk->vk_semaphores[present_idx].presentable;
1158 present_desc.swapchainCount = 1;
1159 present_desc.pSwapchains = &swapchain_vk->vk_swapchain;
1160 present_desc.pImageIndices = &image_idx;
1161 present_desc.pResults = NULL;
1162 if ((vr = VK_CALL(vkQueuePresentKHR(device_vk->vk_queue, &present_desc))))
1163 WARN("Present returned vr %s.\n", wined3d_debug_vkresult(vr));
1164 return vr;
1165}
void wined3d_context_vk_end_current_render_pass(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1564
VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1805
void wined3d_context_vk_image_barrier(struct wined3d_context_vk *context_vk, VkCommandBuffer vk_command_buffer, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask, VkAccessFlags src_access_mask, VkAccessFlags dst_access_mask, VkImageLayout old_layout, VkImageLayout new_layout, VkImage image, const VkImageSubresourceRange *range)
Definition: context_vk.c:2022
void wined3d_context_vk_submit_command_buffer(struct wined3d_context_vk *context_vk, unsigned int wait_semaphore_count, const VkSemaphore *wait_semaphores, const VkPipelineStageFlags *wait_stages, unsigned int signal_semaphore_count, const VkSemaphore *signal_semaphores)
Definition: context_vk.c:1896
void wined3d_context_vk_wait_command_buffer(struct wined3d_context_vk *context_vk, uint64_t id)
Definition: context_vk.c:1990
VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags)
Definition: resource.c:526
#define UINT64_MAX
Definition: stdint.h:86
VkOffset3D srcOffsets[2]
Definition: vulkan.h:16351
VkImageSubresourceLayers srcSubresource
Definition: vulkan.h:16350
VkOffset3D dstOffsets[2]
Definition: vulkan.h:16353
VkImageSubresourceLayers dstSubresource
Definition: vulkan.h:16352
VkImageAspectFlags aspectMask
Definition: vulkan.h:9065
uint32_t baseArrayLayer
Definition: vulkan.h:9076
VkImageAspectFlags aspectMask
Definition: vulkan.h:9073
int32_t x
Definition: vulkan.h:9579
int32_t y
Definition: vulkan.h:9580
int32_t z
Definition: vulkan.h:9581
const VkSemaphore * pWaitSemaphores
Definition: vulkan.h:13417
VkResult * pResults
Definition: vulkan.h:13421
uint32_t waitSemaphoreCount
Definition: vulkan.h:13416
uint32_t swapchainCount
Definition: vulkan.h:13418
const uint32_t * pImageIndices
Definition: vulkan.h:13420
VkStructureType sType
Definition: vulkan.h:13414
const VkSwapchainKHR * pSwapchains
Definition: vulkan.h:13419
const void * pNext
Definition: vulkan.h:13415
struct wined3d_command_buffer_vk current_command_buffer
Definition: wined3d_vk.h:617
const struct wined3d_vk_info * vk_info
Definition: wined3d_vk.h:590
VkDevice vk_device
Definition: wined3d_vk.h:825
unsigned int width
Definition: wined3d_vk.h:1065
unsigned int image_count
Definition: wined3d_vk.h:1064
struct wined3d_swapchain s
Definition: wined3d_vk.h:1053
unsigned int current
Definition: wined3d_vk.h:1064
struct wined3d_swapchain_vk::@366 * vk_semaphores
unsigned int height
Definition: wined3d_vk.h:1065
struct wined3d_image_vk image
Definition: wined3d_vk.h:877
uint32_t bind_mask
Definition: wined3d_vk.h:879
struct wined3d_texture t
Definition: wined3d_vk.h:875
enum VkImageLayout layout
Definition: wined3d_vk.h:878
VkFlags VkPipelineStageFlags
Definition: vulkan.h:1101
VkImageLayout
Definition: vulkan.h:3450
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
Definition: vulkan.h:3457
@ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
Definition: vulkan.h:3460
@ VK_IMAGE_LAYOUT_UNDEFINED
Definition: vulkan.h:3451
@ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
Definition: vulkan.h:3458
VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex)
void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter)
@ VK_IMAGE_ASPECT_COLOR_BIT
Definition: vulkan.h:3365
VkFilter
Definition: vulkan.h:2806
@ VK_FILTER_NEAREST
Definition: vulkan.h:2807
@ VK_FILTER_LINEAR
Definition: vulkan.h:2808
VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo)
@ VK_ACCESS_TRANSFER_WRITE_BIT
Definition: vulkan.h:1641
@ VK_ACCESS_TRANSFER_READ_BIT
Definition: vulkan.h:1640
#define VK_NULL_HANDLE
Definition: vulkan.h:861
@ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
Definition: vulkan.h:4272
@ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
Definition: vulkan.h:4282
@ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
Definition: vulkan.h:4288
@ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
Definition: vulkan.h:4285
@ VK_PIPELINE_STAGE_TRANSFER_BIT
Definition: vulkan.h:4284
@ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR
Definition: vulkan.h:5022
static void wined3d_swapchain_vk_set_swap_interval(struct wined3d_swapchain_vk *swapchain_vk, unsigned int swap_interval)
Definition: swapchain.c:1022
@ WINED3D_SWAP_EFFECT_FLIP_DISCARD
Definition: wined3d.h:536
static void wined3d_context_vk_reference_texture(const struct wined3d_context_vk *context_vk, struct wined3d_texture_vk *texture_vk)
Definition: wined3d_vk.h:1103
#define VK_CALL(f)
Definition: wined3d_vk.h:272

Referenced by swapchain_vk_present().

◆ wined3d_swapchain_vk_cleanup()

void wined3d_swapchain_vk_cleanup ( struct wined3d_swapchain_vk *  swapchain_vk)

Definition at line 125 of file swapchain.c.

126{
127 struct wined3d_cs *cs = swapchain_vk->s.device->cs;
128
131
132 wined3d_swapchain_cleanup(&swapchain_vk->s);
133}
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:2299
#define cs
Definition: i386-dis.c:442
static void wined3d_swapchain_vk_destroy_object(void *object)
Definition: swapchain.c:120

Referenced by adapter_vk_destroy_swapchain().

◆ wined3d_swapchain_vk_create_vulkan_swapchain()

static HRESULT wined3d_swapchain_vk_create_vulkan_swapchain ( struct wined3d_swapchain_vk *  swapchain_vk)
static

Definition at line 866 of file swapchain.c.

867{
868 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
869 const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
870 VkSwapchainCreateInfoKHR vk_swapchain_desc;
871 VkWin32SurfaceCreateInfoKHR surface_desc;
872 unsigned int width, height, image_count;
873 const struct wined3d_vk_info *vk_info;
874 VkSurfaceCapabilitiesKHR surface_caps;
875 struct wined3d_adapter_vk *adapter_vk;
876 VkPresentModeKHR vk_present_mode;
877 VkSwapchainKHR vk_swapchain;
879 VkSurfaceKHR vk_surface;
880 VkBool32 supported;
881 VkFormat vk_format;
882 RECT client_rect;
883 VkResult vr;
884
885 adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
886 vk_info = &adapter_vk->vk_info;
887
889 surface_desc.pNext = NULL;
890 surface_desc.flags = 0;
891 surface_desc.hinstance = (HINSTANCE)GetWindowLongPtrW(swapchain_vk->s.win_handle, GWLP_HINSTANCE);
892 surface_desc.hwnd = swapchain_vk->s.win_handle;
893 if ((vr = VK_CALL(vkCreateWin32SurfaceKHR(vk_info->instance, &surface_desc, NULL, &vk_surface))) < 0)
894 {
895 ERR("Failed to create Vulkan surface, vr %s.\n", wined3d_debug_vkresult(vr));
896 return E_FAIL;
897 }
898 swapchain_vk->vk_surface = vk_surface;
899
901 device_vk->vk_queue_family_index, vk_surface, &supported))) < 0 || !supported)
902 {
903 ERR("Queue family does not support presentation on this surface, vr %s.\n", wined3d_debug_vkresult(vr));
904 goto fail;
905 }
906
907 if ((vk_format = wined3d_swapchain_vk_select_vk_format(swapchain_vk, vk_surface)) == VK_FORMAT_UNDEFINED)
908 {
909 ERR("Failed to select swapchain format.\n");
910 goto fail;
911 }
912
914 swapchain_vk->vk_surface, &surface_caps))) < 0)
915 {
916 ERR("Failed to get surface capabilities, vr %s.\n", wined3d_debug_vkresult(vr));
917 goto fail;
918 }
919
920 image_count = desc->backbuffer_count;
921 if (image_count < surface_caps.minImageCount)
922 image_count = surface_caps.minImageCount;
923 else if (surface_caps.maxImageCount && image_count > surface_caps.maxImageCount)
924 image_count = surface_caps.maxImageCount;
925
926 if (image_count != desc->backbuffer_count)
927 WARN("Image count %u is not supported (%u-%u).\n", desc->backbuffer_count,
928 surface_caps.minImageCount, surface_caps.maxImageCount);
929
930 GetClientRect(swapchain_vk->s.win_handle, &client_rect);
931
932 width = client_rect.right - client_rect.left;
933 if (width < surface_caps.minImageExtent.width)
934 width = surface_caps.minImageExtent.width;
935 else if (width > surface_caps.maxImageExtent.width)
936 width = surface_caps.maxImageExtent.width;
937
938 height = client_rect.bottom - client_rect.top;
939 if (height < surface_caps.minImageExtent.height)
940 height = surface_caps.minImageExtent.height;
941 else if (height > surface_caps.maxImageExtent.height)
942 height = surface_caps.maxImageExtent.height;
943
944 if (width != client_rect.right - client_rect.left || height != client_rect.bottom - client_rect.top)
945 WARN("Swapchain dimensions %lux%lu are not supported (%u-%u x %u-%u).\n",
946 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
947 surface_caps.minImageExtent.width, surface_caps.maxImageExtent.width,
948 surface_caps.minImageExtent.height, surface_caps.maxImageExtent.height);
949
954 WARN("Transfer not supported for swapchain images.\n");
955
957 {
958 FIXME("Unsupported alpha mode, %#x.\n", surface_caps.supportedCompositeAlpha);
959 goto fail;
960 }
961
962 vk_present_mode = VK_PRESENT_MODE_FIFO_KHR;
963 if (!swapchain_vk->s.swap_interval)
964 {
966 vk_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
967 else
968 FIXME("Unsupported swap interval %u.\n", swapchain_vk->s.swap_interval);
969 }
970
972 vk_swapchain_desc.pNext = NULL;
973 vk_swapchain_desc.flags = 0;
974 vk_swapchain_desc.surface = vk_surface;
975 vk_swapchain_desc.minImageCount = image_count;
976 vk_swapchain_desc.imageFormat = vk_format;
978 vk_swapchain_desc.imageExtent.width = width;
979 vk_swapchain_desc.imageExtent.height = height;
980 vk_swapchain_desc.imageArrayLayers = 1;
981 vk_swapchain_desc.imageUsage = usage;
983 vk_swapchain_desc.queueFamilyIndexCount = 0;
984 vk_swapchain_desc.pQueueFamilyIndices = NULL;
985 vk_swapchain_desc.preTransform = surface_caps.currentTransform;
987 vk_swapchain_desc.presentMode = vk_present_mode;
988 vk_swapchain_desc.clipped = VK_TRUE;
989 vk_swapchain_desc.oldSwapchain = VK_NULL_HANDLE;
990 if ((vr = VK_CALL(vkCreateSwapchainKHR(device_vk->vk_device, &vk_swapchain_desc, NULL, &vk_swapchain))) < 0)
991 {
992 ERR("Failed to create Vulkan swapchain, vr %s.\n", wined3d_debug_vkresult(vr));
993 goto fail;
994 }
995 swapchain_vk->vk_swapchain = vk_swapchain;
996
997 if (!wined3d_swapchain_vk_create_vulkan_swapchain_images(swapchain_vk, vk_swapchain))
998 {
999 VK_CALL(vkDestroySwapchainKHR(device_vk->vk_device, vk_swapchain, NULL));
1000 goto fail;
1001 }
1002
1003 swapchain_vk->width = width;
1004 swapchain_vk->height = height;
1005
1006 return WINED3D_OK;
1007
1008fail:
1009 VK_CALL(vkDestroySurfaceKHR(vk_info->instance, vk_surface, NULL));
1010 return E_FAIL;
1011}
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define GetWindowLongPtrW
Definition: winuser.h:4983
#define GWLP_HINSTANCE
Definition: winuser.h:867
uint32_t width
Definition: vulkan.h:8666
uint32_t height
Definition: vulkan.h:8667
VkSurfaceTransformFlagBitsKHR currentTransform
Definition: vulkan.h:14320
VkCompositeAlphaFlagsKHR supportedCompositeAlpha
Definition: vulkan.h:14321
VkExtent2D maxImageExtent
Definition: vulkan.h:14317
VkExtent2D minImageExtent
Definition: vulkan.h:14316
VkImageUsageFlags supportedUsageFlags
Definition: vulkan.h:14322
const void * pNext
Definition: vulkan.h:14367
VkPresentModeKHR presentMode
Definition: vulkan.h:14381
VkImageUsageFlags imageUsage
Definition: vulkan.h:14375
VkSharingMode imageSharingMode
Definition: vulkan.h:14376
VkStructureType sType
Definition: vulkan.h:14366
VkSwapchainCreateFlagsKHR flags
Definition: vulkan.h:14368
VkColorSpaceKHR imageColorSpace
Definition: vulkan.h:14372
uint32_t queueFamilyIndexCount
Definition: vulkan.h:14377
VkSurfaceTransformFlagBitsKHR preTransform
Definition: vulkan.h:14379
const uint32_t * pQueueFamilyIndices
Definition: vulkan.h:14378
VkCompositeAlphaFlagBitsKHR compositeAlpha
Definition: vulkan.h:14380
VkExtent2D imageExtent
Definition: vulkan.h:14373
VkStructureType sType
Definition: vulkan.h:15245
VkWin32SurfaceCreateFlagsKHR flags
Definition: vulkan.h:15247
struct wined3d_vk_info vk_info
Definition: wined3d_vk.h:728
VkPhysicalDevice physical_device
Definition: wined3d_vk.h:731
struct wined3d_device d
Definition: wined3d_vk.h:821
uint32_t vk_queue_family_index
Definition: wined3d_vk.h:827
VkSurfaceKHR vk_surface
Definition: wined3d_vk.h:1056
HANDLE HINSTANCE
Definition: typedefs.h:77
VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
@ VK_SHARING_MODE_EXCLUSIVE
Definition: vulkan.h:4921
#define VK_TRUE
Definition: vulkan.h:55
VkFlags VkImageUsageFlags
Definition: vulkan.h:1050
void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator)
VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32 *pSupported)
@ VK_IMAGE_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:3511
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
Definition: vulkan.h:3514
@ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
Definition: vulkan.h:3510
@ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
Definition: vulkan.h:2232
VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
VkPresentModeKHR
Definition: vulkan.h:4417
@ VK_PRESENT_MODE_IMMEDIATE_KHR
Definition: vulkan.h:4418
@ VK_PRESENT_MODE_FIFO_KHR
Definition: vulkan.h:4420
VkFormat
Definition: vulkan.h:2815
@ VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
Definition: vulkan.h:2118
uint32_t VkBool32
Definition: vulkan.h:946
void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator)
@ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR
Definition: vulkan.h:5023
@ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
Definition: vulkan.h:5021
static VkFormat wined3d_swapchain_vk_select_vk_format(struct wined3d_swapchain_vk *swapchain_vk, VkSurfaceKHR vk_surface)
Definition: swapchain.c:723
static bool wined3d_swapchain_vk_present_mode_supported(struct wined3d_swapchain_vk *swapchain_vk, VkPresentModeKHR vk_present_mode)
Definition: swapchain.c:660
static bool wined3d_swapchain_vk_create_vulkan_swapchain_images(struct wined3d_swapchain_vk *swapchain_vk, VkSwapchainKHR vk_swapchain)
Definition: swapchain.c:792

Referenced by wined3d_swapchain_vk_init(), and wined3d_swapchain_vk_recreate().

◆ wined3d_swapchain_vk_create_vulkan_swapchain_images()

static bool wined3d_swapchain_vk_create_vulkan_swapchain_images ( struct wined3d_swapchain_vk *  swapchain_vk,
VkSwapchainKHR  vk_swapchain 
)
static

Definition at line 792 of file swapchain.c.

794{
795 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
796 const struct wined3d_vk_info *vk_info;
797 VkSemaphoreCreateInfo semaphore_info;
798 uint32_t image_count, i;
799 VkResult vr;
800
801 vk_info = &wined3d_adapter_vk(device_vk->d.adapter)->vk_info;
802
803 if ((vr = VK_CALL(vkGetSwapchainImagesKHR(device_vk->vk_device, vk_swapchain, &image_count, NULL))) < 0)
804 {
805 ERR("Failed to get image count, vr %s\n", wined3d_debug_vkresult(vr));
806 return false;
807 }
808
809 if (!(swapchain_vk->vk_images = calloc(image_count, sizeof(*swapchain_vk->vk_images))))
810 {
811 ERR("Failed to allocate images array.\n");
812 return false;
813 }
814
815 if ((vr = VK_CALL(vkGetSwapchainImagesKHR(device_vk->vk_device,
816 vk_swapchain, &image_count, swapchain_vk->vk_images))) < 0)
817 {
818 ERR("Failed to get swapchain images, vr %s.\n", wined3d_debug_vkresult(vr));
819 free(swapchain_vk->vk_images);
820 return false;
821 }
822
823 if (!(swapchain_vk->vk_semaphores = calloc(image_count, sizeof(*swapchain_vk->vk_semaphores))))
824 {
825 ERR("Failed to allocate semaphores array.\n");
826 free(swapchain_vk->vk_images);
827 return false;
828 }
829
831 semaphore_info.pNext = NULL;
832 semaphore_info.flags = 0;
833 for (i = 0; i < image_count; ++i)
834 {
835 if ((vr = VK_CALL(vkCreateSemaphore(device_vk->vk_device,
836 &semaphore_info, NULL, &swapchain_vk->vk_semaphores[i].available))) < 0)
837 {
838 ERR("Failed to create semaphore, vr %s.\n", wined3d_debug_vkresult(vr));
839 goto fail;
840 }
841
842 if ((vr = VK_CALL(vkCreateSemaphore(device_vk->vk_device,
843 &semaphore_info, NULL, &swapchain_vk->vk_semaphores[i].presentable))) < 0)
844 {
845 ERR("Failed to create semaphore, vr %s.\n", wined3d_debug_vkresult(vr));
846 goto fail;
847 }
848 }
849 swapchain_vk->image_count = image_count;
850
851 return true;
852
853fail:
854 for (i = 0; i < image_count; ++i)
855 {
856 if (swapchain_vk->vk_semaphores[i].available)
857 VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].available, NULL));
858 if (swapchain_vk->vk_semaphores[i].presentable)
859 VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].presentable, NULL));
860 }
861 free(swapchain_vk->vk_semaphores);
862 free(swapchain_vk->vk_images);
863 return false;
864}
VkStructureType sType
Definition: vulkan.h:13937
VkSemaphoreCreateFlags flags
Definition: vulkan.h:13939
const void * pNext
Definition: vulkan.h:13938
void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator)
VkResult VKAPI_CALL vkCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore)
VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages)
@ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
Definition: vulkan.h:4973

Referenced by wined3d_swapchain_vk_create_vulkan_swapchain().

◆ wined3d_swapchain_vk_destroy_object()

static void wined3d_swapchain_vk_destroy_object ( void *  object)
static

Definition at line 120 of file swapchain.c.

121{
123}
static void wined3d_swapchain_vk_destroy_vulkan_swapchain(struct wined3d_swapchain_vk *swapchain_vk)
Definition: swapchain.c:96

Referenced by wined3d_swapchain_vk_cleanup().

◆ wined3d_swapchain_vk_destroy_vulkan_swapchain()

static void wined3d_swapchain_vk_destroy_vulkan_swapchain ( struct wined3d_swapchain_vk *  swapchain_vk)
static

Definition at line 96 of file swapchain.c.

97{
98 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
99 const struct wined3d_vk_info *vk_info;
100 unsigned int i;
101 VkResult vr;
102
103 TRACE("swapchain_vk %p.\n", swapchain_vk);
104
105 vk_info = &wined3d_adapter_vk(device_vk->d.adapter)->vk_info;
106
107 if ((vr = VK_CALL(vkQueueWaitIdle(device_vk->vk_queue))) < 0)
108 ERR("Failed to wait on queue, vr %s.\n", wined3d_debug_vkresult(vr));
109 free(swapchain_vk->vk_images);
110 for (i = 0; i < swapchain_vk->image_count; ++i)
111 {
112 VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].available, NULL));
113 VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].presentable, NULL));
114 }
115 free(swapchain_vk->vk_semaphores);
116 VK_CALL(vkDestroySwapchainKHR(device_vk->vk_device, swapchain_vk->vk_swapchain, NULL));
117 VK_CALL(vkDestroySurfaceKHR(vk_info->instance, swapchain_vk->vk_surface, NULL));
118}
VkInstance instance
Definition: wined3d_vk.h:258
VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)

Referenced by wined3d_swapchain_vk_destroy_object(), and wined3d_swapchain_vk_recreate().

◆ wined3d_swapchain_vk_init()

HRESULT wined3d_swapchain_vk_init ( struct wined3d_swapchain_vk *  swapchain_vk,
struct wined3d_device *  device,
const struct wined3d_swapchain_desc *  desc,
struct wined3d_swapchain_state_parent *  state_parent,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 1707 of file swapchain.c.

1710{
1711 HRESULT hr;
1712
1713 TRACE("swapchain_vk %p, device %p, desc %p, parent %p, parent_ops %p.\n",
1714 swapchain_vk, device, desc, parent, parent_ops);
1715
1716 if (FAILED(hr = wined3d_swapchain_init(&swapchain_vk->s, device, desc, state_parent, parent,
1717 parent_ops, &swapchain_vk_ops)))
1718 return hr;
1719
1720 if (swapchain_vk->s.win_handle == GetDesktopWindow())
1721 {
1722 WARN("Creating a desktop window swapchain.\n");
1723 return hr;
1724 }
1725
1727 WARN("Failed to create a Vulkan swapchain, hr %#lx.\n", hr);
1728
1729 return WINED3D_OK;
1730}
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:628
static HRESULT wined3d_swapchain_vk_create_vulkan_swapchain(struct wined3d_swapchain_vk *swapchain_vk)
Definition: swapchain.c:866
static const struct wined3d_swapchain_ops swapchain_vk_ops
Definition: swapchain.c:1268

Referenced by adapter_vk_create_swapchain().

◆ wined3d_swapchain_vk_present_mode_supported()

static bool wined3d_swapchain_vk_present_mode_supported ( struct wined3d_swapchain_vk *  swapchain_vk,
VkPresentModeKHR  vk_present_mode 
)
static

Definition at line 660 of file swapchain.c.

662{
663 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
664 const struct wined3d_vk_info *vk_info;
665 struct wined3d_adapter_vk *adapter_vk;
666 VkPhysicalDevice vk_physical_device;
667 VkPresentModeKHR *vk_modes;
668 bool supported = false;
670 VkResult vr;
671
672 adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
673 vk_physical_device = adapter_vk->physical_device;
674 vk_info = &adapter_vk->vk_info;
675
676 if ((vr = VK_CALL(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical_device,
677 swapchain_vk->vk_surface, &count, NULL))) < 0)
678 {
679 ERR("Failed to get supported present mode count, vr %s.\n", wined3d_debug_vkresult(vr));
680 return false;
681 }
682
683 if (!(vk_modes = calloc(count, sizeof(*vk_modes))))
684 return false;
685
686 if ((vr = VK_CALL(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical_device,
687 swapchain_vk->vk_surface, &count, vk_modes))) < 0)
688 {
689 ERR("Failed to get supported present modes, vr %s.\n", wined3d_debug_vkresult(vr));
690 goto done;
691 }
692
693 for (i = 0; i < count; ++i)
694 {
695 if (vk_modes[i] == vk_present_mode)
696 {
697 supported = true;
698 goto done;
699 }
700 }
701
702done:
703 free(vk_modes);
704 return supported;
705}
GLuint GLuint GLsizei count
Definition: gl.h:1545
VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes)

Referenced by wined3d_swapchain_vk_create_vulkan_swapchain().

◆ wined3d_swapchain_vk_recreate()

static HRESULT wined3d_swapchain_vk_recreate ( struct wined3d_swapchain_vk *  swapchain_vk)
static

Definition at line 1013 of file swapchain.c.

1014{
1015 TRACE("swapchain_vk %p.\n", swapchain_vk);
1016
1018
1020}

Referenced by swapchain_vk_present(), and wined3d_swapchain_vk_set_swap_interval().

◆ wined3d_swapchain_vk_rotate()

static void wined3d_swapchain_vk_rotate ( struct wined3d_swapchain *  swapchain,
struct wined3d_context_vk *  context_vk 
)
static

Definition at line 1167 of file swapchain.c.

1168{
1169 struct wined3d_texture_sub_resource *sub_resource;
1170 struct wined3d_texture_vk *texture, *texture_prev;
1171 struct wined3d_image_vk image0;
1172 VkDescriptorImageInfo vk_info0;
1173 VkImageLayout vk_layout0;
1174 uint32_t bind_mask0;
1175 DWORD locations0;
1176 unsigned int i;
1177
1178 static const DWORD supported_locations = WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_RB_MULTISAMPLE;
1179
1180 if (swapchain->state.desc.backbuffer_count < 2)
1181 return;
1182
1183 texture_prev = wined3d_texture_vk(swapchain->back_buffers[0]);
1184
1185 /* Back buffer 0 is already in the draw binding. */
1186 image0 = texture_prev->image;
1187 vk_layout0 = texture_prev->layout;
1188 bind_mask0 = texture_prev->bind_mask;
1189 vk_info0 = texture_prev->default_image_info;
1190 locations0 = texture_prev->t.sub_resources[0].locations;
1191
1192 for (i = 1; i < swapchain->state.desc.backbuffer_count; ++i)
1193 {
1195 sub_resource = &texture->t.sub_resources[0];
1196
1197 if (!(sub_resource->locations & supported_locations))
1198 wined3d_texture_load_location(&texture->t, 0, &context_vk->c, texture->t.resource.draw_binding);
1199
1200 texture_prev->image = texture->image;
1201 texture_prev->layout = texture->layout;
1202 texture_prev->bind_mask = texture->bind_mask;
1203 texture_prev->default_image_info = texture->default_image_info;
1204
1205 wined3d_texture_validate_location(&texture_prev->t, 0, sub_resource->locations & supported_locations);
1206 wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(sub_resource->locations & supported_locations));
1207
1208 texture_prev = texture;
1209 }
1210
1211 texture_prev->image = image0;
1212 texture_prev->layout = vk_layout0;
1213 texture_prev->bind_mask = bind_mask0;
1214 texture_prev->default_image_info = vk_info0;
1215
1216 wined3d_texture_validate_location(&texture_prev->t, 0, locations0 & supported_locations);
1217 wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(locations0 & supported_locations));
1218
1220}
VkDescriptorImageInfo default_image_info
Definition: wined3d_vk.h:881

Referenced by swapchain_vk_present().

◆ wined3d_swapchain_vk_select_vk_format()

static VkFormat wined3d_swapchain_vk_select_vk_format ( struct wined3d_swapchain_vk *  swapchain_vk,
VkSurfaceKHR  vk_surface 
)
static

Definition at line 723 of file swapchain.c.

725{
726 struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
727 const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
728 const struct wined3d_vk_info *vk_info;
729 struct wined3d_adapter_vk *adapter_vk;
730 const struct wined3d_format *format;
731 VkPhysicalDevice vk_physical_device;
732 VkSurfaceFormatKHR *vk_formats;
733 uint32_t format_count, i;
734 VkFormat vk_format;
735 VkResult vr;
736
737 adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
738 vk_physical_device = adapter_vk->physical_device;
739 vk_info = &adapter_vk->vk_info;
740
741 if ((format = wined3d_get_format(&adapter_vk->a, desc->backbuffer_format, WINED3D_BIND_RENDER_TARGET)))
742 vk_format = wined3d_format_vk(format)->vk_format;
743 else
744 vk_format = VK_FORMAT_B8G8R8A8_UNORM;
745
746 vr = VK_CALL(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device, vk_surface, &format_count, NULL));
747 if (vr < 0 || !format_count)
748 {
749 WARN("Failed to get supported surface format count, vr %s.\n", wined3d_debug_vkresult(vr));
750 return VK_FORMAT_UNDEFINED;
751 }
752
753 if (!(vk_formats = calloc(format_count, sizeof(*vk_formats))))
754 return VK_FORMAT_UNDEFINED;
755
756 if ((vr = VK_CALL(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device,
757 vk_surface, &format_count, vk_formats))) < 0)
758 {
759 WARN("Failed to get supported surface formats, vr %s.\n", wined3d_debug_vkresult(vr));
760 free(vk_formats);
761 return VK_FORMAT_UNDEFINED;
762 }
763
764 for (i = 0; i < format_count; ++i)
765 {
766 if (vk_formats[i].format == vk_format && vk_formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
767 break;
768 }
769 if (i == format_count)
770 {
771 /* Try to create a swapchain with format conversion. */
772 vk_format = get_swapchain_fallback_format(vk_format);
773 WARN("Failed to find Vulkan swapchain format for %s.\n", debug_d3dformat(desc->backbuffer_format));
774 for (i = 0; i < format_count; ++i)
775 {
776 if (vk_formats[i].format == vk_format && vk_formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
777 break;
778 }
779 }
780 free(vk_formats);
781 if (i == format_count)
782 {
783 FIXME("Failed to find Vulkan swapchain format for %s.\n", debug_d3dformat(desc->backbuffer_format));
784 return VK_FORMAT_UNDEFINED;
785 }
786
787 TRACE("Using Vulkan swapchain format %#x.\n", vk_format);
788
789 return vk_format;
790}
static VkFormat get_swapchain_fallback_format(VkFormat vk_format)
Definition: swapchain.c:1310
struct wined3d_adapter a
Definition: wined3d_vk.h:726
VkFormat vk_format
Definition: wined3d_vk.h:1083
VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats)

Referenced by wined3d_swapchain_vk_create_vulkan_swapchain().

◆ wined3d_swapchain_vk_set_swap_interval()

static void wined3d_swapchain_vk_set_swap_interval ( struct wined3d_swapchain_vk *  swapchain_vk,
unsigned int  swap_interval 
)
static

Definition at line 1022 of file swapchain.c.

1024{
1025 if (swap_interval > 1)
1026 {
1027 if (swap_interval <= 4)
1028 FIXME("Unsupported swap interval %u.\n", swap_interval);
1029 swap_interval = 1;
1030 }
1031
1032 if (swapchain_vk->s.swap_interval == swap_interval)
1033 return;
1034
1035 swapchain_vk->s.swap_interval = swap_interval;
1036 wined3d_swapchain_vk_recreate(swapchain_vk);
1037}

Referenced by wined3d_swapchain_vk_blit().

Variable Documentation

◆ swapchain_gl_ops

const struct wined3d_swapchain_ops swapchain_gl_ops
static
Initial value:
=
{
}
static void swapchain_frontbuffer_updated(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:643
static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
Definition: swapchain.c:583

Definition at line 654 of file swapchain.c.

Referenced by wined3d_swapchain_gl_init().

◆ swapchain_no3d_ops

const struct wined3d_swapchain_ops swapchain_no3d_ops
static
Initial value:
=
{
}
static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
Definition: swapchain.c:1316

Definition at line 1346 of file swapchain.c.

Referenced by wined3d_swapchain_no3d_init().

◆ swapchain_vk_ops

const struct wined3d_swapchain_ops swapchain_vk_ops
static
Initial value:
=
{
}
static void swapchain_vk_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
Definition: swapchain.c:1222

Definition at line 1268 of file swapchain.c.

Referenced by wined3d_swapchain_vk_init().