Vulkan rendering tweaks 73/317873/6
authorDavid Steele <david.steele@samsung.com>
Thu, 19 Sep 2024 17:59:12 +0000 (18:59 +0100)
committerDavid Steele <david.steele@samsung.com>
Wed, 25 Sep 2024 17:31:41 +0000 (18:31 +0100)
Adds a clip space transform matrix to convert from GL clip space to
Vulkan clip space.

Ensures we can get the current framebuffer during recording cmd
buffers from the render target.

Ensure that the color write mask is set to write RGBA bits

DALi is now rendering using Vulkan! (Still a way to go, though)

Change-Id: Id84cca07dbd61a0cf6fdff6672cd410cf365d956

automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp
automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h
dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/egl-graphics-controller.h
dali/internal/graphics/vulkan-impl/vulkan-command-buffer.cpp
dali/internal/graphics/vulkan-impl/vulkan-graphics-controller.cpp
dali/internal/graphics/vulkan-impl/vulkan-graphics-controller.h
dali/internal/graphics/vulkan-impl/vulkan-pipeline-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-render-pass-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-render-target.cpp
dali/internal/graphics/vulkan-impl/vulkan-render-target.h

index f0bc4d6d5dde5f659628ac54300d245fe7d59403..114879fb4faa9ec6e36cc41e6f9dba7419e38aef 100644 (file)
@@ -1505,4 +1505,22 @@ Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::ReleaseTextureFro
   return texture;
 }
 
+bool TestGraphicsController::HasClipMatrix() const
+{
+  return true;
+}
+
+const Matrix& TestGraphicsController::GetClipMatrix() const
+{
+  // This matrix transforms from GL -> Vulkan clip space
+  constexpr float VULKAN_CLIP_MATRIX_DATA[] = {
+    1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f};
+  static const Matrix VULKAN_CLIP_MATRIX(VULKAN_CLIP_MATRIX_DATA);
+  static const Matrix IDENTITY = Matrix::IDENTITY;
+
+  // For now, return IDENTITY to stay in GL clip space.
+  // @todo Add test toggle
+  return IDENTITY;
+}
+
 } // namespace Dali
index e21c30400f009814a08b0683288f1a7d6f5b05f3..2b0a9b97aaedb4ab9ee2facf08ba104f15b74ca6 100644 (file)
@@ -422,6 +422,9 @@ public: // ResourceId relative API.
    */
   Graphics::UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) override;
 
+  bool          HasClipMatrix() const override;
+  const Matrix& GetClipMatrix() const override;
+
 public: // Test Functions
   void SetAutoAttrCreation(bool v)
   {
@@ -499,14 +502,14 @@ public: // Test Functions
                                uint32_t                                      elementStrideInBytes)
   {
     TestGraphicsReflection::TestUniformInfo info;
-    info.name          = std::move(name);
-    info.type          = type;
-    info.uniformClass  = Graphics::UniformClass::UNIFORM;
-    info.numElements   = elementCount;
-    info.locations     = {0};
-    info.bufferIndex   = 0;                    // this will update when AddCustomUniformBlock called
-
-    auto retval= GetUniformBufferArrayStrideAndTypeSize(info, elementStrideInBytes);
+    info.name         = std::move(name);
+    info.type         = type;
+    info.uniformClass = Graphics::UniformClass::UNIFORM;
+    info.numElements  = elementCount;
+    info.locations    = {0};
+    info.bufferIndex  = 0; // this will update when AddCustomUniformBlock called
+
+    auto retval        = GetUniformBufferArrayStrideAndTypeSize(info, elementStrideInBytes);
     info.elementStride = std::max(retval.first, retval.second);
     info.offsets       = {blockInfo.size};
     blockInfo.size += (elementCount == 0 ? 1 : elementCount) * std::max(retval.first, retval.second);
@@ -567,4 +570,4 @@ public:
 
 } // namespace Dali
 
