Compare commits

...

23 Commits

Author SHA1 Message Date
Alexandre
d5d8dc50e4 Compiles, but validation errors prevent it from running 2026-07-02 21:15:33 +02:00
Alexandre
5308e0777b Switched all structs to designated initializers, didn't test building it as I was offline 2026-06-26 19:14:05 +02:00
Alexandre
f05e1605d6 Forgot to init ImGUI, oops 2026-06-09 22:57:10 +02:00
Alexandre
f5965b2142 Added ImGUI demo for compilation 2026-06-09 22:56:11 +02:00
Alexandre
76947a59ee Added ImGUI into the render loop, not tested atm 2026-06-09 22:54:53 +02:00
Alexandre
78b5577ff2 Modified some cmake things 2026-06-09 20:42:06 +02:00
Alexandre
2e111c13e9 Added ImGUI, not called, so benchmark without imgui from here 2026-06-09 20:32:19 +02:00
Alexandre
e9af67ad25 Now draws a gradient with compute 2026-05-28 23:32:38 +02:00
Alexandre
921832a950 Added a descriptor set builder, changed some filepaths and added a basic server 2026-05-24 13:13:20 +02:00
Alexandre
d3cc173d97 Splitted code into folder (see previous commit) 2026-05-05 11:44:41 +02:00
Alexandre
48a88078cd Started adding a server binary, and added common headers, for a modular
approach.
2026-05-05 11:44:15 +02:00
Alexandre
03a30c0096 Fixed a CMake error 2026-05-04 19:11:00 +02:00
Alexandre
a3b498d11b Extended the swapchain creation process 2026-04-23 08:54:57 +02:00
Alexandre
04763de733 Added a version id, the current git hash 2026-04-23 08:28:02 +02:00
Alexandre
a05df4d541 Added a deletion queue, and started reworking the render method 2026-04-22 22:54:24 +02:00
Alexandre
83c5c0bde4 The engine now displays a blue flashing square 2026-04-19 20:37:16 +02:00
Alexandre
0e1c4da452 Create callbacks.h 2026-04-19 01:38:18 +02:00
Alexandre
102e4de093 Switched to GLFW 2026-04-19 01:38:12 +02:00
Alexandre
8cf07095dd Started the engine, using a 'header-only' architecture for compoments of the engine 2026-04-18 23:22:13 +02:00
Alexandre
13327f6fc3 Started the engine, using a 'header-only' architecture for compoments of the engine 2026-04-18 23:22:06 +02:00
Alexandre
7be2cf162d Update README.md 2026-04-18 14:53:37 +02:00
Alexandre
ca590a987b Update README.md 2026-04-18 14:51:30 +02:00
Alexandre
5c52aafc77 Started the vkguide branch, removed everything, exept the licence and
readme
2026-04-18 14:50:50 +02:00
62 changed files with 2527 additions and 289275 deletions

13
.clangd Normal file
View File

@ -0,0 +1,13 @@
CompileFlags:
CompilationDatabase: bin/debug
Add:
- -DENGINE_IMPL
- -DIMAGES_IMPL
- -DINITIALIZERS_IMPL
- -DPIPELINES_IMPL
- -DDESCRIPTORS_IMPL
- -DCALLBACK_IMPL
- -DTIMER_IMPL
- -DLOGGER_IMPL
- -DSERVER_INIT_IMPL
- -DSERVER_IMPL

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Build directories
build/
build-*/
bin/
bin-*/
cmake-build-*/
# CMake generated files

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/imgui"]
path = src/imgui
url = https://github.com/ocornut/imgui.git

52
CMake/BuildInfo.cmake Normal file
View File

@ -0,0 +1,52 @@
find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE ENGINE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE ENGINE_HASH
RESULT_VARIABLE GIT_HASH_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(GIT_DEPS "${CMAKE_SOURCE_DIR}/.git/HEAD")
if(GIT_BRANCH AND EXISTS "${CMAKE_SOURCE_DIR}/.git/refs/heads/${GIT_BRANCH}")
list(APPEND GIT_DEPS "${CMAKE_SOURCE_DIR}/.git/refs/heads/${GIT_BRANCH}")
endif()
# Optionnel : index pour les modifications stagées
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index")
list(APPEND GIT_DEPS "${CMAKE_SOURCE_DIR}/.git/index")
endif()
# On définit la propriété pour le répertoire source.
set_directory_properties(PROPERTIES CMAKE_CONFIGURE_DEPENDS "${GIT_DEPS}")
endif()
# Fallback
if (NOT ENGINE_VERSION OR GIT_DESCRIBE_ERROR_CODE)
set(ENGINE_VERSION "0.0.0")
message(WARNING "No Git tag found, using default version ${ENGINE_VERSION}, fix this....")
endif()
if (NOT ENGINE_HASH OR GIT_HASH_ERROR_CODE)
set(ENGINE_HASH "0000000")
message(WARNING "No Git hash found, using default hash ${ENGINE_HASH}")
endif()
string(REGEX REPLACE "^v" "" ENGINE_VERSION "${ENGINE_VERSION}")

View File

