[Vulkan] New Image and ImageView for Swapchain
authoradam.b <jsr184@gmail.com>
Wed, 31 Jan 2018 16:37:25 +0000 (16:37 +0000)
committeradam.b <jsr184@gmail.com>
Fri, 9 Feb 2018 18:39:18 +0000 (18:39 +0000)
- Minor refactoring ( using Ref rather than Handle )
- Rewritten Image and ImageView
- Added Framebuffer (incomplete yet)
- Swapchain uses new Image/ImageView API

Change-Id: I81a9bd221b370ec2b505111201a98472ab1d10ba

12 files changed:
dali/graphics/vulkan/gpu-memory/vulkan-gpu-memory-allocator.h
dali/graphics/vulkan/gpu-memory/vulkan-gpu-memory-handle.h
dali/graphics/vulkan/gpu-memory/vulkan-gpu-memory-manager.cpp
dali/graphics/vulkan/vulkan-buffer.cpp
dali/graphics/vulkan/vulkan-buffer.h
dali/graphics/vulkan/vulkan-command-buffer.cpp
dali/graphics/vulkan/vulkan-framebuffer.cpp
dali/graphics/vulkan/vulkan-image.cpp
dali/graphics/vulkan/vulkan-image.h
dali/graphics/vulkan/vulkan-standalone-test.cpp
dali/graphics/vulkan/vulkan-surface.cpp
dali/graphics/vulkan/vulkan-types.h

index 66d75d2..14d9b39 100644 (file)
@@ -50,7 +50,7 @@ public:
    * @param memoryProperties
    * @return
    */
-  virtual GpuMemoryBlockHandle Allocate( const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags memoryProperties ) = 0;
+  virtual GpuMemoryBlockRef Allocate( const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags memoryProperties ) = 0;
 
   /**
    *
@@ -58,7 +58,7 @@ public:
    * @param memoryProperties
    * @return
    */
-  virtual GpuMemoryBlockHandle Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
+  virtual GpuMemoryBlockRef Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
 
   /**
    *
@@ -66,7 +66,7 @@ public:
    * @param memoryProperties
    * @return
    */
-  virtual GpuMemoryBlockHandle Allocate( Image& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
+  virtual GpuMemoryBlockRef Allocate( Image& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
 
   // refcounting managed via allocator which ownes all the blocks, allocator may
   // implement this feature any way ( or simply ignore it )
index 1a30f87..65933a1 100644 (file)
@@ -113,8 +113,6 @@ private:
   std::unique_ptr<Any>        mAllocationData; // may be any POD object pointer, depends on allocator
 };
 
-using GpuMemoryBlockHandle = Handle<GpuMemoryBlock>;
-
 }
 }
 }
index 7fc9a64..b979b56 100644 (file)
@@ -83,7 +83,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
   ~GpuMemoryDefaultAllocator() override = default;
 
 
-  GpuMemoryBlockHandle Allocate( const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags memoryProperties ) override
+  GpuMemoryBlockRef Allocate( const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags memoryProperties ) override
   {
 
     auto memoryTypeIndex = GetMemoryIndex(mGraphics.GetMemoryProperties(), requirements.memoryTypeBits,
@@ -96,7 +96,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
                                  .setAllocationSize(requirements.size), mGraphics.GetAllocator()));
 
     // add allocated memory to the heap of memories as a base handle
-    auto handle = GpuMemoryBlockHandle( new GpuMemoryBlock( *this, MakeUnique<MemoryBlock>() ) );
+    auto handle = GpuMemoryBlockRef( new GpuMemoryBlock( *this, MakeUnique<MemoryBlock>() ) );
 
     auto &block = *handle->GetData<MemoryBlock>();
     block.requirements = requirements;
@@ -105,7 +105,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
     block.alignment    = requirements.alignment;
     block.memory       = memory;
 
-    mUniqueBlocks.emplace_back( MakeUnique<GpuMemoryBlockHandle>(handle) );
+    mUniqueBlocks.emplace_back( MakeUnique<GpuMemoryBlockRef>(handle) );
     return handle;
   }
 
@@ -115,7 +115,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
    * @param memoryProperties
    * @return
    */
-  virtual GpuMemoryBlockHandle Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) override
+  virtual GpuMemoryBlockRef Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) override
   {
     return Allocate( mGraphics.GetDevice().getBufferMemoryRequirements( buffer->GetVkBuffer() ),
                      memoryProperties );
@@ -127,9 +127,9 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
    * @param memoryProperties
    * @return
    */
-  GpuMemoryBlockHandle Allocate( Image& image, vk::MemoryPropertyFlags memoryProperties ) override
+  GpuMemoryBlockRef Allocate( Image& image, vk::MemoryPropertyFlags memoryProperties ) override
   {
-    return Allocate( mGraphics.GetDevice().getImageMemoryRequirements( image.GetImage() ),
+    return Allocate( mGraphics.GetDevice().getImageMemoryRequirements( image.GetVkImage() ),
                                memoryProperties );
   }
 
@@ -190,7 +190,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
   GpuMemoryManager& mGpuManager;
   Graphics& mGraphics;
 
-  std::vector<std::unique_ptr<GpuMemoryBlockHandle>> mUniqueBlocks;
+  std::vector<std::unique_ptr<GpuMemoryBlockRef>> mUniqueBlocks;
 };
 
 struct GpuMemoryManager::Impl
index 81226da..445ebb1 100644 (file)
@@ -87,7 +87,7 @@ struct Buffer::Impl final
     return mBuffer;
   }
 
-  void BindMemory( GpuMemoryBlockHandle handle )
+  void BindMemory( GpuMemoryBlockRef handle )
   {
     assert( mBuffer && "Buffer not initialised!");
     VkAssert(mGraphics.GetDevice().bindBufferMemory( mBuffer, (*handle), 0 ));
@@ -96,7 +96,7 @@ struct Buffer::Impl final
 
   Vulkan::Graphics&                     mGraphics;
   Vulkan::Buffer&                       mInterface;
-  GpuMemoryBlockHandle                  mDeviceMemory;
+  GpuMemoryBlockRef                  mDeviceMemory;
   vk::BufferCreateInfo                  mInfo;
   vk::Buffer                            mBuffer;
 };
@@ -107,7 +107,7 @@ struct Buffer::Impl final
  * @param size
  * @return
  */
-BufferHandle Buffer::New(Graphics& graphics, size_t size, Type type)
+BufferRef Buffer::New(Graphics& graphics, size_t size, Type type)
 {
   auto usageFlags = vk::BufferUsageFlags{};
 
@@ -145,7 +145,7 @@ vk::BufferUsageFlags Buffer::GetUsage() const
   return mImpl->GetUsage();
 }
 
-const GpuMemoryBlockHandle& Buffer::GetMemoryHandle() const
+const GpuMemoryBlockRef& Buffer::GetMemoryHandle() const
 {
   return mImpl->mDeviceMemory;
 }
@@ -160,7 +160,7 @@ vk::Buffer Buffer::GetVkBuffer() const
   return mImpl->GetVkBuffer();
 }
 