-#endif //TEST_GRAPHICS_CONTROLLER_H
+#endif // TEST_GRAPHICS_CONTROLLER_H
index 3478d680eed475066a153b1b0d04f7b0bf2e6828..aa37c0234d704ea826e3db46272bc964e382cc21 100644 (file)
@@ -383,7 +383,8 @@ void EglGraphicsController::CreateSurfaceContext(Dali::Integration::RenderSurfac
 void EglGraphicsController::DeleteSurfaceContext(Dali::Integration::RenderSurfaceInterface* surface)
 {
   mSurfaceContexts.erase(std::remove_if(
-                           mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter) { return surface == iter.first; }),
+                           mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter)
+                           { return surface == iter.first; }),
                          mSurfaceContexts.end());
 }
 
@@ -405,7 +406,8 @@ void EglGraphicsController::ActivateSurfaceContext(Dali::Integration::RenderSurf
 {
   if(surface && mGraphics->IsResourceContextSupported())
   {
-    auto iter = std::find_if(mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter) { return (iter.first == surface); });
+    auto iter = std::find_if(mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter)
+                             { return (iter.first == surface); });
 
     if(iter != mSurfaceContexts.end())
     {
@@ -494,7 +496,8 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
   auto       count    = 0u;
   const auto commands = commandBuffer.GetCommands(count);
 
-  DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_EGL_CONTROLLER_PROCESS", [&](std::ostringstream& oss) { oss << "[commandCount:" << count << "]"; });
+  DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_EGL_CONTROLLER_PROCESS", [&](std::ostringstream& oss)
+                                          { oss << "[commandCount:" << count << "]"; });
 
   for(auto i = 0u; i < count; ++i)
   {
@@ -1082,4 +1085,14 @@ Graphics::UniquePtr<Graphics::Texture> EglGraphicsController::ReleaseTextureFrom
   return texture;
 }
 
+bool EglGraphicsController::HasClipMatrix() const
+{
+  return false;
+}
+
+const Matrix& EglGraphicsController::GetClipMatrix() const
+{
+  return Matrix::IDENTITY;
+}
+
 } // namespace Dali::Graphics
index 54a4e8e89615cd9d4258888bd1b18e9f41e778c9..fcf85c96d4a51c86afd49fd1a1eb8965134338d3 100644 (file)
@@ -849,6 +849,9 @@ public:
     return mCapacity;
   }
 
+  bool          HasClipMatrix() const override;
+  const Matrix& GetClipMatrix() const override;
+
 private:
   Integration::GlAbstraction*              mGlAbstraction{nullptr};
   Integration::GlContextHelperAbstraction* mGlContextHelperAbstraction{nullptr};
index 463d4b9434b985e38aa1eb78269c42c436404b25..8d085cf08797747f457878a9433245bdc7dcf58a 100644 (file)
@@ -99,6 +99,7 @@ void CommandBuffer::Begin(const Graphics::CommandBufferBeginInfo& info)
       auto renderTarget                  = ConstGraphicsCast<Vulkan::RenderTarget, Graphics::RenderTarget>(info.renderTarget);
       inheritanceInfo.renderPass         = renderTarget->GetRenderPass(info.renderPass)->GetVkHandle();
       inheritanceInfo.subpass            = 0;
+      inheritanceInfo.framebuffer        = renderTarget->GetCurrentFramebufferImpl()->GetVkHandle();
       inheritanceInfo.queryFlags         = static_cast<vk::QueryControlFlags>(0);
       inheritanceInfo.pipelineStatistics = static_cast<vk::QueryPipelineStatisticFlags>(0);
     }
