From fec1a07b9be7d9e73c1ecd7207ef3a2a59102981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Mar 2018 19:47:06 +0100 Subject: [PATCH] Bootstrap Vulkan support. --- CMakeLists.txt | 6 ++++++ doc/00-page-order.dox | 1 + doc/building.dox | 5 +++++ doc/cmake.dox | 3 +++ doc/namespaces.dox | 22 ++++++++++++++++++++++ doc/vulkan.dox | 34 ++++++++++++++++++++++++++++++++++ modules/FindMagnum.cmake | 14 ++++++++++++-- src/Magnum/CMakeLists.txt | 4 ++++ src/Magnum/Magnum.h | 11 +++++++++++ src/Magnum/Vk/CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/Magnum/configure.h.cmake | 1 + 11 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 doc/vulkan.dox create mode 100644 src/Magnum/Vk/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 5145251a4..0f593e64f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ endif() cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2 / WebGL 1.0" ON "TARGET_GLES" OFF) cmake_dependent_option(TARGET_DESKTOP_GLES "Build for OpenGL ES on desktop" OFF "TARGET_GLES" OFF) cmake_dependent_option(TARGET_HEADLESS "Build command-line utilities for use on a headless machines" OFF "WITH_GL" OFF) +cmake_dependent_option(TARGET_VK "Build libraries with Vulkan interoperability" ON "WITH_VK" OFF) # Magnum GL Info (currently only using GLX/CGL/EGL on *nix, WGL/EGL on Windows # and EGL on Emscripten) @@ -115,8 +116,10 @@ cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" ON "NOT WI cmake_dependent_option(WITH_TRADE "Build Trade library" ON "NOT WITH_MESHTOOLS;NOT WITH_PRIMITIVES;NOT WITH_IMAGECONVERTER;NOT WITH_ANYIMAGEIMPORTER;NOT WITH_ANYIMAGECONVERTER;NOT WITH_ANYSCENEIMPORTER;NOT WITH_OBJIMPORTER;NOT WITH_TGAIMAGECONVERTER;NOT WITH_TGAIMPORTER" ON) cmake_dependent_option(WITH_GL "Build GL library" ON "NOT WITH_SHADERS;NOT WITH_TEXT;NOT WITH_GL_INFO;NOT WITH_ANDROIDAPPLICATION;NOT WITH_WINDOWLESSIOSAPPLICATION;NOT WITH_CGLCONTEXT;NOT WITH_GLXAPPLICATION;NOT WITH_GLXCONTEXT;NOT WITH_XEGLAPPLICATION;NOT WITH_WINDOWLESSWGLAPPLICATION;NOT WITH_GLXCONTEXT;NOT WITH_XEGLAPPLICATION;NOT WITH_WINDOWLESSWGLAPPLICATION;NOT WITH_WGLCONTEXT;NOT WITH_WINDOWLESSWINDOWSEGLAPPLICATION;NOT WITH_GLUTAPPLICATION;NOT WITH_DISTANCEFIELDCONVERTER;NOT WITH_FONTCONVERTER;NOT WITH_IMAGECONVERTER" ON) option(WITH_PRIMITIVES "Builf Primitives library" ON) +option(WITH_VK "Build Vk library" OFF) cmake_dependent_option(TARGET_GL "Build libraries with OpenGL interoperability" ON "WITH_GL" OFF) +cmake_dependent_option(TARGET_VK "Build libraries with Vulkan interoperability" ON "WITH_VK" OFF) # Magnum AL Info cmake_dependent_option(WITH_AL_INFO "Build magnum-al-info utility" OFF "WITH_AUDIO" OFF) @@ -240,6 +243,9 @@ endif() if(TARGET_HEADLESS) set(MAGNUM_TARGET_HEADLESS 1) endif() +if(TARGET_VK) + set(MAGNUM_TARGET_VK 1) +endif() if(CORRADE_TARGET_EMSCRIPTEN) include(UseEmscripten) diff --git a/doc/00-page-order.dox b/doc/00-page-order.dox index 0406dd732..808e7f729 100644 --- a/doc/00-page-order.dox +++ b/doc/00-page-order.dox @@ -33,6 +33,7 @@ @page example-index Examples @page tips Tips and tricks @page utilities Utilities +@page vulkan Vulkan @page opengl OpenGL @page openal OpenAL diff --git a/doc/building.dox b/doc/building.dox index 30c3fa0c1..679d7ad82 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -408,6 +408,10 @@ available for desktop OpenGL only, see @ref requires-gl. used everywhere instead of platform-specific toolkits like CGL, GLX or WGL. Supported mainly on OpenGL ES drivers. Available only when `WITH_GL` is enabled. +- `TARGET_VK` --- Build libraries with Vulkan interoperability enabled. + Enabled by default when `WITH_VK` is enabled. Disabling this will cause + libraries to not depend on the @ref Vk library, but doesn't affect the + @ref Vk library itself. By default the engine is built in a way that allows having multiple independent thread-local Magnum contents. This might cause some performance penalties --- @@ -444,6 +448,7 @@ be built and which not: - `WITH_TEXTURETOOLS` --- Build the @ref TextureTools library. Enabled automatically if `WITH_TEXT` or `WITH_DISTANCEFIELDCONVERTER` is enabled. - `WITH_TRADE` --- Build the @ref Trade library. +- `WITH_VK` --- Build the @ref Vk library There are more involved component dependencies that are not described here (for example the @ref DebugTools has some functionality that gets built only when diff --git a/doc/cmake.dox b/doc/cmake.dox index c17506517..bf6dc9045 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -104,6 +104,7 @@ the components. The optional components are: - `Text` --- @ref Text library - `TextureTools` --- @ref TextureTools library - `Trade` --- @ref Trade library +- `Vk` --- @ref Vk library Platform namespace is split into more components: @@ -219,6 +220,8 @@ are also available as preprocessor variables if including - `MAGNUM_TARGET_WEBGL` --- Defined if compiled for WebGL - `MAGNUM_TARGET_HEADLESS` --- Defined if compiled for headless machines. See @ref MAGNUM_TARGET_HEADLESS documentation for more information. +- `MAGNUM_TARGET_VK` --- Defined if compiled with Vulkan interoperability + enabled Workflows without imported targets are deprecated and the following variables are included just for backwards compatibility and only if diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 5e211d7df..67b57789f 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -456,6 +456,28 @@ Additional plugins are built separately, see particular `Trade::*Importer` and information. */ +/** @dir Magnum/Vk + * @brief Namespace @ref Magnum::Vk + */ +/** @namespace Magnum::Vk +@brief Vulkan wrapping layer + +C++14 wrappers and helpers for Vulkan development. + +This library is built if `WITH_VK` is enabled when building Magnum. To use this +library with CMake, you need to request the `Vk` component of the `Magnum` +package and link to the `Magnum::Vk` target: + +@code{.cmake} +find_package(Magnum REQUIRED Vk) + +# ... +target_link_libraries(your-app Magnum::Vk) +@endcode + +See @ref building, @ref cmake and @ref vulkan for more information. +*/ + /** @dir magnum/src/MagnumPlugins * @brief Magnum plugins (part of @ref building "Magnum library") */ diff --git a/doc/vulkan.dox b/doc/vulkan.dox new file mode 100644 index 000000000..273e731aa --- /dev/null +++ b/doc/vulkan.dox @@ -0,0 +1,34 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + Vladimír Vondruš + + 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. +*/ + +namespace Magnum { + +/** @page vulkan Vuulkan +@brief State of Vulkan support, version and extension requirements. + +Nothing to see here yet, sorry. +*/ + +} diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index c57a51c11..a43d440c3 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -59,6 +59,7 @@ # Text - Text library # TextureTools - TextureTools library # Trade - Trade library +# Vk - Vk library # GlfwApplication - GLFW application # GlutApplication - GLUT application # GlxApplication - GLX application @@ -128,6 +129,7 @@ # emulation on desktop OpenGL # MAGNUM_TARGET_WEBGL - Defined if compiled for WebGL # MAGNUM_TARGET_HEADLESS - Defined if compiled for headless machines +# MAGNUM_TARGET_VK - Defined if compiled with Vulkan interop # # Additionally these variables are defined for internal usage: # @@ -255,7 +257,8 @@ set(_magnumFlags TARGET_GLES3 TARGET_DESKTOP_GLES TARGET_WEBGL - TARGET_HEADLESS) + TARGET_HEADLESS + TARGET_VK) foreach(_magnumFlag ${_magnumFlags}) string(FIND "${_magnumConfigure}" "#define MAGNUM_${_magnumFlag}" _magnum_${_magnumFlag}) if(NOT _magnum_${_magnumFlag} EQUAL -1) @@ -332,7 +335,7 @@ endif() # components from other repositories) set(_MAGNUM_LIBRARY_COMPONENT_LIST Audio DebugTools GL MeshTools Primitives SceneGraph Shaders Shapes Text - TextureTools Trade + TextureTools Trade Vk AndroidApplication GlfwApplication GlutApplication GlxApplication Sdl2Application XEglApplication WindowlessCglApplication WindowlessEglApplication WindowlessGlxApplication WindowlessIosApplication WindowlessWglApplication WindowlessWindowsEglApplication @@ -734,6 +737,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) elseif(_component STREQUAL Trade) set_property(TARGET Magnum::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Corrade::PluginManager) + + # Vk library + elseif(_component STREQUAL Vk) + set(Vulkan_INCLUDE_DIR ${MAGNUM_INCLUDE_DIR}/MagnumExternal/Vulkan) + find_package(Vulkan REQUIRED) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Vulkan::Vulkan) endif() # No special setup for AnyAudioImporter plugin diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 07142993d..dfa75b48c 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -246,6 +246,10 @@ if(WITH_TRADE) add_subdirectory(Trade) endif() +if(WITH_VK) + add_subdirectory(Vk) +endif() + if(BUILD_TESTS) # Math library with graceful assert for testing add_library(MagnumMathTestLib ${SHARED_OR_STATIC} diff --git a/src/Magnum/Magnum.h b/src/Magnum/Magnum.h index 605bd2e3c..159fa87ae 100644 --- a/src/Magnum/Magnum.h +++ b/src/Magnum/Magnum.h @@ -183,6 +183,17 @@ for more information. #undef MAGNUM_TARGET_HEADLESS #endif +/** +@brief Vulkan interoperability + +Defined if the engine is built with Vulkan interoperability enabled --- extra +APIs in various libraries interacting with the @ref Magnum::Vk "Vk" library. +Enabled by default in case the @ref Magnum::Vk "Vk" library is built. +@see @ref building, @ref cmake +*/ +#define MAGNUM_TARGET_VK +#undef MAGNUM_TARGET_VK + /** @{ @name Basic type definitions See @ref types for more information. diff --git a/src/Magnum/Vk/CMakeLists.txt b/src/Magnum/Vk/CMakeLists.txt new file mode 100644 index 000000000..118ea5452 --- /dev/null +++ b/src/Magnum/Vk/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 +# Vladimír Vondruš +# Copyright © 2016 Jonathan Hale +# +# 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. +# + diff --git a/src/Magnum/configure.h.cmake b/src/Magnum/configure.h.cmake index 8a0e6eaea..6460f1405 100644 --- a/src/Magnum/configure.h.cmake +++ b/src/Magnum/configure.h.cmake @@ -35,5 +35,6 @@ #cmakedefine MAGNUM_TARGET_DESKTOP_GLES #cmakedefine MAGNUM_TARGET_WEBGL #cmakedefine MAGNUM_TARGET_HEADLESS +#cmakedefine MAGNUM_TARGET_VK #endif