-void Buffer::BindMemory( const GpuMemoryBlockHandle& handle )
+void Buffer::BindMemory( const GpuMemoryBlockRef& handle )
 {
   mImpl->BindMemory( handle );
 }
index 0b67908..5f223ab 100644 (file)
@@ -26,15 +26,8 @@ namespace Graphics
 {
 namespace Vulkan
 {
-class DeviceMemory;
 class Graphics;
 class GpuMemoryBlock;
-using GpuMemoryBlockHandle = Handle<GpuMemoryBlock>;
-
-using VertexBuffer = Buffer;
-using UniformBuffer = Buffer;
-using IndexBuffer = Buffer;
-using BufferHandle = Handle<Buffer>;
 
 class Buffer : public VkManaged
 {
@@ -63,7 +56,7 @@ public:
    * @param type
    * @return
    */
-  static BufferHandle New( Graphics& graphics, size_t size, Type type );
+  static BufferRef New( Graphics& graphics, size_t size, Type type );
 
   /**
    * Returns buffer usage flags
@@ -87,13 +80,13 @@ public:
    * Returns handle to the allocated memory
    * @return
    */
-  const GpuMemoryBlockHandle& GetMemoryHandle() const;
+  const GpuMemoryBlockRef& GetMemoryHandle() const;
 
   /**
    * Binds buffer memory
    * @param handle
    */
-  void BindMemory( const GpuMemoryBlockHandle& handle );
+  void BindMemory( const GpuMemoryBlockRef& handle );
 
 public:
 
index f67dba9..4082b2f 100644 (file)
  */
 
 // INTERNAL INCLUDES
-#include <dali/graphics/vulkan/vulkan-types.h>
+#include <dali/graphics/vulkan/vulkan-buffer.h>
 #include <dali/graphics/vulkan/vulkan-command-buffer.h>
 #include <dali/graphics/vulkan/vulkan-command-pool.h>
+#include <dali/graphics/vulkan/vulkan-descriptor-set.h>
 #include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/vulkan-buffer.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
 #include <dali/graphics/vulkan/vulkan-pipeline.h>
-#include <dali/graphics/vulkan/vulkan-descriptor-set.h>
 #include <dali/graphics/vulkan/vulkan-surface.h>
+#include <dali/graphics/vulkan/vulkan-types.h>
 
 namespace Dali
 {
@@ -32,7 +32,6 @@ namespace Graphics
 {
 namespace Vulkan
 {
-
 struct CommandBuffer::Impl
 {
   Impl( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer commandBuffer )
@@ -41,7 +40,6 @@ struct CommandBuffer::Impl
     mAllocateInfo( allocateInfo ),
     mCommandBuffer( commandBuffer )
   {
-
   }
 
   ~Impl()
@@ -53,7 +51,7 @@ struct CommandBuffer::Impl
     return true;
   }
 
-  template <class T>
+  template<class T>
   bool IsResourceAdded( Handle<T> resourceHandle )
   {
     for( auto&& res : mResources )
@@ -66,12 +64,12 @@ struct CommandBuffer::Impl
     return false;
   }
 
-  template <class T>
+  template<class T>
   bool PushResource( Handle<T> resourceHandle )
   {
-    if(!IsResourceAdded( resourceHandle ))
+    if( !IsResourceAdded( resourceHandle ) )
     {
-      mResources.push_back(VkTypeCast<VkManaged>( resourceHandle ));
+      mResources.push_back( VkTypeCast<VkManaged>( resourceHandle ) );
       return true;
     }
     return false;
@@ -80,12 +78,12 @@ struct CommandBuffer::Impl
   /**
    *
    */
-  void Begin(vk::CommandBufferUsageFlags usageFlags, vk::CommandBufferInheritanceInfo* inheritanceInfo)
+  void Begin( vk::CommandBufferUsageFlags usageFlags, vk::CommandBufferInheritanceInfo* inheritanceInfo )
   {
-    assert(!mRecording && "CommandBuffer already is in the recording state");
+    assert( !mRecording && "CommandBuffer already is in the recording state" );
     auto info = vk::CommandBufferBeginInfo{};
-    info.setPInheritanceInfo(inheritanceInfo);
-    info.setFlags(usageFlags);
+    info.setPInheritanceInfo( inheritanceInfo );
+    info.setFlags( usageFlags );
 
     // set the inheritance option
     auto inheritance = vk::CommandBufferInheritanceInfo{}.setSubpass( 0 );
@@ -94,38 +92,38 @@ struct CommandBuffer::Impl
     {
       // todo: sets render pass from 'default' surface, should be supplied from primary command buffer
       // which has render pass associated within execution context
-      inheritance.setRenderPass( mGraphics.GetSurface(0).GetRenderPass() );
+      inheritance.setRenderPass( mGraphics.GetSurface( 0 ).GetRenderPass() );
       info.setPInheritanceInfo( &inheritance );
     }
 
-    VkAssert(mCommandBuffer.begin(info));
+    VkAssert( mCommandBuffer.begin( info ) );
     mRecording = true;
   }
 
   void End()
   {
-    assert(mRecording && "CommandBuffer is not in the recording state!");
-    VkAssert(mCommandBuffer.end());
+    assert( mRecording && "CommandBuffer is not in the recording state!" );
+    VkAssert( mCommandBuffer.end() );
     mRecording = false;
   }
 
   void Reset()
   {
-    assert(!mRecording && "Can't reset command buffer during recording!");
-    assert(mCommandBuffer && "Invalid command buffer!");
-    mCommandBuffer.reset(vk::CommandBufferResetFlagBits::eReleaseResources);
+    assert( !mRecording && "Can't reset command buffer during recording!" );
+    assert( mCommandBuffer && "Invalid command buffer!" );
+    mCommandBuffer.reset( vk::CommandBufferResetFlagBits::eReleaseResources );
   }
 
   void Free()
   {
-    assert(mCommandBuffer && "Invalid command buffer!");
-    mGraphics.GetDevice().freeCommandBuffers(mOwnerCommandPool.GetPool(), mCommandBuffer);
+    assert( mCommandBuffer && "Invalid command buffer!" );
+    mGraphics.GetDevice().freeCommandBuffers( mOwnerCommandPool.GetPool(), mCommandBuffer );
   }
 
-  void ImageLayoutTransition(vk::Image            image,
-                             vk::ImageLayout      oldLayout,
-                             vk::ImageLayout      newLayout,
-                             vk::ImageAspectFlags aspectMask)
+  void ImageLayoutTransition( vk::Image            image,
+                              vk::ImageLayout      oldLayout,
+                              vk::ImageLayout      newLayout,
+                              vk::ImageAspectFlags aspectMask )
   {
     // just push new image barrier until any command is being called or buffer recording ends.
     // it will make sure we batch barriers together rather than calling cmdPipelineBarrier
@@ -134,7 +132,7 @@ struct CommandBuffer::Impl
     vk::PipelineStageFlags srcStageMask, dstStageMask;
 
     // TODO: add other transitions
-    switch(oldLayout)
+    switch( oldLayout )
     {
       case vk::ImageLayout::eUndefined:
       {
@@ -143,13 +141,13 @@ struct CommandBuffer::Impl
       break;
       case vk::ImageLayout::ePresentSrcKHR:
       {
-        srcStageMask = vk::PipelineStageFlagBits::eBottomOfPipe;
+        srcStageMask  = vk::PipelineStageFlagBits::eBottomOfPipe;
         srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead;
       }
       break;
       case vk::ImageLayout::eColorAttachmentOptimal:
       {
-        srcStageMask = vk::PipelineStageFlagBits::eFragmentShader | vk::PipelineStageFlagBits::eColorAttachmentOutput;
+        srcStageMask  = vk::PipelineStageFlagBits::eFragmentShader | vk::PipelineStageFlagBits::eColorAttachmentOutput;
         srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead;
       }
       break;
@@ -163,20 +161,21 @@ struct CommandBuffer::Impl
       case vk::ImageLayout::eSharedPresentKHR:
       {
       }
-      }
+    }
 
-      switch(newLayout)
-      {
+    switch( newLayout )
+    {
       case vk::ImageLayout::eColorAttachmentOptimal:
       {
-        dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput | vk::PipelineStageFlagBits::eFragmentShader;
+        dstStageMask  = vk::PipelineStageFlagBits::eColorAttachmentOutput | vk::PipelineStageFlagBits::eFragmentShader;
         dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eHostWrite;
         break;
       }
       case vk::ImageLayout::eDepthStencilAttachmentOptimal:
       {
         dstStageMask = vk::PipelineStageFlagBits::eFragmentShader | vk::PipelineStageFlagBits::eEarlyFragmentTests;
-        dstAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite;
+        dstAccessMask =
+          vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite;
         break;
       }
       case vk::ImageLayout::ePresentSrcKHR:
@@ -195,55 +194,59 @@ struct CommandBuffer::Impl
       {
         break;
       }
-
     }
 
-    RecordImageLayoutTransition(image, srcAccessMask, dstAccessMask, srcStageMask, dstStageMask,
-                                oldLayout, newLayout, aspectMask);
+    RecordImageLayoutTransition(
+      image, srcAccessMask, dstAccessMask, srcStageMask, dstStageMask, oldLayout, newLayout, aspectMask );
   }
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wframe-larger-than="
-  void RecordImageLayoutTransition(vk::Image image, vk::AccessFlags srcAccessMask,
-                                   vk::AccessFlags dstAccessMask, vk::PipelineStageFlags srcStageMask,
-                                   vk::PipelineStageFlags dstStageMask, vk::ImageLayout oldLayout,
-                                   vk::ImageLayout newLayout, vk::ImageAspectFlags aspectMask)
+  void RecordImageLayoutTransition( vk::Image              image,
+                                    vk::AccessFlags        srcAccessMask,
+                                    vk::AccessFlags        dstAccessMask,
+                                    vk::PipelineStageFlags srcStageMask,
+                                    vk::PipelineStageFlags dstStageMask,
+                                    vk::ImageLayout        oldLayout,
+                                    vk::ImageLayout        newLayout,
+                                    vk::ImageAspectFlags   aspectMask )
   {
     vk::ImageSubresourceRange subres;
-    subres.setLayerCount(1).setBaseMipLevel(0).setBaseArrayLayer(0).setLevelCount(1).setAspectMask(aspectMask);
-
+    subres.setLayerCount( 1 ).setBaseMipLevel( 0 ).setBaseArrayLayer( 0 ).setLevelCount( 1 ).setAspectMask(
+      aspectMask );
 
     auto barrier = vk::ImageMemoryBarrier{};
-    barrier
-      .setImage(image)
-      .setSubresourceRange(subres)
-      .setSrcAccessMask(srcAccessMask)
-      .setDstAccessMask(dstAccessMask)
-      .setOldLayout(oldLayout)
-      .setNewLayout(newLayout);
+    barrier.setImage( image )
+      .setSubresourceRange( subres )
+      .setSrcAccessMask( srcAccessMask )
+      .setDstAccessMask( dstAccessMask )
+      .setOldLayout( oldLayout )
+      .setNewLayout( newLayout );
     ;
     // todo: implement barriers batching
-    mCommandBuffer.pipelineBarrier(srcStageMask, dstStageMask, vk::DependencyFlags{}, nullptr, nullptr, barrier);
+    mCommandBuffer.pipelineBarrier( srcStageMask, dstStageMask, vk::DependencyFlags{}, nullptr, nullptr, barrier );
   }
 #pragma GCC diagnostic pop
 
   /** Push wait semaphores */
-  void PushWaitSemaphores(const std::vector< vk::Semaphore >&          semaphores,
-                          const std::vector< vk::PipelineStageFlags >& stages)
+  void PushWaitSemaphores( const std::vector<vk::Semaphore>&          semaphores,
+                           const std::vector<vk::PipelineStageFlags>& stages )
   {
     mWaitSemaphores = semaphores;
     mWaitStages     = stages;
   }
 
   /** Push signal semaphores */
-  void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores)
+  void PushSignalSemaphores( const std::vector<vk::Semaphore>& semaphores )
   {
     mSignalSemaphores = semaphores;
   }
 
   // TODO: handles should be synchronized
-  void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, std::vector<Handle<Buffer>> buffers,
-                                        const vk::DeviceSize *pOffsets)
+  void BindVertexBuffers( uint32_t                    firstBinding,
+                          uint32_t                    bindingCount,
+                          std::vector<Handle<Buffer>> buffers,
+                          const vk::DeviceSize*       pOffsets )
   {
     // update list of used resources and create an array of VkBuffers
     std::vector<vk::Buffer> vkBuffers;
@@ -251,16 +254,17 @@ struct CommandBuffer::Impl
     for( auto&& buffer : buffers )
     {
       vkBuffers.emplace_back( buffer->GetVkBuffer() );
-      PushResource(buffer);
+      PushResource( buffer );
     }
 
-    mCommandBuffer.bindVertexBuffers( firstBinding, bindingCount, vkBuffers.data(), pOffsets);
+    mCommandBuffer.bindVertexBuffers( firstBinding, bindingCount, vkBuffers.data(), pOffsets );
   }
 
-  void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType)
+  void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType )
   {
     // validate
-    assert ( (buffer->GetUsage() & vk::BufferUsageFlagBits::eIndexBuffer) && "The buffer used as index buffer has wrong usage flags!" );
+    assert( ( buffer->GetUsage() & vk::BufferUsageFlagBits::eIndexBuffer ) &&
+            "The buffer used as index buffer has wrong usage flags!" );
 
     PushResource( buffer );
     mCommandBuffer.bindIndexBuffer( buffer->GetVkBuffer(), offset, indexType );
@@ -274,7 +278,9 @@ struct CommandBuffer::Impl
   }
 
   void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
-                                          Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount )
+                           Handle<Pipeline>                                           pipeline,
+                           uint32_t                                                   firstSet,
+                           uint32_t                                                   descriptorSetCount )
   {
     // update resources
     PushResource( pipeline );
@@ -287,8 +293,13 @@ struct CommandBuffer::Impl
     }
 
     // TODO: support dynamic offsets
-    mCommandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipeline->GetVkPipelineLayout(),
-    firstSet, descriptorSetCount, vkSets.data(), 0, nullptr );
+    mCommandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics,
+                                       pipeline->GetVkPipelineLayout(),
+                                       firstSet,
+                                       descriptorSetCount,
+                                       vkSets.data(),
+                                       0,
+                                       nullptr );
   }
 
   void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance )
