diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b6fb4..d89b0ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,11 @@ if ( MSVC OR NOT "${CMAKE_BUILD_TYPE}" STREQUAL "" ) ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/DotExport.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/Exception.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraph.hpp + ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraphBase.hpp + ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraphEnums.hpp + ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraphFunctions.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraphPrerequisites.hpp + ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FrameGraphStructs.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FramePass.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FramePassGroup.hpp ${CRG_SOURCE_DIR}/include/${PROJECT_NAME}/FramePassTimer.hpp @@ -249,7 +253,7 @@ if ( MSVC OR NOT "${CMAKE_BUILD_TYPE}" STREQUAL "" ) ) set_target_properties( ${PROJECT_NAME} PROPERTIES - CXX_STANDARD 17 + CXX_STANDARD 20 FOLDER "${CRG_BASE_DIR}/Core" DEBUG_POSTFIX "d" UNITY_BUILD "${PROJECTS_UNITY_BUILD}" diff --git a/include/RenderGraph/Attachment.hpp b/include/RenderGraph/Attachment.hpp index 79036ce..a5121d6 100644 --- a/include/RenderGraph/Attachment.hpp +++ b/include/RenderGraph/Attachment.hpp @@ -48,9 +48,10 @@ namespace crg , maxLod{ maxLod } { } + + private: + friend bool operator==( SamplerDesc const & lhs, SamplerDesc const & rhs ) = default; }; - CRG_API bool operator==( SamplerDesc const & lhs - , SamplerDesc const & rhs ); /** *\brief * An image attachment. @@ -85,7 +86,6 @@ namespace crg */ /**@{*/ CRG_API ImageViewId view( uint32_t index = 0u )const; - CRG_API VkDescriptorType getDescriptorType()const; CRG_API ImageLayout getImageLayout( bool separateDepthStencilLayouts , bool isInput , bool isOutput )const; @@ -171,13 +171,13 @@ namespace crg public: ImageViewIdArray views{}; - VkAttachmentLoadOp loadOp{}; - VkAttachmentStoreOp storeOp{}; - VkAttachmentLoadOp stencilLoadOp{}; - VkAttachmentStoreOp stencilStoreOp{}; + AttachmentLoadOp loadOp{}; + AttachmentStoreOp storeOp{}; + AttachmentLoadOp stencilLoadOp{}; + AttachmentStoreOp stencilStoreOp{}; SamplerDesc samplerDesc{}; - VkClearValue clearValue{}; - VkPipelineColorBlendAttachmentState blendState = DefaultBlendState; + ClearValue clearValue{}; + PipelineColorBlendAttachmentState blendState = DefaultBlendState; ImageLayout wantedLayout{}; private: @@ -185,23 +185,36 @@ namespace crg CRG_API explicit ImageAttachment( ImageViewId view ); CRG_API ImageAttachment( FlagKind flags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , SamplerDesc samplerDesc - , VkClearValue clearValue - , VkPipelineColorBlendAttachmentState blendState + , ClearValue clearValue + , PipelineColorBlendAttachmentState blendState , ImageLayout wantedLayout ); FlagKind flags{}; - friend CRG_API bool operator==( ImageAttachment const & lhs, ImageAttachment const & rhs ); + friend bool operator==( ImageAttachment const & lhs + , ImageAttachment const & rhs ) + { + return lhs.flags == rhs.flags + && lhs.views == rhs.views + && lhs.loadOp == rhs.loadOp + && lhs.storeOp == rhs.storeOp + && lhs.stencilLoadOp == rhs.stencilLoadOp + && lhs.stencilStoreOp == rhs.stencilStoreOp + && lhs.samplerDesc == rhs.samplerDesc + && lhs.clearValue == rhs.clearValue + && lhs.blendState == rhs.blendState; + } + }; struct BufferSubresourceRange { - VkDeviceSize offset{}; - VkDeviceSize size{}; + DeviceSize offset{}; + DeviceSize size{}; }; /** *\brief @@ -229,10 +242,6 @@ namespace crg TransitionView = Transition | View, }; - CRG_API VkDescriptorType getDescriptorType()const; - CRG_API WriteDescriptorSet getWrite( uint32_t binding - , uint32_t count - , uint32_t index )const; CRG_API AccessFlags getAccessMask( bool isInput , bool isOutput )const; CRG_API PipelineStageFlags getPipelineStageFlags( bool isCompute )const; @@ -301,20 +310,27 @@ namespace crg CRG_API explicit BufferAttachment( Buffer buffer ); CRG_API BufferAttachment( FlagKind flags , Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState access = {} ); CRG_API BufferAttachment( FlagKind flags , Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState access = {} ); FlagKind flags{}; AccessState wantedAccess{}; - friend CRG_API bool operator==( BufferAttachment const & lhs, BufferAttachment const & rhs ); + friend bool operator==( BufferAttachment const & lhs, BufferAttachment const & rhs ) + { + return lhs.flags == rhs.flags + && lhs.buffer == rhs.buffer + && lhs.view == rhs.view + && lhs.range.offset == rhs.range.offset + && lhs.range.size == rhs.range.size; + } }; /** *\brief @@ -349,8 +365,6 @@ namespace crg CRG_API ImageViewId view( uint32_t index = 0u )const; CRG_API VkBuffer buffer( uint32_t index = 0u )const; CRG_API ImageLayout getImageLayout( bool separateDepthStencilLayouts )const; - CRG_API VkDescriptorType getDescriptorType()const; - CRG_API WriteDescriptorSet getBufferWrite( uint32_t index = 0u )const; CRG_API AccessFlags getAccessMask()const; CRG_API PipelineStageFlags getPipelineStageFlags( bool isCompute )const; @@ -598,32 +612,32 @@ namespace crg return imageAttach.samplerDesc; } - VkClearValue const & getClearValue()const + ClearValue const & getClearValue()const { return imageAttach.clearValue; } - VkAttachmentLoadOp getLoadOp()const + AttachmentLoadOp getLoadOp()const { return imageAttach.loadOp; } - VkAttachmentLoadOp getStencilLoadOp()const + AttachmentLoadOp getStencilLoadOp()const { return imageAttach.stencilLoadOp; } - VkAttachmentStoreOp getStoreOp()const + AttachmentStoreOp getStoreOp()const { return imageAttach.storeOp; } - VkAttachmentStoreOp getStencilStoreOp()const + AttachmentStoreOp getStencilStoreOp()const { return imageAttach.stencilStoreOp; } - VkPipelineColorBlendAttachmentState getBlendState()const + PipelineColorBlendAttachmentState getBlendState()const { return imageAttach.blendState; } @@ -664,13 +678,13 @@ namespace crg , std::string name , ImageAttachment::FlagKind imageFlags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , SamplerDesc samplerDesc - , VkClearValue clearValue - , VkPipelineColorBlendAttachmentState blendState + , ClearValue clearValue + , PipelineColorBlendAttachmentState blendState , ImageLayout wantedLayout ); CRG_API Attachment( FlagKind flags , FramePass & pass @@ -678,8 +692,8 @@ namespace crg , std::string name , BufferAttachment::FlagKind bufferFlags , Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ); CRG_API Attachment( FlagKind flags , FramePass & pass @@ -688,16 +702,19 @@ namespace crg , BufferAttachment::FlagKind bufferFlags , Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ); FlagKind flags{}; - friend CRG_API bool operator==( Attachment const & lhs, Attachment const & rhs ); + friend bool operator==( Attachment const & lhs + , Attachment const & rhs ) + { + return lhs.pass == rhs.pass + && lhs.flags == rhs.flags + && lhs.imageAttach == rhs.imageAttach + && lhs.bufferAttach == rhs.bufferAttach; + } }; - - CRG_API bool operator==( BufferAttachment const & lhs, BufferAttachment const & rhs ); - CRG_API bool operator==( ImageAttachment const & lhs, ImageAttachment const & rhs ); - CRG_API bool operator==( Attachment const & lhs, Attachment const & rhs ); } diff --git a/include/RenderGraph/AttachmentTransition.hpp b/include/RenderGraph/AttachmentTransition.hpp index f1a0323..47ce736 100644 --- a/include/RenderGraph/AttachmentTransition.hpp +++ b/include/RenderGraph/AttachmentTransition.hpp @@ -16,10 +16,15 @@ namespace crg DataT data; Attachment outputAttach; Attachment inputAttach; - }; - bool operator==( ViewTransition const & lhs, ViewTransition const & rhs ); - bool operator==( BufferTransition const & lhs, BufferTransition const & rhs ); + private: + friend bool operator==( DataTransitionT const & lhs, DataTransitionT const & rhs ) + { + return match( lhs.data, rhs.data ) + && lhs.outputAttach == rhs.outputAttach + && lhs.inputAttach == rhs.inputAttach; + } + }; struct AttachmentTransitions { diff --git a/include/RenderGraph/FrameGraph.hpp b/include/RenderGraph/FrameGraph.hpp index e271f88..935f7dd 100644 --- a/include/RenderGraph/FrameGraph.hpp +++ b/include/RenderGraph/FrameGraph.hpp @@ -75,30 +75,30 @@ namespace crg /**@{*/ CRG_API LayoutState getFinalLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const; + , ImageSubresourceRange const & range )const; CRG_API LayoutState getFinalLayoutState( ImageViewId view , uint32_t passIndex = 0u )const; CRG_API AccessState const & getFinalAccessState( Buffer const & buffer , uint32_t passIndex = 0u )const; CRG_API void addInput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ); CRG_API void addInput( ImageViewId view , LayoutState const & outputLayout ); CRG_API LayoutState getInputLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const; + , ImageSubresourceRange const & range )const; CRG_API LayoutState getInputLayoutState( ImageViewId view )const; CRG_API void addOutput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ); CRG_API void addOutput( ImageViewId view , LayoutState const & outputLayout ); CRG_API LayoutState getOutputLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const; + , ImageSubresourceRange const & range )const; CRG_API LayoutState getOutputLayoutState( ImageViewId view )const; CRG_API LayerLayoutStatesMap const & getOutputLayoutStates()const; diff --git a/include/RenderGraph/FrameGraphBase.hpp b/include/RenderGraph/FrameGraphBase.hpp new file mode 100644 index 0000000..977c9c5 --- /dev/null +++ b/include/RenderGraph/FrameGraphBase.hpp @@ -0,0 +1,175 @@ +/* +This file belongs to FrameGraph. +See LICENSE file in root folder. +*/ +#pragma once + +#include + +#pragma warning( push ) +#pragma warning( disable: 4365 ) +#pragma warning( disable: 5262 ) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#pragma warning( pop ) + +#if !defined( _WIN32 ) || defined( CRG_BUILD_STATIC ) +# define CRG_API +#else +# if defined( RenderGraph_EXPORTS ) +# define CRG_API __declspec( dllexport ) +# else +# define CRG_API __declspec( dllimport ) +# endif +#endif + +namespace crg +{ + struct Attachment; + struct AttachmentTransitions; + struct Buffer; + struct FramePass; + struct FramePassGroup; + struct FramePassTransitions; + struct GraphContext; + struct GraphNode; + struct ImageData; + struct ImageViewData; + struct IndexBuffer; + struct IndirectBuffer; + struct LayoutState; + struct PipelineState; + struct RootNode; + struct SamplerDesc; + struct SemaphoreWait; + struct Texcoord; + struct VertexBuffer; + struct WriteDescriptorSet; + + class ContextResourcesCache; + class Exception; + class Fence; + class FrameGraph; + class FramePassTimer; + class GraphVisitor; + class ImageCopy; + class PipelinePass; + class RecordContext; + class RenderPass; + class RenderQuad; + class ResourceHandler; + class ResourcesCache; + class RunnableGraph; + class RunnablePass; + + template< typename DataT > + struct Id; + template< typename DataT > + struct DataTransitionT; + template< typename DataT > + using DataTransitionArrayT = std::vector< DataTransitionT< DataT > >; + template< typename VkTypeT > + struct ContextObjectT; + template< typename TypeT > + struct DefaultValueGetterT; + template< typename TypeT > + struct RawTyperT; + + using ImageId = Id< ImageData >; + using ImageViewId = Id< ImageViewData >; + using AccessState = PipelineState; + using DependencyCache = std::unordered_map< size_t, bool >; + using PassDependencyCache = std::unordered_map< FramePass const *, DependencyCache >; + using DeviceSize = VkDeviceSize; + + using FramePassPtr = std::unique_ptr< FramePass >; + using FramePassGroupPtr = std::unique_ptr< FramePassGroup >; + using GraphNodePtr = std::unique_ptr< GraphNode >; + using RunnableGraphPtr = std::unique_ptr< RunnableGraph >; + using RunnablePassPtr = std::unique_ptr< RunnablePass >; + using VertexBufferPtr = std::unique_ptr< VertexBuffer >; + + using GraphAdjacentNode = GraphNode *; + using ConstGraphAdjacentNode = GraphNode const *; + + /** + *\brief + * The transition between two states of an image view. + */ + using ViewTransition = DataTransitionT< ImageViewId >; + using ViewTransitionArray = DataTransitionArrayT< ImageViewId >; + /** + *\brief + * The transition between two states of a storage buffer. + */ + using BufferTransition = DataTransitionT< Buffer >; + using BufferTransitionArray = DataTransitionArrayT< Buffer >; + + using AttachmentArray = std::vector< Attachment >; + using FramePassPtrArray = std::vector< FramePassPtr >; + using FramePassGroupPtrArray = std::vector< FramePassGroupPtr >; + using FrameGraphArray = std::vector< FrameGraph const * >; + using FramePassArray = std::vector< FramePass const * >; + using GraphAdjacentNodeArray = std::vector< GraphAdjacentNode >; + using ConstGraphAdjacentNodeArray = std::vector< ConstGraphAdjacentNode >; + using GraphNodePtrArray = std::vector< GraphNodePtr >; + using FramePassDependencies = std::vector< FramePassTransitions >; + using WriteDescriptorSetArray = std::vector< WriteDescriptorSet >; + using AttachmentsNodeMap = std::map< ConstGraphAdjacentNode, AttachmentTransitions >; + using ImageMemoryMap = std::map< ImageId, std::pair< VkImage, VkDeviceMemory > >; + using ImageViewMap = std::map< ImageViewId, VkImageView >; + using ImageIdArray = std::vector< ImageId >; + using ImageViewIdArray = std::vector< ImageViewId >; + using SemaphoreWaitArray = std::vector< SemaphoreWait >; + + template< typename DataT > + using IdAliasMap = std::map< Id< DataT >, Id< DataT > >; + using ImageIdAliasMap = IdAliasMap< ImageData >; + using ImageViewIdAliasMap = IdAliasMap< ImageViewData >; + + template< typename DataT > + using IdDataOwnerCont = std::map< Id< DataT >, std::unique_ptr< DataT > >; + using ImageIdDataOwnerCont = IdDataOwnerCont< ImageData >; + using ImageViewIdDataOwnerCont = IdDataOwnerCont< ImageViewData >; + + using VkAttachmentDescriptionArray = std::vector< VkAttachmentDescription >; + using VkAttachmentReferenceArray = std::vector< VkAttachmentReference >; + using VkBufferArray = std::vector< VkBuffer >; + using VkBufferViewArray = std::vector< VkBufferView >; + using VkDescriptorBufferInfoArray = std::vector< VkDescriptorBufferInfo >; + using VkDescriptorImageInfoArray = std::vector< VkDescriptorImageInfo >; + using VkDescriptorSetLayoutBindingArray = std::vector< VkDescriptorSetLayoutBinding >; + using VkDescriptorPoolSizeArray = std::vector< VkDescriptorPoolSize >; + using VkImageViewArray = std::vector< VkImageView >; + using VkPipelineColorBlendAttachmentStateArray = std::vector< VkPipelineColorBlendAttachmentState >; + using VkPipelineShaderStageCreateInfoArray = std::vector< VkPipelineShaderStageCreateInfo >; + using VkPushConstantRangeArray = std::vector< VkPushConstantRange >; + using VkScissorArray = std::vector< VkRect2D >; + using VkSubpassDependencyArray = std::vector< VkSubpassDependency >; + using VkVertexInputAttributeDescriptionArray = std::vector< VkVertexInputAttributeDescription >; + using VkVertexInputBindingDescriptionArray = std::vector< VkVertexInputBindingDescription >; + using VkViewportArray = std::vector< VkViewport >; + using VkWriteDescriptorSetArray = std::vector< VkWriteDescriptorSet >; + + using MipLayoutStates = std::map< uint32_t, LayoutState >; + using LayerLayoutStates = std::map< uint32_t, MipLayoutStates >; + using LayoutStateMap = std::unordered_map< uint32_t, LayerLayoutStates >; + using LayerLayoutStatesMap = std::map< uint32_t, LayerLayoutStates >; + using AccessStateMap = std::unordered_map< VkBuffer, AccessState >; + using ViewsLayout = LayoutStateMap; + using BuffersLayout = AccessStateMap; + using ViewsLayoutPtr = std::unique_ptr< ViewsLayout >; + using BuffersLayoutPtr = std::unique_ptr< BuffersLayout >; + using ViewsLayouts = std::vector< ViewsLayoutPtr >; + using BuffersLayouts = std::vector< BuffersLayoutPtr >; + + using ViewLayoutIterators = std::map< uint32_t, ViewsLayouts::iterator >; + using BufferLayoutIterators = std::map< uint32_t, BuffersLayouts::iterator >; +} diff --git a/include/RenderGraph/FrameGraphEnums.hpp b/include/RenderGraph/FrameGraphEnums.hpp new file mode 100644 index 0000000..511a6d7 --- /dev/null +++ b/include/RenderGraph/FrameGraphEnums.hpp @@ -0,0 +1,369 @@ +/* +This file belongs to FrameGraph. +See LICENSE file in root folder. +*/ +#pragma once + +#include "FrameGraphBase.hpp" + +#define CRG_MakeFlags( FlagBits )\ + constexpr FlagBits operator|( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) | std::underlying_type_t< FlagBits >( rhs ) ); }\ + constexpr FlagBits operator&( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) & std::underlying_type_t< FlagBits >( rhs ) ); }\ + constexpr FlagBits operator^( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) ^ std::underlying_type_t< FlagBits >( rhs ) ); }\ + constexpr FlagBits & operator|=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs | rhs; }\ + constexpr FlagBits & operator&=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs & rhs; }\ + constexpr FlagBits & operator^=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs ^ rhs; }\ + constexpr bool checkFlag( FlagBits lhs, FlagBits rhs ) { return ( lhs & rhs ) == rhs; } + +namespace crg +{ + enum class PixelFormat : int32_t + { +#define RGPF_ENUM_VALUE( name, value, components, alpha, colour, depth, stencil, compressed ) e##name = value, +#define RGPF_ENUM_NON_VALUE( name, value ) e##name = value, +#include "PixelFormat.enum" + }; + + enum class ImageType : int32_t + { + e1D = 0, + e2D = 1, + e3D = 2, + }; + + enum class SampleCount : int32_t + { + e1 = 0x00000001, + e2 = 0x00000002, + e4 = 0x00000004, + e8 = 0x00000008, + e16 = 0x00000010, + e32 = 0x00000020, + e64 = 0x00000040, + }; + + enum class ImageTiling : int32_t + { + eOptimal = 0, + eLinear = 1, + eDRMFormatModifier = 1000158000, + }; + + enum class ImageViewType : int32_t + { + e1D = 0, + e2D = 1, + e3D = 2, + eCube = 3, + e1DArray = 4, + e2DArray = 5, + eCubeArray = 6, + }; + + enum class ImageLayout : int32_t + { + eUndefined = 0, + eGeneral = 1, + eColorAttachment = 2, + eDepthStencilAttachment = 3, + eDepthStencilReadOnly = 4, + eShaderReadOnly = 5, + eTransferSrc = 6, + eTransferDst = 7, + ePreinitialized = 8, + eDepthReadOnlyStencilAttachment = 1000117000, + eDepthAttachmentStencilReadOnly = 1000117001, + eDepthAttachment = 1000241000, + eDepthReadOnly = 1000241001, + eStencilAttachment = 1000241002, + eStencilReadOnly = 1000241003, + eReadOnly = 1000314000, + eAttachment = 1000314001, + eRenderingLocalRead = 1000232000, + ePresentSrc = 1000001002, + eVideoDecodeDst = 1000024000, + eVideoDecodeSrc = 1000024001, + eVideoDecodeDpb = 1000024002, + eSharedPresent = 1000111000, + eFragmentDensityMap = 1000218000, + eFragmentShadingRateAttachment = 1000164003, + eVideoEncodeDst = 1000299000, + eVideoEncodeSrc = 1000299001, + eVideoEncodeDpb = 1000299002, + eAttachmentFeedbackLoop = 1000339000, + eVideoEncodeQuantizationMap = 1000553000, + }; + + enum class FilterMode : int32_t + { + eNearest, + eLinear, + }; + + enum class MipmapMode : int32_t + { + eNearest, + eLinear, + }; + + enum class WrapMode : int32_t + { + eRepeat, + eMirroredRepeat, + eClampToBorder, + eClampToEdge, + eMirrorClampToEdge, + }; + + enum class AttachmentLoadOp : int32_t + { + eLoad = 0, + eClear = 1, + eDontCare = 2, + eNone = 1000400000, + }; + + enum class AttachmentStoreOp : int32_t + { + eStore = 0, + eDontCare = 1, + eNone = 1000301000, + }; + + enum class BlendFactor : int32_t + { + eZero = 0, + eOne = 1, + eSrcColor = 2, + eOneMinusSrcColor = 3, + eDstColor = 4, + eOneMinusDstColor = 5, + eSrcAlpha = 6, + eOneMinusSrcAlpha = 7, + eDstAlpha = 8, + eOneMinusDstAlpha = 9, + eConstantColor = 10, + eOneMinusConstantColor = 11, + eConstantAlpha = 12, + eOneMinusConstantAlpha = 13, + eSrcAlphaSaturate = 14, + eSrc1Color = 15, + eOneMinusSrc1Color = 16, + eSrc1Alpha = 17, + eOneMinusSrc1Alpha = 18, + }; + + enum class BlendOp : int32_t + { + eAdd = 0, + eSubtract = 1, + eReverse_subtract = 2, + eMin = 3, + eMax = 4, + eZero = 1000148000, + eSrc = 1000148001, + eDst = 1000148002, + eSrcOver = 1000148003, + eDstOver = 1000148004, + eSrcIn = 1000148005, + eDstIn = 1000148006, + eSrcOut = 1000148007, + eDstOut = 1000148008, + eSrcAtop = 1000148009, + eDstAtop = 1000148010, + eXor = 1000148011, + eMultiply = 1000148012, + eScreen = 1000148013, + eOverlay = 1000148014, + eDarken = 1000148015, + eLighten = 1000148016, + eColordodge = 1000148017, + eColorburn = 1000148018, + eHardlight = 1000148019, + eSoftlight = 1000148020, + eDifference = 1000148021, + eExclusion = 1000148022, + eInvert = 1000148023, + eInvertRGB = 1000148024, + eLineardodge = 1000148025, + eLinearburn = 1000148026, + eVividlight = 1000148027, + eLinearlight = 1000148028, + ePinlight = 1000148029, + eHardmix = 1000148030, + eHSLHue = 1000148031, + eHSLSaturation = 1000148032, + eHSLColor = 1000148033, + eHSLLuminosity = 1000148034, + ePlus = 1000148035, + ePlusClamped = 1000148036, + ePlusClamped_alpha = 1000148037, + ePlusDarker = 1000148038, + eMinus = 1000148039, + eMinus_clamped = 1000148040, + eContrast = 1000148041, + eInvertOVG = 1000148042, + eRed = 1000148043, + eGreen = 1000148044, + eBlue = 1000148045, + }; + + enum class ImageCreateFlags : int32_t + { + eNone = 0, + eSparseBinding = 0x00000001, + eSparseResidency = 0x00000002, + eSparseAliased = 0x00000004, + eMutableFormat = 0x00000008, + eCubeCompatible = 0x00000010, + eAlias = 0x00000400, + eSplitInstanceBindRegions = 0x00000040, + e2DArrayCompatible = 0x00000020, + eBlockTexelViewCompatible = 0x00000080, + eExtendedUsage = 0x00000100, + eProtected = 0x00000800, + eDisjoint = 0x00000200, + eCornerSampled = 0x00002000, + eSampleLocationsCompatibleDepth = 0x00001000, + eSubsampled = 0x00004000, + eDescriptorBufferCaptureReplay = 0x00010000, + eMultisampledRenderToSingleSampled = 0x00040000, + e2DViewCompatible = 0x00020000, + eVideoProfileIndependent = 0x00100000, + eFragmentDensityMapOffset = 0x00008000, + }; + CRG_MakeFlags( ImageCreateFlags ) + + enum class ImageUsageFlags : int32_t + { + eNone = 0, + eTransferSrc = 0x00000001, + eTransferDst = 0x00000002, + eSampled = 0x00000004, + eStorage = 0x00000008, + eColorAttachment = 0x00000010, + eDepthStencilAttachment = 0x00000020, + eTransientAttachment = 0x00000040, + eInputAttachment = 0x00000080, + eHostTransfer = 0x00400000, + eVideoDecodeDst = 0x00000400, + eVideoDecodeSrc = 0x00000800, + eVideoDecodeDpb = 0x00001000, + eFragmentDensityMap = 0x00000200, + eFragmentShadingRateAttachment = 0x00000100, + eVideoEncodeDst = 0x00002000, + eVideoEncodeSrc = 0x00004000, + eVideoEncodeDpb = 0x00008000, + eAttachmentFeedbackLoop = 0x00080000, + eInvocationMask = 0x00040000, + eSampleWeight = 0x00100000, + eSampleBlockMatch = 0x00200000, + eTileMemory = 0x08000000, + eVideoEncodeQuantizationDeltaMap = 0x02000000, + eVideoEncodeEmphasisMap = 0x04000000, + }; + CRG_MakeFlags( ImageUsageFlags ) + + enum class ImageViewCreateFlags : int32_t + { + eNone = 0, + eFragmentDensityMapDynamic = 0x00000001, + eDescriptorBufferCaptureReplay = 0x00000004, + eFragmentDensityMapDeferred = 0x00000002, + }; + CRG_MakeFlags( ImageViewCreateFlags ) + + enum class ImageAspectFlags : int32_t + { + eNone = 0, + eColor = 0x00000001, + eDepth = 0x00000002, + eStencil = 0x00000004, + eDepthStencil = eDepth | eStencil, + eMetadata = 0x00000008, + ePlane0 = 0x00000010, + ePlane1 = 0x00000020, + ePlane2 = 0x00000040, + eMemoryPlane0 = 0x00000080, + eMemoryPlane1 = 0x00000100, + eMemoryPlane2 = 0x00000200, + eMemoryPlane3 = 0x00000400, + }; + CRG_MakeFlags( ImageAspectFlags ) + + enum class PipelineStageFlags : int32_t + { + eNone = 0, + eTopOfPipe = 0x00000001, + eDrawIndirect = 0x00000002, + eVertexInput = 0x00000004, + eVertexShader = 0x00000008, + eTessellationControlShader = 0x00000010, + eTessellationEvaluationShader = 0x00000020, + eGeometryShader = 0x00000040, + eFragmentShader = 0x00000080, + eEarlyFragmentTests = 0x00000100, + eLateFragmentTests = 0x00000200, + eColorAttachmentOutput = 0x00000400, + eComputeShader = 0x00000800, + eTransfer = 0x00001000, + eBottomOfPipe = 0x00002000, + eHost = 0x00004000, + eAllGraphics = 0x00008000, + eAllCommands = 0x00010000, + eTransformFeedback = 0x01000000, + eConditionalRendering = 0x00040000, + eAccelerationStructureBuild = 0x02000000, + eRayTracingShader = 0x00200000, + eFragmentDensityProcess = 0x00800000, + eFragmentShadingRateAttachment = 0x00400000, + eTaskShader = 0x00080000, + eMeshShader = 0x00100000, + eCommandPreprocess = 0x00020000, + }; + CRG_MakeFlags( PipelineStageFlags ) + + enum class AccessFlags : int32_t + { + eNone = 0, + eIndirectCommandRead = 0x00000001, + eIndexRead = 0x00000002, + eVertexAttributeRead = 0x00000004, + eUniformRead = 0x00000008, + eInputAttachmentRead = 0x00000010, + eShaderRead = 0x00000020, + eShaderWrite = 0x00000040, + eColorAttachmentRead = 0x00000080, + eColorAttachmentWrite = 0x00000100, + eDepthStencilAttachmentRead = 0x00000200, + eDepthStencilAttachmentWrite = 0x00000400, + eTransferRead = 0x00000800, + eTransferWrite = 0x00001000, + eHostRead = 0x00002000, + eHostWrite = 0x00004000, + eMemoryRead = 0x00008000, + eMemoryWrite = 0x00010000, + eTransformFeedbackWrite = 0x02000000, + eTransformFeedback_counterRead = 0x04000000, + eTransformFeedback_counterWrite = 0x08000000, + eConditionalRenderingRead = 0x00100000, + eColorAttachmentReadNonCoherent = 0x00080000, + eAccelerationStructureRead = 0x00200000, + eAccelerationStructureWrite = 0x00400000, + eFragmentDensityMapRead = 0x01000000, + eFragmentShadingRateAttachmentRead = 0x00800000, + eCommandPreprocessRead = 0x00020000, + eCommandPreprocessWrite = 0x00040000, + }; + CRG_MakeFlags( AccessFlags ) + + enum class ColorComponentFlags : int32_t + { + eNone = 0, + eR = 0x00000001, + eG = 0x00000002, + eB = 0x00000004, + eA = 0x00000008, + }; + CRG_MakeFlags( ColorComponentFlags ) + } diff --git a/include/RenderGraph/FrameGraphFunctions.hpp b/include/RenderGraph/FrameGraphFunctions.hpp new file mode 100644 index 0000000..055099d --- /dev/null +++ b/include/RenderGraph/FrameGraphFunctions.hpp @@ -0,0 +1,467 @@ +/* +This file belongs to FrameGraph. +See LICENSE file in root folder. +*/ +#pragma once + +#include "FrameGraphStructs.hpp" + +#include + +namespace crg +{ + CRG_API std::string_view getName( PixelFormat v ); + CRG_API std::string_view getName( FilterMode v ); + CRG_API std::string_view getName( MipmapMode v ); + CRG_API std::string_view getName( WrapMode v ); + + CRG_API bool operator==( Buffer const & lhs, Buffer const & rhs ); + + CRG_API ImageCreateFlags getImageCreateFlags( ImageId const & image )noexcept; + CRG_API ImageCreateFlags getImageCreateFlags( ImageViewId const & image )noexcept; + CRG_API Extent3D const & getExtent( ImageId const & image )noexcept; + CRG_API Extent3D const & getExtent( ImageViewId const & image )noexcept; + CRG_API Extent3D getMipExtent( ImageViewId const & image )noexcept; + CRG_API PixelFormat getFormat( ImageId const & image )noexcept; + CRG_API PixelFormat getFormat( ImageViewId const & image )noexcept; + CRG_API ImageType getImageType( ImageId const & image )noexcept; + CRG_API ImageType getImageType( ImageViewId const & image )noexcept; + CRG_API ImageViewType getImageViewType( ImageViewId const & image )noexcept; + CRG_API uint32_t getMipLevels( ImageId const & image )noexcept; + CRG_API uint32_t getMipLevels( ImageViewId const & image )noexcept; + CRG_API uint32_t getArrayLayers( ImageId const & image )noexcept; + CRG_API uint32_t getArrayLayers( ImageViewId const & image )noexcept; + CRG_API ImageAspectFlags getAspectFlags( ImageViewId const & image )noexcept; + CRG_API ImageSubresourceRange const & getSubresourceRange( ImageViewId const & format )noexcept; + CRG_API AccessFlags getAccessMask( ImageLayout layout )noexcept; + CRG_API PipelineStageFlags getStageMask( ImageLayout layout )noexcept; + CRG_API PipelineState getPipelineState( PipelineStageFlags flags )noexcept; + CRG_API LayoutState makeLayoutState( ImageLayout layout )noexcept; + CRG_API ImageAspectFlags getAspectMask( PixelFormat format )noexcept; + CRG_API LayoutState const & addSubresourceRangeLayout( LayerLayoutStates & ranges + , ImageSubresourceRange const & range + , LayoutState const & newLayout ); + CRG_API LayoutState getSubresourceRangeLayout( LayerLayoutStates const & ranges + , ImageSubresourceRange const & range ); + CRG_API ImageSubresourceRange getVirtualRange( ImageId const & image + , ImageViewType viewType + , ImageSubresourceRange const & range )noexcept; + CRG_API bool match( ImageViewId const & lhs, ImageViewId const & rhs )noexcept; + CRG_API bool match( Buffer const & lhs, Buffer const & rhs )noexcept; + CRG_API ImageViewId const & resolveView( ImageViewId const & view + , uint32_t passIndex ); + + CRG_API void convert( SemaphoreWaitArray const & toWait + , std::vector< VkSemaphore > & semaphores + , std::vector< VkPipelineStageFlags > & dstStageMasks ); + CRG_API std::vector< VkClearValue > convert( std::vector< ClearValue > const & v ); + CRG_API VkQueryPool createQueryPool( GraphContext & context + , std::string const & name + , uint32_t passesCount ); + + CRG_API ClearColorValue getClearColorValue( ClearValue const & v ); + CRG_API ClearDepthStencilValue getClearDepthStencilValue( ClearValue const & v ); + + constexpr VkFormat convert( PixelFormat v )noexcept + { + return VkFormat( v ); + } + + constexpr PixelFormat convert( VkFormat v )noexcept + { + return PixelFormat( v ); + } + + constexpr bool isDepthFormat( PixelFormat fmt )noexcept + { + return fmt == PixelFormat::eD16_UNORM + || fmt == PixelFormat::eX8_D24_UNORM + || fmt == PixelFormat::eD32_SFLOAT + || fmt == PixelFormat::eD16_UNORM_S8_UINT + || fmt == PixelFormat::eD24_UNORM_S8_UINT + || fmt == PixelFormat::eD32_SFLOAT_S8_UINT; + } + + constexpr bool isStencilFormat( PixelFormat fmt )noexcept + { + return fmt == PixelFormat::eS8_UINT + || fmt == PixelFormat::eD16_UNORM_S8_UINT + || fmt == PixelFormat::eD24_UNORM_S8_UINT + || fmt == PixelFormat::eD32_SFLOAT_S8_UINT; + } + + constexpr bool isColourFormat( PixelFormat fmt )noexcept + { + return !isDepthFormat( fmt ) && !isStencilFormat( fmt ); + } + + constexpr bool isDepthStencilFormat( PixelFormat fmt )noexcept + { + return isDepthFormat( fmt ) && isStencilFormat( fmt ); + } + + constexpr bool isDepthOrStencilFormat( PixelFormat fmt )noexcept + { + return isDepthFormat( fmt ) || isStencilFormat( fmt ); + } + + constexpr VkImageType convert( ImageType v )noexcept + { + return VkImageType( v ); + } + + constexpr ImageType convert( VkImageType v )noexcept + { + return ImageType( v ); + } + + constexpr VkSampleCountFlagBits convert( SampleCount v )noexcept + { + return VkSampleCountFlagBits( v ); + } + + constexpr SampleCount convert( VkSampleCountFlagBits v )noexcept + { + return SampleCount( v ); + } + + constexpr VkImageTiling convert( ImageTiling v )noexcept + { + return VkImageTiling( v ); + } + + constexpr ImageTiling convert( VkImageTiling v )noexcept + { + return ImageTiling( v ); + } + + constexpr VkImageViewType convert( ImageViewType v )noexcept + { + return VkImageViewType( v ); + } + + constexpr ImageViewType convert( VkImageViewType v )noexcept + { + return ImageViewType( v ); + } + + constexpr VkImageLayout convert( ImageLayout v )noexcept + { + return VkImageLayout( v ); + } + + constexpr ImageLayout convert( VkImageLayout v )noexcept + { + return ImageLayout( v ); + } + + constexpr VkFilter convert( FilterMode v )noexcept + { + return VkFilter( v ); + } + + constexpr FilterMode convert( VkFilter v )noexcept + { + return FilterMode( v ); + } + + constexpr VkSamplerMipmapMode convert( MipmapMode v )noexcept + { + return VkSamplerMipmapMode( v ); + } + + constexpr MipmapMode convert( VkSamplerMipmapMode v )noexcept + { + return MipmapMode( v ); + } + + constexpr VkSamplerAddressMode convert( WrapMode v )noexcept + { + return VkSamplerAddressMode( v ); + } + + constexpr WrapMode convert( VkSamplerAddressMode v )noexcept + { + return WrapMode( v ); + } + + constexpr VkAttachmentLoadOp convert( AttachmentLoadOp v )noexcept + { + return VkAttachmentLoadOp( v ); + } + + constexpr AttachmentLoadOp convert( VkAttachmentLoadOp v )noexcept + { + return AttachmentLoadOp( v ); + } + + constexpr VkBlendFactor convert( BlendFactor v )noexcept + { + return VkBlendFactor( v ); + } + + constexpr BlendFactor convert( VkBlendFactor v )noexcept + { + return BlendFactor( v ); + } + + constexpr VkBlendOp convert( BlendOp v )noexcept + { + return VkBlendOp( v ); + } + + constexpr BlendOp convert( VkBlendOp v )noexcept + { + return BlendOp( v ); + } + + constexpr VkAttachmentStoreOp convert( AttachmentStoreOp v )noexcept + { + return VkAttachmentStoreOp( v ); + } + + constexpr AttachmentStoreOp convert( VkAttachmentStoreOp v )noexcept + { + return AttachmentStoreOp( v ); + } + + constexpr VkImageCreateFlags getImageCreateFlags( ImageCreateFlags v )noexcept + { + return VkImageCreateFlags( v ); + } + + constexpr ImageCreateFlags getImageCreateFlags( VkImageCreateFlags v )noexcept + { + return ImageCreateFlags( v ); + } + + constexpr VkImageUsageFlags getImageUsageFlags( ImageUsageFlags v )noexcept + { + return VkImageUsageFlags( v ); + } + + constexpr ImageUsageFlags getImageUsageFlags( VkImageUsageFlags v )noexcept + { + return ImageUsageFlags( v ); + } + + constexpr VkImageViewCreateFlags getImageViewCreateFlags( ImageViewCreateFlags v )noexcept + { + return VkImageViewCreateFlags( v ); + } + + constexpr ImageViewCreateFlags getImageViewCreateFlags( VkImageViewCreateFlags v )noexcept + { + return ImageViewCreateFlags( v ); + } + + constexpr VkImageAspectFlags getImageAspectFlags( ImageAspectFlags v )noexcept + { + return VkImageAspectFlags( v ); + } + + constexpr ImageAspectFlags getImageAspectFlags( VkImageAspectFlags v )noexcept + { + return ImageAspectFlags( v ); + } + + constexpr VkPipelineStageFlags getPipelineStageFlags( PipelineStageFlags v )noexcept + { + return VkPipelineStageFlags( v ); + } + + constexpr PipelineStageFlags getPipelineStageFlags( VkPipelineStageFlags v )noexcept + { + return PipelineStageFlags( v ); + } + + constexpr VkAccessFlags getAccessFlags( AccessFlags v )noexcept + { + return VkAccessFlags( v ); + } + + constexpr AccessFlags getAccessFlags( VkAccessFlags v )noexcept + { + return AccessFlags( v ); + } + + constexpr VkColorComponentFlags getColorComponentFlags( ColorComponentFlags v )noexcept + { + return VkColorComponentFlags( v ); + } + + constexpr ColorComponentFlags getColorComponentFlags( VkColorComponentFlags v )noexcept + { + return ColorComponentFlags( v ); + } + + constexpr VkExtent2D convert( Extent2D const & v )noexcept + { + return std::bit_cast< VkExtent2D >( v ); + } + + constexpr Extent2D convert( VkExtent2D const & v )noexcept + { + return std::bit_cast< Extent2D >( v ); + } + + constexpr VkOffset2D convert( Offset2D const & v )noexcept + { + return std::bit_cast< VkOffset2D >( v ); + } + + constexpr Offset2D convert( VkOffset2D const & v )noexcept + { + return std::bit_cast< Offset2D >( v ); + } + + constexpr VkRect2D convert( Rect2D const & v )noexcept + { + return std::bit_cast< VkRect2D >( v ); + } + + constexpr Rect2D convert( VkRect2D const & v )noexcept + { + return std::bit_cast< Rect2D >( v ); + } + + constexpr VkExtent3D convert( Extent3D const & v )noexcept + { + return std::bit_cast< VkExtent3D >( v ); + } + + constexpr Extent3D convert( VkExtent3D const & v )noexcept + { + return std::bit_cast< Extent3D >( v ); + } + + constexpr VkOffset3D convert( Offset3D const & v )noexcept + { + return std::bit_cast< VkOffset3D >( v ); + } + + constexpr Offset3D convert( VkOffset3D const & v )noexcept + { + return std::bit_cast< Offset3D >( v ); + } + + constexpr VkImageSubresourceRange convert( ImageSubresourceRange const & v )noexcept + { + return std::bit_cast< VkImageSubresourceRange >( v ); + } + + constexpr ImageSubresourceRange convert( VkImageSubresourceRange const & v )noexcept + { + return std::bit_cast< ImageSubresourceRange >( v ); + } + + constexpr VkPipelineColorBlendAttachmentState convert( PipelineColorBlendAttachmentState const & v )noexcept + { + return std::bit_cast< VkPipelineColorBlendAttachmentState >( v ); + } + + constexpr PipelineColorBlendAttachmentState convert( VkPipelineColorBlendAttachmentState const & v )noexcept + { + return std::bit_cast< PipelineColorBlendAttachmentState >( v ); + } + + constexpr VkClearDepthStencilValue convert( ClearDepthStencilValue const & v )noexcept + { + return std::bit_cast< VkClearDepthStencilValue >( v ); + } + + constexpr VkClearColorValue convert( ClearColorValue const & v )noexcept + { + if ( v.isFloat32() ) + { + VkClearColorValue result; + result.float32[0] = v.float32()[0]; + result.float32[1] = v.float32()[1]; + result.float32[2] = v.float32()[2]; + result.float32[3] = v.float32()[3]; + return result; + } + + if ( v.isInt32() ) + { + VkClearColorValue result; + result.int32[0] = v.int32()[0]; + result.int32[1] = v.int32()[1]; + result.int32[2] = v.int32()[2]; + result.int32[3] = v.int32()[3]; + return result; + } + + + VkClearColorValue result; + result.uint32[0] = v.uint32()[0]; + result.uint32[1] = v.uint32()[1]; + result.uint32[2] = v.uint32()[2]; + result.uint32[3] = v.uint32()[3]; + return result; + } + + constexpr VkClearValue convert( ClearValue const & v )noexcept + { + if ( v.isColor() ) + { + VkClearValue result; + result.color = convert( v.color() ); + return result; + } + + VkClearValue result; + result.depthStencil = convert( v.depthStencil() ); + return result; + } + + constexpr VkImageViewCreateInfo convert( ImageViewCreateInfo const & v )noexcept + { + return VkImageViewCreateInfo{ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr + , getImageViewCreateFlags( v.flags ), VkImage{}, convert( v.viewType ), convert( v.format ) + , { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY } + , convert( v.subresourceRange ) }; + } + + constexpr ImageViewCreateInfo convert( VkImageViewCreateInfo const & v )noexcept + { + return ImageViewCreateInfo{ getImageViewCreateFlags( v.flags ), convert( v.viewType ), convert( v.format ) + , convert( v.subresourceRange ) }; + } + + constexpr VkImageCreateInfo convert( ImageCreateInfo const & v )noexcept + { + return VkImageCreateInfo{ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, nullptr + , getImageCreateFlags( v.flags ), convert( v.imageType ), convert( v.format ) + , convert( v.extent ), v.mipLevels, v.arrayLayers, convert( v.samples ) + , convert( v.tiling ), getImageUsageFlags( v.usage ) + , VK_SHARING_MODE_EXCLUSIVE, 0u, nullptr + , VK_IMAGE_LAYOUT_UNDEFINED }; + } + + constexpr ImageCreateInfo convert( VkImageCreateInfo const & v )noexcept + { + return ImageCreateInfo{ getImageCreateFlags( v.flags ), convert( v.imageType ), convert( v.format ) + , convert( v.extent ), v.mipLevels, v.arrayLayers, convert( v.samples ) + , convert( v.tiling ), getImageUsageFlags( v.usage ) }; + } + + inline VkImageSubresourceLayers getSubresourceLayers( ImageSubresourceRange const & range + , uint32_t layerCount ) + { + return VkImageSubresourceLayers{ getImageAspectFlags( range.aspectMask ) + , range.baseMipLevel + , range.baseArrayLayer + , layerCount }; + } + + inline VkImageSubresourceLayers getSubresourceLayers( ImageSubresourceRange const & range ) + { + return getSubresourceLayers( range, range.layerCount ); + } + + inline VkImageSubresourceLayers getSubresourceLayer( ImageSubresourceRange const & range ) + { + return getSubresourceLayers( range, 1u ); + } +} diff --git a/include/RenderGraph/FrameGraphPrerequisites.hpp b/include/RenderGraph/FrameGraphPrerequisites.hpp index 411fd05..ac35809 100644 --- a/include/RenderGraph/FrameGraphPrerequisites.hpp +++ b/include/RenderGraph/FrameGraphPrerequisites.hpp @@ -4,628 +4,11 @@ See LICENSE file in root folder. */ #pragma once -#include - -#pragma warning( push ) -#pragma warning( disable: 4365 ) -#pragma warning( disable: 5262 ) -#include -#include -#include -#include -#include -#include -#include -#include -#pragma warning( pop ) - -#if !defined( _WIN32 ) || defined( CRG_BUILD_STATIC ) -# define CRG_API -#else -# if defined( RenderGraph_EXPORTS ) -# define CRG_API __declspec( dllexport ) -# else -# define CRG_API __declspec( dllimport ) -# endif -#endif - -#define CRG_MakeFlags( FlagBits )\ - constexpr FlagBits operator|( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) | std::underlying_type_t< FlagBits >( rhs ) ); }\ - constexpr FlagBits operator&( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) & std::underlying_type_t< FlagBits >( rhs ) ); }\ - constexpr FlagBits operator^( FlagBits lhs, FlagBits rhs ) { return FlagBits( std::underlying_type_t< FlagBits >( lhs ) ^ std::underlying_type_t< FlagBits >( rhs ) ); }\ - constexpr FlagBits & operator|=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs | rhs; }\ - constexpr FlagBits & operator&=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs & rhs; }\ - constexpr FlagBits & operator^=( FlagBits & lhs, FlagBits rhs ) { return lhs = lhs ^ rhs; }\ - constexpr bool checkFlag( FlagBits lhs, FlagBits rhs ) { return ( lhs & rhs ) == rhs; } +#include "FrameGraphFunctions.hpp" namespace crg { - enum class PixelFormat : uint32_t - { -#define RGPF_ENUM_VALUE( name, value, components, alpha, colour, depth, stencil, compressed ) e##name = value, -#define RGPF_ENUM_NON_VALUE( name, value ) e##name = value, -#include "PixelFormat.enum" - }; - - enum class ImageType : uint32_t - { - e1D = 0, - e2D = 1, - e3D = 2, - }; - - enum class ImageViewType : uint32_t - { - e1D = 0, - e2D = 1, - e3D = 2, - eCube = 3, - e1DArray = 4, - e2DArray = 5, - eCubeArray = 6, - }; - - enum class ImageLayout : uint32_t - { - eUndefined = 0, - eGeneral = 1, - eColorAttachment = 2, - eDepthStencilAttachment = 3, - eDepthStencilReadOnly = 4, - eShaderReadOnly = 5, - eTransferSrc = 6, - eTransferDst = 7, - ePreinitialized = 8, - eDepthReadOnlyStencilAttachment = 1000117000, - eDepthAttachmentStencilReadOnly = 1000117001, - eDepthAttachment = 1000241000, - eDepthReadOnly = 1000241001, - eStencilAttachment = 1000241002, - eStencilReadOnly = 1000241003, - eReadOnly = 1000314000, - eAttachment = 1000314001, - eRenderingLocalRead = 1000232000, - ePresentSrc = 1000001002, - eVideoDecodeDst = 1000024000, - eVideoDecodeSrc = 1000024001, - eVideoDecodeDpb = 1000024002, - eSharedPresent = 1000111000, - eFragmentDensityMap = 1000218000, - eFragmentShadingRateAttachment = 1000164003, - eVideoEncodeDst = 1000299000, - eVideoEncodeSrc = 1000299001, - eVideoEncodeDpb = 1000299002, - eAttachmentFeedbackLoop = 1000339000, - eVideoEncodeQuantizationMap = 1000553000, - }; - - enum class FilterMode : uint32_t - { - eNearest, - eLinear, - }; - - enum class MipmapMode : uint32_t - { - eNearest, - eLinear, - }; - - enum class WrapMode : uint32_t - { - eRepeat, - eMirroredRepeat, - eClampToBorder, - eClampToEdge, - eMirrorClampToEdge, - }; - - enum class PipelineStageFlags : uint32_t - { - eNone = 0, - eTopOfPipe = 0x00000001, - eDrawIndirect = 0x00000002, - eVertexInput = 0x00000004, - eVertexShader = 0x00000008, - eTessellationControlShader = 0x00000010, - eTessellationEvaluationShader = 0x00000020, - eGeometryShader = 0x00000040, - eFragmentShader = 0x00000080, - eEarlyFragmentTests = 0x00000100, - eLateFragmentTests = 0x00000200, - eColorAttachmentOutput = 0x00000400, - eComputeShader = 0x00000800, - eTransfer = 0x00001000, - eBottomOfPipe = 0x00002000, - eHost = 0x00004000, - eAllGraphics = 0x00008000, - eAllCommands = 0x00010000, - eTransformFeedback = 0x01000000, - eConditionalRendering = 0x00040000, - eAccelerationStructureBuild = 0x02000000, - eRayTracingShader = 0x00200000, - eFragmentDensityProcess = 0x00800000, - eFragmentShadingRateAttachment = 0x00400000, - eTaskShader = 0x00080000, - eMeshShader = 0x00100000, - eCommandPreprocess = 0x00020000, - }; - CRG_MakeFlags( PipelineStageFlags ) - - enum class AccessFlags : uint32_t - { - eNone = 0, - eIndirectCommandRead = 0x00000001, - eIndexRead = 0x00000002, - eVertexAttributeRead = 0x00000004, - eUniformRead = 0x00000008, - eInputAttachmentRead = 0x00000010, - eShaderRead = 0x00000020, - eShaderWrite = 0x00000040, - eColorAttachmentRead = 0x00000080, - eColorAttachmentWrite = 0x00000100, - eDepthStencilAttachmentRead = 0x00000200, - eDepthStencilAttachmentWrite = 0x00000400, - eTransferRead = 0x00000800, - eTransferWrite = 0x00001000, - eHostRead = 0x00002000, - eHostWrite = 0x00004000, - eMemoryRead = 0x00008000, - eMemoryWrite = 0x00010000, - eTransformFeedbackWrite = 0x02000000, - eTransformFeedback_counterRead = 0x04000000, - eTransformFeedback_counterWrite = 0x08000000, - eConditionalRenderingRead = 0x00100000, - eColorAttachmentReadNonCoherent = 0x00080000, - eAccelerationStructureRead = 0x00200000, - eAccelerationStructureWrite = 0x00400000, - eFragmentDensityMapRead = 0x01000000, - eFragmentShadingRateAttachmentRead = 0x00800000, - eCommandPreprocessRead = 0x00020000, - eCommandPreprocessWrite = 0x00040000, - }; - CRG_MakeFlags( AccessFlags ) - - CRG_API std::string_view getName( PixelFormat v ); - CRG_API std::string_view getName( FilterMode v ); - CRG_API std::string_view getName( MipmapMode v ); - CRG_API std::string_view getName( WrapMode v ); - - constexpr VkFormat convert( PixelFormat v )noexcept - { - return VkFormat( v ); - } - - constexpr PixelFormat convert( VkFormat v )noexcept - { - return PixelFormat( v ); - } - - constexpr bool isDepthFormat( PixelFormat fmt )noexcept - { - return fmt == PixelFormat::eD16_UNORM - || fmt == PixelFormat::eX8_D24_UNORM - || fmt == PixelFormat::eD32_SFLOAT - || fmt == PixelFormat::eD16_UNORM_S8_UINT - || fmt == PixelFormat::eD24_UNORM_S8_UINT - || fmt == PixelFormat::eD32_SFLOAT_S8_UINT; - } - - constexpr bool isStencilFormat( PixelFormat fmt )noexcept - { - return fmt == PixelFormat::eS8_UINT - || fmt == PixelFormat::eD16_UNORM_S8_UINT - || fmt == PixelFormat::eD24_UNORM_S8_UINT - || fmt == PixelFormat::eD32_SFLOAT_S8_UINT; - } - - constexpr bool isColourFormat( PixelFormat fmt )noexcept - { - return !isDepthFormat( fmt ) && !isStencilFormat( fmt ); - } - - constexpr bool isDepthStencilFormat( PixelFormat fmt )noexcept - { - return isDepthFormat( fmt ) && isStencilFormat( fmt ); - } - - constexpr bool isDepthOrStencilFormat( PixelFormat fmt )noexcept - { - return isDepthFormat( fmt ) || isStencilFormat( fmt ); - } - - constexpr VkImageType convert( ImageType v )noexcept - { - return VkImageType( v ); - } - - constexpr ImageType convert( VkImageType v )noexcept - { - return ImageType( v ); - } - - constexpr VkImageViewType convert( ImageViewType v )noexcept - { - return VkImageViewType( v ); - } - - constexpr ImageViewType convert( VkImageViewType v )noexcept - { - return ImageViewType( v ); - } - - constexpr VkImageLayout convert( ImageLayout v )noexcept - { - return VkImageLayout( v ); - } - - constexpr ImageLayout convert( VkImageLayout v )noexcept - { - return ImageLayout( v ); - } - - constexpr VkFilter convert( FilterMode v )noexcept - { - return VkFilter( v ); - } - - constexpr FilterMode convert( VkFilter v )noexcept - { - return FilterMode( v ); - } - - constexpr VkSamplerMipmapMode convert( MipmapMode v )noexcept - { - return VkSamplerMipmapMode( v ); - } - - constexpr MipmapMode convert( VkSamplerMipmapMode v )noexcept - { - return MipmapMode( v ); - } - - constexpr VkSamplerAddressMode convert( WrapMode v )noexcept - { - return VkSamplerAddressMode( v ); - } - - constexpr WrapMode convert( VkSamplerAddressMode v )noexcept - { - return WrapMode( v ); - } - - constexpr VkPipelineStageFlags convert( PipelineStageFlags v )noexcept - { - return VkPipelineStageFlags( v ); - } - - constexpr PipelineStageFlags getPipelineStageFlags( VkPipelineStageFlags v )noexcept - { - return PipelineStageFlags( v ); - } - - constexpr VkAccessFlags convert( AccessFlags v )noexcept - { - return VkAccessFlags( v ); - } - - constexpr AccessFlags getAccessFlags( VkAccessFlags v )noexcept - { - return AccessFlags( v ); - } - - template< typename DataT > - struct Id; - - struct Attachment; - struct AttachmentTransitions; - struct Buffer; - struct FramePassTransitions; - struct GraphContext; - struct ImageData; - struct ImageViewData; - struct GraphNode; - struct FramePass; - struct FramePassGroup; - struct RootNode; - struct SamplerDesc; - struct Texcoord; - struct WriteDescriptorSet; - - class ContextResourcesCache; - class Exception; - class Fence; - class FrameGraph; - class FramePassTimer; - class GraphVisitor; - class RecordContext; - class ResourceHandler; - class ResourcesCache; - class RunnableGraph; - class RunnablePass; - - class ImageCopy; - class PipelinePass; - class RenderPass; - class RenderQuad; - - using ImageId = Id< ImageData >; - using ImageViewId = Id< ImageViewData >; - using DependencyCache = std::unordered_map< size_t, bool >; - using PassDependencyCache = std::unordered_map< FramePass const *, DependencyCache >; - - using FramePassPtr = std::unique_ptr< FramePass >; - using FramePassGroupPtr = std::unique_ptr< FramePassGroup >; - using GraphNodePtr = std::unique_ptr< GraphNode >; - using RunnableGraphPtr = std::unique_ptr< RunnableGraph >; - using RunnablePassPtr = std::unique_ptr< RunnablePass >; - using GraphAdjacentNode = GraphNode *; - using ConstGraphAdjacentNode = GraphNode const *; - - template< typename DataT > - struct DataTransitionT; - template< typename DataT > - using DataTransitionArrayT = std::vector< DataTransitionT< DataT > >; - /** - *\brief - * The transition between two states of an image view. - */ - using ViewTransition = DataTransitionT< ImageViewId >; - using ViewTransitionArray = DataTransitionArrayT< ImageViewId >; - /** - *\brief - * The transition between two states of a storage buffer. - */ - using BufferTransition = DataTransitionT< Buffer >; - using BufferTransitionArray = DataTransitionArrayT< Buffer >; - - using AttachmentArray = std::vector< Attachment >; - using FramePassPtrArray = std::vector< FramePassPtr >; - using FramePassGroupPtrArray = std::vector< FramePassGroupPtr >; - using FrameGraphArray = std::vector< FrameGraph const * >; - using FramePassArray = std::vector< FramePass const * >; - using GraphAdjacentNodeArray = std::vector< GraphAdjacentNode >; - using ConstGraphAdjacentNodeArray = std::vector< ConstGraphAdjacentNode >; - using GraphNodePtrArray = std::vector< GraphNodePtr >; - using FramePassDependencies = std::vector< FramePassTransitions >; - using WriteDescriptorSetArray = std::vector< WriteDescriptorSet >; - using AttachmentsNodeMap = std::map< ConstGraphAdjacentNode, AttachmentTransitions >; - using ImageMemoryMap = std::map< ImageId, std::pair< VkImage, VkDeviceMemory > >; - using ImageViewMap = std::map< ImageViewId, VkImageView >; - using ImageIdArray = std::vector< ImageId >; - using ImageViewIdArray = std::vector< ImageViewId >; - - template< typename DataT > - using IdAliasMap = std::map< Id< DataT >, Id< DataT > >; - using ImageIdAliasMap = IdAliasMap< ImageData >; - using ImageViewIdAliasMap = IdAliasMap< ImageViewData >; - - template< typename DataT > - using IdDataOwnerCont = std::map< Id< DataT >, std::unique_ptr< DataT > >; - using ImageIdDataOwnerCont = IdDataOwnerCont< ImageData >; - using ImageViewIdDataOwnerCont = IdDataOwnerCont< ImageViewData >; - - using VkAttachmentDescriptionArray = std::vector< VkAttachmentDescription >; - using VkAttachmentReferenceArray = std::vector< VkAttachmentReference >; - using VkBufferArray = std::vector< VkBuffer >; - using VkBufferViewArray = std::vector< VkBufferView >; - using VkDescriptorBufferInfoArray = std::vector< VkDescriptorBufferInfo >; - using VkDescriptorImageInfoArray = std::vector< VkDescriptorImageInfo >; - using VkDescriptorSetLayoutBindingArray = std::vector< VkDescriptorSetLayoutBinding >; - using VkDescriptorPoolSizeArray = std::vector< VkDescriptorPoolSize >; - using VkImageViewArray = std::vector< VkImageView >; - using VkPipelineColorBlendAttachmentStateArray = std::vector< VkPipelineColorBlendAttachmentState >; - using VkPipelineShaderStageCreateInfoArray = std::vector< VkPipelineShaderStageCreateInfo >; - using VkPushConstantRangeArray = std::vector< VkPushConstantRange >; - using VkScissorArray = std::vector< VkRect2D >; - using VkSubpassDependencyArray = std::vector< VkSubpassDependency >; - using VkVertexInputAttributeDescriptionArray = std::vector< VkVertexInputAttributeDescription >; - using VkVertexInputBindingDescriptionArray = std::vector< VkVertexInputBindingDescription >; - using VkViewportArray = std::vector< VkViewport >; - using VkWriteDescriptorSetArray = std::vector< VkWriteDescriptorSet >; - - struct PipelineState - { - AccessFlags access; - PipelineStageFlags pipelineStage; - }; - - struct LayoutState - { - ImageLayout layout; - PipelineState state; - }; - - using AccessState = PipelineState; - - using MipLayoutStates = std::map< uint32_t, LayoutState >; - using LayerLayoutStates = std::map< uint32_t, MipLayoutStates >; - using LayoutStateMap = std::unordered_map< uint32_t, LayerLayoutStates >; - using LayerLayoutStatesMap = std::map< uint32_t, LayerLayoutStates >; - using AccessStateMap = std::unordered_map< VkBuffer, AccessState >; - using ViewsLayout = LayoutStateMap; - using BuffersLayout = AccessStateMap; - using ViewsLayoutPtr = std::unique_ptr< ViewsLayout >; - using BuffersLayoutPtr = std::unique_ptr< BuffersLayout >; - using ViewsLayouts = std::vector< ViewsLayoutPtr >; - using BuffersLayouts = std::vector< BuffersLayoutPtr >; - - using ViewLayoutIterators = std::map< uint32_t, ViewsLayouts::iterator >; - using BufferLayoutIterators = std::map< uint32_t, BuffersLayouts::iterator >; - - template< typename VkTypeT > - struct ContextObjectT - { - ContextObjectT( ContextObjectT const & rhs ) = delete; - ContextObjectT( ContextObjectT && rhs )noexcept = delete; - ContextObjectT & operator=( ContextObjectT const & rhs ) = delete; - ContextObjectT & operator=( ContextObjectT && rhs )noexcept = delete; - - explicit ContextObjectT( GraphContext & ctx - , VkTypeT obj = {} - , void( *dtor )( GraphContext &, VkTypeT & )noexcept = nullptr ) - : context{ ctx } - , object{ obj } - , destroy{ dtor } - { - } - - ~ContextObjectT()noexcept - { - if ( destroy && object ) - { - destroy( context, object ); - } - } - - GraphContext & context; - VkTypeT object; - void ( *destroy )( GraphContext &, VkTypeT & )noexcept; - }; - - struct Buffer - { - std::string name; - - Buffer( VkBufferArray pbuffers - , std::string pname )noexcept - : name{ std::move( pname ) } - , m_buffers{ std::move( pbuffers ) } - { - } - - Buffer( VkBuffer buffer - , std::string name )noexcept - : Buffer{ VkBufferArray{ buffer }, std::move( name ) } - { - } - - VkBuffer const & buffer( uint32_t index = 0 )const noexcept - { - return m_buffers.size() == 1u - ? m_buffers.front() - : m_buffers[index]; - } - - VkBuffer & buffer( uint32_t index = 0 )noexcept - { - return m_buffers.size() == 1u - ? m_buffers.front() - : m_buffers[index]; - } - - size_t getCount()const noexcept - { - return m_buffers.size(); - } - - private: - VkBufferArray m_buffers; - - friend CRG_API bool operator==( Buffer const & lhs, Buffer const & rhs ); - }; - - CRG_API bool operator==( Buffer const & lhs, Buffer const & rhs ); - - struct VertexBuffer - { - VertexBuffer( VertexBuffer const & rhs ) = delete; - VertexBuffer & operator=( VertexBuffer const & rhs ) = delete; - ~VertexBuffer()noexcept = default; - - explicit VertexBuffer( Buffer pbuffer = { VkBuffer{}, std::string{} } - , VkDeviceMemory pmemory = VkDeviceMemory{} - , VkVertexInputAttributeDescriptionArray pvertexAttribs = {} - , VkVertexInputBindingDescriptionArray pvertexBindings = {} ) - : buffer{ std::move( pbuffer ) } - , memory{ pmemory } - , vertexAttribs{ std::move( pvertexAttribs ) } - , vertexBindings{ std::move( pvertexBindings ) } - { - inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); - inputState.pVertexAttributeDescriptions = vertexAttribs.data(); - inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); - inputState.pVertexBindingDescriptions = vertexBindings.data(); - } - - VertexBuffer( VertexBuffer && rhs )noexcept - : buffer{ rhs.buffer } - , memory{ rhs.memory } - , vertexAttribs{ std::move( rhs.vertexAttribs ) } - , vertexBindings{ std::move( rhs.vertexBindings ) } - , inputState{ std::move( rhs.inputState ) } - { - inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); - inputState.pVertexAttributeDescriptions = vertexAttribs.data(); - inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); - inputState.pVertexBindingDescriptions = vertexBindings.data(); - } - - VertexBuffer & operator=( VertexBuffer && rhs )noexcept - { - buffer = rhs.buffer; - memory = rhs.memory; - vertexAttribs = std::move( rhs.vertexAttribs ); - vertexBindings = std::move( rhs.vertexBindings ); - inputState = std::move( rhs.inputState ); - - inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); - inputState.pVertexAttributeDescriptions = vertexAttribs.data(); - inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); - inputState.pVertexBindingDescriptions = vertexBindings.data(); - - return *this; - } - - Buffer buffer{ VkBuffer{}, std::string{} }; - VkDeviceMemory memory{}; - VkVertexInputAttributeDescriptionArray vertexAttribs{}; - VkVertexInputBindingDescriptionArray vertexBindings{}; - VkPipelineVertexInputStateCreateInfo inputState{ VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, nullptr, {}, {}, {}, {}, {} }; - }; - - using VertexBufferPtr = std::unique_ptr< VertexBuffer >; - - struct IndexBuffer - { - explicit IndexBuffer( Buffer pbuffer = { VkBuffer{}, std::string{} } - , VkDeviceMemory pmemory = VkDeviceMemory{} ) - : buffer{ std::move( pbuffer ) } - , memory{ pmemory } - { - } - - Buffer buffer; - VkDeviceMemory memory; - }; - - struct IndirectBuffer - { - explicit IndirectBuffer( Buffer pbuffer - , uint32_t pstride - , VkDeviceSize poffset = {} ) - : buffer{ std::move( pbuffer ) } - , offset{ poffset } - , stride{ pstride } - { - } - - Buffer buffer; - VkDeviceSize offset; - uint32_t stride; - }; - - static constexpr VkPipelineColorBlendAttachmentState DefaultBlendState{ VK_FALSE - , VK_BLEND_FACTOR_ONE - , VK_BLEND_FACTOR_ZERO - , VK_BLEND_OP_ADD - , VK_BLEND_FACTOR_ONE - , VK_BLEND_FACTOR_ZERO - , VK_BLEND_OP_ADD - , VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT }; - - template< typename TypeT > - struct DefaultValueGetterT; + static constexpr PipelineColorBlendAttachmentState DefaultBlendState; template< typename TypeT > static inline const TypeT defaultV = DefaultValueGetterT< TypeT >::get(); @@ -665,56 +48,6 @@ namespace crg } }; - template< typename TypeT > - struct RawTyperT - { - using Type = TypeT; - }; - template< typename TypeT > using RawTypeT = typename RawTyperT< TypeT >::Type; - - struct SemaphoreWait - { - VkSemaphore semaphore; - PipelineStageFlags dstStageMask; - }; - - using SemaphoreWaitArray = std::vector< SemaphoreWait >; - - CRG_API VkExtent3D const & getExtent( ImageId const & image )noexcept; - CRG_API VkExtent3D const & getExtent( ImageViewId const & image )noexcept; - CRG_API VkExtent3D getMipExtent( ImageViewId const & image )noexcept; - CRG_API PixelFormat getFormat( ImageId const & image )noexcept; - CRG_API PixelFormat getFormat( ImageViewId const & image )noexcept; - CRG_API ImageType getImageType( ImageId const & image )noexcept; - CRG_API ImageType getImageType( ImageViewId const & image )noexcept; - CRG_API ImageViewType getImageViewType( ImageViewId const & image )noexcept; - CRG_API uint32_t getMipLevels( ImageId const & image )noexcept; - CRG_API uint32_t getMipLevels( ImageViewId const & image )noexcept; - CRG_API uint32_t getArrayLayers( ImageId const & image )noexcept; - CRG_API uint32_t getArrayLayers( ImageViewId const & image )noexcept; - CRG_API AccessFlags getAccessMask( ImageLayout layout )noexcept; - CRG_API PipelineStageFlags getStageMask( ImageLayout layout )noexcept; - CRG_API PipelineState getPipelineState( PipelineStageFlags flags )noexcept; - CRG_API LayoutState makeLayoutState( ImageLayout layout )noexcept; - CRG_API VkImageAspectFlags getAspectMask( PixelFormat format )noexcept; - CRG_API LayoutState const & addSubresourceRangeLayout( LayerLayoutStates & ranges - , VkImageSubresourceRange const & range - , LayoutState const & newLayout ); - CRG_API LayoutState getSubresourceRangeLayout( LayerLayoutStates const & ranges - , VkImageSubresourceRange const & range ); - CRG_API VkImageSubresourceRange getVirtualRange( ImageId const & image - , ImageViewType viewType - , VkImageSubresourceRange const & range )noexcept; - CRG_API bool match( ImageViewData const & lhs, ImageViewData const & rhs )noexcept; - CRG_API ImageViewId const & resolveView( ImageViewId const & view - , uint32_t passIndex ); - - CRG_API void convert( SemaphoreWaitArray const & toWait - , std::vector< VkSemaphore > & semaphores - , std::vector< VkPipelineStageFlags > & dstStageMasks ); - CRG_API VkQueryPool createQueryPool( GraphContext & context - , std::string const & name - , uint32_t passesCount ); } diff --git a/include/RenderGraph/FrameGraphStructs.hpp b/include/RenderGraph/FrameGraphStructs.hpp new file mode 100644 index 0000000..97764f3 --- /dev/null +++ b/include/RenderGraph/FrameGraphStructs.hpp @@ -0,0 +1,417 @@ +/* +This file belongs to FrameGraph. +See LICENSE file in root folder. +*/ +#pragma once + +#include "FrameGraphEnums.hpp" + +#include +#include + +namespace crg +{ + struct Offset2D + { + int32_t x; + int32_t y; + + private: + friend bool operator==( Offset2D const & lhs, Offset2D const & rhs ) = default; + }; + + struct Extent2D + { + uint32_t width; + uint32_t height; + + private: + friend bool operator==( Extent2D const & lhs, Extent2D const & rhs ) = default; + }; + + struct Rect2D + { + Offset2D offset; + Extent2D extent; + + private: + friend bool operator==( Rect2D const & lhs, Rect2D const & rhs ) = default; + }; + + struct Offset3D + { + int32_t x; + int32_t y; + int32_t z; + + private: + friend bool operator==( Offset3D const & lhs, Offset3D const & rhs ) = default; + }; + + struct Extent3D + { + uint32_t width; + uint32_t height; + uint32_t depth; + + private: + friend bool operator==( Extent3D const & lhs, Extent3D const & rhs ) = default; + }; + + struct ImageSubresourceRange + { + ImageAspectFlags aspectMask; + uint32_t baseMipLevel; + uint32_t levelCount; + uint32_t baseArrayLayer; + uint32_t layerCount; + + private: + friend bool operator==( ImageSubresourceRange const & lhs, ImageSubresourceRange const & rhs ) = default; + }; + + struct ImageCreateInfo + { + ImageCreateFlags flags; + ImageType imageType; + PixelFormat format; + Extent3D extent; + uint32_t mipLevels; + uint32_t arrayLayers; + SampleCount samples; + ImageTiling tiling; + ImageUsageFlags usage; + + private: + friend bool operator==( ImageCreateInfo const & lhs, ImageCreateInfo const & rhs ) = default; + }; + + struct ImageViewCreateInfo + { + ImageViewCreateFlags flags; + ImageViewType viewType; + PixelFormat format; + ImageSubresourceRange subresourceRange; + + private: + friend bool operator==( ImageViewCreateInfo const & lhs, ImageViewCreateInfo const & rhs ) = default; + }; + + struct ClearColorValue + { + enum ValueIndex + { + eFloat32, + eInt32, + eUInt32, + }; + + template< typename ValueT > + constexpr ClearColorValue( ValueT r, ValueT g, ValueT b, ValueT a )noexcept + : m_value{ std::array< ValueT, 4u >{ r, g, b, a } } + { + } + + constexpr explicit ClearColorValue( std::array< float, 4u > v = { 0.0f, 0.0f, 0.0f, 0.0f } )noexcept + : m_value{ std::move( v ) } + { + } + + constexpr explicit ClearColorValue( std::array< int32_t, 4u > v )noexcept + : m_value{ std::move( v ) } + { + } + + constexpr explicit ClearColorValue( std::array< uint32_t, 4u > v )noexcept + : m_value{ std::move( v ) } + { + } + + constexpr bool isFloat32()const noexcept + { + return m_value.index() == eFloat32; + } + + constexpr bool isInt32()const noexcept + { + return m_value.index() == eInt32; + } + + constexpr bool isUInt32()const noexcept + { + return m_value.index() == eUInt32; + } + + constexpr std::array< float, 4u > const & float32()const noexcept + { + return std::get< eFloat32 >( m_value ); + } + + constexpr std::array< int32_t, 4u > const & int32()const noexcept + { + return std::get< eInt32 >( m_value ); + } + + constexpr std::array< uint32_t, 4u > const & uint32()const noexcept + { + return std::get< eUInt32 >( m_value ); + } + + private: + std::variant< std::array< float, 4u > + , std::array< int32_t, 4u > + , std::array< uint32_t, 4u > > m_value; + + friend bool operator==( ClearColorValue const & lhs, ClearColorValue const & rhs ) = default; + }; + + struct ClearDepthStencilValue + { + float depth; + uint32_t stencil; + + private: + friend bool operator==( ClearDepthStencilValue const & lhs, ClearDepthStencilValue const & rhs ) = default; + }; + + struct ClearValue + { + enum ValueIndex + { + eColor, + eDepthStencil, + }; + + constexpr explicit ClearValue( ClearColorValue v = ClearColorValue{} )noexcept + : m_value{ std::move( v ) } + { + } + + constexpr explicit ClearValue( ClearDepthStencilValue v )noexcept + : m_value{ std::move( v ) } + { + } + + constexpr bool isColor()const noexcept + { + return m_value.index() == eColor; + } + + constexpr bool isDepthStencil()const noexcept + { + return m_value.index() == eDepthStencil; + } + + constexpr ClearColorValue const & color()const noexcept + { + return std::get< eColor >( m_value ); + } + + constexpr ClearDepthStencilValue const & depthStencil()const noexcept + { + return std::get< eDepthStencil >( m_value ); + } + + private: + std::variant< ClearColorValue, ClearDepthStencilValue > m_value; + + friend bool operator==( ClearValue const & lhs, ClearValue const & rhs ) = default; + }; + + struct PipelineColorBlendAttachmentState + { + uint32_t blendEnable{ VK_FALSE }; + BlendFactor srcColorBlendFactor{ BlendFactor::eOne }; + BlendFactor dstColorBlendFactor{ BlendFactor::eZero }; + BlendOp colorBlendOp{ BlendOp::eAdd }; + BlendFactor srcAlphaBlendFactor{ BlendFactor::eOne }; + BlendFactor dstAlphaBlendFactor{ BlendFactor::eZero }; + BlendOp alphaBlendOp{ BlendOp::eAdd }; + ColorComponentFlags colorWriteMask{ ColorComponentFlags::eR | ColorComponentFlags::eG | ColorComponentFlags::eB | ColorComponentFlags::eA }; + + private: + friend bool operator==( PipelineColorBlendAttachmentState const & lhs, PipelineColorBlendAttachmentState const & rhs ) = default; + }; + + struct PipelineState + { + AccessFlags access; + PipelineStageFlags pipelineStage; + }; + + struct LayoutState + { + ImageLayout layout; + PipelineState state; + }; + + template< typename VkTypeT > + struct ContextObjectT + { + ContextObjectT( ContextObjectT const & rhs ) = delete; + ContextObjectT( ContextObjectT && rhs )noexcept = delete; + ContextObjectT & operator=( ContextObjectT const & rhs ) = delete; + ContextObjectT & operator=( ContextObjectT && rhs )noexcept = delete; + + explicit ContextObjectT( GraphContext & ctx + , VkTypeT obj = {} + , void( *dtor )( GraphContext &, VkTypeT & )noexcept = nullptr ) + : context{ ctx } + , object{ obj } + , destroy{ dtor } + { + } + + ~ContextObjectT()noexcept + { + if ( destroy && object ) + { + destroy( context, object ); + } + } + + GraphContext & context; + VkTypeT object; + void ( *destroy )( GraphContext &, VkTypeT & )noexcept; + }; + + struct Buffer + { + std::string name; + + Buffer( VkBufferArray pbuffers + , std::string pname )noexcept + : name{ std::move( pname ) } + , m_buffers{ std::move( pbuffers ) } + { + } + + Buffer( VkBuffer buffer + , std::string name )noexcept + : Buffer{ VkBufferArray{ buffer }, std::move( name ) } + { + } + + VkBuffer const & buffer( uint32_t index = 0 )const noexcept + { + return m_buffers.size() == 1u + ? m_buffers.front() + : m_buffers[index]; + } + + VkBuffer & buffer( uint32_t index = 0 )noexcept + { + return m_buffers.size() == 1u + ? m_buffers.front() + : m_buffers[index]; + } + + size_t getCount()const noexcept + { + return m_buffers.size(); + } + + private: + VkBufferArray m_buffers; + + friend CRG_API bool operator==( Buffer const & lhs, Buffer const & rhs ); + }; + + struct VertexBuffer + { + VertexBuffer( VertexBuffer const & rhs ) = delete; + VertexBuffer & operator=( VertexBuffer const & rhs ) = delete; + ~VertexBuffer()noexcept = default; + + explicit VertexBuffer( Buffer pbuffer = { VkBuffer{}, std::string{} } + , VkDeviceMemory pmemory = VkDeviceMemory{} + , VkVertexInputAttributeDescriptionArray pvertexAttribs = {} + , VkVertexInputBindingDescriptionArray pvertexBindings = {} ) + : buffer{ std::move( pbuffer ) } + , memory{ pmemory } + , vertexAttribs{ std::move( pvertexAttribs ) } + , vertexBindings{ std::move( pvertexBindings ) } + { + inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); + inputState.pVertexAttributeDescriptions = vertexAttribs.data(); + inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); + inputState.pVertexBindingDescriptions = vertexBindings.data(); + } + + VertexBuffer( VertexBuffer && rhs )noexcept + : buffer{ rhs.buffer } + , memory{ rhs.memory } + , vertexAttribs{ std::move( rhs.vertexAttribs ) } + , vertexBindings{ std::move( rhs.vertexBindings ) } + , inputState{ std::move( rhs.inputState ) } + { + inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); + inputState.pVertexAttributeDescriptions = vertexAttribs.data(); + inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); + inputState.pVertexBindingDescriptions = vertexBindings.data(); + } + + VertexBuffer & operator=( VertexBuffer && rhs )noexcept + { + buffer = rhs.buffer; + memory = rhs.memory; + vertexAttribs = std::move( rhs.vertexAttribs ); + vertexBindings = std::move( rhs.vertexBindings ); + inputState = std::move( rhs.inputState ); + + inputState.vertexAttributeDescriptionCount = uint32_t( vertexAttribs.size() ); + inputState.pVertexAttributeDescriptions = vertexAttribs.data(); + inputState.vertexBindingDescriptionCount = uint32_t( vertexBindings.size() ); + inputState.pVertexBindingDescriptions = vertexBindings.data(); + + return *this; + } + + Buffer buffer{ VkBuffer{}, std::string{} }; + VkDeviceMemory memory{}; + VkVertexInputAttributeDescriptionArray vertexAttribs{}; + VkVertexInputBindingDescriptionArray vertexBindings{}; + VkPipelineVertexInputStateCreateInfo inputState{ VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, nullptr, {}, {}, {}, {}, {} }; + }; + + struct IndexBuffer + { + explicit IndexBuffer( Buffer pbuffer = { VkBuffer{}, std::string{} } + , VkDeviceMemory pmemory = VkDeviceMemory{} ) + : buffer{ std::move( pbuffer ) } + , memory{ pmemory } + { + } + + Buffer buffer; + VkDeviceMemory memory; + }; + + struct IndirectBuffer + { + explicit IndirectBuffer( Buffer pbuffer + , uint32_t pstride + , DeviceSize poffset = {} ) + : buffer{ std::move( pbuffer ) } + , offset{ poffset } + , stride{ pstride } + { + } + + Buffer buffer; + DeviceSize offset; + uint32_t stride; + }; + + struct SemaphoreWait + { + VkSemaphore semaphore; + PipelineStageFlags dstStageMask; + }; + + template< typename TypeT > + struct RawTyperT + { + using Type = TypeT; + }; +} diff --git a/include/RenderGraph/FramePass.hpp b/include/RenderGraph/FramePass.hpp index 810bb53..3a3e5e2 100644 --- a/include/RenderGraph/FramePass.hpp +++ b/include/RenderGraph/FramePass.hpp @@ -91,8 +91,8 @@ namespace crg * This buffer will only be used to compute dependencies, and is considered an input, in that goal. */ CRG_API void addImplicitBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ); /** *\brief @@ -100,40 +100,40 @@ namespace crg */ CRG_API void addUniformBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an input storage buffer attachment. */ CRG_API void addInputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an output storage buffer attachment. */ CRG_API void addOutputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates a storage buffer attachment that will be cleared a the beginning of the pass. */ CRG_API void addClearableOutputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an input/output storage buffer attachment. */ CRG_API void addInOutStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an implicit buffer view attachment. @@ -142,8 +142,8 @@ namespace crg */ CRG_API void addImplicitBufferView( Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ); /** *\brief @@ -152,8 +152,8 @@ namespace crg CRG_API void addUniformBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an input storage texel buffer view attachment. @@ -161,8 +161,8 @@ namespace crg CRG_API void addInputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an output storage texel buffer view attachment. @@ -170,8 +170,8 @@ namespace crg CRG_API void addOutputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates a storage texel buffer attachment that will be cleared a the beginning of the pass. @@ -179,8 +179,8 @@ namespace crg CRG_API void addClearableOutputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates an input/output storage texel buffer view attachment. @@ -188,29 +188,29 @@ namespace crg CRG_API void addInOutStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates a transfer input buffer attachment. */ CRG_API void addTransferInputBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates a transfer output buffer attachment. */ CRG_API void addTransferOutputBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range ); + , DeviceSize offset + , DeviceSize range ); /** *\brief * Creates a transfer input/output buffer attachment. */ CRG_API void addTransferInOutBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , Attachment::Flag flag = {} ); /**@}*/ /** @@ -444,8 +444,8 @@ namespace crg addColourView( "Ic" , Attachment::FlagKind( Attachment::Flag::Input ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eDontCare , ImageLayout::eColorAttachment ); } /** @@ -454,15 +454,15 @@ namespace crg */ template< typename ImageViewT > void addInOutColourView( ImageViewT view - , VkPipelineColorBlendAttachmentState blendState = DefaultBlendState ) + , PipelineColorBlendAttachmentState blendState = DefaultBlendState ) { addColourView( "IOc" , Attachment::FlagKind( Attachment::Flag::InOut ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eStore , ImageLayout::eColorAttachment - , {} + , ClearColorValue{} , std::move( blendState ) ); } /** @@ -471,13 +471,13 @@ namespace crg */ template< typename ImageViewT > void addOutputColourView( ImageViewT view - , VkClearValue clearValue = {} ) + , ClearColorValue clearValue = ClearColorValue{} ) { addColourView( "Oc" , Attachment::FlagKind( Attachment::Flag::Output ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_CLEAR - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eClear + , AttachmentStoreOp::eStore , ImageLayout::eColorAttachment , std::move( clearValue ) ); } @@ -491,12 +491,12 @@ namespace crg addDepthView( "Id" , Attachment::FlagKind( Attachment::Flag::Input ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -508,12 +508,12 @@ namespace crg addDepthView( "IOd" , Attachment::FlagKind( Attachment::Flag::InOut ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_STORE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eStore + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -521,15 +521,15 @@ namespace crg */ template< typename ImageViewT > void addOutputDepthView( ImageViewT view - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addDepthView( "Od" , Attachment::FlagKind( Attachment::Flag::Output ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_CLEAR - , VK_ATTACHMENT_STORE_OP_STORE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eClear + , AttachmentStoreOp::eStore + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , ImageLayout::eDepthStencilAttachment , std::move( clearValue ) ); } @@ -544,12 +544,12 @@ namespace crg , Attachment::FlagKind( Attachment::Flag::Input ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilInput ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eDontCare , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -562,12 +562,12 @@ namespace crg , Attachment::FlagKind( Attachment::Flag::InOut ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilInOut ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_STORE - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eStore + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eStore , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -575,16 +575,16 @@ namespace crg */ template< typename ImageViewT > void addOutputDepthStencilView( ImageViewT view - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addDepthStencilView( "Ods" , Attachment::FlagKind( Attachment::Flag::Output ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilOutput ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_CLEAR - , VK_ATTACHMENT_STORE_OP_STORE - , VK_ATTACHMENT_LOAD_OP_CLEAR - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eClear + , AttachmentStoreOp::eStore + , AttachmentLoadOp::eClear + , AttachmentStoreOp::eStore , ImageLayout::eDepthStencilAttachment , std::move( clearValue ) ); } @@ -599,12 +599,12 @@ namespace crg , Attachment::FlagKind( Attachment::Flag::Input ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilInput ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eDontCare , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -617,12 +617,12 @@ namespace crg , Attachment::FlagKind( Attachment::Flag::InOut ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilInOut ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_LOAD - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eLoad + , AttachmentStoreOp::eStore , ImageLayout::eDepthStencilAttachment - , VkClearValue{} ); + , ClearDepthStencilValue{} ); } /** *\brief @@ -630,16 +630,16 @@ namespace crg */ template< typename ImageViewT > void addOutputStencilView( ImageViewT view - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addStencilView( "Os" , Attachment::FlagKind( Attachment::Flag::Output ) , ImageAttachment::FlagKind( ImageAttachment::Flag::StencilOutput ) , std::move( view ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_CLEAR - , VK_ATTACHMENT_STORE_OP_STORE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eClear + , AttachmentStoreOp::eStore , ImageLayout::eDepthStencilAttachment , std::move( clearValue ) ); } @@ -673,49 +673,49 @@ namespace crg CRG_API void addColourView( std::string const & name , Attachment::FlagKind flags , ImageViewIdArray view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} - , VkPipelineColorBlendAttachmentState blendState = DefaultBlendState ); + , ClearColorValue clearValue = ClearColorValue{} + , PipelineColorBlendAttachmentState blendState = DefaultBlendState ); CRG_API void addDepthView( std::string const & name , Attachment::FlagKind flags , ImageViewIdArray view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ); + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ); CRG_API void addStencilView( std::string const & name , Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewIdArray view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ); + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ); CRG_API void addDepthStencilView( std::string const & name , Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewIdArray view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ); + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ); void addColourView( std::string const & name , Attachment::FlagKind flags , ImageViewId view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} - , VkPipelineColorBlendAttachmentState blendState = DefaultBlendState ) + , ClearColorValue clearValue = ClearColorValue{} + , PipelineColorBlendAttachmentState blendState = DefaultBlendState ) { addColourView( name , flags @@ -730,12 +730,12 @@ namespace crg void addDepthView( std::string const & name , Attachment::FlagKind flags , ImageViewId view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addDepthView( name , flags @@ -752,12 +752,12 @@ namespace crg , Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewId view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addStencilView( name , flags @@ -775,12 +775,12 @@ namespace crg , Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewId view - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout = ImageLayout::eUndefined - , VkClearValue clearValue = {} ) + , ClearDepthStencilValue clearValue = ClearDepthStencilValue{} ) { addDepthStencilView( name , flags diff --git a/include/RenderGraph/FramePassGroup.hpp b/include/RenderGraph/FramePassGroup.hpp index b0f7884..ca14fd2 100644 --- a/include/RenderGraph/FramePassGroup.hpp +++ b/include/RenderGraph/FramePassGroup.hpp @@ -58,13 +58,13 @@ namespace crg CRG_API ImageViewId createView( ImageViewData const & view )const; CRG_API void addInput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ); CRG_API void addInput( ImageViewId view , LayoutState const & outputLayout ); CRG_API void addOutput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ); CRG_API void addOutput( ImageViewId view , LayoutState const & outputLayout ); diff --git a/include/RenderGraph/GraphNode.hpp b/include/RenderGraph/GraphNode.hpp index 49c2b8a..058cbad 100644 --- a/include/RenderGraph/GraphNode.hpp +++ b/include/RenderGraph/GraphNode.hpp @@ -91,7 +91,7 @@ namespace crg , std::string name , FramePassGroup const & group ); - protected: + private: Kind kind{}; uint32_t id{}; std::string name{}; diff --git a/include/RenderGraph/Id.hpp b/include/RenderGraph/Id.hpp index 5562c80..0a182df 100644 --- a/include/RenderGraph/Id.hpp +++ b/include/RenderGraph/Id.hpp @@ -25,6 +25,12 @@ namespace crg , data{ data } { } + + private: + friend bool operator==( Id const & lhs, Id const & rhs ) + { + return lhs.id == rhs.id; + } }; template< typename TypeT > @@ -38,16 +44,4 @@ namespace crg { return lhs.id > rhs.id; } - - template< typename TypeT > - inline bool operator==( Id< TypeT > const & lhs, Id< TypeT > const & rhs ) - { - return lhs.id == rhs.id; - } - - template< typename TypeT > - inline bool operator!=( Id< TypeT > const & lhs, Id< TypeT > const & rhs ) - { - return lhs.id != rhs.id; - } } diff --git a/include/RenderGraph/ImageData.hpp b/include/RenderGraph/ImageData.hpp index 141c2f9..5a0483b 100644 --- a/include/RenderGraph/ImageData.hpp +++ b/include/RenderGraph/ImageData.hpp @@ -4,7 +4,7 @@ See LICENSE file in root folder. */ #pragma once -#include "FrameGraphPrerequisites.hpp" +#include "Id.hpp" namespace crg { @@ -15,61 +15,26 @@ namespace crg struct ImageData { std::string name; - VkImageCreateInfo info; + ImageCreateInfo info; explicit ImageData( std::string name = {} - , VkImageCreateFlags flags = {} + , ImageCreateFlags flags = {} , ImageType imageType = {} , PixelFormat format = {} - , VkExtent3D extent = {} - , VkImageUsageFlags usage = {} + , Extent3D extent = {} + , ImageUsageFlags usage = {} , uint32_t mipLevels = 1u , uint32_t arrayLayers = 1u - , VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT - , VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL ) + , SampleCount samples = SampleCount::e1 + , ImageTiling tiling = ImageTiling::eOptimal ) : name{ std::move( name ) } - , info{ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO - , nullptr - , flags - , convert( imageType ) - , convert( format ) - , extent - , mipLevels - , arrayLayers - , samples - , tiling - , usage - , VK_SHARING_MODE_EXCLUSIVE - , 0u - , nullptr - , VK_IMAGE_LAYOUT_UNDEFINED } + , info{ flags, imageType, format + , extent, mipLevels, arrayLayers, samples + , tiling, usage } { } - }; - - inline bool operator==( VkExtent3D const & lhs, VkExtent3D const & rhs ) - { - return lhs.width == rhs.width - && lhs.height == rhs.height - && lhs.depth == rhs.depth; - } - inline bool operator==( VkImageCreateInfo const & lhs, VkImageCreateInfo const & rhs ) - { - return lhs.flags == rhs.flags - && lhs.imageType == rhs.imageType - && lhs.format == rhs.format - && lhs.extent == rhs.extent - && lhs.mipLevels == rhs.mipLevels - && lhs.arrayLayers == rhs.arrayLayers - && lhs.samples == rhs.samples - && lhs.tiling == rhs.tiling - && lhs.usage == rhs.usage; - } - - inline bool operator==( ImageData const & lhs, ImageData const & rhs ) - { - return lhs.name == rhs.name - && lhs.info == rhs.info; - } + private: + friend bool operator==( ImageData const & lhs, ImageData const & rhs ) = default; + }; } diff --git a/include/RenderGraph/ImageViewData.hpp b/include/RenderGraph/ImageViewData.hpp index 80d1df8..20f6be2 100644 --- a/include/RenderGraph/ImageViewData.hpp +++ b/include/RenderGraph/ImageViewData.hpp @@ -16,49 +16,26 @@ namespace crg { std::string name; ImageId image; - VkImageViewCreateInfo info; + ImageViewCreateInfo info; ImageViewIdArray source{}; explicit ImageViewData( std::string name = {} , ImageId image = ImageId{} - , VkImageViewCreateFlags flags = {} + , ImageViewCreateFlags flags = {} , ImageViewType viewType = {} , PixelFormat format = {} - , VkImageSubresourceRange subresourceRange = {} ) + , ImageSubresourceRange subresourceRange = {} ) : name{ std::move( name ) } , image{ std::move( image ) } - , info{ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO - , nullptr - , flags - , VkImage{} - , convert( viewType ) - , convert( format ) - , { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A } - , subresourceRange } + , info{ flags, viewType, format, subresourceRange } { } - }; - - inline bool operator==( VkImageSubresourceRange const & lhs, VkImageSubresourceRange const & rhs ) - { - return lhs.aspectMask == rhs.aspectMask - && lhs.baseArrayLayer == rhs.baseArrayLayer - && lhs.layerCount == rhs.layerCount - && lhs.baseMipLevel == rhs.baseMipLevel - && lhs.levelCount == rhs.levelCount; - } - - inline bool operator==( VkImageViewCreateInfo const & lhs, VkImageViewCreateInfo const & rhs ) - { - return lhs.flags == rhs.flags - && lhs.viewType == rhs.viewType - && lhs.format == rhs.format - && lhs.subresourceRange == rhs.subresourceRange; - } - inline bool operator==( ImageViewData const & lhs, ImageViewData const & rhs ) - { - return lhs.image == rhs.image - && lhs.info == rhs.info; - } + private: + friend bool operator==( ImageViewData const & lhs, ImageViewData const & rhs ) + { + return lhs.image == rhs.image + && lhs.info == rhs.info; + } + }; } diff --git a/include/RenderGraph/LayerLayoutStatesHandler.hpp b/include/RenderGraph/LayerLayoutStatesHandler.hpp index ca51bdb..0d775ce 100644 --- a/include/RenderGraph/LayerLayoutStatesHandler.hpp +++ b/include/RenderGraph/LayerLayoutStatesHandler.hpp @@ -16,13 +16,13 @@ namespace crg CRG_API void setLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & layoutState ); CRG_API void setLayoutState( crg::ImageViewId view , LayoutState const & layoutState ); CRG_API LayoutState getLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const; + , ImageSubresourceRange const & subresourceRange )const; CRG_API LayoutState getLayoutState( ImageViewId view )const; LayerLayoutStatesMap images; diff --git a/include/RenderGraph/Log.hpp b/include/RenderGraph/Log.hpp index f66e180..60fecdd 100644 --- a/include/RenderGraph/Log.hpp +++ b/include/RenderGraph/Log.hpp @@ -20,34 +20,34 @@ namespace crg class Logger { public: - using LogCallback = std::function< void( std::string const & msg, bool newLine ) >; + using LogCallback = void( * )( std::string_view msg, bool newLine )noexcept; public: /** *\brief * Logs a trace message. */ - CRG_API static void logTrace( std::string const & message, bool newLine = true ); + CRG_API static void logTrace( std::string_view message, bool newLine = true )noexcept; /** *\brief * Logs a debug message. */ - CRG_API static void logDebug( std::string const & message, bool newLine = true ); + CRG_API static void logDebug( std::string_view message, bool newLine = true )noexcept; /** *\brief * Logs an info message. */ - CRG_API static void logInfo( std::string const & message, bool newLine = true ); + CRG_API static void logInfo( std::string_view message, bool newLine = true )noexcept; /** *\brief * Logs a warning message. */ - CRG_API static void logWarning( std::string const & message, bool newLine = true ); + CRG_API static void logWarning( std::string_view message, bool newLine = true )noexcept; /** *\brief * Logs an error message. */ - CRG_API static void logError( std::string const & message, bool newLine = true ); + CRG_API static void logError( std::string_view message, bool newLine = true )noexcept; /** *\brief * Sets the trace callback. @@ -77,7 +77,7 @@ namespace crg private: Logger(); - static Logger & doGetInstance(); + static Logger & doGetInstance()noexcept; private: LogCallback m_trace; diff --git a/include/RenderGraph/RecordContext.hpp b/include/RenderGraph/RecordContext.hpp index 02a0c83..5c6e431 100644 --- a/include/RenderGraph/RecordContext.hpp +++ b/include/RenderGraph/RecordContext.hpp @@ -52,16 +52,16 @@ namespace crg CRG_API void setLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & layoutState ); CRG_API LayoutState getLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const; + , ImageSubresourceRange const & subresourceRange )const; CRG_API LayoutState getNextLayoutState( ImageViewId view )const; CRG_API LayoutState getNextLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const; + , ImageSubresourceRange const & subresourceRange )const; CRG_API void registerImplicitTransition( RunnablePass const & pass , crg::ImageViewId view @@ -97,14 +97,14 @@ namespace crg , bool force = false ); CRG_API void memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , ImageLayout initialLayout , LayoutState const & wantedState , bool force = false ); CRG_API void memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , ImageLayout initialLayout , LayoutState const & wantedState , bool force = false ); @@ -114,13 +114,13 @@ namespace crg , bool force = false ); CRG_API void memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & wantedState , bool force = false ); CRG_API void memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & wantedState , bool force = false ); //@} @@ -149,6 +149,7 @@ namespace crg //@} //@} CRG_API GraphContext & getContext()const; + CRG_API ContextResourcesCache & getResources()const; GraphContext * operator->()const { @@ -157,20 +158,21 @@ namespace crg CRG_API static ImplicitAction copyImage( ImageViewId srcView , ImageViewId dstView - , VkExtent2D extent + , Extent2D const & extent , ImageLayout finalLayout = ImageLayout::eUndefined ); CRG_API static ImplicitAction blitImage( ImageViewId srcView , ImageViewId dstView - , VkOffset2D srcOffset - , VkExtent2D srcExtent - , VkOffset2D dstOffset - , VkExtent2D dstExtent + , Rect2D const & srcRect + , Rect2D const & dstRect , FilterMode filter , ImageLayout finalLayout = ImageLayout::eUndefined ); CRG_API static ImplicitAction clearAttachment( Attachment const & attach , ImageLayout finalLayout = ImageLayout::eUndefined ); CRG_API static ImplicitAction clearAttachment( ImageViewId view - , VkClearValue const & clearValue + , ClearColorValue const & clearValue + , ImageLayout finalLayout = ImageLayout::eUndefined ); + CRG_API static ImplicitAction clearAttachment( ImageViewId view + , ClearDepthStencilValue const & clearValue , ImageLayout finalLayout = ImageLayout::eUndefined ); ResourceHandler & getHandler()const @@ -198,9 +200,6 @@ namespace crg return m_nextPipelineState; } - private: - ContextResourcesCache & getResources()const; - private: ResourceHandler * m_handler; ContextResourcesCache * m_resources; diff --git a/include/RenderGraph/RunnableGraph.hpp b/include/RenderGraph/RunnableGraph.hpp index 73d7b91..e7e3546 100644 --- a/include/RenderGraph/RunnableGraph.hpp +++ b/include/RenderGraph/RunnableGraph.hpp @@ -74,7 +74,7 @@ namespace crg CRG_API LayoutState getCurrentLayoutState( RecordContext & context , ImageId image , ImageViewType viewType - , VkImageSubresourceRange range )const; + , ImageSubresourceRange range )const; CRG_API LayoutState getCurrentLayoutState( RecordContext & context , ImageViewId view )const; CRG_API LayoutState getNextLayoutState( RecordContext const & context @@ -82,6 +82,9 @@ namespace crg , ImageViewId view )const; CRG_API LayoutState getOutputLayoutState( ImageViewId view )const; + CRG_API VkDescriptorType getDescriptorType( Attachment const & attach )const; + CRG_API WriteDescriptorSet getBufferWrite( Attachment const & attach, uint32_t index = 0u )const; + ConstGraphAdjacentNode getGraph()const noexcept { return &m_rootNode; diff --git a/include/RenderGraph/RunnablePasses/BufferCopy.hpp b/include/RenderGraph/RunnablePasses/BufferCopy.hpp index 90150ec..f234a94 100644 --- a/include/RenderGraph/RunnablePasses/BufferCopy.hpp +++ b/include/RenderGraph/RunnablePasses/BufferCopy.hpp @@ -14,8 +14,8 @@ namespace crg CRG_API BufferCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkDeviceSize copyOffset - , VkDeviceSize copyRange + , DeviceSize copyOffset + , DeviceSize copyRange , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) , IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) ); @@ -26,7 +26,7 @@ namespace crg , uint32_t index )const; private: - VkDeviceSize m_copyOffset; - VkDeviceSize m_copyRange; + DeviceSize m_copyOffset; + DeviceSize m_copyRange; }; } diff --git a/include/RenderGraph/RunnablePasses/BufferToImageCopy.hpp b/include/RenderGraph/RunnablePasses/BufferToImageCopy.hpp index 5449bc0..7909bc5 100644 --- a/include/RenderGraph/RunnablePasses/BufferToImageCopy.hpp +++ b/include/RenderGraph/RunnablePasses/BufferToImageCopy.hpp @@ -14,14 +14,14 @@ namespace crg CRG_API BufferToImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D copyOffset - , VkExtent3D copySize + , Offset3D const & copyOffset + , Extent3D const & copySize , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) , IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) ); private: - void doRecordInto( RecordContext & context + void doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index )const; diff --git a/include/RenderGraph/RunnablePasses/ImageBlit.hpp b/include/RenderGraph/RunnablePasses/ImageBlit.hpp index c193cd6..21bb9b1 100644 --- a/include/RenderGraph/RunnablePasses/ImageBlit.hpp +++ b/include/RenderGraph/RunnablePasses/ImageBlit.hpp @@ -14,17 +14,17 @@ namespace crg CRG_API ImageBlit( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D blitSrcOffset - , VkExtent3D blitSrcSize - , VkOffset3D blitDstOffset - , VkExtent3D blitDstSize + , Offset3D const & blitSrcOffset + , Extent3D const & blitSrcSize + , Offset3D const & blitDstOffset + , Extent3D const & blitDstSize , FilterMode filter , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) , IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) ); private: - void doRecordInto( RecordContext & context + void doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ); diff --git a/include/RenderGraph/RunnablePasses/ImageCopy.hpp b/include/RenderGraph/RunnablePasses/ImageCopy.hpp index 20304ed..86057e4 100644 --- a/include/RenderGraph/RunnablePasses/ImageCopy.hpp +++ b/include/RenderGraph/RunnablePasses/ImageCopy.hpp @@ -14,14 +14,14 @@ namespace crg CRG_API ImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkExtent3D copySize + , Extent3D const & copySize , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) , IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) ); CRG_API ImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkExtent3D copySize + , Extent3D const & copySize , ImageLayout finalOutputLayout , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) diff --git a/include/RenderGraph/RunnablePasses/ImageToBufferCopy.hpp b/include/RenderGraph/RunnablePasses/ImageToBufferCopy.hpp index ec0ff6a..f6ce5b7 100644 --- a/include/RenderGraph/RunnablePasses/ImageToBufferCopy.hpp +++ b/include/RenderGraph/RunnablePasses/ImageToBufferCopy.hpp @@ -14,14 +14,14 @@ namespace crg CRG_API ImageToBufferCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D copyOffset - , VkExtent3D copySize + , Offset3D const & copyOffset + , Extent3D const & copySize , ru::Config ruConfig = {} , GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } ) , IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) ); private: - void doRecordInto( RecordContext & context + void doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ); diff --git a/include/RenderGraph/RunnablePasses/PipelineConfig.hpp b/include/RenderGraph/RunnablePasses/PipelineConfig.hpp index 1e912c6..2b2110a 100644 --- a/include/RenderGraph/RunnablePasses/PipelineConfig.hpp +++ b/include/RenderGraph/RunnablePasses/PipelineConfig.hpp @@ -39,22 +39,22 @@ namespace crg }; template<> - struct DefaultValueGetterT< VkExtent2D > + struct DefaultValueGetterT< Extent2D > { - static inline VkExtent2D const value{}; + static inline Extent2D const value{}; - static VkExtent2D get() + static Extent2D get() { return value; } }; template<> - struct DefaultValueGetterT< VkOffset2D > + struct DefaultValueGetterT< Offset2D > { - static inline VkOffset2D const value{}; + static inline Offset2D const value{}; - static VkOffset2D get() + static Offset2D get() { return value; } diff --git a/include/RenderGraph/RunnablePasses/PipelineHolder.hpp b/include/RenderGraph/RunnablePasses/PipelineHolder.hpp index 4955db0..1436ff3 100644 --- a/include/RenderGraph/RunnablePasses/PipelineHolder.hpp +++ b/include/RenderGraph/RunnablePasses/PipelineHolder.hpp @@ -36,7 +36,7 @@ namespace crg , VkComputePipelineCreateInfo const & createInfo ); CRG_API void createPipeline( uint32_t index , VkComputePipelineCreateInfo const & createInfo ); - CRG_API void recordInto( RecordContext & context + CRG_API void recordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ); CRG_API void resetPipeline( VkPipelineShaderStageCreateInfoArray config diff --git a/include/RenderGraph/RunnablePasses/RenderMeshConfig.hpp b/include/RenderGraph/RunnablePasses/RenderMeshConfig.hpp index b18ddaf..a4223e9 100644 --- a/include/RenderGraph/RunnablePasses/RenderMeshConfig.hpp +++ b/include/RenderGraph/RunnablePasses/RenderMeshConfig.hpp @@ -90,7 +90,7 @@ namespace crg *\param[in] config * The render area size. */ - auto & renderSize( VkExtent2D config ) + auto & renderSize( Extent2D config ) { m_renderSize = std::move( config ); return *this; @@ -99,7 +99,7 @@ namespace crg *\param[in] config * The render position. */ - auto & renderPosition( VkOffset2D config ) + auto & renderPosition( Offset2D config ) { m_renderPosition = std::move( config ); return *this; @@ -214,7 +214,7 @@ namespace crg } pp::ConfigT< WrapperT > m_baseConfig{}; - WrapperT< VkOffset2D > m_renderPosition{}; + WrapperT< Offset2D > m_renderPosition{}; WrapperT< VkPipelineDepthStencilStateCreateInfo > m_depthStencilState{}; WrapperT< RunnablePass::GetPassIndexCallback > m_getPassIndex{}; WrapperT< RunnablePass::IsEnabledCallback > m_isEnabled{}; @@ -224,7 +224,7 @@ namespace crg WrapperT< GetVertexCountCallback > m_getVertexCount{}; WrapperT< GetIndexTypeCallback > m_getIndexType{}; WrapperT< GetCullModeCallback > m_getCullMode{}; - WrapperT< VkExtent2D > m_renderSize{}; + WrapperT< Extent2D > m_renderSize{}; WrapperT< VertexBuffer > m_vertexBuffer{}; WrapperT< IndexBuffer > m_indexBuffer{}; WrapperT< IndirectBuffer > m_indirectBuffer{}; @@ -233,7 +233,7 @@ namespace crg template<> struct ConfigT< RawTypeT > { - RawTypeT< VkOffset2D > renderPosition{}; + RawTypeT< Offset2D > renderPosition{}; RawTypeT< VkPipelineDepthStencilStateCreateInfo > depthStencilState{}; RawTypeT< RunnablePass::GetPassIndexCallback > getPassIndex{}; RawTypeT< RunnablePass::IsEnabledCallback > isEnabled{}; diff --git a/include/RenderGraph/RunnablePasses/RenderMeshHolder.hpp b/include/RenderGraph/RunnablePasses/RenderMeshHolder.hpp index d39e7aa..ed8145b 100644 --- a/include/RenderGraph/RunnablePasses/RenderMeshHolder.hpp +++ b/include/RenderGraph/RunnablePasses/RenderMeshHolder.hpp @@ -18,12 +18,12 @@ namespace crg , rm::Config config , uint32_t maxPassCount ); - CRG_API void initialise( VkExtent2D const & renderSize + CRG_API void initialise( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ); CRG_API void cleanup(); - CRG_API void resetRenderPass( VkExtent2D const & renderSize + CRG_API void resetRenderPass( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ); @@ -37,14 +37,14 @@ namespace crg , uint32_t index )const; CRG_API uint32_t getPassIndex()const; CRG_API bool isEnabled()const; - CRG_API VkExtent2D getRenderSize()const; + CRG_API Extent2D getRenderSize()const; private: - void doPreparePipelineStates( VkExtent2D const & renderSize + void doPreparePipelineStates( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState ); void doCreatePipeline( uint32_t index ); - VkPipelineViewportStateCreateInfo doCreateViewportState( VkExtent2D const & renderSize + VkPipelineViewportStateCreateInfo doCreateViewportState( Extent2D const & renderSize , VkViewport & viewport , VkRect2D & scissor )const; @@ -52,7 +52,7 @@ namespace crg rm::ConfigData m_config; PipelineHolder m_pipeline; VkRenderPass m_renderPass{}; - VkExtent2D m_renderSize{}; + Extent2D m_renderSize{}; VkViewport m_viewport{}; VkRect2D m_scissor{}; VkPipelineViewportStateCreateInfo m_vpState{}; diff --git a/include/RenderGraph/RunnablePasses/RenderPass.hpp b/include/RenderGraph/RunnablePasses/RenderPass.hpp index 620d182..937e532 100644 --- a/include/RenderGraph/RunnablePasses/RenderPass.hpp +++ b/include/RenderGraph/RunnablePasses/RenderPass.hpp @@ -65,7 +65,7 @@ namespace crg , GraphContext & context , RunnableGraph & graph , Callbacks callbacks - , VkExtent2D const & size = {} + , Extent2D size = {} , ru::Config const & ruConfig = {} ); VkRenderPass getRenderPass( uint32_t passIndex )const diff --git a/include/RenderGraph/RunnablePasses/RenderPassHolder.hpp b/include/RenderGraph/RunnablePasses/RenderPassHolder.hpp index 93f4493..a2028bc 100644 --- a/include/RenderGraph/RunnablePasses/RenderPassHolder.hpp +++ b/include/RenderGraph/RunnablePasses/RenderPassHolder.hpp @@ -26,7 +26,7 @@ namespace crg , GraphContext & context , RunnableGraph & graph , uint32_t maxPassCount - , VkExtent2D size = {} ); + , Extent2D size = {} ); CRG_API ~RenderPassHolder()noexcept; CRG_API bool initialise( RecordContext & context @@ -47,17 +47,17 @@ namespace crg return m_passes[index].renderPass; } - VkExtent2D const & getRenderSize()const + Extent2D const & getRenderSize()const { return m_size; } - VkRect2D const & getRenderArea( uint32_t index )const + Rect2D const & getRenderArea( uint32_t index )const { return m_passes[index].renderArea; } - std::vector< VkClearValue > const & getClearValues( uint32_t index )const + std::vector< ClearValue > const & getClearValues( uint32_t index )const { return m_passes[index].clearValues; } @@ -81,9 +81,9 @@ namespace crg { VkRenderPass renderPass{}; mutable VkFramebuffer frameBuffer{}; - VkRect2D renderArea{}; + Rect2D renderArea{}; std::vector< Attachment const * > attachments; - std::vector< VkClearValue > clearValues; + std::vector< ClearValue > clearValues; std::vector< Entry > attaches; PipelineState previousState; PipelineState nextState; @@ -94,7 +94,7 @@ namespace crg FramePass const & m_pass; GraphContext & m_context; RunnableGraph & m_graph; - VkExtent2D m_size; + Extent2D m_size; std::vector< PassData > m_passes; PassData const * m_currentPass{}; VkPipelineColorBlendAttachmentStateArray m_blendAttachs; diff --git a/include/RenderGraph/RunnablePasses/RenderQuad.hpp b/include/RenderGraph/RunnablePasses/RenderQuad.hpp index 4401805..43d82f1 100644 --- a/include/RenderGraph/RunnablePasses/RenderQuad.hpp +++ b/include/RenderGraph/RunnablePasses/RenderQuad.hpp @@ -65,7 +65,7 @@ namespace crg *\param[in] config * The render area size. */ - auto & renderSize( VkExtent2D config ) + auto & renderSize( Extent2D config ) { m_config.renderSize( std::move( config ) ); return static_cast< BuilderT & >( *this ); @@ -74,7 +74,7 @@ namespace crg *\param[in] config * The render position. */ - auto & renderPosition( VkOffset2D config ) + auto & renderPosition( Offset2D config ) { m_config.renderPosition( std::move( config ) ); return static_cast< BuilderT & >( *this ); diff --git a/include/RenderGraph/RunnablePasses/RenderQuadConfig.hpp b/include/RenderGraph/RunnablePasses/RenderQuadConfig.hpp index d6d5e9c..1ffcdb8 100644 --- a/include/RenderGraph/RunnablePasses/RenderQuadConfig.hpp +++ b/include/RenderGraph/RunnablePasses/RenderQuadConfig.hpp @@ -81,7 +81,7 @@ namespace crg *\param[in] config * The render area size. */ - auto & renderSize( VkExtent2D config ) + auto & renderSize( Extent2D config ) { m_renderSize = std::move( config ); return *this; @@ -90,7 +90,7 @@ namespace crg *\param[in] config * The render position. */ - auto & renderPosition( VkOffset2D config ) + auto & renderPosition( Offset2D config ) { m_renderPosition = std::move( config ); return *this; @@ -170,7 +170,7 @@ namespace crg pp::ConfigT< WrapperT > m_baseConfig{}; WrapperT< Texcoord > m_texcoordConfig{}; - WrapperT< VkOffset2D > m_renderPosition{}; + WrapperT< Offset2D > m_renderPosition{}; WrapperT< VkPipelineDepthStencilStateCreateInfo > m_depthStencilState{}; WrapperT< uint32_t const * > m_passIndex{}; WrapperT< bool const * > m_enabled{}; @@ -178,7 +178,7 @@ namespace crg WrapperT< RunnablePass::RecordCallback > m_recordInto{}; WrapperT< RunnablePass::RecordCallback > m_end{}; WrapperT< uint32_t > m_instances{}; - WrapperT< VkExtent2D > m_renderSize{}; + WrapperT< Extent2D > m_renderSize{}; WrapperT< IndirectBuffer > m_indirectBuffer{}; }; @@ -186,7 +186,7 @@ namespace crg struct ConfigT< RawTypeT > { RawTypeT< Texcoord > texcoordConfig; - RawTypeT< VkOffset2D > renderPosition; + RawTypeT< Offset2D > renderPosition; RawTypeT< VkPipelineDepthStencilStateCreateInfo > depthStencilState; RawTypeT< uint32_t const * > passIndex; RawTypeT< bool const * > enabled; diff --git a/include/RenderGraph/RunnablePasses/RenderQuadHolder.hpp b/include/RenderGraph/RunnablePasses/RenderQuadHolder.hpp index 7630f46..370075d 100644 --- a/include/RenderGraph/RunnablePasses/RenderQuadHolder.hpp +++ b/include/RenderGraph/RunnablePasses/RenderQuadHolder.hpp @@ -18,11 +18,11 @@ namespace crg , rq::Config config , uint32_t maxPassCount ); - CRG_API void initialise( VkExtent2D const & renderSize + CRG_API void initialise( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ); - CRG_API void resetRenderPass( VkExtent2D const & renderSize + CRG_API void resetRenderPass( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ); @@ -53,11 +53,11 @@ namespace crg } private: - void doPreparePipelineStates( VkExtent2D const & renderSize + void doPreparePipelineStates( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState ); void doCreatePipeline( uint32_t passIndex ); - VkPipelineViewportStateCreateInfo doCreateViewportState( VkExtent2D const & renderSize + VkPipelineViewportStateCreateInfo doCreateViewportState( Extent2D const & renderSize , VkViewport & viewport , VkRect2D & scissor )const; @@ -68,7 +68,7 @@ namespace crg bool m_useTexCoord{ true }; VertexBuffer const * m_vertexBuffer{}; VkRenderPass m_renderPass{}; - VkExtent2D m_renderSize{}; + Extent2D m_renderSize{}; VkViewport m_viewport{}; VkRect2D m_scissor{}; VkPipelineViewportStateCreateInfo m_vpState{}; @@ -76,6 +76,6 @@ namespace crg VkPipelineMultisampleStateCreateInfo m_msState{}; VkPipelineRasterizationStateCreateInfo m_rsState{}; VkPipelineColorBlendStateCreateInfo m_blendState{}; - std::vector< VkPipelineColorBlendAttachmentState > m_blendAttachs{}; + VkPipelineColorBlendAttachmentStateArray m_blendAttachs{}; }; } diff --git a/source/RenderGraph/Attachment.cpp b/source/RenderGraph/Attachment.cpp index 9f4bfb7..937c20d 100644 --- a/source/RenderGraph/Attachment.cpp +++ b/source/RenderGraph/Attachment.cpp @@ -14,27 +14,6 @@ namespace crg { //********************************************************************************************* - static bool operator==( VkClearValue const & lhs - , VkClearValue const & rhs ) - { - return std::memcmp( &lhs, &rhs, sizeof( VkClearValue ) ) == 0; - } - - static bool operator==( VkPipelineColorBlendAttachmentState const & lhs - , VkPipelineColorBlendAttachmentState const & rhs ) - { - return lhs.blendEnable == rhs.blendEnable - && lhs.srcColorBlendFactor == rhs.srcColorBlendFactor - && lhs.dstColorBlendFactor == rhs.dstColorBlendFactor - && lhs.colorBlendOp == rhs.colorBlendOp - && lhs.srcAlphaBlendFactor == rhs.srcAlphaBlendFactor - && lhs.dstAlphaBlendFactor == rhs.dstAlphaBlendFactor - && lhs.alphaBlendOp == rhs.alphaBlendOp - && lhs.colorWriteMask == rhs.colorWriteMask; - } - - //********************************************************************************************* - BufferAttachment::BufferAttachment( Buffer buffer ) : buffer{ std::move( buffer ) } { @@ -42,8 +21,8 @@ namespace crg BufferAttachment::BufferAttachment( FlagKind flags , Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState access ) : buffer{ std::move( buffer ) } , range{ offset, range } @@ -55,8 +34,8 @@ namespace crg BufferAttachment::BufferAttachment( FlagKind flags , Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState access ) : buffer{ std::move( buffer ) } , view{ view } @@ -66,48 +45,6 @@ namespace crg { } - WriteDescriptorSet BufferAttachment::getWrite( uint32_t binding - , uint32_t count - , uint32_t index )const - { - WriteDescriptorSet result{ binding - , 0u - , count - , getDescriptorType() }; - - if ( isView() ) - { - result.bufferViewInfo.push_back( VkDescriptorBufferInfo{ buffer.buffer( index ), range.offset, range.size } ); - result.texelBufferView.push_back( view ); - } - else - { - result.bufferInfo.push_back( VkDescriptorBufferInfo{ buffer.buffer( index ), range.offset, range.size } ); - } - - return result; - } - - VkDescriptorType BufferAttachment::getDescriptorType()const - { - if ( isUniformView() ) - { - return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; - } - - if ( isStorageView() ) - { - return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; - } - - if ( isUniform() ) - { - return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - } - - return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; - } - AccessFlags BufferAttachment::getAccessMask( bool isInput , bool isOutput )const { @@ -182,13 +119,13 @@ namespace crg ImageAttachment::ImageAttachment( FlagKind flags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , SamplerDesc samplerDesc - , VkClearValue clearValue - , VkPipelineColorBlendAttachmentState blendState + , ClearValue clearValue + , PipelineColorBlendAttachmentState blendState , ImageLayout wantedLayout ) : views{ std::move( views ) } , loadOp{ loadOp } @@ -201,19 +138,15 @@ namespace crg , wantedLayout{ wantedLayout } , flags{ flags } { - assert( ( ( view().data->info.subresourceRange.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT ) != 0 - && isColourFormat( convert( view().data->info.format ) ) ) - || ( ( view().data->info.subresourceRange.aspectMask & ( VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT ) ) != 0 - && isDepthStencilFormat( convert( view().data->info.format ) ) ) - || ( ( view().data->info.subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT ) != 0 - && isDepthFormat( convert( view().data->info.format ) ) ) - || ( ( view().data->info.subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT ) != 0 - && isStencilFormat( convert( view().data->info.format ) ) ) ); + assert( ( checkFlag( getAspectFlags( view() ), ImageAspectFlags::eColor ) && isColourFormat( getFormat( view() ) ) ) + || ( checkFlag( getAspectFlags( view() ), ImageAspectFlags::eDepthStencil ) && isDepthStencilFormat( getFormat( view() ) ) ) + || ( checkFlag( getAspectFlags( view() ), ImageAspectFlags::eDepth ) && isDepthFormat( getFormat( view() ) ) ) + || ( checkFlag( getAspectFlags( view() ), ImageAspectFlags::eStencil ) && isStencilFormat( getFormat( view() ) ) ) ); assert( ( !isSampledView() && !isTransitionView() && !isTransferView() ) - || ( ( this->loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - && ( this->storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - && ( this->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - && ( this->stencilStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE ) ) ); + || ( ( this->loadOp == AttachmentLoadOp::eDontCare ) + && ( this->storeOp == AttachmentStoreOp::eDontCare ) + && ( this->stencilLoadOp == AttachmentLoadOp::eDontCare ) + && ( this->stencilStoreOp == AttachmentStoreOp::eDontCare ) ) ); } ImageViewId ImageAttachment::view( uint32_t index )const @@ -223,16 +156,6 @@ namespace crg : views[index]; } - VkDescriptorType ImageAttachment::getDescriptorType()const - { - if ( isStorageView() ) - { - return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; - } - - return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - } - ImageLayout ImageAttachment::getImageLayout( bool separateDepthStencilLayouts , bool isInput , bool isOutput )const @@ -254,13 +177,9 @@ namespace crg else if ( isTransferView() ) { if ( isOutput ) - { result = ImageLayout::eTransferDst; - } else if ( isInput ) - { result = ImageLayout::eTransferSrc; - } } else if ( isColourAttach() ) { @@ -272,35 +191,23 @@ namespace crg if ( isDepthStencilAttach() ) { if ( isOutput ) - { result = ImageLayout::eDepthStencilAttachment; - } else if ( isInput ) - { result = ImageLayout::eDepthStencilReadOnly; - } } else if ( isStencilAttach() ) { if ( isOutput && isStencilOutputAttach() ) - { result = ImageLayout::eStencilAttachment; - } else if ( isInput && isStencilInputAttach() ) - { result = ImageLayout::eStencilReadOnly; - } } else if ( isDepthAttach() ) { if ( isOutput ) - { result = ImageLayout::eDepthAttachment; - } else if ( isInput ) - { result = ImageLayout::eDepthReadOnly; - } } } else @@ -337,50 +244,30 @@ namespace crg else if ( isStorageView() ) { if ( isInput ) - { result |= AccessFlags::eShaderRead; - } - if ( isOutput ) - { result |= AccessFlags::eShaderWrite; - } } else if ( isTransferView() ) { if ( isInput ) - { result |= AccessFlags::eTransferRead; - } - if ( isOutput ) - { result |= AccessFlags::eTransferWrite; - } } else if ( isDepthAttach() || isStencilAttach() ) { if ( isInput ) - { result |= AccessFlags::eDepthStencilAttachmentRead; - } - if ( isOutput ) - { result |= AccessFlags::eDepthStencilAttachmentWrite; - } } else { if ( isInput ) - { result |= AccessFlags::eColorAttachmentRead; - } - if ( isOutput ) - { result |= AccessFlags::eColorAttachmentWrite; - } } return result; @@ -401,13 +288,9 @@ namespace crg else if ( isStorageView() ) { if ( isCompute ) - { result |= PipelineStageFlags::eComputeShader; - } else - { result |= PipelineStageFlags::eFragmentShader; - } } else if ( isTransferView() ) { @@ -456,13 +339,13 @@ namespace crg , std::string name , ImageAttachment::FlagKind imageFlags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , SamplerDesc samplerDesc - , VkClearValue clearValue - , VkPipelineColorBlendAttachmentState blendState + , ClearValue clearValue + , PipelineColorBlendAttachmentState blendState , ImageLayout wantedLayout ) : pass{ &pass } , binding{ binding } @@ -479,16 +362,16 @@ namespace crg , wantedLayout } , flags{ FlagKind( flags | FlagKind( Flag::Image ) - | ( loadOp == VK_ATTACHMENT_LOAD_OP_LOAD + | ( loadOp == AttachmentLoadOp::eLoad ? FlagKind( Flag::Input ) : FlagKind( Flag::None ) ) - | ( storeOp == VK_ATTACHMENT_STORE_OP_STORE + | ( storeOp == AttachmentStoreOp::eStore ? FlagKind( Flag::Output ) : FlagKind( Flag::None ) ) - | ( stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD + | ( stencilLoadOp == AttachmentLoadOp::eLoad ? FlagKind( Flag::Input ) : FlagKind( Flag::None ) ) - | ( stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE + | ( stencilStoreOp == AttachmentStoreOp::eStore ? FlagKind( Flag::Output ) : FlagKind( Flag::None ) ) ) } { @@ -500,8 +383,8 @@ namespace crg , std::string name , BufferAttachment::FlagKind bufferFlags , Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ) : pass{ &pass } , binding{ binding } @@ -519,8 +402,8 @@ namespace crg , BufferAttachment::FlagKind bufferFlags , Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ) : pass{ &pass } , binding{ binding } @@ -567,22 +450,6 @@ namespace crg , isOutput() ); } - VkDescriptorType Attachment::getDescriptorType()const - { - if ( isImage() ) - { - return imageAttach.getDescriptorType(); - } - - return bufferAttach.getDescriptorType(); - } - - WriteDescriptorSet Attachment::getBufferWrite( uint32_t index )const - { - assert( isBuffer() ); - return bufferAttach.getWrite( binding, 1u, index ); - } - AccessFlags Attachment::getAccessMask()const { if ( isImage() ) @@ -606,53 +473,4 @@ namespace crg } //********************************************************************************************* - - bool operator==( SamplerDesc const & lhs - , SamplerDesc const & rhs ) - { - return lhs.magFilter == rhs.magFilter - && lhs.minFilter == rhs.minFilter - && lhs.mipmapMode == rhs.mipmapMode - && lhs.addressModeU == rhs.addressModeU - && lhs.addressModeV == rhs.addressModeV - && lhs.addressModeW == rhs.addressModeW - && lhs.mipLodBias == rhs.mipLodBias - && lhs.minLod == rhs.minLod - && lhs.maxLod == rhs.maxLod; - } - - bool operator==( BufferAttachment const & lhs - , BufferAttachment const & rhs ) - { - return lhs.flags == rhs.flags - && lhs.buffer == rhs.buffer - && lhs.view == rhs.view - && lhs.range.offset == rhs.range.offset - && lhs.range.size == rhs.range.size; - } - - bool operator==( ImageAttachment const & lhs - , ImageAttachment const & rhs ) - { - return lhs.flags == rhs.flags - && lhs.views == rhs.views - && lhs.loadOp == rhs.loadOp - && lhs.storeOp == rhs.storeOp - && lhs.stencilLoadOp == rhs.stencilLoadOp - && lhs.stencilStoreOp == rhs.stencilStoreOp - && lhs.samplerDesc == rhs.samplerDesc - && lhs.clearValue == rhs.clearValue - && lhs.blendState == rhs.blendState; - } - - bool operator==( Attachment const & lhs - , Attachment const & rhs ) - { - return lhs.pass == rhs.pass - && lhs.flags == rhs.flags - && lhs.imageAttach == rhs.imageAttach - && lhs.bufferAttach == rhs.bufferAttach; - } - - //********************************************************************************************* } diff --git a/source/RenderGraph/AttachmentTransition.cpp b/source/RenderGraph/AttachmentTransition.cpp index 8e62e04..73ceea9 100644 --- a/source/RenderGraph/AttachmentTransition.cpp +++ b/source/RenderGraph/AttachmentTransition.cpp @@ -32,20 +32,6 @@ namespace crg } } - bool operator==( ViewTransition const & lhs, ViewTransition const & rhs ) - { - return match( *lhs.data.data, *rhs.data.data ) - && lhs.outputAttach == rhs.outputAttach - && lhs.inputAttach == rhs.inputAttach; - } - - bool operator==( BufferTransition const & lhs, BufferTransition const & rhs ) - { - return lhs.data == rhs.data - && lhs.outputAttach == rhs.outputAttach - && lhs.inputAttach == rhs.inputAttach; - } - bool operator==( Buffer const & lhs, Buffer const & rhs ) { return lhs.m_buffers == rhs.m_buffers; diff --git a/source/RenderGraph/DotExport.cpp b/source/RenderGraph/DotExport.cpp index 1d314b5..0b57220 100644 --- a/source/RenderGraph/DotExport.cpp +++ b/source/RenderGraph/DotExport.cpp @@ -468,7 +468,7 @@ namespace crg::dot static void displayNode( std::ostream & stream , std::string const & name , std::string const & shape - , std::string_view const & colour + , std::string_view colour , std::set< std::string, std::less<> > & nodes , Config const & config ) { @@ -499,7 +499,7 @@ namespace crg::dot static FramePassGroupStreams & displayPassNode( uint32_t id , std::string const & name , FramePassGroup const * group - , std::string_view const & colour + , std::string_view colour , FramePassGroupStreams & groups , Config const & config ) { @@ -534,7 +534,7 @@ namespace crg::dot , std::string const & from , std::string const & to , std::string const & label - , std::string_view const & colour + , std::string_view colour , Config const & config ) { stream << Indent{ 2 }; @@ -602,7 +602,7 @@ namespace crg::dot template< typename TransitionT > static void displayTransitionEdge( std::ostream & stream - , std::string_view const & colour + , std::string_view colour , TransitionT const & transition , FramePassGroupStreams & groups , Config const & config ) diff --git a/source/RenderGraph/FrameGraph.cpp b/source/RenderGraph/FrameGraph.cpp index 39e59e0..7a0b6e4 100644 --- a/source/RenderGraph/FrameGraph.cpp +++ b/source/RenderGraph/FrameGraph.cpp @@ -193,7 +193,7 @@ namespace crg LayoutState FrameGraph::getFinalLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const + , ImageSubresourceRange const & range )const { return m_finalState.getLayoutState( image, viewType, range ); } @@ -204,7 +204,7 @@ namespace crg if ( view.data->source.empty() ) { return getFinalLayoutState( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange ); } @@ -219,7 +219,7 @@ namespace crg void FrameGraph::addInput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ) { m_inputs.setLayoutState( image @@ -232,14 +232,14 @@ namespace crg , LayoutState const & outputLayout ) { addInput( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , outputLayout ); } LayoutState FrameGraph::getInputLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const + , ImageSubresourceRange const & range )const { return m_inputs.getLayoutState( image , viewType @@ -249,13 +249,13 @@ namespace crg LayoutState FrameGraph::getInputLayoutState( ImageViewId view )const { return getInputLayoutState( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange ); } void FrameGraph::addOutput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ) { m_outputs.setLayoutState( image @@ -268,14 +268,14 @@ namespace crg , LayoutState const & outputLayout ) { addOutput( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , outputLayout ); } LayoutState FrameGraph::getOutputLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range )const + , ImageSubresourceRange const & range )const { return m_outputs.getLayoutState( image , viewType @@ -285,7 +285,7 @@ namespace crg LayoutState FrameGraph::getOutputLayoutState( ImageViewId view )const { return getOutputLayoutState( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange ); } diff --git a/source/RenderGraph/FrameGraphPrerequisites.cpp b/source/RenderGraph/FrameGraphPrerequisites.cpp index 4badbdb..04377c4 100644 --- a/source/RenderGraph/FrameGraphPrerequisites.cpp +++ b/source/RenderGraph/FrameGraphPrerequisites.cpp @@ -8,10 +8,10 @@ namespace crg { namespace fgph { - static bool match( VkImageSubresourceRange const & lhsRange - , VkImageSubresourceRange const & rhsRange )noexcept + static bool match( ImageSubresourceRange const & lhsRange + , ImageSubresourceRange const & rhsRange )noexcept { - return ( ( lhsRange.aspectMask & rhsRange.aspectMask ) != 0 ) + return ( ( lhsRange.aspectMask & rhsRange.aspectMask ) != ImageAspectFlags::eNone ) && lhsRange.baseArrayLayer == rhsRange.baseArrayLayer && lhsRange.layerCount == rhsRange.layerCount && lhsRange.baseMipLevel == rhsRange.baseMipLevel @@ -21,8 +21,8 @@ namespace crg static bool match( ImageId const & image , ImageViewType lhsType , ImageViewType rhsType - , VkImageSubresourceRange const & lhsRange - , VkImageSubresourceRange const & rhsRange )noexcept + , ImageSubresourceRange const & lhsRange + , ImageSubresourceRange const & rhsRange )noexcept { auto result = lhsType == rhsType; @@ -40,15 +40,21 @@ namespace crg } static bool match( ImageId const & image - , VkImageViewCreateInfo const & lhsInfo - , VkImageViewCreateInfo const & rhsInfo )noexcept + , ImageViewCreateInfo const & lhsInfo + , ImageViewCreateInfo const & rhsInfo )noexcept { return lhsInfo.flags == rhsInfo.flags && lhsInfo.format == rhsInfo.format && match( image - , convert( lhsInfo.viewType ), convert( rhsInfo.viewType ) + , lhsInfo.viewType, rhsInfo.viewType , lhsInfo.subresourceRange, rhsInfo.subresourceRange ); } + + static bool match( ImageViewData const & lhs, ImageViewData const & rhs )noexcept + { + return lhs.image.id == rhs.image.id + && match( lhs.image, lhs.info, rhs.info ); + } } //********************************************************************************************* @@ -477,38 +483,48 @@ namespace crg //********************************************************************************************* - VkExtent3D const & getExtent( ImageId const & image )noexcept + ImageCreateFlags getImageCreateFlags( ImageId const & image )noexcept + { + return image.data->info.flags; + } + + ImageCreateFlags getImageCreateFlags( ImageViewId const & image )noexcept + { + return getImageCreateFlags( image.data->image ); + } + + Extent3D const & getExtent( ImageId const & image )noexcept { return image.data->info.extent; } - VkExtent3D const & getExtent( ImageViewId const & image )noexcept + Extent3D const & getExtent( ImageViewId const & image )noexcept { return getExtent( image.data->image ); } - VkExtent3D getMipExtent( ImageViewId const & image )noexcept + Extent3D getMipExtent( ImageViewId const & image )noexcept { auto result = getExtent( image.data->image ); - result.width >>= image.data->info.subresourceRange.baseMipLevel; - result.height >>= image.data->info.subresourceRange.baseMipLevel; - result.depth >>= image.data->info.subresourceRange.baseMipLevel; + result.width >>= getSubresourceRange( image ).baseMipLevel; + result.height >>= getSubresourceRange( image ).baseMipLevel; + result.depth >>= getSubresourceRange( image ).baseMipLevel; return result; } PixelFormat getFormat( ImageId const & image )noexcept { - return convert( image.data->info.format ); + return image.data->info.format; } PixelFormat getFormat( ImageViewId const & image )noexcept { - return convert( image.data->info.format ); + return image.data->info.format; } ImageType getImageType( ImageId const & image )noexcept { - return convert( image.data->info.imageType ); + return image.data->info.imageType; } ImageType getImageType( ImageViewId const & image )noexcept @@ -518,7 +534,7 @@ namespace crg ImageViewType getImageViewType( ImageViewId const & image )noexcept { - return convert( image.data->info.viewType ); + return image.data->info.viewType; } uint32_t getMipLevels( ImageId const & image )noexcept @@ -528,7 +544,7 @@ namespace crg uint32_t getMipLevels( ImageViewId const & image )noexcept { - return image.data->info.subresourceRange.levelCount; + return getSubresourceRange( image ).levelCount; } uint32_t getArrayLayers( ImageId const & image )noexcept @@ -538,7 +554,17 @@ namespace crg uint32_t getArrayLayers( ImageViewId const & image )noexcept { - return image.data->info.subresourceRange.layerCount; + return getSubresourceRange( image ).layerCount; + } + + ImageAspectFlags getAspectFlags( ImageViewId const & image )noexcept + { + return getSubresourceRange( image ).aspectMask; + } + + ImageSubresourceRange const & getSubresourceRange( ImageViewId const & image )noexcept + { + return image.data->info.subresourceRange; } AccessFlags getAccessMask( ImageLayout layout )noexcept @@ -689,19 +715,19 @@ namespace crg return result; } - VkImageAspectFlags getAspectMask( PixelFormat format )noexcept + ImageAspectFlags getAspectMask( PixelFormat format )noexcept { - return VkImageAspectFlags( isDepthStencilFormat( format ) - ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT + return ImageAspectFlags( isDepthStencilFormat( format ) + ? ImageAspectFlags::eDepth | ImageAspectFlags::eStencil : ( isDepthFormat( format ) - ? VK_IMAGE_ASPECT_DEPTH_BIT + ? ImageAspectFlags::eDepth : ( isStencilFormat( format ) - ? VK_IMAGE_ASPECT_STENCIL_BIT - : VK_IMAGE_ASPECT_COLOR_BIT ) ) ); + ? ImageAspectFlags::eStencil + : ImageAspectFlags::eColor ) ) ); } LayoutState const & addSubresourceRangeLayout( LayerLayoutStates & ranges - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & newLayout ) { for ( uint32_t layerIdx = 0u; layerIdx < range.layerCount; ++layerIdx ) @@ -718,23 +744,21 @@ namespace crg } LayoutState getSubresourceRangeLayout( LayerLayoutStates const & ranges - , VkImageSubresourceRange const & range ) + , ImageSubresourceRange const & range ) { std::map< ImageLayout, LayoutState > states; for ( uint32_t layerIdx = 0u; layerIdx < range.layerCount; ++layerIdx ) { - auto layerIt = ranges.find( range.baseArrayLayer + layerIdx ); - - if ( layerIt != ranges.end() ) + if ( auto layerIt = ranges.find( range.baseArrayLayer + layerIdx ); + layerIt != ranges.end() ) { auto & layers = layerIt->second; for ( uint32_t levelIdx = 0u; levelIdx < range.levelCount; ++levelIdx ) { - auto it = layers.find( range.baseMipLevel + levelIdx ); - - if ( it != layers.end() ) + if ( auto it = layers.find( range.baseMipLevel + levelIdx ); + it != layers.end() ) { auto state = it->second; auto [rit, res] = states.emplace( state.layout, state ); @@ -761,11 +785,11 @@ namespace crg return states.begin()->second; } - VkImageSubresourceRange getVirtualRange( ImageId const & image + ImageSubresourceRange getVirtualRange( ImageId const & image , ImageViewType viewType - , VkImageSubresourceRange const & range )noexcept + , ImageSubresourceRange const & range )noexcept { - VkImageSubresourceRange result = range; + ImageSubresourceRange result = range; if ( viewType == ImageViewType::e3D && ( range.levelCount == 1u @@ -778,12 +802,14 @@ namespace crg return result; } - bool match( ImageViewData const & lhs, ImageViewData const & rhs )noexcept + bool match( ImageViewId const & lhs, ImageViewId const & rhs )noexcept + { + return fgph::match( *lhs.data, *rhs.data ); + } + + bool match( Buffer const & lhs, Buffer const & rhs )noexcept { - return lhs.image.id == rhs.image.id - && fgph::match( lhs.image - , lhs.info - , rhs.info ); + return lhs == rhs; } ImageViewId const & resolveView( ImageViewId const & view @@ -794,5 +820,21 @@ namespace crg : view.data->source[passIndex]; } + ClearColorValue getClearColorValue( ClearValue const & v ) + { + if ( v.isColor() ) + return v.color(); + static ClearColorValue dummy{}; + return dummy; + } + + ClearDepthStencilValue getClearDepthStencilValue( ClearValue const & v ) + { + if ( v.isDepthStencil() ) + return v.depthStencil(); + static ClearDepthStencilValue dummy{}; + return dummy; + } + //********************************************************************************************* } diff --git a/source/RenderGraph/FramePass.cpp b/source/RenderGraph/FramePass.cpp index e809da2..be182e0 100644 --- a/source/RenderGraph/FramePass.cpp +++ b/source/RenderGraph/FramePass.cpp @@ -85,8 +85,7 @@ namespace crg , []( Attachment const & lhs , ImageViewId const & rhs ) { - return match( *lhs.view().data, *rhs.data ) - && lhs.isOutput(); + return lhs.isOutput() && match( lhs.view(), rhs ); } ); } ); @@ -105,8 +104,7 @@ namespace crg , []( Attachment const & lhs , ImageViewId const & rhs ) { - return match( *lhs.view().data, *rhs.data ) - && lhs.isInput(); + return lhs.isInput() && match( lhs.view(), rhs ); } ); } ); @@ -184,6 +182,58 @@ namespace crg | ( ptrdiff_t( buffer.buffer() ) & 0x0000FFFF ); } } + + static void mergeViewData( ImageViewId const & view + , bool mergeMipLevels + , bool mergeArrayLayers + , ImageViewData & data ) + { + if ( data.image.id == 0 ) + { + data.image = view.data->image; + data.name = data.image.data->name; + data.info.flags = view.data->info.flags; + data.info.format = view.data->info.format; + data.info.viewType = view.data->info.viewType; + data.info.subresourceRange = view.data->info.subresourceRange; + } + else + { + assert( data.image == view.data->image ); + + if ( mergeMipLevels ) + { + auto maxLevel = std::max( data.info.subresourceRange.levelCount + data.info.subresourceRange.baseMipLevel + , view.data->info.subresourceRange.levelCount + view.data->info.subresourceRange.baseMipLevel ); + data.info.subresourceRange.baseMipLevel = std::min( view.data->info.subresourceRange.baseMipLevel + , data.info.subresourceRange.baseMipLevel ); + data.info.subresourceRange.levelCount = maxLevel - data.info.subresourceRange.baseMipLevel; + } + else + { + data.info.subresourceRange.baseMipLevel = std::min( view.data->info.subresourceRange.baseMipLevel + , data.info.subresourceRange.baseMipLevel ); + data.info.subresourceRange.levelCount = 1u; + } + + if ( mergeArrayLayers ) + { + auto maxLayer = std::max( data.info.subresourceRange.layerCount + data.info.subresourceRange.baseArrayLayer + , view.data->info.subresourceRange.layerCount + view.data->info.subresourceRange.baseArrayLayer ); + data.info.subresourceRange.baseArrayLayer = std::min( view.data->info.subresourceRange.baseArrayLayer + , data.info.subresourceRange.baseArrayLayer ); + data.info.subresourceRange.layerCount = maxLayer - data.info.subresourceRange.baseArrayLayer; + } + else + { + data.info.subresourceRange.baseArrayLayer = std::min( view.data->info.subresourceRange.baseArrayLayer + , data.info.subresourceRange.baseArrayLayer ); + data.info.subresourceRange.layerCount = 1u; + } + } + + data.source.push_back( view ); + } } FramePass::FramePass( FramePassGroup const & pgroup @@ -275,8 +325,8 @@ namespace crg } void FramePass::addImplicitBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/ImplB"; @@ -293,8 +343,8 @@ namespace crg void FramePass::addUniformBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/UB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Input ) @@ -310,8 +360,8 @@ namespace crg void FramePass::addInputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/ISB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Input ) @@ -327,8 +377,8 @@ namespace crg void FramePass::addOutputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/OSB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Output ) @@ -344,8 +394,8 @@ namespace crg void FramePass::addClearableOutputStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/OSB"; buffers.push_back( Attachment{ ( Attachment::FlagKind( Attachment::Flag::Output ) @@ -362,8 +412,8 @@ namespace crg void FramePass::addInOutStorageBuffer( Buffer buffer , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/IOSB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::InOut ) @@ -379,8 +429,8 @@ namespace crg void FramePass::addImplicitBufferView( Buffer buffer , VkBufferView view - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , AccessState wantedAccess ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/ImplBV"; @@ -399,8 +449,8 @@ namespace crg void FramePass::addUniformBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/UBV"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Input ) @@ -418,8 +468,8 @@ namespace crg void FramePass::addInputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/ISBV"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Input ) @@ -437,8 +487,8 @@ namespace crg void FramePass::addOutputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/OSBV"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Output ) @@ -456,8 +506,8 @@ namespace crg void FramePass::addClearableOutputStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/OSBV"; buffers.push_back( Attachment{ ( Attachment::FlagKind( Attachment::Flag::Output ) @@ -476,8 +526,8 @@ namespace crg void FramePass::addInOutStorageBufferView( Buffer buffer , VkBufferView view , uint32_t binding - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/IOSBV"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::InOut ) @@ -493,8 +543,8 @@ namespace crg } void FramePass::addTransferInputBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/ITB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Input ) @@ -509,8 +559,8 @@ namespace crg } void FramePass::addTransferOutputBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range ) + , DeviceSize offset + , DeviceSize range ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/OTB"; buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Output ) @@ -525,8 +575,8 @@ namespace crg } void FramePass::addTransferInOutBuffer( Buffer buffer - , VkDeviceSize offset - , VkDeviceSize range + , DeviceSize offset + , DeviceSize range , Attachment::Flag flag ) { auto attachName = fpass::adjustName( *this, buffer.name ) + "/IOTB"; @@ -546,87 +596,39 @@ namespace crg , bool mergeArrayLayers ) { ImageViewData data; - for ( auto & view : views ) - { - if ( data.image.id == 0 ) - { - data.image = view.data->image; - data.name = data.image.data->name; - data.info.components = view.data->info.components; - data.info.flags = view.data->info.flags; - data.info.format = view.data->info.format; - data.info.viewType = view.data->info.viewType; - data.info.subresourceRange = view.data->info.subresourceRange; - } - else - { - assert( data.image == view.data->image ); - - if ( mergeMipLevels ) - { - auto maxLevel = std::max( data.info.subresourceRange.levelCount + data.info.subresourceRange.baseMipLevel - , view.data->info.subresourceRange.levelCount + view.data->info.subresourceRange.baseMipLevel ); - data.info.subresourceRange.baseMipLevel = std::min( view.data->info.subresourceRange.baseMipLevel - , data.info.subresourceRange.baseMipLevel ); - data.info.subresourceRange.levelCount = maxLevel - data.info.subresourceRange.baseMipLevel; - } - else - { - data.info.subresourceRange.baseMipLevel = std::min( view.data->info.subresourceRange.baseMipLevel - , data.info.subresourceRange.baseMipLevel ); - data.info.subresourceRange.levelCount = 1u; - } - - if ( mergeArrayLayers ) - { - auto maxLayer = std::max( data.info.subresourceRange.layerCount + data.info.subresourceRange.baseArrayLayer - , view.data->info.subresourceRange.layerCount + view.data->info.subresourceRange.baseArrayLayer ); - data.info.subresourceRange.baseArrayLayer = std::min( view.data->info.subresourceRange.baseArrayLayer - , data.info.subresourceRange.baseArrayLayer ); - data.info.subresourceRange.layerCount = maxLayer - data.info.subresourceRange.baseArrayLayer; - } - else - { - data.info.subresourceRange.baseArrayLayer = std::min( view.data->info.subresourceRange.baseArrayLayer - , data.info.subresourceRange.baseArrayLayer ); - data.info.subresourceRange.layerCount = 1u; - } - } - - data.source.push_back( view ); - } + fpass::mergeViewData( view, mergeMipLevels, mergeArrayLayers, data ); if ( data.info.subresourceRange.layerCount > 1u ) { switch ( data.info.viewType ) { - case VK_IMAGE_VIEW_TYPE_1D: - data.info.viewType = VK_IMAGE_VIEW_TYPE_1D_ARRAY; + case ImageViewType::e1D: + data.info.viewType = ImageViewType::e1DArray; break; - case VK_IMAGE_VIEW_TYPE_2D: - if ( ( data.image.data->info.flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT ) + case ImageViewType::e2D: + if ( checkFlag( data.image.data->info.flags, ImageCreateFlags::eCubeCompatible ) && ( data.info.subresourceRange.layerCount % 6u ) == 0u && data.info.subresourceRange.baseArrayLayer == 0u ) { if ( data.info.subresourceRange.layerCount > 6u ) { - data.info.viewType = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; + data.info.viewType = ImageViewType::eCubeArray; } else { - data.info.viewType = VK_IMAGE_VIEW_TYPE_CUBE; + data.info.viewType = ImageViewType::eCube; } } else { - data.info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + data.info.viewType = ImageViewType::e2DArray; } break; - case VK_IMAGE_VIEW_TYPE_CUBE: + case ImageViewType::eCube: if ( data.info.subresourceRange.layerCount > 6u ) { - data.info.viewType = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; + data.info.viewType = ImageViewType::eCubeArray; } break; default: @@ -648,13 +650,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Sampled ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , std::move( samplerDesc ) - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eShaderReadOnly } ); } @@ -668,13 +670,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Transition ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } @@ -689,13 +691,13 @@ namespace crg , ( ImageAttachment::FlagKind( ImageAttachment::Flag::Transition ) | ImageAttachment::FlagKind( ImageAttachment::Flag::Depth ) ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } @@ -710,13 +712,13 @@ namespace crg , ( ImageAttachment::FlagKind( ImageAttachment::Flag::Transition ) | ImageAttachment::FlagKind( ImageAttachment::Flag::DepthStencil ) ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } @@ -730,13 +732,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Storage ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eGeneral } ); } @@ -750,13 +752,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Storage ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eGeneral } ); } @@ -771,13 +773,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Storage ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eGeneral } ); } @@ -791,13 +793,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Storage ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eGeneral } ); } @@ -810,13 +812,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Transfer ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eTransferSrc } ); } @@ -829,13 +831,13 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Transfer ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eTransferDst } ); } @@ -849,24 +851,24 @@ namespace crg , std::move( attachName ) , ImageAttachment::FlagKind( ImageAttachment::Flag::Transfer ) , std::move( views ) - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , VkClearValue{} - , VkPipelineColorBlendAttachmentState{} + , ClearValue{} + , PipelineColorBlendAttachmentState{} , ImageLayout::eTransferSrc } ); } void FramePass::addColourView( std::string const & pname , crg::Attachment::FlagKind flags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp , ImageLayout wantedLayout - , VkClearValue clearValue - , VkPipelineColorBlendAttachmentState blendState ) + , ClearColorValue clearValue + , PipelineColorBlendAttachmentState blendState ) { auto attachName = fpass::adjustName( *this, views.front().data->name ) + "/" + pname; images.push_back( { flags @@ -877,10 +879,10 @@ namespace crg , std::move( views ) , loadOp , storeOp - , VK_ATTACHMENT_LOAD_OP_DONT_CARE - , VK_ATTACHMENT_STORE_OP_DONT_CARE + , AttachmentLoadOp::eDontCare + , AttachmentStoreOp::eDontCare , SamplerDesc{} - , std::move( clearValue ) + , ClearValue{ std::move( clearValue ) } , std::move( blendState ) , wantedLayout } ); } @@ -888,12 +890,12 @@ namespace crg void FramePass::addDepthView( std::string const & pname , crg::Attachment::FlagKind flags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout - , VkClearValue clearValue ) + , ClearDepthStencilValue clearValue ) { auto attachName = fpass::adjustName( *this, views.front().data->name ) + "/" + pname; images.insert( images.begin() @@ -908,8 +910,8 @@ namespace crg , stencilLoadOp , stencilStoreOp , SamplerDesc{} - , std::move( clearValue ) - , VkPipelineColorBlendAttachmentState{} + , ClearValue{ std::move( clearValue ) } + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } @@ -917,12 +919,12 @@ namespace crg , crg::Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout - , VkClearValue clearValue ) + , ClearDepthStencilValue clearValue ) { auto attachName = fpass::adjustName( *this, views.front().data->name ) + "/" + pname; images.insert( images.begin() @@ -938,8 +940,8 @@ namespace crg , stencilLoadOp , stencilStoreOp , SamplerDesc{} - , std::move( clearValue ) - , VkPipelineColorBlendAttachmentState{} + , ClearValue{ std::move( clearValue ) } + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } @@ -947,12 +949,12 @@ namespace crg , crg::Attachment::FlagKind flags , ImageAttachment::FlagKind stencilFlags , ImageViewIdArray views - , VkAttachmentLoadOp loadOp - , VkAttachmentStoreOp storeOp - , VkAttachmentLoadOp stencilLoadOp - , VkAttachmentStoreOp stencilStoreOp + , AttachmentLoadOp loadOp + , AttachmentStoreOp storeOp + , AttachmentLoadOp stencilLoadOp + , AttachmentStoreOp stencilStoreOp , ImageLayout wantedLayout - , VkClearValue clearValue ) + , ClearDepthStencilValue clearValue ) { auto attachName = fpass::adjustName( *this, views.front().data->name ) + "/" + pname; images.insert( images.begin() @@ -968,8 +970,8 @@ namespace crg , stencilLoadOp , stencilStoreOp , SamplerDesc{} - , std::move( clearValue ) - , VkPipelineColorBlendAttachmentState{} + , ClearValue{ std::move( clearValue ) } + , PipelineColorBlendAttachmentState{} , wantedLayout } ); } diff --git a/source/RenderGraph/FramePassDependenciesBuilder.cpp b/source/RenderGraph/FramePassDependenciesBuilder.cpp index 1a5842e..4fb7b47 100644 --- a/source/RenderGraph/FramePassDependenciesBuilder.cpp +++ b/source/RenderGraph/FramePassDependenciesBuilder.cpp @@ -311,8 +311,8 @@ namespace crg::builder || isInRange( rhsLBound, lhsLBound, lhsCount ); } - static bool areIntersecting( VkImageSubresourceRange const & lhs - , VkImageSubresourceRange const & rhs ) + static bool areIntersecting( ImageSubresourceRange const & lhs + , ImageSubresourceRange const & rhs ) { return areIntersecting( lhs.baseMipLevel , lhs.levelCount @@ -328,8 +328,8 @@ namespace crg::builder , ImageViewData const & rhs ) { return lhs.image == rhs.image - && areIntersecting( getVirtualRange( lhs.image, convert( lhs.info.viewType ), lhs.info.subresourceRange ) - , getVirtualRange( rhs.image, convert( rhs.info.viewType ), rhs.info.subresourceRange ) ); + && areIntersecting( getVirtualRange( lhs.image, lhs.info.viewType, lhs.info.subresourceRange ) + , getVirtualRange( rhs.image, rhs.info.viewType, rhs.info.subresourceRange ) ); } static bool areOverlapping( ImageViewId const & lhs @@ -356,8 +356,7 @@ namespace crg::builder static void insertAttach( Attachment const & attach , AttachesArrayT< DataT > & cont ) { - auto it = std::find_if( cont.begin() - , cont.end() + auto it = std::find_if( cont.begin(), cont.end() , [&attach]( AttachesT< DataT > const & lookup ) { return lookup.data == AttachDataTraitsT< DataT >::get( attach ); @@ -369,11 +368,8 @@ namespace crg::builder it = std::prev( cont.end() ); } - auto attachesIt = std::find( it->attaches.begin() - , it->attaches.end() - , attach ); - - if ( attachesIt == it->attaches.end() ) + if ( auto attachesIt = std::find( it->attaches.begin(), it->attaches.end(), attach ); + attachesIt == it->attaches.end() ) { it->attaches.push_back( attach ); } @@ -387,9 +383,7 @@ namespace crg::builder , std::function< bool( DataT const &, DataT const & ) > processAttach ) { if ( processAttach( sourceView, attachView ) - && lookup.attaches.end() == std::find( lookup.attaches.begin() - , lookup.attaches.end() - , attach ) ) + && lookup.attaches.end() == std::find( lookup.attaches.begin(), lookup.attaches.end(), attach ) ) { lookup.attaches.push_back( attach ); } @@ -466,9 +460,7 @@ namespace crg::builder static bool hasTransition( DataTransitionArrayT< DataT > const & transitions , DataTransitionT< DataT > const & transition ) { - return transitions.end() != std::find( transitions.begin() - , transitions.end() - , transition ); + return transitions.end() != std::find( transitions.begin(), transitions.end(), transition ); } static FramePassTransitions & insertPass( FramePass const * pass @@ -509,27 +501,23 @@ namespace crg::builder { if ( !hasTransition( transitions, transition ) ) { - auto it = std::find_if( transitions.begin() - , transitions.end() + if ( auto it = std::find_if( transitions.begin(), transitions.end() , [&transition, &cache]( DataTransitionT< DataT > const & lookup ) { return dependsOn( lookup, transition, cache ); } ); - - if ( it != transitions.end() ) + it != transitions.end() ) { transitions.insert( it, transition ); } else { - auto rit = std::find_if( transitions.rbegin() - , transitions.rend() + if ( auto rit = std::find_if( transitions.rbegin(), transitions.rend() , [&transition, &cache]( DataTransitionT< DataT > const & lookup ) { return dependsOn( transition, lookup, cache ); } ); - - if ( rit != transitions.rend() ) + rit != transitions.rend() ) { transitions.insert( rit.base(), transition ); } @@ -605,16 +593,6 @@ namespace crg::builder } } - static bool match( Buffer const & lhs, Buffer const & rhs ) - { - return lhs.buffer() == rhs.buffer(); - } - - static bool match( ImageViewId const & lhs, ImageViewId const & rhs ) - { - return match( *lhs.data, *rhs.data ); - } - template< typename DataT > static void addDependency( Attachment const & outputAttach , Attachment const & inputAttach @@ -691,11 +669,10 @@ namespace crg::builder // Disabled because GitHub Actions weirdly cries on this #pragma warning( push ) #pragma warning( disable:5233 ) - auto it = std::find_if( all.begin() - , all.end() + auto it = std::find_if( all.begin(), all.end() , [&input]( AttachesT< DataT > const & lookup ) { - return lookup.data == input.data; + return lookup.data == input.data; } ); #pragma warning( pop ) diff --git a/source/RenderGraph/FramePassGroup.cpp b/source/RenderGraph/FramePassGroup.cpp index 46468e5..a1110c7 100644 --- a/source/RenderGraph/FramePassGroup.cpp +++ b/source/RenderGraph/FramePassGroup.cpp @@ -18,10 +18,7 @@ namespace crg static FramePassGroup const * getOutermost( FramePassGroup const * group ) { while ( group && group->parent ) - { group = group->parent; - } - return group; } @@ -155,7 +152,7 @@ namespace crg void FramePassGroup::addInput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ) { m_graph.addInput( image @@ -168,14 +165,14 @@ namespace crg , LayoutState const & outputLayout ) { addInput( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , outputLayout ); } void FramePassGroup::addOutput( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & range + , ImageSubresourceRange const & range , LayoutState const & outputLayout ) { m_graph.addOutput( image @@ -188,7 +185,7 @@ namespace crg , LayoutState const & outputLayout ) { addOutput( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , outputLayout ); } diff --git a/source/RenderGraph/FramePassTimer.cpp b/source/RenderGraph/FramePassTimer.cpp index 63962d3..dff6485 100644 --- a/source/RenderGraph/FramePassTimer.cpp +++ b/source/RenderGraph/FramePassTimer.cpp @@ -1,5 +1,6 @@ #include "RenderGraph/FramePassTimer.hpp" #include "RenderGraph/GraphContext.hpp" +#include "RenderGraph/Log.hpp" #include diff --git a/source/RenderGraph/GraphBuilder.cpp b/source/RenderGraph/GraphBuilder.cpp index 10cd987..7df79d8 100644 --- a/source/RenderGraph/GraphBuilder.cpp +++ b/source/RenderGraph/GraphBuilder.cpp @@ -22,8 +22,7 @@ namespace crg::builder } GraphAdjacentNode result{}; - auto it = std::find_if( nodes.begin() - , nodes.end() + auto it = std::find_if( nodes.begin(), nodes.end() , [pass]( auto & lookup ) { return getFramePass( *lookup ) == pass; @@ -51,10 +50,8 @@ namespace crg::builder { for ( DataTransitionT< DataT > const & transition : transitions ) { - GraphAdjacentNode outputAdjNode = findNode( transition.outputAttach.pass - , nodes ); - GraphAdjacentNode inputAdjNode = findNode( transition.inputAttach.pass - , nodes ); + GraphAdjacentNode outputAdjNode = findNode( transition.outputAttach.pass, nodes ); + GraphAdjacentNode inputAdjNode = findNode( transition.inputAttach.pass, nodes ); if ( inputAdjNode && outputAdjNode diff --git a/source/RenderGraph/GraphContext.cpp b/source/RenderGraph/GraphContext.cpp index 3c403ce..2845402 100644 --- a/source/RenderGraph/GraphContext.cpp +++ b/source/RenderGraph/GraphContext.cpp @@ -366,9 +366,9 @@ namespace crg if ( object ) { lock_type lock{ m_mutex }; - auto it = m_allocated.find( size_t( object ) ); - if ( it != m_allocated.end() ) + if ( auto it = m_allocated.find( size_t( object ) ); + it != m_allocated.end() ) { std::stringstream stream; stream.imbue( std::locale{ "C" } ); diff --git a/source/RenderGraph/LayerLayoutStatesHandler.cpp b/source/RenderGraph/LayerLayoutStatesHandler.cpp index cdccb1a..1d2836a 100644 --- a/source/RenderGraph/LayerLayoutStatesHandler.cpp +++ b/source/RenderGraph/LayerLayoutStatesHandler.cpp @@ -25,7 +25,7 @@ namespace crg void LayerLayoutStatesHandler::setLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & layoutState ) { auto range = getVirtualRange( image @@ -43,14 +43,14 @@ namespace crg assert( view.data->source.empty() && "Merged image views must be resolved before setting their layout state" ); setLayoutState( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , layoutState ); } LayoutState LayerLayoutStatesHandler::getLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const + , ImageSubresourceRange const & subresourceRange )const { if ( auto imageIt = images.find( image.id ); imageIt != images.end() ) { @@ -69,7 +69,7 @@ namespace crg assert( view.data->source.empty() && "Merged image views must be resolved before finding their layout state" ); return getLayoutState( view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange ); } } diff --git a/source/RenderGraph/Log.cpp b/source/RenderGraph/Log.cpp index ece938b..381edcc 100644 --- a/source/RenderGraph/Log.cpp +++ b/source/RenderGraph/Log.cpp @@ -13,49 +13,49 @@ namespace crg { using lock_type = std::unique_lock< std::mutex >; - static void doLog( std::string const & message + static void doLog( std::string_view message , bool newLine - , std::ostream & stream ) + , FILE * stream )noexcept { - stream << message; + fprintf( stream, "%s", message.data() ); if ( newLine ) { - stream << std::endl; + fprintf( stream, "\n" ); } } } Logger::Logger() - : m_trace{ []( std::string const & msg, bool newLine ){ log::doLog( msg, newLine, std::clog ); } } - , m_debug{ []( std::string const & msg, bool newLine ){ log::doLog( msg, newLine, std::clog ); } } - , m_info{ []( std::string const & msg, bool newLine ){ log::doLog( msg, newLine, std::cout ); } } - , m_warning{ []( std::string const & msg, bool newLine ){ log::doLog( msg, newLine, std::cout ); } } - , m_error{ []( std::string const & msg, bool newLine ){ log::doLog( msg, newLine, std::cerr ); } } + : m_trace{ []( std::string_view msg, bool newLine )noexcept { log::doLog( msg, newLine, stdout ); } } + , m_debug{ []( std::string_view msg, bool newLine )noexcept { log::doLog( msg, newLine, stdout ); } } + , m_info{ []( std::string_view msg, bool newLine )noexcept { log::doLog( msg, newLine, stdout ); } } + , m_warning{ []( std::string_view msg, bool newLine )noexcept { log::doLog( msg, newLine, stdout ); } } + , m_error{ []( std::string_view msg, bool newLine )noexcept { log::doLog( msg, newLine, stderr ); } } { } - void Logger::logTrace( std::string const & message, bool newLine ) + void Logger::logTrace( std::string_view message, bool newLine )noexcept { doGetInstance().m_trace( message, newLine ); } - void Logger::logDebug( std::string const & message, bool newLine ) + void Logger::logDebug( std::string_view message, bool newLine )noexcept { doGetInstance().m_debug( message, newLine ); } - void Logger::logInfo( std::string const & message, bool newLine ) + void Logger::logInfo( std::string_view message, bool newLine )noexcept { doGetInstance().m_info( message, newLine ); } - void Logger::logWarning( std::string const & message, bool newLine ) + void Logger::logWarning( std::string_view message, bool newLine )noexcept { doGetInstance().m_warning( message, newLine ); } - void Logger::logError( std::string const & message, bool newLine ) + void Logger::logError( std::string_view message, bool newLine )noexcept { doGetInstance().m_error( message, newLine ); } @@ -85,7 +85,7 @@ namespace crg doGetInstance().m_error = std::move( callback ); } - Logger & Logger::doGetInstance() + Logger & Logger::doGetInstance()noexcept { static Logger instance; static std::mutex mutex; diff --git a/source/RenderGraph/RecordContext.cpp b/source/RenderGraph/RecordContext.cpp index 0bfef3e..902cd50 100644 --- a/source/RenderGraph/RecordContext.cpp +++ b/source/RenderGraph/RecordContext.cpp @@ -24,24 +24,58 @@ namespace crg namespace recctx { - static VkImageSubresourceRange adaptRange( GraphContext const & context + static ImageSubresourceRange adaptRange( GraphContext const & context , PixelFormat format - , VkImageSubresourceRange const & subresourceRange ) + , ImageSubresourceRange const & subresourceRange ) { - VkImageSubresourceRange result = subresourceRange; + ImageSubresourceRange result = subresourceRange; - if ( !context.separateDepthStencilLayouts ) - { - if ( isDepthStencilFormat( format ) - && ( result.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT - || result.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ) ) - { - result.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; - } - } + if ( !context.separateDepthStencilLayouts + && isDepthStencilFormat( format ) + && ( checkFlag( result.aspectMask, ImageAspectFlags::eDepth ) + || checkFlag( result.aspectMask, ImageAspectFlags::eStencil ) ) ) + result.aspectMask = ImageAspectFlags::eDepthStencil; return result; } + + static void clearAttachment( RecordContext & recContext + , VkCommandBuffer commandBuffer + , ImageViewId dstView + , ClearColorValue const & clearValue + , ImageLayout finalLayout ) + { + auto & resources = recContext.getResources(); + recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); + auto subresourceRange = convert( getSubresourceRange( dstView ) ); + assert( isColourFormat( getFormat( dstView ) ) ); + auto vkClearValue = convert( clearValue ); + resources->vkCmdClearColorImage( commandBuffer + , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , &vkClearValue, 1u, &subresourceRange ); + + if ( finalLayout != ImageLayout::eUndefined ) + recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( finalLayout ) ); + } + + static void clearAttachment( RecordContext & recContext + , VkCommandBuffer commandBuffer + , ImageViewId dstView + , ClearDepthStencilValue const & clearValue + , ImageLayout finalLayout ) + { + auto & resources = recContext.getResources(); + recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); + auto subresourceRange = convert( getSubresourceRange( dstView ) ); + assert( isDepthOrStencilFormat( getFormat( dstView ) ) ); + auto vkClearValue = convert( clearValue ); + resources->vkCmdClearDepthStencilImage( commandBuffer + , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , &vkClearValue, 1u, &subresourceRange ); + + if ( finalLayout != ImageLayout::eUndefined ) + recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( finalLayout ) ); + } } //************************************************************************************************ @@ -85,7 +119,7 @@ namespace crg m_nextImages = LayerLayoutStatesHandler{ imageLayouts }; } - void RecordContext::setLayoutState( crg::ImageViewId view + void RecordContext::setLayoutState( ImageViewId view , LayoutState const & layoutState ) { m_images.setLayoutState( view, layoutState ); @@ -98,7 +132,7 @@ namespace crg void RecordContext::setLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & layoutState ) { m_images.setLayoutState( image @@ -109,7 +143,7 @@ namespace crg LayoutState RecordContext::getLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const + , ImageSubresourceRange const & subresourceRange )const { return m_images.getLayoutState( image , viewType @@ -123,7 +157,7 @@ namespace crg LayoutState RecordContext::getNextLayoutState( ImageId image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange )const + , ImageSubresourceRange const & subresourceRange )const { return m_nextImages.getLayoutState( image , viewType @@ -131,7 +165,7 @@ namespace crg } void RecordContext::registerImplicitTransition( RunnablePass const & pass - , crg::ImageViewId view + , ImageViewId view , RecordContext::ImplicitAction action ) { registerImplicitTransition( { &pass, view, std::move( action ) } ); @@ -144,7 +178,7 @@ namespace crg void RecordContext::runImplicitTransition( VkCommandBuffer commandBuffer , uint32_t index - , crg::ImageViewId view ) + , ImageViewId view ) { auto it = std::find_if( m_implicitTransitions.begin() , m_implicitTransitions.end() @@ -193,7 +227,7 @@ namespace crg { memoryBarrier( commandBuffer , view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , initialLayout , wantedState @@ -202,7 +236,7 @@ namespace crg void RecordContext::memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , ImageLayout initialLayout , LayoutState const & wantedState , bool force ) @@ -219,13 +253,13 @@ namespace crg void RecordContext::memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , ImageLayout initialLayout , LayoutState const & wantedState , bool force ) { auto range = recctx::adaptRange( *m_resources - , convert( image.data->info.format ) + , image.data->info.format , subresourceRange ); auto from = getLayoutState( image , viewType @@ -244,17 +278,17 @@ namespace crg auto & resources = getResources(); VkImageMemoryBarrier barrier{ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER , nullptr - , convert( from.state.access ) - , convert( wantedState.state.access ) + , getAccessFlags( from.state.access ) + , getAccessFlags( wantedState.state.access ) , convert( from.layout ) , convert( wantedState.layout ) , VK_QUEUE_FAMILY_IGNORED , VK_QUEUE_FAMILY_IGNORED , resources.createImage( image ) - , range }; + , convert( range ) }; resources->vkCmdPipelineBarrier( commandBuffer - , convert( from.state.pipelineStage ) - , convert( wantedState.state.pipelineStage ) + , getPipelineStageFlags( from.state.pipelineStage ) + , getPipelineStageFlags( wantedState.state.pipelineStage ) , VK_DEPENDENCY_BY_REGION_BIT , 0u , nullptr @@ -276,7 +310,7 @@ namespace crg { memoryBarrier( commandBuffer , view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange , wantedState , force ); @@ -284,7 +318,7 @@ namespace crg void RecordContext::memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & wantedState , bool force ) { @@ -299,7 +333,7 @@ namespace crg void RecordContext::memoryBarrier( VkCommandBuffer commandBuffer , ImageId const & image , ImageViewType viewType - , VkImageSubresourceRange const & subresourceRange + , ImageSubresourceRange const & subresourceRange , LayoutState const & wantedState , bool force ) { @@ -339,7 +373,7 @@ namespace crg auto from = getAccessState( buffer , subresourceRange ); - if ( from.pipelineStage == PipelineStageFlags::eBottomOfPipe ) + if ( checkFlag( from.pipelineStage, PipelineStageFlags::eBottomOfPipe ) ) { from = { initialMask, initialStage }; } @@ -351,16 +385,16 @@ namespace crg auto const & resources = getResources(); VkBufferMemoryBarrier barrier{ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER , nullptr - , convert( from.access ) - , convert( wantedState.access ) + , getAccessFlags( from.access ) + , getAccessFlags( wantedState.access ) , VK_QUEUE_FAMILY_IGNORED , VK_QUEUE_FAMILY_IGNORED , buffer , subresourceRange.offset , subresourceRange.size }; resources->vkCmdPipelineBarrier( commandBuffer - , convert( from.pipelineStage ) - , convert( wantedState.pipelineStage ) + , getPipelineStageFlags( from.pipelineStage ) + , getPipelineStageFlags( wantedState.pipelineStage ) , VK_DEPENDENCY_BY_REGION_BIT , 0u , nullptr @@ -394,9 +428,20 @@ namespace crg return getResources(); } + ContextResourcesCache & RecordContext::getResources()const + { + if ( !m_resources ) + { + Logger::logError( "No resources available." ); + CRG_Exception( "No resources available." ); + } + + return *m_resources; + } + RecordContext::ImplicitAction RecordContext::copyImage( ImageViewId srcView , ImageViewId dstView - , VkExtent2D extent + , Extent2D const & extent , ImageLayout finalLayout ) { return [srcView, dstView, extent, finalLayout]( RecordContext & recContext @@ -406,8 +451,8 @@ namespace crg recContext.runImplicitTransition( commandBuffer, index, srcView ); auto & srcSubresource = srcView.data->info.subresourceRange; auto & dstSubresource = dstView.data->info.subresourceRange; - VkImageCopy region{ VkImageSubresourceLayers{ srcSubresource.aspectMask, srcSubresource.baseMipLevel, srcSubresource.baseArrayLayer, 1u }, VkOffset3D{ 0u, 0u, 0u } - , VkImageSubresourceLayers{ dstSubresource.aspectMask, dstSubresource.baseMipLevel, dstSubresource.baseArrayLayer, 1u }, VkOffset3D{ 0u, 0u, 0u } + VkImageCopy region{ getSubresourceLayer( srcSubresource ), VkOffset3D{ 0u, 0u, 0u } + , getSubresourceLayer( dstSubresource ), VkOffset3D{ 0u, 0u, 0u } , { extent.width, extent.height, 1u } }; recContext.memoryBarrier( commandBuffer, srcView, makeLayoutState( ImageLayout::eTransferSrc ) ); recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); @@ -424,24 +469,20 @@ namespace crg RecordContext::ImplicitAction RecordContext::blitImage( ImageViewId srcView , ImageViewId dstView - , VkOffset2D srcOffset - , VkExtent2D srcExtent - , VkOffset2D dstOffset - , VkExtent2D dstExtent + , Rect2D const & srcRect + , Rect2D const & dstRect , FilterMode filter , ImageLayout finalLayout ) { - return [srcView, dstView, srcOffset, srcExtent, dstOffset, dstExtent, filter, finalLayout]( RecordContext & recContext + return [srcView, dstView, srcRect, dstRect, filter, finalLayout]( RecordContext & recContext , VkCommandBuffer commandBuffer , uint32_t index ) { recContext.runImplicitTransition( commandBuffer, index, srcView ); auto & srcSubresource = srcView.data->info.subresourceRange; auto & dstSubresource = dstView.data->info.subresourceRange; - VkImageBlit region{ VkImageSubresourceLayers{ srcSubresource.aspectMask, srcSubresource.baseMipLevel, srcSubresource.baseArrayLayer, 1u } - , { VkOffset3D{ srcOffset.x, srcOffset.y, 0u }, VkOffset3D{ int32_t( srcExtent.width ), int32_t( srcExtent.height ), 1 } } - , VkImageSubresourceLayers{ dstSubresource.aspectMask, dstSubresource.baseMipLevel, dstSubresource.baseArrayLayer, 1u } - , { VkOffset3D{ dstOffset.x, dstOffset.y, 0u }, VkOffset3D{ int32_t( dstExtent.width ), int32_t( dstExtent.height ), 1 } } }; + VkImageBlit region{ getSubresourceLayer( srcSubresource ), { VkOffset3D{ srcRect.offset.x, srcRect.offset.y, 0u }, VkOffset3D{ int32_t( srcRect.extent.width ), int32_t( srcRect.extent.height ), 1 } } + , getSubresourceLayer( dstSubresource ), { VkOffset3D{ dstRect.offset.x, dstRect.offset.y, 0u }, VkOffset3D{ int32_t( dstRect.extent.width ), int32_t( dstRect.extent.height ), 1 } } }; recContext.memoryBarrier( commandBuffer, srcView, makeLayoutState( ImageLayout::eTransferSrc ) ); recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); auto & resources = recContext.getResources(); @@ -462,58 +503,36 @@ namespace crg , VkCommandBuffer commandBuffer , uint32_t index ) { - auto & resources = recContext.getResources(); auto dstView = attach.view( index ); - recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); - if ( isColourFormat( getFormat( dstView ) ) ) - resources->vkCmdClearColorImage( commandBuffer - , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &attach.getClearValue().color, 1u, &dstView.data->info.subresourceRange ); + recctx::clearAttachment( recContext, commandBuffer, dstView, getClearColorValue( attach.getClearValue() ), finalLayout ); else - resources->vkCmdClearDepthStencilImage( commandBuffer - , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &attach.getClearValue().depthStencil, 1u, &dstView.data->info.subresourceRange ); - - if ( finalLayout != ImageLayout::eUndefined ) - recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( finalLayout ) ); + recctx::clearAttachment( recContext, commandBuffer, dstView, getClearDepthStencilValue( attach.getClearValue() ), finalLayout ); }; } - ContextResourcesCache & RecordContext::getResources()const + RecordContext::ImplicitAction RecordContext::clearAttachment( ImageViewId dstView + , ClearColorValue const & clearValue + , ImageLayout finalLayout ) { - if ( !m_resources ) - { - Logger::logError( "No resources available." ); - CRG_Exception( "No resources available." ); - } - - return *m_resources; + return [clearValue, dstView, finalLayout]( RecordContext & recContext + , VkCommandBuffer commandBuffer + , [[maybe_unused]] uint32_t index ) + { + recctx::clearAttachment( recContext, commandBuffer, dstView, clearValue, finalLayout ); + }; } RecordContext::ImplicitAction RecordContext::clearAttachment( ImageViewId dstView - , VkClearValue const & clearValue + , ClearDepthStencilValue const & clearValue , ImageLayout finalLayout ) { return [clearValue, dstView, finalLayout]( RecordContext & recContext , VkCommandBuffer commandBuffer , [[maybe_unused]] uint32_t index ) - { - auto & resources = recContext.getResources(); - recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( ImageLayout::eTransferDst ) ); - - if ( isColourFormat( getFormat( dstView ) ) ) - resources->vkCmdClearColorImage( commandBuffer - , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &clearValue.color, 1u, &dstView.data->info.subresourceRange ); - else - resources->vkCmdClearDepthStencilImage( commandBuffer - , resources.createImage( dstView.data->image ), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &clearValue.depthStencil, 1u, &dstView.data->info.subresourceRange ); - - if ( finalLayout != ImageLayout::eUndefined ) - recContext.memoryBarrier( commandBuffer, dstView, makeLayoutState( finalLayout ) ); - }; + { + recctx::clearAttachment( recContext, commandBuffer, dstView, clearValue, finalLayout ); + }; } //************************************************************************************************ diff --git a/source/RenderGraph/ResourceHandler.cpp b/source/RenderGraph/ResourceHandler.cpp index d532e8f..136a6eb 100644 --- a/source/RenderGraph/ResourceHandler.cpp +++ b/source/RenderGraph/ResourceHandler.cpp @@ -37,13 +37,13 @@ namespace crg static VkImageCreateInfo convert( ImageData const & data ) { - return data.info; + return convert( data.info ); } static VkImageViewCreateInfo convert( ImageViewData const & data , VkImage const & image ) { - auto result = data.info; + auto result = convert( data.info ); result.image = image; return result; } diff --git a/source/RenderGraph/RunnableGraph.cpp b/source/RenderGraph/RunnableGraph.cpp index 2e283ab..3f84d85 100644 --- a/source/RenderGraph/RunnableGraph.cpp +++ b/source/RenderGraph/RunnableGraph.cpp @@ -130,6 +130,48 @@ namespace crg ? ( *nextPassIt )->getPipelineState() : currentState; } + + static VkDescriptorType getDescriptorType( BufferAttachment const & attach ) + { + if ( attach.isUniformView() ) + return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; + if ( attach.isStorageView() ) + return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; + if ( attach.isUniform() ) + return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + } + + static VkDescriptorType getDescriptorType( ImageAttachment const & attach ) + { + if ( attach.isStorageView() ) + return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + } + + static WriteDescriptorSet getWrite( BufferAttachment const & attach + , uint32_t binding + , uint32_t count + , uint32_t index ) + { + WriteDescriptorSet result{ binding + , 0u + , count + , getDescriptorType( attach ) }; + VkDescriptorBufferInfo info{ attach.buffer.buffer( index ), attach.range.offset, attach.range.size }; + + if ( attach.isView() ) + { + result.bufferViewInfo.push_back( info ); + result.texelBufferView.push_back( attach.view ); + } + else + { + result.bufferInfo.push_back( info ); + } + + return result; + } } //************************************************************************************************ @@ -417,7 +459,7 @@ namespace crg LayoutState RunnableGraph::getCurrentLayoutState( RecordContext & context , ImageId image , ImageViewType viewType - , VkImageSubresourceRange range )const + , ImageSubresourceRange range )const { auto result = context.getLayoutState( image, viewType, range ); @@ -451,7 +493,7 @@ namespace crg { return getCurrentLayoutState( context , view.data->image - , convert( view.data->info.viewType ) + , view.data->info.viewType , view.data->info.subresourceRange ); } @@ -480,4 +522,17 @@ namespace crg { return m_graph.getOutputLayoutState( view ); } + + VkDescriptorType RunnableGraph::getDescriptorType( Attachment const & attach )const + { + if ( attach.isImage() ) + return rungrf::getDescriptorType( attach.imageAttach ); + return rungrf::getDescriptorType( attach.bufferAttach ); + } + + WriteDescriptorSet RunnableGraph::getBufferWrite( Attachment const & attach, uint32_t index )const + { + assert( attach.isBuffer() ); + return rungrf::getWrite( attach.bufferAttach, attach.binding, 1u, index ); + } } diff --git a/source/RenderGraph/RunnablePass.cpp b/source/RenderGraph/RunnablePass.cpp index 74e03b8..226ed7a 100644 --- a/source/RenderGraph/RunnablePass.cpp +++ b/source/RenderGraph/RunnablePass.cpp @@ -19,13 +19,150 @@ namespace crg { namespace details { - static constexpr VkDeviceSize getAlignedSize( VkDeviceSize size, VkDeviceSize align ) + static constexpr DeviceSize getAlignedSize( DeviceSize size, DeviceSize align ) { auto rem = size % align; return ( rem ? size + ( align - rem ) : size ); } + + static void registerImage( Attachment const & attach + , bool isComputePass, bool separateDepthStencilLayouts + , LayerLayoutStatesHandler & imageLayouts ) + { + for ( uint32_t i = 0u; i < attach.getViewCount(); ++i ) + { + auto view = attach.view( i ); + + if ( view.data->source.empty() ) + { + imageLayouts.setLayoutState( view + , { attach.getImageLayout( separateDepthStencilLayouts ) + , attach.getAccessMask() + , attach.getPipelineStageFlags( isComputePass ) } ); + } + else + { + for ( auto & source : view.data->source ) + { + imageLayouts.setLayoutState( source + , { attach.getImageLayout( separateDepthStencilLayouts ) + , attach.getAccessMask() + , attach.getPipelineStageFlags( isComputePass ) } ); + } + } + } + } + + static void registerBuffer( Attachment const & attach + , bool isComputePass + , AccessStateMap & bufferAccesses ) + { + for ( uint32_t i = 0u; i < attach.getBufferCount(); ++i ) + { + bufferAccesses.insert_or_assign( attach.buffer( i ) + , AccessState{ attach.getAccessMask() + , attach.getPipelineStageFlags( isComputePass ) } ); + } + } + + static void prepareImage( VkCommandBuffer commandBuffer + , uint32_t index + , Attachment const & attach + , bool separateDepthStencilLayouts + , RunnableGraph & graph + , RecordContext & recordContext ) + { + auto view = attach.view( index ); + recordContext.runImplicitTransition( commandBuffer + , index + , view ); + + if ( !attach.isNoTransition() + && ( attach.isSampledView() || attach.isStorageView() || attach.isTransferView() || attach.isTransitionView() ) ) + { + auto needed = makeLayoutState( attach.getImageLayout( separateDepthStencilLayouts ) ); + auto currentLayout = ( !attach.isInput() + ? crg::makeLayoutState( ImageLayout::eUndefined ) + : graph.getCurrentLayoutState( recordContext, view ) ); + checkUndefinedInput( "Record", attach, view, currentLayout.layout ); + + if ( attach.isClearableImage() ) + { + recordContext.memoryBarrier( commandBuffer + , view + , currentLayout.layout + , makeLayoutState( ImageLayout::eTransferDst ) ); + auto subresourceRange = convert( getSubresourceRange( view ) ); + + if ( isColourFormat( getFormat( view ) ) ) + { + VkClearColorValue colour{}; + recordContext->vkCmdClearColorImage( commandBuffer + , graph.createImage( view.data->image ) + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , &colour + , 1u, &subresourceRange ); + } + else + { + VkClearDepthStencilValue depthStencil{}; + recordContext->vkCmdClearDepthStencilImage( commandBuffer + , graph.createImage( view.data->image ) + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , &depthStencil + , 1u, &subresourceRange ); + } + + currentLayout.layout = ImageLayout::eTransferDst; + currentLayout.state.access = AccessFlags::eTransferWrite; + currentLayout.state.pipelineStage = PipelineStageFlags::eTransfer; + } + + recordContext.memoryBarrier( commandBuffer + , view + , currentLayout.layout + , needed ); + } + } + + static void prepareBuffer( VkCommandBuffer commandBuffer + , uint32_t index + , Attachment const & attach + , bool isComputePass + , RecordContext & recordContext ) + { + if ( !attach.isNoTransition() + && ( attach.isStorageBuffer() || attach.isTransferBuffer() || attach.isTransitionBuffer() ) ) + { + auto & range = attach.getBufferRange(); + auto buffer = attach.buffer( index ); + auto currentState = recordContext.getAccessState( buffer, range ); + + if ( attach.isClearableBuffer() ) + { + recordContext.memoryBarrier( commandBuffer + , buffer + , range + , currentState + , { AccessFlags::eTransferWrite, PipelineStageFlags::eTransfer } ); + recordContext->vkCmdFillBuffer( commandBuffer + , buffer + , range.offset == 0u ? 0u : details::getAlignedSize( range.offset, 4u ) + , range.size == VK_WHOLE_SIZE ? VK_WHOLE_SIZE : details::getAlignedSize( range.size, 4u ) + , 0u ); + currentState.access = AccessFlags::eTransferWrite; + currentState.pipelineStage = PipelineStageFlags::eTransfer; + } + + recordContext.memoryBarrier( commandBuffer + , buffer + , range + , currentState + , { attach.getAccessMask(), attach.getPipelineStageFlags( isComputePass ) } ); + } + } } //********************************************************************************************* @@ -36,9 +173,7 @@ namespace crg , ImageLayout currentLayout ) { if ( !attach.isTransitionView() && attach.isInput() && currentLayout == ImageLayout::eUndefined ) - { Logger::logWarning( stepName + " - [" + attach.pass->getFullName() + "]: Input view [" + view.data->name + "] is currently in undefined layout" ); - } } void convert( SemaphoreWaitArray const & toWait @@ -53,11 +188,20 @@ namespace crg , wait.semaphore ) ) { semaphores.push_back( wait.semaphore ); - dstStageMasks.push_back( convert( wait.dstStageMask ) ); + dstStageMasks.push_back( getPipelineStageFlags( wait.dstStageMask ) ); } } } + std::vector< VkClearValue > convert( std::vector< ClearValue > const & v ) + { + std::vector< VkClearValue > result; + result.reserve( v.size() ); + for ( auto & value : v ) + result.push_back( convert( value ) ); + return result; + } + //********************************************************************************************* RunnablePass::Callbacks::Callbacks( InitialiseCallback initialise @@ -261,41 +405,11 @@ namespace crg m_passContexts.emplace_back( graph.getResources() ); } + bool isComputePass = m_callbacks.isComputePass(); for ( auto & attach : m_pass.images ) - { - for ( uint32_t i = 0u; i < attach.getViewCount(); ++i ) - { - auto view = attach.view( i ); - - if ( view.data->source.empty() ) - { - m_imageLayouts.setLayoutState( view - , { attach.getImageLayout( m_context.separateDepthStencilLayouts ) - , attach.getAccessMask() - , attach.getPipelineStageFlags( m_callbacks.isComputePass() ) } ); - } - else - { - for ( auto & source : view.data->source ) - { - m_imageLayouts.setLayoutState( source - , { attach.getImageLayout( m_context.separateDepthStencilLayouts ) - , attach.getAccessMask() - , attach.getPipelineStageFlags( m_callbacks.isComputePass() ) } ); - } - } - } - } - + details::registerImage( attach, isComputePass, m_context.separateDepthStencilLayouts, m_imageLayouts ); for ( auto & attach : m_pass.buffers ) - { - for ( uint32_t i = 0u; i < attach.getBufferCount(); ++i ) - { - m_bufferAccesses.insert_or_assign( attach.buffer( i ) - , AccessState{ attach.getAccessMask() - , attach.getPipelineStageFlags( m_callbacks.isComputePass() ) } ); - } - } + details::registerBuffer( attach, isComputePass, m_bufferAccesses ); } RunnablePass::~RunnablePass()noexcept @@ -388,93 +502,10 @@ namespace crg m_timer.beginPass( commandBuffer ); for ( auto & attach : m_pass.images ) - { - auto view = attach.view( index ); - context.runImplicitTransition( commandBuffer - , index - , view ); - - if ( !attach.isNoTransition() - && ( attach.isSampledView() || attach.isStorageView() || attach.isTransferView() || attach.isTransitionView() ) ) - { - auto needed = makeLayoutState( attach.getImageLayout( m_context.separateDepthStencilLayouts ) ); - auto currentLayout = ( !attach.isInput() - ? crg::makeLayoutState( ImageLayout::eUndefined ) - : m_graph.getCurrentLayoutState( context, view ) ); - checkUndefinedInput( "Record", attach, view, currentLayout.layout ); - - if ( attach.isClearableImage() ) - { - context.memoryBarrier( commandBuffer - , view - , currentLayout.layout - , makeLayoutState( ImageLayout::eTransferDst ) ); - - if ( isColourFormat( getFormat( view ) ) ) - { - VkClearColorValue colour{}; - m_context.vkCmdClearColorImage( commandBuffer - , m_graph.createImage( view.data->image ) - , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &colour - , 1u - , &view.data->info.subresourceRange ); - } - else - { - VkClearDepthStencilValue depthStencil{}; - m_context.vkCmdClearDepthStencilImage( commandBuffer - , m_graph.createImage( view.data->image ) - , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL - , &depthStencil - , 1u - , &view.data->info.subresourceRange ); - } - - currentLayout.layout = ImageLayout::eTransferDst; - currentLayout.state.access = AccessFlags::eTransferWrite; - currentLayout.state.pipelineStage = PipelineStageFlags::eTransfer; - } - - context.memoryBarrier( commandBuffer - , view - , currentLayout.layout - , needed ); - } - } + details::prepareImage( commandBuffer, index, attach, m_context.separateDepthStencilLayouts, m_graph, context ); for ( auto & attach : m_pass.buffers ) - { - if ( !attach.isNoTransition() - && ( attach.isStorageBuffer() || attach.isTransferBuffer() || attach.isTransitionBuffer() ) ) - { - auto & range = attach.getBufferRange(); - auto buffer = attach.buffer( index ); - auto currentState = context.getAccessState( buffer, range ); - - if ( attach.isClearableBuffer() ) - { - context.memoryBarrier( commandBuffer - , buffer - , range - , currentState - , { AccessFlags::eTransferWrite, PipelineStageFlags::eTransfer } ); - m_context.vkCmdFillBuffer( commandBuffer - , buffer - , range.offset == 0u ? 0u : details::getAlignedSize( range.offset, 4u ) - , range.size == VK_WHOLE_SIZE ? VK_WHOLE_SIZE : details::getAlignedSize( range.size, 4u ) - , 0u ); - currentState.access = AccessFlags::eTransferWrite; - currentState.pipelineStage = PipelineStageFlags::eTransfer; - } - - context.memoryBarrier( commandBuffer - , buffer - , range - , currentState - , { attach.getAccessMask(), attach.getPipelineStageFlags( m_callbacks.isComputePass() ) } ); - } - } + details::prepareBuffer( commandBuffer, index, attach, m_callbacks.isComputePass(), context ); for ( auto const & action : m_ruConfig.prePassActions ) { diff --git a/source/RenderGraph/RunnablePasses/BufferCopy.cpp b/source/RenderGraph/RunnablePasses/BufferCopy.cpp index 1e2587f..6e189b7 100644 --- a/source/RenderGraph/RunnablePasses/BufferCopy.cpp +++ b/source/RenderGraph/RunnablePasses/BufferCopy.cpp @@ -15,8 +15,8 @@ namespace crg BufferCopy::BufferCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkDeviceSize copyOffset - , VkDeviceSize copyRange + , DeviceSize copyOffset + , DeviceSize copyRange , ru::Config ruConfig , GetPassIndexCallback passIndex , IsEnabledCallback isEnabled ) diff --git a/source/RenderGraph/RunnablePasses/BufferToImageCopy.cpp b/source/RenderGraph/RunnablePasses/BufferToImageCopy.cpp index fb707f4..96b74e8 100644 --- a/source/RenderGraph/RunnablePasses/BufferToImageCopy.cpp +++ b/source/RenderGraph/RunnablePasses/BufferToImageCopy.cpp @@ -12,22 +12,11 @@ See LICENSE file in root folder. namespace crg { - namespace bufToImg - { - static VkImageSubresourceLayers convert( VkImageSubresourceRange const & range ) - { - return VkImageSubresourceLayers{ range.aspectMask - , range.baseMipLevel - , range.baseArrayLayer - , range.layerCount }; - } - } - BufferToImageCopy::BufferToImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D copyOffset - , VkExtent3D copySize + , Offset3D const & copyOffset + , Extent3D const & copySize , ru::Config ruConfig , GetPassIndexCallback passIndex , IsEnabledCallback isEnabled ) @@ -36,16 +25,16 @@ namespace crg , graph , { defaultV< InitialiseCallback > , GetPipelineStateCallback( [](){ return crg::getPipelineState( PipelineStageFlags::eTransfer ); } ) - , [this]( RecordContext & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } + , [this]( RecordContext const & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } , std::move( passIndex ) , std::move( isEnabled ) } , std::move( ruConfig ) } - , m_copyOffset{ copyOffset } - , m_copySize{ copySize } + , m_copyOffset{ convert( copyOffset ) } + , m_copySize{ convert( copySize ) } { } - void BufferToImageCopy::doRecordInto( RecordContext & context + void BufferToImageCopy::doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index )const { @@ -53,7 +42,7 @@ namespace crg auto srcBuffer{ m_pass.buffers.front().buffer( index ) }; auto dstImage{ m_graph.createImage( dstAttach.data->image ) }; // Copy source to target. - auto range = bufToImg::convert( dstAttach.data->info.subresourceRange ); + auto range = getSubresourceLayers( dstAttach.data->info.subresourceRange ); VkBufferImageCopy copyRegion{ 0ULL , 0u , 0u diff --git a/source/RenderGraph/RunnablePasses/GenerateMipmaps.cpp b/source/RenderGraph/RunnablePasses/GenerateMipmaps.cpp index 60cc393..2191a87 100644 --- a/source/RenderGraph/RunnablePasses/GenerateMipmaps.cpp +++ b/source/RenderGraph/RunnablePasses/GenerateMipmaps.cpp @@ -65,13 +65,13 @@ namespace crg for ( uint32_t i = 0u; i < layerCount; ++i ) { auto layer = baseArrayLayer + i; - VkImageSubresourceRange mipSubRange{ aspectMask + ImageSubresourceRange mipSubRange{ aspectMask , 0u , 1u , layer , 1u }; VkImageBlit imageBlit{}; - imageBlit.dstSubresource.aspectMask = aspectMask; + imageBlit.dstSubresource.aspectMask = getImageAspectFlags( aspectMask ); imageBlit.dstSubresource.baseArrayLayer = mipSubRange.baseArrayLayer; imageBlit.dstSubresource.layerCount = 1; imageBlit.dstSubresource.mipLevel = mipSubRange.baseMipLevel; @@ -85,7 +85,7 @@ namespace crg // Transition first mip level to transfer source for read in next iteration auto firstLayoutState = m_graph.getCurrentLayoutState( context , imageId - , convert( viewId.data->info.viewType ) + , viewId.data->info.viewType , mipSubRange ); context.memoryBarrier( commandBuffer , imageId diff --git a/source/RenderGraph/RunnablePasses/ImageBlit.cpp b/source/RenderGraph/RunnablePasses/ImageBlit.cpp index 6e903d3..3e3009f 100644 --- a/source/RenderGraph/RunnablePasses/ImageBlit.cpp +++ b/source/RenderGraph/RunnablePasses/ImageBlit.cpp @@ -12,24 +12,13 @@ See LICENSE file in root folder. namespace crg { - namespace imgBlit - { - static VkImageSubresourceLayers convert( VkImageSubresourceRange const & range ) - { - return VkImageSubresourceLayers{ range.aspectMask - , range.baseMipLevel - , range.baseArrayLayer - , range.layerCount }; - } - } - ImageBlit::ImageBlit( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D blitSrcOffset - , VkExtent3D blitSrcSize - , VkOffset3D blitDstOffset - , VkExtent3D blitDstSize + , Offset3D const & blitSrcOffset + , Extent3D const & blitSrcSize + , Offset3D const & blitDstOffset + , Extent3D const & blitDstSize , FilterMode filter , ru::Config ruConfig , GetPassIndexCallback passIndex @@ -39,20 +28,20 @@ namespace crg , graph , { defaultV< InitialiseCallback > , GetPipelineStateCallback( [](){ return crg::getPipelineState( PipelineStageFlags::eTransfer ); } ) - , [this]( RecordContext & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } + , [this]( RecordContext const & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } , std::move( passIndex ) , std::move( isEnabled ) } , std::move( ruConfig ) } - , m_srcOffset{ std::move( blitSrcOffset ) } - , m_srcSize{ std::move( blitSrcSize ) } - , m_dstOffset{ std::move( blitDstOffset ) } - , m_dstSize{ std::move( blitDstSize ) } + , m_srcOffset{ convert( blitSrcOffset ) } + , m_srcSize{ convert( blitSrcSize ) } + , m_dstOffset{ convert( blitDstOffset ) } + , m_dstSize{ convert( blitDstSize ) } , m_filter{ filter } { assert( pass.images.size() == 2u ); } - void ImageBlit::doRecordInto( RecordContext & context + void ImageBlit::doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ) { @@ -60,9 +49,9 @@ namespace crg auto dstAttach{ m_pass.images.back().view( index ) }; auto srcImage{ m_graph.createImage( srcAttach.data->image ) }; auto dstImage{ m_graph.createImage( dstAttach.data->image ) }; - VkImageBlit blitRegion{ imgBlit::convert( srcAttach.data->info.subresourceRange ) + VkImageBlit blitRegion{ getSubresourceLayers( srcAttach.data->info.subresourceRange ) , { m_srcOffset, VkOffset3D{ int32_t( m_srcSize.width ), int32_t( m_srcSize.height ), int32_t( m_srcSize.depth ) } } - , imgBlit::convert( dstAttach.data->info.subresourceRange ) + , getSubresourceLayers( dstAttach.data->info.subresourceRange ) , { m_dstOffset, VkOffset3D{ int32_t( m_dstSize.width ), int32_t( m_dstSize.height ), int32_t( m_dstSize.depth ) } } }; context->vkCmdBlitImage( commandBuffer , srcImage diff --git a/source/RenderGraph/RunnablePasses/ImageCopy.cpp b/source/RenderGraph/RunnablePasses/ImageCopy.cpp index bebcd38..bff16bf 100644 --- a/source/RenderGraph/RunnablePasses/ImageCopy.cpp +++ b/source/RenderGraph/RunnablePasses/ImageCopy.cpp @@ -12,21 +12,10 @@ See LICENSE file in root folder. namespace crg { - namespace imgCopy - { - static VkImageSubresourceLayers convert( VkImageSubresourceRange const & range ) - { - return VkImageSubresourceLayers{ range.aspectMask - , range.baseMipLevel - , range.baseArrayLayer - , range.layerCount }; - } - } - ImageCopy::ImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkExtent3D copySize + , Extent3D const & copySize , ImageLayout finalOutputLayout , ru::Config ruConfig , GetPassIndexCallback passIndex @@ -40,7 +29,7 @@ namespace crg , std::move( passIndex ) , std::move( isEnabled ) } , std::move( ruConfig ) } - , m_copySize{std::move( copySize ) } + , m_copySize{ convert( copySize ) } , m_finalOutputLayout{ finalOutputLayout } { assert( ( pass.images.size() % 2u ) == 0u ); @@ -49,7 +38,7 @@ namespace crg ImageCopy::ImageCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkExtent3D copySize + , Extent3D const & copySize , ru::Config ruConfig , GetPassIndexCallback passIndex , IsEnabledCallback isEnabled ) @@ -79,9 +68,9 @@ namespace crg auto srcImage{ m_graph.createImage( srcAttach.data->image ) }; auto dstImage{ m_graph.createImage( dstAttach.data->image ) }; // Copy source to target. - VkImageCopy copyRegion{ imgCopy::convert( srcAttach.data->info.subresourceRange ) + VkImageCopy copyRegion{ getSubresourceLayers( srcAttach.data->info.subresourceRange ) , {} - , imgCopy::convert( dstAttach.data->info.subresourceRange ) + , getSubresourceLayers( dstAttach.data->info.subresourceRange ) , {} , m_copySize }; context->vkCmdCopyImage( commandBuffer diff --git a/source/RenderGraph/RunnablePasses/ImageToBufferCopy.cpp b/source/RenderGraph/RunnablePasses/ImageToBufferCopy.cpp index 3abf5bd..2caa4a5 100644 --- a/source/RenderGraph/RunnablePasses/ImageToBufferCopy.cpp +++ b/source/RenderGraph/RunnablePasses/ImageToBufferCopy.cpp @@ -12,22 +12,11 @@ See LICENSE file in root folder. namespace crg { - namespace imToBuf - { - static VkImageSubresourceLayers convert( VkImageSubresourceRange const & range ) - { - return VkImageSubresourceLayers{ range.aspectMask - , range.baseMipLevel - , range.baseArrayLayer - , range.layerCount }; - } - } - ImageToBufferCopy::ImageToBufferCopy( FramePass const & pass , GraphContext & context , RunnableGraph & graph - , VkOffset3D copyOffset - , VkExtent3D copySize + , Offset3D const & copyOffset + , Extent3D const & copySize , ru::Config ruConfig , GetPassIndexCallback passIndex , IsEnabledCallback isEnabled ) @@ -36,16 +25,16 @@ namespace crg , graph , { defaultV< InitialiseCallback > , GetPipelineStateCallback( [](){ return crg::getPipelineState( PipelineStageFlags::eTransfer ); } ) - , [this]( RecordContext & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } + , [this]( RecordContext const & recContext, VkCommandBuffer cb, uint32_t i ){ doRecordInto( recContext, cb, i ); } , std::move( passIndex ) , std::move( isEnabled ) } , std::move( ruConfig ) } - , m_copyOffset{ std::move( copyOffset ) } - , m_copySize{ std::move( copySize ) } + , m_copyOffset{ convert( copyOffset ) } + , m_copySize{ convert( copySize ) } { } - void ImageToBufferCopy::doRecordInto( RecordContext & context + void ImageToBufferCopy::doRecordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ) { @@ -53,7 +42,7 @@ namespace crg auto dstBuffer{ m_pass.buffers.front().buffer( index ) }; auto srcImage{ m_graph.createImage( srcAttach.data->image ) }; // Copy source to target. - auto range = imToBuf::convert( srcAttach.data->info.subresourceRange ); + auto range = getSubresourceLayers( srcAttach.data->info.subresourceRange ); VkBufferImageCopy copyRegion{ 0ULL , 0u , 0u diff --git a/source/RenderGraph/RunnablePasses/PipelineHolder.cpp b/source/RenderGraph/RunnablePasses/PipelineHolder.cpp index c899604..fae24e0 100644 --- a/source/RenderGraph/RunnablePasses/PipelineHolder.cpp +++ b/source/RenderGraph/RunnablePasses/PipelineHolder.cpp @@ -190,7 +190,7 @@ namespace crg , createInfo ); } - void PipelineHolder::recordInto( RecordContext & context + void PipelineHolder::recordInto( RecordContext const & context , VkCommandBuffer commandBuffer , uint32_t index ) { @@ -263,11 +263,8 @@ namespace crg for ( auto & buffer : m_pass.buffers ) { - if ( buffer.isStorageBuffer() - || buffer.isUniformBuffer() ) - { - descriptorSet.writes.push_back( buffer.getBufferWrite( index ) ); - } + if ( buffer.isStorageBuffer() || buffer.isUniformBuffer() ) + descriptorSet.writes.push_back( m_graph.getBufferWrite( buffer, index ) ); } VkDescriptorSetAllocateInfo allocateInfo{ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO @@ -310,7 +307,7 @@ namespace crg if ( attach.isSampledView() || attach.isStorageView() ) { m_descriptorBindings.push_back( { attach.binding - , attach.getDescriptorType() + , m_graph.getDescriptorType( attach ) , 1u , shaderStage , nullptr } ); @@ -323,7 +320,7 @@ namespace crg || attach.isUniformBufferView() || attach.isStorageBufferView() ) { m_descriptorBindings.push_back( { attach.binding - , attach.getDescriptorType() + , m_graph.getDescriptorType( attach ) , 1u , shaderStage , nullptr } ); diff --git a/source/RenderGraph/RunnablePasses/RenderMeshHolder.cpp b/source/RenderGraph/RunnablePasses/RenderMeshHolder.cpp index ee2f234..7d6480c 100644 --- a/source/RenderGraph/RunnablePasses/RenderMeshHolder.cpp +++ b/source/RenderGraph/RunnablePasses/RenderMeshHolder.cpp @@ -13,7 +13,7 @@ namespace crg , RunnableGraph & graph , rm::Config config , uint32_t maxPassCount ) - : m_config{ config.m_renderPosition ? std::move( *config.m_renderPosition ) : getDefaultV< VkOffset2D >() + : m_config{ config.m_renderPosition ? std::move( *config.m_renderPosition ) : getDefaultV< Offset2D >() , config.m_depthStencilState ? std::move( *config.m_depthStencilState ) : getDefaultV< VkPipelineDepthStencilStateCreateInfo >() , config.m_getPassIndex ? std::move( *config.m_getPassIndex ) : getDefaultV< RunnablePass::GetPassIndexCallback >() , config.m_isEnabled ? std::move( *config.m_isEnabled ) : getDefaultV< RunnablePass::IsEnabledCallback >() @@ -32,7 +32,7 @@ namespace crg , config.m_baseConfig , VK_PIPELINE_BIND_POINT_GRAPHICS , maxPassCount } - , m_renderSize{ config.m_renderSize ? *config.m_renderSize : getDefaultV< VkExtent2D >() } + , m_renderSize{ config.m_renderSize ? *config.m_renderSize : getDefaultV< Extent2D >() } { m_iaState = { VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO , nullptr @@ -63,7 +63,7 @@ namespace crg , 0.0f }; } - void RenderMeshHolder::initialise( VkExtent2D const & renderSize + void RenderMeshHolder::initialise( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ) @@ -87,7 +87,7 @@ namespace crg m_pipeline.cleanup(); } - void RenderMeshHolder::resetRenderPass( VkExtent2D const & renderSize + void RenderMeshHolder::resetRenderPass( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ) @@ -115,7 +115,7 @@ namespace crg doCreatePipeline( index ); m_pipeline.recordInto( context, commandBuffer, index ); m_config.recordInto( context, commandBuffer, index ); - VkDeviceSize offset{}; + DeviceSize offset{}; if ( m_config.vertexBuffer.buffer.buffer( index ) ) { @@ -162,12 +162,12 @@ namespace crg return m_config.isEnabled(); } - VkExtent2D RenderMeshHolder::getRenderSize()const + Extent2D RenderMeshHolder::getRenderSize()const { return m_renderSize; } - void RenderMeshHolder::doPreparePipelineStates( VkExtent2D const & renderSize + void RenderMeshHolder::doPreparePipelineStates( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState ) { @@ -210,7 +210,7 @@ namespace crg } - VkPipelineViewportStateCreateInfo RenderMeshHolder::doCreateViewportState( VkExtent2D const & renderSize + VkPipelineViewportStateCreateInfo RenderMeshHolder::doCreateViewportState( Extent2D const & renderSize , VkViewport & viewport , VkRect2D & scissor )const { diff --git a/source/RenderGraph/RunnablePasses/RenderPass.cpp b/source/RenderGraph/RunnablePasses/RenderPass.cpp index a61a195..1785959 100644 --- a/source/RenderGraph/RunnablePasses/RenderPass.cpp +++ b/source/RenderGraph/RunnablePasses/RenderPass.cpp @@ -95,7 +95,7 @@ namespace crg , GraphContext & context , RunnableGraph & graph , Callbacks callbacks - , VkExtent2D const & size + , Extent2D size , ru::Config const & ruConfig ) : RunnablePass{ pass , context @@ -111,7 +111,7 @@ namespace crg , context , graph , ruConfig.maxPassCount - , size } + , std::move( size ) } { } diff --git a/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp b/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp index 6939b16..28c1b4e 100644 --- a/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp +++ b/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp @@ -22,7 +22,7 @@ namespace crg , ImageViewId view , VkAttachmentDescriptionArray & attaches , std::vector< RenderPassHolder::Entry > & viewAttaches - , std::vector< VkClearValue > & clearValues + , std::vector< ClearValue > & clearValues , LayoutState initialLayout , LayoutState finalLayout , bool separateDepthStencilLayouts ) @@ -30,14 +30,14 @@ namespace crg VkAttachmentReference result{ uint32_t( attaches.size() ) , convert( attach.getImageLayout( separateDepthStencilLayouts ) ) }; attaches.push_back( { 0u - , view.data->info.format - , view.data->image.data->info.samples - , ( initialLayout.layout == ImageLayout::eUndefined - ? VK_ATTACHMENT_LOAD_OP_CLEAR + , convert( view.data->info.format ) + , convert( view.data->image.data->info.samples ) + , convert( initialLayout.layout == ImageLayout::eUndefined + ? AttachmentLoadOp::eClear : attach.getLoadOp() ) - , attach.getStoreOp() - , attach.getStencilLoadOp() - , attach.getStencilStoreOp() + , convert( attach.getStoreOp() ) + , convert( attach.getStencilLoadOp() ) + , convert( attach.getStencilStoreOp() ) , convert( initialLayout.layout ) , convert( finalLayout.layout ) } ); viewAttaches.push_back( { view, initialLayout, finalLayout } ); @@ -63,13 +63,13 @@ namespace crg , ImageViewId view , VkAttachmentDescriptionArray & attaches , std::vector< RenderPassHolder::Entry > & viewAttaches - , std::vector< VkClearValue > & clearValues + , std::vector< ClearValue > & clearValues , VkPipelineColorBlendAttachmentStateArray & blendAttachs , LayoutState initialLayout , LayoutState finalLayout , bool separateDepthStencilLayouts ) { - blendAttachs.push_back( attach.getBlendState() ); + blendAttachs.push_back( convert( attach.getBlendState() ) ); return addAttach( context , attach , view @@ -142,7 +142,7 @@ namespace crg , GraphContext & context , RunnableGraph & graph , uint32_t maxPassCount - , VkExtent2D size ) + , Extent2D size ) : m_pass{ pass } , m_context{ context } , m_graph{ graph } @@ -190,13 +190,14 @@ namespace crg VkRenderPassBeginInfo RenderPassHolder::getBeginInfo( uint32_t index )const { auto frameBuffer = getFramebuffer( index ); + auto clearValues = convert( getClearValues( index ) ); return VkRenderPassBeginInfo{ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO , nullptr , getRenderPass( index ) , frameBuffer - , getRenderArea( index ) - , uint32_t( getClearValues( index ).size() ) - , getClearValues( index ).data() }; + , convert( getRenderArea( index ) ) + , uint32_t( clearValues.size() ) + , clearValues.data() }; } void RenderPassHolder::begin( RecordContext & context @@ -303,17 +304,17 @@ namespace crg VkSubpassDependencyArray dependencies{ { VK_SUBPASS_EXTERNAL , 0u - , convert( previousState.pipelineStage ) + , getPipelineStageFlags( previousState.pipelineStage ) , VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT - , convert( previousState.access ) + , getAccessFlags( previousState.access ) , VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT , VK_DEPENDENCY_BY_REGION_BIT } , { 0u , VK_SUBPASS_EXTERNAL , VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT - , convert( nextState.pipelineStage ) + , getPipelineStageFlags( nextState.pipelineStage ) , VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT - , convert( nextState.access ) + , getAccessFlags( nextState.access ) , VK_DEPENDENCY_BY_REGION_BIT } }; VkRenderPassCreateInfo createInfo{ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO , nullptr diff --git a/source/RenderGraph/RunnablePasses/RenderQuad.cpp b/source/RenderGraph/RunnablePasses/RenderQuad.cpp index a21471e..a62f69e 100644 --- a/source/RenderGraph/RunnablePasses/RenderQuad.cpp +++ b/source/RenderGraph/RunnablePasses/RenderQuad.cpp @@ -33,7 +33,7 @@ namespace crg , context , graph , ruConfig.maxPassCount - , rqConfig.m_renderSize ? *rqConfig.m_renderSize : getDefaultV< VkExtent2D >() } + , rqConfig.m_renderSize ? *rqConfig.m_renderSize : getDefaultV< Extent2D >() } { } diff --git a/source/RenderGraph/RunnablePasses/RenderQuadHolder.cpp b/source/RenderGraph/RunnablePasses/RenderQuadHolder.cpp index cf1cbff..5b9eae3 100644 --- a/source/RenderGraph/RunnablePasses/RenderQuadHolder.cpp +++ b/source/RenderGraph/RunnablePasses/RenderQuadHolder.cpp @@ -16,7 +16,7 @@ namespace crg , rq::Config config , uint32_t maxPassCount ) : m_config{ config.m_texcoordConfig ? std::move( *config.m_texcoordConfig ) : getDefaultV< Texcoord >() - , config.m_renderPosition ? std::move( *config.m_renderPosition ) : getDefaultV< VkOffset2D >() + , config.m_renderPosition ? std::move( *config.m_renderPosition ) : getDefaultV< Offset2D >() , config.m_depthStencilState ? std::move( *config.m_depthStencilState ) : getDefaultV< VkPipelineDepthStencilStateCreateInfo >() , config.m_passIndex ? *config.m_passIndex : getDefaultV< uint32_t const * >() , config.m_enabled ? *config.m_enabled : getDefaultV< bool const * >() @@ -63,7 +63,7 @@ namespace crg , 0.0f }; } - void RenderQuadHolder::initialise( VkExtent2D const & renderSize + void RenderQuadHolder::initialise( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ) @@ -83,7 +83,7 @@ namespace crg doCreatePipeline( index ); } - void RenderQuadHolder::resetRenderPass( VkExtent2D const & renderSize + void RenderQuadHolder::resetRenderPass( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState , uint32_t index ) @@ -111,7 +111,7 @@ namespace crg doCreatePipeline( index ); m_pipeline.recordInto( context, commandBuffer, index ); m_config.recordInto( context, commandBuffer, index ); - VkDeviceSize offset{}; + DeviceSize offset{}; if ( m_vertexBuffer && m_vertexBuffer->buffer.buffer( index ) ) @@ -150,7 +150,7 @@ namespace crg : ( m_config.enabled ? *m_config.enabled : true ) ); } - void RenderQuadHolder::doPreparePipelineStates( VkExtent2D const & renderSize + void RenderQuadHolder::doPreparePipelineStates( Extent2D const & renderSize , VkRenderPass renderPass , VkPipelineColorBlendStateCreateInfo blendState ) { @@ -192,7 +192,7 @@ namespace crg m_pipeline.createPipeline( index, createInfo ); } - VkPipelineViewportStateCreateInfo RenderQuadHolder::doCreateViewportState( VkExtent2D const & renderSize + VkPipelineViewportStateCreateInfo RenderQuadHolder::doCreateViewportState( Extent2D const & renderSize , VkViewport & viewport , VkRect2D & scissor )const { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2aafe8a..aff9089 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,7 +34,7 @@ target_include_directories( ${TEST_NAME} ) set_target_properties( ${TEST_NAME} PROPERTIES - CXX_STANDARD 17 + CXX_STANDARD 20 FOLDER "Tests/${MAIN_PROJECT_NAME}" ) @@ -57,7 +57,7 @@ foreach ( TEST_FILE ${TEST_FILES} ) ) set_target_properties( ${TEST_NAME} PROPERTIES - CXX_STANDARD 17 + CXX_STANDARD 20 FOLDER "Tests/${MAIN_PROJECT_NAME}" ) target_include_directories( ${TEST_NAME} diff --git a/test/Common.cpp b/test/Common.cpp index 3eae964..37fef25 100644 --- a/test/Common.cpp +++ b/test/Common.cpp @@ -61,7 +61,7 @@ namespace test } crg::ImageViewType getViewType( crg::ImageType type - , VkImageCreateFlags flags + , crg::ImageCreateFlags flags , uint32_t layerCount ) { switch ( type ) @@ -75,7 +75,7 @@ namespace test default: if ( layerCount > 1u ) { - if ( ( ( layerCount % 6u ) == 0u ) && ( flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT ) ) + if ( ( ( layerCount % 6u ) == 0u ) && checkFlag( flags, crg::ImageCreateFlags::eCubeCompatible ) ) { return ( layerCount > 6u ) ? crg::ImageViewType::eCubeArray @@ -100,12 +100,12 @@ namespace test , uint32_t arrayLayers ) { return crg::ImageData{ std::move( name ) - , 0u + , crg::ImageCreateFlags::eNone , crg::ImageType::e2D , format , { 1024, 1024 } - , ( VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT - | VK_IMAGE_USAGE_SAMPLED_BIT ) + , ( crg::ImageUsageFlags::eColorAttachment + | crg::ImageUsageFlags::eSampled ) , mipLevels , arrayLayers }; } @@ -116,12 +116,12 @@ namespace test , uint32_t arrayLayers ) { return crg::ImageData{ std::move( name ) - , 0u + , crg::ImageCreateFlags::eNone , crg::ImageType::e1D , format , { 1024 } - , ( VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT - | VK_IMAGE_USAGE_SAMPLED_BIT ) + , ( crg::ImageUsageFlags::eColorAttachment + | crg::ImageUsageFlags::eSampled ) , mipLevels , arrayLayers }; } @@ -132,12 +132,12 @@ namespace test , uint32_t arrayLayers ) { return crg::ImageData{ std::move( name ) - , VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT + , crg::ImageCreateFlags::eCubeCompatible , crg::ImageType::e2D , format , { 1024, 1024u } - , ( VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT - | VK_IMAGE_USAGE_SAMPLED_BIT ) + , ( crg::ImageUsageFlags::eColorAttachment + | crg::ImageUsageFlags::eSampled ) , mipLevels , arrayLayers * 6u }; } @@ -151,7 +151,7 @@ namespace test { return createView( std::move( name ) , image - , crg::convert( image.data->info.format ) + , image.data->info.format , baseMipLevel , levelCount , baseArrayLayer @@ -166,19 +166,12 @@ namespace test , uint32_t baseArrayLayer , uint32_t layerCount ) { - VkImageAspectFlags aspect = ( isDepthStencilFormat( format ) - ? ( VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_DEPTH_BIT ) - : ( isDepthFormat( format ) - ? VK_IMAGE_ASPECT_DEPTH_BIT - : ( isStencilFormat( format ) - ? VK_IMAGE_ASPECT_STENCIL_BIT - : VK_IMAGE_ASPECT_COLOR_BIT ) ) ); return crg::ImageViewData{ std::move( name ) , image - , 0u - , getViewType( crg::convert( image.data->info.imageType ), image.data->info.flags, layerCount ) + , crg::ImageViewCreateFlags::eNone + , getViewType( getImageType( image ), getImageCreateFlags( image ), layerCount ) , format - , { aspect, baseMipLevel, levelCount, baseArrayLayer, layerCount } }; + , { getAspectMask( format ), baseMipLevel, levelCount, baseArrayLayer, layerCount } }; } crg::GraphContext & getDummyContext() diff --git a/test/TestAttachment.cpp b/test/TestAttachment.cpp index b900be0..c5f969e 100644 --- a/test/TestAttachment.cpp +++ b/test/TestAttachment.cpp @@ -33,10 +33,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Spl" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == 1u ) check( attachment.getSamplerDesc() == defaultSamplerDesc ) @@ -50,8 +50,8 @@ namespace testBegin( "testImplicitColourAttachment" ) crg::ResourceHandler handler; crg::FrameGraph graph{ handler, testCounts.testName }; - auto image = graph.createImage( crg::ImageData{ "Test", 0u, crg::ImageType::e3D, crg::PixelFormat::eR32G32B32A32_SFLOAT, { 1024, 1024, 1024 }, VK_IMAGE_USAGE_SAMPLED_BIT, 1u, 1u } ); - auto range = crg::getVirtualRange( image, crg::ImageViewType::e3D, { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } ); + auto image = graph.createImage( crg::ImageData{ "Test", crg::ImageCreateFlags::eNone, crg::ImageType::e3D, crg::PixelFormat::eR32G32B32A32_SFLOAT, { 1024, 1024, 1024 }, crg::ImageUsageFlags::eSampled, 1u, 1u } ); + auto range = crg::getVirtualRange( image, crg::ImageViewType::e3D, { crg::ImageAspectFlags::eColor, 0u, 1u, 0u, 1u } ); check( range.baseArrayLayer == 0 ) auto view = graph.createView( test::createView( "Test", image ) ); crg::FramePass & pass = graph.createPass( "test", crg::RunnablePassCreator{} ); @@ -70,10 +70,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Impl" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getSamplerDesc() == defaultSamplerDesc ) @@ -106,10 +106,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Impl" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getSamplerDesc() == defaultSamplerDesc ) @@ -143,10 +143,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Impl" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getSamplerDesc() == defaultSamplerDesc ) @@ -178,10 +178,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IStr" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == 1u ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eGeneral ) @@ -212,10 +212,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/OStr" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == 1u ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eGeneral ) @@ -246,10 +246,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/COStr" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == 1u ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eGeneral ) @@ -280,10 +280,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOStr" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == 1u ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eGeneral ) @@ -314,10 +314,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/It" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eTransferSrc ) @@ -348,10 +348,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Ot" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eTransferDst ) @@ -382,10 +382,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOt" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.binding == crg::InvalidBindingId ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eTransferDst ) @@ -421,10 +421,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Ic" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eColorAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eColorAttachment ) @@ -459,10 +459,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Oc" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eClear ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eColorAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eColorAttachment ) @@ -497,10 +497,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOc" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eColorAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eColorAttachment ) @@ -535,10 +535,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Id" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilReadOnly ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthReadOnly ) @@ -573,10 +573,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Od" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eClear ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthAttachment ) @@ -611,10 +611,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOd" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthAttachment ) check( attachment.view() == view ) @@ -649,10 +649,10 @@ namespace check( attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Ids" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilReadOnly ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthStencilReadOnly ) @@ -687,10 +687,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Ods" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eClear ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eClear ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eStore ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthStencilAttachment ) @@ -725,10 +725,10 @@ namespace check( attachment.imageAttach.isStencilInputAttach() ) check( attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOds" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eStore ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eDepthStencilAttachment ) @@ -763,10 +763,10 @@ namespace check( attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Is" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eDontCare ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilReadOnly ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eStencilReadOnly ) @@ -801,10 +801,10 @@ namespace check( !attachment.imageAttach.isStencilInputAttach() ) check( attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/Os" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eClear ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eStore ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eStencilAttachment ) @@ -839,10 +839,10 @@ namespace check( attachment.imageAttach.isStencilInputAttach() ) check( attachment.imageAttach.isStencilOutputAttach() ) check( attachment.name == pass.getGroupName() + "/" + view.data->name + "/IOs" ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eDontCare ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eDontCare ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eStore ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eDepthStencilAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eStencilAttachment ) @@ -873,10 +873,10 @@ namespace check( !attachment.imageAttach.isStencilAttach() ) check( !attachment.imageAttach.isStencilInputAttach() ) check( !attachment.imageAttach.isStencilOutputAttach() ) - check( attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) - check( attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_LOAD ) - check( attachment.getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE ) + check( attachment.getLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStoreOp() == crg::AttachmentStoreOp::eStore ) + check( attachment.getStencilLoadOp() == crg::AttachmentLoadOp::eLoad ) + check( attachment.getStencilStoreOp() == crg::AttachmentStoreOp::eStore ) check( attachment.view() == view ) check( attachment.getImageLayout( false ) == crg::ImageLayout::eColorAttachment ) check( attachment.getImageLayout( true ) == crg::ImageLayout::eColorAttachment ) diff --git a/test/TestBases.cpp b/test/TestBases.cpp index 21c30db..d5cc721 100644 --- a/test/TestBases.cpp +++ b/test/TestBases.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,8 @@ namespace getMipExtent( view ); auto type = getImageType( image ); check( getImageType( view ) == type ) - check( getImageViewType( view ) == crg::convert( view.data->info.viewType ) ) + check( getImageViewType( view ) == view.data->info.viewType ) + check( getImageCreateFlags( view ) == getImageCreateFlags( image ) ) check( getMipLevels( image ) == 8u ) check( getMipLevels( view ) == 2u ) check( getArrayLayers( image ) == 6u ) @@ -91,6 +93,77 @@ namespace testEnd() } + void testClearValues( test::TestCounts & testCounts ) + { + testBegin( "testClearValues" ) + crg::ClearColorValue clearColorInt32{ std::array< int32_t, 4u >{ 1, 2, 3, 4 } }; + crg::ClearColorValue clearColorUInt32{ std::array< uint32_t, 4u >{ 1u, 2u, 3u, 4u } }; + crg::ClearColorValue clearColorFloat32{ std::array< float, 4u >{ 1.0f, 2.0f, 3.0f, 4.0f } }; + crg::ClearDepthStencilValue clearDepthStencil{ 1.0f, 255u }; + + checkNoThrow( getClearDepthStencilValue( crg::ClearValue{ clearColorFloat32 } ) ); + checkNoThrow( getClearColorValue( crg::ClearValue{ clearDepthStencil } ) ); + checkNoThrow( getClearColorValue( crg::ClearValue{ clearColorFloat32 } ) ); + checkNoThrow( getClearDepthStencilValue( crg::ClearValue{ clearDepthStencil } ) ); + checkNoThrow( convert( crg::ClearValue{ clearColorFloat32 } ) ); + checkNoThrow( convert( crg::ClearValue{ clearDepthStencil } ) ); + check( clearColorFloat32.isFloat32() ); + check( !clearColorFloat32.isInt32() ); + check( !clearColorFloat32.isUInt32() ); + check( !clearColorUInt32.isFloat32() ); + check( !clearColorUInt32.isInt32() ); + check( clearColorUInt32.isUInt32() ); + check( !clearColorInt32.isFloat32() ); + check( clearColorInt32.isInt32() ); + check( !clearColorInt32.isUInt32() ); + check( crg::ClearValue{ clearColorFloat32 }.isColor() ); + check( !crg::ClearValue{ clearColorFloat32 }.isDepthStencil() ); + check( !crg::ClearValue{ clearDepthStencil }.isColor() ); + check( crg::ClearValue{ clearDepthStencil }.isDepthStencil() ); + { + auto vkClearColorFloat32 = crg::convert( clearColorFloat32 ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorFloat32.float32[i] == clearColorFloat32.float32()[i] ); + } + { + auto vkClearColorFloat32 = crg::convert( crg::ClearValue{ clearColorFloat32 } ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorFloat32.color.float32[i] == clearColorFloat32.float32()[i] ); + } + { + auto vkClearColorInt32 = crg::convert( clearColorInt32 ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorInt32.int32[i] == clearColorInt32.int32()[i] ); + } + { + auto vkClearColorInt32 = crg::convert( crg::ClearValue{ clearColorInt32 } ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorInt32.color.int32[i] == clearColorInt32.int32()[i] ); + } + { + auto vkClearColorUInt32 = crg::convert( clearColorUInt32 ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorUInt32.uint32[i] == clearColorUInt32.uint32()[i] ); + } + { + auto vkClearColorUInt32 = crg::convert( crg::ClearValue{ clearColorUInt32 } ); + for ( uint32_t i = 0; i < 4u; ++i ) + check( vkClearColorUInt32.color.uint32[i] == clearColorUInt32.uint32()[i] ); + } + { + auto vkClearDepthStencil = crg::convert( clearDepthStencil ); + check( vkClearDepthStencil.depth == clearDepthStencil.depth ); + check( vkClearDepthStencil.stencil == clearDepthStencil.stencil ); + } + { + auto vkClearDepthStencil = crg::convert( crg::ClearValue{ clearDepthStencil } ); + check( vkClearDepthStencil.depthStencil.depth == clearDepthStencil.depth ); + check( vkClearDepthStencil.depthStencil.stencil == clearDepthStencil.stencil ); + } + + testEnd() + } + void testSignal( test::TestCounts & testCounts ) { testBegin( "testSignal" ) @@ -268,7 +341,7 @@ namespace auto depthIt = framePass.images.begin(); auto colourIt = std::next( depthIt ); auto extent3D = getExtent( colour2v ); - auto extent2D = VkExtent2D{ extent3D.width, extent3D.height }; + auto extent2D = crg::Extent2D{ extent3D.width, extent3D.height }; return createDummy( testCounts , framePass, context, runGraph, crg::PipelineStageFlags::eFragmentShader , test::checkDummy @@ -276,10 +349,10 @@ namespace , false , crg::ru::Config{} .implicitAction( depthIt->view(), crg::RecordContext::clearAttachment( *depthIt, crg::ImageLayout::eDepthStencilAttachment ) ) - .implicitAction( depth2v, crg::RecordContext::clearAttachment( depth2v, {}, crg::ImageLayout::eDepthStencilAttachment ) ) + .implicitAction( depth2v, crg::RecordContext::clearAttachment( depth2v, crg::ClearDepthStencilValue{}, crg::ImageLayout::eDepthStencilAttachment ) ) .implicitAction( colourIt->view(), crg::RecordContext::clearAttachment( *colourIt ) ) - .implicitAction( colour4v, crg::RecordContext::clearAttachment( colour4v, {} ) ) - .implicitAction( colour2v, crg::RecordContext::blitImage( colour1v, colour2v, {}, extent2D, {}, extent2D, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) + .implicitAction( colour4v, crg::RecordContext::clearAttachment( colour4v, crg::ClearColorValue{}, crg::ImageLayout::eShaderReadOnly ) ) + .implicitAction( colour2v, crg::RecordContext::blitImage( colour1v, colour2v, { {}, extent2D }, { {}, extent2D }, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) .implicitAction( colour3v, crg::RecordContext::copyImage( colour2v, colour3v, extent2D, crg::ImageLayout::eShaderReadOnly ) ) ); } ); testPass1.addOutputDepthStencilView( depth1v ); @@ -337,16 +410,16 @@ namespace auto depthIt = framePass.images.begin(); auto colourIt = std::next( depthIt ); auto extent3D = getExtent( colour2v ); - auto extent2D = VkExtent2D{ extent3D.width, extent3D.height }; + auto extent2D = crg::Extent2D{ extent3D.width, extent3D.height }; return createDummy( testCounts , framePass, context, runGraph, crg::PipelineStageFlags::eFragmentShader , test::checkDummy , crg::ru::Config{} .prePassAction( crg::RecordContext::clearAttachment( *depthIt, crg::ImageLayout::eDepthStencilAttachment ) ) - .prePassAction( crg::RecordContext::clearAttachment( depth2v, {}, crg::ImageLayout::eDepthStencilAttachment ) ) + .prePassAction( crg::RecordContext::clearAttachment( depth2v, crg::ClearDepthStencilValue{}, crg::ImageLayout::eDepthStencilAttachment ) ) .prePassAction( crg::RecordContext::clearAttachment( *colourIt ) ) - .prePassAction( crg::RecordContext::clearAttachment( colour4v, {} ) ) - .prePassAction( crg::RecordContext::blitImage( colour1v, colour2v, {}, extent2D, {}, extent2D, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) + .prePassAction( crg::RecordContext::clearAttachment( colour4v, crg::ClearColorValue{} ) ) + .prePassAction( crg::RecordContext::blitImage( colour1v, colour2v, { {}, extent2D }, { {}, extent2D }, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) .prePassAction( crg::RecordContext::copyImage( colour2v, colour3v, extent2D, crg::ImageLayout::eShaderReadOnly ) ) ); } ); testPass1.addOutputDepthStencilView( depth1v ); @@ -396,7 +469,7 @@ namespace auto colour3v = graph.createView( test::createView( "colour3v", colour3, crg::PixelFormat::eR16G16B16A16_SFLOAT, 0u, 1u, 0u, 1u ) ); auto colour4 = graph.createImage( test::createImage( "colour4", crg::PixelFormat::eR16G16B16A16_SFLOAT ) ); auto colour4v = graph.createView( test::createView( "colour4v", colour4, crg::PixelFormat::eR16G16B16A16_SFLOAT, 0u, 1u, 0u, 1u ) ); - crg::RunnablePass * runPass{}; + crg::RunnablePass const * runPass{}; auto & testPass1 = graph.createPass( "Mesh" , [&runPass , &testCounts, depth2v, colour1v, colour2v, colour3v, colour4v]( crg::FramePass const & framePass , crg::GraphContext & context @@ -405,16 +478,16 @@ namespace auto depthIt = framePass.images.begin(); auto colourIt = std::next( depthIt ); auto extent3D = getExtent( colour2v ); - auto extent2D = VkExtent2D{ extent3D.width, extent3D.height }; + auto extent2D = crg::Extent2D{ extent3D.width, extent3D.height }; auto res = createDummy( testCounts , framePass, context, runGraph, crg::PipelineStageFlags::eFragmentShader , test::checkDummy , crg::ru::Config{ 1u, true } .postPassAction( crg::RecordContext::clearAttachment( *depthIt, crg::ImageLayout::eDepthStencilAttachment ) ) - .postPassAction( crg::RecordContext::clearAttachment( depth2v, {}, crg::ImageLayout::eDepthStencilAttachment ) ) + .postPassAction( crg::RecordContext::clearAttachment( depth2v, crg::ClearDepthStencilValue{}, crg::ImageLayout::eDepthStencilAttachment ) ) .postPassAction( crg::RecordContext::clearAttachment( *colourIt ) ) - .postPassAction( crg::RecordContext::clearAttachment( colour4v, {} ) ) - .postPassAction( crg::RecordContext::blitImage( colour1v, colour2v, {}, extent2D, {}, extent2D, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) + .postPassAction( crg::RecordContext::clearAttachment( colour4v, crg::ClearColorValue{} ) ) + .postPassAction( crg::RecordContext::blitImage( colour1v, colour2v, { {}, extent2D }, { {}, extent2D }, crg::FilterMode::eLinear, crg::ImageLayout::eShaderReadOnly ) ) .postPassAction( crg::RecordContext::copyImage( colour2v, colour3v, extent2D, crg::ImageLayout::eShaderReadOnly ) ) ); runPass = res.get(); return res; @@ -716,6 +789,7 @@ int main( int argc, char ** argv ) { testSuiteBegin( "TestBases" ) testBaseFuncs( testCounts ); + testClearValues( testCounts ); testSignal( testCounts ); testFence( testCounts ); testFramePassTimer( testCounts ); diff --git a/test/TestRenderGraph.cpp b/test/TestRenderGraph.cpp index 12f341c..b526edb 100644 --- a/test/TestRenderGraph.cpp +++ b/test/TestRenderGraph.cpp @@ -31,7 +31,7 @@ namespace auto resolved = crg::resolveView( view, index ); check( context.getNextLayoutState( resolved ).layout == crg::ImageLayout::eShaderReadOnly ) check( context.getNextLayoutState( resolved.data->image - , crg::convert( resolved.data->info.viewType ) + , resolved.data->info.viewType , resolved.data->info.subresourceRange ).layout == crg::ImageLayout::eShaderReadOnly ) } } @@ -66,7 +66,8 @@ namespace { testBegin( "testNoPass" ) crg::ResourceHandler handler; - auto graph = buildNoPassGraph( testCounts, handler ); + auto graph1 = buildNoPassGraph( testCounts, handler ); + crg::FrameGraph graph{ std::move( graph1 ) }; auto rt = graph.createImage( test::createImage( "rt", crg::PixelFormat::eR32G32B32A32_SFLOAT ) ); auto rtv = graph.createView( test::createView( "rtv", rt ) ); diff --git a/test/TestRenderPass.cpp b/test/TestRenderPass.cpp index e430d37..4ba5ff9 100644 --- a/test/TestRenderPass.cpp +++ b/test/TestRenderPass.cpp @@ -12,19 +12,13 @@ namespace void testLog( test::TestCounts & testCounts ) { testBegin( "testLog" ) - auto callback = []( std::string const & msg, bool newLine ) - { - std::cout << msg << "Callback"; - - if ( newLine ) - { - std::cout << "\n"; - } - else + auto callback = []( std::string_view msg, bool newLine )noexcept { - std::cout << " "; - } - }; + if ( newLine ) + printf( "%s Callback\n", msg.data() ); + else + printf( "%s Callback ", msg.data() ); + }; crg::Logger::setTraceCallback( callback ); crg::Logger::setDebugCallback( callback ); diff --git a/test/TestRunnablePass.cpp b/test/TestRunnablePass.cpp index 47a3363..84a7edd 100644 --- a/test/TestRunnablePass.cpp +++ b/test/TestRunnablePass.cpp @@ -77,7 +77,7 @@ namespace , crg::RunnableGraph & runGraph ) { return std::make_unique< crg::BufferToImageCopy >( pass, context, runGraph - , VkOffset3D{}, VkExtent3D{ 1024, 1024, 1u } ); + , crg::Offset3D{}, crg::Extent3D{ 1024, 1024, 1u } ); } ); testPass.addTransferInputBuffer( crg::Buffer{ VkBuffer( 1 ), "inBuffer" }, 0u, 1024u ); testPass.addTransferOutputView( resultv ); @@ -123,8 +123,8 @@ namespace , crg::RunnableGraph & runGraph ) { return std::make_unique< crg::ImageBlit >( pass, context, runGraph - , VkOffset3D{}, getExtent( inputv ) - , VkOffset3D{}, getExtent( resultv ) + , crg::Offset3D{}, getExtent( inputv ) + , crg::Offset3D{}, getExtent( resultv ) , crg::FilterMode::eLinear ); } ); testPass.addTransferInputView( inputv ); @@ -221,7 +221,7 @@ namespace , crg::RunnableGraph & runGraph ) { return std::make_unique< crg::ImageToBufferCopy >( pass, context, runGraph - , VkOffset3D{}, getExtent( inputv ) ); + , crg::Offset3D{}, getExtent( inputv ) ); } ); testPass.addTransferInputView( inputv ); testPass.addTransferOutputBuffer( crg::Buffer{ VkBuffer( 1 ), "outBuffer" }, 0u, 1024u ); @@ -453,7 +453,7 @@ namespace auto resultv = graph.createView( test::createView( "resultv", result, crg::PixelFormat::eR16G16B16A16_SFLOAT, 0u, 1u, 0u, 1u ) ); auto depth = graph.createImage( test::createImage( "depth", crg::PixelFormat::eD32_SFLOAT ) ); auto depthv = graph.createView( test::createView( "depthv", depth, crg::PixelFormat::eD32_SFLOAT, 0u, 1u, 0u, 1u ) ); - VkExtent2D extent{ getExtent( resultv ).width, getExtent( resultv ).height }; + crg::Extent2D extent{ getExtent( resultv ).width, getExtent( resultv ).height }; auto & testPass = graph.createPass( "Pass" , [&passIndex, extent]( crg::FramePass const & pass , crg::GraphContext & context