[Vulkan] Support for clear color in Swapchain
authoradam.b <jsr184@gmail.com>
Fri, 25 May 2018 13:45:50 +0000 (14:45 +0100)
committeradam.b <jsr184@gmail.com>
Fri, 25 May 2018 14:00:50 +0000 (15:00 +0100)
Change-Id: I69c0f44539183a915b7a6309b5bc5ede3ced69a7

dali/graphics/vulkan/vulkan-pipeline-cache.h
dali/graphics/vulkan/vulkan-swapchain.cpp
dali/graphics/vulkan/vulkan-swapchain.h

index a8bba0b..17617ea 100644 (file)
@@ -20,7 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/graphics/vulkan/vulkan-types.h>
-
+#include <dali/graphics-api/graphics-api-render-command.h>
 namespace Dali
 {
 namespace Graphics
@@ -34,10 +34,13 @@ struct PipelineDescription
   ShaderRef vertexShader;
   ShaderRef fragmentShader;
 
+  API::RenderCommand::RenderState::BlendState blendState;
+
   bool operator==(const PipelineDescription& description) const
   {
     return (vertexShader == description.vertexShader) &&
-           (fragmentShader == description.fragmentShader);
+           (fragmentShader == description.fragmentShader) &&
+           (std::memcmp( &blendState, &description.blendState, sizeof(blendState) ));
   }
 
   std::vector<vk::DescriptorSetLayout> descriptorSetLayouts;
index a7c858c..35dcc06 100644 (file)
@@ -255,7 +255,6 @@ struct Swapchain::Impl
     mQueue.Submit( cmdBuffer, FenceRef{} );
     mQueue.WaitIdle();
   }
-#pragma GCC diagnostic pop
 
   bool SetImageFormat()
   {
@@ -439,14 +438,13 @@ struct Swapchain::Impl
     }
     swapBuffer.firstUse = false;
 
-    // Begins primary render pass
-    BeginPrimaryRenderPass( swapBuffer );
-
     return swapBuffer.framebuffer;
   }
-#pragma GCC diagnostic pop
-  void BeginPrimaryRenderPass( SwapchainBuffer& currentBuffer )
+
+  void BeginPrimaryRenderPass()
   {
+    auto& currentBuffer = mSwapchainBuffer[mCurrentBufferIndex];
+
     vk::RenderPassBeginInfo rpInfo{};
     rpInfo.setRenderPass( currentBuffer.framebuffer->GetVkRenderPass() )
       .setFramebuffer( currentBuffer.framebuffer->GetVkFramebuffer() )
@@ -457,6 +455,28 @@ struct Swapchain::Impl
     currentBuffer.masterCmdBuffer->BeginRenderPass( rpInfo, vk::SubpassContents::eSecondaryCommandBuffers );
   }
 
+  void BeginPrimaryRenderPass( std::vector<std::array<float,4>> colors )
+  {
+    auto& currentBuffer = mSwapchainBuffer[mCurrentBufferIndex];
+
+    vk::RenderPassBeginInfo rpInfo{};
+
+    auto newColors = currentBuffer.framebuffer->GetDefaultClearValues();
+    newColors[0].color.setFloat32( { colors[0][0],
+                                     colors[0][1],
+                                     colors[0][2],
+                                     colors[0][3]
+                                   } );
+
+    rpInfo.setRenderArea( vk::Rect2D( {0, 0}, mSurface->GetSize() ) )
+          .setRenderPass( currentBuffer.framebuffer->GetVkRenderPass() )
+          .setFramebuffer( currentBuffer.framebuffer->GetVkFramebuffer() )
+          .setPClearValues( newColors.data() )
+          .setClearValueCount( U32( currentBuffer.framebuffer->GetDefaultClearValues().size() ) );
+
+    currentBuffer.masterCmdBuffer->BeginRenderPass( rpInfo, vk::SubpassContents::eSecondaryCommandBuffers );
+  }
+
   void EndPrimaryRenderPass( SwapchainBuffer& currentBuffer )
   {
     currentBuffer.masterCmdBuffer->EndRenderPass();
@@ -468,8 +488,6 @@ struct Swapchain::Impl
    * The master command buffer must be in the recording state
    * @param swapBuffer
    */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
   void UpdateLayoutPresentToColorAttachment( SwapchainBuffer& swapBuffer )
   {
     auto& cmdBuf = swapBuffer.masterCmdBuffer;
@@ -501,7 +519,6 @@ struct Swapchain::Impl
                              std::vector<vk::BufferMemoryBarrier>{},
                              barriers );
   }
-#pragma GCC diagnostic pop
 
   CommandBufferRef GetPrimaryCommandBuffer() const
   {
@@ -639,6 +656,17 @@ CommandBufferRef Swapchain::GetPrimaryCommandBuffer() const
   return mImpl->GetPrimaryCommandBuffer();
 }
 
+void Swapchain::BeginPrimaryRenderPass()
+{
+  mImpl->BeginPrimaryRenderPass( );
+}
+
+void Swapchain::BeginPrimaryRenderPass( std::vector<std::array<float,4>> colors )
+{
+  mImpl->BeginPrimaryRenderPass( colors );
+}
+
+
 } // namespace Vulkan
 } // namespace Graphics
 } // namespace Dali
index 23141f9..9081f85 100644 (file)
@@ -71,6 +71,17 @@ public:
   CommandBufferRef GetPrimaryCommandBuffer() const;
 
   /**
+   * Begins primary render pass, must be called after acquiring new image
+   */
+  void BeginPrimaryRenderPass();
+
+  /**
+   * Begins primary render pass, must be called after acquiring new image
+   * @param beginInfo custom initialisation structure
+   */
+  void BeginPrimaryRenderPass( std::vector<std::array<float,4>> colors );
+
+  /**
    * Presents using default present queue, asynchronously
    */
   void Present();