diff --git a/gfx/common/d3d10_common.h b/gfx/common/d3d10_common.h index 7c1225dae1..f347c664b9 100644 --- a/gfx/common/d3d10_common.h +++ b/gfx/common/d3d10_common.h @@ -1123,6 +1123,7 @@ typedef struct DXGI_FORMAT format; bool vsync; + bool need_resize; } d3d10_video_t; void d3d10_init_texture(D3D10Device device, d3d10_texture_t* texture); diff --git a/gfx/common/d3d11_common.h b/gfx/common/d3d11_common.h index c040db3a17..8f2f561fda 100644 --- a/gfx/common/d3d11_common.h +++ b/gfx/common/d3d11_common.h @@ -2501,6 +2501,7 @@ typedef struct DXGI_FORMAT format; bool vsync; + bool need_resize; } d3d11_video_t; void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture); diff --git a/gfx/common/d3d12_common.h b/gfx/common/d3d12_common.h index 246328c771..9b0f1d894a 100644 --- a/gfx/common/d3d12_common.h +++ b/gfx/common/d3d12_common.h @@ -1172,6 +1172,7 @@ typedef struct DXGI_FORMAT format; D3D12_GPU_DESCRIPTOR_HANDLE sampler_linear; D3D12_GPU_DESCRIPTOR_HANDLE sampler_nearest; + bool need_resize; #ifdef DEBUG D3D12Debug debugController; diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index 53fa0c207b..3ea6925d5e 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -217,6 +217,26 @@ static bool d3d10_gfx_frame( (void)msg; d3d10_video_t* d3d10 = (d3d10_video_t*)data; + + if (d3d10->need_resize) + { + D3D10Texture2D backBuffer; + D3D10_VIEWPORT vp = { 0, 0, video_info->width, video_info->height, 0.0f, 1.0f }; + + Release(d3d10->renderTargetView); + DXGIResizeBuffers(d3d10->swapChain, 0, 0, 0, 0, 0); + + DXGIGetSwapChainBufferD3D10(d3d10->swapChain, 0, &backBuffer); + D3D10CreateTexture2DRenderTargetView(d3d10->device, backBuffer, NULL, &d3d10->renderTargetView); + Release(backBuffer); + + D3D10SetRenderTargets(d3d10->device, 1, &d3d10->renderTargetView, NULL); + D3D10SetViewports(d3d10->device, 1, &vp); + + d3d10->need_resize = false; + } + + PERF_START(); D3D10ClearRenderTargetView(d3d10->device, d3d10->renderTargetView, d3d10->clearcolor); @@ -286,7 +306,9 @@ static bool d3d10_gfx_alive(void* data) unsigned width; unsigned height; - win32_check_window(&quit, &resize, &width, &height); + d3d10_video_t* d3d10 = (d3d10_video_t*)data; + + win32_check_window(&quit, &d3d10->need_resize, &width, &height); if (width != 0 && height != 0) video_driver_set_size(&width, &height); diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index bf29fd41e4..6fbf8fe1d4 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -230,6 +230,24 @@ static bool d3d11_gfx_frame( { d3d11_video_t* d3d11 = (d3d11_video_t*)data; + if (d3d11->need_resize) + { + D3D11Texture2D backBuffer; + D3D11_VIEWPORT vp = { 0, 0, video_info->width, video_info->height, 0.0f, 1.0f }; + + Release(d3d11->renderTargetView); + DXGIResizeBuffers(d3d11->swapChain, 0, 0, 0, 0, 0); + + DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &backBuffer); + D3D11CreateTexture2DRenderTargetView(d3d11->device, backBuffer, NULL, &d3d11->renderTargetView); + Release(backBuffer); + + D3D11SetRenderTargets(d3d11->ctx, 1, &d3d11->renderTargetView, NULL); + D3D11SetViewports(d3d11->ctx, 1, &vp); + + d3d11->need_resize = false; + } + PERF_START(); D3D11ClearRenderTargetView(d3d11->ctx, d3d11->renderTargetView, d3d11->clearcolor); @@ -303,9 +321,9 @@ static bool d3d11_gfx_alive(void* data) unsigned width; unsigned height; - (void)data; + d3d11_video_t* d3d11 = (d3d11_video_t*)data; - win32_check_window(&quit, &resize, &width, &height); + win32_check_window(&quit, &d3d11->need_resize, &width, &height); if (width != 0 && height != 0) video_driver_set_size(&width, &height); diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c index f6212849d1..39599e8f69 100644 --- a/gfx/drivers/d3d12.c +++ b/gfx/drivers/d3d12.c @@ -103,7 +103,32 @@ static bool d3d12_gfx_frame( { d3d12_video_t* d3d12 = (d3d12_video_t*)data; - (void)msg; + if (d3d12->need_resize) + { + int i; + + for (int i = 0; i < countof(d3d12->chain.renderTargets); i++) + Release(d3d12->chain.renderTargets[i]); + + DXGIResizeBuffers(d3d12->chain.handle, 0, 0, 0, 0, 0); + + for (int i = 0; i < countof(d3d12->chain.renderTargets); i++) + { + DXGIGetSwapChainBuffer(d3d12->chain.handle, i, &d3d12->chain.renderTargets[i]); + D3D12CreateRenderTargetView( + d3d12->device, d3d12->chain.renderTargets[i], NULL, d3d12->chain.desc_handles[i]); + } + + d3d12->chain.viewport.Width = video_info->width; + d3d12->chain.viewport.Height = video_info->height; + d3d12->chain.scissorRect.right = video_info->width; + d3d12->chain.scissorRect.bottom = video_info->height; + d3d12->chain.frame_index = DXGIGetCurrentBackBufferIndex(d3d12->chain.handle); + + d3d12->need_resize = false; + } + + PERF_START(); D3D12ResetCommandAllocator(d3d12->queue.allocator); @@ -209,7 +234,9 @@ static bool d3d12_gfx_alive(void* data) unsigned width; unsigned height; - win32_check_window(&quit, &resize, &width, &height); + d3d12_video_t* d3d12 = (d3d12_video_t*)data; + + win32_check_window(&quit, &d3d12->need_resize, &width, &height); if (width != 0 && height != 0) video_driver_set_size(&width, &height);