Building samples for Linux (#491)

* CMake: Fix SAMPLES_BUILD and TESTS_BUILD

* CMake: Enable sample build on linux

* samples: Use glfw for window creation

* samples: Fix include order

* samples: Support new window handling

* samples: Add build target for util

* samples: Update CMake scripts to use util target

* samples: Add WindowData to manage unique window

* samples: Surface handling using WIndowData

* sampels: Remove call for vk::su::destroyWindow()

* CMake: FIx more options

* samples: Build SurfaceCapabilities only on WIN32

* samples: Fixed RayTracing sample to build on Linux

* samples: Fix wrong check on SurfaceProtectedCapabilitiesKHR

This also fixes compilation with MinGW gcc/clang

* CMake: check CMAKE_SYSTEM_NAME for Linux samples

* CMake: Add source group for utils

* samples: Fix potential bugs

* samples: Reduce warnings on gcc/clang

* samples: Fix missmatched new/free() which is UB

* samples: Add missing initialization for dynamic dispatcher

* samples: Remove unnecessary  dispacther construct

Co-authored-by: Andreas Süßenbach <asuessenbach@nvidia.com>
This commit is contained in:
mocabe 2020-01-28 18:16:10 +09:00 committed by Andreas Süßenbach
parent f1668a6e28
commit b6a190f4a2
100 changed files with 408 additions and 686 deletions

View File

@ -102,14 +102,14 @@ if (VULKAN_HPP_RUN_GENERATOR)
DEPENDS "${vulkan_hpp}" "${vk_spec}") DEPENDS "${vulkan_hpp}" "${vk_spec}")
endif() endif()
option (SAMPLES_BUILD OFF) option (SAMPLES_BUILD "Build samples" OFF)
if (SAMPLES_BUILD) if (SAMPLES_BUILD)
add_subdirectory(glfw) add_subdirectory(glfw)
add_subdirectory(glslang) add_subdirectory(glslang)
add_subdirectory(samples) add_subdirectory(samples)
endif (SAMPLES_BUILD) endif (SAMPLES_BUILD)
option (TESTS_BUILD OFF) option (TESTS_BUILD "Build tests" OFF)
if (TESTS_BUILD) if (TESTS_BUILD)
add_subdirectory(tests) add_subdirectory(tests)
endif (TESTS_BUILD) endif (TESTS_BUILD)

View File

