Add initial support for compute pipelines
This commit is contained in:
committed by
Jérôme Leclercq
parent
e4064997d8
commit
9578ba3ef5
@@ -382,8 +382,9 @@ namespace Nz
|
||||
{
|
||||
switch (bindingType)
|
||||
{
|
||||
case ShaderBindingType::Sampler: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
case ShaderBindingType::StorageBuffer: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
case ShaderBindingType::Texture: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
case ShaderBindingType::Texture: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
case ShaderBindingType::UniformBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
}
|
||||
|
||||
@@ -395,6 +396,7 @@ namespace Nz
|
||||
{
|
||||
switch (stageType)
|
||||
{
|
||||
case nzsl::ShaderStageType::Compute: return VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
case nzsl::ShaderStageType::Fragment: return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
case nzsl::ShaderStageType::Vertex: return VK_SHADER_STAGE_VERTEX_BIT;
|
||||
}
|
||||
@@ -459,6 +461,7 @@ namespace Nz
|
||||
case TextureUsage::ColorAttachment: return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
case TextureUsage::DepthStencilAttachment: return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
case TextureUsage::InputAttachment: return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
case TextureUsage::ShaderReadWrite: return VK_IMAGE_USAGE_STORAGE_BIT;
|
||||
case TextureUsage::ShaderSampling: return VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
case TextureUsage::TransferSource: return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
case TextureUsage::TransferDestination: return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
|
||||
@@ -27,8 +27,9 @@ namespace Nz
|
||||
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
||||
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
||||
|
||||
void BindComputePipeline(const ComputePipeline& pipeline) override;
|
||||
void BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset = 0) override;
|
||||
void BindPipeline(const RenderPipeline& pipeline) override;
|
||||
void BindRenderPipeline(const RenderPipeline& pipeline) override;
|
||||
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
||||
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
||||
void BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset = 0) override;
|
||||
@@ -39,6 +40,8 @@ namespace Nz
|
||||
void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0) override;
|
||||
void CopyTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Vector3ui& toPos, TextureLayout toLayout) override;
|
||||
|
||||
void Dispatch(UInt32 workgroupX, UInt32 workgroupY, UInt32 workgroupZ) override;
|
||||
|
||||
void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
|
||||
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstIndex = 0, UInt32 firstInstance = 0) override;
|
||||
|
||||
|
||||
45
include/Nazara/VulkanRenderer/VulkanComputePipeline.hpp
Normal file
45
include/Nazara/VulkanRenderer/VulkanComputePipeline.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Vulkan renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANCOMPUTEPIPELINE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANCOMPUTEPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Renderer/ComputePipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Pipeline.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class VulkanDevice;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API VulkanComputePipeline : public ComputePipeline
|
||||
{
|
||||
public:
|
||||
VulkanComputePipeline(VulkanDevice& device, ComputePipelineInfo pipelineInfo);
|
||||
VulkanComputePipeline(const VulkanComputePipeline&) = delete;
|
||||
VulkanComputePipeline(VulkanComputePipeline&&) = delete;
|
||||
~VulkanComputePipeline() = default;
|
||||
|
||||
inline const Vk::Pipeline& GetPipeline() const;
|
||||
inline const ComputePipelineInfo& GetPipelineInfo() const override;
|
||||
|
||||
void UpdateDebugName(std::string_view name) override;
|
||||
|
||||
VulkanComputePipeline& operator=(const VulkanComputePipeline&) = delete;
|
||||
VulkanComputePipeline& operator=(VulkanComputePipeline&&) = delete;
|
||||
|
||||
private:
|
||||
Vk::Pipeline m_pipeline;
|
||||
ComputePipelineInfo m_pipelineInfo;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanComputePipeline.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VULKANCOMPUTEPIPELINE_HPP
|
||||
21
include/Nazara/VulkanRenderer/VulkanComputePipeline.inl
Normal file
21
include/Nazara/VulkanRenderer/VulkanComputePipeline.inl
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Vulkan renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanComputePipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const Vk::Pipeline& VulkanComputePipeline::GetPipeline() const
|
||||
{
|
||||
return m_pipeline;
|
||||
}
|
||||
|
||||
inline const ComputePipelineInfo& VulkanComputePipeline::GetPipelineInfo() const
|
||||
{
|
||||
return m_pipelineInfo;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
@@ -28,6 +28,7 @@ namespace Nz
|
||||
|
||||
std::shared_ptr<RenderBuffer> InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData = nullptr) override;
|
||||
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
||||
std::shared_ptr<ComputePipeline> InstantiateComputePipeline(ComputePipelineInfo pipelineInfo) override;
|
||||
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
||||
std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) override;
|
||||
std::shared_ptr<RenderPipeline> InstantiateRenderPipeline(RenderPipelineInfo pipelineInfo) override;
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace Nz
|
||||
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 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);
|
||||
|
||||
|
||||
@@ -302,6 +302,11 @@ namespace Nz
|
||||
return m_pool->GetDevice()->vkCmdCopyImage(m_handle, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, regions);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Dispatch(UInt32 groupCountX, UInt32 groupCountY, UInt32 groupCountZ)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDispatch(m_handle, groupCountX, groupCountY, groupCountZ);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
|
||||
Reference in New Issue
Block a user