Switched to Volk
This commit is contained in:
parent
089e7493b6
commit
b5bae50f55
@ -82,7 +82,13 @@ endif()
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
set(ENGINE_EXTRA_DEFINITIONS "")
|
# Same in every mode: no link-time dependency on libvulkan, all Vulkan
|
||||||
|
# functions come from volk (otherwise vk*KHR aliases are undefined at link).
|
||||||
|
set(ENGINE_EXTRA_DEFINITIONS
|
||||||
|
VK_NO_PROTOTYPES
|
||||||
|
VMA_STATIC_VULKAN_FUNCTIONS=0
|
||||||
|
VMA_DYNAMIC_VULKAN_FUNCTIONS=1
|
||||||
|
)
|
||||||
|
|
||||||
if(VULKANENGINE_FETCH_DEPS)
|
if(VULKANENGINE_FETCH_DEPS)
|
||||||
# Portable = static libs, bundle = shared libs (in lib/)
|
# Portable = static libs, bundle = shared libs (in lib/)
|
||||||
@ -118,7 +124,7 @@ if(VULKANENGINE_FETCH_DEPS)
|
|||||||
GIT_REPOSITORY https://github.com/zeux/volk.git
|
GIT_REPOSITORY https://github.com/zeux/volk.git
|
||||||
GIT_TAG 1.4.304)
|
GIT_TAG 1.4.304)
|
||||||
FetchContent_Declare(VMA
|
FetchContent_Declare(VMA
|
||||||
GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndPatches/VulkanMemoryAllocator.git
|
GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
|
||||||
GIT_TAG v3.2.1)
|
GIT_TAG v3.2.1)
|
||||||
FetchContent_Declare(glfw
|
FetchContent_Declare(glfw
|
||||||
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
||||||
@ -145,14 +151,9 @@ if(VULKANENGINE_FETCH_DEPS)
|
|||||||
|
|
||||||
target_link_libraries(volk PUBLIC Vulkan::Headers)
|
target_link_libraries(volk PUBLIC Vulkan::Headers)
|
||||||
|
|
||||||
# No link-time dependency on libvulkan: functions come from volk
|
|
||||||
list(APPEND ENGINE_EXTRA_DEFINITIONS
|
|
||||||
VK_NO_PROTOTYPES
|
|
||||||
VMA_STATIC_VULKAN_FUNCTIONS=0
|
|
||||||
VMA_DYNAMIC_VULKAN_FUNCTIONS=1
|
|
||||||
)
|
|
||||||
else()
|
else()
|
||||||
# Nix path (unchanged)
|
# Nix path
|
||||||
|
find_package( volk CONFIG REQUIRED )
|
||||||
find_package( glfw3 REQUIRED )
|
find_package( glfw3 REQUIRED )
|
||||||
find_package( glm REQUIRED )
|
find_package( glm REQUIRED )
|
||||||
find_package( VulkanMemoryAllocator CONFIG REQUIRED )
|
find_package( VulkanMemoryAllocator CONFIG REQUIRED )
|
||||||
@ -297,10 +298,8 @@ function ( addBinary BINARY_NAME )
|
|||||||
${CMAKE_SOURCE_DIR}/include/imgui/backends/imgui_impl_vulkan.cpp
|
${CMAKE_SOURCE_DIR}/include/imgui/backends/imgui_impl_vulkan.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# imgui's Vulkan backend must use volk when there is no linked loader
|
# imgui's Vulkan backend must use volk since there is no linked loader
|
||||||
if(VULKANENGINE_FETCH_DEPS)
|
target_compile_definitions(${BINARY_NAME} PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK)
|
||||||
target_compile_definitions(${BINARY_NAME} PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
@ -410,7 +409,8 @@ if(VULKANENGINE_FETCH_DEPS)
|
|||||||
simdjson::simdjson
|
simdjson::simdjson
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
list(APPEND lib_list vulkan)
|
# Nix: volk comes from nixpkgs (vulkan-volk); libvulkan is NOT linked
|
||||||
|
list(APPEND lib_list volk::volk)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
addBinary (
|
addBinary (
|
||||||
|
|||||||
@ -15,12 +15,12 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <volk.h>
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
#include <vulkan/vk_enum_string_helper.h>
|
#include <vulkan/vk_enum_string_helper.h>
|
||||||
#include <vk_mem_alloc.h>
|
#include <vk_mem_alloc.h>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_NONE
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
|||||||
@ -624,6 +624,7 @@ void Engine::initVulkan() {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
_logger.logRAM(ENGINE, EINIT, "Initializing Vulkan...");
|
_logger.logRAM(ENGINE, EINIT, "Initializing Vulkan...");
|
||||||
#endif
|
#endif
|
||||||
|
volkInitialize();
|
||||||
vkb::InstanceBuilder builder;
|
vkb::InstanceBuilder builder;
|
||||||
|
|
||||||
// Create a basic VK instance, with debuging features if compiled in debug mode
|
// Create a basic VK instance, with debuging features if compiled in debug mode
|
||||||
@ -639,6 +640,8 @@ void Engine::initVulkan() {
|
|||||||
_instance = vkbInst.instance;
|
_instance = vkbInst.instance;
|
||||||
_debugMessenger = vkbInst.debug_messenger;
|
_debugMessenger = vkbInst.debug_messenger;
|
||||||
|
|
||||||
|
volkLoadInstance(_instance);
|
||||||
|
|
||||||
// Create the surface
|
// Create the surface
|
||||||
if (glfwCreateWindowSurface(_instance, window, nullptr, & _surface) != VK_SUCCESS) {
|
if (glfwCreateWindowSurface(_instance, window, nullptr, & _surface) != VK_SUCCESS) {
|
||||||
_logger.logFatal(ENGINE, "Failed to create window surface !\nAborting...");
|
_logger.logFatal(ENGINE, "Failed to create window surface !\nAborting...");
|
||||||
@ -769,6 +772,8 @@ void Engine::initVulkan() {
|
|||||||
vkGetDeviceQueue(_device, _graphicsQueueFamily, 0, &_graphicsQueue);
|
vkGetDeviceQueue(_device, _graphicsQueueFamily, 0, &_graphicsQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volkLoadDevice(_device);
|
||||||
|
|
||||||
VmaAllocatorCreateInfo allocatorInfo = {
|
VmaAllocatorCreateInfo allocatorInfo = {
|
||||||
.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT,
|
.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT,
|
||||||
.physicalDevice = _choosenGPU,
|
.physicalDevice = _choosenGPU,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user