@ -1,106 +0,0 @@
# FindKTX.cmake
#
# Finds the KTX library
#
# This will define the following variables
#
# KTX_FOUND
# KTX_INCLUDE_DIRS
# KTX_LIBRARIES
#
# and the following imported targets
#
# KTX::ktx
#
# Check if we're on Linux - if so, we'll skip the search and directly use FetchContent
if(UNIX AND NOT APPLE)
# On Linux, we assume KTX is not installed and proceed directly to fetching it
set(KTX_FOUND FALSE)
else()
# On non-Linux platforms, try to find KTX using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_KTX QUIET ktx libktx ktx2 libktx2)
endif()
# Try to find KTX using standard find_package
find_path(KTX_INCLUDE_DIR
NAMES ktx.h
PATH_SUFFIXES include ktx KTX ktx2 KTX2
HINTS
${PC_KTX_INCLUDEDIR}
/usr/include
/usr/local/include
$ENV{KTX_DIR}/include
$ENV{VULKAN_SDK}/include
${CMAKE_SOURCE_DIR}/external/ktx/include
)
find_library(KTX_LIBRARY
NAMES ktx ktx2 libktx libktx2
PATH_SUFFIXES lib lib64
HINTS
${PC_KTX_LIBDIR}
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
$ENV{KTX_DIR}/lib
$ENV{VULKAN_SDK}/lib
${CMAKE_SOURCE_DIR}/external/ktx/lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(KTX
REQUIRED_VARS KTX_INCLUDE_DIR KTX_LIBRARY
FAIL_MESSAGE "" # Suppress the error message to allow our fallback
)
# Debug output if KTX is not found (only on non-Linux platforms)
if(NOT KTX_FOUND)
message(STATUS "KTX include directory search paths: ${PC_KTX_INCLUDEDIR}, /usr/include, /usr/local/include, $ENV{KTX_DIR}/include, $ENV{VULKAN_SDK}/include, ${CMAKE_SOURCE_DIR}/external/ktx/include")
message(STATUS "KTX library search paths: ${PC_KTX_LIBDIR}, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64, $ENV{KTX_DIR}/lib, $ENV{VULKAN_SDK}/lib, ${CMAKE_SOURCE_DIR}/external/ktx/lib")
endif()
endif()
if(KTX_FOUND)
set(KTX_INCLUDE_DIRS ${KTX_INCLUDE_DIR})
set(KTX_LIBRARIES ${KTX_LIBRARY})
if(NOT TARGET KTX::ktx)
add_library(KTX::ktx UNKNOWN IMPORTED)
set_target_properties(KTX::ktx PROPERTIES
IMPORTED_LOCATION "${KTX_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${KTX_INCLUDE_DIRS}"
)
endif()
else()
# If not found, use FetchContent to download and build
include(FetchContent)
# Only show the message on non-Linux platforms
if(NOT (UNIX AND NOT APPLE))
message(STATUS "KTX not found, fetching from GitHub...")
endif()
FetchContent_Declare(
ktx
GIT_REPOSITORY https://github.com/KhronosGroup/KTX-Software.git
GIT_TAG v4.3.1 # Use a specific tag for stability
)
# Set options to minimize build time and dependencies
set(KTX_FEATURE_TOOLS OFF CACHE BOOL "Build KTX tools" FORCE)
set(KTX_FEATURE_DOC OFF CACHE BOOL "Build KTX documentation" FORCE)
set(KTX_FEATURE_TESTS OFF CACHE BOOL "Build KTX tests" FORCE)
FetchContent_MakeAvailable(ktx)
# Create an alias to match the expected target name
if(NOT TARGET KTX::ktx)
add_library(KTX::ktx ALIAS ktx)
endif()
set(KTX_FOUND TRUE)
endif()

View File

@ -1,937 +0,0 @@
# Updates for iOS Copyright (c) 2024, Holochip Inc.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindVulkan
----------
.. versionadded:: 3.7
Find Vulkan, which is a low-overhead, cross-platform 3D graphics
and computing API.
Optional COMPONENTS
^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.24
This module respects several optional COMPONENTS.
There are corresponding imported targets for each of these.
``glslc``
The SPIR-V compiler.
``glslangValidator``
The ``glslangValidator`` tool.
``glslang``
The SPIR-V generator library.
``shaderc_combined``
The static library for Vulkan shader compilation.
``SPIRV-Tools``
Tools to process SPIR-V modules.
``MoltenVK``
On macOS, an additional component ``MoltenVK`` is available.
``dxc``
.. versionadded:: 3.25
The DirectX Shader Compiler.
The ``glslc`` and ``glslangValidator`` components are provided even
if not explicitly requested (for backward compatibility).
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found:
``Vulkan::Vulkan``
The main Vulkan library.
``Vulkan::glslc``
.. versionadded:: 3.19
The GLSLC SPIR-V compiler, if it has been found.
``Vulkan::Headers``
.. versionadded:: 3.21
Provides just Vulkan headers include paths, if found. No library is
included in this target. This can be useful for applications that
load Vulkan library dynamically.
``Vulkan::glslangValidator``
.. versionadded:: 3.21
The glslangValidator tool, if found. It is used to compile GLSL and
HLSL shaders into SPIR-V.
``Vulkan::glslang``
.. versionadded:: 3.24
Defined if SDK has the Khronos-reference front-end shader parser and SPIR-V
generator library (glslang).
``Vulkan::shaderc_combined``
.. versionadded:: 3.24
Defined if SDK has the Google static library for Vulkan shader compilation
(shaderc_combined).
``Vulkan::SPIRV-Tools``
.. versionadded:: 3.24
Defined if SDK has the Khronos library to process SPIR-V modules
(SPIRV-Tools).
``Vulkan::MoltenVK``
.. versionadded:: 3.24
Defined if SDK has the Khronos library which implement a subset of Vulkan API
over Apple Metal graphics framework. (MoltenVK).
``Vulkan::volk``
.. versionadded:: 3.25
Defined if SDK has the Vulkan meta-loader (volk).
``Vulkan::dxc_lib``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler library.
``Vulkan::dxc_exe``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler CLI tool.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``Vulkan_FOUND``
set to true if Vulkan was found
``Vulkan_INCLUDE_DIRS``
include directories for Vulkan
``Vulkan_LIBRARIES``
link against this library to use Vulkan
``Vulkan_VERSION``
.. versionadded:: 3.23
value from ``vulkan/vulkan_core.h``
``Vulkan_glslc_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslc executable.
``Vulkan_glslangValidator_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslangValidator executable.
``Vulkan_glslang_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslang library.
``Vulkan_shaderc_combined_FOUND``
.. versionadded:: 3.24
True, if the SDK has the shaderc_combined library.
``Vulkan_SPIRV-Tools_FOUND``
.. versionadded:: 3.24
True, if the SDK has the SPIRV-Tools library.
``Vulkan_MoltenVK_FOUND``
.. versionadded:: 3.24
True, if the SDK has the MoltenVK library.
``Vulkan_volk_FOUND``
.. versionadded:: 3.25
True, if the SDK has the volk library.
``Vulkan_dxc_lib_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler library.
``Vulkan_dxc_exe_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler CLI tool.
The module will also defines these cache variables:
``Vulkan_INCLUDE_DIR``
the Vulkan include directory
``Vulkan_LIBRARY``
the path to the Vulkan library
``Vulkan_GLSLC_EXECUTABLE``
the path to the GLSL SPIR-V compiler
``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE``
the path to the glslangValidator tool
``Vulkan_glslang_LIBRARY``
.. versionadded:: 3.24
Path to the glslang library.
``Vulkan_shaderc_combined_LIBRARY``
.. versionadded:: 3.24
Path to the shaderc_combined library.
``Vulkan_SPIRV-Tools_LIBRARY``
.. versionadded:: 3.24
Path to the SPIRV-Tools library.
``Vulkan_MoltenVK_LIBRARY``
.. versionadded:: 3.24
Path to the MoltenVK library.
``Vulkan_volk_LIBRARY``
.. versionadded:: 3.25
Path to the volk library.
``Vulkan_dxc_LIBRARY``
.. versionadded:: 3.25
Path to the DirectX shader compiler library.
``Vulkan_dxc_EXECUTABLE``
.. versionadded:: 3.25
Path to the DirectX shader compiler CLI tool.
Hints
^^^^^
.. versionadded:: 3.18
The ``VULKAN_SDK`` environment variable optionally specifies the
location of the Vulkan SDK root directory for the given
architecture. It is typically set by sourcing the toplevel
``setup-env.sh`` script of the Vulkan SDK directory into the shell
environment.
#]=======================================================================]
cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW)
# Provide compatibility with a common invalid component request that
# was silently ignored prior to CMake 3.24.
if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
message(AUTHOR_WARNING
"Ignoring unknown component 'FATAL_ERROR'.\n"
"The find_package() command documents no such argument."
)
list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
endif()
if(IOS)
get_filename_component(Vulkan_Target_SDK "$ENV{VULKAN_SDK}/.." REALPATH)
list(APPEND CMAKE_FRAMEWORK_PATH "${Vulkan_Target_SDK}/iOS/lib")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
endif()
# For backward compatibility as `FindVulkan` in previous CMake versions allow to retrieve `glslc`
# and `glslangValidator` without requesting the corresponding component.
if(NOT glslc IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslc)
endif()
if(NOT glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslangValidator)
endif()
if(WIN32)
set(_Vulkan_library_name vulkan-1)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
)
else()
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib32"
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
)
endif()
else()
set(_Vulkan_library_name vulkan)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
)
endif()
if(APPLE AND DEFINED ENV{VULKAN_SDK})
list(APPEND _Vulkan_hint_include_search_paths
"${Vulkan_Target_SDK}/macOS/include"
)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/iOS/lib"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/tvOS/lib"
)
else()
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}}/lib"
)
endif()
endif()
find_path(Vulkan_INCLUDE_DIR
NAMES vulkan/vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
message(STATUS "vulkan_include_dir ${Vulkan_INCLUDE_DIR} search paths ${_Vulkan_hint_include_search_paths}")
mark_as_advanced(Vulkan_INCLUDE_DIR)
find_library(Vulkan_LIBRARY
NAMES ${_Vulkan_library_name}
HINTS
${_Vulkan_hint_library_search_paths}
)
message(STATUS "vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
mark_as_advanced(Vulkan_LIBRARY)
find_library(Vulkan_Layer_API_DUMP
NAMES VkLayer_api_dump
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_API_DUMP)
find_library(Vulkan_Layer_SHADER_OBJECT
NAMES VkLayer_khronos_shader_object
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(VkLayer_khronos_shader_object)
find_library(Vulkan_Layer_SYNC2
NAMES VkLayer_khronos_synchronization2
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_SYNC2)
find_library(Vulkan_Layer_VALIDATION
NAMES VkLayer_khronos_validation
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_VALIDATION)
if(glslc IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLC_EXECUTABLE
NAMES glslc
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLC_EXECUTABLE)
endif()
if(glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE
NAMES glslangValidator
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
endif()
if(glslang IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_glslang-spirv_LIBRARY
NAMES SPIRV
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_LIBRARY)
find_library(Vulkan_glslang-spirv_DEBUG_LIBRARY
NAMES SPIRVd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_DEBUG_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_LIBRARY
NAMES OGLCompiler
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY
NAMES OGLCompilerd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
find_library(Vulkan_glslang-osdependent_LIBRARY
NAMES OSDependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_LIBRARY)
find_library(Vulkan_glslang-osdependent_DEBUG_LIBRARY
NAMES OSDependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-machineindependent_LIBRARY
NAMES MachineIndependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_LIBRARY)
find_library(Vulkan_glslang-machineindependent_DEBUG_LIBRARY
NAMES MachineIndependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_LIBRARY
NAMES GenericCodeGen
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY
NAMES GenericCodeGend
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
find_library(Vulkan_glslang_LIBRARY
NAMES glslang
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_LIBRARY)
find_library(Vulkan_glslang_DEBUG_LIBRARY
NAMES glslangd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_DEBUG_LIBRARY)
endif()
if(shaderc_combined IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_shaderc_combined_LIBRARY
NAMES shaderc_combined
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_LIBRARY)
find_library(Vulkan_shaderc_combined_DEBUG_LIBRARY
NAMES shaderc_combinedd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_DEBUG_LIBRARY)
endif()
if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_SPIRV-Tools_LIBRARY
NAMES SPIRV-Tools
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_LIBRARY)
find_library(Vulkan_SPIRV-Tools_DEBUG_LIBRARY
NAMES SPIRV-Toolsd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
endif()
if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
# CMake has a bug in 3.28 that doesn't handle xcframeworks. Do it by hand for now.
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
if(CMAKE_VERSION VERSION_LESS 3.29)
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/MoltenVK.xcframework/ios-arm64)
else ()
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/)
endif ()
endif ()
find_library(Vulkan_MoltenVK_LIBRARY
NAMES MoltenVK
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_LIBRARY)
find_path(Vulkan_MoltenVK_INCLUDE_DIR
NAMES MoltenVK/mvk_vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_INCLUDE_DIR)
endif()
if(volk IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_volk_LIBRARY
NAMES volk
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_Volk_LIBRARY)
endif()
if (dxc IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_dxc_LIBRARY
NAMES dxcompiler
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_dxc_LIBRARY)
find_program(Vulkan_dxc_EXECUTABLE
NAMES dxc
HINTS
${_Vulkan_hint_executable_search_paths})
mark_as_advanced(Vulkan_dxc_EXECUTABLE)
endif()
if(Vulkan_GLSLC_EXECUTABLE)
set(Vulkan_glslc_FOUND TRUE)
else()
set(Vulkan_glslc_FOUND FALSE)
endif()
if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
set(Vulkan_glslangValidator_FOUND TRUE)
else()
set(Vulkan_glslangValidator_FOUND FALSE)
endif()
if (Vulkan_dxc_EXECUTABLE)
set(Vulkan_dxc_exe_FOUND TRUE)
else()
set(Vulkan_dxc_exe_FOUND FALSE)
endif()
function(_Vulkan_set_library_component_found component)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
"NO_WARNING"
""
"DEPENDENT_COMPONENTS")
set(all_dependent_component_found TRUE)
foreach(dependent_component IN LISTS _ARG_DEPENDENT_COMPONENTS)
if(NOT Vulkan_${dependent_component}_FOUND)
set(all_dependent_component_found FALSE)
break()
endif()
endforeach()
if(all_dependent_component_found AND (Vulkan_${component}_LIBRARY OR Vulkan_${component}_DEBUG_LIBRARY))
set(Vulkan_${component}_FOUND TRUE PARENT_SCOPE)
# For Windows Vulkan SDK, third party tools binaries are provided with different MSVC ABI:
# - Release binaries uses a runtime library
# - Debug binaries uses a debug runtime library
# This lead to incompatibilities in linking for some configuration types due to CMake-default or project-configured selected MSVC ABI.
if(WIN32 AND NOT _ARG_NO_WARNING)
if(NOT Vulkan_${component}_LIBRARY)
message(WARNING
"Library ${component} for Release configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI.")
endif()
if(NOT Vulkan_${component}_DEBUG_LIBRARY)
message(WARNING
"Library ${component} for Debug configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI. Consider re-installing the Vulkan SDK and request debug libraries to fix this warning.")
endif()
endif()
else()
set(Vulkan_${component}_FOUND FALSE PARENT_SCOPE)
endif()
endfunction()
_Vulkan_set_library_component_found(glslang-spirv NO_WARNING)
_Vulkan_set_library_component_found(glslang-oglcompiler NO_WARNING)
_Vulkan_set_library_component_found(glslang-osdependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-machineindependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-genericcodegen NO_WARNING)
_Vulkan_set_library_component_found(glslang
DEPENDENT_COMPONENTS
glslang-spirv
glslang-oglcompiler
glslang-osdependent
glslang-machineindependent
glslang-genericcodegen)
_Vulkan_set_library_component_found(shaderc_combined)
_Vulkan_set_library_component_found(SPIRV-Tools)
_Vulkan_set_library_component_found(volk)
_Vulkan_set_library_component_found(dxc)
if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY)
set(Vulkan_MoltenVK_FOUND TRUE)
else()
set(Vulkan_MoltenVK_FOUND FALSE)
endif()
set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
# detect version e.g 1.2.189
set(Vulkan_VERSION "")
if(Vulkan_INCLUDE_DIR)
set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h)
if(EXISTS ${VULKAN_CORE_H})
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}")
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine2 REGEX "^#define VK_HEADER_VERSION_COMPLETE ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion2 "${VulkanHeaderVersionLine2}")
list(LENGTH VulkanHeaderVersion2 _len)
# versions >= 1.2.175 have an additional numbers in front of e.g. '0, 1, 2' instead of '1, 2'
if(_len EQUAL 3)
list(REMOVE_AT VulkanHeaderVersion2 0)
endif()
list(APPEND VulkanHeaderVersion2 ${VulkanHeaderVersion})
list(JOIN VulkanHeaderVersion2 "." Vulkan_VERSION)
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
set(Vulkan_MoltenVK_VERSION "")
if(Vulkan_MoltenVK_INCLUDE_DIR)
set(VK_MVK_MOLTENVK_H ${Vulkan_MoltenVK_INCLUDE_DIR}/MoltenVK/vk_mvk_moltenvk.h)
if(EXISTS ${VK_MVK_MOLTENVK_H})
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MAJOR REGEX "^#define MVK_VERSION_MAJOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MAJOR "${_Vulkan_MoltenVK_VERSION_MAJOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MINOR REGEX "^#define MVK_VERSION_MINOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MINOR "${_Vulkan_MoltenVK_VERSION_MINOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_PATCH REGEX "^#define MVK_VERSION_PATCH ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_PATCH "${_Vulkan_MoltenVK_VERSION_PATCH}")
set(Vulkan_MoltenVK_VERSION "${_Vulkan_MoltenVK_VERSION_MAJOR}.${_Vulkan_MoltenVK_VERSION_MINOR}.${_Vulkan_MoltenVK_VERSION_PATCH}")
unset(_Vulkan_MoltenVK_VERSION_MAJOR)
unset(_Vulkan_MoltenVK_VERSION_MINOR)
unset(_Vulkan_MoltenVK_VERSION_PATCH)
endif()
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Vulkan
REQUIRED_VARS
Vulkan_LIBRARY
Vulkan_INCLUDE_DIR
VERSION_VAR
Vulkan_VERSION
HANDLE_COMPONENTS
)
if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
set_target_properties(Vulkan::Vulkan PROPERTIES
IMPORTED_LOCATION "${Vulkan_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
endif()
if(Vulkan_FOUND AND NOT TARGET Vulkan::Headers)
add_library(Vulkan::Headers INTERFACE IMPORTED)
set_target_properties(Vulkan::Headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLC_EXECUTABLE AND NOT TARGET Vulkan::glslc)
add_executable(Vulkan::glslc IMPORTED)
set_property(TARGET Vulkan::glslc PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLC_EXECUTABLE}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLANG_VALIDATOR_EXECUTABLE AND NOT TARGET Vulkan::glslangValidator)
add_executable(Vulkan::glslangValidator IMPORTED)
set_property(TARGET Vulkan::glslangValidator PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}")
endif()
if(Vulkan_FOUND)
if((Vulkan_glslang-spirv_LIBRARY OR Vulkan_glslang-spirv_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-spirv)
add_library(Vulkan::glslang-spirv STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-spirv_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-spirv_LIBRARY}")
endif()
if(Vulkan_glslang-spirv_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-spirv_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-oglcompiler_LIBRARY OR Vulkan_glslang-oglcompiler_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-oglcompiler)
add_library(Vulkan::glslang-oglcompiler STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-oglcompiler_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-oglcompiler_LIBRARY}")
endif()
if(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-oglcompiler_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-osdependent_LIBRARY OR Vulkan_glslang-osdependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-osdependent)
add_library(Vulkan::glslang-osdependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-osdependent_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-osdependent_LIBRARY}")
endif()
if(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-osdependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-machineindependent_LIBRARY OR Vulkan_glslang-machineindependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-machineindependent)
add_library(Vulkan::glslang-machineindependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-machineindependent_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-machineindependent_LIBRARY}")
endif()
if(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-machineindependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-genericcodegen_LIBRARY OR Vulkan_glslang-genericcodegen_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-genericcodegen)
add_library(Vulkan::glslang-genericcodegen STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-genericcodegen_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-genericcodegen_LIBRARY}")
endif()
if(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-genericcodegen_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang_LIBRARY OR Vulkan_glslang_DEBUG_LIBRARY)
AND TARGET Vulkan::glslang-spirv
AND TARGET Vulkan::glslang-oglcompiler
AND TARGET Vulkan::glslang-osdependent
AND TARGET Vulkan::glslang-machineindependent
AND TARGET Vulkan::glslang-genericcodegen
AND NOT TARGET Vulkan::glslang)
add_library(Vulkan::glslang STATIC IMPORTED)
set_property(TARGET Vulkan::glslang
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang_LIBRARY}")
endif()
if(Vulkan_glslang_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang_DEBUG_LIBRARY}")
endif()
target_link_libraries(Vulkan::glslang
INTERFACE
Vulkan::glslang-spirv
Vulkan::glslang-oglcompiler
Vulkan::glslang-osdependent
Vulkan::glslang-machineindependent
Vulkan::glslang-genericcodegen
)
endif()
if((Vulkan_shaderc_combined_LIBRARY OR Vulkan_shaderc_combined_DEBUG_LIBRARY) AND NOT TARGET Vulkan::shaderc_combined)
add_library(Vulkan::shaderc_combined STATIC IMPORTED)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_shaderc_combined_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_shaderc_combined_LIBRARY}")
endif()
if(Vulkan_shaderc_combined_DEBUG_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_shaderc_combined_DEBUG_LIBRARY}")
endif()
if(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(Vulkan::shaderc_combined
INTERFACE
Threads::Threads)
endif()
endif()
if((Vulkan_SPIRV-Tools_LIBRARY OR Vulkan_SPIRV-Tools_DEBUG_LIBRARY) AND NOT TARGET Vulkan::SPIRV-Tools)
add_library(Vulkan::SPIRV-Tools STATIC IMPORTED)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_SPIRV-Tools_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_SPIRV-Tools_LIBRARY}")
endif()
if(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_SPIRV-Tools_DEBUG_LIBRARY}")
endif()
endif()
if(Vulkan_volk_LIBRARY AND NOT TARGET Vulkan::volk)
add_library(Vulkan::volk STATIC IMPORTED)
set_property(TARGET Vulkan::volk
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_volk_LIBRARY}")
if (NOT WIN32)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES dl)
endif()
endif()
if (Vulkan_dxc_LIBRARY AND NOT TARGET Vulkan::dxc_lib)
add_library(Vulkan::dxc_lib STATIC IMPORTED)
set_property(TARGET Vulkan::dxc_lib
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_dxc_LIBRARY}")
endif()
if(Vulkan_dxc_EXECUTABLE AND NOT TARGET Vulkan::dxc_exe)
add_executable(Vulkan::dxc_exe IMPORTED)
set_property(TARGET Vulkan::dxc_exe PROPERTY IMPORTED_LOCATION "${Vulkan_dxc_EXECUTABLE}")
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
if(Vulkan_MoltenVK_LIBRARY AND NOT TARGET Vulkan::MoltenVK)
add_library(Vulkan::MoltenVK SHARED IMPORTED)
set_target_properties(Vulkan::MoltenVK
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_MoltenVK_INCLUDE_DIR}"
IMPORTED_LOCATION "${Vulkan_MoltenVK_LIBRARY}"
)
endif()
endif()
unset(_Vulkan_library_name)
unset(_Vulkan_hint_include_search_paths)
unset(_Vulkan_hint_executable_search_paths)
unset(_Vulkan_hint_library_search_paths)
cmake_policy(POP)

