Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Sketch of a possible Magnum::Vk (Vulkan Target) #202

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e288d5b
Add TARGET_VULKAN option
Squareys Apr 21, 2016
9d83e27
modules: Add FindVulkan.cmake
Squareys Apr 21, 2016
de2ba76
Platform: Add createVkSurface to GlfwApplication
Squareys Apr 21, 2016
778e389
Vk: Add visibility.h
Squareys Apr 21, 2016
0a8e323
Vk: Add to cmake project
Squareys Apr 21, 2016
e768dab
[TODO] Platform: Add Vulkan library to GlfwApplication
Squareys Apr 21, 2016
cf3d958
modules: Add Magnum::Vk to FindMagnum.cmake
Squareys Apr 21, 2016
a73b272
Vk: Add Context
Squareys Apr 21, 2016
5687379
Vk: Add ContextTest
Squareys Apr 22, 2016
d06ec5a
Vk: Add AbstractVulkanTester
Squareys Apr 22, 2016
bdd3d9b
Vk: Continue context setup
Squareys Apr 26, 2016
582e799
Vk: Add some Nvidia specific VkResults and required win32 surface ext
Squareys Apr 28, 2016
3b16f13
Vk: Fix Validation enum
Squareys May 1, 2016
c585d60
Vk: Wrap many Vulkan types
Squareys May 1, 2016
c25faa3
Some merge conflicts resolved WIP
Squareys Jun 2, 2016
fb3aeef
Re-add C++14 flags
Squareys Jun 5, 2016
5b531f4
Vk: Improve pipelineBarrier and beginRenderPass commands
Squareys Jun 5, 2016
62ba27e
Vk: Enhance Framebuffer, Image, Pipeline wrap DescriptorPool, Descrip…
Squareys Jun 5, 2016
cac8f85
Vk: Rename Context to Instance to match Vulkan naming
Squareys Jul 11, 2016
ca6b633
Vk: Add GraphicsPipelineBuilder
Squareys Jul 11, 2016
a68c3cf
Vk: Add function for creating persp proj matrix with [0,1] clipping r…
Squareys Jul 11, 2016
936f32a
Vk: Lazily initialize physical device memory properties
Squareys Jul 11, 2016
ef13e7f
Vk: Add Mesh
Squareys Jul 11, 2016
74d5c78
Vk: Add begin and end commands
Squareys Jul 11, 2016
a851d30
Vk: Add more and missing source files to CMakeLists.txt
Squareys Jul 11, 2016
15fb4a6
Vk: Add Texture class
Squareys Jul 14, 2016
5a64703
Vk: Changes to PhysicalDevice
Squareys Jul 20, 2016
7fbacd2
Vk: doc++ for CommandBuffer
Squareys Jul 22, 2016
ba28bda
Vk: Improve PhysicalDevice::getMemoryType(...) and doc++
Squareys Jul 22, 2016
c2040d4
Vk: Add ability to get descriptor from buffer and check an error
Squareys Jul 24, 2016
4e1b170
Vk: Loads of improvements everywhere
Squareys Aug 24, 2016
6b4581d
modules: Fix FindVulkan
Squareys Aug 26, 2016
ac3db52
Vk: Add NoCreate constructors, remove .vk*() methods, avoid some vectors
Squareys Aug 26, 2016
9610fdd
Vk: Create instance in AbstractVulkanTester
Squareys Sep 16, 2016
d4dcd01
Vk: Add BufferTest, rename Context*Test to Instance*Test
Squareys Sep 16, 2016
176649b
Vk: Use explicit conversions for MSVC
Squareys Sep 29, 2016
bb513de
Vk: Cleanup some code
Squareys Sep 29, 2016
cd35431
Vk: Add DeviceFeature enum and DeviceQueueCreateInfo struct
Squareys Sep 29, 2016
91f64d4
Vk: Create device in AbstractVulkanTester
Squareys Sep 29, 2016
0f12a9a
Vk: Quick fix
Squareys Oct 5, 2016
a57c837
modules: Fix detection of Magnum::Vk headers
Squareys Oct 9, 2016
01a4942
Do not try to destroy state if _version was Version::None
Squareys Oct 9, 2016
d73004e
Vk: Fix device and loads of UnsignedInt conversion errors.
Squareys Oct 9, 2016
126f64f
GlfwApplication: Properly handle Version::None
Squareys Oct 9, 2016
7416e3d
More code...
Squareys Oct 13, 2016
f3e1bdb
'nother big chunk of code
Squareys Oct 15, 2016
d4398e5
More code...
Squareys Oct 16, 2016
f13b15d
Vk: Clean up Format enum naming
Squareys Oct 18, 2016
27b3876
Vk: Fix dangling device memory references
Squareys Oct 18, 2016
55609d1
Vk: Make sure to use normalized texture coordinates
Squareys Oct 18, 2016
55f67e7
More fixes and code
Squareys Oct 31, 2016
0f5d920
Prefer 24 bit depth components
Squareys Nov 2, 2016
496fee9
Add TARGET_VULKAN option
Squareys Apr 21, 2016
be75342
Vk: Add Context
Squareys Apr 21, 2016
5b31fc8
fixup! Vk: Add Context
Squareys Apr 21, 2016
c3a82ef
fixup! Vk: Add Context
Squareys Apr 22, 2016
707f277
WIP
Squareys Apr 26, 2016
26c8f75
WIP
Squareys Apr 27, 2016
f5d3c94
[WIP] Fix Debug callback setup
Squareys May 1, 2016
5e09403
WIP/TEMP
Squareys May 1, 2016
36db8d9
Use ArrayView rather than Array for passing shader code
May 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Expand Up @@ -53,6 +53,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)
option(TARGET_HEADLESS "Build command-line utilities for use on a headless machines" OFF)
option(TARGET_VULKAN "Build for Vulkan" OFF)