@@ -296,12 +307,14 @@ struct CommandBuffer::Impl
     mCommandBuffer.draw( vertexCount, instanceCount, firstVertex, firstInstance );
   }
 
-  void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance )
+  void DrawIndexed(
+    uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance )
   {
-    mCommandBuffer.drawIndexed( indexCount, instanceCount, firstIndex, vertexOffset, firstInstance );
+    mCommandBuffer.drawIndexed(
+      indexCount, instanceCount, firstIndex, static_cast<int32_t>( vertexOffset ), firstInstance );
   }
 
-  const std::vector< Handle<VkManaged>> GetResources() const
+  const std::vector<Handle<VkManaged>> GetResources() const
   {
     return mResources;
   }
@@ -309,17 +322,17 @@ struct CommandBuffer::Impl
   // RENDER PASS
   void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex )
   {
-    auto& surface = mGraphics.GetSurface( framebufferId );
-    auto renderPass = surface.GetRenderPass();
-    auto frameBuffer = surface.GetFramebuffer( bufferIndex );
-    auto clearValues = surface.GetClearValues();
+    auto& surface     = mGraphics.GetSurface( framebufferId );
+    auto  renderPass  = surface.GetRenderPass();
+    auto  frameBuffer = surface.GetFramebuffer( bufferIndex );
+    auto  clearValues = surface.GetClearValues();
 
     auto info = vk::RenderPassBeginInfo{};
     info.setFramebuffer( frameBuffer );
     info.setRenderPass( renderPass );
-    info.setClearValueCount( U32(clearValues.size()) );
+    info.setClearValueCount( U32( clearValues.size() ) );
     info.setPClearValues( clearValues.data() );
-    info.setRenderArea( vk::Rect2D( { 0,0 }, surface.GetSize() ) );
+    info.setRenderArea( vk::Rect2D( {0, 0}, surface.GetSize() ) );
 
     mCurrentRenderPass = renderPass;
     mCommandBuffer.beginRenderPass( info, vk::SubpassContents::eInline );
@@ -350,24 +363,24 @@ struct CommandBuffer::Impl
     mCommandBuffer.executeCommands( vkBuffers );
   }
 