View File

@ -1,426 +0,0 @@
# FindVulkanHpp.cmake
#
# Finds or downloads the Vulkan-Hpp headers and Vulkan Profiles headers
#
# This will define the following variables
#
# VulkanHpp_FOUND
# VulkanHpp_INCLUDE_DIRS
#
# and the following imported targets
#
# VulkanHpp::VulkanHpp
#
# Try to find the package using standard find_path
find_path(VulkanHpp_INCLUDE_DIR
NAMES vulkan/vulkan.hpp
PATHS
${Vulkan_INCLUDE_DIR}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
)
# Also try to find vulkan.cppm
find_path(VulkanHpp_CPPM_DIR
NAMES vulkan/vulkan.cppm
PATHS
${Vulkan_INCLUDE_DIR}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
)
# Try to find vulkan_profiles.hpp
find_path(VulkanProfiles_INCLUDE_DIR
NAMES vulkan/vulkan_profiles.hpp
PATHS
${Vulkan_INCLUDE_DIR}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
)
# Function to extract Vulkan version from vulkan_core.h
function(extract_vulkan_version VULKAN_CORE_H_PATH OUTPUT_VERSION_TAG)
# Extract the version information from vulkan_core.h
file(STRINGS ${VULKAN_CORE_H_PATH} VULKAN_VERSION_MAJOR_LINE REGEX "^#define VK_VERSION_MAJOR")
file(STRINGS ${VULKAN_CORE_H_PATH} VULKAN_VERSION_MINOR_LINE REGEX "^#define VK_VERSION_MINOR")
file(STRINGS ${VULKAN_CORE_H_PATH} VULKAN_HEADER_VERSION_LINE REGEX "^#define VK_HEADER_VERSION")
set(VERSION_TAG "v1.3.275") # Default fallback
if(VULKAN_VERSION_MAJOR_LINE AND VULKAN_VERSION_MINOR_LINE AND VULKAN_HEADER_VERSION_LINE)
string(REGEX REPLACE "^#define VK_VERSION_MAJOR[ \t]+([0-9]+).*$" "\\1" VULKAN_VERSION_MAJOR "${VULKAN_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define VK_VERSION_MINOR[ \t]+([0-9]+).*$" "\\1" VULKAN_VERSION_MINOR "${VULKAN_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define VK_HEADER_VERSION[ \t]+([0-9]+).*$" "\\1" VULKAN_HEADER_VERSION "${VULKAN_HEADER_VERSION_LINE}")
# Construct the version tag
set(VERSION_TAG "v${VULKAN_VERSION_MAJOR}.${VULKAN_VERSION_MINOR}.${VULKAN_HEADER_VERSION}")
else()
# Alternative approach: look for VK_HEADER_VERSION_COMPLETE
file(STRINGS ${VULKAN_CORE_H_PATH} VULKAN_HEADER_VERSION_COMPLETE_LINE REGEX "^#define VK_HEADER_VERSION_COMPLETE")
file(STRINGS ${VULKAN_CORE_H_PATH} VULKAN_HEADER_VERSION_LINE REGEX "^#define VK_HEADER_VERSION")
if(VULKAN_HEADER_VERSION_COMPLETE_LINE AND VULKAN_HEADER_VERSION_LINE)
# Extract the header version
string(REGEX REPLACE "^#define VK_HEADER_VERSION[ \t]+([0-9]+).*$" "\\1" VULKAN_HEADER_VERSION "${VULKAN_HEADER_VERSION_LINE}")
# Check if the complete version line contains the major and minor versions
if(VULKAN_HEADER_VERSION_COMPLETE_LINE MATCHES "VK_MAKE_API_VERSION\\(.*,[ \t]*([0-9]+),[ \t]*([0-9]+),[ \t]*VK_HEADER_VERSION\\)")
set(VULKAN_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(VULKAN_VERSION_MINOR "${CMAKE_MATCH_2}")
set(VERSION_TAG "v${VULKAN_VERSION_MAJOR}.${VULKAN_VERSION_MINOR}.${VULKAN_HEADER_VERSION}")
endif()
endif()
endif()
# Return the version tag
set(${OUTPUT_VERSION_TAG} ${VERSION_TAG} PARENT_SCOPE)
endfunction()
# Determine the Vulkan version to use for Vulkan-Hpp and Vulkan-Profiles
set(VULKAN_VERSION_TAG "v1.3.275") # Default version
# Try to detect the Vulkan version
set(VULKAN_CORE_H "")
# If we're building for Android, try to detect the NDK's Vulkan version
if(DEFINED ANDROID_NDK)
# Find the vulkan_core.h file in the NDK
find_file(VULKAN_CORE_H vulkan_core.h
PATHS
${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/vulkan
${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/vulkan
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/vulkan
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows/sysroot/usr/include/vulkan
NO_DEFAULT_PATH
)
if(VULKAN_CORE_H)
extract_vulkan_version(${VULKAN_CORE_H} VULKAN_VERSION_TAG)
message(STATUS "Detected NDK Vulkan version: ${VULKAN_VERSION_TAG}")
else()
message(STATUS "Could not find vulkan_core.h in NDK, using default version: ${VULKAN_VERSION_TAG}")
endif()
# For desktop builds, try to detect the Vulkan SDK version
elseif(DEFINED ENV{VULKAN_SDK})
# Find the vulkan_core.h file in the Vulkan SDK
find_file(VULKAN_CORE_H vulkan_core.h
PATHS
$ENV{VULKAN_SDK}/include/vulkan
NO_DEFAULT_PATH
)
if(VULKAN_CORE_H)
extract_vulkan_version(${VULKAN_CORE_H} VULKAN_VERSION_TAG)
message(STATUS "Detected Vulkan SDK version: ${VULKAN_VERSION_TAG}")
else()
message(STATUS "Could not find vulkan_core.h in Vulkan SDK, using default version: ${VULKAN_VERSION_TAG}")
endif()
# If Vulkan package was already found, try to use its include directory
elseif(DEFINED Vulkan_INCLUDE_DIR)
# Find the vulkan_core.h file in the Vulkan include directory
find_file(VULKAN_CORE_H vulkan_core.h
PATHS
${Vulkan_INCLUDE_DIR}/vulkan
NO_DEFAULT_PATH
)
if(VULKAN_CORE_H)
extract_vulkan_version(${VULKAN_CORE_H} VULKAN_VERSION_TAG)
message(STATUS "Detected Vulkan version from include directory: ${VULKAN_VERSION_TAG}")
else()
message(STATUS "Could not find vulkan_core.h in Vulkan include directory, using default version: ${VULKAN_VERSION_TAG}")
endif()
else()
# Try to find vulkan_core.h in system paths
find_file(VULKAN_CORE_H vulkan_core.h
PATHS
/usr/include/vulkan
/usr/local/include/vulkan
)
if(VULKAN_CORE_H)
extract_vulkan_version(${VULKAN_CORE_H} VULKAN_VERSION_TAG)
message(STATUS "Detected system Vulkan version: ${VULKAN_VERSION_TAG}")
else()
message(STATUS "Could not find vulkan_core.h in system paths, using default version: ${VULKAN_VERSION_TAG}")
endif()
endif()
# If the include directory wasn't found, use FetchContent to download and build
if(NOT VulkanHpp_INCLUDE_DIR OR NOT VulkanHpp_CPPM_DIR)
# If not found, use FetchContent to download
include(FetchContent)
message(STATUS "Vulkan-Hpp not found, fetching from GitHub with version ${VULKAN_VERSION_TAG}...")
FetchContent_Declare(
VulkanHpp
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Hpp.git
GIT_TAG ${VULKAN_VERSION_TAG} # Use the detected or default version
)
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Make sure FetchContent is available
include(FetchContent)
# Populate the content
FetchContent_GetProperties(VulkanHpp SOURCE_DIR VulkanHpp_SOURCE_DIR)
if(NOT VulkanHpp_POPULATED)
FetchContent_Populate(VulkanHpp)
# Get the source directory after populating
FetchContent_GetProperties(VulkanHpp SOURCE_DIR VulkanHpp_SOURCE_DIR)
endif()
# Set the include directory to the source directory
set(VulkanHpp_INCLUDE_DIR ${VulkanHpp_SOURCE_DIR})
message(STATUS "VulkanHpp_SOURCE_DIR: ${VulkanHpp_SOURCE_DIR}")
message(STATUS "VulkanHpp_INCLUDE_DIR: ${VulkanHpp_INCLUDE_DIR}")
# Check if vulkan.cppm exists in the downloaded repository
if(EXISTS "${VulkanHpp_SOURCE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${VulkanHpp_SOURCE_DIR})
else()
# If vulkan.cppm doesn't exist, we need to create it
set(VulkanHpp_CPPM_DIR ${CMAKE_CURRENT_BINARY_DIR}/VulkanHpp)
file(MAKE_DIRECTORY ${VulkanHpp_CPPM_DIR}/vulkan)
# Create vulkan.cppm file
file(WRITE "${VulkanHpp_CPPM_DIR}/vulkan/vulkan.cppm"
"// Auto-generated vulkan.cppm file
module;
#include <vulkan/vulkan.hpp>
export module vulkan;
export namespace vk {
using namespace VULKAN_HPP_NAMESPACE;
}
")
endif()
endif()
# If the Vulkan Profiles include directory wasn't found, use FetchContent to download
if(NOT VulkanProfiles_INCLUDE_DIR)
# If not found, use FetchContent to download
include(FetchContent)
message(STATUS "Vulkan-Profiles not found, fetching from GitHub main branch...")
FetchContent_Declare(
VulkanProfiles
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Profiles.git
GIT_TAG main # Use main branch instead of a specific tag
)
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Populate the content
FetchContent_GetProperties(VulkanProfiles SOURCE_DIR VulkanProfiles_SOURCE_DIR)
if(NOT VulkanProfiles_POPULATED)
FetchContent_Populate(VulkanProfiles)
# Get the source directory after populating
FetchContent_GetProperties(VulkanProfiles SOURCE_DIR VulkanProfiles_SOURCE_DIR)
endif()
# Create the include directory structure if it doesn't exist
set(VulkanProfiles_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/VulkanProfiles/include)
file(MAKE_DIRECTORY ${VulkanProfiles_INCLUDE_DIR}/vulkan)
# Create a stub vulkan_profiles.hpp file if it doesn't exist
if(NOT EXISTS "${VulkanProfiles_INCLUDE_DIR}/vulkan/vulkan_profiles.hpp")
file(WRITE "${VulkanProfiles_INCLUDE_DIR}/vulkan/vulkan_profiles.hpp"
"// Auto-generated vulkan_profiles.hpp stub file
#pragma once
#include <vulkan/vulkan.hpp>
namespace vp {
// Stub implementation for Vulkan Profiles
struct ProfileDesc {
const char* name;
uint32_t specVersion;
};
inline bool GetProfileSupport(VkPhysicalDevice physicalDevice, const ProfileDesc* pProfile, VkBool32* pSupported) {
*pSupported = VK_TRUE;
return true;
}
}
")
endif()
message(STATUS "VulkanProfiles_SOURCE_DIR: ${VulkanProfiles_SOURCE_DIR}")
message(STATUS "VulkanProfiles_INCLUDE_DIR: ${VulkanProfiles_INCLUDE_DIR}")
endif()
# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(VulkanHpp
REQUIRED_VARS VulkanHpp_INCLUDE_DIR
FAIL_MESSAGE "Could NOT find VulkanHpp. Install it or set VulkanHpp_INCLUDE_DIR to the directory containing vulkan/vulkan.hpp"
)
# Debug output
message(STATUS "VulkanHpp_FOUND: ${VulkanHpp_FOUND}")
message(STATUS "VULKANHPP_FOUND: ${VULKANHPP_FOUND}")
if(VulkanHpp_FOUND)
set(VulkanHpp_INCLUDE_DIRS ${VulkanHpp_INCLUDE_DIR})
# Make sure VulkanHpp_CPPM_DIR is set
if(NOT DEFINED VulkanHpp_CPPM_DIR)
# Check if vulkan.cppm exists in the include directory
if(EXISTS "${VulkanHpp_INCLUDE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${VulkanHpp_INCLUDE_DIR})
message(STATUS "Found vulkan.cppm in VulkanHpp_INCLUDE_DIR: ${VulkanHpp_CPPM_DIR}")
elseif(DEFINED VulkanHpp_SOURCE_DIR AND EXISTS "${VulkanHpp_SOURCE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${VulkanHpp_SOURCE_DIR})
message(STATUS "Found vulkan.cppm in VulkanHpp_SOURCE_DIR: ${VulkanHpp_CPPM_DIR}")
elseif(DEFINED vulkanhpp_SOURCE_DIR AND EXISTS "${vulkanhpp_SOURCE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${vulkanhpp_SOURCE_DIR})
message(STATUS "Found vulkan.cppm in vulkanhpp_SOURCE_DIR: ${VulkanHpp_CPPM_DIR}")
else()
# If vulkan.cppm doesn't exist, we need to create it
set(VulkanHpp_CPPM_DIR ${CMAKE_CURRENT_BINARY_DIR}/VulkanHpp)
file(MAKE_DIRECTORY ${VulkanHpp_CPPM_DIR}/vulkan)
message(STATUS "Creating vulkan.cppm in ${VulkanHpp_CPPM_DIR}")
# Create vulkan.cppm file
file(WRITE "${VulkanHpp_CPPM_DIR}/vulkan/vulkan.cppm"
"// Auto-generated vulkan.cppm file
module;
#include <vulkan/vulkan.hpp>
export module vulkan;
export namespace vk {
using namespace VULKAN_HPP_NAMESPACE;
}
")
endif()
endif()
message(STATUS "Final VulkanHpp_CPPM_DIR: ${VulkanHpp_CPPM_DIR}")
# Add Vulkan Profiles include directory if found
if(VulkanProfiles_INCLUDE_DIR AND EXISTS "${VulkanProfiles_INCLUDE_DIR}/vulkan/vulkan_profiles.hpp")
list(APPEND VulkanHpp_INCLUDE_DIRS ${VulkanProfiles_INCLUDE_DIR})
message(STATUS "Added Vulkan Profiles include directory: ${VulkanProfiles_INCLUDE_DIR}")
endif()
# Create an imported target
if(NOT TARGET VulkanHpp::VulkanHpp)
add_library(VulkanHpp::VulkanHpp INTERFACE IMPORTED)
set_target_properties(VulkanHpp::VulkanHpp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${VulkanHpp_INCLUDE_DIRS}"
)
endif()
elseif(DEFINED VulkanHpp_SOURCE_DIR OR DEFINED vulkanhpp_SOURCE_DIR)
# If find_package_handle_standard_args failed but we have a VulkanHpp source directory from FetchContent
# Create an imported target
if(NOT TARGET VulkanHpp::VulkanHpp)
add_library(VulkanHpp::VulkanHpp INTERFACE IMPORTED)
# Determine the source directory
if(DEFINED VulkanHpp_SOURCE_DIR)
set(_vulkanhpp_source_dir ${VulkanHpp_SOURCE_DIR})
elseif(DEFINED vulkanhpp_SOURCE_DIR)
set(_vulkanhpp_source_dir ${vulkanhpp_SOURCE_DIR})
endif()
message(STATUS "Using fallback VulkanHpp source directory: ${_vulkanhpp_source_dir}")
set_target_properties(VulkanHpp::VulkanHpp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_vulkanhpp_source_dir}"
)
endif()
# Set variables to indicate that VulkanHpp was found
set(VulkanHpp_FOUND TRUE)
set(VULKANHPP_FOUND TRUE)
# Set include directories
if(DEFINED _vulkanhpp_source_dir)
set(VulkanHpp_INCLUDE_DIR ${_vulkanhpp_source_dir})
elseif(DEFINED VulkanHpp_SOURCE_DIR)
set(VulkanHpp_INCLUDE_DIR ${VulkanHpp_SOURCE_DIR})
elseif(DEFINED vulkanhpp_SOURCE_DIR)
set(VulkanHpp_INCLUDE_DIR ${vulkanhpp_SOURCE_DIR})
endif()
set(VulkanHpp_INCLUDE_DIRS ${VulkanHpp_INCLUDE_DIR})
# Add Vulkan Profiles include directory if found
if(VulkanProfiles_INCLUDE_DIR AND EXISTS "${VulkanProfiles_INCLUDE_DIR}/vulkan/vulkan_profiles.hpp")
list(APPEND VulkanHpp_INCLUDE_DIRS ${VulkanProfiles_INCLUDE_DIR})
message(STATUS "Added Vulkan Profiles include directory to fallback: ${VulkanProfiles_INCLUDE_DIR}")
endif()
# Make sure VulkanHpp_CPPM_DIR is set
if(NOT DEFINED VulkanHpp_CPPM_DIR)
# Check if vulkan.cppm exists in the downloaded repository
if(DEFINED VulkanHpp_INCLUDE_DIR AND EXISTS "${VulkanHpp_INCLUDE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${VulkanHpp_INCLUDE_DIR})
message(STATUS "Found vulkan.cppm in VulkanHpp_INCLUDE_DIR: ${VulkanHpp_CPPM_DIR}")
elseif(DEFINED _vulkanhpp_source_dir AND EXISTS "${_vulkanhpp_source_dir}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${_vulkanhpp_source_dir})
message(STATUS "Found vulkan.cppm in _vulkanhpp_source_dir: ${VulkanHpp_CPPM_DIR}")
elseif(DEFINED VulkanHpp_SOURCE_DIR AND EXISTS "${VulkanHpp_SOURCE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${VulkanHpp_SOURCE_DIR})
message(STATUS "Found vulkan.cppm in VulkanHpp_SOURCE_DIR: ${VulkanHpp_CPPM_DIR}")
elseif(DEFINED vulkanhpp_SOURCE_DIR AND EXISTS "${vulkanhpp_SOURCE_DIR}/vulkan/vulkan.cppm")
set(VulkanHpp_CPPM_DIR ${vulkanhpp_SOURCE_DIR})
message(STATUS "Found vulkan.cppm in vulkanhpp_SOURCE_DIR: ${VulkanHpp_CPPM_DIR}")
else()
# If vulkan.cppm doesn't exist, we need to create it
set(VulkanHpp_CPPM_DIR ${CMAKE_CURRENT_BINARY_DIR}/VulkanHpp)
file(MAKE_DIRECTORY ${VulkanHpp_CPPM_DIR}/vulkan)
message(STATUS "Creating vulkan.cppm in ${VulkanHpp_CPPM_DIR}")
# Create vulkan.cppm file
file(WRITE "${VulkanHpp_CPPM_DIR}/vulkan/vulkan.cppm"
"// Auto-generated vulkan.cppm file
module;
#include <vulkan/vulkan.hpp>
export module vulkan;
export namespace vk {
using namespace VULKAN_HPP_NAMESPACE;
}
")
endif()
endif()
message(STATUS "Final VulkanHpp_CPPM_DIR: ${VulkanHpp_CPPM_DIR}")
endif()
mark_as_advanced(VulkanHpp_INCLUDE_DIR VulkanHpp_CPPM_DIR)

View File

@ -1,133 +0,0 @@
# Findglm.cmake
#
# Finds the GLM library
#
# This will define the following variables
#
# glm_FOUND
# glm_INCLUDE_DIRS
#
# and the following imported targets
#
# glm::glm
#
# Try to find the package using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_glm QUIET glm)
endif()
# Find the include directory
find_path(glm_INCLUDE_DIR
NAMES glm/glm.hpp
PATHS
${PC_glm_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES glm
)
# If the include directory wasn't found, use FetchContent to download and build
if(NOT glm_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)
message(STATUS "GLM not found, fetching from GitHub...")
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 0.9.9.8 # Use a specific tag for stability
)
# Define a function to update the CMake minimum required version
function(update_glm_cmake_version)
# Get the source directory
FetchContent_GetProperties(glm SOURCE_DIR glm_SOURCE_DIR)
# Update the minimum required CMake version
file(READ "${glm_SOURCE_DIR}/CMakeLists.txt" GLM_CMAKE_CONTENT)
string(REPLACE "cmake_minimum_required(VERSION 3.2"
"cmake_minimum_required(VERSION 3.5"
GLM_CMAKE_CONTENT "${GLM_CMAKE_CONTENT}")
file(WRITE "${glm_SOURCE_DIR}/CMakeLists.txt" "${GLM_CMAKE_CONTENT}")
endfunction()
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# First, declare and populate the content
FetchContent_GetProperties(glm)
if(NOT glm_POPULATED)
FetchContent_Populate(glm)
# Update the CMake version before making it available
update_glm_cmake_version()
endif()
# Now make it available (this will process the CMakeLists.txt)
FetchContent_MakeAvailable(glm)
# Get the include directory from the target
if(TARGET glm)
get_target_property(glm_INCLUDE_DIR glm INTERFACE_INCLUDE_DIRECTORIES)
if(NOT glm_INCLUDE_DIR)
# If we can't get the include directory from the target, use the source directory
set(glm_INCLUDE_DIR ${glm_SOURCE_DIR})
endif()
else()
# GLM might not create a target, so use the source directory
set(glm_INCLUDE_DIR ${glm_SOURCE_DIR})
endif()
endif()
# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(glm
REQUIRED_VARS glm_INCLUDE_DIR
)
if(glm_FOUND)
set(glm_INCLUDE_DIRS ${glm_INCLUDE_DIR})
# Create an imported target
if(NOT TARGET glm::glm)
add_library(glm::glm INTERFACE IMPORTED)
set_target_properties(glm::glm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${glm_INCLUDE_DIRS}"
)
endif()
elseif(TARGET glm)
# If find_package_handle_standard_args failed but we have a glm target from FetchContent
# Create an alias for the glm target
if(NOT TARGET glm::glm)
add_library(glm::glm ALIAS glm)
endif()
# Set variables to indicate that glm was found
set(glm_FOUND TRUE)
set(GLM_FOUND TRUE)
# Set include directories
get_target_property(glm_INCLUDE_DIR glm INTERFACE_INCLUDE_DIRECTORIES)
if(glm_INCLUDE_DIR)
set(glm_INCLUDE_DIRS ${glm_INCLUDE_DIR})
else()
# If we can't get the include directory from the target, use the source directory
set(glm_INCLUDE_DIR ${glm_SOURCE_DIR})
set(glm_INCLUDE_DIRS ${glm_INCLUDE_DIR})
endif()
endif()
mark_as_advanced(glm_INCLUDE_DIR)

View File

@ -1,154 +0,0 @@
# Findnlohmann_json.cmake
#
# Finds the nlohmann_json library
#
# This will define the following variables
#
# nlohmann_json_FOUND
# nlohmann_json_INCLUDE_DIRS
#
# and the following imported targets
#
# nlohmann_json::nlohmann_json
#
# Try to find the package using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_nlohmann_json QUIET nlohmann_json)
endif()
# Find the include directory
find_path(nlohmann_json_INCLUDE_DIR
NAMES nlohmann/json.hpp json.hpp
PATHS
${PC_nlohmann_json_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES nlohmann json
)
# If the include directory wasn't found, use FetchContent to download and build
if(NOT nlohmann_json_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)
message(STATUS "nlohmann_json not found, fetching from GitHub...")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0 # Use a specific tag for stability
)
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Populate the content but don't configure it yet
FetchContent_GetProperties(nlohmann_json)
if(NOT nlohmann_json_POPULATED)
FetchContent_Populate(nlohmann_json)
if(ANDROID)
# Update the minimum required CMake version before including the CMakeLists.txt
file(READ "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" NLOHMANN_JSON_CMAKE_CONTENT)
string(REPLACE "cmake_minimum_required(VERSION 3.1"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.2"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.3"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.4"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.5"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.6"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.7"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.8"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.9"
"cmake_minimum_required(VERSION 3.10"
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
file(WRITE "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" "${NLOHMANN_JSON_CMAKE_CONTENT}")
endif()
# Now add the subdirectory manually
add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR})
else()
# If already populated, just make it available
FetchContent_MakeAvailable(nlohmann_json)
endif()
# Get the include directory from the target
if(TARGET nlohmann_json)
get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
if(NOT nlohmann_json_INCLUDE_DIR)
# If we can't get the include directory from the target, use the source directory
set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_SOURCE_DIR}/include)
endif()
else()
# nlohmann_json might not create a target, so use the source directory
set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_SOURCE_DIR}/include)
endif()
endif()
# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(nlohmann_json
REQUIRED_VARS nlohmann_json_INCLUDE_DIR
)
if(nlohmann_json_FOUND)
set(nlohmann_json_INCLUDE_DIRS ${nlohmann_json_INCLUDE_DIR})
# Create an imported target
if(NOT TARGET nlohmann_json::nlohmann_json)
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIRS}"
)
endif()
elseif(TARGET nlohmann_json)
# If find_package_handle_standard_args failed but we have a nlohmann_json target from FetchContent
# Create an alias for the nlohmann_json target
if(NOT TARGET nlohmann_json::nlohmann_json)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
endif()
# Set variables to indicate that nlohmann_json was found
set(nlohmann_json_FOUND TRUE)
set(NLOHMANN_JSON_FOUND TRUE)
# Set include directories
get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
if(nlohmann_json_INCLUDE_DIR)
set(nlohmann_json_INCLUDE_DIRS ${nlohmann_json_INCLUDE_DIR})
else()
# If we can't get the include directory from the target, use the source directory
set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_SOURCE_DIR}/include)
set(nlohmann_json_INCLUDE_DIRS ${nlohmann_json_INCLUDE_DIR})
endif()
endif()
mark_as_advanced(nlohmann_json_INCLUDE_DIR)

View File

@ -1,86 +0,0 @@
# Findstb.cmake
#
# Finds the stb library (specifically stb_image.h)
#
# This will define the following variables
#
# stb_FOUND
# stb_INCLUDE_DIRS
#
# and the following imported targets
#
# stb::stb
#
# Try to find the package using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_stb QUIET stb)
endif()
# Find the include directory
find_path(stb_INCLUDE_DIR
NAMES stb_image.h
PATHS
${PC_stb_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES stb
)
# If the include directory wasn't found, use FetchContent to download and build
if(NOT stb_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)
message(STATUS "stb_image.h not found, fetching from GitHub...")
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb.git
GIT_TAG master # stb doesn't use version tags, so we use master
)
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Populate the content
FetchContent_GetProperties(stb)
if(NOT stb_POPULATED)
FetchContent_Populate(stb)
endif()
# stb is a header-only library with no CMakeLists.txt, so we just need to set the include directory
set(stb_INCLUDE_DIR ${stb_SOURCE_DIR})
endif()
# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(stb
REQUIRED_VARS stb_INCLUDE_DIR
)
if(stb_FOUND)
set(stb_INCLUDE_DIRS ${stb_INCLUDE_DIR})
# Create an imported target
if(NOT TARGET stb::stb)
add_library(stb::stb INTERFACE IMPORTED)
set_target_properties(stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${stb_INCLUDE_DIRS}"
)
endif()
endif()
mark_as_advanced(stb_INCLUDE_DIR)