# Magnum Info (currently only using GLX, CGL, WGL/EGL on Windows or on NaCl)
if(CORRADE_TARGET_UNIX OR CORRADE_TARGET_NACL OR CORRADE_TARGET_WINDOWS)
Expand Down Expand Up @@ -211,7 +212,9 @@ endif()
if(TARGET_HEADLESS)
set(MAGNUM_TARGET_HEADLESS 1)
endif()

if(TARGET_VULKAN)
set(MAGNUM_TARGET_VULKAN 1)
endif()
if(CORRADE_TARGET_EMSCRIPTEN)
include(UseEmscripten)
endif()
Expand Down
12 changes: 10 additions & 2 deletions modules/FindMagnum.cmake
Expand Up @@ -364,7 +364,7 @@ endif()

# Component distinction (listing them explicitly to avoid mistakes with finding
# components from other repositories)
set(_MAGNUM_LIBRARY_COMPONENTS "^(Audio|DebugTools|MeshTools|Primitives|SceneGraph|Shaders|Shapes|Text|TextureTools|AndroidApplication|GlfwApplication|GlutApplication|GlxApplication|NaClApplication|Sdl2Application|XEglApplication|WindowlessCglApplication|WindowlessEglApplication|WindowlessGlxApplication|WindowlessIosApplication|WindowlessNaClApplication|WindowlessWglApplication|WindowlessWindowsEglApplication|CglContext|EglContext|GlxContext|WglContext)$")
set(_MAGNUM_LIBRARY_COMPONENTS "^(Audio|DebugTools|MeshTools|Primitives|SceneGraph|Shaders|Shapes|Text|TextureTools|Vk|AndroidApplication|GlfwApplication|GlutApplication|GlxApplication|NaClApplication|Sdl2Application|XEglApplication|WindowlessCglApplication|WindowlessEglApplication|WindowlessGlxApplication|WindowlessIosApplication|WindowlessNaClApplication|WindowlessWglApplication|WindowlessWindowsEglApplication|CglContext|EglContext|GlxContext|WglContext)$")
set(_MAGNUM_PLUGIN_COMPONENTS "^(MagnumFont|MagnumFontConverter|ObjImporter|TgaImageConverter|TgaImporter|WavAudioImporter)$")
set(_MAGNUM_EXECUTABLE_COMPONENTS "^(distancefieldconverter|fontconverter|imageconverter|info|al-info)$")

Expand Down Expand Up @@ -563,7 +563,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Context libraries
elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Context.h)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Instance.h)

# GLX context dependencies
if(_component STREQUAL GlxContext)
Expand Down Expand Up @@ -609,6 +609,14 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# TextureTools library
elseif(_component STREQUAL TextureTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h)

elseif(_component STREQUAL Vk)
find_package(Vulkan)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Vulkan::Vulkan)
set_target_properties(Magnum::${_component} PROPERTIES
INTERFACE_CORRADE_CXX_STANDARD 14)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Context.h)
endif()

