From cc221d605297a8aaa7ea5d370281d73dbbca00e4 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 6 Jun 2024 01:06:48 -0400 Subject: [PATCH] Cleanup of other code and performance profiling with better logging --- src/core/main.cpp | 4 +- src/engine/EngineContext.cpp | 9 ++- src/engine/GameObject.cpp | 24 +++++- src/engine/GameObject.hpp | 71 +++++++++++++++-- src/engine/buffers/vector/DeviceVector.hpp | 4 +- src/engine/logging/formatters/filesystem.cpp | 38 +++++++++ src/engine/logging/formatters/filesystem.hpp | 79 +++++++++++++++++++ src/engine/{ => logging}/logging.hpp | 8 +- src/engine/math/noise/perlin/generator.cpp | 1 + src/engine/model/Model.cpp | 6 ++ src/engine/model/builders/ModelBuilder.cpp | 2 + src/engine/model/builders/SceneBuilder.cpp | 52 +++++++----- src/engine/model/builders/loadGltf.cpp | 5 +- src/engine/pipeline/Shader.hpp | 4 +- src/engine/primitives/Frustum.cpp | 3 +- src/engine/primitives/Rotation.hpp | 14 ++-- .../primitives/boxes/OrientedBoundingBox.cpp | 4 +- src/engine/rendering/Device.cpp | 14 ++-- src/engine/systems/EntityRendererSystem.cpp | 2 - src/engine/texture/Texture.cpp | 39 +++++++++ src/engine/texture/Texture.hpp | 3 + 21 files changed, 334 insertions(+), 52 deletions(-) create mode 100644 src/engine/logging/formatters/filesystem.cpp create mode 100644 src/engine/logging/formatters/filesystem.hpp rename src/engine/{ => logging}/logging.hpp (74%) diff --git a/src/core/main.cpp b/src/core/main.cpp index 8fdf9e7..32e141a 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -5,11 +5,11 @@ #include #include "engine/EngineContext.hpp" -#include "engine/logging.hpp" +#include "engine/logging/logging.hpp" int main() { - spdlog::set_level( spdlog::level::debug ); + fgl::engine::log::set_level( spdlog::level::debug ); fgl::engine::EngineContext engine_ctx {}; diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 4f72475..516fb25 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -5,6 +5,7 @@ #include "EngineContext.hpp" #include +#include #include #include @@ -27,6 +28,7 @@ namespace fgl::engine EngineContext::EngineContext() { + ZoneScoped; using namespace fgl::literals::size_literals; initGlobalStagingBuffer( 512_MiB ); #if ENABLE_IMGUI @@ -39,6 +41,7 @@ namespace fgl::engine void EngineContext::run() { + TracyCZoneN( TRACY_PrepareEngine, "Inital Run", true ); std::cout << "Starting main loop run" << std::endl; using namespace fgl::literals::size_literals; Buffer global_ubo_buffer { 512_KiB, @@ -109,6 +112,8 @@ namespace fgl::engine const auto old_aspect_ratio { m_renderer.getAspectRatio() }; + TracyCZoneEnd( TRACY_PrepareEngine ); + while ( !m_window.shouldClose() ) { ZoneScopedN( "Poll" ); @@ -196,6 +201,7 @@ namespace fgl::engine void EngineContext::loadGameObjects() { + ZoneScoped; std::cout << "Loading game objects" << std::endl; auto command_buffer { Device::getInstance().beginSingleTimeCommands() }; @@ -254,6 +260,7 @@ namespace fgl::engine }*/ { + ZoneScopedN( "Load phyiscs test" ); std::vector< std::shared_ptr< Model > > models { Model::createModelsFromScene( Device::getInstance(), "models/PhysicsTest.glb", @@ -275,6 +282,7 @@ namespace fgl::engine } { + ZoneScopedN( "Load terrain" ); auto model { generateTerrainModel( m_terrain_system.getVertexBuffer(), m_terrain_system.getIndexBuffer() ) }; @@ -380,5 +388,4 @@ namespace fgl::engine #endif } - } // namespace fgl::engine diff --git a/src/engine/GameObject.cpp b/src/engine/GameObject.cpp index e619b68..88456fd 100644 --- a/src/engine/GameObject.cpp +++ b/src/engine/GameObject.cpp @@ -4,6 +4,8 @@ #include "GameObject.hpp" +#include "engine/gui/helpers.hpp" +#include "engine/gui/safe_include.hpp" #include "engine/model/Model.hpp" namespace fgl::engine @@ -11,10 +13,30 @@ namespace fgl::engine GameObject GameObject::createGameObject() { - static ID current_id { 0 }; + static GameObjectID current_id { 0 }; return { current_id++ }; } + void GameObject::drawImGui() + { + ImGui::InputText( "Name", &this->name ); + + // Transform - Position + WorldCoordinate& translation { this->m_transform.translation }; + gui::dragFloat3( "Position", translation.vec() ); + + Rotation& rotation { this->m_transform.rotation }; + gui::dragFloat3Rot( "Rotation", rotation ); + + auto& scale { this->m_transform.scale }; + gui::dragFloat3( "Scale", scale ); + + for ( const GameObjectComponentBase* component : components ) + { + + } + } + OrientedBoundingBox< CoordinateSpace::World > GameObject::getBoundingBox() const { assert( this->m_transform.translation.vec() != constants::DEFAULT_VEC3 ); diff --git a/src/engine/GameObject.hpp b/src/engine/GameObject.hpp index 8a9f05b..3bf4e9c 100644 --- a/src/engine/GameObject.hpp +++ b/src/engine/GameObject.hpp @@ -36,29 +36,86 @@ namespace fgl::engine TEXTURELESS = 1 << 0, }; + struct ComponentImGuiInterface + { + virtual void drawImGui() = 0; + virtual ~ComponentImGuiInterface() = default; + }; + + struct GameObjectComponentBase + { + using ComponentID = std::uint8_t; + virtual ComponentID id() const = 0; + virtual std::string_view name() const = 0; + + virtual ~GameObjectComponentBase() = default; + }; + + template < GameObjectComponentBase::ComponentID T_ID > + struct GameObjectComponent : ComponentImGuiInterface, GameObjectComponentBase + { + constexpr static ComponentID ID { T_ID }; + + virtual ComponentID id() const override final { return ID; } + }; + + template < typename T > + concept is_component = requires( T t ) { + std::is_base_of_v< T, GameObjectComponentBase >; + { + t.ID + } -> std::same_as< GameObjectComponentBase::ComponentID >; + }; + + class ModelComponent final : public GameObjectComponent< 1 > + { + std::shared_ptr m_model; + + public: + + void drawImGui() override; + std::string_view name() const override; + ~ModelComponent() override; + }; + class GameObject { public: - using ID = unsigned int; - using Map = std::unordered_map< ID, GameObject >; + using GameObjectID = unsigned int; + using Map = std::unordered_map< GameObjectID, GameObject >; - static constexpr ID INVALID_ID { std::numeric_limits< ID >::max() }; + static constexpr GameObjectID INVALID_ID { std::numeric_limits< GameObjectID >::max() }; - ID m_id { INVALID_ID }; + GameObjectID m_id { INVALID_ID }; GameObjectFlagType object_flags { GameObjectFlagMask::MASK_DEFAULT }; TransformComponent m_transform {}; + std::vector< GameObjectComponentBase* > components {}; + std::shared_ptr< Model > m_model { nullptr }; + std::string name { "Unnamed Game Object" }; private: - GameObject( ID obj_id ) : m_id( obj_id ) {} + GameObject( GameObjectID obj_id ) : m_id( obj_id ) {} GameObject() = delete; public: + template < typename T > + requires is_component< T > + bool hasComponent() + { + for ( const GameObjectComponentBase* comp : components ) + { + if ( comp->id() == T::ID ) return true; + } + + return false; + } + GameObject( const GameObject& other ) = delete; GameObject& operator=( const GameObject& other ) = delete; @@ -73,7 +130,9 @@ namespace fgl::engine static GameObject createGameObject(); - inline ID getId() const { return m_id; } + inline GameObjectID getId() const { return m_id; } + + void drawImGui(); }; // static_assert( offsetof( GameObject, hot_limter ) < 64, "Hot limit reached" ); diff --git a/src/engine/buffers/vector/DeviceVector.hpp b/src/engine/buffers/vector/DeviceVector.hpp index 3e2b830..a39862b 100644 --- a/src/engine/buffers/vector/DeviceVector.hpp +++ b/src/engine/buffers/vector/DeviceVector.hpp @@ -6,7 +6,7 @@ #include "BufferVector.hpp" #include "HostVector.hpp" -#include "engine/logging.hpp" +#include "engine/logging/logging.hpp" namespace fgl::engine { @@ -21,7 +21,7 @@ namespace fgl::engine DeviceVector( Buffer& buffer, const std::uint32_t count = 1 ) : BufferVector( buffer, count, sizeof( T ) ) { - spdlog::debug( "Creating DeviceVector of size {}", count ); + log::debug( "Creating DeviceVector of size {}", count ); assert( count != 0 && "BufferSuballocationVector::BufferSuballocationVector() called with count == 0" ); } diff --git a/src/engine/logging/formatters/filesystem.cpp b/src/engine/logging/formatters/filesystem.cpp new file mode 100644 index 0000000..7679fc1 --- /dev/null +++ b/src/engine/logging/formatters/filesystem.cpp @@ -0,0 +1,38 @@ +// +// Created by kj16609 on 6/5/24. +// + +#include "filesystem.hpp" + +auto format_ns::formatter< std::filesystem::path >::format( const std::filesystem::path& path, format_context& ctx ) + const -> decltype( ctx.out() ) +{ + if ( print_canonical && std::filesystem::exists( path ) ) + { + if ( print_exists ) + return format_ns::format_to( + ctx.out(), + "[\"{}\", (Canonical: \"{}\") Exists: \"{}\"]", + path.string(), + std::filesystem::canonical( path ).string(), + std::filesystem::exists( path ) ? "True" : "False" ); + else + return format_ns::format_to( + ctx.out(), "[\"{}\" (Canonical: \"{}\")]", path.string(), std::filesystem::canonical( path ).string() ); + } + else + { + if ( print_exists ) + return format_ns:: + format_to( ctx.out(), "[\"{}\"]", path.string(), std::filesystem::exists( path ) ? "True" : "False" ); + else + return format_ns::format_to( ctx.out(), "[\"{}\"]", path.string() ); + } +} + +auto format_ns::formatter< std::source_location >::format( const std::source_location& loc, format_context& ctx ) const + -> decltype( ctx.out() ) +{ + return format_ns:: + format_to( ctx.out(), "File: {}:{}\n\tFunction: {}\n\t", loc.file_name(), loc.line(), loc.function_name() ); +} diff --git a/src/engine/logging/formatters/filesystem.hpp b/src/engine/logging/formatters/filesystem.hpp new file mode 100644 index 0000000..1aa9987 --- /dev/null +++ b/src/engine/logging/formatters/filesystem.hpp @@ -0,0 +1,79 @@ +// +// Created by kj16609 on 6/5/24. +// + +#pragma once + +#ifdef HAVE_STD_FORMAT +#include +namespace format_ns = std; + +#else +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wswitch-default" +#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" +#endif + +#include +namespace format_ns = fmt; + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +#endif + +#include +#include + +template <> +struct format_ns::formatter< std::filesystem::path > +{ + bool print_canonical { false }; + bool print_exists { false }; + + constexpr format_parse_context::iterator parse( format_parse_context& ctx ) + { + //Check if ctx has 'c' 'ce' or 'e' and return the itterator after it + auto idx { ctx.begin() }; + const auto end { ctx.end() }; + + if ( idx != end && *idx == 'c' ) + { + print_canonical = true; + ++idx; + } + + if ( idx != end && *idx == 'e' ) + { + print_exists = true; + ++idx; + } + + return idx; + } + + format_context::iterator format( const std::filesystem::path& path, format_context& ctx ) const; +}; + +template <> +struct format_ns::formatter< std::source_location > +{ + constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); } + + format_context::iterator format( const std::source_location& loc, format_context& ctx ) const; +}; + +template <> +struct format_ns::formatter< format_ns::format_string<> > +{ + constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); } + + format_context::iterator format( const format_ns::format_string<>& str, format_context& ctx ) const; +}; + + + + diff --git a/src/engine/logging.hpp b/src/engine/logging/logging.hpp similarity index 74% rename from src/engine/logging.hpp rename to src/engine/logging/logging.hpp index 78317e5..f47d664 100644 --- a/src/engine/logging.hpp +++ b/src/engine/logging/logging.hpp @@ -4,10 +4,16 @@ #pragma once - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #include #pragma GCC diagnostic pop + +#include "formatters/filesystem.hpp" + +namespace fgl::engine::log +{ + using namespace ::spdlog; +} \ No newline at end of file diff --git a/src/engine/math/noise/perlin/generator.cpp b/src/engine/math/noise/perlin/generator.cpp index 975efba..8880d15 100644 --- a/src/engine/math/noise/perlin/generator.cpp +++ b/src/engine/math/noise/perlin/generator.cpp @@ -68,6 +68,7 @@ namespace fgl::engine std::vector< std::byte > generatePerlinImage( const glm::vec< 2, std::size_t > size, const int octives, const std::size_t seed ) { + ZoneScoped; constexpr std::size_t channel_count { 4 }; // RGBA std::vector< std::byte > data { size.x * size.y * channel_count }; diff --git a/src/engine/model/Model.cpp b/src/engine/model/Model.cpp index 8f51288..41942ce 100644 --- a/src/engine/model/Model.cpp +++ b/src/engine/model/Model.cpp @@ -18,6 +18,7 @@ namespace fgl::engine std::vector< vk::DrawIndexedIndirectCommand > Model::buildParameters( const std::vector< Primitive >& primitives ) { + ZoneScoped; std::vector< vk::DrawIndexedIndirectCommand > draw_parameters {}; draw_parameters.reserve( primitives.size() ); @@ -40,6 +41,7 @@ namespace fgl::engine OrientedBoundingBox< CoordinateSpace::Model > Model::buildBoundingBox( const std::vector< Primitive >& primitives ) { + ZoneScoped; assert( primitives.size() > 0 ); if ( primitives.size() <= 0 ) return {}; @@ -52,6 +54,7 @@ namespace fgl::engine std::vector< vk::DrawIndexedIndirectCommand > Model::getDrawCommand( const std::uint32_t index ) const { + ZoneScoped; std::vector< vk::DrawIndexedIndirectCommand > draw_commands {}; draw_commands.reserve( m_primitives.size() ); for ( const auto& cmd : m_draw_parameters ) @@ -85,6 +88,7 @@ namespace fgl::engine std::shared_ptr< Model > Model:: createModel( Device& device, const std::filesystem::path& path, Buffer& vertex_buffer, Buffer& index_buffer ) { + ZoneScoped; std::cout << "Creating model: " << path << std::endl; ModelBuilder builder { vertex_buffer, index_buffer }; builder.loadModel( path ); @@ -101,6 +105,7 @@ namespace fgl::engine std::vector< std::shared_ptr< Model > > Model::createModelsFromScene( Device& device, const std::filesystem::path& path, Buffer& vertex_buffer, Buffer& index_buffer ) { + ZoneScoped; std::cout << "Loading scene: " << path << std::endl; SceneBuilder builder { vertex_buffer, index_buffer }; builder.loadScene( path ); @@ -117,6 +122,7 @@ namespace fgl::engine Buffer& vertex_buffer, Buffer& index_buffer ) { + ZoneScoped; ModelBuilder builder { vertex_buffer, index_buffer }; builder.loadVerts( std::move( verts ), std::move( indicies ) ); diff --git a/src/engine/model/builders/ModelBuilder.cpp b/src/engine/model/builders/ModelBuilder.cpp index b02df99..132f2c0 100644 --- a/src/engine/model/builders/ModelBuilder.cpp +++ b/src/engine/model/builders/ModelBuilder.cpp @@ -11,6 +11,7 @@ namespace fgl::engine void ModelBuilder::loadModel( const std::filesystem::path& filepath ) { + ZoneScoped; if ( filepath.extension() == ".obj" ) { loadObj( filepath ); @@ -25,6 +26,7 @@ namespace fgl::engine void ModelBuilder::loadVerts( std::vector< Vertex > verts, std::vector< std::uint32_t > indicies ) { + ZoneScoped; VertexBufferSuballocation vertex_suballoc { this->m_vertex_buffer, verts }; IndexBufferSuballocation index_suballoc { this->m_index_buffer, std::move( indicies ) }; diff --git a/src/engine/model/builders/SceneBuilder.cpp b/src/engine/model/builders/SceneBuilder.cpp index 9a414bf..faf2745 100644 --- a/src/engine/model/builders/SceneBuilder.cpp +++ b/src/engine/model/builders/SceneBuilder.cpp @@ -12,7 +12,7 @@ #include "objectloaders/tiny_gltf.h" #pragma GCC diagnostic pop -#include +#include namespace fgl::engine { @@ -24,6 +24,7 @@ namespace fgl::engine int SceneBuilder::getTexcoordCount( const tinygltf::Primitive& prim ) const { + ZoneScoped; int counter { 0 }; for ( const auto& [ key, value ] : prim.attributes ) { @@ -35,6 +36,7 @@ namespace fgl::engine template < typename T > std::vector< T > extractData( const tinygltf::Model& model, const tinygltf::Accessor& accessor ) { + ZoneScoped; if ( accessor.sparse.isSparse ) { //Sparse loading required @@ -85,8 +87,7 @@ namespace fgl::engine if ( T_SIZE != copy_size ) throw std::runtime_error( - std::string( "Accessor copy values not matching sizeof(T): sizeof(" ) - + std::string( typeid( T ).name() ) + ") == " + std::to_string( T_SIZE ) + std::string( "Accessor copy values not matching sizeof(T): sizeof(T) == " ) + std::to_string( T_SIZE ) + " vs copy_size = " + std::to_string( copy_size ) ); const auto real_size { copy_size * accessor.count }; @@ -101,6 +102,7 @@ namespace fgl::engine std::vector< std::uint32_t > SceneBuilder:: extractIndicies( const tinygltf::Primitive& prim, const tinygltf::Model& model ) { + ZoneScoped; const auto& indicies_accessor { model.accessors.at( prim.indices ) }; if ( indicies_accessor.componentType == TINYGLTF_COMPONENT_TYPE_INT ) @@ -125,11 +127,13 @@ namespace fgl::engine const tinygltf::Accessor& SceneBuilder::getAccessorForAttribute( const tinygltf::Primitive& prim, const tinygltf::Model& root, const std::string attrib ) const { + ZoneScoped; return root.accessors.at( prim.attributes.at( attrib ) ); } Texture SceneBuilder::loadTexture( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { + ZoneScoped; const auto mat_idx { prim.material }; if ( mat_idx == -1 ) { @@ -141,7 +145,7 @@ namespace fgl::engine for ( const auto& [ key, value ] : material.values ) { - spdlog::debug( "Parsing texture for key {}", key ); + log::debug( "Parsing texture for key {}", key ); } //TODO: @@ -150,6 +154,7 @@ namespace fgl::engine std::vector< std::shared_ptr< Model > > SceneBuilder::getModels() { + ZoneScoped; std::vector< std::shared_ptr< Model > > new_models { std::move( models ) }; return new_models; @@ -158,6 +163,7 @@ namespace fgl::engine std::vector< glm::vec3 > SceneBuilder:: extractPositionInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { + ZoneScoped; const tinygltf::Accessor& accessor { getAccessorForAttribute( prim, root, "POSITION" ) }; return extractData< glm::vec3 >( root, accessor ); @@ -166,6 +172,7 @@ namespace fgl::engine std::vector< glm::vec3 > SceneBuilder:: extractNormalInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { + ZoneScoped; if ( !hasAttribute( prim, "NORMAL" ) ) return {}; const tinygltf::Accessor& accessor { getAccessorForAttribute( prim, root, "NORMAL" ) }; @@ -174,7 +181,8 @@ namespace fgl::engine std::vector< glm::vec2 > SceneBuilder::extractUVInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { - spdlog::debug( "Extracting UV info" ); + ZoneScoped; + log::debug( "Extracting UV info" ); //TODO: Figure out how I can use multiple textures for various things. if ( !hasAttribute( prim, "TEXCOORD_0" ) ) return {}; @@ -186,13 +194,15 @@ namespace fgl::engine bool SceneBuilder::hasAttribute( const tinygltf::Primitive& prim, const std::string_view str ) { + ZoneScoped; return prim.attributes.contains( std::string( str ) ); } std::vector< Vertex > SceneBuilder:: extractVertexInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { - spdlog::debug( "Extracting vert info" ); + ZoneScoped; + log::debug( "Extracting vert info" ); const auto pos { extractPositionInfo( prim, root ) }; std::vector< Vertex > verts {}; @@ -219,7 +229,7 @@ namespace fgl::engine verts.emplace_back( vert ); } - spdlog::debug( + log::debug( "Found {} verts.\n\t- Has UV info: {}\n\t- Has normals: {}", verts.size(), has_uv ? "Yes" : "No", @@ -230,12 +240,13 @@ namespace fgl::engine Primitive SceneBuilder::loadPrimitive( const tinygltf::Primitive& prim, const tinygltf::Model& root ) { + ZoneScoped; std::string att_str; for ( const auto& attrib : prim.attributes ) { att_str += "Attribute: " + attrib.first + "\n"; } - spdlog::debug( "Attributes for primitive:\n{}", att_str ); + log::debug( "Attributes for primitive:\n{}", att_str ); const bool has_normal { hasAttribute( prim, "NORMAL" ) }; const bool has_position { hasAttribute( prim, "POSITION" ) }; @@ -278,7 +289,7 @@ namespace fgl::engine } default: { - spdlog::error( "Unsupported mode for primtiive loading: {}", prim.mode ); + log::error( "Unsupported mode for primtiive loading: {}", prim.mode ); throw std::runtime_error( "Unsupported mode for primitive loading" ); } } @@ -288,6 +299,7 @@ namespace fgl::engine OrientedBoundingBox< CoordinateSpace::Model > createModelBoundingBox( const std::vector< Primitive >& primitives ) { + ZoneScoped; if ( primitives.size() <= 0 ) return {}; OrientedBoundingBox< CoordinateSpace::Model > box { primitives.at( 0 ).m_bounding_box }; @@ -299,10 +311,11 @@ namespace fgl::engine std::shared_ptr< Model > SceneBuilder::loadModel( const int mesh_idx, const tinygltf::Model& root ) { + ZoneScoped; const auto mesh { root.meshes[ mesh_idx ] }; const auto& primitives { mesh.primitives }; - spdlog::debug( "Mesh idx {} has {} primitives", mesh_idx, primitives.size() ); + log::debug( "Mesh idx {} has {} primitives", mesh_idx, primitives.size() ); std::vector< Primitive > finished_primitives {}; @@ -312,7 +325,7 @@ namespace fgl::engine finished_primitives.emplace_back( std::move( primitive ) ); } - spdlog::debug( "Finished loading model with {} primitives", finished_primitives.size() ); + log::debug( "Finished loading model with {} primitives", finished_primitives.size() ); const auto bounding_box { createModelBoundingBox( finished_primitives ) }; @@ -321,14 +334,15 @@ namespace fgl::engine void SceneBuilder::handleNode( const int node_idx, const tinygltf::Model& root ) { + ZoneScoped; const auto& node { root.nodes[ node_idx ] }; - spdlog::debug( "Handling node: Index:{} Name:\"{}\"", node_idx, node.name ); + log::debug( "Handling node: Index:{} Name:\"{}\"", node_idx, node.name ); const auto mesh_idx { node.mesh }; const auto skin_idx { node.skin }; - spdlog::debug( "Mesh IDX: {}", mesh_idx ); - spdlog::debug( "Skin IDX: {}", skin_idx ); + log::debug( "Mesh IDX: {}", mesh_idx ); + log::debug( "Skin IDX: {}", skin_idx ); std::shared_ptr< Model > model { loadModel( mesh_idx, root ) }; @@ -340,9 +354,10 @@ namespace fgl::engine void SceneBuilder::handleScene( const tinygltf::Scene& scene, const tinygltf::Model& root ) { - spdlog::debug( "Handling scene: ", scene.name ); + ZoneScoped; + log::debug( "Handling scene: ", scene.name ); - spdlog::debug( "Scene has {} nodes", scene.nodes.size() ); + log::debug( "Scene has {} nodes", scene.nodes.size() ); for ( const auto node_idx : scene.nodes ) { handleNode( node_idx, root ); @@ -351,6 +366,7 @@ namespace fgl::engine void SceneBuilder::loadScene( const std::filesystem::path path ) { + ZoneScoped; if ( !std::filesystem::exists( path ) ) throw std::runtime_error( "Failed to find scene at filepath" ); tinygltf::TinyGLTF loader {}; @@ -366,13 +382,13 @@ namespace fgl::engine if ( !err.empty() ) { - spdlog::error( "Error loading model {}: \"{}\"", path.string(), err ); + log::error( "Error loading model {}: \"{}\"", path.string(), err ); throw std::runtime_error( err ); } if ( !warn.empty() ) { - spdlog::warn( "Warning loading model {}: \"{}\"", path.string(), warn ); + log::warn( "Warning loading model {}: \"{}\"", path.string(), warn ); } const auto scenes { gltf_model.scenes }; diff --git a/src/engine/model/builders/loadGltf.cpp b/src/engine/model/builders/loadGltf.cpp index 2f91344..a46fa57 100644 --- a/src/engine/model/builders/loadGltf.cpp +++ b/src/engine/model/builders/loadGltf.cpp @@ -21,6 +21,7 @@ namespace fgl::engine template < typename T > std::vector< T > extractData( const tinygltf::Model& model, const tinygltf::Accessor& accessor ) { + ZoneScoped; if ( accessor.sparse.isSparse ) { //Sparse loading required @@ -71,8 +72,7 @@ namespace fgl::engine if ( T_SIZE != copy_size ) throw std::runtime_error( - std::string( "Accessor copy values not matching sizeof(T): sizeof(" ) - + std::string( typeid( T ).name() ) + ") == " + std::to_string( T_SIZE ) + std::string( "Accessor copy values not matching sizeof(T): sizeof(T) == " ) + std::to_string( T_SIZE ) + " vs copy_size = " + std::to_string( copy_size ) ); const auto real_size { copy_size * accessor.count }; @@ -86,6 +86,7 @@ namespace fgl::engine void ModelBuilder::loadGltf( const std::filesystem::path& filepath ) { + ZoneScoped; std::cout << "Loading gltf model " << filepath << std::endl; if ( !std::filesystem::exists( filepath ) ) throw std::runtime_error( "File does not exist" ); diff --git a/src/engine/pipeline/Shader.hpp b/src/engine/pipeline/Shader.hpp index 2134ed2..39f901f 100644 --- a/src/engine/pipeline/Shader.hpp +++ b/src/engine/pipeline/Shader.hpp @@ -6,7 +6,7 @@ #include -#include "engine/logging.hpp" +#include "engine/logging/logging.hpp" namespace fgl::engine { @@ -62,7 +62,7 @@ namespace fgl::engine } else { - spdlog::critical( "Failed to load shader module {}. Path not found", path.string() ); + log::critical( "Failed to load shader module {}. Path not found", path.string() ); throw std::runtime_error( "Failed to load shader module. Path not found" ); } } diff --git a/src/engine/primitives/Frustum.cpp b/src/engine/primitives/Frustum.cpp index 969e641..365fe09 100644 --- a/src/engine/primitives/Frustum.cpp +++ b/src/engine/primitives/Frustum.cpp @@ -8,7 +8,6 @@ #include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp" #include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" -#include "imgui/imgui.h" namespace fgl::engine { @@ -173,6 +172,7 @@ namespace fgl::engine void imGuiFrustumSettings() { + /* #if ENABLE_IMGUI //Check if any of the box's points are inside the frustum if ( ImGui::CollapsingHeader( "Frustum intersection settings" ) ) @@ -189,6 +189,7 @@ namespace fgl::engine } } #endif + */ } template <> diff --git a/src/engine/primitives/Rotation.hpp b/src/engine/primitives/Rotation.hpp index 776ed18..41e48d0 100644 --- a/src/engine/primitives/Rotation.hpp +++ b/src/engine/primitives/Rotation.hpp @@ -74,13 +74,13 @@ namespace fgl::engine Rotation( const glm::quat other ) : glm::quat( other ) {} - auto pitch() { return RotationModifier< RotationModifierType::Pitch >( *this ); } + FGL_FORCE_INLINE_FLATTEN auto pitch() { return RotationModifier< RotationModifierType::Pitch >( *this ); } - auto roll() { return RotationModifier< RotationModifierType::Roll >( *this ); } + FGL_FORCE_INLINE_FLATTEN auto roll() { return RotationModifier< RotationModifierType::Roll >( *this ); } - auto yaw() { return RotationModifier< RotationModifierType::Yaw >( *this ); } + FGL_FORCE_INLINE_FLATTEN auto yaw() { return RotationModifier< RotationModifierType::Yaw >( *this ); } - float pitch() const + FGL_FORCE_INLINE float pitch() const { //TODO: Ask entry to explain this stuff const float sinr_cosp { 2.0f * ( w * x + y * z ) }; @@ -88,14 +88,14 @@ namespace fgl::engine return std::atan2( sinr_cosp, cosr_cosp ); } - float roll() const + FGL_FORCE_INLINE float roll() const { const float sinp { glm::sqrt( 1.0f + 2.0f * ( w * y - x * z ) ) }; const float cosp { glm::sqrt( 1.0f - 2.0f * ( w * y - x * z ) ) }; return 2.0f * std::atan2( sinp, cosp ) - ( std::numbers::pi_v< float > / 2.0f ); } - float yaw() const + FGL_FORCE_INLINE float yaw() const { const float siny_cosp { 2.0f * ( w * z + x * y ) }; const float cosy_cosp { 1.0f - 2.0f * ( y * y + z * z ) }; @@ -120,7 +120,7 @@ namespace fgl::engine }; template < RotationModifierType ModifierType > - RotationModifier< ModifierType >::operator float() const + FGL_FORCE_INLINE_FLATTEN RotationModifier< ModifierType >::operator float() const { switch ( ModifierType ) { diff --git a/src/engine/primitives/boxes/OrientedBoundingBox.cpp b/src/engine/primitives/boxes/OrientedBoundingBox.cpp index 6ebf85e..f63ad79 100644 --- a/src/engine/primitives/boxes/OrientedBoundingBox.cpp +++ b/src/engine/primitives/boxes/OrientedBoundingBox.cpp @@ -8,7 +8,7 @@ #include -#include "engine/logging.hpp" +#include "engine/logging/logging.hpp" #include "engine/model/Vertex.hpp" #include "engine/primitives/lines/LineSegment.hpp" #include "engine/primitives/points/Coordinate.hpp" @@ -238,7 +238,7 @@ namespace fgl::engine OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< Vertex >& verts ) { - spdlog::debug( "Generating bounding box for {} verts", verts.size() ); + log::debug( "Generating bounding box for {} verts", verts.size() ); // neg (min) glm::vec3 top_right_forward { verts[ 0 ].m_position }; // pos (max) diff --git a/src/engine/rendering/Device.cpp b/src/engine/rendering/Device.cpp index bac2a83..1b89999 100644 --- a/src/engine/rendering/Device.cpp +++ b/src/engine/rendering/Device.cpp @@ -8,7 +8,7 @@ #include #include -#include "engine/logging.hpp" +#include "engine/logging/logging.hpp" PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT { nullptr }; PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT { nullptr }; @@ -22,23 +22,24 @@ static VKAPI_ATTR vk::Bool32 VKAPI_CALL debugCallback( [[maybe_unused]] void* pUserData ) { using Bits = VkDebugUtilsMessageSeverityFlagBitsEXT; + using namespace fgl::engine; if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT ) { - spdlog::info( pCallbackData->pMessage ); + log::info( pCallbackData->pMessage ); } else if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT ) { - spdlog::warn( pCallbackData->pMessage ); + log::warn( pCallbackData->pMessage ); } else if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT ) { - spdlog::error( pCallbackData->pMessage ); + log::error( pCallbackData->pMessage ); std::abort(); } else { - //spdlog::critical( "Unknown severity message: {}", pCallbackData->pMessage ); + //log::critical( "Unknown severity message: {}", pCallbackData->pMessage ); //std::abort(); } @@ -570,6 +571,7 @@ namespace fgl::engine vk::CommandBuffer Device::beginSingleTimeCommands() { + ZoneScoped; vk::CommandBufferAllocateInfo allocInfo {}; allocInfo.level = vk::CommandBufferLevel::ePrimary; allocInfo.commandPool = m_commandPool; @@ -589,6 +591,7 @@ namespace fgl::engine void Device::endSingleTimeCommands( vk::CommandBuffer commandBuffer ) { + ZoneScoped; vkEndCommandBuffer( commandBuffer ); vk::SubmitInfo submitInfo {}; @@ -606,6 +609,7 @@ namespace fgl::engine void Device:: copyBufferToImage( vk::Buffer buffer, vk::Image image, uint32_t width, uint32_t height, uint32_t layerCount ) { + ZoneScoped; vk::CommandBuffer commandBuffer { beginSingleTimeCommands() }; vk::BufferImageCopy region {}; diff --git a/src/engine/systems/EntityRendererSystem.cpp b/src/engine/systems/EntityRendererSystem.cpp index 1cbdd14..a9c58b9 100644 --- a/src/engine/systems/EntityRendererSystem.cpp +++ b/src/engine/systems/EntityRendererSystem.cpp @@ -4,14 +4,12 @@ #include "EntityRendererSystem.hpp" -#include #include #include #include #include "DrawPair.hpp" -#include "engine/debug/drawers.hpp" #include "engine/literals/size.hpp" #include "engine/tree/octtree/OctTreeNode.hpp" diff --git a/src/engine/texture/Texture.cpp b/src/engine/texture/Texture.cpp index e6153fe..80ebe72 100644 --- a/src/engine/texture/Texture.cpp +++ b/src/engine/texture/Texture.cpp @@ -22,6 +22,8 @@ #include "imgui/backends/imgui_impl_vulkan.h" #pragma GCC diagnostic pop +#include "engine/logging/logging.hpp" + namespace fgl::engine { @@ -53,6 +55,7 @@ namespace fgl::engine Texture Texture::loadFromFile( const std::filesystem::path& path ) { ZoneScoped; + log::debug( "Loading texture: {}", path ); //TODO: Make some way of cleaning the map when loading textures if ( texture_map.contains( path.string() ) ) @@ -74,11 +77,42 @@ namespace fgl::engine texture_map.emplace( path.string(), tex.m_handle ); + log::debug( "Loaded texture at {} with res {}x{}", path, tex.getExtent().width, tex.getExtent().height ); + return std::move( tex ); } + void Texture::drawImGui( vk::Extent2D extent ) + { + if ( this->m_handle->m_imgui_set == VK_NULL_HANDLE ) createImGuiSet(); + + if ( extent == vk::Extent2D() ) + { + extent = getExtent(); + } + + const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) }; + + ImGui::Image( static_cast< ImTextureID >( getImGuiDescriptorSet() ), imgui_size ); + } + + bool Texture::drawImGuiButton( vk::Extent2D extent ) + { + if ( this->m_handle->m_imgui_set == VK_NULL_HANDLE ) createImGuiSet(); + + if ( extent == vk::Extent2D() ) + { + extent = getExtent(); + } + + const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) }; + + return ImGui::ImageButton( static_cast< ImTextureID >( getImGuiDescriptorSet() ), imgui_size ); + } + Texture Texture::generateFromPerlinNoise( int x_size, int y_size, std::size_t seed ) { + ZoneScoped; const std::vector< std::byte > data { generatePerlinImage( { x_size, y_size }, 15, seed ) }; Texture tex { data, x_size, y_size, 4 }; @@ -207,7 +241,12 @@ namespace fgl::engine auto& view { m_handle->m_image_view }; + assert( view ); + VkImageView vk_view { view->getVkView() }; + assert( vk_view ); + + assert( view->getSampler() ); VkSampler vk_sampler { view->getSampler()->getVkSampler() }; m_handle->m_imgui_set = diff --git a/src/engine/texture/Texture.hpp b/src/engine/texture/Texture.hpp index f51a22c..c338af0 100644 --- a/src/engine/texture/Texture.hpp +++ b/src/engine/texture/Texture.hpp @@ -53,6 +53,9 @@ namespace fgl::engine [[nodiscard]] static Texture generateFromPerlinNoise( int x_size, int y_size, std::size_t seed = 0 ); [[nodiscard]] static Texture loadFromFile( const std::filesystem::path& path ); + void drawImGui( vk::Extent2D extent = {} ); + bool drawImGuiButton(vk::Extent2D extent = {}); + static DescriptorSet& getTextureDescriptorSet(); };