View File

@ -1,162 +0,0 @@
# Findtinygltf.cmake
#
# Finds the tinygltf library
#
# This will define the following variables
#
# tinygltf_FOUND
# tinygltf_INCLUDE_DIRS
#
# and the following imported targets
#
# tinygltf::tinygltf
#
# First, try to find nlohmann_json
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
include(FetchContent)
message(STATUS "nlohmann_json not found, fetching v3.12.0 from GitHub...")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0 # Use a specific tag for stability
)
FetchContent_MakeAvailable(nlohmann_json)
endif()
# Try to find tinygltf using standard find_package
find_path(tinygltf_INCLUDE_DIR
NAMES tiny_gltf.h
PATHS
${PC_tinygltf_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES tinygltf include
)
# If not found, use FetchContent to download and build
if(NOT tinygltf_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)
message(STATUS "tinygltf not found, fetching from GitHub...")
FetchContent_Declare(
tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.8.18 # Use a specific tag for stability
)
# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Populate the content but don't configure it yet
FetchContent_GetProperties(tinygltf)
if(NOT tinygltf_POPULATED)
FetchContent_Populate(tinygltf)
# Update the minimum required CMake version to avoid deprecation warning
file(READ "${tinygltf_SOURCE_DIR}/CMakeLists.txt" TINYGLTF_CMAKE_CONTENT)
string(REPLACE "cmake_minimum_required(VERSION 3.6)"
"cmake_minimum_required(VERSION 3.10)"
TINYGLTF_CMAKE_CONTENT "${TINYGLTF_CMAKE_CONTENT}")
file(WRITE "${tinygltf_SOURCE_DIR}/CMakeLists.txt" "${TINYGLTF_CMAKE_CONTENT}")
# Create a symbolic link to make nlohmann/json.hpp available
if(EXISTS "${tinygltf_SOURCE_DIR}/json.hpp")
file(MAKE_DIRECTORY "${tinygltf_SOURCE_DIR}/nlohmann")
file(CREATE_LINK "${tinygltf_SOURCE_DIR}/json.hpp" "${tinygltf_SOURCE_DIR}/nlohmann/json.hpp" SYMBOLIC)
endif()
# Set tinygltf to header-only mode
set(TINYGLTF_HEADER_ONLY ON CACHE BOOL "Use header only version" FORCE)
set(TINYGLTF_INSTALL OFF CACHE BOOL "Do not install tinygltf" FORCE)
# Add the subdirectory after modifying the CMakeLists.txt
add_subdirectory(${tinygltf_SOURCE_DIR} ${tinygltf_BINARY_DIR})
else()
# If already populated, just make it available
FetchContent_MakeAvailable(tinygltf)
endif()
# Get the include directory from the target
get_target_property(tinygltf_INCLUDE_DIR tinygltf INTERFACE_INCLUDE_DIRECTORIES)
if(NOT tinygltf_INCLUDE_DIR)
# If we can't get the include directory from the target, use the source directory
FetchContent_GetProperties(tinygltf SOURCE_DIR tinygltf_SOURCE_DIR)
set(tinygltf_INCLUDE_DIR ${tinygltf_SOURCE_DIR})
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(tinygltf
REQUIRED_VARS tinygltf_INCLUDE_DIR
)
if(tinygltf_FOUND)
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})
if(NOT TARGET tinygltf::tinygltf)
add_library(tinygltf::tinygltf INTERFACE IMPORTED)
set_target_properties(tinygltf::tinygltf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinygltf_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "TINYGLTF_IMPLEMENTATION;TINYGLTF_NO_EXTERNAL_IMAGE;TINYGLTF_NO_STB_IMAGE;TINYGLTF_NO_STB_IMAGE_WRITE"
)
if(TARGET nlohmann_json::nlohmann_json)
target_link_libraries(tinygltf::tinygltf INTERFACE nlohmann_json::nlohmann_json)
endif()
endif()
elseif(TARGET tinygltf)
# If find_package_handle_standard_args failed but we have a tinygltf target from FetchContent
# Create an alias for the tinygltf target
if(NOT TARGET tinygltf::tinygltf)
add_library(tinygltf_wrapper INTERFACE)
target_link_libraries(tinygltf_wrapper INTERFACE tinygltf)
target_compile_definitions(tinygltf_wrapper INTERFACE
TINYGLTF_IMPLEMENTATION
TINYGLTF_NO_EXTERNAL_IMAGE
TINYGLTF_NO_STB_IMAGE
TINYGLTF_NO_STB_IMAGE_WRITE
)
if(TARGET nlohmann_json::nlohmann_json)
target_link_libraries(tinygltf_wrapper INTERFACE nlohmann_json::nlohmann_json)
endif()
add_library(tinygltf::tinygltf ALIAS tinygltf_wrapper)
endif()
# Set variables to indicate that tinygltf was found
set(tinygltf_FOUND TRUE)
set(TINYGLTF_FOUND TRUE)
# Set include directories
get_target_property(tinygltf_INCLUDE_DIR tinygltf INTERFACE_INCLUDE_DIRECTORIES)
if(tinygltf_INCLUDE_DIR)
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})
else()
# If we can't get the include directory from the target, use the source directory
FetchContent_GetProperties(tinygltf SOURCE_DIR tinygltf_SOURCE_DIR)
set(tinygltf_INCLUDE_DIR ${tinygltf_SOURCE_DIR})
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})
# Explicitly set the include directory on the target
if(TARGET tinygltf)
set_target_properties(tinygltf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinygltf_INCLUDE_DIR}"
)
endif()
endif()
endif()
mark_as_advanced(tinygltf_INCLUDE_DIR)