@ -39,7 +39,7 @@ int main(int /*argc*/, char ** /*argv*/)
// Note: No need to explicitly destroy the instance, as the corresponding destroy function is // Note: No need to explicitly destroy the instance, as the corresponding destroy function is
// called by the destructor of the UniqueInstance on leaving this scope. // called by the destructor of the UniqueInstance on leaving this scope.
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -41,7 +41,7 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(02_EnumerateDevices) project(02_EnumerateDevices)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
02_EnumerateDevices.cpp 02_EnumerateDevices.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(02_EnumerateDevices
) )
set_target_properties(02_EnumerateDevices PROPERTIES FOLDER "Samples") set_target_properties(02_EnumerateDevices PROPERTIES FOLDER "Samples")
target_compile_definitions(02_EnumerateDevices PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(02_EnumerateDevices PRIVATE utils)

View File

@ -55,7 +55,7 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(03_InitDevice) project(03_InitDevice)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
03_InitDevice.cpp 03_InitDevice.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(03_InitDevice
) )
set_target_properties(03_InitDevice PROPERTIES FOLDER "Samples") set_target_properties(03_InitDevice PROPERTIES FOLDER "Samples")
target_compile_definitions(03_InitDevice PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(03_InitDevice PRIVATE utils)

View File

@ -49,7 +49,7 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(04_InitCommandBuffer) project(04_InitCommandBuffer)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
04_InitCommandBuffer.cpp 04_InitCommandBuffer.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(04_InitCommandBuffer
) )
set_target_properties(04_InitCommandBuffer PROPERTIES FOLDER "Samples") set_target_properties(04_InitCommandBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(04_InitCommandBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(04_InitCommandBuffer PRIVATE utils)

View File

@ -40,13 +40,14 @@ int main(int /*argc*/, char ** /*argv*/)
uint32_t width = 64; uint32_t width = 64;
uint32_t height = 64; uint32_t height = 64;
#if defined(VK_USE_PLATFORM_WIN32_KHR) vk::su::WindowData window = vk::su::createWindow(AppName, {width, height});
HWND window = vk::su::initializeWindow(AppName, AppName, width, height); vk::UniqueSurfaceKHR surface;
{
vk::UniqueSurfaceKHR surface = instance->createWin32SurfaceKHRUnique(vk::Win32SurfaceCreateInfoKHR(vk::Win32SurfaceCreateFlagsKHR(), GetModuleHandle(nullptr), window)); VkSurfaceKHR _surface;
#else glfwCreateWindowSurface(instance.get(), window.handle, nullptr, &_surface);
#pragma error "unhandled platform" vk::ObjectDestroy<vk::Instance, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> _deleter(instance.get());
#endif surface = vk::UniqueSurfaceKHR(_surface, _deleter);
}
// determine a queueFamilyIndex that suports present // determine a queueFamilyIndex that suports present
// first check if the graphicsQueueFamiliyIndex is good enough // first check if the graphicsQueueFamiliyIndex is good enough
@ -140,23 +141,17 @@ int main(int /*argc*/, char ** /*argv*/)
imageViews.push_back(device->createImageViewUnique(imageViewCreateInfo)); imageViews.push_back(device->createImageViewUnique(imageViewCreateInfo));
} }
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(window);
#else
#pragma error "unhandled platform"
#endif
// Note: No need to explicitly destroy the ImageViews or the swapChain, as the corresponding destroy // Note: No need to explicitly destroy the ImageViews or the swapChain, as the corresponding destroy
// functions are called by the destructor of the UniqueImageView and the UniqueSwapChainKHR on leaving this scope. // functions are called by the destructor of the UniqueImageView and the UniqueSwapChainKHR on leaving this scope.
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(05_InitSwapchain) project(05_InitSwapchain)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
05_InitSwapchain.cpp 05_InitSwapchain.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(05_InitSwapchain
) )
set_target_properties(05_InitSwapchain PROPERTIES FOLDER "Samples") set_target_properties(05_InitSwapchain PROPERTIES FOLDER "Samples")
target_compile_definitions(05_InitSwapchain PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(05_InitSwapchain PRIVATE utils)

View File

@ -33,7 +33,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -82,19 +82,13 @@ int main(int /*argc*/, char ** /*argv*/)
vk::UniqueImageView depthView = device->createImageViewUnique(vk::ImageViewCreateInfo(vk::ImageViewCreateFlags(), depthImage.get(), vk::ImageViewType::e2D, depthFormat, componentMapping, subResourceRange)); vk::UniqueImageView depthView = device->createImageViewUnique(vk::ImageViewCreateInfo(vk::ImageViewCreateFlags(), depthImage.get(), vk::ImageViewType::e2D, depthFormat, componentMapping, subResourceRange));
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(06_InitDepthBuffer) project(06_InitDepthBuffer)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
06_InitDepthBuffer.cpp 06_InitDepthBuffer.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(06_InitDepthBuffer
) )
set_target_properties(06_InitDepthBuffer PROPERTIES FOLDER "Samples") set_target_properties(06_InitDepthBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(06_InitDepthBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(06_InitDepthBuffer PRIVATE utils)

View File

@ -64,12 +64,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(07_InitUniformBuffer) project(07_InitUniformBuffer)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
07_InitUniformBuffer.cpp 07_InitUniformBuffer.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(07_InitUniformBuffer
) )
set_target_properties(07_InitUniformBuffer PROPERTIES FOLDER "Samples") set_target_properties(07_InitUniformBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(07_InitUniformBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(07_InitUniformBuffer PRIVATE utils)

View File

@ -49,12 +49,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(08_InitPipelineLayout) project(08_InitPipelineLayout)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
08_InitPipelineLayout.cpp 08_InitPipelineLayout.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(08_InitPipelineLayout
) )
set_target_properties(08_InitPipelineLayout PROPERTIES FOLDER "Samples") set_target_properties(08_InitPipelineLayout PROPERTIES FOLDER "Samples")
target_compile_definitions(08_InitPipelineLayout PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(08_InitPipelineLayout PRIVATE utils)

View File

@ -59,12 +59,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,14 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(09_InitDescriptorSet) project(09_InitDescriptorSet)
set(HEADERS set(HEADERS
../utils/math.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
09_InitDescriptorSet.cpp 09_InitDescriptorSet.cpp
../utils/math.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -36,4 +32,4 @@ add_executable(09_InitDescriptorSet
) )
set_target_properties(09_InitDescriptorSet PROPERTIES FOLDER "Samples") set_target_properties(09_InitDescriptorSet PROPERTIES FOLDER "Samples")
target_compile_definitions(09_InitDescriptorSet PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(09_InitDescriptorSet PRIVATE utils)

View File

@ -37,7 +37,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(64, 64)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(64, 64));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -63,19 +63,13 @@ int main(int /*argc*/, char ** /*argv*/)
// functions are called by the destructor of the UniqueRenderPass and the UniqueSemaphore on leaving this scope. // functions are called by the destructor of the UniqueRenderPass and the UniqueSemaphore on leaving this scope.
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(10_InitRenderPass) project(10_InitRenderPass)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
10_InitRenderPass.cpp 10_InitRenderPass.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(10_InitRenderPass
) )
set_target_properties(10_InitRenderPass PROPERTIES FOLDER "Samples") set_target_properties(10_InitRenderPass PROPERTIES FOLDER "Samples")
target_compile_definitions(10_InitRenderPass PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(10_InitRenderPass PRIVATE utils)

View File

@ -62,12 +62,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,15 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(11_InitShaders) project(11_InitShaders)
set(HEADERS set(HEADERS
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
11_InitShaders.cpp 11_InitShaders.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -37,6 +32,4 @@ add_executable(11_InitShaders
) )
set_target_properties(11_InitShaders PROPERTIES FOLDER "Samples") set_target_properties(11_InitShaders PROPERTIES FOLDER "Samples")
target_compile_definitions(11_InitShaders PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(11_InitShaders PRIVATE utils)
target_include_directories(11_InitShaders PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(11_InitShaders PUBLIC glslang SPIRV)

View File

@ -33,7 +33,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(64, 64)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(64, 64));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -61,19 +61,13 @@ int main(int /*argc*/, char ** /*argv*/)
// Note: No need to explicitly destroy the Framebuffers, as the destroy functions are called by the destructor of the UniqueFramebuffer on leaving this scope. // Note: No need to explicitly destroy the Framebuffers, as the destroy functions are called by the destructor of the UniqueFramebuffer on leaving this scope.
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(12_InitFrameBuffers) project(12_InitFrameBuffers)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
12_InitFrameBuffers.cpp 12_InitFrameBuffers.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(12_InitFrameBuffers
) )
set_target_properties(12_InitFrameBuffers PROPERTIES FOLDER "Samples") set_target_properties(12_InitFrameBuffers PROPERTIES FOLDER "Samples")
target_compile_definitions(12_InitFrameBuffers PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(12_InitFrameBuffers PRIVATE utils)

View File

@ -34,7 +34,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(64, 64)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(64, 64));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -95,19 +95,13 @@ int main(int /*argc*/, char ** /*argv*/)
// by the destructor of the UniqueBuffer, UniqueDeviceMemory, and UniqueSemaphore, respectively, on leaving this scope. // by the destructor of the UniqueBuffer, UniqueDeviceMemory, and UniqueSemaphore, respectively, on leaving this scope.
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,13 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(13_InitVertexBuffer) project(13_InitVertexBuffer)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
13_InitVertexBuffer.cpp 13_InitVertexBuffer.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -35,4 +32,4 @@ add_executable(13_InitVertexBuffer
) )
set_target_properties(13_InitVertexBuffer PROPERTIES FOLDER "Samples") set_target_properties(13_InitVertexBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(13_InitVertexBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(13_InitVertexBuffer PRIVATE utils)

View File

@ -37,7 +37,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -133,7 +133,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount 1, // attachmentCount
&pipelineColorBlendAttachmentState, // pAttachments &pipelineColorBlendAttachmentState, // pAttachments
{ { (1.0f, 1.0f, 1.0f, 1.0f) } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
@ -160,19 +160,13 @@ int main(int /*argc*/, char ** /*argv*/)
vk::UniquePipeline pipeline = device->createGraphicsPipelineUnique(nullptr, graphicsPipelineCreateInfo); vk::UniquePipeline pipeline = device->createGraphicsPipelineUnique(nullptr, graphicsPipelineCreateInfo);
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError &err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(14_InitPipeline) project(14_InitPipeline)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
14_InitPipeline.cpp 14_InitPipeline.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(14_InitPipeline
) )
set_target_properties(14_InitPipeline PROPERTIES FOLDER "Samples") set_target_properties(14_InitPipeline PROPERTIES FOLDER "Samples")
target_compile_definitions(14_InitPipeline PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(14_InitPipeline PRIVATE utils)
target_include_directories(14_InitPipeline PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(14_InitPipeline PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "15_DrawCube"; static char const* AppName = "15_DrawCube";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -116,23 +117,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(15_DrawCube) project(15_DrawCube)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
15_DrawCube.cpp 15_DrawCube.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(15_DrawCube
) )
set_target_properties(15_DrawCube PROPERTIES FOLDER "Samples") set_target_properties(15_DrawCube PROPERTIES FOLDER "Samples")
target_compile_definitions(15_DrawCube PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(15_DrawCube PRIVATE utils)
target_include_directories(15_DrawCube PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(15_DrawCube PUBLIC glslang SPIRV)

View File

@ -96,12 +96,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(16_Vulkan_1_1) project(16_Vulkan_1_1)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
16_Vulkan_1_1.cpp 16_Vulkan_1_1.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(16_Vulkan_1_1
) )
set_target_properties(16_Vulkan_1_1 PROPERTIES FOLDER "Samples") set_target_properties(16_Vulkan_1_1 PROPERTIES FOLDER "Samples")
target_compile_definitions(16_Vulkan_1_1 PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(16_Vulkan_1_1 PRIVATE utils)

View File

@ -18,12 +18,14 @@ find_package(Vulkan REQUIRED)
project(Vulkan-Hpp_Samples) project(Vulkan-Hpp_Samples)
option (SAMPLES_BUILD_WITH_LOCAL_VULKAN_HPP OFF) option (SAMPLES_BUILD_WITH_LOCAL_VULKAN_HPP "Build with local Vulkan headers" OFF)
if (CMAKE_SYSTEM_NAME MATCHES "Windows") if (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-DNOMINMAX -DVK_USE_PLATFORM_WIN32_KHR) add_definitions(-DNOMINMAX -DVK_USE_PLATFORM_WIN32_KHR)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
else() else()
message(FATAL_ERROR, "unhandled platform !") message(FATAL_ERROR, "Vulkan-Hpp: unhandled platform for samples!")
endif() endif()
FILE (GLOB linkunits ${CMAKE_CURRENT_SOURCE_DIR}/*) FILE (GLOB linkunits ${CMAKE_CURRENT_SOURCE_DIR}/*)

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(CopyBlitImage) project(CopyBlitImage)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
CopyBlitImage.cpp CopyBlitImage.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(CopyBlitImage
) )
set_target_properties(CopyBlitImage PROPERTIES FOLDER "Samples") set_target_properties(CopyBlitImage PROPERTIES FOLDER "Samples")
target_compile_definitions(CopyBlitImage PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(CopyBlitImage PRIVATE utils)

View File

@ -18,6 +18,8 @@
#include "../utils/utils.hpp" #include "../utils/utils.hpp"
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include <thread>
static char const* AppName = "CopyBlitImage"; static char const* AppName = "CopyBlitImage";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -32,7 +34,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(640, 640)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(640, 640));
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(surfaceData.surface.get()); vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(surfaceData.surface.get());
if (!(surfaceCapabilities.supportedUsageFlags & vk::ImageUsageFlagBits::eTransferDst)) if (!(surfaceCapabilities.supportedUsageFlags & vk::ImageUsageFlagBits::eTransferDst))
@ -150,22 +152,16 @@ int main(int /*argc*/, char ** /*argv*/)
/* Now present the image in the window */ /* Now present the image in the window */
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer, nullptr)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer, nullptr));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -125,12 +125,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(DrawTexturedCube) project(DrawTexturedCube)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
DrawTexturedCube.cpp DrawTexturedCube.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(DrawTexturedCube
) )
set_target_properties(DrawTexturedCube PROPERTIES FOLDER "Samples") set_target_properties(DrawTexturedCube PROPERTIES FOLDER "Samples")
target_compile_definitions(DrawTexturedCube PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(DrawTexturedCube PRIVATE utils)
target_include_directories(DrawTexturedCube PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(DrawTexturedCube PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "DrawTexturedCube"; static char const* AppName = "DrawTexturedCube";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -122,23 +123,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(DynamicUniform) project(DynamicUniform)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
DynamicUniform.cpp DynamicUniform.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(DynamicUniform
) )
set_target_properties(DynamicUniform PROPERTIES FOLDER "Samples") set_target_properties(DynamicUniform PROPERTIES FOLDER "Samples")
target_compile_definitions(DynamicUniform PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(DynamicUniform PRIVATE utils)
target_include_directories(DynamicUniform PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(DynamicUniform PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "DynamicUniform"; static char const* AppName = "DynamicUniform";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -151,23 +152,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -32,4 +32,4 @@ add_executable(EnableValidationWithCallback
) )
set_target_properties(EnableValidationWithCallback PROPERTIES FOLDER "Samples") set_target_properties(EnableValidationWithCallback PROPERTIES FOLDER "Samples")
target_link_libraries(EnableValidationWithCallback PUBLIC "${Vulkan_LIBRARIES}") target_link_libraries(EnableValidationWithCallback PRIVATE utils)

View File

@ -101,6 +101,13 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
try try
{ {
#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1)
// initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
#endif
std::vector<vk::LayerProperties> instanceLayerProperties = vk::enumerateInstanceLayerProperties(); std::vector<vk::LayerProperties> instanceLayerProperties = vk::enumerateInstanceLayerProperties();
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -123,6 +130,11 @@ int main(int /*argc*/, char ** /*argv*/)
vk::su::checked_cast<uint32_t>(instanceExtensionNames.size()) , instanceExtensionNames.data() ); vk::su::checked_cast<uint32_t>(instanceExtensionNames.size()) , instanceExtensionNames.data() );
vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo); vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo);
#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1)
// initialize function pointers for instance
VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance);
#endif
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT")); pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
if (!pfnVkCreateDebugUtilsMessengerEXT) if (!pfnVkCreateDebugUtilsMessengerEXT)
{ {
@ -164,12 +176,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(EnumerateDevicesAdvanced) project(EnumerateDevicesAdvanced)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
EnumerateDevicesAdvanced.cpp EnumerateDevicesAdvanced.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(EnumerateDevicesAdvanced
) )
set_target_properties(EnumerateDevicesAdvanced PROPERTIES FOLDER "Samples") set_target_properties(EnumerateDevicesAdvanced PROPERTIES FOLDER "Samples")
target_compile_definitions(EnumerateDevicesAdvanced PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(EnumerateDevicesAdvanced PRIVATE utils)

View File

@ -63,7 +63,7 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(Events) project(Events)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
Events.cpp Events.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(Events
) )
set_target_properties(Events PROPERTIES FOLDER "Samples") set_target_properties(Events PROPERTIES FOLDER "Samples")
target_compile_definitions(Events PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(Events PRIVATE utils)

View File

@ -132,12 +132,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(ImmutableSampler) project(ImmutableSampler)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
ImmutableSampler.cpp ImmutableSampler.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(ImmutableSampler
) )
set_target_properties(ImmutableSampler PROPERTIES FOLDER "Samples") set_target_properties(ImmutableSampler PROPERTIES FOLDER "Samples")
target_compile_definitions(ImmutableSampler PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(ImmutableSampler PRIVATE utils)
target_include_directories(ImmutableSampler PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(ImmutableSampler PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "ImmutableSampler"; static char const* AppName = "ImmutableSampler";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -136,21 +137,16 @@ int main(int /*argc*/, char ** /*argv*/)
vk::su::submitAndWait(device, graphicsQueue, commandBuffer); vk::su::submitAndWait(device, graphicsQueue, commandBuffer);
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(InitTexture) project(InitTexture)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
InitTexture.cpp InitTexture.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(InitTexture
) )
set_target_properties(InitTexture PROPERTIES FOLDER "Samples") set_target_properties(InitTexture PROPERTIES FOLDER "Samples")
target_compile_definitions(InitTexture PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(InitTexture PRIVATE utils)
target_include_directories(InitTexture PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(InitTexture PUBLIC glslang SPIRV)

View File

@ -37,7 +37,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(50, 50)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(50, 50));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -139,19 +139,13 @@ int main(int /*argc*/, char ** /*argv*/)
vk::UniqueImageView imageView = device->createImageViewUnique(imageViewCreateInfo); vk::UniqueImageView imageView = device->createImageViewUnique(imageViewCreateInfo);
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(InputAttachment) project(InputAttachment)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
InputAttachment.cpp InputAttachment.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(InputAttachment
) )
set_target_properties(InputAttachment PROPERTIES FOLDER "Samples") set_target_properties(InputAttachment PROPERTIES FOLDER "Samples")
target_compile_definitions(InputAttachment PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(InputAttachment PRIVATE utils)
target_include_directories(InputAttachment PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(InputAttachment PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "InputAttachment"; static char const* AppName = "InputAttachment";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -72,7 +73,7 @@ int main(int /*argc*/, char ** /*argv*/)
exit(-1); exit(-1);
} }
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -179,20 +180,14 @@ int main(int /*argc*/, char ** /*argv*/)
vk::su::submitAndWait(device, graphicsQueue, commandBuffer); vk::su::submitAndWait(device, graphicsQueue, commandBuffer);
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -44,12 +44,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -83,12 +83,12 @@ int main(int /*argc*/, char ** /*argv*/)
} }
std::cout << std::endl; std::cout << std::endl;
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -32,5 +32,4 @@ add_executable(InstanceLayerProperties
) )
set_target_properties(InstanceLayerProperties PROPERTIES FOLDER "Samples") set_target_properties(InstanceLayerProperties PROPERTIES FOLDER "Samples")
target_link_libraries(InstanceLayerProperties PUBLIC "$ENV{VULKAN_SDK}/Lib/vulkan-1.lib" target_link_libraries(InstanceLayerProperties "${Vulkan_LIBRARIES}")
)

View File

@ -48,12 +48,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -38,12 +38,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(MultipleSets) project(MultipleSets)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
MultipleSets.cpp MultipleSets.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(MultipleSets
) )
set_target_properties(MultipleSets PROPERTIES FOLDER "Samples") set_target_properties(MultipleSets PROPERTIES FOLDER "Samples")
target_compile_definitions(MultipleSets PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(MultipleSets PRIVATE utils)
target_include_directories(MultipleSets PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(MultipleSets PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "MultipleSets"; static char const* AppName = "MultipleSets";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -87,7 +88,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -197,21 +198,16 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(OcclusionQuery) project(OcclusionQuery)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
OcclusionQuery.cpp OcclusionQuery.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(OcclusionQuery
) )
set_target_properties(OcclusionQuery PROPERTIES FOLDER "Samples") set_target_properties(OcclusionQuery PROPERTIES FOLDER "Samples")
target_compile_definitions(OcclusionQuery PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(OcclusionQuery PRIVATE utils)
target_include_directories(OcclusionQuery PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(OcclusionQuery PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "OcclusionQuery"; static char const* AppName = "OcclusionQuery";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -155,22 +156,16 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceExtensions) project(PhysicalDeviceExtensions)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceExtensions.cpp PhysicalDeviceExtensions.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceExtensions
) )
set_target_properties(PhysicalDeviceExtensions PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceExtensions PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceExtensions PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceExtensions PRIVATE utils)

View File

@ -53,12 +53,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceFeatures) project(PhysicalDeviceFeatures)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceFeatures.cpp PhysicalDeviceFeatures.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceFeatures
) )
set_target_properties(PhysicalDeviceFeatures PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceFeatures PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceFeatures PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceFeatures PRIVATE utils)

View File

@ -565,12 +565,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceGroups) project(PhysicalDeviceGroups)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceGroups.cpp PhysicalDeviceGroups.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceGroups
) )
set_target_properties(PhysicalDeviceGroups PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceGroups PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceGroups PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceGroups PRIVATE utils)

View File

@ -76,12 +76,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceMemoryProperties) project(PhysicalDeviceMemoryProperties)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceMemoryProperties.cpp PhysicalDeviceMemoryProperties.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceMemoryProperties
) )
set_target_properties(PhysicalDeviceMemoryProperties PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceMemoryProperties PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceMemoryProperties PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceMemoryProperties PRIVATE utils)

