From e0e420605600fa98234788d2cb20430cc7836806 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Wed, 9 Jul 2025 08:08:54 -0400 Subject: [PATCH 01/22] Fixes Material defaults being suboptimal for material-less objects --- src/assets/TransferTest/Orbs.bin | 4 ++-- src/assets/TransferTest/Orbs.gltf | 4 ++-- src/assets/invalid.png | 4 ++-- src/engine/assets/material/Material.hpp | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/assets/TransferTest/Orbs.bin b/src/assets/TransferTest/Orbs.bin index 4b056f2..848394a 100644 --- a/src/assets/TransferTest/Orbs.bin +++ b/src/assets/TransferTest/Orbs.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6ec4bff357474c050373cfa4fa977de9e24f71a092d69f5f876b4666d33d0889 -size 66846720 +oid sha256:14a63bb12d426dd02dc054d5669cc88f3dc9223b7143165ee4172a37bcc5f6b8 +size 132736 diff --git a/src/assets/TransferTest/Orbs.gltf b/src/assets/TransferTest/Orbs.gltf index 58bd7ab..cc3e8d3 100644 --- a/src/assets/TransferTest/Orbs.gltf +++ b/src/assets/TransferTest/Orbs.gltf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e8356cdd06fca6e13a881e2e697a7d217f80a9140db30e3e33a33729063098bb -size 2744 +oid sha256:8cb1a22bb6a816df2bf391fb7af925c833a5e46c0c279c43548cbf7f26baf851 +size 2336 diff --git a/src/assets/invalid.png b/src/assets/invalid.png index e8b9008..5687178 100644 --- a/src/assets/invalid.png +++ b/src/assets/invalid.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a98a975d0a53739ffcb54c387359b098ef601c1b5b8dcb4457e52ca4a1c7814d -size 193 +oid sha256:28fc77df0125c8b7c05eed643ad37172930e4521e7afa61c5f3bec26ba90ba0a +size 1618 diff --git a/src/engine/assets/material/Material.hpp b/src/engine/assets/material/Material.hpp index cf5dd91..b7cc0c3 100644 --- a/src/engine/assets/material/Material.hpp +++ b/src/engine/assets/material/Material.hpp @@ -45,7 +45,7 @@ namespace fgl::engine struct { std::shared_ptr< Texture > m_color_tex {}; - glm::vec4 m_color_factors { 0.0f }; + glm::vec4 m_color_factors { 1.0f }; std::shared_ptr< Texture > m_metallic_roughness_tex; float m_metallic_factor { 0.0f }; @@ -54,19 +54,19 @@ namespace fgl::engine struct { - float m_scale { 0.0f }; + float m_scale { 1.0f }; std::shared_ptr< Texture > m_texture; } m_normal; struct { - float m_strength { 0.0f }; + float m_strength { 1.0f }; std::shared_ptr< Texture > m_texture; } m_occlusion; struct { - glm::vec3 m_factors { 0.0f }; + glm::vec3 m_factors { 1.0f }; std::shared_ptr< Texture > m_texture; } m_emissive; @@ -85,7 +85,7 @@ namespace fgl::engine alignas( 16 ) struct Albedo { TextureID color_texture_id { constants::INVALID_TEXTURE_ID }; - alignas( 4 * 4 ) glm::vec4 color_factors {}; + alignas( 4 * 4 ) glm::vec4 color_factors { 1.0f, 1.0f, 1.0f, 1.0f }; } color; alignas( 16 ) struct Metallic -- 2.49.1 From 5ddf5d3466b5814006cf8ae8a67cf4fd1fc843aa Mon Sep 17 00:00:00 2001 From: kj16609 Date: Wed, 9 Jul 2025 09:00:39 -0400 Subject: [PATCH 02/22] Improves small copy handling in TransferData --- src/engine/assets/transfer/TransferData.cpp | 6 ++--- src/engine/memory/buffers/BufferHandle.cpp | 11 +++++++++ .../buffers/BufferSuballocationHandle.cpp | 9 ++++--- .../buffers/BufferSuballocationHandle.hpp | 4 ++-- .../memory/buffers/vector/BufferVector.cpp | 11 ++++++++- .../memory/buffers/vector/DeviceVector.hpp | 2 +- .../memory/buffers/vector/IndexedVector.hpp | 24 ++++++++++++++----- 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/engine/assets/transfer/TransferData.cpp b/src/engine/assets/transfer/TransferData.cpp index 761e113..71571c0 100644 --- a/src/engine/assets/transfer/TransferData.cpp +++ b/src/engine/assets/transfer/TransferData.cpp @@ -116,11 +116,11 @@ namespace fgl::engine::memory bool TransferData::performBufferStage( CopyRegionMap& copy_regions ) { ZoneScoped; - auto& source { std::get< TransferBufferHandle >( m_source ) }; - auto& target { std::get< TransferBufferHandle >( m_target ) }; + const auto& source { std::get< TransferBufferHandle >( m_source ) }; + const auto& target { std::get< TransferBufferHandle >( m_target ) }; const CopyRegionKey key { std::make_pair( source->getBuffer(), target->getBuffer() ) }; - const auto copy_info { source->copyRegion( *target, m_target_offset ) }; + const auto copy_info { source->copyRegion( *target, m_target_offset, m_size ) }; if ( auto itter = copy_regions.find( key ); itter != copy_regions.end() ) { diff --git a/src/engine/memory/buffers/BufferHandle.cpp b/src/engine/memory/buffers/BufferHandle.cpp index 11c259f..f1c0694 100644 --- a/src/engine/memory/buffers/BufferHandle.cpp +++ b/src/engine/memory/buffers/BufferHandle.cpp @@ -335,6 +335,17 @@ namespace fgl::engine::memory const auto aligned_offset { align( selected_block_offset, alignment(), t_alignment ) }; FGL_ASSERT( aligned_offset % combineAlignment( alignment(), t_alignment ) == 0, "Alignment failed!" ); + const auto stride { t_alignment }; + FGL_ASSERT( + aligned_offset % stride == 0, + std::format( + "{} % {} != 0 (Was {}). The offset should be aligned with the stride, alignment() = {}, t_alignment = {}", + aligned_offset, + stride, + aligned_offset % stride, + alignment(), + t_alignment ) ); + //Fix the offset and size if they aren't alligned if ( aligned_offset != selected_block_offset ) { diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.cpp b/src/engine/memory/buffers/BufferSuballocationHandle.cpp index be170e0..638abed 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.cpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.cpp @@ -27,6 +27,7 @@ namespace fgl::engine::memory m_alignment( alignment ), m_ptr( m_parent_buffer->map( *this ) ) { + if ( memory_size == 1024 ) throw std::runtime_error( "AAAAA" ); // assert( memory_size != 0 && "BufferSuballocation::BufferSuballocation() called with memory_size == 0" ); } @@ -40,11 +41,13 @@ namespace fgl::engine::memory m_parent_buffer->free( *this ); } - vk::BufferCopy BufferSuballocationHandle:: - copyRegion( const BufferSuballocationHandle& target, const std::size_t suballocation_offset ) const + vk::BufferCopy BufferSuballocationHandle::copyRegion( + const BufferSuballocationHandle& target, + const std::size_t suballocation_offset, + const vk::DeviceSize size ) const { vk::BufferCopy copy {}; - copy.size = std::min( this->m_size, target.m_size ); + copy.size = size == 0 ? std::min( this->m_size, target.m_size ) : size; copy.srcOffset = this->offset(); copy.dstOffset = target.offset() + suballocation_offset; return copy; diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.hpp b/src/engine/memory/buffers/BufferSuballocationHandle.hpp index 4a8693b..31c240f 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.hpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.hpp @@ -78,8 +78,8 @@ namespace fgl::engine::memory void setReady( bool value ); - [[nodiscard]] vk::BufferCopy - copyRegion( const BufferSuballocationHandle& target, std::size_t suballocation_offset ) const; + [[nodiscard]] vk::BufferCopy copyRegion( + const BufferSuballocationHandle& target, std::size_t suballocation_offset, vk::DeviceSize size = 0 ) const; [[nodiscard]] vk::Buffer getBuffer() const; [[nodiscard]] vk::Buffer getVkBuffer() const; diff --git a/src/engine/memory/buffers/vector/BufferVector.cpp b/src/engine/memory/buffers/vector/BufferVector.cpp index dbafe7d..31e2a6a 100644 --- a/src/engine/memory/buffers/vector/BufferVector.cpp +++ b/src/engine/memory/buffers/vector/BufferVector.cpp @@ -10,7 +10,9 @@ namespace fgl::engine::memory { - constexpr std::uint32_t min_capacity { 1024 }; + //TODO: Lower this number to make small copies not as impactful to the staging buffer. + // For some reason lowing this to a very low value causes the alignment for allocations to fail. + constexpr std::uint32_t min_capacity { 512 }; [[nodiscard]] BufferVector::BufferVector( Buffer& buffer, const std::uint32_t count, const std::uint32_t stride ) : BufferSuballocation( buffer.allocate( std::max( count, min_capacity ) * stride, stride ) ), @@ -26,6 +28,13 @@ namespace fgl::engine::memory m_offset, m_stride, m_offset % m_stride ) ); + FGL_ASSERT( + count * stride <= this->bytesize(), + std::format( + "Allocation create insufficent buffer for count * stride = {} * {} > {}", + count, + stride, + this->bytesize() ) ); } //! Returns the offset count from the start of the buffer to the first element diff --git a/src/engine/memory/buffers/vector/DeviceVector.hpp b/src/engine/memory/buffers/vector/DeviceVector.hpp index c5a8df8..e5e69e8 100644 --- a/src/engine/memory/buffers/vector/DeviceVector.hpp +++ b/src/engine/memory/buffers/vector/DeviceVector.hpp @@ -11,7 +11,7 @@ namespace fgl::engine::memory { - struct Buffer; + class Buffer; } namespace fgl::engine diff --git a/src/engine/memory/buffers/vector/IndexedVector.hpp b/src/engine/memory/buffers/vector/IndexedVector.hpp index e6610cc..92e677d 100644 --- a/src/engine/memory/buffers/vector/IndexedVector.hpp +++ b/src/engine/memory/buffers/vector/IndexedVector.hpp @@ -33,6 +33,8 @@ namespace fgl::engine class Index { + static_assert( std::is_default_constructible_v< T >, "T must be default constructible" ); + T m_source_data {}; IndexedVector< T >& m_vector; std::uint32_t m_idx { std::numeric_limits< std::uint32_t >::max() }; @@ -48,20 +50,30 @@ namespace fgl::engine using Vec = IndexedVector; - void update( const T& t ) { return m_vector.updateData( m_idx, t ); } - - Index& operator=( const Index& other ) = delete; - - Index( const Index& other ) : m_vector( other.m_vector ), m_idx( m_vector.acquireInternal() ) + void update( const T& t ) { - //TODO: Update the data from the original item + static_assert( std::is_copy_constructible_v< T >, "T must be copy constructible" ); + m_source_data = t; + return m_vector.updateData( m_idx, t ); } + // Copy + Index& operator=( const Index& other ) = delete; + + // Copy + Index( const Index& other ) : m_vector( other.m_vector ), m_idx( m_vector.acquireInternal() ) + { + update( other.m_source_data ); + } + + // Move Index& operator=( Index&& other ) = delete; + // Move Index( Index&& other ) noexcept : m_vector( other.m_vector ), m_idx( other.m_idx ) { other.m_idx = std::numeric_limits< std::uint32_t >::max(); + update( other.m_source_data ); } // Privated to force returning to the IndexedVector -- 2.49.1 From 554d37929e7e6ae13d6cf6780b3edb88f55048a9 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Wed, 9 Jul 2025 09:01:45 -0400 Subject: [PATCH 03/22] Adds big orb test --- src/assets/TransferTest/LottaOrbs.bin | 3 +++ src/assets/TransferTest/LottaOrbs.gltf | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 src/assets/TransferTest/LottaOrbs.bin create mode 100644 src/assets/TransferTest/LottaOrbs.gltf diff --git a/src/assets/TransferTest/LottaOrbs.bin b/src/assets/TransferTest/LottaOrbs.bin new file mode 100644 index 0000000..1fbd70a --- /dev/null +++ b/src/assets/TransferTest/LottaOrbs.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de3c18e3e75f3f4c4dbbfafbfe93100e06cc8d67b3723ae245eff55767d1b942 +size 983520 diff --git a/src/assets/TransferTest/LottaOrbs.gltf b/src/assets/TransferTest/LottaOrbs.gltf new file mode 100644 index 0000000..92d2835 --- /dev/null +++ b/src/assets/TransferTest/LottaOrbs.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59e6d13ef8cb765bf3c1a1495ec36fa5a335893adf91d9fec3080845e1c45d38 +size 126774 -- 2.49.1 From 126bfab3e828b0132a70cbd65a7849b04c5e4296 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Tue, 23 Sep 2025 02:28:34 -0400 Subject: [PATCH 04/22] Fixes missing ; --- src/shaders/gui-compose.slang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shaders/gui-compose.slang b/src/shaders/gui-compose.slang index a2cb13b..7c063d2 100644 --- a/src/shaders/gui-compose.slang +++ b/src/shaders/gui-compose.slang @@ -17,7 +17,7 @@ Vertex vertexMain( uint index : SV_VertexID ) struct FragOut { vec4 color; -} +}; [shader("fragment")] FragOut fragmentMain( Vertex vertex ) -- 2.49.1 From 43716bd46328f657aeaf86fb7928ff10abd98fd2 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Tue, 23 Sep 2025 02:30:04 -0400 Subject: [PATCH 05/22] Remove buffer resizing --- src/engine/assets/transfer/TransferData.cpp | 34 +- .../assets/transfer/TransferManager.cpp | 2 +- src/engine/memory/buffers/BufferHandle.cpp | 434 +++++++----------- src/engine/memory/buffers/BufferHandle.hpp | 39 +- .../buffers/BufferSuballocationHandle.cpp | 65 ++- .../buffers/BufferSuballocationHandle.hpp | 16 - 6 files changed, 231 insertions(+), 359 deletions(-) diff --git a/src/engine/assets/transfer/TransferData.cpp b/src/engine/assets/transfer/TransferData.cpp index 71571c0..ec40398 100644 --- a/src/engine/assets/transfer/TransferData.cpp +++ b/src/engine/assets/transfer/TransferData.cpp @@ -29,6 +29,23 @@ namespace fgl::engine::memory return seed; } + bool TransferData::convertRawToBuffer( Buffer& staging_buffer ) + { + // Prepare the staging buffer first. + assert( std::holds_alternative< RawData >( m_source ) ); + assert( !std::get< RawData >( m_source ).empty() ); + + // Check if we are capable of allocating into the staging buffer + if ( !staging_buffer->canAllocate( std::get< RawData >( m_source ).size(), 1 ) ) return false; + + HostVector< std::byte > vector { staging_buffer, std::get< RawData >( m_source ) }; + + m_source = vector.getHandle(); + std::get< TransferBufferHandle >( m_source )->setReady( true ); + + return true; + } + bool TransferData:: performImageStage( vk::raii::CommandBuffer& cmd_buffer, std::uint32_t transfer_idx, std::uint32_t graphics_idx ) { @@ -142,23 +159,6 @@ namespace fgl::engine::memory return performBufferStage( copy_regions ); } - bool TransferData::convertRawToBuffer( Buffer& staging_buffer ) - { - // Prepare the staging buffer first. - assert( std::holds_alternative< RawData >( m_source ) ); - assert( !std::get< RawData >( m_source ).empty() ); - - // Check if we are capable of allocating into the staging buffer - if ( !staging_buffer->canAllocate( std::get< RawData >( m_source ).size(), 1 ) ) return false; - - HostVector< std::byte > vector { staging_buffer, std::get< RawData >( m_source ) }; - - m_source = vector.getHandle(); - std::get< TransferBufferHandle >( m_source )->setReady( true ); - - return true; - } - bool TransferData::stage( vk::raii::CommandBuffer& buffer, Buffer& staging_buffer, diff --git a/src/engine/assets/transfer/TransferManager.cpp b/src/engine/assets/transfer/TransferManager.cpp index f621cfe..3772278 100644 --- a/src/engine/assets/transfer/TransferManager.cpp +++ b/src/engine/assets/transfer/TransferManager.cpp @@ -96,7 +96,7 @@ namespace fgl::engine::memory void TransferManager::resizeBuffer( const std::uint64_t size ) { - m_staging_buffer.resize( size ); + // m_staging_buffer.resize( size ); } void TransferManager::copySuballocationRegion( diff --git a/src/engine/memory/buffers/BufferHandle.cpp b/src/engine/memory/buffers/BufferHandle.cpp index f1c0694..ae6df13 100644 --- a/src/engine/memory/buffers/BufferHandle.cpp +++ b/src/engine/memory/buffers/BufferHandle.cpp @@ -11,15 +11,71 @@ #include "align.hpp" #include "assets/transfer/TransferManager.hpp" #include "engine/debug/logging/logging.hpp" -#include "engine/memory/buffers/BufferHandle.hpp" #include "engine/memory/buffers/exceptions.hpp" #include "engine/rendering/devices/Device.hpp" #include "math/literals/size.hpp" -#include "memory/DefferedCleanup.hpp" namespace fgl::engine::memory { + std::tuple< vk::Buffer, VmaAllocationInfo, VmaAllocation > BufferHandle::allocBuffer( + const vk::DeviceSize memory_size, vk::BufferUsageFlags usage, const vk::MemoryPropertyFlags property_flags ) + { + // Used for resizing. + //TODO: Make this only available if resize is desired. Otherwise do not have it. + usage |= vk::BufferUsageFlagBits::eTransferDst; + usage |= vk::BufferUsageFlagBits::eTransferSrc; + + assert( memory_size > 0 ); + vk::BufferCreateInfo buffer_info {}; + buffer_info.pNext = VK_NULL_HANDLE; + buffer_info.flags = {}; + buffer_info.size = memory_size; + buffer_info.usage = usage; + buffer_info.sharingMode = vk::SharingMode::eExclusive; + buffer_info.queueFamilyIndexCount = 0; + buffer_info.pQueueFamilyIndices = VK_NULL_HANDLE; + + VmaAllocationCreateInfo create_info {}; + + create_info.usage = VMA_MEMORY_USAGE_AUTO; + + if ( property_flags & vk::MemoryPropertyFlagBits::eHostVisible ) + create_info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; + + if ( usage & vk::BufferUsageFlagBits::eTransferSrc ) + { + //Remove VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM BIT if we are transfer src + create_info.flags &= ~VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; + + create_info.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; + } + + VmaAllocationInfo alloc_info {}; + VmaAllocation allocation {}; + + const VkBufferCreateInfo& vk_buffer_info = buffer_info; + VkBuffer buffer { VK_NULL_HANDLE }; + if ( vmaCreateBuffer( + Device::getInstance().allocator(), &vk_buffer_info, &create_info, &buffer, &allocation, nullptr ) + != VK_SUCCESS ) + { + throw BufferException( "Unable to allocate memory in VMA" ); + } + + vmaGetAllocationInfo( Device::getInstance().allocator(), allocation, &alloc_info ); + + return std::make_tuple< + vk::Buffer, + VmaAllocationInfo, + VmaAllocation >( std::move( buffer ), std::move( alloc_info ), std::move( allocation ) ); + } + + void BufferHandle::deallocBuffer( const vk::Buffer& buffer, const VmaAllocation& allocation ) + { + vmaDestroyBuffer( Device::getInstance().allocator(), buffer, allocation ); + } + void BufferHandle::swap( BufferHandle& other ) noexcept { std::swap( m_buffer, other.m_buffer ); @@ -83,229 +139,43 @@ namespace fgl::engine::memory deallocBuffer( m_buffer, m_allocation ); } - void* BufferHandle::map( const BufferSuballocationHandle& handle ) const + vk::DeviceSize BufferHandle::largestBlock() const { - if ( m_alloc_info.pMappedData == nullptr ) return nullptr; + vk::DeviceSize largest { 0 }; - return static_cast< std::byte* >( m_alloc_info.pMappedData ) + handle.offset(); + for ( const auto& size : m_free_blocks | std::views::values ) + { + largest = std::max( largest, size ); + } + + return largest; } - void BufferHandle::deallocBuffer( const vk::Buffer& buffer, const VmaAllocation& allocation ) + vk::DeviceSize BufferHandle::used() const { - vmaDestroyBuffer( Device::getInstance().allocator(), buffer, allocation ); + vk::DeviceSize total_size { 0 }; + + for ( auto& suballocation : m_active_suballocations ) + { + if ( suballocation.expired() ) continue; + total_size += suballocation.lock()->size(); + } + + return total_size; } - std::tuple< vk::Buffer, VmaAllocationInfo, VmaAllocation > BufferHandle::allocBuffer( - const vk::DeviceSize memory_size, vk::BufferUsageFlags usage, const vk::MemoryPropertyFlags property_flags ) + vk::DeviceMemory BufferHandle::getMemory() const { - // Used for resizing. - //TODO: Make this only available if resize is desired. Otherwise do not have it. - usage |= vk::BufferUsageFlagBits::eTransferDst; - usage |= vk::BufferUsageFlagBits::eTransferSrc; + assert( m_alloc_info.deviceMemory != VK_NULL_HANDLE ); - assert( memory_size > 0 ); - vk::BufferCreateInfo buffer_info {}; - buffer_info.pNext = VK_NULL_HANDLE; - buffer_info.flags = {}; - buffer_info.size = memory_size; - buffer_info.usage = usage; - buffer_info.sharingMode = vk::SharingMode::eExclusive; - buffer_info.queueFamilyIndexCount = 0; - buffer_info.pQueueFamilyIndices = VK_NULL_HANDLE; - - VmaAllocationCreateInfo create_info {}; - - create_info.usage = VMA_MEMORY_USAGE_AUTO; - - if ( property_flags & vk::MemoryPropertyFlagBits::eHostVisible ) - create_info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; - - if ( usage & vk::BufferUsageFlagBits::eTransferSrc ) - { - //Remove VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM BIT if we are transfer src - create_info.flags &= ~VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; - - create_info.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; - } - - VmaAllocationInfo alloc_info {}; - VmaAllocation allocation {}; - - const VkBufferCreateInfo& vk_buffer_info = buffer_info; - VkBuffer buffer { VK_NULL_HANDLE }; - if ( vmaCreateBuffer( - Device::getInstance().allocator(), &vk_buffer_info, &create_info, &buffer, &allocation, nullptr ) - != VK_SUCCESS ) - { - throw BufferException( "Unable to allocate memory in VMA" ); - } - - vmaGetAllocationInfo( Device::getInstance().allocator(), allocation, &alloc_info ); - - return std::make_tuple< - vk::Buffer, - VmaAllocationInfo, - VmaAllocation >( std::move( buffer ), std::move( alloc_info ), std::move( allocation ) ); + return m_alloc_info.deviceMemory; } - vk::DeviceSize BufferHandle::alignment() const + std::string BufferHandle::sizeName() const { - vk::DeviceSize size { 1 }; - - if ( m_usage & vk::BufferUsageFlagBits::eStorageBuffer ) - { - size = std::max( size, Device::getInstance().m_properties.limits.minStorageBufferOffsetAlignment ); - } - - if ( m_usage & vk::BufferUsageFlagBits::eUniformBuffer ) - { - size = std::max( size, Device::getInstance().m_properties.limits.minUniformBufferOffsetAlignment ); - } - - if ( m_memory_properties & vk::MemoryPropertyFlagBits::eHostVisible ) - { - size = std::max( size, Device::getInstance().m_properties.limits.nonCoherentAtomSize ); - } - - return size; + return std::format( "{}: {}", m_debug_name, literals::size_literals::toString( size() ) ); } - decltype( BufferHandle::m_free_blocks )::iterator BufferHandle:: - findAvailableBlock( vk::DeviceSize memory_size, std::uint32_t t_alignment ) - { - //Find a free space. - return std::ranges::find_if( - m_free_blocks, - [ this, memory_size, t_alignment ]( const std::pair< vk::DeviceSize, vk::DeviceSize >& pair ) - { - const auto [ offset, size ] = pair; - - const auto new_offset = align( offset, alignment(), t_alignment ); - const auto after_size { size - ( new_offset - offset ) }; - - // If the size of the block after alignment is greater than or equal to the size of the memory we want to allocate using it. - return after_size >= memory_size; - } ); - } - - BufferSuballocation Buffer::allocate( const vk::DeviceSize desired_size, const std::uint32_t alignment ) - { - auto allocation { operator->()->allocate( desired_size, alignment ) }; - - if ( !allocation ) - { - // Resize to x1.5 the size, or the size plus the desired size x1.5, Whichever is bigger - const auto optimal_size { std::max( this->size() * 2, this->size() + desired_size * 2 ) }; - this->resize( optimal_size ); - - FGL_ASSERT( optimal_size == this->size(), "Optimal size not met!" ); - - allocation = operator->()->allocate( desired_size, alignment ); - } - - return allocation; - } - - void Buffer::resize( const vk::DeviceSize size ) - { - const std::shared_ptr< BufferHandle > old_handle { *this }; - const auto new_handle { old_handle->remake( size ) }; - new_handle->setDebugName( old_handle->m_debug_name ); - - *this = new_handle; - } - - std::shared_ptr< BufferHandle > BufferHandle::remake( vk::DeviceSize new_size ) - { - ZoneScoped; - auto new_handle { std::make_shared< BufferHandle >( new_size, m_usage, m_memory_properties ) }; - - const auto& old_allocations { m_active_suballocations }; - const auto& old_allocations_traces { m_allocation_traces }; - - // Remake all allocations into the new buffer - std::vector< - std::pair< std::shared_ptr< BufferSuballocationHandle >, std::shared_ptr< BufferSuballocationHandle > > > - allocations {}; - allocations.reserve( old_allocations.size() ); - - for ( const auto& suballocation_weak : old_allocations ) - { - if ( suballocation_weak.expired() ) continue; - - auto suballocation { suballocation_weak.lock() }; - - auto [ old_suballocation, new_suballocation ] = suballocation->reallocate( new_handle ); - - allocations.emplace_back( old_suballocation, new_suballocation ); - - // Copy the data from the old allocation to the new allocation - TransferManager::getInstance().copySuballocationRegion( old_suballocation, new_suballocation ); - - old_suballocation->flagReallocated( new_suballocation ); - } - - return new_handle; - } - - /* - void BufferHandle::resize( const vk::DeviceSize new_size ) - { - log::warn( "Resizing buffer from {} to {}", size(), new_size ); - - std::shared_ptr< BufferHandle > new_handle { new BufferHandle( new_size, m_usage, m_memory_properties ) }; - - //Now we need to re-create all the current live allocations and transfer/replace them using the new buffer - std::vector< - std::pair< std::shared_ptr< BufferSuballocationHandle >, std::shared_ptr< BufferSuballocationHandle > > > - allocations {}; - - allocations.reserve( m_active_suballocations.size() ); - - for ( auto& suballocation_weak : m_active_suballocations ) - { - if ( suballocation_weak.expired() ) continue; - try - { - auto suballocation { suballocation_weak.lock() }; - - auto new_suballocation { new_handle->allocate( suballocation->m_size, suballocation->m_alignment ) }; - allocations.emplace_back( suballocation, new_suballocation ); - } - catch ( std::bad_weak_ptr& e ) - { - // noop - void(); - } - } - - std::swap( m_buffer, new_handle->m_buffer ); - std::swap( m_alloc_info, new_handle->m_alloc_info ); - std::swap( m_allocation, new_handle->m_allocation ); - std::swap( m_free_blocks, new_handle->m_free_blocks ); - std::swap( m_active_suballocations, new_handle->m_active_suballocations ); - std::swap( m_allocation_traces, new_handle->m_allocation_traces ); - - // This transforms any memory::Buffer to be the `new_handle` we allocated above. - const auto old_handle { new_handle }; - FGL_ASSERT( old_handle.get() != this, "Old handle should not be the current buffer anymore!" ); - new_handle = this->shared_from_this(); - - for ( auto& [ old_allocation, new_allocation ] : allocations ) - { - old_allocation->m_parent_buffer = old_handle; - new_allocation->m_parent_buffer = new_handle; - } - - //Now we need to transfer the data from the old buffer to the new buffer - for ( const auto& allocation : allocations ) - { - const auto& [ old_suballocation, new_suballocation ] = allocation; - TransferManager::getInstance().copySuballocationRegion( old_suballocation, new_suballocation ); - } - } - */ - std::shared_ptr< BufferSuballocationHandle > BufferHandle:: allocate( vk::DeviceSize desired_memory_size, const vk::DeviceSize t_alignment ) { @@ -403,6 +273,45 @@ namespace fgl::engine::memory return true; } + void BufferHandle::free( BufferSuballocationHandle& info ) + { + ZoneScoped; + + if ( info.offset() >= this->size() ) throw std::runtime_error( "Offset was outside of bounds of buffer" ); + if ( info.offset() + info.size() > this->size() ) + throw std::runtime_error( + std::format( + "offset() + size() was outside the bounds of the buffer ({} + {} == {} >= {})", + info.offset(), + info.size(), + info.offset() + info.size(), + size() ) ); + + //Add the block back to the free blocks + m_free_blocks.emplace_back( info.offset(), info.size() ); + + mergeFreeBlocks(); + +#ifndef NDEBUG + //Check that we haven't lost any memory + std::size_t sum { 0 }; + for ( const auto& size : this->m_free_blocks | std::views::values ) + { + sum += size; + } + + for ( auto& suballocation : m_active_suballocations ) + { + if ( suballocation.expired() ) continue; + sum += suballocation.lock()->size(); + } + + if ( sum != this->size() ) + throw std::runtime_error( + std::format( "Memory leaked! Expected {} was {}: Lost {}", this->size(), sum, this->size() - sum ) ); +#endif + } + void BufferHandle::mergeFreeBlocks() { ZoneScoped; @@ -460,68 +369,75 @@ namespace fgl::engine::memory Device::getInstance().setDebugUtilsObjectName( info ); } - void BufferHandle::free( BufferSuballocationHandle& info ) + void* BufferHandle::map( const BufferSuballocationHandle& handle ) const { - ZoneScoped; + if ( m_alloc_info.pMappedData == nullptr ) return nullptr; - if ( info.offset() >= this->size() ) throw std::runtime_error( "Offset was outside of bounds of buffer" ); - if ( info.offset() + info.size() > this->size() ) - throw std::runtime_error( - std::format( - "offset() + size() was outside the bounds of the buffer ({} + {} == {} >= {})", - info.offset(), - info.size(), - info.offset() + info.size(), - size() ) ); - - //Add the block back to the free blocks - m_free_blocks.emplace_back( info.offset(), info.size() ); - - mergeFreeBlocks(); - -#ifndef NDEBUG - //Check that we haven't lost any memory - std::size_t sum { 0 }; - for ( const auto& size : this->m_free_blocks | std::views::values ) - { - sum += size; - } - - for ( auto& suballocation : m_active_suballocations ) - { - if ( suballocation.expired() ) continue; - sum += suballocation.lock()->size(); - } - - if ( sum != this->size() ) - throw std::runtime_error( - std::format( "Memory leaked! Expected {} was {}: Lost {}", this->size(), sum, this->size() - sum ) ); -#endif + return static_cast< std::byte* >( m_alloc_info.pMappedData ) + handle.offset(); } - vk::DeviceSize BufferHandle::used() const + vk::DeviceSize BufferHandle::alignment() const { - vk::DeviceSize total_size { 0 }; + vk::DeviceSize size { 1 }; - for ( auto& suballocation : m_active_suballocations ) + if ( m_usage & vk::BufferUsageFlagBits::eStorageBuffer ) { - if ( suballocation.expired() ) continue; - total_size += suballocation.lock()->size(); + size = std::max( size, Device::getInstance().m_properties.limits.minStorageBufferOffsetAlignment ); } - return total_size; + if ( m_usage & vk::BufferUsageFlagBits::eUniformBuffer ) + { + size = std::max( size, Device::getInstance().m_properties.limits.minUniformBufferOffsetAlignment ); + } + + if ( m_memory_properties & vk::MemoryPropertyFlagBits::eHostVisible ) + { + size = std::max( size, Device::getInstance().m_properties.limits.nonCoherentAtomSize ); + } + + return size; } - vk::DeviceSize BufferHandle::largestBlock() const + decltype( BufferHandle::m_free_blocks )::iterator BufferHandle:: + findAvailableBlock( vk::DeviceSize memory_size, const vk::DeviceSize t_alignment ) { - vk::DeviceSize largest { 0 }; + //Find a free space. + return std::ranges::find_if( + m_free_blocks, + [ this, memory_size, t_alignment ]( const std::pair< vk::DeviceSize, vk::DeviceSize >& pair ) + { + const auto [ offset, size ] = pair; - for ( const auto& size : m_free_blocks | std::views::values ) - { - largest = std::max( largest, size ); - } + const auto new_offset = align( offset, alignment(), t_alignment ); + const auto after_size { size - ( new_offset - offset ) }; - return largest; + // If the size of the block after alignment is greater than or equal to the size of the memory we want to allocate using it. + return after_size >= memory_size; + } ); + } + + Buffer Buffer::operator=( const std::shared_ptr< BufferHandle >& other ) + { + std::shared_ptr< BufferHandle >::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 ) ) + {} + + Buffer::Buffer( const std::shared_ptr< BufferHandle >& buffer ) : std::shared_ptr< BufferHandle >( 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 ); + } + + vk::DeviceSize Buffer::size() const + { + return std::shared_ptr< BufferHandle >::operator->()->size(); } } // namespace fgl::engine::memory diff --git a/src/engine/memory/buffers/BufferHandle.hpp b/src/engine/memory/buffers/BufferHandle.hpp index ad3890b..9151947 100644 --- a/src/engine/memory/buffers/BufferHandle.hpp +++ b/src/engine/memory/buffers/BufferHandle.hpp @@ -110,19 +110,11 @@ namespace fgl::engine::memory vk::Buffer getVkBuffer() const { return m_buffer; } //! Returns the vulkan memory handle for this buffer - vk::DeviceMemory getMemory() const - { - assert( m_alloc_info.deviceMemory != VK_NULL_HANDLE ); + vk::DeviceMemory getMemory() const; - return m_alloc_info.deviceMemory; - } + std::string sizeName() const; - FGL_FORCE_INLINE std::string sizeName() const - { - return std::format( "{}: {}", m_debug_name, literals::size_literals::toString( size() ) ); - } - - friend struct BufferSuballocationHandle; + friend class BufferSuballocationHandle; friend class BufferSuballocation; //TODO: Remove this friend gui::AllocationList gui::getTotalAllocated(); @@ -132,8 +124,6 @@ namespace fgl::engine::memory private: friend class Buffer; - std::shared_ptr< BufferHandle > remake( vk::DeviceSize new_size ); - // void resize( vk::DeviceSize new_size ); public: @@ -170,33 +160,24 @@ namespace fgl::engine::memory //! Returns the required alignment for this buffer. vk::DeviceSize alignment() const; - decltype( m_free_blocks )::iterator findAvailableBlock( vk::DeviceSize memory_size, std::uint32_t t_alignment ); + decltype( m_free_blocks )::iterator + findAvailableBlock( vk::DeviceSize memory_size, vk::DeviceSize t_alignment ); }; class Buffer final : public std::shared_ptr< BufferHandle > { - Buffer operator=( const std::shared_ptr< BufferHandle >& other ) - { - std::shared_ptr< BufferHandle >::operator=( other ); - return *this; - } + Buffer operator=( const std::shared_ptr< BufferHandle >& other ); public: [[nodiscard]] 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 ) ) - {} + vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties ); - [[nodiscard]] explicit Buffer( const std::shared_ptr< BufferHandle >& buffer ) : - std::shared_ptr< BufferHandle >( buffer ) - {} + [[nodiscard]] explicit Buffer( const std::shared_ptr< BufferHandle >& buffer ); - BufferSuballocation allocate( vk::DeviceSize desired_size, std::uint32_t alignment = 1 ); + BufferSuballocation allocate( const vk::DeviceSize desired_size, const std::uint32_t alignment = 1 ) const; - [[nodiscard]] vk::DeviceSize size() const { return std::shared_ptr< BufferHandle >::operator->()->size(); } - - void resize( vk::DeviceSize size ); + [[nodiscard]] vk::DeviceSize size() const; ~Buffer() = default; }; diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.cpp b/src/engine/memory/buffers/BufferSuballocationHandle.cpp index 638abed..c411fbc 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.cpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.cpp @@ -11,11 +11,6 @@ namespace fgl::engine::memory { - vk::Buffer BufferSuballocationHandle::getBuffer() const - { - return m_parent_buffer->getVkBuffer(); - } - BufferSuballocationHandle::BufferSuballocationHandle( const Buffer& p_buffer, const vk::DeviceSize offset, @@ -31,28 +26,11 @@ namespace fgl::engine::memory // assert( memory_size != 0 && "BufferSuballocation::BufferSuballocation() called with memory_size == 0" ); } - vk::Buffer BufferSuballocationHandle::getVkBuffer() const - { - return m_parent_buffer->getVkBuffer(); - } - BufferSuballocationHandle::~BufferSuballocationHandle() { m_parent_buffer->free( *this ); } - vk::BufferCopy BufferSuballocationHandle::copyRegion( - const BufferSuballocationHandle& target, - const std::size_t suballocation_offset, - const vk::DeviceSize size ) const - { - vk::BufferCopy copy {}; - copy.size = size == 0 ? std::min( this->m_size, target.m_size ) : size; - copy.srcOffset = this->offset(); - copy.dstOffset = target.offset() + suballocation_offset; - return copy; - } - void BufferSuballocationHandle::copyTo( const vk::raii::CommandBuffer& cmd_buffer, const BufferSuballocationHandle& other, @@ -65,20 +43,39 @@ namespace fgl::engine::memory cmd_buffer.copyBuffer( this->getVkBuffer(), other.getVkBuffer(), copy_regions ); } - std::pair< std::shared_ptr< BufferSuballocationHandle >, std::shared_ptr< BufferSuballocationHandle > > - BufferSuballocationHandle::reallocate( const std::shared_ptr< BufferHandle >& shared ) - { - auto old_allocation { this->shared_from_this() }; - auto new_allocation { shared->allocate( m_size, m_alignment ) }; - - return { old_allocation, new_allocation }; - } - void BufferSuballocationHandle::markSource( const std::shared_ptr< BufferSuballocationHandle >& source ) { m_dependents.push_back( source ); } + void BufferSuballocationHandle::setReady( const bool value ) + { + std::ranges::remove_if( m_dependents, []( const auto& handle ) { return handle.expired(); } ); + m_staged = value; + } + + vk::BufferCopy BufferSuballocationHandle::copyRegion( + const BufferSuballocationHandle& target, + const std::size_t suballocation_offset, + const vk::DeviceSize size ) const + { + vk::BufferCopy copy {}; + copy.size = size == 0 ? std::min( this->m_size, target.m_size ) : size; + copy.srcOffset = this->offset(); + copy.dstOffset = target.offset() + suballocation_offset; + return copy; + } + + vk::Buffer BufferSuballocationHandle::getBuffer() const + { + return m_parent_buffer->getVkBuffer(); + } + + vk::Buffer BufferSuballocationHandle::getVkBuffer() const + { + return m_parent_buffer->getVkBuffer(); + } + bool BufferSuballocationHandle::stable() const { return std::ranges:: @@ -89,10 +86,4 @@ namespace fgl::engine::memory { return m_staged; } - - void BufferSuballocationHandle::setReady( const bool value ) - { - std::ranges::remove_if( m_dependents, []( const auto& handle ) { return handle.expired(); } ); - m_staged = value; - } } // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.hpp b/src/engine/memory/buffers/BufferSuballocationHandle.hpp index 31c240f..d9d556c 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.hpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.hpp @@ -39,9 +39,6 @@ namespace fgl::engine::memory void* m_ptr { nullptr }; - bool m_reallocated { false }; - std::shared_ptr< BufferSuballocationHandle > m_reallocated_to { nullptr }; - bool m_staged { false }; std::vector< std::weak_ptr< BufferSuballocationHandle > > m_dependents {}; @@ -61,19 +58,6 @@ namespace fgl::engine::memory const BufferSuballocationHandle& other, std::size_t offset ) const; - void flagReallocated( const std::shared_ptr< BufferSuballocationHandle >& shared ) - { - m_reallocated = true; - m_reallocated_to = shared; - } - - std::pair< std::shared_ptr< BufferSuballocationHandle >, std::shared_ptr< BufferSuballocationHandle > > - reallocate( const std::shared_ptr< BufferHandle >& shared ); - - bool reallocated() const { return m_reallocated; } - - std::shared_ptr< BufferSuballocationHandle > reallocatedTo() const { return m_reallocated_to; } - void markSource( const std::shared_ptr< BufferSuballocationHandle >& source ); void setReady( bool value ); -- 2.49.1 From 2eb9024b5c29f888b12d40a42cd77c886dd839a4 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Tue, 23 Sep 2025 02:30:15 -0400 Subject: [PATCH 06/22] Fix tracy toggle --- cmake_modules/dependencies/tracy.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake_modules/dependencies/tracy.cmake b/cmake_modules/dependencies/tracy.cmake index a9f6f14..bbfbd55 100644 --- a/cmake_modules/dependencies/tracy.cmake +++ b/cmake_modules/dependencies/tracy.cmake @@ -5,7 +5,7 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_UPPER_BUILD_TYPE) message("-- Cmake upper: ${CMAKE_UPPER_BUILD_TYPE}") #if (CMAKE_UPPER_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_UPPER_BUILD_TYPE STREQUAL "RELWITHDEBINFO" AND DEFINED FGL_ENABLE_PROFILING) -if (DEFINED FGL_ENABLE_PROFILING AND FGL_ENABLE_PROFILING) +if (DEFINED FGL_ENABLE_PROFILING AND FGL_ENABLE_PROFILING EQUAL 1) set(TRACY_ENABLE ON) set(TRACY_ON_DEMAND ON) set(TRACY_NO_EXIT ON) -- 2.49.1 From 9d1a01163904b6c524f8a04e67e4119fd56fbced Mon Sep 17 00:00:00 2001 From: kj16609 Date: Tue, 23 Sep 2025 02:30:23 -0400 Subject: [PATCH 07/22] Bump slang ver --- dependencies/slang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/slang b/dependencies/slang index 680fb0b..206f6cf 160000 --- a/dependencies/slang +++ b/dependencies/slang @@ -1 +1 @@ -Subproject commit 680fb0b4e9cbb65d46677183a3f68630be1f6179 +Subproject commit 206f6cf5657177dfec9113d1f1b88b685eb2b75a -- 2.49.1 From 9ff05731f619fb40bc211f94e83c3827bf361e79 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sat, 27 Sep 2025 14:44:46 -0400 Subject: [PATCH 08/22] Start basic shadowmap stuff --- .../src/gui/{camera.cpp => RenderCamera.cpp} | 6 +- src/editor/src/gui/core.hpp | 2 + src/editor/src/gui/drawStats.cpp | 40 +- src/editor/src/gui/preview.cpp | 6 +- src/editor/src/gui/preview.hpp | 4 +- src/engine/EngineContext.cpp | 61 +-- src/engine/EngineContext.hpp | 14 +- src/engine/FrameInfo.cpp | 13 +- src/engine/FrameInfo.hpp | 14 +- src/engine/assets/model/Model.cpp | 1 - src/engine/assets/model/Model.hpp | 3 - .../assets/model/builders/SceneBuilder.cpp | 2 +- src/engine/camera/CameraInfo.hpp | 2 + src/engine/camera/CameraManager.cpp | 69 +++- src/engine/camera/CameraManager.hpp | 15 +- src/engine/camera/CameraViewpoint.cpp | 240 +++++++++++ .../{Camera.hpp => CameraViewpoint.hpp} | 185 +++------ src/engine/camera/GBufferCompositor.cpp | 9 +- src/engine/camera/GBufferCompositor.hpp | 4 +- src/engine/camera/GBufferRenderer.cpp | 3 +- .../camera/{Camera.cpp => RenderCamera.cpp} | 306 ++++---------- src/engine/camera/RenderCamera.hpp | 110 +++++ src/engine/camera/ShadowMap.cpp | 167 ++++++++ src/engine/camera/ShadowMap.hpp | 55 +++ src/engine/camera/Swapchain.cpp | 80 ++++ src/engine/camera/Swapchain.hpp | 69 ++++ src/engine/constants.hpp | 2 + src/engine/descriptors/DescriptorPool.cpp | 10 +- src/engine/descriptors/DescriptorPool.hpp | 3 - .../components/CameraComponent.hpp | 6 +- src/engine/lighting/lights/Sun.cpp | 12 + src/engine/lighting/lights/Sun.hpp | 19 + src/engine/lighting/shadows/ShadowMap.cpp | 59 --- src/engine/lighting/shadows/ShadowMap.hpp | 47 --- src/engine/primitives/Frustum.hpp | 4 +- .../primitives/rotation/UniversalRotation.cpp | 5 + .../primitives/rotation/UniversalRotation.hpp | 2 + src/engine/rendering/devices/extensions.hpp | 2 + src/engine/rendering/pipelines/Attachment.hpp | 51 --- .../pipelines/v2/PipelineBuilder.cpp | 378 +++++++++--------- src/engine/scene/Scene.hpp | 2 +- .../systems/prerender/CullingSystem.cpp | 13 +- .../systems/prerender/CullingSystem.hpp | 2 +- .../systems/render/EntityRendererSystem.cpp | 17 +- src/engine/systems/render/LineDrawer.cpp | 4 +- src/shaders/composition.slang | 14 +- src/shaders/culling.slang | 2 +- src/shaders/objects/camera.slang | 7 + src/shaders/objects/gamemodel.slang | 37 +- src/shaders/objects/gbuffer.slang | 7 + src/shaders/shadowmap.slang | 27 +- src/shaders/textured.slang | 16 +- 52 files changed, 1373 insertions(+), 855 deletions(-) rename src/editor/src/gui/{camera.cpp => RenderCamera.cpp} (94%) create mode 100644 src/engine/camera/CameraViewpoint.cpp rename src/engine/camera/{Camera.hpp => CameraViewpoint.hpp} (52%) rename src/engine/camera/{Camera.cpp => RenderCamera.cpp} (61%) create mode 100644 src/engine/camera/RenderCamera.hpp create mode 100644 src/engine/camera/ShadowMap.cpp create mode 100644 src/engine/camera/ShadowMap.hpp create mode 100644 src/engine/camera/Swapchain.cpp create mode 100644 src/engine/camera/Swapchain.hpp create mode 100644 src/engine/lighting/lights/Sun.cpp create mode 100644 src/engine/lighting/lights/Sun.hpp delete mode 100644 src/engine/lighting/shadows/ShadowMap.cpp delete mode 100644 src/engine/lighting/shadows/ShadowMap.hpp diff --git a/src/editor/src/gui/camera.cpp b/src/editor/src/gui/RenderCamera.cpp similarity index 94% rename from src/editor/src/gui/camera.cpp rename to src/editor/src/gui/RenderCamera.cpp index badee38..f29b024 100644 --- a/src/editor/src/gui/camera.cpp +++ b/src/editor/src/gui/RenderCamera.cpp @@ -2,7 +2,7 @@ // Created by kj16609 on 7/23/24. // -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" #include @@ -13,7 +13,7 @@ namespace fgl::engine::gui { - void handleCameraInput( const FrameInfo& info, Camera& camera ) + void handleCameraInput( const FrameInfo& info, RenderCamera& camera ) { const auto delta_time { info.delta_time }; @@ -104,7 +104,7 @@ namespace fgl::engine::gui assert( camera_ptr ); - Camera& camera { *camera_ptr }; + RenderCamera& camera { *camera_ptr }; std::string name {}; diff --git a/src/editor/src/gui/core.hpp b/src/editor/src/gui/core.hpp index 59fc51f..f3b9984 100644 --- a/src/editor/src/gui/core.hpp +++ b/src/editor/src/gui/core.hpp @@ -31,6 +31,8 @@ namespace fgl::engine::gui void drawComponentsList( GameObject& game_object ); void drawSelectedComponent(); + void drawShadowmaps( const FrameInfo& info ); + void drawCameraOutputs( FrameInfo& info ); void drawStats( const FrameInfo& info ); diff --git a/src/editor/src/gui/drawStats.cpp b/src/editor/src/gui/drawStats.cpp index c2d9ffc..2487bf0 100644 --- a/src/editor/src/gui/drawStats.cpp +++ b/src/editor/src/gui/drawStats.cpp @@ -2,13 +2,14 @@ #include #include "assets/transfer/TransferManager.hpp" +#include "camera/CameraManager.hpp" +#include "camera/ShadowMap.hpp" #include "core.hpp" #include "engine/debug/profiling/counters.hpp" #include "engine/debug/timing/FlameGraph.hpp" #include "engine/flags.hpp" #include "engine/math/literals/size.hpp" #include "engine/memory/buffers/BufferHandle.hpp" -#include "memory/buffers/BufferHandle.hpp" #include "safe_include.hpp" namespace fgl::engine::gui @@ -123,6 +124,38 @@ namespace fgl::engine::gui } } + void drawShadowmaps( const FrameInfo& info ) + { + ImGui::Begin( "Shadowmaps" ); + + static std::unordered_map< int*, std::vector< Texture > > textures {}; + + bool move_sun { false }; + + move_sun = ImGui::Button( "Move sun shadowmap to camera" ); + + for ( const auto& weak_shadowmap : getShadowmaps() ) + { + if ( weak_shadowmap.expired() ) continue; + + auto shadowmap_ptr { weak_shadowmap.lock() }; + + ShadowMap& shadowmap { *shadowmap_ptr }; + + // if ( move_sun ) + { + shadowmap.m_camera->moveTo( CameraManager::instance().getPrimary()->getTransform() ); + } + + const FrameIndex frame_index { info.in_flight_idx }; + // camera.getCompositeSwapchain().m_gbuffer_target[ frame_index ]->drawImGui( target_size ); + + shadowmap.m_swapchain->depthTexture( frame_index )->drawImGui(); + } + + ImGui::End(); + } + void drawStats( const FrameInfo& info ) { ImGui::Begin( "Stats" ); @@ -143,6 +176,11 @@ namespace fgl::engine::gui debug::timing::render(); } + if ( ImGui::CollapsingHeader( "Shadowmaps" ) ) + { + drawShadowmaps( info ); + } + if ( ImGui::Button( "Reload shaders" ) ) { flags::triggerShaderReload(); diff --git a/src/editor/src/gui/preview.cpp b/src/editor/src/gui/preview.cpp index 24f5636..534646d 100644 --- a/src/editor/src/gui/preview.cpp +++ b/src/editor/src/gui/preview.cpp @@ -7,7 +7,7 @@ #include "engine/FrameInfo.hpp" #include "engine/assets/model/Model.hpp" #include "engine/assets/model/builders/SceneBuilder.hpp" -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" #include "engine/filesystem/scanner/FileScanner.hpp" #include "engine/filesystem/types.hpp" #include "engine/rendering/PresentSwapChain.hpp" @@ -126,7 +126,7 @@ namespace fgl::engine::gui inline void drawConfigBar( [[maybe_unused]] const FrameInfo& info, - [[maybe_unused]] const Camera& camera, + [[maybe_unused]] const RenderCamera& camera, [[maybe_unused]] const FrameIndex frame_index, std::uint_fast8_t& current ) { @@ -167,7 +167,7 @@ namespace fgl::engine::gui } } - void drawRenderingOutputs( FrameInfo& info, const Camera& camera ) + void drawRenderingOutputs( FrameInfo& info, const RenderCamera& camera ) { ZoneScoped; const auto frame_index { info.in_flight_idx }; diff --git a/src/editor/src/gui/preview.hpp b/src/editor/src/gui/preview.hpp index 6634e50..649d53f 100644 --- a/src/editor/src/gui/preview.hpp +++ b/src/editor/src/gui/preview.hpp @@ -7,12 +7,12 @@ namespace fgl::engine { struct FrameInfo; - class Camera; + class RenderCamera; } // namespace fgl::engine namespace fgl::engine::gui { - void drawRenderingOutputs( FrameInfo& info, const Camera& camera ); + void drawRenderingOutputs( FrameInfo& info, const RenderCamera& camera ); } // namespace fgl::engine::gui diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index e61b8cd..ed4ff41 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -11,9 +11,10 @@ #include #include "KeyboardMovementController.hpp" -#include "camera/Camera.hpp" #include "camera/CameraManager.hpp" #include "camera/GBufferRenderer.hpp" +#include "camera/RenderCamera.hpp" +#include "camera/ShadowMap.hpp" #include "debug/timing/FlameGraph.hpp" #include "engine/assets/model/builders/SceneBuilder.hpp" #include "engine/assets/transfer/TransferManager.hpp" @@ -27,49 +28,20 @@ namespace fgl::engine constexpr float MAX_DELTA_TIME { 0.5 }; inline static EngineContext* instance { nullptr }; - PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > createDrawCommandsDescriptors( - PerFrameArray< DeviceVector< vk::DrawIndexedIndirectCommand > >& gpu_draw_commands, - PerFrameArray< DeviceVector< InstanceRenderInfo > >& per_vertex_info ) - { - PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > descriptors {}; - - for ( std::uint16_t i = 0; i < gpu_draw_commands.size(); ++i ) - { - auto& command_buffer { gpu_draw_commands[ i ] }; - auto& per_vertex_buffer { per_vertex_info[ i ] }; - auto descriptor { COMMANDS_SET.create() }; - - descriptor->bindStorageBuffer( 0, command_buffer ); - descriptor->bindStorageBuffer( 1, per_vertex_buffer ); - descriptor->update(); - descriptor->setName( "Command Buffer + Vertex Buffer" ); - - descriptors[ i ] = std::move( descriptor ); - } - - return descriptors; - } - EngineContext::EngineContext() : m_ubo_buffer_pool( 1_MiB, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible ), - m_draw_parameter_pool( - 4_MiB, - vk::BufferUsageFlagBits::eIndirectBuffer | vk::BufferUsageFlagBits::eStorageBuffer, - vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible ), - m_gpu_draw_commands( - constructPerFrame< DeviceVector< vk::DrawIndexedIndirectCommand > >( m_draw_parameter_pool ) ), - m_per_vertex_infos( m_model_buffers.m_generated_instance_info ), - m_gpu_draw_cmds_desc( createDrawCommandsDescriptors( m_gpu_draw_commands, m_per_vertex_infos ) ), - m_delta_time( 0.0 ) + m_delta_time( 0.0 ), + m_camera_manager() { ZoneScoped; using namespace fgl::literals::size_literals; instance = this; - // memory::TransferManager::createInstance( device, 128_MiB ); + m_camera_manager.createPrimary(); + m_sun = std::make_unique< Sun >(); - m_draw_parameter_pool->setDebugName( "Draw parameter pool" ); + // memory::TransferManager::createInstance( device, 128_MiB ); } static Average< float, 60 * 15 > rolling_ms_average; @@ -116,10 +88,19 @@ namespace fgl::engine auto sh_camera { current_camera_ptr.lock() }; - Camera& current_camera { *sh_camera }; + RenderCamera& current_camera { *sh_camera }; current_camera.pass( frame_info ); } + + for ( auto& shadow_map : getShadowmaps() ) + { + if ( shadow_map.expired() ) continue; + + auto shadowmap { shadow_map.lock() }; + + shadowmap->pass( frame_info ); + } } void EngineContext::renderFrame() @@ -136,9 +117,6 @@ namespace fgl::engine // Begin by getting every single instance ready. DeviceVector< PrimitiveInstanceInfo >& instances { m_model_buffers.m_primitive_instances.vec() }; - m_gpu_draw_commands[ in_flight_idx ].resize( instances.size() ); - m_model_buffers.m_generated_instance_info[ in_flight_idx ].resize( instances.size() ); - FrameInfo frame_info { in_flight_idx, present_idx, m_delta_time, @@ -148,8 +126,9 @@ namespace fgl::engine m_renderer.getCurrentTracyCTX(), *m_model_buffers.m_primitives_desc, *m_model_buffers.m_instances_desc, - *m_gpu_draw_cmds_desc[ in_flight_idx ], - m_gpu_draw_commands[ in_flight_idx ], + instances, + // *m_gpu_draw_cmds_desc[ in_flight_idx ], + // m_gpu_draw_commands[ in_flight_idx ], m_game_objects, this->m_renderer.getSwapChain() }; diff --git a/src/engine/EngineContext.hpp b/src/engine/EngineContext.hpp index 7a9d2e6..4a451e9 100644 --- a/src/engine/EngineContext.hpp +++ b/src/engine/EngineContext.hpp @@ -12,6 +12,7 @@ #include "engine/assets/transfer/TransferManager.hpp" #include "engine/math/literals/size.hpp" #include "engine/rendering/Renderer.hpp" +#include "lighting/lights/Sun.hpp" #include "scene/World.hpp" #include "systems/composition/GuiSystem.hpp" @@ -67,9 +68,6 @@ namespace fgl::engine // Memory pool for shader uniforms. memory::Buffer m_ubo_buffer_pool; - // Memory pool for matrix info and draw parameters - memory::Buffer m_draw_parameter_pool; - public: std::vector< std::shared_ptr< GameObject > > m_game_objects {}; @@ -78,22 +76,18 @@ namespace fgl::engine private: - PerFrameArray< DeviceVector< vk::DrawIndexedIndirectCommand > > m_gpu_draw_commands; - //TODO: Outright remove this. Or the one in model buffers. - PerFrameArray< DeviceVector< InstanceRenderInfo > >& m_per_vertex_infos; - PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > m_gpu_draw_cmds_desc; - MaterialManager m_material_manager {}; - CameraManager m_camera_manager {}; - memory::TransferManager m_transfer_manager { m_device, 512_MiB }; std::chrono::time_point< Clock > m_last_tick { Clock::now() }; DeltaTime m_delta_time; + CameraManager m_camera_manager {}; // World m_world; + std::unique_ptr< Sun > m_sun; + public: // ModelManager& models() { return m_model_manager; } diff --git a/src/engine/FrameInfo.cpp b/src/engine/FrameInfo.cpp index 705e5be..adffbdf 100644 --- a/src/engine/FrameInfo.cpp +++ b/src/engine/FrameInfo.cpp @@ -4,20 +4,21 @@ #include "FrameInfo.hpp" -#include "camera/Camera.hpp" #include "camera/GBufferSwapchain.hpp" +#include "camera/RenderCamera.hpp" namespace fgl::engine { - descriptors::DescriptorSet& FrameInfo::getGBufferDescriptor() const - { - return camera->getSwapchain().getGBufferDescriptor( in_flight_idx ); - } + // descriptors::DescriptorSet& FrameInfo::getGBufferDescriptor() const + // { + // return camera->getSwapchain().getGBufferDescriptor( in_flight_idx ); + // } descriptors::DescriptorSet& FrameInfo::getCameraDescriptor() const { - return camera->getDescriptor( in_flight_idx ); + FGL_ASSERT( camera != nullptr, "Camera not set" ); + return *camera->m_camera_info_descriptors[ in_flight_idx ]; } void FrameInfo::bindCamera( [[maybe_unused]] Pipeline& pipeline ) diff --git a/src/engine/FrameInfo.hpp b/src/engine/FrameInfo.hpp index 29ae8eb..2203702 100644 --- a/src/engine/FrameInfo.hpp +++ b/src/engine/FrameInfo.hpp @@ -21,6 +21,7 @@ namespace fgl::engine { + class CameraViewpoint; struct PrimitiveRenderInfo; struct PrimitiveInstanceInfo; class Pipeline; @@ -31,7 +32,7 @@ namespace fgl::engine } class PresentSwapChain; - class Camera; + class RenderCamera; struct PointLight { @@ -81,9 +82,9 @@ namespace fgl::engine CommandBuffers& command_buffer; - Camera* camera { nullptr }; + CameraViewpoint* camera { nullptr }; - std::vector< std::weak_ptr< Camera > >& m_camera_list; + std::vector< std::weak_ptr< RenderCamera > >& m_camera_list; // descriptors::DescriptorSet& global_descriptor_set; // OctTreeNode& game_objects; @@ -91,16 +92,17 @@ namespace fgl::engine descriptors::DescriptorSet& m_primitives_desc; descriptors::DescriptorSet& m_instances_desc; - descriptors::DescriptorSet& m_command_buffer_desc; + DeviceVector< PrimitiveInstanceInfo >& instances; + // descriptors::DescriptorSet& m_command_buffer_desc; // out for rendering process //! Populated commands buffer by the culling pass - DeviceVector< vk::DrawIndexedIndirectCommand >& m_commands; + // DeviceVector< vk::DrawIndexedIndirectCommand >& m_commands; std::vector< std::shared_ptr< GameObject > >& m_game_objects; // descriptors::DescriptorSet& gui_input_descriptor; - [[nodiscard]] descriptors::DescriptorSet& getGBufferDescriptor() const; + // [[nodiscard]] descriptors::DescriptorSet& getGBufferDescriptor() const; [[nodiscard]] descriptors::DescriptorSet& getCameraDescriptor() const; PresentSwapChain& swap_chain; diff --git a/src/engine/assets/model/Model.cpp b/src/engine/assets/model/Model.cpp index 484b97d..8cb78ea 100644 --- a/src/engine/assets/model/Model.cpp +++ b/src/engine/assets/model/Model.cpp @@ -38,7 +38,6 @@ namespace fgl::engine 1_GiB, vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eDeviceLocal ), - m_generated_instance_info( constructPerFrame< DeviceVector< InstanceRenderInfo > >( m_vertex_buffer ) ), m_primitive_info( m_long_buffer ), m_primitive_instances( m_short_buffer ), m_model_instances( m_short_buffer ) diff --git a/src/engine/assets/model/Model.hpp b/src/engine/assets/model/Model.hpp index 1347066..ffde8af 100644 --- a/src/engine/assets/model/Model.hpp +++ b/src/engine/assets/model/Model.hpp @@ -104,9 +104,6 @@ namespace fgl::engine memory::Buffer m_vertex_buffer; memory::Buffer m_index_buffer; - //! Generated by the compute shader, This vector contains the instance info for each primitive. - PerFrameArray< DeviceVector< InstanceRenderInfo > > m_generated_instance_info; - //! contains the core primitive info, like vertex and index offsets and counts IndexedVector< PrimitiveRenderInfo > m_primitive_info; //! contains a list of all rendered primitives diff --git a/src/engine/assets/model/builders/SceneBuilder.cpp b/src/engine/assets/model/builders/SceneBuilder.cpp index ce7c648..2f9420e 100644 --- a/src/engine/assets/model/builders/SceneBuilder.cpp +++ b/src/engine/assets/model/builders/SceneBuilder.cpp @@ -14,7 +14,7 @@ #include "assets/model/ModelVertex.hpp" #include "engine/assets/stores.hpp" -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" #include "engine/debug/logging/logging.hpp" #include "engine/descriptors/DescriptorSet.hpp" #include "engine/gameobjects/GameObject.hpp" diff --git a/src/engine/camera/CameraInfo.hpp b/src/engine/camera/CameraInfo.hpp index 391e4d7..e0926ed 100644 --- a/src/engine/camera/CameraInfo.hpp +++ b/src/engine/camera/CameraInfo.hpp @@ -4,6 +4,8 @@ #pragma once +#include + namespace fgl::engine { diff --git a/src/engine/camera/CameraManager.cpp b/src/engine/camera/CameraManager.cpp index 3690d8c..bfac59f 100644 --- a/src/engine/camera/CameraManager.cpp +++ b/src/engine/camera/CameraManager.cpp @@ -4,8 +4,8 @@ #include "CameraManager.hpp" -#include "Camera.hpp" #include "GBufferRenderer.hpp" +#include "RenderCamera.hpp" #include "engine/debug/DEBUG_NAMES.hpp" #include "engine/math/literals/size.hpp" @@ -14,35 +14,64 @@ namespace fgl::engine using namespace fgl::literals::size_literals; - std::vector< std::weak_ptr< Camera > >& CameraManager::getCameras() - { - return cameras; - } - - std::shared_ptr< Camera >& CameraManager::getPrimary() - { - return m_primary_camera; - } + inline static CameraManager* camera_manager_instance { nullptr }; CameraManager::CameraManager() : m_renderer( std::make_shared< GBufferRenderer >() ), m_data_buffer( 4_KiB, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible ) { - m_primary_camera = createCamera( { 1920, 1080 } ); - m_primary_camera->setName( CAMERA_EDITOR_NAME ); - } + FGL_ASSERT( camera_manager_instance == nullptr, "CameraManager already initialized" ); + camera_manager_instance = this; - std::shared_ptr< Camera > CameraManager::createCamera( const vk::Extent2D extent ) - { - std::shared_ptr< Camera > camera { new Camera( extent, m_data_buffer, m_renderer ) }; - - this->cameras.emplace_back( camera ); - - return camera; + m_data_buffer->setDebugName( "Camera data buffer" ); } CameraManager::~CameraManager() { m_primary_camera.reset(); + camera_manager_instance = nullptr; + } + + std::vector< std::weak_ptr< RenderCamera > >& CameraManager::getCameras() + { + return cameras; + } + + std::shared_ptr< RenderCamera >& CameraManager::getPrimary() + { + return m_primary_camera; + } + + void CameraManager::createPrimary() + { + m_primary_camera = createCamera( { 1920, 1080 } ); + m_primary_camera->setName( CAMERA_EDITOR_NAME ); + } + + CameraManager& CameraManager::instance() + { + FGL_ASSERT( camera_manager_instance, "CameraManager not initialized" ); + return *camera_manager_instance; + } + + std::shared_ptr< RenderCamera > CameraManager::createCamera( const vk::Extent2D extent ) + { + auto& instance = CameraManager::instance(); + + std::shared_ptr< RenderCamera > camera { + new RenderCamera( extent, instance.m_data_buffer, instance.m_renderer ) + }; + + instance.cameras.emplace_back( camera ); + + return camera; + } + + std::shared_ptr< CameraViewpoint > CameraManager::createViewpoint( const vk::Extent2D extent ) + { + auto& instance = CameraManager::instance(); + std::shared_ptr< CameraViewpoint > camera_viewpoint { new CameraViewpoint( instance.m_data_buffer, extent ) }; + + return camera_viewpoint; } } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/camera/CameraManager.hpp b/src/engine/camera/CameraManager.hpp index 8bd8ec8..e863148 100644 --- a/src/engine/camera/CameraManager.hpp +++ b/src/engine/camera/CameraManager.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include "Camera.hpp" +#include "RenderCamera.hpp" #include "engine/memory/buffers/BufferHandle.hpp" namespace fgl::engine @@ -20,20 +20,23 @@ namespace fgl::engine std::shared_ptr< GBufferRenderer > m_renderer; memory::Buffer m_data_buffer; - std::shared_ptr< Camera > m_primary_camera { nullptr }; + std::shared_ptr< RenderCamera > m_primary_camera { nullptr }; - std::vector< std::weak_ptr< Camera > > cameras {}; + std::vector< std::weak_ptr< RenderCamera > > cameras {}; public: CameraManager(); ~CameraManager(); - std::vector< std::weak_ptr< Camera > >& getCameras(); + std::vector< std::weak_ptr< RenderCamera > >& getCameras(); - std::shared_ptr< Camera >& getPrimary(); + std::shared_ptr< RenderCamera >& getPrimary(); + void createPrimary(); - std::shared_ptr< Camera > createCamera( vk::Extent2D extent ); + static CameraManager& instance(); + static std::shared_ptr< RenderCamera > createCamera( vk::Extent2D extent ); + static std::shared_ptr< CameraViewpoint > createViewpoint( vk::Extent2D extent ); }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/camera/CameraViewpoint.cpp b/src/engine/camera/CameraViewpoint.cpp new file mode 100644 index 0000000..264319b --- /dev/null +++ b/src/engine/camera/CameraViewpoint.cpp @@ -0,0 +1,240 @@ +// +// Created by kj16609 on 9/23/25. +// +#include "CameraViewpoint.hpp" + +#include "CameraInfo.hpp" +#include "RenderCamera.hpp" +#include "assets/model/Model.hpp" + +namespace fgl::engine +{ + + void CameraViewpoint::updateMatrix() + { + const auto& [ pos, scale, rotation ] = m_transform; + + const auto rotation_matrix { rotation.forcedQuat().mat() }; + + const glm::vec3 forward { rotation_matrix * glm::vec4( constants::WORLD_FORWARD, 0.0f ) }; + + const glm::vec3 camera_up { rotation_matrix * glm::vec4( -constants::WORLD_Z, 0.0f ) }; + + const WorldCoordinate center_pos { pos + forward }; + + m_view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAt( pos.vec(), center_pos.vec(), camera_up ) ); + + m_inverse_view_matrix = glm::inverse( m_view_matrix ); + + updateFrustum(); + } + + void CameraViewpoint::updateFrustum() + { + m_last_frustum_pos = getPosition(); + + const Matrix< MatrixType::ModelToWorld > translation_matrix { frustumTranslationMatrix() }; + + m_frustum = translation_matrix * m_base_frustum; + } + + constexpr descriptors::Descriptor camera_descriptor { 0, + vk::DescriptorType::eUniformBuffer, + vk::ShaderStageFlagBits::eAllGraphics }; + + inline static descriptors::DescriptorSetLayout camera_descriptor_set { 1, camera_descriptor }; + + memory::BufferSuballocation& CameraViewpoint::frameInfo( const FrameIndex i ) + { + return m_camera_frame_info[ i ]; + } + + std::vector< std::unique_ptr< descriptors::DescriptorSet > > CameraViewpoint::createCameraDescriptors() + { + std::vector< std::unique_ptr< descriptors::DescriptorSet > > sets {}; + sets.reserve( constants::MAX_FRAMES_IN_FLIGHT ); + + for ( std::uint8_t i = 0; i < constants::MAX_FRAMES_IN_FLIGHT; ++i ) + { + auto set { camera_descriptor_set.create() }; + set->bindUniformBuffer( 0, m_camera_frame_info[ i ] ); + set->update(); + set->setName( std::format( "Viewpoint {} descriptor set {}", m_viewpoint_idx, i ) ); + + sets.emplace_back( std::move( set ) ); + } + return sets; + } + + using namespace fgl::literals::size_literals; + + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > createDrawCommandsDescriptors( + PerFrameArray< DeviceVector< vk::DrawIndexedIndirectCommand > >& gpu_draw_commands, + PerFrameArray< DeviceVector< InstanceRenderInfo > >& per_vertex_info ) + { + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > descriptors {}; + + for ( std::uint16_t i = 0; i < gpu_draw_commands.size(); ++i ) + { + auto& command_buffer { gpu_draw_commands[ i ] }; + auto& per_vertex_buffer { per_vertex_info[ i ] }; + auto descriptor { COMMANDS_SET.create() }; + + descriptor->bindStorageBuffer( 0, command_buffer ); + descriptor->bindStorageBuffer( 1, per_vertex_buffer ); + descriptor->update(); + descriptor->setName( "Command Buffer + Vertex Buffer" ); + + descriptors[ i ] = std::move( descriptor ); + } + + return descriptors; + } + + CameraViewpoint::CameraViewpoint( memory::Buffer& buffer, const vk::Extent2D extent ) : + m_extent( extent ), + m_camera_frame_info( buffer ), + m_draw_parameter_pool( + 4_MiB, + vk::BufferUsageFlagBits::eIndirectBuffer | vk::BufferUsageFlagBits::eStorageBuffer, + vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible ), + m_gpu_draw_commands( + constructPerFrame< DeviceVector< vk::DrawIndexedIndirectCommand > >( m_draw_parameter_pool ) ), + m_generated_instance_info( + constructPerFrame< DeviceVector< InstanceRenderInfo > >( getModelBuffers().m_vertex_buffer ) ), + m_gpu_draw_cmds_desc( createDrawCommandsDescriptors( m_gpu_draw_commands, m_generated_instance_info ) ), + m_camera_info_descriptors( createCameraDescriptors() ) + { + setFOV( m_fov_y ); + } + + Coordinate< CoordinateSpace::World > CameraViewpoint::getPosition() const + { + //Should maybe store the inverse view matrix + return WorldCoordinate( m_inverse_view_matrix[ 3 ] ); + } + + Matrix< MatrixType::WorldToScreen > CameraViewpoint::getProjectionViewMatrix() const + { + assert( m_projection_matrix != constants::MAT4_IDENTITY ); + return m_projection_matrix * m_view_matrix; + } + + glm::mat4 CameraViewpoint::getInverseViewMatrix() const + { + return glm::inverse( m_view_matrix ); + } + + FGL_FLATTEN_HOT void CameraViewpoint:: + setView( const WorldCoordinate pos, const QuatRotation& rotation, const ViewMode mode ) + { + switch ( mode ) + { + case ViewMode::TaitBryan: + { + m_transform.translation = pos; + m_transform.rotation = rotation; + updateMatrix(); + break; + } + case ViewMode::Euler: + [[fallthrough]]; + { + //TODO: Implement + //view_matrix = glm::lookAt(position, position + ); + } + default: + throw std::runtime_error( "Unimplemented view mode" ); + } + + updateFrustum(); + } + + void CameraViewpoint::setOrthographicProjection( + const float left, const float right, const float top, const float bottom, const float near, const float far ) + { + m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::ortho( left, right, bottom, top, near, far ) ); + } + + FGL_FLATTEN_HOT void CameraViewpoint:: + setPerspectiveProjection( const float fovy, const float aspect, const float near, const float far ) + { + m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspective( fovy, aspect, near, far ) ); + + m_base_frustum = createFrustum( aspect, fovy, near, far ); + } + + void CameraViewpoint::setViewport( const vk::raii::CommandBuffer& command_buffer ) + { + vk::Viewport viewport {}; + viewport.x = 0.0f; + viewport.y = 0.0f; + + const auto& [ width, height ] = m_extent; + viewport.width = static_cast< float >( width ); + viewport.height = static_cast< float >( height ); + viewport.minDepth = 0.0f; + viewport.maxDepth = 1.0f; + + const std::vector< vk::Viewport > viewports { viewport }; + + command_buffer.setViewport( 0, viewports ); + } + + void CameraViewpoint::setScissor( const vk::raii::CommandBuffer& command_buffer ) + { + const vk::Rect2D scissor { { 0, 0 }, m_extent }; + + const std::vector< vk::Rect2D > scissors { scissor }; + + command_buffer.setScissor( 0, scissors ); + } + + void CameraViewpoint::setFOV( const float fov_y ) + { + m_fov_y = fov_y; + setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); + } + + float CameraViewpoint::aspectRatio() const + { + return static_cast< float >( m_extent.width ) / static_cast< float >( m_extent.height ); + } + + void CameraViewpoint::moveTo( const WorldTransform pos ) + { + this->m_transform = pos; + } + + void CameraViewpoint::updateInfo( const FrameIndex frame_index ) + { + ZoneScoped; + updateMatrix(); + CameraInfo current_camera_info { .projection = getProjectionMatrix(), + .view = getViewMatrix(), + .inverse_view = getInverseViewMatrix() }; + + m_camera_frame_info[ frame_index ] = current_camera_info; + } + + void CameraViewpoint::setExtent( const vk::Extent2D extent ) + { + m_extent = extent; + } + + vk::Rect2D CameraViewpoint::scissor() const + { + return { { 0, 0 }, m_extent }; + } + + vk::Viewport CameraViewpoint::viewport() const + { + return { 0, 0, this->m_extent.width, this->m_extent.height, 0.0f, 1.0f }; + } + + descriptors::DescriptorSetLayout& CameraViewpoint::getDescriptorLayout() + { + return camera_descriptor_set; + } + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/camera/Camera.hpp b/src/engine/camera/CameraViewpoint.hpp similarity index 52% rename from src/engine/camera/Camera.hpp rename to src/engine/camera/CameraViewpoint.hpp index b223be6..38f0f7d 100644 --- a/src/engine/camera/Camera.hpp +++ b/src/engine/camera/CameraViewpoint.hpp @@ -1,82 +1,37 @@ // -// Created by kj16609 on 11/28/23. +// Created by kj16609 on 9/23/25. // - #pragma once +#include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" -#define GLM_ENABLE_EXPERIMENTAL -#include -#include -#pragma GCC diagnostic pop - -#include "../primitives/rotation/QuatRotation.hpp" -#include "CompositeSwapchain.hpp" -#include "GBufferSwapchain.hpp" -#include "debug/Track.hpp" -#include "engine/descriptors/DescriptorSet.hpp" -#include "engine/memory/buffers/HostSingleT.hpp" -#include "engine/memory/buffers/UniqueFrameSuballocation.hpp" -#include "engine/primitives/Frustum.hpp" -#include "engine/primitives/Transform.hpp" -#include "engine/rendering/types.hpp" - -namespace vk::raii -{ - class CommandBuffer; - class RenderPass; -} // namespace vk::raii +#include "CameraInfo.hpp" +#include "memory/buffers/HostSingleT.hpp" +#include "memory/buffers/UniqueFrameSuballocation.hpp" +#include "primitives/Frustum.hpp" +#include "primitives/Transform.hpp" +#include "primitives/matricies/Matrix.hpp" +#include "rendering/PresentSwapChain.hpp" namespace fgl::engine { + struct InstanceRenderInfo; + namespace descriptors { class DescriptorSetLayout; - } - class Image; - struct FrameInfo; - class GBufferRenderer; + class DescriptorSet; + } // namespace descriptors - struct CameraInfo; - class Camera; - - FrustumBase createFrustum( float aspect, float fovy, float near, float far ); - - using CameraIDX = std::uint8_t; - - class Camera + class CameraViewpoint { - inline static CameraIDX m_camera_counter { 0 }; - - debug::Track< "CPU", "Camera" > m_camera {}; - - vk::Extent2D m_target_extent; - - std::unique_ptr< CompositeSwapchain > m_composite_swapchain; - std::unique_ptr< GBufferSwapchain > m_gbuffer_swapchain; - - //TODO: Move to deffered deleter - std::queue< std::unique_ptr< CompositeSwapchain > > m_old_composite_swapchain {}; - std::queue< std::unique_ptr< GBufferSwapchain > > m_old_gbuffer_swapchain {}; - - std::shared_ptr< GBufferRenderer > m_camera_renderer; - - //! True if the camera is active and to be rendered - bool m_active { true }; - - //! If true, The camera's swapchain is to be destroyed in order to preserve memory. - //! This is here to allow us to set a camera cold when it's not likely to be used soon - bool m_cold { false }; - - // Const is acceptable, Since this value should never change. EVER - const CameraIDX m_camera_idx { m_camera_counter++ }; + protected: + vk::Extent2D m_extent; Matrix< MatrixType::CameraToScreen > m_projection_matrix { 1.0f }; Matrix< MatrixType::WorldToCamera > m_view_matrix { 1.0f }; glm::mat4 m_inverse_view_matrix { 1.0f }; + bool m_ortho { false }; //! Frustum of the camera in model space relative to the camera //! @note Must be transformed by the inverse view matrix to get the frustum in world space @@ -86,58 +41,62 @@ namespace fgl::engine WorldTransform m_transform {}; - float m_fov_y { glm::radians( 90.0f ) }; + float& x { m_transform.translation.x }; + float& y { m_transform.translation.y }; + float& z { m_transform.translation.z }; PerFrameSuballocation< HostSingleT< CameraInfo > > m_camera_frame_info; + std::uint32_t m_viewpoint_idx { 0 }; + + memory::Buffer m_draw_parameter_pool; + + public: + + PerFrameArray< DeviceVector< vk::DrawIndexedIndirectCommand > > m_gpu_draw_commands; + PerFrameArray< DeviceVector< InstanceRenderInfo > > m_generated_instance_info; + + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > m_gpu_draw_cmds_desc; + + memory::BufferSuballocation& frameInfo( FrameIndex i ); // Camera info is expected at binding 0 std::vector< std::unique_ptr< descriptors::DescriptorSet > > createCameraDescriptors(); std::vector< std::unique_ptr< descriptors::DescriptorSet > > m_camera_info_descriptors; - std::string m_name { "Unnamed Camera" }; + private: - [[nodiscard]] Matrix< MatrixType::ModelToWorld > frustumTranslationMatrix() const; - - void updateFrustum(); - -#ifdef EXPOSE_CAMERA_TESTS - //Constructor for tests - Camera( vk::Extent2D test_extent ) : m_target_extent( test_extent ) {} -#endif - - Camera( vk::Extent2D extent, memory::Buffer& buffer, const std::shared_ptr< GBufferRenderer >& renderer ); - - friend class CameraManager; + enum ViewMode + { + Euler, + TaitBryan + }; public: - float& x { m_transform.translation.x }; - float& y { m_transform.translation.y }; - float& z { m_transform.translation.z }; + float m_fov_y { glm::radians( 90.0f ) }; - FGL_DELETE_ALL_RO5( Camera ); + FGL_DELETE_ALL_RO5( CameraViewpoint ); - ~Camera(); + explicit CameraViewpoint( memory::Buffer& buffer, vk::Extent2D extent = { 1920, 1080 } ); - [[nodiscard]] CameraIDX getIDX() const; + [[nodiscard]] Coordinate< CoordinateSpace::World > getPosition() const; - [[nodiscard]] const std::string& getName() const; - - void setExtent( vk::Extent2D extent ); + WorldTransform& getTransform() { return m_transform; } [[nodiscard]] QuatRotation getRotation() const { return m_transform.rotation.forcedQuat(); } [[nodiscard]] const WorldTransform& getTransform() const { return m_transform; } - WorldTransform& getTransform() { return m_transform; } - - WorldCoordinate getFrustumPosition() const; - [[nodiscard]] const FrustumBase& getBaseFrustum() const { return m_base_frustum; } //! Returns the frustum of the camera in world space [[nodiscard]] const Frustum& getFrustumBounds() const { return m_frustum; } + [[nodiscard]] WorldCoordinate getFrustumPosition() const; + + void updateMatrix(); + void updateFrustum(); + [[nodiscard]] const Matrix< MatrixType::CameraToScreen >& getProjectionMatrix() const { return m_projection_matrix; @@ -148,20 +107,13 @@ namespace fgl::engine [[nodiscard]] Matrix< MatrixType::WorldToScreen > getProjectionViewMatrix() const; [[nodiscard]] glm::mat4 getInverseViewMatrix() const; - - enum ViewMode - { - Euler, - TaitBryan - }; + [[nodiscard]] Matrix< MatrixType::ModelToWorld > frustumTranslationMatrix() const; void setView( WorldCoordinate pos, const QuatRotation& rotation, ViewMode mode = TaitBryan ); void setOrthographicProjection( float left, float right, float top, float bottom, float near, float far ); void setPerspectiveProjection( float fovy, float aspect, float near, float far ); - [[nodiscard]] Coordinate< CoordinateSpace::World > getPosition() const; - - FGL_FORCE_INLINE NormalVector getUp() const { return -getDown(); } + FGL_FORCE_INLINE NormalVector getLeft() const { return -getRight(); } FGL_FORCE_INLINE NormalVector getRight() const { @@ -173,45 +125,30 @@ namespace fgl::engine return -NormalVector( glm::vec3( m_inverse_view_matrix[ 2 ] ) ); } - FGL_FORCE_INLINE NormalVector getLeft() const { return -getRight(); } - FGL_FORCE_INLINE NormalVector getBackward() const { return -getForward(); } + FGL_FORCE_INLINE NormalVector getUp() const { return -getDown(); } + FGL_FORCE_INLINE NormalVector getDown() const { return NormalVector( glm::vec3( m_inverse_view_matrix[ 1 ] ) ); } - //! Updates the required info for rendering - void updateInfo( FrameIndex frame_index ); - descriptors::DescriptorSet& getDescriptor( FrameIndex index ); - - void setFOV( float fov_y ); - - //! Performs the render pass for this camera - void pass( FrameInfo& frame_info ); - - [[nodiscard]] GBufferSwapchain& getSwapchain() const; - [[nodiscard]] CompositeSwapchain& getCompositeSwapchain() const; void setViewport( const vk::raii::CommandBuffer& command_buffer ); void setScissor( const vk::raii::CommandBuffer& command_buffer ); + void setFOV( float fov_y ); + [[nodiscard]] float aspectRatio() const; - void remakeSwapchain( vk::Extent2D extent ); + void moveTo( const WorldTransform pos ); - void setName( std::string_view str ); + //! Updates the required info for rendering + void updateInfo( FrameIndex frame_index ); - float aspectRatio() const; + void setExtent( vk::Extent2D extent ); - void copyOutput( const vk::raii::CommandBuffer& command_buffer, FrameIndex frame_index, Image& target ); - void updateMatrix(); + vk::Rect2D scissor() const; + vk::Viewport viewport() const; static descriptors::DescriptorSetLayout& getDescriptorLayout(); - -#ifdef EXPOSE_CAMERA_TESTS - - Camera CREATE_TESTING_CAMERA() { return { { 1920, 1080 } }; } - -#endif }; - -} // namespace fgl::engine +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/camera/GBufferCompositor.cpp b/src/engine/camera/GBufferCompositor.cpp index 1005621..bfa56ff 100644 --- a/src/engine/camera/GBufferCompositor.cpp +++ b/src/engine/camera/GBufferCompositor.cpp @@ -3,9 +3,10 @@ // #include "GBufferCompositor.hpp" -#include "Camera.hpp" #include "CompositeSwapchain.hpp" #include "GBufferSwapchain.hpp" +#include "RenderCamera.hpp" +#include "ShadowMap.hpp" #include "engine/rendering/pipelines/v2/AttachmentBuilder.hpp" namespace fgl::engine @@ -56,7 +57,8 @@ namespace fgl::engine PipelineBuilder builder { 0 }; builder.addDescriptorSet( gbuffer_set ); - builder.addDescriptorSet( Camera::getDescriptorLayout() ); + builder.addDescriptorSet( RenderCamera::getDescriptorLayout() ); + builder.addDescriptorSet( ShadowMap::getDescriptorLayout() ); builder.addColorAttachment().setFormat( pickColorFormat() ).finish(); @@ -73,7 +75,8 @@ namespace fgl::engine m_pipeline->setDebugName( "Composition pipeline" ); } - void GBufferCompositor::composite( CommandBuffer& command_buffer, Camera& camera, const FrameIndex frame_index ) + void GBufferCompositor:: + composite( CommandBuffer& command_buffer, RenderCamera& camera, const FrameIndex frame_index ) { auto& gbuffer_swapchain { camera.getSwapchain() }; auto& composite_swapchain { camera.getCompositeSwapchain() }; diff --git a/src/engine/camera/GBufferCompositor.hpp b/src/engine/camera/GBufferCompositor.hpp index 6b08027..94670c7 100644 --- a/src/engine/camera/GBufferCompositor.hpp +++ b/src/engine/camera/GBufferCompositor.hpp @@ -5,7 +5,7 @@ #include -#include "Camera.hpp" +#include "RenderCamera.hpp" #include "engine/rendering/pipelines/v2/Pipeline.hpp" #include "engine/rendering/types.hpp" #include "engine/systems/composition/Control.hpp" @@ -48,7 +48,7 @@ namespace fgl::engine GBufferCompositor( CompositeFlags flags = CompositeFlagBits_Standard ); - void composite( CommandBuffer& command_buffer, Camera& camera, FrameIndex frame_index ); + void composite( CommandBuffer& command_buffer, RenderCamera& camera, FrameIndex frame_index ); inline void switchMode( const CompositeFlags flags ) { m_flags = flags; } }; diff --git a/src/engine/camera/GBufferRenderer.cpp b/src/engine/camera/GBufferRenderer.cpp index 446b67d..b4ca39b 100644 --- a/src/engine/camera/GBufferRenderer.cpp +++ b/src/engine/camera/GBufferRenderer.cpp @@ -73,7 +73,8 @@ namespace fgl::engine camera_swapchain.transitionImages( command_buffer, GBufferSwapchain::FINAL, frame_info.in_flight_idx ); - m_compositor.composite( command_buffer, *frame_info.camera, frame_info.in_flight_idx ); + m_compositor + .composite( command_buffer, *static_cast< RenderCamera* >( frame_info.camera ), frame_info.in_flight_idx ); } } // namespace fgl::engine diff --git a/src/engine/camera/Camera.cpp b/src/engine/camera/RenderCamera.cpp similarity index 61% rename from src/engine/camera/Camera.cpp rename to src/engine/camera/RenderCamera.cpp index 2b70c82..31b33c8 100644 --- a/src/engine/camera/Camera.cpp +++ b/src/engine/camera/RenderCamera.cpp @@ -2,13 +2,12 @@ // Created by kj16609 on 11/28/23. // -#include "Camera.hpp" +#include "RenderCamera.hpp" #define GLM_ENABLE_EXPERIMENTAL #include #include -#include "CameraInfo.hpp" #include "GBufferRenderer.hpp" #include "GBufferSwapchain.hpp" #include "engine/debug/timing/FlameGraph.hpp" @@ -16,61 +15,67 @@ namespace fgl::engine { - Matrix< MatrixType::WorldToScreen > Camera::getProjectionViewMatrix() const + FrustumBase createFrustum( const float aspect, const float fov_y, const float near, const float far ) { - assert( m_projection_matrix != constants::MAT4_IDENTITY ); - return m_projection_matrix * m_view_matrix; + const Plane< CoordinateSpace::Model > near_plane { ModelCoordinate( constants::WORLD_FORWARD * near ), + NormalVector( constants::WORLD_FORWARD ) }; + const Plane< CoordinateSpace::Model > far_plane { ModelCoordinate( constants::WORLD_FORWARD * far ), + NormalVector( -constants::WORLD_FORWARD ) }; + + const float half_height { far * glm::tan( fov_y / 2.0f ) }; + const float half_width { half_height * aspect }; + + const ModelCoordinate far_forward { constants::WORLD_FORWARD * far }; + const ModelCoordinate right_half { constants::WORLD_RIGHT * half_width }; + + const Vector right_forward { ( far_forward + right_half ).vec() }; + const Vector left_forward { ( far_forward - right_half ).vec() }; + + const Plane< CoordinateSpace::Model > right_plane { + ModelCoordinate( constants::WORLD_CENTER ), + NormalVector( glm::cross( right_forward.vec(), constants::WORLD_Z_NEG ) ) + }; + const Plane< CoordinateSpace::Model > left_plane { + ModelCoordinate( constants::WORLD_CENTER ), + NormalVector( glm::cross( left_forward.vec(), constants::WORLD_Z ) ) + }; + + const ModelCoordinate top_half { constants::WORLD_Z * half_height }; + + const Vector top_forward { ( far_forward + top_half ).vec() }; + const Vector bottom_forward { ( far_forward - top_half ).vec() }; + + const Plane< CoordinateSpace::Model > top_plane { + ModelCoordinate( constants::WORLD_CENTER ), + NormalVector( glm::cross( top_forward.vec(), constants::WORLD_RIGHT ) ) + }; + + const Plane< CoordinateSpace::Model > bottom_plane { + ModelCoordinate( constants::WORLD_CENTER ), + NormalVector( glm::cross( bottom_forward.vec(), -constants::WORLD_RIGHT ) ) + }; + + return { near_plane, + far_plane, + top_plane, + bottom_plane, + right_plane, + left_plane, + Coordinate< CoordinateSpace::Model >( constants::WORLD_CENTER ) }; } - glm::mat4 Camera::getInverseViewMatrix() const + const std::string& RenderCamera::getName() const { - return glm::inverse( m_view_matrix ); + return m_name; } - void Camera::setOrthographicProjection( float left, float right, float top, float bottom, float near, float far ) - { - m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::ortho( left, right, bottom, top, near, far ) ); - - //TODO: Figure out frustum culling for orthographic projection. (If we even wanna use it) - } - - FGL_FLATTEN_HOT void Camera:: - setPerspectiveProjection( const float fovy, const float aspect, const float near, const float far ) - { - m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspective( fovy, aspect, near, far ) ); - - m_base_frustum = createFrustum( aspect, fovy, near, far ); - } - - Coordinate< CoordinateSpace::World > Camera::getPosition() const - { - //Should maybe store the inverse view matrix - return WorldCoordinate( m_inverse_view_matrix[ 3 ] ); - } - - void Camera::updateInfo( const FrameIndex frame_index ) - { - ZoneScoped; - CameraInfo current_camera_info { .projection = getProjectionMatrix(), - .view = getViewMatrix(), - .inverse_view = getInverseViewMatrix() }; - - m_camera_frame_info[ frame_index ] = current_camera_info; - } - - descriptors::DescriptorSet& Camera::getDescriptor( const FrameIndex index ) + descriptors::DescriptorSet& RenderCamera::getDescriptor( const FrameIndex index ) { assert( index < m_camera_info_descriptors.size() ); return *m_camera_info_descriptors[ index ]; } - void Camera::setFOV( const float fov_y ) - { - m_fov_y = fov_y; - setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); - } - - void Camera::pass( FrameInfo& frame_info ) + void RenderCamera::pass( FrameInfo& frame_info ) { ZoneScopedN( "Camera::pass" ); auto timer = debug::timing::push( "Camera" ); @@ -98,45 +103,20 @@ namespace fgl::engine frame_info.camera = nullptr; } - GBufferSwapchain& Camera::getSwapchain() const + GBufferSwapchain& RenderCamera::getSwapchain() const { return *m_gbuffer_swapchain; } - CompositeSwapchain& Camera::getCompositeSwapchain() const + CompositeSwapchain& RenderCamera::getCompositeSwapchain() const { return *m_composite_swapchain; } - void Camera::setViewport( const vk::raii::CommandBuffer& command_buffer ) + void RenderCamera::remakeSwapchain( vk::Extent2D extent ) { - vk::Viewport viewport {}; - viewport.x = 0.0f; - viewport.y = 0.0f; - - const auto& [ width, height ] = m_gbuffer_swapchain->getExtent(); - viewport.width = static_cast< float >( width ); - viewport.height = static_cast< float >( height ); - viewport.minDepth = 0.0f; - viewport.maxDepth = 1.0f; - - const std::vector< vk::Viewport > viewports { viewport }; - - command_buffer.setViewport( 0, viewports ); - } - - void Camera::setScissor( const vk::raii::CommandBuffer& command_buffer ) - { - const vk::Rect2D scissor { { 0, 0 }, m_gbuffer_swapchain->getExtent() }; - - const std::vector< vk::Rect2D > scissors { scissor }; - - command_buffer.setScissor( 0, scissors ); - } - - void Camera::remakeSwapchain( vk::Extent2D extent ) - { - this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); + setExtent( extent ); + this->setPerspectiveProjection( m_fov_y, this->aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); log::debug( "Camera swapchain recreated" ); @@ -148,20 +128,22 @@ namespace fgl::engine m_composite_swapchain = std::make_unique< CompositeSwapchain >( extent ); m_gbuffer_swapchain = std::make_unique< GBufferSwapchain >( extent ); + + CameraViewpoint::setExtent( extent ); } - void Camera::setName( const std::string_view str ) + void RenderCamera::setName( const std::string_view str ) { m_name = str; } - float Camera::aspectRatio() const + float RenderCamera::aspectRatio() const { return m_gbuffer_swapchain->getAspectRatio(); } - void Camera:: - copyOutput( const vk::raii::CommandBuffer& command_buffer, const FrameIndex frame_index, Image& target ) + void RenderCamera:: + copyOutput( const vk::raii::CommandBuffer& command_buffer, const FrameIndex frame_index, Image& target ) const { assert( m_gbuffer_swapchain->getExtent() == target.getExtent() ); @@ -271,175 +253,39 @@ namespace fgl::engine { barrier_to_source } ); } - void Camera::updateMatrix() + WorldCoordinate CameraViewpoint::getFrustumPosition() const { - const auto& [ pos, scale, rotation ] = m_transform; - - const auto rotation_matrix { rotation.forcedQuat().mat() }; - - const glm::vec3 forward { rotation_matrix * glm::vec4( constants::WORLD_FORWARD, 0.0f ) }; - - const glm::vec3 camera_up { rotation_matrix * glm::vec4( -constants::WORLD_Z, 0.0f ) }; - - const WorldCoordinate center_pos { pos + forward }; - - m_view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAt( pos.vec(), center_pos.vec(), camera_up ) ); - - m_inverse_view_matrix = glm::inverse( m_view_matrix ); - - updateFrustum(); + return m_last_frustum_pos; } - FGL_FLATTEN_HOT void Camera::setView( const WorldCoordinate pos, const QuatRotation& rotation, const ViewMode mode ) + Matrix< MatrixType::ModelToWorld > CameraViewpoint::frustumTranslationMatrix() const { - switch ( mode ) - { - case ViewMode::TaitBryan: - { - m_transform.translation = pos; - m_transform.rotation = rotation; - updateMatrix(); - break; - } - case ViewMode::Euler: - [[fallthrough]]; - { - //TODO: Implement - //view_matrix = glm::lookAt(position, position + ); - } - default: - throw std::runtime_error( "Unimplemented view mode" ); - } - - updateFrustum(); + return m_transform.mat(); } - void Camera::updateFrustum() - { - m_last_frustum_pos = getPosition(); - - const Matrix< MatrixType::ModelToWorld > translation_matrix { frustumTranslationMatrix() }; - - m_frustum = translation_matrix * m_base_frustum; - } - - const std::string& Camera::getName() const - { - return m_name; - } - - constexpr descriptors::Descriptor camera_descriptor { 0, - vk::DescriptorType::eUniformBuffer, - vk::ShaderStageFlagBits::eAllGraphics }; - - inline static descriptors::DescriptorSetLayout camera_descriptor_set { 1, camera_descriptor }; - - descriptors::DescriptorSetLayout& Camera::getDescriptorLayout() - { - return camera_descriptor_set; - } - - Camera::Camera( + RenderCamera::RenderCamera( const vk::Extent2D extent, memory::Buffer& buffer, const std::shared_ptr< GBufferRenderer >& renderer ) : + CameraViewpoint( buffer, extent ), m_target_extent( extent ), m_composite_swapchain( std::make_unique< CompositeSwapchain >( m_target_extent ) ), m_gbuffer_swapchain( std::make_unique< GBufferSwapchain >( m_target_extent ) ), - m_camera_renderer( renderer ), - m_camera_frame_info( buffer ), - m_camera_info_descriptors( createCameraDescriptors() ) + m_camera_renderer( renderer ) { FGL_ASSERT( renderer, "Camera renderer is null" ); this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); this->setView( WorldCoordinate( constants::CENTER ), QuatRotation( 0.0f, 0.0f, 0.0f ) ); } - std::vector< std::unique_ptr< descriptors::DescriptorSet > > Camera::createCameraDescriptors() - { - std::vector< std::unique_ptr< descriptors::DescriptorSet > > sets {}; - sets.reserve( constants::MAX_FRAMES_IN_FLIGHT ); + RenderCamera::~RenderCamera() = default; - for ( std::uint8_t i = 0; i < constants::MAX_FRAMES_IN_FLIGHT; ++i ) - { - auto set { camera_descriptor_set.create() }; - set->bindUniformBuffer( 0, m_camera_frame_info[ i ] ); - set->update(); - set->setName( std::format( "Camera {} descriptor set {}", m_camera_idx, i ) ); - - sets.emplace_back( std::move( set ) ); - } - return sets; - } - - void Camera::setExtent( const vk::Extent2D extent ) - { - m_target_extent = extent; - } - - FrustumBase createFrustum( const float aspect, const float fov_y, const float near, const float far ) - { - const Plane< CoordinateSpace::Model > near_plane { ModelCoordinate( constants::WORLD_FORWARD * near ), - NormalVector( constants::WORLD_FORWARD ) }; - const Plane< CoordinateSpace::Model > far_plane { ModelCoordinate( constants::WORLD_FORWARD * far ), - NormalVector( -constants::WORLD_FORWARD ) }; - - const float half_height { far * glm::tan( fov_y / 2.0f ) }; - const float half_width { half_height * aspect }; - - const ModelCoordinate far_forward { constants::WORLD_FORWARD * far }; - const ModelCoordinate right_half { constants::WORLD_RIGHT * half_width }; - - const Vector right_forward { ( far_forward + right_half ).vec() }; - const Vector left_forward { ( far_forward - right_half ).vec() }; - - const Plane< CoordinateSpace::Model > right_plane { - ModelCoordinate( constants::WORLD_CENTER ), - NormalVector( glm::cross( right_forward.vec(), constants::WORLD_Z_NEG ) ) - }; - const Plane< CoordinateSpace::Model > left_plane { - ModelCoordinate( constants::WORLD_CENTER ), - NormalVector( glm::cross( left_forward.vec(), constants::WORLD_Z ) ) - }; - - const ModelCoordinate top_half { constants::WORLD_Z * half_height }; - - const Vector top_forward { ( far_forward + top_half ).vec() }; - const Vector bottom_forward { ( far_forward - top_half ).vec() }; - - const Plane< CoordinateSpace::Model > top_plane { - ModelCoordinate( constants::WORLD_CENTER ), - NormalVector( glm::cross( top_forward.vec(), constants::WORLD_RIGHT ) ) - }; - - const Plane< CoordinateSpace::Model > bottom_plane { - ModelCoordinate( constants::WORLD_CENTER ), - NormalVector( glm::cross( bottom_forward.vec(), -constants::WORLD_RIGHT ) ) - }; - - return { near_plane, - far_plane, - top_plane, - bottom_plane, - right_plane, - left_plane, - Coordinate< CoordinateSpace::Model >( constants::WORLD_CENTER ) }; - } - - Matrix< MatrixType::ModelToWorld > Camera::frustumTranslationMatrix() const - { - return m_transform.mat(); - } - - WorldCoordinate Camera::getFrustumPosition() const - { - return m_last_frustum_pos; - } - - Camera::~Camera() - {} - - CameraIDX Camera::getIDX() const + CameraIDX RenderCamera::getIDX() const { return m_camera_idx; } + void RenderCamera::setExtent( const vk::Extent2D extent ) + { + m_target_extent = extent; + } + } // namespace fgl::engine diff --git a/src/engine/camera/RenderCamera.hpp b/src/engine/camera/RenderCamera.hpp new file mode 100644 index 0000000..c062291 --- /dev/null +++ b/src/engine/camera/RenderCamera.hpp @@ -0,0 +1,110 @@ +// +// Created by kj16609 on 11/28/23. +// + +#pragma once + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wduplicated-branches" +#define GLM_ENABLE_EXPERIMENTAL +#include +#include +#pragma GCC diagnostic pop + +#include "CameraViewpoint.hpp" +#include "CompositeSwapchain.hpp" +#include "GBufferSwapchain.hpp" +#include "debug/Track.hpp" +#include "engine/descriptors/DescriptorSet.hpp" +#include "engine/memory/buffers/HostSingleT.hpp" +#include "engine/memory/buffers/UniqueFrameSuballocation.hpp" +#include "engine/primitives/Frustum.hpp" +#include "engine/rendering/types.hpp" + +namespace vk::raii +{ + class CommandBuffer; + class RenderPass; +} // namespace vk::raii + +namespace fgl::engine +{ + namespace descriptors + { + class DescriptorSetLayout; + } + class Image; + struct FrameInfo; + class GBufferRenderer; + + struct CameraInfo; + class RenderCamera; + + FrustumBase createFrustum( float aspect, float fovy, float near, float far ); + + using CameraIDX = std::uint8_t; + + class RenderCamera final : public CameraViewpoint + { + inline static CameraIDX m_camera_counter { 0 }; + + debug::Track< "CPU", "Camera" > m_camera {}; + + vk::Extent2D m_target_extent; + + std::unique_ptr< CompositeSwapchain > m_composite_swapchain; + std::unique_ptr< GBufferSwapchain > m_gbuffer_swapchain; + + //TODO: Move to deffered deleter + std::queue< std::unique_ptr< CompositeSwapchain > > m_old_composite_swapchain {}; + std::queue< std::unique_ptr< GBufferSwapchain > > m_old_gbuffer_swapchain {}; + + std::shared_ptr< GBufferRenderer > m_camera_renderer; + + //! True if the camera is active and to be rendered + bool m_active { true }; + + //! If true, The camera's swapchain is to be destroyed to preserve memory. + //! This is here to allow us to set a camera cold when it's not likely to be used soon + bool m_cold { false }; + + // Const is acceptable, Since this value should never change. EVER + const CameraIDX m_camera_idx { m_camera_counter++ }; + + std::string m_name { "Unnamed Camera" }; + + RenderCamera( vk::Extent2D extent, memory::Buffer& buffer, const std::shared_ptr< GBufferRenderer >& renderer ); + + friend class CameraManager; + + public: + + FGL_DELETE_ALL_RO5( RenderCamera ); + + ~RenderCamera(); + + [[nodiscard]] CameraIDX getIDX() const; + + [[nodiscard]] const std::string& getName() const; + + descriptors::DescriptorSet& getDescriptor( FrameIndex index ); + + void setExtent( vk::Extent2D extent ); + + //! Performs the render pass for this camera + void pass( FrameInfo& frame_info ); + + [[nodiscard]] GBufferSwapchain& getSwapchain() const; + [[nodiscard]] CompositeSwapchain& getCompositeSwapchain() const; + + void remakeSwapchain( vk::Extent2D extent ); + + void setName( std::string_view str ); + + [[nodiscard]] float aspectRatio() const; + + void copyOutput( const vk::raii::CommandBuffer& command_buffer, FrameIndex frame_index, Image& target ) const; + }; + +} // namespace fgl::engine diff --git a/src/engine/camera/ShadowMap.cpp b/src/engine/camera/ShadowMap.cpp new file mode 100644 index 0000000..8fdbcc5 --- /dev/null +++ b/src/engine/camera/ShadowMap.cpp @@ -0,0 +1,167 @@ +// +// Created by kj16609 on 9/23/25. +// +#include "ShadowMap.hpp" + +#include "CameraManager.hpp" +#include "assets/model/Model.hpp" +#include "assets/model/ModelVertex.hpp" +#include "debug/timing/FlameGraph.hpp" +#include "rendering/pipelines/v2/Pipeline.hpp" +#include "rendering/pipelines/v2/PipelineBuilder.hpp" + +namespace fgl::engine +{ + + std::shared_ptr< Swapchain > createDepthSwapchain( const vk::Extent2D extent ) + { + std::vector< SwapchainImageInfo > swapchain_images { + { .m_format = { .m_canidates = { vk::Format::eD32Sfloat, + vk::Format::eD32SfloatS8Uint, + vk::Format::eD24UnormS8Uint }, + .m_usage = + vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eSampled, + .m_features = vk::FormatFeatureFlagBits::eDepthStencilAttachment }, + .m_inital_layout = vk::ImageLayout::eUndefined, + .m_final_layout = vk::ImageLayout::eDepthReadOnlyOptimal, + .m_extent = extent, + .m_name = "Shadowmap Depth" } + }; + + return std::make_shared< Swapchain >( std::move( swapchain_images ) ); + } + + constexpr descriptors::Descriptor camera_descriptor { 0, + vk::DescriptorType::eUniformBuffer, + vk::ShaderStageFlagBits::eAllGraphics }; + + // 2d sampler + constexpr descriptors::Descriptor shadowmap_descriptor { 1, + vk::DescriptorType::eSampledImage, + vk::ShaderStageFlagBits::eFragment }; + + inline static descriptors::DescriptorSetLayout shadowmap_descriptor_set { 2, + camera_descriptor, + shadowmap_descriptor }; + + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > ShadowMap::createShadowmapDescriptors() const + { + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > data {}; + + for ( std::size_t i = 0; i < data.size(); ++i ) + { + auto set { shadowmap_descriptor_set.create() }; + + set->bindImage( + shadowmap_descriptor.m_index, + *this->m_swapchain->depthView( i ), + vk::ImageLayout::eDepthReadOnlyOptimal ); + set->bindUniformBuffer( camera_descriptor.m_index, this->m_camera->frameInfo( i ) ); + + set->update(); + + data[ i ] = std::move( set ); + } + + return data; + } + + ShadowMap::ShadowMap( const UniversalRotation& direction, const vk::Extent2D extent ) : + m_swapchain( createDepthSwapchain( extent ) ), + m_direction( direction ), + m_camera( CameraManager::createViewpoint( extent ) ), + m_extent( extent ), + m_shadowmap_descriptor( createShadowmapDescriptors() ) + { + PipelineBuilder builder { 0 }; + + builder.addDepthAttachment(); + + builder.addDescriptorSet( CameraViewpoint::getDescriptorLayout() ); + builder.setVertexShader( Shader::loadVertex( "shaders/shadowmap.slang" ) ); + builder.setFragmentShader( Shader::loadFragment( "shaders/shadowmap.slang" ) ); + + builder.setAttributeDescriptions( ModelVertex::getAttributeDescriptions() ); + builder.setBindingDescriptions( ModelVertex::getBindingDescriptions() ); + + m_shadow_pipeline = builder.create(); + m_shadow_pipeline->setDebugName( "Shadow pipeline" ); + } + + void ShadowMap::pass( FrameInfo info ) + { + ZoneScopedN( "ShadowMap::pass" ); + auto timer = debug::timing::push( "ShadowMap" ); + + info.camera = m_camera.get(); + + info.camera->updateInfo( info.in_flight_idx ); + + m_culling_system.pass( info ); + + auto& command_buffer { info.command_buffer.render_cb }; + + vk::RenderingInfo rendering_info {}; + vk::RenderingAttachmentInfo depth_info {}; + depth_info.setClearValue( vk::ClearDepthStencilValue( 1.0f, 0 ) ); + depth_info.setLoadOp( vk::AttachmentLoadOp::eClear ); + depth_info.setStoreOp( vk::AttachmentStoreOp::eStore ); + depth_info.imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal; + depth_info.imageView = m_swapchain->depthView( info.in_flight_idx )->getVkView(); + rendering_info.colorAttachmentCount = 0; + rendering_info.pColorAttachments = nullptr; + rendering_info.setRenderArea( { { 0, 0 }, this->m_extent } ); + rendering_info.layerCount = 1; + + rendering_info.setPDepthAttachment( &depth_info ); + + command_buffer->beginRendering( rendering_info ); + + command_buffer->setViewport( 0, { info.camera->viewport() } ); + command_buffer->setScissor( 0, { info.camera->scissor() } ); + + m_shadow_pipeline->bind( command_buffer ); + + m_shadow_pipeline->bindDescriptor( command_buffer, info.getCameraDescriptor() ); + + auto& model_buffers { getModelBuffers() }; + + const std::vector< vk::Buffer > vert_buffers { + model_buffers.m_vertex_buffer->getVkBuffer(), + info.camera->m_generated_instance_info[ info.in_flight_idx ].getVkBuffer(), + }; + + command_buffer->bindVertexBuffers( + 0, vert_buffers, { 0, info.camera->m_generated_instance_info[ info.in_flight_idx ].getOffset() } ); + command_buffer->bindIndexBuffer( model_buffers.m_index_buffer->getVkBuffer(), 0, vk::IndexType::eUint32 ); + + const auto& commands { info.camera->m_gpu_draw_commands[ info.in_flight_idx ] }; + + command_buffer + ->drawIndexedIndirect( commands.getVkBuffer(), commands.getOffset(), commands.size(), commands.stride() ); + + command_buffer->endRendering(); + } + + static std::vector< std::weak_ptr< ShadowMap > > shadowmaps {}; + + descriptors::DescriptorSetLayout& ShadowMap::getDescriptorLayout() + { + return shadowmap_descriptor_set; + } + + std::shared_ptr< ShadowMap > createShadowmap( UniversalRotation direction ) + { + constexpr int size { 1024 }; + auto ptr { std::make_shared< ShadowMap >( direction, vk::Extent2D { size, size } ) }; + + shadowmaps.emplace_back( ptr ); + + return ptr; + } + + std::vector< std::weak_ptr< ShadowMap > > getShadowmaps() + { + return shadowmaps; + } +} // namespace fgl::engine diff --git a/src/engine/camera/ShadowMap.hpp b/src/engine/camera/ShadowMap.hpp new file mode 100644 index 0000000..f053881 --- /dev/null +++ b/src/engine/camera/ShadowMap.hpp @@ -0,0 +1,55 @@ +// +// Created by kj16609 on 9/23/25. +// +#pragma once + +#include + +#include + +#include "RenderCamera.hpp" +#include "Swapchain.hpp" +#include "primitives/rotation/UniversalRotation.hpp" +#include "systems/prerender/CullingSystem.hpp" + +namespace fgl::engine +{ + namespace gui + { + void drawShadowmaps( const FrameInfo& info ); + } + + struct CameraInfo; + + class ShadowMap + { + std::shared_ptr< Swapchain > m_swapchain; + UniversalRotation m_direction; + + std::shared_ptr< CameraViewpoint > m_camera; + + std::unique_ptr< Pipeline > m_shadow_pipeline; + + CullingSystem m_culling_system; + vk::Extent2D m_extent; + + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > createShadowmapDescriptors() const; + PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > m_shadowmap_descriptor; + + public: + + ShadowMap() = delete; + + ShadowMap( const UniversalRotation& direction, vk::Extent2D extent ); + + void pass( FrameInfo info ); + + friend void gui::drawShadowmaps( const FrameInfo& info ); + static descriptors::DescriptorSetLayout& getDescriptorLayout(); + }; + + std::shared_ptr< ShadowMap > createShadowmap( UniversalRotation direction ); + + std::vector< std::weak_ptr< ShadowMap > > getShadowmaps(); + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/camera/Swapchain.cpp b/src/engine/camera/Swapchain.cpp new file mode 100644 index 0000000..2cb8779 --- /dev/null +++ b/src/engine/camera/Swapchain.cpp @@ -0,0 +1,80 @@ +// +// Created by kj16609 on 9/23/25. +// +#include "Swapchain.hpp" + +#include "assets/image/Image.hpp" +#include "assets/image/ImageView.hpp" +#include "assets/texture/Texture.hpp" +#include "constants.hpp" +#include "rendering/devices/Device.hpp" +#include "slang.h" + +namespace fgl::engine +{ + + vk::Format SwapchainImageInfo::pickBestFormat() const + { + return Device::getInstance() + .findSupportedFormat( m_format.m_canidates, vk::ImageTiling::eOptimal, m_format.m_features ); + } + + SwapchainImageSet::SwapchainImageSet( const SwapchainImageInfo& info ) + { + for ( int i = 0; i < constants::MAX_FRAMES_IN_FLIGHT; ++i ) + { + auto image_itter { m_image.emplace_back( + std::make_shared< Image >( + info.m_extent, + info.pickBestFormat(), + info.m_format.m_usage, + info.m_inital_layout, + info.m_final_layout ) ) }; + auto view_itter { m_view.emplace_back( image_itter->getView() ) }; + + image_itter->setName( std::format( "Swapchain image {}:{}", info.m_name, i ) ); + } + } + + std::shared_ptr< Texture > SwapchainImageSet::getTexture( const FrameIndex frame_index ) const + { + if ( m_texture.empty() ) m_texture.resize( constants::MAX_FRAMES_IN_FLIGHT ); + + if ( !m_texture[ frame_index ] ) + { + Sampler default_sampler {}; + m_texture[ frame_index ] = + std::make_shared< Texture >( m_image[ frame_index ], std::move( default_sampler ) ); + } + + return m_texture[ frame_index ]; + } + + std::shared_ptr< ImageView > Swapchain::depthView( const FrameIndex frame_index ) const + { + const SwapchainImageSet& set { m_depth.value() }; + + return set.m_view[ frame_index ]; + } + + std::shared_ptr< Image > Swapchain::depthImage( const FrameIndex frame_index ) const + { + return m_depth.value().m_image[ frame_index ]; + } + + std::shared_ptr< Texture > Swapchain::depthTexture( const FrameIndex frame_index ) const + { + return m_depth.value().getTexture( frame_index ); + } + + Swapchain::Swapchain( const std::vector< SwapchainImageInfo >& in ) + { + for ( const SwapchainImageInfo& info : in ) + { + if ( info.m_format.m_usage & vk::ImageUsageFlagBits::eDepthStencilAttachment ) + m_depth.emplace( info ); + else + m_swapchain_images.emplace_back( info ); + } + } +} // namespace fgl::engine diff --git a/src/engine/camera/Swapchain.hpp b/src/engine/camera/Swapchain.hpp new file mode 100644 index 0000000..7dbfe0a --- /dev/null +++ b/src/engine/camera/Swapchain.hpp @@ -0,0 +1,69 @@ +// +// Created by kj16609 on 9/23/25. +// +#pragma once +#include + +#include +#include +#include + +#include "FGL_DEFINES.hpp" +#include "assets/texture/Texture.hpp" +#include "rendering/types.hpp" + +namespace fgl::engine +{ + class Image; + class ImageView; + + struct SwapchainImageInfo + { + struct + { + std::vector< vk::Format > m_canidates; + vk::ImageUsageFlags m_usage; + vk::FormatFeatureFlags m_features; + } m_format; + + vk::ImageLayout m_inital_layout; + vk::ImageLayout m_final_layout; + + vk::Extent2D m_extent; + std::string m_name; + + [[nodiscard]] vk::Format pickBestFormat() const; + }; + + class SwapchainImageSet + { + std::vector< std::shared_ptr< Image > > m_image {}; + std::vector< std::shared_ptr< ImageView > > m_view {}; + mutable std::vector< std::shared_ptr< Texture > > m_texture {}; + + friend class Swapchain; + + public: + + SwapchainImageSet() = delete; + + [[nodiscard]] SwapchainImageSet( const SwapchainImageInfo& info ); + std::shared_ptr< Texture > getTexture( FrameIndex frame_index ) const; + }; + + class Swapchain + { + std::vector< SwapchainImageSet > m_swapchain_images {}; + std::optional< SwapchainImageSet > m_depth {}; + + public: + + [[nodiscard]] std::shared_ptr< ImageView > depthView( FrameIndex frame_index ) const; + [[nodiscard]] std::shared_ptr< Image > depthImage( FrameIndex frame_index ) const; + std::shared_ptr< Texture > depthTexture( FrameIndex frame_index ) const; + + FGL_DELETE_ALL_RO5( Swapchain ); + + [[nodiscard]] explicit Swapchain( const std::vector< SwapchainImageInfo >& in ); + }; +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/constants.hpp b/src/engine/constants.hpp index 410dd48..74883dd 100644 --- a/src/engine/constants.hpp +++ b/src/engine/constants.hpp @@ -55,4 +55,6 @@ namespace fgl::engine::constants constexpr glm::vec3 DEFAULT_SCALE { 1.0f }; + constexpr glm::vec3 SUN_DIR { 0.0f, 0.0f, 1.0f }; + } // namespace fgl::engine::constants diff --git a/src/engine/descriptors/DescriptorPool.cpp b/src/engine/descriptors/DescriptorPool.cpp index ec616a8..5657453 100644 --- a/src/engine/descriptors/DescriptorPool.cpp +++ b/src/engine/descriptors/DescriptorPool.cpp @@ -9,7 +9,15 @@ namespace fgl::engine::descriptors { - vk::raii::DescriptorPool createPool( std::uint32_t set_count ) + static const std::unordered_map< vk::DescriptorType, float > DESCRIPTOR_ALLOCATION_RATIOS { + { vk::DescriptorType::eUniformBuffer, 1.0f }, + { vk::DescriptorType::eCombinedImageSampler, 2.0f }, + { vk::DescriptorType::eStorageBuffer, 1.0f }, + { vk::DescriptorType::eInputAttachment, 0.5f }, + { vk::DescriptorType::eSampledImage, 2.0f } + }; + + vk::raii::DescriptorPool createPool( const std::uint32_t set_count ) { std::vector< vk::DescriptorPoolSize > pool_sizes {}; for ( auto& [ type, ratio ] : DESCRIPTOR_ALLOCATION_RATIOS ) diff --git a/src/engine/descriptors/DescriptorPool.hpp b/src/engine/descriptors/DescriptorPool.hpp index 25d7ab4..0b9ed0a 100644 --- a/src/engine/descriptors/DescriptorPool.hpp +++ b/src/engine/descriptors/DescriptorPool.hpp @@ -17,9 +17,6 @@ namespace fgl::engine namespace fgl::engine::descriptors { - static const std::unordered_map< vk::DescriptorType, float > DESCRIPTOR_ALLOCATION_RATIOS { - { vk::DescriptorType::eUniformBuffer, 2.0f }, { vk::DescriptorType::eCombinedImageSampler, 2.0f } - }; class DescriptorPool { diff --git a/src/engine/gameobjects/components/CameraComponent.hpp b/src/engine/gameobjects/components/CameraComponent.hpp index b60e734..ebcff79 100644 --- a/src/engine/gameobjects/components/CameraComponent.hpp +++ b/src/engine/gameobjects/components/CameraComponent.hpp @@ -10,16 +10,16 @@ namespace fgl::engine { - class Camera; + class RenderCamera; COMPONENT_CLASS( CameraComponent, CameraComponentID ) { - std::shared_ptr< Camera > m_camera; + std::shared_ptr< RenderCamera > m_camera; public: CameraComponent() = delete; - CameraComponent( std::shared_ptr< Camera > & camera ); + CameraComponent( std::shared_ptr< RenderCamera > & camera ); ~CameraComponent(); }; diff --git a/src/engine/lighting/lights/Sun.cpp b/src/engine/lighting/lights/Sun.cpp new file mode 100644 index 0000000..1495bca --- /dev/null +++ b/src/engine/lighting/lights/Sun.cpp @@ -0,0 +1,12 @@ +// +// Created by kj16609 on 9/23/25. +// +#include "Sun.hpp" + +#include "camera/ShadowMap.hpp" + +namespace fgl::engine +{ + Sun::Sun() : m_shadowmap( createShadowmap( UniversalRotation::pointAt( constants::SUN_DIR ) ) ) + {} +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/lighting/lights/Sun.hpp b/src/engine/lighting/lights/Sun.hpp new file mode 100644 index 0000000..57f58a5 --- /dev/null +++ b/src/engine/lighting/lights/Sun.hpp @@ -0,0 +1,19 @@ +// +// Created by kj16609 on 9/23/25. +// +#pragma once +#include + +namespace fgl::engine +{ + class ShadowMap; + + struct Sun + { + std::shared_ptr< ShadowMap > m_shadowmap; + + public: + + Sun(); + }; +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/lighting/shadows/ShadowMap.cpp b/src/engine/lighting/shadows/ShadowMap.cpp deleted file mode 100644 index ba559fe..0000000 --- a/src/engine/lighting/shadows/ShadowMap.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// -// Created by kj16609 on 2/17/25. -// -#include "ShadowMap.hpp" - -#include "assets/image/Image.hpp" -#include "assets/texture/Texture.hpp" - -namespace fgl::engine::shadows -{ - - std::shared_ptr< Image > getDepthImage( const vk::Extent2D extent ) - { - constexpr auto format { vk::Format::eR16Unorm }; - constexpr vk::ImageUsageFlags usage_flags { vk::ImageUsageFlagBits::eSampled - | vk::ImageUsageFlagBits::eDepthStencilAttachment }; - constexpr auto inital_layout { vk::ImageLayout::eUndefined }; - constexpr auto final_layout { vk::ImageLayout::eDepthReadOnlyOptimal }; - - return std::make_shared< Image >( extent, format, usage_flags, inital_layout, final_layout ); - } - - PerFrameArray< std::shared_ptr< Image > > createDepthImages( vk::Extent2D extent ) - { - PerFrameArray< std::shared_ptr< Image > > array {}; - - for ( std::size_t i = 0; i < array.size(); ++i ) array[ i ] = getDepthImage( extent ); - - return array; - } - - PerFrameArray< std::shared_ptr< Texture > > ShadowMap::createDepthTargets() - { - PerFrameArray< std::shared_ptr< Texture > > array {}; - - Sampler default_sampler {}; - for ( std::size_t i = 0; i < array.size(); ++i ) - array[ i ] = std::make_shared< Texture >( m_image[ i ], std::move( default_sampler ) ); - - return array; - } - - void ShadowMap::renderForCamera( const Camera& camera ) - { - // model -> world -> camera (identity) -> screen (shadow) - // since the camera in this case is the shadow map we just need to convert the screen space to world space. So we can just use an identity matrix - - const Matrix< MatrixType::WorldToCamera > camera_matrix { m_transform.mat() }; - const Matrix< MatrixType::CameraToScreen > identity { 1.0f }; - - const Matrix< MatrixType::WorldToScreen > matrix { camera_matrix * identity }; - } - - ShadowMap::ShadowMap( const vk::Extent2D extent ) : - m_image( createDepthImages( extent ) ), - m_target( createDepthTargets() ) - {} - -} // namespace fgl::engine::shadows \ No newline at end of file diff --git a/src/engine/lighting/shadows/ShadowMap.hpp b/src/engine/lighting/shadows/ShadowMap.hpp deleted file mode 100644 index 61b4054..0000000 --- a/src/engine/lighting/shadows/ShadowMap.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Created by kj16609 on 2/17/25. -// -#pragma once -#include - -#include - -#include "primitives/Transform.hpp" -#include "primitives/matricies/Matrix.hpp" -#include "primitives/matricies/MatrixEvolvedTypes.hpp" -#include "rendering/PresentSwapChain.hpp" - -namespace fgl::engine -{ - class Image; - class Texture; -} // namespace fgl::engine - -namespace fgl::engine::shadows -{ - - class ShadowMap - { - PerFrameArray< std::shared_ptr< Image > > m_image; - PerFrameArray< std::shared_ptr< Texture > > m_target; - - Matrix< MatrixType::WorldToScreen > m_matrix { 1.0f }; - - Transform< CoordinateSpace::World > m_transform {}; - - PerFrameArray< std::shared_ptr< Texture > > createDepthTargets(); - - public: - - void renderForCamera( const Camera& camera ); - - ShadowMap( vk::Extent2D extent ); - ~ShadowMap(); - }; - -} // namespace fgl::engine::shadows - -namespace fgl::engine -{ - using namespace shadows; -} \ No newline at end of file diff --git a/src/engine/primitives/Frustum.hpp b/src/engine/primitives/Frustum.hpp index 8c6775f..f99f6d8 100644 --- a/src/engine/primitives/Frustum.hpp +++ b/src/engine/primitives/Frustum.hpp @@ -15,7 +15,7 @@ namespace fgl::engine { - class Camera; + class RenderCamera; //! Frustum constructed in model space (To be translated to a World space frustum later) struct FrustumBase @@ -60,7 +60,7 @@ namespace fgl::engine WorldCoordinate m_position {}; - friend class Camera; + friend class RenderCamera; public: diff --git a/src/engine/primitives/rotation/UniversalRotation.cpp b/src/engine/primitives/rotation/UniversalRotation.cpp index 0ff7bd3..1eadd55 100644 --- a/src/engine/primitives/rotation/UniversalRotation.cpp +++ b/src/engine/primitives/rotation/UniversalRotation.cpp @@ -6,6 +6,11 @@ namespace fgl::engine { + UniversalRotation UniversalRotation::pointAt( const glm::vec3 vec ) + { + return UniversalRotation( QuatRotation( glm::normalize( vec ) ) ); + } + void UniversalRotation::addX( const float value ) { if ( isQuat() ) [[likely]] diff --git a/src/engine/primitives/rotation/UniversalRotation.hpp b/src/engine/primitives/rotation/UniversalRotation.hpp index 937c931..1bd8204 100644 --- a/src/engine/primitives/rotation/UniversalRotation.hpp +++ b/src/engine/primitives/rotation/UniversalRotation.hpp @@ -75,6 +75,8 @@ namespace fgl::engine return q_rotation; } + static UniversalRotation pointAt( const glm::vec3 vec ); + // Universal modification void addX( float value ); void addY( float value ); diff --git a/src/engine/rendering/devices/extensions.hpp b/src/engine/rendering/devices/extensions.hpp index 235fc6c..1159ce7 100644 --- a/src/engine/rendering/devices/extensions.hpp +++ b/src/engine/rendering/devices/extensions.hpp @@ -14,6 +14,8 @@ inline const static std::vector< const char* > DEVICE_EXTENSIONS = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, // Used for descriptor indexing + VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, + // VK_EXT_MESH_SHADER_EXTENSION_NAME, // MAGICAL SHIT VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME // Required until vulkan 1.4 }; diff --git a/src/engine/rendering/pipelines/Attachment.hpp b/src/engine/rendering/pipelines/Attachment.hpp index 386284e..0a65bdc 100644 --- a/src/engine/rendering/pipelines/Attachment.hpp +++ b/src/engine/rendering/pipelines/Attachment.hpp @@ -168,45 +168,6 @@ namespace fgl::engine friend class RenderPassBuilder; }; - template < std::size_t index, vk::ImageLayout layout > - struct InputAttachment - { - static constexpr bool is_input { true }; - static constexpr vk::ImageLayout m_layout { layout }; - static constexpr std::size_t m_index { index }; - }; - - template < std::size_t index, vk::ImageLayout layout > - struct UsedAttachment - { - static constexpr vk::ImageLayout m_layout { layout }; - static constexpr std::size_t m_index { index }; - static constexpr bool is_input { false }; - }; - - template < typename T > - concept is_input_attachment = requires( T a ) { - { a.is_input } -> std::same_as< const bool& >; - { a.m_layout } -> std::same_as< const vk::ImageLayout& >; - } && T::is_input; - - template < typename T > - concept is_used_attachment = requires( T a ) { - { a.is_input } -> std::same_as< const bool& >; - { a.m_layout } -> std::same_as< const vk::ImageLayout& >; - } && !T::is_input; - - template < typename T > concept is_wrapped_attachment = is_input_attachment< T > || is_used_attachment< T >; - - template < typename T > - requires is_wrapped_attachment< T > - using UnwrappedAttachment = std::conditional_t< is_wrapped_attachment< T >, typename T::Attachment, T >; - - //! Checks if the wrapped attachment is a depth attachment - template < typename T > - concept is_wrapped_depth_attachment = is_wrapped_attachment< T > && is_attachment< UnwrappedAttachment< T > > - && ( T::m_layout == vk::ImageLayout::eDepthStencilAttachmentOptimal ); - //Helper functions template < is_attachment Attachment, is_attachment... Attachments > consteval std::uint32_t maxIndex() @@ -221,18 +182,6 @@ namespace fgl::engine } } - template < is_attachment... Attachments > - static std::vector< vk::ImageView > getViewsForFrame( const FrameIndex frame_idx, Attachments... attachments ) - { - std::vector< vk::ImageView > view {}; - view.resize( sizeof...( Attachments ) ); - static_assert( maxIndex< Attachments... >() + 1 == sizeof...( Attachments ) ); - - ( ( view[ attachments.m_index ] = *attachments.getView( frame_idx ) ), ... ); - - return view; - } - template < is_attachment... Attachments > static std::vector< vk::ClearValue > gatherClearValues( Attachments... attachments ) { diff --git a/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp b/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp index 4e625e7..1d97014 100644 --- a/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp +++ b/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp @@ -13,6 +13,189 @@ namespace fgl::engine { + vk::raii::PipelineLayout PipelineBuilder::createLayout() + { + vk::PipelineLayoutCreateInfo info {}; + + if ( m_state->push_constant.size > 0 ) info.setPushConstantRanges( m_state->push_constant ); + + std::vector< vk::DescriptorSetLayout > set_layouts {}; + + set_layouts.reserve( m_state->descriptor_set_layouts.size() ); + + SetID max_set_idx { 0 }; + + for ( const auto& [ set_idx, _ ] : m_state->descriptor_set_layouts ) + { + max_set_idx = std::max( max_set_idx, set_idx ); + } + + // Any sets not used, Should be set to VK_NULL_HANDLE + set_layouts.resize( max_set_idx + 1 ); + + for ( std::size_t i = 0; i < set_layouts.size(); ++i ) + { + auto itter { m_state->descriptor_set_layouts.find( static_cast< SetID >( i ) ) }; + if ( itter == m_state->descriptor_set_layouts.end() ) + { + // Could not find it. Empty + set_layouts[ i ] = m_empty_set_layout.layout(); + } + else + { + set_layouts[ i ] = itter->second; + } + } + + for ( const auto& [ set_idx, layout ] : m_state->descriptor_set_layouts ) + { + set_layouts[ set_idx ] = layout; + } + + info.setSetLayouts( set_layouts ); + + return Device::getInstance()->createPipelineLayout( info ); + } + + void PipelineBuilder:: + addDescriptorSet( const SetID idx, const vk::raii::DescriptorSetLayout& descriptor_set_layout ) const + { + FGL_ASSERT( !m_state->descriptor_set_layouts.contains( idx ), "Descriptor already set! Conflicting SetIDs" ); + m_state->descriptor_set_layouts.insert( std::make_pair( idx, *descriptor_set_layout ) ); + } + + void PipelineBuilder::addDescriptorSet( descriptors::DescriptorSetLayout& descriptor ) + { + addDescriptorSet( descriptor.m_set_idx, descriptor.layout() ); + } + + void PipelineBuilder::addDynamicState( vk::DynamicState dynamic_state ) + { + m_state->m_dynamic_state.emplace_back( dynamic_state ); + } + + void PipelineBuilder::setPushConstant( const vk::ShaderStageFlags flags, std::uint32_t size ) + { + m_state->push_constant.offset = 0; + m_state->push_constant.size = size; + m_state->push_constant.stageFlags = flags; + } + + void PipelineBuilder::setBindPoint( vk::PipelineBindPoint bind_point ) + { + m_state->bind_point = bind_point; + } + + PipelineBuilder::BuilderState::Formats::Formats() + {} + + [[nodiscard]] vk::PipelineColorBlendAttachmentState& PipelineBuilder::BuilderState::addColorAttachment() + { + color_blend_attachment.emplace_back(); + color_blend_info.setAttachments( color_blend_attachment ); + return color_blend_attachment.back(); + } + + PipelineBuilder::BuilderState::BuilderState( std::uint32_t subpass ) : m_subpass_stage( subpass ) + { + setDefault(); + } + + void PipelineBuilder::BuilderState::setDefault() + { + viewport_info.viewportCount = 1; + viewport_info.pViewports = nullptr; + viewport_info.scissorCount = 1; + viewport_info.pScissors = nullptr; + + assembly_info.topology = vk::PrimitiveTopology::eTriangleList; + assembly_info.primitiveRestartEnable = VK_FALSE; + + rasterization_info.depthClampEnable = VK_FALSE; + rasterization_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_info.polygonMode = vk::PolygonMode::eFill; + rasterization_info.cullMode = vk::CullModeFlagBits::eBack; + rasterization_info.frontFace = vk::FrontFace::eClockwise; + rasterization_info.depthBiasEnable = VK_FALSE; + rasterization_info.depthBiasConstantFactor = 0.0f; + rasterization_info.depthBiasClamp = 0.0f; + rasterization_info.depthBiasSlopeFactor = 0.0f; + rasterization_info.lineWidth = 1.0f; + + multisample_info.rasterizationSamples = vk::SampleCountFlagBits::e1; + multisample_info.sampleShadingEnable = VK_FALSE; + multisample_info.minSampleShading = 1.0f; + multisample_info.pSampleMask = nullptr; + multisample_info.alphaToCoverageEnable = VK_FALSE; + multisample_info.alphaToOneEnable = VK_FALSE; + + color_blend_info.logicOpEnable = VK_FALSE; + color_blend_info.logicOp = vk::LogicOp::eCopy; + color_blend_info.attachmentCount = 0; + color_blend_info.pAttachments = nullptr; + color_blend_info.blendConstants[ 0 ] = 0.0f; + color_blend_info.blendConstants[ 1 ] = 0.0f; + color_blend_info.blendConstants[ 2 ] = 0.0f; + color_blend_info.blendConstants[ 3 ] = 0.0f; + + depth_stencil_info.depthTestEnable = VK_TRUE; + depth_stencil_info.depthWriteEnable = VK_TRUE; + depth_stencil_info.depthCompareOp = vk::CompareOp::eLess; + depth_stencil_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_info.stencilTestEnable = VK_FALSE; + //depth_stencil_info.front = {}; + //depth_stencil_info.back = {}; + depth_stencil_info.minDepthBounds = 0.0f; + depth_stencil_info.maxDepthBounds = 1.0f; + + dynamic_state_enables = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; + dynamic_state_info.setDynamicStates( dynamic_state_enables ); + //info.dynamic_state_info.flags = 0; + } + + void PipelineBuilder::setTopology( const vk::PrimitiveTopology primitive_topology ) + { + m_state->assembly_info.topology = primitive_topology; + } + + void PipelineBuilder::disableVertexInput() + { + m_state->vertex_input_descriptions.bindings = {}; + m_state->vertex_input_descriptions.attributes = {}; + } + + void PipelineBuilder::disableCulling() + { + m_state->rasterization_info.cullMode = vk::CullModeFlagBits::eNone; + } + + void PipelineBuilder::addDepthAttachment() + { + m_state->formats.depth = pickDepthFormat(); + } + + AttachmentBuilder PipelineBuilder::addAttachment() + { + return { *this }; + } + + AttachmentBuilder PipelineBuilder::addColorAttachment() + { + AttachmentBuilder builder { addAttachment() }; + return builder; + } + + void PipelineBuilder::setBindingDescriptions( const std::vector< vk::VertexInputBindingDescription >& descriptions ) + { + m_state->vertex_input_descriptions.bindings = descriptions; + } + + void PipelineBuilder:: + setAttributeDescriptions( const std::vector< vk::VertexInputAttributeDescription >& descriptions ) const + { + m_state->vertex_input_descriptions.attributes = descriptions; + } + PipelineBuilder::PipelineBuilder( std::uint32_t subpass ) : m_state( std::make_unique< BuilderState >( subpass ) ) { addDynamicState( vk::DynamicState::eViewport ); @@ -87,6 +270,12 @@ namespace fgl::engine return pipeline; } + vk::raii::Pipeline PipelineBuilder::createDynamicPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) + { + if ( state.shaders.compute ) return createComputePipeline( state, layout ); + return createGraphicsPipeline( state, layout ); + } + vk::raii::Pipeline PipelineBuilder::createComputePipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) { vk::StructureChain< vk::ComputePipelineCreateInfo > chain {}; @@ -106,12 +295,6 @@ namespace fgl::engine return Device::getInstance()->createComputePipeline( VK_NULL_HANDLE, info ); } - vk::raii::Pipeline PipelineBuilder::createDynamicPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) - { - if ( state.shaders.compute ) return createComputePipeline( state, layout ); - return createGraphicsPipeline( state, layout ); - } - vk::raii::Pipeline PipelineBuilder::createGraphicsPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) { vk::StructureChain< vk::GraphicsPipelineCreateInfo, vk::PipelineRenderingCreateInfo > chain {}; @@ -174,189 +357,6 @@ namespace fgl::engine return pipeline; } - vk::raii::PipelineLayout PipelineBuilder::createLayout() - { - vk::PipelineLayoutCreateInfo info {}; - - if ( m_state->push_constant.size > 0 ) info.setPushConstantRanges( m_state->push_constant ); - - std::vector< vk::DescriptorSetLayout > set_layouts {}; - - set_layouts.reserve( m_state->descriptor_set_layouts.size() ); - - SetID max_set_idx { 0 }; - - for ( const auto& [ set_idx, _ ] : m_state->descriptor_set_layouts ) - { - max_set_idx = std::max( max_set_idx, set_idx ); - } - - // Any sets not used, Should be set to VK_NULL_HANDLE - set_layouts.resize( max_set_idx + 1 ); - - for ( std::size_t i = 0; i < set_layouts.size(); ++i ) - { - auto itter { m_state->descriptor_set_layouts.find( static_cast< SetID >( i ) ) }; - if ( itter == m_state->descriptor_set_layouts.end() ) - { - // Could not find it. Empty - set_layouts[ i ] = m_empty_set_layout.layout(); - } - else - { - set_layouts[ i ] = itter->second; - } - } - - for ( const auto& [ set_idx, layout ] : m_state->descriptor_set_layouts ) - { - set_layouts[ set_idx ] = layout; - } - - info.setSetLayouts( set_layouts ); - - return Device::getInstance()->createPipelineLayout( info ); - } - - void PipelineBuilder:: - addDescriptorSet( const SetID idx, const vk::raii::DescriptorSetLayout& descriptor_set_layout ) const - { - FGL_ASSERT( !m_state->descriptor_set_layouts.contains( idx ), "Descriptor already set!" ); - m_state->descriptor_set_layouts.insert( std::make_pair( idx, *descriptor_set_layout ) ); - } - - void PipelineBuilder::addDescriptorSet( descriptors::DescriptorSetLayout& descriptor ) - { - addDescriptorSet( descriptor.m_set_idx, descriptor.layout() ); - } - - void PipelineBuilder::addDynamicState( vk::DynamicState dynamic_state ) - { - m_state->m_dynamic_state.emplace_back( dynamic_state ); - } - - void PipelineBuilder::setPushConstant( const vk::ShaderStageFlags flags, std::uint32_t size ) - { - m_state->push_constant.offset = 0; - m_state->push_constant.size = size; - m_state->push_constant.stageFlags = flags; - } - - void PipelineBuilder::setBindPoint( vk::PipelineBindPoint bind_point ) - { - m_state->bind_point = bind_point; - } - - PipelineBuilder::BuilderState::Formats::Formats() - {} - - [[nodiscard]] vk::PipelineColorBlendAttachmentState& PipelineBuilder::BuilderState::addColorAttachment() - { - color_blend_attachment.emplace_back(); - color_blend_info.setAttachments( color_blend_attachment ); - return color_blend_attachment.back(); - } - - void PipelineBuilder::BuilderState::setDefault() - { - viewport_info.viewportCount = 1; - viewport_info.pViewports = nullptr; - viewport_info.scissorCount = 1; - viewport_info.pScissors = nullptr; - - assembly_info.topology = vk::PrimitiveTopology::eTriangleList; - assembly_info.primitiveRestartEnable = VK_FALSE; - - rasterization_info.depthClampEnable = VK_FALSE; - rasterization_info.rasterizerDiscardEnable = VK_FALSE; - rasterization_info.polygonMode = vk::PolygonMode::eFill; - rasterization_info.cullMode = vk::CullModeFlagBits::eBack; - rasterization_info.frontFace = vk::FrontFace::eClockwise; - rasterization_info.depthBiasEnable = VK_FALSE; - rasterization_info.depthBiasConstantFactor = 0.0f; - rasterization_info.depthBiasClamp = 0.0f; - rasterization_info.depthBiasSlopeFactor = 0.0f; - rasterization_info.lineWidth = 1.0f; - - multisample_info.rasterizationSamples = vk::SampleCountFlagBits::e1; - multisample_info.sampleShadingEnable = VK_FALSE; - multisample_info.minSampleShading = 1.0f; - multisample_info.pSampleMask = nullptr; - multisample_info.alphaToCoverageEnable = VK_FALSE; - multisample_info.alphaToOneEnable = VK_FALSE; - - color_blend_info.logicOpEnable = VK_FALSE; - color_blend_info.logicOp = vk::LogicOp::eCopy; - color_blend_info.attachmentCount = 0; - color_blend_info.pAttachments = nullptr; - color_blend_info.blendConstants[ 0 ] = 0.0f; - color_blend_info.blendConstants[ 1 ] = 0.0f; - color_blend_info.blendConstants[ 2 ] = 0.0f; - color_blend_info.blendConstants[ 3 ] = 0.0f; - - depth_stencil_info.depthTestEnable = VK_TRUE; - depth_stencil_info.depthWriteEnable = VK_TRUE; - depth_stencil_info.depthCompareOp = vk::CompareOp::eLess; - depth_stencil_info.depthBoundsTestEnable = VK_FALSE; - depth_stencil_info.stencilTestEnable = VK_FALSE; - //depth_stencil_info.front = {}; - //depth_stencil_info.back = {}; - depth_stencil_info.minDepthBounds = 0.0f; - depth_stencil_info.maxDepthBounds = 1.0f; - - dynamic_state_enables = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; - dynamic_state_info.setDynamicStates( dynamic_state_enables ); - //info.dynamic_state_info.flags = 0; - } - - PipelineBuilder::BuilderState::BuilderState( std::uint32_t subpass ) : m_subpass_stage( subpass ) - { - setDefault(); - } - - void PipelineBuilder::setTopology( const vk::PrimitiveTopology primitive_topology ) - { - m_state->assembly_info.topology = primitive_topology; - } - - void PipelineBuilder::disableVertexInput() - { - m_state->vertex_input_descriptions.bindings = {}; - m_state->vertex_input_descriptions.attributes = {}; - } - - void PipelineBuilder::disableCulling() - { - m_state->rasterization_info.cullMode = vk::CullModeFlagBits::eNone; - } - - void PipelineBuilder::addDepthAttachment() - { - m_state->formats.depth = pickDepthFormat(); - } - - AttachmentBuilder PipelineBuilder::addAttachment() - { - return { *this }; - } - - AttachmentBuilder PipelineBuilder::addColorAttachment() - { - AttachmentBuilder builder { addAttachment() }; - return builder; - } - - void PipelineBuilder::setBindingDescriptions( const std::vector< vk::VertexInputBindingDescription >& descriptions ) - { - m_state->vertex_input_descriptions.bindings = descriptions; - } - - void PipelineBuilder:: - setAttributeDescriptions( const std::vector< vk::VertexInputAttributeDescription >& descriptions ) const - { - m_state->vertex_input_descriptions.attributes = descriptions; - } - vk::raii::Pipeline PipelineBuilder::createFromState( BuilderState& state, vk::raii::PipelineLayout& layout ) { return createDynamicPipeline( state, layout ); diff --git a/src/engine/scene/Scene.hpp b/src/engine/scene/Scene.hpp index 2e6172f..20caaf9 100644 --- a/src/engine/scene/Scene.hpp +++ b/src/engine/scene/Scene.hpp @@ -2,7 +2,7 @@ // Created by kj16609 on 2/28/25. // #pragma once -#include "camera/Camera.hpp" +#include "camera/RenderCamera.hpp" namespace fgl::engine { diff --git a/src/engine/systems/prerender/CullingSystem.cpp b/src/engine/systems/prerender/CullingSystem.cpp index 70f6547..a4ed4e8 100644 --- a/src/engine/systems/prerender/CullingSystem.cpp +++ b/src/engine/systems/prerender/CullingSystem.cpp @@ -8,7 +8,7 @@ #include "assets/model/Model.hpp" #include "engine/FrameInfo.hpp" -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" namespace fgl::engine { @@ -44,7 +44,7 @@ namespace fgl::engine CullingSystem::~CullingSystem() {} - void CullingSystem::pass( FrameInfo& info ) + void CullingSystem::pass( const FrameInfo& info ) { ZoneScopedN( "Culling pass" ); @@ -61,10 +61,13 @@ namespace fgl::engine m_cull_compute->bindDescriptor( command_buffer, info.m_primitives_desc ); // primitive set m_cull_compute->bindDescriptor( command_buffer, info.m_instances_desc ); // instances - m_cull_compute->bindDescriptor( command_buffer, info.m_command_buffer_desc ); // commands output + m_cull_compute->bindDescriptor( + command_buffer, *info.camera->m_gpu_draw_cmds_desc[ info.in_flight_idx ] ); // commands output + auto& commands { info.camera->m_gpu_draw_commands[ info.in_flight_idx ] }; + commands.resize( info.instances.size() ); CullPushConstants push_constants {}; - push_constants.draw_count = info.m_commands.size(); + push_constants.draw_count = commands.size(); command_buffer->pushConstants< CullPushConstants >( m_cull_compute->layout(), vk::ShaderStageFlagBits::eCompute, 0, { push_constants } ); @@ -76,7 +79,7 @@ namespace fgl::engine command_buffer->dispatch( group_count, 1, 1 ); - // Add a memory barrier to ensure synchronization between the compute and subsequent stages + // Add a memory barrier to ensure synchronization between the compute and later stages vk::MemoryBarrier memory_barrier { vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eVertexAttributeRead | vk::AccessFlagBits::eIndirectCommandRead, diff --git a/src/engine/systems/prerender/CullingSystem.hpp b/src/engine/systems/prerender/CullingSystem.hpp index 2478118..4d937f3 100644 --- a/src/engine/systems/prerender/CullingSystem.hpp +++ b/src/engine/systems/prerender/CullingSystem.hpp @@ -38,7 +38,7 @@ namespace fgl::engine ~CullingSystem(); - void pass( FrameInfo& info ); + void pass( const FrameInfo& info ); }; static_assert( is_system< CullingSystem > ); diff --git a/src/engine/systems/render/EntityRendererSystem.cpp b/src/engine/systems/render/EntityRendererSystem.cpp index c2c4d41..bdda447 100644 --- a/src/engine/systems/render/EntityRendererSystem.cpp +++ b/src/engine/systems/render/EntityRendererSystem.cpp @@ -10,7 +10,7 @@ #include "EngineContext.hpp" #include "assets/model/ModelVertex.hpp" #include "engine/assets/material/Material.hpp" -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" #include "engine/debug/timing/FlameGraph.hpp" #include "engine/rendering/pipelines/v2/Pipeline.hpp" #include "engine/rendering/pipelines/v2/PipelineBuilder.hpp" @@ -29,7 +29,7 @@ namespace fgl::engine addGBufferAttachments( builder ); - builder.addDescriptorSet( Camera::getDescriptorLayout() ); + builder.addDescriptorSet( RenderCamera::getDescriptorLayout() ); builder.addDescriptorSet( Texture::getDescriptorLayout() ); builder.addDescriptorSet( Material::getDescriptorLayout() ); @@ -92,18 +92,17 @@ namespace fgl::engine const std::vector< vk::Buffer > vert_buffers { model_buffers.m_vertex_buffer->getVkBuffer(), - model_buffers.m_generated_instance_info[ info.in_flight_idx ].getVkBuffer() + info.camera->m_generated_instance_info[ info.in_flight_idx ].getVkBuffer(), }; command_buffer->bindVertexBuffers( - 0, vert_buffers, { 0, model_buffers.m_generated_instance_info[ info.in_flight_idx ].getOffset() } ); + 0, vert_buffers, { 0, info.camera->m_generated_instance_info[ info.in_flight_idx ].getOffset() } ); command_buffer->bindIndexBuffer( model_buffers.m_index_buffer->getVkBuffer(), 0, vk::IndexType::eUint32 ); - command_buffer->drawIndexedIndirect( - info.m_commands.getVkBuffer(), - info.m_commands.getOffset(), - info.m_commands.size(), - info.m_commands.stride() ); + const auto& commands { info.camera->m_gpu_draw_commands[ info.in_flight_idx ] }; + + command_buffer + ->drawIndexedIndirect( commands.getVkBuffer(), commands.getOffset(), commands.size(), commands.stride() ); }; } // namespace fgl::engine diff --git a/src/engine/systems/render/LineDrawer.cpp b/src/engine/systems/render/LineDrawer.cpp index 8e5450c..a061624 100644 --- a/src/engine/systems/render/LineDrawer.cpp +++ b/src/engine/systems/render/LineDrawer.cpp @@ -6,7 +6,7 @@ #include "engine/FrameInfo.hpp" #include "engine/assets/model/SimpleVertex.hpp" -#include "engine/camera/Camera.hpp" +#include "engine/camera/RenderCamera.hpp" #include "engine/debug/drawers.hpp" #include "engine/primitives/points/Coordinate.hpp" #include "engine/rendering/pipelines/v2/Pipeline.hpp" @@ -27,7 +27,7 @@ namespace fgl::engine { PipelineBuilder builder { 0 }; - builder.addDescriptorSet( Camera::getDescriptorLayout() ); + builder.addDescriptorSet( RenderCamera::getDescriptorLayout() ); addGBufferAttachments( builder ); diff --git a/src/shaders/composition.slang b/src/shaders/composition.slang index 8643c90..a8f636e 100644 --- a/src/shaders/composition.slang +++ b/src/shaders/composition.slang @@ -1,6 +1,7 @@ #version 450 import objects.camera; +import objects.gbuffer; struct Vertex { vec4 position : SV_Position; @@ -24,13 +25,6 @@ struct CompositeFragment { vec4 color; }; -struct GBufferInput { - SubpassInput color : COLOR; - SubpassInput position : POSITION; - SubpassInput normal : NORMAL; - SubpassInput metallic : METALLIC; - SubpassInput emissive : EMISSIVE; -}; // SubpassInput< vec4 > test : TEST; @@ -46,6 +40,12 @@ ParameterBlock gbuffer : GBUFFER; [[vk::binding(0,1)]] ParameterBlock< CameraData > camera : CAMERA; +[[vk::binding(0,2)]] +ParameterBlock< CameraData > sun_camera; + +[[vk::binding(1,2)]] +Sampler2D shadow_sampler; + //TODO: constant flags // Direction the sun is facing diff --git a/src/shaders/culling.slang b/src/shaders/culling.slang index 0469e50..3a79cad 100644 --- a/src/shaders/culling.slang +++ b/src/shaders/culling.slang @@ -75,7 +75,7 @@ void computeMain( uint3 dispatch_id : SV_DispatchThreadID) out_instances[ instance_index ].material_id = instance.material_id; const ModelInstanceInfo model_instance = model_instances[ instance.model_index ]; - out_instances[ instance_index ].model_matrix = model_instance.model_matrix; + out_instances[ instance_index ].model_matrix = {model_instance.model_matrix}; // out_instances[ instance_index ].normal_matrix = model_instance.normal_matrix; } else diff --git a/src/shaders/objects/camera.slang b/src/shaders/objects/camera.slang index d2561cc..7f9533f 100644 --- a/src/shaders/objects/camera.slang +++ b/src/shaders/objects/camera.slang @@ -14,6 +14,13 @@ public struct CameraData return vec3( inverse_view[ 0 ][ 3 ], inverse_view[ 1 ][ 3 ], inverse_view[ 2 ][ 3 ] ); } + public vec4 toCameraSpace(const vec4 world_coordinate) + { + return mul(mat(), world_coordinate); + } + + + public mat4x4 mat() { return mul( projection, view ); diff --git a/src/shaders/objects/gamemodel.slang b/src/shaders/objects/gamemodel.slang index a2c30a6..0172d76 100644 --- a/src/shaders/objects/gamemodel.slang +++ b/src/shaders/objects/gamemodel.slang @@ -11,6 +11,41 @@ public struct PrimitiveRenderInfo { public uint32_t index_count; }; +public struct ModelMatrix +{ + mat4x4 matrix; + + public mat3 toNormalMatrix() + { + return transpose( inverse( mat3( matrix ) ) ); + } + + public vec3 normalizeNormal( vec3 normal ) + { + return normalize( mul( toNormalMatrix(), normal ) ); + } + + public vec4 toWorldSpace( vec4 position ) + { + return mul(matrix, position); + } + + public __init( mat4x4 matrix_in ) + { + matrix = matrix_in; + } + + public mat4x4 mat() + { + return matrix; + } +}; + +ModelMatrix operator=(mat4x4 matrix) +{ + return {matrix}; +} + // Each primitive has one instance public struct PrimitiveInstanceInfo { @@ -22,7 +57,7 @@ public struct PrimitiveInstanceInfo // One object exists for each render instance public struct InstanceRenderInfo { - public mat4x4 model_matrix; + public ModelMatrix model_matrix; // public mat4x4 normal_matrix; public uint32_t material_id; }; diff --git a/src/shaders/objects/gbuffer.slang b/src/shaders/objects/gbuffer.slang index 668a691..0d9aab2 100644 --- a/src/shaders/objects/gbuffer.slang +++ b/src/shaders/objects/gbuffer.slang @@ -11,3 +11,10 @@ public struct GBufferFragment public vec3 emissive : EMISSIVE; }; +public struct GBufferInput { + public SubpassInput color : COLOR; + public SubpassInput position : POSITION; + public SubpassInput normal : NORMAL; + public SubpassInput metallic : METALLIC; + public SubpassInput emissive : EMISSIVE; +}; diff --git a/src/shaders/shadowmap.slang b/src/shaders/shadowmap.slang index b1482fb..4e28eb9 100644 --- a/src/shaders/shadowmap.slang +++ b/src/shaders/shadowmap.slang @@ -1,15 +1,36 @@ - +#version 450 import model.vertex; +import objects.camera; struct CoarseVertex { float4 position : SV_Position; -} +}; + +struct Fragment +{ +}; + +[ [ vk::binding( 0, 1 ) ] ] +ConstantBuffer< CameraData > camera : CAMERA; [shader("vertex")] -CoarseVertex vertexMain( ModelVertex in_vertex ) +CoarseVertex vertexMain(ModelVertex in_vertex) { + CoarseVertex out_vertex; + vec4 world_pos = in_vertex.instance.model_matrix.toWorldSpace( vec4(in_vertex.simple.position, 1.0) ); + out_vertex.position = camera.toCameraSpace( world_pos ); + return out_vertex; } + +[shader("fragment")] +Fragment fragmentMain(CoarseVertex vertex) +{ + Fragment fragment; + + return fragment; + +} \ No newline at end of file diff --git a/src/shaders/textured.slang b/src/shaders/textured.slang index ad81cee..a77a68a 100644 --- a/src/shaders/textured.slang +++ b/src/shaders/textured.slang @@ -23,18 +23,20 @@ CoarseVertex vertexMain( ModelVertex in_vertex ) { CoarseVertex out_vertex; - vec4 world_pos = mul(in_vertex.instance.model_matrix, vec4(in_vertex.simple.position, 1.0)); - - const float4 transformed_pos = mul( camera.mat(), world_pos ); - out_vertex.position = transformed_pos; +// vec4 world_pos = mul(in_vertex.instance.model_matrix, vec4(in_vertex.simple.position, 1.0)); + vec4 world_pos = in_vertex.instance.model_matrix.toWorldSpace( vec4(in_vertex.simple.position, 1.0) ); out_vertex.world_pos = world_pos.xyz; - mat3 normal_matrix = transpose( inverse( mat3( in_vertex.instance.model_matrix ) ) ); + out_vertex.position = camera.toCameraSpace( world_pos) ; - out_vertex.normal = normalize( mul(normal_matrix, in_vertex.normal) ); +// mat3 normal_matrix = transpose( inverse( mat3( in_vertex.instance.model_matrix ) ) ); + mat3 normal_matrix = in_vertex.instance.model_matrix.toNormalMatrix(); + +// out_vertex.normal = normalize( mul(normal_matrix, in_vertex.normal) ); + out_vertex.normal = in_vertex.instance.model_matrix.normalizeNormal( in_vertex.normal ); out_vertex.tex_coord = in_vertex.uv; out_vertex.material_id = in_vertex.instance.material_id; - out_vertex.matrix = in_vertex.instance.model_matrix; + out_vertex.matrix = in_vertex.instance.model_matrix.mat(); out_vertex.tangent = in_vertex.tangent; return out_vertex; -- 2.49.1 From 2d3b1f6c7f8637dd439b26a2598fb1e6ea836e4e Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sat, 27 Sep 2025 14:51:13 -0400 Subject: [PATCH 09/22] Cleanup pass 1 --- src/editor/src/components/GameComponent.cpp | 1 - src/engine/assets/image/Image.hpp | 2 +- src/engine/assets/material/Material.hpp | 12 ++++------ src/engine/assets/model/Model.hpp | 4 ---- src/engine/assets/model/ModelVertex.cpp | 4 ---- src/engine/assets/model/ModelVertex.hpp | 4 ---- src/engine/assets/model/Primitive.hpp | 7 +----- src/engine/assets/model/SimpleVertex.hpp | 3 --- src/engine/assets/model/VertexAttribute.hpp | 4 ---- .../assets/model/builders/ModelBuilder.cpp | 5 ++-- .../assets/model/builders/ModelBuilder.hpp | 3 +-- .../assets/model/builders/SceneBuilder.cpp | 10 ++------ .../assets/model/builders/SceneBuilder.hpp | 4 ---- src/engine/assets/model/builders/loadObj.cpp | 4 ---- src/engine/assets/stores.hpp | 2 +- src/engine/assets/texture/Texture.cpp | 6 ----- src/engine/camera/RenderCamera.hpp | 6 ----- src/engine/concepts/is_bindable.hpp | 8 ++----- src/engine/concepts/is_constant_range.hpp | 4 +--- src/engine/concepts/is_image.hpp | 14 ++++------- src/engine/constants.hpp | 3 --- src/engine/debug/logging/formatters/glm.cpp | 4 ---- .../debug/logging/formatters/matrix.cpp | 4 ---- src/engine/debug/logging/logging.hpp | 8 +------ src/engine/debug/timing/FlameGraph.cpp | 9 ++----- src/engine/descriptors/DescriptorPool.hpp | 1 - src/engine/gameobjects/components/drawers.cpp | 4 ---- .../interface/ComponentEditorInterface.cpp | 4 ---- .../interface/GameObjectComponent.cpp | 4 ---- .../lighting/lights/GlobalIlluminator.cpp | 1 - .../math/intersections/aabb/coordinate.cpp | 2 -- src/engine/math/noise/perlin/generator.cpp | 5 ---- src/engine/math/noise/perlin/generator.hpp | 3 --- src/engine/memory/DefferedCleanup.hpp | 5 ++-- src/engine/memory/buffers/HostSingleT.hpp | 3 ++- src/engine/primitives/Scale.hpp | 3 --- src/engine/primitives/boxes/concepts.hpp | 24 +++++-------------- src/engine/primitives/lines/LineBase.cpp | 3 --- src/engine/primitives/lines/LineBase.hpp | 3 --- src/engine/primitives/matricies/Matrix.hpp | 3 --- .../matricies/MatrixEvolvedTypes.hpp | 4 +--- .../primitives/matricies/RotationMatrix.hpp | 3 --- .../primitives/matricies/mult_operators.cpp | 5 ---- src/engine/primitives/planes/concepts.hpp | 24 +++++-------------- src/engine/primitives/points/Coordinate.hpp | 4 ---- src/engine/primitives/points/concepts.hpp | 14 ++++------- .../primitives/rotation/EulerRotation.hpp | 6 +---- .../primitives/rotation/QuatRotation.cpp | 4 ++-- .../primitives/rotation/QuatRotation.hpp | 4 ---- .../primitives/vectors/NormalVector.hpp | 3 --- src/engine/primitives/vectors/Vector.hpp | 3 --- src/engine/rendering/devices/Device.hpp | 1 + src/engine/rendering/pipelines/Attachment.hpp | 4 ++-- .../rendering/pipelines/shaders/Compiler.cpp | 12 +--------- src/engine/rendering/renderpass/Subpass.hpp | 4 +--- src/engine/systems/concepts.hpp | 16 ++++--------- 56 files changed, 57 insertions(+), 257 deletions(-) diff --git a/src/editor/src/components/GameComponent.cpp b/src/editor/src/components/GameComponent.cpp index 8cf7e13..ef27113 100644 --- a/src/editor/src/components/GameComponent.cpp +++ b/src/editor/src/components/GameComponent.cpp @@ -7,5 +7,4 @@ namespace fgl::engine { - } diff --git a/src/engine/assets/image/Image.hpp b/src/engine/assets/image/Image.hpp index abcf57d..5bb9393 100644 --- a/src/engine/assets/image/Image.hpp +++ b/src/engine/assets/image/Image.hpp @@ -60,7 +60,7 @@ namespace fgl::engine [[nodiscard]] const vk::Extent2D& getExtent() const { return m_extent; } - [[nodiscard]] std::shared_ptr< ImageView > getView( Sampler sampler = {}); + [[nodiscard]] std::shared_ptr< ImageView > getView( Sampler sampler = {} ); [[nodiscard]] vk::ImageMemoryBarrier transitionTo( vk::ImageLayout old_layout, vk::ImageLayout new_layout, const vk::ImageSubresourceRange& range ) const; diff --git a/src/engine/assets/material/Material.hpp b/src/engine/assets/material/Material.hpp index b7cc0c3..e8efb3d 100644 --- a/src/engine/assets/material/Material.hpp +++ b/src/engine/assets/material/Material.hpp @@ -4,20 +4,16 @@ #pragma once +#include +#include + #include -#include "engine/types.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#include "glm/vec3.hpp" -#include "glm/vec4.hpp" -#pragma GCC diagnostic pop - #include "engine/constants.hpp" #include "engine/descriptors/Descriptor.hpp" #include "engine/descriptors/DescriptorSetLayout.hpp" #include "engine/memory/buffers/vector/DeviceVector.hpp" +#include "engine/types.hpp" namespace fgl::engine { diff --git a/src/engine/assets/model/Model.hpp b/src/engine/assets/model/Model.hpp index ffde8af..2a3215d 100644 --- a/src/engine/assets/model/Model.hpp +++ b/src/engine/assets/model/Model.hpp @@ -4,11 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include -#pragma GCC diagnostic pop #include #include diff --git a/src/engine/assets/model/ModelVertex.cpp b/src/engine/assets/model/ModelVertex.cpp index 20375aa..4194ea9 100644 --- a/src/engine/assets/model/ModelVertex.cpp +++ b/src/engine/assets/model/ModelVertex.cpp @@ -5,12 +5,8 @@ #include "ModelVertex.hpp" #define GLM_ENABLE_EXPERIMENTAL -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include #include -#pragma GCC diagnostic pop #include "Model.hpp" #include "ModelInstance.hpp" diff --git a/src/engine/assets/model/ModelVertex.hpp b/src/engine/assets/model/ModelVertex.hpp index b2197d9..06b135a 100644 --- a/src/engine/assets/model/ModelVertex.hpp +++ b/src/engine/assets/model/ModelVertex.hpp @@ -4,13 +4,9 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include #include -#pragma GCC diagnostic pop - #include #include "SimpleVertex.hpp" diff --git a/src/engine/assets/model/Primitive.hpp b/src/engine/assets/model/Primitive.hpp index 2354cb9..c9fcfcf 100644 --- a/src/engine/assets/model/Primitive.hpp +++ b/src/engine/assets/model/Primitive.hpp @@ -6,17 +6,12 @@ #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" -#include "objectloaders/tiny_gltf.h" -#pragma GCC diagnostic pop - #include "ModelInstanceInfo.hpp" #include "assets/material/Material.hpp" #include "engine/memory/buffers/vector/DeviceVector.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" #include "memory/buffers/vector/IndexedVector.hpp" +#include "objectloaders/tiny_gltf.h" namespace fgl::engine { diff --git a/src/engine/assets/model/SimpleVertex.hpp b/src/engine/assets/model/SimpleVertex.hpp index 00ae720..a4c2142 100644 --- a/src/engine/assets/model/SimpleVertex.hpp +++ b/src/engine/assets/model/SimpleVertex.hpp @@ -4,11 +4,8 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include -#pragma GCC diagnostic pop #include diff --git a/src/engine/assets/model/VertexAttribute.hpp b/src/engine/assets/model/VertexAttribute.hpp index 3caa33e..224975f 100644 --- a/src/engine/assets/model/VertexAttribute.hpp +++ b/src/engine/assets/model/VertexAttribute.hpp @@ -2,12 +2,8 @@ // Created by kj16609 on 7/5/25. // #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include #include -#pragma GCC diagnostic pop #include "rendering/RenderingFormats.hpp" diff --git a/src/engine/assets/model/builders/ModelBuilder.cpp b/src/engine/assets/model/builders/ModelBuilder.cpp index cc48949..f122523 100644 --- a/src/engine/assets/model/builders/ModelBuilder.cpp +++ b/src/engine/assets/model/builders/ModelBuilder.cpp @@ -6,8 +6,8 @@ #include -#include "engine/assets/model/Primitive.hpp" #include "engine/assets/model/ModelVertex.hpp" +#include "engine/assets/model/Primitive.hpp" namespace fgl::engine { @@ -23,7 +23,8 @@ namespace fgl::engine throw std::runtime_error( "Unknown model file extension" ); } - void ModelBuilder::loadVerts( const std::vector< ModelVertex >& verts, const std::vector< std::uint32_t >& indicies ) + void ModelBuilder:: + loadVerts( const std::vector< ModelVertex >& verts, const std::vector< std::uint32_t >& indicies ) { ZoneScoped; VertexBufferSuballocation vertex_suballoc { this->m_vertex_buffer, verts }; diff --git a/src/engine/assets/model/builders/ModelBuilder.hpp b/src/engine/assets/model/builders/ModelBuilder.hpp index 0a694b8..aec856a 100644 --- a/src/engine/assets/model/builders/ModelBuilder.hpp +++ b/src/engine/assets/model/builders/ModelBuilder.hpp @@ -24,8 +24,7 @@ namespace fgl::engine ModelBuilder() = delete; - ModelBuilder( - const memory::Buffer& parent_vertex_buffer, const memory::Buffer& parent_index_buffer ) : + ModelBuilder( const memory::Buffer& parent_vertex_buffer, const memory::Buffer& parent_index_buffer ) : m_vertex_buffer( parent_vertex_buffer ), m_index_buffer( parent_index_buffer ) {} diff --git a/src/engine/assets/model/builders/SceneBuilder.cpp b/src/engine/assets/model/builders/SceneBuilder.cpp index 2f9420e..5f90231 100644 --- a/src/engine/assets/model/builders/SceneBuilder.cpp +++ b/src/engine/assets/model/builders/SceneBuilder.cpp @@ -4,15 +4,8 @@ #include "SceneBuilder.hpp" -#include "engine/assets/model/Model.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" -#include "objectloaders/tiny_gltf.h" -#pragma GCC diagnostic pop - #include "assets/model/ModelVertex.hpp" +#include "engine/assets/model/Model.hpp" #include "engine/assets/stores.hpp" #include "engine/camera/RenderCamera.hpp" #include "engine/debug/logging/logging.hpp" @@ -20,6 +13,7 @@ #include "engine/gameobjects/GameObject.hpp" #include "gameobjects/components/TransformComponent.hpp" #include "mikktspace/mikktspace.hpp" +#include "objectloaders/tiny_gltf.h" namespace fgl::engine { diff --git a/src/engine/assets/model/builders/SceneBuilder.hpp b/src/engine/assets/model/builders/SceneBuilder.hpp index a0a03c8..75829ef 100644 --- a/src/engine/assets/model/builders/SceneBuilder.hpp +++ b/src/engine/assets/model/builders/SceneBuilder.hpp @@ -4,14 +4,10 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include #include #include -#pragma GCC diagnostic pop #include #include diff --git a/src/engine/assets/model/builders/loadObj.cpp b/src/engine/assets/model/builders/loadObj.cpp index 4d00026..cc271fa 100644 --- a/src/engine/assets/model/builders/loadObj.cpp +++ b/src/engine/assets/model/builders/loadObj.cpp @@ -2,11 +2,7 @@ // Created by kj16609 on 5/18/24. // -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include #include diff --git a/src/engine/assets/stores.hpp b/src/engine/assets/stores.hpp index 6530b24..6363f80 100644 --- a/src/engine/assets/stores.hpp +++ b/src/engine/assets/stores.hpp @@ -10,7 +10,7 @@ namespace fgl::engine { class Texture; - using TextureStore = AssetStore< Texture>; + using TextureStore = AssetStore< Texture >; TextureStore& getTextureStore(); diff --git a/src/engine/assets/texture/Texture.cpp b/src/engine/assets/texture/Texture.cpp index 870981b..d1024ec 100644 --- a/src/engine/assets/texture/Texture.cpp +++ b/src/engine/assets/texture/Texture.cpp @@ -10,15 +10,9 @@ #include "engine/debug/logging/logging.hpp" #include "engine/descriptors/DescriptorSet.hpp" #include "engine/math/noise/perlin/generator.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wconversion" #include "engine/utility/IDPool.hpp" #include "imgui/backends/imgui_impl_vulkan.h" #include "objectloaders/stb_image.h" -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/camera/RenderCamera.hpp b/src/engine/camera/RenderCamera.hpp index c062291..3bb0971 100644 --- a/src/engine/camera/RenderCamera.hpp +++ b/src/engine/camera/RenderCamera.hpp @@ -4,21 +4,15 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include #include -#pragma GCC diagnostic pop #include "CameraViewpoint.hpp" #include "CompositeSwapchain.hpp" #include "GBufferSwapchain.hpp" #include "debug/Track.hpp" #include "engine/descriptors/DescriptorSet.hpp" -#include "engine/memory/buffers/HostSingleT.hpp" -#include "engine/memory/buffers/UniqueFrameSuballocation.hpp" #include "engine/primitives/Frustum.hpp" #include "engine/rendering/types.hpp" diff --git a/src/engine/concepts/is_bindable.hpp b/src/engine/concepts/is_bindable.hpp index 7ef851c..87bd8dd 100644 --- a/src/engine/concepts/is_bindable.hpp +++ b/src/engine/concepts/is_bindable.hpp @@ -10,16 +10,12 @@ namespace fgl::engine { template < typename T > concept is_bindable_buffer = requires( T t ) { - { - t.descriptorInfo() - } -> std::same_as< vk::DescriptorBufferInfo >; + { t.descriptorInfo() } -> std::same_as< vk::DescriptorBufferInfo >; }; template < typename T > concept is_bindable_image = requires( T t ) { - { - t.descriptorInfo() - } -> std::same_as< vk::DescriptorImageInfo >; + { t.descriptorInfo() } -> std::same_as< vk::DescriptorImageInfo >; }; template < typename T > concept is_bindable = is_bindable_image< T > || is_bindable_buffer< T >; diff --git a/src/engine/concepts/is_constant_range.hpp b/src/engine/concepts/is_constant_range.hpp index 1736ebc..fee0c35 100644 --- a/src/engine/concepts/is_constant_range.hpp +++ b/src/engine/concepts/is_constant_range.hpp @@ -10,8 +10,6 @@ namespace fgl::engine { template < typename T > concept is_constant_range = requires( T t ) { - { - t.m_range - } -> std::same_as< const vk::PushConstantRange& >; + { t.m_range } -> std::same_as< const vk::PushConstantRange& >; }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/concepts/is_image.hpp b/src/engine/concepts/is_image.hpp index 2abd3eb..6197b88 100644 --- a/src/engine/concepts/is_image.hpp +++ b/src/engine/concepts/is_image.hpp @@ -9,15 +9,9 @@ namespace fgl::engine template < typename T > concept is_image = requires( T a ) { - { - a.getVkImage() - } -> std::same_as< vk::Image& >; - { - a.format() - } -> std::same_as< vk::Format >; - { - a.extent() - } -> std::same_as< vk::Extent2D >; + { a.getVkImage() } -> std::same_as< vk::Image& >; + { a.format() } -> std::same_as< vk::Format >; + { a.extent() } -> std::same_as< vk::Extent2D >; }; -} \ No newline at end of file +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/constants.hpp b/src/engine/constants.hpp index 74883dd..18ea7e9 100644 --- a/src/engine/constants.hpp +++ b/src/engine/constants.hpp @@ -4,11 +4,8 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include -#pragma GCC diagnostic pop #include "types.hpp" diff --git a/src/engine/debug/logging/formatters/glm.cpp b/src/engine/debug/logging/formatters/glm.cpp index 91bbe85..64b4ee1 100644 --- a/src/engine/debug/logging/formatters/glm.cpp +++ b/src/engine/debug/logging/formatters/glm.cpp @@ -4,12 +4,8 @@ #include "glm.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include -#pragma GCC diagnostic pop std::format_context::iterator std::formatter< glm::qua< float > >::format( const glm::quat& quat, format_context& ctx ) const diff --git a/src/engine/debug/logging/formatters/matrix.cpp b/src/engine/debug/logging/formatters/matrix.cpp index 9e43611..4c4044e 100644 --- a/src/engine/debug/logging/formatters/matrix.cpp +++ b/src/engine/debug/logging/formatters/matrix.cpp @@ -4,11 +4,7 @@ #include "matrix.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include -#pragma GCC diagnostic pop std::format_context::iterator std::formatter< glm::vec4 >::format( const glm::vec4& vec, format_context& ctx ) const { diff --git a/src/engine/debug/logging/logging.hpp b/src/engine/debug/logging/logging.hpp index c0ac1e4..69c5142 100644 --- a/src/engine/debug/logging/logging.hpp +++ b/src/engine/debug/logging/logging.hpp @@ -4,17 +4,11 @@ #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" -#pragma GCC diagnostic ignored "-Wnoexcept" #include -#pragma GCC diagnostic pop #include "formatters/filesystem.hpp" -#include "formatters/matrix.hpp" #include "formatters/glm.hpp" +#include "formatters/matrix.hpp" namespace fgl::engine::log { diff --git a/src/engine/debug/timing/FlameGraph.cpp b/src/engine/debug/timing/FlameGraph.cpp index 533a548..8c574e4 100644 --- a/src/engine/debug/timing/FlameGraph.cpp +++ b/src/engine/debug/timing/FlameGraph.cpp @@ -5,12 +5,7 @@ #include "FlameGraph.hpp" #include - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include "engine/FGL_DEFINES.hpp" #include "engine/clock.hpp" @@ -30,9 +25,9 @@ namespace fgl::engine::debug using Duration = ProfilingClock::duration; - Duration getDuration() const { return m_end - m_start; } + [[nodiscard]] Duration getDuration() const { return m_end - m_start; } - Duration getTotalTime() const + [[nodiscard]] Duration getTotalTime() const { if ( m_parent != nullptr ) return m_parent->getTotalTime(); diff --git a/src/engine/descriptors/DescriptorPool.hpp b/src/engine/descriptors/DescriptorPool.hpp index 0b9ed0a..44cc6cb 100644 --- a/src/engine/descriptors/DescriptorPool.hpp +++ b/src/engine/descriptors/DescriptorPool.hpp @@ -17,7 +17,6 @@ namespace fgl::engine namespace fgl::engine::descriptors { - class DescriptorPool { vk::raii::DescriptorPool m_pool; diff --git a/src/engine/gameobjects/components/drawers.cpp b/src/engine/gameobjects/components/drawers.cpp index 0fdb8cb..43ed536 100644 --- a/src/engine/gameobjects/components/drawers.cpp +++ b/src/engine/gameobjects/components/drawers.cpp @@ -4,13 +4,9 @@ #include "drawers.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" #include #include "editor/src/gui/helpers.hpp" -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp b/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp index 5103ba8..ffa606b 100644 --- a/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp +++ b/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp @@ -4,11 +4,7 @@ #include "ComponentEditorInterface.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" #include -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/gameobjects/components/interface/GameObjectComponent.cpp b/src/engine/gameobjects/components/interface/GameObjectComponent.cpp index e43d94e..9432ef2 100644 --- a/src/engine/gameobjects/components/interface/GameObjectComponent.cpp +++ b/src/engine/gameobjects/components/interface/GameObjectComponent.cpp @@ -4,11 +4,7 @@ #include "GameObjectComponent.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" #include -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/lighting/lights/GlobalIlluminator.cpp b/src/engine/lighting/lights/GlobalIlluminator.cpp index 714e8a8..d2c7f69 100644 --- a/src/engine/lighting/lights/GlobalIlluminator.cpp +++ b/src/engine/lighting/lights/GlobalIlluminator.cpp @@ -3,7 +3,6 @@ // #include "GlobalIlluminator.hpp" - namespace fgl::engine::lights { diff --git a/src/engine/math/intersections/aabb/coordinate.cpp b/src/engine/math/intersections/aabb/coordinate.cpp index cbacfb6..658d3c9 100644 --- a/src/engine/math/intersections/aabb/coordinate.cpp +++ b/src/engine/math/intersections/aabb/coordinate.cpp @@ -20,8 +20,6 @@ namespace fgl::engine::intersections return top_in_range && bottom_in_range; } - - template bool contains< CS::World >( const AxisAlignedBoundingBox< CS::World >&, const Coordinate< CS::World >& ); } // namespace fgl::engine::intersections diff --git a/src/engine/math/noise/perlin/generator.cpp b/src/engine/math/noise/perlin/generator.cpp index b012f56..1a84918 100644 --- a/src/engine/math/noise/perlin/generator.cpp +++ b/src/engine/math/noise/perlin/generator.cpp @@ -4,12 +4,7 @@ #include "generator.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop - - #include #include diff --git a/src/engine/math/noise/perlin/generator.hpp b/src/engine/math/noise/perlin/generator.hpp index b4ac981..c8f25d7 100644 --- a/src/engine/math/noise/perlin/generator.hpp +++ b/src/engine/math/noise/perlin/generator.hpp @@ -4,10 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include diff --git a/src/engine/memory/DefferedCleanup.hpp b/src/engine/memory/DefferedCleanup.hpp index 81c9a82..30eef0b 100644 --- a/src/engine/memory/DefferedCleanup.hpp +++ b/src/engine/memory/DefferedCleanup.hpp @@ -6,6 +6,7 @@ namespace fgl::engine::memory { - void deferredDelete( auto&& item ) {} + void deferredDelete( auto&& item ) + {} -} +} // namespace fgl::engine::memory diff --git a/src/engine/memory/buffers/HostSingleT.hpp b/src/engine/memory/buffers/HostSingleT.hpp index d401f81..4177aab 100644 --- a/src/engine/memory/buffers/HostSingleT.hpp +++ b/src/engine/memory/buffers/HostSingleT.hpp @@ -26,7 +26,8 @@ namespace fgl::engine HostSingleT( HostSingleT&& ) = delete; HostSingleT& operator=( const HostSingleT& ) = delete; - HostSingleT( const memory::Buffer& buffer ) : memory::BufferSuballocation( buffer, sizeof( T ), alignof( T ) ) {} + HostSingleT( const memory::Buffer& buffer ) : memory::BufferSuballocation( buffer, sizeof( T ), alignof( T ) ) + {} HostSingleT& operator=( T& t ) { diff --git a/src/engine/primitives/Scale.hpp b/src/engine/primitives/Scale.hpp index ee1556d..bf9ad20 100644 --- a/src/engine/primitives/Scale.hpp +++ b/src/engine/primitives/Scale.hpp @@ -4,10 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include diff --git a/src/engine/primitives/boxes/concepts.hpp b/src/engine/primitives/boxes/concepts.hpp index 9d0a8b6..7736d68 100644 --- a/src/engine/primitives/boxes/concepts.hpp +++ b/src/engine/primitives/boxes/concepts.hpp @@ -17,29 +17,17 @@ namespace fgl::engine template < typename T > concept has_space_type = requires( const T t ) { - { - T::SpaceType - } -> std::same_as< CoordinateSpace >; + { T::SpaceType } -> std::same_as< CoordinateSpace >; }; template < typename T > concept is_bounding_box = requires( const T t ) { requires has_space_type< T >; - { - t.right() - } -> is_normal_vector; - { - t.up() - } -> is_normal_vector; - { - t.forward() - } -> is_normal_vector; - { - t.topLeftForward() - } -> is_coordinate; - { - t.bottomLeftBack() - } -> is_coordinate; + { t.right() } -> is_normal_vector; + { t.up() } -> is_normal_vector; + { t.forward() } -> is_normal_vector; + { t.topLeftForward() } -> is_coordinate; + { t.bottomLeftBack() } -> is_coordinate; }; } // namespace fgl::engine diff --git a/src/engine/primitives/lines/LineBase.cpp b/src/engine/primitives/lines/LineBase.cpp index 89d64fe..b02ada0 100644 --- a/src/engine/primitives/lines/LineBase.cpp +++ b/src/engine/primitives/lines/LineBase.cpp @@ -4,10 +4,7 @@ #include "LineBase.hpp" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic push namespace fgl::engine { diff --git a/src/engine/primitives/lines/LineBase.hpp b/src/engine/primitives/lines/LineBase.hpp index b52e5bb..ed6c195 100644 --- a/src/engine/primitives/lines/LineBase.hpp +++ b/src/engine/primitives/lines/LineBase.hpp @@ -4,10 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/primitives/matricies/Matrix.hpp b/src/engine/primitives/matricies/Matrix.hpp index f738fc9..e29e7f6 100644 --- a/src/engine/primitives/matricies/Matrix.hpp +++ b/src/engine/primitives/matricies/Matrix.hpp @@ -4,12 +4,9 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include #include -#pragma GCC diagnostic pop #include "MatrixEvolvedTypes.hpp" diff --git a/src/engine/primitives/matricies/MatrixEvolvedTypes.hpp b/src/engine/primitives/matricies/MatrixEvolvedTypes.hpp index d2c342c..d7da732 100644 --- a/src/engine/primitives/matricies/MatrixEvolvedTypes.hpp +++ b/src/engine/primitives/matricies/MatrixEvolvedTypes.hpp @@ -82,9 +82,7 @@ namespace fgl::engine //! Checks if CType can be evolved by MType. (The input type must match the input matrix type) template < CoordinateSpace CType, MatrixType MType > concept can_be_evolved = requires() { - { - DevolvedType< MType >() == CType - }; + { DevolvedType< MType >() == CType }; }; } // namespace fgl::engine diff --git a/src/engine/primitives/matricies/RotationMatrix.hpp b/src/engine/primitives/matricies/RotationMatrix.hpp index b9c5184..c14a5d9 100644 --- a/src/engine/primitives/matricies/RotationMatrix.hpp +++ b/src/engine/primitives/matricies/RotationMatrix.hpp @@ -4,10 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/primitives/matricies/mult_operators.cpp b/src/engine/primitives/matricies/mult_operators.cpp index 33dc9e4..cb3771e 100644 --- a/src/engine/primitives/matricies/mult_operators.cpp +++ b/src/engine/primitives/matricies/mult_operators.cpp @@ -2,10 +2,7 @@ // Created by kj16609 on 2/28/24. // -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include "RotationMatrix.hpp" #include "engine/primitives/vectors/NormalVector.hpp" @@ -24,6 +21,4 @@ namespace fgl::engine return Vector( static_cast< glm::mat3 >( rot_mat ) * vec.vec() ); } - - } // namespace fgl::engine diff --git a/src/engine/primitives/planes/concepts.hpp b/src/engine/primitives/planes/concepts.hpp index d5d32ab..6bb315d 100644 --- a/src/engine/primitives/planes/concepts.hpp +++ b/src/engine/primitives/planes/concepts.hpp @@ -21,24 +21,12 @@ namespace fgl::engine template < typename T > concept is_plane = requires( T t ) { - { - T::SpaceType - } -> std::same_as< const CoordinateSpace& >; - { - t.distance() - } -> std::same_as< float >; - { - t.getPosition() - } -> is_coordinate; - { - t.getDirection() - } -> is_normal_vector; - { - t.isForward( std::declval< Coordinate< T::SpaceType > >() ) - } -> std::same_as< bool >; - { - t.mapToPlane( std::declval< Coordinate< T::SpaceType > >() ) - } -> is_coordinate; + { T::SpaceType } -> std::same_as< const CoordinateSpace& >; + { t.distance() } -> std::same_as< float >; + { t.getPosition() } -> is_coordinate; + { t.getDirection() } -> is_normal_vector; + { t.isForward( std::declval< Coordinate< T::SpaceType > >() ) } -> std::same_as< bool >; + { t.mapToPlane( std::declval< Coordinate< T::SpaceType > >() ) } -> is_coordinate; }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/primitives/points/Coordinate.hpp b/src/engine/primitives/points/Coordinate.hpp index 4ff6dee..f9da326 100644 --- a/src/engine/primitives/points/Coordinate.hpp +++ b/src/engine/primitives/points/Coordinate.hpp @@ -4,11 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include -#pragma GCC diagnostic pop #include "engine/constants.hpp" #include "engine/primitives/CoordinateSpace.hpp" diff --git a/src/engine/primitives/points/concepts.hpp b/src/engine/primitives/points/concepts.hpp index b1929ca..794e20f 100644 --- a/src/engine/primitives/points/concepts.hpp +++ b/src/engine/primitives/points/concepts.hpp @@ -11,15 +11,9 @@ namespace fgl::engine template < typename T > concept is_coordinate = requires( T t ) { requires std::is_base_of_v< glm::vec3, T >; - { - t.up() - } -> std::same_as< float& >; - { - t.right() - } -> std::same_as< float& >; - { - t.forward() - } -> std::same_as< float& >; + { t.up() } -> std::same_as< float& >; + { t.right() } -> std::same_as< float& >; + { t.forward() } -> std::same_as< float& >; }; -} +} // namespace fgl::engine diff --git a/src/engine/primitives/rotation/EulerRotation.hpp b/src/engine/primitives/rotation/EulerRotation.hpp index f6c4378..0e797fc 100644 --- a/src/engine/primitives/rotation/EulerRotation.hpp +++ b/src/engine/primitives/rotation/EulerRotation.hpp @@ -3,12 +3,8 @@ // #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#include "glm/vec3.hpp" -#pragma GCC diagnostic pop - #include "QuatRotation.hpp" +#include "glm/vec3.hpp" namespace fgl::engine { diff --git a/src/engine/primitives/rotation/QuatRotation.cpp b/src/engine/primitives/rotation/QuatRotation.cpp index 3fe30da..93667cf 100644 --- a/src/engine/primitives/rotation/QuatRotation.cpp +++ b/src/engine/primitives/rotation/QuatRotation.cpp @@ -13,7 +13,6 @@ namespace fgl::engine { - QuatRotation::QuatRotation() : QuatRotation( 0.0f ) {} @@ -44,7 +43,8 @@ namespace fgl::engine return glm::normalize( q ); } - QuatRotation::QuatRotation( const float x_i, const float y_i, const float z_i ) : glm::quat( toQuat( x_i, y_i, z_i ) ) + QuatRotation::QuatRotation( const float x_i, const float y_i, const float z_i ) : + glm::quat( toQuat( x_i, y_i, z_i ) ) {} QuatRotation::QuatRotation( const float value ) : QuatRotation( value, value, value ) diff --git a/src/engine/primitives/rotation/QuatRotation.hpp b/src/engine/primitives/rotation/QuatRotation.hpp index 13f09cc..09eb60a 100644 --- a/src/engine/primitives/rotation/QuatRotation.hpp +++ b/src/engine/primitives/rotation/QuatRotation.hpp @@ -4,12 +4,8 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wduplicated-branches" #include #include -#pragma GCC diagnostic pop #define GLM_ENABLE_EXPERIMENTAL #include diff --git a/src/engine/primitives/vectors/NormalVector.hpp b/src/engine/primitives/vectors/NormalVector.hpp index 10a72b1..658bbc6 100644 --- a/src/engine/primitives/vectors/NormalVector.hpp +++ b/src/engine/primitives/vectors/NormalVector.hpp @@ -4,11 +4,8 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include -#pragma GCC diagnostic pop #include "engine/primitives/CoordinateSpace.hpp" diff --git a/src/engine/primitives/vectors/Vector.hpp b/src/engine/primitives/vectors/Vector.hpp index ccc1db6..dabc071 100644 --- a/src/engine/primitives/vectors/Vector.hpp +++ b/src/engine/primitives/vectors/Vector.hpp @@ -4,10 +4,7 @@ #pragma once -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop #include "engine/FGL_DEFINES.hpp" #include "engine/constants.hpp" diff --git a/src/engine/rendering/devices/Device.hpp b/src/engine/rendering/devices/Device.hpp index ddf78f6..5e5c9f2 100644 --- a/src/engine/rendering/devices/Device.hpp +++ b/src/engine/rendering/devices/Device.hpp @@ -104,6 +104,7 @@ namespace fgl::engine vk::PhysicalDeviceProperties m_properties; vk::CommandPoolCreateInfo commandPoolInfo(); + CommandBufferPool& getCmdBufferPool() { return m_command_pool; } Device( Window&, Instance& ); diff --git a/src/engine/rendering/pipelines/Attachment.hpp b/src/engine/rendering/pipelines/Attachment.hpp index 0a65bdc..8097ec9 100644 --- a/src/engine/rendering/pipelines/Attachment.hpp +++ b/src/engine/rendering/pipelines/Attachment.hpp @@ -117,7 +117,7 @@ namespace fgl::engine usage | vk::ImageUsageFlagBits::eInputAttachment | extra_flags, vk::ImageLayout::eUndefined, final_layout ) ) }; - image_views.emplace_back( itter->getView( ) ); + image_views.emplace_back( itter->getView() ); } } @@ -134,7 +134,7 @@ namespace fgl::engine for ( std::uint32_t i = 0; i < count; ++i ) { m_attachment_resources.m_images.emplace_back( image ); - m_attachment_resources.m_image_views.emplace_back( image->getView( ) ); + m_attachment_resources.m_image_views.emplace_back( image->getView() ); } } diff --git a/src/engine/rendering/pipelines/shaders/Compiler.cpp b/src/engine/rendering/pipelines/shaders/Compiler.cpp index 91155fa..32684b3 100644 --- a/src/engine/rendering/pipelines/shaders/Compiler.cpp +++ b/src/engine/rendering/pipelines/shaders/Compiler.cpp @@ -6,19 +6,9 @@ #include #include -#include - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wuseless-cast" -#pragma GCC diagnostic ignored "-Wredundant-tags" -#pragma GCC diagnostic ignored "-Wcast-qual" -#pragma GCC diagnostic ignored "-Weffc++" #include #include -#pragma GCC diagnostic pop +#include #include "engine/FGL_DEFINES.hpp" #include "engine/constants.hpp" diff --git a/src/engine/rendering/renderpass/Subpass.hpp b/src/engine/rendering/renderpass/Subpass.hpp index 7511996..51aad44 100644 --- a/src/engine/rendering/renderpass/Subpass.hpp +++ b/src/engine/rendering/renderpass/Subpass.hpp @@ -17,9 +17,7 @@ namespace fgl::engine template < typename T > concept is_subpass = requires( T a ) { - { - a.description() - } -> std::same_as< vk::SubpassDescription >; + { a.description() } -> std::same_as< vk::SubpassDescription >; }; template < typename T > diff --git a/src/engine/systems/concepts.hpp b/src/engine/systems/concepts.hpp index 7730164..b9d0ade 100644 --- a/src/engine/systems/concepts.hpp +++ b/src/engine/systems/concepts.hpp @@ -14,23 +14,15 @@ namespace fgl::engine template < typename T > concept is_system = requires( T t, FrameInfo info ) { - { - t.pass( info ) - }; + { t.pass( info ) }; }; template < typename T > concept is_threaded_system = requires( T t, FrameInfo info ) { requires is_system< T >; - { - t.startPass( info ) - }; - { - t.wait() - }; - { - t.setupSystem( info ) - } -> std::same_as< vk::raii::CommandBuffer& >; + { t.startPass( info ) }; + { t.wait() }; + { t.setupSystem( info ) } -> std::same_as< vk::raii::CommandBuffer& >; }; } // namespace fgl::engine -- 2.49.1 From 082d1e8c88c56d29e25af4953f8b02cd308afac7 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sun, 28 Sep 2025 14:13:51 -0400 Subject: [PATCH 10/22] Bump dependencies --- dependencies/SPIRV-Headers | 2 +- dependencies/SPIRV-Tools | 2 +- dependencies/catch2 | 1 - dependencies/glslang | 2 +- dependencies/imgui | 2 +- dependencies/shaderc | 2 +- dependencies/slang | 2 +- dependencies/spdlog | 2 +- dependencies/vma | 2 +- 9 files changed, 8 insertions(+), 9 deletions(-) delete mode 160000 dependencies/catch2 diff --git a/dependencies/SPIRV-Headers b/dependencies/SPIRV-Headers index f013f08..2a611a9 160000 --- a/dependencies/SPIRV-Headers +++ b/dependencies/SPIRV-Headers @@ -1 +1 @@ -Subproject commit f013f08e4455bcc1f0eed8e3dd5e2009682656d9 +Subproject commit 2a611a970fdbc41ac2e3e328802aed9985352dca diff --git a/dependencies/SPIRV-Tools b/dependencies/SPIRV-Tools index 246daf2..33e0256 160000 --- a/dependencies/SPIRV-Tools +++ b/dependencies/SPIRV-Tools @@ -1 +1 @@ -Subproject commit 246daf246bb17336afcf4482680bba434b1e5557 +Subproject commit 33e02568181e3312f49a3cf33df470bf96ef293a diff --git a/dependencies/catch2 b/dependencies/catch2 deleted file mode 160000 index 05e10df..0000000 --- a/dependencies/catch2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 05e10dfccc28c7f973727c54f850237d07d5e10f diff --git a/dependencies/glslang b/dependencies/glslang index e40c14a..8a85691 160000 --- a/dependencies/glslang +++ b/dependencies/glslang @@ -1 +1 @@ -Subproject commit e40c14a3e007fac0e4f2e4164fdf14d1712355bd +Subproject commit 8a85691a0740d390761a1008b4696f57facd02c4 diff --git a/dependencies/imgui b/dependencies/imgui index b4c9635..62275e8 160000 --- a/dependencies/imgui +++ b/dependencies/imgui @@ -1 +1 @@ -Subproject commit b4c96355c9b51b54c4deb52e7d7cdfc7bf79bc2f +Subproject commit 62275e877a691bd2e51d1ca86bdfed49fa5cb297 diff --git a/dependencies/shaderc b/dependencies/shaderc index ff84893..7374358 160000 --- a/dependencies/shaderc +++ b/dependencies/shaderc @@ -1 +1 @@ -Subproject commit ff84893dd52d28f0b1737d2635733d952013bd9c +Subproject commit 73743588fe9c39f2f1c780a087d94afac691a189 diff --git a/dependencies/slang b/dependencies/slang index 206f6cf..f55f669 160000 --- a/dependencies/slang +++ b/dependencies/slang @@ -1 +1 @@ -Subproject commit 206f6cf5657177dfec9113d1f1b88b685eb2b75a +Subproject commit f55f669d1badc94eb4eabf77a22a5994acca7a89 diff --git a/dependencies/spdlog b/dependencies/spdlog index 27cb4c7..6fa3601 160000 --- a/dependencies/spdlog +++ b/dependencies/spdlog @@ -1 +1 @@ -Subproject commit 27cb4c76708608465c413f6d0e6b8d99a4d84302 +Subproject commit 6fa36017cfd5731d617e1a934f0e5ea9c4445b13 diff --git a/dependencies/vma b/dependencies/vma index 009ecd1..1d8f600 160000 --- a/dependencies/vma +++ b/dependencies/vma @@ -1 +1 @@ -Subproject commit 009ecd192c1289c7529bff248a16cfe896254816 +Subproject commit 1d8f600fd424278486eade7ed3e877c99f0846b1 -- 2.49.1 From 2a5a526b07f27495a03784b6d89e81471156641c Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 29 Sep 2025 05:30:22 -0400 Subject: [PATCH 11/22] Cleanup more warnings and bad code --- CMakeLists.txt | 4 - cmake_modules/dependencies/catch2.cmake | 1 - src/CMakeLists.txt | 1 - .../src/components/TransformComponent.cpp | 2 +- src/editor/src/gui/EditorGuiContext.cpp | 11 +- src/editor/src/gui/core.cpp | 12 +- src/engine/CMakeLists.txt | 41 +++--- src/engine/EngineContext.cpp | 5 +- src/engine/assets/image/Image.cpp | 90 +------------ src/engine/assets/material/Material.cpp | 2 +- src/engine/assets/material/Material.hpp | 38 ++---- src/engine/assets/model/Model.cpp | 8 +- src/engine/assets/model/ModelVertex.cpp | 5 +- src/engine/assets/model/Primitive.cpp | 12 +- src/engine/assets/model/Primitive.hpp | 22 +++- src/engine/assets/model/SimpleVertex.cpp | 6 + src/engine/assets/model/SimpleVertex.hpp | 4 +- .../assets/model/builders/ModelBuilder.cpp | 2 +- .../assets/model/builders/SceneBuilder.cpp | 52 ++++---- .../assets/model/builders/SceneBuilder.hpp | 5 - src/engine/assets/model/builders/loadObj.cpp | 41 +++--- .../model/builders/mikktspace/mikktspace.cpp | 13 +- src/engine/assets/texture/Texture.cpp | 18 ++- src/engine/assets/transfer/TransferData.hpp | 2 +- .../assets/transfer/TransferManager.cpp | 10 +- .../assets/transfer/TransferManager.hpp | 2 +- src/engine/camera/CameraViewpoint.cpp | 3 +- src/engine/camera/RenderCamera.hpp | 4 - src/engine/camera/ShadowMap.cpp | 4 +- src/engine/camera/ShadowMap.hpp | 2 +- src/engine/camera/Swapchain.cpp | 1 - src/engine/debug/logging/formatters/glm.cpp | 4 + src/engine/debug/timing/FlameGraph.cpp | 5 + src/engine/descriptors/DescriptorSet.cpp | 121 ++++++++--------- src/engine/descriptors/DescriptorSet.hpp | 10 +- src/engine/filesystem/types.hpp | 4 +- .../components/TransformComponent.hpp | 2 +- src/engine/gameobjects/components/drawers.cpp | 4 + .../interface/ComponentEditorInterface.cpp | 2 - src/engine/lighting/lights/Sun.cpp | 2 +- src/engine/math/raycast/raycast.hpp | 1 - src/engine/memory/buffers/BufferHandle.cpp | 6 +- src/engine/memory/buffers/BufferHandle.hpp | 11 +- .../memory/buffers/BufferSuballocation.hpp | 2 +- .../buffers/BufferSuballocationHandle.cpp | 2 +- .../buffers/BufferSuballocationHandle.hpp | 1 + src/engine/memory/buffers/HostSingleT.hpp | 2 +- .../memory/buffers/SuballocationView.cpp | 29 +++-- .../memory/buffers/SuballocationView.hpp | 14 +- src/engine/primitives/matricies/Matrix.hpp | 2 - .../primitives/rotation/QuatRotation.cpp | 15 +++ .../primitives/rotation/QuatRotation.hpp | 21 ++- .../primitives/rotation/UniversalRotation.cpp | 46 ++++++- .../primitives/rotation/UniversalRotation.hpp | 56 +++----- src/engine/rendering/PresentSwapChain.hpp | 2 +- src/engine/rendering/Renderer.cpp | 2 +- src/engine/rendering/devices/Device.hpp | 6 +- .../rendering/pipelines/shaders/Compiler.cpp | 13 +- .../pipelines/v2/PipelineBuilder.cpp | 23 ++-- .../pipelines/v2/PipelineBuilder.hpp | 10 +- src/engine/rendering/types.hpp | 6 +- .../systems/render/EntityRendererSystem.hpp | 4 +- src/engine/systems/render/LineDrawer.cpp | 2 +- src/engine/systems/render/ShadowRenderer.cpp | 34 ----- src/engine/systems/render/ShadowRenderer.hpp | 30 ----- src/objectloaders/CMakeLists.txt | 2 +- src/objectloaders/{ => include}/stb_image.h | 0 .../{ => include}/stb_image_write.h | 0 src/objectloaders/{ => include}/tiny_gltf.h | 2 + .../{ => include}/tiny_obj_loader.h | 6 +- src/objectloaders/{ => src}/gltf_impl.cpp | 2 +- src/objectloaders/{ => src}/json.hpp | 2 +- src/objectloaders/{ => src}/obj_impl.cpp | 2 +- src/tests/CMakeLists.txt | 25 ---- src/tests/src/gtest_printers.hpp | 122 ------------------ 75 files changed, 448 insertions(+), 632 deletions(-) delete mode 100644 cmake_modules/dependencies/catch2.cmake delete mode 100644 src/engine/systems/render/ShadowRenderer.cpp delete mode 100644 src/engine/systems/render/ShadowRenderer.hpp rename src/objectloaders/{ => include}/stb_image.h (100%) rename src/objectloaders/{ => include}/stb_image_write.h (100%) rename src/objectloaders/{ => include}/tiny_gltf.h (99%) rename src/objectloaders/{ => include}/tiny_obj_loader.h (99%) rename src/objectloaders/{ => src}/gltf_impl.cpp (96%) rename src/objectloaders/{ => src}/json.hpp (99%) rename src/objectloaders/{ => src}/obj_impl.cpp (90%) delete mode 100644 src/tests/CMakeLists.txt delete mode 100644 src/tests/src/gtest_printers.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 880a7d4..4ab8811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,6 @@ add_subdirectory(dependencies/libFGL) PreSetup() -#file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/data) - -#Enable cmake_modules list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") message("-- CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") @@ -22,7 +19,6 @@ include(dependencies/glfw) include(dependencies/glm) include(cmake_modules/dependencies/tracy.cmake) include(dependencies/vulkan) -include(dependencies/catch2) include(dependencies/slang) include(dependencies/json) diff --git a/cmake_modules/dependencies/catch2.cmake b/cmake_modules/dependencies/catch2.cmake deleted file mode 100644 index cea8d3c..0000000 --- a/cmake_modules/dependencies/catch2.cmake +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/catch2) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ccaf9fe..1a61ef0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,6 @@ add_subdirectory(vma) add_subdirectory(engine) add_subdirectory(objectloaders) add_subdirectory(editor) -add_subdirectory(tests) 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/src/components/TransformComponent.cpp b/src/editor/src/components/TransformComponent.cpp index e9ca237..874f200 100644 --- a/src/editor/src/components/TransformComponent.cpp +++ b/src/editor/src/components/TransformComponent.cpp @@ -28,7 +28,7 @@ namespace fgl::engine::components } } - TransformComponent::TransformComponent() + TransformComponent::TransformComponent() : m_transform() {} TransformComponent::TransformComponent( const WorldTransform& transform ) : m_transform( transform ) diff --git a/src/editor/src/gui/EditorGuiContext.cpp b/src/editor/src/gui/EditorGuiContext.cpp index 84930da..39fbbc0 100644 --- a/src/editor/src/gui/EditorGuiContext.cpp +++ b/src/editor/src/gui/EditorGuiContext.cpp @@ -7,6 +7,7 @@ #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wuseless-cast" #include #include @@ -50,26 +51,28 @@ namespace fgl::editor ImGui_ImplGlfw_InitForVulkan( window.window(), true ); ImGui_ImplVulkan_InitInfo init_info { + .ApiVersion = VK_API_VERSION_1_4, .Instance = device.instance(), .PhysicalDevice = *device.phyDevice().handle(), .Device = *device, .QueueFamily = device.phyDevice().queueInfo().getIndex( vk::QueueFlagBits::eGraphics ), .Queue = *device.graphicsQueue(), .DescriptorPool = *DescriptorPool::getInstance().getPool(), - .RenderPass = VK_NULL_HANDLE, + .DescriptorPoolSize = 0, .MinImageCount = 2, .ImageCount = 2, - .MSAASamples = VK_SAMPLE_COUNT_1_BIT, - .PipelineCache = VK_NULL_HANDLE, + .RenderPass = VK_NULL_HANDLE, .Subpass = 0, + .MSAASamples = VK_SAMPLE_COUNT_1_BIT, .UseDynamicRendering = VK_TRUE, .PipelineRenderingCreateInfo = pipeline_info, .Allocator = VK_NULL_HANDLE, .CheckVkResultFn = VK_NULL_HANDLE, - .MinAllocationSize = 1024 * 1024 + .MinAllocationSize = 1024 * 1024, + }; ImGui_ImplVulkan_Init( &init_info ); diff --git a/src/editor/src/gui/core.cpp b/src/editor/src/gui/core.cpp index b077399..42ba12a 100644 --- a/src/editor/src/gui/core.cpp +++ b/src/editor/src/gui/core.cpp @@ -8,6 +8,7 @@ #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wuseless-cast" #include // Included for DockBuilder since it's not exposed yet #pragma GCC diagnostic pop @@ -15,7 +16,6 @@ #include "FileBrowser.hpp" #include "engine/assets/model/Model.hpp" #include "engine/debug/DEBUG_NAMES.hpp" -#include "engine/descriptors/DescriptorPool.hpp" #include "engine/rendering/Renderer.hpp" #include "gui_window_names.hpp" #include "safe_include.hpp" @@ -96,9 +96,9 @@ namespace fgl::engine::gui // ImGui::PopStyleVar(); } - static std::weak_ptr< GameObject > selected_object {}; + static std::weak_ptr< GameObject > SELECTED_OBJECT {}; - void itterateGameObjectNode( FrameInfo& info, OctTreeNode& node ) + void itterateGameObjectNode( [[maybe_unused]] FrameInfo& info, [[maybe_unused]] OctTreeNode& node ) { /* if ( node.isLeaf() ) @@ -161,7 +161,7 @@ namespace fgl::engine::gui if ( ImGui::Selectable( object->getName().c_str() ) ) { - selected_object = object; + SELECTED_OBJECT = object; } ImGui::PopID(); @@ -194,13 +194,13 @@ namespace fgl::engine::gui ZoneScoped; ImGui::Begin( ENTITY_INFO_NAME ); - if ( selected_object.expired() ) + if ( SELECTED_OBJECT.expired() ) { ImGui::End(); return; } - const auto object { selected_object.lock() }; + const auto object { SELECTED_OBJECT.lock() }; drawObject( *object ); drawComponentsList( *object ); diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 5b8eefa..05220e9 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -1,6 +1,6 @@ file(GLOB_RECURSE CPP_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/**.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/**.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/**.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/**.hpp" ) AddFGLLibrary(FGLEngine STATIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -13,34 +13,45 @@ target_link_libraries(FGLEngine PUBLIC stdc++exp) include(dependencies/spdlog) include(dependencies/imgui) -target_link_libraries(FGLEngine PUBLIC Vulkan::Vulkan glm ImGui FGLLoader spdlog slang) +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_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") - set(FGL_ENABLE_IMGUI 1) + set(FGL_ENABLE_IMGUI 1) 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) + 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) + 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) - target_link_libraries(FGLEngine PUBLIC Catch2::Catch2) + target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=1) + target_compile_definitions(FGLEngine PUBLIC FGL_ENABLE_TEST_ASSERT=1) else () - target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=0) - target_compile_definitions(FGLEngine PUBLIC FGL_ENABLE_TEST_ASSERT=0) + target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=0) + target_compile_definitions(FGLEngine PUBLIC FGL_ENABLE_TEST_ASSERT=0) endif () # Enable tracking for buffers, I need to find some way to disable this when trying to link @@ -52,7 +63,7 @@ target_compile_definitions(FGLEngine PUBLIC TRACK_BUFFERS) target_compile_definitions(FGLEngine PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE) if (DEFINED FGL_ENABLE_CALIBRATED_PROFILING AND FGL_ENABLE_CALIBRATED_PROFILING) - target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=1) + target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=1) else () - target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=0) + target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=0) endif () diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index ed4ff41..fb5984b 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -31,7 +31,8 @@ namespace fgl::engine EngineContext::EngineContext() : m_ubo_buffer_pool( 1_MiB, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible ), m_delta_time( 0.0 ), - m_camera_manager() + m_camera_manager(), + m_sun( nullptr ) { ZoneScoped; using namespace fgl::literals::size_literals; @@ -44,8 +45,6 @@ namespace fgl::engine // memory::TransferManager::createInstance( device, 128_MiB ); } - static Average< float, 60 * 15 > rolling_ms_average; - void EngineContext::processInput() { auto timer = debug::timing::push( "Process Inputs" ); diff --git a/src/engine/assets/image/Image.cpp b/src/engine/assets/image/Image.cpp index 1262354..bb42a91 100644 --- a/src/engine/assets/image/Image.cpp +++ b/src/engine/assets/image/Image.cpp @@ -19,6 +19,9 @@ namespace fgl::engine return ptr; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-enum" + constexpr vk::AccessFlags getAccessFlags( const vk::ImageLayout layout ) { switch ( layout ) @@ -27,13 +30,8 @@ namespace fgl::engine FGL_UNREACHABLE(); case vk::ImageLayout::eUndefined: return vk::AccessFlagBits::eNone; - case vk::ImageLayout::eGeneral: - break; case vk::ImageLayout::eColorAttachmentOptimal: return vk::AccessFlagBits::eColorAttachmentRead | vk::AccessFlagBits::eColorAttachmentWrite; - break; - case vk::ImageLayout::eDepthStencilReadOnlyOptimal: - break; case vk::ImageLayout::eShaderReadOnlyOptimal: return vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eInputAttachmentRead; case vk::ImageLayout::eTransferSrcOptimal: @@ -42,50 +40,18 @@ namespace fgl::engine return vk::AccessFlagBits::eTransferWrite; case vk::ImageLayout::ePreinitialized: return vk::AccessFlagBits::eHostWrite; - case vk::ImageLayout::eDepthReadOnlyStencilAttachmentOptimal: - break; - case vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal: - break; - case vk::ImageLayout::eStencilAttachmentOptimal: - break; case vk::ImageLayout::eDepthStencilAttachmentOptimal: [[fallthrough]]; case vk::ImageLayout::eDepthReadOnlyOptimal: [[fallthrough]]; case vk::ImageLayout::eDepthAttachmentOptimal: return vk::AccessFlagBits::eDepthStencilAttachmentWrite; - case vk::ImageLayout::eStencilReadOnlyOptimal: - break; - case vk::ImageLayout::eReadOnlyOptimal: - break; - case vk::ImageLayout::eAttachmentOptimal: - break; case vk::ImageLayout::ePresentSrcKHR: return vk::AccessFlags( 0 ); - case vk::ImageLayout::eVideoDecodeDstKHR: - break; - case vk::ImageLayout::eVideoDecodeSrcKHR: - break; - case vk::ImageLayout::eVideoDecodeDpbKHR: - break; - case vk::ImageLayout::eSharedPresentKHR: - break; - case vk::ImageLayout::eFragmentDensityMapOptimalEXT: - break; case vk::ImageLayout::eFragmentShadingRateAttachmentOptimalKHR: return vk::AccessFlagBits::eFragmentShadingRateAttachmentReadKHR; case vk::ImageLayout::eRenderingLocalReadKHR: return vk::AccessFlagBits::eColorAttachmentWrite; - case vk::ImageLayout::eVideoEncodeDstKHR: - break; - case vk::ImageLayout::eVideoEncodeSrcKHR: - break; - case vk::ImageLayout::eVideoEncodeDpbKHR: - break; - case vk::ImageLayout::eAttachmentFeedbackLoopOptimalEXT: - break; - case vk::ImageLayout::eVideoEncodeQuantizationMapKHR: - break; } FGL_UNREACHABLE(); @@ -99,69 +65,23 @@ namespace fgl::engine FGL_UNREACHABLE(); case vk::ImageLayout::eUndefined: return vk::PipelineStageFlagBits::eTopOfPipe; - case vk::ImageLayout::eGeneral: - break; case vk::ImageLayout::eColorAttachmentOptimal: return vk::PipelineStageFlagBits::eColorAttachmentOutput; - case vk::ImageLayout::eDepthStencilAttachmentOptimal: - break; - case vk::ImageLayout::eDepthStencilReadOnlyOptimal: - break; case vk::ImageLayout::eShaderReadOnlyOptimal: return vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader; case vk::ImageLayout::eTransferSrcOptimal: [[fallthrough]]; case vk::ImageLayout::eTransferDstOptimal: return vk::PipelineStageFlagBits::eTransfer; - case vk::ImageLayout::ePreinitialized: - break; - case vk::ImageLayout::eDepthReadOnlyStencilAttachmentOptimal: - break; - case vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal: - break; - case vk::ImageLayout::eDepthAttachmentOptimal: - break; - case vk::ImageLayout::eDepthReadOnlyOptimal: - break; - case vk::ImageLayout::eStencilAttachmentOptimal: - break; - case vk::ImageLayout::eStencilReadOnlyOptimal: - break; - case vk::ImageLayout::eReadOnlyOptimal: - break; - case vk::ImageLayout::eAttachmentOptimal: - break; case vk::ImageLayout::ePresentSrcKHR: return vk::PipelineStageFlagBits::eBottomOfPipe; - case vk::ImageLayout::eVideoDecodeDstKHR: - break; - case vk::ImageLayout::eVideoDecodeSrcKHR: - break; - case vk::ImageLayout::eVideoDecodeDpbKHR: - break; - case vk::ImageLayout::eSharedPresentKHR: - break; - case vk::ImageLayout::eFragmentDensityMapOptimalEXT: - break; - case vk::ImageLayout::eFragmentShadingRateAttachmentOptimalKHR: - break; - case vk::ImageLayout::eRenderingLocalReadKHR: - break; - case vk::ImageLayout::eVideoEncodeDstKHR: - break; - case vk::ImageLayout::eVideoEncodeSrcKHR: - break; - case vk::ImageLayout::eVideoEncodeDpbKHR: - break; - case vk::ImageLayout::eAttachmentFeedbackLoopOptimalEXT: - break; - case vk::ImageLayout::eVideoEncodeQuantizationMapKHR: - break; } FGL_UNREACHABLE(); } +#pragma GCC diagnostic pop + vk::ImageMemoryBarrier Image::transitionTo( const vk::ImageLayout old_layout, const vk::ImageLayout new_layout, diff --git a/src/engine/assets/material/Material.cpp b/src/engine/assets/material/Material.cpp index fb22408..a023e0c 100644 --- a/src/engine/assets/material/Material.cpp +++ b/src/engine/assets/material/Material.cpp @@ -53,7 +53,7 @@ namespace fgl::engine return data; } - MaterialProperties::MaterialProperties() + MaterialProperties::MaterialProperties() : m_pbr(), m_normal(), m_occlusion(), m_emissive() { Sampler sampler {}; diff --git a/src/engine/assets/material/Material.hpp b/src/engine/assets/material/Material.hpp index e8efb3d..aeee228 100644 --- a/src/engine/assets/material/Material.hpp +++ b/src/engine/assets/material/Material.hpp @@ -40,31 +40,31 @@ namespace fgl::engine { struct { - std::shared_ptr< Texture > m_color_tex {}; + std::shared_ptr< Texture > m_color_tex { nullptr }; glm::vec4 m_color_factors { 1.0f }; - std::shared_ptr< Texture > m_metallic_roughness_tex; + std::shared_ptr< Texture > m_metallic_roughness_tex { nullptr }; float m_metallic_factor { 0.0f }; float m_roughness_factor { 0.0f }; - } m_pbr; + } m_pbr {}; struct { float m_scale { 1.0f }; - std::shared_ptr< Texture > m_texture; - } m_normal; + std::shared_ptr< Texture > m_texture { nullptr }; + } m_normal {}; struct { float m_strength { 1.0f }; - std::shared_ptr< Texture > m_texture; - } m_occlusion; + std::shared_ptr< Texture > m_texture { nullptr }; + } m_occlusion {}; struct { glm::vec3 m_factors { 1.0f }; - std::shared_ptr< Texture > m_texture; - } m_emissive; + std::shared_ptr< Texture > m_texture { nullptr }; + } m_emissive {}; void writeData( DeviceMaterialData& data ) const; DeviceMaterialData data() const; @@ -82,7 +82,7 @@ namespace fgl::engine { TextureID color_texture_id { constants::INVALID_TEXTURE_ID }; alignas( 4 * 4 ) glm::vec4 color_factors { 1.0f, 1.0f, 1.0f, 1.0f }; - } color; + } color {}; alignas( 16 ) struct Metallic { @@ -90,25 +90,25 @@ namespace fgl::engine alignas( 16 ) TextureID metallic_texture_id { constants::INVALID_TEXTURE_ID }; float metallic_factor { 0.0f }; float roughness_factor { 0.0f }; - } metallic; + } metallic {}; alignas( 16 ) struct Normal { TextureID normal_texture_id { constants::INVALID_TEXTURE_ID }; float normal_tex_scale { 0.0f }; - } normal; + } normal {}; alignas( 16 ) struct Occlusion { TextureID occlusion_texture_id { constants::INVALID_TEXTURE_ID }; float occlusion_tex_strength { 0.0f }; - } occlusion; + } occlusion {}; alignas( 16 ) struct Emissive { TextureID emissive_texture_id { constants::INVALID_TEXTURE_ID }; alignas( 4 * 4 ) glm::vec3 emissive_factors { 0.0f, 0.0f, 0.0f }; - } emissive; + } emissive {}; DeviceMaterialData() = default; }; @@ -134,16 +134,6 @@ namespace fgl::engine static_assert( sizeof( DeviceMaterialData ) == 112 ); - /* - static_assert( sizeof( DeviceMaterialData ) == 76 ); - static_assert( offsetof( DeviceMaterialData, color_factors ) == 16 ); - static_assert( offsetof( DeviceMaterialData, metallic_texture_id ) == 32 ); - static_assert( offsetof( DeviceMaterialData, normal_texture_id ) == 44 ); - static_assert( offsetof( DeviceMaterialData, occlusion_texture_id ) == 52 ); - static_assert( offsetof( DeviceMaterialData, emissive_texture_id ) == 60 ); - static_assert( offsetof( DeviceMaterialData, emissive_factors ) == 64 ); - */ - class Material { MaterialID m_id; diff --git a/src/engine/assets/model/Model.cpp b/src/engine/assets/model/Model.cpp index 8cb78ea..8144748 100644 --- a/src/engine/assets/model/Model.cpp +++ b/src/engine/assets/model/Model.cpp @@ -40,17 +40,17 @@ namespace fgl::engine vk::MemoryPropertyFlagBits::eDeviceLocal ), m_primitive_info( m_long_buffer ), m_primitive_instances( m_short_buffer ), - m_model_instances( m_short_buffer ) + m_model_instances( m_short_buffer ), + m_primitives_desc( PRIMITIVE_SET.create() ), + m_instances_desc( INSTANCES_SET.create() ) { m_vertex_buffer->setDebugName( "Vertex buffer GPU" ); m_index_buffer->setDebugName( "Index buffer" ); - m_primitives_desc = PRIMITIVE_SET.create(); m_primitives_desc->bindStorageBuffer( 0, m_primitive_info ); m_primitives_desc->update(); m_primitives_desc->setName( "Primitives" ); - m_instances_desc = INSTANCES_SET.create(); m_instances_desc->bindStorageBuffer( 0, m_primitive_instances ); m_instances_desc->bindStorageBuffer( 1, m_model_instances ); m_instances_desc->update(); @@ -109,7 +109,7 @@ namespace fgl::engine PrimitiveInstanceInfo instance_info {}; instance_info.m_primitive_info = render_info->idx(); instance_info.m_model_info = model_instance.idx(); - instance_info.m_material = primitive.default_material->getID(); + instance_info.m_material = primitive.m_default_material->getID(); primitive_instances.emplace_back( buffers.m_primitive_instances.acquire( instance_info ) ); } diff --git a/src/engine/assets/model/ModelVertex.cpp b/src/engine/assets/model/ModelVertex.cpp index 4194ea9..c953dda 100644 --- a/src/engine/assets/model/ModelVertex.cpp +++ b/src/engine/assets/model/ModelVertex.cpp @@ -4,9 +4,12 @@ #include "ModelVertex.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include -#include +#pragma GCC diagnostic pop #include "Model.hpp" #include "ModelInstance.hpp" diff --git a/src/engine/assets/model/Primitive.cpp b/src/engine/assets/model/Primitive.cpp index 0a70ebf..479e70a 100644 --- a/src/engine/assets/model/Primitive.cpp +++ b/src/engine/assets/model/Primitive.cpp @@ -34,10 +34,10 @@ namespace fgl::engine bool Primitive::ready() const { - return default_material->ready() && m_vertex_buffer.ready() && m_index_buffer.ready(); + return m_default_material->ready() && m_vertex_buffer.ready() && m_index_buffer.ready(); } - std::shared_ptr< PrimitiveRenderInfoIndex > Primitive::buildRenderInfo() + std::shared_ptr< PrimitiveRenderInfoIndex > Primitive::buildRenderInfo() const { auto& buffers { getModelBuffers() }; @@ -59,8 +59,8 @@ namespace fgl::engine m_index_buffer( std::move( index_buffer ) ), m_bounding_box( bounding_box ), m_mode( mode ), - default_material(), - m_primitive_info( buildRenderInfo() ) + m_primitive_info( buildRenderInfo() ), + m_default_material() { assert( m_bounding_box.getTransform().scale != glm::vec3( 0.0f ) ); } @@ -75,8 +75,8 @@ namespace fgl::engine m_index_buffer( std::move( index_buffer ) ), m_bounding_box( bounding_box ), m_mode( mode ), - default_material( material ), - m_primitive_info( buildRenderInfo() ) + m_primitive_info( buildRenderInfo() ), + m_default_material( material ) { assert( m_bounding_box.getTransform().scale != glm::vec3( 0.0f ) ); } diff --git a/src/engine/assets/model/Primitive.hpp b/src/engine/assets/model/Primitive.hpp index c9fcfcf..e2942b1 100644 --- a/src/engine/assets/model/Primitive.hpp +++ b/src/engine/assets/model/Primitive.hpp @@ -4,14 +4,11 @@ #pragma once -#include - #include "ModelInstanceInfo.hpp" #include "assets/material/Material.hpp" #include "engine/memory/buffers/vector/DeviceVector.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" #include "memory/buffers/vector/IndexedVector.hpp" -#include "objectloaders/tiny_gltf.h" namespace fgl::engine { @@ -22,6 +19,18 @@ namespace fgl::engine using IndexBufferSuballocation = DeviceVector< std::uint32_t >; + enum class PrimitiveMode + { + POINTS, + LINE, + LINE_LOOP, + LINE_STRIP, + TRIANGLES, + TRIANGLE_STRIP, + TRIANGLE_FAN + }; + + /* enum PrimitiveMode { POINTS = TINYGLTF_MODE_POINTS, @@ -32,6 +41,7 @@ namespace fgl::engine TRI_STRIP = TINYGLTF_MODE_TRIANGLE_STRIP, TRI_FAN = TINYGLTF_MODE_TRIANGLE_FAN }; + */ struct PrimitiveTextures { @@ -67,7 +77,7 @@ namespace fgl::engine struct Primitive { - bool draw { true }; + bool m_draw { true }; VertexBufferSuballocation m_vertex_buffer; IndexBufferSuballocation m_index_buffer; OrientedBoundingBox< CoordinateSpace::Model > m_bounding_box; @@ -75,14 +85,14 @@ namespace fgl::engine std::shared_ptr< PrimitiveRenderInfoIndex > m_primitive_info; - std::shared_ptr< Material > default_material; + std::shared_ptr< Material > m_default_material; std::string m_name { "Unnamed Primitive" }; //! Returns true if the primitive is ready to be rendered (must have all textures, vertex buffer, and index buffer ready) bool ready() const; - std::shared_ptr< PrimitiveRenderInfoIndex > buildRenderInfo(); + std::shared_ptr< PrimitiveRenderInfoIndex > buildRenderInfo() const; Primitive( VertexBufferSuballocation&& vertex_buffer, diff --git a/src/engine/assets/model/SimpleVertex.cpp b/src/engine/assets/model/SimpleVertex.cpp index 5a1b883..f315625 100644 --- a/src/engine/assets/model/SimpleVertex.cpp +++ b/src/engine/assets/model/SimpleVertex.cpp @@ -12,6 +12,12 @@ namespace fgl::engine { + SimpleVertex::SimpleVertex() + {} + + SimpleVertex::SimpleVertex( const glm::vec3 pos, const glm::vec3 color ) : m_position( pos ), m_color( color ) + {} + std::vector< vk::VertexInputBindingDescription > SimpleVertex::getBindingDescriptions() { // {buffer_idx, stride, rate} diff --git a/src/engine/assets/model/SimpleVertex.hpp b/src/engine/assets/model/SimpleVertex.hpp index a4c2142..dd01335 100644 --- a/src/engine/assets/model/SimpleVertex.hpp +++ b/src/engine/assets/model/SimpleVertex.hpp @@ -22,9 +22,9 @@ namespace fgl::engine glm::vec3 m_position { 0.0f }; glm::vec3 m_color { 1.0f }; - SimpleVertex() = default; + SimpleVertex(); - SimpleVertex( const glm::vec3 pos, const glm::vec3 color ) : m_position( pos ), m_color( color ) {} + SimpleVertex( glm::vec3 pos, glm::vec3 color ); static std::vector< vk::VertexInputBindingDescription > getBindingDescriptions(); static std::vector< vk::VertexInputAttributeDescription > getAttributeDescriptions(); diff --git a/src/engine/assets/model/builders/ModelBuilder.cpp b/src/engine/assets/model/builders/ModelBuilder.cpp index f122523..01368eb 100644 --- a/src/engine/assets/model/builders/ModelBuilder.cpp +++ b/src/engine/assets/model/builders/ModelBuilder.cpp @@ -34,7 +34,7 @@ namespace fgl::engine std::move( vertex_suballoc ), std::move( index_suballoc ), generateBoundingFromVerts( verts ), - PrimitiveMode::TRIS ); + PrimitiveMode::TRIANGLES ); } } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/assets/model/builders/SceneBuilder.cpp b/src/engine/assets/model/builders/SceneBuilder.cpp index 5f90231..7a3cecf 100644 --- a/src/engine/assets/model/builders/SceneBuilder.cpp +++ b/src/engine/assets/model/builders/SceneBuilder.cpp @@ -4,6 +4,12 @@ #include "SceneBuilder.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#include +#pragma GCC diagnostic pop + #include "assets/model/ModelVertex.hpp" #include "engine/assets/model/Model.hpp" #include "engine/assets/stores.hpp" @@ -13,7 +19,6 @@ #include "engine/gameobjects/GameObject.hpp" #include "gameobjects/components/TransformComponent.hpp" #include "mikktspace/mikktspace.hpp" -#include "objectloaders/tiny_gltf.h" namespace fgl::engine { @@ -367,11 +372,11 @@ namespace fgl::engine context.m_pUserData = &interface; context.m_pInterface = &interface; - auto getNumFaces = [ & ]( [[maybe_unused]] const SMikkTSpaceContext* ctx ) -> int + auto getNumFaces = [ & ]( [[maybe_unused]] const SMikkTSpaceContext* ctx ) noexcept -> int { return static_cast< int >( indicies.size() ) / 3; }; auto getNumVerticesOfFace = - [ & ]( [[maybe_unused]] const SMikkTSpaceContext* ctx, [[maybe_unused]] const int i_face ) -> int + [ & ]( [[maybe_unused]] const SMikkTSpaceContext* ctx, [[maybe_unused]] const int i_face ) noexcept -> int { return 3; }; auto getPosition = [ & ]( @@ -456,22 +461,25 @@ namespace fgl::engine std::vector< ModelVertex > verts { extractVertexInfo( prim, root ) }; std::vector< std::uint32_t > indicies { extractIndicies( prim, root ) }; - switch ( static_cast< PrimitiveMode >( prim.mode ) ) + PrimitiveMode primitive_mode { PrimitiveMode::POINTS }; + + switch ( prim.mode ) { - case TRIS: + case TINYGLTF_MODE_TRIANGLES: generateTrisTangents( verts, indicies ); + primitive_mode = PrimitiveMode::TRIANGLES; break; - case POINTS: + case TINYGLTF_MODE_POINTS: [[fallthrough]]; - case LINE: + case TINYGLTF_MODE_LINE: [[fallthrough]]; - case LINE_LOOP: + case TINYGLTF_MODE_LINE_LOOP: [[fallthrough]]; - case LINE_STRIP: + case TINYGLTF_MODE_LINE_STRIP: [[fallthrough]]; - case TRI_STRIP: + case TINYGLTF_MODE_TRIANGLE_STRIP: [[fallthrough]]; - case TRI_FAN: + case TINYGLTF_MODE_TRIANGLE_FAN: [[fallthrough]]; default: { @@ -480,18 +488,16 @@ namespace fgl::engine } } - Primitive primitive_mesh { Primitive::fromVerts( - std::move( verts ), - static_cast< PrimitiveMode >( prim.mode ), - std::move( indicies ), - m_vertex_buffer, - m_index_buffer ) }; + auto primitive_mesh { + Primitive:: + fromVerts( std::move( verts ), primitive_mode, std::move( indicies ), m_vertex_buffer, m_index_buffer ) + }; // If we have a texcoord then we have a UV map. Meaning we likely have textures to use if ( !has_texcoord ) return primitive_mesh; //primitive_mesh.m_textures = loadTextures( prim, root ); - primitive_mesh.default_material = loadMaterial( prim, root ); + primitive_mesh.m_default_material = loadMaterial( prim, root ); return primitive_mesh; } @@ -648,15 +654,15 @@ namespace fgl::engine material->properties.m_pbr.m_metallic_roughness_tex = loadTexture( metallic_roughness.metallicRoughnessTexture.index, root ); - material->properties.m_pbr.m_metallic_factor = metallic_roughness.metallicFactor; - material->properties.m_pbr.m_roughness_factor = metallic_roughness.roughnessFactor; + material->properties.m_pbr.m_metallic_factor = static_cast< float >( metallic_roughness.metallicFactor ); + material->properties.m_pbr.m_roughness_factor = static_cast< float >( metallic_roughness.roughnessFactor ); } material->properties.m_normal.m_texture = loadTexture( gltf_material.normalTexture.index, root ); - material->properties.m_normal.m_scale = gltf_material.normalTexture.scale; + material->properties.m_normal.m_scale = static_cast< float >( gltf_material.normalTexture.scale ); material->properties.m_occlusion.m_texture = loadTexture( gltf_material.occlusionTexture.index, root ); - material->properties.m_occlusion.m_strength = gltf_material.occlusionTexture.strength; + material->properties.m_occlusion.m_strength = static_cast< float >( gltf_material.occlusionTexture.strength ); material->properties.m_emissive.m_texture = loadTexture( gltf_material.emissiveTexture.index, root ); material->properties.m_emissive.m_factors = convertToVec3( gltf_material.emissiveFactor ); @@ -672,7 +678,7 @@ namespace fgl::engine const tinygltf::Node& node { root.nodes[ node_idx ] }; const int mesh_idx { node.mesh }; - const int skin_idx { node.skin }; + [[maybe_unused]] const int skin_idx { node.skin }; auto obj { GameObject::createGameObject() }; diff --git a/src/engine/assets/model/builders/SceneBuilder.hpp b/src/engine/assets/model/builders/SceneBuilder.hpp index 75829ef..937e799 100644 --- a/src/engine/assets/model/builders/SceneBuilder.hpp +++ b/src/engine/assets/model/builders/SceneBuilder.hpp @@ -4,11 +4,6 @@ #pragma once -#define GLM_ENABLE_EXPERIMENTAL -#include -#include -#include - #include #include diff --git a/src/engine/assets/model/builders/loadObj.cpp b/src/engine/assets/model/builders/loadObj.cpp index cc271fa..a8a72a2 100644 --- a/src/engine/assets/model/builders/loadObj.cpp +++ b/src/engine/assets/model/builders/loadObj.cpp @@ -2,11 +2,14 @@ // Created by kj16609 on 5/18/24. // -#include - #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#include +#pragma GCC diagnostic pop + #include "ModelBuilder.hpp" #include "engine/assets/model/ModelVertex.hpp" #include "engine/assets/model/Primitive.hpp" @@ -28,7 +31,7 @@ namespace fgl::engine const std::vector< tinyobj::shape_t >& shapes { reader.GetShapes() }; [[maybe_unused]] const std::vector< tinyobj::material_t >& materials { reader.GetMaterials() }; - if ( shapes.size() == 0 ) throw std::runtime_error( "Failed to get shapes from OBJ" ); + if ( shapes.empty() ) throw std::runtime_error( "Failed to get shapes from OBJ" ); const std::string& warn { reader.Warning() }; const std::string& error { reader.Error() }; @@ -47,33 +50,37 @@ namespace fgl::engine for ( const auto& index : shape.mesh.indices ) { ModelVertex vert {}; + if ( index.vertex_index >= 0 ) { + const auto vertex_index { 3ul * static_cast< std::uint64_t >( index.vertex_index ) }; vert.m_position = { - attrib.vertices[ static_cast< std::uint64_t >( 3 * index.vertex_index + 0 ) ], - attrib.vertices[ static_cast< std::uint64_t >( 3 * index.vertex_index + 1 ) ], - attrib.vertices[ static_cast< std::uint64_t >( 3 * index.vertex_index + 2 ) ], + attrib.vertices[ vertex_index + 0ul ], + attrib.vertices[ vertex_index + 1ul ], + attrib.vertices[ vertex_index + 2ul ], }; - vert.m_color = { attrib.colors[ static_cast< std::uint64_t >( 3 * index.vertex_index + 0 ) ], - attrib.colors[ static_cast< std::uint64_t >( 3 * index.vertex_index + 1 ) ], - attrib.colors[ static_cast< std::uint64_t >( 3 * index.vertex_index + 2 ) ] }; + vert.m_color = { attrib.colors[ vertex_index + 0ul ], + attrib.colors[ vertex_index + 1ul ], + attrib.colors[ vertex_index + 2ul ] }; } if ( index.normal_index >= 0 ) { + const auto normal_index { 3ul * static_cast< std::uint64_t >( index.normal_index ) }; vert.m_normal = { - attrib.normals[ static_cast< std::uint64_t >( 3 * index.normal_index + 0 ) ], - attrib.normals[ static_cast< std::uint64_t >( 3 * index.normal_index + 1 ) ], - attrib.normals[ static_cast< std::uint64_t >( 3 * index.normal_index + 2 ) ], + attrib.normals[ normal_index + 0ul ], + attrib.normals[ normal_index + 1ul ], + attrib.normals[ normal_index + 2ul ], }; } if ( index.texcoord_index >= 0 ) { + const auto texcoord_index { 3ul * static_cast< std::uint64_t >( index.texcoord_index ) }; vert.m_uv = { - attrib.texcoords[ static_cast< std::uint64_t >( 3 * index.texcoord_index + 0 ) ], - attrib.texcoords[ static_cast< std::uint64_t >( 3 * index.texcoord_index + 1 ) ], + attrib.texcoords[ texcoord_index + 0ul ], + attrib.texcoords[ texcoord_index + 1ul ], }; } @@ -102,9 +109,9 @@ namespace fgl::engine const OrientedBoundingBox bounding_box { generateBoundingFromVerts( verts ) }; [[maybe_unused]] auto& itter = m_primitives.emplace_back( - VertexBufferSuballocation( m_vertex_buffer, std::move( verts ) ), - IndexBufferSuballocation( m_index_buffer, std::move( indicies ) ), + VertexBufferSuballocation( m_vertex_buffer, verts ), + IndexBufferSuballocation( m_index_buffer, indicies ), bounding_box, - PrimitiveMode::TRIS ); + PrimitiveMode::TRIANGLES ); } } // namespace fgl::engine diff --git a/src/engine/assets/model/builders/mikktspace/mikktspace.cpp b/src/engine/assets/model/builders/mikktspace/mikktspace.cpp index b12a9a4..aa60e7e 100644 --- a/src/engine/assets/model/builders/mikktspace/mikktspace.cpp +++ b/src/engine/assets/model/builders/mikktspace/mikktspace.cpp @@ -35,6 +35,11 @@ #include "glm/geometric.hpp" #include "glm/vec3.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wshadow" + #define TFALSE false #define TTRUE true @@ -853,10 +858,10 @@ int GenerateInitialVerticesIndexList( const SVec3 P1 = GetPosition( pContext, i1 ); const SVec3 P2 = GetPosition( pContext, i2 ); const SVec3 P3 = GetPosition( pContext, i3 ); - const float distSQ_02 = LengthSquared( vsub( P2, P0 ) ); - const float distSQ_13 = LengthSquared( vsub( P3, P1 ) ); + const float distSQ_02_2 = LengthSquared( vsub( P2, P0 ) ); + const float distSQ_13_2 = LengthSquared( vsub( P3, P1 ) ); - bQuadDiagIs_02 = distSQ_13 >= distSQ_02; + bQuadDiagIs_02 = distSQ_13_2 >= distSQ_02_2; } if ( bQuadDiagIs_02 ) @@ -1984,3 +1989,5 @@ void DegenEpilogue( } } } + +#pragma GCC diagnostic pop \ No newline at end of file diff --git a/src/engine/assets/texture/Texture.cpp b/src/engine/assets/texture/Texture.cpp index d1024ec..2f98107 100644 --- a/src/engine/assets/texture/Texture.cpp +++ b/src/engine/assets/texture/Texture.cpp @@ -4,6 +4,18 @@ #include "Texture.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wconversion" +#include +#pragma GCC diagnostic pop + +#pragma GCC diagnostic push +#include +#pragma GCC diagnostic pop + #include "engine/FrameInfo.hpp" #include "engine/assets/image/Image.hpp" #include "engine/assets/image/ImageView.hpp" @@ -11,8 +23,6 @@ #include "engine/descriptors/DescriptorSet.hpp" #include "engine/math/noise/perlin/generator.hpp" #include "engine/utility/IDPool.hpp" -#include "imgui/backends/imgui_impl_vulkan.h" -#include "objectloaders/stb_image.h" namespace fgl::engine { @@ -40,8 +50,8 @@ namespace fgl::engine std::vector< std::byte > data {}; - data.resize( x * y * 4 ); - std::memcpy( data.data(), data_c, x * y * 4 ); + data.resize( static_cast< std::size_t >( x ) * static_cast< std::size_t >( y ) * 4 ); + std::memcpy( data.data(), data_c, data.size() ); stbi_image_free( data_c ); diff --git a/src/engine/assets/transfer/TransferData.hpp b/src/engine/assets/transfer/TransferData.hpp index 785eb7c..29a966b 100644 --- a/src/engine/assets/transfer/TransferData.hpp +++ b/src/engine/assets/transfer/TransferData.hpp @@ -28,7 +28,7 @@ namespace fgl::engine namespace memory { - struct BufferSuballocationHandle; + class BufferSuballocationHandle; class BufferHandle; } // namespace memory } // namespace fgl::engine diff --git a/src/engine/assets/transfer/TransferManager.cpp b/src/engine/assets/transfer/TransferManager.cpp index 3772278..0cdc4c2 100644 --- a/src/engine/assets/transfer/TransferManager.cpp +++ b/src/engine/assets/transfer/TransferManager.cpp @@ -13,7 +13,11 @@ #include "engine/memory/buffers/vector/HostVector.hpp" #ifdef ENABLE_IMGUI -#include "imgui.h" +#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 @@ -94,7 +98,7 @@ namespace fgl::engine::memory command_buffer.endDebugUtilsLabelEXT(); } - void TransferManager::resizeBuffer( const std::uint64_t size ) + void TransferManager::resizeBuffer( [[maybe_unused]] const std::uint64_t size ) { // m_staging_buffer.resize( size ); } @@ -367,7 +371,7 @@ namespace fgl::engine::memory "|- %s Unused", literals::size_literals::toString( m_staging_buffer->size() - m_staging_buffer->used() ).c_str() ); - ImGui::Text( "|- %i transfer remaining", m_queue.size() ); + ImGui::Text( "|- %zu transfer remaining", m_queue.size() ); ImGui::Text( "|- %zu objects being processed", m_processing.size() ); ImGui::Text( "|- %zu total copy regions", m_copy_regions.size() ); #endif diff --git a/src/engine/assets/transfer/TransferManager.hpp b/src/engine/assets/transfer/TransferManager.hpp index 387a031..749b691 100644 --- a/src/engine/assets/transfer/TransferManager.hpp +++ b/src/engine/assets/transfer/TransferManager.hpp @@ -21,7 +21,7 @@ namespace fgl::engine { class BufferVector; - struct BufferSuballocationHandle; + class BufferSuballocationHandle; class BufferSuballocation; } // namespace memory diff --git a/src/engine/camera/CameraViewpoint.cpp b/src/engine/camera/CameraViewpoint.cpp index 264319b..2d0e75f 100644 --- a/src/engine/camera/CameraViewpoint.cpp +++ b/src/engine/camera/CameraViewpoint.cpp @@ -229,7 +229,8 @@ namespace fgl::engine vk::Viewport CameraViewpoint::viewport() const { - return { 0, 0, this->m_extent.width, this->m_extent.height, 0.0f, 1.0f }; + return { 0, 0, static_cast< float >( this->m_extent.width ), static_cast< float >( this->m_extent.height ), + 0.0f, 1.0f }; } descriptors::DescriptorSetLayout& CameraViewpoint::getDescriptorLayout() diff --git a/src/engine/camera/RenderCamera.hpp b/src/engine/camera/RenderCamera.hpp index 3bb0971..b289ccb 100644 --- a/src/engine/camera/RenderCamera.hpp +++ b/src/engine/camera/RenderCamera.hpp @@ -4,10 +4,6 @@ #pragma once -#define GLM_ENABLE_EXPERIMENTAL -#include -#include - #include "CameraViewpoint.hpp" #include "CompositeSwapchain.hpp" #include "GBufferSwapchain.hpp" diff --git a/src/engine/camera/ShadowMap.cpp b/src/engine/camera/ShadowMap.cpp index 8fdbcc5..e20353e 100644 --- a/src/engine/camera/ShadowMap.cpp +++ b/src/engine/camera/ShadowMap.cpp @@ -48,7 +48,7 @@ namespace fgl::engine { PerFrameArray< std::unique_ptr< descriptors::DescriptorSet > > data {}; - for ( std::size_t i = 0; i < data.size(); ++i ) + for ( FrameIndex i = 0; i < data.size(); ++i ) { auto set { shadowmap_descriptor_set.create() }; @@ -70,6 +70,8 @@ namespace fgl::engine m_swapchain( createDepthSwapchain( extent ) ), m_direction( direction ), m_camera( CameraManager::createViewpoint( extent ) ), + m_shadow_pipeline( nullptr ), + m_culling_system(), m_extent( extent ), m_shadowmap_descriptor( createShadowmapDescriptors() ) { diff --git a/src/engine/camera/ShadowMap.hpp b/src/engine/camera/ShadowMap.hpp index f053881..12a9c96 100644 --- a/src/engine/camera/ShadowMap.hpp +++ b/src/engine/camera/ShadowMap.hpp @@ -16,7 +16,7 @@ namespace fgl::engine { namespace gui { - void drawShadowmaps( const FrameInfo& info ); + extern void drawShadowmaps( const FrameInfo& info ); } struct CameraInfo; diff --git a/src/engine/camera/Swapchain.cpp b/src/engine/camera/Swapchain.cpp index 2cb8779..96d0e23 100644 --- a/src/engine/camera/Swapchain.cpp +++ b/src/engine/camera/Swapchain.cpp @@ -8,7 +8,6 @@ #include "assets/texture/Texture.hpp" #include "constants.hpp" #include "rendering/devices/Device.hpp" -#include "slang.h" namespace fgl::engine { diff --git a/src/engine/debug/logging/formatters/glm.cpp b/src/engine/debug/logging/formatters/glm.cpp index 64b4ee1..91bbe85 100644 --- a/src/engine/debug/logging/formatters/glm.cpp +++ b/src/engine/debug/logging/formatters/glm.cpp @@ -4,8 +4,12 @@ #include "glm.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include +#pragma GCC diagnostic pop std::format_context::iterator std::formatter< glm::qua< float > >::format( const glm::quat& quat, format_context& ctx ) const diff --git a/src/engine/debug/timing/FlameGraph.cpp b/src/engine/debug/timing/FlameGraph.cpp index 8c574e4..7d261df 100644 --- a/src/engine/debug/timing/FlameGraph.cpp +++ b/src/engine/debug/timing/FlameGraph.cpp @@ -5,7 +5,12 @@ #include "FlameGraph.hpp" #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" diff --git a/src/engine/descriptors/DescriptorSet.cpp b/src/engine/descriptors/DescriptorSet.cpp index 2be00c9..5035470 100644 --- a/src/engine/descriptors/DescriptorSet.cpp +++ b/src/engine/descriptors/DescriptorSet.cpp @@ -17,15 +17,75 @@ namespace fgl::engine::descriptors { + void DescriptorSet::resetUpdate() + { + m_infos.clear(); + //Clear all writes + m_descriptor_writes.clear(); + + m_infos.resize( m_binding_count ); + } + + bool DescriptorSet::hasUpdates() const + { + return !m_descriptor_writes.empty(); + } + + void DescriptorSet::update() + { + Device::getInstance().device().updateDescriptorSets( m_descriptor_writes, {} ); + m_initalized = true; + resetUpdate(); + } + + VkDescriptorSet DescriptorSet::operator*() const + { + return getVkDescriptorSet(); + } + + VkDescriptorSet DescriptorSet::getVkDescriptorSet() const + { + FGL_ASSERT( !hasUpdates(), "Descriptor set has updates but binding was attempted" ); + FGL_ASSERT( m_initalized, "Descriptor set has not been initialized" ); + return *m_set; + } + DescriptorSet::DescriptorSet( const vk::raii::DescriptorSetLayout& layout, const DescriptorIDX idx, const std::size_t binding_count ) : m_set_idx( idx ), + m_infos(), + m_descriptor_writes(), + m_resources(), m_set( DescriptorPool::getInstance().allocateSet( layout ) ), m_binding_count( binding_count ) { m_infos.resize( m_binding_count ); } + DescriptorSet::~DescriptorSet() + {} + + void DescriptorSet:: + bindImage( const std::uint32_t binding_idx, const ImageView& view, const vk::ImageLayout layout ) + { + assert( binding_idx < m_infos.size() && "Binding index out of range" ); + + //Store info + m_infos[ binding_idx ] = view.descriptorInfo( layout ); + + vk::WriteDescriptorSet write {}; + write.dstSet = m_set; + write.dstBinding = binding_idx; + write.dstArrayElement = 0; + write.descriptorCount = 1; + write.descriptorType = vk::DescriptorType::eSampledImage; + write.pBufferInfo = VK_NULL_HANDLE; + write.pImageInfo = &( std::get< vk::DescriptorImageInfo >( m_infos[ binding_idx ] ) ); + write.pTexelBufferView = VK_NULL_HANDLE; + + m_descriptor_writes.push_back( write ); + } + void DescriptorSet::bindUniformBuffer( const std::uint32_t binding_idx, const memory::BufferSuballocation& buffer ) { assert( binding_idx < m_infos.size() && "Binding index out of range" ); @@ -93,7 +153,7 @@ namespace fgl::engine::descriptors } void DescriptorSet:: - bindImage( const std::uint32_t binding_idx, const ImageView& view, const vk::ImageLayout layout ) + bindAttachment( const std::uint32_t binding_idx, const ImageView& view, const vk::ImageLayout layout ) { assert( binding_idx < m_infos.size() && "Binding index out of range" ); @@ -105,7 +165,7 @@ namespace fgl::engine::descriptors write.dstBinding = binding_idx; write.dstArrayElement = 0; write.descriptorCount = 1; - write.descriptorType = vk::DescriptorType::eSampledImage; + write.descriptorType = vk::DescriptorType::eInputAttachment; write.pBufferInfo = VK_NULL_HANDLE; write.pImageInfo = &( std::get< vk::DescriptorImageInfo >( m_infos[ binding_idx ] ) ); write.pTexelBufferView = VK_NULL_HANDLE; @@ -139,63 +199,6 @@ namespace fgl::engine::descriptors m_descriptor_writes.push_back( write ); } - void DescriptorSet::update() - { - Device::getInstance().device().updateDescriptorSets( m_descriptor_writes, {} ); - m_initalized = true; - resetUpdate(); - } - - VkDescriptorSet DescriptorSet::operator*() const - { - return getVkDescriptorSet(); - } - - VkDescriptorSet DescriptorSet::getVkDescriptorSet() const - { - FGL_ASSERT( !hasUpdates(), "Descriptor set has updates but binding was attempted" ); - FGL_ASSERT( m_initalized, "Descriptor set has not been initialized" ); - return *m_set; - } - - DescriptorSet::~DescriptorSet() - {} - - void DescriptorSet::resetUpdate() - { - m_infos.clear(); - //Clear all writes - m_descriptor_writes.clear(); - - m_infos.resize( m_binding_count ); - } - - bool DescriptorSet::hasUpdates() const - { - return !m_descriptor_writes.empty(); - } - - void DescriptorSet:: - bindAttachment( const std::uint32_t binding_idx, const ImageView& view, const vk::ImageLayout layout ) - { - assert( binding_idx < m_infos.size() && "Binding index out of range" ); - - //Store info - m_infos[ binding_idx ] = view.descriptorInfo( layout ); - - vk::WriteDescriptorSet write {}; - write.dstSet = m_set; - write.dstBinding = binding_idx; - write.dstArrayElement = 0; - write.descriptorCount = 1; - write.descriptorType = vk::DescriptorType::eInputAttachment; - write.pBufferInfo = VK_NULL_HANDLE; - write.pImageInfo = &( std::get< vk::DescriptorImageInfo >( m_infos[ binding_idx ] ) ); - write.pTexelBufferView = VK_NULL_HANDLE; - - m_descriptor_writes.push_back( write ); - } - void DescriptorSet::setName( const std::string& str ) const { vk::DebugUtilsObjectNameInfoEXT info {}; diff --git a/src/engine/descriptors/DescriptorSet.hpp b/src/engine/descriptors/DescriptorSet.hpp index 7ebb6a3..2cb17d2 100644 --- a/src/engine/descriptors/DescriptorSet.hpp +++ b/src/engine/descriptors/DescriptorSet.hpp @@ -60,18 +60,10 @@ namespace fgl::engine::descriptors [[nodiscard]] DescriptorIDX setIDX() const { return m_set_idx; } - FGL_DELETE_DEFAULT_CTOR( DescriptorSet ); + FGL_DELETE_ALL_RO5( DescriptorSet ); DescriptorSet( const vk::raii::DescriptorSetLayout& layout, DescriptorIDX idx, std::size_t binding_count ); - FGL_DELETE_COPY( DescriptorSet ); - - FGL_DELETE_MOVE( DescriptorSet ); - - //Move - // DescriptorSet( DescriptorSet&& other ) noexcept; - // DescriptorSet& operator=( DescriptorSet&& other ) noexcept; - ~DescriptorSet(); void bindImage( std::uint32_t binding_idx, const ImageView& view, vk::ImageLayout layout ); diff --git a/src/engine/filesystem/types.hpp b/src/engine/filesystem/types.hpp index 2b7905f..acd0778 100644 --- a/src/engine/filesystem/types.hpp +++ b/src/engine/filesystem/types.hpp @@ -4,5 +4,5 @@ #pragma once -inline static constexpr char* DRAG_TYPE_FILE_MODEL_INFO { "_MODEL_FILE_INFO" }; -inline static constexpr char* DRAG_TYPE_FILE_TEXTURE_INFO { "_TEXTURE_FILE_INFO" }; +inline static constexpr auto* DRAG_TYPE_FILE_MODEL_INFO { "_MODEL_FILE_INFO" }; +inline static constexpr auto* DRAG_TYPE_FILE_TEXTURE_INFO { "_TEXTURE_FILE_INFO" }; diff --git a/src/engine/gameobjects/components/TransformComponent.hpp b/src/engine/gameobjects/components/TransformComponent.hpp index e39c1af..d0935cc 100644 --- a/src/engine/gameobjects/components/TransformComponent.hpp +++ b/src/engine/gameobjects/components/TransformComponent.hpp @@ -16,7 +16,7 @@ namespace fgl::engine::components COMPONENT_CLASS( TransformComponent, TransformComponentID ) { WorldTransform m_transform; - std::shared_ptr< ModelInstanceInfoIndex > m_model_instance_info_index; + std::shared_ptr< ModelInstanceInfoIndex > m_model_instance_info_index {}; using Updatable = std::variant< std::weak_ptr< ModelInstance > >; diff --git a/src/engine/gameobjects/components/drawers.cpp b/src/engine/gameobjects/components/drawers.cpp index 43ed536..6003804 100644 --- a/src/engine/gameobjects/components/drawers.cpp +++ b/src/engine/gameobjects/components/drawers.cpp @@ -4,7 +4,11 @@ #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" diff --git a/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp b/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp index ffa606b..60ff210 100644 --- a/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp +++ b/src/engine/gameobjects/components/interface/ComponentEditorInterface.cpp @@ -4,8 +4,6 @@ #include "ComponentEditorInterface.hpp" -#include - namespace fgl::engine { diff --git a/src/engine/lighting/lights/Sun.cpp b/src/engine/lighting/lights/Sun.cpp index 1495bca..448a029 100644 --- a/src/engine/lighting/lights/Sun.cpp +++ b/src/engine/lighting/lights/Sun.cpp @@ -7,6 +7,6 @@ namespace fgl::engine { - Sun::Sun() : m_shadowmap( createShadowmap( UniversalRotation::pointAt( constants::SUN_DIR ) ) ) + Sun::Sun() : m_shadowmap( createShadowmap( UniversalRotation::pointIn( constants::SUN_DIR ) ) ) {} } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/math/raycast/raycast.hpp b/src/engine/math/raycast/raycast.hpp index 812dafb..2475bc4 100644 --- a/src/engine/math/raycast/raycast.hpp +++ b/src/engine/math/raycast/raycast.hpp @@ -3,7 +3,6 @@ // #pragma once -#include "../../primitives/rotation/QuatRotation.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" #include "engine/primitives/points/Coordinate.hpp" diff --git a/src/engine/memory/buffers/BufferHandle.cpp b/src/engine/memory/buffers/BufferHandle.cpp index ae6df13..816ce24 100644 --- a/src/engine/memory/buffers/BufferHandle.cpp +++ b/src/engine/memory/buffers/BufferHandle.cpp @@ -247,8 +247,8 @@ namespace fgl::engine::memory .emplace_back( selected_block_offset + desired_memory_size, selected_block_size - desired_memory_size ); } - std::ranges:: - remove_if( m_active_suballocations, []( auto& suballocation ) -> bool { return suballocation.expired(); } ); + std::ranges::remove_if( + m_active_suballocations, []( auto& suballocation ) noexcept -> bool { return suballocation.expired(); } ); auto suballocation_handle { std::make_shared< BufferSuballocationHandle >( Buffer( this->shared_from_this() ), selected_block_offset, desired_memory_size, t_alignment ) }; @@ -416,7 +416,7 @@ namespace fgl::engine::memory } ); } - Buffer Buffer::operator=( const std::shared_ptr< BufferHandle >& other ) + Buffer& Buffer::operator=( const std::shared_ptr< BufferHandle >& other ) { std::shared_ptr< BufferHandle >::operator=( other ); return *this; diff --git a/src/engine/memory/buffers/BufferHandle.hpp b/src/engine/memory/buffers/BufferHandle.hpp index 9151947..7320ed5 100644 --- a/src/engine/memory/buffers/BufferHandle.hpp +++ b/src/engine/memory/buffers/BufferHandle.hpp @@ -14,10 +14,13 @@ #include #include -#include "FGL_DEFINES.hpp" #include "engine/debug/Track.hpp" #include "math/literals/size.hpp" -#include "vma/vma_impl.hpp" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wundef" +#include +#pragma GCC diagnostic pop namespace fgl::engine { @@ -166,8 +169,6 @@ namespace fgl::engine::memory class Buffer final : public std::shared_ptr< BufferHandle > { - Buffer operator=( const std::shared_ptr< BufferHandle >& other ); - public: [[nodiscard]] Buffer( @@ -179,6 +180,8 @@ namespace fgl::engine::memory [[nodiscard]] vk::DeviceSize size() const; + Buffer& operator=( const std::shared_ptr< BufferHandle >& other ); + ~Buffer() = default; }; diff --git a/src/engine/memory/buffers/BufferSuballocation.hpp b/src/engine/memory/buffers/BufferSuballocation.hpp index a1dbe80..1f85816 100644 --- a/src/engine/memory/buffers/BufferSuballocation.hpp +++ b/src/engine/memory/buffers/BufferSuballocation.hpp @@ -13,7 +13,7 @@ namespace fgl::engine::memory class BufferHandle; class SuballocationView; - struct BufferSuballocationHandle; + class BufferSuballocationHandle; class BufferSuballocation { diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.cpp b/src/engine/memory/buffers/BufferSuballocationHandle.cpp index c411fbc..6c4284d 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.cpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.cpp @@ -50,7 +50,7 @@ namespace fgl::engine::memory void BufferSuballocationHandle::setReady( const bool value ) { - std::ranges::remove_if( m_dependents, []( const auto& handle ) { return handle.expired(); } ); + std::ranges::remove_if( m_dependents, []( const auto& handle ) noexcept -> bool { return handle.expired(); } ); m_staged = value; } diff --git a/src/engine/memory/buffers/BufferSuballocationHandle.hpp b/src/engine/memory/buffers/BufferSuballocationHandle.hpp index d9d556c..2f7ef55 100644 --- a/src/engine/memory/buffers/BufferSuballocationHandle.hpp +++ b/src/engine/memory/buffers/BufferSuballocationHandle.hpp @@ -9,6 +9,7 @@ #include #include "BufferHandle.hpp" +#include "FGL_DEFINES.hpp" #include "engine/debug/Track.hpp" namespace vk::raii diff --git a/src/engine/memory/buffers/HostSingleT.hpp b/src/engine/memory/buffers/HostSingleT.hpp index 4177aab..afdc856 100644 --- a/src/engine/memory/buffers/HostSingleT.hpp +++ b/src/engine/memory/buffers/HostSingleT.hpp @@ -10,7 +10,7 @@ namespace fgl::engine { namespace memory { - struct Buffer; + class Buffer; } //! Single element allocation of T diff --git a/src/engine/memory/buffers/SuballocationView.cpp b/src/engine/memory/buffers/SuballocationView.cpp index 6304a87..c2c0012 100644 --- a/src/engine/memory/buffers/SuballocationView.cpp +++ b/src/engine/memory/buffers/SuballocationView.cpp @@ -10,19 +10,28 @@ namespace fgl::engine::memory { - vk::Buffer SuballocationView::getVkBuffer() - { - return m_suballocation->getVkBuffer(); - } + SuballocationView::SuballocationView( + const std::shared_ptr< BufferSuballocationHandle >& handle, + const vk::DeviceSize offset, + const vk::DeviceSize size ) : + m_suballocation( handle ), + m_offset( offset ), + m_size( size ) + {} - vk::DeviceSize SuballocationView::offset() - { - return m_offset + m_suballocation->offset(); - } - - void SuballocationView::setOffset( vk::DeviceSize offset ) + void SuballocationView::setOffset( const vk::DeviceSize offset ) { m_offset = offset; } + vk::Buffer SuballocationView::getVkBuffer() const + { + return m_suballocation->getVkBuffer(); + } + + vk::DeviceSize SuballocationView::offset() const + { + return m_offset + m_suballocation->offset(); + } + } // namespace fgl::engine::memory diff --git a/src/engine/memory/buffers/SuballocationView.hpp b/src/engine/memory/buffers/SuballocationView.hpp index 1b0a0a6..55884c6 100644 --- a/src/engine/memory/buffers/SuballocationView.hpp +++ b/src/engine/memory/buffers/SuballocationView.hpp @@ -11,7 +11,7 @@ namespace fgl::engine::memory { - struct BufferSuballocationHandle; + class BufferSuballocationHandle; class SuballocationView { @@ -21,20 +21,16 @@ namespace fgl::engine::memory public: - SuballocationView( - std::shared_ptr< BufferSuballocationHandle > handle, vk::DeviceSize offset, vk::DeviceSize size ) : - m_suballocation( handle ), - m_offset( offset ), - m_size( size ) - {} + [[nodiscard]] SuballocationView( + const std::shared_ptr< BufferSuballocationHandle >& handle, vk::DeviceSize offset, vk::DeviceSize size ); void setOffset( vk::DeviceSize offset ); //! Returns the buffer - vk::Buffer getVkBuffer(); + [[nodiscard]] vk::Buffer getVkBuffer() const; //! Returns the offset of this view within the buffer - vk::DeviceSize offset(); + [[nodiscard]] vk::DeviceSize offset() const; }; } // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/primitives/matricies/Matrix.hpp b/src/engine/primitives/matricies/Matrix.hpp index e29e7f6..a683511 100644 --- a/src/engine/primitives/matricies/Matrix.hpp +++ b/src/engine/primitives/matricies/Matrix.hpp @@ -4,9 +4,7 @@ #pragma once -#define GLM_ENABLE_EXPERIMENTAL #include -#include #include "MatrixEvolvedTypes.hpp" diff --git a/src/engine/primitives/rotation/QuatRotation.cpp b/src/engine/primitives/rotation/QuatRotation.cpp index 93667cf..bbaeeac 100644 --- a/src/engine/primitives/rotation/QuatRotation.cpp +++ b/src/engine/primitives/rotation/QuatRotation.cpp @@ -102,4 +102,19 @@ namespace fgl::engine *this = q * *this; } + glm::quat QuatRotation::internal_quat() const + { + return *this; + } + + bool QuatRotation::operator==( const QuatRotation& rot ) const + { + return static_cast< glm::quat >( *this ) == static_cast< glm::quat >( rot ); + } + + bool operator==( const QuatRotation& rot, const glm::quat& quat ) + { + return static_cast< glm::quat >( rot ) == quat; + } + } // namespace fgl::engine diff --git a/src/engine/primitives/rotation/QuatRotation.hpp b/src/engine/primitives/rotation/QuatRotation.hpp index 09eb60a..6572408 100644 --- a/src/engine/primitives/rotation/QuatRotation.hpp +++ b/src/engine/primitives/rotation/QuatRotation.hpp @@ -4,12 +4,13 @@ #pragma once -#include -#include - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#pragma GCC diagnostic ignored "-Wduplicated-branches" #define GLM_ENABLE_EXPERIMENTAL #include -#include +#include +#pragma GCC diagnostic pop #include "engine/primitives/matricies/RotationMatrix.hpp" #include "engine/primitives/vectors/NormalVector.hpp" @@ -52,20 +53,14 @@ namespace fgl::engine void addZWorld( float ); // internal - inline glm::quat internal_quat() const { return *this; } + glm::quat internal_quat() const; - bool operator==( const QuatRotation& rot ) const - { - return static_cast< glm::quat >( *this ) == static_cast< glm::quat >( rot ); - } + bool operator==( const QuatRotation& rot ) const; friend bool operator==( const QuatRotation&, const glm::quat& ); }; - inline bool operator==( const QuatRotation& rot, const glm::quat& quat ) - { - return static_cast< glm::quat >( rot ) == quat; - } + bool operator==( const QuatRotation& rot, const glm::quat& quat ); namespace constants { diff --git a/src/engine/primitives/rotation/UniversalRotation.cpp b/src/engine/primitives/rotation/UniversalRotation.cpp index 1eadd55..29e1498 100644 --- a/src/engine/primitives/rotation/UniversalRotation.cpp +++ b/src/engine/primitives/rotation/UniversalRotation.cpp @@ -6,7 +6,51 @@ namespace fgl::engine { - UniversalRotation UniversalRotation::pointAt( const glm::vec3 vec ) + UniversalRotation::UniversalRotation() : e_rotation( constants::DEFAULT_ROTATION ), m_euler( true ) + {} + + UniversalRotation::UniversalRotation( const EulerRotation e_rotation_in ) : + e_rotation( e_rotation_in ), + m_euler( true ) + {} + + UniversalRotation::UniversalRotation( const QuatRotation q_rotation_in ) : + q_rotation( q_rotation_in ), + m_euler( false ) + {} + + QuatRotation UniversalRotation::forcedQuat() const + { + if ( m_euler ) [[unlikely]] + return e_rotation.toRotation(); + return q_rotation; + } + + EulerRotation& UniversalRotation::euler() + { + FGL_ASSERT( isEuler(), "Rotation is not euler" ); + return e_rotation; + } + + const EulerRotation& UniversalRotation::euler() const + { + FGL_ASSERT( isEuler(), "Rotation is not euler" ); + return e_rotation; + } + + QuatRotation& UniversalRotation::quat() + { + FGL_ASSERT( isQuat(), "Rotation is not quat" ); + return q_rotation; + } + + const QuatRotation& UniversalRotation::quat() const + { + FGL_ASSERT( isQuat(), "Rotation is not quat" ); + return q_rotation; + } + + UniversalRotation UniversalRotation::pointIn( const glm::vec3 vec ) { return UniversalRotation( QuatRotation( glm::normalize( vec ) ) ); } diff --git a/src/engine/primitives/rotation/UniversalRotation.hpp b/src/engine/primitives/rotation/UniversalRotation.hpp index 1bd8204..2c155df 100644 --- a/src/engine/primitives/rotation/UniversalRotation.hpp +++ b/src/engine/primitives/rotation/UniversalRotation.hpp @@ -13,69 +13,47 @@ namespace fgl::engine union { QuatRotation q_rotation; - EulerRotation e_rotation { constants::DEFAULT_ROTATION }; + EulerRotation e_rotation; }; - //! If true then the rotation is in a - bool m_euler { true }; + //! If true then the rotation is a euler rotation + bool m_euler; public: - [[nodiscard]] UniversalRotation() : e_rotation( constants::DEFAULT_ROTATION ), m_euler( true ) {} + [[nodiscard]] UniversalRotation(); - [[nodiscard]] UniversalRotation( const EulerRotation& euler ) : e_rotation( euler ) {} + [[nodiscard]] UniversalRotation( EulerRotation e_rotation_in ); - [[nodiscard]] UniversalRotation( const QuatRotation& q_rotation ) : q_rotation( q_rotation ) {} + [[nodiscard]] UniversalRotation( QuatRotation q_rotation_in ); FGL_DEFAULT_MOVE( UniversalRotation ); FGL_DEFAULT_COPY( UniversalRotation ); - NormalVector forward() const { return forcedQuat().forward(); } + [[nodiscard]] NormalVector forward() const { return forcedQuat().forward(); } - NormalVector right() const { return forcedQuat().right(); } + [[nodiscard]] NormalVector right() const { return forcedQuat().right(); } - NormalVector up() const { return forcedQuat().up(); } + [[nodiscard]] NormalVector up() const { return forcedQuat().up(); } - inline bool isEuler() const { return m_euler; } + [[nodiscard]] bool isEuler() const { return m_euler; } - inline bool isQuat() const { return !isEuler(); } + [[nodiscard]] bool isQuat() const { return !isEuler(); } //! Returns a quaternion rotation no matter the original rotation - FGL_HOT [[nodiscard]] QuatRotation forcedQuat() const - { - if ( m_euler ) [[unlikely]] - return e_rotation.toRotation(); - else [[likely]] - return q_rotation; - } + [[nodiscard]] QuatRotation forcedQuat() const; // Marked cold because it's only usd in the editor - FGL_COLD EulerRotation& euler() - { - FGL_ASSERT( isEuler(), "Rotation is not euler" ); - return e_rotation; - } + [[nodiscard]] EulerRotation& euler(); // Marked cold because it's only usd in the editor - FGL_COLD const EulerRotation& euler() const - { - FGL_ASSERT( isEuler(), "Rotation is not euler" ); - return e_rotation; - } + [[nodiscard]] const EulerRotation& euler() const; - FGL_HOT QuatRotation& quat() - { - FGL_ASSERT( isQuat(), "Rotation is not quat" ); - return q_rotation; - } + [[nodiscard]] QuatRotation& quat(); - FGL_HOT const QuatRotation& quat() const - { - FGL_ASSERT( isQuat(), "Rotation is not quat" ); - return q_rotation; - } + [[nodiscard]] const QuatRotation& quat() const; - static UniversalRotation pointAt( const glm::vec3 vec ); + [[nodiscard]] static UniversalRotation pointIn( glm::vec3 vec ); // Universal modification void addX( float value ); diff --git a/src/engine/rendering/PresentSwapChain.hpp b/src/engine/rendering/PresentSwapChain.hpp index 838a5d2..f751423 100644 --- a/src/engine/rendering/PresentSwapChain.hpp +++ b/src/engine/rendering/PresentSwapChain.hpp @@ -88,7 +88,7 @@ namespace fgl::engine [[nodiscard]] PresentIndex imageCount() const { - return static_cast< std::uint16_t >( m_swap_chain_images.size() ); + return static_cast< PresentIndex >( m_swap_chain_images.size() ); } [[nodiscard]] vk::Extent2D getSwapChainExtent() const { return m_swapchain_extent; } diff --git a/src/engine/rendering/Renderer.cpp b/src/engine/rendering/Renderer.cpp index 72882a8..708f93a 100644 --- a/src/engine/rendering/Renderer.cpp +++ b/src/engine/rendering/Renderer.cpp @@ -259,7 +259,7 @@ namespace fgl::engine throw std::runtime_error( "Failed to submit commmand buffer" ); is_frame_started = false; - current_frame_idx = static_cast< std::uint16_t >( ( current_frame_idx + 1 ) % constants::MAX_FRAMES_IN_FLIGHT ); + current_frame_idx = static_cast< FrameIndex >( ( current_frame_idx + 1 ) % constants::MAX_FRAMES_IN_FLIGHT ); } void Renderer::setViewport( const CommandBuffer& buffer ) diff --git a/src/engine/rendering/devices/Device.hpp b/src/engine/rendering/devices/Device.hpp index 5e5c9f2..bd32f73 100644 --- a/src/engine/rendering/devices/Device.hpp +++ b/src/engine/rendering/devices/Device.hpp @@ -11,7 +11,11 @@ #include "engine/rendering/Surface.hpp" #include "extensions.hpp" #include "rendering/CommandBufferPool.hpp" -#include "vma/vma_impl.hpp" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wundef" +#include +#pragma GCC diagnostic pop namespace fgl::engine { diff --git a/src/engine/rendering/pipelines/shaders/Compiler.cpp b/src/engine/rendering/pipelines/shaders/Compiler.cpp index 32684b3..7160859 100644 --- a/src/engine/rendering/pipelines/shaders/Compiler.cpp +++ b/src/engine/rendering/pipelines/shaders/Compiler.cpp @@ -6,9 +6,18 @@ #include #include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wuseless-cast" +#pragma GCC diagnostic ignored "-Wredundant-tags" +#pragma GCC diagnostic ignored "-Wcast-qual" +#pragma GCC diagnostic ignored "-Weffc++" #include #include -#include +#pragma GCC diagnostic pop #include "engine/FGL_DEFINES.hpp" #include "engine/constants.hpp" @@ -125,7 +134,7 @@ namespace fgl::engine // Add the source directory to search paths const auto source_dir = path.parent_path().string(); - std::array< const char*, 2 > search_paths = { search_path_str.c_str(), source_dir.c_str() }; + std::array< const char*, 2 > search_paths = { { search_path_str.c_str(), source_dir.c_str() } }; session_desc.searchPaths = search_paths.data(); session_desc.searchPathCount = search_paths.size(); diff --git a/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp b/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp index 1d97014..cc642d7 100644 --- a/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp +++ b/src/engine/rendering/pipelines/v2/PipelineBuilder.cpp @@ -25,7 +25,7 @@ namespace fgl::engine SetID max_set_idx { 0 }; - for ( const auto& [ set_idx, _ ] : m_state->descriptor_set_layouts ) + for ( const auto& set_idx : m_state->descriptor_set_layouts | std::views::keys ) { max_set_idx = std::max( max_set_idx, set_idx ); } @@ -74,14 +74,14 @@ namespace fgl::engine m_state->m_dynamic_state.emplace_back( dynamic_state ); } - void PipelineBuilder::setPushConstant( const vk::ShaderStageFlags flags, std::uint32_t size ) + void PipelineBuilder::setPushConstant( const vk::ShaderStageFlags flags, const std::uint32_t size ) { m_state->push_constant.offset = 0; m_state->push_constant.size = size; m_state->push_constant.stageFlags = flags; } - void PipelineBuilder::setBindPoint( vk::PipelineBindPoint bind_point ) + void PipelineBuilder::setBindPoint( const vk::PipelineBindPoint bind_point ) { m_state->bind_point = bind_point; } @@ -96,7 +96,9 @@ namespace fgl::engine return color_blend_attachment.back(); } - PipelineBuilder::BuilderState::BuilderState( std::uint32_t subpass ) : m_subpass_stage( subpass ) + PipelineBuilder::BuilderState::BuilderState( const std::uint32_t subpass ) : + m_subpass_stage( subpass ), + bind_point( vk::PipelineBindPoint::eGraphics ) { setDefault(); } @@ -270,13 +272,15 @@ namespace fgl::engine return pipeline; } - vk::raii::Pipeline PipelineBuilder::createDynamicPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) + vk::raii::Pipeline PipelineBuilder:: + createDynamicPipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ) { if ( state.shaders.compute ) return createComputePipeline( state, layout ); return createGraphicsPipeline( state, layout ); } - vk::raii::Pipeline PipelineBuilder::createComputePipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) + vk::raii::Pipeline PipelineBuilder:: + createComputePipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ) { vk::StructureChain< vk::ComputePipelineCreateInfo > chain {}; @@ -295,7 +299,8 @@ namespace fgl::engine return Device::getInstance()->createComputePipeline( VK_NULL_HANDLE, info ); } - vk::raii::Pipeline PipelineBuilder::createGraphicsPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ) + vk::raii::Pipeline PipelineBuilder:: + createGraphicsPipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ) { vk::StructureChain< vk::GraphicsPipelineCreateInfo, vk::PipelineRenderingCreateInfo > chain {}; vk::GraphicsPipelineCreateInfo& info { chain.get< vk::GraphicsPipelineCreateInfo >() }; @@ -357,12 +362,12 @@ namespace fgl::engine return pipeline; } - vk::raii::Pipeline PipelineBuilder::createFromState( BuilderState& state, vk::raii::PipelineLayout& layout ) + vk::raii::Pipeline PipelineBuilder::createFromState( BuilderState& state, const vk::raii::PipelineLayout& layout ) { return createDynamicPipeline( state, layout ); } - vk::raii::Pipeline PipelineBuilder::rebuildFromState( BuilderState& state, vk::raii::PipelineLayout& layout ) + vk::raii::Pipeline PipelineBuilder::rebuildFromState( BuilderState& state, const vk::raii::PipelineLayout& layout ) { auto& shaders { state.shaders }; diff --git a/src/engine/rendering/pipelines/v2/PipelineBuilder.hpp b/src/engine/rendering/pipelines/v2/PipelineBuilder.hpp index 2198a2c..3e3c26f 100644 --- a/src/engine/rendering/pipelines/v2/PipelineBuilder.hpp +++ b/src/engine/rendering/pipelines/v2/PipelineBuilder.hpp @@ -135,13 +135,13 @@ namespace fgl::engine static vk::raii::Pipeline createRenderPassPipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ); - static vk::raii::Pipeline createDynamicPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ); + static vk::raii::Pipeline createDynamicPipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ); - static vk::raii::Pipeline createComputePipeline( BuilderState& state, vk::raii::PipelineLayout& layout ); - static vk::raii::Pipeline createGraphicsPipeline( BuilderState& state, vk::raii::PipelineLayout& layout ); + static vk::raii::Pipeline createComputePipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ); + static vk::raii::Pipeline createGraphicsPipeline( BuilderState& state, const vk::raii::PipelineLayout& layout ); - static vk::raii::Pipeline createFromState( BuilderState& state, vk::raii::PipelineLayout& layout ); - static vk::raii::Pipeline rebuildFromState( BuilderState& state, vk::raii::PipelineLayout& layout ); + static vk::raii::Pipeline createFromState( BuilderState& state, const vk::raii::PipelineLayout& layout ); + static vk::raii::Pipeline rebuildFromState( BuilderState& state, const vk::raii::PipelineLayout& layout ); std::unique_ptr< Pipeline > create(); }; diff --git a/src/engine/rendering/types.hpp b/src/engine/rendering/types.hpp index a419b3e..d87635a 100644 --- a/src/engine/rendering/types.hpp +++ b/src/engine/rendering/types.hpp @@ -8,10 +8,10 @@ namespace fgl::engine { - using PresentIndex = std::uint16_t; - using FrameIndex = std::uint16_t; + using PresentIndex = std::uint_fast8_t; + using FrameIndex = std::uint_fast8_t; - using CameraIndex = std::uint16_t; + using CameraIndex = std::uint_fast16_t; using DeltaTime = float; } // namespace fgl::engine diff --git a/src/engine/systems/render/EntityRendererSystem.hpp b/src/engine/systems/render/EntityRendererSystem.hpp index 0b2cd1f..c37c536 100644 --- a/src/engine/systems/render/EntityRendererSystem.hpp +++ b/src/engine/systems/render/EntityRendererSystem.hpp @@ -23,10 +23,10 @@ namespace fgl::engine class EntityRendererSystem { //! Standard pipeline for textureless models - std::unique_ptr< Pipeline > m_standard_pipeline; + std::unique_ptr< Pipeline > m_standard_pipeline {}; //! Pipeline for basic textured models (Single texture) - std::unique_ptr< Pipeline > m_textured_pipeline; + std::unique_ptr< Pipeline > m_textured_pipeline {}; // std::unique_ptr< ComputePipeline > m_cull_pipeline {}; CommandBuffer& setupSystem( const FrameInfo& ); diff --git a/src/engine/systems/render/LineDrawer.cpp b/src/engine/systems/render/LineDrawer.cpp index a061624..6f85596 100644 --- a/src/engine/systems/render/LineDrawer.cpp +++ b/src/engine/systems/render/LineDrawer.cpp @@ -57,7 +57,7 @@ namespace fgl::engine return command_buffer; } - void LineDrawer::pass( FrameInfo& info ) + void LineDrawer::pass( [[maybe_unused]] FrameInfo& info ) { /* ZoneScopedN( "LineDrawer::pass" ); diff --git a/src/engine/systems/render/ShadowRenderer.cpp b/src/engine/systems/render/ShadowRenderer.cpp deleted file mode 100644 index b81bea3..0000000 --- a/src/engine/systems/render/ShadowRenderer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by kj16609 on 2/28/25. -// -#include "ShadowRenderer.hpp" - -#include "FrameInfo.hpp" - -namespace fgl::engine -{ - CommandBuffer& ShadowRenderer::setupSystem( const FrameInfo& info ) - {} - - void ShadowRenderer::pass( FrameInfo& info ) - { - // Render any shadowmaps attach to the camera - auto& command_buffer { setupSystem( info ) }; - - //TODO: Implement object culling for shadowmaps - // if ( draw_commands.empty() ) return; - - m_pipeline->bind( command_buffer ); - } - - ShadowRenderer::ShadowRenderer() - { - PipelineBuilder builder { 0 }; - - builder.setVertexShader( Shader::loadVertex( "shaders/shadowmap.slang" ) ); - - m_pipeline = builder.create(); - m_pipeline->setDebugName( "Shadow map pipeline" ); - } - -} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/systems/render/ShadowRenderer.hpp b/src/engine/systems/render/ShadowRenderer.hpp deleted file mode 100644 index 85a0cbc..0000000 --- a/src/engine/systems/render/ShadowRenderer.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// Created by kj16609 on 2/28/25. -// -#pragma once -#include - -#include "memory/buffers/vector/HostVector.hpp" -#include "rendering/pipelines/v2/Pipeline.hpp" - -namespace fgl::engine -{ - struct FrameInfo; - struct ModelMatrixInfo; - - class ShadowRenderer - { - std::unique_ptr< Pipeline > m_pipeline {}; - - using DrawParameterBuffer = HostVector< vk::DrawIndexedIndirectCommand >; - using DrawIndexedIndirectCommand = HostVector< ModelMatrixInfo >; - - public: - - CommandBuffer& setupSystem( const FrameInfo& info ); - void pass( FrameInfo& info ); - - ShadowRenderer(); - }; - -} // namespace fgl::engine \ No newline at end of file diff --git a/src/objectloaders/CMakeLists.txt b/src/objectloaders/CMakeLists.txt index 529ce64..af25ac3 100644 --- a/src/objectloaders/CMakeLists.txt +++ b/src/objectloaders/CMakeLists.txt @@ -1,3 +1,3 @@ -AddFGLChildLibrary(FGLLoader STATIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) +AddFGLChildLibrary(FGLLoader STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include) #target_include_directories(FGLLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/objectloaders/stb_image.h b/src/objectloaders/include/stb_image.h similarity index 100% rename from src/objectloaders/stb_image.h rename to src/objectloaders/include/stb_image.h diff --git a/src/objectloaders/stb_image_write.h b/src/objectloaders/include/stb_image_write.h similarity index 100% rename from src/objectloaders/stb_image_write.h rename to src/objectloaders/include/stb_image_write.h diff --git a/src/objectloaders/tiny_gltf.h b/src/objectloaders/include/tiny_gltf.h similarity index 99% rename from src/objectloaders/tiny_gltf.h rename to src/objectloaders/include/tiny_gltf.h index d470bf4..2dfe716 100644 --- a/src/objectloaders/tiny_gltf.h +++ b/src/objectloaders/include/tiny_gltf.h @@ -34,6 +34,8 @@ // - base64: base64 decode/encode library. // - stb_image: Image loading library. // + +#pragma once #ifndef TINY_GLTF_H_ #define TINY_GLTF_H_ diff --git a/src/objectloaders/tiny_obj_loader.h b/src/objectloaders/include/tiny_obj_loader.h similarity index 99% rename from src/objectloaders/tiny_obj_loader.h rename to src/objectloaders/include/tiny_obj_loader.h index d3b992f..9e008f6 100644 --- a/src/objectloaders/tiny_obj_loader.h +++ b/src/objectloaders/include/tiny_obj_loader.h @@ -57,6 +57,7 @@ THE SOFTWARE. // #include "tiny_obj_loader.h" // +#pragma once #ifndef TINY_OBJ_LOADER_H_ #define TINY_OBJ_LOADER_H_ @@ -2366,9 +2367,8 @@ namespace tinyobj // flush previous material. if ( !material.name.empty() ) { - material_map->insert( std::pair< - std::string, - int >( material.name, static_cast< int >( materials->size() ) ) ); + material_map->insert( + std::pair< std::string, int >( material.name, static_cast< int >( materials->size() ) ) ); materials->push_back( material ); } diff --git a/src/objectloaders/gltf_impl.cpp b/src/objectloaders/src/gltf_impl.cpp similarity index 96% rename from src/objectloaders/gltf_impl.cpp rename to src/objectloaders/src/gltf_impl.cpp index 37ce602..30ac857 100644 --- a/src/objectloaders/gltf_impl.cpp +++ b/src/objectloaders/src/gltf_impl.cpp @@ -19,5 +19,5 @@ #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION #define TINYGLTF_USE_CPP14 -#include "tiny_gltf.h" +#include "../include/tiny_gltf.h" #pragma GCC diagnostic pop diff --git a/src/objectloaders/json.hpp b/src/objectloaders/src/json.hpp similarity index 99% rename from src/objectloaders/json.hpp rename to src/objectloaders/src/json.hpp index 87475ab..2178876 100644 --- a/src/objectloaders/json.hpp +++ b/src/objectloaders/src/json.hpp @@ -15267,7 +15267,7 @@ class binary_writer static CharType to_char_type(std::uint8_t x) noexcept { static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); - static_assert(std::is_trivial::value, "CharType must be trivial"); + static_assert(std::is_trivially_constructible_v && std::is_trivially_copyable_v, "CharType must be trivial"); CharType result; std::memcpy(&result, &x, sizeof(x)); return result; diff --git a/src/objectloaders/obj_impl.cpp b/src/objectloaders/src/obj_impl.cpp similarity index 90% rename from src/objectloaders/obj_impl.cpp rename to src/objectloaders/src/obj_impl.cpp index 003d746..1f26c46 100644 --- a/src/objectloaders/obj_impl.cpp +++ b/src/objectloaders/src/obj_impl.cpp @@ -9,5 +9,5 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wuseless-cast" #define TINYOBJLOADER_IMPLEMENTATION -#include "tiny_obj_loader.h" +#include "../include/tiny_obj_loader.h" #pragma GCC diagnostic pop \ No newline at end of file diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt deleted file mode 100644 index ee7d4a7..0000000 --- a/src/tests/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -if (NOT DEFINED FGL_ENABLE_TESTS) - set(FGL_ENABLE_TESTS 0) -endif () - - -if (FGL_ENABLE_TESTS) - message("-- FGL_ENABLE_TESTS: Enabled") - enable_testing() - - file(GLOB_RECURSE FGL_TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/**.cpp") - - set(CMAKE_CXX_STANDARD_REQUIRED 23) - - add_executable(FGLTests ${FGL_TEST_SOURCES}) - target_link_libraries(FGLTests PUBLIC FGLEngine) - target_link_libraries(FGLTests PRIVATE Catch2::Catch2WithMain) - target_compile_definitions(FGLTests PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE) - target_compile_features(FGLTests PRIVATE cxx_std_23) - - include(CTest) - include(Catch) - catch_discover_tests(FGLTests) -else () - message("-- FGL_ENABLE_TESTS: Disabled") -endif () \ No newline at end of file diff --git a/src/tests/src/gtest_printers.hpp b/src/tests/src/gtest_printers.hpp deleted file mode 100644 index a3eeba8..0000000 --- a/src/tests/src/gtest_printers.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Created by kj16609 on 2/15/24. -// - -#pragma once - -#define GLM_ENABLE_EXPERIMENTAL -#include -#include -#include - -#include "engine/primitives/Scale.hpp" -#include "engine/primitives/matricies/Matrix.hpp" -#include "engine/primitives/points/Coordinate.hpp" -#include "engine/primitives/rotation/EulerRotation.hpp" -#include "engine/primitives/rotation/QuatRotation.hpp" -#include "engine/primitives/vectors/Vector.hpp" - -namespace Catch -{ - template <> - struct StringMaker< glm::vec3 > - { - static std::string convert( const glm::vec3& vec ) { return glm::to_string( vec ); } - }; - - template <> - struct StringMaker< fgl::engine::Vector > - { - static std::string convert( const fgl::engine::Vector& vec ) - { - return StringMaker< glm::vec3 >::convert( static_cast< glm::vec3 >( vec.vec() ) ); - } - }; - - template <> - struct StringMaker< glm::mat4 > - { - static std::string convert( const glm::mat4& mat ) - { - return "\n\t" + glm::to_string( mat[ 0 ] ) + "\n\t" + glm::to_string( mat[ 1 ] ) + "\n\t" - + glm::to_string( mat[ 2 ] ) + "\n\t" + glm::to_string( mat[ 3 ] ); - } - }; - - template <> - struct StringMaker< glm::quat > - { - static std::string convert( const glm::quat& quat ) - { - return std::format( "({},{},{},{})", quat.w, quat.x, quat.y, quat.z ); - } - }; - - template <> - struct StringMaker< fgl::engine::QuatRotation > - { - static std::string convert( const fgl::engine::QuatRotation& rot ) - { - return StringMaker< glm::quat >::convert( rot.internal_quat() ); - } - }; - - template <> - struct StringMaker< fgl::engine::EulerRotation > - { - static std::string convert( const fgl::engine::EulerRotation& rot ) - { - return StringMaker< glm::vec3 >::convert( glm::vec3( rot.x, rot.y, rot.z ) ); - } - }; - - template < fgl::engine::MatrixType MType > - struct StringMaker< fgl::engine::Matrix< MType > > - { - static std::string convert( const fgl::engine::Matrix< MType >& mat ) - { - return StringMaker< glm::mat4 >::convert( static_cast< glm::mat4 >( mat ) ); - } - }; - - template <> - struct StringMaker< ::fgl::engine::NormalVector > - { - static std::string convert( const fgl::engine::NormalVector vec ) - { - return StringMaker< fgl::engine::Vector >::convert( static_cast< fgl::engine::Vector >( vec ) ); - } - }; - - template <> - struct StringMaker< ::fgl::engine::Scale > - { - static std::string convert( const fgl::engine::Scale scale ) - { - return StringMaker< glm::vec3 >::convert( static_cast< glm::vec3 >( scale ) ); - } - }; - - template <> - struct StringMaker< ::fgl::engine::ModelCoordinate > - { - static std::string convert( const fgl::engine::ModelCoordinate coord ) - { - return StringMaker< glm::vec3 >::convert( coord.vec() ); - } - }; - -} // namespace Catch - -#ifndef NDEBUG -namespace glm -{ - inline bool operator==( const glm::vec3& lhs, const glm::vec3& rhs ) - { - return glm::all( ::glm::epsilonEqual( lhs, rhs, std::numeric_limits< float >::epsilon() ) ); - } - -} // namespace glm -#else -#warning "Debug mode not enabled. Tests will fail when checking for floating point equality." -#endif -- 2.49.1 From e6371069fb9da1aecd381ccac3cd47b0a9676f34 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 29 Sep 2025 05:30:32 -0400 Subject: [PATCH 12/22] Fixes ImGui Texture --- src/engine/assets/texture/Texture.cpp | 28 ++++++++++++++++++--------- src/engine/assets/texture/Texture.hpp | 7 +++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/engine/assets/texture/Texture.cpp b/src/engine/assets/texture/Texture.cpp index 2f98107..9b35925 100644 --- a/src/engine/assets/texture/Texture.cpp +++ b/src/engine/assets/texture/Texture.cpp @@ -76,7 +76,7 @@ namespace fgl::engine const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) }; - ImGui::Image( getImGuiDescriptorSet(), imgui_size ); + ImGui::Image( getImGuiTexture(), imgui_size ); } bool Texture::drawImGuiButton( vk::Extent2D extent ) @@ -98,7 +98,7 @@ namespace fgl::engine const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) }; - return ImGui::ImageButton( m_name.c_str(), getImGuiDescriptorSet(), imgui_size ); + return ImGui::ImageButton( m_name.c_str(), getImGuiTexture(), imgui_size ); } Texture::Texture( std::tuple< std::vector< std::byte >, int, int, vk::Format, Sampler > tuple ) : @@ -176,6 +176,23 @@ namespace fgl::engine return m_image_view->descriptorInfo( vk::ImageLayout::eGeneral ); } + ImTextureRef Texture::createImGuiTexture() const + { + const ImTextureRef ref { m_imgui_set }; + + return ref; + } + + ImTextureRef Texture::getImGuiTexture() const + { + if ( !m_imgui_texture.has_value() ) + { + m_imgui_texture = createImGuiTexture(); + } + + return m_imgui_texture.value(); + } + vk::Extent2D Texture::getExtent() const { return m_image_view->getExtent(); @@ -208,13 +225,6 @@ namespace fgl::engine m_imgui_set = ImGui_ImplVulkan_AddTexture( vk_sampler, vk_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ); } - vk::DescriptorSet& Texture::getImGuiDescriptorSet() - { - assert( ready() ); - assert( m_imgui_set != VK_NULL_HANDLE ); - return m_imgui_set; - } - Texture::Texture( const std::shared_ptr< Image >& image, Sampler&& sampler ) : m_texture_id( texture_id_pool.getID() ), m_image( image ), diff --git a/src/engine/assets/texture/Texture.hpp b/src/engine/assets/texture/Texture.hpp index 8290a53..59abc29 100644 --- a/src/engine/assets/texture/Texture.hpp +++ b/src/engine/assets/texture/Texture.hpp @@ -61,7 +61,8 @@ namespace fgl::engine vk::Extent2D m_extent; //! Descriptor set used for displaying the texture in ImGui - vk::DescriptorSet m_imgui_set { VK_NULL_HANDLE }; + mutable vk::DescriptorSet m_imgui_set { VK_NULL_HANDLE }; + mutable std::optional< ImTextureRef > m_imgui_texture { std::nullopt }; std::string m_name; @@ -111,7 +112,9 @@ namespace fgl::engine const std::string& getName() const { return m_name; } [[nodiscard]] vk::DescriptorImageInfo getDescriptor() const; - [[nodiscard]] vk::DescriptorSet& getImGuiDescriptorSet(); + [[nodiscard]] ImTextureRef createImGuiTexture() const; + // [[nodiscard]] vk::DescriptorSet& getImGuiDescriptorSet(); + [[nodiscard]] ImTextureRef getImGuiTexture() const; [[nodiscard]] vk::Extent2D getExtent() const; -- 2.49.1 From a414b8afef81d6379a63f3f8378b56f07bca36de Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 29 Sep 2025 05:35:50 -0400 Subject: [PATCH 13/22] Remove some submodules --- dependencies/SPIRV-Headers | 1 - dependencies/SPIRV-Tools | 1 - dependencies/shaderc | 1 - 3 files changed, 3 deletions(-) delete mode 160000 dependencies/SPIRV-Headers delete mode 160000 dependencies/SPIRV-Tools delete mode 160000 dependencies/shaderc diff --git a/dependencies/SPIRV-Headers b/dependencies/SPIRV-Headers deleted file mode 160000 index 2a611a9..0000000 --- a/dependencies/SPIRV-Headers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2a611a970fdbc41ac2e3e328802aed9985352dca diff --git a/dependencies/SPIRV-Tools b/dependencies/SPIRV-Tools deleted file mode 160000 index 33e0256..0000000 --- a/dependencies/SPIRV-Tools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 33e02568181e3312f49a3cf33df470bf96ef293a diff --git a/dependencies/shaderc b/dependencies/shaderc deleted file mode 160000 index 7374358..0000000 --- a/dependencies/shaderc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 73743588fe9c39f2f1c780a087d94afac691a189 -- 2.49.1 From 82519b43c1ca11c60f6c8fab51e7365b2a8ad767 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 29 Sep 2025 11:11:34 -0400 Subject: [PATCH 14/22] Fixes X11 issues --- cmake_modules/dependencies/blurhash.cmake | 2 -- cmake_modules/dependencies/glfw.cmake | 20 ++++++++------------ cmake_modules/dependencies/gtest.cmake | 11 ----------- cmake_modules/dependencies/lz4.cmake | 11 ----------- cmake_modules/dependencies/qt.cmake | 13 ------------- src/editor/CMakeLists.txt | 2 +- 6 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 cmake_modules/dependencies/blurhash.cmake delete mode 100644 cmake_modules/dependencies/gtest.cmake delete mode 100644 cmake_modules/dependencies/lz4.cmake delete mode 100644 cmake_modules/dependencies/qt.cmake diff --git a/cmake_modules/dependencies/blurhash.cmake b/cmake_modules/dependencies/blurhash.cmake deleted file mode 100644 index 4f23ec7..0000000 --- a/cmake_modules/dependencies/blurhash.cmake +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/blurhash) -set_target_properties(BlurhashCXX PROPERTIES COMPILE_FLAGS ${FGL_FLAGS}) \ No newline at end of file diff --git a/cmake_modules/dependencies/glfw.cmake b/cmake_modules/dependencies/glfw.cmake index c9abe48..3022dc3 100644 --- a/cmake_modules/dependencies/glfw.cmake +++ b/cmake_modules/dependencies/glfw.cmake @@ -3,18 +3,14 @@ set(GLFW_BUILD_X11 ON) set(GLFW_BUILD_WAYLAND OFF) -#if (WIN32) - if (DEFINED ENV{GLFW_PATH}) - message("-- GLFW_PATH defined as: $ENV{GLFW_PATH}.") - list(APPEND CMAKE_PREFIX_PATH $ENV{GLFW_PATH}) - find_package(glfw3 REQUIRED) - else () - message("-- GLFW_PATH not defined. Using submodule instead") - add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/glfw3) - endif () -#else () -# find_package(glfw3 REQUIRED) -#endif () +if (DEFINED ENV{GLFW_PATH}) + message("-- GLFW_PATH defined as: $ENV{GLFW_PATH}.") + list(APPEND CMAKE_PREFIX_PATH $ENV{GLFW_PATH}) + find_package(glfw3 REQUIRED) +else () + message("-- GLFW_PATH not defined. Using submodule instead") + add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/glfw3) +endif () set(GLFW_BUILD_X11 ON) set(GLFW_BUILD_WAYLAND OFF) diff --git a/cmake_modules/dependencies/gtest.cmake b/cmake_modules/dependencies/gtest.cmake deleted file mode 100644 index bdb60af..0000000 --- a/cmake_modules/dependencies/gtest.cmake +++ /dev/null @@ -1,11 +0,0 @@ - - -include(FetchContent) -include(FetchContent) -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) \ No newline at end of file diff --git a/cmake_modules/dependencies/lz4.cmake b/cmake_modules/dependencies/lz4.cmake deleted file mode 100644 index 329fa60..0000000 --- a/cmake_modules/dependencies/lz4.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set(LZ4_DIR ${CMAKE_SOURCE_DIR}/dependencies/lz4/lib) - -file(GLOB_RECURSE LZ4_SOURCES ${LZ4_DIR}/*.c) - -add_library(lz4 STATIC ${LZ4_SOURCES}) -target_include_directories(lz4 PUBLIC ${LZ4_DIR}) - -if (WIN32) - #target_compile_definitions(${CMAKE_SOURCE_DIR}/dependencies/lz4 PRIVATE UNICODE=1) - target_compile_definitions(lz4 PRIVATE LZ4_DEBUG=0) -endif () \ No newline at end of file diff --git a/cmake_modules/dependencies/qt.cmake b/cmake_modules/dependencies/qt.cmake deleted file mode 100644 index 6421e6a..0000000 --- a/cmake_modules/dependencies/qt.cmake +++ /dev/null @@ -1,13 +0,0 @@ -#Verify after setting QT_PATH -if (DEFINED QT_PATH) - message("-- QT_PATH defined as ${QT_PATH}.") - list(APPEND CMAKE_PREFIX_PATH ${QT_PATH}) -else () - message("-- QT_PATH not defined.") -endif () - -find_package(Qt6 COMPONENTS Widgets Core Concurrent Network Test Charts REQUIRED) - -set(CMAKE_AUTOUIC ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index 05b285c..1bdeef2 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -14,4 +14,4 @@ AddFGLExecutable(TitorEditor ${CMAKE_CURRENT_SOURCE_DIR}/src) target_link_libraries(TitorEditor PRIVATE FGLEngine) target_compile_definitions(TitorEditor PUBLIC TITOR_EDITOR) target_compile_features(TitorEditor PRIVATE cxx_std_23) -target_link_libraries(TitorEditor PRIVATE glfw ImGui) +target_link_libraries(TitorEditor PRIVATE glfw ImGui X11) -- 2.49.1 From ba22b5213ef630ca455a27cd55501a4297cee052 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 2 Oct 2025 17:53:29 -0400 Subject: [PATCH 15/22] Removes -fmodules-ts from compiler flags --- dependencies/libFGL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/libFGL b/dependencies/libFGL index 7274f88..71fab92 160000 --- a/dependencies/libFGL +++ b/dependencies/libFGL @@ -1 +1 @@ -Subproject commit 7274f88c6f2a698f68f18e90c6cb5df5652c0e60 +Subproject commit 71fab926e03b4f5e3740e88db882095af150f427 -- 2.49.1 From 18f92409337076687bd02764c12048c35341fd6b Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 2 Oct 2025 17:53:44 -0400 Subject: [PATCH 16/22] Uses bitfields instead of masking for vk version info --- src/editor/src/main.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/editor/src/main.cpp b/src/editor/src/main.cpp index 3dd594c..4f52096 100644 --- a/src/editor/src/main.cpp +++ b/src/editor/src/main.cpp @@ -23,20 +23,17 @@ int main() // major 7-bit, bits 28-22 // minor, 10 bit, 21-12 // patch, 12 bit, 10-0 - // clang-format off - constexpr std::uint64_t PATCH_BITMASK { 0b00000000000000000000111111111111 }; - constexpr std::uint64_t MINOR_BITMASK { 0b00000000001111111111000000000000 }; - constexpr std::uint64_t MAJOR_BITMASK { 0b00011111110000000000000000000000 }; - constexpr std::uint64_t VARIANT_BITMASK { 0b11100000000000000000000000000000 }; + struct VersionBits + { + unsigned int patch:12; + unsigned int minor:10; + unsigned int major:7; + unsigned int variant:3; + }; - const auto patch { ( version & PATCH_BITMASK ) >> 0}; - const auto minor { ( version & MINOR_BITMASK ) >> 10}; - const auto major { ( version & MAJOR_BITMASK ) >> (10 + 12)}; - [[maybe_unused]] const auto variant { ( version & VARIANT_BITMASK ) >> (10 + 12 + 7) }; + const auto [ patch, minor, major, variant ] { static_cast< VersionBits >( version ) }; - // clang-format on - - log::debug( "Vulkan instance version: {}.{}.{}.{}", major, minor, patch, minor ); + log::debug( "Vulkan instance version: {}.{}.{}.{}", major, minor, patch, variant ); try { -- 2.49.1 From 2dfbec09363ada5d4b3aaae14ef6cf18ad1f499e Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 2 Oct 2025 17:55:43 -0400 Subject: [PATCH 17/22] Remove -fmodules-ts from compile flags --- dependencies/libFGL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/libFGL b/dependencies/libFGL index 71fab92..0b0158e 160000 --- a/dependencies/libFGL +++ b/dependencies/libFGL @@ -1 +1 @@ -Subproject commit 71fab926e03b4f5e3740e88db882095af150f427 +Subproject commit 0b0158e0137c60bc826622c4faaa15248b7483f4 -- 2.49.1 From 9a9f2f5a5e06461c2ba672e58b7394c06960886c Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 2 Oct 2025 18:12:49 -0400 Subject: [PATCH 18/22] use bitfield instead of mask for getting vk version --- src/editor/src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/editor/src/main.cpp b/src/editor/src/main.cpp index 4f52096..881d0ac 100644 --- a/src/editor/src/main.cpp +++ b/src/editor/src/main.cpp @@ -31,9 +31,14 @@ int main() unsigned int variant:3; }; - const auto [ patch, minor, major, variant ] { static_cast< VersionBits >( version ) }; + const auto* version_ptr { reinterpret_cast< const VersionBits* >( &version ) }; - log::debug( "Vulkan instance version: {}.{}.{}.{}", major, minor, patch, variant ); + log::debug( + "Vulkan instance version: {}.{}.{}.{}", + version_ptr->major, + version_ptr->minor, + version_ptr->patch, + version_ptr->variant ); try { -- 2.49.1 From 4f0f7ad585d47edb0f3d4c8dbe35dd69bd705332 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Thu, 2 Oct 2025 18:13:01 -0400 Subject: [PATCH 19/22] Fix some unneeded includes --- src/engine/systems/prerender/CullingSystem.hpp | 2 -- src/engine/systems/render/EntityRendererSystem.cpp | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/engine/systems/prerender/CullingSystem.hpp b/src/engine/systems/prerender/CullingSystem.hpp index 4d937f3..1ea10c5 100644 --- a/src/engine/systems/prerender/CullingSystem.hpp +++ b/src/engine/systems/prerender/CullingSystem.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #include "engine/systems/concepts.hpp" #include "rendering/pipelines/v2/Pipeline.hpp" diff --git a/src/engine/systems/render/EntityRendererSystem.cpp b/src/engine/systems/render/EntityRendererSystem.cpp index bdda447..0f2d5bf 100644 --- a/src/engine/systems/render/EntityRendererSystem.cpp +++ b/src/engine/systems/render/EntityRendererSystem.cpp @@ -7,14 +7,12 @@ #include #include -#include "EngineContext.hpp" +#include "assets/model/Model.hpp" #include "assets/model/ModelVertex.hpp" -#include "engine/assets/material/Material.hpp" -#include "engine/camera/RenderCamera.hpp" -#include "engine/debug/timing/FlameGraph.hpp" -#include "engine/rendering/pipelines/v2/Pipeline.hpp" -#include "engine/rendering/pipelines/v2/PipelineBuilder.hpp" -#include "memory/buffers/BufferHandle.hpp" +#include "camera/RenderCamera.hpp" +#include "debug/timing/FlameGraph.hpp" +#include "rendering/pipelines/v2/Pipeline.hpp" +#include "rendering/pipelines/v2/PipelineBuilder.hpp" namespace fgl::engine { -- 2.49.1 From 88027f157c1b001115da71b18a79c6d74872c604 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sat, 11 Oct 2025 07:00:21 -0400 Subject: [PATCH 20/22] Render graph work --- src/engine/EngineContext.cpp | 5 + src/engine/FGL_DEFINES.hpp | 44 +++++---- src/engine/FrameInfo.hpp | 2 + src/engine/assets/image/Sampler.cpp | 17 ++++ src/engine/assets/image/Sampler.hpp | 28 +++--- src/engine/assets/model/ModelInstanceInfo.hpp | 1 + .../assets/transfer/TransferManager.hpp | 1 + src/engine/descriptors/DescriptorSet.hpp | 1 + .../descriptors/DescriptorSetLayout.cpp | 1 + .../memory/buffers/BufferSuballocation.cpp | 1 + .../memory/buffers/BufferSuballocation.hpp | 1 - .../buffers/UniqueFrameSuballocation.hpp | 1 + .../rendering/pipelines/v2/Pipeline.cpp | 2 + .../rendering/pipelines/v2/Pipeline.hpp | 2 +- src/engine/systems/RenderGraph.cpp | 92 +++++++++++++++++++ src/engine/systems/RenderGraph.hpp | 90 ++++++++++++++++++ .../systems/render/EntityRendererSystem.cpp | 21 ++++- 17 files changed, 274 insertions(+), 36 deletions(-) create mode 100644 src/engine/systems/RenderGraph.cpp create mode 100644 src/engine/systems/RenderGraph.hpp diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index fb5984b..2f7cbc2 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -22,6 +22,7 @@ #include "engine/math/Average.hpp" #include "engine/math/literals/size.hpp" #include "memory/buffers/BufferHandle.hpp" +#include "systems/RenderGraph.hpp" namespace fgl::engine { @@ -105,6 +106,9 @@ namespace fgl::engine void EngineContext::renderFrame() { ZoneScoped; + + RenderGraph graph {}; + if ( auto command_buffers_o = m_renderer.beginFrame(); command_buffers_o.has_value() ) { const auto timer = debug::timing::push( "Render Frame" ); @@ -119,6 +123,7 @@ namespace fgl::engine FrameInfo frame_info { in_flight_idx, present_idx, m_delta_time, + graph, command_buffers, nullptr, // Camera m_camera_manager.getCameras(), diff --git a/src/engine/FGL_DEFINES.hpp b/src/engine/FGL_DEFINES.hpp index 3eade49..b4439c7 100644 --- a/src/engine/FGL_DEFINES.hpp +++ b/src/engine/FGL_DEFINES.hpp @@ -4,25 +4,37 @@ #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_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 ) + 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_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 ) + 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 ) ) ) diff --git a/src/engine/FrameInfo.hpp b/src/engine/FrameInfo.hpp index 2203702..66996e1 100644 --- a/src/engine/FrameInfo.hpp +++ b/src/engine/FrameInfo.hpp @@ -21,6 +21,7 @@ namespace fgl::engine { + class RenderGraph; class CameraViewpoint; struct PrimitiveRenderInfo; struct PrimitiveInstanceInfo; @@ -79,6 +80,7 @@ namespace fgl::engine FrameIndex in_flight_idx; PresentIndex present_idx; DeltaTime delta_time; + RenderGraph& graph; CommandBuffers& command_buffer; diff --git a/src/engine/assets/image/Sampler.cpp b/src/engine/assets/image/Sampler.cpp index 3708808..d0c8866 100644 --- a/src/engine/assets/image/Sampler.cpp +++ b/src/engine/assets/image/Sampler.cpp @@ -56,6 +56,23 @@ namespace fgl::engine m_sampler( createSampler( min_filter, mag_filter, mipmap_mode, sampler_wrap_u, sampler_wrap_v, sampler_wrap_w ) ) {} + Sampler::Sampler( + const vk::Filter min_filter, + const vk::Filter mag_filter, + const vk::SamplerMipmapMode mipmap_mode, + const vk::SamplerAddressMode sampler_wrap_u, + const vk::SamplerAddressMode sampler_wrap_v ) : + Sampler( min_filter, mag_filter, mipmap_mode, sampler_wrap_u, sampler_wrap_v, sampler_wrap_v ) + {} + + Sampler::Sampler( + const vk::Filter min_filter, + const vk::Filter mag_filter, + const vk::SamplerMipmapMode mipmap_mode, + const vk::SamplerAddressMode sampler_wrap_u ) : + Sampler( min_filter, mag_filter, mipmap_mode, sampler_wrap_u, sampler_wrap_u, sampler_wrap_u ) + {} + namespace gl { vk::Filter filterToVk( const int value ) diff --git a/src/engine/assets/image/Sampler.hpp b/src/engine/assets/image/Sampler.hpp index b5e7956..69df2e2 100644 --- a/src/engine/assets/image/Sampler.hpp +++ b/src/engine/assets/image/Sampler.hpp @@ -18,7 +18,7 @@ namespace fgl::engine public: - FGL_DELETE_COPY( Sampler ) + FGL_DELETE_COPY( Sampler ); Sampler() : Sampler( @@ -36,22 +36,18 @@ namespace fgl::engine vk::SamplerAddressMode sampler_wrap_v, vk::SamplerAddressMode sampler_wrap_w ); - FGL_FORCE_INLINE_FLATTEN Sampler( - const vk::Filter min_filter, - const vk::Filter mag_filter, - const vk::SamplerMipmapMode mipmap_mode, - const vk::SamplerAddressMode sampler_wrap_u, - const vk::SamplerAddressMode sampler_wrap_v ) : - Sampler( min_filter, mag_filter, mipmap_mode, sampler_wrap_u, sampler_wrap_v, sampler_wrap_v ) - {} + Sampler( + vk::Filter min_filter, + vk::Filter mag_filter, + vk::SamplerMipmapMode mipmap_mode, + vk::SamplerAddressMode sampler_wrap_u, + vk::SamplerAddressMode sampler_wrap_v ); - FGL_FORCE_INLINE_FLATTEN Sampler( - const vk::Filter min_filter, - const vk::Filter mag_filter, - const vk::SamplerMipmapMode mipmap_mode, - const vk::SamplerAddressMode sampler_wrap_u ) : - Sampler( min_filter, mag_filter, mipmap_mode, sampler_wrap_u, sampler_wrap_u, sampler_wrap_u ) - {} + Sampler( + vk::Filter min_filter, + vk::Filter mag_filter, + vk::SamplerMipmapMode mipmap_mode, + vk::SamplerAddressMode sampler_wrap_u ); //TODO: This should be moved to favor a single sampler when possible, Making a duplicate sampler is not required. //TODO: Singleton diff --git a/src/engine/assets/model/ModelInstanceInfo.hpp b/src/engine/assets/model/ModelInstanceInfo.hpp index b219a94..d9be334 100644 --- a/src/engine/assets/model/ModelInstanceInfo.hpp +++ b/src/engine/assets/model/ModelInstanceInfo.hpp @@ -2,6 +2,7 @@ // Created by kj16609 on 4/5/25. // #pragma once +#include "constants.hpp" #include "memory/buffers/vector/IndexedVector.hpp" namespace fgl::engine diff --git a/src/engine/assets/transfer/TransferManager.hpp b/src/engine/assets/transfer/TransferManager.hpp index 749b691..736df16 100644 --- a/src/engine/assets/transfer/TransferManager.hpp +++ b/src/engine/assets/transfer/TransferManager.hpp @@ -14,6 +14,7 @@ namespace fgl::engine { + class CommandBuffer; class Image; class Device; diff --git a/src/engine/descriptors/DescriptorSet.hpp b/src/engine/descriptors/DescriptorSet.hpp index 2cb17d2..80c7cbd 100644 --- a/src/engine/descriptors/DescriptorSet.hpp +++ b/src/engine/descriptors/DescriptorSet.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include diff --git a/src/engine/descriptors/DescriptorSetLayout.cpp b/src/engine/descriptors/DescriptorSetLayout.cpp index 3bb6193..a30a605 100644 --- a/src/engine/descriptors/DescriptorSetLayout.cpp +++ b/src/engine/descriptors/DescriptorSetLayout.cpp @@ -6,6 +6,7 @@ #include "DescriptorSet.hpp" #include "engine/debug/logging/logging.hpp" +#include "rendering/devices/Device.hpp" namespace fgl::engine::descriptors { diff --git a/src/engine/memory/buffers/BufferSuballocation.cpp b/src/engine/memory/buffers/BufferSuballocation.cpp index 53cb9de..d6372f8 100644 --- a/src/engine/memory/buffers/BufferSuballocation.cpp +++ b/src/engine/memory/buffers/BufferSuballocation.cpp @@ -8,6 +8,7 @@ #include "SuballocationView.hpp" #include "align.hpp" #include "engine/debug/logging/logging.hpp" +#include "rendering/devices/Device.hpp" namespace fgl::engine::memory { diff --git a/src/engine/memory/buffers/BufferSuballocation.hpp b/src/engine/memory/buffers/BufferSuballocation.hpp index 1f85816..ee1b200 100644 --- a/src/engine/memory/buffers/BufferSuballocation.hpp +++ b/src/engine/memory/buffers/BufferSuballocation.hpp @@ -6,7 +6,6 @@ #include "BufferSuballocationHandle.hpp" #include "debug/Track.hpp" -#include "engine/rendering/devices/Device.hpp" namespace fgl::engine::memory { diff --git a/src/engine/memory/buffers/UniqueFrameSuballocation.hpp b/src/engine/memory/buffers/UniqueFrameSuballocation.hpp index 35e9408..2cb5fb7 100644 --- a/src/engine/memory/buffers/UniqueFrameSuballocation.hpp +++ b/src/engine/memory/buffers/UniqueFrameSuballocation.hpp @@ -4,6 +4,7 @@ #pragma once +#include "constants.hpp" #include "engine/concepts/is_suballocation.hpp" namespace fgl::engine diff --git a/src/engine/rendering/pipelines/v2/Pipeline.cpp b/src/engine/rendering/pipelines/v2/Pipeline.cpp index 0c2a692..7b18963 100644 --- a/src/engine/rendering/pipelines/v2/Pipeline.cpp +++ b/src/engine/rendering/pipelines/v2/Pipeline.cpp @@ -8,6 +8,8 @@ #include "engine/debug/logging/logging.hpp" #include "engine/descriptors/DescriptorSet.hpp" #include "engine/flags.hpp" +#include "rendering/CommandBufferPool.hpp" +#include "rendering/devices/Device.hpp" namespace fgl::engine { diff --git a/src/engine/rendering/pipelines/v2/Pipeline.hpp b/src/engine/rendering/pipelines/v2/Pipeline.hpp index 1fd4969..d4bfed9 100644 --- a/src/engine/rendering/pipelines/v2/Pipeline.hpp +++ b/src/engine/rendering/pipelines/v2/Pipeline.hpp @@ -6,9 +6,9 @@ #include "PipelineBuilder.hpp" #include "engine/descriptors/DescriptorSet.hpp" +#include "rendering/CommandBufferPool.hpp" namespace fgl::engine - { namespace descriptors { diff --git a/src/engine/systems/RenderGraph.cpp b/src/engine/systems/RenderGraph.cpp new file mode 100644 index 0000000..f951ca1 --- /dev/null +++ b/src/engine/systems/RenderGraph.cpp @@ -0,0 +1,92 @@ +// +// Created by kj16609 on 10/2/25. +// +#include "RenderGraph.hpp" + +namespace fgl::engine +{ + + void RenderGraph::submitInfo( AttachmentInfo&& attachment_info ) + { + m_queue.emplace( attachment_info ); + // m_current->m_infos.emplace_back( std::forward< AttachmentInfo >( attachment_info ) ); + } + + void RenderGraph::transformAttachment( const AttachmentInfo& value, CommandBuffer& command_buffer ) + { + const auto& itter { m_attachment_state.find( value.m_name ) }; + + if ( itter == m_attachment_state.end() ) + throw std:: + runtime_error( std::format( "Failed to find an attachment state for attachment {}", value.m_name ) ); + + AttachmentState& state { itter->second }; + + const bool needs_layout_change { state.current_layout != value.m_layout }; + const bool dont_care_load { + value.m_loadOp != vk::AttachmentLoadOp::eDontCare + }; // We don't care about anything that happens to this attachment before this point + const bool clear_load { value.m_loadOp + == vk::AttachmentLoadOp::eClear }; // We need to clear this attachment before we use it + + vk::ImageMemoryBarrier barrier { + state.m_image->transitionTo( state.current_layout, value.m_layout, state.aspect_flags ) + }; + + m_image_barriers.emplace_back( barrier ); + } + + void RenderGraph::push() + { + // auto new_node { std::make_unique< Node >() }; + // auto& itter { m_current->m_children.emplace_back( std::move( new_node ) ) }; + // m_current = itter.get(); + } + + void RenderGraph::pop() + { + // m_current = m_current->m_parent; + } + + void RenderGraph::addAttachmentInput( const std::string& image_name, const vk::ImageLayout desired_layout ) + { + AttachmentInfo attachment_info { .m_name = image_name, + .m_layout = desired_layout, + .m_loadOp = vk::AttachmentLoadOp::eLoad, + .m_storeOp = vk::AttachmentStoreOp::eDontCare }; + + submitInfo( std::move( attachment_info ) ); + } + + void RenderGraph::addAttachmentOutput( const std::string& image_name, const vk::ImageLayout desired_layout ) + { + AttachmentInfo attachment_info { .m_name = image_name, + .m_layout = desired_layout, + .m_loadOp = vk::AttachmentLoadOp::eDontCare, + .m_storeOp = vk::AttachmentStoreOp::eStore }; + + submitInfo( std::move( attachment_info ) ); + } + + void RenderGraph::addAttachmentMutable( const std::string& image_name, const vk::ImageLayout desired_layout ) + { + AttachmentInfo attachment_info { .m_name = image_name, + .m_layout = desired_layout, + .m_loadOp = vk::AttachmentLoadOp::eLoad, + .m_storeOp = vk::AttachmentStoreOp::eStore }; + + submitInfo( std::move( attachment_info ) ); + } + + void RenderGraph::flush( const CommandBuffer& command_buffer ) + { + while ( !m_queue.empty() ) + { + auto itter = m_queue.back(); + m_queue.pop(); + + transformAttachment( itter, command_buffer ); + } + } + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/systems/RenderGraph.hpp b/src/engine/systems/RenderGraph.hpp new file mode 100644 index 0000000..19a7ca1 --- /dev/null +++ b/src/engine/systems/RenderGraph.hpp @@ -0,0 +1,90 @@ +// +// Created by kj16609 on 10/2/25. +// +#pragma once + +#include +#include +#include +#include + +#include "assets/model/Model.hpp" + +namespace vk +{ + enum class AttachmentStoreOp; + enum class AttachmentLoadOp; + enum class Format; +} // namespace vk + +namespace fgl::engine +{ + + using AttachmentImage = std::shared_ptr< Image >; + using AttachmentImageView = std::shared_ptr< ImageView >; + + struct AttachmentInfo + { + std::string m_name; + + //! The format we want to be in for this moment + vk::ImageLayout m_layout; + vk::AttachmentLoadOp m_loadOp; + vk::AttachmentStoreOp m_storeOp; + }; + + struct AttachmentState : AttachmentInfo + { + AttachmentImage m_image; + AttachmentImageView m_view; + + vk::ImageLayout current_layout; + + vk::ImageAspectFlags aspect_flags; + }; + + class RenderGraph + { + struct Node + { + using Variant = std::variant< AttachmentInfo >; + Node* m_parent { nullptr }; + std::vector< std::unique_ptr< Node > > m_children {}; + + std::vector< Variant > m_infos {}; + }; + + std::unordered_map< std::string, AttachmentState > m_attachment_state {}; + + std::queue< AttachmentInfo > m_queue {}; + + std::vector< vk::ImageMemoryBarrier > m_image_barriers {}; + std::vector< vk::BufferMemoryBarrier > m_buffer_barriers {}; + + // //TODO: Allocator + // std::unique_ptr< Node > m_root {}; + // Node* m_current {}; + + void submitInfo( AttachmentInfo&& attachment_info ); + + void transformAttachment( const AttachmentInfo& value, CommandBuffer& command_buffer ); + + public: + + friend class RenderGraph; + + void push(); + void pop(); + + void addAttachmentInput( const std::string& image_name, vk::ImageLayout desired_layout ); + void addAttachmentOutput( const std::string& image_name, vk::ImageLayout desired_layout ); + + //! Adds an attachment that will be used as an input and output + void addAttachmentMutable( const std::string& image_name, vk::ImageLayout desired_layout ); + + void registerBuffer( const std::string& str, const memory::BufferSuballocation& value ); + void addBufferDependency( std::string buffer_name ); + void flush( const 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 0f2d5bf..5887a6f 100644 --- a/src/engine/systems/render/EntityRendererSystem.cpp +++ b/src/engine/systems/render/EntityRendererSystem.cpp @@ -13,6 +13,7 @@ #include "debug/timing/FlameGraph.hpp" #include "rendering/pipelines/v2/Pipeline.hpp" #include "rendering/pipelines/v2/PipelineBuilder.hpp" +#include "systems/RenderGraph.hpp" namespace fgl::engine { @@ -78,8 +79,24 @@ 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" ); + + // info.graph.registerBuffer( "MODEL_INSTANCES", info.camera->m_generated_instance_info[ info.in_flight_idx ] ); + + // info.graph.addBufferDependency( "MODEL_INSTANCES" ); + // compute shader + info.graph.flush( command_buffer ); + m_textured_pipeline->bind( command_buffer ); m_textured_pipeline->bindDescriptor( command_buffer, info.getCameraDescriptor() ); @@ -89,8 +106,8 @@ namespace fgl::engine auto& model_buffers { getModelBuffers() }; const std::vector< vk::Buffer > vert_buffers { - model_buffers.m_vertex_buffer->getVkBuffer(), - info.camera->m_generated_instance_info[ info.in_flight_idx ].getVkBuffer(), + model_buffers.m_vertex_buffer->getVkBuffer(), // VERTEX_BUFFER + info.camera->m_generated_instance_info[ info.in_flight_idx ].getVkBuffer(), // MODEL_INSTANCES }; command_buffer->bindVertexBuffers( -- 2.49.1 From 32ed28b5aedda0fc9f20f6be7e75ebbcd45eeb79 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sun, 23 Nov 2025 03:32:14 -0500 Subject: [PATCH 21/22] bumps libFGL --- dependencies/libFGL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/libFGL b/dependencies/libFGL index 0b0158e..fac5494 160000 --- a/dependencies/libFGL +++ b/dependencies/libFGL @@ -1 +1 @@ -Subproject commit 0b0158e0137c60bc826622c4faaa15248b7483f4 +Subproject commit fac5494bee70dfc1b436bf57b70e152a0ba31632 -- 2.49.1 From d848080d5e8769f614920f02191b3218197f9d6c Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 15 Dec 2025 19:56:18 -0500 Subject: [PATCH 22/22] update --- .gitmodules | 5 +- CMakeLists.txt | 2 - cmake_modules/dependencies/vulkan.cmake | 34 +++++++ src/CMakeLists.txt | 6 +- src/editor/CMakeLists.txt | 2 + src/editor/src/gui/drawStats.cpp | 2 +- src/editor/src/gui/safe_include.hpp | 3 +- src/engine/CMakeLists.txt | 22 +---- src/engine/EngineContext.cpp | 2 +- src/engine/FGL_DEFINES.hpp | 98 ------------------- src/engine/FrameInfo.hpp | 1 + src/engine/assets/AssetManager.hpp | 1 + src/engine/assets/MaterialManager.cpp | 2 +- src/engine/assets/MaterialManager.hpp | 2 +- src/engine/assets/image/ImageHandle.hpp | 2 +- src/engine/assets/material/Material.cpp | 12 +-- src/engine/assets/model/Model.hpp | 4 +- src/engine/assets/model/ModelVertex.cpp | 21 ++-- src/engine/assets/model/SimpleVertex.cpp | 6 +- src/engine/assets/model/VertexAttribute.hpp | 2 +- .../assets/model/builders/ModelBuilder.hpp | 2 +- .../assets/model/builders/SceneBuilder.hpp | 2 +- src/engine/assets/texture/Texture.cpp | 2 - src/engine/assets/texture/Texture.hpp | 2 + src/engine/assets/transfer/TransferData.cpp | 2 +- src/engine/assets/transfer/TransferData.hpp | 4 +- .../assets/transfer/TransferManager.cpp | 10 +- .../assets/transfer/TransferManager.hpp | 1 + src/engine/camera/CameraManager.hpp | 2 +- src/engine/camera/CameraViewpoint.cpp | 1 + src/engine/camera/GBufferSwapchain.cpp | 2 + src/engine/debug/timing/FlameGraph.cpp | 6 -- src/engine/descriptors/DescriptorSet.hpp | 6 ++ src/engine/gameobjects/components/drawers.cpp | 8 +- src/engine/gameobjects/components/drawers.hpp | 2 +- .../memory/buffers/BufferSuballocation.hpp | 2 +- .../buffers/BufferSuballocationHandle.cpp | 2 +- .../buffers/BufferSuballocationHandle.hpp | 4 +- .../{BufferHandle.cpp => VulkanBuffer.cpp} | 59 ++++++----- .../{BufferHandle.hpp => VulkanBuffer.hpp} | 41 ++++---- .../memory/buffers/vector/BufferVector.cpp | 4 +- src/engine/memory/vma_impl.cpp | 6 ++ src/engine/memory/vma_impl.hpp | 6 ++ src/engine/rendering/CommandBufferPool.hpp | 1 + src/engine/rendering/PresentSwapChain.cpp | 2 +- src/engine/rendering/PresentSwapChain.hpp | 2 +- src/engine/rendering/devices/Device.cpp | 21 +--- src/engine/rendering/devices/Device.hpp | 6 +- src/engine/systems/RenderGraph.cpp | 2 +- src/engine/systems/RenderGraph.hpp | 4 +- .../systems/render/EntityRendererSystem.cpp | 4 +- .../systems/render/EntityRendererSystem.hpp | 2 +- src/renderer/CMakeLists.txt | 37 +++++++ src/renderer/src/FGLRenderSurface.cpp | 9 ++ src/renderer/src/FGLRenderSurface.hpp | 20 ++++ src/renderer/src/FGLRenderer.cpp | 18 ++++ src/renderer/src/FGLRenderer.hpp | 32 ++++++ src/renderer/src/surfaces/Surface.hpp | 16 +++ .../src/surfaces/glfw/GLFWRenderSurface.cpp | 52 ++++++++++ .../src/surfaces/glfw/GLFWRenderSurface.hpp | 41 ++++++++ src/renderer/src/vulkan/Vulkan.cpp | 85 ++++++++++++++++ src/renderer/src/vulkan/Vulkan.hpp | 33 +++++++ src/renderer/src/vulkan/VulkanAllocator.cpp | 4 + src/renderer/src/vulkan/VulkanAllocator.hpp | 20 ++++ src/renderer/src/vulkan/VulkanDevice.cpp | 11 +++ src/renderer/src/vulkan/VulkanDevice.hpp | 20 ++++ .../src/vulkan/VulkanPhysicalDevice.cpp | 9 ++ .../src/vulkan/VulkanPhysicalDevice.hpp | 20 ++++ src/renderer/tests/CMakeLists.txt | 2 + src/renderer/tests/main.cpp | 14 +++ src/vma/CMakeLists.txt | 5 - src/vma/vma_impl.cpp | 6 -- src/vma/vma_impl.hpp | 24 ----- 73 files changed, 627 insertions(+), 300 deletions(-) delete mode 100644 src/engine/FGL_DEFINES.hpp rename src/engine/memory/buffers/{BufferHandle.cpp => VulkanBuffer.cpp} (88%) rename src/engine/memory/buffers/{BufferHandle.hpp => VulkanBuffer.hpp} (78%) create mode 100644 src/engine/memory/vma_impl.cpp create mode 100644 src/engine/memory/vma_impl.hpp create mode 100644 src/renderer/CMakeLists.txt create mode 100644 src/renderer/src/FGLRenderSurface.cpp create mode 100644 src/renderer/src/FGLRenderSurface.hpp create mode 100644 src/renderer/src/FGLRenderer.cpp create mode 100644 src/renderer/src/FGLRenderer.hpp create mode 100644 src/renderer/src/surfaces/Surface.hpp create mode 100644 src/renderer/src/surfaces/glfw/GLFWRenderSurface.cpp create mode 100644 src/renderer/src/surfaces/glfw/GLFWRenderSurface.hpp create mode 100644 src/renderer/src/vulkan/Vulkan.cpp create mode 100644 src/renderer/src/vulkan/Vulkan.hpp create mode 100644 src/renderer/src/vulkan/VulkanAllocator.cpp create mode 100644 src/renderer/src/vulkan/VulkanAllocator.hpp create mode 100644 src/renderer/src/vulkan/VulkanDevice.cpp create mode 100644 src/renderer/src/vulkan/VulkanDevice.hpp create mode 100644 src/renderer/src/vulkan/VulkanPhysicalDevice.cpp create mode 100644 src/renderer/src/vulkan/VulkanPhysicalDevice.hpp create mode 100644 src/renderer/tests/CMakeLists.txt create mode 100644 src/renderer/tests/main.cpp delete mode 100644 src/vma/CMakeLists.txt delete mode 100644 src/vma/vma_impl.cpp delete mode 100644 src/vma/vma_impl.hpp 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 -- 2.49.1