2008-10-29 09:00:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include "dxgi_private.h"
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
#ifdef SONAME_LIBVKD3D
|
|
|
|
#define VK_NO_PROTOTYPES
|
|
|
|
#define VKD3D_NO_PROTOTYPES
|
|
|
|
#define VKD3D_NO_VULKAN_H
|
|
|
|
#define VKD3D_NO_WIN32_TYPES
|
2018-06-01 13:10:22 +02:00
|
|
|
#define WINE_VK_HOST
|
2018-05-31 12:39:04 +02:00
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/vulkan.h"
|
|
|
|
#include "wine/vulkan_driver.h"
|
|
|
|
#include <vkd3d.h>
|
|
|
|
#endif
|
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
|
2018-05-31 12:39:04 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2018-08-30 13:50:26 +02:00
|
|
|
static DXGI_SWAP_EFFECT dxgi_swap_effect_from_wined3d(enum wined3d_swap_effect swap_effect)
|
|
|
|
{
|
|
|
|
switch (swap_effect)
|
|
|
|
{
|
|
|
|
case WINED3D_SWAP_EFFECT_DISCARD:
|
|
|
|
return DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
case WINED3D_SWAP_EFFECT_SEQUENTIAL:
|
|
|
|
return DXGI_SWAP_EFFECT_SEQUENTIAL;
|
|
|
|
case WINED3D_SWAP_EFFECT_FLIP_DISCARD:
|
|
|
|
return DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
|
|
|
case WINED3D_SWAP_EFFECT_FLIP_SEQUENTIAL:
|
|
|
|
return DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
|
|
|
default:
|
|
|
|
FIXME("Invalid swap effect %#x.\n", swap_effect);
|
|
|
|
return DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 16:06:02 +02:00
|
|
|
static BOOL dxgi_validate_flip_swap_effect_format(DXGI_FORMAT format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_R16G16B16A16_FLOAT:
|
|
|
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
WARN("Invalid swapchain format %#x for flip presentation model.\n", format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 16:06:00 +02:00
|
|
|
BOOL dxgi_validate_swapchain_desc(const DXGI_SWAP_CHAIN_DESC1 *desc)
|
|
|
|
{
|
|
|
|
unsigned int min_buffer_count;
|
|
|
|
|
|
|
|
switch (desc->SwapEffect)
|
|
|
|
{
|
|
|
|
case DXGI_SWAP_EFFECT_DISCARD:
|
|
|
|
case DXGI_SWAP_EFFECT_SEQUENTIAL:
|
|
|
|
min_buffer_count = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_DISCARD:
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL:
|
|
|
|
min_buffer_count = 2;
|
|
|
|
|
2018-09-18 16:06:02 +02:00
|
|
|
if (!dxgi_validate_flip_swap_effect_format(desc->Format))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-09-18 16:06:00 +02:00
|
|
|
if (desc->SampleDesc.Count != 1 || desc->SampleDesc.Quality)
|
|
|
|
{
|
|
|
|
WARN("Invalid sample desc %u, %u for swap effect %#x.\n",
|
|
|
|
desc->SampleDesc.Count, desc->SampleDesc.Quality, desc->SwapEffect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("Invalid swap effect %u used.\n", desc->SwapEffect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->BufferCount < min_buffer_count || desc->BufferCount > DXGI_MAX_SWAP_CHAIN_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("BufferCount is %u.\n", desc->BufferCount);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static inline struct d3d11_swapchain *d3d11_swapchain_from_IDXGISwapChain1(IDXGISwapChain1 *iface)
|
2011-06-06 10:25:49 +02:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d11_swapchain, IDXGISwapChain1_iface);
|
2011-06-06 10:25:49 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_QueryInterface(IDXGISwapChain1 *iface, REFIID riid, void **object)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIObject)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
|
2018-01-19 13:30:14 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGISwapChain)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGISwapChain1))
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d3d11_swapchain_AddRef(IDXGISwapChain1 *iface)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&swapchain->refcount);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
TRACE("%p increasing refcount to %u\n", swapchain, refcount);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2011-04-07 18:46:01 +02:00
|
|
|
if (refcount == 1)
|
2015-09-17 01:10:14 +02:00
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
2018-05-28 14:40:25 +02:00
|
|
|
wined3d_swapchain_incref(swapchain->wined3d_swapchain);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
2011-04-07 18:46:01 +02:00
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d3d11_swapchain_Release(IDXGISwapChain1 *iface)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2016-04-12 12:29:38 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&swapchain->refcount);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-04-12 12:29:38 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", swapchain, refcount);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
|
|
|
if (!refcount)
|
2015-09-17 01:10:14 +02:00
|
|
|
{
|
2016-04-12 12:29:38 +02:00
|
|
|
IWineDXGIDevice *device = swapchain->device;
|
2016-08-28 22:30:54 +02:00
|
|
|
if (swapchain->target)
|
|
|
|
{
|
|
|
|
WARN("Releasing fullscreen swapchain.\n");
|
|
|
|
IDXGIOutput_Release(swapchain->target);
|
|
|
|
}
|
2016-04-14 12:20:25 +02:00
|
|
|
if (swapchain->factory)
|
|
|
|
IDXGIFactory_Release(swapchain->factory);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2016-04-12 12:29:38 +02:00
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2016-04-12 12:29:38 +02:00
|
|
|
if (device)
|
|
|
|
IWineDXGIDevice_Release(device);
|
2015-09-17 01:10:14 +02:00
|
|
|
}
|
2008-10-29 09:00:26 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_SetPrivateData(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2015-02-17 10:15:40 +01:00
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_set_private_data(&swapchain->private_store, guid, data_size, data);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_SetPrivateDataInterface(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, const IUnknown *object)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2015-02-17 10:15:41 +01:00
|
|
|
TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return dxgi_set_private_data_interface(&swapchain->private_store, guid, object);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetPrivateData(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2015-02-18 10:39:28 +01:00
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_get_private_data(&swapchain->private_store, guid, data_size, data);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetParent(IDXGISwapChain1 *iface, REFIID riid, void **parent)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-04-14 12:20:25 +02:00
|
|
|
TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
|
|
|
|
|
|
|
|
if (!swapchain->factory)
|
|
|
|
{
|
|
|
|
ERR("Implicit swapchain does not store reference to parent.\n");
|
|
|
|
*parent = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IDXGIFactory_QueryInterface(swapchain->factory, riid, parent);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetDevice(IDXGISwapChain1 *iface, REFIID riid, void **device)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-04-12 12:29:38 +02:00
|
|
|
TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
|
|
|
|
|
|
|
|
if (!swapchain->device)
|
|
|
|
{
|
|
|
|
ERR("Implicit swapchain does not store reference to device.\n");
|
|
|
|
*device = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IWineDXGIDevice_QueryInterface(swapchain->device, riid, device);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
/* IDXGISwapChain1 methods */
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_Present(IDXGISwapChain1 *iface, UINT sync_interval, UINT flags)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
TRACE("iface %p, sync_interval %u, flags %#x.\n", iface, sync_interval, flags);
|
2015-09-17 01:10:14 +02:00
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
return IDXGISwapChain1_Present1(&swapchain->IDXGISwapChain1_iface, sync_interval, flags, NULL);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetBuffer(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
UINT buffer_idx, REFIID riid, void **surface)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2015-09-03 12:52:52 +02:00
|
|
|
struct wined3d_texture *texture;
|
2009-02-24 07:43:02 +01:00
|
|
|
IUnknown *parent;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, buffer_idx %u, riid %s, surface %p\n",
|
2008-10-29 09:00:26 +01:00
|
|
|
iface, buffer_idx, debugstr_guid(riid), surface);
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
if (!(texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, buffer_idx)))
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2012-10-04 13:53:27 +02:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2015-09-03 12:52:52 +02:00
|
|
|
parent = wined3d_texture_get_parent(texture);
|
2010-08-31 18:41:40 +02:00
|
|
|
hr = IUnknown_QueryInterface(parent, riid, surface);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE DECLSPEC_HOTPATCH d3d11_swapchain_SetFullscreenState(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
BOOL fullscreen, IDXGIOutput *target)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2016-08-03 09:41:41 +02:00
|
|
|
struct wined3d_swapchain_desc swapchain_desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, fullscreen %#x, target %p.\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
if (!fullscreen && target)
|
|
|
|
{
|
|
|
|
WARN("Invalid call.\n");
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
IDXGIOutput_AddRef(target);
|
|
|
|
}
|
2018-01-19 13:30:14 +01:00
|
|
|
else if (FAILED(hr = IDXGISwapChain1_GetContainingOutput(iface, &target)))
|
2016-08-03 09:41:41 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to get default target output for swapchain, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &swapchain_desc);
|
|
|
|
swapchain_desc.windowed = !fullscreen;
|
|
|
|
hr = wined3d_swapchain_set_fullscreen(swapchain->wined3d_swapchain, &swapchain_desc, NULL);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2016-08-28 22:30:53 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
swapchain->fullscreen = fullscreen;
|
|
|
|
if (swapchain->target)
|
|
|
|
IDXGIOutput_Release(swapchain->target);
|
|
|
|
swapchain->target = target;
|
2018-07-09 15:25:54 +02:00
|
|
|
return S_OK;
|
2016-08-28 22:30:53 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 15:25:54 +02:00
|
|
|
if (target)
|
|
|
|
IDXGIOutput_Release(target);
|
2016-08-03 09:41:41 +02:00
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetFullscreenState(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
BOOL *fullscreen, IDXGIOutput **target)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-08-03 09:41:40 +02:00
|
|
|
TRACE("iface %p, fullscreen %p, target %p.\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
if (fullscreen)
|
|
|
|
*fullscreen = swapchain->fullscreen;
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
*target = swapchain->target;
|
|
|
|
if (*target)
|
|
|
|
IDXGIOutput_AddRef(*target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetDesc(IDXGISwapChain1 *iface, DXGI_SWAP_CHAIN_DESC *desc)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2012-09-24 20:01:29 +02:00
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2018-01-25 10:56:29 +01:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
2012-09-24 20:01:29 +02:00
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
2012-09-24 20:01:29 +02:00
|
|
|
return E_INVALIDARG;
|
2018-01-19 13:30:14 +01:00
|
|
|
}
|
2012-09-24 20:01:29 +02:00
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-10-04 13:53:28 +02:00
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2012-09-24 20:01:29 +02:00
|
|
|
|
2018-08-30 13:50:26 +02:00
|
|
|
FIXME("Ignoring ScanlineOrdering and Scaling.\n");
|
2012-09-24 20:01:29 +02:00
|
|
|
|
|
|
|
desc->BufferDesc.Width = wined3d_desc.backbuffer_width;
|
|
|
|
desc->BufferDesc.Height = wined3d_desc.backbuffer_height;
|
|
|
|
desc->BufferDesc.RefreshRate.Numerator = wined3d_desc.refresh_rate;
|
|
|
|
desc->BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
desc->BufferDesc.Format = dxgi_format_from_wined3dformat(wined3d_desc.backbuffer_format);
|
|
|
|
desc->BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
|
|
|
desc->BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
2018-01-25 10:56:29 +01:00
|
|
|
dxgi_sample_desc_from_wined3d(&desc->SampleDesc,
|
|
|
|
wined3d_desc.multisample_type, wined3d_desc.multisample_quality);
|
|
|
|
desc->BufferUsage = dxgi_usage_from_wined3d_usage(wined3d_desc.backbuffer_usage);
|
2012-09-24 20:01:29 +02:00
|
|
|
desc->BufferCount = wined3d_desc.backbuffer_count;
|
|
|
|
desc->OutputWindow = wined3d_desc.device_window;
|
|
|
|
desc->Windowed = wined3d_desc.windowed;
|
2018-08-30 13:50:26 +02:00
|
|
|
desc->SwapEffect = dxgi_swap_effect_from_wined3d(wined3d_desc.swap_effect);
|
2016-08-03 09:41:38 +02:00
|
|
|
desc->Flags = dxgi_swapchain_flags_from_wined3d(wined3d_desc.flags);
|
2012-09-24 20:01:29 +02:00
|
|
|
|
2012-10-04 13:53:28 +02:00
|
|
|
return S_OK;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_ResizeBuffers(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2015-08-07 10:01:34 +02:00
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
2015-09-03 12:52:52 +02:00
|
|
|
struct wined3d_texture *texture;
|
2015-08-07 10:01:34 +02:00
|
|
|
IUnknown *parent;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-08-18 00:53:25 +02:00
|
|
|
TRACE("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x.\n",
|
2008-10-29 09:00:26 +01:00
|
|
|
iface, buffer_count, width, height, debug_dxgi_format(format), flags);
|
|
|
|
|
2015-08-07 10:01:34 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2015-08-07 10:01:34 +02:00
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
|
|
|
for (i = 0; i < wined3d_desc.backbuffer_count; ++i)
|
|
|
|
{
|
2015-09-07 23:50:34 +02:00
|
|
|
texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, i);
|
2015-09-03 12:52:52 +02:00
|
|
|
parent = wined3d_texture_get_parent(texture);
|
2015-08-07 10:01:34 +02:00
|
|
|
IUnknown_AddRef(parent);
|
|
|
|
if (IUnknown_Release(parent))
|
|
|
|
{
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2015-08-07 10:01:34 +02:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (format != DXGI_FORMAT_UNKNOWN)
|
|
|
|
wined3d_desc.backbuffer_format = wined3dformat_from_dxgi_format(format);
|
|
|
|
hr = wined3d_swapchain_resize_buffers(swapchain->wined3d_swapchain, buffer_count, width, height,
|
|
|
|
wined3d_desc.backbuffer_format, wined3d_desc.multisample_type, wined3d_desc.multisample_quality);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2015-08-07 10:01:34 +02:00
|
|
|
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_ResizeTarget(IDXGISwapChain1 *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
const DXGI_MODE_DESC *target_mode_desc)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2016-08-04 17:23:43 +02:00
|
|
|
struct wined3d_display_mode mode;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, target_mode_desc %p.\n", iface, target_mode_desc);
|
|
|
|
|
|
|
|
if (!target_mode_desc)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
2016-08-04 17:23:43 +02:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2018-01-19 13:30:14 +01:00
|
|
|
}
|
2016-08-04 17:23:43 +02:00
|
|
|
|
|
|
|
TRACE("Mode: %s.\n", debug_dxgi_mode(target_mode_desc));
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-08-04 17:23:43 +02:00
|
|
|
if (target_mode_desc->Scaling)
|
|
|
|
FIXME("Ignoring scaling %#x.\n", target_mode_desc->Scaling);
|
|
|
|
|
2016-08-25 12:22:50 +02:00
|
|
|
wined3d_display_mode_from_dxgi(&mode, target_mode_desc);
|
2016-08-04 17:23:43 +02:00
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
hr = wined3d_swapchain_resize_target(swapchain->wined3d_swapchain, &mode);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetContainingOutput(IDXGISwapChain1 *iface, IDXGIOutput **output)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2016-04-12 12:29:40 +02:00
|
|
|
IDXGIAdapter *adapter;
|
|
|
|
IDXGIDevice *device;
|
|
|
|
HRESULT hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2016-04-12 12:29:40 +02:00
|
|
|
TRACE("iface %p, output %p.\n", iface, output);
|
|
|
|
|
2016-08-03 09:41:43 +02:00
|
|
|
if (swapchain->target)
|
|
|
|
{
|
|
|
|
IDXGIOutput_AddRef(*output = swapchain->target);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
if (FAILED(hr = d3d11_swapchain_GetDevice(iface, &IID_IDXGIDevice, (void **)&device)))
|
2016-04-12 12:29:40 +02:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDXGIDevice_GetAdapter(device, &adapter);
|
|
|
|
IDXGIDevice_Release(device);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("GetAdapter failed, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(IDXGIAdapter_EnumOutputs(adapter, 1, output)))
|
|
|
|
{
|
|
|
|
FIXME("Adapter has got multiple outputs, returning the first one.\n");
|
|
|
|
IDXGIOutput_Release(*output);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDXGIAdapter_EnumOutputs(adapter, 0, output);
|
|
|
|
IDXGIAdapter_Release(adapter);
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetFrameStatistics(IDXGISwapChain1 *iface,
|
2018-01-19 13:30:14 +01:00
|
|
|
DXGI_FRAME_STATISTICS *stats)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, stats %p stub!\n", iface, stats);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetLastPresentCount(IDXGISwapChain1 *iface,
|
2018-01-19 13:30:14 +01:00
|
|
|
UINT *last_present_count)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, last_present_count %p stub!\n", iface, last_present_count);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
/* IDXGISwapChain1 methods */
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetDesc1(IDXGISwapChain1 *iface, DXGI_SWAP_CHAIN_DESC1 *desc)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2018-01-22 14:11:54 +01:00
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
2018-01-19 13:30:14 +01:00
|
|
|
|
2018-01-22 14:11:54 +01:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2018-08-30 13:50:26 +02:00
|
|
|
FIXME("Ignoring Stereo, Scaling and AlphaMode.\n");
|
2018-01-22 14:11:54 +01:00
|
|
|
|
|
|
|
desc->Width = wined3d_desc.backbuffer_width;
|
|
|
|
desc->Height = wined3d_desc.backbuffer_height;
|
|
|
|
desc->Format = dxgi_format_from_wined3dformat(wined3d_desc.backbuffer_format);
|
|
|
|
desc->Stereo = FALSE;
|
|
|
|
dxgi_sample_desc_from_wined3d(&desc->SampleDesc,
|
|
|
|
wined3d_desc.multisample_type, wined3d_desc.multisample_quality);
|
2018-01-25 10:56:29 +01:00
|
|
|
desc->BufferUsage = dxgi_usage_from_wined3d_usage(wined3d_desc.backbuffer_usage);
|
2018-01-22 14:11:54 +01:00
|
|
|
desc->BufferCount = wined3d_desc.backbuffer_count;
|
|
|
|
desc->Scaling = DXGI_SCALING_STRETCH;
|
2018-08-30 13:50:26 +02:00
|
|
|
desc->SwapEffect = dxgi_swap_effect_from_wined3d(wined3d_desc.swap_effect);
|
2018-01-22 14:11:54 +01:00
|
|
|
desc->AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
|
|
|
desc->Flags = dxgi_swapchain_flags_from_wined3d(wined3d_desc.flags);
|
|
|
|
|
|
|
|
return S_OK;
|
2018-01-19 13:30:14 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetFullscreenDesc(IDXGISwapChain1 *iface,
|
2018-01-19 13:30:14 +01:00
|
|
|
DXGI_SWAP_CHAIN_FULLSCREEN_DESC *desc)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2018-01-22 14:11:55 +01:00
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
2018-01-19 13:30:14 +01:00
|
|
|
|
2018-01-22 14:11:55 +01:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
FIXME("Ignoring ScanlineOrdering and Scaling.\n");
|
|
|
|
|
|
|
|
desc->RefreshRate.Numerator = wined3d_desc.refresh_rate;
|
|
|
|
desc->RefreshRate.Denominator = 1;
|
|
|
|
desc->ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
|
|
|
desc->Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
|
|
|
desc->Windowed = wined3d_desc.windowed;
|
|
|
|
|
|
|
|
return S_OK;
|
2018-01-19 13:30:14 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetHwnd(IDXGISwapChain1 *iface, HWND *hwnd)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2018-01-19 13:30:14 +01:00
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
|
|
|
|
|
|
|
TRACE("iface %p, hwnd %p.\n", iface, hwnd);
|
|
|
|
|
|
|
|
if (!hwnd)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
*hwnd = wined3d_desc.device_window;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetCoreWindow(IDXGISwapChain1 *iface,
|
2018-01-19 13:30:14 +01:00
|
|
|
REFIID iid, void **core_window)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, iid %s, core_window %p stub!\n", iface, debugstr_guid(iid), core_window);
|
|
|
|
|
|
|
|
if (core_window)
|
|
|
|
*core_window = NULL;
|
|
|
|
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_Present1(IDXGISwapChain1 *iface,
|
2018-01-19 13:30:14 +01:00
|
|
|
UINT sync_interval, UINT flags, const DXGI_PRESENT_PARAMETERS *present_parameters)
|
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface);
|
2018-01-19 13:30:14 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, sync_interval %u, flags %#x, present_parameters %p.\n",
|
|
|
|
iface, sync_interval, flags, present_parameters);
|
|
|
|
|
2018-03-22 08:48:31 +01:00
|
|
|
if (sync_interval > 4)
|
|
|
|
{
|
|
|
|
WARN("Invalid sync interval %u.\n", sync_interval);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
2018-01-25 10:33:26 +01:00
|
|
|
if (flags & ~DXGI_PRESENT_TEST)
|
|
|
|
FIXME("Unimplemented flags %#x.\n", flags);
|
|
|
|
if (flags & DXGI_PRESENT_TEST)
|
|
|
|
{
|
|
|
|
WARN("Returning S_OK for DXGI_PRESENT_TEST.\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
if (present_parameters)
|
|
|
|
FIXME("Ignored present parameters %p.\n", present_parameters);
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
2018-03-22 08:48:31 +01:00
|
|
|
hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, NULL, NULL, NULL, sync_interval, 0);
|
2018-01-19 13:30:14 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static BOOL STDMETHODCALLTYPE d3d11_swapchain_IsTemporaryMonoSupported(IDXGISwapChain1 *iface)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetRestrictToOutput(IDXGISwapChain1 *iface, IDXGIOutput **output)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, output %p stub!\n", iface, output);
|
|
|
|
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*output = NULL;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_SetBackgroundColor(IDXGISwapChain1 *iface, const DXGI_RGBA *color)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, color %p stub!\n", iface, color);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetBackgroundColor(IDXGISwapChain1 *iface, DXGI_RGBA *color)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, color %p stub!\n", iface, color);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_SetRotation(IDXGISwapChain1 *iface, DXGI_MODE_ROTATION rotation)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, rotation %#x stub!\n", iface, rotation);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetRotation(IDXGISwapChain1 *iface, DXGI_MODE_ROTATION *rotation)
|
2018-01-19 13:30:14 +01:00
|
|
|
{
|
|
|
|
FIXME("iface %p, rotation %p stub!\n", iface, rotation);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static const struct IDXGISwapChain1Vtbl d3d11_swapchain_vtbl =
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_QueryInterface,
|
|
|
|
d3d11_swapchain_AddRef,
|
|
|
|
d3d11_swapchain_Release,
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IDXGIObject methods */
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_SetPrivateData,
|
|
|
|
d3d11_swapchain_SetPrivateDataInterface,
|
|
|
|
d3d11_swapchain_GetPrivateData,
|
|
|
|
d3d11_swapchain_GetParent,
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IDXGIDeviceSubObject methods */
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_GetDevice,
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IDXGISwapChain methods */
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_Present,
|
|
|
|
d3d11_swapchain_GetBuffer,
|
|
|
|
d3d11_swapchain_SetFullscreenState,
|
|
|
|
d3d11_swapchain_GetFullscreenState,
|
|
|
|
d3d11_swapchain_GetDesc,
|
|
|
|
d3d11_swapchain_ResizeBuffers,
|
|
|
|
d3d11_swapchain_ResizeTarget,
|
|
|
|
d3d11_swapchain_GetContainingOutput,
|
|
|
|
d3d11_swapchain_GetFrameStatistics,
|
|
|
|
d3d11_swapchain_GetLastPresentCount,
|
2018-01-19 13:30:14 +01:00
|
|
|
/* IDXGISwapChain1 methods */
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_GetDesc1,
|
|
|
|
d3d11_swapchain_GetFullscreenDesc,
|
|
|
|
d3d11_swapchain_GetHwnd,
|
|
|
|
d3d11_swapchain_GetCoreWindow,
|
|
|
|
d3d11_swapchain_Present1,
|
|
|
|
d3d11_swapchain_IsTemporaryMonoSupported,
|
|
|
|
d3d11_swapchain_GetRestrictToOutput,
|
|
|
|
d3d11_swapchain_SetBackgroundColor,
|
|
|
|
d3d11_swapchain_GetBackgroundColor,
|
|
|
|
d3d11_swapchain_SetRotation,
|
|
|
|
d3d11_swapchain_GetRotation,
|
2008-10-29 09:00:26 +01:00
|
|
|
};
|
2009-12-28 17:38:05 +01:00
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static void STDMETHODCALLTYPE d3d11_swapchain_wined3d_object_released(void *parent)
|
2011-04-07 18:46:01 +02:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
struct d3d11_swapchain *swapchain = parent;
|
2015-02-17 10:15:40 +01:00
|
|
|
|
|
|
|
wined3d_private_store_cleanup(&swapchain->private_store);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(parent);
|
2011-04-07 18:46:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
static const struct wined3d_parent_ops d3d11_swapchain_wined3d_parent_ops =
|
2011-04-07 18:46:01 +02:00
|
|
|
{
|
2018-05-28 14:40:25 +02:00
|
|
|
d3d11_swapchain_wined3d_object_released,
|
2011-04-07 18:46:01 +02:00
|
|
|
};
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_device *device,
|
2016-04-12 12:29:38 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, BOOL implicit)
|
2009-12-28 17:38:05 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
/*
|
2016-04-12 12:29:38 +02:00
|
|
|
* A reference to the implicit swapchain is held by the wined3d device.
|
|
|
|
* In order to avoid circular references we do not keep a reference
|
|
|
|
* to the device in the implicit swapchain.
|
|
|
|
*/
|
|
|
|
if (!implicit)
|
|
|
|
{
|
2018-01-30 15:54:56 +01:00
|
|
|
if (FAILED(hr = IWineDXGIAdapter_GetParent(device->adapter, &IID_IDXGIFactory,
|
2016-04-14 12:20:25 +02:00
|
|
|
(void **)&swapchain->factory)))
|
|
|
|
{
|
|
|
|
WARN("Failed to get adapter parent, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2016-08-03 09:41:42 +02:00
|
|
|
IWineDXGIDevice_AddRef(swapchain->device = &device->IWineDXGIDevice_iface);
|
2016-04-12 12:29:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
swapchain->device = NULL;
|
2016-04-14 12:20:25 +02:00
|
|
|
swapchain->factory = NULL;
|
2016-04-12 12:29:38 +02:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:25 +02:00
|
|
|
swapchain->IDXGISwapChain1_iface.lpVtbl = &d3d11_swapchain_vtbl;
|
2016-04-14 12:20:25 +02:00
|
|
|
swapchain->refcount = 1;
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_private_store_init(&swapchain->private_store);
|
|
|
|
|
2016-08-25 12:22:55 +02:00
|
|
|
if (!desc->windowed && (!desc->backbuffer_width || !desc->backbuffer_height))
|
|
|
|
FIXME("Fullscreen swapchain with back buffer width/height equal to 0 not supported properly.\n");
|
|
|
|
|
2016-08-15 16:00:21 +02:00
|
|
|
swapchain->fullscreen = !desc->windowed;
|
|
|
|
desc->windowed = TRUE;
|
2016-04-14 12:20:25 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
|
2018-05-28 14:40:25 +02:00
|
|
|
&d3d11_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain)))
|
2016-04-14 12:20:25 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
|
2016-08-03 09:41:42 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
swapchain->target = NULL;
|
|
|
|
if (swapchain->fullscreen)
|
|
|
|
{
|
2016-08-15 16:00:21 +02:00
|
|
|
desc->windowed = FALSE;
|
2016-08-03 09:41:42 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_set_fullscreen(swapchain->wined3d_swapchain,
|
|
|
|
desc, NULL)))
|
|
|
|
{
|
|
|
|
WARN("Failed to set fullscreen state, hr %#x.\n", hr);
|
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:30:14 +01:00
|
|
|
if (FAILED(hr = IDXGISwapChain1_GetContainingOutput(&swapchain->IDXGISwapChain1_iface,
|
2016-08-03 09:41:42 +02:00
|
|
|
&swapchain->target)))
|
|
|
|
{
|
|
|
|
WARN("Failed to get target output for fullscreen swapchain, hr %#x.\n", hr);
|
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-04-14 12:20:25 +02:00
|
|
|
}
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2009-12-28 17:38:05 +01:00
|
|
|
return S_OK;
|
2016-08-03 09:41:42 +02:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
wined3d_private_store_cleanup(&swapchain->private_store);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (swapchain->factory)
|
|
|
|
IDXGIFactory_Release(swapchain->factory);
|
|
|
|
if (swapchain->device)
|
|
|
|
IWineDXGIDevice_Release(swapchain->device);
|
|
|
|
return hr;
|
2009-12-28 17:38:05 +01:00
|
|
|
}
|
2018-05-28 14:40:26 +02:00
|
|
|
|
|
|
|
HRESULT d3d11_swapchain_create(IWineDXGIDevice *device, HWND window, const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc,
|
|
|
|
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc, IDXGISwapChain1 **swapchain)
|
|
|
|
{
|
|
|
|
struct wined3d_swapchain *wined3d_swapchain;
|
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (swapchain_desc->Scaling != DXGI_SCALING_STRETCH)
|
|
|
|
FIXME("Ignoring scaling %#x.\n", swapchain_desc->Scaling);
|
|
|
|
if (swapchain_desc->AlphaMode != DXGI_ALPHA_MODE_IGNORE)
|
|
|
|
FIXME("Ignoring alpha mode %#x.\n", swapchain_desc->AlphaMode);
|
|
|
|
if (fullscreen_desc && fullscreen_desc->ScanlineOrdering)
|
|
|
|
FIXME("Unhandled scanline ordering %#x.\n", fullscreen_desc->ScanlineOrdering);
|
|
|
|
if (fullscreen_desc && fullscreen_desc->Scaling)
|
|
|
|
FIXME("Unhandled mode scaling %#x.\n", fullscreen_desc->Scaling);
|
|
|
|
|
|
|
|
switch (swapchain_desc->SwapEffect)
|
|
|
|
{
|
|
|
|
case DXGI_SWAP_EFFECT_DISCARD:
|
|
|
|
wined3d_desc.swap_effect = WINED3D_SWAP_EFFECT_DISCARD;
|
|
|
|
break;
|
|
|
|
case DXGI_SWAP_EFFECT_SEQUENTIAL:
|
|
|
|
wined3d_desc.swap_effect = WINED3D_SWAP_EFFECT_SEQUENTIAL;
|
|
|
|
break;
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_DISCARD:
|
|
|
|
wined3d_desc.swap_effect = WINED3D_SWAP_EFFECT_FLIP_DISCARD;
|
|
|
|
break;
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL:
|
|
|
|
wined3d_desc.swap_effect = WINED3D_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Invalid swap effect %#x.\n", swapchain_desc->SwapEffect);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_desc.backbuffer_width = swapchain_desc->Width;
|
|
|
|
wined3d_desc.backbuffer_height = swapchain_desc->Height;
|
|
|
|
wined3d_desc.backbuffer_format = wined3dformat_from_dxgi_format(swapchain_desc->Format);
|
|
|
|
wined3d_desc.backbuffer_count = swapchain_desc->BufferCount;
|
|
|
|
wined3d_desc.backbuffer_usage = wined3d_usage_from_dxgi_usage(swapchain_desc->BufferUsage);
|
|
|
|
wined3d_sample_desc_from_dxgi(&wined3d_desc.multisample_type,
|
|
|
|
&wined3d_desc.multisample_quality, &swapchain_desc->SampleDesc);
|
|
|
|
wined3d_desc.device_window = window;
|
|
|
|
wined3d_desc.windowed = fullscreen_desc ? fullscreen_desc->Windowed : TRUE;
|
|
|
|
wined3d_desc.enable_auto_depth_stencil = FALSE;
|
|
|
|
wined3d_desc.auto_depth_stencil_format = 0;
|
|
|
|
wined3d_desc.flags = wined3d_swapchain_flags_from_dxgi(swapchain_desc->Flags);
|
|
|
|
wined3d_desc.refresh_rate = fullscreen_desc ? dxgi_rational_to_uint(&fullscreen_desc->RefreshRate) : 0;
|
|
|
|
wined3d_desc.auto_restore_display_mode = TRUE;
|
|
|
|
|
|
|
|
if (FAILED(hr = IWineDXGIDevice_create_swapchain(device, &wined3d_desc, FALSE, &wined3d_swapchain)))
|
|
|
|
{
|
|
|
|
WARN("Failed to create swapchain, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
*swapchain = wined3d_swapchain_get_parent(wined3d_swapchain);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
#ifdef SONAME_LIBVKD3D
|
|
|
|
|
|
|
|
static PFN_vkd3d_acquire_vk_queue vkd3d_acquire_vk_queue;
|
|
|
|
static PFN_vkd3d_create_image_resource vkd3d_create_image_resource;
|
|
|
|
static PFN_vkd3d_get_vk_device vkd3d_get_vk_device;
|
|
|
|
static PFN_vkd3d_get_vk_format vkd3d_get_vk_format;
|
|
|
|
static PFN_vkd3d_get_vk_physical_device vkd3d_get_vk_physical_device;
|
|
|
|
static PFN_vkd3d_get_vk_queue_family_index vkd3d_get_vk_queue_family_index;
|
|
|
|
static PFN_vkd3d_instance_from_device vkd3d_instance_from_device;
|
|
|
|
static PFN_vkd3d_instance_get_vk_instance vkd3d_instance_get_vk_instance;
|
|
|
|
static PFN_vkd3d_release_vk_queue vkd3d_release_vk_queue;
|
|
|
|
static PFN_vkd3d_resource_decref vkd3d_resource_decref;
|
|
|
|
static PFN_vkd3d_resource_incref vkd3d_resource_incref;
|
|
|
|
|
|
|
|
struct dxgi_vk_funcs
|
|
|
|
{
|
|
|
|
PFN_vkAcquireNextImageKHR p_vkAcquireNextImageKHR;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkAllocateCommandBuffers p_vkAllocateCommandBuffers;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkAllocateMemory p_vkAllocateMemory;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkBeginCommandBuffer p_vkBeginCommandBuffer;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkBindImageMemory p_vkBindImageMemory;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkCmdBlitImage p_vkCmdBlitImage;
|
|
|
|
PFN_vkCmdPipelineBarrier p_vkCmdPipelineBarrier;
|
|
|
|
PFN_vkCreateCommandPool p_vkCreateCommandPool;
|
2018-08-08 16:11:35 +02:00
|
|
|
PFN_vkCreateFence p_vkCreateFence;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkCreateImage p_vkCreateImage;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkCreateSemaphore p_vkCreateSemaphore;
|
2018-05-31 12:39:04 +02:00
|
|
|
PFN_vkCreateSwapchainKHR p_vkCreateSwapchainKHR;
|
|
|
|
PFN_vkCreateWin32SurfaceKHR p_vkCreateWin32SurfaceKHR;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkDestroyCommandPool p_vkDestroyCommandPool;
|
2018-08-08 16:11:35 +02:00
|
|
|
PFN_vkDestroyFence p_vkDestroyFence;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkDestroyImage p_vkDestroyImage;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkDestroySemaphore p_vkDestroySemaphore;
|
2018-05-31 12:39:04 +02:00
|
|
|
PFN_vkDestroySurfaceKHR p_vkDestroySurfaceKHR;
|
|
|
|
PFN_vkDestroySwapchainKHR p_vkDestroySwapchainKHR;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkEndCommandBuffer p_vkEndCommandBuffer;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkFreeMemory p_vkFreeMemory;
|
|
|
|
PFN_vkGetImageMemoryRequirements p_vkGetImageMemoryRequirements;
|
2018-05-31 12:39:04 +02:00
|
|
|
PFN_vkGetInstanceProcAddr p_vkGetInstanceProcAddr;
|
2018-08-08 16:11:37 +02:00
|
|
|
PFN_vkGetPhysicalDeviceMemoryProperties p_vkGetPhysicalDeviceMemoryProperties;
|
2018-05-31 12:39:04 +02:00
|
|
|
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR p_vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR p_vkGetPhysicalDeviceSurfaceFormatsKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR p_vkGetPhysicalDeviceSurfacePresentModesKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceSupportKHR p_vkGetPhysicalDeviceSurfaceSupportKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR p_vkGetPhysicalDeviceWin32PresentationSupportKHR;
|
|
|
|
PFN_vkGetSwapchainImagesKHR p_vkGetSwapchainImagesKHR;
|
|
|
|
PFN_vkQueuePresentKHR p_vkQueuePresentKHR;
|
2018-08-08 16:11:38 +02:00
|
|
|
PFN_vkQueueSubmit p_vkQueueSubmit;
|
2018-08-08 16:11:35 +02:00
|
|
|
PFN_vkQueueWaitIdle p_vkQueueWaitIdle;
|
2018-05-31 12:39:04 +02:00
|
|
|
PFN_vkResetFences p_vkResetFences;
|
2018-08-08 16:11:35 +02:00
|
|
|
PFN_vkWaitForFences p_vkWaitForFences;
|
2018-05-31 12:39:04 +02:00
|
|
|
};
|
|
|
|
|
2018-06-01 12:45:07 +02:00
|
|
|
static HRESULT hresult_from_vk_result(VkResult vr)
|
|
|
|
{
|
|
|
|
switch (vr)
|
|
|
|
{
|
|
|
|
case VK_SUCCESS:
|
|
|
|
return S_OK;
|
|
|
|
case VK_ERROR_OUT_OF_HOST_MEMORY:
|
|
|
|
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled VkResult %d.\n", vr);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:27 +02:00
|
|
|
struct d3d12_swapchain
|
|
|
|
{
|
|
|
|
IDXGISwapChain3 IDXGISwapChain3_iface;
|
|
|
|
LONG refcount;
|
|
|
|
struct wined3d_private_store private_store;
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
VkSwapchainKHR vk_swapchain;
|
|
|
|
VkSurfaceKHR vk_surface;
|
|
|
|
VkFence vk_fence;
|
|
|
|
VkInstance vk_instance;
|
|
|
|
VkDevice vk_device;
|
2018-08-08 16:11:37 +02:00
|
|
|
VkPhysicalDevice vk_physical_device;
|
|
|
|
VkDeviceMemory vk_memory;
|
2018-08-08 16:11:38 +02:00
|
|
|
VkCommandPool vk_cmd_pool;
|
2018-08-08 16:11:37 +02:00
|
|
|
VkImage vk_images[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
2018-08-08 16:11:38 +02:00
|
|
|
VkCommandBuffer vk_cmd_buffers[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
|
|
|
VkSemaphore vk_semaphores[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
2018-05-31 12:39:04 +02:00
|
|
|
ID3D12Resource *buffers[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
|
|
|
unsigned int buffer_count;
|
|
|
|
|
|
|
|
uint32_t current_buffer_index;
|
|
|
|
struct dxgi_vk_funcs vk_funcs;
|
|
|
|
|
2018-05-28 14:40:27 +02:00
|
|
|
ID3D12CommandQueue *command_queue;
|
|
|
|
ID3D12Device *device;
|
|
|
|
IWineDXGIFactory *factory;
|
|
|
|
|
|
|
|
HWND window;
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 desc;
|
|
|
|
DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreen_desc;
|
|
|
|
};
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static DXGI_FORMAT dxgi_format_from_vk_format(VkFormat vk_format)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
switch (vk_format)
|
|
|
|
{
|
|
|
|
case VK_FORMAT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
|
2018-08-30 13:50:24 +02:00
|
|
|
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return DXGI_FORMAT_R10G10B10A2_UNORM;
|
2018-09-18 16:06:03 +02:00
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
|
2018-08-29 12:53:34 +02:00
|
|
|
default:
|
|
|
|
WARN("Unhandled format %#x.\n", vk_format);
|
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static VkFormat get_swapchain_fallback_format(VkFormat vk_format)
|
|
|
|
{
|
|
|
|
switch (vk_format)
|
|
|
|
{
|
2018-09-18 16:06:03 +02:00
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
|
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
return VK_FORMAT_B8G8R8A8_UNORM;
|
2018-08-29 12:53:34 +02:00
|
|
|
default:
|
|
|
|
WARN("Unhandled format %#x.\n", vk_format);
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static HRESULT select_vk_format(const struct dxgi_vk_funcs *vk_funcs,
|
|
|
|
VkPhysicalDevice vk_physical_device, VkSurfaceKHR vk_surface,
|
|
|
|
const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc, VkFormat *vk_format)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
VkSurfaceFormatKHR *formats;
|
|
|
|
uint32_t format_count;
|
|
|
|
VkFormat format;
|
|
|
|
unsigned int i;
|
|
|
|
VkResult vr;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
*vk_format = VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
format = vkd3d_get_vk_format(swapchain_desc->Format);
|
|
|
|
|
|
|
|
vr = vk_funcs->p_vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device, vk_surface, &format_count, NULL);
|
|
|
|
if (vr < 0 || !format_count)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
WARN("Failed to get supported surface formats, vr %d.\n", vr);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if (!(formats = heap_calloc(format_count, sizeof(*formats))))
|
|
|
|
return E_OUTOFMEMORY;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device,
|
|
|
|
vk_surface, &format_count, formats)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to enumerate supported surface formats, vr %d.\n", vr);
|
|
|
|
heap_free(formats);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
for (i = 0; i < format_count; ++i)
|
|
|
|
{
|
|
|
|
if (formats[i].format == format && formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == format_count)
|
|
|
|
{
|
|
|
|
/* Try to create a swapchain with format conversion. */
|
|
|
|
format = get_swapchain_fallback_format(format);
|
|
|
|
WARN("Failed to find Vulkan swapchain format for %s.\n", debug_dxgi_format(swapchain_desc->Format));
|
|
|
|
for (i = 0; i < format_count; ++i)
|
|
|
|
{
|
|
|
|
if (formats[i].format == format && formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
|
|
{
|
|
|
|
format = formats[i].format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free(formats);
|
|
|
|
if (i == format_count)
|
|
|
|
{
|
|
|
|
FIXME("Failed to find Vulkan swapchain format for %s.\n", debug_dxgi_format(swapchain_desc->Format));
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
TRACE("Using Vulkan swapchain format %#x.\n", format);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
*vk_format = format;
|
|
|
|
return S_OK;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static HRESULT vk_select_memory_type(const struct dxgi_vk_funcs *vk_funcs,
|
|
|
|
VkPhysicalDevice vk_physical_device, uint32_t memory_type_mask,
|
|
|
|
VkMemoryPropertyFlags flags, uint32_t *memory_type_index)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
VkPhysicalDeviceMemoryProperties memory_properties;
|
2018-05-31 12:39:04 +02:00
|
|
|
unsigned int i;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_funcs->p_vkGetPhysicalDeviceMemoryProperties(vk_physical_device, &memory_properties);
|
|
|
|
for (i = 0; i < memory_properties.memoryTypeCount; ++i)
|
2018-08-08 16:11:35 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
if (!(memory_type_mask & (1u << i)))
|
|
|
|
continue;
|
2018-08-08 16:11:35 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((memory_properties.memoryTypes[i].propertyFlags & flags) == flags)
|
2018-08-08 16:11:35 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
*memory_type_index = i;
|
|
|
|
return S_OK;
|
2018-08-08 16:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
FIXME("Failed to find memory type (allowed types %#x).\n", memory_type_mask);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
static HRESULT d3d12_swapchain_create_user_buffers(struct d3d12_swapchain *swapchain, VkFormat vk_format)
|
2018-08-29 12:53:34 +02:00
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkDeviceSize image_offset[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
|
|
|
VkDevice vk_device = swapchain->vk_device;
|
|
|
|
VkMemoryAllocateInfo allocate_info;
|
|
|
|
VkMemoryRequirements requirements;
|
|
|
|
VkImageCreateInfo image_info;
|
|
|
|
uint32_t memory_type_mask;
|
|
|
|
VkDeviceSize memory_size;
|
|
|
|
unsigned int i;
|
|
|
|
VkResult vr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
memset(&image_info, 0, sizeof(image_info));
|
|
|
|
image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
|
|
|
image_info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
|
|
|
image_info.imageType = VK_IMAGE_TYPE_2D;
|
|
|
|
image_info.format = vk_format;
|
2018-08-29 12:53:36 +02:00
|
|
|
image_info.extent.width = swapchain->desc.Width;
|
|
|
|
image_info.extent.height = swapchain->desc.Height;
|
2018-08-29 12:53:34 +02:00
|
|
|
image_info.extent.depth = 1;
|
|
|
|
image_info.mipLevels = 1;
|
|
|
|
image_info.arrayLayers = 1;
|
|
|
|
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
|
|
image_info.queueFamilyIndexCount = 0;
|
|
|
|
image_info.pQueueFamilyIndices = NULL;
|
|
|
|
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-08 16:11:34 +02:00
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkCreateImage(vk_device, &image_info, NULL, &swapchain->vk_images[i])) < 0)
|
2018-08-08 16:11:38 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
WARN("Failed to create Vulkan image, vr %d.\n", vr);
|
|
|
|
swapchain->vk_images[i] = VK_NULL_HANDLE;
|
|
|
|
return hresult_from_vk_result(vr);
|
2018-08-08 16:11:38 +02:00
|
|
|
}
|
2018-08-08 16:11:34 +02:00
|
|
|
}
|
2018-05-31 12:39:04 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
memory_size = 0;
|
|
|
|
memory_type_mask = ~0u;
|
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
2018-08-08 16:11:34 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_funcs->p_vkGetImageMemoryRequirements(vk_device, swapchain->vk_images[i], &requirements);
|
2018-08-08 16:11:37 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
TRACE("Size %s, alignment %s, memory types %#x.\n",
|
|
|
|
wine_dbgstr_longlong(requirements.size), wine_dbgstr_longlong(requirements.alignment),
|
|
|
|
requirements.memoryTypeBits);
|
|
|
|
|
|
|
|
image_offset[i] = (memory_size + (requirements.alignment - 1)) & ~(requirements.alignment - 1);
|
|
|
|
memory_size = image_offset[i] + requirements.size;
|
|
|
|
|
|
|
|
memory_type_mask &= requirements.memoryTypeBits;
|
2018-08-08 16:11:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
TRACE("Allocating %s bytes for user images.\n", wine_dbgstr_longlong(memory_size));
|
2018-05-31 12:39:04 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
|
|
|
allocate_info.pNext = NULL;
|
|
|
|
allocate_info.allocationSize = memory_size;
|
2018-08-08 16:11:34 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if (FAILED(hr = vk_select_memory_type(vk_funcs, swapchain->vk_physical_device,
|
|
|
|
memory_type_mask, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &allocate_info.memoryTypeIndex)))
|
|
|
|
return hr;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkAllocateMemory(vk_device, &allocate_info, NULL, &swapchain->vk_memory)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to allocate device memory, vr %d.\n", vr);
|
|
|
|
swapchain->vk_memory = VK_NULL_HANDLE;
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-08-08 16:11:34 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
2018-08-08 16:11:34 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkBindImageMemory(vk_device, swapchain->vk_images[i],
|
|
|
|
swapchain->vk_memory, image_offset[i])) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to bind image memory, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
return S_OK;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static void vk_cmd_image_barrier(const struct dxgi_vk_funcs *vk_funcs, VkCommandBuffer cmd_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)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
VkImageMemoryBarrier barrier;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
|
|
|
barrier.pNext = NULL;
|
|
|
|
barrier.srcAccessMask = src_access_mask;
|
|
|
|
barrier.dstAccessMask = dst_access_mask;
|
|
|
|
barrier.oldLayout = old_layout;
|
|
|
|
barrier.newLayout = new_layout;
|
|
|
|
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
|
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
|
barrier.image = image;
|
|
|
|
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
barrier.subresourceRange.baseMipLevel = 0;
|
|
|
|
barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
|
|
|
barrier.subresourceRange.baseArrayLayer = 0;
|
|
|
|
barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_funcs->p_vkCmdPipelineBarrier(cmd_buffer,
|
|
|
|
src_stage_mask, dst_stage_mask, 0, 0, NULL, 0, NULL, 1, &barrier);
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static HRESULT d3d12_swapchain_prepare_command_buffers(struct d3d12_swapchain *swapchain,
|
2018-08-29 12:53:36 +02:00
|
|
|
uint32_t queue_family_index, VkImage vk_swapchain_images[DXGI_MAX_SWAP_CHAIN_BUFFERS])
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkDevice vk_device = swapchain->vk_device;
|
|
|
|
VkCommandBufferAllocateInfo allocate_info;
|
|
|
|
VkSemaphoreCreateInfo semaphore_info;
|
|
|
|
VkCommandBufferBeginInfo begin_info;
|
|
|
|
VkCommandPoolCreateInfo pool_info;
|
|
|
|
VkImageBlit blit;
|
|
|
|
unsigned int i;
|
|
|
|
VkResult vr;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
|
|
pool_info.pNext = NULL;
|
|
|
|
pool_info.flags = 0;
|
|
|
|
pool_info.queueFamilyIndex = queue_family_index;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkCreateCommandPool(vk_device, &pool_info,
|
|
|
|
NULL, &swapchain->vk_cmd_pool)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to create command pool, vr %d.\n", vr);
|
|
|
|
swapchain->vk_cmd_pool = VK_NULL_HANDLE;
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
|
|
|
allocate_info.pNext = NULL;
|
|
|
|
allocate_info.commandPool = swapchain->vk_cmd_pool;
|
|
|
|
allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
|
|
allocate_info.commandBufferCount = swapchain->buffer_count;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkAllocateCommandBuffers(vk_device, &allocate_info,
|
|
|
|
swapchain->vk_cmd_buffers)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to allocate command buffers, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
|
|
|
VkCommandBuffer vk_cmd_buffer = swapchain->vk_cmd_buffers[i];
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
|
|
begin_info.pNext = NULL;
|
|
|
|
begin_info.flags = 0;
|
|
|
|
begin_info.pInheritanceInfo = NULL;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkBeginCommandBuffer(vk_cmd_buffer, &begin_info)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to begin command buffer, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_cmd_image_barrier(vk_funcs, vk_cmd_buffer,
|
|
|
|
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
0, VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
vk_swapchain_images[i]);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
blit.srcSubresource.mipLevel = 0;
|
|
|
|
blit.srcSubresource.baseArrayLayer = 0;
|
|
|
|
blit.srcSubresource.layerCount = 1;
|
|
|
|
blit.srcOffsets[0].x = 0;
|
|
|
|
blit.srcOffsets[0].y = 0;
|
|
|
|
blit.srcOffsets[0].z = 0;
|
2018-08-29 12:53:36 +02:00
|
|
|
blit.srcOffsets[1].x = swapchain->desc.Width;
|
|
|
|
blit.srcOffsets[1].y = swapchain->desc.Height;
|
2018-08-29 12:53:34 +02:00
|
|
|
blit.srcOffsets[1].z = 1;
|
|
|
|
blit.dstSubresource = blit.srcSubresource;
|
|
|
|
blit.dstOffsets[0] = blit.srcOffsets[0];
|
|
|
|
blit.dstOffsets[1] = blit.srcOffsets[1];
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_funcs->p_vkCmdBlitImage(vk_cmd_buffer,
|
|
|
|
swapchain->vk_images[i], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
|
|
vk_swapchain_images[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
1, &blit, VK_FILTER_NEAREST);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vk_cmd_image_barrier(vk_funcs, vk_cmd_buffer,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT, 0,
|
|
|
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
|
|
|
vk_swapchain_images[i]);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkEndCommandBuffer(vk_cmd_buffer)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to end command buffer, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
|
|
|
semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
|
|
semaphore_info.pNext = NULL;
|
|
|
|
semaphore_info.flags = 0;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkCreateSemaphore(vk_device, &semaphore_info,
|
|
|
|
NULL, &swapchain->vk_semaphores[i])) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to create semaphore, vr %d.\n", vr);
|
|
|
|
swapchain->vk_semaphores[i] = VK_NULL_HANDLE;
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
return S_OK;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static HRESULT d3d12_swapchain_create_buffers(struct d3d12_swapchain *swapchain,
|
2018-08-29 12:53:36 +02:00
|
|
|
VkFormat vk_swapchain_format, VkFormat vk_format)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkImage vk_swapchain_images[DXGI_MAX_SWAP_CHAIN_BUFFERS];
|
|
|
|
struct vkd3d_image_resource_create_info resource_info;
|
|
|
|
VkSwapchainKHR vk_swapchain = swapchain->vk_swapchain;
|
2018-08-29 12:53:36 +02:00
|
|
|
ID3D12CommandQueue *queue = swapchain->command_queue;
|
2018-08-29 12:53:34 +02:00
|
|
|
VkDevice vk_device = swapchain->vk_device;
|
2018-08-29 12:53:36 +02:00
|
|
|
ID3D12Device *device = swapchain->device;
|
2018-08-29 12:53:34 +02:00
|
|
|
uint32_t image_count, queue_family_index;
|
|
|
|
D3D12_COMMAND_QUEUE_DESC queue_desc;
|
|
|
|
unsigned int i;
|
|
|
|
VkResult vr;
|
|
|
|
HRESULT hr;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if ((vr = vk_funcs->p_vkGetSwapchainImagesKHR(vk_device, vk_swapchain, &image_count, NULL)) < 0)
|
2018-05-31 12:04:33 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
WARN("Failed to get Vulkan swapchain images, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
2018-08-29 12:53:36 +02:00
|
|
|
if (image_count != swapchain->desc.BufferCount)
|
|
|
|
FIXME("Got %u swapchain images, expected %u.\n", image_count, swapchain->desc.BufferCount);
|
2018-08-29 12:53:34 +02:00
|
|
|
if (image_count > ARRAY_SIZE(vk_swapchain_images))
|
|
|
|
return E_FAIL;
|
|
|
|
swapchain->buffer_count = image_count;
|
|
|
|
if ((vr = vk_funcs->p_vkGetSwapchainImagesKHR(vk_device, vk_swapchain,
|
|
|
|
&image_count, vk_swapchain_images)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to get Vulkan swapchain images, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
2018-05-31 12:04:33 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
resource_info.type = VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO;
|
|
|
|
resource_info.next = NULL;
|
|
|
|
resource_info.desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
|
|
|
resource_info.desc.Alignment = 0;
|
2018-08-29 12:53:36 +02:00
|
|
|
resource_info.desc.Width = swapchain->desc.Width;
|
|
|
|
resource_info.desc.Height = swapchain->desc.Height;
|
2018-08-29 12:53:34 +02:00
|
|
|
resource_info.desc.DepthOrArraySize = 1;
|
|
|
|
resource_info.desc.MipLevels = 1;
|
|
|
|
resource_info.desc.Format = dxgi_format_from_vk_format(vk_format);
|
|
|
|
resource_info.desc.SampleDesc.Count = 1;
|
|
|
|
resource_info.desc.SampleDesc.Quality = 0;
|
|
|
|
resource_info.desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
|
|
|
resource_info.desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
|
|
|
resource_info.flags = VKD3D_RESOURCE_INITIAL_STATE_TRANSITION | VKD3D_RESOURCE_PRESENT_STATE_TRANSITION;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if (vk_swapchain_format != vk_format)
|
|
|
|
{
|
|
|
|
queue_desc = ID3D12CommandQueue_GetDesc(queue);
|
|
|
|
if (queue_desc.Type != D3D12_COMMAND_LIST_TYPE_DIRECT)
|
|
|
|
{
|
|
|
|
/* vkCmdBlitImage() is only supported for Graphics queues. */
|
|
|
|
FIXME("Format conversion not implemented for command queue type %#x.\n", queue_desc.Type);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
queue_family_index = vkd3d_get_vk_queue_family_index(queue);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
TRACE("Creating user swapchain buffers for format conversion.\n");
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
if (FAILED(hr = d3d12_swapchain_create_user_buffers(swapchain, vk_format)))
|
2018-08-29 12:53:34 +02:00
|
|
|
return hr;
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
if (FAILED(hr = d3d12_swapchain_prepare_command_buffers(swapchain,
|
2018-08-29 12:53:34 +02:00
|
|
|
queue_family_index, vk_swapchain_images)))
|
|
|
|
return hr;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
|
|
|
if (swapchain->vk_images[i])
|
|
|
|
{
|
|
|
|
resource_info.vk_image = swapchain->vk_images[i];
|
|
|
|
resource_info.present_state = D3D12_RESOURCE_STATE_COPY_SOURCE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resource_info.vk_image = vk_swapchain_images[i];
|
|
|
|
resource_info.present_state = D3D12_RESOURCE_STATE_PRESENT;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
if (FAILED(hr = vkd3d_create_image_resource(device, &resource_info, &swapchain->buffers[i])))
|
|
|
|
{
|
|
|
|
WARN("Failed to create vkd3d resource for Vulkan image %u, hr %#x.\n", i, hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
vkd3d_resource_incref(swapchain->buffers[i]);
|
|
|
|
ID3D12Resource_Release(swapchain->buffers[i]);
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:37 +02:00
|
|
|
static HRESULT d3d12_swapchain_acquire_next_image(struct d3d12_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkDevice vk_device = swapchain->vk_device;
|
|
|
|
VkFence vk_fence = swapchain->vk_fence;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
if ((vr = vk_funcs->p_vkAcquireNextImageKHR(vk_device, swapchain->vk_swapchain, UINT64_MAX,
|
|
|
|
VK_NULL_HANDLE, vk_fence, &swapchain->current_buffer_index)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to acquire next Vulkan image, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vr = vk_funcs->p_vkWaitForFences(vk_device, 1, &vk_fence, VK_TRUE, UINT64_MAX)) != VK_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to wait for fence, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
if ((vr = vk_funcs->p_vkResetFences(vk_device, 1, &vk_fence)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to reset fence, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:35 +02:00
|
|
|
static void d3d12_swapchain_destroy_buffers(struct d3d12_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkQueue vk_queue;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (swapchain->command_queue)
|
|
|
|
{
|
|
|
|
if ((vk_queue = vkd3d_acquire_vk_queue(swapchain->command_queue)))
|
|
|
|
{
|
|
|
|
vk_funcs->p_vkQueueWaitIdle(vk_queue);
|
|
|
|
|
|
|
|
vkd3d_release_vk_queue(swapchain->command_queue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Failed to acquire Vulkan queue.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
|
|
|
if (swapchain->buffers[i])
|
|
|
|
{
|
|
|
|
vkd3d_resource_decref(swapchain->buffers[i]);
|
|
|
|
swapchain->buffers[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->vk_device)
|
|
|
|
{
|
|
|
|
vk_funcs->p_vkDestroyImage(swapchain->vk_device, swapchain->vk_images[i], NULL);
|
|
|
|
swapchain->vk_images[i] = VK_NULL_HANDLE;
|
|
|
|
vk_funcs->p_vkDestroySemaphore(swapchain->vk_device, swapchain->vk_semaphores[i], NULL);
|
|
|
|
swapchain->vk_semaphores[i] = VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->vk_device)
|
|
|
|
{
|
|
|
|
vk_funcs->p_vkFreeMemory(swapchain->vk_device, swapchain->vk_memory, NULL);
|
|
|
|
swapchain->vk_memory = VK_NULL_HANDLE;
|
|
|
|
vk_funcs->p_vkDestroyCommandPool(swapchain->vk_device, swapchain->vk_cmd_pool, NULL);
|
|
|
|
swapchain->vk_cmd_pool = VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
static HRESULT d3d12_swapchain_create_vulkan_swapchain(struct d3d12_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
VkPhysicalDevice vk_physical_device = swapchain->vk_physical_device;
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkSwapchainCreateInfoKHR vk_swapchain_desc;
|
|
|
|
VkDevice vk_device = swapchain->vk_device;
|
|
|
|
VkFormat vk_format, vk_swapchain_format;
|
|
|
|
VkSurfaceCapabilitiesKHR surface_caps;
|
|
|
|
VkSwapchainKHR vk_swapchain;
|
|
|
|
VkImageUsageFlags usage;
|
|
|
|
VkResult vr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(vk_format = vkd3d_get_vk_format(swapchain->desc.Format)))
|
|
|
|
{
|
|
|
|
WARN("Invalid format %#x.\n", swapchain->desc.Format);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = select_vk_format(vk_funcs, vk_physical_device,
|
|
|
|
swapchain->vk_surface, &swapchain->desc, &vk_swapchain_format)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if ((vr = vk_funcs->p_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_physical_device,
|
|
|
|
swapchain->vk_surface, &surface_caps)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to get surface capabilities, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface_caps.maxImageCount && (swapchain->desc.BufferCount > surface_caps.maxImageCount
|
|
|
|
|| swapchain->desc.BufferCount < surface_caps.minImageCount))
|
|
|
|
{
|
|
|
|
WARN("Buffer count %u is not supported (%u-%u).\n", swapchain->desc.BufferCount,
|
|
|
|
surface_caps.minImageCount, surface_caps.maxImageCount);
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->desc.Width > surface_caps.maxImageExtent.width
|
|
|
|
|| swapchain->desc.Width < surface_caps.minImageExtent.width
|
|
|
|
|| swapchain->desc.Height > surface_caps.maxImageExtent.height
|
|
|
|
|| swapchain->desc.Height < surface_caps.minImageExtent.height)
|
|
|
|
{
|
|
|
|
FIXME("Swapchain dimensions %ux%u are not supported (%u-%u x %u-%u).\n",
|
|
|
|
swapchain->desc.Width, swapchain->desc.Height,
|
|
|
|
surface_caps.minImageExtent.width, surface_caps.maxImageExtent.width,
|
|
|
|
surface_caps.minImageExtent.height, surface_caps.maxImageExtent.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(surface_caps.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR))
|
|
|
|
{
|
|
|
|
FIXME("Unsupported alpha mode.\n");
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
usage |= surface_caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
|
|
usage |= surface_caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
|
|
|
if (!(usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) || !(usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT))
|
|
|
|
WARN("Transfer not supported for swapchain images.\n");
|
|
|
|
|
|
|
|
vk_swapchain_desc.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
|
|
|
vk_swapchain_desc.pNext = NULL;
|
|
|
|
vk_swapchain_desc.flags = 0;
|
|
|
|
vk_swapchain_desc.surface = swapchain->vk_surface;
|
|
|
|
vk_swapchain_desc.minImageCount = swapchain->desc.BufferCount;
|
|
|
|
vk_swapchain_desc.imageFormat = vk_swapchain_format;
|
|
|
|
vk_swapchain_desc.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
|
|
|
vk_swapchain_desc.imageExtent.width = swapchain->desc.Width;
|
|
|
|
vk_swapchain_desc.imageExtent.height = swapchain->desc.Height;
|
|
|
|
vk_swapchain_desc.imageArrayLayers = 1;
|
|
|
|
vk_swapchain_desc.imageUsage = usage;
|
|
|
|
vk_swapchain_desc.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
|
|
vk_swapchain_desc.queueFamilyIndexCount = 0;
|
|
|
|
vk_swapchain_desc.pQueueFamilyIndices = NULL;
|
|
|
|
vk_swapchain_desc.preTransform = surface_caps.currentTransform;
|
|
|
|
vk_swapchain_desc.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
|
|
|
vk_swapchain_desc.presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
|
|
|
vk_swapchain_desc.clipped = VK_TRUE;
|
|
|
|
vk_swapchain_desc.oldSwapchain = swapchain->vk_swapchain;
|
|
|
|
if ((vr = vk_funcs->p_vkCreateSwapchainKHR(vk_device, &vk_swapchain_desc, NULL, &vk_swapchain)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to create Vulkan swapchain, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->vk_swapchain)
|
|
|
|
vk_funcs->p_vkDestroySwapchainKHR(swapchain->vk_device, swapchain->vk_swapchain, NULL);
|
|
|
|
|
|
|
|
swapchain->vk_swapchain = vk_swapchain;
|
|
|
|
|
|
|
|
if (FAILED(hr = d3d12_swapchain_create_buffers(swapchain, vk_swapchain_format, vk_format)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:34 +02:00
|
|
|
static inline struct d3d12_swapchain *d3d12_swapchain_from_IDXGISwapChain3(IDXGISwapChain3 *iface)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-08-29 12:53:34 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d12_swapchain, IDXGISwapChain3_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_QueryInterface(IDXGISwapChain3 *iface, REFIID iid, void **object)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, iid %s, object %p.\n", iface, debugstr_guid(iid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGIObject)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGIDeviceSubObject)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGISwapChain)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGISwapChain1)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGISwapChain2)
|
|
|
|
|| IsEqualGUID(iid, &IID_IDXGISwapChain3))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d12_swapchain_AddRef(IDXGISwapChain3 *iface)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&swapchain->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", swapchain, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d12_swapchain_destroy(struct d3d12_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
|
2018-08-29 12:53:35 +02:00
|
|
|
d3d12_swapchain_destroy_buffers(swapchain);
|
2018-08-29 12:53:34 +02:00
|
|
|
|
2018-08-29 12:53:35 +02:00
|
|
|
if (swapchain->command_queue)
|
2018-08-29 12:53:34 +02:00
|
|
|
ID3D12CommandQueue_Release(swapchain->command_queue);
|
|
|
|
|
|
|
|
wined3d_private_store_cleanup(&swapchain->private_store);
|
|
|
|
|
|
|
|
if (swapchain->vk_device)
|
|
|
|
{
|
|
|
|
vk_funcs->p_vkDestroyFence(swapchain->vk_device, swapchain->vk_fence, NULL);
|
|
|
|
vk_funcs->p_vkDestroySwapchainKHR(swapchain->vk_device, swapchain->vk_swapchain, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->vk_instance)
|
|
|
|
vk_funcs->p_vkDestroySurfaceKHR(swapchain->vk_instance, swapchain->vk_surface, NULL);
|
|
|
|
|
|
|
|
if (swapchain->device)
|
|
|
|
ID3D12Device_Release(swapchain->device);
|
2018-08-29 12:53:35 +02:00
|
|
|
|
|
|
|
if (swapchain->factory)
|
|
|
|
IWineDXGIFactory_Release(swapchain->factory);
|
2018-08-29 12:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d12_swapchain_Release(IDXGISwapChain3 *iface)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&swapchain->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", swapchain, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
d3d12_swapchain_destroy(swapchain);
|
|
|
|
heap_free(swapchain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetPrivateData(IDXGISwapChain3 *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_set_private_data(&swapchain->private_store, guid, data_size, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetPrivateDataInterface(IDXGISwapChain3 *iface,
|
|
|
|
REFGUID guid, const IUnknown *object)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return dxgi_set_private_data_interface(&swapchain->private_store, guid, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetPrivateData(IDXGISwapChain3 *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_get_private_data(&swapchain->private_store, guid, data_size, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetParent(IDXGISwapChain3 *iface, REFIID iid, void **parent)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, iid %s, parent %p.\n", iface, debugstr_guid(iid), parent);
|
|
|
|
|
|
|
|
return IWineDXGIFactory_QueryInterface(swapchain->factory, iid, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetDevice(IDXGISwapChain3 *iface, REFIID iid, void **device)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, iid %s, device %p.\n", iface, debugstr_guid(iid), device);
|
|
|
|
|
|
|
|
return ID3D12Device_QueryInterface(swapchain->device, iid, device);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISwapChain methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_Present(IDXGISwapChain3 *iface, UINT sync_interval, UINT flags)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, sync_interval %u, flags %#x.\n", iface, sync_interval, flags);
|
|
|
|
|
|
|
|
return IDXGISwapChain3_Present1(&swapchain->IDXGISwapChain3_iface, sync_interval, flags, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetBuffer(IDXGISwapChain3 *iface,
|
|
|
|
UINT buffer_idx, REFIID iid, void **surface)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, buffer_idx %u, iid %s, surface %p.\n",
|
|
|
|
iface, buffer_idx, debugstr_guid(iid), surface);
|
|
|
|
|
|
|
|
if (buffer_idx >= swapchain->buffer_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid buffer index %u.\n", buffer_idx);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ID3D12Resource_QueryInterface(swapchain->buffers[buffer_idx], iid, surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE DECLSPEC_HOTPATCH d3d12_swapchain_SetFullscreenState(IDXGISwapChain3 *iface,
|
|
|
|
BOOL fullscreen, IDXGIOutput *target)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, fullscreen %#x, target %p stub!\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetFullscreenState(IDXGISwapChain3 *iface,
|
|
|
|
BOOL *fullscreen, IDXGIOutput **target)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, fullscreen %p, target %p stub!\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetDesc(IDXGISwapChain3 *iface, DXGI_SWAP_CHAIN_DESC *desc)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc = &swapchain->fullscreen_desc;
|
|
|
|
const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc = &swapchain->desc;
|
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc->BufferDesc.Width = swapchain_desc->Width;
|
|
|
|
desc->BufferDesc.Height = swapchain_desc->Height;
|
|
|
|
desc->BufferDesc.RefreshRate = fullscreen_desc->RefreshRate;
|
|
|
|
desc->BufferDesc.Format = swapchain_desc->Format;
|
|
|
|
desc->BufferDesc.ScanlineOrdering = fullscreen_desc->ScanlineOrdering;
|
|
|
|
desc->BufferDesc.Scaling = fullscreen_desc->Scaling;
|
|
|
|
desc->SampleDesc = swapchain_desc->SampleDesc;
|
|
|
|
desc->BufferUsage = swapchain_desc->BufferUsage;
|
|
|
|
desc->BufferCount = swapchain_desc->BufferCount;
|
|
|
|
desc->OutputWindow = swapchain->window;
|
|
|
|
desc->Windowed = fullscreen_desc->Windowed;
|
|
|
|
desc->SwapEffect = swapchain_desc->SwapEffect;
|
|
|
|
desc->Flags = swapchain_desc->Flags;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_ResizeBuffers(IDXGISwapChain3 *iface,
|
|
|
|
UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags)
|
|
|
|
{
|
2018-08-29 12:53:37 +02:00
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
2018-09-18 16:06:01 +02:00
|
|
|
DXGI_SWAP_CHAIN_DESC1 *desc, new_desc;
|
2018-08-29 12:53:37 +02:00
|
|
|
unsigned int i;
|
|
|
|
ULONG refcount;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x.\n",
|
2018-08-29 12:53:34 +02:00
|
|
|
iface, buffer_count, width, height, debug_dxgi_format(format), flags);
|
|
|
|
|
2018-08-29 12:53:37 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->buffer_count; ++i)
|
|
|
|
{
|
|
|
|
ID3D12Resource_AddRef(swapchain->buffers[i]);
|
|
|
|
if ((refcount = ID3D12Resource_Release(swapchain->buffers[i])))
|
|
|
|
{
|
|
|
|
WARN("Buffer %p has %u references left.\n", swapchain->buffers[i], refcount);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = &swapchain->desc;
|
2018-09-18 16:06:01 +02:00
|
|
|
new_desc = swapchain->desc;
|
2018-08-29 12:53:37 +02:00
|
|
|
|
2018-09-18 16:06:01 +02:00
|
|
|
if (buffer_count)
|
|
|
|
new_desc.BufferCount = buffer_count;
|
2018-08-29 12:53:37 +02:00
|
|
|
if (!width || !height)
|
|
|
|
{
|
|
|
|
RECT client_rect;
|
|
|
|
|
|
|
|
if (!GetClientRect(swapchain->window, &client_rect))
|
|
|
|
{
|
|
|
|
WARN("Failed to get client rect, last error %#x.\n", GetLastError());
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!width)
|
|
|
|
width = client_rect.right;
|
|
|
|
if (!height)
|
|
|
|
height = client_rect.bottom;
|
|
|
|
}
|
2018-09-18 16:06:01 +02:00
|
|
|
new_desc.Width = width;
|
|
|
|
new_desc.Height = height;
|
2018-08-29 12:53:37 +02:00
|
|
|
|
2018-09-18 16:06:01 +02:00
|
|
|
if (format)
|
|
|
|
new_desc.Format = format;
|
2018-08-29 12:53:37 +02:00
|
|
|
|
2018-09-18 16:06:01 +02:00
|
|
|
if (!dxgi_validate_swapchain_desc(&new_desc))
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2018-08-29 12:53:37 +02:00
|
|
|
|
2018-09-18 16:06:01 +02:00
|
|
|
if (desc->Width == new_desc.Width && desc->Height == new_desc.Height
|
|
|
|
&& desc->Format == new_desc.Format && desc->BufferCount == new_desc.BufferCount)
|
|
|
|
return S_OK;
|
2018-08-29 12:53:37 +02:00
|
|
|
|
2018-09-18 16:06:01 +02:00
|
|
|
d3d12_swapchain_destroy_buffers(swapchain);
|
|
|
|
swapchain->desc = new_desc;
|
2018-08-29 12:53:37 +02:00
|
|
|
if (FAILED(hr = d3d12_swapchain_create_vulkan_swapchain(swapchain)))
|
|
|
|
{
|
|
|
|
ERR("Failed to recreate Vulkan swapchain, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return d3d12_swapchain_acquire_next_image(swapchain);
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_ResizeTarget(IDXGISwapChain3 *iface,
|
|
|
|
const DXGI_MODE_DESC *target_mode_desc)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, target_mode_desc %p stub!\n", iface, target_mode_desc);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetContainingOutput(IDXGISwapChain3 *iface,
|
|
|
|
IDXGIOutput **output)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, output %p stub!\n", iface, output);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetFrameStatistics(IDXGISwapChain3 *iface,
|
|
|
|
DXGI_FRAME_STATISTICS *stats)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, stats %p stub!\n", iface, stats);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetLastPresentCount(IDXGISwapChain3 *iface,
|
|
|
|
UINT *last_present_count)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, last_present_count %p stub!\n", iface, last_present_count);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISwapChain1 methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetDesc1(IDXGISwapChain3 *iface, DXGI_SWAP_CHAIN_DESC1 *desc)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*desc = swapchain->desc;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetFullscreenDesc(IDXGISwapChain3 *iface,
|
|
|
|
DXGI_SWAP_CHAIN_FULLSCREEN_DESC *desc)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*desc = swapchain->fullscreen_desc;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetHwnd(IDXGISwapChain3 *iface, HWND *hwnd)
|
|
|
|
{
|
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, hwnd %p.\n", iface, hwnd);
|
|
|
|
|
|
|
|
if (!hwnd)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*hwnd = swapchain->window;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetCoreWindow(IDXGISwapChain3 *iface,
|
|
|
|
REFIID iid, void **core_window)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, iid %s, core_window %p stub!\n", iface, debugstr_guid(iid), core_window);
|
|
|
|
|
|
|
|
if (core_window)
|
|
|
|
*core_window = NULL;
|
|
|
|
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:11:38 +02:00
|
|
|
static HRESULT d3d12_swapchain_blit_buffer(struct d3d12_swapchain *swapchain, VkQueue vk_queue)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkSubmitInfo submit_info;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
|
|
submit_info.pNext = NULL;
|
|
|
|
submit_info.waitSemaphoreCount = 0;
|
|
|
|
submit_info.pWaitSemaphores = NULL;
|
|
|
|
submit_info.pWaitDstStageMask = NULL;
|
|
|
|
submit_info.commandBufferCount = 1;
|
|
|
|
submit_info.pCommandBuffers = &swapchain->vk_cmd_buffers[swapchain->current_buffer_index];
|
|
|
|
submit_info.signalSemaphoreCount = 1;
|
|
|
|
submit_info.pSignalSemaphores = &swapchain->vk_semaphores[swapchain->current_buffer_index];
|
|
|
|
|
|
|
|
if ((vr = vk_funcs->p_vkQueueSubmit(vk_queue, 1, &submit_info, VK_NULL_HANDLE)) < 0)
|
|
|
|
ERR("Failed to blit swapchain buffer, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT d3d12_swapchain_queue_present(struct d3d12_swapchain *swapchain, VkQueue vk_queue)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
|
|
|
VkPresentInfoKHR present_info;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
|
|
present_info.pNext = NULL;
|
|
|
|
present_info.waitSemaphoreCount = 0;
|
|
|
|
present_info.pWaitSemaphores = NULL;
|
|
|
|
present_info.swapchainCount = 1;
|
|
|
|
present_info.pSwapchains = &swapchain->vk_swapchain;
|
|
|
|
present_info.pImageIndices = &swapchain->current_buffer_index;
|
|
|
|
present_info.pResults = NULL;
|
|
|
|
|
|
|
|
if (swapchain->vk_semaphores[swapchain->current_buffer_index])
|
|
|
|
{
|
|
|
|
present_info.waitSemaphoreCount = 1;
|
|
|
|
present_info.pWaitSemaphores = &swapchain->vk_semaphores[swapchain->current_buffer_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vr = vk_funcs->p_vkQueuePresentKHR(vk_queue, &present_info)) < 0)
|
|
|
|
ERR("Failed to queue present, vr %d.\n", vr);
|
|
|
|
return hresult_from_vk_result(vr);
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:27 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_Present1(IDXGISwapChain3 *iface,
|
|
|
|
UINT sync_interval, UINT flags, const DXGI_PRESENT_PARAMETERS *present_parameters)
|
|
|
|
{
|
2018-05-31 12:04:35 +02:00
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
VkQueue vk_queue;
|
2018-08-08 16:11:38 +02:00
|
|
|
HRESULT hr;
|
2018-05-31 12:04:35 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, sync_interval %u, flags %#x, present_parameters %p.\n",
|
2018-05-28 14:40:27 +02:00
|
|
|
iface, sync_interval, flags, present_parameters);
|
|
|
|
|
2018-05-31 12:04:35 +02:00
|
|
|
if (sync_interval > 4)
|
|
|
|
{
|
|
|
|
WARN("Invalid sync interval %u.\n", sync_interval);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
if (sync_interval != 1)
|
|
|
|
FIXME("Ignoring sync interval %u.\n", sync_interval);
|
|
|
|
|
|
|
|
if (flags & ~DXGI_PRESENT_TEST)
|
|
|
|
FIXME("Unimplemented flags %#x.\n", flags);
|
|
|
|
if (flags & DXGI_PRESENT_TEST)
|
|
|
|
{
|
|
|
|
WARN("Returning S_OK for DXGI_PRESENT_TEST.\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (present_parameters)
|
|
|
|
FIXME("Ignored present parameters %p.\n", present_parameters);
|
|
|
|
|
|
|
|
if (!(vk_queue = vkd3d_acquire_vk_queue(swapchain->command_queue)))
|
|
|
|
{
|
|
|
|
ERR("Failed to acquire Vulkan queue.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2018-08-08 16:11:38 +02:00
|
|
|
|
|
|
|
if (swapchain->vk_images[swapchain->current_buffer_index])
|
|
|
|
{
|
|
|
|
if (FAILED(hr = d3d12_swapchain_blit_buffer(swapchain, vk_queue)))
|
|
|
|
{
|
|
|
|
vkd3d_release_vk_queue(swapchain->command_queue);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = d3d12_swapchain_queue_present(swapchain, vk_queue)))
|
|
|
|
{
|
|
|
|
vkd3d_release_vk_queue(swapchain->command_queue);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:04:35 +02:00
|
|
|
vkd3d_release_vk_queue(swapchain->command_queue);
|
|
|
|
|
|
|
|
return d3d12_swapchain_acquire_next_image(swapchain);
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL STDMETHODCALLTYPE d3d12_swapchain_IsTemporaryMonoSupported(IDXGISwapChain3 *iface)
|
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetRestrictToOutput(IDXGISwapChain3 *iface, IDXGIOutput **output)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, output %p stub!\n", iface, output);
|
|
|
|
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
WARN("Invalid pointer.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*output = NULL;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetBackgroundColor(IDXGISwapChain3 *iface, const DXGI_RGBA *color)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, color %p stub!\n", iface, color);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetBackgroundColor(IDXGISwapChain3 *iface, DXGI_RGBA *color)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, color %p stub!\n", iface, color);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetRotation(IDXGISwapChain3 *iface, DXGI_MODE_ROTATION rotation)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, rotation %#x stub!\n", iface, rotation);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetRotation(IDXGISwapChain3 *iface, DXGI_MODE_ROTATION *rotation)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, rotation %p stub!\n", iface, rotation);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISwapChain2 methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetSourceSize(IDXGISwapChain3 *iface, UINT width, UINT height)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetSourceSize(IDXGISwapChain3 *iface, UINT *width, UINT *height)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetMaximumFrameLatency(IDXGISwapChain3 *iface, UINT max_latency)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetMaximumFrameLatency(IDXGISwapChain3 *iface, UINT *max_latency)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HANDLE STDMETHODCALLTYPE d3d12_swapchain_GetFrameLatencyWaitableObject(IDXGISwapChain3 *iface)
|
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetMatrixTransform(IDXGISwapChain3 *iface,
|
|
|
|
const DXGI_MATRIX_3X2_F *matrix)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, matrix %p stub!\n", iface, matrix);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_GetMatrixTransform(IDXGISwapChain3 *iface,
|
|
|
|
DXGI_MATRIX_3X2_F *matrix)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, matrix %p stub!\n", iface, matrix);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISwapChain3 methods */
|
|
|
|
|
|
|
|
static UINT STDMETHODCALLTYPE d3d12_swapchain_GetCurrentBackBufferIndex(IDXGISwapChain3 *iface)
|
|
|
|
{
|
2018-05-31 12:04:34 +02:00
|
|
|
struct d3d12_swapchain *swapchain = d3d12_swapchain_from_IDXGISwapChain3(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2018-05-28 14:40:27 +02:00
|
|
|
|
2018-05-31 12:04:34 +02:00
|
|
|
return swapchain->current_buffer_index;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_CheckColorSpaceSupport(IDXGISwapChain3 *iface,
|
|
|
|
DXGI_COLOR_SPACE_TYPE colour_space, UINT *colour_space_support)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, colour_space %#x, colour_space_support %p stub!\n",
|
|
|
|
iface, colour_space, colour_space_support);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_SetColorSpace1(IDXGISwapChain3 *iface,
|
|
|
|
DXGI_COLOR_SPACE_TYPE colour_space)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, colour_space %#x stub!\n", iface, colour_space);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d12_swapchain_ResizeBuffers1(IDXGISwapChain3 *iface,
|
|
|
|
UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags,
|
|
|
|
const UINT *node_mask, IUnknown * const *present_queue)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x, "
|
|
|
|
"node_mask %p, present_queue %p stub!\n",
|
|
|
|
iface, buffer_count, width, height, debug_dxgi_format(format), flags, node_mask, present_queue);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IDXGISwapChain3Vtbl d3d12_swapchain_vtbl =
|
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
d3d12_swapchain_QueryInterface,
|
|
|
|
d3d12_swapchain_AddRef,
|
|
|
|
d3d12_swapchain_Release,
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
d3d12_swapchain_SetPrivateData,
|
|
|
|
d3d12_swapchain_SetPrivateDataInterface,
|
|
|
|
d3d12_swapchain_GetPrivateData,
|
|
|
|
d3d12_swapchain_GetParent,
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
d3d12_swapchain_GetDevice,
|
|
|
|
/* IDXGISwapChain methods */
|
|
|
|
d3d12_swapchain_Present,
|
|
|
|
d3d12_swapchain_GetBuffer,
|
|
|
|
d3d12_swapchain_SetFullscreenState,
|
|
|
|
d3d12_swapchain_GetFullscreenState,
|
|
|
|
d3d12_swapchain_GetDesc,
|
|
|
|
d3d12_swapchain_ResizeBuffers,
|
|
|
|
d3d12_swapchain_ResizeTarget,
|
|
|
|
d3d12_swapchain_GetContainingOutput,
|
|
|
|
d3d12_swapchain_GetFrameStatistics,
|
|
|
|
d3d12_swapchain_GetLastPresentCount,
|
|
|
|
/* IDXGISwapChain1 methods */
|
|
|
|
d3d12_swapchain_GetDesc1,
|
|
|
|
d3d12_swapchain_GetFullscreenDesc,
|
|
|
|
d3d12_swapchain_GetHwnd,
|
|
|
|
d3d12_swapchain_GetCoreWindow,
|
|
|
|
d3d12_swapchain_Present1,
|
|
|
|
d3d12_swapchain_IsTemporaryMonoSupported,
|
|
|
|
d3d12_swapchain_GetRestrictToOutput,
|
|
|
|
d3d12_swapchain_SetBackgroundColor,
|
|
|
|
d3d12_swapchain_GetBackgroundColor,
|
|
|
|
d3d12_swapchain_SetRotation,
|
|
|
|
d3d12_swapchain_GetRotation,
|
|
|
|
/* IDXGISwapChain2 methods */
|
|
|
|
d3d12_swapchain_SetSourceSize,
|
|
|
|
d3d12_swapchain_GetSourceSize,
|
|
|
|
d3d12_swapchain_SetMaximumFrameLatency,
|
|
|
|
d3d12_swapchain_GetMaximumFrameLatency,
|
|
|
|
d3d12_swapchain_GetFrameLatencyWaitableObject,
|
|
|
|
d3d12_swapchain_SetMatrixTransform,
|
|
|
|
d3d12_swapchain_GetMatrixTransform,
|
|
|
|
/* IDXGISwapChain3 methods */
|
|
|
|
d3d12_swapchain_GetCurrentBackBufferIndex,
|
|
|
|
d3d12_swapchain_CheckColorSpaceSupport,
|
|
|
|
d3d12_swapchain_SetColorSpace1,
|
|
|
|
d3d12_swapchain_ResizeBuffers1,
|
|
|
|
};
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
static const struct vulkan_funcs *get_vk_funcs(void)
|
|
|
|
{
|
|
|
|
const struct vulkan_funcs *vk_funcs;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
vk_funcs = __wine_get_vulkan_driver(hdc, WINE_VULKAN_DRIVER_VERSION);
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return vk_funcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL load_vkd3d_functions(void *vkd3d_handle)
|
|
|
|
{
|
|
|
|
#define LOAD_FUNCPTR(f) if (!(f = wine_dlsym(vkd3d_handle, #f, NULL, 0))) return FALSE;
|
|
|
|
LOAD_FUNCPTR(vkd3d_acquire_vk_queue)
|
|
|
|
LOAD_FUNCPTR(vkd3d_create_image_resource)
|
|
|
|
LOAD_FUNCPTR(vkd3d_get_vk_device)
|
|
|
|
LOAD_FUNCPTR(vkd3d_get_vk_format)
|
|
|
|
LOAD_FUNCPTR(vkd3d_get_vk_physical_device)
|
|
|
|
LOAD_FUNCPTR(vkd3d_get_vk_queue_family_index)
|
|
|
|
LOAD_FUNCPTR(vkd3d_instance_from_device)
|
|
|
|
LOAD_FUNCPTR(vkd3d_instance_get_vk_instance)
|
|
|
|
LOAD_FUNCPTR(vkd3d_release_vk_queue)
|
|
|
|
LOAD_FUNCPTR(vkd3d_resource_decref)
|
|
|
|
LOAD_FUNCPTR(vkd3d_resource_incref)
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *vkd3d_handle;
|
|
|
|
|
|
|
|
static BOOL WINAPI init_vkd3d_once(INIT_ONCE *once, void *param, void **context)
|
|
|
|
{
|
|
|
|
TRACE("Loading vkd3d %s.\n", SONAME_LIBVKD3D);
|
|
|
|
|
|
|
|
if (!(vkd3d_handle = wine_dlopen(SONAME_LIBVKD3D, RTLD_NOW, NULL, 0)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!load_vkd3d_functions(vkd3d_handle))
|
|
|
|
{
|
|
|
|
ERR("Failed to load vkd3d functions.\n");
|
|
|
|
wine_dlclose(vkd3d_handle, NULL, 0);
|
|
|
|
vkd3d_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL init_vkd3d(void)
|
|
|
|
{
|
|
|
|
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
|
|
|
|
InitOnceExecuteOnce(&init_once, init_vkd3d_once, NULL, NULL);
|
|
|
|
return !!vkd3d_handle;
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:11:37 +02:00
|
|
|
static BOOL init_vk_funcs(struct dxgi_vk_funcs *dxgi, VkInstance vk_instance, VkDevice vk_device)
|
2018-05-31 12:39:04 +02:00
|
|
|
{
|
|
|
|
const struct vulkan_funcs *vk;
|
|
|
|
|
|
|
|
if (!(vk = get_vk_funcs()))
|
|
|
|
{
|
|
|
|
ERR_(winediag)("Failed to load Wine Vulkan driver.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dxgi->p_vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)vk->p_vkGetInstanceProcAddr;
|
|
|
|
|
2018-08-08 16:11:37 +02:00
|
|
|
#define LOAD_INSTANCE_PFN(name) \
|
|
|
|
if (!(dxgi->p_##name = vk->p_vkGetInstanceProcAddr(vk_instance, #name))) \
|
|
|
|
{ \
|
|
|
|
ERR("Failed to get instance proc "#name".\n"); \
|
|
|
|
return FALSE; \
|
|
|
|
}
|
2018-08-15 12:03:25 +02:00
|
|
|
LOAD_INSTANCE_PFN(vkCreateWin32SurfaceKHR)
|
|
|
|
LOAD_INSTANCE_PFN(vkDestroySurfaceKHR)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceMemoryProperties)
|
2018-08-15 12:03:25 +02:00
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
|
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceSurfaceFormatsKHR)
|
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceSurfacePresentModesKHR)
|
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceSurfaceSupportKHR)
|
|
|
|
LOAD_INSTANCE_PFN(vkGetPhysicalDeviceWin32PresentationSupportKHR)
|
2018-08-08 16:11:37 +02:00
|
|
|
#undef LOAD_INSTANCE_PFN
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
#define LOAD_DEVICE_PFN(name) \
|
|
|
|
if (!(dxgi->p_##name = vk->p_vkGetDeviceProcAddr(vk_device, #name))) \
|
|
|
|
{ \
|
|
|
|
ERR("Failed to get device proc "#name".\n"); \
|
|
|
|
return FALSE; \
|
|
|
|
}
|
2018-07-16 15:18:21 +02:00
|
|
|
LOAD_DEVICE_PFN(vkAcquireNextImageKHR)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkAllocateCommandBuffers)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_DEVICE_PFN(vkAllocateMemory)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkBeginCommandBuffer)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_DEVICE_PFN(vkBindImageMemory)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkCmdBlitImage)
|
|
|
|
LOAD_DEVICE_PFN(vkCmdPipelineBarrier)
|
|
|
|
LOAD_DEVICE_PFN(vkCreateCommandPool)
|
2018-05-31 12:39:04 +02:00
|
|
|
LOAD_DEVICE_PFN(vkCreateFence)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_DEVICE_PFN(vkCreateImage)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkCreateSemaphore)
|
2018-08-15 12:03:25 +02:00
|
|
|
LOAD_DEVICE_PFN(vkCreateSwapchainKHR)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkDestroyCommandPool)
|
2018-05-31 12:39:04 +02:00
|
|
|
LOAD_DEVICE_PFN(vkDestroyFence)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_DEVICE_PFN(vkDestroyImage)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkDestroySemaphore)
|
2018-08-15 12:03:25 +02:00
|
|
|
LOAD_DEVICE_PFN(vkDestroySwapchainKHR)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkEndCommandBuffer)
|
2018-08-08 16:11:37 +02:00
|
|
|
LOAD_DEVICE_PFN(vkFreeMemory)
|
|
|
|
LOAD_DEVICE_PFN(vkGetImageMemoryRequirements)
|
2018-08-15 12:03:25 +02:00
|
|
|
LOAD_DEVICE_PFN(vkGetSwapchainImagesKHR)
|
|
|
|
LOAD_DEVICE_PFN(vkQueuePresentKHR)
|
2018-08-08 16:11:38 +02:00
|
|
|
LOAD_DEVICE_PFN(vkQueueSubmit)
|
2018-08-08 16:11:35 +02:00
|
|
|
LOAD_DEVICE_PFN(vkQueueWaitIdle)
|
2018-07-16 15:18:21 +02:00
|
|
|
LOAD_DEVICE_PFN(vkResetFences)
|
|
|
|
LOAD_DEVICE_PFN(vkWaitForFences)
|
2018-05-31 12:39:04 +02:00
|
|
|
#undef LOAD_DEVICE_PFN
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT d3d12_swapchain_init(struct d3d12_swapchain *swapchain, IWineDXGIFactory *factory,
|
|
|
|
ID3D12Device *device, ID3D12CommandQueue *queue, HWND window,
|
|
|
|
const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc, const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc)
|
|
|
|
{
|
|
|
|
const struct dxgi_vk_funcs *vk_funcs = &swapchain->vk_funcs;
|
2018-08-29 12:53:36 +02:00
|
|
|
VkWin32SurfaceCreateInfoKHR surface_desc;
|
2018-05-31 12:39:04 +02:00
|
|
|
VkPhysicalDevice vk_physical_device;
|
|
|
|
VkFenceCreateInfo fence_desc;
|
|
|
|
uint32_t queue_family_index;
|
2018-08-29 12:53:36 +02:00
|
|
|
VkSurfaceKHR vk_surface;
|
2018-05-31 12:39:04 +02:00
|
|
|
VkInstance vk_instance;
|
|
|
|
VkBool32 supported;
|
|
|
|
VkDevice vk_device;
|
2018-08-29 12:53:36 +02:00
|
|
|
VkFence vk_fence;
|
2018-05-31 12:39:04 +02:00
|
|
|
VkResult vr;
|
2018-06-01 12:45:07 +02:00
|
|
|
HRESULT hr;
|
2018-05-31 12:39:04 +02:00
|
|
|
|
|
|
|
swapchain->IDXGISwapChain3_iface.lpVtbl = &d3d12_swapchain_vtbl;
|
|
|
|
swapchain->refcount = 1;
|
|
|
|
|
|
|
|
swapchain->window = window;
|
|
|
|
swapchain->desc = *swapchain_desc;
|
|
|
|
swapchain->fullscreen_desc = *fullscreen_desc;
|
|
|
|
|
|
|
|
switch (swapchain_desc->SwapEffect)
|
|
|
|
{
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL:
|
|
|
|
case DXGI_SWAP_EFFECT_FLIP_DISCARD:
|
|
|
|
FIXME("Ignoring swap effect %#x.\n", swapchain_desc->SwapEffect);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Invalid swap effect %#x.\n", swapchain_desc->SwapEffect);
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!init_vkd3d())
|
|
|
|
{
|
|
|
|
ERR_(winediag)("libvkd3d could not be loaded.\n");
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain_desc->BufferUsage && swapchain_desc->BufferUsage != DXGI_USAGE_RENDER_TARGET_OUTPUT)
|
|
|
|
FIXME("Ignoring buffer usage %#x.\n", swapchain_desc->BufferUsage);
|
|
|
|
if (swapchain_desc->Scaling != DXGI_SCALING_STRETCH)
|
|
|
|
FIXME("Ignoring scaling %#x.\n", swapchain_desc->Scaling);
|
|
|
|
if (swapchain_desc->AlphaMode && swapchain_desc->AlphaMode != DXGI_ALPHA_MODE_IGNORE)
|
|
|
|
FIXME("Ignoring alpha mode %#x.\n", swapchain_desc->AlphaMode);
|
|
|
|
if (swapchain_desc->Flags)
|
|
|
|
FIXME("Ignoring swapchain flags %#x.\n", swapchain_desc->Flags);
|
|
|
|
|
|
|
|
FIXME("Ignoring refresh rate.\n");
|
|
|
|
if (fullscreen_desc->ScanlineOrdering)
|
|
|
|
FIXME("Unhandled scanline ordering %#x.\n", fullscreen_desc->ScanlineOrdering);
|
|
|
|
if (fullscreen_desc->Scaling)
|
|
|
|
FIXME("Unhandled mode scaling %#x.\n", fullscreen_desc->Scaling);
|
|
|
|
if (!fullscreen_desc->Windowed)
|
|
|
|
FIXME("Fullscreen not supported yet.\n");
|
|
|
|
|
|
|
|
vk_instance = vkd3d_instance_get_vk_instance(vkd3d_instance_from_device(device));
|
|
|
|
vk_physical_device = vkd3d_get_vk_physical_device(device);
|
|
|
|
vk_device = vkd3d_get_vk_device(device);
|
|
|
|
|
2018-08-08 16:11:34 +02:00
|
|
|
swapchain->vk_instance = vk_instance;
|
|
|
|
swapchain->vk_device = vk_device;
|
2018-08-08 16:11:37 +02:00
|
|
|
swapchain->vk_physical_device = vk_physical_device;
|
2018-08-08 16:11:34 +02:00
|
|
|
|
2018-08-08 16:11:37 +02:00
|
|
|
if (!init_vk_funcs(&swapchain->vk_funcs, vk_instance, vk_device))
|
2018-05-31 12:39:04 +02:00
|
|
|
return E_FAIL;
|
|
|
|
|
2018-08-08 16:11:34 +02:00
|
|
|
wined3d_private_store_init(&swapchain->private_store);
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
surface_desc.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
|
|
|
surface_desc.pNext = NULL;
|
|
|
|
surface_desc.flags = 0;
|
|
|
|
surface_desc.hinstance = GetModuleHandleA("dxgi.dll");
|
|
|
|
surface_desc.hwnd = window;
|
|
|
|
if ((vr = vk_funcs->p_vkCreateWin32SurfaceKHR(vk_instance, &surface_desc, NULL, &vk_surface)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to create Vulkan surface, vr %d.\n", vr);
|
2018-08-08 16:11:34 +02:00
|
|
|
d3d12_swapchain_destroy(swapchain);
|
|
|
|
return hresult_from_vk_result(vr);
|
2018-05-31 12:39:04 +02:00
|
|
|
}
|
2018-08-08 16:11:34 +02:00
|
|
|
swapchain->vk_surface = vk_surface;
|
2018-05-31 12:39:04 +02:00
|
|
|
|
|
|
|
queue_family_index = vkd3d_get_vk_queue_family_index(queue);
|
|
|
|
if ((vr = vk_funcs->p_vkGetPhysicalDeviceSurfaceSupportKHR(vk_physical_device,
|
|
|
|
queue_family_index, vk_surface, &supported)) < 0 || !supported)
|
|
|
|
{
|
|
|
|
FIXME("Queue family does not support presentation, vr %d.\n", vr);
|
2018-08-08 16:11:34 +02:00
|
|
|
d3d12_swapchain_destroy(swapchain);
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
2018-05-31 12:39:04 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
ID3D12CommandQueue_AddRef(swapchain->command_queue = queue);
|
|
|
|
ID3D12Device_AddRef(swapchain->device = device);
|
2018-08-08 16:11:33 +02:00
|
|
|
|
2018-08-29 12:53:36 +02:00
|
|
|
if (FAILED(hr = d3d12_swapchain_create_vulkan_swapchain(swapchain)))
|
2018-05-31 12:39:04 +02:00
|
|
|
{
|
2018-08-08 16:11:34 +02:00
|
|
|
d3d12_swapchain_destroy(swapchain);
|
2018-08-29 12:53:36 +02:00
|
|
|
return hr;
|
2018-05-31 12:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fence_desc.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
|
|
|
fence_desc.pNext = NULL;
|
|
|
|
fence_desc.flags = 0;
|
|
|
|
if ((vr = vk_funcs->p_vkCreateFence(vk_device, &fence_desc, NULL, &vk_fence)) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to create Vulkan fence, vr %d.\n", vr);
|
2018-08-08 16:11:34 +02:00
|
|
|
d3d12_swapchain_destroy(swapchain);
|
|
|
|
return hresult_from_vk_result(vr);
|
2018-05-31 12:39:04 +02:00
|
|
|
}
|
2018-08-08 16:11:34 +02:00
|
|
|
swapchain->vk_fence = vk_fence;
|
2018-05-31 12:39:04 +02:00
|
|
|
|
2018-05-31 12:04:35 +02:00
|
|
|
if (FAILED(hr = d3d12_swapchain_acquire_next_image(swapchain)))
|
|
|
|
{
|
|
|
|
WARN("Failed to acquire Vulkan image, hr %#x.\n", hr);
|
2018-08-08 16:11:34 +02:00
|
|
|
d3d12_swapchain_destroy(swapchain);
|
|
|
|
return hr;
|
2018-05-31 12:04:35 +02:00
|
|
|
}
|
2018-05-31 12:39:04 +02:00
|
|
|
|
|
|
|
IWineDXGIFactory_AddRef(swapchain->factory = factory);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:40:27 +02:00
|
|
|
HRESULT d3d12_swapchain_create(IWineDXGIFactory *factory, ID3D12CommandQueue *queue, HWND window,
|
|
|
|
const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc, const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc,
|
|
|
|
IDXGISwapChain1 **swapchain)
|
|
|
|
{
|
2018-05-31 12:39:04 +02:00
|
|
|
DXGI_SWAP_CHAIN_FULLSCREEN_DESC default_fullscreen_desc;
|
2018-05-28 14:40:27 +02:00
|
|
|
struct d3d12_swapchain *object;
|
|
|
|
ID3D12Device *device;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
if (!fullscreen_desc)
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-05-31 12:39:04 +02:00
|
|
|
memset(&default_fullscreen_desc, 0, sizeof(default_fullscreen_desc));
|
|
|
|
default_fullscreen_desc.Windowed = TRUE;
|
|
|
|
fullscreen_desc = &default_fullscreen_desc;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2018-05-31 12:39:04 +02:00
|
|
|
if (FAILED(hr = ID3D12CommandQueue_GetDevice(queue, &IID_ID3D12Device, (void **)&device)))
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-05-31 12:39:04 +02:00
|
|
|
ERR("Failed to get D3D12 device, hr %#x.\n", hr);
|
|
|
|
heap_free(object);
|
|
|
|
return hr;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
2018-05-31 12:39:04 +02:00
|
|
|
|
|
|
|
hr = d3d12_swapchain_init(object, factory, device, queue, window, swapchain_desc, fullscreen_desc);
|
|
|
|
ID3D12Device_Release(device);
|
|
|
|
if (FAILED(hr))
|
2018-05-28 14:40:27 +02:00
|
|
|
{
|
2018-05-31 12:39:04 +02:00
|
|
|
heap_free(object);
|
|
|
|
return hr;
|
2018-05-28 14:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created swapchain %p.\n", object);
|
|
|
|
|
|
|
|
*swapchain = (IDXGISwapChain1 *)&object->IDXGISwapChain3_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-05-31 12:39:04 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
HRESULT d3d12_swapchain_create(IWineDXGIFactory *factory, ID3D12CommandQueue *queue, HWND window,
|
|
|
|
const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc, const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc,
|
|
|
|
IDXGISwapChain1 **swapchain)
|
|
|
|
{
|
|
|
|
ERR_(winediag)("Wine was built without Direct3D 12 support.\n");
|
|
|
|
return DXGI_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SONAME_LIBVKD3D */
|