Build Vulkan on all platforms, won't be used if not supported.

This commit is contained in:
Henrik Rydgård 2017-12-21 14:13:55 +01:00
parent 9007abddbf
commit f73ec4608e
2 changed files with 37 additions and 32 deletions

View file

@ -355,23 +355,19 @@ set(CommonWindows
Common/stdafx.h) Common/stdafx.h)
source_group(Windows FILES ${CommonWindows}) source_group(Windows FILES ${CommonWindows})
if(VULKAN) set(CommonVulkan ${CommonExtra}
set(CommonVulkan ${CommonExtra} Common/Vulkan/SPIRVDisasm.cpp
Common/Vulkan/SPIRVDisasm.cpp Common/Vulkan/SPIRVDisasm.h
Common/Vulkan/SPIRVDisasm.h Common/Vulkan/VulkanContext.cpp
Common/Vulkan/VulkanContext.cpp Common/Vulkan/VulkanContext.h
Common/Vulkan/VulkanContext.h Common/Vulkan/VulkanDebug.cpp
Common/Vulkan/VulkanDebug.cpp Common/Vulkan/VulkanDebug.h
Common/Vulkan/VulkanDebug.h Common/Vulkan/VulkanImage.cpp
Common/Vulkan/VulkanImage.cpp Common/Vulkan/VulkanImage.h
Common/Vulkan/VulkanImage.h Common/Vulkan/VulkanLoader.cpp
Common/Vulkan/VulkanLoader.cpp Common/Vulkan/VulkanLoader.h
Common/Vulkan/VulkanLoader.h Common/Vulkan/VulkanMemory.cpp
Common/Vulkan/VulkanMemory.cpp Common/Vulkan/VulkanMemory.h)
Common/Vulkan/VulkanMemory.h)
else()
set(CommonVulkan)
endif()
add_library(Common STATIC add_library(Common STATIC
${CommonX86} ${CommonX86}
@ -838,15 +834,14 @@ if(ANDROID)
endif() endif()
set(THIN3D_PLATFORMS ext/native/thin3d/thin3d_gl.cpp) set(THIN3D_PLATFORMS ext/native/thin3d/thin3d_gl.cpp)
if(VULKAN) set(THIN3D_PLATFORMS ${THIN3D_PLATFORMS}
set(THIN3D_PLATFORMS ${THIN3D_PLATFORMS} ext/native/thin3d/thin3d_vulkan.cpp
ext/native/thin3d/thin3d_vulkan.cpp
ext/native/thin3d/VulkanRenderManager.cpp ext/native/thin3d/VulkanRenderManager.cpp
ext/native/thin3d/VulkanRenderManager.h ext/native/thin3d/VulkanRenderManager.h
ext/native/thin3d/VulkanQueueRunner.cpp ext/native/thin3d/VulkanQueueRunner.cpp
ext/native/thin3d/VulkanQueueRunner.h ext/native/thin3d/VulkanQueueRunner.h
ext/native/thin3d/DataFormat.h) ext/native/thin3d/DataFormat.h)
endif()
if(WIN32) if(WIN32)
set(THIN3D_PLATFORMS ${THIN3D_PLATFORMS} set(THIN3D_PLATFORMS ${THIN3D_PLATFORMS}
ext/native/thin3d/thin3d_d3d9.cpp ext/native/thin3d/thin3d_d3d9.cpp
@ -1679,7 +1674,11 @@ set(CoreExtraLibs ${CoreExtraLibs} armips)
set(GlslangLibs glslang OGLCompiler OSDependent SPIRV SPVRemapper spirv-cross-glsl) set(GlslangLibs glslang OGLCompiler OSDependent SPIRV SPVRemapper spirv-cross-glsl)
target_link_libraries(${CoreLibName} Common native kirk cityhash sfmt19937 xbrz xxhash ${GlslangLibs} target_link_libraries(${CoreLibName} Common native kirk cityhash sfmt19937 xbrz xxhash ${GlslangLibs}
${CoreExtraLibs} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${CMAKE_DL_LIBS} ${Vulkan_LIBRARY}) ${CoreExtraLibs} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${CMAKE_DL_LIBS})
if(VULKAN)
target_link_libraries(${CoreLibName} ${Vulkan_LIBRARY})
endif()
if(FFmpeg_FOUND) if(FFmpeg_FOUND)
target_compile_definitions(${CoreLibName} PRIVATE USE_FFMPEG=1) target_compile_definitions(${CoreLibName} PRIVATE USE_FFMPEG=1)

View file

@ -155,16 +155,13 @@ int8_t EGL_Init() {
g_eglContext = eglCreateContext(g_eglDisplay, g_eglConfig, NULL, attributes ); g_eglContext = eglCreateContext(g_eglDisplay, g_eglConfig, NULL, attributes );
if (g_eglContext == EGL_NO_CONTEXT) EGL_ERROR("Unable to create GLES context!", true); if (g_eglContext == EGL_NO_CONTEXT) EGL_ERROR("Unable to create GLES context!", true);
#if !defined(USING_FBDEV) #if !defined(USING_FBDEV) && !defined(__APPLE__)
//Get the SDL window handle //Get the SDL window handle
SDL_SysWMinfo sysInfo; //Will hold our Window information SDL_SysWMinfo sysInfo; //Will hold our Window information
SDL_VERSION(&sysInfo.version); //Set SDL version SDL_VERSION(&sysInfo.version); //Set SDL version
#endif
#ifdef USING_FBDEV
g_Window = (NativeWindowType)NULL;
#else
g_Window = (NativeWindowType)sysInfo.info.x11.window; g_Window = (NativeWindowType)sysInfo.info.x11.window;
#else
g_Window = (NativeWindowType)NULL;
#endif #endif
g_eglSurface = eglCreateWindowSurface(g_eglDisplay, g_eglConfig, g_Window, 0); g_eglSurface = eglCreateWindowSurface(g_eglDisplay, g_eglConfig, g_Window, 0);
if (g_eglSurface == EGL_NO_SURFACE) if (g_eglSurface == EGL_NO_SURFACE)
@ -207,7 +204,8 @@ public:
delete draw_; delete draw_;
} }
bool Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message); // Returns 0 on success.
int Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message);
void Shutdown() override { void Shutdown() override {
#ifdef USING_EGL #ifdef USING_EGL
@ -235,7 +233,8 @@ private:
SDL_GLContext glContext = nullptr; SDL_GLContext glContext = nullptr;
}; };
bool SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message) { // Returns 0 on success.
int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message) {
struct GLVersionPair { struct GLVersionPair {
int major; int major;
int minor; int minor;
@ -337,6 +336,7 @@ bool SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std
bool success = draw_->CreatePresets(); bool success = draw_->CreatePresets();
assert(success); assert(success);
window_ = window; window_ = window;
return 0;
} }
class SDLVulkanGraphicsContext : public GraphicsContext { class SDLVulkanGraphicsContext : public GraphicsContext {
@ -424,6 +424,7 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode,
return false; return false;
} }
#if !defined(__APPLE__)
SDL_SysWMinfo sys_info{}; SDL_SysWMinfo sys_info{};
SDL_VERSION(&sys_info.version); //Set SDL version SDL_VERSION(&sys_info.version); //Set SDL version
if (!SDL_GetWindowWMInfo(window, &sys_info)) { if (!SDL_GetWindowWMInfo(window, &sys_info)) {
@ -440,6 +441,11 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode,
exit(1); exit(1);
break; break;
} }
#else
// Fake to make it build on Apple. This code won't run there though.
void *display = nullptr;
int x11_window = 0;
#endif
ILOG("Display: %p", display); ILOG("Display: %p", display);
#if defined(VK_USE_PLATFORM_XLIB_KHR) #if defined(VK_USE_PLATFORM_XLIB_KHR)
@ -854,8 +860,8 @@ int main(int argc, char *argv[]) {
std::string error_message; std::string error_message;
if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) {
SDLGLGraphicsContext *ctx = new SDLGLGraphicsContext(); SDLGLGraphicsContext *ctx = new SDLGLGraphicsContext();
if (!ctx->Init(window, x, y, mode, &error_message)) { if (ctx->Init(window, x, y, mode, &error_message) != 0) {
printf("GL init error '%s' - falling back to GL\n", error_message.c_str()); printf("GL init error '%s'\n", error_message.c_str());
} }
graphicsContext = ctx; graphicsContext = ctx;
} else if (g_Config.iGPUBackend == GPU_BACKEND_VULKAN) { } else if (g_Config.iGPUBackend == GPU_BACKEND_VULKAN) {