-  Graphics&                       mGraphics;
-  CommandPool&                    mOwnerCommandPool;
-  vk::CommandBufferAllocateInfo   mAllocateInfo {};
+  Graphics&                     mGraphics;
+  CommandPool&                  mOwnerCommandPool;
+  vk::CommandBufferAllocateInfo mAllocateInfo{};
 
-  vk::CommandBuffer     mCommandBuffer {};
+  vk::CommandBuffer mCommandBuffer{};
 
   // semaphores per command buffer
-  std::vector< vk::Semaphore >          mSignalSemaphores {};
-  std::vector< vk::Semaphore >          mWaitSemaphores {};
-  std::vector< vk::PipelineStageFlags > mWaitStages {};
+  std::vector<vk::Semaphore>          mSignalSemaphores{};
+  std::vector<vk::Semaphore>          mWaitSemaphores{};
+  std::vector<vk::PipelineStageFlags> mWaitStages{};
 
-  std::vector< Handle<VkManaged>> mResources; // used resources
+  std::vector<Handle<VkManaged>> mResources; // used resources
 
   PipelineRef mCurrentPipeline;
 
   vk::RenderPass mCurrentRenderPass;
 
-  bool mRecording { false };
+  bool mRecording{false};
 };
 
 /**
@@ -376,7 +389,9 @@ struct CommandBuffer::Impl
  *
  */
 
-CommandBuffer::CommandBuffer( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer vkCommandBuffer )
+CommandBuffer::CommandBuffer( CommandPool&                         commandPool,
+                              const vk::CommandBufferAllocateInfo& allocateInfo,
+                              vk::CommandBuffer                    vkCommandBuffer )
 {
   mImpl = MakeUnique<Impl>( commandPool, allocateInfo, vkCommandBuffer );
 }
@@ -386,7 +401,7 @@ CommandBuffer::~CommandBuffer()
 }
 
 /** Begin recording */
-void CommandBuffer::Begin(vk::CommandBufferUsageFlags usageFlags, vk::CommandBufferInheritanceInfo* inheritanceInfo)
+void CommandBuffer::Begin( vk::CommandBufferUsageFlags usageFlags, vk::CommandBufferInheritanceInfo* inheritanceInfo )
 {
   mImpl->Begin( usageFlags, inheritanceInfo );
 }
@@ -410,46 +425,51 @@ void CommandBuffer::Free()
 }
 
 /** Records image layout transition barrier for one image */
-void CommandBuffer::ImageLayoutTransition(vk::Image            image,
-                                          vk::ImageLayout      oldLayout,
-                                          vk::ImageLayout      newLayout,
-                                          vk::ImageAspectFlags aspectMask)
+void CommandBuffer::ImageLayoutTransition( vk::Image            image,
+                                           vk::ImageLayout      oldLayout,
+                                           vk::ImageLayout      newLayout,
+                                           vk::ImageAspectFlags aspectMask )
 {
   mImpl->ImageLayoutTransition( image, oldLayout, newLayout, aspectMask );
 }
 
-void CommandBuffer::RecordImageLayoutTransition(vk::Image image, vk::AccessFlags srcAccessMask,
-                                                vk::AccessFlags dstAccessMask, vk::PipelineStageFlags srcStageMask,
-                                                vk::PipelineStageFlags dstStageMask, vk::ImageLayout oldLayout,
-                                                vk::ImageLayout newLayout, vk::ImageAspectFlags aspectMask)
+void CommandBuffer::RecordImageLayoutTransition( vk::Image              image,
+                                                 vk::AccessFlags        srcAccessMask,
+                                                 vk::AccessFlags        dstAccessMask,
+                                                 vk::PipelineStageFlags srcStageMask,
+                                                 vk::PipelineStageFlags dstStageMask,
+                                                 vk::ImageLayout        oldLayout,
+                                                 vk::ImageLayout        newLayout,
+                                                 vk::ImageAspectFlags   aspectMask )
 {
-  mImpl->RecordImageLayoutTransition( image, srcAccessMask, dstAccessMask,srcStageMask, dstStageMask, oldLayout, newLayout, aspectMask );
+  mImpl->RecordImageLayoutTransition(
+    image, srcAccessMask, dstAccessMask, srcStageMask, dstStageMask, oldLayout, newLayout, aspectMask );
 }
 
 /** Push wait semaphores */
-void CommandBuffer::PushWaitSemaphores(const std::vector< vk::Semaphore >&          semaphores,
-                                       const std::vector< vk::PipelineStageFlags >& stages)
+void CommandBuffer::PushWaitSemaphores( const std::vector<vk::Semaphore>&          semaphores,
+                                        const std::vector<vk::PipelineStageFlags>& stages )
 {
   mImpl->PushWaitSemaphores( semaphores, stages );
 }
 
 /** Push signal semaphores */
