From 5589aaf301a3682a4488e2781326f168d2979837 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 29 Jan 2024 20:54:41 +0100 Subject: [PATCH] Move vk_allocator to common --- client/CMakeLists.txt | 20 ----------- client/application.cpp | 3 +- client/decoder/ffmpeg/ffmpeg_decoder.cpp | 1 - client/render/text_rasterizer.cpp | 1 - client/{utils => xr}/check.h | 26 +------------- client/xr/details/enumerate.h | 2 +- client/xr/error_category.cpp | 2 +- client/xr/instance.h | 8 ++--- client/xr/system.cpp | 3 +- client/xr/xr.h | 2 +- common/CMakeLists.txt | 28 ++++++++++++++- {client => common}/vk/allocation.cpp | 2 +- {client => common}/vk/allocation.h | 0 common/vk/check.h | 46 ++++++++++++++++++++++++ {client => common}/vk/error_category.cpp | 2 +- {client => common}/vk/vk_allocator.cpp | 2 +- {client => common}/vk/vk_allocator.h | 0 {client => common/vk}/vk_mem_alloc.cpp | 0 18 files changed, 86 insertions(+), 62 deletions(-) rename client/{utils => xr}/check.h (70%) rename {client => common}/vk/allocation.cpp (99%) rename {client => common}/vk/allocation.h (100%) create mode 100644 common/vk/check.h rename {client => common}/vk/error_category.cpp (98%) rename {client => common}/vk/vk_allocator.cpp (97%) rename {client => common}/vk/vk_allocator.h (100%) rename {client => common/vk}/vk_mem_alloc.cpp (100%) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 453747c6..3e68b137 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -77,25 +77,6 @@ else() file(CREATE_LINK ${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/share/wivrn/assets SYMBOLIC) endif() -if(ANDROID OR Vulkan_VERSION VERSION_LESS 1.3.268) - # The Vulkan headers in Android do not include the C++ headers, download them - # Minimum version is 1.3.256 - set(VULKAN_VERSION "1.3.268.0") - - if(NOT EXISTS ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz) - if (EXISTS ${CMAKE_SOURCE_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz) - file(CREATE_LINK ${CMAKE_SOURCE_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz SYMBOLIC) - else() - file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-Headers/archive/vulkan-sdk-${VULKAN_VERSION}.tar.gz ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz - EXPECTED_HASH SHA256=94993cbe2b1a604c0d5d9ea37a767e1aba4d771d2bfd4ddceefd66243095164f) - endif() - endif() - - file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz DESTINATION ${CMAKE_BINARY_DIR}) - - target_include_directories(wivrn PRIVATE ${CMAKE_BINARY_DIR}/Vulkan-Headers-vulkan-sdk-${VULKAN_VERSION}/include) -endif() - target_sources(wivrn PRIVATE ${imgui_SOURCE_DIR}/imgui.cpp ${imgui_SOURCE_DIR}/imgui_draw.cpp @@ -116,7 +97,6 @@ target_compile_definitions(wivrn PRIVATE IMGUI_DEFINE_MATH_OPERATORS) target_compile_features(wivrn PRIVATE cxx_std_20) target_compile_definitions(wivrn PRIVATE "XR_USE_TIMESPEC=1") -target_compile_definitions(wivrn PRIVATE VULKAN_HPP_NO_STRUCT_CONSTRUCTORS VMA_VULKAN_VERSION=1001000) set_target_properties(wivrn PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/client/application.cpp b/client/application.cpp index 9ce651eb..fae1f2a8 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -24,7 +24,6 @@ #include "scene.h" #include "spdlog/common.h" #include "spdlog/spdlog.h" -#include "utils/check.h" #include "utils/files.h" #include "utils/named_thread.h" #include "xr/actionset.h" @@ -39,6 +38,8 @@ #include #include #include +#include "vk/check.h" +#include "xr/check.h" #include #include #include diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/decoder/ffmpeg/ffmpeg_decoder.cpp index 9aa9b623..3206ffd2 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -21,7 +21,6 @@ #include "scenes/stream.h" #include "spdlog/spdlog.h" -#include "utils/check.h" #include #include diff --git a/client/render/text_rasterizer.cpp b/client/render/text_rasterizer.cpp index 798ebab6..d206aa15 100644 --- a/client/render/text_rasterizer.cpp +++ b/client/render/text_rasterizer.cpp @@ -27,7 +27,6 @@ #include #include -#include "utils/check.h" #include #include #include diff --git a/client/utils/check.h b/client/xr/check.h similarity index 70% rename from client/utils/check.h rename to client/xr/check.h index f442f747..21d2a733 100644 --- a/client/utils/check.h +++ b/client/xr/check.h @@ -19,37 +19,14 @@ #pragma once -#include -#include -#include #include +#include namespace xr { const std::error_category & error_category(); } -namespace vk -{ -const std::error_category & error_category(); -} - -static inline VkResult check(VkResult result, const char * statement) -{ - if (result != VK_SUCCESS) - throw std::system_error(result, vk::error_category(), statement); - - return result; -} - -static inline VkResult check(VkResult result, const char * /*statement*/, const char * message) -{ - if (result != VK_SUCCESS) - throw std::system_error(result, vk::error_category(), message); - - return result; -} - static inline XrResult check(XrResult result, const char * statement) { if (!XR_SUCCEEDED(result)) @@ -66,5 +43,4 @@ static inline XrResult check(XrResult result, const char * /*statement*/, const return result; } -#define CHECK_VK(result, ...) check(result, #result __VA_OPT__(, ) __VA_ARGS__) #define CHECK_XR(result, ...) check(result, #result __VA_OPT__(, ) __VA_ARGS__) diff --git a/client/xr/details/enumerate.h b/client/xr/details/enumerate.h index a72f1c60..4bd935ff 100644 --- a/client/xr/details/enumerate.h +++ b/client/xr/details/enumerate.h @@ -23,8 +23,8 @@ #include #endif -#include "utils/check.h" #include "utils/typename.h" +#include "xr/check.h" #include #include #include diff --git a/client/xr/error_category.cpp b/client/xr/error_category.cpp index b6938d88..2f28ebe2 100644 --- a/client/xr/error_category.cpp +++ b/client/xr/error_category.cpp @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "utils/check.h" +#include "xr/check.h" #include "xr.h" #include diff --git a/client/xr/instance.h b/client/xr/instance.h index ae744ba1..8cc1c51f 100644 --- a/client/xr/instance.h +++ b/client/xr/instance.h @@ -24,8 +24,8 @@ #endif #include "error.h" -#include "utils/check.h" #include "utils/handle.h" +#include "xr/check.h" #include #include #include @@ -77,11 +77,7 @@ public: F get_proc(const char * name) { F f; - XrResult result = xrGetInstanceProcAddr(id, name, (PFN_xrVoidFunction *)&f); - if (!XR_SUCCEEDED(result)) - { - throw std::system_error(result, vk::error_category(), std::string("xrGetInstanceProcAddr(") + name + ")"); - } + CHECK_XR(xrGetInstanceProcAddr(id, name, (PFN_xrVoidFunction *)&f), name); return f; } diff --git a/client/xr/system.cpp b/client/xr/system.cpp index 7ac6ecb2..21f5c07e 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -20,7 +20,8 @@ #include "system.h" #include "details/enumerate.h" -#include "xr.h" +#include "vk/check.h" +#include "xr/check.h" #include #include diff --git a/client/xr/xr.h b/client/xr/xr.h index 0619d744..2ca95f22 100644 --- a/client/xr/xr.h +++ b/client/xr/xr.h @@ -25,7 +25,7 @@ #include "session.h" #include "swapchain.h" #include "system.h" -#include "utils/check.h" +#include "xr/check.h" #include #include diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index d7592513..175e2663 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -24,10 +24,36 @@ configure_file(wivrn_config.h.in wivrn_config.h) add_library(wivrn-common STATIC wivrn_sockets.cpp + vk/allocation.cpp + vk/error_category.cpp + vk/vk_allocator.cpp + vk/vk_mem_alloc.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) -target_link_libraries(wivrn-common PUBLIC Boost::pfr) +if(ANDROID) + # The Vulkan headers in Android do not include the C++ headers, download them + # Minimum version is 1.3.256 + set(VULKAN_VERSION "1.3.268.0") + + if(NOT EXISTS ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz) + if (EXISTS ${CMAKE_SOURCE_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz) + file(CREATE_LINK ${CMAKE_SOURCE_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz SYMBOLIC) + else() + file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-Headers/archive/vulkan-sdk-${VULKAN_VERSION}.tar.gz ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz + EXPECTED_HASH SHA256=94993cbe2b1a604c0d5d9ea37a767e1aba4d771d2bfd4ddceefd66243095164f) + endif() + endif() + + file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/vulkan-sdk-${VULKAN_VERSION}.tar.gz DESTINATION ${CMAKE_BINARY_DIR}) + + target_include_directories(wivrn-common PUBLIC ${CMAKE_BINARY_DIR}/Vulkan-Headers-vulkan-sdk-${VULKAN_VERSION}/include) +else() + target_link_libraries(wivrn-common PUBLIC Vulkan::Headers) +endif() + +target_link_libraries(wivrn-common PUBLIC Boost::pfr wivrn-external) target_compile_features(wivrn-common PRIVATE cxx_std_20) +target_compile_definitions(wivrn-common PUBLIC VULKAN_HPP_NO_STRUCT_CONSTRUCTORS VMA_VULKAN_VERSION=1001000) target_include_directories(wivrn-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/client/vk/allocation.cpp b/common/vk/allocation.cpp similarity index 99% rename from client/vk/allocation.cpp rename to common/vk/allocation.cpp index 2227aacb..35bb9ad9 100644 --- a/client/vk/allocation.cpp +++ b/common/vk/allocation.cpp @@ -19,7 +19,7 @@ #include "allocation.h" -#include "utils/check.h" +#include "vk/check.h" #include "vulkan/vulkan_raii.hpp" #include diff --git a/client/vk/allocation.h b/common/vk/allocation.h similarity index 100% rename from client/vk/allocation.h rename to common/vk/allocation.h diff --git a/common/vk/check.h b/common/vk/check.h new file mode 100644 index 00000000..3e0f6804 --- /dev/null +++ b/common/vk/check.h @@ -0,0 +1,46 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2022 Guillaume Meunier + * Copyright (C) 2022 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +namespace vk +{ +const std::error_category & error_category(); +} + +static inline VkResult check(VkResult result, const char * statement) +{ + if (result != VK_SUCCESS) + throw std::system_error(result, vk::error_category(), statement); + + return result; +} + +static inline VkResult check(VkResult result, const char * /*statement*/, const char * message) +{ + if (result != VK_SUCCESS) + throw std::system_error(result, vk::error_category(), message); + + return result; +} + +#define CHECK_VK(result, ...) check(result, #result __VA_OPT__(, ) __VA_ARGS__) diff --git a/client/vk/error_category.cpp b/common/vk/error_category.cpp similarity index 98% rename from client/vk/error_category.cpp rename to common/vk/error_category.cpp index e899a4e3..167178b2 100644 --- a/client/vk/error_category.cpp +++ b/common/vk/error_category.cpp @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "utils/check.h" +#include "vk/check.h" #include #include #include diff --git a/client/vk/vk_allocator.cpp b/common/vk/vk_allocator.cpp similarity index 97% rename from client/vk/vk_allocator.cpp rename to common/vk/vk_allocator.cpp index 1c50fba2..9ea62e63 100644 --- a/client/vk/vk_allocator.cpp +++ b/common/vk/vk_allocator.cpp @@ -18,7 +18,7 @@ */ #include "vk_allocator.h" -#include "utils/check.h" +#include "vk/check.h" vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info) { diff --git a/client/vk/vk_allocator.h b/common/vk/vk_allocator.h similarity index 100% rename from client/vk/vk_allocator.h rename to common/vk/vk_allocator.h diff --git a/client/vk_mem_alloc.cpp b/common/vk/vk_mem_alloc.cpp similarity index 100% rename from client/vk_mem_alloc.cpp rename to common/vk/vk_mem_alloc.cpp