View File

@ -87,12 +87,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceProperties) project(PhysicalDeviceProperties)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceProperties.cpp PhysicalDeviceProperties.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceProperties
) )
set_target_properties(PhysicalDeviceProperties PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceProperties PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceProperties PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceProperties PRIVATE utils)

View File

@ -650,12 +650,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PhysicalDeviceQueueFamilyProperties) project(PhysicalDeviceQueueFamilyProperties)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PhysicalDeviceQueueFamilyProperties.cpp PhysicalDeviceQueueFamilyProperties.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(PhysicalDeviceQueueFamilyProperties
) )
set_target_properties(PhysicalDeviceQueueFamilyProperties PROPERTIES FOLDER "Samples") set_target_properties(PhysicalDeviceQueueFamilyProperties PROPERTIES FOLDER "Samples")
target_compile_definitions(PhysicalDeviceQueueFamilyProperties PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PhysicalDeviceQueueFamilyProperties PRIVATE utils)

View File

@ -72,12 +72,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PipelineCache) project(PipelineCache)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PipelineCache.cpp PipelineCache.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(PipelineCache
) )
set_target_properties(PipelineCache PROPERTIES FOLDER "Samples") set_target_properties(PipelineCache PROPERTIES FOLDER "Samples")
target_compile_definitions(PipelineCache PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PipelineCache PRIVATE utils)
target_include_directories(PipelineCache PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(PipelineCache PUBLIC glslang SPIRV)

View File

@ -23,6 +23,7 @@
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <thread>
// For timestamp code (getMilliseconds) // For timestamp code (getMilliseconds)
#ifdef WIN32 #ifdef WIN32
@ -70,7 +71,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::PhysicalDeviceProperties properties = physicalDevice.getProperties(); vk::PhysicalDeviceProperties properties = physicalDevice.getProperties();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -130,7 +131,7 @@ int main(int /*argc*/, char ** /*argv*/)
readCacheStream.seekg(0, readCacheStream.beg); readCacheStream.seekg(0, readCacheStream.beg);
// Allocate memory to hold the initial cache data // Allocate memory to hold the initial cache data
startCacheData = new char[startCacheSize]; startCacheData = (char *)std::malloc(startCacheSize);
// Read the data into our buffer // Read the data into our buffer
readCacheStream.read(startCacheData, startCacheSize); readCacheStream.read(startCacheData, startCacheSize);
@ -294,7 +295,7 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// Store away the cache that we've populated. This could conceivably happen // Store away the cache that we've populated. This could conceivably happen
// earlier, depends on when the pipeline cache stops being populated // earlier, depends on when the pipeline cache stops being populated
@ -316,19 +317,13 @@ int main(int /*argc*/, char ** /*argv*/)
} }
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PipelineDerivative) project(PipelineDerivative)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PipelineDerivative.cpp PipelineDerivative.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(PipelineDerivative
) )
set_target_properties(PipelineDerivative PROPERTIES FOLDER "Samples") set_target_properties(PipelineDerivative PROPERTIES FOLDER "Samples")
target_compile_definitions(PipelineDerivative PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PipelineDerivative PRIVATE utils)
target_include_directories(PipelineDerivative PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(PipelineDerivative PUBLIC glslang SPIRV)

View File

@ -21,6 +21,7 @@
#include "../utils/utils.hpp" #include "../utils/utils.hpp"
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <thread>
static char const* AppName = "PipelineDerivative"; static char const* AppName = "PipelineDerivative";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -36,7 +37,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -116,7 +117,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA); vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(false, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, colorComponentFlags); vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(false, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, colorComponentFlags);
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, 1, &pipelineColorBlendAttachmentState, { { (1.0f, 1.0f, 1.0f, 1.0f) } }); vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, 1, &pipelineColorBlendAttachmentState, { { 1.0f, 1.0f, 1.0f, 1.0f } });
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates);
@ -191,20 +192,14 @@ void main()
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PushConstants) project(PushConstants)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PushConstants.cpp PushConstants.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(PushConstants
) )
set_target_properties(PushConstants PROPERTIES FOLDER "Samples") set_target_properties(PushConstants PROPERTIES FOLDER "Samples")
target_compile_definitions(PushConstants PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PushConstants PRIVATE utils)
target_include_directories(PushConstants PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(PushConstants PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "PushConstants"; static char const* AppName = "PushConstants";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -78,7 +79,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -181,20 +182,14 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(PushDescriptors) project(PushDescriptors)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
PushDescriptors.cpp PushDescriptors.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(PushDescriptors
) )
set_target_properties(PushDescriptors PROPERTIES FOLDER "Samples") set_target_properties(PushDescriptors PROPERTIES FOLDER "Samples")
target_compile_definitions(PushDescriptors PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(PushDescriptors PRIVATE utils)
target_include_directories(PushDescriptors PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(PushDescriptors PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "PushDescriptors"; static char const* AppName = "PushDescriptors";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -68,7 +69,7 @@ int main(int /*argc*/, char ** /*argv*/)
std::vector<std::string> deviceExtensions = vk::su::getDeviceExtensions(); std::vector<std::string> deviceExtensions = vk::su::getDeviceExtensions();
deviceExtensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); deviceExtensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions);
@ -136,7 +137,7 @@ int main(int /*argc*/, char ** /*argv*/)
}; };
// this call is from an extension and needs the dynamic dispatcher !! // this call is from an extension and needs the dynamic dispatcher !!
commandBuffer->pushDescriptorSetKHR(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { 2, writeDescriptorSets }, vk::DispatchLoaderDynamic(*instance, *device)); commandBuffer->pushDescriptorSetKHR(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, {2, writeDescriptorSets});
commandBuffer->bindVertexBuffers(0, *vertexBufferData.buffer, {0}); commandBuffer->bindVertexBuffers(0, *vertexBufferData.buffer, {0});
commandBuffer->setViewport(0, vk::Viewport(0.0f, 0.0f, static_cast<float>(surfaceData.extent.width), static_cast<float>(surfaceData.extent.height), 0.0f, 1.0f)); commandBuffer->setViewport(0, vk::Viewport(0.0f, 0.0f, static_cast<float>(surfaceData.extent.width), static_cast<float>(surfaceData.extent.height), 0.0f, 1.0f));
@ -156,23 +157,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -18,16 +18,11 @@ project(RayTracing)
set(HEADERS set(HEADERS
CameraManipulator.hpp CameraManipulator.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
CameraManipulator.cpp CameraManipulator.cpp
RayTracing.cpp RayTracing.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -39,17 +34,10 @@ add_executable(RayTracing
) )
set_target_properties(RayTracing PROPERTIES FOLDER "Samples") set_target_properties(RayTracing PROPERTIES FOLDER "Samples")
target_compile_definitions(RayTracing PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(RayTracing PRIVATE utils)
target_include_directories(RayTracing PUBLIC target_include_directories(RayTracing PUBLIC
${CMAKE_SOURCE_DIR}/glslang
${CMAKE_SOURCE_DIR}/glfw/include
${CMAKE_SOURCE_DIR}/samples/RayTracing/common ${CMAKE_SOURCE_DIR}/samples/RayTracing/common
${CMAKE_SOURCE_DIR}/samples/RayTracing/vulkannv ${CMAKE_SOURCE_DIR}/samples/RayTracing/vulkannv
${CMAKE_SOURCE_DIR}/stb ${CMAKE_SOURCE_DIR}/stb
${CMAKE_SOURCE_DIR}/tinyobjloader ${CMAKE_SOURCE_DIR}/tinyobjloader
) )
target_link_libraries(RayTracing PUBLIC glslang SPIRV
legacy_stdio_definitions.lib
${CMAKE_SOURCE_DIR}/builds/VS2017_64/glfw/src/Debug/glfw3.lib
)

View File

@ -29,7 +29,7 @@ namespace vk
enum class Mode { Examine, Fly, Walk, Trackball }; enum class Mode { Examine, Fly, Walk, Trackball };
enum class MouseButton { None, Left, Middle, Right }; enum class MouseButton { None, Left, Middle, Right };
enum class ModifierFlagBits { Shift = 1, Ctrl = 2, Alt = 4 }; enum class ModifierFlagBits { Shift = 1, Ctrl = 2, Alt = 4 };
using ModifierFlags = vk::Flags<ModifierFlagBits>; using ModifierFlags = vk::Flags<ModifierFlagBits, uint32_t>;
public: public:
CameraManipulator(); CameraManipulator();

View File

@ -31,8 +31,8 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "CameraManipulator.hpp" #include "CameraManipulator.hpp"
#include "..\..\utils\shaders.hpp" #include "../utils/shaders.hpp"
#include "..\..\utils\utils.hpp" #include "../utils/utils.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
static char const* AppName = "RayTracing"; static char const* AppName = "RayTracing";
@ -939,7 +939,7 @@ int main(int /*argc*/, char** /*argv*/)
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue(std::array<float, 4>({0.2f, 0.2f, 0.2f, 0.2f})); clearValues[0].color = vk::ClearColorValue(std::array<float, 4>({0.2f, 0.2f, 0.2f, 0.2f}));
clearValues[1].depthStencil = {1.0f, 0}; clearValues[1].depthStencil = vk::ClearDepthStencilValue(1.0f, 0);
// Main loop // Main loop
uint32_t frameIndex = 0; uint32_t frameIndex = 0;
@ -1067,12 +1067,12 @@ int main(int /*argc*/, char** /*argv*/)
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(SecondaryCommandBuffer) project(SecondaryCommandBuffer)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
SecondaryCommandBuffer.cpp SecondaryCommandBuffer.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(SecondaryCommandBuffer
) )
set_target_properties(SecondaryCommandBuffer PROPERTIES FOLDER "Samples") set_target_properties(SecondaryCommandBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(SecondaryCommandBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(SecondaryCommandBuffer PRIVATE utils)
target_include_directories(SecondaryCommandBuffer PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(SecondaryCommandBuffer PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "SecondaryCommandBuffer"; static char const* AppName = "SecondaryCommandBuffer";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -159,23 +160,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(SeparateImageSampler) project(SeparateImageSampler)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
SeparateImageSampler.cpp SeparateImageSampler.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(SeparateImageSampler
) )
set_target_properties(SeparateImageSampler PROPERTIES FOLDER "Samples") set_target_properties(SeparateImageSampler PROPERTIES FOLDER "Samples")
target_compile_definitions(SeparateImageSampler PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(SeparateImageSampler PRIVATE utils)
target_include_directories(SeparateImageSampler PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(SeparateImageSampler PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "SeparateImageSampler"; static char const* AppName = "SeparateImageSampler";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -67,7 +68,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -128,7 +129,6 @@ int main(int /*argc*/, char ** /*argv*/)
// Create pipeline layout // Create pipeline layout
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &(*descriptorSetLayout))); vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &(*descriptorSetLayout)));
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo[1] = {};
// Create a single pool to contain data for the descriptor set // Create a single pool to contain data for the descriptor set
std::array<vk::DescriptorPoolSize, 3> poolSizes = std::array<vk::DescriptorPoolSize, 3> poolSizes =
@ -196,21 +196,16 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,21 +17,23 @@ cmake_minimum_required(VERSION 3.2)
project(SurfaceCapabilities) project(SurfaceCapabilities)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
SurfaceCapabilities.cpp SurfaceCapabilities.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES}) source_group(sources FILES ${SOURCES})
add_executable(SurfaceCapabilities # Win32 exclusive vk::SurfaceCapabilitiesFullScreenExclusiveEXT is used
if(WIN32)
add_executable(SurfaceCapabilities
${HEADERS} ${HEADERS}
${SOURCES} ${SOURCES}
) )
set_target_properties(SurfaceCapabilities PROPERTIES FOLDER "Samples")
target_link_libraries(SurfaceCapabilities PRIVATE utils)
set_target_properties(SurfaceCapabilities PROPERTIES FOLDER "Samples") endif()
target_compile_definitions(SurfaceCapabilities PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1)

View File

@ -68,7 +68,7 @@ int main(int /*argc*/, char ** /*argv*/)
// enumerate the physicalDevices // enumerate the physicalDevices
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices(); std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -116,7 +116,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>(); vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n"; std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n";
std::cout << "\t\t" << "setSupportsProtected = " << static_cast<bool>(surfaceProtectedCapabilities.setSupportsProtected) << "\n"; std::cout << "\t\t" << "supportsProtected = " << static_cast<bool>(surfaceProtectedCapabilities.supportsProtected) << "\n";
std::cout << "\n"; std::cout << "\n";
} }
} }
@ -129,12 +129,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,12 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(SurfaceFormats) project(SurfaceFormats)
set(HEADERS set(HEADERS
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
SurfaceFormats.cpp SurfaceFormats.cpp
../utils/utils.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -34,4 +32,4 @@ add_executable(SurfaceFormats
) )
set_target_properties(SurfaceFormats PROPERTIES FOLDER "Samples") set_target_properties(SurfaceFormats PROPERTIES FOLDER "Samples")
target_compile_definitions(SurfaceFormats PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(SurfaceFormats PRIVATE utils)

View File

@ -36,7 +36,7 @@ int main(int /*argc*/, char ** /*argv*/)
// enumerate the physicalDevices // enumerate the physicalDevices
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices(); std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -56,12 +56,12 @@ int main(int /*argc*/, char ** /*argv*/)
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(Template) project(Template)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
Template.cpp Template.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(Template
) )
set_target_properties(Template PROPERTIES FOLDER "Samples") set_target_properties(Template PROPERTIES FOLDER "Samples")
target_compile_definitions(Template PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(Template PRIVATE utils)
target_include_directories(Template PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(Template PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "Template"; static char const* AppName = "Template";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -37,7 +38,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -119,21 +120,16 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -17,18 +17,10 @@ cmake_minimum_required(VERSION 3.2)
project(TexelBuffer) project(TexelBuffer)
set(HEADERS set(HEADERS
../utils/geometries.hpp
../utils/math.hpp
../utils/shaders.hpp
../utils/utils.hpp
) )
set(SOURCES set(SOURCES
TexelBuffer.cpp TexelBuffer.cpp
../utils/math.cpp
../utils/shaders.cpp
../utils/utils.cpp
../../glslang/StandAlone/ResourceLimits.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
@ -40,6 +32,4 @@ add_executable(TexelBuffer
) )
set_target_properties(TexelBuffer PROPERTIES FOLDER "Samples") set_target_properties(TexelBuffer PROPERTIES FOLDER "Samples")
target_compile_definitions(TexelBuffer PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) target_link_libraries(TexelBuffer PRIVATE utils)
target_include_directories(TexelBuffer PUBLIC ${CMAKE_SOURCE_DIR}/glslang)
target_link_libraries(TexelBuffer PUBLIC glslang SPIRV)

View File

@ -22,6 +22,7 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#include <iostream> #include <iostream>
#include <thread>
static char const* AppName = "TexelBuffer"; static char const* AppName = "TexelBuffer";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
@ -79,7 +80,7 @@ int main(int /*argc*/, char ** /*argv*/)
exit(-1); exit(-1);
} }
vk::su::SurfaceData surfaceData(instance, AppName, AppName, vk::Extent2D(500, 500)); vk::su::SurfaceData surfaceData(instance, AppName, vk::Extent2D(500, 500));
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface); std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions()); vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
@ -153,23 +154,18 @@ int main(int /*argc*/, char ** /*argv*/)
; ;
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value)); presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value));
Sleep(1000); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
device->waitIdle(); device->waitIdle();
#if defined(VK_USE_PLATFORM_WIN32_KHR)
DestroyWindow(surfaceData.window);
#else
#pragma error "unhandled platform"
#endif
} }
catch (vk::SystemError err) catch (vk::SystemError& err)
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit(-1);
} }
catch (std::runtime_error err) catch (std::runtime_error& err)
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1); exit(-1);