-void CommandBuffer::PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores)
+void CommandBuffer::PushSignalSemaphores( const std::vector<vk::Semaphore>& semaphores )
 {
   mImpl->PushSignalSemaphores( semaphores );
 }
 
-const std::vector< vk::Semaphore >& CommandBuffer::GetSignalSemaphores() const
+const std::vector<vk::Semaphore>& CommandBuffer::GetSignalSemaphores() const
 {
   return mImpl->mSignalSemaphores;
 }
 
-const std::vector< vk::Semaphore >& CommandBuffer::GetSWaitSemaphores() const
+const std::vector<vk::Semaphore>& CommandBuffer::GetSWaitSemaphores() const
 {
   return mImpl->mWaitSemaphores;
 }
 
-const std::vector< vk::PipelineStageFlags >& CommandBuffer::GetWaitSemaphoreStages() const
+const std::vector<vk::PipelineStageFlags>& CommandBuffer::GetWaitSemaphoreStages() const
 {
   return mImpl->mWaitStages;
 }
@@ -464,20 +484,24 @@ bool CommandBuffer::IsPrimary() const
   return mImpl->mAllocateInfo.level == vk::CommandBufferLevel::ePrimary;
 }
 
-void CommandBuffer::BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, std::vector<Handle<Buffer>> buffers,
-                       const vk::DeviceSize *pOffsets)
+void CommandBuffer::BindVertexBuffers( uint32_t                    firstBinding,
+                                       uint32_t                    bindingCount,
+                                       std::vector<Handle<Buffer>> buffers,
+                                       const vk::DeviceSize*       pOffsets )
 {
   mImpl->BindVertexBuffers( firstBinding, bindingCount, buffers, pOffsets );
 }
 
-void CommandBuffer::BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType)
+void CommandBuffer::BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType )
 {
   mImpl->BindIndexBuffer( buffer, offset, indexType );
 }
 
-void CommandBuffer::BindVertexBuffer(uint32_t binding, Dali::Graphics::Vulkan::Handle<Buffer> buffer, vk::DeviceSize offset )
+void CommandBuffer::BindVertexBuffer( uint32_t                               binding,
+                                      Dali::Graphics::Vulkan::Handle<Buffer> buffer,
+                                      vk::DeviceSize                         offset )
 {
-  mImpl->BindVertexBuffers( binding, 1, std::vector<Handle<Buffer>>({ buffer }), &offset );
+  mImpl->BindVertexBuffers( binding, 1, std::vector<Handle<Buffer>>( {buffer} ), &offset );
 }
 
 void CommandBuffer::BindGraphicsPipeline( Handle<Pipeline> pipeline )
@@ -486,14 +510,18 @@ void CommandBuffer::BindGraphicsPipeline( Handle<Pipeline> pipeline )
 }
 
 void CommandBuffer::BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
-                         Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount )
+                                        Handle<Pipeline>                                           pipeline,
+                                        uint32_t                                                   firstSet,
+                                        uint32_t                                                   descriptorSetCount )
 {
   mImpl->BindDescriptorSets( descriptorSets, pipeline, firstSet, descriptorSetCount );
 }
 
-void CommandBuffer::BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets, uint32_t firstSet )
+void CommandBuffer::BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
+                                        uint32_t                                                   firstSet )
 {
-  mImpl->BindDescriptorSets( descriptorSets, mImpl->mCurrentPipeline, 0, static_cast<uint32_t>(descriptorSets.size()) );
+  mImpl->BindDescriptorSets(
+    descriptorSets, mImpl->mCurrentPipeline, 0, static_cast<uint32_t>( descriptorSets.size() ) );
 }
 
 void CommandBuffer::Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance )
@@ -501,7 +529,8 @@ void CommandBuffer::Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t
   mImpl->Draw( vertexCount, instanceCount, firstVertex, firstInstance );
 }
 
-void CommandBuffer::DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance )
+void CommandBuffer::DrawIndexed(
+  uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance )
 {
   mImpl->DrawIndexed( indexCount, instanceCount, firstIndex, vertexOffset, firstInstance );
 }
