Fixes a bunch of validation errors
This commit is contained in:
2
dependencies/tracy
vendored
2
dependencies/tracy
vendored
Submodule dependencies/tracy updated: a17c218351...0c6803e5c6
@@ -139,6 +139,9 @@ namespace fgl::engine
|
||||
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
//Trash handling
|
||||
descriptors::deleteQueuedDescriptors();
|
||||
}
|
||||
|
||||
Window& EngineContext::getWindow()
|
||||
@@ -189,7 +192,7 @@ namespace fgl::engine
|
||||
renderFrame();
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
// std::this_thread::sleep_for( 13ms );
|
||||
// std::this_thread::sleep_for( 13ms );
|
||||
}
|
||||
|
||||
Device::getInstance().device().waitIdle();
|
||||
|
||||
@@ -121,6 +121,7 @@ namespace fgl::engine
|
||||
void Camera::remakeSwapchain( vk::Extent2D extent )
|
||||
{
|
||||
this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE );
|
||||
m_old_swapchain = m_swapchain;
|
||||
m_swapchain = std::make_shared< CameraSwapchain >( camera_renderer->getRenderpass(), extent );
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ namespace fgl::engine
|
||||
// Camera info is expected at binding 0
|
||||
std::vector< descriptors::DescriptorSet > m_camera_info_descriptors {};
|
||||
|
||||
// TODO: Remove this old swapchain and instead do a proper deffered cleanup of it.
|
||||
std::shared_ptr< CameraSwapchain > m_old_swapchain { nullptr };
|
||||
std::shared_ptr< CameraSwapchain > m_swapchain;
|
||||
|
||||
std::string name;
|
||||
|
||||
@@ -127,4 +127,12 @@ namespace fgl::engine
|
||||
gbuffer.depth.setName( "Depth" );
|
||||
}
|
||||
|
||||
CameraSwapchain::~CameraSwapchain()
|
||||
{
|
||||
for ( auto& descriptor : m_gbuffer_descriptor_set )
|
||||
{
|
||||
descriptors::queueDescriptorDeletion( std::move( descriptor ) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -46,6 +46,7 @@ namespace fgl::engine
|
||||
public:
|
||||
|
||||
CameraSwapchain( vk::raii::RenderPass& renderpass, vk::Extent2D extent );
|
||||
~CameraSwapchain();
|
||||
|
||||
const std::vector< vk::ClearValue >& getClearValues();
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
||||
#include "DescriptorPool.hpp"
|
||||
#include "engine/buffers/BufferSuballocation.hpp"
|
||||
#include "engine/image/ImageView.hpp"
|
||||
#include "engine/rendering/SwapChain.hpp"
|
||||
#include "engine/texture/Texture.hpp"
|
||||
|
||||
namespace fgl::engine::descriptors
|
||||
@@ -117,6 +119,9 @@ namespace fgl::engine::descriptors
|
||||
reset();
|
||||
}
|
||||
|
||||
DescriptorSet::~DescriptorSet()
|
||||
{}
|
||||
|
||||
void DescriptorSet::reset()
|
||||
{
|
||||
m_infos.clear();
|
||||
@@ -165,4 +170,27 @@ namespace fgl::engine::descriptors
|
||||
|
||||
Device::getInstance().setDebugUtilsObjectName( info );
|
||||
}
|
||||
|
||||
inline static std::vector< std::pair< std::uint_fast8_t, std::unique_ptr< DescriptorSet > > > queue {};
|
||||
|
||||
void queueDescriptorDeletion( std::unique_ptr< DescriptorSet > set )
|
||||
{
|
||||
queue.emplace_back( std::make_pair( 0, std::move( set ) ) );
|
||||
}
|
||||
|
||||
void deleteQueuedDescriptors()
|
||||
{
|
||||
for ( auto itter = queue.begin(); itter != queue.end(); itter = itter++ )
|
||||
{
|
||||
auto& [ counter, set ] = *itter;
|
||||
// Prevent deleting a descriptor until we are sure it's been here long enough
|
||||
if ( counter > SwapChain::MAX_FRAMES_IN_FLIGHT + 1 )
|
||||
{
|
||||
itter = queue.erase( itter );
|
||||
}
|
||||
else
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fgl::engine::descriptors
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <variant>
|
||||
|
||||
#include "engine/buffers/BufferSuballocation.hpp"
|
||||
#include "engine/rendering/types.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -62,6 +63,8 @@ namespace fgl::engine::descriptors
|
||||
DescriptorSet( DescriptorSet&& other ) noexcept;
|
||||
DescriptorSet& operator=( DescriptorSet&& other ) noexcept;
|
||||
|
||||
~DescriptorSet();
|
||||
|
||||
void bindImage(
|
||||
std::uint32_t binding_idx,
|
||||
ImageView& view,
|
||||
@@ -81,4 +84,9 @@ namespace fgl::engine::descriptors
|
||||
void setName( const std::string& str );
|
||||
};
|
||||
|
||||
//! Queues a descriptor to be deleted.
|
||||
//
|
||||
void queueDescriptorDeletion( std::unique_ptr< DescriptorSet > set );
|
||||
void deleteQueuedDescriptors();
|
||||
|
||||
} // namespace fgl::engine::descriptors
|
||||
@@ -112,7 +112,7 @@ namespace fgl::engine
|
||||
}
|
||||
|
||||
std::shared_ptr< Model > Model::createModelFromVerts(
|
||||
std::vector< Vertex > verts,
|
||||
std::vector< ModelVertex > verts,
|
||||
std::vector< std::uint32_t > indicies,
|
||||
memory::Buffer& vertex_buffer,
|
||||
memory::Buffer& index_buffer )
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Primitive.hpp"
|
||||
#include "engine/primitives/TransformComponent.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -58,14 +57,14 @@ namespace fgl::engine
|
||||
|
||||
std::vector< Primitive > m_primitives {};
|
||||
|
||||
std::vector< vk::DrawIndexedIndirectCommand > getDrawCommand( const std::uint32_t index ) const;
|
||||
std::vector< vk::DrawIndexedIndirectCommand > getDrawCommand( std::uint32_t index ) const;
|
||||
|
||||
//TODO: Switch to using shared_ptr instead of unique_ptr
|
||||
static std::shared_ptr< Model > createModel(
|
||||
const std::filesystem::path& path, memory::Buffer& vertex_buffer, memory::Buffer& index_buffer );
|
||||
|
||||
static std::shared_ptr< Model > createModelFromVerts(
|
||||
std::vector< Vertex > verts,
|
||||
std::vector< ModelVertex > verts,
|
||||
std::vector< std::uint32_t > indicies,
|
||||
memory::Buffer& vertex_buffer,
|
||||
memory::Buffer& index_buffer );
|
||||
@@ -73,13 +72,11 @@ namespace fgl::engine
|
||||
const std::string& getName() const { return m_name; }
|
||||
|
||||
Model(
|
||||
ModelBuilder& builder,
|
||||
const OrientedBoundingBox< CoordinateSpace::Model > bounding_box,
|
||||
std::string name = {} );
|
||||
ModelBuilder& builder, OrientedBoundingBox< CoordinateSpace::Model > bounding_box, std::string name = {} );
|
||||
|
||||
Model(
|
||||
std::vector< Primitive >&& primitives,
|
||||
const OrientedBoundingBox< CoordinateSpace::Model > bounding_box,
|
||||
OrientedBoundingBox< CoordinateSpace::Model > bounding_box,
|
||||
std::string name = {} );
|
||||
|
||||
~Model() = default;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by kj16609 on 2/5/24.
|
||||
//
|
||||
|
||||
#include "Vertex.hpp"
|
||||
#include "ModelVertex.hpp"
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#pragma GCC diagnostic push
|
||||
@@ -18,30 +18,33 @@
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
bool Vertex::operator==( const Vertex& other ) const
|
||||
bool ModelVertex::operator==( const ModelVertex& other ) const
|
||||
{
|
||||
return m_position == other.m_position && m_color == other.m_color && m_normal == other.m_normal
|
||||
&& m_uv == other.m_uv;
|
||||
}
|
||||
|
||||
std::vector< vk::VertexInputBindingDescription > Vertex::getBindingDescriptions()
|
||||
std::vector< vk::VertexInputBindingDescription > ModelVertex::getBindingDescriptions()
|
||||
{
|
||||
std::vector< vk::VertexInputBindingDescription > binding_descriptions {
|
||||
{ 0, sizeof( Vertex ), vk::VertexInputRate::eVertex },
|
||||
{ 0, sizeof( ModelVertex ), vk::VertexInputRate::eVertex },
|
||||
{ 1, sizeof( ModelMatrixInfo ), vk::VertexInputRate::eInstance }
|
||||
};
|
||||
|
||||
return binding_descriptions;
|
||||
}
|
||||
|
||||
std::vector< vk::VertexInputAttributeDescription > Vertex::getAttributeDescriptions()
|
||||
std::vector< vk::VertexInputAttributeDescription > ModelVertex::getAttributeDescriptions()
|
||||
{
|
||||
std::vector< vk::VertexInputAttributeDescription > attribute_descriptions {};
|
||||
std::vector< vk::VertexInputAttributeDescription > attribute_descriptions {
|
||||
SimpleVertex::getAttributeDescriptions()
|
||||
};
|
||||
|
||||
attribute_descriptions.emplace_back( 0, 0, vk::Format::eR32G32B32Sfloat, offsetof( Vertex, m_position ) );
|
||||
attribute_descriptions.emplace_back( 1, 0, vk::Format::eR32G32B32Sfloat, offsetof( Vertex, m_color ) );
|
||||
attribute_descriptions.emplace_back( 2, 0, vk::Format::eR32G32B32Sfloat, offsetof( Vertex, m_normal ) );
|
||||
attribute_descriptions.emplace_back( 3, 0, vk::Format::eR32G32Sfloat, offsetof( Vertex, m_uv ) );
|
||||
// {location, binding, format, offset}
|
||||
// attribute_descriptions.emplace_back( 0, 0, vk::Format::eR32G32B32Sfloat, offsetof( ModelVertex, m_position ) );
|
||||
// attribute_descriptions.emplace_back( 1, 0, vk::Format::eR32G32B32Sfloat, offsetof( ModelVertex, m_color ) );
|
||||
attribute_descriptions.emplace_back( 2, 0, vk::Format::eR32G32B32Sfloat, offsetof( ModelVertex, m_normal ) );
|
||||
attribute_descriptions.emplace_back( 3, 0, vk::Format::eR32G32Sfloat, offsetof( ModelVertex, m_uv ) );
|
||||
|
||||
//Normal Matrix
|
||||
attribute_descriptions.emplace_back( 4, 1, vk::Format::eR32G32B32A32Sfloat, 0 );
|
||||
@@ -49,13 +52,10 @@ namespace fgl::engine
|
||||
attribute_descriptions.emplace_back( 6, 1, vk::Format::eR32G32B32A32Sfloat, 2 * sizeof( glm::vec4 ) );
|
||||
attribute_descriptions.emplace_back( 7, 1, vk::Format::eR32G32B32A32Sfloat, 3 * sizeof( glm::vec4 ) );
|
||||
|
||||
attribute_descriptions.emplace_back( 8, 1, vk::Format::eR32Uint, 4 * sizeof( glm::vec4 ) );
|
||||
attribute_descriptions.emplace_back( 9, 1, vk::Format::eR32Uint, 5 * sizeof( glm::vec4 ) );
|
||||
attribute_descriptions.emplace_back( 10, 1, vk::Format::eR32Uint, 6 * sizeof( glm::vec4 ) );
|
||||
|
||||
static_assert(
|
||||
4 * sizeof( glm::vec4 ) + sizeof( unsigned int ) + sizeof( unsigned int ) + sizeof( unsigned int )
|
||||
== sizeof( ModelMatrixInfo ) );
|
||||
attribute_descriptions.emplace_back( 8, 1, vk::Format::eR32Uint, offsetof( ModelMatrixInfo, albedo_id ) );
|
||||
attribute_descriptions.emplace_back( 9, 1, vk::Format::eR32Uint, offsetof( ModelMatrixInfo, normal_id ) );
|
||||
attribute_descriptions
|
||||
.emplace_back( 10, 1, vk::Format::eR32Uint, offsetof( ModelMatrixInfo, metallic_roughness ) );
|
||||
|
||||
return attribute_descriptions;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace fgl::engine
|
||||
|
||||
namespace std
|
||||
{
|
||||
std::size_t hash< fgl::engine::Vertex >::operator()( const fgl::engine::Vertex& vertex ) const
|
||||
std::size_t hash< fgl::engine::ModelVertex >::operator()( const fgl::engine::ModelVertex& vertex ) const
|
||||
{
|
||||
std::size_t seed { 0 };
|
||||
fgl::engine::hashCombine( seed, vertex.m_position, vertex.m_color, vertex.m_normal, vertex.m_uv );
|
||||
@@ -12,19 +12,18 @@
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "SimpleVertex.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
struct Vertex
|
||||
struct ModelVertex : public SimpleVertex
|
||||
{
|
||||
glm::vec3 m_position { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 m_color { 1.0f, 1.0f, 1.0f };
|
||||
glm::vec3 m_normal { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec2 m_uv { 0.0f, 0.0f };
|
||||
|
||||
Vertex( const glm::vec3 pos, const glm::vec3 color, const glm::vec3 norm, const glm::vec2 uv ) noexcept :
|
||||
m_position( pos ),
|
||||
m_color( color ),
|
||||
ModelVertex( const glm::vec3 pos, const glm::vec3 color, const glm::vec3 norm, const glm::vec2 uv ) noexcept :
|
||||
SimpleVertex( pos, color ),
|
||||
m_normal( norm ),
|
||||
m_uv( uv )
|
||||
{}
|
||||
@@ -32,20 +31,22 @@ namespace fgl::engine
|
||||
static std::vector< vk::VertexInputBindingDescription > getBindingDescriptions();
|
||||
static std::vector< vk::VertexInputAttributeDescription > getAttributeDescriptions();
|
||||
|
||||
Vertex() noexcept = default;
|
||||
ModelVertex() noexcept = default;
|
||||
|
||||
bool operator==( const Vertex& other ) const;
|
||||
bool operator==( const ModelVertex& other ) const;
|
||||
};
|
||||
|
||||
static_assert( offsetof( ModelVertex, m_normal ) > offsetof( SimpleVertex, m_color ) );
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
struct hash< fgl::engine::Vertex >
|
||||
struct hash< fgl::engine::ModelVertex >
|
||||
{
|
||||
std::size_t operator()( const fgl::engine::Vertex& vertex ) const;
|
||||
std::size_t operator()( const fgl::engine::ModelVertex& vertex ) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
@@ -8,7 +8,7 @@ namespace fgl::engine
|
||||
{
|
||||
|
||||
Primitive Primitive::fromVerts(
|
||||
const std::vector< Vertex >&& verts,
|
||||
const std::vector< ModelVertex >&& verts,
|
||||
const PrimitiveMode mode,
|
||||
const std::vector< std::uint32_t >&& indicies,
|
||||
memory::Buffer& vertex_buffer,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "Vertex.hpp"
|
||||
#include "ModelVertex.hpp"
|
||||
#include "engine/buffers/vector/DeviceVector.hpp"
|
||||
#include "engine/primitives/CoordinateSpace.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
using VertexBufferSuballocation = DeviceVector< Vertex >;
|
||||
using VertexBufferSuballocation = DeviceVector< ModelVertex >;
|
||||
|
||||
using IndexBufferSuballocation = DeviceVector< std::uint32_t >;
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace fgl::engine
|
||||
Primitive( Primitive&& other ) = default;
|
||||
|
||||
static Primitive fromVerts(
|
||||
const std::vector< Vertex >&& verts,
|
||||
const std::vector< ModelVertex >&& verts,
|
||||
PrimitiveMode mode,
|
||||
const std::vector< std::uint32_t >&& indicies,
|
||||
memory::Buffer& vertex_buffer,
|
||||
|
||||
29
src/engine/model/SimpleVertex.cpp
Normal file
29
src/engine/model/SimpleVertex.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by kj16609 on 8/12/24.
|
||||
//
|
||||
|
||||
#include "SimpleVertex.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ModelVertex.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
std::vector< vk::VertexInputBindingDescription > SimpleVertex::getBindingDescriptions()
|
||||
{
|
||||
// {buffer_idx, stride, rate}
|
||||
return { { 0, sizeof( SimpleVertex ), vk::VertexInputRate::eVertex } };
|
||||
}
|
||||
|
||||
std::vector< vk::VertexInputAttributeDescription > SimpleVertex::getAttributeDescriptions()
|
||||
{
|
||||
// {location, binding, format, offset}
|
||||
return {
|
||||
{ 0, 0, vk::Format::eR32G32B32Sfloat, offsetof( SimpleVertex, m_position ) },
|
||||
{ 1, 0, vk::Format::eR32G32B32Sfloat, offsetof( SimpleVertex, m_color ) },
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
32
src/engine/model/SimpleVertex.hpp
Normal file
32
src/engine/model/SimpleVertex.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by kj16609 on 8/12/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vk
|
||||
{
|
||||
struct VertexInputAttributeDescription;
|
||||
struct VertexInputBindingDescription;
|
||||
}
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
struct SimpleVertex
|
||||
{
|
||||
glm::vec3 m_position { 0.0f };
|
||||
glm::vec3 m_color { 1.0f };
|
||||
|
||||
SimpleVertex() = default;
|
||||
|
||||
SimpleVertex( const glm::vec3 pos, const glm::vec3 color ) : m_position( pos ), m_color( color ) {}
|
||||
|
||||
static std::vector< vk::VertexInputBindingDescription > getBindingDescriptions();
|
||||
static std::vector< vk::VertexInputAttributeDescription > getAttributeDescriptions();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace fgl::engine
|
||||
throw std::runtime_error( "Unknown model file extension" );
|
||||
}
|
||||
|
||||
void ModelBuilder::loadVerts( std::vector< Vertex > verts, std::vector< std::uint32_t > indicies )
|
||||
void ModelBuilder::loadVerts( std::vector< ModelVertex > verts, std::vector< std::uint32_t > indicies )
|
||||
{
|
||||
ZoneScoped;
|
||||
VertexBufferSuballocation vertex_suballoc { this->m_vertex_buffer, verts };
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
struct Vertex;
|
||||
struct ModelVertex;
|
||||
struct Primitive;
|
||||
|
||||
namespace memory
|
||||
@@ -36,7 +36,7 @@ namespace fgl::engine
|
||||
void loadModel( const std::filesystem::path& filepath );
|
||||
void loadObj( const std::filesystem::path& filepath );
|
||||
void loadGltf( const std::filesystem::path& filepath );
|
||||
void loadVerts( std::vector< Vertex > verts, std::vector< std::uint32_t > indicies );
|
||||
void loadVerts( std::vector< ModelVertex > verts, std::vector< std::uint32_t > indicies );
|
||||
};
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -272,14 +272,14 @@ namespace fgl::engine
|
||||
return prim.attributes.contains( std::string( str ) );
|
||||
}
|
||||
|
||||
std::vector< Vertex > SceneBuilder::
|
||||
std::vector< ModelVertex > SceneBuilder::
|
||||
extractVertexInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
log::debug( "Extracting vert info" );
|
||||
const auto pos { extractPositionInfo( prim, root ) };
|
||||
|
||||
std::vector< Vertex > verts {};
|
||||
std::vector< ModelVertex > verts {};
|
||||
|
||||
verts.reserve( pos.size() );
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace fgl::engine
|
||||
|
||||
for ( std::size_t i = 0; i < pos.size(); ++i )
|
||||
{
|
||||
Vertex vert {};
|
||||
ModelVertex vert {};
|
||||
vert.m_position = pos[ i ];
|
||||
vert.m_normal = has_normals ? normals[ i ] : glm::vec3();
|
||||
vert.m_uv = has_uv ? uvs[ i ] : glm::vec2();
|
||||
@@ -347,7 +347,7 @@ namespace fgl::engine
|
||||
[[fallthrough]];
|
||||
case TRI_FAN:
|
||||
{
|
||||
std::vector< Vertex > verts { extractVertexInfo( prim, root ) };
|
||||
std::vector< ModelVertex > verts { extractVertexInfo( prim, root ) };
|
||||
std::vector< std::uint32_t > indicies { extractIndicies( prim, root ) };
|
||||
|
||||
Primitive primitive_mesh { Primitive::fromVerts(
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
namespace fgl::engine
|
||||
{
|
||||
struct PrimitiveTextures;
|
||||
struct Vertex;
|
||||
struct ModelVertex;
|
||||
class Model;
|
||||
struct Primitive;
|
||||
class Texture;
|
||||
@@ -64,7 +64,7 @@ namespace fgl::engine
|
||||
|
||||
std::vector< std::uint32_t > extractIndicies( const tinygltf::Primitive& prim, const tinygltf::Model& model );
|
||||
|
||||
std::vector< Vertex > extractVertexInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root );
|
||||
std::vector< ModelVertex > extractVertexInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root );
|
||||
|
||||
std::vector< glm::vec3 > extractPositionInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root );
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ModelBuilder.hpp"
|
||||
#include "engine/model/ModelVertex.hpp"
|
||||
#include "engine/model/Primitive.hpp"
|
||||
#include "engine/model/Vertex.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -41,16 +41,16 @@ namespace fgl::engine
|
||||
|
||||
if ( !error.empty() ) log::error( "While loading model {}: {}", filepath, error );
|
||||
|
||||
std::unordered_map< Vertex, std::uint32_t > unique_verts {};
|
||||
std::unordered_map< ModelVertex, std::uint32_t > unique_verts {};
|
||||
|
||||
std::vector< Vertex > verts {};
|
||||
std::vector< ModelVertex > verts {};
|
||||
std::vector< std::uint32_t > indicies {};
|
||||
|
||||
for ( const auto& shape : shapes )
|
||||
{
|
||||
for ( const auto& index : shape.mesh.indices )
|
||||
{
|
||||
Vertex vert {};
|
||||
ModelVertex vert {};
|
||||
if ( index.vertex_index >= 0 )
|
||||
{
|
||||
vert.m_position = {
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace fgl::engine
|
||||
|
||||
std::shared_ptr< Model > generateTerrainModel( memory::Buffer& vertex_buffer, memory::Buffer& index_buffer )
|
||||
{
|
||||
std::vector< Vertex > verts {};
|
||||
std::vector< ModelVertex > verts {};
|
||||
|
||||
constexpr glm::vec3 TOP_LEFT { -0.5f, 0.5f, 0.0f };
|
||||
constexpr glm::vec3 TOP_RIGHT { 0.5f, 0.5f, 0.0f };
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace fgl::engine::internal
|
||||
vk::raii::Pipeline Pipeline::createGraphicsPipeline(
|
||||
std::vector< std::unique_ptr< ShaderHandle > >& shaders,
|
||||
const PipelineConfigInfo& info,
|
||||
vk::raii::PipelineLayout& layout )
|
||||
const vk::raii::PipelineLayout& layout )
|
||||
{
|
||||
assert( info.render_pass != VK_NULL_HANDLE && "Cannot create graphics pipeline: no render pass provided" );
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace fgl::engine::internal
|
||||
vk::raii::Pipeline createGraphicsPipeline(
|
||||
std::vector< std::unique_ptr< ShaderHandle > >& shaders,
|
||||
const PipelineConfigInfo& info,
|
||||
vk::raii::PipelineLayout& layout );
|
||||
const vk::raii::PipelineLayout& layout );
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -76,8 +76,30 @@ namespace fgl::engine
|
||||
info.dynamic_state_info.dynamicStateCount = static_cast< std::uint32_t >( info.dynamic_state_enables.size() );
|
||||
//info.dynamic_state_info.flags = 0;
|
||||
|
||||
info.binding_descriptions = Vertex::getBindingDescriptions();
|
||||
info.attribute_descriptions = Vertex::getAttributeDescriptions();
|
||||
info.binding_descriptions = ModelVertex::getBindingDescriptions();
|
||||
info.attribute_descriptions = ModelVertex::getAttributeDescriptions();
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::setVertexInputType( PipelineConfigInfo& info, const VertexInputType type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case None:
|
||||
disableVertexInput( info );
|
||||
case Simple:
|
||||
{
|
||||
info.binding_descriptions = SimpleVertex::getBindingDescriptions();
|
||||
info.attribute_descriptions = SimpleVertex::getAttributeDescriptions();
|
||||
}
|
||||
break;
|
||||
case Textured:
|
||||
{
|
||||
info.binding_descriptions = ModelVertex::getBindingDescriptions();
|
||||
info.attribute_descriptions = ModelVertex::getAttributeDescriptions();
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::disableVertexInput( PipelineConfigInfo& info )
|
||||
@@ -122,6 +144,11 @@ namespace fgl::engine
|
||||
info.color_blend_info.attachmentCount = static_cast< std::uint32_t >( info.color_blend_attachment.size() );
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::addGBufferAttachmentsConfig( PipelineConfigInfo& config )
|
||||
{
|
||||
for ( int i = 0; i < 3; ++i ) addColorAttachmentConfig( config );
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::disableCulling( PipelineConfigInfo& info )
|
||||
{
|
||||
info.rasterization_info.cullMode = vk::CullModeFlagBits::eNone;
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
enum VertexInputType
|
||||
{
|
||||
None,
|
||||
Simple,
|
||||
Textured
|
||||
};
|
||||
|
||||
struct PipelineConfigInfo
|
||||
{
|
||||
vk::PipelineViewportStateCreateInfo viewport_info {};
|
||||
@@ -43,6 +50,8 @@ namespace fgl::engine
|
||||
PipelineConfigInfo& operator=( PipelineConfigInfo&& other ) = default;
|
||||
PipelineConfigInfo( PipelineConfigInfo&& other ) = default;
|
||||
|
||||
static void setVertexInputType( PipelineConfigInfo& info, const VertexInputType type );
|
||||
|
||||
static void disableVertexInput( PipelineConfigInfo& info );
|
||||
static void setTriangleListTopo( PipelineConfigInfo& info );
|
||||
static void setTriangleStripTopo( PipelineConfigInfo& info );
|
||||
@@ -50,8 +59,10 @@ namespace fgl::engine
|
||||
static void setPointPatch( PipelineConfigInfo& info );
|
||||
static void defaultConfig( PipelineConfigInfo& info );
|
||||
static void enableAlphaBlending( PipelineConfigInfo& config );
|
||||
static void addColorAttachmentConfig( PipelineConfigInfo& info );
|
||||
static void disableCulling( PipelineConfigInfo& info );
|
||||
static void addColorAttachmentConfig( PipelineConfigInfo& info );
|
||||
|
||||
static void addGBufferAttachmentsConfig( PipelineConfigInfo& config );
|
||||
};
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <array>
|
||||
|
||||
#include "engine/logging/logging.hpp"
|
||||
#include "engine/model/Vertex.hpp"
|
||||
#include "engine/model/ModelVertex.hpp"
|
||||
#include "engine/primitives/lines/LineSegment.hpp"
|
||||
#include "engine/primitives/points/Coordinate.hpp"
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace fgl::engine
|
||||
return { Coordinate< CType >( midpoint ), scale };
|
||||
}
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< Vertex >& verts )
|
||||
OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< ModelVertex >& verts )
|
||||
{
|
||||
assert( verts.size() > 0 );
|
||||
log::debug( "Generating bounding box for {} verts", verts.size() );
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace fgl::engine
|
||||
template < CoordinateSpace CType >
|
||||
class LineSegment;
|
||||
|
||||
struct Vertex;
|
||||
struct ModelVertex;
|
||||
|
||||
template < CoordinateSpace CType >
|
||||
struct OrientedBoundingBox : public interface::BoundingBox
|
||||
@@ -83,7 +83,7 @@ namespace fgl::engine
|
||||
return OrientedBoundingBox< EvolvedType< MType >() >( new_middle, new_scale, new_rot );
|
||||
}
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< Vertex >& verts );
|
||||
OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< ModelVertex >& verts );
|
||||
|
||||
using ModelBoundingBox = OrientedBoundingBox< CoordinateSpace::Model >;
|
||||
|
||||
|
||||
@@ -8,15 +8,12 @@
|
||||
#include <vulkan/vulkan_handles.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
#include "Device.hpp"
|
||||
#include "SwapChain.hpp"
|
||||
#include "engine/Window.hpp"
|
||||
#include "engine/descriptors/DescriptorSet.hpp"
|
||||
|
||||
//clang-format: off
|
||||
#include <tracy/TracyVulkan.hpp>
|
||||
@@ -37,11 +34,25 @@ namespace fgl::engine
|
||||
range.levelCount = 1;
|
||||
range.baseMipLevel = 0;
|
||||
|
||||
/*
|
||||
command_buffer.clearColorImage(
|
||||
image.getVkImage(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ClearColorValue( 0.0f, 0.0f, 0.0f, 0.0f ),
|
||||
{ range } );
|
||||
*/
|
||||
|
||||
// Transition the image back to readOnly
|
||||
vk::ImageMemoryBarrier barrier {};
|
||||
barrier.oldLayout = vk::ImageLayout::eUndefined;
|
||||
barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
|
||||
barrier.image = image.getVkImage();
|
||||
barrier.subresourceRange = range;
|
||||
barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
|
||||
barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
|
||||
|
||||
command_buffer.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eFragmentShader, {}, {}, {}, { barrier } );
|
||||
}
|
||||
|
||||
Renderer::Renderer( Window& window, PhysicalDevice& phy_device ) :
|
||||
|
||||
@@ -419,6 +419,9 @@ namespace fgl::engine
|
||||
}
|
||||
}
|
||||
|
||||
SwapChain::~SwapChain()
|
||||
{}
|
||||
|
||||
descriptors::DescriptorSet& SwapChain::getInputDescriptor( const PresentIndex present_index )
|
||||
{
|
||||
assert( present_index < m_input_descriptors.size() );
|
||||
|
||||
@@ -78,6 +78,8 @@ namespace fgl::engine
|
||||
SwapChain( const SwapChain& ) = delete;
|
||||
SwapChain& operator=( const SwapChain& ) = delete;
|
||||
|
||||
~SwapChain();
|
||||
|
||||
descriptors::DescriptorSet& getInputDescriptor( const PresentIndex present_index );
|
||||
|
||||
Image& getInputImage( PresentIndex present_index ) const;
|
||||
|
||||
@@ -28,17 +28,23 @@ namespace fgl::engine
|
||||
EntityRendererSystem::EntityRendererSystem( Device& device, vk::raii::RenderPass& render_pass ) : m_device( device )
|
||||
{
|
||||
ZoneScoped;
|
||||
PipelineConfigInfo standard_info { render_pass };
|
||||
for ( int i = 0; i < 3; ++i ) PipelineConfigInfo::addColorAttachmentConfig( standard_info );
|
||||
standard_info.subpass = 0;
|
||||
m_standard_pipeline = std::make_unique< StandardPipeline >( m_device, std::move( standard_info ) );
|
||||
m_standard_pipeline->setDebugName( "Standard entity pipeline" );
|
||||
{
|
||||
PipelineConfigInfo standard_info { render_pass };
|
||||
PipelineConfigInfo::addGBufferAttachmentsConfig( standard_info );
|
||||
|
||||
PipelineConfigInfo textured_info { render_pass };
|
||||
for ( int i = 0; i < 3; ++i ) PipelineConfigInfo::addColorAttachmentConfig( textured_info );
|
||||
textured_info.subpass = 0;
|
||||
m_textured_pipeline = std::make_unique< TexturedPipeline >( m_device, std::move( textured_info ) );
|
||||
m_textured_pipeline->setDebugName( "Textured entity pipeline" );
|
||||
standard_info.subpass = 0;
|
||||
m_standard_pipeline = std::make_unique< StandardPipeline >( m_device, std::move( standard_info ) );
|
||||
m_standard_pipeline->setDebugName( "Standard entity pipeline" );
|
||||
}
|
||||
|
||||
{
|
||||
PipelineConfigInfo textured_info { render_pass };
|
||||
PipelineConfigInfo::addGBufferAttachmentsConfig( textured_info );
|
||||
|
||||
textured_info.subpass = 0;
|
||||
m_textured_pipeline = std::make_unique< TexturedPipeline >( m_device, std::move( textured_info ) );
|
||||
m_textured_pipeline->setDebugName( "Textured entity pipeline" );
|
||||
}
|
||||
|
||||
using namespace fgl::literals::size_literals;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user