Open Calinou opened 1 year ago
I was about to submit this very proposal when I found there already is one. Thanks, search function!
I'd like to add that this impacts OpenGL as well, not just Vulkan (for those wanting to use the Compatibility profile). For GL, other projects have reported success using the WGL_NV_DX_interop2
extension to swap via DXGI.
I'd also like to mention that there is a current workaround for those on nVidia drivers. Users can go to the nVidia Control Panel and set the "Vulkan/OpenGL present method" to "Prefer layered on DXGI Swapchain":
AMD may provide a driver option in the future. It should be noted that the nVidia option is currently a workaround - as such, the user has to manually opt into this. It's not on by default.
PresentMon may be useful to verify that the correct swapchain is being used. A correct result should show Hardware Composed: Independent Flip. Currently Godot is showing Composed: Copy with GPU GDI.
I suppose implementation on this can start when #70315 gets merged... from what i can gather here, we literally just need to use a DXGI swapchain, the presentation code stayed exactly the same as far as I can tell. I guess the data you give to the swapchain in Vulkan can also be given, as is, to a DX12 swapchain?
Currently swapchain creation seems to be here, in vulkan_context.cpp's _update_swap_chain
.
In DX12 (#70315), swapchain creation seems to be here, in d3d12_context.cpp's _update_swap_chain
.
So I suppose we do some DX12 initialization stuff even if the selected renderer is Vulkan, then in vulkan_context.cpp, we #include "drivers/d3d12/d3d12_context.h"
, and in all calls to _update_swap_chain
, we do:
#ifdef WINDOWS_ENABLED
D3D12Context::_update_swap_chain(&window);
#else
VulkanContext::_update_swap_chain(&window);
Although since this is Vulkan/DX12, I'm sure it won't actually be as simple as all that...
@Jamsers how feasible to bring Godot 4 as 3D visualization to e.g. MAUI framework/WPF/WinForm as e.g. UserControl
I gave this a shot but the synchronization does not work as intended.
https://github.com/DarioSamo/godot/tree/vulkan_dxgi
A very dirty example and it'd definitely need more code reorganization to be done properly, but I'm unsure as to what the missing synchronization is between present and the command queue for this to work. Right now it does render but there's visible corruption glitches that go away if the frame is waited on instead from the CPU (which would be incorrect).
Maybe someone familiar with the inner workings of Vulkan/D3D12/DXGI can spot the error?
@DarioSamo thanks for your effort, your work helps the community one step closer to hosting Godot4 engine in e.g. winform, WPF, and WinUI
@DarioSamo if you could share a downloadable simple application exe showing how the DXGI possibilities open the integration of Godot4 in e.g. WPF, AvaloniaUI etc,
This will be game changing
When are we getting this feature added in Godot?
When are we getting this feature added in Godot?
There is a pull request implementing this for OpenGL, but none for Vulkan yet. We don't have an ETA on when this will be implemented.
Describe the project you are working on
The Godot editor :slightly_smiling_face:
Describe the problem or limitation you are having in your project
Vulkan and OpenGL on Windows tend to exhibit lower smoothness and greater input lag compared to Direct3D applications (any version). This sometimes leads to the impression that OpenGL and Vulkan perform worse on Windows compared to Linux, when it's actually not the case – the issue is in the frame presentation itself.
A Direct3D 12 renderer is being worked on, but for users wishing to use Vulkan on Windows instead, they won't get the best possible experience.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Most AAA games using Vulkan use DirectX Graphics Infrastructure (DXGI) to create a window and present frames rendered via Vulkan. This has several benefits over using Vulkan directly like Godot currently does:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Quoting this comment and this comment from @HybridEidolon for posterity:
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, as presenting frames is handled by the renderer.
Is there a reason why this should be core and not an add-on in the asset library?
This is core rendering functionality.