From d717335bca251d1a60d7d87a623b8b29701c76ec Mon Sep 17 00:00:00 2001 From: SirLynix Date: Wed, 12 Apr 2023 14:13:34 +0200 Subject: [PATCH] VulkanRenderer: Fix unitybuild causing #define issue because of Windows.h --- .../VulkanRenderer/Wrapper/CommandBuffer.hpp | 165 +++--- .../VulkanRenderer/Wrapper/CommandBuffer.inl | 2 +- .../VulkanRenderer/Wrapper/DescriptorSet.inl | 251 ++++----- .../VulkanRenderer/Wrapper/Instance.hpp | 104 ++-- .../VulkanRenderer/Wrapper/Instance.inl | 249 ++++----- src/Nazara/VulkanRenderer/Export.cpp | 4 - src/Nazara/VulkanRenderer/Vulkan.cpp | 4 - src/Nazara/VulkanRenderer/VulkanBuffer.cpp | 1 + .../VulkanRenderer/VulkanCommandBuffer.cpp | 3 - .../VulkanCommandBufferBuilder.cpp | 4 - .../VulkanRenderer/VulkanCommandPool.cpp | 4 - .../VulkanRenderer/VulkanComputePipeline.cpp | 4 - src/Nazara/VulkanRenderer/VulkanDevice.cpp | 4 - .../VulkanRenderer/VulkanFramebuffer.cpp | 4 - .../VulkanRenderer/VulkanRenderImage.cpp | 4 - .../VulkanRenderer/VulkanRenderPass.cpp | 4 - .../VulkanRenderer/VulkanRenderPipeline.cpp | 4 - .../VulkanRenderPipelineLayout.cpp | 4 - src/Nazara/VulkanRenderer/VulkanRenderer.cpp | 4 - .../VulkanRenderer/VulkanShaderBinding.cpp | 4 - .../VulkanRenderer/VulkanShaderModule.cpp | 4 - src/Nazara/VulkanRenderer/VulkanSwapchain.cpp | 5 + src/Nazara/VulkanRenderer/VulkanTexture.cpp | 1 + .../VulkanTextureFramebuffer.cpp | 4 - .../VulkanRenderer/VulkanTextureSampler.cpp | 4 - .../VulkanRenderer/VulkanUploadPool.cpp | 4 - .../VulkanWindowFramebuffer.cpp | 4 - .../VulkanRenderer/Wrapper/CommandPool.cpp | 4 - .../VulkanRenderer/Wrapper/DescriptorPool.cpp | 4 - src/Nazara/VulkanRenderer/Wrapper/Device.cpp | 1 + .../VulkanRenderer/Wrapper/Instance.cpp | 529 +++++++++--------- 31 files changed, 652 insertions(+), 739 deletions(-) diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp index 754678c37..f5c1dcf44 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp @@ -14,120 +14,117 @@ #include #include -namespace Nz +namespace Nz::Vk { - namespace Vk + class CommandBuffer { - class CommandBuffer - { - friend CommandPool; + friend CommandPool; - public: - inline CommandBuffer(); - CommandBuffer(const CommandBuffer&) = delete; - inline CommandBuffer(CommandBuffer&& commandBuffer); - ~CommandBuffer() = default; + public: + inline CommandBuffer(); + CommandBuffer(const CommandBuffer&) = delete; + inline CommandBuffer(CommandBuffer&& commandBuffer) noexcept; + ~CommandBuffer() = default; - inline bool Begin(const VkCommandBufferBeginInfo& info); - inline bool Begin(VkCommandBufferUsageFlags flags = 0); - inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo); - inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics); - inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics); + inline bool Begin(const VkCommandBufferBeginInfo& info); + inline bool Begin(VkCommandBufferUsageFlags flags = 0); + inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo); + inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics); + inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics); - inline void BeginDebugRegion(const char* label); - inline void BeginDebugRegion(const char* label, Color color); - inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE); + inline void BeginDebugRegion(const char* label); + inline void BeginDebugRegion(const char* label, Color color); + inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE); - inline void BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets); - inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets); - inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets); - inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType); - inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline); - inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset); - inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset); + inline void BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets); + inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets); + inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets); + inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType); + inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline); + inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset); + inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset); - inline void BlitImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, const VkImageBlit& region, VkFilter filter); - inline void BlitImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, UInt32 regionCount, const VkImageBlit* regions, VkFilter filter); + inline void BlitImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, const VkImageBlit& region, VkFilter filter); + inline void BlitImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, UInt32 regionCount, const VkImageBlit* regions, VkFilter filter); - inline void ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect); - inline void ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects); + inline void ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect); + inline void ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects); - inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range); - inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges); + inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range); + inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges); - inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range); - inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges); + inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range); + inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges); - inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0); - inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height, UInt32 depth = 1); - inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, Int32 x, Int32 y, Int32 z, UInt32 width, UInt32 height, UInt32 depth); - inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 width, UInt32 height, UInt32 depth = 1); - inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkBufferImageCopy& region); - inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 regionCount, const VkBufferImageCopy* regions); - inline void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, const VkImageCopy& region); - inline void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, UInt32 regionCount, const VkImageCopy* regions); + inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0); + inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height, UInt32 depth = 1); + inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, Int32 x, Int32 y, Int32 z, UInt32 width, UInt32 height, UInt32 depth); + inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 width, UInt32 height, UInt32 depth = 1); + inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkBufferImageCopy& region); + inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 regionCount, const VkBufferImageCopy* regions); + inline void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, const VkImageCopy& region); + inline void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, UInt32 regionCount, const VkImageCopy* regions); - inline void Dispatch(UInt32 groupCountX, UInt32 groupCountY, UInt32 groupCountZ); + inline void Dispatch(UInt32 groupCountX, UInt32 groupCountY, UInt32 groupCountZ); - inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0); - inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0); + inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0); + inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0); - inline bool End(); + inline bool End(); - inline void EndDebugRegion(); - inline void EndRenderPass(); + inline void EndDebugRegion(); + inline void EndRenderPass(); - inline void Free(); + inline void Free(); - inline VkResult GetLastErrorCode() const; - inline CommandPool& GetPool(); + inline VkResult GetLastErrorCode() const; + inline CommandPool& GetPool(); - inline void ImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImage image, const VkImageSubresourceRange& subresourceRange); + inline void ImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImage image, const VkImageSubresourceRange& subresourceRange); - inline void InsertDebugLabel(const char* label); - inline void InsertDebugLabel(const char* label, Color color); + inline void InsertDebugLabel(const char* label); + inline void InsertDebugLabel(const char* label, Color color); - inline void MemoryBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask); + inline void MemoryBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask); - inline void NextSubpass(VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE); + inline void NextSubpass(VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE); - inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier); - inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier); - inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers); + inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier); + inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier); + inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers); - inline void SetScissor(const Recti& scissorRegion); - inline void SetScissor(const VkRect2D& scissorRegion); - inline void SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors); - inline void SetViewport(const Rectf& viewport, float minDepth, float maxDepth); - inline void SetViewport(const VkViewport& viewport); - inline void SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports); + inline void SetScissor(const Recti& scissorRegion); + inline void SetScissor(const VkRect2D& scissorRegion); + inline void SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors); + inline void SetViewport(const Rectf& viewport, float minDepth, float maxDepth); + inline void SetViewport(const VkViewport& viewport); + inline void SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports); - inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); - inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange); - inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); - inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange); + inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); + inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange); + inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); + inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange); - CommandBuffer& operator=(const CommandBuffer&) = delete; - CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept; + CommandBuffer& operator=(const CommandBuffer&) = delete; + CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept; - inline operator VkCommandBuffer() const; + inline operator VkCommandBuffer() const; - private: - inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle); + private: + inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle); - CommandPool* m_pool; - VkCommandBuffer m_handle; - VkResult m_lastErrorCode; - }; + CommandPool* m_pool; + VkCommandBuffer m_handle; + VkResult m_lastErrorCode; + }; - class AutoCommandBuffer : public AutoFree - { - public: - using AutoFree::AutoFree; + class AutoCommandBuffer : public AutoFree + { + public: + using AutoFree::AutoFree; - operator VkCommandBuffer() const { return Get(); } - }; - } + operator VkCommandBuffer() const { return Get(); } + }; } #include diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl index 0f89b5bfc..f39b671f4 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl @@ -23,7 +23,7 @@ namespace Nz { } - inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) : + inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) noexcept : m_pool(commandBuffer.m_pool), m_handle(commandBuffer.m_handle), m_lastErrorCode(commandBuffer.m_lastErrorCode) diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl index 5017c6ba4..9c0cbf806 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl @@ -7,158 +7,155 @@ #include #include -namespace Nz +namespace Nz::Vk { - namespace Vk + inline DescriptorSet::DescriptorSet() : + m_pool(nullptr), + m_handle(VK_NULL_HANDLE) { - inline DescriptorSet::DescriptorSet() : - m_pool(nullptr), - m_handle(VK_NULL_HANDLE) + } + + inline DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle) : + m_pool(&pool), + m_handle(handle) + { + } + + inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) noexcept : + m_pool(descriptorSet.m_pool), + m_handle(descriptorSet.m_handle) + { + descriptorSet.m_handle = VK_NULL_HANDLE; + } + + inline void DescriptorSet::Free() + { + if (m_handle) { + assert(m_pool); + m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle); } + } - inline DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle) : - m_pool(&pool), - m_handle(handle) - { - } + inline bool DescriptorSet::IsValid() const + { + return m_handle != VK_NULL_HANDLE; + } - inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) noexcept : - m_pool(descriptorSet.m_pool), - m_handle(descriptorSet.m_handle) - { - descriptorSet.m_handle = VK_NULL_HANDLE; - } + inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout) + { + return WriteCombinedImageSamplerDescriptor(binding, 0, sampler, imageView, imageLayout); + } - inline void DescriptorSet::Free() - { - if (m_handle) - { - assert(m_pool); - m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle); - } - } + inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, const VkDescriptorImageInfo& imageInfo) + { + return WriteCombinedImageSamplerDescriptor(binding, 0, imageInfo); + } - inline bool DescriptorSet::IsValid() const - { - return m_handle != VK_NULL_HANDLE; - } + inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout) + { + VkDescriptorImageInfo imageInfo = { + sampler, + imageView, + imageLayout + }; - inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout) - { - return WriteCombinedImageSamplerDescriptor(binding, 0, sampler, imageView, imageLayout); - } + return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo); + } - inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, const VkDescriptorImageInfo& imageInfo) - { - return WriteCombinedImageSamplerDescriptor(binding, 0, imageInfo); - } + inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorImageInfo& imageInfo) + { + return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo); + } - inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout) - { - VkDescriptorImageInfo imageInfo = { - sampler, - imageView, - imageLayout - }; + inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo) + { + return WriteCombinedImageSamplerDescriptors(binding, 0U, descriptorCount, imageInfo); + } - return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo); - } + inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo) + { + VkWriteDescriptorSet writeDescriptorSet = { + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + nullptr, + m_handle, + binding, + arrayElement, + descriptorCount, + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + imageInfo, + nullptr, + nullptr + }; - inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorImageInfo& imageInfo) - { - return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo); - } + return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr); + } - inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo) - { - return WriteCombinedImageSamplerDescriptors(binding, 0U, descriptorCount, imageInfo); - } + inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) + { + return WriteUniformDescriptor(binding, 0U, buffer, offset, range); + } - inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo) - { - VkWriteDescriptorSet writeDescriptorSet = { - VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - nullptr, - m_handle, - binding, - arrayElement, - descriptorCount, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - imageInfo, - nullptr, - nullptr - }; + inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo) + { + return WriteUniformDescriptors(binding, 0U, 1U, &bufferInfo); + } - return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr); - } + inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) + { + VkDescriptorBufferInfo bufferInfo = { + buffer, + offset, + range + }; - inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) - { - return WriteUniformDescriptor(binding, 0U, buffer, offset, range); - } + return WriteUniformDescriptor(binding, arrayElement, bufferInfo); + } - inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo) - { - return WriteUniformDescriptors(binding, 0U, 1U, &bufferInfo); - } + inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo) + { + return WriteUniformDescriptors(binding, arrayElement, 1U, &bufferInfo); + } - inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) - { - VkDescriptorBufferInfo bufferInfo = { - buffer, - offset, - range - }; + inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) + { + return WriteUniformDescriptors(binding, 0U, descriptorCount, bufferInfo); + } - return WriteUniformDescriptor(binding, arrayElement, bufferInfo); - } + inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) + { + VkWriteDescriptorSet writeDescriptorSet = { + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + nullptr, + m_handle, + binding, + arrayElement, + descriptorCount, + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + nullptr, + bufferInfo, + nullptr + }; - inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo) - { - return WriteUniformDescriptors(binding, arrayElement, 1U, &bufferInfo); - } + return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr); + } - inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) - { - return WriteUniformDescriptors(binding, 0U, descriptorCount, bufferInfo); - } + inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet) noexcept + { + std::swap(m_handle, descriptorSet.m_handle); + std::swap(m_pool, descriptorSet.m_pool); - inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) - { - VkWriteDescriptorSet writeDescriptorSet = { - VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - nullptr, - m_handle, - binding, - arrayElement, - descriptorCount, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - nullptr, - bufferInfo, - nullptr - }; + return *this; + } - return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr); - } + inline DescriptorSet::operator bool() const + { + return IsValid(); + } - inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet) noexcept - { - std::swap(m_handle, descriptorSet.m_handle); - std::swap(m_pool, descriptorSet.m_pool); - - return *this; - } - - inline DescriptorSet::operator bool() const - { - return IsValid(); - } - - inline DescriptorSet::operator VkDescriptorSet() const - { - return m_handle; - } + inline DescriptorSet::operator VkDescriptorSet() const + { + return m_handle; } } diff --git a/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp b/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp index 43b15286d..44126c91b 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp @@ -21,17 +21,24 @@ #endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR -#include #include #endif #ifdef VK_USE_PLATFORM_WIN32_KHR -#include +typedef struct HINSTANCE__* HINSTANCE; +typedef struct HWND__* HWND; +typedef struct HMONITOR__* HMONITOR; +typedef void* HANDLE; +typedef /*_Null_terminated_*/ const wchar_t* LPCWSTR; +typedef unsigned long DWORD; +typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES; #include #endif #ifdef VK_USE_PLATFORM_XCB_KHR -#include +struct xcb_connection_t; +typedef uint32_t xcb_window_t; +typedef uint32_t xcb_visualid_t; #include #endif @@ -48,72 +55,69 @@ typedef unsigned long VisualID; #include #endif -namespace Nz +namespace Nz::Vk { - namespace Vk + class NAZARA_VULKANRENDERER_API Instance { - class NAZARA_VULKANRENDERER_API Instance - { - public: - Instance(); - Instance(const Instance&) = delete; - Instance(Instance&&) = delete; - ~Instance(); + public: + Instance(); + Instance(const Instance&) = delete; + Instance(Instance&&) = delete; + ~Instance(); - bool Create(RenderAPIValidationLevel validationLevel, const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); - inline bool Create(RenderAPIValidationLevel validationLevel, const std::string& appName, UInt32 appVersion, const std::string& engineName, UInt32 engineVersion, UInt32 apiVersion, const std::vector& layers, const std::vector& extensions, const VkAllocationCallbacks* allocator = nullptr); - inline void Destroy(); + bool Create(RenderAPIValidationLevel validationLevel, const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(RenderAPIValidationLevel validationLevel, const std::string& appName, UInt32 appVersion, const std::string& engineName, UInt32 engineVersion, UInt32 apiVersion, const std::vector& layers, const std::vector& extensions, const VkAllocationCallbacks* allocator = nullptr); + inline void Destroy(); - bool EnumeratePhysicalDevices(std::vector* physicalDevices) const; + bool EnumeratePhysicalDevices(std::vector* physicalDevices) const; - inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name) const; + inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name) const; - inline UInt32 GetApiVersion() const; - inline VkResult GetLastErrorCode() const; + inline UInt32 GetApiVersion() const; + inline VkResult GetLastErrorCode() const; - bool GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties) const; - inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device) const; - inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format) const; - inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties) const; - inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const; - inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device) const; - bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector* queueFamilyProperties) const; - inline PFN_vkVoidFunction GetProcAddr(const char* name) const; - inline RenderAPIValidationLevel GetValidationLevel() const; + bool GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties) const; + inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device) const; + inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format) const; + inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties) const; + inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const; + inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device) const; + bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector* queueFamilyProperties) const; + inline PFN_vkVoidFunction GetProcAddr(const char* name) const; + inline RenderAPIValidationLevel GetValidationLevel() const; - void InstallDebugMessageCallback(); + void InstallDebugMessageCallback(); - inline bool IsExtensionLoaded(const std::string& extensionName) const; - inline bool IsLayerLoaded(const std::string& layerName) const; - inline bool IsValid() const; + inline bool IsExtensionLoaded(const std::string& extensionName) const; + inline bool IsLayerLoaded(const std::string& layerName) const; + inline bool IsValid() const; - Instance& operator=(const Instance&) = delete; - Instance& operator=(Instance&&) = delete; + Instance& operator=(const Instance&) = delete; + Instance& operator=(Instance&&) = delete; - inline operator VkInstance(); + inline operator VkInstance(); - // Vulkan functions + // Vulkan functions #define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) PFN_##func func; #define NAZARA_VULKANRENDERER_INSTANCE_CORE_EXT_FUNCTION(func, ...) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) #include - private: - void DestroyInstance(); - void ResetPointers(); + private: + void DestroyInstance(); + void ResetPointers(); - struct InternalData; + struct InternalData; - std::unique_ptr m_internalData; - std::unordered_set m_loadedExtensions; - std::unordered_set m_loadedLayers; - VkAllocationCallbacks m_allocator; - VkInstance m_instance; - mutable VkResult m_lastErrorCode; - RenderAPIValidationLevel m_validationLevel; - UInt32 m_apiVersion; - }; - } + std::unique_ptr m_internalData; + std::unordered_set m_loadedExtensions; + std::unordered_set m_loadedLayers; + VkAllocationCallbacks m_allocator; + VkInstance m_instance; + mutable VkResult m_lastErrorCode; + RenderAPIValidationLevel m_validationLevel; + UInt32 m_apiVersion; + }; } #include diff --git a/include/Nazara/VulkanRenderer/Wrapper/Instance.inl b/include/Nazara/VulkanRenderer/Wrapper/Instance.inl index a8de4793e..6e3742c38 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Instance.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Instance.inl @@ -7,143 +7,140 @@ #include #include -namespace Nz +namespace Nz::Vk { - namespace Vk + inline bool Instance::Create(RenderAPIValidationLevel validationLevel, const std::string& appName, UInt32 appVersion, const std::string& engineName, UInt32 engineVersion, UInt32 apiVersion, const std::vector& layers, const std::vector& extensions, const VkAllocationCallbacks* allocator) { - inline bool Instance::Create(RenderAPIValidationLevel validationLevel, const std::string& appName, UInt32 appVersion, const std::string& engineName, UInt32 engineVersion, UInt32 apiVersion, const std::vector& layers, const std::vector& extensions, const VkAllocationCallbacks* allocator) + VkApplicationInfo appInfo = { - VkApplicationInfo appInfo = - { - VK_STRUCTURE_TYPE_APPLICATION_INFO, - nullptr, - appName.data(), - appVersion, - engineName.data(), - engineVersion, - apiVersion - }; + VK_STRUCTURE_TYPE_APPLICATION_INFO, + nullptr, + appName.data(), + appVersion, + engineName.data(), + engineVersion, + apiVersion + }; - VkInstanceCreateInfo instanceInfo = - { - VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, - nullptr, - 0, - &appInfo, - static_cast(layers.size()), - (!layers.empty()) ? layers.data() : nullptr, - static_cast(extensions.size()), - (!extensions.empty()) ? extensions.data() : nullptr - }; + VkInstanceCreateInfo instanceInfo = + { + VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + nullptr, + 0, + &appInfo, + static_cast(layers.size()), + (!layers.empty()) ? layers.data() : nullptr, + static_cast(extensions.size()), + (!extensions.empty()) ? extensions.data() : nullptr + }; - return Create(validationLevel, instanceInfo, allocator); + return Create(validationLevel, instanceInfo, allocator); + } + + inline void Instance::Destroy() + { + if (m_instance) + { + DestroyInstance(); + ResetPointers(); + } + } + + inline PFN_vkVoidFunction Instance::GetDeviceProcAddr(VkDevice device, const char* name) const + { + PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name); + if (!func) + NazaraError("Failed to get " + std::string(name) + " address"); + + return func; + } + + inline UInt32 Instance::GetApiVersion() const + { + return m_apiVersion; + } + + inline VkResult Instance::GetLastErrorCode() const + { + return m_lastErrorCode; + } + + inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name) const + { + PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name); + if (!func) + NazaraError("Failed to get " + std::string(name) + " address"); + + return func; + } + + inline RenderAPIValidationLevel Instance::GetValidationLevel() const + { + return m_validationLevel; + } + + inline bool Instance::IsExtensionLoaded(const std::string& extensionName) const + { + return m_loadedExtensions.count(extensionName) > 0; + } + + inline bool Instance::IsLayerLoaded(const std::string& layerName) const + { + return m_loadedLayers.count(layerName) > 0; + } + + inline bool Instance::IsValid() const + { + return m_instance != nullptr; + } + + inline Instance::operator VkInstance() + { + return m_instance; + } + + inline VkPhysicalDeviceFeatures Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device) const + { + VkPhysicalDeviceFeatures features; + vkGetPhysicalDeviceFeatures(device, &features); + + return features; + } + + inline VkFormatProperties Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format) const + { + VkFormatProperties formatProperties; + vkGetPhysicalDeviceFormatProperties(device, format, &formatProperties); + + return formatProperties; + } + + inline bool Instance::GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties) const + { + m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties); + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to get physical device image format properties: " + TranslateVulkanError(m_lastErrorCode)); + return false; } - inline void Instance::Destroy() - { - if (m_instance) - { - DestroyInstance(); - ResetPointers(); - } - } + return true; + } - inline PFN_vkVoidFunction Instance::GetDeviceProcAddr(VkDevice device, const char* name) const - { - PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name); - if (!func) - NazaraError("Failed to get " + std::string(name) + " address"); + inline VkPhysicalDeviceMemoryProperties Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const + { + VkPhysicalDeviceMemoryProperties memoryProperties; + vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties); - return func; - } + return memoryProperties; + } - inline UInt32 Instance::GetApiVersion() const - { - return m_apiVersion; - } + inline VkPhysicalDeviceProperties Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device) const + { + VkPhysicalDeviceProperties properties; + vkGetPhysicalDeviceProperties(device, &properties); - inline VkResult Instance::GetLastErrorCode() const - { - return m_lastErrorCode; - } - - inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name) const - { - PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name); - if (!func) - NazaraError("Failed to get " + std::string(name) + " address"); - - return func; - } - - inline RenderAPIValidationLevel Instance::GetValidationLevel() const - { - return m_validationLevel; - } - - inline bool Instance::IsExtensionLoaded(const std::string& extensionName) const - { - return m_loadedExtensions.count(extensionName) > 0; - } - - inline bool Instance::IsLayerLoaded(const std::string& layerName) const - { - return m_loadedLayers.count(layerName) > 0; - } - - inline bool Instance::IsValid() const - { - return m_instance != nullptr; - } - - inline Instance::operator VkInstance() - { - return m_instance; - } - - inline VkPhysicalDeviceFeatures Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device) const - { - VkPhysicalDeviceFeatures features; - vkGetPhysicalDeviceFeatures(device, &features); - - return features; - } - - inline VkFormatProperties Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format) const - { - VkFormatProperties formatProperties; - vkGetPhysicalDeviceFormatProperties(device, format, &formatProperties); - - return formatProperties; - } - - inline bool Instance::GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties) const - { - m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties); - if (m_lastErrorCode != VkResult::VK_SUCCESS) - { - NazaraError("Failed to get physical device image format properties: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - return true; - } - - inline VkPhysicalDeviceMemoryProperties Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const - { - VkPhysicalDeviceMemoryProperties memoryProperties; - vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties); - - return memoryProperties; - } - - inline VkPhysicalDeviceProperties Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device) const - { - VkPhysicalDeviceProperties properties; - vkGetPhysicalDeviceProperties(device, &properties); - - return properties; - } + return properties; } } diff --git a/src/Nazara/VulkanRenderer/Export.cpp b/src/Nazara/VulkanRenderer/Export.cpp index 530bb1c8b..598fa2e0d 100644 --- a/src/Nazara/VulkanRenderer/Export.cpp +++ b/src/Nazara/VulkanRenderer/Export.cpp @@ -17,7 +17,3 @@ extern "C" } #endif - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index ea32825e5..c320af314 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -625,7 +625,3 @@ namespace Nz Vk::Instance Vulkan::s_instance; ParameterList Vulkan::s_initializationParameters; } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanBuffer.cpp b/src/Nazara/VulkanRenderer/VulkanBuffer.cpp index 1a47a32bf..e80bd959f 100644 --- a/src/Nazara/VulkanRenderer/VulkanBuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanBuffer.cpp @@ -143,6 +143,7 @@ namespace Nz } } +// vma includes vulkan.h which includes system headers #if defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_LINUX) diff --git a/src/Nazara/VulkanRenderer/VulkanCommandBuffer.cpp b/src/Nazara/VulkanRenderer/VulkanCommandBuffer.cpp index 539388a6a..1b2553203 100644 --- a/src/Nazara/VulkanRenderer/VulkanCommandBuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanCommandBuffer.cpp @@ -18,6 +18,3 @@ namespace Nz m_owner.Release(*this); } } -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp b/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp index 3f00b3236..db392208d 100644 --- a/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp +++ b/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp @@ -290,7 +290,3 @@ namespace Nz m_commandBuffer.ImageBarrier(ToVulkan(srcStageMask), ToVulkan(dstStageMask), VkDependencyFlags(0), ToVulkan(srcAccessMask), ToVulkan(dstAccessMask), ToVulkan(oldLayout), ToVulkan(newLayout), vkTexture.GetImage(), vkTexture.GetSubresourceRange()); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp b/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp index 92154915a..f074323b4 100644 --- a/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp +++ b/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp @@ -76,7 +76,3 @@ namespace Nz TryToShrink(); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp b/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp index e154a33e5..d70217f5c 100644 --- a/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp +++ b/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp @@ -54,7 +54,3 @@ namespace Nz m_pipeline.SetDebugName(name); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanDevice.cpp b/src/Nazara/VulkanRenderer/VulkanDevice.cpp index 809bb6f68..12f98b6c5 100644 --- a/src/Nazara/VulkanRenderer/VulkanDevice.cpp +++ b/src/Nazara/VulkanRenderer/VulkanDevice.cpp @@ -140,7 +140,3 @@ namespace Nz return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanFramebuffer.cpp b/src/Nazara/VulkanRenderer/VulkanFramebuffer.cpp index 086af8925..21cda3f3c 100644 --- a/src/Nazara/VulkanRenderer/VulkanFramebuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanFramebuffer.cpp @@ -12,7 +12,3 @@ namespace Nz GetFramebuffer().SetDebugName(name); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp b/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp index ba172f22e..699875a7a 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp @@ -91,7 +91,3 @@ namespace Nz } } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanRenderPass.cpp b/src/Nazara/VulkanRenderer/VulkanRenderPass.cpp index ab0d81df9..aeea2f927 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderPass.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderPass.cpp @@ -139,7 +139,3 @@ namespace Nz return m_renderPass.SetDebugName(name); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp b/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp index b94bba9e6..5f9012a44 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp @@ -328,7 +328,3 @@ namespace Nz m_pipelineCreateInfo.stateData->colorBlendState = BuildColorBlendInfo(m_pipelineInfo, m_pipelineCreateInfo.colorBlendAttachmentState); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp b/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp index 0501664c8..026900d47 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp @@ -159,7 +159,3 @@ namespace Nz TryToShrink(); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp index 161a629fc..b4a69effd 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp @@ -64,7 +64,3 @@ namespace Nz return m_deviceInfos; } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp b/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp index 9e7d49127..dca6fb51d 100644 --- a/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp +++ b/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp @@ -147,7 +147,3 @@ namespace Nz m_owner.Release(*this); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp b/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp index 5a0811c0c..2f8ae2d0e 100644 --- a/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp +++ b/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp @@ -147,7 +147,3 @@ namespace Nz m_shaderModule.SetDebugName(name); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp index b291ac039..0c7719da8 100644 --- a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp +++ b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp @@ -15,6 +15,11 @@ #include #include +#ifdef VK_USE_PLATFORM_WIN32_KHR +#include +#include +#endif + #ifdef VK_USE_PLATFORM_METAL_EXT #include #include diff --git a/src/Nazara/VulkanRenderer/VulkanTexture.cpp b/src/Nazara/VulkanRenderer/VulkanTexture.cpp index aacf07d30..775f30979 100644 --- a/src/Nazara/VulkanRenderer/VulkanTexture.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTexture.cpp @@ -501,6 +501,7 @@ namespace Nz } } +// vma includes vulkan.h which includes system headers #if defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_LINUX) diff --git a/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp b/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp index 25d8b60dd..f96f26100 100644 --- a/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp @@ -42,7 +42,3 @@ namespace Nz throw std::runtime_error("failed to instantiate Vulkan framebuffer: " + TranslateVulkanError(m_framebuffer.GetLastErrorCode())); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanTextureSampler.cpp b/src/Nazara/VulkanRenderer/VulkanTextureSampler.cpp index f1d154917..0fac100fb 100644 --- a/src/Nazara/VulkanRenderer/VulkanTextureSampler.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTextureSampler.cpp @@ -40,7 +40,3 @@ namespace Nz return m_sampler.SetDebugName(name); } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanUploadPool.cpp b/src/Nazara/VulkanRenderer/VulkanUploadPool.cpp index 0601d1de1..07c08a835 100644 --- a/src/Nazara/VulkanRenderer/VulkanUploadPool.cpp +++ b/src/Nazara/VulkanRenderer/VulkanUploadPool.cpp @@ -103,7 +103,3 @@ namespace Nz m_nextAllocationIndex = 0; } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/VulkanWindowFramebuffer.cpp b/src/Nazara/VulkanRenderer/VulkanWindowFramebuffer.cpp index 58bf1a942..635b73367 100644 --- a/src/Nazara/VulkanRenderer/VulkanWindowFramebuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanWindowFramebuffer.cpp @@ -8,7 +8,3 @@ namespace Nz { } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/Wrapper/CommandPool.cpp b/src/Nazara/VulkanRenderer/Wrapper/CommandPool.cpp index d6db0460a..b51373f0b 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/CommandPool.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/CommandPool.cpp @@ -51,7 +51,3 @@ namespace Nz } } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp b/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp index 7399e8b49..e325b1d62 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp @@ -49,7 +49,3 @@ namespace Nz } } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif diff --git a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp index 30ecf553e..d5a4427c7 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp @@ -300,6 +300,7 @@ namespace Nz } } +// vma includes vulkan.h which includes system headers #if defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_LINUX) diff --git a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp index 25ee5a880..133fcc1ef 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp @@ -12,331 +12,324 @@ #include #include -namespace Nz +namespace Nz::Vk { - namespace Vk + namespace { - namespace + VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback( + VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT messageTypes, + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, + void* pUserData) { - VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback( - VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, - VkDebugUtilsMessageTypeFlagsEXT messageTypes, - const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, - void* pUserData) + Instance& instance = *static_cast(pUserData); + if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { - Instance& instance = *static_cast(pUserData); - if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) - { - RenderAPIValidationLevel validationLevel = instance.GetValidationLevel(); - if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Debug) - return VK_FALSE; + RenderAPIValidationLevel validationLevel = instance.GetValidationLevel(); + if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Debug) + return VK_FALSE; - if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Verbose) - return VK_FALSE; + if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Verbose) + return VK_FALSE; - if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Warnings) - return VK_FALSE; - } - - std::stringstream ss; - ss << "Vulkan log: "; - - if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) - ss << "[Verbose]"; - - if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) - ss << "[Info]"; - - if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) - ss << "[Warning]"; - - if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) - ss << "[Error]"; - - - if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) - ss << "[General]"; - - if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) - ss << "[Performance]"; - - if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) - ss << "[Validation]"; - - ss << "[" << pCallbackData->messageIdNumber; - if (pCallbackData->pMessageIdName) - ss << ":" << pCallbackData->pMessageIdName; - - ss << "]: " << pCallbackData->pMessage; - - if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) - NazaraError(ss.str()); - else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) - NazaraWarning(ss.str()); - else - NazaraNotice(ss.str()); - - return VK_FALSE; //< Should the Vulkan call be aborted + if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) && validationLevel < RenderAPIValidationLevel::Warnings) + return VK_FALSE; } - VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback( - VkDebugReportFlagsEXT flags, - VkDebugReportObjectTypeEXT /*objectType*/, - uint64_t /*object*/, - size_t /*location*/, - int32_t messageCode, - const char* pLayerPrefix, - const char* pMessage, - void* /*pUserData*/) - { - std::stringstream ss; - ss << "Vulkan log: "; + std::stringstream ss; + ss << "Vulkan log: "; - if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) - ss << "[Info]"; + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) + ss << "[Verbose]"; - if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) - ss << "[Warning]"; + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) + ss << "[Info]"; - if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) - ss << "[Error]"; + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) + ss << "[Warning]"; - if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) - ss << "[Performance]"; + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) + ss << "[Error]"; - if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) - ss << "[Debug]"; - ss << "[" << messageCode << "]"; - if (pLayerPrefix) - ss << "[layer " << pLayerPrefix << "]"; + if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) + ss << "[General]"; - ss << ": " << pMessage; + if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) + ss << "[Performance]"; - if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) - NazaraError(ss.str()); - else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) - NazaraWarning(ss.str()); - else - NazaraNotice(ss.str()); + if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) + ss << "[Validation]"; - return VK_FALSE; //< Should the Vulkan call be aborted - } - } + ss << "[" << pCallbackData->messageIdNumber; + if (pCallbackData->pMessageIdName) + ss << ":" << pCallbackData->pMessageIdName; - struct Instance::InternalData - { - DebugReportCallbackEXT debugCallback; - DebugUtilsMessengerEXT debugMessenger; - }; + ss << "]: " << pCallbackData->pMessage; - Instance::Instance() : - m_instance(nullptr) - { - } - - Instance::~Instance() - { - if (m_instance) - DestroyInstance(); - } - - bool Instance::Create(RenderAPIValidationLevel validationLevel, const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) - { - m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance); - if (m_lastErrorCode != VkResult::VK_SUCCESS) - { - NazaraError("Failed to create Vulkan instance: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - m_apiVersion = createInfo.pApplicationInfo->apiVersion; - m_validationLevel = validationLevel; - - // Store the allocator to access them when needed - if (allocator) - m_allocator = *allocator; + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) + NazaraError(ss.str()); + else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) + NazaraWarning(ss.str()); else - m_allocator.pfnAllocation = nullptr; + NazaraNotice(ss.str()); - // Parse extensions and layers - for (UInt32 i = 0; i < createInfo.enabledExtensionCount; ++i) - m_loadedExtensions.insert(createInfo.ppEnabledExtensionNames[i]); + return VK_FALSE; //< Should the Vulkan call be aborted + } - for (UInt32 i = 0; i < createInfo.enabledLayerCount; ++i) - m_loadedLayers.insert(createInfo.ppEnabledLayerNames[i]); + VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback( + VkDebugReportFlagsEXT flags, + VkDebugReportObjectTypeEXT /*objectType*/, + uint64_t /*object*/, + size_t /*location*/, + int32_t messageCode, + const char* pLayerPrefix, + const char* pMessage, + void* /*pUserData*/) + { + std::stringstream ss; + ss << "Vulkan log: "; - // And now load everything - try - { - ErrorFlags flags(ErrorMode::ThrowException, true); + if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) + ss << "[Info]"; + + if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) + ss << "[Warning]"; + + if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) + ss << "[Error]"; + + if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) + ss << "[Performance]"; + + if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) + ss << "[Debug]"; + + ss << "[" << messageCode << "]"; + if (pLayerPrefix) + ss << "[layer " << pLayerPrefix << "]"; + + ss << ": " << pMessage; + + if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) + NazaraError(ss.str()); + else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) + NazaraWarning(ss.str()); + else + NazaraNotice(ss.str()); + + return VK_FALSE; //< Should the Vulkan call be aborted + } + } + + struct Instance::InternalData + { + DebugReportCallbackEXT debugCallback; + DebugUtilsMessengerEXT debugMessenger; + }; + + Instance::Instance() : + m_instance(nullptr) + { + } + + Instance::~Instance() + { + if (m_instance) + DestroyInstance(); + } + + bool Instance::Create(RenderAPIValidationLevel validationLevel, const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) + { + m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance); + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to create Vulkan instance: " + TranslateVulkanError(m_lastErrorCode)); + return false; + } + + m_apiVersion = createInfo.pApplicationInfo->apiVersion; + m_validationLevel = validationLevel; + + // Store the allocator to access them when needed + if (allocator) + m_allocator = *allocator; + else + m_allocator.pfnAllocation = nullptr; + + // Parse extensions and layers + for (UInt32 i = 0; i < createInfo.enabledExtensionCount; ++i) + m_loadedExtensions.insert(createInfo.ppEnabledExtensionNames[i]); + + for (UInt32 i = 0; i < createInfo.enabledLayerCount; ++i) + m_loadedLayers.insert(createInfo.ppEnabledLayerNames[i]); + + // And now load everything + try + { + ErrorFlags flags(ErrorMode::ThrowException, true); #define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) if (IsExtensionLoaded(#ext)) { \ - NazaraDebug(#ext " extension is supported"); + NazaraDebug(#ext " extension is supported"); #define NAZARA_VULKANRENDERER_INSTANCE_EXT_END() } #define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) func = reinterpret_cast(GetProcAddr(#func)); \ - if (!func) \ - NazaraWarning("failed to get a function pointer for " #func " despite its being reported as supported"); + if (!func) \ + NazaraWarning("failed to get a function pointer for " #func " despite its being reported as supported"); #define NAZARA_VULKANRENDERER_INSTANCE_CORE_EXT_FUNCTION(func, coreVersion, suffix, extName) \ - if (m_apiVersion >= coreVersion) \ - func = reinterpret_cast(GetProcAddr(#func)); \ - else if (IsExtensionLoaded("VK_" #suffix "_" #extName)) \ - func = reinterpret_cast(GetProcAddr(#func #suffix)); + if (m_apiVersion >= coreVersion) \ + func = reinterpret_cast(GetProcAddr(#func)); \ + else if (IsExtensionLoaded("VK_" #suffix "_" #extName)) \ + func = reinterpret_cast(GetProcAddr(#func #suffix)); #include - } - catch (const std::exception& e) - { - NazaraError(std::string("Failed to query instance function: ") + e.what()); - return false; - } - - m_internalData = std::make_unique(); - InstallDebugMessageCallback(); - - return true; + } + catch (const std::exception& e) + { + NazaraError(std::string("Failed to query instance function: ") + e.what()); + return false; } - bool Instance::EnumeratePhysicalDevices(std::vector* devices) const + m_internalData = std::make_unique(); + InstallDebugMessageCallback(); + + return true; + } + + bool Instance::EnumeratePhysicalDevices(std::vector* devices) const + { + NazaraAssert(devices, "Invalid device vector"); + + // First, query physical device count + UInt32 deviceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t + m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr); + if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0) { - NazaraAssert(devices, "Invalid device vector"); - - // First, query physical device count - UInt32 deviceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t - m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr); - if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0) - { - NazaraError("Failed to query physical device count: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - // Now we can get the list of the available physical device - devices->resize(deviceCount); - m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data()); - if (m_lastErrorCode != VkResult::VK_SUCCESS) - { - NazaraError("Failed to query physical devices: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - return true; + NazaraError("Failed to query physical device count: " + TranslateVulkanError(m_lastErrorCode)); + return false; } - bool Instance::GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties) const + // Now we can get the list of the available physical device + devices->resize(deviceCount); + m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data()); + if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraAssert(extensionProperties, "Invalid extension properties vector"); - - // First, query extension count - UInt32 extensionPropertyCount = 0; - m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, nullptr); - if (m_lastErrorCode != VkResult::VK_SUCCESS) - { - NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - if (extensionPropertyCount == 0) - return true; //< No extension available - - // Now we can get the list of the available extensions - extensionProperties->resize(extensionPropertyCount); - m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, extensionProperties->data()); - if (m_lastErrorCode != VkResult::VK_SUCCESS) - { - NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); - return false; - } - - return true; + NazaraError("Failed to query physical devices: " + TranslateVulkanError(m_lastErrorCode)); + return false; } - bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector* queueFamilyProperties) const + return true; + } + + bool Instance::GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties) const + { + NazaraAssert(extensionProperties, "Invalid extension properties vector"); + + // First, query extension count + UInt32 extensionPropertyCount = 0; + m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, nullptr); + if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraAssert(queueFamilyProperties, "Invalid family properties vector"); - - // First, query physical device count - UInt32 queueFamiliesCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t - vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, nullptr); - if (queueFamiliesCount == 0) - { - NazaraError("Failed to query physical device count"); - return false; - } - - // Now we can get the list of the available physical device - queueFamilyProperties->resize(queueFamiliesCount); - vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, queueFamilyProperties->data()); - - return true; + NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); + return false; } - void Instance::InstallDebugMessageCallback() + if (extensionPropertyCount == 0) + return true; //< No extension available + + // Now we can get the list of the available extensions + extensionProperties->resize(extensionPropertyCount); + m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, extensionProperties->data()); + if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraAssert(m_internalData, "Instance must be created before callbacks are installed"); + NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); + return false; + } - if (Vk::DebugUtilsMessengerEXT::IsSupported(*this)) + return true; + } + + bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector* queueFamilyProperties) const + { + NazaraAssert(queueFamilyProperties, "Invalid family properties vector"); + + // First, query physical device count + UInt32 queueFamiliesCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t + vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, nullptr); + if (queueFamiliesCount == 0) + { + NazaraError("Failed to query physical device count"); + return false; + } + + // Now we can get the list of the available physical device + queueFamilyProperties->resize(queueFamiliesCount); + vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, queueFamilyProperties->data()); + + return true; + } + + void Instance::InstallDebugMessageCallback() + { + NazaraAssert(m_internalData, "Instance must be created before callbacks are installed"); + + if (Vk::DebugUtilsMessengerEXT::IsSupported(*this)) + { + VkDebugUtilsMessengerCreateInfoEXT callbackCreateInfo = {}; + callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; + callbackCreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; + callbackCreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; + callbackCreateInfo.pfnUserCallback = &DebugMessengerCallback; + callbackCreateInfo.pUserData = this; + + if (!m_internalData->debugMessenger.Create(*this, callbackCreateInfo)) { - VkDebugUtilsMessengerCreateInfoEXT callbackCreateInfo = {}; - callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - callbackCreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; - callbackCreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; - callbackCreateInfo.pfnUserCallback = &DebugMessengerCallback; - callbackCreateInfo.pUserData = this; - - if (!m_internalData->debugMessenger.Create(*this, callbackCreateInfo)) - { - NazaraWarning("failed to install debug message callback"); - return; - } - } - else if (Vk::DebugReportCallbackEXT::IsSupported(*this)) - { - NazaraWarning(VK_EXT_DEBUG_UTILS_EXTENSION_NAME " is not supported, falling back on " VK_EXT_DEBUG_REPORT_EXTENSION_NAME); - - VkDebugReportCallbackCreateInfoEXT callbackCreateInfo = {}; - callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; - callbackCreateInfo.flags = VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_INFORMATION_BIT_EXT; - callbackCreateInfo.pfnCallback = &DebugReportCallback; - callbackCreateInfo.pUserData = this; - - if (!m_internalData->debugCallback.Create(*this, callbackCreateInfo)) - { - NazaraWarning("failed to install debug message callback"); - return; - } - } - else - { - NazaraWarning(VK_EXT_DEBUG_UTILS_EXTENSION_NAME " nor " VK_EXT_DEBUG_REPORT_EXTENSION_NAME " are not supported, cannot install debug message callback"); + NazaraWarning("failed to install debug message callback"); return; } + } + else if (Vk::DebugReportCallbackEXT::IsSupported(*this)) + { + NazaraWarning(VK_EXT_DEBUG_UTILS_EXTENSION_NAME " is not supported, falling back on " VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + VkDebugReportCallbackCreateInfoEXT callbackCreateInfo = {}; + callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; + callbackCreateInfo.flags = VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_INFORMATION_BIT_EXT; + callbackCreateInfo.pfnCallback = &DebugReportCallback; + callbackCreateInfo.pUserData = this; + + if (!m_internalData->debugCallback.Create(*this, callbackCreateInfo)) + { + NazaraWarning("failed to install debug message callback"); + return; + } + } + else + { + NazaraWarning(VK_EXT_DEBUG_UTILS_EXTENSION_NAME " nor " VK_EXT_DEBUG_REPORT_EXTENSION_NAME " are not supported, cannot install debug message callback"); + return; } - void Instance::DestroyInstance() - { - assert(m_instance != VK_NULL_HANDLE); + } - m_internalData.reset(); + void Instance::DestroyInstance() + { + assert(m_instance != VK_NULL_HANDLE); - if (vkDestroyInstance) - vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); - } + m_internalData.reset(); - void Instance::ResetPointers() - { - assert(m_instance != VK_NULL_HANDLE); - m_instance = VK_NULL_HANDLE; + if (vkDestroyInstance) + vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); + } + + void Instance::ResetPointers() + { + assert(m_instance != VK_NULL_HANDLE); + m_instance = VK_NULL_HANDLE; #define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) func = nullptr; #define NAZARA_VULKANRENDERER_INSTANCE_CORE_EXT_FUNCTION(func, ...) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) #include - } } } - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#endif