index b04cbd58572dd6e6cd2a5a208e5c74105208aeca..70877483a98ec4eb6e69d219248f8e96c9e76893 100644 (file)
@@ -192,7 +192,8 @@ struct VulkanGraphicsController::Impl
     if(!mTextureStagingBuffer ||
        mTextureStagingBuffer->GetImpl()->GetSize() < size)
     {
-      auto workerFunc = [&, size](auto workerIndex) {
+      auto workerFunc = [&, size](auto workerIndex)
+      {
         Graphics::BufferCreateInfo createInfo{};
         createInfo.SetSize(size)
           .SetUsage(0u | Dali::Graphics::BufferUsage::TRANSFER_SRC);
@@ -282,7 +283,8 @@ struct VulkanGraphicsController::Impl
         }
         assert(image);
 
-        auto predicate = [&](auto& item) -> bool {
+        auto predicate = [&](auto& item) -> bool
+        {
           return image->GetVkHandle() == item.image.GetVkHandle();
         };
         auto it = std::find_if(requestMap.begin(), requestMap.end(), predicate);
@@ -597,7 +599,8 @@ void VulkanGraphicsController::UpdateTextures(
 
         if(destTexture->GetProperties().directWriteAccessEnabled)
         {
-          auto taskLambda = [pInfo, sourcePtr, sourceInfoPtr, texture](auto workerIndex) {
+          auto taskLambda = [pInfo, sourcePtr, sourceInfoPtr, texture](auto workerIndex)
+          {
             const auto& properties = texture->GetProperties();
 
             if(properties.emulated)
@@ -632,7 +635,8 @@ void VulkanGraphicsController::UpdateTextures(
           // The staging buffer is not allocated yet. The task knows pointer to the pointer which will point
           // at staging buffer right before executing tasks. The function will either perform direct copy
           // or will do suitable conversion if source format isn't supported and emulation is available.
-          auto taskLambda = [ppStagingMemory, currentOffset, pInfo, sourcePtr, texture](auto workerThread) {
+          auto taskLambda = [ppStagingMemory, currentOffset, pInfo, sourcePtr, texture](auto workerThread)
+          {
             char* pStagingMemory = reinterpret_cast<char*>(*ppStagingMemory);
 
             // Try to initialise` texture resources explicitly if they are not yet initialised
@@ -670,7 +674,8 @@ void VulkanGraphicsController::UpdateTextures(
   for(auto& item : updateMap)
   {
     auto pUpdates = &item.second;
-    auto task     = [pUpdates](auto workerIndex) {
+    auto task     = [pUpdates](auto workerIndex)
+    {
       for(auto& update : *pUpdates)
       {
         update.copyTask(workerIndex);
@@ -1083,4 +1088,17 @@ std::size_t VulkanGraphicsController::GetCapacity() const
   return mImpl->mCapacity;
 }
 
+bool VulkanGraphicsController::HasClipMatrix() const
+{
+  return true;
+}
+
+const Matrix& VulkanGraphicsController::GetClipMatrix() const
+{
+  constexpr float CLIP_MATRIX_DATA[] = {
+    1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f};
+  static const Matrix CLIP_MATRIX(CLIP_MATRIX_DATA);
+  return CLIP_MATRIX;
+}
+
 } // namespace Dali::Graphics::Vulkan
index 2c76e20b0240d9baacfbcbbb033ff320409dd34d..a21f735045f58b8806e073063a3674f1ffb1b47a 100644 (file)
@@ -417,6 +417,16 @@ public: // ResourceId relative API.
    */
   UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) override;
 
+  /**
+   * @return true if there is a clip space transform matrix
+   */
+  bool HasClipMatrix() const override;
+
+  /**
+   * @return the clip space transform matrix
+   */
+  const Matrix& GetClipMatrix() const override;
+
 public: // For debug
   void FrameStart();
 
index 14be67635f3b430fa696f8885174fc173f8088c5..becd5d085461709b6702cf17fae04c418beae8b6 100644 (file)
@@ -831,8 +831,11 @@ void PipelineImpl::InitializeColorBlendState(vk::PipelineColorBlendStateCreateIn
 
   att.setAlphaBlendOp(ConvBlendOp(in->alphaBlendOp));
   att.setBlendEnable(in->blendEnable);
+  //att.setColorWriteMask()
   att.setColorBlendOp(ConvBlendOp(in->colorBlendOp));
   att.setColorWriteMask(vk::ColorComponentFlags(in->colorComponentWriteBits));
+  att.setColorWriteMask(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
+                        vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
   att.setDstAlphaBlendFactor(ConvBlendFactor(in->dstAlphaBlendFactor));
   att.setDstColorBlendFactor(ConvBlendFactor(in->dstColorBlendFactor));
   att.setSrcAlphaBlendFactor(ConvBlendFactor(in->srcAlphaBlendFactor));
index 67a6f1f3e6d18cee2847419481f2d65ceab1fd6b..eceb474669330b1336354c9ba70f929da0b9bf27 100644 (file)
@@ -29,7 +29,6 @@ extern Debug::Filter* gVulkanFilter;
 
 namespace Dali::Graphics::Vulkan
 {
-
 RenderPassImpl* RenderPassImpl::New(
   Vulkan::Device&                            device,
   const std::vector<FramebufferAttachment*>& colorAttachments,
@@ -173,10 +172,12 @@ void RenderPassImpl::CreateCompatibleCreateInfo(
       .setDstAccessMask(vk::AccessFlagBits::eMemoryRead)
       .setDependencyFlags(vk::DependencyFlagBits::eByRegion)};
 
-  mCreateInfo.createInfo.setAttachmentCount(U32(mCreateInfo.attachmentDescriptions.size()))
+  mCreateInfo.createInfo
+    .setAttachmentCount(U32(mCreateInfo.attachmentDescriptions.size()))
     .setPAttachments(mCreateInfo.attachmentDescriptions.data())
     .setPSubpasses(&mCreateInfo.subpassDesc)
     .setSubpassCount(1)
+    .setDependencyCount(2)
     .setPDependencies(mCreateInfo.subpassDependencies.data());
 }
 
index 10df9e06102472bc3e9b770a5d054849bb5de31e..1dbd4c207785a14021ae5fd2b5b68e666d06f15c 100644 (file)
@@ -67,10 +67,8 @@ Integration::RenderSurfaceInterface* RenderTarget::GetSurface() const
   return mCreateInfo.surface;
 }
 
-Vulkan::RenderPassImpl* RenderTarget::GetRenderPass(const Graphics::RenderPass* gfxRenderPass) const
+Vulkan::FramebufferImpl* RenderTarget::GetCurrentFramebufferImpl() const
 {
-  auto renderPass = const_cast<Vulkan::RenderPass*>(static_cast<const Vulkan::RenderPass*>(gfxRenderPass));
-
   auto framebuffer = GetFramebuffer();
   auto surface     = GetSurface();
 
@@ -86,8 +84,14 @@ Vulkan::RenderPassImpl* RenderTarget::GetRenderPass(const Graphics::RenderPass*
   {
     fbImpl = framebuffer->GetImpl();
   }
+  return fbImpl;
+}
 
-  return fbImpl->GetImplFromRenderPass(renderPass);
+Vulkan::RenderPassImpl* RenderTarget::GetRenderPass(const Graphics::RenderPass* gfxRenderPass) const
+{
+  auto renderPass      = const_cast<Vulkan::RenderPass*>(static_cast<const Vulkan::RenderPass*>(gfxRenderPass));
+  auto framebufferImpl = GetCurrentFramebufferImpl();
+  return framebufferImpl->GetImplFromRenderPass(renderPass);
 }
 
 } // namespace Dali::Graphics::Vulkan
index 3002a3abf14d71c385b0c969493e9552f9b2ab4e..d3c43100211a68a0c69cdf32580729848a70c26e 100644 (file)
@@ -70,6 +70,13 @@ public:
    */
   [[nodiscard]] Integration::RenderSurfaceInterface* GetSurface() const;
 
+  /**
+   * @brief Returns the current framebuffer impl for this frame.
+   * (May be either the swapchain's current fb, or the offscreen's fb).
+   * @return the current framebuffer
+   */
+  [[nodiscard]] Vulkan::FramebufferImpl* GetCurrentFramebufferImpl() const;
+
   /**
    * Find a matching render pass for this render target
    * @param[in] renderPass A render pass to search for