// INTERNAL INCLUDES
#include <dali/internal/graphics/vulkan-impl/vulkan-buffer-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-buffer.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-command-buffer.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-command-pool-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-framebuffer-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-image-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-pipeline-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-swapchain-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-types.h>
#include <dali/internal/graphics/vulkan/vulkan-device.h>
{
namespace Vulkan
{
-
CommandBufferImpl::CommandBufferImpl(CommandPool& commandPool,
uint32_t poolIndex,
const vk::CommandBufferAllocateInfo& allocateInfo,
mGraphicsDevice->GetLogicalDevice().freeCommandBuffers(mOwnerCommandPool->GetVkHandle(), mCommandBuffer);
}
+void CommandBufferImpl::BindPipeline(const Graphics::Pipeline* pipeline)
+{
+ assert(mCommandBuffer && "Invalid command buffer!");
+ assert(mRecording && "Can't bind pipeline when buffer isn't recording!");
+ assert(pipeline && "Can't bind null pipeline!");
+
+ auto& pipelineImpl = static_cast<const Vulkan::Pipeline*>(pipeline)->GetImpl();
+
+ // Bind if pipeline is ready (if nullptr, pipeline isn't ready).
+ // If pipeline is valid, bind it early
+ if(pipelineImpl.GetVkPipeline())
+ {
+ mCommandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipelineImpl.GetVkPipeline());
+ }
+}
+
vk::CommandBuffer CommandBufferImpl::GetVkHandle() const
{
return mCommandBuffer;
return true;
}
+void CommandBufferImpl::Draw(uint32_t vertexCount,
+ uint32_t instanceCount,
+ uint32_t firstVertex,
+ uint32_t firstInstance)
+{
+}
+
+void CommandBufferImpl::DrawIndexed(uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t vertexOffset,
+ uint32_t firstInstance)
+{
+}
+
+void CommandBufferImpl::DrawIndexedIndirect(Graphics::Buffer& buffer,
+ uint32_t offset,
+ uint32_t drawCount,
+ uint32_t stride)
+{
+}
+
+void CommandBufferImpl::ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers)
+{
+}
+
} // namespace Vulkan
} // namespace Graphics
} // namespace Dali
class Buffer;
class Device;
class CommandPool;
+class PipelineImpl;
class CommandBufferImpl : public VkManaged
{
/** Free command buffer */
void Free();
+ /** Binds Vulkan pipeline */
+ void BindPipeline(const Graphics::Pipeline* pipeline);
+
+ /** Final validation of the pipeline */
+ void ValidatePipeline();
+
/** Returns Vulkan object associated with the buffer */
[[nodiscard]] vk::CommandBuffer GetVkHandle() const;
*/
bool OnDestroy() override;
+ void Draw(
+ uint32_t vertexCount,
+ uint32_t instanceCount,
+ uint32_t firstVertex,
+ uint32_t firstInstance);
+
+ void DrawIndexed(
+ uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t vertexOffset,
+ uint32_t firstInstance);
+
+ void DrawIndexedIndirect(
+ Graphics::Buffer& buffer,
+ uint32_t offset,
+ uint32_t drawCount,
+ uint32_t stride);
+
+ void ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers);
+
private:
/**
* Returns allocation index
namespace Dali::Graphics::Vulkan
{
-
CommandBuffer::CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, VulkanGraphicsController& controller)
: CommandBufferResource(createInfo, controller),
mCommandBufferImpl(nullptr)
void CommandBuffer::BindPipeline(const Graphics::Pipeline& pipeline)
{
+ mCommandBufferImpl->BindPipeline(&pipeline);
}
void CommandBuffer::BindTextures(const std::vector<TextureBinding>& textureBindings)
uint32_t firstVertex,
uint32_t firstInstance)
{
+ mCommandBufferImpl->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
}
void CommandBuffer::DrawIndexed(uint32_t indexCount,
int32_t vertexOffset,
uint32_t firstInstance)
{
+ mCommandBufferImpl->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
}
void CommandBuffer::DrawIndexedIndirect(Graphics::Buffer& buffer,
uint32_t drawCount,
uint32_t stride)
{
+ mCommandBufferImpl->DrawIndexedIndirect(buffer, offset, drawCount, stride);
}
void CommandBuffer::DrawNative(const DrawNativeInfo* drawInfo)
namespace Dali::Graphics::Vulkan
{
-
FramebufferAttachment* FramebufferAttachment::NewColorAttachment(ImageView* imageView,
vk::ClearColorValue clearColorValue,
bool presentable)
std::transform(attachments.cbegin(),
attachments.cend(),
std::back_inserter(imageViewAttachments),
- [&](FramebufferAttachment* entry)
- {
+ [&](FramebufferAttachment* entry) {
return entry->GetImageView()->GetVkHandle();
});
return 0u;
}
+uint32_t FramebufferImpl::GetRenderPassCount() const
+{
+ return uint32_t(mRenderPasses.size());
+}
+
+RenderPassImpl* FramebufferImpl::GetRenderPass(uint32_t index) const
+{
+ if(index < mRenderPasses.size())
+ {
+ return mRenderPasses[index].renderPassImpl;
+ }
+ return nullptr;
+}
+
RenderPassImpl* FramebufferImpl::GetRenderPass(RenderPass* renderPass)
{
auto attachments = renderPass->GetCreateInfo().attachments;
std::transform(mAttachments.begin(), // @todo & color clear enabled / depth clear enabled
mAttachments.end(),
std::back_inserter(result),
- [](FramebufferAttachment* attachment)
- {
+ [](FramebufferAttachment* attachment) {
return attachment->GetClearValue();
});
auto allocator = &mGraphicsDevice->GetAllocator();
- mGraphicsDevice->DiscardResource([device, frameBuffer, renderPass, allocator]()
- {
+ mGraphicsDevice->DiscardResource([device, frameBuffer, renderPass, allocator]() {
DALI_LOG_INFO(gVulkanFilter, Debug::General, "Invoking deleter function: framebuffer->%p\n", static_cast<VkFramebuffer>(frameBuffer))
device.destroyFramebuffer(frameBuffer, allocator);
[[nodiscard]] RenderPassImpl* GetRenderPass(RenderPass* renderPass); // May mutate mRenderPasses
+ [[nodiscard]] RenderPassImpl* GetRenderPass(uint32_t index) const;
+
+ [[nodiscard]] uint32_t GetRenderPassCount() const;
+
[[nodiscard]] vk::Framebuffer GetVkHandle() const;
[[nodiscard]] std::vector<vk::ClearValue> GetClearValues() const;
#include <vulkan/vulkan.hpp>
// INTERNAL INCLUDES
+#include <dali/internal/graphics/vulkan-impl/vulkan-framebuffer-impl.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-graphics-controller.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-program-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-render-pass-impl.h>
#include <dali/internal/graphics/vulkan/vulkan-device.h>
+#include <dali/internal/window-system/common/window-render-surface.h>
namespace Dali::Graphics::Vulkan
{
RasterizationState rasterizationState;
VertexInputState vertexInputState;
InputAssemblyState inputAssemblyState;
-
- PipelineCache* pipelineCache{};
+ RenderTarget* renderTarget;
+ PipelineCache* pipelineCache{};
};
PipelineImpl::PipelineImpl(const Graphics::PipelineCreateInfo& createInfo, VulkanGraphicsController& controller, PipelineCache* pipelineCache)
CopyStateIfSet(createInfo.colorBlendState, mPipelineState->colorBlendState, &mCreateInfo.colorBlendState);
CopyStateIfSet(createInfo.depthStencilState, mPipelineState->depthStencilState, &mCreateInfo.depthStencilState);
CopyStateIfSet(createInfo.viewportState, mPipelineState->viewportState, &mCreateInfo.viewportState);
+ mCreateInfo.renderTarget = createInfo.renderTarget;
InitializePipeline();
}
{
}
+vk::Pipeline PipelineImpl::GetVkPipeline() const
+{
+ return mVkPipelines[0].pipeline;
+}
+
void PipelineImpl::Retain()
{
//++mRefCount;
gfxPipelineInfo.setBasePipelineHandle(nullptr);
gfxPipelineInfo.setBasePipelineIndex(0);
- // TODO: to resolve
- gfxPipelineInfo.setRenderPass({});
- gfxPipelineInfo.setSubpass({});
-
// 1. PipelineVertexInputStateCreateInfo
vk::PipelineVertexInputStateCreateInfo visInfo;
InitializeVertexInputState(visInfo);
// 8. PipelineColorBlendStateCreateInfo
vk::PipelineColorBlendStateCreateInfo bsInfo;
+ InitializeColorBlendState(bsInfo);
gfxPipelineInfo.setPColorBlendState(&bsInfo);
// 9. PipelineDynamicStateCreateInfo
dynInfo.setDynamicStates(mDynamicStates);
gfxPipelineInfo.setPDynamicState(&dynInfo);
- auto& allocator = mController.GetGraphicsDevice().GetAllocator();
+ auto& allocator = mController.GetGraphicsDevice().GetAllocator();
+ auto rtImpl = static_cast<Vulkan::RenderTarget*>(mCreateInfo.renderTarget);
+ auto framebuffer = rtImpl->GetFramebuffer();
+ auto surface = rtImpl->GetSurface();
- VkAssert(vkDevice.createGraphicsPipelines(VK_NULL_HANDLE,
- 1,
- &gfxPipelineInfo,
- &allocator,
- &mVkPipeline));
+ FramebufferImpl* fbImpl = nullptr;
+ if(surface)
+ {
+ auto& gfxDevice = mController.GetGraphicsDevice();
+ auto surfaceId = static_cast<Internal::Adaptor::WindowRenderSurface*>(surface)->GetSurfaceId();
+ auto swapchain = gfxDevice.GetSwapchainForSurfaceId(surfaceId);
+ fbImpl = swapchain->GetCurrentFramebuffer();
+ }
+ else if(framebuffer)
+ {
+ fbImpl = framebuffer->GetImpl();
+ }
+
+ auto renderPassCount = fbImpl->GetRenderPassCount();
+ for(auto i = 0u; i < renderPassCount; ++i)
+ {
+ RenderPassImpl* impl = fbImpl->GetRenderPass(i);
+ gfxPipelineInfo.renderPass = impl->GetVkHandle();
+ gfxPipelineInfo.subpass = 0;
+
+ if(gfxPipelineInfo.pColorBlendState)
+ {
+ auto attachmentCount = impl->GetAttachments().size();
+
+ if(attachmentCount != mBlendStateAttachments.size())
+ {
+ // Make sure array is 1
+ mBlendStateAttachments.resize(1);
+
+ // make it the right size
+ mBlendStateAttachments.resize(attachmentCount);
+
+ // Fill with defaults
+ std::fill(mBlendStateAttachments.begin() + 1, mBlendStateAttachments.end(), mBlendStateAttachments[0]);
+ const_cast<vk::PipelineColorBlendStateCreateInfo*>(gfxPipelineInfo.pColorBlendState)->attachmentCount = attachmentCount;
+ const_cast<vk::PipelineColorBlendStateCreateInfo*>(gfxPipelineInfo.pColorBlendState)->pAttachments = mBlendStateAttachments.data();
+ }
+ }
+
+ vk::Pipeline vkPipeline;
+ VkAssert(vkDevice.createGraphicsPipelines(VK_NULL_HANDLE,
+ 1,
+ &gfxPipelineInfo,
+ &allocator,
+ &vkPipeline));
+
+ RenderPassPipelinePair item;
+ item.renderPass = nullptr;
+ item.pipeline = vkPipeline;
+ mVkPipelines.emplace_back(item);
+ }
}
void PipelineImpl::InitializeVertexInputState(vk::PipelineVertexInputStateCreateInfo& out)
#include <dali/internal/graphics/vulkan-impl/vulkan-graphics-resource.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-pipeline.h>
#include <dali/internal/graphics/vulkan-impl/vulkan-reflection.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-render-pass.h>
namespace Dali::Graphics::Vulkan
{
*/
[[nodiscard]] VulkanGraphicsController& GetController() const;
-private:
+ vk::Pipeline GetVkPipeline() const;
+
void InitializePipeline();
+private:
void InitializeVertexInputState(vk::PipelineVertexInputStateCreateInfo& out);
void InitializeInputAssemblyState(vk::PipelineInputAssemblyStateCreateInfo& out) const;
void InitializeViewportState(vk::PipelineViewportStateCreateInfo& out);
std::vector<vk::DynamicState> mDynamicStates;
- vk::Pipeline mVkPipeline;
+ struct RenderPassPipelinePair
+ {
+ Graphics::RenderPass* renderPass;
+ vk::Pipeline pipeline;
+ };
+
+ std::vector<RenderPassPipelinePair> mVkPipelines;
};
} // namespace Dali::Graphics::Vulkan
*
* @return Valid pipeline implementation
*/
- [[nodiscard]] auto& GetPipeline() const
+ [[nodiscard]] Vulkan::PipelineImpl& GetImpl() const
{
- return mPipeline;
+ return *mPipeline;
}
/**