Add static Vulkan loader.

Initial Vulkan support for Windows.
Initial Vulkan support for macOS.
This commit is contained in:
bruvzg 2019-06-22 19:34:26 +03:00
parent 4fe3ee1730
commit eb48be51db
120 changed files with 142158 additions and 357 deletions

View file

@ -8,7 +8,6 @@ import platform_windows_builders
common_win = [
"godot_windows.cpp",
"context_gl_windows.cpp",
"crash_handler_windows.cpp",
"os_windows.cpp",
"key_mapping_windows.cpp",
@ -17,6 +16,11 @@ common_win = [
"windows_terminal_logger.cpp"
]
if (env["renderer"] == "vulkan"):
common_win += ["vulkan_context_win.cpp"]
else:
common_win += ["context_gl_windows.cpp"]
res_file = 'godot_res.rc'
res_target = "godot_res" + env["OBJSUFFIX"]
res_obj = env.RES(res_target, res_file)

View file

@ -207,7 +207,7 @@ def configure_msvc(env, manual_msvc_config):
else:
print("Missing environment variable: WindowsSdkDir")
env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED', 'OPENGL_ENABLED',
env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED',
'WASAPI_ENABLED', 'WINMIDI_ENABLED',
'TYPED_METHOD_BIND',
'WIN32', 'MSVC',
@ -219,10 +219,22 @@ def configure_msvc(env, manual_msvc_config):
## Libs
LIBS = ['winmm', 'opengl32', 'dsound', 'kernel32', 'ole32', 'oleaut32',
LIBS = ['winmm', 'dsound', 'kernel32', 'ole32', 'oleaut32',
'user32', 'gdi32', 'IPHLPAPI', 'Shlwapi', 'wsock32', 'Ws2_32',
'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt',
'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt', 'Avrt',
'dwmapi']
if (env["renderer"] == "vulkan"):
env.Prepend(CPPPATH=['#thirdparty/vulkan/include/', "#thirdparty/vulkan/registry/"])
env.AppendUnique(CPPDEFINES = ['VULKAN_ENABLED'])
if not env["builtin_vulkan_loader"]:
LIBS += ['vulkan']
else:
LIBS += ['cfgmgr32']
else:
env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED'])
LIBS += ['opengl32']
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])
if manual_msvc_config:
@ -345,9 +357,21 @@ def configure_mingw(env):
## Compile flags
env.Append(CCFLAGS=['-mwindows'])
env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'OPENGL_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
env.Append(CPPDEFINES=[('WINVER', env['target_win_version']), ('_WIN32_WINNT', env['target_win_version'])])
env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
env.Append(LIBS=['mingw32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
if (env["renderer"] == "vulkan"):
env.Prepend(CPPPATH=['#thirdparty/vulkan/include/', "#thirdparty/vulkan/registry/"])
env.Append(CPPDEFINES=['VULKAN_ENABLED'])
if not env["builtin_vulkan_loader"]:
env.Append(LIBS=['vulkan'])
else:
env.Append(LIBS=['cfgmgr32'])
else:
env.Append(CPPDEFINES=['OPENGL_ENABLED'])
env.Append(LIBS=['opengl32'])
env.Append(CPPDEFINES=['MINGW_ENABLED', ('MINGW_HAS_SECURE_API', 1)])

View file

@ -35,8 +35,15 @@
#include "core/io/marshalls.h"
#include "core/version_generated.gen.h"
#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles3/rasterizer_gles3.h"
#endif
#if defined(VULKAN_ENABLED)
#include "servers/visual/rasterizer/rasterizer_rd.h"
#endif
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
#include "drivers/windows/mutex_windows.h"
@ -893,6 +900,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
preserve_window_size = false;
set_window_size(Size2(video_mode.width, video_mode.height));
}
#if defined(VULKAN_ENABLED)
context_vulkan->window_resize(0, video_mode.width, video_mode.height);
#endif
}
if (wParam == SIZE_MAXIMIZED) {
@ -1489,7 +1499,18 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
gl_context->set_use_vsync(video_mode.use_vsync);
set_vsync_via_compositor(video_mode.vsync_via_compositor);
#endif
#if defined(VULKAN_ENABLED)
video_driver_index = VIDEO_DRIVER_VULKAN;
context_vulkan = memnew(VulkanContextWindows);
context_vulkan->initialize();
context_vulkan->window_create(hWnd, hInstance, get_video_mode().width, get_video_mode().height);
//temporary
rendering_device = memnew(RenderingDeviceVulkan);
rendering_device->initialize(context_vulkan);
RasterizerRD::make_current();
#endif
visual_server = memnew(VisualServerRaster);
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
@ -1665,6 +1686,13 @@ void OS_Windows::finalize() {
memdelete(gl_context);
#endif
#if defined(VULKAN_ENABLED)
rendering_device->finalize();
memdelete(rendering_device);
memdelete(context_vulkan);
#endif
if (user_proc) {
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)user_proc);
};
@ -1965,6 +1993,10 @@ void OS_Windows::set_window_size(const Size2 p_size) {
video_mode.width = w;
video_mode.height = h;
#if defined(VULKAN_ENABLED)
context_vulkan->window_resize(0, video_mode.width, video_mode.height);
#endif
if (video_mode.fullscreen) {
return;
}
@ -3121,18 +3153,24 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const {
}
void OS_Windows::release_rendering_thread() {
#if defined(OPENGL_ENABLED)
gl_context->release_current();
#endif
}
void OS_Windows::make_rendering_thread() {
#if defined(OPENGL_ENABLED)
gl_context->make_current();
#endif
}
void OS_Windows::swap_buffers() {
#if defined(OPENGL_ENABLED)
gl_context->swap_buffers();
#endif
#if defined(VULKAN_ENABLED)
context_vulkan->swap_buffers();
#endif
}
void OS_Windows::force_process_input() {
@ -3299,9 +3337,10 @@ String OS_Windows::get_joy_guid(int p_device) const {
}
void OS_Windows::_set_use_vsync(bool p_enable) {
#if defined(OPENGL_ENABLED)
if (gl_context)
gl_context->set_use_vsync(p_enable);
#endif
}
/*
bool OS_Windows::is_vsync_enabled() const {

View file

@ -31,7 +31,6 @@
#ifndef OS_WINDOWS_H
#define OS_WINDOWS_H
#include "context_gl_windows.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@ -49,6 +48,15 @@
#include "drivers/xaudio2/audio_driver_xaudio2.h"
#endif
#if defined(OPENGL_ENABLED)
#include "context_gl_windows.h"
#endif
#if defined(VULKAN_ENABLED)
#include "drivers/vulkan/rendering_device_vulkan.h"
#include "platform/windows/vulkan_context_win.h"
#endif
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
@ -173,6 +181,12 @@ class OS_Windows : public OS {
#if defined(OPENGL_ENABLED)
ContextGL_Windows *gl_context;
#endif
#if defined(VULKAN_ENABLED)
VulkanContextWindows *context_vulkan;
RenderingDeviceVulkan *rendering_device;
#endif
VisualServer *visual_server;
int pressrc;
HINSTANCE hInstance; // Holds The Instance Of The Application

View file

@ -0,0 +1,57 @@
/*************************************************************************/
/* vulkan_context_win.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "vulkan_context_win.h"
#include <vulkan/vulkan_win32.h>
const char *VulkanContextWindows::_get_platform_surface_extension() const {
return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
}
int VulkanContextWindows::window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height) {
VkWin32SurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.hinstance = p_instance;
createInfo.hwnd = p_window;
VkSurfaceKHR surface;
VkResult err = vkCreateWin32SurfaceKHR(_get_instance(), &createInfo, NULL, &surface);
ERR_FAIL_COND_V(err, -1);
return _window_create(surface, p_width, p_height);
}
VulkanContextWindows::VulkanContextWindows() {
}
VulkanContextWindows::~VulkanContextWindows() {
}

View file

@ -0,0 +1,48 @@
/*************************************************************************/
/* vulkan_context_win.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef VULKAN_DEVICE_WIN_H
#define VULKAN_DEVICE_WIN_H
#include "drivers/vulkan/vulkan_context.h"
#include <windows.h>
class VulkanContextWindows : public VulkanContext {
virtual const char *_get_platform_surface_extension() const;
public:
int window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height);
VulkanContextWindows();
~VulkanContextWindows();
};
#endif // VULKAN_DEVICE_WIN_H