# Find library/plugin includes
Expand Down
83 changes: 83 additions & 0 deletions modules/FindVulkan.cmake
@@ -0,0 +1,83 @@
#.rst:
# Find Vulkan
# ---------
#
# Finds the Vulkan library. This module defines:
#
# VULKAN_FOUND - True if VULKAN library is found
# VULKAN::VULKAN - VULKAN imported target
#
# Additionally these variables are defined for internal usage:
#
# VULKAN_LIBRARY - VULKAN library
# VULKAN_INCLUDE_DIR - Root include dir
#

#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
# Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
#
# 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.
#

if (WIN32)
find_path(VULKAN_INCLUDE_DIR NAMES vulkan.h HINTS
"$ENV{VULKAN_SDK}/Include"
"$ENV{VK_SDK_PATH}/Include"
PATH_SUFFIXES vulkan)
if (CMAKE_CL_64)
find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS
"$ENV{VULKAN_SDK}/Bin"
"$ENV{VK_SDK_PATH}/Bin")
else()
find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS
"$ENV{VULKAN_SDK}/Bin32"
"$ENV{VK_SDK_PATH}/Bin32")
endif()
else()
find_path(VULKAN_INCLUDE_DIR NAMES vulkan.h HINTS
"$ENV{VULKAN_SDK}/Include" PATH_SUFFIXES vulkan)
find_library(VULKAN_LIBRARY NAMES vulkan HINTS
"$ENV{VULKAN_SDK}/Bin")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("VULKAN" DEFAULT_MSG
VULKAN_LIBRARY
VULKAN_INCLUDE_DIR)

if(NOT TARGET Vulkan::Vulkan)
add_library(Vulkan::Vulkan UNKNOWN IMPORTED)

# Work around BUGGY framework support on OSX
# https://cmake.org/Bug/view.php?id=14105
if(CORRADE_TARGET_APPLE AND ${VULKAN_LIBRARY} MATCHES "\\.framework$")
set_property(TARGET Vulkan::Vulkan PROPERTY IMPORTED_LOCATION ${VULKAN_LIBRARY}/VULKAN)
else()
set_property(TARGET Vulkan::Vulkan PROPERTY IMPORTED_LOCATION ${VULKAN_LIBRARY})
endif()

set_property(TARGET Vulkan::Vulkan PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${VULKAN_INCLUDE_DIR})
endif()


5 changes: 5 additions & 0 deletions src/Magnum/CMakeLists.txt
Expand Up @@ -323,6 +323,11 @@ if(WITH_TEXTURETOOLS)
add_subdirectory(TextureTools)
endif()

# Vulkan stuff
if(TARGET_VULKAN)
add_subdirectory(Vk)
endif()

if(BUILD_TESTS)
# Library with graceful assert for testing
add_library(MagnumMathTestLib ${SHARED_OR_STATIC}
Expand Down
5 changes: 4 additions & 1 deletion src/Magnum/Context.cpp
Expand Up @@ -468,7 +468,10 @@ Context::Context(Context&& other): _version{std::move(other._version)},
}