index ecd334a..dc36c7c 100644 (file)
@@ -25,25 +25,22 @@ namespace Graphics
 {
 namespace Vulkan
 {
-
 struct Framebuffer::Impl
 {
-  Impl( Framebuffer& owner, Graphics& graphics, uint32_t width, uint32_t height ) :
-    mInterface( owner ),
-    mGraphics( graphics )
+  Impl( Framebuffer& owner, Graphics& graphics, uint32_t width, uint32_t height )
+  : mInterface( owner ), mGraphics( graphics )
   {
-
   }
 
   // Framebuffer creation may be deferred
   bool Initialise()
   {
-    if(mInitialised)
+    if( mInitialised )
     {
       return true;
     }
 
-    if(!Validate())
+    if( !Validate() )
     {
       return false;
     }
@@ -83,6 +80,77 @@ struct Framebuffer::Impl
     mInitialised = true;
   }
 
+  // creating render pass may happen either as deferred or
+  // when framebuffer is initialised into immutable state
+  void CreateRenderPass()
+  {
+    // for each attachment...
+#if 0
+    auto attRef = vk::AttachmentReference{};
+
+    // 1. Need to know layout during render pass ( Image::GetLayout() )
+    // 2. Usually it's going to be:
+    //    - color_attachment_optimal
+    //    - depth_stencil_attachment_optimal
+    //attRef.setLayout();
+    //attRef.setAttachment();
+
+    // Single subpass support, all attachments used
+    // TODO: input, preserve, resolve
+    // TODO: create subpasses
+
+    // creating single subpass per framebuffer
+    auto subpassDesc = vk::SubpassDescription{};
+    subpassDesc.setPipelineBindPoint( vk::PipelineBindPoint::eGraphics );
+    subpassDesc.setColorAttachmentCount( 0 );
+    subpassDesc.setInputAttachmentCount( 0 );
+    subpassDesc.setPDepthStencilAttachment( nullptr );
+    subpassDesc.setPColorAttachments( nullptr );
+    subpassDesc.setPInputAttachments( nullptr );
+    subpassDesc.setPPreserveAttachments( nullptr );
+    subpassDesc.setPResolveAttachments( nullptr );
+
+    // create compatible render pass
+    auto rpInfo = vk::RenderPassCreateInfo{};
+    //rpInfo.setAttachmentCount( mAttachments.size() );
+    //rpInfo.setPAttachments( )
+    rpInfo.setDependencyCount( 0 );
+    rpInfo.setPDependencies( nullptr );
+    rpInfo.setPSubpasses( &subpassDesc );
+    rpInfo.setSubpassCount( 1 );
+#endif
+  }
+
+  void InitialiseAttachments()
+  {
+    ImageRef                attachment;
+    vk::ImageViewCreateInfo info;
+    info.setViewType( vk::ImageViewType::e2D );
+    info.setSubresourceRange( //get layercount, get level count
+      vk::ImageSubresourceRange{}.setLevelCount( 1 ).setLayerCount( 1 ).setBaseMipLevel( 0 ).setBaseArrayLayer( 0 ) );
+    info.setImage( attachment->GetVkImage() ); //
+    info.setComponents( vk::ComponentMapping(
+      vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA ) );
+    info.setFormat( vk::Format::eD16Unorm ); // get format
+
+    //ImageViewRef ref = ImageView::New( attachment );
+  }
+
+  void CreateFramebuffer()
+  {
+    // assert if framebuffer is already created
+    InitialiseAttachments();
+
+    vk::FramebufferCreateInfo info;
+    info.setRenderPass( mVkRenderPass )
+      .setPAttachments( nullptr ) // attach imageviews, imageviews are created from supplied images
+      .setLayers( 1 )
+      .setWidth( mWidth )
+      .setHeight( mHeight )
+      .setAttachmentCount( 1 );
+
+    mVkFramebuffer = VkAssert( mGraphics.GetDevice().createFramebuffer( info, mGraphics.GetAllocator() ) );
+  }
 
   void SetAttachment( Handle<Image> image, Framebuffer::AttachmentType type, uint32_t index )
   {
@@ -91,7 +159,7 @@ struct Framebuffer::Impl
 
     if( attachments.size() <= index )
     {
-      attachments.resize( index+1 );
+      attachments.resize( index + 1 );
     }
     attachments[index] = image;
   }
@@ -108,7 +176,7 @@ struct Framebuffer::Impl
 
   bool Validate()
   {
-    if( mWidth == 0u || mHeight == 0  )
+    if( mWidth == 0u || mHeight == 0 )
     {
       return false;
     }
@@ -116,7 +184,6 @@ struct Framebuffer::Impl
 
   ~Impl()
   {
-
   }
 
   vk::RenderPass GetVkRenderPass() const
@@ -129,22 +196,21 @@ struct Framebuffer::Impl
     return mVkFramebuffer;
   }
 
-  Framebuffer&            mInterface;
-  Graphics&               mGraphics;
+  Framebuffer& mInterface;
+  Graphics&    mGraphics;
 
-  uint32_t mWidth;
-  uint32_t mHeight;
-  std::vector<Handle<Image>>      mColorAttachments;
-  std::vector<Handle<Image>>      mDepthStencilAttachments;
+  uint32_t                   mWidth;
+  uint32_t                   mHeight;
+  std::vector<Handle<Image>> mColorAttachments;
+  std::vector<Handle<Image>> mDepthStencilAttachments;
 
-  std::vector<ImageView>  mImageViewAttachments;
-  vk::Framebuffer         mVkFramebuffer;
-  vk::RenderPass          mVkRenderPass;
+  std::vector<ImageView> mImageViewAttachments;
+  vk::Framebuffer        mVkFramebuffer;
+  vk::RenderPass         mVkRenderPass;
 
-  bool mInitialised { false };
+  bool mInitialised{false};
 };
 
-
 Handle<Framebuffer> Framebuffer::New( Graphics& graphics, uint32_t width, uint32_t height )
 {
   return FramebufferRef();
index 5ec2477..3a4a184 100644 (file)
@@ -24,44 +24,191 @@ namespace Graphics
 {
 namespace Vulkan
 {
+struct Image::Impl
+{
+  Impl( Image& owner, Graphics& graphics, vk::ImageCreateInfo createInfo, vk::Image externalImage = nullptr )
+  : mOwner( owner ),
+    mGraphics( graphics ),
+    mVkImage( externalImage ),
+    mCreateInfo( std::move( createInfo ) ),
+    mIsExternal( static_cast<bool>( externalImage ) )
+  {
+  }
+
+  ~Impl()
+  {
+    if( !mIsExternal )
+    {
+      // destroy
+    }
+  }
+
+  bool Initialise()
+  {
+    if( !mIsExternal )
+    {
+      mVkImage = VkAssert( mGraphics.GetDevice().createImage( mCreateInfo, mGraphics.GetAllocator() ) );
+      if( !mVkImage )
+      {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  Image&              mOwner;
+  Graphics&           mGraphics;
+  vk::Image           mVkImage;
+  vk::ImageLayout     mVkImageLayout;
+  vk::ImageCreateInfo mCreateInfo;
+
+  bool mIsExternal;
+};
+
+Image::~Image() = default;
+
+ImageRef Image::New( Graphics& graphics, vk::ImageCreateInfo createInfo )
+{
+  ImageRef retval( new Image( graphics, createInfo, nullptr ) );
+  if( !retval->mImpl->Initialise() )
+  {
+    retval.Reset();
+  }
+  else
+  {
+    graphics.AddImage( retval );
+  }
+  return retval;
+}
+
+ImageRef Image::New( Graphics& graphics, vk::ImageCreateInfo createInfo, vk::Image externalImage )
+{
+  ImageRef retval( new Image( graphics, createInfo, externalImage ) );
+  if( !retval->mImpl->Initialise() )
+  {
+    retval.Reset();
+  }
+  else
+  {
+    graphics.AddImage( retval );
+  }
+  return retval;
+}
 
-Image::Image(Graphics& graphics, const vk::ImageCreateInfo& createInfo) : mGraphics(graphics)
+Image::Image( Graphics& graphics, const vk::ImageCreateInfo& createInfo, vk::Image externalImage )
 {
+  mImpl = MakeUnique<Impl>( *this, graphics, createInfo, externalImage );
 }
 
-Image::Image(Graphics& graphics, vk::Image externalImage)
-: mGraphics(graphics), mImage(externalImage)
+vk::Image Image::GetVkImage() const
 {
+  return mImpl->mVkImage;
 }
 
-vk::ImageView Image::CreateUnmanagedView(const vk::ImageViewCreateInfo& info)
+vk::ImageLayout Image::GetVkImageLayout() const
 {
-  NotImplemented();
-  return nullptr;
+  return mImpl->mVkImageLayout;
 }
 
-ImageViewRef Image::CreateView(const vk::ImageViewCreateInfo& info)
+uint32_t Image::GetWidth() const
 {
-  return MakeRef< ImageView >(mGraphics, *this, info);
+  return mImpl->mCreateInfo.extent.width;
 }
 
-ImageView::ImageView(Graphics& graphics, Image& image) : mGraphics(graphics), mImageRef(&image)
+uint32_t Image::GetHeight() const
 {
+  return mImpl->mCreateInfo.extent.height;
 }
 
-ImageView::ImageView(Graphics& graphics, Image& image, const VkImageViewCreateInfo& createInfo)
-: mGraphics(graphics), mImageRef(&image)
+uint32_t Image::GetLayerCount() const
 {
-  mImageView =
-      VkAssert(mGraphics.GetDevice().createImageView(createInfo, mGraphics.GetAllocator()));
+  return mImpl->mCreateInfo.arrayLayers;
 }
 
-ImageView::~ImageView()
+uint32_t Image::GetLevelCount() const
 {
-  if(mImageView)
+  return mImpl->mCreateInfo.mipLevels;
+}
+
+vk::Format Image::GetVkFormat() const
+{
+  return mImpl->mCreateInfo.format;
+}
+
+vk::ImageType Image::GetVkImageType() const
+{
+  return mImpl->mCreateInfo.imageType;
+}
+
+vk::ImageTiling Image::GetVkImageTiling() const
+{
+  return mImpl->mCreateInfo.tiling;
+}
+
+void Image::BindMemory( GpuMemoryBlockRef& handle )
+{
+}
+
+/***************************************************************************
+ *
+ *  ImageView
+ *
+ */
+
+struct ImageView::Impl
+{
+  Impl( ImageView& owner, Graphics& graphics, ImageRef image, vk::ImageViewCreateInfo createInfo )
+  : mOwner( owner ), mGraphics( graphics ), mImage( image ), mCreateInfo( createInfo )
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  bool Initialise()
   {
-    mGraphics.GetDevice().destroyImageView( mImageView, mGraphics.GetAllocator());
+    mVkImageView = VkAssert( mGraphics.GetDevice().createImageView( mCreateInfo, mGraphics.GetAllocator() ) );
+    if( !mVkImageView )
+    {
+      return false;
+    }
+    return true;
   }
+
+  ImageView&              mOwner;
+  Graphics&               mGraphics;
+  ImageRef                mImage;
+  vk::ImageViewCreateInfo mCreateInfo;
+
+  vk::ImageView mVkImageView;
+};
+
+ImageViewRef ImageView::New( Graphics& graphics, ImageRef image, vk::ImageViewCreateInfo info )
+{
+  auto retval = ImageViewRef( new ImageView( graphics, image, info ) );
+  if(!retval->mImpl->Initialise())
+  {
+    return ImageViewRef();
+  }
+  return retval;
+}
+
+ImageView::ImageView( Graphics& graphics, ImageRef image, const VkImageViewCreateInfo& createInfo )
+{
+  mImpl = MakeUnique<Impl>( *this, graphics, image, createInfo );
+}
+
+ImageView::~ImageView() = default;
+
+const vk::ImageView& ImageView::GetVkImageView() const
+{
+  return mImpl->mVkImageView;
+}
+
+ImageRef ImageView::GetImage() const
+{
+  return mImpl->mImage;
 }
 
 } // namespace Vulkan
index aefb4e9..b566e27 100644 (file)
@@ -26,74 +26,104 @@ namespace Graphics
 {
 namespace Vulkan
 {
-
 class ImageView;
-enum class ResourceOwnershipType
-{
-  OWNED,
-  EXTERNAL
-};
-
 class Image : public VkManaged
 {
 public:
   /**
-   * Creates new VkImage with given specification, it doesn't
-   * bind the memory.
+   * Creates new managed Image object
    * @param graphics
    * @param createInfo
+   * @return
    */
-  Image(Graphics& graphics, const vk::ImageCreateInfo& createInfo);
+  static ImageRef New( Graphics& graphics, vk::ImageCreateInfo createInfo );
 
   /**
-   * Constructor creates wrapper on the VkImage coming from external
-   * source. It doesn't take over ownership so it's still owner's
-   * responsibility to destroy it and maintain the usage.
-   *
+   * Creates new managed object from external image, lifecycle must be managed
+   * explicitly, as well as any data
    * @param graphics
-   * @param externalImage
+   * @param createInfo
+   * @param image
+   * @return
    */
-  Image(Graphics& graphics, vk::Image externalImage);
+  static ImageRef New( Graphics& graphics, vk::ImageCreateInfo createInfo, vk::Image externalImage );
 
   /**
    * Destructor
    */
-  virtual ~Image() = default;
+  ~Image() override;
 
   /**
-   * Creates UNMANAGED VkImageView from the current image.
-   * Usage requires external lifecycle management and synchronization
-   * Memory MUST be bound for this function to work!
-   * @param info
+   * Returns underlying Vulkan object
    * @return
    */
-  vk::ImageView CreateUnmanagedView(const vk::ImageViewCreateInfo& info);
+  vk::Image GetVkImage() const;
 
   /**
-   * Creates MANAGED ImageView from the current image
-   * Memory MUST be bound for this function to work!
-   * @param info
+   * Returns VkImageLayout associated with the image
    * @return
    */
-  ImageViewRef CreateView(const vk::ImageViewCreateInfo& info);
+  vk::ImageLayout GetVkImageLayout() const;
 
   /**
-   * Returns underlying Vulkan object
+   * Returns width in pixels
    * @return
    */
-  vk::Image GetImage() const
-  {
-    return mImage;
-  }
+  uint32_t GetWidth() const;
 
-private:
+  /**
+   * Returns height in pixels
+   * @return
+   */
+  uint32_t GetHeight() const;
 
-  Graphics& mGraphics;
+  /**
+   * Returns number of layers
+   * @return
+   */
+  uint32_t GetLayerCount() const;
 
-  vk::Image       mImage;
-  vk::ImageLayout mLayout;
+  /**
+   * Returns number of mipmap levels
+   * @return
+   */
+  uint32_t GetLevelCount() const;
+
+  /**
+   * Returns pixel format
+   * @return
+   */
+  vk::Format GetVkFormat() const;
 
-  ResourceOwnershipType mOwnershipType;
+  /**
+   * returns image type ( VkImageType)
+   * @return
+   */
+  vk::ImageType GetVkImageType() const;
+
+  /**
+   * Returns used image tiling mode
+   * @return
+   */
+  vk::ImageTiling GetVkImageTiling() const;
+
+  /**
+   * Binds image memory
+   * @param handle
+   */
+  void BindMemory( GpuMemoryBlockRef& handle );
+
+  /**
+   * Creates new VkImage with given specification, it doesn't
+   * bind the memory.
+   * @param graphics
+   * @param createInfo
+   */
+  Image( Graphics& graphics, const vk::ImageCreateInfo& createInfo, vk::Image externalImage );
+
+private:
+  class Impl;
+  std::unique_ptr<Impl> mImpl;
 };
 
 /*
@@ -103,27 +133,29 @@ private:
 class ImageView : public VkManaged
 {
 public:
-  ImageView(Graphics& graphics, Image& image);
-  ImageView(Graphics& graphics, Image& image, const VkImageViewCreateInfo& createInfo);
+
+  static ImageViewRef New( Graphics& graphics, ImageRef image, vk::ImageViewCreateInfo info );
 
   virtual ~ImageView() override;
 
-  const vk::ImageView& GetImageView() const
-  {
-    return mImageView;
-  }
+  /**
+   *
+   * @return
+   */
+  const vk::ImageView& GetVkImageView() const;
 
-  Image& GetImage() const
-  {
-    return *mImageRef;
-  }
+  /**
+   * Returns bound ImageRef
+   * @return
+   */
+  ImageRef GetImage() const;
 
 private:
 
-  Graphics&             mGraphics;
-  Handle<Image>         mImageRef;
+  ImageView( Graphics& graphics, ImageRef image, const VkImageViewCreateInfo& createInfo );
 
-  vk::ImageView mImageView;
+  class Impl;
+  std::unique_ptr<Impl> mImpl;
 };
 
 } // namespace Vulkan
index ff62bb0..b7491d1 100644 (file)
@@ -49,7 +49,6 @@ using namespace glm;
 using Dali::Integration::Graphics::Graphics;
 using Dali::Integration::Graphics::Vulkan::VkSurfaceFactory;
 using Dali::Graphics::Vulkan::Buffer;
-using Dali::Graphics::Vulkan::DeviceMemory;
 using Dali::Graphics::Vulkan::Shader;
 using Dali::Graphics::Vulkan::DescriptorSetLayout;
 using Dali::Graphics::Vulkan::GpuMemoryManager;
@@ -218,7 +217,7 @@ std::unique_ptr< Test::xcb_window_t > create_xcb_window(int width, int height)
 namespace VulkanTest
 {
 
-Dali::Graphics::Vulkan::GpuMemoryBlockHandle test_gpu_memory_manager( Dali::Graphics::Vulkan::Graphics& graphics,
+Dali::Graphics::Vulkan::GpuMemoryBlockRef test_gpu_memory_manager( Dali::Graphics::Vulkan::Graphics& graphics,
                                          GpuMemoryManager& gpuManager,
                                          const Dali::Graphics::Vulkan::Handle<Buffer>& buffer )
 {
@@ -244,14 +243,14 @@ mat4 MVP;
 
 
 template <class T>
-void update_buffer( Dali::Graphics::Vulkan::BufferHandle buffer, T& value )
+void update_buffer( Dali::Graphics::Vulkan::BufferRef buffer, T& value )
 {
   auto ptr = reinterpret_cast<T*>(buffer->GetMemoryHandle()->Map());
   *ptr = value;
   buffer->GetMemoryHandle()->Unmap();
 }
 
-void update_translation( Dali::Graphics::Vulkan::BufferHandle buffer )
+void update_translation( Dali::Graphics::Vulkan::BufferRef buffer )
 {
   static float x = 0.0f;
   x += 0.5f;
@@ -274,7 +273,7 @@ void update_translation( Dali::Graphics::Vulkan::BufferHandle buffer )
   update_buffer( buffer, ub );
 }
 
-Dali::Graphics::Vulkan::BufferHandle create_uniform_buffer( Dali::Graphics::Vulkan::Graphics& gr )
+Dali::Graphics::Vulkan::BufferRef create_uniform_buffer( Dali::Graphics::Vulkan::Graphics& gr )
 {
   // create uniform buffer
   auto uniformBuffer = Buffer::New( gr, sizeof(UniformData), Buffer::Type::UNIFORM );
@@ -328,7 +327,7 @@ void test_handle()
 {
   /*
   using namespace Dali::Graphics::Vulkan;
-  GpuMemoryBlockHandle handle( new GpuMemoryBlock() );
+  GpuMemoryBlockRef handle( new GpuMemoryBlock() );
 
   decltype(handle) handle2 = handle;
   handle.GetRefCount();*/
index c38377a..3547724 100644 (file)
@@ -295,7 +295,7 @@ void Surface::InitialiseSwapchain()
 void Surface::AddSwapchainImage(vk::Image image, std::vector< SwapchainImage >& swapchainImages)
 {
   auto swapImage  = std::move(SwapchainImage{});
-  swapImage.image = MakeRef<Image>( mGraphics, image );
+  swapImage.image = NewRef<Image>( mGraphics, vk::ImageCreateInfo{}, image );
 
   // create ImageView
   CreateImageView(swapImage);
@@ -318,7 +318,7 @@ void Surface::CreateImageView(SwapchainImage& swapImage)
   auto ivInfo = vk::ImageViewCreateInfo{};
   ivInfo.setFormat(mFormat)
       .setComponents(VK_COMPONENT_MAPPING_RGBA)
-      .setImage(swapImage.image->GetImage())
+      .setImage(swapImage.image->GetVkImage())
       .setSubresourceRange(vk::ImageSubresourceRange()
                                .setAspectMask(vk::ImageAspectFlagBits::eColor)
                                .setBaseArrayLayer(0)
@@ -327,14 +327,14 @@ void Surface::CreateImageView(SwapchainImage& swapImage)
                                .setLevelCount(1))
       .setViewType(vk::ImageViewType::e2D);
 
-  swapImage.imageView = swapImage.image->CreateView( ivInfo );
+  swapImage.imageView = ImageView::New( mGraphics, swapImage.image, ivInfo );
 }
 
 void Surface::CreateFramebuffer(SwapchainImage& swapImage)
 {
   vk::FramebufferCreateInfo fbInfo;
   fbInfo.setAttachmentCount(mHasDepthStencil ? 2 : 1)
-      .setPAttachments(&swapImage.imageView->GetImageView()) // todo: add depth/stencil attachment
+      .setPAttachments(&swapImage.imageView->GetVkImageView()) // todo: add depth/stencil attachment
       .setHeight(mExtent.height)
       .setWidth(mExtent.width)
       .setLayers(1)
@@ -430,7 +430,7 @@ void Surface::CreateCommandBuffers()
     // Record layout transition for each image, after transition command buffers will be re-recorded
     // and will take in account only present -> color layout transition
     swapImage.layoutToColorCmdBuf->Begin();
-    swapImage.layoutToColorCmdBuf->ImageLayoutTransition(swapImage.image->GetImage(),
+    swapImage.layoutToColorCmdBuf->ImageLayoutTransition(swapImage.image->GetVkImage(),
                                                          swapImage.layout,
                                                          vk::ImageLayout::eColorAttachmentOptimal,
                                                          vk::ImageAspectFlagBits::eColor);
@@ -453,7 +453,7 @@ void Surface::CreateCommandBuffers()
   {
     swapImage.layoutToColorCmdBuf->Reset();
     swapImage.layoutToColorCmdBuf->Begin();
-    swapImage.layoutToColorCmdBuf->ImageLayoutTransition(swapImage.image->GetImage(),
+    swapImage.layoutToColorCmdBuf->ImageLayoutTransition(swapImage.image->GetVkImage(),
                                                          vk::ImageLayout::ePresentSrcKHR,
                                                          vk::ImageLayout::eColorAttachmentOptimal,
                                                          vk::ImageAspectFlagBits::eColor);
index 9ccc269..bf0f292 100644 (file)
@@ -261,7 +261,20 @@ Handle<K> Handle<T>::DynamicCast()
 template< typename T, typename... Args >
 Handle< T > MakeRef(Args&&... args)
 {
-  return Handle< T  >(new T(std::forward< Args >(args)...));
+  return Handle< T >(new T(std::forward< Args >(args)...));
+}
+
+template< typename T, typename... Args >
+Handle< T > NewRef(Args&&... args)
+{
+  return Handle< T >(T::New(std::forward< Args >(args)...));
+}
+
+
+template<class T>
+typename T::Impl& GetImpl( Handle<T>& object )
+{
+  return static_cast<typename T::Impl&>(*object->mImpl);
 }
 
 class VkManaged
@@ -331,7 +344,7 @@ using ImageViewRef = Handle<class ImageView>;
 using DescriptorPoolRef = Handle<class DescriptorPool>;
 using CommandPoolRef = Handle<class CommandPool>;
 using CommandBufferRef = Handle<class CommandBuffer>;
-
+using GpuMemoryBlockRef = Handle<class GpuMemoryBlock>;
 /*
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wframe-larger-than="