diff --git a/.gitmodules b/.gitmodules index 3b294c3..787e89e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -39,4 +39,7 @@ url = https://github.com/shader-slang/slang.git [submodule "dependencies/libFGL"] path = dependencies/libFGL - url = git@github.com:KJNeko/libFGL.git \ No newline at end of file + url = git@github.com:KJNeko/libFGL.git +[submodule "dependencies/gtest"] + path = dependencies/gtest + url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ab8811..afd9d30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.25.0) set(CMAKE_CXX_STANDARD 26) -set(CMAKE_CXX_STANDARD_REQUIRED ON) project(TitorGameEngine LANGUAGES CXX C) @@ -14,7 +13,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") message("-- CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") string(TOUPPER ${CMAKE_BUILD_TYPE} UPPER_BUILD_TYPE) -add_subdirectory(dependencies/vma) include(dependencies/glfw) include(dependencies/glm) include(cmake_modules/dependencies/tracy.cmake) diff --git a/cmake_modules/dependencies/vulkan.cmake b/cmake_modules/dependencies/vulkan.cmake index da6afe0..40de10a 100644 --- a/cmake_modules/dependencies/vulkan.cmake +++ b/cmake_modules/dependencies/vulkan.cmake @@ -3,4 +3,38 @@ if (NOT Vulkan_FOUND) error("Vulkan not found") endif () +#add_library(VulkanCppModule) +#add_library(Vulkan::cppm ALIAS VulkanCppModule) +# +#target_compile_definitions(VulkanCppModule PUBLIC +# VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 +# VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1 +# VULKAN_HPP_NO_STD_MODULE=1 +#) +# +#target_include_directories(VulkanCppModule PRIVATE "${Vulkan_INCLUDE_DIR}") +# +#target_link_libraries(VulkanCppModule PUBLIC Vulkan::Vulkan) +# +#target_sources(VulkanCppModule +# PUBLIC +# FILE_SET cxx_modules TYPE CXX_MODULES +# BASE_DIRS "${Vulkan_INCLUDE_DIR}" +# FILES "${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm" +#) +# +#if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28" AND VULKAN_HEADERS_ENABLE_MODULE AND COMPILER_SUPPORTS_CXX_MODULES) +# add_library(Vulkan-Module) +# add_library(Vulkan::VulkanHppModule ALIAS Vulkan-Module) +# target_sources(Vulkan-Module +# PUBLIC +# FILE_SET module +# TYPE CXX_MODULES +# BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" +# FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan.cppm" +# ) +# target_compile_features(Vulkan-Module PUBLIC cxx_std_20) +# target_link_libraries(Vulkan-Module PUBLIC Vulkan-Headers) +#endif () + message("Vulkan include: ${Vulkan_INCLUDE_DIR}") \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a61ef0..9f0ac4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ -add_subdirectory(vma) -add_subdirectory(engine) +add_subdirectory(renderer) add_subdirectory(objectloaders) -add_subdirectory(editor) +#add_subdirectory(editor) +#add_subdirectory(engine) message("-- Creating SYMLINK ${CMAKE_BINARY_DIR}/shaders -> ${CMAKE_CURRENT_SOURCE_DIR}/shaders") file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/shaders ${CMAKE_BINARY_DIR}/bin/shaders SYMBOLIC) diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index 1bdeef2..05772d9 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -2,6 +2,8 @@ set(CMAKE_CXX_STANDARD 23) +include(dependencies/imgui) + target_compile_definitions(FGLEngine PUBLIC VULKAN_HPP_FLAGS_MASK_TYPE_AS_PUBLIC) file(GLOB_RECURSE SOURCE_FILES diff --git a/src/editor/src/gui/drawStats.cpp b/src/editor/src/gui/drawStats.cpp index 2487bf0..8911ac5 100644 --- a/src/editor/src/gui/drawStats.cpp +++ b/src/editor/src/gui/drawStats.cpp @@ -9,7 +9,7 @@ #include "engine/debug/timing/FlameGraph.hpp" #include "engine/flags.hpp" #include "engine/math/literals/size.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" #include "safe_include.hpp" namespace fgl::engine::gui diff --git a/src/editor/src/gui/safe_include.hpp b/src/editor/src/gui/safe_include.hpp index 88d5a30..74abbee 100644 --- a/src/editor/src/gui/safe_include.hpp +++ b/src/editor/src/gui/safe_include.hpp @@ -2,6 +2,7 @@ // Created by kj16609 on 6/5/24. // + // ReSharper disable CppDFAInfiniteRecursion // ReSharper disable CppInconsistentNaming // ReSharper disable CppZeroConstantCanBeReplacedWithNullptr @@ -12,8 +13,6 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wconversion" // clang-format off -#include -#include // clang-format on #pragma GCC diagnostic pop diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 05220e9..098ee2f 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -11,24 +11,13 @@ target_compile_definitions(FGLEngine PUBLIC VULKAN_HPP_FLAGS_MASK_TYPE_AS_PUBLIC target_link_libraries(FGLEngine PUBLIC stdc++exp) include(dependencies/spdlog) -include(dependencies/imgui) target_link_libraries(FGLEngine PUBLIC Vulkan::Vulkan ImGui FGLLoader spdlog slang glm) target_include_directories(FGLEngine SYSTEM PUBLIC ${GLM_INCLUDE_DIRS}) -target_link_libraries(FGLEngine PUBLIC glfw Tracy::TracyClient VMA) +target_link_libraries(FGLEngine PUBLIC glfw Tracy::TracyClient) target_include_directories(FGLEngine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) target_compile_features(FGLEngine PUBLIC cxx_std_23) -target_precompile_headers(FGLEngine PUBLIC - - - - - - - -) - string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_UPPER_BUILD_TYPE) if (NOT DEFINED FGL_ENABLE_IMGUI AND CMAKE_UPPER_BUILD_TYPE STREQUAL "DEBUG") @@ -37,15 +26,6 @@ endif () message("-- FGL_ENABLE_IMGUI: ${FGL_ENABLE_IMGUI}") - -if (FGL_ENABLE_IMGUI) - target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI=1) - target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=1) -else () - target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI=0) - target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=0) -endif () - if (DEFINED FGL_ENABLE_TESTS AND FGL_ENABLE_TESTS) target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=1) target_compile_definitions(FGLEngine PUBLIC FGL_ENABLE_TEST_ASSERT=1) diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 2f7cbc2..1229a81 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -21,7 +21,7 @@ #include "engine/flags.hpp" #include "engine/math/Average.hpp" #include "engine/math/literals/size.hpp" -#include "memory/buffers/BufferHandle.hpp" +#include "memory/buffers/VulkanBuffer.hpp" #include "systems/RenderGraph.hpp" namespace fgl::engine diff --git a/src/engine/FGL_DEFINES.hpp b/src/engine/FGL_DEFINES.hpp deleted file mode 100644 index b4439c7..0000000 --- a/src/engine/FGL_DEFINES.hpp +++ /dev/null @@ -1,98 +0,0 @@ -// -// Created by kj16609 on 3/1/24. -// - -#pragma once - -#define FGL_DELETE_DEFAULT_CTOR( ClassName ) ClassName() = delete -#define FGL_DELETE_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = delete -#define FGL_DELETE_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = delete -#define FGL_DELETE_MOVE_ASSIGN( ClassName ) ClassName& operator=( ClassName&& ) = delete -#define FGL_DELETE_MOVE_CTOR( ClassName ) ClassName( ClassName&& ) = delete -#define FGL_DELETE_COPY( ClassName ) \ - FGL_DELETE_COPY_CTOR( ClassName ); \ - FGL_DELETE_COPY_ASSIGN( ClassName ) -#define FGL_DELETE_MOVE( ClassName ) \ - FGL_DELETE_MOVE_CTOR( ClassName ); \ - FGL_DELETE_MOVE_ASSIGN( ClassName ) -#define FGL_DELETE_ALL_RO5( ClassName ) \ - FGL_DELETE_DEFAULT_CTOR( ClassName ); \ - FGL_DELETE_COPY( ClassName ); \ - FGL_DELETE_MOVE( ClassName ) - -#define FGL_DEFAULT_DEFAULT_CTOR( ClassName ) ClassName() = default -#define FGL_DEFAULT_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = default -#define FGL_DEFAULT_COPY_CTOR( ClassName ) [[nodiscard]] ClassName( const ClassName& ) = default -#define FGL_DEFAULT_MOVE_ASSIGN( ClassName ) ClassName& operator=( ClassName&& ) = default -#define FGL_DEFAULT_MOVE_CTOR( ClassName ) [[nodiscard]] ClassName( ClassName&& ) = default -#define FGL_DEFAULT_COPY( ClassName ) \ - FGL_DEFAULT_COPY_CTOR( ClassName ); \ - FGL_DEFAULT_COPY_ASSIGN( ClassName ) -#define FGL_DEFAULT_MOVE( ClassName ) \ - FGL_DEFAULT_MOVE_CTOR( ClassName ); \ - FGL_DEFAULT_MOVE_ASSIGN( ClassName ) -#define FGL_DEFAULT_ALL_RO5( ClassName ) \ - FGL_DEFAULT_DEFAULT_CTOR( ClassName ); \ - FGL_DEFAULT_COPY( ClassName ); \ - FGL_DEFAULT_MOVE( ClassName ) - -#define FGL_PACKED __attribute__( ( packed ) ) -#define FGL_PACKED_ALIGNED( al ) __attribute__( ( packed, aligned( al ) ) ) -#define FGL_FLATTEN [[gnu::flatten]] -#define FGL_ARTIFICIAL [[gnu::artificial]] -#define FGL_HOT [[gnu::hot]] -#define FGL_COLD [[gnu::cold]] -#define FGL_FLATTEN_HOT FGL_FLATTEN FGL_HOT -#define FGL_FORCE_INLINE [[gnu::always_inline]] -#define FGL_FORCE_INLINE_FLATTEN FGL_FLATTEN FGL_FORCE_INLINE - -#ifndef NDEBUG -#define FGL_ASSUME( ... ) \ - FGL_ASSERT( ( __VA_ARGS__ ), "FGL_ASSUME: Check failed!" ); \ - [[gnu::assume( __VA_ARGS__ )]]; -#else -#define FGL_ASSUME( ... ) [[gnu::assume( __VA_ARGS__ )]] -#endif - -#define FGL_ALIGN( bytesize ) [[gnu::alligned( bitsize )]] - -#define FGL_FUNC_CLEANUP( func ) [[gnu::cleanup( func )]] - -//! Warns if the variable is used as a string (strlen) -#define FGL_NONSTRING_DATA [[gnu::nonstring]] - -//! Warns if the structure field is not alligned with a set number of bytes -#define FGL_STRICT_ALIGNMENT( bytesize ) [[gnu::warn_if_not_aligned( bytesize )]] - -#ifndef NDEBUG -#include -#include -#pragma GCC diagnostic push -// Placed here to prevent strict warnings from preventing compilation, This is intentional. -#pragma GCC diagnostic ignored "-Wterminate" -#define FGL_ASSERT( test, msg ) \ - if ( !( test ) ) \ - throw std::runtime_error( std::format( "{}:{}:{}: {}", __FILE__, __LINE__, __PRETTY_FUNCTION__, msg ) ); -#pragma GCC diagnostic pop -#else -#define FGL_ASSERT( test, msg ) -#endif - -#define FGL_UNIMPLEMENTED() FGL_ASSERT( false, "unimplemented" ); - -#ifndef NDEBUG -#include -#define FGL_UNREACHABLE() \ - FGL_ASSERT( false, "Should have been unreachable!" ); \ - std::unreachable() -#else -#define FGL_UNREACHABLE() std::unreachable() -#endif - -#define FGL_NOTNAN( value ) FGL_ASSERT( !std::isnan( value ), "Value is NaN!" ) -#define FGL_NOTNANVEC3( vec3 ) \ - FGL_ASSERT( !std::isnan( ( vec3 ).x ), "X value was NaN!" ); \ - FGL_ASSERT( !std::isnan( ( vec3 ).y ), "Y value was NaN!" ); \ - FGL_ASSERT( !std::isnan( ( vec3 ).z ), "Z value was NaN!" ) - -#define FGL_TODO() throw std::runtime_error( std::format( "TODO: {}:{}:{}", __FILE__, __LINE__, __PRETTY_FUNCTION__ ) ); diff --git a/src/engine/FrameInfo.hpp b/src/engine/FrameInfo.hpp index 66996e1..e1909eb 100644 --- a/src/engine/FrameInfo.hpp +++ b/src/engine/FrameInfo.hpp @@ -21,6 +21,7 @@ namespace fgl::engine { + class RenderGraph; class CameraViewpoint; struct PrimitiveRenderInfo; diff --git a/src/engine/assets/AssetManager.hpp b/src/engine/assets/AssetManager.hpp index 2b7fc27..682fb6b 100644 --- a/src/engine/assets/AssetManager.hpp +++ b/src/engine/assets/AssetManager.hpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace fgl::engine diff --git a/src/engine/assets/MaterialManager.cpp b/src/engine/assets/MaterialManager.cpp index 96793b1..d4748e1 100644 --- a/src/engine/assets/MaterialManager.cpp +++ b/src/engine/assets/MaterialManager.cpp @@ -6,7 +6,7 @@ #include "engine/debug/logging/logging.hpp" #include "engine/math/literals/size.hpp" #include "material/Material.hpp" -#include "memory/buffers/BufferHandle.hpp" +#include "memory/buffers/VulkanBuffer.hpp" namespace fgl::engine { diff --git a/src/engine/assets/MaterialManager.hpp b/src/engine/assets/MaterialManager.hpp index 762f052..8c40cee 100644 --- a/src/engine/assets/MaterialManager.hpp +++ b/src/engine/assets/MaterialManager.hpp @@ -3,7 +3,7 @@ // #pragma once -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" #include "material/Material.hpp" #include "memory/buffers/vector/DeviceVector.hpp" diff --git a/src/engine/assets/image/ImageHandle.hpp b/src/engine/assets/image/ImageHandle.hpp index dc99253..8e0944c 100644 --- a/src/engine/assets/image/ImageHandle.hpp +++ b/src/engine/assets/image/ImageHandle.hpp @@ -10,7 +10,7 @@ #include "engine/debug/logging/logging.hpp" #include "engine/rendering/devices/Device.hpp" -#include "vma/vma_impl.hpp" +#include "memory/vma_impl.hpp" #include "vulkan/vulkan.hpp" namespace fgl::engine diff --git a/src/engine/assets/material/Material.cpp b/src/engine/assets/material/Material.cpp index a023e0c..c649d56 100644 --- a/src/engine/assets/material/Material.cpp +++ b/src/engine/assets/material/Material.cpp @@ -15,14 +15,14 @@ namespace fgl::engine inline static IDPool< MaterialID > material_id_counter { 1 }; + TextureID getTexID( const std::shared_ptr< Texture >& tex ) + { + if ( tex ) return tex->getID(); + return constants::INVALID_TEXTURE_ID; + } + void MaterialProperties::writeData( DeviceMaterialData& data ) const { - auto getTexID = []( const std::shared_ptr< Texture >& tex ) - { - if ( tex ) return tex->getID(); - return constants::INVALID_TEXTURE_ID; - }; - // PBR data.color.color_texture_id = getTexID( m_pbr.m_color_tex ); data.color.color_factors = m_pbr.m_color_factors; diff --git a/src/engine/assets/model/Model.hpp b/src/engine/assets/model/Model.hpp index 2a3215d..f008f19 100644 --- a/src/engine/assets/model/Model.hpp +++ b/src/engine/assets/model/Model.hpp @@ -32,13 +32,15 @@ namespace fgl::engine namespace memory { - class BufferHandle; + class VulkanBuffer; } struct ModelBuilder; ModelGPUBuffers& getModelBuffers(); + + // Primitive render info, Contains the vertex and index info constexpr descriptors::Descriptor RENDER_INFO_DESCRIPTOR { 0, vk::DescriptorType::eStorageBuffer, diff --git a/src/engine/assets/model/ModelVertex.cpp b/src/engine/assets/model/ModelVertex.cpp index c953dda..43c166e 100644 --- a/src/engine/assets/model/ModelVertex.cpp +++ b/src/engine/assets/model/ModelVertex.cpp @@ -11,6 +11,8 @@ #include #pragma GCC diagnostic pop +#include + #include "Model.hpp" #include "ModelInstance.hpp" #include "VertexAttribute.hpp" @@ -39,24 +41,23 @@ namespace fgl::engine { AttributeBuilder builder { SimpleVertex::getAttributeDescriptions() }; -#pragma GCC diagnostic push // TODO: Fix with reflection once we get it in 20 years -#pragma GCC diagnostic ignored "-Winvalid-offsetof" // builder.add< decltype( ModelVertex::m_position ), offsetof( ModelVertex, m_position ) >( 0 ); // builder.add< decltype( ModelVertex::m_color ), offsetof( ModelVertex, m_color ) >( 0 ); - builder.add< decltype( ModelVertex::m_normal ), offsetof( ModelVertex, m_normal ) >( 0 ); - builder.add< decltype( ModelVertex::m_tangent ), offsetof( ModelVertex, m_tangent ) >( 0 ); - builder.add< decltype( ModelVertex::m_uv ), offsetof( ModelVertex, m_uv ) >( 0 ); -#pragma GCC diagnostic pop + builder.add< decltype( ModelVertex::m_normal ), std::meta::offset_of( ^^ModelVertex::m_normal ).bytes >( 0 ); + builder.add< decltype( ModelVertex::m_tangent ), std::meta::offset_of( ^^ModelVertex::m_tangent ).bytes >( 0 ); + builder.add< decltype( ModelVertex::m_uv ), std::meta::offset_of( ^^ModelVertex::m_uv ).bytes >( 0 ); - builder - .add< decltype( InstanceRenderInfo::m_model_matrix ), offsetof( InstanceRenderInfo, m_model_matrix ) >( 1 ); + builder.add< + decltype( InstanceRenderInfo::m_model_matrix ), + std::meta::offset_of( ^^InstanceRenderInfo::m_model_matrix ).bytes >( 1 ); // builder.add< // decltype( InstanceRenderInfo::m_normal_matrix ), // offsetof( InstanceRenderInfo, m_normal_matrix ) >( 1 ); - builder - .add< decltype( InstanceRenderInfo::m_material_id ), offsetof( InstanceRenderInfo, m_material_id ) >( 1 ); + builder.add< + decltype( InstanceRenderInfo::m_material_id ), + std::meta::offset_of( ^^InstanceRenderInfo::m_material_id ).bytes >( 1 ); return builder.get(); } diff --git a/src/engine/assets/model/SimpleVertex.cpp b/src/engine/assets/model/SimpleVertex.cpp index f315625..d0078ef 100644 --- a/src/engine/assets/model/SimpleVertex.cpp +++ b/src/engine/assets/model/SimpleVertex.cpp @@ -4,6 +4,7 @@ #include "SimpleVertex.hpp" +#include #include #include "ModelVertex.hpp" @@ -28,8 +29,9 @@ namespace fgl::engine { AttributeBuilder builder {}; - builder.add< decltype( SimpleVertex::m_position ), offsetof( SimpleVertex, m_position ) >( 0 ); - builder.add< decltype( SimpleVertex::m_color ), offsetof( SimpleVertex, m_color ) >( 0 ); + builder + .add< decltype( SimpleVertex::m_position ), std::meta::offset_of( ^^SimpleVertex::m_position ).bytes >( 0 ); + builder.add< decltype( SimpleVertex::m_color ), std::meta::offset_of( ^^SimpleVertex::m_color ).bytes >( 0 ); return builder.get(); } diff --git a/src/engine/assets/model/VertexAttribute.hpp b/src/engine/assets/model/VertexAttribute.hpp index 224975f..8100d00 100644 --- a/src/engine/assets/model/VertexAttribute.hpp +++ b/src/engine/assets/model/VertexAttribute.hpp @@ -21,7 +21,7 @@ namespace fgl::engine { return vk::Format::eR32G32B32Sfloat; } - else if constexpr ( std::same_as< T, glm::vec4 > || std ::same_as< T, glm::mat4 > ) + else if constexpr ( std::same_as< T, glm::vec4 > || std::same_as< T, glm::mat4 > ) { return vk::Format::eR32G32B32A32Sfloat; } diff --git a/src/engine/assets/model/builders/ModelBuilder.hpp b/src/engine/assets/model/builders/ModelBuilder.hpp index aec856a..650b352 100644 --- a/src/engine/assets/model/builders/ModelBuilder.hpp +++ b/src/engine/assets/model/builders/ModelBuilder.hpp @@ -8,7 +8,7 @@ #include #include "engine/primitives/Transform.hpp" -#include "memory/buffers/BufferHandle.hpp" +#include "memory/buffers/VulkanBuffer.hpp" namespace fgl::engine { diff --git a/src/engine/assets/model/builders/SceneBuilder.hpp b/src/engine/assets/model/builders/SceneBuilder.hpp index 937e799..fe65416 100644 --- a/src/engine/assets/model/builders/SceneBuilder.hpp +++ b/src/engine/assets/model/builders/SceneBuilder.hpp @@ -21,7 +21,7 @@ namespace fgl::engine namespace memory { - class BufferHandle; + class VulkanBuffer; } } // namespace fgl::engine diff --git a/src/engine/assets/texture/Texture.cpp b/src/engine/assets/texture/Texture.cpp index 9b35925..0aaa8b9 100644 --- a/src/engine/assets/texture/Texture.cpp +++ b/src/engine/assets/texture/Texture.cpp @@ -136,9 +136,7 @@ namespace fgl::engine memory::TransferManager::getInstance() .copyToImage( std::forward< std::vector< std::byte > >( data ), *m_image ); -#if ENABLE_IMGUI createImGuiSet(); -#endif } Texture::Texture( const std::filesystem::path& path, Sampler&& sampler, const vk::Format format ) : diff --git a/src/engine/assets/texture/Texture.hpp b/src/engine/assets/texture/Texture.hpp index 59abc29..a761b60 100644 --- a/src/engine/assets/texture/Texture.hpp +++ b/src/engine/assets/texture/Texture.hpp @@ -15,6 +15,8 @@ #include "engine/constants.hpp" #include "engine/types.hpp" +struct ImTextureRef; + namespace fgl::engine { class Sampler; diff --git a/src/engine/assets/transfer/TransferData.cpp b/src/engine/assets/transfer/TransferData.cpp index ec40398..f74acd8 100644 --- a/src/engine/assets/transfer/TransferData.cpp +++ b/src/engine/assets/transfer/TransferData.cpp @@ -6,7 +6,7 @@ #include "engine/assets/image/ImageHandle.hpp" #include "engine/debug/logging/logging.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" #include "engine/memory/buffers/exceptions.hpp" #include "engine/memory/buffers/vector/HostVector.hpp" #include "engine/utils.hpp" diff --git a/src/engine/assets/transfer/TransferData.hpp b/src/engine/assets/transfer/TransferData.hpp index 29a966b..80fb41c 100644 --- a/src/engine/assets/transfer/TransferData.hpp +++ b/src/engine/assets/transfer/TransferData.hpp @@ -9,7 +9,7 @@ #include #include -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" namespace vk { @@ -29,7 +29,7 @@ namespace fgl::engine namespace memory { class BufferSuballocationHandle; - class BufferHandle; + class VulkanBuffer; } // namespace memory } // namespace fgl::engine diff --git a/src/engine/assets/transfer/TransferManager.cpp b/src/engine/assets/transfer/TransferManager.cpp index 0cdc4c2..db33a61 100644 --- a/src/engine/assets/transfer/TransferManager.cpp +++ b/src/engine/assets/transfer/TransferManager.cpp @@ -8,18 +8,10 @@ #include "engine/assets/image/ImageHandle.hpp" #include "engine/assets/texture/Texture.hpp" #include "engine/math/literals/size.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" #include "engine/memory/buffers/BufferSuballocation.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" #include "engine/memory/buffers/vector/HostVector.hpp" -#ifdef ENABLE_IMGUI -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" -#include -#pragma GCC diagnostic pop -#endif - namespace fgl::engine::memory { void TransferManager::recordCommands( vk::raii::CommandBuffer& command_buffer ) diff --git a/src/engine/assets/transfer/TransferManager.hpp b/src/engine/assets/transfer/TransferManager.hpp index 736df16..a6b38e3 100644 --- a/src/engine/assets/transfer/TransferManager.hpp +++ b/src/engine/assets/transfer/TransferManager.hpp @@ -26,6 +26,7 @@ namespace fgl::engine class BufferSuballocation; } // namespace memory + } // namespace fgl::engine namespace fgl::engine::memory diff --git a/src/engine/camera/CameraManager.hpp b/src/engine/camera/CameraManager.hpp index e863148..288a586 100644 --- a/src/engine/camera/CameraManager.hpp +++ b/src/engine/camera/CameraManager.hpp @@ -6,7 +6,7 @@ #include #include "RenderCamera.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" namespace fgl::engine { diff --git a/src/engine/camera/CameraViewpoint.cpp b/src/engine/camera/CameraViewpoint.cpp index 2d0e75f..d6c71be 100644 --- a/src/engine/camera/CameraViewpoint.cpp +++ b/src/engine/camera/CameraViewpoint.cpp @@ -6,6 +6,7 @@ #include "CameraInfo.hpp" #include "RenderCamera.hpp" #include "assets/model/Model.hpp" +#include "math/literals/size.hpp" namespace fgl::engine { diff --git a/src/engine/camera/GBufferSwapchain.cpp b/src/engine/camera/GBufferSwapchain.cpp index bb5a8ca..4103de7 100644 --- a/src/engine/camera/GBufferSwapchain.cpp +++ b/src/engine/camera/GBufferSwapchain.cpp @@ -4,6 +4,8 @@ #include "GBufferSwapchain.hpp" +#include + #include "engine/descriptors/DescriptorSet.hpp" namespace fgl::engine diff --git a/src/engine/debug/timing/FlameGraph.cpp b/src/engine/debug/timing/FlameGraph.cpp index 7d261df..b109a40 100644 --- a/src/engine/debug/timing/FlameGraph.cpp +++ b/src/engine/debug/timing/FlameGraph.cpp @@ -6,12 +6,6 @@ #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include -#pragma GCC diagnostic pop - #include "engine/FGL_DEFINES.hpp" #include "engine/clock.hpp" #include "engine/debug/logging/logging.hpp" diff --git a/src/engine/descriptors/DescriptorSet.hpp b/src/engine/descriptors/DescriptorSet.hpp index 80c7cbd..4546fc3 100644 --- a/src/engine/descriptors/DescriptorSet.hpp +++ b/src/engine/descriptors/DescriptorSet.hpp @@ -77,6 +77,12 @@ namespace fgl::engine::descriptors std::size_t array_idx, std::size_t item_size ); + template + void bindAttachmentObject(T& t, std::size_t view_idx) + { + + } + void bindAttachment( std::uint32_t binding_idx, const ImageView& view, vk::ImageLayout layout ); void bindTexture( std::uint32_t binding_idx, const std::shared_ptr< Texture >& tex_ptr ); diff --git a/src/engine/gameobjects/components/drawers.cpp b/src/engine/gameobjects/components/drawers.cpp index 6003804..d02793c 100644 --- a/src/engine/gameobjects/components/drawers.cpp +++ b/src/engine/gameobjects/components/drawers.cpp @@ -4,17 +4,12 @@ #include "drawers.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include -#pragma GCC diagnostic pop - #include "editor/src/gui/helpers.hpp" namespace fgl::engine { + /* void drawComponentTransform( ComponentTransform& transform ) { if ( ImGui::CollapsingHeader( "Transform" ) ) @@ -35,5 +30,6 @@ namespace fgl::engine ImGui::DragFloat3( "Scale", &transform.scale.x, speed ); } } + */ } // namespace fgl::engine diff --git a/src/engine/gameobjects/components/drawers.hpp b/src/engine/gameobjects/components/drawers.hpp index 11815f6..acaf38c 100644 --- a/src/engine/gameobjects/components/drawers.hpp +++ b/src/engine/gameobjects/components/drawers.hpp @@ -8,6 +8,6 @@ namespace fgl::engine { - void drawComponentTransform( ComponentTransform& transform ); + // void drawComponentTransform( ComponentTransform& transform ); } \ No newline at end of file diff --git a/src/engine/memory/buffers/BufferSuballocation.hpp b/src/engine/memory/buffers/BufferSuballocation.hpp index ee1b200..ca8a8eb 100644 --- a/src/engine/memory/buffers/BufferSuballocation.hpp +++ b/src/engine/memory/buffers/BufferSuballocation.hpp @@ -9,7 +9,7 @@ namespace fgl::engine::memory { - class BufferHandle; + class VulkanBuffer; class SuballocationView; class BufferSuballocationHandle; diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.cpp b/src/engine/memory/buffers/BufferSuballocationHandle.cpp index 6c4284d..1308f05 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.cpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.cpp @@ -4,8 +4,8 @@ #include "BufferSuballocationHandle.hpp" -#include "BufferHandle.hpp" #include "BufferSuballocation.hpp" +#include "VulkanBuffer.hpp" #include "assets/transfer/TransferManager.hpp" #include "engine/debug/logging/logging.hpp" diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.hpp b/src/engine/memory/buffers/BufferSuballocationHandle.hpp index 2f7ef55..30b1290 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.hpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.hpp @@ -8,8 +8,8 @@ #include -#include "BufferHandle.hpp" #include "FGL_DEFINES.hpp" +#include "VulkanBuffer.hpp" #include "engine/debug/Track.hpp" namespace vk::raii @@ -19,7 +19,7 @@ namespace vk::raii namespace fgl::engine::memory { - class BufferHandle; + class VulkanBuffer; class BufferSuballocationHandle : public std::enable_shared_from_this< BufferSuballocationHandle > { diff --git a/src/engine/memory/buffers/BufferHandle.cpp b/src/engine/memory/buffers/VulkanBuffer.cpp similarity index 88% rename from src/engine/memory/buffers/BufferHandle.cpp rename to src/engine/memory/buffers/VulkanBuffer.cpp index 816ce24..451301c 100644 --- a/src/engine/memory/buffers/BufferHandle.cpp +++ b/src/engine/memory/buffers/VulkanBuffer.cpp @@ -2,12 +2,11 @@ // Created by kj16609 on 12/30/23. // -#include "BufferHandle.hpp" - #include #include #include "BufferSuballocationHandle.hpp" +#include "VulkanBuffer.hpp" #include "align.hpp" #include "assets/transfer/TransferManager.hpp" #include "engine/debug/logging/logging.hpp" @@ -18,7 +17,7 @@ namespace fgl::engine::memory { - std::tuple< vk::Buffer, VmaAllocationInfo, VmaAllocation > BufferHandle::allocBuffer( + std::tuple< vk::Buffer, VmaAllocationInfo, VmaAllocation > VulkanBuffer::allocBuffer( const vk::DeviceSize memory_size, vk::BufferUsageFlags usage, const vk::MemoryPropertyFlags property_flags ) { // Used for resizing. @@ -71,12 +70,12 @@ namespace fgl::engine::memory VmaAllocation >( std::move( buffer ), std::move( alloc_info ), std::move( allocation ) ); } - void BufferHandle::deallocBuffer( const vk::Buffer& buffer, const VmaAllocation& allocation ) + void VulkanBuffer::deallocBuffer( const vk::Buffer& buffer, const VmaAllocation& allocation ) { vmaDestroyBuffer( Device::getInstance().allocator(), buffer, allocation ); } - void BufferHandle::swap( BufferHandle& other ) noexcept + void VulkanBuffer::swap( VulkanBuffer& other ) noexcept { std::swap( m_buffer, other.m_buffer ); std::swap( m_allocation, other.m_allocation ); @@ -91,7 +90,7 @@ namespace fgl::engine::memory std::swap( m_free_blocks, other.m_free_blocks ); } - BufferHandle::BufferHandle( + VulkanBuffer::VulkanBuffer( vk::DeviceSize memory_size, const vk::BufferUsageFlags usage, const vk::MemoryPropertyFlags memory_properties ) : @@ -108,7 +107,7 @@ namespace fgl::engine::memory m_free_blocks.emplace_back( 0, memory_size ); } - BufferHandle::~BufferHandle() + VulkanBuffer::~VulkanBuffer() { if ( !m_active_suballocations.empty() ) { @@ -139,7 +138,17 @@ namespace fgl::engine::memory deallocBuffer( m_buffer, m_allocation ); } - vk::DeviceSize BufferHandle::largestBlock() const + VkDeviceMemory VulkanBuffer::address() const + { + return m_alloc_info.deviceMemory; + } + + VkDeviceSize VulkanBuffer::size() const + { + return m_alloc_info.size; + } + + vk::DeviceSize VulkanBuffer::largestBlock() const { vk::DeviceSize largest { 0 }; @@ -151,7 +160,7 @@ namespace fgl::engine::memory return largest; } - vk::DeviceSize BufferHandle::used() const + vk::DeviceSize VulkanBuffer::used() const { vk::DeviceSize total_size { 0 }; @@ -164,19 +173,19 @@ namespace fgl::engine::memory return total_size; } - vk::DeviceMemory BufferHandle::getMemory() const + vk::DeviceMemory VulkanBuffer::getMemory() const { assert( m_alloc_info.deviceMemory != VK_NULL_HANDLE ); return m_alloc_info.deviceMemory; } - std::string BufferHandle::sizeName() const + std::string VulkanBuffer::sizeName() const { return std::format( "{}: {}", m_debug_name, literals::size_literals::toString( size() ) ); } - std::shared_ptr< BufferSuballocationHandle > BufferHandle:: + std::shared_ptr< BufferSuballocationHandle > VulkanBuffer:: allocate( vk::DeviceSize desired_memory_size, const vk::DeviceSize t_alignment ) { ZoneScoped; @@ -258,7 +267,7 @@ namespace fgl::engine::memory return suballocation_handle; } - bool BufferHandle::canAllocate( const vk::DeviceSize memory_size, const vk::DeviceSize alignment ) + bool VulkanBuffer::canAllocate( const vk::DeviceSize memory_size, const vk::DeviceSize alignment ) { // TODO: This check can be optimized by itterating through and virtually combining blocks that would be combined. // If the combined block is large enough then we should consider it being capable of allocation. @@ -273,7 +282,7 @@ namespace fgl::engine::memory return true; } - void BufferHandle::free( BufferSuballocationHandle& info ) + void VulkanBuffer::free( BufferSuballocationHandle& info ) { ZoneScoped; @@ -312,7 +321,7 @@ namespace fgl::engine::memory #endif } - void BufferHandle::mergeFreeBlocks() + void VulkanBuffer::mergeFreeBlocks() { ZoneScoped; //Can't combine blocks if there is only 1 @@ -356,7 +365,7 @@ namespace fgl::engine::memory } } - void BufferHandle::setDebugName( const std::string& str ) + void VulkanBuffer::setDebugName( const std::string& str ) { m_debug_name = str; std::string sized_name { std::format( "{}: {}", m_debug_name, literals::size_literals::toString( size() ) ) }; @@ -369,14 +378,14 @@ namespace fgl::engine::memory Device::getInstance().setDebugUtilsObjectName( info ); } - void* BufferHandle::map( const BufferSuballocationHandle& handle ) const + void* VulkanBuffer::map( const BufferSuballocationHandle& handle ) const { if ( m_alloc_info.pMappedData == nullptr ) return nullptr; return static_cast< std::byte* >( m_alloc_info.pMappedData ) + handle.offset(); } - vk::DeviceSize BufferHandle::alignment() const + vk::DeviceSize VulkanBuffer::alignment() const { vk::DeviceSize size { 1 }; @@ -398,7 +407,7 @@ namespace fgl::engine::memory return size; } - decltype( BufferHandle::m_free_blocks )::iterator BufferHandle:: + decltype( VulkanBuffer::m_free_blocks )::iterator VulkanBuffer:: findAvailableBlock( vk::DeviceSize memory_size, const vk::DeviceSize t_alignment ) { //Find a free space. @@ -416,28 +425,28 @@ namespace fgl::engine::memory } ); } - Buffer& Buffer::operator=( const std::shared_ptr< BufferHandle >& other ) + Buffer& Buffer::operator=( const std::shared_ptr< VulkanBuffer >& other ) { - std::shared_ptr< BufferHandle >::operator=( other ); + std::shared_ptr< VulkanBuffer >::operator=( other ); return *this; } Buffer:: Buffer( vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties ) : - std::shared_ptr< BufferHandle >( std::make_shared< BufferHandle >( memory_size, usage, memory_properties ) ) + std::shared_ptr< VulkanBuffer >( std::make_shared< VulkanBuffer >( memory_size, usage, memory_properties ) ) {} - Buffer::Buffer( const std::shared_ptr< BufferHandle >& buffer ) : std::shared_ptr< BufferHandle >( buffer ) + Buffer::Buffer( const std::shared_ptr< VulkanBuffer >& buffer ) : std::shared_ptr< VulkanBuffer >( buffer ) {} BufferSuballocation Buffer::allocate( const vk::DeviceSize desired_size, const std::uint32_t alignment ) const { - return std::shared_ptr< BufferHandle >::operator->()->allocate( desired_size, alignment ); + return std::shared_ptr< VulkanBuffer >::operator->()->allocate( desired_size, alignment ); } vk::DeviceSize Buffer::size() const { - return std::shared_ptr< BufferHandle >::operator->()->size(); + return std::shared_ptr< VulkanBuffer >::operator->()->size(); } } // namespace fgl::engine::memory diff --git a/src/engine/memory/buffers/BufferHandle.hpp b/src/engine/memory/buffers/VulkanBuffer.hpp similarity index 78% rename from src/engine/memory/buffers/BufferHandle.hpp rename to src/engine/memory/buffers/VulkanBuffer.hpp index 7320ed5..be8b9a3 100644 --- a/src/engine/memory/buffers/BufferHandle.hpp +++ b/src/engine/memory/buffers/VulkanBuffer.hpp @@ -8,19 +8,13 @@ #include #include -#include #include #include #include #include #include "engine/debug/Track.hpp" -#include "math/literals/size.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wundef" -#include -#pragma GCC diagnostic pop +#include "memory/vma_impl.hpp" namespace fgl::engine { @@ -47,9 +41,7 @@ namespace fgl::engine::memory //TODO: Dynamic/onDemand resizing of Buffer for suballocations //TODO: Defragmentation - //TODO: Ensure this class can't be directly accessed from within Buffer unless we are trying - // to access it in a debug manner (IE the drawStats menu) - class BufferHandle : public std::enable_shared_from_this< BufferHandle > + class VulkanBuffer : public std::enable_shared_from_this< VulkanBuffer > { vk::Buffer m_buffer { VK_NULL_HANDLE }; VmaAllocation m_allocation {}; @@ -84,24 +76,24 @@ namespace fgl::engine::memory vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags property_flags ); static void deallocBuffer( const vk::Buffer&, const VmaAllocation& ); - BufferHandle() = delete; - BufferHandle( const BufferHandle& other ) = delete; - BufferHandle& operator=( const BufferHandle& other ) = delete; - BufferHandle( BufferHandle&& other ) = delete; - BufferHandle& operator=( BufferHandle&& other ) = delete; + VulkanBuffer() = delete; + VulkanBuffer( const VulkanBuffer& other ) = delete; + VulkanBuffer& operator=( const VulkanBuffer& other ) = delete; + VulkanBuffer( VulkanBuffer&& other ) = delete; + VulkanBuffer& operator=( VulkanBuffer&& other ) = delete; - void swap( BufferHandle& other ) noexcept; + void swap( VulkanBuffer& other ) noexcept; public: - BufferHandle( + VulkanBuffer( vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties ); - ~BufferHandle(); + ~VulkanBuffer(); - auto address() const { return m_alloc_info.deviceMemory; } + VkDeviceMemory address() const; - auto size() const { return m_alloc_info.size; } + VkDeviceSize size() const; vk::DeviceSize largestBlock() const; @@ -167,23 +159,24 @@ namespace fgl::engine::memory findAvailableBlock( vk::DeviceSize memory_size, vk::DeviceSize t_alignment ); }; - class Buffer final : public std::shared_ptr< BufferHandle > + class Buffer final : public std::shared_ptr< VulkanBuffer > { public: [[nodiscard]] Buffer( vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties ); - [[nodiscard]] explicit Buffer( const std::shared_ptr< BufferHandle >& buffer ); + [[nodiscard]] explicit Buffer( const std::shared_ptr< VulkanBuffer >& buffer ); - BufferSuballocation allocate( const vk::DeviceSize desired_size, const std::uint32_t alignment = 1 ) const; + BufferSuballocation allocate( vk::DeviceSize desired_size, std::uint32_t alignment = 1 ) const; [[nodiscard]] vk::DeviceSize size() const; - Buffer& operator=( const std::shared_ptr< BufferHandle >& other ); + Buffer& operator=( const std::shared_ptr< VulkanBuffer >& other ); ~Buffer() = default; }; std::vector< std::weak_ptr< Buffer > > getActiveBuffers(); + } // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/memory/buffers/vector/BufferVector.cpp b/src/engine/memory/buffers/vector/BufferVector.cpp index 31e2a6a..8b11cfd 100644 --- a/src/engine/memory/buffers/vector/BufferVector.cpp +++ b/src/engine/memory/buffers/vector/BufferVector.cpp @@ -4,8 +4,10 @@ #include "BufferVector.hpp" +#include + #include "engine/assets/transfer/TransferManager.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" +#include "engine/memory/buffers/VulkanBuffer.hpp" namespace fgl::engine::memory { diff --git a/src/engine/memory/vma_impl.cpp b/src/engine/memory/vma_impl.cpp new file mode 100644 index 0000000..d81164b --- /dev/null +++ b/src/engine/memory/vma_impl.cpp @@ -0,0 +1,6 @@ +// +// Created by kj16609 on 11/22/25. +// + +#define VMA_IMPLEMENTATION +#include \ No newline at end of file diff --git a/src/engine/memory/vma_impl.hpp b/src/engine/memory/vma_impl.hpp new file mode 100644 index 0000000..6a5a4c8 --- /dev/null +++ b/src/engine/memory/vma_impl.hpp @@ -0,0 +1,6 @@ +// +// Created by kj16609 on 11/22/25. +// +#pragma once + +#include \ No newline at end of file diff --git a/src/engine/rendering/CommandBufferPool.hpp b/src/engine/rendering/CommandBufferPool.hpp index 0db2a94..6e82c42 100644 --- a/src/engine/rendering/CommandBufferPool.hpp +++ b/src/engine/rendering/CommandBufferPool.hpp @@ -3,6 +3,7 @@ // #pragma once #include +#include #include #include "CommandBuffer.hpp" diff --git a/src/engine/rendering/PresentSwapChain.cpp b/src/engine/rendering/PresentSwapChain.cpp index 3915291..f76b4f4 100644 --- a/src/engine/rendering/PresentSwapChain.cpp +++ b/src/engine/rendering/PresentSwapChain.cpp @@ -99,7 +99,7 @@ namespace fgl::engine // render_attachments.input_color.setName( "Input Color" ); } - std::pair< vk::Result, PresentIndex > PresentSwapChain::acquireNextImage() + vk::ResultValue< uint32_t > PresentSwapChain::acquireNextImage() const { ZoneScoped; diff --git a/src/engine/rendering/PresentSwapChain.hpp b/src/engine/rendering/PresentSwapChain.hpp index f751423..640d348 100644 --- a/src/engine/rendering/PresentSwapChain.hpp +++ b/src/engine/rendering/PresentSwapChain.hpp @@ -101,7 +101,7 @@ namespace fgl::engine [[nodiscard]] float extentAspectRatio() const; - [[nodiscard]] std::pair< vk::Result, PresentIndex > acquireNextImage(); + [[nodiscard]] vk::ResultValue< uint32_t > acquireNextImage() const; [[nodiscard]] vk::Result submitCommandBuffers( const CommandBuffer& buffers, PresentIndex present_index ); void transitionImages( const CommandBuffer& command_buffer, StageID stage_id, FrameIndex frame_index ) const; diff --git a/src/engine/rendering/devices/Device.cpp b/src/engine/rendering/devices/Device.cpp index e43e1de..66b0dc9 100644 --- a/src/engine/rendering/devices/Device.cpp +++ b/src/engine/rendering/devices/Device.cpp @@ -1,14 +1,15 @@ #include "Device.hpp" +#include +#include +#include +#include + #include "engine/descriptors/DescriptorPool.hpp" // std headers #include -#include -#include -#include - #include "debug/Track.hpp" #include "engine/debug/logging/logging.hpp" @@ -138,18 +139,6 @@ namespace fgl::engine std::cout << "\t" << desired_ext << ": " << found << std::endl; if ( !found ) throw std::runtime_error( "Failed to find required extension" ); } - - // might not really be necessary anymore because device specific validation layers - // have been deprecated - if ( true ) - { - m_create_info.enabledLayerCount = static_cast< uint32_t >( m_validation_layers.size() ); - m_create_info.ppEnabledLayerNames = m_validation_layers.data(); - } - else - { - m_create_info.enabledLayerCount = 0; - } } Device::DeviceCreateInfo::DeviceCreateInfo( PhysicalDevice& physical_device ) : diff --git a/src/engine/rendering/devices/Device.hpp b/src/engine/rendering/devices/Device.hpp index bd32f73..b9b6adc 100644 --- a/src/engine/rendering/devices/Device.hpp +++ b/src/engine/rendering/devices/Device.hpp @@ -10,13 +10,9 @@ #include "engine/rendering/Instance.hpp" #include "engine/rendering/Surface.hpp" #include "extensions.hpp" +#include "memory/vma_impl.hpp" #include "rendering/CommandBufferPool.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wundef" -#include -#pragma GCC diagnostic pop - namespace fgl::engine { diff --git a/src/engine/systems/RenderGraph.cpp b/src/engine/systems/RenderGraph.cpp index f951ca1..df0c63f 100644 --- a/src/engine/systems/RenderGraph.cpp +++ b/src/engine/systems/RenderGraph.cpp @@ -78,7 +78,7 @@ namespace fgl::engine submitInfo( std::move( attachment_info ) ); } - void RenderGraph::flush( const CommandBuffer& command_buffer ) + void RenderGraph::flush( CommandBuffer& command_buffer ) { while ( !m_queue.empty() ) { diff --git a/src/engine/systems/RenderGraph.hpp b/src/engine/systems/RenderGraph.hpp index 19a7ca1..db27d41 100644 --- a/src/engine/systems/RenderGraph.hpp +++ b/src/engine/systems/RenderGraph.hpp @@ -71,8 +71,6 @@ namespace fgl::engine public: - friend class RenderGraph; - void push(); void pop(); @@ -84,7 +82,7 @@ namespace fgl::engine void registerBuffer( const std::string& str, const memory::BufferSuballocation& value ); void addBufferDependency( std::string buffer_name ); - void flush( const CommandBuffer& command_buffer ); + void flush( CommandBuffer& command_buffer ); }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/systems/render/EntityRendererSystem.cpp b/src/engine/systems/render/EntityRendererSystem.cpp index 5887a6f..5c0f927 100644 --- a/src/engine/systems/render/EntityRendererSystem.cpp +++ b/src/engine/systems/render/EntityRendererSystem.cpp @@ -79,12 +79,14 @@ namespace fgl::engine auto& command_buffer { info.command_buffer.render_cb }; TracyVkZone( info.tracy_ctx, **command_buffer, "Render textured entities" ); + /* info.graph.addAttachmentOutput( "G_DEPTH", vk::ImageLayout::eDepthAttachmentOptimal ); info.graph.addAttachmentOutput( "G_COLOR", vk::ImageLayout::eAttachmentOptimal ); info.graph.addAttachmentOutput( "G_NORMAL", vk::ImageLayout::eAttachmentOptimal ); info.graph.addAttachmentOutput( "G_POSITION", vk::ImageLayout::eAttachmentOptimal ); info.graph.addAttachmentOutput( "G_EMISSIVE", vk::ImageLayout::eAttachmentOptimal ); info.graph.addAttachmentOutput( "G_METALLIC", vk::ImageLayout::eAttachmentOptimal ); + */ // info.graph.addBufferDependency( "VERTEX_BUFFER" ); // info.graph.addBufferDependency( "INDEX_BUFFER" ); @@ -95,7 +97,7 @@ namespace fgl::engine // compute shader - info.graph.flush( command_buffer ); + // info.graph.flush( command_buffer ); m_textured_pipeline->bind( command_buffer ); diff --git a/src/engine/systems/render/EntityRendererSystem.hpp b/src/engine/systems/render/EntityRendererSystem.hpp index c37c536..f986c4f 100644 --- a/src/engine/systems/render/EntityRendererSystem.hpp +++ b/src/engine/systems/render/EntityRendererSystem.hpp @@ -15,7 +15,7 @@ namespace fgl::engine namespace memory { - class BufferHandle; + class VulkanBuffer; } struct FrameInfo; diff --git a/src/renderer/CMakeLists.txt b/src/renderer/CMakeLists.txt new file mode 100644 index 0000000..57b47ce --- /dev/null +++ b/src/renderer/CMakeLists.txt @@ -0,0 +1,37 @@ + +file(GLOB_RECURSE CPP_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/src/**.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/**.hpp" +) + +AddFGLLibrary(FGLRenderer SHARED ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +target_compile_definitions(FGLRenderer PUBLIC + VULKAN_HPP_NO_CONSTRUCTORS # Disabled constructors + VULKAN_HPP_NO_SETTERS # Disable setters for structs + VULKAN_HPP_NO_STD_MODULE # No import std + VULKAN_HPP_NO_TO_STRING # use reflection instead + VULKAN_HPP_NO_WIN32_PROTOTYPES + VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST +) + +include(dependencies/spdlog) + +target_link_libraries(FGLRenderer PUBLIC Vulkan::Vulkan FGLLoader spdlog slang glm) +target_include_directories(FGLRenderer SYSTEM PUBLIC ${GLM_INCLUDE_DIRS}) +target_link_libraries(FGLRenderer PUBLIC glfw Tracy::TracyClient libFGL) +target_include_directories(FGLRenderer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) + +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_UPPER_BUILD_TYPE) + +#GLM settings +# GLM_FORCE_NO_CTOR_INIT +target_compile_definitions(FGLRenderer PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE) + +if (DEFINED FGL_ENABLE_CALIBRATED_PROFILING AND FGL_ENABLE_CALIBRATED_PROFILING) + target_compile_definitions(FGLRenderer PUBLIC ENABLE_CALIBRATED_PROFILING=1) +else () + target_compile_definitions(FGLRenderer PUBLIC ENABLE_CALIBRATED_PROFILING=0) +endif () + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests) \ No newline at end of file diff --git a/src/renderer/src/FGLRenderSurface.cpp b/src/renderer/src/FGLRenderSurface.cpp new file mode 100644 index 0000000..d784dd1 --- /dev/null +++ b/src/renderer/src/FGLRenderSurface.cpp @@ -0,0 +1,9 @@ +// +// Created by kj16609 on 12/7/25. +// +#include "FGLRenderSurface.hpp" + +namespace fgl::renderer +{ + +} diff --git a/src/renderer/src/FGLRenderSurface.hpp b/src/renderer/src/FGLRenderSurface.hpp new file mode 100644 index 0000000..9e961f8 --- /dev/null +++ b/src/renderer/src/FGLRenderSurface.hpp @@ -0,0 +1,20 @@ +// +// Created by kj16609 on 12/7/25. +// +#pragma once +#include +#include + +namespace fgl::renderer +{ + class GLFWRenderSurface; + + using RenderSurfaceBase = std::unique_ptr< std::variant< GLFWRenderSurface > >; + + class FGLRenderSurface + { + public: + + FGLRenderSurface( int start_width, int start_height, bool fullscreen = false ); + }; +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/FGLRenderer.cpp b/src/renderer/src/FGLRenderer.cpp new file mode 100644 index 0000000..6e6e20a --- /dev/null +++ b/src/renderer/src/FGLRenderer.cpp @@ -0,0 +1,18 @@ +// +// Created by kj16609 on 12/4/25. +// + +#include "FGLRenderer.hpp" + +#include "FGLRenderSurface.hpp" +#include "vulkan/Vulkan.hpp" + +namespace fgl::renderer +{ + + FGLRenderer FGLRenderer::createVkRenderer() + {} + + FGLRenderer::~FGLRenderer() = default; + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/FGLRenderer.hpp b/src/renderer/src/FGLRenderer.hpp new file mode 100644 index 0000000..2ecb981 --- /dev/null +++ b/src/renderer/src/FGLRenderer.hpp @@ -0,0 +1,32 @@ +// +// Created by kj16609 on 12/4/25. +// +#pragma once + +#include +#include + +#include "fgl/defines.hpp" + +namespace fgl::renderer +{ + class Vulkan; + + using RendererBase = std::unique_ptr< Vulkan >; + + class FGLRenderer + { + RendererBase m_base; + + public: + + FGLRenderer() = delete; + FGL_DELETE_MOVE( FGLRenderer ); + FGL_DELETE_COPY( FGLRenderer ); + + static FGLRenderer createVkRenderer(); + + ~FGLRenderer(); + }; + +} // namespace fgl::renderer diff --git a/src/renderer/src/surfaces/Surface.hpp b/src/renderer/src/surfaces/Surface.hpp new file mode 100644 index 0000000..b0b523c --- /dev/null +++ b/src/renderer/src/surfaces/Surface.hpp @@ -0,0 +1,16 @@ +// +// Created by kj16609 on 12/7/25. +// +#pragma once + +#include + +namespace vk::raii +{ + class SurfaceKHR; +} + +namespace fgl::renderer +{ + using Surface = std::unique_ptr< vk::raii::SurfaceKHR >; +} diff --git a/src/renderer/src/surfaces/glfw/GLFWRenderSurface.cpp b/src/renderer/src/surfaces/glfw/GLFWRenderSurface.cpp new file mode 100644 index 0000000..1c1614f --- /dev/null +++ b/src/renderer/src/surfaces/glfw/GLFWRenderSurface.cpp @@ -0,0 +1,52 @@ +// +// Created by kj16609 on 12/7/25. +// +#include "GLFWRenderSurface.hpp" + +#include + +#include "GLFW/glfw3.h" + +namespace fgl::renderer +{ + + void resizeCallback( GLFWwindow* window_ptr, int width, int height ) + { + auto* window { static_cast< GLFWRenderSurface* >( glfwGetWindowUserPointer( window_ptr ) ) }; + if ( window ) + { + window->m_resized = true; + window->m_width = width; + window->m_height = height; + } + } + + GLFWRenderSurface::GLFWRenderSurface( const int width, const int height, const std::string_view window_name ) : + m_window( nullptr ), + m_width( width ), + m_height( height ) + { + glfwInit(); + glfwWindowHint( GLFW_CLIENT_API, GLFW_NO_API ); + glfwWindowHint( GLFW_RESIZABLE, GLFW_TRUE ); + + m_window = glfwCreateWindow( width, height, window_name.data(), nullptr, nullptr ); + + glfwSetWindowUserPointer( m_window, this ); + glfwSetFramebufferSizeCallback( m_window, resizeCallback ); + } + + bool GLFWRenderSurface::shouldClose() const + { + return glfwWindowShouldClose( m_window ); + } + + Surface GLFWRenderSurface::createVkWindowSurface( vk::raii::Instance& instance ) const + { + VkSurfaceKHR target_surface { VK_NULL_HANDLE }; + glfwCreateWindowSurface( *instance, m_window, nullptr, &target_surface ); + + return std::make_unique< vk::raii::SurfaceKHR >( instance, target_surface ); + } + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/surfaces/glfw/GLFWRenderSurface.hpp b/src/renderer/src/surfaces/glfw/GLFWRenderSurface.hpp new file mode 100644 index 0000000..0bbb0c0 --- /dev/null +++ b/src/renderer/src/surfaces/glfw/GLFWRenderSurface.hpp @@ -0,0 +1,41 @@ +// +// Created by kj16609 on 12/7/25. +// +#pragma once +#include + +#include "surfaces/Surface.hpp" + +namespace vk::raii +{ + class Instance; +} +struct GLFWwindow; + +namespace fgl::renderer +{ + + class GLFWRenderSurface + { + GLFWwindow* m_window; + bool m_resized { false }; + int m_width; + int m_height; + + friend void resizeCallback( GLFWwindow* window_ptr, int width, int height ); + + public: + + GLFWRenderSurface( int width, int height, std::string_view window_name ); + + // FGL_DELETE_ALL_RO5( GLFWRenderSurface ); + + //! Returns true if the window has been resized since the last check + bool hasResized() const; + + bool shouldClose() const; + + Surface createVkWindowSurface( vk::raii::Instance& instance ) const; + }; + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/vulkan/Vulkan.cpp b/src/renderer/src/vulkan/Vulkan.cpp new file mode 100644 index 0000000..a757b8f --- /dev/null +++ b/src/renderer/src/vulkan/Vulkan.cpp @@ -0,0 +1,85 @@ +// +// Created by kj16609 on 12/4/25. +// + +#include "vulkan/Vulkan.hpp" + +#include "VulkanDevice.hpp" +#include "VulkanPhysicalDevice.hpp" + +namespace fgl::renderer +{ + + inline static PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT { nullptr }; + inline static PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT { nullptr }; + inline static PFN_vkSetDebugUtilsObjectNameEXT pfnVkSetDebugUtilsObjectNameEXT { nullptr }; + + // Callback function for vulkan messaging. + static VKAPI_ATTR vk::Bool32 VKAPI_CALL debugCallback( + const vk::DebugUtilsMessageSeverityFlagBitsEXT message_severity, + [[maybe_unused]] vk::DebugUtilsMessageTypeFlagsEXT message_type, + const vk::DebugUtilsMessengerCallbackDataEXT* p_callback_data, + [[maybe_unused]] void* p_user_data ) + { + switch ( message_severity ) + { + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose: + break; + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo: + break; + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning: + break; + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError: + break; + default: + { + throw std::runtime_error { "Unknown severity from debug callback" }; + } + } + + return VK_FALSE; + } + + VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( + VkInstance instance, + const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDebugUtilsMessengerEXT* pMessenger ) + { + assert( pfnVkCreateDebugUtilsMessengerEXT ); + return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger ); + } + + VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( + VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator ) + { + assert( pfnVkDestroyDebugUtilsMessengerEXT ); + return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator ); + } + + VKAPI_ATTR VkResult VKAPI_CALL + vkSetDebugUtilsObjectNameEXT( VkDevice device, const VkDebugUtilsObjectNameInfoEXT* nameInfo ) + { + assert( pfnVkSetDebugUtilsObjectNameEXT ); + return pfnVkSetDebugUtilsObjectNameEXT( device, nameInfo ); + } + + inline static vk::ApplicationInfo s_app_info { + .pApplicationName = "FGL App", + .applicationVersion = VK_MAKE_VERSION( 1, 0, 0 ), + .pEngineName = "FGL Engine", + .engineVersion = VK_MAKE_VERSION( 1, 0, 0 ), + .apiVersion = VK_API_VERSION_1_4, + }; + + inline static vk::InstanceCreateInfo s_create_info { + .pApplicationInfo = &s_app_info + }; + + Vulkan::Vulkan( const std::string_view app_name ) : m_ctx(), , m_instance( m_ctx, s_create_info ) + {} + + Vulkan::~Vulkan() + {} + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/vulkan/Vulkan.hpp b/src/renderer/src/vulkan/Vulkan.hpp new file mode 100644 index 0000000..4d2205e --- /dev/null +++ b/src/renderer/src/vulkan/Vulkan.hpp @@ -0,0 +1,33 @@ +// +// Created by kj16609 on 12/4/25. +// +#pragma once +#include + +#include + +#include "fgl/defines.hpp" + +namespace fgl::renderer +{ + class VulkanDevice; + class VulkanPhysicalDevice; + + class Vulkan + { + vk::raii::Context m_ctx; + vk::raii::Instance m_instance; + + std::unique_ptr< VulkanDevice > m_device; + std::unique_ptr< VulkanPhysicalDevice > m_phy_device; + + public: + + FGL_DELETE_MOVE( Vulkan ); + FGL_DELETE_COPY( Vulkan ); + + Vulkan(); + ~Vulkan(); + }; + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/vulkan/VulkanAllocator.cpp b/src/renderer/src/vulkan/VulkanAllocator.cpp new file mode 100644 index 0000000..a88cdea --- /dev/null +++ b/src/renderer/src/vulkan/VulkanAllocator.cpp @@ -0,0 +1,4 @@ +// +// Created by kj16609 on 12/9/25. +// +#include "VulkanAllocator.hpp" diff --git a/src/renderer/src/vulkan/VulkanAllocator.hpp b/src/renderer/src/vulkan/VulkanAllocator.hpp new file mode 100644 index 0000000..1eadf60 --- /dev/null +++ b/src/renderer/src/vulkan/VulkanAllocator.hpp @@ -0,0 +1,20 @@ +// +// Created by kj16609 on 12/9/25. +// +#pragma once + +#include "fgl/size.hpp" + +namespace fgl::renderer +{ + using namespace fgl::size::literals; + + class VulkanAllocator + { + static constexpr auto minimim_block_size { 64_MiB }; + + public: + + VulkanAllocator(); + }; +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/vulkan/VulkanDevice.cpp b/src/renderer/src/vulkan/VulkanDevice.cpp new file mode 100644 index 0000000..527b2d0 --- /dev/null +++ b/src/renderer/src/vulkan/VulkanDevice.cpp @@ -0,0 +1,11 @@ +// +// Created by kj16609 on 12/7/25. +// +#include "VulkanDevice.hpp" + +namespace fgl::renderer +{ + + + +} \ No newline at end of file diff --git a/src/renderer/src/vulkan/VulkanDevice.hpp b/src/renderer/src/vulkan/VulkanDevice.hpp new file mode 100644 index 0000000..97ef6ef --- /dev/null +++ b/src/renderer/src/vulkan/VulkanDevice.hpp @@ -0,0 +1,20 @@ +// +// Created by kj16609 on 12/7/25. +// +#pragma once + +#include + +namespace fgl::renderer +{ + + class VulkanDevice + { + vk::raii::Device m_device; + + public: + + VulkanDevice(); + }; + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/src/vulkan/VulkanPhysicalDevice.cpp b/src/renderer/src/vulkan/VulkanPhysicalDevice.cpp new file mode 100644 index 0000000..a20850b --- /dev/null +++ b/src/renderer/src/vulkan/VulkanPhysicalDevice.cpp @@ -0,0 +1,9 @@ +// +// Created by kj16609 on 12/7/25. +// +#include "VulkanPhysicalDevice.hpp" + +namespace fgl::renderer +{ + +} diff --git a/src/renderer/src/vulkan/VulkanPhysicalDevice.hpp b/src/renderer/src/vulkan/VulkanPhysicalDevice.hpp new file mode 100644 index 0000000..84fec00 --- /dev/null +++ b/src/renderer/src/vulkan/VulkanPhysicalDevice.hpp @@ -0,0 +1,20 @@ +// +// Created by kj16609 on 12/7/25. +// +#pragma once + +#include + +namespace fgl::renderer +{ + + class VulkanPhysicalDevice + { + vk::raii::PhysicalDevice m_device; + + public: + + VulkanPhysicalDevice(); + }; + +} // namespace fgl::renderer \ No newline at end of file diff --git a/src/renderer/tests/CMakeLists.txt b/src/renderer/tests/CMakeLists.txt new file mode 100644 index 0000000..bb3e63b --- /dev/null +++ b/src/renderer/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +AddFGLExecutable(FGLRenderer_TESTS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(FGLRenderer_TESTS PUBLIC FGLRenderer) \ No newline at end of file diff --git a/src/renderer/tests/main.cpp b/src/renderer/tests/main.cpp new file mode 100644 index 0000000..abd992d --- /dev/null +++ b/src/renderer/tests/main.cpp @@ -0,0 +1,14 @@ +// +// Created by kj16609 on 12/4/25. +// + +#include + +#include "FGLRenderer.hpp" + +int main( int argc, char* argv[] ) +{ + fgl::renderer::FGLRenderer renderer { fgl::renderer::FGLRenderer::createVkRenderer() }; + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/src/vma/CMakeLists.txt b/src/vma/CMakeLists.txt deleted file mode 100644 index 4e2ee3e..0000000 --- a/src/vma/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - - - -add_library(VMA STATIC ${CMAKE_CURRENT_SOURCE_DIR}/vma_impl.cpp) -target_link_libraries(VMA PUBLIC Vulkan::Vulkan GPUOpen::VulkanMemoryAllocator) diff --git a/src/vma/vma_impl.cpp b/src/vma/vma_impl.cpp deleted file mode 100644 index f1adbd8..0000000 --- a/src/vma/vma_impl.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// -// Created by kj16609 on 12/2/23. -// - -#define VMA_IMPLEMENTATION -#include "vma_impl.hpp" \ No newline at end of file diff --git a/src/vma/vma_impl.hpp b/src/vma/vma_impl.hpp deleted file mode 100644 index 5994f5a..0000000 --- a/src/vma/vma_impl.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// Created by kj16609 on 12/2/23. -// - -#pragma once - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wswitch-enum" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wredundant-tags" -#pragma GCC diagnostic ignored "-Wduplicated-branches" -#pragma GCC diagnostic ignored "-Wunused-variable" -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#pragma GCC diagnostic ignored "-Wuseless-cast" - -#define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 -#include "vk_mem_alloc.h" - -#pragma GCC diagnostic pop