Context::~Context() {
delete _state;
if(_version != Version::None) {
/* Context was not created */
delete _state;
}

if(currentContext == this) currentContext = nullptr;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Magnum/Platform/CMakeLists.txt
Expand Up @@ -106,6 +106,13 @@ if(WITH_GLFWAPPLICATION)
message(FATAL_ERROR "GLFW library, required by GlfwApplication, was not found. Set WITH_GLFWAPPLICATION to OFF to skip building it.")
endif()

if(TARGET_VULKAN)
find_package(Vulkan)
if(NOT GLFW_FOUND)
message(FATAL_ERROR "Vulakn SDK was not found. Set TARGET_VULKAN to OFF to turn off Vulkan support.")
endif()
endif()

set(MagnumGlfwApplication_SRCS
GlfwApplication.cpp
${MagnumSomeContext_OBJECTS})
Expand All @@ -119,6 +126,10 @@ if(WITH_GLFWAPPLICATION)
# linked to the executable and not to any intermediate shared lib
target_link_libraries(MagnumGlfwApplication Magnum GLFW::GLFW)

if(TARGET_VULKAN)
target_link_libraries(MagnumGlfwApplication Magnum Vulkan::Vulkan)
endif()

install(FILES ${MagnumGlfwApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumGlfwApplication
RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
Expand Down
31 changes: 30 additions & 1 deletion src/Magnum/Platform/GlfwApplication.cpp
Expand Up @@ -33,6 +33,10 @@
#include "Magnum/Platform/Context.h"
#include "Magnum/Platform/ScreenedApplication.hpp"

#ifdef MAGNUM_TARGET_VULKAN
#include "Magnum/Vk/Instance.h"
#endif

namespace Magnum { namespace Platform {

GlfwApplication* GlfwApplication::_instance = nullptr;
Expand Down Expand Up @@ -90,6 +94,7 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) {
glfwWindowHint(GLFW_ICONIFIED, flags >= Configuration::WindowFlag::Minimized);
glfwWindowHint(GLFW_FLOATING, flags >= Configuration::WindowFlag::Floating);
}

glfwWindowHint(GLFW_FOCUSED, configuration.windowFlags() >= Configuration::WindowFlag::Focused);

/* Context window hints */
Expand Down Expand Up @@ -120,7 +125,10 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) {
#else
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
#endif
} else {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

/* Set context flags */
_window = glfwCreateWindow(configuration.size().x(), configuration.size().y(), configuration.title().c_str(), monitor, nullptr);
Expand All @@ -140,7 +148,15 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) {
glfwMakeContextCurrent(_window);

/* Return true if the initialization succeeds */
return _context->tryCreate();
<<<<<<< HEAD
if(configuration.version() != Version::None) {
return _context->tryCreate();
} else {
return true;
}
=======
return true; //_context->tryCreate();
>>>>>>> WIP/TEMP
}

GlfwApplication::~GlfwApplication() {
Expand Down Expand Up @@ -237,6 +253,19 @@ void GlfwApplication::mouseReleaseEvent(MouseEvent&) {}
void GlfwApplication::mouseMoveEvent(MouseMoveEvent&) {}
void GlfwApplication::mouseScrollEvent(MouseScrollEvent&) {}

#ifdef MAGNUM_TARGET_VULKAN
VkSurfaceKHR GlfwApplication::createVkSurface() {
VkSurfaceKHR surface;

VkResult res = glfwCreateWindowSurface(Magnum::Vk::Instance::current(), _window, nullptr, &surface);
if(res != VK_SUCCESS) {
Error() << "Vulkan Surface creation failed.";
}

return surface;
}
#endif

GlfwApplication::Configuration::Configuration():
_title{"Magnum GLFW Application"},
_size{800, 600}, _sampleCount{0},
Expand Down
15 changes: 15 additions & 0 deletions src/Magnum/Platform/GlfwApplication.h
Expand Up @@ -40,7 +40,13 @@
/* We must include our own GL headers first to avoid conflicts */
#include "Magnum/OpenGL.h"

#ifdef MAGNUM_TARGET_VULKAN
#include "vulkan.h"
#endif

#include <glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <glfw3native.h>

namespace Magnum { namespace Platform {

Expand Down Expand Up @@ -216,6 +222,15 @@ class GlfwApplication {
glfwSetCursorPos(_window, Double(position.x()), Double(position.y()));
}


#ifdef MAGNUM_TARGET_VULKAN
VkSurfaceKHR createVkSurface();

HWND getPlatformWindow() {
return glfwGetWin32Window(_window);
}
#endif

#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else
Expand Down
20 changes: 13 additions & 7 deletions src/Magnum/Test/ContextTest.cpp
Expand Up @@ -3,6 +3,7 @@

Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2016 Jonathan Hale <squareys@googlemail.com>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -33,21 +34,26 @@ namespace Magnum { namespace Test {
struct ContextTest: TestSuite::Tester {
explicit ContextTest();

void debugFlag();
void createAndDestroy();
void flag();
void result();
};

ContextTest::ContextTest() {
addTests({&ContextTest::debugFlag});
addTests({&ContextTest::createAndDestroy,
&ContextTest::flag,
&ContextTest::result});
}

void ContextTest::debugFlag() {
#ifdef MAGNUM_TARGET_WEBGL
CORRADE_SKIP("No context flags on Emscripten yet.");
#else
void ContextTest::createAndDestroy() {
Vk::Context c{{}};
CORRADE_COMPARE(c.version(), Vk::Version::Vulkan_1_0);
}

void ContextTest::flag() {
std::ostringstream out;
Debug(&out) << Context::Flag::Debug << Context::Flag(0xdead);
CORRADE_COMPARE(out.str(), "Context::Flag::Debug Context::Flag(0xdead)\n");
#endif
}

}}
Expand Down