Enforces better checking when making swapchains with depth buffers
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "engine/rendering/Attachment.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
class ImageView;
|
||||
@@ -37,9 +39,6 @@ namespace fgl::engine
|
||||
} -> std::same_as< vk::ClearValue& >;
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
concept is_depth_attachment = is_attachment< T > && T::Layout == vk::ImageLayout::eDepthStencilAttachmentOptimal;
|
||||
|
||||
template < typename T >
|
||||
concept is_color_attachment = is_attachment< T > && T::Layout == vk::ImageLayout::eColorAttachmentOptimal;
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "engine/concepts/is_attachment.hpp"
|
||||
#include "engine/image/Image.hpp"
|
||||
#include "engine/rendering/Device.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -47,10 +46,10 @@ namespace fgl::engine
|
||||
|
||||
void setIndex( const std::uint32_t idx ) { index = idx; }
|
||||
|
||||
constexpr static vk::AttachmentLoadOp loadOp = load_op;
|
||||
constexpr static vk::AttachmentStoreOp storeOp = store_op;
|
||||
constexpr static vk::ImageLayout InitalLayout = inital_layout;
|
||||
constexpr static vk::ImageLayout FinalLayout = final_layout;
|
||||
constexpr static vk::AttachmentLoadOp loadOp { load_op };
|
||||
constexpr static vk::AttachmentStoreOp storeOp { store_op };
|
||||
constexpr static vk::ImageLayout InitalLayout { inital_layout };
|
||||
constexpr static vk::ImageLayout FinalLayout { final_layout };
|
||||
|
||||
Attachment( const vk::Format format )
|
||||
{
|
||||
@@ -179,6 +178,11 @@ namespace fgl::engine
|
||||
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... Attachments >
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace fgl::engine
|
||||
class Subpass
|
||||
{
|
||||
//! Set to true if the first attachment is a valid depth stencil attachment
|
||||
constexpr static bool has_depth_stencil_attachment { Attachment::m_layout
|
||||
== vk::ImageLayout::eDepthStencilAttachmentOptimal };
|
||||
constexpr static bool has_depth_stencil_attachment { is_wrapped_depth_attachment< Attachment > };
|
||||
|
||||
constexpr static std::uint32_t attachment_count { ( ( !is_input_attachment< Attachments > ? 1 : 0 ) + ... )
|
||||
+ ( has_depth_stencil_attachment ? 0 : 1 ) };
|
||||
@@ -58,14 +57,36 @@ namespace fgl::engine
|
||||
template < is_wrapped_attachment T >
|
||||
void registerAttachment( UnwrappedAttachment< T >& attachment )
|
||||
{
|
||||
static_assert(
|
||||
!is_wrapped_depth_attachment< T >,
|
||||
"Unable to register depth attachment. Are you using more then one?" );
|
||||
|
||||
static_assert(
|
||||
T::m_layout != vk::ImageLayout::eDepthAttachmentOptimal,
|
||||
"Vulkan specification states that pColorAttachments can not have the type \'eDepthAttachmentOptimal\'" );
|
||||
static_assert(
|
||||
T::m_layout != vk::ImageLayout::eDepthReadOnlyOptimal,
|
||||
"Vulkan specification states that pColorAttachments can not have the type \'eDepthReadOnlyOptimal\'" );
|
||||
static_assert(
|
||||
T::m_layout != vk::ImageLayout::eDepthStencilAttachmentOptimal,
|
||||
"Vulkan specification states that pColorAttachments can not have the type \'eDepthStencilAttachmentOptimal\'" );
|
||||
static_assert(
|
||||
T::m_layout != vk::ImageLayout::eStencilReadOnlyOptimal,
|
||||
"Vulkan specification states that pColorAttachments can not have the type \'eStencilReadOnlyOptimal\'" );
|
||||
|
||||
if constexpr ( is_input_attachment< T > )
|
||||
{
|
||||
input_attachment_references[ current_input_idx++ ] = { attachment.getIndex(), T::m_layout };
|
||||
}
|
||||
else if constexpr ( is_used_attachment< T > )
|
||||
{
|
||||
log::debug( "Adding attachment at index {} for usage", current_attachment_idx );
|
||||
attachment_references[ current_attachment_idx++ ] = { attachment.getIndex(), T::m_layout };
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert( false, "Unknown attachment attempting to be registered" );
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -80,10 +101,10 @@ namespace fgl::engine
|
||||
{
|
||||
//TODO: Redo this check. As this will prevent any input attachments from being used as a depth input (Which may be done?)
|
||||
static_assert(
|
||||
( ( Attachments::m_layout != vk::ImageLayout::eDepthStencilAttachmentOptimal ) && ... ),
|
||||
( (!is_wrapped_depth_attachment< Attachments >) || ... ),
|
||||
"Depth stencil must be at attachment index 0 in template parameters" );
|
||||
|
||||
if constexpr ( has_depth_stencil_attachment )
|
||||
if constexpr ( is_wrapped_depth_attachment< Attachment > )
|
||||
{
|
||||
depth_stencil_reference.layout = Attachment::m_layout;
|
||||
depth_stencil_reference.attachment = first_attachment.getIndex();
|
||||
@@ -100,7 +121,7 @@ namespace fgl::engine
|
||||
subpass_description.colorAttachmentCount = static_cast< std::uint32_t >( attachment_references.size() );
|
||||
|
||||
subpass_description.pDepthStencilAttachment =
|
||||
has_depth_stencil_attachment ? &depth_stencil_reference : nullptr;
|
||||
is_wrapped_depth_attachment< Attachment > ? &depth_stencil_reference : nullptr;
|
||||
|
||||
subpass_description.pInputAttachments = input_attachment_references.data();
|
||||
subpass_description.inputAttachmentCount =
|
||||
|
||||
Reference in New Issue
Block a user