@@ -2469,7 +2469,7 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue,
24692469 DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = {};
24702470 if (swap_chain->d3d_swap_chain != nullptr ) {
24712471 _swap_chain_release_buffers (swap_chain);
2472- res = swap_chain->d3d_swap_chain ->ResizeBuffers (p_desired_framebuffer_count, 0 , 0 , DXGI_FORMAT_UNKNOWN, creation_flags);
2472+ res = swap_chain->d3d_swap_chain ->ResizeBuffers (p_desired_framebuffer_count, surface-> width , surface-> height , DXGI_FORMAT_UNKNOWN, creation_flags);
24732473 ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_UNAVAILABLE);
24742474 } else {
24752475 swap_chain_desc.BufferCount = p_desired_framebuffer_count;
@@ -2478,22 +2478,19 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue,
24782478 swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
24792479 swap_chain_desc.SampleDesc .Count = 1 ;
24802480 swap_chain_desc.Flags = creation_flags;
2481- swap_chain_desc.Scaling = DXGI_SCALING_NONE ;
2481+ swap_chain_desc.Scaling = DXGI_SCALING_STRETCH ;
24822482 if (OS::get_singleton ()->is_layered_allowed ()) {
24832483 swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
24842484 has_comp_alpha[(uint64_t )p_cmd_queue.id ] = true ;
24852485 } else {
24862486 swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
24872487 has_comp_alpha[(uint64_t )p_cmd_queue.id ] = false ;
24882488 }
2489+ swap_chain_desc.Width = surface->width ;
2490+ swap_chain_desc.Height = surface->height ;
24892491
24902492 ComPtr<IDXGISwapChain1> swap_chain_1;
2491- res = context_driver->dxgi_factory_get ()->CreateSwapChainForHwnd (command_queue->d3d_queue .Get (), surface->hwnd , &swap_chain_desc, nullptr , nullptr , swap_chain_1.GetAddressOf ());
2492- if (!SUCCEEDED (res) && swap_chain_desc.AlphaMode != DXGI_ALPHA_MODE_IGNORE) {
2493- swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
2494- has_comp_alpha[(uint64_t )p_cmd_queue.id ] = false ;
2495- res = context_driver->dxgi_factory_get ()->CreateSwapChainForHwnd (command_queue->d3d_queue .Get (), surface->hwnd , &swap_chain_desc, nullptr , nullptr , swap_chain_1.GetAddressOf ());
2496- }
2493+ res = context_driver->dxgi_factory_get ()->CreateSwapChainForComposition (command_queue->d3d_queue .Get (), &swap_chain_desc, nullptr , swap_chain_1.GetAddressOf ());
24972494 ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
24982495
24992496 swap_chain_1.As (&swap_chain->d3d_swap_chain );
@@ -2503,6 +2500,36 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue,
25032500 ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
25042501 }
25052502
2503+ if (surface->composition_device .Get () == nullptr ) {
2504+ using PFN_DCompositionCreateDevice = HRESULT (WINAPI *)(IDXGIDevice *, REFIID, void **);
2505+ PFN_DCompositionCreateDevice pfn_DCompositionCreateDevice = (PFN_DCompositionCreateDevice)(void *)GetProcAddress (context_driver->lib_dcomp , " DCompositionCreateDevice" );
2506+ ERR_FAIL_NULL_V (pfn_DCompositionCreateDevice, ERR_CANT_CREATE);
2507+
2508+ res = pfn_DCompositionCreateDevice (nullptr , IID_PPV_ARGS (surface->composition_device .GetAddressOf ()));
2509+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2510+
2511+ res = surface->composition_device ->CreateTargetForHwnd (surface->hwnd , TRUE , surface->composition_target .GetAddressOf ());
2512+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2513+
2514+ res = surface->composition_device ->CreateVisual (surface->composition_visual .GetAddressOf ());
2515+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2516+
2517+ res = surface->composition_visual ->SetContent (swap_chain->d3d_swap_chain .Get ());
2518+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2519+
2520+ res = surface->composition_target ->SetRoot (surface->composition_visual .Get ());
2521+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2522+
2523+ res = surface->composition_device ->Commit ();
2524+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2525+ } else {
2526+ res = surface->composition_visual ->SetContent (swap_chain->d3d_swap_chain .Get ());
2527+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2528+
2529+ res = surface->composition_device ->Commit ();
2530+ ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
2531+ }
2532+
25062533 res = swap_chain->d3d_swap_chain ->GetDesc1 (&swap_chain_desc);
25072534 ERR_FAIL_COND_V (!SUCCEEDED (res), ERR_CANT_CREATE);
25082535 ERR_FAIL_COND_V (swap_chain_desc.BufferCount == 0 , ERR_CANT_CREATE);
0 commit comments