View File

@ -1,160 +0,0 @@
# Findtinyobjloader.cmake
# Find the tinyobjloader library
#
# This module defines the following variables:
# tinyobjloader_FOUND - True if tinyobjloader was found
# tinyobjloader_INCLUDE_DIRS - Include directories for tinyobjloader
# tinyobjloader_LIBRARIES - Libraries to link against tinyobjloader
#
# It also defines the following targets:
# tinyobjloader::tinyobjloader
# Try to find the package using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_tinyobjloader QUIET tinyobjloader)
endif()
# Find the include directory
find_path(tinyobjloader_INCLUDE_DIR
NAMES tiny_obj_loader.h
PATHS
${PC_tinyobjloader_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES tinyobjloader tiny_obj_loader
)
# Find the library
find_library(tinyobjloader_LIBRARY
NAMES tinyobjloader
PATHS
${PC_tinyobjloader_LIBRARY_DIRS}
/usr/lib
/usr/local/lib
$ENV{VULKAN_SDK}/lib
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/lib
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../lib
PATH_SUFFIXES lib
)
# If the include directory wasn't found, use FetchContent to download and build
if(NOT tinyobjloader_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)
message(STATUS "tinyobjloader not found, fetching from GitHub...")
FetchContent_Declare(
tinyobjloader
GIT_REPOSITORY https://github.com/tinyobjloader/tinyobjloader.git
GIT_TAG v2.0.0rc10 # Use a specific tag for stability
)
# Set options before making tinyobjloader available
set(TINYOBJLOADER_BUILD_TEST_LOADER OFF CACHE BOOL "Do not build test loader" FORCE)
set(TINYOBJLOADER_BUILD_OBJ_STICHER OFF CACHE BOOL "Do not build obj sticher" FORCE)
set(TINYOBJLOADER_INSTALL OFF CACHE BOOL "Do not install tinyobjloader" FORCE)
# Update CMake policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# Populate the content but don't configure it yet
FetchContent_GetProperties(tinyobjloader)
if(NOT tinyobjloader_POPULATED)
FetchContent_Populate(tinyobjloader)
# Update the minimum required CMake version before including the CMakeLists.txt
file(READ "${tinyobjloader_SOURCE_DIR}/CMakeLists.txt" TINYOBJLOADER_CMAKE_CONTENT)
string(REPLACE "cmake_minimum_required(VERSION 3.2)"
"cmake_minimum_required(VERSION 3.10)"
TINYOBJLOADER_CMAKE_CONTENT "${TINYOBJLOADER_CMAKE_CONTENT}")
string(REPLACE "cmake_minimum_required(VERSION 3.5)"
"cmake_minimum_required(VERSION 3.10)"
TINYOBJLOADER_CMAKE_CONTENT "${TINYOBJLOADER_CMAKE_CONTENT}")
file(WRITE "${tinyobjloader_SOURCE_DIR}/CMakeLists.txt" "${TINYOBJLOADER_CMAKE_CONTENT}")
# Now add the subdirectory manually
add_subdirectory(${tinyobjloader_SOURCE_DIR} ${tinyobjloader_BINARY_DIR})
else()
# If already populated, just make it available
FetchContent_MakeAvailable(tinyobjloader)
endif()
# Get the include directory from the target
get_target_property(tinyobjloader_INCLUDE_DIR tinyobjloader INTERFACE_INCLUDE_DIRECTORIES)
if(NOT tinyobjloader_INCLUDE_DIR)
# If we can't get the include directory from the target, use the source directory
set(tinyobjloader_INCLUDE_DIR ${tinyobjloader_SOURCE_DIR})
endif()
endif()
# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(tinyobjloader
REQUIRED_VARS tinyobjloader_INCLUDE_DIR
)
if(tinyobjloader_FOUND)
set(tinyobjloader_INCLUDE_DIRS ${tinyobjloader_INCLUDE_DIR})
if(tinyobjloader_LIBRARY)
set(tinyobjloader_LIBRARIES ${tinyobjloader_LIBRARY})
else()
# tinyobjloader is a header-only library, so no library is needed
set(tinyobjloader_LIBRARIES "")
endif()
# Create an imported target
if(NOT TARGET tinyobjloader::tinyobjloader)
add_library(tinyobjloader::tinyobjloader INTERFACE IMPORTED)
set_target_properties(tinyobjloader::tinyobjloader PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinyobjloader_INCLUDE_DIRS}"
)
if(tinyobjloader_LIBRARIES)
set_target_properties(tinyobjloader::tinyobjloader PROPERTIES
INTERFACE_LINK_LIBRARIES "${tinyobjloader_LIBRARIES}"
)
endif()
endif()
elseif(TARGET tinyobjloader)
# If find_package_handle_standard_args failed but we have a tinyobjloader target from FetchContent
# Create an alias for the tinyobjloader target
if(NOT TARGET tinyobjloader::tinyobjloader)
add_library(tinyobjloader::tinyobjloader ALIAS tinyobjloader)
endif()
# Set variables to indicate that tinyobjloader was found
set(tinyobjloader_FOUND TRUE)
set(TINYOBJLOADER_FOUND TRUE)
# Set include directories
get_target_property(tinyobjloader_INCLUDE_DIR tinyobjloader INTERFACE_INCLUDE_DIRECTORIES)
if(tinyobjloader_INCLUDE_DIR)
set(tinyobjloader_INCLUDE_DIRS ${tinyobjloader_INCLUDE_DIR})
else()
# If we can't get the include directory from the target, use the source directory
set(tinyobjloader_INCLUDE_DIR ${tinyobjloader_SOURCE_DIR})
set(tinyobjloader_INCLUDE_DIRS ${tinyobjloader_INCLUDE_DIR})
endif()
endif()
mark_as_advanced(tinyobjloader_INCLUDE_DIR tinyobjloader_LIBRARY)

View File

