(D3D11) Split init swapchain code up into own function

This commit is contained in:
twinaphex 2020-12-15 08:19:04 +01:00
parent ad2502b645
commit a1fd1d425c
1 changed files with 105 additions and 99 deletions

View File

@ -622,57 +622,10 @@ static void d3d11_gfx_free(void* data)
free(d3d11);
}
static void *d3d11_gfx_init(const video_info_t* video,
input_driver_t** input, void** input_data)
{
unsigned i;
#ifdef HAVE_MONITOR
MONITORINFOEX current_mon;
HMONITOR hm_to_use;
WNDCLASSEX wndclass = { 0 };
#endif
settings_t* settings = config_get_ptr();
d3d11_video_t* d3d11 = (d3d11_video_t*)calloc(1, sizeof(*d3d11));
if (!d3d11)
return NULL;
#ifdef HAVE_WINDOW
win32_window_reset();
#endif
#ifdef HAVE_MONITOR
win32_monitor_init();
wndclass.lpfnWndProc = wnd_proc_d3d_common;
#ifdef HAVE_DINPUT
if (string_is_equal(settings->arrays.input_driver, "dinput"))
wndclass.lpfnWndProc = wnd_proc_d3d_dinput;
#endif
#ifdef HAVE_WINDOW
win32_window_init(&wndclass, true, NULL);
#endif
win32_monitor_info(&current_mon, &hm_to_use, &d3d11->cur_mon_id);
#endif
d3d11->vp.full_width = video->width;
d3d11->vp.full_height = video->height;
#ifdef HAVE_MONITOR
if (!d3d11->vp.full_width)
d3d11->vp.full_width = current_mon.rcMonitor.right - current_mon.rcMonitor.left;
if (!d3d11->vp.full_height)
d3d11->vp.full_height = current_mon.rcMonitor.bottom - current_mon.rcMonitor.top;
#endif
if (!win32_set_video_mode(d3d11, d3d11->vp.full_width, d3d11->vp.full_height, video->fullscreen))
{
RARCH_ERR("[D3D11]: win32_set_video_mode failed.\n");
goto error;
}
d3d_input_driver(settings->arrays.input_driver, settings->arrays.input_joypad_driver, input, input_data);
static bool d3d11_gfx_init_swapchain(d3d11_video_t* d3d11)
{
IDXGIDevice* dxgiDevice = NULL;
IDXGIAdapter* adapter = NULL;
UINT flags = 0;
D3D_FEATURE_LEVEL
requested_feature_levels[] =
@ -727,6 +680,7 @@ static void *d3d11_gfx_init(const video_info_t* video,
#ifdef DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
if(cached_device_d3d11 && cached_context)
{
d3d11->device = cached_device_d3d11;
@ -740,38 +694,90 @@ static void *d3d11_gfx_init(const video_info_t* video,
requested_feature_levels, number_feature_levels,
D3D11_SDK_VERSION, &d3d11->device,
&d3d11->supportedFeatureLevel, &d3d11->context)))
goto error;
return false;
}
IDXGIDevice* dxgiDevice = NULL;
IDXGIAdapter* adapter = NULL;
d3d11->device->lpVtbl->QueryInterface(
d3d11->device, uuidof(IDXGIDevice), (void**)&dxgiDevice);
dxgiDevice->lpVtbl->GetAdapter(dxgiDevice, &adapter);
#ifndef __WINRT__
IDXGIFactory* dxgiFactory = NULL;
adapter->lpVtbl->GetParent(
adapter, uuidof(IDXGIFactory1), (void**)&dxgiFactory);
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChain(
dxgiFactory, (IUnknown*)d3d11->device,
&desc, (IDXGISwapChain**)&d3d11->swapChain)))
goto error;
#else
#ifdef __WINRT__
IDXGIFactory2* dxgiFactory = NULL;
adapter->lpVtbl->GetParent(
adapter, uuidof(IDXGIFactory2), (void**)&dxgiFactory);
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChainForCoreWindow(
dxgiFactory, (IUnknown*)d3d11->device, uwp_get_corewindow(),
&desc, NULL, (IDXGISwapChain1**)&d3d11->swapChain)))
goto error;
return false;
#else
IDXGIFactory* dxgiFactory = NULL;
adapter->lpVtbl->GetParent(
adapter, uuidof(IDXGIFactory1), (void**)&dxgiFactory);
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChain(
dxgiFactory, (IUnknown*)d3d11->device,
&desc, (IDXGISwapChain**)&d3d11->swapChain)))
return false;
#endif
dxgiFactory->lpVtbl->Release(dxgiFactory);
adapter->lpVtbl->Release(adapter);
dxgiDevice->lpVtbl->Release(dxgiDevice);
return true;
}
static void *d3d11_gfx_init(const video_info_t* video,
input_driver_t** input, void** input_data)
{
unsigned i;
#ifdef HAVE_MONITOR
MONITORINFOEX current_mon;
HMONITOR hm_to_use;
WNDCLASSEX wndclass = { 0 };
#endif
settings_t* settings = config_get_ptr();
d3d11_video_t* d3d11 = (d3d11_video_t*)calloc(1, sizeof(*d3d11));
if (!d3d11)
return NULL;
#ifdef HAVE_WINDOW
win32_window_reset();
#endif
#ifdef HAVE_MONITOR
win32_monitor_init();
wndclass.lpfnWndProc = wnd_proc_d3d_common;
#ifdef HAVE_DINPUT
if (string_is_equal(settings->arrays.input_driver, "dinput"))
wndclass.lpfnWndProc = wnd_proc_d3d_dinput;
#endif
#ifdef HAVE_WINDOW
win32_window_init(&wndclass, true, NULL);
#endif
win32_monitor_info(&current_mon, &hm_to_use, &d3d11->cur_mon_id);
#endif
d3d11->vp.full_width = video->width;
d3d11->vp.full_height = video->height;
#ifdef HAVE_MONITOR
if (!d3d11->vp.full_width)
d3d11->vp.full_width = current_mon.rcMonitor.right - current_mon.rcMonitor.left;
if (!d3d11->vp.full_height)
d3d11->vp.full_height = current_mon.rcMonitor.bottom - current_mon.rcMonitor.top;
#endif
if (!win32_set_video_mode(d3d11, d3d11->vp.full_width, d3d11->vp.full_height, video->fullscreen))
{
RARCH_ERR("[D3D11]: win32_set_video_mode failed.\n");
goto error;
}
d3d_input_driver(settings->arrays.input_driver, settings->arrays.input_joypad_driver, input, input_data);
if (!d3d11_gfx_init_swapchain(d3d11))
goto error;
{
D3D11Texture2D backBuffer;
DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &backBuffer);