View File

@ -0,0 +1,43 @@
# Copyright(c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.2)
project(utils)
set(HEADERS
math.hpp
shaders.hpp
utils.hpp
)
set(SOURCES
math.cpp
shaders.cpp
utils.cpp
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_library(utils
${SOURCES}
${HEADERS}
)
target_link_libraries(utils PUBLIC glfw)
target_link_libraries(utils PUBLIC glslang)
target_link_libraries(utils PUBLIC glslang-default-resource-limits)
target_link_libraries(utils PUBLIC SPIRV)
target_compile_definitions(utils PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1)

View File

@ -154,7 +154,7 @@ namespace vk
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(false, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, vk::BlendFactor::eZero, vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(false, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, vk::BlendFactor::eZero,
vk::BlendFactor::eZero, vk::BlendOp::eAdd, colorComponentFlags); vk::BlendFactor::eZero, vk::BlendOp::eAdd, colorComponentFlags);
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, 1, &pipelineColorBlendAttachmentState, vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, 1, &pipelineColorBlendAttachmentState,
{ { (1.0f, 1.0f, 1.0f, 1.0f) } }); { { 1.0f, 1.0f, 1.0f, 1.0f } });
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates);
@ -608,7 +608,7 @@ namespace vk
bufferInfos.reserve(bufferData.size()); bufferInfos.reserve(bufferData.size());
std::vector<vk::WriteDescriptorSet> writeDescriptorSets; std::vector<vk::WriteDescriptorSet> writeDescriptorSets;
writeDescriptorSets.reserve(bufferData.size() + textureData.empty() ? 0 : 1); writeDescriptorSets.reserve(bufferData.size() + (textureData.empty() ? 0 : 1));
uint32_t dstBinding = bindingOffset; uint32_t dstBinding = bindingOffset;
for (auto const& bd : bufferData) for (auto const& bd : bufferData)
{ {
@ -666,15 +666,16 @@ namespace vk
imageView = device->createImageViewUnique(imageViewCreateInfo); imageView = device->createImageViewUnique(imageViewCreateInfo);
} }
SurfaceData::SurfaceData(vk::UniqueInstance &instance, std::string const& className, std::string const& windowName, vk::Extent2D const& extent_) SurfaceData::SurfaceData(vk::UniqueInstance &instance, std::string const &windowName, vk::Extent2D const &extent_)
: extent(extent_) : extent(extent_)
, window(vk::su::createWindow(windowName, extent))
{ {
#if defined(VK_USE_PLATFORM_WIN32_KHR) VkSurfaceKHR _surface;
window = vk::su::initializeWindow(className.c_str(), windowName.c_str(), extent.width, extent.height); VkResult err = glfwCreateWindowSurface(instance.get(), window.handle, nullptr, &_surface);
surface = instance->createWin32SurfaceKHRUnique(vk::Win32SurfaceCreateInfoKHR(vk::Win32SurfaceCreateFlagsKHR(), GetModuleHandle(nullptr), window)); if (err != VK_SUCCESS)
#else throw std::runtime_error("Failed to create window!");
#pragma error "unhandled platform" vk::ObjectDestroy<vk::Instance, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> _deleter(instance.get());
#endif surface = vk::UniqueSurfaceKHR(_surface, _deleter);
} }
SwapChainData::SwapChainData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::SurfaceKHR const& surface, vk::Extent2D const& extent, vk::ImageUsageFlags usage, SwapChainData::SwapChainData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::SurfaceKHR const& surface, vk::Extent2D const& extent, vk::ImageUsageFlags usage,
@ -825,56 +826,54 @@ namespace vk
memcpy(m_data, data, VK_UUID_SIZE * sizeof(uint8_t)); memcpy(m_data, data, VK_UUID_SIZE * sizeof(uint8_t));
} }
#if defined(VK_USE_PLATFORM_WIN32_KHR) WindowData::WindowData(GLFWwindow *wnd, std::string const &name, vk::Extent2D const &extent)
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) : handle{wnd}
, name{name}
, extent{extent}
{ {
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
default:
break;
}
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
} }
HWND initializeWindow(std::string const& className, std::string const& windowName, LONG width, LONG height) WindowData::WindowData(WindowData &&other)
: handle{}
, name{}
, extent{}
{ {
WNDCLASSEX windowClass; std::swap(handle, other.handle);
memset(&windowClass, 0, sizeof(WNDCLASSEX)); std::swap(name, other.name);
std::swap(extent, other.extent);
HINSTANCE instance = GetModuleHandle(nullptr);
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WindowProc;
windowClass.hInstance = instance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszClassName = className.c_str();
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if (!RegisterClassEx(&windowClass))
{
throw std::runtime_error("Failed to register WNDCLASSEX -> terminating");
} }
RECT windowRect = { 0, 0, width, height }; WindowData::~WindowData() noexcept
AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE);
HWND window = CreateWindowEx(0, className.c_str(), windowName.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU, 100, 100, windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top, nullptr, nullptr, instance, nullptr);
if (!window)
{ {
throw std::runtime_error("Failed to create window -> terminating"); glfwDestroyWindow(handle);
} }
return window; WindowData createWindow(std::string const &windowName, vk::Extent2D const &extent)
{
struct glfwContext
{
glfwContext()
{
glfwInit();
glfwSetErrorCallback([](int error, const char *msg) {
std::cerr << "glfw: "
<< "(" << error << ") " << msg << std::endl;
});
}
~glfwContext()
{
glfwTerminate();
}
};
static auto glfwCtx = glfwContext();
(void)glfwCtx;
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *window = glfwCreateWindow(extent.width, extent.height, windowName.c_str(), nullptr, nullptr);
return WindowData(window, windowName, extent);
} }
#else
#pragma error "unhandled platform"
#endif
} }
} }