@ -1,233 +1,209 @@
cmake_minimum_required (VERSION 3.29)
project (VulkanTutorial)
project(VulkanEngine)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
# Add option to enable/disable C++ 20 module
option(ENABLE_CPP20_MODULE "Enable C++ 20 module support for Vulkan" OFF)
include(BuildInfo)
include(FetchContent)
#LTO
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_ERROR)
# Enable C++ module dependency scanning only if C++ 20 module is enabled
if(ENABLE_CPP20_MODULE)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
find_program(GCC_AR NAMES gcc-ar REQUIRED)
find_program(GCC_RANLIB NAMES gcc-ranlib REQUIRED)
set(CMAKE_AR "${GCC_AR}")
set(CMAKE_RANLIB "${GCC_RANLIB}")
endif()
find_package (glfw3 REQUIRED)
find_package (glm REQUIRED)
find_package (Vulkan 1.4.335 REQUIRED) # Require Vulkan SDK version 1.4.335 or higher
find_package (tinyobjloader REQUIRED)
find_package (tinygltf REQUIRED)
find_package (nlohmann_json REQUIRED)
find_library(KTX_LIBRARY NAMES ktx REQUIRED)
find_path(KTX_INCLUDE_DIR NAMES ktx.h REQUIRED)
message(STATUS "KTX library found at: ${KTX_LIBRARY}")
message(STATUS "KTX include dir: ${KTX_INCLUDE_DIR}")
add_library(KTX::ktx SHARED IMPORTED GLOBAL)
set_target_properties(KTX::ktx PROPERTIES
IMPORTED_LOCATION "${KTX_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${KTX_INCLUDE_DIR}"
)
# set up Vulkan C++ module only if enabled
if(ENABLE_CPP20_MODULE)
add_library(VulkanCppModule)
add_library(Vulkan::cppm ALIAS VulkanCppModule)
target_compile_definitions(VulkanCppModule
PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
)
target_include_directories(VulkanCppModule
PUBLIC
"${Vulkan_INCLUDE_DIR}"
)
target_link_libraries(VulkanCppModule
PUBLIC
Vulkan::Vulkan
)
set_target_properties(VulkanCppModule PROPERTIES CXX_STANDARD 20)
# Add MSVC-specific compiler options for proper C++ module support
if(MSVC)
target_compile_options(VulkanCppModule PRIVATE
/std:c++latest # Use latest C++ standard for better module support
/permissive- # Standards conformance mode
/Zc:__cplusplus # Enable correct __cplusplus macro
/EHsc # Enable C++ exception handling
/Zc:preprocessor # Use conforming preprocessor
/translateInclude # Automatically translate #include to import for standard library
)
endif()
target_sources(VulkanCppModule
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES
BASE_DIRS
"${Vulkan_INCLUDE_DIR}"
FILES
"${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm"
)
# Add the vulkan.cppm file directly as a source file
target_sources(VulkanCppModule
PRIVATE
"${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm"
)
else()
# Create a dummy interface library when C++ 20 module is disabled
add_library(VulkanCppModule INTERFACE)
add_library(Vulkan::cppm ALIAS VulkanCppModule)
target_link_libraries(VulkanCppModule INTERFACE Vulkan::Vulkan)
target_compile_definitions(VulkanCppModule
INTERFACE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
)
endif()
find_package(stb REQUIRED)
set(STB_INCLUDEDIR ${stb_INCLUDE_DIRS})
# Find all package dependencies
find_package( glfw3 REQUIRED )
find_package( glm REQUIRED )
find_package( VulkanMemoryAllocator CONFIG REQUIRED )
find_package( fmt REQUIRED )
# Shader compilers
add_executable (glslang::validator IMPORTED)
find_program (GLSLANG_VALIDATOR "glslangValidator" HINTS $ENV{VULKAN_SDK}/bin REQUIRED)
set_property (TARGET glslang::validator PROPERTY IMPORTED_LOCATION "${GLSLANG_VALIDATOR}")
find_program(SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK}/bin REQUIRED)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_ERROR)
# fastgltf because it's not in nixpkgs
if(LTO_SUPPORTED AND CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "LTO activated")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "LTO not supported : ${LTO_ERROR}")
endif()
FetchContent_Declare(
fastgltf
GIT_REPOSITORY https://github.com/spnda/fastgltf.git
GIT_TAG v0.8.0
)
FetchContent_MakeAvailable(fastgltf)
function (add_shaders_target TARGET)
cmake_parse_arguments ("SHADER" "" "CHAPTER_NAME" "SOURCES" ${ARGN})
set (SHADERS_DIR ${SHADER_CHAPTER_NAME}/shaders)
add_custom_command (
OUTPUT ${SHADERS_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DIR}
)
add_custom_command (
OUTPUT ${SHADERS_DIR}/frag.spv ${SHADERS_DIR}/vert.spv
# vk-bootstrap because CMAKE can't find it on NixOS
FetchContent_Declare(
vk-bootstrap
GIT_REPOSITORY https://github.com/charles-lunarg/vk-bootstrap.git
GIT_TAG v1.3.295
)
FetchContent_MakeAvailable(vk-bootstrap)
# Helper functions to build shaders
function(addGlslShader SOURCE OUTPUT_DIR)
get_filename_component(SHADER_NAME ${SOURCE} NAME_WE)
set(SPV_FILE "${OUTPUT_DIR}/${SHADER_NAME}.spv")
add_custom_command(
OUTPUT ${SPV_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}
COMMAND glslang::validator
ARGS --target-env vulkan1.0 ${SHADER_SOURCES} --quiet
WORKING_DIRECTORY ${SHADERS_DIR}
DEPENDS ${SHADERS_DIR} ${SHADER_SOURCES}
COMMENT "Compiling Shaders"
-V
--target-env vulkan1.3 # Change if needed
-o ${SPV_FILE}
${SOURCE}
DEPENDS ${SOURCE}
COMMENT "Compiling GLSL shader: ${SOURCE} -> ${SPV_FILE}"
VERBATIM
)
add_custom_target (${TARGET} DEPENDS ${SHADERS_DIR}/frag.spv ${SHADERS_DIR}/vert.spv)
endfunction ()
function (add_slang_shader_target TARGET)
cmake_parse_arguments ("SHADER" "" "CHAPTER_NAME" "SOURCES" ${ARGN})
set (SHADERS_DIR ${SHADER_CHAPTER_NAME}/shaders)
#file(GLOB HAS_COMPUTE ${CHAPTER_SHADER}.comp)
set (ENTRY_POINTS -entry vertMain -entry fragMain)
if(HAS_COMPUTE)
list(APPEND ENTRY_POINTS -entry compMain)
endif()
add_custom_command (
OUTPUT ${SHADERS_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DIR}
)
add_custom_command (
OUTPUT ${SHADERS_DIR}/slang.spv
COMMAND ${SLANGC_EXECUTABLE} ${SHADER_SOURCES} -target spirv -profile spirv_1_4+spvRayQueryKHR -emit-spirv-directly -fvk-use-entrypoint-name ${ENTRY_POINTS} -o slang.spv
WORKING_DIRECTORY ${SHADERS_DIR}
DEPENDS ${SHADERS_DIR} ${SHADER_SOURCES}
COMMENT "Compiling Slang Shaders"
VERBATIM
)
add_custom_target (${TARGET} DEPENDS ${SHADERS_DIR}/slang.spv)
set(SPV_FILE ${SPV_FILE} PARENT_SCOPE)
endfunction()
function (add_chapter CHAPTER_NAME)
cmake_parse_arguments (CHAPTER "" "SHADER" "LIBS;TEXTURES;MODELS" ${ARGN})
add_executable (${CHAPTER_NAME} src/${CHAPTER_NAME}.cpp)
set_target_properties (${CHAPTER_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CHAPTER_NAME})
set_target_properties (${CHAPTER_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries (${CHAPTER_NAME} Vulkan::cppm glfw)
target_include_directories (${CHAPTER_NAME} PRIVATE ${STB_INCLUDEDIR})
# Add compile definition if C++ 20 module is enabled
if(ENABLE_CPP20_MODULE)
target_compile_definitions(${CHAPTER_NAME} PRIVATE USE_CPP20_MODULES=1)
function(addSlangShader SOURCES ENTRY_POINTS OUTPUT_DIR)
set(SPV_FILE "${OUTPUT_DIR}/slang.spv")
add_custom_command(
OUTPUT ${SPV_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}
COMMAND ${SLANGC_EXECUTABLE}
${SOURCES}
-target spirv
-profile spirv_1_4+spvRayQueryKHR # Change if needed
-emit-spirv-directly
-fvk-use-entrypoint-name
${ENTRY_POINTS}
-o ${SPV_FILE}
DEPENDS ${SOURCES}
COMMENT "Compiling Slang shaders -> ${SPV_FILE}"
VERBATIM
)
set(SPV_FILE ${SPV_FILE} PARENT_SCOPE)
endfunction()
# A function to automate executables aditions
function ( addBinary BINARY_NAME )
cmake_parse_arguments ( BINARY "IMGUI" "SOURCE" "SHADERS;SLANG_SHADERS;LIBS;TEXTURES;MODELS" ${ARGN} )
if (DEFINED BINARY_SOURCE)
add_executable ( ${BINARY_NAME} src/${BINARY_SOURCE}.cpp )
endif()
target_include_directories( ${BINARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src )
# Sets the output dir to have clear separation between binaries
set_target_properties ( ${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BINARY_NAME} )
set_target_properties ( ${BINARY_NAME} PROPERTIES CXX_STANDARD 20 ) # Uses C++20
# Sets per binary LTO
if(LTO_SUPPORTED AND CMAKE_BUILD_TYPE STREQUAL "Release")
set_target_properties(${BINARY_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
message("Enabled LTO")
endif()
set_target_properties(${BINARY_NAME} PROPERTIES CXX_SCAN_FOR_MODULES OFF)
# Define VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS to treat VK_ERROR_OUT_OF_DATE_KHR as a success code
target_compile_definitions(${CHAPTER_NAME} PRIVATE "VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS" )
target_compile_definitions (
${BINARY_NAME}
PRIVATE
"VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS"
$<$<CONFIG:Debug>:DEBUG> # So CMAKE expose a #define DEBUG for debug builds
# Exposes versions
BUILD_ID="${ENGINE_VERSION}"
)
if(BINARY_IMGUI)
target_include_directories(${BINARY_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/src/imgui
${CMAKE_SOURCE_DIR}/src/imgui/backends
)
target_sources(${BINARY_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/src/imgui/imgui.cpp
if(WIN32)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set_target_properties(${CHAPTER_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${CHAPTER_NAME}")
endif()
${CMAKE_SOURCE_DIR}/src/imgui/imgui_draw.cpp
${CMAKE_SOURCE_DIR}/src/imgui/imgui_tables.cpp
${CMAKE_SOURCE_DIR}/src/imgui/imgui_widgets.cpp
${CMAKE_SOURCE_DIR}/src/imgui/imgui_demo.cpp
${CMAKE_SOURCE_DIR}/src/imgui/backends/imgui_impl_glfw.cpp
${CMAKE_SOURCE_DIR}/src/imgui/backends/imgui_impl_vulkan.cpp
)
endif()
if (DEFINED CHAPTER_SHADER)
set (CHAPTER_SHADER_TARGET ${CHAPTER_NAME}_shader)
file (GLOB SHADER_SOURCES ${CHAPTER_SHADER}.frag ${CHAPTER_SHADER}.vert ${CHAPTER_SHADER}.comp)
if (SHADER_SOURCES)
add_shaders_target (${CHAPTER_SHADER_TARGET} CHAPTER_NAME ${CHAPTER_NAME} SOURCES ${SHADER_SOURCES})
add_dependencies (${CHAPTER_NAME} ${CHAPTER_SHADER_TARGET})
endif()
if(DEFINED BINARY_SHADERS)
set(SHADER_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${BINARY_NAME}/shaders)
set(ALL_SPV_FILES "")
foreach(SHADER_SRC ${BINARY_SHADERS})
if(NOT IS_ABSOLUTE ${SHADER_SRC})
set(SHADER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER_SRC})
endif()
addGlslShader(${SHADER_SRC} ${SHADER_OUTPUT_DIR})
list(APPEND ALL_SPV_FILES ${SPV_FILE})
endforeach()
set (CHAPTER_SHADER_SLANG_TARGET ${CHAPTER_NAME}_slang_shader)
file (GLOB SHADER_SLANG_SOURCES ${CHAPTER_SHADER}.slang)
if(SHADER_SLANG_SOURCES)
add_slang_shader_target( ${CHAPTER_SHADER_SLANG_TARGET} CHAPTER_NAME ${CHAPTER_NAME} SOURCES ${SHADER_SLANG_SOURCES})
add_dependencies(${CHAPTER_NAME} ${CHAPTER_SHADER_SLANG_TARGET})
add_custom_target(shaders_${BINARY_NAME} DEPENDS ${ALL_SPV_FILES})
add_dependencies(${BINARY_NAME} shaders_${BINARY_NAME})
endif()
if(DEFINED BINARY_SLANG_SHADERS)
set(SLANG_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${BINARY_NAME}/shaders)
if(NOT DEFINED BINARY_SLANG_ENTRIES)
message(FATAL_ERROR "addBinary: SLANG_SHADERS nécessite SLANG_ENTRIES")
endif()
endif ()
if (DEFINED CHAPTER_LIBS)
target_link_libraries (${CHAPTER_NAME} ${CHAPTER_LIBS})
endif ()
if (DEFINED CHAPTER_MODELS)
addSlangShader("${BINARY_SLANG_SHADERS}" "${BINARY_SLANG_ENTRIES}" ${SLANG_OUTPUT_DIR})
add_custom_target(slang_shaders_${BINARY_NAME} DEPENDS ${SPV_FILE})
add_dependencies(${BINARY_NAME} slang_shaders_${BINARY_NAME})
endif()
if (DEFINED BINARY_LIBS)
target_link_libraries ( ${BINARY_NAME} ${BINARY_LIBS} )
endif()
if (DEFINED BINARY_MODELS) # Adds the 3D models in the binary folder
set(RESOLVED_MODELS "")
foreach(MODEL_PATTERN ${CHAPTER_MODELS})
foreach(MODEL_PATTERN ${BINARY_MODELS})
file(GLOB MATCHED_MODELS CONFIGURE_DEPENDS
"${CMAKE_SOURCE_DIR}/models/${MODEL_PATTERN}"
"${CMAKE_SOURCE_DIR}/assets/models/${MODEL_PATTERN}"
)
list(APPEND RESOLVED_MODELS ${MATCHED_MODELS})
endforeach()
if (RESOLVED_MODELS)
file(COPY ${RESOLVED_MODELS} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/models)
file(COPY ${RESOLVED_MODELS} DESTINATION ${CMAKE_BINARY_DIR}/${BINARY_NAME}/models)
endif()
endif()
endif ()
if (DEFINED CHAPTER_TEXTURES)
if (DEFINED BINARY_TEXTURES) # Adds the textures in the binary folder
set(RESOLVED_TEXTURES "")
foreach(TEX_PATTERN ${CHAPTER_TEXTURES})
foreach(TEX_PATTERN ${BINARY_TEXTURES})
file(GLOB MATCHED_TEXTURES CONFIGURE_DEPENDS
"${CMAKE_SOURCE_DIR}/textures/${TEX_PATTERN}"
"${CMAKE_SOURCE_DIR}/assets/textures/${TEX_PATTERN}"
)
list(APPEND RESOLVED_TEXTURES ${MATCHED_TEXTURES})
endforeach()
if (RESOLVED_TEXTURES)
file(COPY ${RESOLVED_TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/textures)
file(COPY ${RESOLVED_TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/${BINARY_NAME}/textures)
endif()
endif ()
endfunction ()
endfunction()
add_chapter (main
SHADER shaders/main
TEXTURES *
MODELS *
LIBS nlohmann_json::nlohmann_json KTX::ktx
# Adds the main binary
addBinary (
engine
SOURCE Engine/main
SHADERS shaders/gradient.comp
LIBS glfw fmt vk-bootstrap vulkan
IMGUI
)
#add_chapter (38_ray_tracing
# SHADER 38_ray_tracing
# MODELS plant_on_table.obj
# MODELS plant_on_table.mtl
# TEXTURES plant_on_table_textures/nettle_plant_diff_4k.png
# TEXTURES plant_on_table_textures/potted_plant_02_pot_diff_1k.png
# TEXTURES plant_on_table_textures/wooden_picnic_table_bottom_diff_1k.png
# TEXTURES plant_on_table_textures/wooden_picnic_table_top_diff_1k.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
addBinary (
server
SOURCE Server/main
)

65
CMakePresets.json Normal file
View File

@ -0,0 +1,65 @@
{
"version": 6,
"cmakeMinimumRequired": { "major": 3 },
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/bin/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "debug",
"displayName": "Debug",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS_DEBUG": "-g"
}
},
{
"name": "debug-san",
"displayName": "Debug + Sanitizers",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS_DEBUG": "-g -fsanitize=address,undefined"
}
},
{
"name": "release",
"displayName": "Release",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS_RELEASE": "-O3 -march=native -flto"
}
},
{
"name": "release-fast",
"displayName": "Release (Ofast, non-conformant)",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS_RELEASE": "-Ofast -march=native -flto"
}
}
],
"buildPresets": [
{
"name": "debug",
"displayName": "Build Debug",
"configurePreset": "debug"
},
{
"name": "release",
"displayName": "Build Release",
"configurePreset": "release"
}
]
}

View File

@ -1,4 +1,7 @@
# Vulkan
A simple Vulkan tutorial.
Might expending it later into a game or engine.
A simple Vulkan tutorial.
Might expending it later into a game or engine.
Based from [vkguide](https://vkguide.dev/)
This has a very different philosophy than the main [Khronos Vulkan Tutorial](https://docs.vulkan.org/tutorial/latest/00_Introduction.html)

View File

@ -1 +0,0 @@
slangc shaders/main.slang -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name -entry vertMain -entry fragMain -o shaders/slang.spv

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

22
shaders/gradient.comp Normal file
View File

@ -0,0 +1,22 @@
// GLSL version
#version 460
layout ( local_size_x = 16, local_size_y = 16 ) in;
layout ( rgba16f, set = 0, binding = 0 ) uniform image2D image;
void main() {
ivec2 texelCoord = ivec2( gl_GlobalInvocationID.xy );
ivec2 size = imageSize( image );
if ( texelCoord.x < size.x && texelCoord.y < size.y ) {
vec4 color = vec4( 0.0, 0.0, 0.0, 1.0 );
if ( gl_LocalInvocationID.x != 0 && gl_LocalInvocationID.y != 0 ) {
color.x = float(texelCoord.x)/(size.x);
color.y = float(texelCoord.y)/(size.y);
}
imageStore(image, texelCoord, color);
}
}

View File

@ -1,34 +0,0 @@
struct VSInput {
float3 inPosition;
float3 inColor;
float2 inTexCoord;
};
struct UniformBuffer {
float4x4 model;
float4x4 view;
float4x4 proj;
};
ConstantBuffer<UniformBuffer> ubo;
struct VSOutput {
float4 pos : SV_Position;
float3 fragColor;
float2 fragTexCoord;
};
[shader("vertex")]
VSOutput vertMain(VSInput input) {
VSOutput output;
output.pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(input.inPosition, 1.0))));
output.fragColor = input.inColor;
output.fragTexCoord = input.inTexCoord;
return output;
}
Sampler2D texture;
[shader("fragment")]
float4 fragMain(VSOutput vertIn) : SV_Target {
return texture.Sample(vertIn.fragTexCoord);
}

View File

@ -1,30 +0,0 @@
static float2 positions[3] = float2[](
float2(0.0, -0.5),
float2(0.5, 0.5),
float2(-0.5, 0.5)
);
static float3 colors[3] = float3[] (
float3(1.0, 0.0, 0.0),
float3(0.0, 1.0, 0.0),
float3(0.0, 0.0, 1.0)
);
struct VertexOutput {
float3 color;
float4 sv_position : SV_Position;
};
[shader("vertex")]
VertexOutput vertMain(uint vid : SV_VertexID) {
VertexOutput output;
output.sv_position = float4(positions[vid], 0.0, 1.0);
output.color = colors[vid];
return output;
}
[shader("fragment")]
float4 fragMain(VertexOutput inVert) : SV_Target {
float3 color = inVert.color;
return float4(color, 1.0);
}

Binary file not shown.

40
src/Common/Logger.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef LOGGER_H
#define LOGGER_H
// Custom includes
class NetLogger {
public:
struct Server{
int priority;
char* url[]; // Put the url at the end for bit optimization
};
void initNetLogger(Server server);
void logNet(char* body[], char* head, Server server);
void logNetAsync(); // Todo
private:
};
#endif // End of header
#ifdef LOGGER_IMPL
#ifndef LOGGER_IMPL_H
#define LOGGER_IMPL_H
// Implementation
// Includes
#include <httplib.h> // Todo : add it in the flake
void NetLogger::initNetLogger(Server server) {
httplib::Client cli(server.url)
// Todo : add error handling
}
#endif
#endif

41
src/Common/Timer.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef TIMER_H
#define TIMER_H
// Custom includes
#include <chrono>
class RunTimer {
public:
void startTimer();
int endTimer();
private:
// Aliases
using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<Clock>;
TimePoint startTime;
TimePoint endTime;
};
#endif // End of header
#ifdef TIMER_IMPL
#ifndef TIMER_IMPL_H
#define TIMER_IMPL_H
// Implementation
void RunTimer::startTimer(){
startTime = Clock::now();
}
int RunTimer::endTimer() {
endTime = Clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime);
return elapsed.count();
}
#endif
#endif

87
src/Common/Types.h Normal file
View File

@ -0,0 +1,87 @@
#ifndef TYPES_H
#define TYPES_H
// Normal header
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <span>
#include <array>
#include <functional>
#include <deque>
#include <chrono>
#include <thread>
#include <fmt/base.h>
#include <stdexcept>
#include <cstdint>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
#include <vulkan/vk_enum_string_helper.h>
#include <vk_mem_alloc.h>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <glm/mat4x4.hpp>
#include <glm/vec4.hpp>
// Custom headers
//#include "callbacks.h"
#include "Timer.h"
#include "Logger.h"
// Custom macro
#define VK_CHECK(x) \
do { \
VkResult err = x; \
if (err) { \
fmt::println("[Engine:Error] Vulkan error : {}", string_VkResult(err)); \
abort(); \
} \
} while (0) \
// Custom types
struct DeletionQueue {
std::deque<std::function<void()>> deletors;
void pushFunction(
std::function<void()>&& function
) {
deletors.push_back(function);
}
void flush() {
// Reverse iterate the deletion queue to destroy in order
for (
auto it = deletors.rbegin();
it != deletors.rend();
it++
) {
(*it)();
}
deletors.clear();
}
};
struct AllocatedImage {
VkImage image;
VkImageView imageView;
VmaAllocation allocation;
VkExtent3D imageExtent;
VkFormat imageFormat;
};
#endif
#ifdef TYPES_IMPL
#ifndef TYPES_IMPL_H
#define TYPES_IMPL_H
// Implementation
#endif
#endif

View File

@ -0,0 +1,25 @@
#ifndef CALLBACK_H
#define CALLBACK_H
// Header
// Other includes
#include "Common/Types.h"
class Callback {
public:
static void keyboardCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
};
#endif
#ifdef CALLBACK_IMPL
#ifndef CALLBACK_IMPL_H
#define CALLBACK_IMPL_H
void Callback::keyboardCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
#ifdef DEBUG
fmt::println("Key pressed, key {}", key);
#endif
}
#endif
#endif

View File

@ -0,0 +1,232 @@
#ifndef DESCRIPTORS_H
#define DESCRIPTORS_H
// Header
// Other includes
#include "Common/Types.h"
#include <cstdint>
#include <fmt/base.h>
#include <span>
#include <vulkan/vulkan_core.h>
struct DescriptorLayoutBuilder {
std::vector<VkDescriptorSetLayoutBinding> bindings;
void addBinding(
uint32_t binding,
VkDescriptorType type
);
void clear();
VkDescriptorSetLayout build (
VkDevice device,
VkShaderStageFlags shaderStages,
void* pNext = nullptr,
VkDescriptorSetLayoutCreateFlags flags = 0
);
};
struct DescriptorAllocator {
struct PoolSizeRatio {
VkDescriptorType type;
float ratio;
};
VkDescriptorPool pool;
void initPool(
VkDevice device,
uint32_t maxSets,
std::span<PoolSizeRatio> poolRatios
);
void clearDescriptors(
VkDevice device
);
void destroyPool(
VkDevice device
);
VkDescriptorSet allocate(
VkDevice device,
VkDescriptorSetLayout layout
);
};
#endif
#ifdef DESCRIPTORS_IMPL
#ifndef DESCRIPTORS_IMPL_H
#define DESCRIPTORS_IMPL_H
// The actual implementation
void DescriptorLayoutBuilder::addBinding(
uint32_t binding,
VkDescriptorType type
){
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Adding a descriptor set binding...");
#endif
VkDescriptorSetLayoutBinding newBind {
.binding = binding,
.descriptorType = type,
.descriptorCount = 1
};
bindings.push_back(newBind);
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Descriptor set binding added !");
#endif
}
void DescriptorLayoutBuilder::clear() {
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Clearing a descriptor set...");
#endif
bindings.clear();
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Descriptor set cleared !");
#endif
}
VkDescriptorSetLayout DescriptorLayoutBuilder::build (
VkDevice device,
VkShaderStageFlags shaderStages,
void* pNext,
VkDescriptorSetLayoutCreateFlags flags
) {
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Building a descriptor set...");
#endif
for (auto& b : bindings) {
b.stageFlags |= shaderStages;
}
VkDescriptorSetLayoutCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = pNext,
.flags = flags,
.bindingCount = (uint32_t)bindings.size(),
.pBindings = bindings.data(),
};
VkDescriptorSetLayout set;
VK_CHECK(
vkCreateDescriptorSetLayout(
device,
&info,
nullptr,
&set
)
);
#ifdef DEBUG
fmt::println("[DescriptorLayoutBuilder] Descriptor set built !");
#endif
return set;
}
void DescriptorAllocator::initPool(
VkDevice device,
uint32_t maxSets,
std::span<PoolSizeRatio> poolRatios
) {
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Initializing a new pool..");
#endif
std::vector<VkDescriptorPoolSize> poolSizes;
for (PoolSizeRatio ratio : poolRatios) {
poolSizes.push_back(VkDescriptorPoolSize {
.type = ratio.type,
.descriptorCount = uint32_t(ratio.ratio * maxSets)
});
}
VkDescriptorPoolCreateInfo poolInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.flags = 0,
.maxSets = maxSets,
.poolSizeCount = (uint32_t)poolSizes.size(),
.pPoolSizes = poolSizes.data()
};
vkCreateDescriptorPool(
device,
&poolInfo,
nullptr,
&pool
);
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Descriptor pool initialized...");
#endif
}
void DescriptorAllocator::clearDescriptors(
VkDevice device
) {
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Clearing a descriptor set...");
#endif
vkResetDescriptorPool(
device,
pool,
0
);
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Descriptor set cleared !");
#endif
}
void DescriptorAllocator::destroyPool(
VkDevice device
) {
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Destroying a descriptor pool...");
#endif
vkDestroyDescriptorPool(
device,
pool,
nullptr
);
#ifdef DEBUG
fmt::println("[DescriptorAllocator] Descriptor pool destroyed !");
#endif
}
VkDescriptorSet DescriptorAllocator::allocate(
VkDevice device,
VkDescriptorSetLayout layout
){
VkDescriptorSetAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = nullptr,
.descriptorPool = pool,
.descriptorSetCount = 1,
.pSetLayouts = &layout
};
VkDescriptorSet ds;
VK_CHECK(
vkAllocateDescriptorSets(
device,
&allocInfo,
&ds
)
);
return ds;
}
#endif
#endif

