VulkanRenderer: Fix unitybuild causing #define issue because of Windows.h

This commit is contained in:
SirLynix
2023-04-12 14:13:34 +02:00
parent f034e71ba4
commit d717335bca
31 changed files with 652 additions and 739 deletions

View File

@@ -14,120 +14,117 @@
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
#include <vulkan/vulkan_core.h>
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<CommandBuffer>
{
public:
using AutoFree::AutoFree;
class AutoCommandBuffer : public AutoFree<CommandBuffer>
{
public:
using AutoFree::AutoFree;
operator VkCommandBuffer() const { return Get(); }
};
}
operator VkCommandBuffer() const { return Get(); }
};
}
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl>

View File

@@ -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)

View File

@@ -7,158 +7,155 @@
#include <cassert>
#include <Nazara/VulkanRenderer/Debug.hpp>
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;
}
}

View File

@@ -21,17 +21,24 @@
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
#include <wayland-client.h>
#include <vulkan/vulkan_wayland.h>
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
#include <windows.h>
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 <vulkan/vulkan_win32.h>
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
#include <xcb/xcb.h>
struct xcb_connection_t;
typedef uint32_t xcb_window_t;
typedef uint32_t xcb_visualid_t;
#include <vulkan/vulkan_xcb.h>
#endif
@@ -48,72 +55,69 @@ typedef unsigned long VisualID;
#include <vulkan/vulkan_xlib.h>
#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<const char*>& layers, const std::vector<const char*>& 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<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator = nullptr);
inline void Destroy();
bool EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* physicalDevices) const;
bool EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* 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<VkExtensionProperties>* 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<VkQueueFamilyProperties>* queueFamilyProperties) const;
inline PFN_vkVoidFunction GetProcAddr(const char* name) const;
inline RenderAPIValidationLevel GetValidationLevel() const;
bool GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector<VkExtensionProperties>* 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<VkQueueFamilyProperties>* 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 <Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp>
private:
void DestroyInstance();
void ResetPointers();
private:
void DestroyInstance();
void ResetPointers();
struct InternalData;
struct InternalData;
std::unique_ptr<InternalData> m_internalData;
std::unordered_set<std::string> m_loadedExtensions;
std::unordered_set<std::string> m_loadedLayers;
VkAllocationCallbacks m_allocator;
VkInstance m_instance;
mutable VkResult m_lastErrorCode;
RenderAPIValidationLevel m_validationLevel;
UInt32 m_apiVersion;
};
}
std::unique_ptr<InternalData> m_internalData;
std::unordered_set<std::string> m_loadedExtensions;
std::unordered_set<std::string> m_loadedLayers;
VkAllocationCallbacks m_allocator;
VkInstance m_instance;
mutable VkResult m_lastErrorCode;
RenderAPIValidationLevel m_validationLevel;
UInt32 m_apiVersion;
};
}
#include <Nazara/VulkanRenderer/Wrapper/Instance.inl>

View File

@@ -7,143 +7,140 @@
#include <cassert>
#include <Nazara/VulkanRenderer/Debug.hpp>
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<const char*>& layers, const std::vector<const char*>& 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<const char*>& layers, const std::vector<const char*>& 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<UInt32>(layers.size()),
(!layers.empty()) ? layers.data() : nullptr,
static_cast<UInt32>(extensions.size()),
(!extensions.empty()) ? extensions.data() : nullptr
};
VkInstanceCreateInfo instanceInfo =
{
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
nullptr,
0,
&appInfo,
static_cast<UInt32>(layers.size()),
(!layers.empty()) ? layers.data() : nullptr,
static_cast<UInt32>(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;
}
}