From 77084729d80718be3e4f35fcbce47f56caab44e1 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 10:00:21 -0500 Subject: [PATCH 01/18] CONGE-1 - Setup that works with conan and cmake --- .gitignore | 1 + CMakeLists.txt | 30 ++++++++++++++----- ConjureEngine/CMakeLists.txt | 23 ++++---------- .../src/ConjureEngine/ConjureEngine.h | 4 +++ Demo1/CMakeLists.txt | 13 +------- Demo1/conanfile.txt | 8 ----- ConjureEngine/conanfile.txt => conanfile.txt | 0 debug.sh | 8 +++++ release.sh | 8 +++++ 9 files changed, 51 insertions(+), 44 deletions(-) delete mode 100644 Demo1/conanfile.txt rename ConjureEngine/conanfile.txt => conanfile.txt (100%) create mode 100755 debug.sh create mode 100755 release.sh diff --git a/.gitignore b/.gitignore index 8d7f31d..d5e139a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ CMakeCache.txt build.ninja cmake_install.cmake CMakeCache.txt +CMakeUserPresets.json .ninja* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index eec78fb..7c209cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,35 @@ cmake_minimum_required(VERSION 3.29) project(ConjureEngineProject) +set(CMAKE_CXX_STANDARD 20) + # Set the default build type to Debug if not specified by the user if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type (default Debug)" FORCE) endif() -set(CONAN_DEPENDENCIES_DIR ${CMAKE_BINARY_DIR}/Conan) +# Set architecture +if(NOT DEFINED ARCH) + set(ARCH x64) # Default to x64 architecture +endif() -execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR}/ConjureEngine --output-folder=${CONAN_DEPENDENCIES_DIR} --build=missing) -execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR}/Demo1 --output-folder=${CONAN_DEPENDENCIES_DIR} --build=missing) +set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) -set(CMAKE_TOOLCHAIN_FILE "${CONAN_DEPENDENCIES_DIR}/build/Release/generators/conan_toolchain.cmake" CACHE FILEPATH "Conan toolchain file") -set(CMAKE_PREFIX_PATH "${CONAN_DEPENDENCIES_DIR}/build/Release/generators" ${CMAKE_PREFIX_PATH}) -set(CMAKE_MODULE_PATH "${CONAN_DEPENDENCIES_DIR}/build/Release/generators" ${CMAKE_MODULE_PATH}) +# Include the Conan-generated files +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") +include("${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") + + +# Set common output directories +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/intermediates/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) + +# Locate packages using find_package +find_package(glm REQUIRED) +find_package(SDL2 REQUIRED) + +# Add subdirectories for engine and demo add_subdirectory(./ConjureEngine) -add_subdirectory(./Demo1) \ No newline at end of file +add_subdirectory(./Demo1) diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index 909c6f8..b5b42f6 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -1,27 +1,16 @@ cmake_minimum_required(VERSION 3.29) project(ConjureEngine) -set(CMAKE_CXX_STANDARD 17) - -# Set the architecture (assuming you're passing the architecture as a CMake variable) -# Replace 'x64' with your system's architecture, or set this dynamically based on the system -if(NOT DEFINED ARCH) - set(ARCH x64) # You can change this to x86 or any other architecture you are targeting -endif() - - - -# Set common output directories -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/intermediates/${ARCH}/${PROJECT_NAME}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${ARCH}/${PROJECT_NAME}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${ARCH}/${PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 20) find_package(glm REQUIRED) +find_package(SDL2 REQUIRED) find_package(Vulkan REQUIRED) add_library(${PROJECT_NAME} STATIC src/ConjureEngine/ConjureEngine.h src/ConjureEngine/ConjureEngine.cpp) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) - # Specify include directories -target_include_directories(ConjureEngine PUBLIC include) \ No newline at end of file +target_include_directories(${PROJECT_NAME} PUBLIC include) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include) + +target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm) \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/ConjureEngine.h b/ConjureEngine/src/ConjureEngine/ConjureEngine.h index b2a96c2..a076112 100644 --- a/ConjureEngine/src/ConjureEngine/ConjureEngine.h +++ b/ConjureEngine/src/ConjureEngine/ConjureEngine.h @@ -1,4 +1,8 @@ #pragma once + +#include "glm/glm.hpp" + namespace ConjureEngine { void SayHello(); + glm::vec3& Forward(); } diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index 0eec459..a2c2abc 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -1,18 +1,7 @@ cmake_minimum_required(VERSION 3.29) project(Demo1) -set(CMAKE_CXX_STANDARD 17) - -# Set the architecture (assuming you're passing the architecture as a CMake variable) -# Replace 'x64' with your system's architecture, or set this dynamically based on the system -if(NOT DEFINED ARCH) - set(ARCH x64) # You can change this to x86 or any other architecture you are targeting -endif() - -# Set common output directories -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/intermediates/${ARCH}/${PROJECT_NAME}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${ARCH}/${PROJECT_NAME}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${ARCH}/${PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME} src/main.cpp) diff --git a/Demo1/conanfile.txt b/Demo1/conanfile.txt deleted file mode 100644 index bc6f23d..0000000 --- a/Demo1/conanfile.txt +++ /dev/null @@ -1,8 +0,0 @@ -[requires] - -[generators] -CMakeDeps -CMakeToolchain - -[layout] -cmake_layout \ No newline at end of file diff --git a/ConjureEngine/conanfile.txt b/conanfile.txt similarity index 100% rename from ConjureEngine/conanfile.txt rename to conanfile.txt diff --git a/debug.sh b/debug.sh new file mode 100755 index 0000000..4fb253f --- /dev/null +++ b/debug.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Run Conan to install dependencies +conan install . -s build_type=Debug --build=missing + +# Run CMake with the updated CMAKE_PREFIX_PATH +#cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build +#cmake --build build diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..dbada7d --- /dev/null +++ b/release.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Run Conan to install dependencies +conan install . -s build_type=Release --build=missing + +# Run CMake with the updated CMAKE_PREFIX_PATH +#cmake -DCMAKE_BUILD_TYPE=Release -S . -B build +#cmake --build build From 6ffd75fb04d5c259faa083943f55a87ea2dd29eb Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 10:11:03 -0500 Subject: [PATCH 02/18] CONGE-1 - added support for bat files and README.md --- README.md | 27 +++++++++++++++++++++++++++ debug.bat | 2 ++ release.bat | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 README.md create mode 100755 debug.bat create mode 100755 release.bat diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b5cee8 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Conjure Engine +## Installation +### Dependancies +To install this project, it is required that you install the folowind dependancies +on you computer: +- Vulkan SDK: https://vulkan.lunarg.com/sdk/home +- Conan 2: https://docs.conan.io/2/installation.html + +### Platforms supported +- Mac 14+ +- Windows 10+ +- Linux 6+ + +Those are wide guideline and any version recent enough of your OS should work +as long it supports vulkan and conan. + +### Debug +1. Execute `./debug.sh` (LINUX/MAC) or `.\debug.bat` (WINDOWS) +2. Load CMakeUserPresets.json that was created during step 1 +3. You should be able to build the different subprojects +4. The binaries are available in bin/ + +### Release +1. Execute `./release.sh` (LINUX/MAC) or `.\release.bat` (WINDOWS) +2. Load CMakeUserPresets.json that was created during step 1 +3. You should be able to build the different subprojects +4. The binaries are available in bin/ \ No newline at end of file diff --git a/debug.bat b/debug.bat new file mode 100755 index 0000000..0988e26 --- /dev/null +++ b/debug.bat @@ -0,0 +1,2 @@ +@Run Conan to install dependencies +conan install . -s build_type=Debug --build=missing diff --git a/release.bat b/release.bat new file mode 100755 index 0000000..13ca3dc --- /dev/null +++ b/release.bat @@ -0,0 +1,2 @@ +@ Run Conan to install dependencies +conan install . -s build_type=Release --build=missing From af2d1c06830a637304f5f8147c7ef21ea63389f2 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 15:32:56 -0500 Subject: [PATCH 03/18] CONGE-1 Made it work for windows and mac for both release and debug --- CMakeLists.txt | 6 ++---- Configure.bat | 8 ++++++++ Configure.sh | 10 ++++++++++ README.md | 16 ++++++---------- debug.bat | 2 -- debug.sh | 8 -------- release.bat | 2 -- release.sh | 8 -------- 8 files changed, 26 insertions(+), 34 deletions(-) create mode 100644 Configure.bat create mode 100644 Configure.sh delete mode 100755 debug.bat delete mode 100755 debug.sh delete mode 100755 release.bat delete mode 100755 release.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c209cb..5464007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type (default Debug)" FORCE) endif() +message(${CMAKE_BUILD_TYPE}) + # Set architecture if(NOT DEFINED ARCH) set(ARCH x64) # Default to x64 architecture @@ -26,10 +28,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/intermediates/${CMAKE_BUI set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) -# Locate packages using find_package -find_package(glm REQUIRED) -find_package(SDL2 REQUIRED) - # Add subdirectories for engine and demo add_subdirectory(./ConjureEngine) add_subdirectory(./Demo1) diff --git a/Configure.bat b/Configure.bat new file mode 100644 index 0000000..1106840 --- /dev/null +++ b/Configure.bat @@ -0,0 +1,8 @@ +@REM Run Conan to install dependencies +rmdir build /s /q + +@REM DEBUG +conan install . -c tools.cmake.cmaketoolchain:generator=Msbuild -s build_type=Debug --build=missing + +@REM RELEASE +conan install . -c tools.cmake.cmaketoolchain:generator=Msbuild -s build_type=Release --build=missing diff --git a/Configure.sh b/Configure.sh new file mode 100644 index 0000000..180db67 --- /dev/null +++ b/Configure.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Run Conan to install dependencies +rm -Rf build + +# DEBUG +conan install . -s build_type=Debug --build=missing + +# RELEASE +conan install . -s build_type=Release --build=missing diff --git a/README.md b/README.md index 2b5cee8..6fd018e 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,10 @@ on you computer: Those are wide guideline and any version recent enough of your OS should work as long it supports vulkan and conan. -### Debug -1. Execute `./debug.sh` (LINUX/MAC) or `.\debug.bat` (WINDOWS) -2. Load CMakeUserPresets.json that was created during step 1 -3. You should be able to build the different subprojects -4. The binaries are available in bin/ +### Installation step -### Release -1. Execute `./release.sh` (LINUX/MAC) or `.\release.bat` (WINDOWS) -2. Load CMakeUserPresets.json that was created during step 1 -3. You should be able to build the different subprojects -4. The binaries are available in bin/ \ No newline at end of file +#### Configure your IDE +1. Execute `./Configure.sh` (LINUX/MAC) or `.\Configure.bat` (WINDOWS). This step installs all the dependencies for both release and debug. +2. Load the generated CMakeUserPresets.json that was generated at step 1. +3. Select an executable project (like Demo1) +4. Build \ No newline at end of file diff --git a/debug.bat b/debug.bat deleted file mode 100755 index 0988e26..0000000 --- a/debug.bat +++ /dev/null @@ -1,2 +0,0 @@ -@Run Conan to install dependencies -conan install . -s build_type=Debug --build=missing diff --git a/debug.sh b/debug.sh deleted file mode 100755 index 4fb253f..0000000 --- a/debug.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# Run Conan to install dependencies -conan install . -s build_type=Debug --build=missing - -# Run CMake with the updated CMAKE_PREFIX_PATH -#cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build -#cmake --build build diff --git a/release.bat b/release.bat deleted file mode 100755 index 13ca3dc..0000000 --- a/release.bat +++ /dev/null @@ -1,2 +0,0 @@ -@ Run Conan to install dependencies -conan install . -s build_type=Release --build=missing diff --git a/release.sh b/release.sh deleted file mode 100755 index dbada7d..0000000 --- a/release.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# Run Conan to install dependencies -conan install . -s build_type=Release --build=missing - -# Run CMake with the updated CMAKE_PREFIX_PATH -#cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -#cmake --build build From 9766eb80cfc23c22231f34894722ea3c928a12ea Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 16:13:11 -0500 Subject: [PATCH 04/18] CONGE-1 Fixed some issues to make it cross compatible with clion, vscode and vs studio --- .gitignore | 3 ++- CMakeLists.txt | 6 +++--- Configure.bat | 6 ++++-- ConjureEngine/CMakeLists.txt | 7 +++++-- Demo1/CMakeLists.txt | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d5e139a..e946c61 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ build.ninja cmake_install.cmake CMakeCache.txt CMakeUserPresets.json -.ninja* \ No newline at end of file +.ninja* +.vs/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5464007..2507bb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.29) +cmake_minimum_required(VERSION 3.26) project(ConjureEngineProject) set(CMAKE_CXX_STANDARD 20) @@ -18,9 +18,9 @@ endif() set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) # Include the Conan-generated files -list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") -include("${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") +include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") # Set common output directories diff --git a/Configure.bat b/Configure.bat index 1106840..b35b3d4 100644 --- a/Configure.bat +++ b/Configure.bat @@ -1,8 +1,10 @@ @REM Run Conan to install dependencies rmdir build /s /q +mkdir build + @REM DEBUG -conan install . -c tools.cmake.cmaketoolchain:generator=Msbuild -s build_type=Debug --build=missing +conan install . -s build_type=Debug --build=missing @REM RELEASE -conan install . -c tools.cmake.cmaketoolchain:generator=Msbuild -s build_type=Release --build=missing +conan install . -s build_type=Release --build=missing diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index b5b42f6..100cb66 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -1,8 +1,11 @@ -cmake_minimum_required(VERSION 3.29) -project(ConjureEngine) +cmake_minimum_required(VERSION 3.26) + set(CMAKE_CXX_STANDARD 20) +project(ConjureEngine) + + find_package(glm REQUIRED) find_package(SDL2 REQUIRED) find_package(Vulkan REQUIRED) diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index a2c2abc..f1b17b4 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.29) +cmake_minimum_required(VERSION 3.26) project(Demo1) set(CMAKE_CXX_STANDARD 20) From 16364abcde449f4168e23f58fe09d8901b078bd6 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 16:18:15 -0500 Subject: [PATCH 05/18] CONGE-1 This work in mac --- CMakeLists.txt | 4 ++-- Configure.bat | 6 ++---- Configure.sh | 0 3 files changed, 4 insertions(+), 6 deletions(-) mode change 100644 => 100755 Configure.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2507bb6..6bc9f3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,9 @@ endif() set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) # Include the Conan-generated files -list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") -include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") +include("${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") # Set common output directories diff --git a/Configure.bat b/Configure.bat index b35b3d4..95abdad 100644 --- a/Configure.bat +++ b/Configure.bat @@ -1,10 +1,8 @@ @REM Run Conan to install dependencies rmdir build /s /q -mkdir build - @REM DEBUG -conan install . -s build_type=Debug --build=missing +conan install . -of build -s build_type=Debug --build=missing @REM RELEASE -conan install . -s build_type=Release --build=missing +conan install . -of build -s build_type=Release --build=missing diff --git a/Configure.sh b/Configure.sh old mode 100644 new mode 100755 From 0cfa8b7cea63d5f319bbc4fe0fc7bc10fa390c3c Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 16:25:34 -0500 Subject: [PATCH 06/18] CONGE-1 Special case between windows and mac. Will have to test if it's the case on other machines --- CMakeLists.txt | 10 +++++++--- Configure.bat | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bc9f3d..fa0168c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,14 @@ endif() set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) # Include the Conan-generated files -list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") - -include("${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") +IF (WIN32) + list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") + include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") +ELSE() + list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") + include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") +ENDIF() # Set common output directories set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/intermediates/${CMAKE_BUILD_TYPE}/${ARCH}/${PROJECT_NAME}) diff --git a/Configure.bat b/Configure.bat index 95abdad..e4a13c0 100644 --- a/Configure.bat +++ b/Configure.bat @@ -2,7 +2,7 @@ rmdir build /s /q @REM DEBUG -conan install . -of build -s build_type=Debug --build=missing +conan install . -s build_type=Debug --build=missing @REM RELEASE -conan install . -of build -s build_type=Release --build=missing +conan install . -s build_type=Release --build=missing From 85746cfadf766e0883af3e15122b51d4c1b630e5 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Thu, 21 Nov 2024 16:26:47 -0500 Subject: [PATCH 07/18] CONGE-1 fixed mac version --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa0168c..3aca493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,11 +20,11 @@ set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) # Include the Conan-generated files IF (WIN32) - list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") - include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") -ELSE() list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") include("${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake") +ELSE() + list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators") + include("${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") ENDIF() # Set common output directories From dccbcf3cca64e57313581040401e483d7a2443d9 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 06:49:48 -0500 Subject: [PATCH 08/18] CONGE-2 : (WIP) adding the basic structure for the engine --- ConjureEngine/CMakeLists.txt | 22 +++- .../src/ConjureEngine/Application.cpp | 8 ++ ConjureEngine/src/ConjureEngine/Application.h | 13 ++ .../src/ConjureEngine/ConjureEngine.cpp | 10 -- ConjureEngine/src/ConjureEngine/Engine.cpp | 4 + .../{ConjureEngine.h => Engine.h} | 3 +- ConjureEngine/src/ConjureEngine/PCH.h | 21 ++++ ConjureEngine/src/ConjureEngine/Window.cpp | 119 ++++++++++++++++++ ConjureEngine/src/ConjureEngine/Window.h | 29 +++++ Demo1/src/main.cpp | 3 +- 10 files changed, 215 insertions(+), 17 deletions(-) create mode 100644 ConjureEngine/src/ConjureEngine/Application.cpp create mode 100644 ConjureEngine/src/ConjureEngine/Application.h delete mode 100644 ConjureEngine/src/ConjureEngine/ConjureEngine.cpp create mode 100644 ConjureEngine/src/ConjureEngine/Engine.cpp rename ConjureEngine/src/ConjureEngine/{ConjureEngine.h => Engine.h} (58%) create mode 100644 ConjureEngine/src/ConjureEngine/PCH.h create mode 100644 ConjureEngine/src/ConjureEngine/Window.cpp create mode 100644 ConjureEngine/src/ConjureEngine/Window.h diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index 100cb66..813d541 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -1,19 +1,35 @@ cmake_minimum_required(VERSION 3.26) - set(CMAKE_CXX_STANDARD 20) project(ConjureEngine) +set(HEADER_FILES + src/ConjureEngine/Application.h + src/ConjureEngine/Engine.h + src/ConjureEngine/Window.h +) + +set(SOURCES_FILES + src/ConjureEngine/Application.cpp + src/ConjureEngine/Engine.cpp + src/ConjureEngine/Window.cpp +) find_package(glm REQUIRED) find_package(SDL2 REQUIRED) find_package(Vulkan REQUIRED) -add_library(${PROJECT_NAME} STATIC src/ConjureEngine/ConjureEngine.h src/ConjureEngine/ConjureEngine.cpp) +add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCES_FILES}) # Specify include directories target_include_directories(${PROJECT_NAME} PUBLIC include) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include) -target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm Vulkan::Vulkan) + +target_precompile_headers( + ${PROJECT_NAME} + PUBLIC + src/ConjureEngine/PCH.h +) \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Application.cpp b/ConjureEngine/src/ConjureEngine/Application.cpp new file mode 100644 index 0000000..e0417f4 --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/Application.cpp @@ -0,0 +1,8 @@ +// +// Created by calap on 11/21/2024. +// + +#include "Application.h" + +namespace ConjureEngine { +} // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Application.h b/ConjureEngine/src/ConjureEngine/Application.h new file mode 100644 index 0000000..161eb0e --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/Application.h @@ -0,0 +1,13 @@ +// +// Created by calap on 11/21/2024. +// + +#pragma once + +namespace ConjureEngine { + +class Application { + +}; + +} // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/ConjureEngine.cpp b/ConjureEngine/src/ConjureEngine/ConjureEngine.cpp deleted file mode 100644 index 107dd0c..0000000 --- a/ConjureEngine/src/ConjureEngine/ConjureEngine.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by Jimmy Tremblay-bernier on 2024-11-14. -// -#include "ConjureEngine.h" -#include - -void ConjureEngine::SayHello() -{ - printf("Hello World\n"); -} \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Engine.cpp b/ConjureEngine/src/ConjureEngine/Engine.cpp new file mode 100644 index 0000000..693210c --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/Engine.cpp @@ -0,0 +1,4 @@ +// +// Created by Jimmy Tremblay-bernier on 2024-11-14. +// +#include "Engine.h" diff --git a/ConjureEngine/src/ConjureEngine/ConjureEngine.h b/ConjureEngine/src/ConjureEngine/Engine.h similarity index 58% rename from ConjureEngine/src/ConjureEngine/ConjureEngine.h rename to ConjureEngine/src/ConjureEngine/Engine.h index a076112..8ff00e5 100644 --- a/ConjureEngine/src/ConjureEngine/ConjureEngine.h +++ b/ConjureEngine/src/ConjureEngine/Engine.h @@ -3,6 +3,5 @@ #include "glm/glm.hpp" namespace ConjureEngine { - void SayHello(); - glm::vec3& Forward(); + } diff --git a/ConjureEngine/src/ConjureEngine/PCH.h b/ConjureEngine/src/ConjureEngine/PCH.h new file mode 100644 index 0000000..f1f8d61 --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/PCH.h @@ -0,0 +1,21 @@ +// +// Created by calap on 11/21/2024. +// + +#pragma once + +// STANDARD LIBS +#include +#include +#include + +// GLM +#include "glm/glm.hpp" + +// SDL2 +#include "SDL2/SDL.h" +#include "SDL2/SDL_vulkan.h" +#include "SDL2/SDL_video.h" + +// VULKAN +#include "Vulkan/vulkan.h" \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp new file mode 100644 index 0000000..0dde45f --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -0,0 +1,119 @@ +// +// Created by calap on 11/21/2024. +// +#include "Window.h" + +namespace ConjureEngine { + + Window::Window(const WindowInfo& windowInfo) + { + SDL_Init(SDL_INIT_VIDEO); + SDL_Vulkan_LoadLibrary(nullptr); + m_window = std::shared_ptr( + SDL_CreateWindow(windowInfo.title.c_str(), 0, 0, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN |SDL_WINDOW_VULKAN) + ); + + + SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, nullptr); + m_extensionNames = new const char *[m_extensionCount]; + SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, m_extensionNames); + const VkInstanceCreateInfo instInfo = { + VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType + nullptr, // pNext + 0, // flags + nullptr, // pApplicationInfo + 0, // enabledLayerCount + nullptr, // ppEnabledLayerNames + m_extensionCount, // enabledExtensionCount + m_extensionNames, // ppEnabledExtensionNames + }; + vkCreateInstance(&instInfo, nullptr, &m_vkInst); + + vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr); + m_physicalDevices = std::vector(m_physicalDeviceCount); + + vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data()); + + // TODO - I'M AT THIS POINT + VkPhysicalDevice physicalDevice = m_physicalDevices[0]; + + uint32_t queueFamilyCount; + vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr); + std::vector queueFamilies(queueFamilyCount); + vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilies.data()); + + VkSurfaceKHR surface; + SDL_Vulkan_CreateSurface(window, vkInst, &surface); + + uint32_t graphicsQueueIndex = UINT32_MAX; + uint32_t presentQueueIndex = UINT32_MAX; + VkBool32 support; + uint32_t i = 0; + for (VkQueueFamilyProperties queueFamily : queueFamilies) { + if (graphicsQueueIndex == UINT32_MAX && queueFamily.queueCount > 0 && queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) + graphicsQueueIndex = i; + if (presentQueueIndex == UINT32_MAX) { + vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, surface, &support); + if(support) + presentQueueIndex = i; + } + ++i; + } + + float queuePriority = 1.0f; + VkDeviceQueueCreateInfo queueInfo = { + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType + nullptr, // pNext + 0, // flags + graphicsQueueIndex, // graphicsQueueIndex + 1, // queueCount + &queuePriority, // pQueuePriorities + }; + + VkPhysicalDeviceFeatures deviceFeatures = {}; + const char* deviceExtensionNames[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + VkDeviceCreateInfo createInfo = { + VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType + nullptr, // pNext + 0, // flags + 1, // queueCreateInfoCount + &queueInfo, // pQueueCreateInfos + 0, // enabledLayerCount + nullptr, // ppEnabledLayerNames + 1, // enabledExtensionCount + deviceExtensionNames, // ppEnabledExtensionNames + &deviceFeatures, // pEnabledFeatures + }; + VkDevice device; + vkCreateDevice(physicalDevice, &createInfo, nullptr, &device); + + VkQueue graphicsQueue; + vkGetDeviceQueue(device, graphicsQueueIndex, 0, &graphicsQueue); + + VkQueue presentQueue; + vkGetDeviceQueue(device, presentQueueIndex, 0, &presentQueue); + + SDL_Log("Initialized with errors: %s", SDL_GetError()); + + bool running = true; + while(running) { + SDL_Event windowEvent; + while(SDL_PollEvent(&windowEvent)) + if(windowEvent.type == SDL_QUIT) { + running = false; + break; + } + } + + vkDestroyDevice(device, nullptr); + vkDestroyInstance(vkInst, nullptr); + SDL_DestroyWindow(window); + SDL_Vulkan_UnloadLibrary(); + SDL_Quit(); + + SDL_Log("Cleaned up with errors: %s", SDL_GetError()); + + return 0; + } + +} // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Window.h b/ConjureEngine/src/ConjureEngine/Window.h new file mode 100644 index 0000000..ebc1b7e --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/Window.h @@ -0,0 +1,29 @@ +// +// Created by calap on 11/21/2024. +// + +#pragma once + +namespace ConjureEngine { + +struct WindowInfo { + std::string title; + int width; + int height; +}; + +class Window { + public: + explicit Window(const WindowInfo& windowInfo); + private: + public: + private: + std::shared_ptr m_window; + uint32_t m_extensionCount{0}; + const char** m_extensionNames{nullptr}; + VkInstance m_vkInst; + uint32_t m_physicalDeviceCount{0}; + std::vector m_physicalDevices; +}; + +} // ConjureEngine \ No newline at end of file diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 5668f0f..1acdc2d 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -1,6 +1,5 @@ -#include "ConjureEngine/ConjureEngine.h" +#include "ConjureEngine/Engine.h" int main(int argc, char** argv) { - ConjureEngine::SayHello(); return 0; } \ No newline at end of file From f64bb01ab22aee1fca9e9a5a8f89c1f1fabe5353 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 11:17:46 -0500 Subject: [PATCH 09/18] CONGE-2 added the basic setup to open a windows on mac and windows --- ConjureEngine/CMakeLists.txt | 5 +- ConjureEngine/docs/.gitkeep | 0 ConjureEngine/docs/class.mmd | 24 ++++ .../src/ConjureEngine/Application.cpp | 8 +- ConjureEngine/src/ConjureEngine/Application.h | 22 ++- .../src/ConjureEngine/ConjureEngine.h | 4 + ConjureEngine/src/ConjureEngine/Engine.cpp | 4 - ConjureEngine/src/ConjureEngine/Engine.h | 7 - ConjureEngine/src/ConjureEngine/PCH.h | 6 +- .../src/ConjureEngine/VulkanContext.cpp | 125 ++++++++++++++++++ .../src/ConjureEngine/VulkanContext.h | 31 +++++ ConjureEngine/src/ConjureEngine/Window.cpp | 119 +++-------------- ConjureEngine/src/ConjureEngine/Window.h | 28 ++-- Demo1/CMakeLists.txt | 4 +- Demo1/src/Demo1.cpp | 42 ++++++ Demo1/src/Demo1.h | 17 +++ Demo1/src/main.cpp | 7 +- 17 files changed, 320 insertions(+), 133 deletions(-) delete mode 100644 ConjureEngine/docs/.gitkeep create mode 100644 ConjureEngine/docs/class.mmd create mode 100644 ConjureEngine/src/ConjureEngine/ConjureEngine.h delete mode 100644 ConjureEngine/src/ConjureEngine/Engine.cpp delete mode 100644 ConjureEngine/src/ConjureEngine/Engine.h create mode 100644 ConjureEngine/src/ConjureEngine/VulkanContext.cpp create mode 100644 ConjureEngine/src/ConjureEngine/VulkanContext.h create mode 100644 Demo1/src/Demo1.cpp create mode 100644 Demo1/src/Demo1.h diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index 813d541..bc6f39d 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -6,13 +6,14 @@ project(ConjureEngine) set(HEADER_FILES src/ConjureEngine/Application.h - src/ConjureEngine/Engine.h + src/ConjureEngine/ConjureEngine.h + src/ConjureEngine/VulkanContext.h src/ConjureEngine/Window.h ) set(SOURCES_FILES src/ConjureEngine/Application.cpp - src/ConjureEngine/Engine.cpp + src/ConjureEngine/VulkanContext.cpp src/ConjureEngine/Window.cpp ) diff --git a/ConjureEngine/docs/.gitkeep b/ConjureEngine/docs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/ConjureEngine/docs/class.mmd b/ConjureEngine/docs/class.mmd new file mode 100644 index 0000000..2b7b43a --- /dev/null +++ b/ConjureEngine/docs/class.mmd @@ -0,0 +1,24 @@ +classDiagram + namespace ConjureEngine { + class Application { + + Run() int + + Tick(double deltaTime) void + } + + class Window { + + std::shared_ptr~SDL_Window~ m_window; + + std::shared_ptr~VulkanContext~ m_vulkanContext; + } + + class VulkanContext { + - uint32_t m_extensionCount + - char** m_extensionNames + - VkInstance m_vkInst + - uint32_t m_physicalDeviceCount + - std::vector~VkPhysicalDevice~ m_physicalDevices + - VkPhysicalDevice m_selectedDevice + - uint32_t m_queueFamilyCount + } + } + + Window "1" *-- "1" VulkanContext \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Application.cpp b/ConjureEngine/src/ConjureEngine/Application.cpp index e0417f4..5333878 100644 --- a/ConjureEngine/src/ConjureEngine/Application.cpp +++ b/ConjureEngine/src/ConjureEngine/Application.cpp @@ -5,4 +5,10 @@ #include "Application.h" namespace ConjureEngine { -} // ConjureEngine \ No newline at end of file + Application::Application(const ApplicationInfo &applicationInfo): m_applicationInfo(applicationInfo) { + } + + int Application::Run() const { return 0; } + void Application::Tick(double deltaTime) const {} + +} // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/Application.h b/ConjureEngine/src/ConjureEngine/Application.h index 161eb0e..0c2840b 100644 --- a/ConjureEngine/src/ConjureEngine/Application.h +++ b/ConjureEngine/src/ConjureEngine/Application.h @@ -4,10 +4,26 @@ #pragma once +#include "PCH.h" +#include "Window.h" + namespace ConjureEngine { + struct ApplicationInfo { + WindowInfo window{"", 0, 0, 0, 0}; + }; -class Application { + class Application { + public: + explicit Application(const ApplicationInfo &applicationInfo); + virtual ~Application() = default; -}; + virtual int Run() const; -} // ConjureEngine \ No newline at end of file + virtual void Tick(double deltaTime) const; + + protected: + public: + protected: + ApplicationInfo m_applicationInfo; + }; +} // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/ConjureEngine.h b/ConjureEngine/src/ConjureEngine/ConjureEngine.h new file mode 100644 index 0000000..af90929 --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/ConjureEngine.h @@ -0,0 +1,4 @@ +#pragma once + +#include "Application.h" +#include "Window.h" diff --git a/ConjureEngine/src/ConjureEngine/Engine.cpp b/ConjureEngine/src/ConjureEngine/Engine.cpp deleted file mode 100644 index 693210c..0000000 --- a/ConjureEngine/src/ConjureEngine/Engine.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// -// Created by Jimmy Tremblay-bernier on 2024-11-14. -// -#include "Engine.h" diff --git a/ConjureEngine/src/ConjureEngine/Engine.h b/ConjureEngine/src/ConjureEngine/Engine.h deleted file mode 100644 index 8ff00e5..0000000 --- a/ConjureEngine/src/ConjureEngine/Engine.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "glm/glm.hpp" - -namespace ConjureEngine { - -} diff --git a/ConjureEngine/src/ConjureEngine/PCH.h b/ConjureEngine/src/ConjureEngine/PCH.h index f1f8d61..d31b963 100644 --- a/ConjureEngine/src/ConjureEngine/PCH.h +++ b/ConjureEngine/src/ConjureEngine/PCH.h @@ -18,4 +18,8 @@ #include "SDL2/SDL_video.h" // VULKAN -#include "Vulkan/vulkan.h" \ No newline at end of file +#include "vulkan/vulkan.h" +#include "vulkan/vulkan_core.h" +#ifdef __APPLE__ + #include "vulkan/vulkan_metal.h" +#endif \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp new file mode 100644 index 0000000..e07fc94 --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -0,0 +1,125 @@ +// +// Created by Jimmy Tremblay-bernier on 2024-11-22. +// + +#include "VulkanContext.h" + +#ifdef __APPLE__ + #define VK_USE_PLATFORM_METAL_EXT +#endif + +namespace ConjureEngine { + VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) { + // LOAD THE EXTENSIONS + SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); + m_extensionNames.reserve(m_extensionCount); + SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data()); + + + // Fill the instance create info using appInfo + VkInstanceCreateInfo vulkanInfos{}; + vulkanInfos.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + vulkanInfos.pApplicationInfo = &appInfo; + + // ENABLE THE REQUIRED EXTENSIONS + this->EnableGlobalExtentions(window, vulkanInfos); + + // CREATE VULKAN INSTANCE + vkCreateInstance(&vulkanInfos, nullptr, &m_vkInst); + + // LOAD THE PHYSICAL DEVICES (GPUs) + vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr); + m_physicalDevices = std::vector(m_physicalDeviceCount); + vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data()); + + // SELECT THE MAIN GPU (WE COULD HAVE A SMARTER SELECTION LATER) + m_selectedPhysicalDevice = m_physicalDevices[0]; + + // LOAD THE FAMILLY QUEUE PROPERTIES + vkGetPhysicalDeviceQueueFamilyProperties(m_selectedPhysicalDevice, &m_queueFamilyCount, nullptr); + std::vector queueFamilies(m_queueFamilyCount); + vkGetPhysicalDeviceQueueFamilyProperties(m_selectedPhysicalDevice, &m_queueFamilyCount, queueFamilies.data()); + + // CREATE THE SURFACE FOR RENDERING + SDL_Vulkan_CreateSurface(window, m_vkInst, &m_surface); + + // ??? + uint32_t graphicsQueueIndex = UINT32_MAX; + uint32_t presentQueueIndex = UINT32_MAX; + VkBool32 support; + uint32_t i = 0; + for (VkQueueFamilyProperties queueFamily: queueFamilies) { + if (graphicsQueueIndex == UINT32_MAX && queueFamily.queueCount > 0 && queueFamily.queueFlags & + VK_QUEUE_GRAPHICS_BIT) + graphicsQueueIndex = i; + if (presentQueueIndex == UINT32_MAX) { + vkGetPhysicalDeviceSurfaceSupportKHR(m_selectedPhysicalDevice, i, m_surface, &support); + if (support) + presentQueueIndex = i; + } + ++i; + } + + // + float queuePriority = 1.0f; + m_deviceQueueCreateInfo = { + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType + nullptr, // pNext + 0, // flags + graphicsQueueIndex, // graphicsQueueIndex + 1, // queueCount + &queuePriority, // pQueuePriorities + }; + + // FETCH THE PHYSICAL DEVICES FEATURES + VkPhysicalDeviceFeatures deviceFeatures = {}; + const char *deviceExtensionNames[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + m_deviceCreateInfo = { + VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType + nullptr, // pNext + 0, // flags + 1, // queueCreateInfoCount + &m_deviceQueueCreateInfo, // pQueueCreateInfos + 0, // enabledLayerCount + nullptr, // ppEnabledLayerNames + 1, // enabledExtensionCount + deviceExtensionNames, // ppEnabledExtensionNames + &deviceFeatures, // pEnabledFeatures + }; + + + // CREATE VIRTUAL DEVICE FOR RENDERING + vkCreateDevice(m_selectedPhysicalDevice, &m_deviceCreateInfo, nullptr, &m_device); + + vkGetDeviceQueue(m_device, graphicsQueueIndex, 0, &m_graphicQueue); + vkGetDeviceQueue(m_device, presentQueueIndex, 0, &m_presentQueue); + + const std::string error = SDL_GetError(); + if(!error.empty()) { + SDL_Log("Initialized with errors: %s", error.c_str()); + } + else { + SDL_Log("Initialized without errors"); + } + } + + void VulkanContext::EnableGlobalExtentions(SDL_Window* window, VkInstanceCreateInfo &vulkanInfos) { + SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); + this->m_extensionNames.reserve(m_extensionCount); + SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data()); + + #ifdef __APPLE__ + this->m_extensionNames.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + this->m_extensionNames.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME); + vulkanInfos.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; + #endif + + vulkanInfos.enabledExtensionCount = static_cast(this->m_extensionNames.size()); + vulkanInfos.ppEnabledExtensionNames = this->m_extensionNames.data(); + } + + VulkanContext::~VulkanContext() { + vkDestroyDevice(m_device, nullptr); + vkDestroyInstance(m_vkInst, nullptr); + } +} // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.h b/ConjureEngine/src/ConjureEngine/VulkanContext.h new file mode 100644 index 0000000..18bcd29 --- /dev/null +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.h @@ -0,0 +1,31 @@ +// +// Created by Jimmy Tremblay-bernier on 2024-11-22. +// + +#pragma once + +namespace ConjureEngine { +#include "PCH.h" + + class VulkanContext { + public: + explicit VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo); + ~VulkanContext(); + void EnableGlobalExtentions(SDL_Window* window, VkInstanceCreateInfo &vulkanInfos); + + private: + uint32_t m_extensionCount{0}; + std::vector m_extensionNames; + VkInstance m_vkInst{}; + uint32_t m_physicalDeviceCount{0}; + std::vector m_physicalDevices; + VkPhysicalDevice m_selectedPhysicalDevice; + uint32_t m_queueFamilyCount{0}; + VkSurfaceKHR m_surface; + VkDeviceQueueCreateInfo m_deviceQueueCreateInfo; + VkDeviceCreateInfo m_deviceCreateInfo; + VkDevice m_device; + VkQueue m_graphicQueue; + VkQueue m_presentQueue; + }; +} // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp index 0dde45f..61cd396 100644 --- a/ConjureEngine/src/ConjureEngine/Window.cpp +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -7,113 +7,32 @@ namespace ConjureEngine { Window::Window(const WindowInfo& windowInfo) { + // INIT WINDOW SDL_Init(SDL_INIT_VIDEO); SDL_Vulkan_LoadLibrary(nullptr); - m_window = std::shared_ptr( - SDL_CreateWindow(windowInfo.title.c_str(), 0, 0, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN |SDL_WINDOW_VULKAN) - ); + m_window = SDL_CreateWindow(windowInfo.title.c_str(), 0, 0, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN |SDL_WINDOW_VULKAN); + // Fill the application information + VkApplicationInfo appInfo{}; + appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + appInfo.pApplicationName = windowInfo.title.c_str(); + appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); + appInfo.pEngineName = "Conjure Engine"; + appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); + appInfo.apiVersion = VK_API_VERSION_1_0; - SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, nullptr); - m_extensionNames = new const char *[m_extensionCount]; - SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, m_extensionNames); - const VkInstanceCreateInfo instInfo = { - VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType - nullptr, // pNext - 0, // flags - nullptr, // pApplicationInfo - 0, // enabledLayerCount - nullptr, // ppEnabledLayerNames - m_extensionCount, // enabledExtensionCount - m_extensionNames, // ppEnabledExtensionNames - }; - vkCreateInstance(&instInfo, nullptr, &m_vkInst); + // INIT VULKAN + m_vulkanContext = new VulkanContext(m_window, appInfo); + } - vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr); - m_physicalDevices = std::vector(m_physicalDeviceCount); + Window::~Window() { + delete m_vulkanContext; - vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data()); + SDL_DestroyWindow(m_window); + SDL_Vulkan_UnloadLibrary(); + SDL_Quit(); - // TODO - I'M AT THIS POINT - VkPhysicalDevice physicalDevice = m_physicalDevices[0]; - - uint32_t queueFamilyCount; - vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr); - std::vector queueFamilies(queueFamilyCount); - vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilies.data()); - - VkSurfaceKHR surface; - SDL_Vulkan_CreateSurface(window, vkInst, &surface); - - uint32_t graphicsQueueIndex = UINT32_MAX; - uint32_t presentQueueIndex = UINT32_MAX; - VkBool32 support; - uint32_t i = 0; - for (VkQueueFamilyProperties queueFamily : queueFamilies) { - if (graphicsQueueIndex == UINT32_MAX && queueFamily.queueCount > 0 && queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) - graphicsQueueIndex = i; - if (presentQueueIndex == UINT32_MAX) { - vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, surface, &support); - if(support) - presentQueueIndex = i; - } - ++i; - } - - float queuePriority = 1.0f; - VkDeviceQueueCreateInfo queueInfo = { - VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType - nullptr, // pNext - 0, // flags - graphicsQueueIndex, // graphicsQueueIndex - 1, // queueCount - &queuePriority, // pQueuePriorities - }; - - VkPhysicalDeviceFeatures deviceFeatures = {}; - const char* deviceExtensionNames[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; - VkDeviceCreateInfo createInfo = { - VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType - nullptr, // pNext - 0, // flags - 1, // queueCreateInfoCount - &queueInfo, // pQueueCreateInfos - 0, // enabledLayerCount - nullptr, // ppEnabledLayerNames - 1, // enabledExtensionCount - deviceExtensionNames, // ppEnabledExtensionNames - &deviceFeatures, // pEnabledFeatures - }; - VkDevice device; - vkCreateDevice(physicalDevice, &createInfo, nullptr, &device); - - VkQueue graphicsQueue; - vkGetDeviceQueue(device, graphicsQueueIndex, 0, &graphicsQueue); - - VkQueue presentQueue; - vkGetDeviceQueue(device, presentQueueIndex, 0, &presentQueue); - - SDL_Log("Initialized with errors: %s", SDL_GetError()); - - bool running = true; - while(running) { - SDL_Event windowEvent; - while(SDL_PollEvent(&windowEvent)) - if(windowEvent.type == SDL_QUIT) { - running = false; - break; - } - } - - vkDestroyDevice(device, nullptr); - vkDestroyInstance(vkInst, nullptr); - SDL_DestroyWindow(window); - SDL_Vulkan_UnloadLibrary(); - SDL_Quit(); - - SDL_Log("Cleaned up with errors: %s", SDL_GetError()); - - return 0; + SDL_Log("Cleaned up with errors: %s", SDL_GetError()); } } // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Window.h b/ConjureEngine/src/ConjureEngine/Window.h index ebc1b7e..f5ce802 100644 --- a/ConjureEngine/src/ConjureEngine/Window.h +++ b/ConjureEngine/src/ConjureEngine/Window.h @@ -4,26 +4,30 @@ #pragma once -namespace ConjureEngine { +#include "PCH.h" +#include "VulkanContext.h" -struct WindowInfo { - std::string title; - int width; - int height; -}; +namespace ConjureEngine { + struct WindowInfo { + std::string title; + int x; + int y; + int width; + int height; + }; class Window { public: explicit Window(const WindowInfo& windowInfo); + ~Window(); + + const std::shared_ptr& GetWindow() const; + const std::shared_ptr& GetVulkanContext() const; private: public: private: - std::shared_ptr m_window; - uint32_t m_extensionCount{0}; - const char** m_extensionNames{nullptr}; - VkInstance m_vkInst; - uint32_t m_physicalDeviceCount{0}; - std::vector m_physicalDevices; + SDL_Window* m_window; + VulkanContext* m_vulkanContext; }; } // ConjureEngine \ No newline at end of file diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index f1b17b4..63941d0 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -3,7 +3,9 @@ project(Demo1) set(CMAKE_CXX_STANDARD 20) -add_executable(${PROJECT_NAME} src/main.cpp) +add_executable(${PROJECT_NAME} src/main.cpp + src/Demo1.cpp + src/Demo1.h) target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp new file mode 100644 index 0000000..49512bd --- /dev/null +++ b/Demo1/src/Demo1.cpp @@ -0,0 +1,42 @@ +// +// Created by Jimmy Tremblay-bernier on 2024-11-22. +// + +#include "Demo1.h" +#include "ConjureEngine/ConjureEngine.h" + +namespace Demo1 { + Demo1::Demo1(): ConjureEngine::Application( + { + {"Demo1", 0, 0, 1920, 1080} + } + ) { + } + + + int Demo1::Run() const { + ConjureEngine::Window window(m_applicationInfo.window); + + bool running = true; + while (running) { + SDL_Event windowEvent; + uint64_t timeSinceStart = SDL_GetTicks64(); + + while (SDL_PollEvent(&windowEvent)) { + if (windowEvent.type == SDL_QUIT) { + running = false; + break; + } + } + + this->Tick((double)timeSinceStart/1000.0f); + } + + return 0; + } + + void Demo1::Tick(double deltaTime) const { + + } + +} // Demo1 diff --git a/Demo1/src/Demo1.h b/Demo1/src/Demo1.h new file mode 100644 index 0000000..c339852 --- /dev/null +++ b/Demo1/src/Demo1.h @@ -0,0 +1,17 @@ +// +// Created by Jimmy Tremblay-bernier on 2024-11-22. +// + +#pragma once +#include "ConjureEngine/ConjureEngine.h" + +namespace Demo1 { + +class Demo1: public ConjureEngine::Application { + public: + Demo1(); + int Run() const override; + void Tick(double deltaTime) const override; +}; + +} // Demo1 \ No newline at end of file diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 1acdc2d..c98f119 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -1,5 +1,8 @@ -#include "ConjureEngine/Engine.h" +#include "ConjureEngine/ConjureEngine.h" +#include "Demo1.h" int main(int argc, char** argv) { - return 0; + Demo1::Demo1 app; + + return app.Run(); } \ No newline at end of file From b253c08bf8ab7eaed1f63bbccbd8f61969d1b43b Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 11:43:22 -0500 Subject: [PATCH 10/18] CONGE-2 BUG with windows --- ConjureEngine/CMakeLists.txt | 2 +- ConjureEngine/src/ConjureEngine/PCH.h | 3 ++ .../src/ConjureEngine/VulkanContext.cpp | 4 --- ConjureEngine/src/ConjureEngine/Window.cpp | 9 ++++++ ConjureEngine/src/ConjureEngine/Window.h | 31 ++++++++++--------- Demo1/CMakeLists.txt | 8 +++-- Demo1/src/Demo1.cpp | 21 ++++++++----- Demo1/src/Demo1.h | 2 +- Demo1/src/main.cpp | 6 ++-- 9 files changed, 53 insertions(+), 33 deletions(-) diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index bc6f39d..729604b 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -31,6 +31,6 @@ target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm Vulkan::Vulkan) target_precompile_headers( ${PROJECT_NAME} - PUBLIC + PRIVATE src/ConjureEngine/PCH.h ) \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/PCH.h b/ConjureEngine/src/ConjureEngine/PCH.h index d31b963..ef309e2 100644 --- a/ConjureEngine/src/ConjureEngine/PCH.h +++ b/ConjureEngine/src/ConjureEngine/PCH.h @@ -20,6 +20,9 @@ // VULKAN #include "vulkan/vulkan.h" #include "vulkan/vulkan_core.h" + #ifdef __APPLE__ #include "vulkan/vulkan_metal.h" +#elifdef __WINDOWS__ + #include "vulkan/vulkan_win32.h" #endif \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index e07fc94..d287486 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -4,10 +4,6 @@ #include "VulkanContext.h" -#ifdef __APPLE__ - #define VK_USE_PLATFORM_METAL_EXT -#endif - namespace ConjureEngine { VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) { // LOAD THE EXTENSIONS diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp index 61cd396..b2ac76e 100644 --- a/ConjureEngine/src/ConjureEngine/Window.cpp +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -35,4 +35,13 @@ namespace ConjureEngine { SDL_Log("Cleaned up with errors: %s", SDL_GetError()); } + const SDL_Window* Window::GetWindow() const + { + return m_window; + } + + const VulkanContext * Window::GetVulkanContext() const + { + return m_vulkanContext; + } } // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Window.h b/ConjureEngine/src/ConjureEngine/Window.h index f5ce802..3d6d5b5 100644 --- a/ConjureEngine/src/ConjureEngine/Window.h +++ b/ConjureEngine/src/ConjureEngine/Window.h @@ -7,7 +7,8 @@ #include "PCH.h" #include "VulkanContext.h" -namespace ConjureEngine { +namespace ConjureEngine +{ struct WindowInfo { std::string title; int x; @@ -16,18 +17,20 @@ namespace ConjureEngine { int height; }; -class Window { - public: - explicit Window(const WindowInfo& windowInfo); - ~Window(); + class Window { + public: + explicit Window(const WindowInfo &windowInfo); - const std::shared_ptr& GetWindow() const; - const std::shared_ptr& GetVulkanContext() const; - private: - public: - private: - SDL_Window* m_window; - VulkanContext* m_vulkanContext; -}; + ~Window(); -} // ConjureEngine \ No newline at end of file + const SDL_Window *GetWindow() const; + + const VulkanContext *GetVulkanContext() const; + + private: + public: + private: + SDL_Window *m_window; + VulkanContext *m_vulkanContext; + }; +} // ConjureEngine diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index 63941d0..870ccb1 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -5,10 +5,14 @@ set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME} src/main.cpp src/Demo1.cpp - src/Demo1.h) + src/Demo1.h +) target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS} ConjureEngine) +find_package(SDL2 REQUIRED) + target_include_directories(${PROJECT_NAME} PRIVATE include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine/src) + +target_link_libraries(${PROJECT_NAME} SDL2::SDL2 ConjureEngine) \ No newline at end of file diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index 49512bd..b2db90d 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -5,13 +5,20 @@ #include "Demo1.h" #include "ConjureEngine/ConjureEngine.h" -namespace Demo1 { - Demo1::Demo1(): ConjureEngine::Application( +static ConjureEngine::ApplicationInfo appInfo = ConjureEngine::ApplicationInfo{ { - {"Demo1", 0, 0, 1920, 1080} + ConjureEngine::WindowInfo{ + "Demo1", + 0, + 0, + 1920, + 1080 + } } - ) { - } +}; + +namespace Demo1 { + Demo1::Demo1(): ConjureEngine::Application(appInfo) {} int Demo1::Run() const { @@ -35,8 +42,6 @@ namespace Demo1 { return 0; } - void Demo1::Tick(double deltaTime) const { - - } + void Demo1::Tick(double deltaTime) const {} } // Demo1 diff --git a/Demo1/src/Demo1.h b/Demo1/src/Demo1.h index c339852..a6e8846 100644 --- a/Demo1/src/Demo1.h +++ b/Demo1/src/Demo1.h @@ -1,4 +1,4 @@ -// +/// // Created by Jimmy Tremblay-bernier on 2024-11-22. // diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index c98f119..247f446 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -1,8 +1,8 @@ -#include "ConjureEngine/ConjureEngine.h" #include "Demo1.h" -int main(int argc, char** argv) { - Demo1::Demo1 app; +int main(int argc, char* argv[]) +{ + const Demo1::Demo1 app; return app.Run(); } \ No newline at end of file From 11b558f8360391b94a7c2ffab86184fab52c94fa Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 14:29:54 -0500 Subject: [PATCH 11/18] CONGE-2 working window on windows. Need to test on mac --- ConjureEngine/CMakeLists.txt | 5 ++++ .../src/ConjureEngine/Application.cpp | 7 ++++++ ConjureEngine/src/ConjureEngine/Application.h | 9 ++++++- .../src/ConjureEngine/ConjureEngine.h | 1 + ConjureEngine/src/ConjureEngine/PCH.h | 8 +------ .../src/ConjureEngine/VulkanContext.cpp | 11 +++++++++ ConjureEngine/src/ConjureEngine/Window.cpp | 24 +++---------------- ConjureEngine/src/ConjureEngine/Window.h | 12 +++------- Demo1/src/Demo1.cpp | 24 ++++++++++--------- Demo1/src/main.cpp | 6 ++++- 10 files changed, 57 insertions(+), 50 deletions(-) diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index 729604b..44a802d 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -21,6 +21,11 @@ find_package(glm REQUIRED) find_package(SDL2 REQUIRED) find_package(Vulkan REQUIRED) +IF (WIN32) + define_property(TARGET PROPERTY VK_PROTOTYPES ) + define_property(TARGET PROPERTY VK_USE_PLATFORM_WIN32_KHR) +endif () + add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCES_FILES}) # Specify include directories diff --git a/ConjureEngine/src/ConjureEngine/Application.cpp b/ConjureEngine/src/ConjureEngine/Application.cpp index 5333878..1530cb9 100644 --- a/ConjureEngine/src/ConjureEngine/Application.cpp +++ b/ConjureEngine/src/ConjureEngine/Application.cpp @@ -6,6 +6,13 @@ namespace ConjureEngine { Application::Application(const ApplicationInfo &applicationInfo): m_applicationInfo(applicationInfo) { + // Fill the application information + m_vkAppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + m_vkAppInfo.pApplicationName = applicationInfo.title.c_str(); + m_vkAppInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); + m_vkAppInfo.pEngineName = "Conjure Engine"; + m_vkAppInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); + m_vkAppInfo.apiVersion = VK_API_VERSION_1_0; } int Application::Run() const { return 0; } diff --git a/ConjureEngine/src/ConjureEngine/Application.h b/ConjureEngine/src/ConjureEngine/Application.h index 0c2840b..eedec4f 100644 --- a/ConjureEngine/src/ConjureEngine/Application.h +++ b/ConjureEngine/src/ConjureEngine/Application.h @@ -9,7 +9,13 @@ namespace ConjureEngine { struct ApplicationInfo { - WindowInfo window{"", 0, 0, 0, 0}; + std::string title; + WindowInfo window{ + 0, + 0, + 0, + 0 + }; }; class Application { @@ -25,5 +31,6 @@ namespace ConjureEngine { public: protected: ApplicationInfo m_applicationInfo; + VkApplicationInfo m_vkAppInfo{}; }; } // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/ConjureEngine.h b/ConjureEngine/src/ConjureEngine/ConjureEngine.h index af90929..4bc960e 100644 --- a/ConjureEngine/src/ConjureEngine/ConjureEngine.h +++ b/ConjureEngine/src/ConjureEngine/ConjureEngine.h @@ -1,4 +1,5 @@ #pragma once #include "Application.h" +#include "VulkanContext.h" #include "Window.h" diff --git a/ConjureEngine/src/ConjureEngine/PCH.h b/ConjureEngine/src/ConjureEngine/PCH.h index ef309e2..7748be7 100644 --- a/ConjureEngine/src/ConjureEngine/PCH.h +++ b/ConjureEngine/src/ConjureEngine/PCH.h @@ -19,10 +19,4 @@ // VULKAN #include "vulkan/vulkan.h" -#include "vulkan/vulkan_core.h" - -#ifdef __APPLE__ - #include "vulkan/vulkan_metal.h" -#elifdef __WINDOWS__ - #include "vulkan/vulkan_win32.h" -#endif \ No newline at end of file +#include "vulkan/vulkan_core.h" \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index d287486..f577b15 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -4,6 +4,13 @@ #include "VulkanContext.h" +#ifdef __WIN32__ + // #include +#endif +#ifdef __APPLE__ + #include "vulkan/vulkan_metal.h" +#endif + namespace ConjureEngine { VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) { // LOAD THE EXTENSIONS @@ -110,6 +117,10 @@ namespace ConjureEngine { vulkanInfos.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; #endif + #ifdef __WIN32__ + this->m_extensionNames.push_back("VK_KHR_win32_surface"); + #endif + vulkanInfos.enabledExtensionCount = static_cast(this->m_extensionNames.size()); vulkanInfos.ppEnabledExtensionNames = this->m_extensionNames.data(); } diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp index b2ac76e..63bf2fc 100644 --- a/ConjureEngine/src/ConjureEngine/Window.cpp +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -5,29 +5,16 @@ namespace ConjureEngine { - Window::Window(const WindowInfo& windowInfo) + Window::Window(const char* title, const WindowInfo& windowInfo) { // INIT WINDOW SDL_Init(SDL_INIT_VIDEO); SDL_Vulkan_LoadLibrary(nullptr); - m_window = SDL_CreateWindow(windowInfo.title.c_str(), 0, 0, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN |SDL_WINDOW_VULKAN); - // Fill the application information - VkApplicationInfo appInfo{}; - appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; - appInfo.pApplicationName = windowInfo.title.c_str(); - appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); - appInfo.pEngineName = "Conjure Engine"; - appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); - appInfo.apiVersion = VK_API_VERSION_1_0; - - // INIT VULKAN - m_vulkanContext = new VulkanContext(m_window, appInfo); + m_window = SDL_CreateWindow(title, 0, 32, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN); } Window::~Window() { - delete m_vulkanContext; - SDL_DestroyWindow(m_window); SDL_Vulkan_UnloadLibrary(); SDL_Quit(); @@ -35,13 +22,8 @@ namespace ConjureEngine { SDL_Log("Cleaned up with errors: %s", SDL_GetError()); } - const SDL_Window* Window::GetWindow() const + SDL_Window* Window::GetWindow() const { return m_window; } - - const VulkanContext * Window::GetVulkanContext() const - { - return m_vulkanContext; - } } // ConjureEngine \ No newline at end of file diff --git a/ConjureEngine/src/ConjureEngine/Window.h b/ConjureEngine/src/ConjureEngine/Window.h index 3d6d5b5..3856666 100644 --- a/ConjureEngine/src/ConjureEngine/Window.h +++ b/ConjureEngine/src/ConjureEngine/Window.h @@ -5,12 +5,10 @@ #pragma once #include "PCH.h" -#include "VulkanContext.h" namespace ConjureEngine { struct WindowInfo { - std::string title; int x; int y; int width; @@ -19,18 +17,14 @@ namespace ConjureEngine class Window { public: - explicit Window(const WindowInfo &windowInfo); + explicit Window(const char* title, const WindowInfo &windowInfo); ~Window(); - const SDL_Window *GetWindow() const; - - const VulkanContext *GetVulkanContext() const; - + SDL_Window* GetWindow() const; private: public: private: - SDL_Window *m_window; - VulkanContext *m_vulkanContext; + SDL_Window* m_window; }; } // ConjureEngine diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index b2db90d..2fdcca5 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -5,16 +5,15 @@ #include "Demo1.h" #include "ConjureEngine/ConjureEngine.h" -static ConjureEngine::ApplicationInfo appInfo = ConjureEngine::ApplicationInfo{ - { - ConjureEngine::WindowInfo{ - "Demo1", - 0, - 0, - 1920, - 1080 - } - } +static ConjureEngine::ApplicationInfo appInfo = ConjureEngine::ApplicationInfo +{ + "Demo1", + ConjureEngine::WindowInfo { + 0, + 0, + 1920, + 1080 + } }; namespace Demo1 { @@ -22,7 +21,10 @@ namespace Demo1 { int Demo1::Run() const { - ConjureEngine::Window window(m_applicationInfo.window); + ConjureEngine::Window window(appInfo.title.c_str(), m_applicationInfo.window); + + // INIT VULKAN + ConjureEngine::VulkanContext vulkanContext(window.GetWindow(), this->m_vkAppInfo); bool running = true; while (running) { diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 247f446..33d1642 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -1,7 +1,11 @@ +#define SDL_MAIN_HANDLED + #include "Demo1.h" -int main(int argc, char* argv[]) +int main ( int argc, char* argv[] ) { + SDL_SetMainReady(); + const Demo1::Demo1 app; return app.Run(); From d74d19fdf27556d7ed95e87a8b71867bbb72bef1 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 15:03:04 -0500 Subject: [PATCH 12/18] CONGE-2 REMOVED PRESENTATION QUEUE ON MAC --- ConjureEngine/CMakeLists.txt | 5 ----- .../src/ConjureEngine/VulkanContext.cpp | 18 +++++++++++++----- .../src/ConjureEngine/VulkanContext.h | 18 ++++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ConjureEngine/CMakeLists.txt b/ConjureEngine/CMakeLists.txt index 44a802d..729604b 100644 --- a/ConjureEngine/CMakeLists.txt +++ b/ConjureEngine/CMakeLists.txt @@ -21,11 +21,6 @@ find_package(glm REQUIRED) find_package(SDL2 REQUIRED) find_package(Vulkan REQUIRED) -IF (WIN32) - define_property(TARGET PROPERTY VK_PROTOTYPES ) - define_property(TARGET PROPERTY VK_USE_PLATFORM_WIN32_KHR) -endif () - add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCES_FILES}) # Specify include directories diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index f577b15..2ce5c34 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -4,15 +4,13 @@ #include "VulkanContext.h" -#ifdef __WIN32__ - // #include -#endif #ifdef __APPLE__ #include "vulkan/vulkan_metal.h" #endif namespace ConjureEngine { - VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) { + VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) + { // LOAD THE EXTENSIONS SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); m_extensionNames.reserve(m_extensionCount); @@ -92,10 +90,20 @@ namespace ConjureEngine { // CREATE VIRTUAL DEVICE FOR RENDERING - vkCreateDevice(m_selectedPhysicalDevice, &m_deviceCreateInfo, nullptr, &m_device); + VkResult result = vkCreateDevice(m_selectedPhysicalDevice, &m_deviceCreateInfo, nullptr, &m_device); + if(result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Error while creating the device: %d", static_cast(result)); + } + else { + SDL_Log("DEVICE CREATED SUCCESSFULLY"); + } vkGetDeviceQueue(m_device, graphicsQueueIndex, 0, &m_graphicQueue); + + #ifndef __APPLE__ // MAC DOESNT SUPPORT 2 QUEUES LIKE ON WINDOWS/ vkGetDeviceQueue(m_device, presentQueueIndex, 0, &m_presentQueue); + #endif + const std::string error = SDL_GetError(); if(!error.empty()) { diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.h b/ConjureEngine/src/ConjureEngine/VulkanContext.h index 18bcd29..24e5c86 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.h +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.h @@ -16,16 +16,18 @@ namespace ConjureEngine { private: uint32_t m_extensionCount{0}; std::vector m_extensionNames; - VkInstance m_vkInst{}; + VkInstance m_vkInst{nullptr}; uint32_t m_physicalDeviceCount{0}; std::vector m_physicalDevices; - VkPhysicalDevice m_selectedPhysicalDevice; + VkPhysicalDevice m_selectedPhysicalDevice{nullptr}; uint32_t m_queueFamilyCount{0}; - VkSurfaceKHR m_surface; - VkDeviceQueueCreateInfo m_deviceQueueCreateInfo; - VkDeviceCreateInfo m_deviceCreateInfo; - VkDevice m_device; - VkQueue m_graphicQueue; - VkQueue m_presentQueue; + VkSurfaceKHR m_surface{nullptr}; + VkDeviceQueueCreateInfo m_deviceQueueCreateInfo{}; + VkDeviceCreateInfo m_deviceCreateInfo{}; + VkDevice m_device{nullptr}; + VkQueue m_graphicQueue{nullptr}; + #ifndef __APPLE__ + VkQueue m_presentQueue{nullptr}; + #endif }; } // ConjureEngine From 194ea8eeef269c55ab7b3db7914c52a9e1c3a902 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 15:08:02 -0500 Subject: [PATCH 13/18] CONGE-2 Tweaked the logic to handle cases where presentation queue is not available instead of using #ifndef --- ConjureEngine/src/ConjureEngine/VulkanContext.cpp | 8 +++++--- ConjureEngine/src/ConjureEngine/VulkanContext.h | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index 2ce5c34..f27cce7 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -100,9 +100,11 @@ namespace ConjureEngine { vkGetDeviceQueue(m_device, graphicsQueueIndex, 0, &m_graphicQueue); - #ifndef __APPLE__ // MAC DOESNT SUPPORT 2 QUEUES LIKE ON WINDOWS/ - vkGetDeviceQueue(m_device, presentQueueIndex, 0, &m_presentQueue); - #endif + // WHEN POSSIBLE, WE WANT TO USE THE PRESENTATION QUEUE, BUT MAC DOESN'T SUPPORT IT + if(presentQueueIndex != UINT32_MAX) { + m_supportsPresentationQueue = true; + vkGetDeviceQueue(m_device, presentQueueIndex, 0, &m_presentQueue); + } const std::string error = SDL_GetError(); diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.h b/ConjureEngine/src/ConjureEngine/VulkanContext.h index 24e5c86..f667312 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.h +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.h @@ -26,8 +26,7 @@ namespace ConjureEngine { VkDeviceCreateInfo m_deviceCreateInfo{}; VkDevice m_device{nullptr}; VkQueue m_graphicQueue{nullptr}; - #ifndef __APPLE__ VkQueue m_presentQueue{nullptr}; - #endif + bool m_supportsPresentationQueue = false; }; } // ConjureEngine From 829c7b5c524f10dcc069a038c1bdcadabec8b89a Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 18:54:08 -0500 Subject: [PATCH 14/18] CONGE-2 Reworked the API for the application to move more of the logic and initialization to the Engine and just have the application specifics in Demo1 --- .../src/ConjureEngine/Application.cpp | 45 ++++++++++++++++++- ConjureEngine/src/ConjureEngine/Application.h | 24 +++++++++- .../src/ConjureEngine/VulkanContext.cpp | 8 +++- .../src/ConjureEngine/VulkanContext.h | 4 +- Demo1/src/Demo1.cpp | 41 +++++++---------- Demo1/src/Demo1.h | 6 ++- Demo1/src/main.cpp | 4 +- 7 files changed, 98 insertions(+), 34 deletions(-) diff --git a/ConjureEngine/src/ConjureEngine/Application.cpp b/ConjureEngine/src/ConjureEngine/Application.cpp index 1530cb9..a56d7df 100644 --- a/ConjureEngine/src/ConjureEngine/Application.cpp +++ b/ConjureEngine/src/ConjureEngine/Application.cpp @@ -3,6 +3,7 @@ // #include "Application.h" +#include "VulkanContext.h" namespace ConjureEngine { Application::Application(const ApplicationInfo &applicationInfo): m_applicationInfo(applicationInfo) { @@ -15,7 +16,47 @@ namespace ConjureEngine { m_vkAppInfo.apiVersion = VK_API_VERSION_1_0; } - int Application::Run() const { return 0; } - void Application::Tick(double deltaTime) const {} + int Application::Run() + { + // CREATE SDL WINDOW + Window window(this->m_applicationInfo.title.c_str(), m_applicationInfo.window); + // INIT VULKAN + VulkanContext vulkanContext; + vulkanContext.AttachTo(window.GetWindow(), this->m_vkAppInfo); + + // INITIALIZATION OF THE WORLD + this->Awake(); + this->Start(); + + // MAIN LOOP + bool running = true; + + static uint64_t lastTick = SDL_GetTicks64(); // TIME IS IN MS + while (running) { + + + // HANDLE INPUTS HERE (CODE BELOW IS FROM A TUTORIAL) + SDL_Event windowEvent; + while (SDL_PollEvent(&windowEvent)) { + if (windowEvent.type == SDL_QUIT) { + running = false; + break; + } + } + + // TICK SCENE HERE + const uint64_t currentTick = SDL_GetTicks64(); // TIME IS IN MS + const uint64_t deltaTime = currentTick - lastTick; // TIME IS IN MS + this->Tick(static_cast(deltaTime)/1000.f); + + // HANDLE PHYSICS HERE + lastTick = currentTick; + } + + // CLEANUP HERE + this->Destroy(); + + return 0; + } } // ConjureEngine diff --git a/ConjureEngine/src/ConjureEngine/Application.h b/ConjureEngine/src/ConjureEngine/Application.h index eedec4f..67a5d87 100644 --- a/ConjureEngine/src/ConjureEngine/Application.h +++ b/ConjureEngine/src/ConjureEngine/Application.h @@ -23,9 +23,29 @@ namespace ConjureEngine { explicit Application(const ApplicationInfo &applicationInfo); virtual ~Application() = default; - virtual int Run() const; + int Run(); + + /** + * First function call right after SDL and VULKAN are init + */ + virtual inline void Awake() {}; + + /** + * Called after awake is done + */ + virtual inline void Start() {}; + + /** + * Called every frame after Start + * @param deltaTime Time in seconds since last call to Tick + */ + virtual inline void Tick(double deltaTime) {} + + /** + * Call when the application is being closed + */ + virtual inline void Destroy() {}; - virtual void Tick(double deltaTime) const; protected: public: diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index f27cce7..35599e2 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -4,14 +4,18 @@ #include "VulkanContext.h" +#include "Window.h" + #ifdef __APPLE__ #include "vulkan/vulkan_metal.h" #endif namespace ConjureEngine { - VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo) + VulkanContext::VulkanContext()= default; + + void VulkanContext::AttachTo(SDL_Window* window, const VkApplicationInfo& appInfo) { - // LOAD THE EXTENSIONS + // LOAD THE EXTENSIONS SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); m_extensionNames.reserve(m_extensionCount); SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data()); diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.h b/ConjureEngine/src/ConjureEngine/VulkanContext.h index f667312..a0e7aa8 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.h +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.h @@ -9,8 +9,10 @@ namespace ConjureEngine { class VulkanContext { public: - explicit VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo); + explicit VulkanContext(); ~VulkanContext(); + void AttachTo(SDL_Window* window, const VkApplicationInfo& appInfo); + private: void EnableGlobalExtentions(SDL_Window* window, VkInstanceCreateInfo &vulkanInfos); private: diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index 2fdcca5..da119e8 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -19,31 +19,24 @@ static ConjureEngine::ApplicationInfo appInfo = ConjureEngine::ApplicationInfo namespace Demo1 { Demo1::Demo1(): ConjureEngine::Application(appInfo) {} - - int Demo1::Run() const { - ConjureEngine::Window window(appInfo.title.c_str(), m_applicationInfo.window); - - // INIT VULKAN - ConjureEngine::VulkanContext vulkanContext(window.GetWindow(), this->m_vkAppInfo); - - bool running = true; - while (running) { - SDL_Event windowEvent; - uint64_t timeSinceStart = SDL_GetTicks64(); - - while (SDL_PollEvent(&windowEvent)) { - if (windowEvent.type == SDL_QUIT) { - running = false; - break; - } - } - - this->Tick((double)timeSinceStart/1000.0f); - } - - return 0; + void Demo1::Awake() + { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - AWAKING"); } - void Demo1::Tick(double deltaTime) const {} + void Demo1::Start() + { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - STARTING"); + } + + void Demo1::Tick(double deltaTime) + { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[DEMO1 - TRACE] - TICKING %f", deltaTime); + } + + void Demo1::Destroy() + { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - DESTROYING"); + } } // Demo1 diff --git a/Demo1/src/Demo1.h b/Demo1/src/Demo1.h index a6e8846..73a5e7b 100644 --- a/Demo1/src/Demo1.h +++ b/Demo1/src/Demo1.h @@ -10,8 +10,10 @@ namespace Demo1 { class Demo1: public ConjureEngine::Application { public: Demo1(); - int Run() const override; - void Tick(double deltaTime) const override; + void Awake() override; + void Start() override; + void Tick(double deltaTime) override; + void Destroy() override; }; } // Demo1 \ No newline at end of file diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 33d1642..9ad6781 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -6,7 +6,9 @@ int main ( int argc, char* argv[] ) { SDL_SetMainReady(); - const Demo1::Demo1 app; + // I WANT TO CREATE AN APP + Demo1::Demo1 app; + // AND THEN START IT return app.Run(); } \ No newline at end of file From 15f8898808c7699441d17276f078dfde166b3417 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Fri, 22 Nov 2024 20:29:48 -0500 Subject: [PATCH 15/18] CONGE-2 Added better login in Demo1 and added error handling in VulkanContext.cpp --- .../src/ConjureEngine/VulkanContext.cpp | 91 +++++++++++++++---- ConjureEngine/src/ConjureEngine/Window.cpp | 6 +- Demo1/src/Demo1.cpp | 8 +- Demo1/src/main.cpp | 82 ++++++++++++++++- 4 files changed, 163 insertions(+), 24 deletions(-) diff --git a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp index 35599e2..46c8a94 100644 --- a/ConjureEngine/src/ConjureEngine/VulkanContext.cpp +++ b/ConjureEngine/src/ConjureEngine/VulkanContext.cpp @@ -15,13 +15,32 @@ namespace ConjureEngine { void VulkanContext::AttachTo(SDL_Window* window, const VkApplicationInfo& appInfo) { - // LOAD THE EXTENSIONS - SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); + // LOAD THE EXTENSIONS + SDL_bool sdlSuccess; + VkResult vk_result; + + // FETCH NUMBER OF EXTENSIONS TO RESERVE SPACE IN VECTOR + sdlSuccess = SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr); + if(sdlSuccess != SDL_TRUE) + { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error Getting Extensions: %s", SDL_GetError()); + exit(1); + } m_extensionNames.reserve(m_extensionCount); - SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data()); + // FILLING UP THE VECTOR + sdlSuccess = SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data()); + if(sdlSuccess != SDL_TRUE) + { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error Getting Extensions: %s", SDL_GetError()); + exit(1); + } + else + { + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM,"FETCHING OF EXTENSION FINISHED SUCCESSFULLY"); + } - // Fill the instance create info using appInfo + // Fill the instance create info struct using appInfo VkInstanceCreateInfo vulkanInfos{}; vulkanInfos.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; vulkanInfos.pApplicationInfo = &appInfo; @@ -29,26 +48,57 @@ namespace ConjureEngine { // ENABLE THE REQUIRED EXTENSIONS this->EnableGlobalExtentions(window, vulkanInfos); - // CREATE VULKAN INSTANCE - vkCreateInstance(&vulkanInfos, nullptr, &m_vkInst); + // CREATE THE VULKAN INSTANCE + vk_result = vkCreateInstance(&vulkanInfos, nullptr, &m_vkInst); + if(vk_result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error while creating the device: CODE = %d", static_cast(vk_result)); + exit(1); + } + else { + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM,"VULKAN INSTANCE CREATED SUCCESSFULLY"); + } - // LOAD THE PHYSICAL DEVICES (GPUs) - vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr); + // FETCH THE NUMBER OF PHYSICAL DEVICES (GPUs) TO RESERVE SPACE INTHE VECTOR + vk_result = vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr); + if(vk_result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error while enumerating physical devices: CODE = %d", static_cast(vk_result)); + exit(1); + } m_physicalDevices = std::vector(m_physicalDeviceCount); - vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data()); - // SELECT THE MAIN GPU (WE COULD HAVE A SMARTER SELECTION LATER) + // FILL THE VECTOR WITH ACTUAL DEVICES DATA + vk_result = vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data()); + if(vk_result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error while enumerating physical devices: CODE = %d", static_cast(vk_result)); + exit(1); + } + else { + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "VULKAN ENUMERATION OF PHYSICAL DEVICES FINISHED SUCCESSFULLY"); + } + + // SELECT THE MAIN GPU (WE COULD HAVE A SMARTER SELECTION LATER. FOR NOW, WE SELECT THE FIRST ONE WE SEE) m_selectedPhysicalDevice = m_physicalDevices[0]; - // LOAD THE FAMILLY QUEUE PROPERTIES + // FETCH THE QUANTITY OF FAMILY QUEUE TO RESERVE SPACE IN THE VECTOR vkGetPhysicalDeviceQueueFamilyProperties(m_selectedPhysicalDevice, &m_queueFamilyCount, nullptr); std::vector queueFamilies(m_queueFamilyCount); + + // FILL THE VECTOR WITH ACTUAL QUEUE DATA vkGetPhysicalDeviceQueueFamilyProperties(m_selectedPhysicalDevice, &m_queueFamilyCount, queueFamilies.data()); // CREATE THE SURFACE FOR RENDERING - SDL_Vulkan_CreateSurface(window, m_vkInst, &m_surface); + sdlSuccess = SDL_Vulkan_CreateSurface(window, m_vkInst, &m_surface); + if(sdlSuccess != SDL_TRUE) + { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error Getting Extensions: %s", SDL_GetError()); + exit(1); + } + else + { + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "VULKAN SURFACE CREATED SUCCESSFULLY"); + } - // ??? + // NOT SURE WHAT THIS DOES YET, WILL CHECK IN THE TUTORIAL uint32_t graphicsQueueIndex = UINT32_MAX; uint32_t presentQueueIndex = UINT32_MAX; VkBool32 support; @@ -58,7 +108,11 @@ namespace ConjureEngine { VK_QUEUE_GRAPHICS_BIT) graphicsQueueIndex = i; if (presentQueueIndex == UINT32_MAX) { - vkGetPhysicalDeviceSurfaceSupportKHR(m_selectedPhysicalDevice, i, m_surface, &support); + vk_result = vkGetPhysicalDeviceSurfaceSupportKHR(m_selectedPhysicalDevice, i, m_surface, &support); + if(vk_result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Error while checking the surface capability: CODE = %d", static_cast(vk_result)); + } + if (support) presentQueueIndex = i; } @@ -94,12 +148,13 @@ namespace ConjureEngine { // CREATE VIRTUAL DEVICE FOR RENDERING - VkResult result = vkCreateDevice(m_selectedPhysicalDevice, &m_deviceCreateInfo, nullptr, &m_device); - if(result != VkResult::VK_SUCCESS) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Error while creating the device: %d", static_cast(result)); + vk_result = vkCreateDevice(m_selectedPhysicalDevice, &m_deviceCreateInfo, nullptr, &m_device); + if(vk_result != VkResult::VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Error while creating the device: %d", static_cast(vk_result)); + exit(1); } else { - SDL_Log("DEVICE CREATED SUCCESSFULLY"); + SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "DEVICE CREATED SUCCESSFULLY"); } vkGetDeviceQueue(m_device, graphicsQueueIndex, 0, &m_graphicQueue); diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp index 63bf2fc..e678e6f 100644 --- a/ConjureEngine/src/ConjureEngine/Window.cpp +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -19,7 +19,11 @@ namespace ConjureEngine { SDL_Vulkan_UnloadLibrary(); SDL_Quit(); - SDL_Log("Cleaned up with errors: %s", SDL_GetError()); + std::string error = SDL_GetError(); + if(!error.empty()) + { + SDL_Log("Cleaned up with errors: %s", error); + } } SDL_Window* Window::GetWindow() const diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index da119e8..9425f1a 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -21,22 +21,22 @@ namespace Demo1 { void Demo1::Awake() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - AWAKING"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"AWAKING"); } void Demo1::Start() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - STARTING"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"STARTING"); } void Demo1::Tick(double deltaTime) { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[DEMO1 - TRACE] - TICKING %f", deltaTime); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "TICKING %f", deltaTime); } void Demo1::Destroy() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - DESTROYING"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"DESTROYING"); } } // Demo1 diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 9ad6781..004ff01 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -1,14 +1,94 @@ #define SDL_MAIN_HANDLED +#include +#include + #include "Demo1.h" +static std::ofstream logFile; + +void OutputLog(void *userdata, int category, SDL_LogPriority priority, const char *message) +{ + (void)userdata; + + std::string categoryString; + switch (category) + { + case SDL_LOG_CATEGORY_APPLICATION: + categoryString = "Application"; + break; + case SDL_LOG_CATEGORY_ERROR: + categoryString = "Error"; + break; + case SDL_LOG_CATEGORY_ASSERT: + categoryString = "Assert"; + break; + case SDL_LOG_CATEGORY_SYSTEM: + categoryString = "System"; + break; + case SDL_LOG_CATEGORY_AUDIO: + categoryString = "Audio"; + break; + case SDL_LOG_CATEGORY_VIDEO: + categoryString = "Video"; + break; + case SDL_LOG_CATEGORY_RENDER: + categoryString = "Render"; + break; + case SDL_LOG_CATEGORY_INPUT: + categoryString = "Input"; + break; + case SDL_LOG_CATEGORY_TEST: + categoryString = "Test"; + break; + default: + categoryString = ""; + break; + } + + std::string priorityString; + switch (priority) + { + case SDL_LOG_PRIORITY_VERBOSE: + priorityString = "VERBOSE"; + break; + case SDL_LOG_PRIORITY_DEBUG: + priorityString = "DEBUG"; + break; + case SDL_LOG_PRIORITY_INFO: + priorityString = "INFO"; + break; + case SDL_LOG_PRIORITY_WARN: + priorityString = "WARN"; + break; + case SDL_LOG_PRIORITY_ERROR: + priorityString = "ERROR"; + break; + case SDL_LOG_PRIORITY_CRITICAL: + priorityString = "CRITICAL"; + break; + default: + std::cout << message << "\n"; + break; + } + + logFile << "[" << categoryString << " - " << priorityString << "] " << message << "\n"; + std::cout << "[" << categoryString << " - " << priorityString << "] " << message << "\n"; +} + int main ( int argc, char* argv[] ) { + logFile = std::ofstream{"log.txt"}; SDL_SetMainReady(); + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); + SDL_LogSetOutputFunction(&OutputLog, nullptr); + // I WANT TO CREATE AN APP Demo1::Demo1 app; // AND THEN START IT - return app.Run(); + int status = app.Run(); + + return status; } \ No newline at end of file From 63d9eb10819fe818461f45f1ceeee3f56188c7e9 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Tue, 26 Nov 2024 21:19:50 -0500 Subject: [PATCH 16/18] CONGE-2 ADDED THE SHADER COMPILATION FROM GLSL TO SPIRV --- ConjureEngine/docs/RenderingPipelineSteps.mmd | 41 ++++++++++++++++++ ConjureEngine/docs/renderingPipeline.mmd | 28 ++++++++++++ Demo1/.gitignore | 4 +- Demo1/CMakeLists.txt | 10 +++++ Demo1/CompileShaders.py | 43 +++++++++++++++++++ Demo1/src/Demo1.cpp | 8 ++-- Demo1/src/Shaders/Test.frag | 7 +++ Demo1/src/Shaders/Test.vert | 5 +++ Demo1/src/main.cpp | 4 +- 9 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 ConjureEngine/docs/RenderingPipelineSteps.mmd create mode 100644 ConjureEngine/docs/renderingPipeline.mmd create mode 100644 Demo1/CompileShaders.py create mode 100644 Demo1/src/Shaders/Test.frag create mode 100644 Demo1/src/Shaders/Test.vert diff --git a/ConjureEngine/docs/RenderingPipelineSteps.mmd b/ConjureEngine/docs/RenderingPipelineSteps.mmd new file mode 100644 index 0000000..b5a2ff5 --- /dev/null +++ b/ConjureEngine/docs/RenderingPipelineSteps.mmd @@ -0,0 +1,41 @@ +--- +title: Rendering Pipeline Steps +--- +stateDiagram-v2 + direction LR + state "Data" as Data1 + state "Vertex Shader" as VertexShader1 + state "Tesselation Shader" as TesselationShader1 + state "Rasterization" as Rasterization1 + state "Fragment Shader" as FragmentShader1 + state "Blending" as Blending1 + state "Texture" as Texture1 + + state "Texture" as Texture2 + state "Vertex Shader" as VertexShader2 + state "Tesselation Shader" as TesselationShader2 + state "Rasterization" as Rasterization2 + state "Fragment Shader" as FragmentShader2 + state "Blending" as Blending2 + state "Frame Buffer" as FrameBuffer2 + + Data1 --> VertexShader1 + state "Pass 1" as Pass1{ + direction LR + VertexShader1 --> TesselationShader1 + TesselationShader1 --> Rasterization1 + Rasterization1 --> FragmentShader1 + FragmentShader1 --> Blending1 + } + Blending1 --> Texture1 + + + Texture2 --> VertexShader2 + state "Pass 2" as Pass2{ + direction LR + VertexShader2 --> TesselationShader2 + TesselationShader2 --> Rasterization2 + Rasterization2 --> FragmentShader2 + FragmentShader2 --> Blending2 + } + Blending2 --> FrameBuffer2 \ No newline at end of file diff --git a/ConjureEngine/docs/renderingPipeline.mmd b/ConjureEngine/docs/renderingPipeline.mmd new file mode 100644 index 0000000..6a9a952 --- /dev/null +++ b/ConjureEngine/docs/renderingPipeline.mmd @@ -0,0 +1,28 @@ +--- +title: Rendering Pipeline +--- +classDiagram + class VAO + class VBO + class Shader + class Pipeline0 + class Pipeline1 + class Pipeline2 + + class Entity0 + class Entity1 + class Entity2 + + Entity0 -- Pipeline0 + Entity0 -- Pipeline1 + Entity0 -- Pipeline2 + + Entity1 -- Pipeline0 + Entity1 -- Pipeline1 + + Entity2 -- Pipeline1 + Entity2 -- Pipeline2 + + Pipeline0 -- Shader + Pipeline1 -- Shader + Pipeline2 -- Shader \ No newline at end of file diff --git a/Demo1/.gitignore b/Demo1/.gitignore index e210f52..bc5d3a8 100644 --- a/Demo1/.gitignore +++ b/Demo1/.gitignore @@ -1,3 +1,5 @@ CMakeFiles/ cmake_install.cmake -CMakeUserPresets.json \ No newline at end of file +CMakeUserPresets.json +CompileShaders.log +**/*.spv \ No newline at end of file diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index 870ccb1..d39fedd 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -3,11 +3,21 @@ project(Demo1) set(CMAKE_CXX_STANDARD 20) +find_package(Python3 REQUIRED COMPONENTS Interpreter) + + add_executable(${PROJECT_NAME} src/main.cpp src/Demo1.cpp src/Demo1.h ) +# SHADERS +add_custom_command( + TARGET ${PROJECT_NAME} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CompileShaders.py ${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders + COMMENT "Compiling shaders" +) + target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) find_package(SDL2 REQUIRED) diff --git a/Demo1/CompileShaders.py b/Demo1/CompileShaders.py new file mode 100644 index 0000000..d5c49bc --- /dev/null +++ b/Demo1/CompileShaders.py @@ -0,0 +1,43 @@ +import os +import sys +import subprocess +import logging + +os.chdir(sys.argv[1]) + +# Configure logging +logging.basicConfig( + filename=os.path.join("D:/Dev/ETS/CONJURE/conjure-engine/Demo1", "CompileShaders.log"), # Log file name + filemode="w", # Append mode (use "w" for overwrite) + format="%(asctime)s - %(levelname)s - %(message)s", # Log format + level=logging.INFO # Logging level +) + + +SHADERS_PATH = os.path.join(os.getcwd()) +GLSLC_PATH = os.path.join(os.environ.get("VULKAN_SDK"), "bin", "glslc") + +def filterFunc(fileName): + logging.info(fileName) + name, ext = fileName.split(".") + return ext != "spv" + +def __main__(): + logging.info("SHADER PATH: " + SHADERS_PATH) + logging.info("GLSLC PATH:" + GLSLC_PATH) + + shaders = filter(filterFunc, os.listdir(SHADERS_PATH)) + for shader in shaders: + name, ext = shader.split(".") + + command = GLSLC_PATH + args = [ + os.path.join(SHADERS_PATH, shader), + "-o", + os.path.join(SHADERS_PATH, name + "." + ext + ".spv") + ] + + logging.info(command + " " + str.join(" ", args)) + subprocess.run(command + " " + str.join(" ", args)) +if __name__ == "__main__": + __main__() \ No newline at end of file diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index 9425f1a..5d7705f 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -21,22 +21,22 @@ namespace Demo1 { void Demo1::Awake() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"AWAKING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"AWAKING"); } void Demo1::Start() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"STARTING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"STARTING"); } void Demo1::Tick(double deltaTime) { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "TICKING %f", deltaTime); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "TICKING %f", deltaTime); } void Demo1::Destroy() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"DESTROYING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"DESTROYING"); } } // Demo1 diff --git a/Demo1/src/Shaders/Test.frag b/Demo1/src/Shaders/Test.frag new file mode 100644 index 0000000..2801bac --- /dev/null +++ b/Demo1/src/Shaders/Test.frag @@ -0,0 +1,7 @@ +#version 460 core + +layout (location = 0) out vec4 oColor; + +void main() { + oColor = vec4(1); +} \ No newline at end of file diff --git a/Demo1/src/Shaders/Test.vert b/Demo1/src/Shaders/Test.vert new file mode 100644 index 0000000..4a76a79 --- /dev/null +++ b/Demo1/src/Shaders/Test.vert @@ -0,0 +1,5 @@ +#version 460 core + +void main() { + gl_Position = vec4(0); +} \ No newline at end of file diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 004ff01..106453e 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -88,7 +88,5 @@ int main ( int argc, char* argv[] ) Demo1::Demo1 app; // AND THEN START IT - int status = app.Run(); - - return status; + return app.Run(); } \ No newline at end of file From 2e2dd848f72dfd48801667082ad87b0a0c57c09a Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Tue, 26 Nov 2024 22:09:39 -0500 Subject: [PATCH 17/18] CONGE-2 MADE THE MAC COMPILATION WORK --- ConjureEngine/src/ConjureEngine/Window.cpp | 2 +- Demo1/CMakeLists.txt | 23 +++++++++++++++---- Demo1/CompileShaders.py | 26 ++++++++++++---------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/ConjureEngine/src/ConjureEngine/Window.cpp b/ConjureEngine/src/ConjureEngine/Window.cpp index e678e6f..a927927 100644 --- a/ConjureEngine/src/ConjureEngine/Window.cpp +++ b/ConjureEngine/src/ConjureEngine/Window.cpp @@ -22,7 +22,7 @@ namespace ConjureEngine { std::string error = SDL_GetError(); if(!error.empty()) { - SDL_Log("Cleaned up with errors: %s", error); + SDL_Log("Cleaned up with errors: %s", error.c_str()); } } diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index d39fedd..a7bb35f 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -5,19 +5,34 @@ set(CMAKE_CXX_STANDARD 20) find_package(Python3 REQUIRED COMPONENTS Interpreter) +set(SHADER_FILES + src/Shaders/Test.frag + src/Shaders/Test.vert +) -add_executable(${PROJECT_NAME} src/main.cpp +add_executable(${PROJECT_NAME} + src/main.cpp src/Demo1.cpp src/Demo1.h ) -# SHADERS +# STAMP FILE THAT TRACK THE CHANGES IN SHADERS +set(OUTPUT_SHADER_STAMP "${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders/shaders.stamp") + +# COMPILE SHADERS USING PYTHON add_custom_command( - TARGET ${PROJECT_NAME} - COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CompileShaders.py ${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders + OUTPUT ${OUTPUT_SHADER_STAMP} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CompileShaders.py ${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${SHADER_FILES} COMMENT "Compiling shaders" ) +# CREATE CUSTOM TARGET THAT LINK THE COMMAND TO THE PROJECT +add_custom_target(shader_compilation DEPENDS ${OUTPUT_SHADER_STAMP}) + +# ADD THE CUSTOM TARGET AS A DEPENDENCY +add_dependencies(${PROJECT_NAME} shader_compilation) + target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) find_package(SDL2 REQUIRED) diff --git a/Demo1/CompileShaders.py b/Demo1/CompileShaders.py index d5c49bc..3ad4277 100644 --- a/Demo1/CompileShaders.py +++ b/Demo1/CompileShaders.py @@ -7,24 +7,25 @@ os.chdir(sys.argv[1]) # Configure logging logging.basicConfig( - filename=os.path.join("D:/Dev/ETS/CONJURE/conjure-engine/Demo1", "CompileShaders.log"), # Log file name + filename=os.path.join(sys.argv[2], "CompileShaders.log"), # Log file name filemode="w", # Append mode (use "w" for overwrite) format="%(asctime)s - %(levelname)s - %(message)s", # Log format level=logging.INFO # Logging level ) - -SHADERS_PATH = os.path.join(os.getcwd()) -GLSLC_PATH = os.path.join(os.environ.get("VULKAN_SDK"), "bin", "glslc") - def filterFunc(fileName): - logging.info(fileName) - name, ext = fileName.split(".") - return ext != "spv" + params = fileName.split(".") + return params[len(params) - 1] != "spv" def __main__(): - logging.info("SHADER PATH: " + SHADERS_PATH) - logging.info("GLSLC PATH:" + GLSLC_PATH) + SHADERS_PATH = os.path.join(os.getcwd()) + if os.name == "nt": + GLSLC_PATH = os.path.join(os.environ.get("VULKAN_SDK"), "bin", "glslc") + else: + GLSLC_PATH = "/usr/local/bin/glslc" + + logging.info(str.join(" ", ["SHADER PATH:", SHADERS_PATH])) + logging.info(str.join(" ", ["GLSLC PATH:", GLSLC_PATH])) shaders = filter(filterFunc, os.listdir(SHADERS_PATH)) for shader in shaders: @@ -37,7 +38,8 @@ def __main__(): os.path.join(SHADERS_PATH, name + "." + ext + ".spv") ] - logging.info(command + " " + str.join(" ", args)) - subprocess.run(command + " " + str.join(" ", args)) + logging.info(str.join(" ", ["Compiling:", shader])) + logging.info(str.join(" ", [command] + args)) + subprocess.Popen([command] + args) if __name__ == "__main__": __main__() \ No newline at end of file From b4a706ca12766ef09d17b0987835e3e53d08c086 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Tue, 26 Nov 2024 22:25:08 -0500 Subject: [PATCH 18/18] CONGE-2 UPDATED CMAKE CONFIG --- Demo1/CMakeLists.txt | 19 +++---------------- Demo1/CompileShaders.py | 1 + 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index a7bb35f..b4c0794 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -5,32 +5,19 @@ set(CMAKE_CXX_STANDARD 20) find_package(Python3 REQUIRED COMPONENTS Interpreter) -set(SHADER_FILES - src/Shaders/Test.frag - src/Shaders/Test.vert -) - add_executable(${PROJECT_NAME} src/main.cpp src/Demo1.cpp src/Demo1.h ) -# STAMP FILE THAT TRACK THE CHANGES IN SHADERS -set(OUTPUT_SHADER_STAMP "${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders/shaders.stamp") - -# COMPILE SHADERS USING PYTHON -add_custom_command( - OUTPUT ${OUTPUT_SHADER_STAMP} +# CREATE CUSTOM TARGET THAT COMPILE SHADERS EVERY BUILD +add_custom_target(shader_compilation ALL COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CompileShaders.py ${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${SHADER_FILES} COMMENT "Compiling shaders" ) -# CREATE CUSTOM TARGET THAT LINK THE COMMAND TO THE PROJECT -add_custom_target(shader_compilation DEPENDS ${OUTPUT_SHADER_STAMP}) - -# ADD THE CUSTOM TARGET AS A DEPENDENCY +# ADD THE CUSTOM TARGET AS A DEPENDENCY OF DEMO1 add_dependencies(${PROJECT_NAME} shader_compilation) target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) diff --git a/Demo1/CompileShaders.py b/Demo1/CompileShaders.py index 3ad4277..0cf7f44 100644 --- a/Demo1/CompileShaders.py +++ b/Demo1/CompileShaders.py @@ -18,6 +18,7 @@ def filterFunc(fileName): return params[len(params) - 1] != "spv" def __main__(): + SHADERS_PATH = os.path.join(os.getcwd()) if os.name == "nt": GLSLC_PATH = os.path.join(os.environ.get("VULKAN_SDK"), "bin", "glslc")