1151
src/Engine/engine/engine.h Normal file

File diff suppressed because it is too large Load Diff

127
src/Engine/engine/images.h Normal file
View File

@ -0,0 +1,127 @@
#ifndef IMAGES_H
#define IMAGES_H
// Normal header
#include "Common/Types.h"
namespace vkutil {
void transitionImage(
VkCommandBuffer cmd,
VkImage image,
VkImageLayout currentLayout,
VkImageLayout newLayout
);
void copyImageToImage(
VkCommandBuffer cmd,
VkImage source,
VkImage destination,
VkExtent2D srcSize,
VkExtent2D dstSize
);
}
#endif
#ifdef IMAGES_IMPL
#ifndef IMAGES_IMPL_H
#define IMAGES_IMPL_H
// Implementation
#include "initializers.h"
namespace vkutil {
void transitionImage(
VkCommandBuffer cmd,
VkImage image,
VkImageLayout currentLayout,
VkImageLayout newLayout
) {
VkImageMemoryBarrier2 imageBarrier {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
.pNext = nullptr,
.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
.dstAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT,
.oldLayout = currentLayout,
.newLayout = newLayout
};
VkImageAspectFlags aspectMask = (newLayout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
imageBarrier.subresourceRange = vkinit::imageSubresourceRange(aspectMask);
imageBarrier.image = image;
VkDependencyInfo depInfo {
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
.pNext = nullptr,
.imageMemoryBarrierCount = 1,
.pImageMemoryBarriers = &imageBarrier
};
vkCmdPipelineBarrier2(cmd, &depInfo);
}
void copyImageToImage(
VkCommandBuffer cmd,
VkImage source,
VkImage destination,
VkExtent2D srcSize,
VkExtent2D dstSize
) {
VkImageBlit2 blitRegion {
.sType = VK_STRUCTURE_TYPE_IMAGE_BLIT_2,
.pNext = nullptr,
.srcSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.srcOffsets = {
VkOffset3D { 0, 0, 0 },
VkOffset3D {
(int32_t)srcSize.width,
(int32_t)srcSize.height,
1
}
},
.dstSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1
},
.dstOffsets = {
VkOffset3D { 0, 0, 0 },
VkOffset3D {
(int32_t)dstSize.width,
(int32_t)dstSize.height,
1
}
},
};
VkBlitImageInfo2 blitInfo = {
.sType = VK_STRUCTURE_TYPE_BLIT_IMAGE_INFO_2,
.pNext = nullptr,
.srcImage = source,
.srcImageLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
.dstImage = destination,
.dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.regionCount = 1,
.pRegions = &blitRegion,
.filter = VK_FILTER_LINEAR,
};
vkCmdBlitImage2(cmd, &blitInfo);
}
}
#endif
#endif