View File

@ -16,6 +16,10 @@
// //
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
@ -25,6 +29,71 @@ namespace vk
{ {
const uint64_t FenceTimeout = 100000000; const uint64_t FenceTimeout = 100000000;
template <typename Func>
void oneTimeSubmit(vk::UniqueCommandBuffer const& commandBuffer, vk::Queue const& queue, Func const& func)
{
commandBuffer->begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
func(commandBuffer);
commandBuffer->end();
queue.submit(vk::SubmitInfo(0, nullptr, nullptr, 1, &(*commandBuffer)), nullptr);
queue.waitIdle();
}
template <typename Func>
void oneTimeSubmit(vk::UniqueDevice const& device, vk::UniqueCommandPool const& commandPool, vk::Queue const& queue, Func const& func)
{
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(*commandPool, vk::CommandBufferLevel::ePrimary, 1)).front());
oneTimeSubmit(commandBuffer, queue, func);
}
template <class T>
void copyToDevice(vk::UniqueDevice const& device, vk::UniqueDeviceMemory const& memory, T const* pData, size_t count, size_t stride = sizeof(T))
{
assert(sizeof(T) <= stride);
uint8_t* deviceData = static_cast<uint8_t*>(device->mapMemory(memory.get(), 0, count * stride));
if (stride == sizeof(T))
{
memcpy(deviceData, pData, count * sizeof(T));
}
else
{
for (size_t i = 0; i < count; i++)
{
memcpy(deviceData, &pData[i], sizeof(T));
deviceData += stride;
}
}
device->unmapMemory(memory.get());
}
template <class T>
void copyToDevice(vk::UniqueDevice const& device, vk::UniqueDeviceMemory const& memory, T const& data)
{
copyToDevice<T>(device, memory, &data, 1);
}
template<class T>
VULKAN_HPP_INLINE constexpr const T& clamp(const T& v, const T& lo, const T& hi)
{
return v < lo ? lo : hi < v ? hi : v;
}
void setImageLayout(vk::UniqueCommandBuffer const &commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout);
struct WindowData
{
WindowData(GLFWwindow *wnd, std::string const& name, vk::Extent2D const& extent);
WindowData(const WindowData &) = delete;
WindowData(WindowData &&other);
~WindowData() noexcept;
GLFWwindow *handle;
std::string name;
vk::Extent2D extent;
};
WindowData createWindow(std::string const &windowName, vk::Extent2D const &extent);
struct BufferData struct BufferData
{ {
BufferData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::DeviceSize size, vk::BufferUsageFlags usage, BufferData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::DeviceSize size, vk::BufferUsageFlags usage,
@ -79,7 +148,7 @@ namespace vk
vk::DeviceSize m_size; vk::DeviceSize m_size;
vk::BufferUsageFlags m_usage; vk::BufferUsageFlags m_usage;
vk::MemoryPropertyFlags m_propertyFlags; vk::MemoryPropertyFlags m_propertyFlags;
#endif) #endif
}; };
struct ImageData struct ImageData
@ -100,12 +169,10 @@ namespace vk
struct SurfaceData struct SurfaceData
{ {
SurfaceData(vk::UniqueInstance &instance, std::string const& className, std::string const& windowName, vk::Extent2D const& extent); SurfaceData(vk::UniqueInstance &instance, std::string const& windowName, vk::Extent2D const& extent);
vk::Extent2D extent; vk::Extent2D extent;
#if defined(VK_USE_PLATFORM_WIN32_KHR) WindowData window;
HWND window;
#endif
vk::UniqueSurfaceKHR surface; vk::UniqueSurfaceKHR surface;
}; };
@ -214,55 +281,6 @@ namespace vk
return static_cast<TargetType>(value); return static_cast<TargetType>(value);
} }
template <class T>
void copyToDevice(vk::UniqueDevice const& device, vk::UniqueDeviceMemory const& memory, T const* pData, size_t count, size_t stride = sizeof(T))
{
assert(sizeof(T) <= stride);
uint8_t* deviceData = static_cast<uint8_t*>(device->mapMemory(memory.get(), 0, count * stride));
if (stride == sizeof(T))
{
memcpy(deviceData, pData, count * sizeof(T));
}
else
{
for (size_t i = 0; i < count; i++)
{
memcpy(deviceData, &pData[i], sizeof(T));
deviceData += stride;
}
}
device->unmapMemory(memory.get());
}
template <class T>
void copyToDevice(vk::UniqueDevice const& device, vk::UniqueDeviceMemory const& memory, T const& data)
{
copyToDevice<T>(device, memory, &data, 1);
}
template<class T>
VULKAN_HPP_INLINE constexpr const T& clamp(const T& v, const T& lo, const T& hi)
{
return v < lo ? lo : hi < v ? hi : v;
}
template <typename Func>
void oneTimeSubmit(vk::UniqueCommandBuffer const& commandBuffer, vk::Queue const& queue, Func const& func)
{
commandBuffer->begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
func(commandBuffer);
commandBuffer->end();
queue.submit(vk::SubmitInfo(0, nullptr, nullptr, 1, &(*commandBuffer)), nullptr);
queue.waitIdle();
}
template <typename Func>
void oneTimeSubmit(vk::UniqueDevice const& device, vk::UniqueCommandPool const& commandPool, vk::Queue const& queue, Func const& func)
{
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(*commandPool, vk::CommandBufferLevel::ePrimary, 1)).front());
oneTimeSubmit(commandBuffer, queue, func);
}
vk::UniqueDeviceMemory allocateMemory(vk::UniqueDevice const& device, vk::PhysicalDeviceMemoryProperties const& memoryProperties, vk::MemoryRequirements const& memoryRequirements, vk::UniqueDeviceMemory allocateMemory(vk::UniqueDevice const& device, vk::PhysicalDeviceMemoryProperties const& memoryProperties, vk::MemoryRequirements const& memoryRequirements,
vk::MemoryPropertyFlags memoryPropertyFlags); vk::MemoryPropertyFlags memoryPropertyFlags);
bool contains(std::vector<vk::ExtensionProperties> const& extensionProperties, std::string const& extensionName); bool contains(std::vector<vk::ExtensionProperties> const& extensionProperties, std::string const& extensionName);
@ -290,7 +308,6 @@ namespace vk
vk::Format pickDepthFormat(vk::PhysicalDevice const& physicalDevice); vk::Format pickDepthFormat(vk::PhysicalDevice const& physicalDevice);
vk::PresentModeKHR pickPresentMode(std::vector<vk::PresentModeKHR> const& presentModes); vk::PresentModeKHR pickPresentMode(std::vector<vk::PresentModeKHR> const& presentModes);
vk::SurfaceFormatKHR pickSurfaceFormat(std::vector<vk::SurfaceFormatKHR> const& formats); vk::SurfaceFormatKHR pickSurfaceFormat(std::vector<vk::SurfaceFormatKHR> const& formats);
void setImageLayout(vk::UniqueCommandBuffer const& commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout);
void submitAndWait(vk::UniqueDevice &device, vk::Queue queue, vk::UniqueCommandBuffer &commandBuffer); void submitAndWait(vk::UniqueDevice &device, vk::Queue queue, vk::UniqueCommandBuffer &commandBuffer);
void updateDescriptorSets(vk::UniqueDevice const& device, vk::UniqueDescriptorSet const& descriptorSet, void updateDescriptorSets(vk::UniqueDevice const& device, vk::UniqueDescriptorSet const& descriptorSet,
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData, vk::su::TextureData const& textureData, std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData, vk::su::TextureData const& textureData,
@ -299,11 +316,6 @@ namespace vk
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData, std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData,
std::vector<vk::su::TextureData> const& textureData, uint32_t bindingOffset = 0); std::vector<vk::su::TextureData> const& textureData, uint32_t bindingOffset = 0);
#if defined(VK_USE_PLATFORM_WIN32_KHR)
HWND initializeWindow(std::string const& className, std::string const& windowName, LONG width, LONG height);
#else
# error "unhandled platform"
#endif
} }
} }

View File

@ -17,8 +17,8 @@ cmake_minimum_required(VERSION 3.2)
project(Vulkan-Hpp_Tests) project(Vulkan-Hpp_Tests)
option (TESTS_BUILD_WITH_LOCAL_VULKAN_HPP OFF) option (TESTS_BUILD_WITH_LOCAL_VULKAN_HPP "Build with local Vulkan headers" OFF)
option (TESTS_BUILD_ONLY_DYNAMIC OFF) option (TESTS_BUILD_ONLY_DYNAMIC "Build only dynamic" OFF)
if (NOT (TESTS_BUILD_ONLY_DYNAMIC AND TESTS_BUILD_WITH_LOCAL_VULKAN_HPP)) if (NOT (TESTS_BUILD_ONLY_DYNAMIC AND TESTS_BUILD_WITH_LOCAL_VULKAN_HPP))
find_package(Vulkan REQUIRED) find_package(Vulkan REQUIRED)