From 952667d3c06e1581d9d68e4507084d0b6c3bfb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Wed, 26 Oct 2016 10:49:58 +0200 Subject: [PATCH 1/3] Add operator~() on Flags<> and FlagBits (#44) * Add operator~() on Flags<> and FlagBits --- VulkanHppGenerator.cpp | 43 +++- vulkan/vulkan.hpp | 480 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 520 insertions(+), 3 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 9ca0c9d..5652d8d 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -62,6 +62,11 @@ const std::string exceptionHeader( ); const std::string flagsHeader( +" template struct FlagTraits\n" +" {\n" +" enum { allFlags = 0 };\n" +" };\n" +"\n" " template \n" " class Flags\n" " {\n" @@ -131,6 +136,13 @@ const std::string flagsHeader( " return !m_mask;\n" " }\n" "\n" +" Flags operator~() const\n" +" {\n" +" Flags result(*this);\n" +" result.m_mask ^= FlagTraits::allFlags;\n" +" return result;\n" +" }\n" +"\n" " bool operator==(Flags const& rhs) const\n" " {\n" " return m_mask == rhs.m_mask;\n" @@ -602,7 +614,7 @@ void writeTypeCommand(std::ofstream & ofs, VkData const& vkData, DependencyData void writeTypeCommandEnhanced(std::ofstream & ofs, VkData const& vkData, std::string const& indentation, std::string const& className, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData); void writeTypeCommandStandard(std::ofstream & ofs, std::string const& indentation, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData, std::set const& vkTypes); void writeTypeEnum(std::ofstream & ofs, DependencyData const& dependencyData, EnumData const& enumData); -void writeTypeFlags( std::ofstream & ofs, DependencyData const& dependencyData, FlagData const& flagData ); +void writeTypeFlags(std::ofstream & ofs, DependencyData const& dependencyData, FlagData const& flagData, std::map::const_iterator enumData); void writeTypeHandle(std::ofstream & ofs, VkData const& vkData, DependencyData const& dependencyData, HandleData const& handle, std::list const& dependencies); void writeTypeScalar( std::ofstream & ofs, DependencyData const& dependencyData ); void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData const& dependencyData, std::map const& defaultValues ); @@ -2650,7 +2662,7 @@ void writeEnumsToString(std::ofstream & ofs, VkData const& vkData) } } -void writeTypeFlags( std::ofstream & ofs, DependencyData const& dependencyData, FlagData const& flagData ) +void writeTypeFlags(std::ofstream & ofs, DependencyData const& dependencyData, FlagData const& flagData, std::map::const_iterator enumData) { assert( dependencyData.dependencies.size() == 1 ); enterProtect(ofs, flagData.protect); @@ -2660,6 +2672,31 @@ void writeTypeFlags( std::ofstream & ofs, DependencyData const& dependencyData, << " {" << std::endl << " return " << dependencyData.name << "( bit0 ) | bit1;" << std::endl << " }" << std::endl; + if (!enumData->second.members.empty()) + { + ofs << std::endl + << " VULKAN_HPP_INLINE " << dependencyData.name << " operator~( " << *dependencyData.dependencies.begin() << " bits )" << std::endl + << " {" << std::endl + << " return ~( " << dependencyData.name << "( bits ) );" << std::endl + << " }" << std::endl + << std::endl + << " template <> struct FlagTraits<" << *dependencyData.dependencies.begin() << ">" << std::endl + << " {" << std::endl + << " enum" << std::endl + << " {" << std::endl + << " allFlags = "; + for (size_t i = 0; i < enumData->second.members.size(); i++) + { + if (i != 0) + { + ofs << " | "; + } + ofs << "VkFlags(" << *dependencyData.dependencies.begin() << "::" << enumData->second.members[i].name << ")"; + } + ofs << std::endl + << " };" << std::endl + << " };" << std::endl; + } leaveProtect(ofs, flagData.protect); ofs << std::endl; } @@ -3007,7 +3044,7 @@ void writeTypes(std::ofstream & ofs, VkData const& vkData, std::mapname) != vkData.flags.end()); - writeTypeFlags( ofs, *it, vkData.flags.find( it->name)->second ); + writeTypeFlags( ofs, *it, vkData.flags.find( it->name)->second, vkData.enums.find(generateEnumNameForFlags(it->name)) ); break; case DependencyData::Category::FUNC_POINTER : case DependencyData::Category::REQUIRED : diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index dc94858..dcb0b61 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -85,6 +85,11 @@ static_assert( VK_HEADER_VERSION == 32 , "Wrong VK_HEADER_VERSION!" ); namespace vk { + template struct FlagTraits + { + enum { allFlags = 0 }; + }; + template class Flags { @@ -154,6 +159,13 @@ namespace vk return !m_mask; } + Flags operator~() const + { + Flags result(*this); + result.m_mask ^= FlagTraits::allFlags; + return result; + } + bool operator==(Flags const& rhs) const { return m_mask == rhs.m_mask; @@ -4783,6 +4795,19 @@ namespace vk return CullModeFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE CullModeFlags operator~( CullModeFlagBits bits ) + { + return ~( CullModeFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CullModeFlagBits::eNone) | VkFlags(CullModeFlagBits::eFront) | VkFlags(CullModeFlagBits::eBack) | VkFlags(CullModeFlagBits::eFrontAndBack) + }; + }; + enum class FrontFace { eCounterClockwise = VK_FRONT_FACE_COUNTER_CLOCKWISE, @@ -9183,6 +9208,19 @@ namespace vk return QueueFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE QueueFlags operator~( QueueFlagBits bits ) + { + return ~( QueueFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(QueueFlagBits::eGraphics) | VkFlags(QueueFlagBits::eCompute) | VkFlags(QueueFlagBits::eTransfer) | VkFlags(QueueFlagBits::eSparseBinding) + }; + }; + struct QueueFamilyProperties { operator const VkQueueFamilyProperties&() const @@ -9226,6 +9264,19 @@ namespace vk return MemoryPropertyFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE MemoryPropertyFlags operator~( MemoryPropertyFlagBits bits ) + { + return ~( MemoryPropertyFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(MemoryPropertyFlagBits::eDeviceLocal) | VkFlags(MemoryPropertyFlagBits::eHostVisible) | VkFlags(MemoryPropertyFlagBits::eHostCoherent) | VkFlags(MemoryPropertyFlagBits::eHostCached) | VkFlags(MemoryPropertyFlagBits::eLazilyAllocated) + }; + }; + struct MemoryType { operator const VkMemoryType&() const @@ -9261,6 +9312,19 @@ namespace vk return MemoryHeapFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE MemoryHeapFlags operator~( MemoryHeapFlagBits bits ) + { + return ~( MemoryHeapFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(MemoryHeapFlagBits::eDeviceLocal) + }; + }; + struct MemoryHeap { operator const VkMemoryHeap&() const @@ -9339,6 +9403,19 @@ namespace vk return AccessFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE AccessFlags operator~( AccessFlagBits bits ) + { + return ~( AccessFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(AccessFlagBits::eIndirectCommandRead) | VkFlags(AccessFlagBits::eIndexRead) | VkFlags(AccessFlagBits::eVertexAttributeRead) | VkFlags(AccessFlagBits::eUniformRead) | VkFlags(AccessFlagBits::eInputAttachmentRead) | VkFlags(AccessFlagBits::eShaderRead) | VkFlags(AccessFlagBits::eShaderWrite) | VkFlags(AccessFlagBits::eColorAttachmentRead) | VkFlags(AccessFlagBits::eColorAttachmentWrite) | VkFlags(AccessFlagBits::eDepthStencilAttachmentRead) | VkFlags(AccessFlagBits::eDepthStencilAttachmentWrite) | VkFlags(AccessFlagBits::eTransferRead) | VkFlags(AccessFlagBits::eTransferWrite) | VkFlags(AccessFlagBits::eHostRead) | VkFlags(AccessFlagBits::eHostWrite) | VkFlags(AccessFlagBits::eMemoryRead) | VkFlags(AccessFlagBits::eMemoryWrite) + }; + }; + struct MemoryBarrier { MemoryBarrier( AccessFlags srcAccessMask_ = AccessFlags(), AccessFlags dstAccessMask_ = AccessFlags() ) @@ -9550,6 +9627,19 @@ namespace vk return BufferUsageFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE BufferUsageFlags operator~( BufferUsageFlagBits bits ) + { + return ~( BufferUsageFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(BufferUsageFlagBits::eTransferSrc) | VkFlags(BufferUsageFlagBits::eTransferDst) | VkFlags(BufferUsageFlagBits::eUniformTexelBuffer) | VkFlags(BufferUsageFlagBits::eStorageTexelBuffer) | VkFlags(BufferUsageFlagBits::eUniformBuffer) | VkFlags(BufferUsageFlagBits::eStorageBuffer) | VkFlags(BufferUsageFlagBits::eIndexBuffer) | VkFlags(BufferUsageFlagBits::eVertexBuffer) | VkFlags(BufferUsageFlagBits::eIndirectBuffer) + }; + }; + enum class BufferCreateFlagBits { eSparseBinding = VK_BUFFER_CREATE_SPARSE_BINDING_BIT, @@ -9564,6 +9654,19 @@ namespace vk return BufferCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE BufferCreateFlags operator~( BufferCreateFlagBits bits ) + { + return ~( BufferCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(BufferCreateFlagBits::eSparseBinding) | VkFlags(BufferCreateFlagBits::eSparseResidency) | VkFlags(BufferCreateFlagBits::eSparseAliased) + }; + }; + struct BufferCreateInfo { BufferCreateInfo( BufferCreateFlags flags_ = BufferCreateFlags(), DeviceSize size_ = 0, BufferUsageFlags usage_ = BufferUsageFlags(), SharingMode sharingMode_ = SharingMode::eExclusive, uint32_t queueFamilyIndexCount_ = 0, const uint32_t* pQueueFamilyIndices_ = nullptr ) @@ -9692,6 +9795,19 @@ namespace vk return ShaderStageFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE ShaderStageFlags operator~( ShaderStageFlagBits bits ) + { + return ~( ShaderStageFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ShaderStageFlagBits::eVertex) | VkFlags(ShaderStageFlagBits::eTessellationControl) | VkFlags(ShaderStageFlagBits::eTessellationEvaluation) | VkFlags(ShaderStageFlagBits::eGeometry) | VkFlags(ShaderStageFlagBits::eFragment) | VkFlags(ShaderStageFlagBits::eCompute) | VkFlags(ShaderStageFlagBits::eAllGraphics) | VkFlags(ShaderStageFlagBits::eAll) + }; + }; + struct DescriptorSetLayoutBinding { DescriptorSetLayoutBinding( uint32_t binding_ = 0, DescriptorType descriptorType_ = DescriptorType::eSampler, uint32_t descriptorCount_ = 0, ShaderStageFlags stageFlags_ = ShaderStageFlags(), const Sampler* pImmutableSamplers_ = nullptr ) @@ -10133,6 +10249,19 @@ namespace vk return ImageUsageFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE ImageUsageFlags operator~( ImageUsageFlagBits bits ) + { + return ~( ImageUsageFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ImageUsageFlagBits::eTransferSrc) | VkFlags(ImageUsageFlagBits::eTransferDst) | VkFlags(ImageUsageFlagBits::eSampled) | VkFlags(ImageUsageFlagBits::eStorage) | VkFlags(ImageUsageFlagBits::eColorAttachment) | VkFlags(ImageUsageFlagBits::eDepthStencilAttachment) | VkFlags(ImageUsageFlagBits::eTransientAttachment) | VkFlags(ImageUsageFlagBits::eInputAttachment) + }; + }; + enum class ImageCreateFlagBits { eSparseBinding = VK_IMAGE_CREATE_SPARSE_BINDING_BIT, @@ -10149,6 +10278,19 @@ namespace vk return ImageCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE ImageCreateFlags operator~( ImageCreateFlagBits bits ) + { + return ~( ImageCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ImageCreateFlagBits::eSparseBinding) | VkFlags(ImageCreateFlagBits::eSparseResidency) | VkFlags(ImageCreateFlagBits::eSparseAliased) | VkFlags(ImageCreateFlagBits::eMutableFormat) | VkFlags(ImageCreateFlagBits::eCubeCompatible) + }; + }; + enum class PipelineCreateFlagBits { eDisableOptimization = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, @@ -10163,6 +10305,19 @@ namespace vk return PipelineCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE PipelineCreateFlags operator~( PipelineCreateFlagBits bits ) + { + return ~( PipelineCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(PipelineCreateFlagBits::eDisableOptimization) | VkFlags(PipelineCreateFlagBits::eAllowDerivatives) | VkFlags(PipelineCreateFlagBits::eDerivative) + }; + }; + struct ComputePipelineCreateInfo { ComputePipelineCreateInfo( PipelineCreateFlags flags_ = PipelineCreateFlags(), PipelineShaderStageCreateInfo stage_ = PipelineShaderStageCreateInfo(), PipelineLayout layout_ = PipelineLayout(), Pipeline basePipelineHandle_ = Pipeline(), int32_t basePipelineIndex_ = 0 ) @@ -10278,6 +10433,19 @@ namespace vk return ColorComponentFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE ColorComponentFlags operator~( ColorComponentFlagBits bits ) + { + return ~( ColorComponentFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ColorComponentFlagBits::eR) | VkFlags(ColorComponentFlagBits::eG) | VkFlags(ColorComponentFlagBits::eB) | VkFlags(ColorComponentFlagBits::eA) + }; + }; + struct PipelineColorBlendAttachmentState { PipelineColorBlendAttachmentState( Bool32 blendEnable_ = 0, BlendFactor srcColorBlendFactor_ = BlendFactor::eZero, BlendFactor dstColorBlendFactor_ = BlendFactor::eZero, BlendOp colorBlendOp_ = BlendOp::eAdd, BlendFactor srcAlphaBlendFactor_ = BlendFactor::eZero, BlendFactor dstAlphaBlendFactor_ = BlendFactor::eZero, BlendOp alphaBlendOp_ = BlendOp::eAdd, ColorComponentFlags colorWriteMask_ = ColorComponentFlags() ) @@ -10505,6 +10673,19 @@ namespace vk return FenceCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE FenceCreateFlags operator~( FenceCreateFlagBits bits ) + { + return ~( FenceCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(FenceCreateFlagBits::eSignaled) + }; + }; + struct FenceCreateInfo { FenceCreateInfo( FenceCreateFlags flags_ = FenceCreateFlags() ) @@ -10594,6 +10775,19 @@ namespace vk return FormatFeatureFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE FormatFeatureFlags operator~( FormatFeatureFlagBits bits ) + { + return ~( FormatFeatureFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(FormatFeatureFlagBits::eSampledImage) | VkFlags(FormatFeatureFlagBits::eStorageImage) | VkFlags(FormatFeatureFlagBits::eStorageImageAtomic) | VkFlags(FormatFeatureFlagBits::eUniformTexelBuffer) | VkFlags(FormatFeatureFlagBits::eStorageTexelBuffer) | VkFlags(FormatFeatureFlagBits::eStorageTexelBufferAtomic) | VkFlags(FormatFeatureFlagBits::eVertexBuffer) | VkFlags(FormatFeatureFlagBits::eColorAttachment) | VkFlags(FormatFeatureFlagBits::eColorAttachmentBlend) | VkFlags(FormatFeatureFlagBits::eDepthStencilAttachment) | VkFlags(FormatFeatureFlagBits::eBlitSrc) | VkFlags(FormatFeatureFlagBits::eBlitDst) | VkFlags(FormatFeatureFlagBits::eSampledImageFilterLinear) | VkFlags(FormatFeatureFlagBits::eSampledImageFilterCubicIMG) + }; + }; + struct FormatProperties { operator const VkFormatProperties&() const @@ -10631,6 +10825,19 @@ namespace vk return QueryControlFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE QueryControlFlags operator~( QueryControlFlagBits bits ) + { + return ~( QueryControlFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(QueryControlFlagBits::ePrecise) + }; + }; + enum class QueryResultFlagBits { e64 = VK_QUERY_RESULT_64_BIT, @@ -10646,6 +10853,19 @@ namespace vk return QueryResultFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE QueryResultFlags operator~( QueryResultFlagBits bits ) + { + return ~( QueryResultFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(QueryResultFlagBits::e64) | VkFlags(QueryResultFlagBits::eWait) | VkFlags(QueryResultFlagBits::eWithAvailability) | VkFlags(QueryResultFlagBits::ePartial) + }; + }; + enum class CommandBufferUsageFlagBits { eOneTimeSubmit = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, @@ -10660,6 +10880,19 @@ namespace vk return CommandBufferUsageFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE CommandBufferUsageFlags operator~( CommandBufferUsageFlagBits bits ) + { + return ~( CommandBufferUsageFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CommandBufferUsageFlagBits::eOneTimeSubmit) | VkFlags(CommandBufferUsageFlagBits::eRenderPassContinue) | VkFlags(CommandBufferUsageFlagBits::eSimultaneousUse) + }; + }; + enum class QueryPipelineStatisticFlagBits { eInputAssemblyVertices = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, @@ -10682,6 +10915,19 @@ namespace vk return QueryPipelineStatisticFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE QueryPipelineStatisticFlags operator~( QueryPipelineStatisticFlagBits bits ) + { + return ~( QueryPipelineStatisticFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(QueryPipelineStatisticFlagBits::eInputAssemblyVertices) | VkFlags(QueryPipelineStatisticFlagBits::eInputAssemblyPrimitives) | VkFlags(QueryPipelineStatisticFlagBits::eVertexShaderInvocations) | VkFlags(QueryPipelineStatisticFlagBits::eGeometryShaderInvocations) | VkFlags(QueryPipelineStatisticFlagBits::eGeometryShaderPrimitives) | VkFlags(QueryPipelineStatisticFlagBits::eClippingInvocations) | VkFlags(QueryPipelineStatisticFlagBits::eClippingPrimitives) | VkFlags(QueryPipelineStatisticFlagBits::eFragmentShaderInvocations) | VkFlags(QueryPipelineStatisticFlagBits::eTessellationControlShaderPatches) | VkFlags(QueryPipelineStatisticFlagBits::eTessellationEvaluationShaderInvocations) | VkFlags(QueryPipelineStatisticFlagBits::eComputeShaderInvocations) + }; + }; + struct CommandBufferInheritanceInfo { CommandBufferInheritanceInfo( RenderPass renderPass_ = RenderPass(), uint32_t subpass_ = 0, Framebuffer framebuffer_ = Framebuffer(), Bool32 occlusionQueryEnable_ = 0, QueryControlFlags queryFlags_ = QueryControlFlags(), QueryPipelineStatisticFlags pipelineStatistics_ = QueryPipelineStatisticFlags() ) @@ -10970,6 +11216,19 @@ namespace vk return ImageAspectFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE ImageAspectFlags operator~( ImageAspectFlagBits bits ) + { + return ~( ImageAspectFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ImageAspectFlagBits::eColor) | VkFlags(ImageAspectFlagBits::eDepth) | VkFlags(ImageAspectFlagBits::eStencil) | VkFlags(ImageAspectFlagBits::eMetadata) + }; + }; + struct ImageSubresource { ImageSubresource( ImageAspectFlags aspectMask_ = ImageAspectFlags(), uint32_t mipLevel_ = 0, uint32_t arrayLayer_ = 0 ) @@ -11795,6 +12054,19 @@ namespace vk return SparseImageFormatFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE SparseImageFormatFlags operator~( SparseImageFormatFlagBits bits ) + { + return ~( SparseImageFormatFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(SparseImageFormatFlagBits::eSingleMiptail) | VkFlags(SparseImageFormatFlagBits::eAlignedMipSize) | VkFlags(SparseImageFormatFlagBits::eNonstandardBlockSize) + }; + }; + struct SparseImageFormatProperties { operator const VkSparseImageFormatProperties&() const @@ -11861,6 +12133,19 @@ namespace vk return SparseMemoryBindFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE SparseMemoryBindFlags operator~( SparseMemoryBindFlagBits bits ) + { + return ~( SparseMemoryBindFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(SparseMemoryBindFlagBits::eMetadata) + }; + }; + struct SparseMemoryBind { SparseMemoryBind( DeviceSize resourceOffset_ = 0, DeviceSize size_ = 0, DeviceMemory memory_ = DeviceMemory(), DeviceSize memoryOffset_ = 0, SparseMemoryBindFlags flags_ = SparseMemoryBindFlags() ) @@ -12384,6 +12669,19 @@ namespace vk return PipelineStageFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE PipelineStageFlags operator~( PipelineStageFlagBits bits ) + { + return ~( PipelineStageFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(PipelineStageFlagBits::eTopOfPipe) | VkFlags(PipelineStageFlagBits::eDrawIndirect) | VkFlags(PipelineStageFlagBits::eVertexInput) | VkFlags(PipelineStageFlagBits::eVertexShader) | VkFlags(PipelineStageFlagBits::eTessellationControlShader) | VkFlags(PipelineStageFlagBits::eTessellationEvaluationShader) | VkFlags(PipelineStageFlagBits::eGeometryShader) | VkFlags(PipelineStageFlagBits::eFragmentShader) | VkFlags(PipelineStageFlagBits::eEarlyFragmentTests) | VkFlags(PipelineStageFlagBits::eLateFragmentTests) | VkFlags(PipelineStageFlagBits::eColorAttachmentOutput) | VkFlags(PipelineStageFlagBits::eComputeShader) | VkFlags(PipelineStageFlagBits::eTransfer) | VkFlags(PipelineStageFlagBits::eBottomOfPipe) | VkFlags(PipelineStageFlagBits::eHost) | VkFlags(PipelineStageFlagBits::eAllGraphics) | VkFlags(PipelineStageFlagBits::eAllCommands) + }; + }; + enum class CommandPoolCreateFlagBits { eTransient = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, @@ -12397,6 +12695,19 @@ namespace vk return CommandPoolCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE CommandPoolCreateFlags operator~( CommandPoolCreateFlagBits bits ) + { + return ~( CommandPoolCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CommandPoolCreateFlagBits::eTransient) | VkFlags(CommandPoolCreateFlagBits::eResetCommandBuffer) + }; + }; + struct CommandPoolCreateInfo { CommandPoolCreateInfo( CommandPoolCreateFlags flags_ = CommandPoolCreateFlags(), uint32_t queueFamilyIndex_ = 0 ) @@ -12482,6 +12793,19 @@ namespace vk return CommandPoolResetFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE CommandPoolResetFlags operator~( CommandPoolResetFlagBits bits ) + { + return ~( CommandPoolResetFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CommandPoolResetFlagBits::eReleaseResources) + }; + }; + enum class CommandBufferResetFlagBits { eReleaseResources = VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT @@ -12494,6 +12818,19 @@ namespace vk return CommandBufferResetFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE CommandBufferResetFlags operator~( CommandBufferResetFlagBits bits ) + { + return ~( CommandBufferResetFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CommandBufferResetFlagBits::eReleaseResources) + }; + }; + enum class SampleCountFlagBits { e1 = VK_SAMPLE_COUNT_1_BIT, @@ -12512,6 +12849,19 @@ namespace vk return SampleCountFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE SampleCountFlags operator~( SampleCountFlagBits bits ) + { + return ~( SampleCountFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(SampleCountFlagBits::e1) | VkFlags(SampleCountFlagBits::e2) | VkFlags(SampleCountFlagBits::e4) | VkFlags(SampleCountFlagBits::e8) | VkFlags(SampleCountFlagBits::e16) | VkFlags(SampleCountFlagBits::e32) | VkFlags(SampleCountFlagBits::e64) + }; + }; + struct ImageFormatProperties { operator const VkImageFormatProperties&() const @@ -13319,6 +13669,19 @@ namespace vk return AttachmentDescriptionFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE AttachmentDescriptionFlags operator~( AttachmentDescriptionFlagBits bits ) + { + return ~( AttachmentDescriptionFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(AttachmentDescriptionFlagBits::eMayAlias) + }; + }; + struct AttachmentDescription { AttachmentDescription( AttachmentDescriptionFlags flags_ = AttachmentDescriptionFlags(), Format format_ = Format::eUndefined, SampleCountFlagBits samples_ = SampleCountFlagBits::e1, AttachmentLoadOp loadOp_ = AttachmentLoadOp::eLoad, AttachmentStoreOp storeOp_ = AttachmentStoreOp::eStore, AttachmentLoadOp stencilLoadOp_ = AttachmentLoadOp::eLoad, AttachmentStoreOp stencilStoreOp_ = AttachmentStoreOp::eStore, ImageLayout initialLayout_ = ImageLayout::eUndefined, ImageLayout finalLayout_ = ImageLayout::eUndefined ) @@ -13448,6 +13811,19 @@ namespace vk return StencilFaceFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE StencilFaceFlags operator~( StencilFaceFlagBits bits ) + { + return ~( StencilFaceFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(StencilFaceFlagBits::eFront) | VkFlags(StencilFaceFlagBits::eBack) | VkFlags(StencilFaceFlagBits::eVkStencilFrontAndBack) + }; + }; + enum class DescriptorPoolCreateFlagBits { eFreeDescriptorSet = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT @@ -13460,6 +13836,19 @@ namespace vk return DescriptorPoolCreateFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE DescriptorPoolCreateFlags operator~( DescriptorPoolCreateFlagBits bits ) + { + return ~( DescriptorPoolCreateFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(DescriptorPoolCreateFlagBits::eFreeDescriptorSet) + }; + }; + struct DescriptorPoolCreateInfo { DescriptorPoolCreateInfo( DescriptorPoolCreateFlags flags_ = DescriptorPoolCreateFlags(), uint32_t maxSets_ = 0, uint32_t poolSizeCount_ = 0, const DescriptorPoolSize* pPoolSizes_ = nullptr ) @@ -13563,6 +13952,19 @@ namespace vk return DependencyFlags( bit0 ) | bit1; } + VULKAN_HPP_INLINE DependencyFlags operator~( DependencyFlagBits bits ) + { + return ~( DependencyFlags( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(DependencyFlagBits::eByRegion) + }; + }; + class CommandBuffer { public: @@ -14816,6 +15218,19 @@ namespace vk return DisplayPlaneAlphaFlagsKHR( bit0 ) | bit1; } + VULKAN_HPP_INLINE DisplayPlaneAlphaFlagsKHR operator~( DisplayPlaneAlphaFlagBitsKHR bits ) + { + return ~( DisplayPlaneAlphaFlagsKHR( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(DisplayPlaneAlphaFlagBitsKHR::eOpaque) | VkFlags(DisplayPlaneAlphaFlagBitsKHR::eGlobal) | VkFlags(DisplayPlaneAlphaFlagBitsKHR::ePerPixel) | VkFlags(DisplayPlaneAlphaFlagBitsKHR::ePerPixelPremultiplied) + }; + }; + struct DisplayPlaneCapabilitiesKHR { operator const VkDisplayPlaneCapabilitiesKHR&() const @@ -14868,6 +15283,19 @@ namespace vk return CompositeAlphaFlagsKHR( bit0 ) | bit1; } + VULKAN_HPP_INLINE CompositeAlphaFlagsKHR operator~( CompositeAlphaFlagBitsKHR bits ) + { + return ~( CompositeAlphaFlagsKHR( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(CompositeAlphaFlagBitsKHR::eOpaque) | VkFlags(CompositeAlphaFlagBitsKHR::ePreMultiplied) | VkFlags(CompositeAlphaFlagBitsKHR::ePostMultiplied) | VkFlags(CompositeAlphaFlagBitsKHR::eInherit) + }; + }; + enum class SurfaceTransformFlagBitsKHR { eIdentity = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, @@ -14888,6 +15316,19 @@ namespace vk return SurfaceTransformFlagsKHR( bit0 ) | bit1; } + VULKAN_HPP_INLINE SurfaceTransformFlagsKHR operator~( SurfaceTransformFlagBitsKHR bits ) + { + return ~( SurfaceTransformFlagsKHR( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(SurfaceTransformFlagBitsKHR::eIdentity) | VkFlags(SurfaceTransformFlagBitsKHR::eRotate90) | VkFlags(SurfaceTransformFlagBitsKHR::eRotate180) | VkFlags(SurfaceTransformFlagBitsKHR::eRotate270) | VkFlags(SurfaceTransformFlagBitsKHR::eHorizontalMirror) | VkFlags(SurfaceTransformFlagBitsKHR::eHorizontalMirrorRotate90) | VkFlags(SurfaceTransformFlagBitsKHR::eHorizontalMirrorRotate180) | VkFlags(SurfaceTransformFlagBitsKHR::eHorizontalMirrorRotate270) | VkFlags(SurfaceTransformFlagBitsKHR::eInherit) + }; + }; + struct DisplayPropertiesKHR { operator const VkDisplayPropertiesKHR&() const @@ -15302,6 +15743,19 @@ namespace vk return DebugReportFlagsEXT( bit0 ) | bit1; } + VULKAN_HPP_INLINE DebugReportFlagsEXT operator~( DebugReportFlagBitsEXT bits ) + { + return ~( DebugReportFlagsEXT( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(DebugReportFlagBitsEXT::eInformation) | VkFlags(DebugReportFlagBitsEXT::eWarning) | VkFlags(DebugReportFlagBitsEXT::ePerformanceWarning) | VkFlags(DebugReportFlagBitsEXT::eError) | VkFlags(DebugReportFlagBitsEXT::eDebug) + }; + }; + struct DebugReportCallbackCreateInfoEXT { DebugReportCallbackCreateInfoEXT( DebugReportFlagsEXT flags_ = DebugReportFlagsEXT(), PFN_vkDebugReportCallbackEXT pfnCallback_ = nullptr, void* pUserData_ = nullptr ) @@ -15690,6 +16144,19 @@ namespace vk return ExternalMemoryHandleTypeFlagsNV( bit0 ) | bit1; } + VULKAN_HPP_INLINE ExternalMemoryHandleTypeFlagsNV operator~( ExternalMemoryHandleTypeFlagBitsNV bits ) + { + return ~( ExternalMemoryHandleTypeFlagsNV( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ExternalMemoryHandleTypeFlagBitsNV::eOpaqueWin32) | VkFlags(ExternalMemoryHandleTypeFlagBitsNV::eOpaqueWin32Kmt) | VkFlags(ExternalMemoryHandleTypeFlagBitsNV::eD3D11Image) | VkFlags(ExternalMemoryHandleTypeFlagBitsNV::eD3D11ImageKmt) + }; + }; + class Device { public: @@ -17087,6 +17554,19 @@ namespace vk return ExternalMemoryFeatureFlagsNV( bit0 ) | bit1; } + VULKAN_HPP_INLINE ExternalMemoryFeatureFlagsNV operator~( ExternalMemoryFeatureFlagBitsNV bits ) + { + return ~( ExternalMemoryFeatureFlagsNV( bits ) ); + } + + template <> struct FlagTraits + { + enum + { + allFlags = VkFlags(ExternalMemoryFeatureFlagBitsNV::eDedicatedOnly) | VkFlags(ExternalMemoryFeatureFlagBitsNV::eExportable) | VkFlags(ExternalMemoryFeatureFlagBitsNV::eImportable) + }; + }; + struct ExternalImageFormatPropertiesNV { ExternalImageFormatPropertiesNV( ImageFormatProperties imageFormatProperties_ = ImageFormatProperties(), ExternalMemoryFeatureFlagsNV externalMemoryFeatures_ = ExternalMemoryFeatureFlagsNV(), ExternalMemoryHandleTypeFlagsNV exportFromImportedHandleTypes_ = ExternalMemoryHandleTypeFlagsNV(), ExternalMemoryHandleTypeFlagsNV compatibleHandleTypes_ = ExternalMemoryHandleTypeFlagsNV() ) From 3e3c16a0a17f4e3eadcbabd2a118ee978529498b Mon Sep 17 00:00:00 2001 From: Markus Tavenrath Date: Fri, 4 Nov 2016 09:14:53 +0100 Subject: [PATCH 2/3] Add constructor to Optional which accepts a RefType* in addition RefType& and nullptr. This is required since *nullptr is illegal and writing (ptr == nullptr) ? nullptr : *ptr isn't an efficient solution for the problem. (#45) --- VulkanHppGenerator.cpp | 75 +++++++++++++++++++++--------------------- vulkan/vulkan.hpp | 2 ++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 5652d8d..ed60728 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -136,11 +136,11 @@ const std::string flagsHeader( " return !m_mask;\n" " }\n" "\n" -" Flags operator~() const\n" -" {\n" -" Flags result(*this);\n" -" result.m_mask ^= FlagTraits::allFlags;\n" -" return result;\n" +" Flags operator~() const\n" +" {\n" +" Flags result(*this);\n" +" result.m_mask ^= FlagTraits::allFlags;\n" +" return result;\n" " }\n" "\n" " bool operator==(Flags const& rhs) const\n" @@ -187,23 +187,24 @@ const std::string flagsHeader( "\n" ); -std::string const optionalClassHeader = ( - " template \n" - " class Optional\n" - " {\n" - " public:\n" - " Optional(RefType & reference) { m_ptr = &reference; }\n" - " Optional(std::nullptr_t) { m_ptr = nullptr; }\n" - "\n" - " operator RefType*() const { return m_ptr; }\n" - " RefType const* operator->() const { return m_ptr; }\n" - " explicit operator bool() const { return !!m_ptr; }\n" - "\n" - " private:\n" - " RefType *m_ptr;\n" - " };\n" - "\n" -); +std::string const optionalClassHeader = R"( + template + class Optional + { + public: + Optional(RefType & reference) { m_ptr = &reference; } + Optional(RefType * ptr) { m_ptr = ptr; } + Optional(std::nullptr_t) { m_ptr = nullptr; } + + operator RefType*() const { return m_ptr; } + RefType const* operator->() const { return m_ptr; } + explicit operator bool() const { return !!m_ptr; } + + private: + RefType *m_ptr; + }; + +)"; std::string const arrayProxyHeader = ( "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE\n" @@ -2680,21 +2681,21 @@ void writeTypeFlags(std::ofstream & ofs, DependencyData const& dependencyData, F << " return ~( " << dependencyData.name << "( bits ) );" << std::endl << " }" << std::endl << std::endl - << " template <> struct FlagTraits<" << *dependencyData.dependencies.begin() << ">" << std::endl - << " {" << std::endl - << " enum" << std::endl - << " {" << std::endl - << " allFlags = "; - for (size_t i = 0; i < enumData->second.members.size(); i++) - { - if (i != 0) - { - ofs << " | "; - } - ofs << "VkFlags(" << *dependencyData.dependencies.begin() << "::" << enumData->second.members[i].name << ")"; - } - ofs << std::endl - << " };" << std::endl + << " template <> struct FlagTraits<" << *dependencyData.dependencies.begin() << ">" << std::endl + << " {" << std::endl + << " enum" << std::endl + << " {" << std::endl + << " allFlags = "; + for (size_t i = 0; i < enumData->second.members.size(); i++) + { + if (i != 0) + { + ofs << " | "; + } + ofs << "VkFlags(" << *dependencyData.dependencies.begin() << "::" << enumData->second.members[i].name << ")"; + } + ofs << std::endl + << " };" << std::endl << " };" << std::endl; } leaveProtect(ofs, flagData.protect); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index dcb0b61..159f36e 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -208,11 +208,13 @@ namespace vk return flags ^ bit; } + template class Optional { public: Optional(RefType & reference) { m_ptr = &reference; } + Optional(RefType * ptr) { m_ptr = ptr; } Optional(std::nullptr_t) { m_ptr = nullptr; } operator RefType*() const { return m_ptr; } From 81dd365ccc6601570e0b6633ac6cb93153660ff2 Mon Sep 17 00:00:00 2001 From: Markus Tavenrath Date: Tue, 22 Nov 2016 08:53:31 +0100 Subject: [PATCH 3/3] Fix naming conventions for functions in README.md and update to Vulkan 1.0.34 (#50) Fixes issue #49 --- README.md | 4 ++-- Vulkan-Docs | 2 +- vulkan/vulkan.hpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a94f095..03ebfed 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Vulkan-Hpp requires a C++11 capable compiler to compile. The following compilers # namespace vk To avoid name collisions with the Vulkan C API the C++ bindings reside in the vk namespace. The following rules apply to the new naming -* All functions, enums and structs have the Vk prefix removed. - * ```vkCreateImage``` can be accessed as ```vk::CreateImage``` +* All functions, enums, handles, and structs have the Vk prefix removed. In addition to this the first leter of functions is lower case. + * ```vkCreateImage``` can be accessed as ```vk::createImage``` * ```VkImageTiling``` can be accessed as ```vk::ImageTiling``` * ```VkImageCreateInfo``` can be accessed as ```vk::ImageCreateInfo``` * Enums are mapped to scoped enums to provide compile time type safety. The names have been changed to 'e' + CamelCase with the VK_ prefix and type infix removed. In case the enum type is an extension the extension suffix has been removed from the enum values. diff --git a/Vulkan-Docs b/Vulkan-Docs index 368b08a..08310a8 160000 --- a/Vulkan-Docs +++ b/Vulkan-Docs @@ -1 +1 @@ -Subproject commit 368b08a7b2add6db489d0af766bd74854e1c87d4 +Subproject commit 08310a88df8c803ac916102e7a364fff912e3281 diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 159f36e..df00d28 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -41,7 +41,7 @@ # include #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ -static_assert( VK_HEADER_VERSION == 32 , "Wrong VK_HEADER_VERSION!" ); +static_assert( VK_HEADER_VERSION == 34 , "Wrong VK_HEADER_VERSION!" ); // 32-bit vulkan is not typesafe for handles, so don't allow copy constructors on this platform by default. // To enable this feature on 32-bit platforms please define VULKAN_HPP_TYPESAFE_CONVERSION