View File

@ -0,0 +1,308 @@
#ifndef INITIALIZERS_H
#define INITIALIZERS_H
// Normal header
#include "Common/Types.h"
#include <vulkan/vulkan_core.h>
namespace vkinit {
VkCommandPoolCreateInfo commandPoolCreateInfo(
uint32_t queueFamilyIndex,
VkCommandPoolCreateFlags flags = 0
);
VkCommandBufferAllocateInfo commandBufferAllocateInfo(
VkCommandPool pool,
uint32_t count
);
VkFenceCreateInfo fenceCreateInfo(
VkFenceCreateFlags flags = 0
);
VkSemaphoreCreateInfo semaphoreCreateInfo (
VkSemaphoreCreateFlags flags = 0
);
VkCommandBufferBeginInfo commandBufferBeginInfo (
VkCommandBufferUsageFlags flags = 0
);
VkImageSubresourceRange imageSubresourceRange(
VkImageAspectFlags aspectMask
);
VkSemaphoreSubmitInfo semaphoreSubmitInfo(
VkPipelineStageFlags2 stageMask,
VkSemaphore semaphore
);
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
VkCommandBuffer cmd
);
VkSubmitInfo2 submitInfo(
VkCommandBufferSubmitInfo* cmd,
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
VkSemaphoreSubmitInfo* waitSemaphoreInfo
);
VkImageCreateInfo imageCreateInfo(
VkFormat format,
VkImageUsageFlags usageFlags,
VkExtent3D extent
);
VkImageViewCreateInfo imageViewCreateInfo(
VkFormat format,
VkImage image,
VkImageAspectFlags aspectFlags
);
VkRenderingAttachmentInfo attachmentInfo(
VkImageView view,
VkClearValue* clear,
VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/
);
VkRenderingInfo renderingInfo(
VkExtent2D renderExtent,
VkRenderingAttachmentInfo* colorAttachment,
VkRenderingAttachmentInfo* depthAttachment
);
}
#endif
#ifdef INITIALIZERS_IMPL
#ifndef INITIALIZERS_IMPL_H
#define INITIALIZERS_IMPL_H
// Implementation
namespace vkinit {
VkCommandPoolCreateInfo commandPoolCreateInfo(
uint32_t queueFamilyIndex,
VkCommandPoolCreateFlags flags
) {
VkCommandPoolCreateInfo info {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = flags,
.queueFamilyIndex = queueFamilyIndex
};
return info;
}
VkCommandBufferAllocateInfo commandBufferAllocateInfo(
VkCommandPool pool,
uint32_t count
) {
VkCommandBufferAllocateInfo info {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = nullptr,
.commandPool = pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = count
};
return info;
}
VkFenceCreateInfo fenceCreateInfo(
VkFenceCreateFlags flags /*= 0 */
) {
VkFenceCreateInfo info {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = nullptr,
.flags = flags
};
return info;
}
VkSemaphoreCreateInfo semaphoreCreateInfo (
VkSemaphoreCreateFlags flags /*= 0*/
) {
VkSemaphoreCreateInfo info {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
.pNext = nullptr,
.flags = flags,
};
return info;
}
VkCommandBufferBeginInfo commandBufferBeginInfo (
VkCommandBufferUsageFlags flags /*= 0*/
) {
VkCommandBufferBeginInfo info {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = flags,
.pInheritanceInfo = nullptr
};
return info;
}
VkImageSubresourceRange imageSubresourceRange(
VkImageAspectFlags aspectMask
) {
VkImageSubresourceRange subImage {
.aspectMask = aspectMask,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
};
return subImage;
}
VkSemaphoreSubmitInfo semaphoreSubmitInfo(
VkPipelineStageFlags2 stageMask,
VkSemaphore semaphore
) {
VkSemaphoreSubmitInfo submitInfo {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
.pNext = nullptr,
.semaphore = semaphore,
.value = 1,
.stageMask = stageMask,
.deviceIndex = 0
};
return submitInfo;
}
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
VkCommandBuffer cmd
) {
VkCommandBufferSubmitInfo info {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
.pNext = nullptr,
.commandBuffer = cmd,
.deviceMask = 0
};
return info;
}
VkSubmitInfo2 submitInfo(
VkCommandBufferSubmitInfo* cmd,
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
VkSemaphoreSubmitInfo* waitSemaphoreInfo
) {
VkSubmitInfo2 info {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
.pNext = nullptr,
.waitSemaphoreInfoCount = static_cast<uint32_t>(waitSemaphoreInfo == nullptr ? 0 : 1),
.pWaitSemaphoreInfos = waitSemaphoreInfo,
.commandBufferInfoCount = 1,
.pCommandBufferInfos = cmd,
.signalSemaphoreInfoCount = static_cast<uint32_t>(signalSemaphoreInfo == nullptr ? 0 : 1),
.pSignalSemaphoreInfos = signalSemaphoreInfo
};
return info;
}
VkImageCreateInfo imageCreateInfo(
VkFormat format,
VkImageUsageFlags usageFlags,
VkExtent3D extent
) {
VkImageCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = nullptr,
.imageType = VK_IMAGE_TYPE_2D,
.format = format,
.extent = extent,
.mipLevels = 1,
.arrayLayers = 1,
//for MSAA. I won't be using it, so only 1 sample per pixel
.samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = usageFlags
};
return info;
}
VkImageViewCreateInfo imageViewCreateInfo(
VkFormat format,
VkImage image,
VkImageAspectFlags aspectFlags
) {
VkImageViewCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = nullptr,
.image = image,
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = format,
.subresourceRange = {
.aspectMask = aspectFlags,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
}
};
return info;
}
VkRenderingAttachmentInfo attachmentInfo(
VkImageView view,
VkClearValue* clear,
VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/
) {
VkRenderingAttachmentInfo colorAttachment {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.pNext = nullptr,
.imageView = view,
.imageLayout = layout,
.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE
};
if (clear) {
colorAttachment.clearValue = *clear;
}
return colorAttachment;
}
VkRenderingInfo renderingInfo(
VkExtent2D renderExtent,
VkRenderingAttachmentInfo* colorAttachment,
VkRenderingAttachmentInfo* depthAttachment
) {
VkRenderingInfo renderInfo {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.pNext = nullptr,
.renderArea = VkRect2D {
VkOffset2D {
0,
0
}, renderExtent
},
.layerCount = 1,
.colorAttachmentCount = 1,
.pColorAttachments = colorAttachment,
.pDepthAttachment = depthAttachment,
.pStencilAttachment = nullptr
};
return renderInfo;
}
}
#endif
#endif

View File

@ -0,0 +1,96 @@
#ifndef PIPELINES_H
#define PIPELINES_H
// Normal header
#include "Common/Types.h"
#include <cstddef>
#include <cstdint>
#include <fmt/base.h>
#include <vector>
#include <vulkan/vulkan_core.h>
namespace vkutil {
bool loadShaderModule(
const char* filePath,
VkDevice device,
VkShaderModule* outShaderModule
);
};
#endif
#ifdef PIPELINES_IMPL
#ifndef PIPELINES_IMPL_H
#define PIPELINES_IMPL_H
// Implementation
// Imports
#include <fstream>
// Custom imports
#include "initializers.h"
namespace vkutil {
bool loadShaderModule(
const char* filePath,
VkDevice device,
VkShaderModule* outShaderModule
) {
#ifdef DEBUG
fmt::println("[Engine:Utils] Loading shader located at {}...", filePath);
#endif
// Open the file, with the cursor at the end
std::ifstream file(
filePath,
std::ios::ate | std::ios::binary
);
if (!file.is_open()) {
return false;
}
// Find the size of the file by looking
// at the cursor
size_t fileSize = (size_t)file.tellg();
// Allocate a big enough vector to suit SPIR-V
std::vector<uint32_t> buffer(fileSize/ sizeof(uint32_t));
file.seekg(0); // Put the cursor at the begining
// Load the file in the buffer
file.read((char*)buffer.data(), fileSize);
file.close();
// Create the shader module
VkShaderModuleCreateInfo createInfo {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.pNext = nullptr,
.codeSize = buffer.size() * sizeof(uint32_t), // Convert to bytes
.pCode = buffer.data()
};
// Check that everything went well
VkShaderModule shaderModule;
if (vkCreateShaderModule(
device,
&createInfo,
nullptr,
&shaderModule
) != VK_SUCCESS){
return false;
}
*outShaderModule = shaderModule;
#ifdef DEBUG
fmt::println("[Engine:Utils] Shader loaded from {} and size {}", filePath, fileSize);
#endif
return true;
}
};
#endif
#endif

15
src/Engine/main.cpp Normal file
View File

@ -0,0 +1,15 @@
#define ENGINE_IMPL
#include "engine/engine.h"
int main(int argc, char* argv[]) {
Engine engine;
engine.init();
engine.run();
engine.cleanup();
return 0;
}

10
src/Server/main.cpp Normal file
View File

@ -0,0 +1,10 @@
#define SERVER_IMPL
#include "server/server.h"
int main() {
GameServer mainServer;
mainServer.init();
return 0;
}

43
src/Server/server/init.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef SERVER_INIT_H
#define SERVER_INIT_H
// Normal header
class GameServerInit {
// This class groups all the code required for
// the server to initialize and start being
// usable
public:
bool init(); // Uses a bool to mark if init was sucessfull
void cleanup();
private:
};
#endif
#ifdef SERVER_INIT_IMPL
#ifndef SERVER_INIT_IMPL_H
#define SERVER_INIT_IMPL_H
// Implementation
#include "Common/Types.h"
bool GameServerInit::init() {
// Create the logger server object,
// to send messages
// Try to compile but I don't think it'll work in the current state
NetLogger::Server logServer {
.priority = 1,
.url = "https://ntfy.alexdelcamp.fr"
// clangd gives an error, fix it using the corrext type ig
// Todo : read the server from a file and fallback to my own
};
NetLogger::initNetLogger(logServer);
// Add error detection (no connectivity for exemple)
return true; // Everything went correctly
}
#endif
#endif

View File

@ -0,0 +1,28 @@
#ifndef SERVER_H
#define SERVER_H
// Normal header
class GameServer {
public:
void init(); // Wrapper to the init function in the init class
void cleanup(); // Wrapper to the cleanup function in the init class
private:
};
#endif
#ifdef SERVER_IMPL
#ifndef SERVER_IMPL_H
#define SERVER_IMPL_H
// Implementation
#include "init.h"
void GameServer::init(){
//GameServerInit::init();
}
#endif
#endif

1
src/imgui Submodule

@ -0,0 +1 @@
Subproject commit 5220a3f48d39c000da8b46fb0fccf3dd62695c51

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 940 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB