VulkanImageView moved to separate files
authorAngelos Gkountis <a.gkountis@samsung.com>
Tue, 29 May 2018 12:45:29 +0000 (13:45 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 11 Jun 2018 13:00:03 +0000 (13:00 +0000)
> Now the Graphics class has a single instance of the Resource class
> Cache insertions and removals use mutex locks to synchronize
> Removed not needed #pragmas.
> Applied correct code formatting on vulkan-graphics.cpp

Change-Id: Ib1bcbc3aae7a2099cd4338d2521f9f014f1e3850

15 files changed:
dali/graphics/file.list
dali/graphics/vulkan/api/vulkan-api-render-command.cpp
dali/graphics/vulkan/vulkan-command-buffer.cpp
dali/graphics/vulkan/vulkan-descriptor-set.cpp
dali/graphics/vulkan/vulkan-framebuffer.cpp
dali/graphics/vulkan/vulkan-graphics-texture.cpp
dali/graphics/vulkan/vulkan-graphics.cpp
dali/graphics/vulkan/vulkan-graphics.h
dali/graphics/vulkan/vulkan-image-view.cpp [new file with mode: 0644]
dali/graphics/vulkan/vulkan-image-view.h [new file with mode: 0644]
dali/graphics/vulkan/vulkan-image.cpp
dali/graphics/vulkan/vulkan-image.h
dali/graphics/vulkan/vulkan-resource-cache.cpp
dali/graphics/vulkan/vulkan-swapchain.cpp
dali/graphics/vulkan/vulkan-types.h

index b489b78..648d87b 100644 (file)
@@ -11,6 +11,7 @@ graphics_src_files = \
     $(graphics_src_dir)/vulkan/gpu-memory/vulkan-gpu-memory-handle.cpp \
     $(graphics_src_dir)/vulkan/gpu-memory/vulkan-gpu-memory-manager.cpp \
     $(graphics_src_dir)/vulkan/vulkan-image.cpp \
+    $(graphics_src_dir)/vulkan/vulkan-image-view.cpp \
     $(graphics_src_dir)/vulkan/vulkan-command-buffer.cpp \
     $(graphics_src_dir)/vulkan/vulkan-pipeline.cpp \
     $(graphics_src_dir)/vulkan/vulkan-pipeline-cache.cpp \
index 8fef24b..f73d94d 100644 (file)
@@ -28,6 +28,7 @@
 #include <dali/graphics/vulkan/vulkan-pipeline.h>
 #include <dali/graphics/vulkan/vulkan-sampler.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
 #include <dali/graphics/vulkan/vulkan-descriptor-set.h>
 #include <dali/graphics/vulkan/vulkan-swapchain.h>
index 6f85def..e0701bb 100644 (file)
@@ -325,7 +325,7 @@ struct CommandBuffer::Impl
          .setOldLayout( oldLayout )
          .setSrcAccessMask( srcAccessMask )
          .setDstAccessMask( dstAccessMask )
-         .setSubresourceRange( vk::ImageSubresourceRange{ aspectMask, 0, image->GetLevelCount(), 0, image->GetLayerCount() } );
+         .setSubresourceRange( vk::ImageSubresourceRange{ aspectMask, 0, image->GetMipLevelCount(), 0, image->GetLayerCount() } );
   }
 
   CommandBuffer&                mOwner;
index 6f1ff4a..25a44fb 100644 (file)
@@ -19,6 +19,7 @@
 #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-image-view.h>
 #include <dali/graphics/vulkan/vulkan-sampler.h>
 
 namespace Dali
@@ -172,7 +173,7 @@ struct DescriptorSet::Impl
 
     auto imageViewInfo = vk::DescriptorImageInfo{}
          .setImageLayout( vk::ImageLayout::eShaderReadOnlyOptimal )
-         .setImageView( imageView->GetVkImageView() )
+         .setImageView( imageView->GetVkHandle() )
          .setSampler(sampler->GetVkHandle() );
 
     auto write = vk::WriteDescriptorSet{}.setPImageInfo( &imageViewInfo )
index 413fa67..7ae876b 100644 (file)
@@ -18,6 +18,7 @@
 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
 #include <dali/graphics/vulkan/vulkan-graphics.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
 
 namespace Dali
 {
@@ -52,7 +53,7 @@ struct Framebuffer::Impl
       attRef.setLayout( vk::ImageLayout::eColorAttachmentOptimal );
       attRef.setAttachment( colorAttachmentSize++ );
       mAttachmentReference.emplace_back( attRef );
-      attachments.emplace_back( colorAttachment->GetVkImageView() );
+      attachments.emplace_back( colorAttachment->GetVkHandle() );
 
       vk::AttachmentDescription attDesc{};
       attDesc.setSamples( vk::SampleCountFlagBits::e1 )
@@ -81,7 +82,7 @@ struct Framebuffer::Impl
       attRef.setLayout( vk::ImageLayout::eDepthStencilAttachmentOptimal );
       attRef.setAttachment( colorAttachmentSize );
       mAttachmentReference.emplace_back( attRef );
-      attachments.emplace_back( mDepthStencilImageViewAttachment->GetVkImageView() );
+      attachments.emplace_back( mDepthStencilImageViewAttachment->GetVkHandle() );
 
       vk::AttachmentDescription attDesc{};
       attDesc.setSamples( vk::SampleCountFlagBits::e1 )
index 494d760..63afce1 100644 (file)
 #include <dali/graphics/vulkan/vulkan-command-pool.h>
 #include <dali/graphics/vulkan/vulkan-graphics.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
 #include <dali/graphics/vulkan/vulkan-fence.h>
 #include <dali/graphics/vulkan/vulkan-queue.h>
 #include <dali/graphics/vulkan/vulkan-sampler.h>
 #include <thread>
+
 namespace Dali
 {
 namespace Graphics
@@ -40,8 +42,9 @@ struct Pixmap
   explicit Pixmap( uint32_t _width, uint32_t _height, vk::Format format  )
     : width( _width ), height( _height ), bytesPerPixel(1), pixelFormat( format )
   {
-    totalSizeInBytes = width*height*bytesPerPixel;
-    data.resize( totalSizeInBytes );
+    totalSizeInBytes = width * height * bytesPerPixel;
+    data.resize(totalSizeInBytes);
+  }
 
   explicit Pixmap( uint32_t _width, uint32_t _height )
   : width( _width ), height( _height ), bytesPerPixel( 4 ), pixelFormat( vk::Format::eR8G8B8A8Unorm )
@@ -155,6 +158,7 @@ struct Texture::Impl
   // uploaded at this point
   bool Initialise()
   {
+    //TODO: Create image using the Graphics class
     // create image
     mImage = Image::New( mGraphics,
                          vk::ImageCreateInfo{}
@@ -173,7 +177,7 @@ struct Texture::Impl
     mImage->BindMemory( allocator.Allocate( mImage, vk::MemoryPropertyFlagBits::eDeviceLocal ) );
 
     // create default image view
-    mImageView = ImageView::New( mGraphics, mImage );
+    mImageView = mGraphics.CreateImageView(mImage);
 
     // create basic sampler
     CreateSampler();
index 202c364..15ca0c9 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <dali/graphics/vulkan/vulkan-buffer.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
 #include <dali/graphics/vulkan/vulkan-pipeline.h>
 #include <dali/graphics/vulkan/vulkan-shader.h>
 #include <dali/graphics/vulkan/vulkan-descriptor-set.h>
@@ -34,6 +35,8 @@
 #include <dali/graphics/vulkan/vulkan-sampler.h>
 #include <dali/graphics/vulkan/vulkan-resource-cache.h>
 #include <dali/graphics/vulkan/vulkan-debug.h>
+#include <dali/graphics/vulkan/vulkan-fence.h>
+
 #include <dali/graphics-api/graphics-api-controller.h>
 
 #ifndef VK_KHR_XLIB_SURFACE_EXTENSION_NAME
@@ -48,6 +51,9 @@
 #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
 #endif
 
+#include <iostream>
+#include <utility>
+
 namespace Dali
 {
 namespace Graphics
@@ -74,6 +80,7 @@ const auto VALIDATION_LAYERS = std::vector< const char* >{
 };
 
 Graphics::Graphics() = default;
+
 Graphics::~Graphics() = default;
 
 // Create methods -----------------------------------------------------------------------------------------------
@@ -83,7 +90,7 @@ void Graphics::Create()
   auto extensions = PrepareDefaultInstanceExtensions();
 
   auto layers = vk::enumerateInstanceLayerProperties();
-  std::vector<const char*> validationLayers;
+  std::vector< const char* > validationLayers;
   for( auto&& reqLayer : VALIDATION_LAYERS )
   {
     for( auto&& prop : layers.value )
@@ -91,17 +98,18 @@ void Graphics::Create()
       DALI_LOG_STREAM( gVulkanFilter, Debug::General, prop.layerName );
       if( std::string(prop.layerName) == reqLayer )
       {
-        validationLayers.push_back(reqLayer);
+        validationLayers.push_back( reqLayer );
       }
     }
   }
 
-  CreateInstance(extensions, validationLayers);
+  CreateInstance( extensions, validationLayers );
   PreparePhysicalDevice();
 }
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wframe-larger-than="
+
 void Graphics::CreateDevice()
 {
   auto queueInfos = GetQueueCreateInfos();
@@ -112,82 +120,67 @@ void Graphics::CreateDevice()
       maxQueueCountPerFamily = std::max( info.queueCount, maxQueueCountPerFamily );
     }
 
-    auto priorities = std::vector<float>( maxQueueCountPerFamily );
+    auto priorities = std::vector< float >( maxQueueCountPerFamily );
     std::fill( priorities.begin(), priorities.end(), 1.0f );
 
     for( auto& info : queueInfos )
     {
-      info.setPQueuePriorities( priorities.data() );
+      info.setPQueuePriorities( priorities.data());
     }
 
-    std::vector< const char* > extensions{VK_KHR_SWAPCHAIN_EXTENSION_NAME};
+    std::vector< const char* > extensions{ VK_KHR_SWAPCHAIN_EXTENSION_NAME };
 
     auto info = vk::DeviceCreateInfo{};
-    info.setEnabledExtensionCount(U32(extensions.size()))
-            .setPpEnabledExtensionNames(extensions.data())
-            .setPEnabledFeatures(&(*mPhysicalDeviceFeatures))
-            .setPQueueCreateInfos(queueInfos.data())
-            .setQueueCreateInfoCount(U32(queueInfos.size()));
+    info.setEnabledExtensionCount( U32( extensions.size()))
+        .setPpEnabledExtensionNames( extensions.data())
+        .setPEnabledFeatures( &( *mPhysicalDeviceFeatures ))
+        .setPQueueCreateInfos( queueInfos.data())
+        .setQueueCreateInfoCount( U32( queueInfos.size()));
 
-    mDevice = VkAssert(mPhysicalDevice.createDevice(info, *mAllocator));
+    mDevice = VkAssert( mPhysicalDevice.createDevice( info, *mAllocator ));
   }
 
   // create Queue objects
-  for(auto& queueInfo : queueInfos)
+  for( auto& queueInfo : queueInfos )
   {
-    for(auto i = 0u; i < queueInfo.queueCount; ++i)
+    for( auto i = 0u; i < queueInfo.queueCount; ++i )
     {
-      auto queue = mDevice.getQueue(queueInfo.queueFamilyIndex, i);
+      auto queue = mDevice.getQueue( queueInfo.queueFamilyIndex, i );
 
       // based on family push queue instance into right array
       auto flags = mQueueFamilyProperties[queueInfo.queueFamilyIndex].queueFlags;
-      if(flags & vk::QueueFlagBits::eGraphics)
+      if( flags & vk::QueueFlagBits::eGraphics )
       {
         mGraphicsQueues.emplace_back(
-                MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+                MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
       }
-      if(flags & vk::QueueFlagBits::eTransfer)
+      if( flags & vk::QueueFlagBits::eTransfer )
       {
         mTransferQueues.emplace_back(
-                MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+                MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
       }
-      if(flags & vk::QueueFlagBits::eCompute)
+      if( flags & vk::QueueFlagBits::eCompute )
       {
         mComputeQueues.emplace_back(
-                MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+                MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
       }
 
       // todo: present queue
     }
   }
 
-  mPipelineDatabase = std::make_unique<PipelineCache>( *this );
-  mResourceCacheMap[std::this_thread::get_id()] = MakeUnique<ResourceCache>();
-}
-#pragma GCC diagnostic pop
-
-void Graphics::GetPhysicalDeviceProperties()
-{
-  // store data on heap to keep object smaller
-  mPhysicalDeviceProperties =
-    MakeUnique<vk::PhysicalDeviceProperties>(mPhysicalDevice.getProperties());
-  mPhysicalDeviceMemoryProperties =
-    MakeUnique<vk::PhysicalDeviceMemoryProperties>(mPhysicalDevice.getMemoryProperties());
-  mPhysicalDeviceFeatures =
-    MakeUnique<vk::PhysicalDeviceFeatures>(mPhysicalDevice.getFeatures());
+  mPipelineDatabase = std::make_unique< PipelineCache >( *this );
+  mResourceCache = MakeUnique< ResourceCache >();
 }
 
-void Graphics::GetQueueFamilyProperties()
-{
-  mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
-}
+#pragma GCC diagnostic pop
 
-FBID Graphics::CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory)
+FBID Graphics::CreateSurface( std::unique_ptr< SurfaceFactory > surfaceFactory )
 {
   // create surface from the factory
-  auto surfaceRef = Surface::New( *this, std::move(surfaceFactory) );
+  auto surfaceRef = Surface::New( *this, std::move( surfaceFactory ));
 
-  if( surfaceRef->Create() )
+  if( surfaceRef->Create())
   {
 
     // map surface to FBID
@@ -201,15 +194,17 @@ FBID Graphics::CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory)
 RefCountedSwapchain Graphics::CreateSwapchainForSurface( RefCountedSurface surface )
 {
   auto swapchain = Swapchain::New( *this,
-                                   GetGraphicsQueue(0u),
+                                   GetGraphicsQueue( 0u ),
                                    surface, 4, 0 );
 
   // store swapchain in the correct pair
   for( auto&& val : mSurfaceFBIDMap )
   {
-    if( val.second.surface == surface )
+    if( val.second
+           .surface == surface )
     {
-      val.second.swapchain = swapchain;
+      val.second
+         .swapchain = swapchain;
       break;
     }
   }
@@ -229,57 +224,62 @@ RefCountedPipeline Graphics::CreatePipeline()
 
 RefCountedFence Graphics::CreateFence( const vk::FenceCreateInfo& fenceCreateInfo )
 {
-  auto refCountedFence = Fence::New(*this);
+  auto refCountedFence = Fence::New( *this );
 
-  VkAssert(mDevice.createFence(&fenceCreateInfo, mAllocator.get(), refCountedFence->Ref()));
+  VkAssert( mDevice.createFence( &fenceCreateInfo, mAllocator.get(), refCountedFence->Ref()));
 
   return refCountedFence;
 }
 
-RefCountedBuffer Graphics::CreateBuffer(size_t size, BufferType type)
+RefCountedBuffer Graphics::CreateBuffer( size_t size, BufferType type )
 {
   auto usageFlags = vk::BufferUsageFlags{};
 
-  switch ( type ) {
-    case BufferType::VERTEX: {
+  switch( type )
+  {
+    case BufferType::VERTEX:
+    {
       usageFlags |= vk::BufferUsageFlagBits::eVertexBuffer;
       break;
     };
-    case BufferType::INDEX: {
+    case BufferType::INDEX:
+    {
       usageFlags |= vk::BufferUsageFlagBits::eIndexBuffer;
       break;
     };
-    case BufferType::UNIFORM: {
+    case BufferType::UNIFORM:
+    {
       usageFlags |= vk::BufferUsageFlagBits::eUniformBuffer;
       break;
     };
-    case BufferType::SHADER_STORAGE: {
+    case BufferType::SHADER_STORAGE:
+    {
       usageFlags |= vk::BufferUsageFlagBits::eStorageBuffer;
       break;
     };
   }
 
   auto info = vk::BufferCreateInfo{};
-  info.setSharingMode(vk::SharingMode::eExclusive);
-  info.setSize(size);
-  info.setUsage(usageFlags | vk::BufferUsageFlagBits::eTransferDst);
+  info.setSharingMode( vk::SharingMode::eExclusive );
+  info.setSize( size );
+  info.setUsage( usageFlags | vk::BufferUsageFlagBits::eTransferDst );
 
-  auto refCountedBuffer = Buffer::New(*this, info);
+  auto refCountedBuffer = Buffer::New( *this, info );
 
-  VkAssert(mDevice.createBuffer(&info, mAllocator.get(), refCountedBuffer->Ref()));
+  VkAssert( mDevice.createBuffer( &info, mAllocator.get(), refCountedBuffer->Ref()));
 
-  AddBuffer(refCountedBuffer);
+  AddBuffer( refCountedBuffer );
 
   return refCountedBuffer;
 }
 
 RefCountedBuffer Graphics::CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo )
 {
-  auto refCountedBuffer = Buffer::New(*this, bufferCreateInfo);
+  auto refCountedBuffer = Buffer::New( *this, bufferCreateInfo );
 
-  VkAssert(mDevice.createBuffer(&bufferCreateInfo, mAllocator.get(), refCountedBuffer->Ref()));
+  VkAssert( mDevice.createBuffer( &bufferCreateInfo, mAllocator.get(), refCountedBuffer->Ref()));
 
-  AddBuffer(refCountedBuffer);
+  AddBuffer( refCountedBuffer );
 
   return refCountedBuffer;
 }
@@ -294,9 +294,61 @@ RefCountedImage Graphics::CreateImage()
   NotImplemented()
 }
 
-RefCountedImageView Graphics::CreateImageView()
+RefCountedImageView Graphics::CreateImageView( const vk::ImageViewCreateFlags& flags,
+                                               const RefCountedImage& image,
+                                               vk::ImageViewType viewType,
+                                               vk::Format format,
+                                               vk::ComponentMapping components,
+                                               vk::ImageSubresourceRange subresourceRange )
 {
-  NotImplemented()
+  auto imageViewCreateInfo = vk::ImageViewCreateInfo{}
+          .setFlags( flags )
+          .setImage( image->GetVkHandle())
+          .setViewType( viewType )
+          .setFormat( format )
+          .setComponents( components )
+          .setSubresourceRange( std::move( subresourceRange ));
+
+  auto refCountedImageView = ImageView::New( *this, image, imageViewCreateInfo );
+
+  VkAssert( mDevice.createImageView( &imageViewCreateInfo, nullptr, refCountedImageView->Ref()));
+
+  return refCountedImageView;
+}
+
+RefCountedImageView Graphics::CreateImageView( RefCountedImage image )
+{
+  vk::ComponentMapping componentsMapping = { vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG,
+                                             vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA };
+  vk::ImageAspectFlags aspectFlags{};
+  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eColorAttachment )
+  {
+    aspectFlags |= vk::ImageAspectFlagBits::eColor;
+    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB,vk::ComponentSwizzle::eA };
+  }
+  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eDepthStencilAttachment )
+  {
+    aspectFlags |= ( vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil );
+  }
+  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eSampled )
+  {
+    aspectFlags |= ( vk::ImageAspectFlagBits::eColor );
+    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eR,vk::ComponentSwizzle::eA };
+  }
+
+  auto subresourceRange = vk::ImageSubresourceRange{}
+          .setAspectMask( aspectFlags )
+          .setBaseArrayLayer( 0 )
+          .setBaseMipLevel( 0 )
+          .setLevelCount( image->GetMipLevelCount())
+          .setLayerCount( image->GetLayerCount());
+
+  return CreateImageView( {},
+                          image,
+                          vk::ImageViewType::e2D,
+                          image->GetVkFormat(),
+                          componentsMapping,
+                          subresourceRange );
 }
 
 RefCountedDescriptorPool Graphics::CreateDescriptorPool()
@@ -304,11 +356,13 @@ RefCountedDescriptorPool Graphics::CreateDescriptorPool()
   NotImplemented()
 }
 
-RefCountedCommandPool Graphics::CreateCommandPool(const vk::CommandPoolCreateInfo& info)
+RefCountedCommandPool Graphics::CreateCommandPool( const vk::CommandPoolCreateInfo& info )
 {
+  //TODO: move the logic of creation here
+  //TODO: add the object to the cache
   return CommandPool::New( *this,
                            vk::CommandPoolCreateInfo{}.setQueueFamilyIndex( 0u )
-                                                      .setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer ) );
+                                                      .setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer ));
 }
 
 RefCountedCommandBuffer Graphics::CreateCommandBuffer()
@@ -316,7 +370,7 @@ RefCountedCommandBuffer Graphics::CreateCommandBuffer()
   NotImplemented()
 }
 
-std::vector<RefCountedCommandBuffer> Graphics::CreateCommandBuffers()
+std::vector< RefCountedCommandBuffer > Graphics::CreateCommandBuffers()
 {
   NotImplemented()
 }
@@ -340,38 +394,35 @@ RefCountedSampler Graphics::CreateSampler()
 // Actions ------------------------------------------------------------------------------------------------------
 vk::Result Graphics::WaitForFence( RefCountedFence fence, uint32_t timeout )
 {
-  return mDevice.waitForFences(1, *fence, VK_TRUE, timeout);
+  return mDevice.waitForFences( 1, *fence, VK_TRUE, timeout );
 }
-#pragma GCC diagnostic pop
 
-vk::Result Graphics::WaitForFences( const std::vector<RefCountedFence>& fences, bool waitAll, uint32_t timeout )
+vk::Result Graphics::WaitForFences( const std::vector< RefCountedFence >& fences, bool waitAll, uint32_t timeout )
 {
-  std::vector<vk::Fence> vkFenceHandles{};
-  std::transform(fences.begin(),
-                 fences.end(),
-                 std::back_inserter(vkFenceHandles),
-                 [](RefCountedFence entry){ return entry->GetVkHandle(); });
+  std::vector< vk::Fence > vkFenceHandles{};
+  std::transform( fences.begin(),
+                  fences.end(),
+                  std::back_inserter( vkFenceHandles ),
+                  []( RefCountedFence entry ) { return entry->GetVkHandle(); } );
 
-    auto priorities = std::vector<float>( maxQueueCountPerFamily );
-    std::fill( priorities.begin(), priorities.end(), 1.0f );
 
-  return mDevice.waitForFences(vkFenceHandles, vk::Bool32(waitAll), timeout);
+  return mDevice.waitForFences( vkFenceHandles, vk::Bool32( waitAll ), timeout );
 }
 
 vk::Result Graphics::ResetFence( RefCountedFence fence )
 {
-  return mDevice.resetFences(1, *fence);
+  return mDevice.resetFences( 1, *fence );
 }
 
-vk::Result Graphics::ResetFences( const std::vector<RefCountedFence>& fences )
+vk::Result Graphics::ResetFences( const std::vector< RefCountedFence >& fences )
 {
-  std::vector<vk::Fence> vkFenceHandles{};
-  std::transform(fences.begin(),
-                 fences.end(),
-                 std::back_inserter(vkFenceHandles),
-                 [](RefCountedFence entry){ return entry->GetVkHandle(); });
+  std::vector< vk::Fence > vkFenceHandles{};
+  std::transform( fences.begin(),
+                  fences.end(),
+                  std::back_inserter( vkFenceHandles ),
+                  []( RefCountedFence entry ) { return entry->GetVkHandle(); } );
 
-  return mDevice.resetFences(vkFenceHandles);
+  return mDevice.resetFences( vkFenceHandles );
 }
 // --------------------------------------------------------------------------------------------------------------
 
@@ -382,7 +433,9 @@ RefCountedSurface Graphics::GetSurface( FBID surfaceId )
   // such thing as default framebuffer.
   if( surfaceId == 0 )
   {
-    return mSurfaceFBIDMap.begin()->second.surface;
+    return mSurfaceFBIDMap.begin()
+                          ->second
+                          .surface;
   }
   return mSurfaceFBIDMap[surfaceId].surface;
 }
@@ -391,10 +444,11 @@ RefCountedSwapchain Graphics::GetSwapchainForSurface( RefCountedSurface surface
 {
   for( auto&& val : mSurfaceFBIDMap )
   {
-    if( val.second.surface == surface )
+    if( val.second
+           .surface == surface )
     {
       return val.second
-              .swapchain;
+                .swapchain;
     }
   }
   return RefCountedSwapchain();
@@ -402,13 +456,14 @@ RefCountedSwapchain Graphics::GetSwapchainForSurface( RefCountedSurface surface
 
 RefCountedSwapchain Graphics::GetSwapchainForFBID( FBID surfaceId )
 {
-  if(surfaceId == 0)
+  if( surfaceId == 0 )
   {
-    return mSurfaceFBIDMap.begin()->second.swapchain;
+    return mSurfaceFBIDMap.begin()
+                          ->second
+                          .swapchain;
   }
   return mSurfaceFBIDMap[surfaceId].swapchain;
 }
-#pragma GCC diagnostic pop
 
 vk::Device Graphics::GetDevice() const
 {
@@ -440,29 +495,29 @@ const vk::PhysicalDeviceMemoryProperties& Graphics::GetMemoryProperties() const
   return *mPhysicalDeviceMemoryProperties;
 }
 
-Queue& Graphics::GetGraphicsQueue(uint32_t index) const
+Queue& Graphics::GetGraphicsQueue( uint32_t index ) const
 {
   // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
   // this will change in the future
-  assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+  assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
 
   return *mGraphicsQueues[0]; // will be mGraphicsQueues[index]
 }
 
-Queue& Graphics::GetTransferQueue(uint32_t index) const
+Queue& Graphics::GetTransferQueue( uint32_t index ) const
 {
   // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
   // this will change in the future
-  assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+  assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
 
   return *mTransferQueues[0]; // will be mGraphicsQueues[index]
 }
 
-Queue& Graphics::GetComputeQueue(uint32_t index) const
+Queue& Graphics::GetComputeQueue( uint32_t index ) const
 {
   // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
   // this will change in the future
-  assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+  assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
 
   return *mComputeQueues[0]; // will be mGraphicsQueues[index]
 }
@@ -470,7 +525,7 @@ Queue& Graphics::GetComputeQueue(uint32_t index) const
 Queue& Graphics::GetPresentQueue() const
 {
   // fixme: should be a dedicated presentation queue
-  return GetGraphicsQueue(0);
+  return GetGraphicsQueue( 0 );
 }
 
 Platform Graphics::GetDefaultPlatform() const
@@ -488,9 +543,9 @@ Platform Graphics::GetDefaultPlatform() const
 
 Dali::Graphics::API::Controller& Graphics::GetController()
 {
-  if(!mGfxController)
+  if( !mGfxController )
   {
-    mGfxController = Dali::Graphics::VulkanAPI::Controller::New(*this);
+    mGfxController = Dali::Graphics::VulkanAPI::Controller::New( *this );
   }
 
   return *mGfxController;
@@ -503,89 +558,107 @@ PipelineCache& Graphics::GetPipelineCache()
 // --------------------------------------------------------------------------------------------------------------
 
 // Cache manipulation methods -----------------------------------------------------------------------------------
-void Graphics::AddBuffer( Handle<Buffer> buffer )
+void Graphics::AddBuffer( Handle< Buffer > buffer )
 {
-  GetResourceCache(std::this_thread::get_id())->AddBuffer(std::move(buffer));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddBuffer( std::move( buffer ));
 }
 
-void Graphics::AddImage( Handle<Image> image )
+void Graphics::AddImage( Handle< Image > image )
 {
-  GetResourceCache(std::this_thread::get_id())->AddImage(std::move(image));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddImage( std::move( image ));
 }
 
-void Graphics::AddShader( Handle<Shader> shader )
+void Graphics::AddShader( Handle< Shader > shader )
 {
-  GetResourceCache(std::this_thread::get_id())->AddShader(std::move(shader));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddShader( std::move( shader ));
 }
 
-void Graphics::AddCommandPool( Handle<CommandPool> pool )
+void Graphics::AddCommandPool( Handle< CommandPool > pool )
 {
-  GetResourceCache(std::this_thread::get_id())->AddCommandPool(std::move(pool));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddCommandPool( std::move( pool ));
 }
 
-void Graphics::AddDescriptorPool( Handle<DescriptorPool> pool )
+void Graphics::AddDescriptorPool( Handle< DescriptorPool > pool )
 {
-  GetResourceCache(std::this_thread::get_id())->AddDescriptorPool(std::move(pool));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddDescriptorPool( std::move( pool ));
 }
 
-void Graphics::AddFramebuffer( Handle<Framebuffer> framebuffer )
+void Graphics::AddFramebuffer( Handle< Framebuffer > framebuffer )
 {
-  GetResourceCache(std::this_thread::get_id())->AddFramebuffer(std::move(framebuffer));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->AddFramebuffer( std::move( framebuffer ));
 }
 
 RefCountedShader Graphics::FindShader( vk::ShaderModule shaderModule )
 {
-  return GetResourceCache(std::this_thread::get_id())->FindShader(shaderModule);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  return mResourceCache->FindShader( shaderModule );
 }
 
 RefCountedImage Graphics::FindImage( vk::Image image )
 {
-  return GetResourceCache(std::this_thread::get_id())->FindImage(image);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  return mResourceCache->FindImage( image );
 }
 
 void Graphics::RemoveBuffer( Buffer& buffer )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveBuffer(buffer);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveBuffer( buffer );
 }
 
 void Graphics::RemoveShader( Shader& shader )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveShader(shader);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveShader( shader );
 }
 
 void Graphics::RemoveCommandPool( CommandPool& commandPool )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveCommandPool(commandPool);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveCommandPool( commandPool );
 }
 
 void Graphics::RemoveDescriptorPool( DescriptorPool& pool )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveDescriptorPool(pool);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveDescriptorPool( pool );
 }
 
 void Graphics::RemoveFramebuffer( Framebuffer& framebuffer )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveFramebuffer(framebuffer);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveFramebuffer( framebuffer );
 }
 
 void Graphics::RemoveSampler( Sampler& sampler )
 {
-  GetResourceCache(std::this_thread::get_id())->RemoveSampler(sampler);
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->RemoveSampler( sampler );
 }
 
 void Graphics::CollectGarbage()
 {
-  GetResourceCache(std::this_thread::get_id())->CollectGarbage();
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->CollectGarbage();
 }
 
-void Graphics::DiscardResource( std::function<void()> deleter )
+void Graphics::DiscardResource( std::function< void() > deleter )
 {
-  GetResourceCache(std::this_thread::get_id())->EnqueueDiscardOperation(std::move(deleter));
+  std::lock_guard< std::mutex > lock{ mMutex };
+  mResourceCache->EnqueueDiscardOperation( std::move( deleter ));
 }
 // --------------------------------------------------------------------------------------------------------------
 
 
-void Graphics::CreateInstance( const std::vector<const char*>& extensions, const std::vector<const char*>& validationLayers )
+void
+Graphics::CreateInstance( const std::vector< const char* >& extensions,
+                          const std::vector< const char* >& validationLayers )
 {
   auto info = vk::InstanceCreateInfo{};
 
@@ -606,9 +679,9 @@ void Graphics::CreateInstance( const std::vector<const char*>& extensions, const
 
 void Graphics::DestroyInstance()
 {
-  if(mInstance)
+  if( mInstance )
   {
-    mInstance.destroy(*mAllocator);
+    mInstance.destroy( *mAllocator );
     mInstance = nullptr;
   }
 }
@@ -616,22 +689,21 @@ void Graphics::DestroyInstance()
 
 void Graphics::PreparePhysicalDevice()
 {
-  auto devices = VkAssert(mInstance.enumeratePhysicalDevices());
-  assert(!devices.empty() && "No Vulkan supported device found!");
+  auto devices = VkAssert( mInstance.enumeratePhysicalDevices());
+  assert( !devices.empty() && "No Vulkan supported device found!" );
 
   // if only one, pick first
   mPhysicalDevice = nullptr;
-  if(devices.size() == 1)
+  if( devices.size() == 1 )
   {
     mPhysicalDevice = devices[0];
-  }
-  else // otherwise look for one which is a graphics device
+  }else // otherwise look for one which is a graphics device
   {
-    for(auto& device : devices)
+    for( auto& device : devices )
     {
-      auto properties =device.getProperties();
-      if(properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu ||
-         properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu)
+      auto properties = device.getProperties();
+      if( properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu ||
+          properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu )
       {
         mPhysicalDevice = device;
         break;
@@ -639,7 +711,7 @@ void Graphics::PreparePhysicalDevice()
     }
   }
 
-  assert(mPhysicalDevice && "No suitable Physical Device found!");
+  assert( mPhysicalDevice && "No suitable Physical Device found!" );
 
   GetPhysicalDeviceProperties();
 
@@ -652,11 +724,11 @@ void Graphics::GetPhysicalDeviceProperties()
 {
   // store data on heap to keep object smaller
   mPhysicalDeviceProperties =
-    MakeUnique<vk::PhysicalDeviceProperties>(mPhysicalDevice.getProperties());
+          MakeUnique< vk::PhysicalDeviceProperties >( mPhysicalDevice.getProperties());
   mPhysicalDeviceMemoryProperties =
-    MakeUnique<vk::PhysicalDeviceMemoryProperties>(mPhysicalDevice.getMemoryProperties());
+          MakeUnique< vk::PhysicalDeviceMemoryProperties >( mPhysicalDevice.getMemoryProperties());
   mPhysicalDeviceFeatures =
-    MakeUnique<vk::PhysicalDeviceFeatures>(mPhysicalDevice.getFeatures());
+          MakeUnique< vk::PhysicalDeviceFeatures >( mPhysicalDevice.getFeatures());
 }
 
 void Graphics::GetQueueFamilyProperties()
@@ -664,21 +736,19 @@ void Graphics::GetQueueFamilyProperties()
   mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
 }
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
 std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
 {
   // surface is needed in order to find a family that supports presentation to this surface
   // fixme: assuming all surfaces will be compatible with the queue family
-  assert(!mSurfaceFBIDMap.empty() &&
-         "At least one surface has to be created before creating VkDevice!");
+  assert( !mSurfaceFBIDMap.empty() &&
+          "At least one surface has to be created before creating VkDevice!" );
 
   std::vector< vk::DeviceQueueCreateInfo > queueInfos{};
 
   constexpr uint8_t MAX_QUEUE_TYPES = 3;
   // find suitable family for each type of queue
   uint32_t familyIndexType[MAX_QUEUE_TYPES];
-  std::fill(&familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES], -1u);
+  std::fill( &familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES], -1u );
 
   // Graphics
   auto& graphicsFamily = familyIndexType[0];
@@ -690,42 +760,45 @@ std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
   auto& presentFamily = familyIndexType[2];
 
   auto queueFamilyIndex = 0u;
-  for(auto& prop : mQueueFamilyProperties)
+  for( auto& prop : mQueueFamilyProperties )
   {
-    if((prop.queueFlags & vk::QueueFlagBits::eGraphics) && graphicsFamily == -1u)
+    if(( prop.queueFlags & vk::QueueFlagBits::eGraphics ) && graphicsFamily == -1u )
     {
       graphicsFamily = queueFamilyIndex;
     }
-    if((prop.queueFlags & vk::QueueFlagBits::eTransfer) && transferFamily == -1u)
+    if(( prop.queueFlags & vk::QueueFlagBits::eTransfer ) && transferFamily == -1u )
     {
       transferFamily = queueFamilyIndex;
     }
-    if(mPhysicalDevice.getSurfaceSupportKHR(queueFamilyIndex, mSurfaceFBIDMap.begin()->second.surface->GetSurfaceKHR())
-           .value &&
-       presentFamily == -1u)
+    if( mPhysicalDevice.getSurfaceSupportKHR( queueFamilyIndex, mSurfaceFBIDMap.begin()
+                                                                               ->second
+                                                                               .surface
+                                                                               ->GetSurfaceKHR())
+                       .value &&
+        presentFamily == -1u )
     {
       presentFamily = queueFamilyIndex;
     }
     ++queueFamilyIndex;
   }
 
-  assert(graphicsFamily != -1u && "No queue family that supports graphics operations!");
-  assert(transferFamily != -1u && "No queue family that supports transfer operations!");
-  assert(presentFamily != -1u && "No queue family that supports present operations!");
+  assert( graphicsFamily != -1u && "No queue family that supports graphics operations!" );
+  assert( transferFamily != -1u && "No queue family that supports transfer operations!" );
+  assert( presentFamily != -1u && "No queue family that supports present operations!" );
 
   // todo: we may require that the family must be same for all types of operations, it makes
   // easier to handle synchronisation related issues.
 
   // sort queues
-  std::sort(&familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES]);
+  std::sort( &familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES] );
 
   // allocate all queues from graphics family
   uint32_t prevQueueFamilyIndex = -1u;
 
-  for(auto i = 0u; i < MAX_QUEUE_TYPES; ++i)
+  for( auto i = 0u; i < MAX_QUEUE_TYPES; ++i )
   {
     auto& familyIndex = familyIndexType[i];
-    if(prevQueueFamilyIndex == familyIndex)
+    if( prevQueueFamilyIndex == familyIndex )
     {
       continue;
     }
@@ -736,26 +809,25 @@ std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
     // note the priorities are not being set as local pointer will out of scope, this
     // will be fixed by the caller function
     auto info = vk::DeviceQueueCreateInfo{}
-                    .setPQueuePriorities(nullptr)
-                    .setQueueCount(queueCount)
-                    .setQueueFamilyIndex(familyIndex);
-    queueInfos.push_back(info);
+            .setPQueuePriorities( nullptr )
+            .setQueueCount( queueCount )
+            .setQueueFamilyIndex( familyIndex );
+    queueInfos.push_back( info );
     prevQueueFamilyIndex = familyIndex;
   }
 
   return queueInfos;
 }
-#pragma GCC diagnostic pop
 
-std::vector<const char*> Graphics::PrepareDefaultInstanceExtensions()
+std::vector< const char* > Graphics::PrepareDefaultInstanceExtensions()
 {
   auto extensions = vk::enumerateInstanceExtensionProperties();
 
   std::string extensionName;
 
-  bool xlibAvailable    { false };
-  bool xcbAvailable     { false };
-  bool waylandAvailable { false };
+  bool xlibAvailable{ false };
+  bool xcbAvailable{ false };
+  bool waylandAvailable{ false };
 
   for( auto&& ext : extensions.value )
   {
@@ -774,7 +846,7 @@ std::vector<const char*> Graphics::PrepareDefaultInstanceExtensions()
     }
   }
 
-  std::vector<const char*> retval{};
+  std::vector< const char* > retval{};
 
   // depending on the platform validate extensions
   auto platform = GetDefaultPlatform();
@@ -825,17 +897,6 @@ std::vector<const char*> Graphics::PrepareDefaultInstanceExtensions()
   return retval;
 }
 
-std::unique_ptr<ResourceCache>& Graphics::GetResourceCache(std::thread::id threadId)
-{
-  if( mResourceCacheMap.count(threadId) == 0 )
-  {
-    std::lock_guard<std::mutex> lock{ mMutex };
-    mResourceCacheMap[threadId] = MakeUnique< ResourceCache >();
-  }
-
-  return mResourceCacheMap[threadId];
-}
-
 } // namespace Vulkan
 } // namespace Graphics
 } // namespace Dali
index 6b7f359..4cb64d8 100644 (file)
@@ -47,11 +47,6 @@ class Controller;
 
 namespace Vulkan
 {
-  UNDEFINED,
-  XLIB,
-  XCB,
-  WAYLAND,
-};
 
 class Buffer;
 class Image;
@@ -66,7 +61,6 @@ class PipelineCache;
 class ResourceCache;
 
 using SurfaceFactory = Dali::Integration::Graphics::SurfaceFactory;
-using ResourceCacheMap = std::unordered_map< std::thread::id, std::unique_ptr<ResourceCache> >;
 
 struct SwapchainSurfacePair
 {
@@ -96,7 +90,13 @@ public: // Create methods
   RefCountedBuffer                        CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo );
   RefCountedFramebuffer                   CreateFramebuffer();
   RefCountedImage                         CreateImage();
-  RefCountedImageView                     CreateImageView();
+  RefCountedImageView                     CreateImageView(const vk::ImageViewCreateFlags& flags,
+                                                          const RefCountedImage& image,
+                                                          vk::ImageViewType viewType,
+                                                          vk::Format format,
+                                                          vk::ComponentMapping components,
+                                                          vk::ImageSubresourceRange subresourceRange);
+  RefCountedImageView                     CreateImageView(RefCountedImage image);
   RefCountedDescriptorPool                CreateDescriptorPool();
   RefCountedCommandPool                   CreateCommandPool(const vk::CommandPoolCreateInfo& info);
   RefCountedCommandBuffer                 CreateCommandBuffer();
@@ -109,7 +109,7 @@ public: // Actions
   vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = 0 );
   vk::Result WaitForFences( const std::vector< RefCountedFence >& fences,
                             bool waitAll = true,
-                            uint32_t timeout = std::numeric_limits<uint32_t>::max() );
+                            uint32_t timeout = std::numeric_limits< uint32_t >::max() );
   vk::Result ResetFence( RefCountedFence fence );
   vk::Result ResetFences( const std::vector< RefCountedFence >& fences );
 
@@ -177,8 +177,6 @@ private: // Methods
   std::vector< vk::DeviceQueueCreateInfo >  GetQueueCreateInfos();
   std::vector<const char*>                  PrepareDefaultInstanceExtensions();
 
-  std::unique_ptr< ResourceCache >&         GetResourceCache(std::thread::id thread_id);
-
 private: // Members
 
   std::unique_ptr<GpuMemoryManager>                           mDeviceMemoryManager;
@@ -217,7 +215,8 @@ private: // Members
   std::unique_ptr<PipelineCache>                              mPipelineDatabase;
 
   std::mutex                                                  mMutex;
-  ResourceCacheMap                                            mResourceCacheMap;
+  std::unique_ptr< ResourceCache >                            mResourceCache;
+
 };
 
 } // namespace Vulkan
diff --git a/dali/graphics/vulkan/vulkan-image-view.cpp b/dali/graphics/vulkan/vulkan-image-view.cpp
new file mode 100644 (file)
index 0000000..2c2417d
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali/graphics/vulkan/vulkan-image-view.h>
+#include <dali/graphics/vulkan/vulkan-graphics.h>
+#include <dali/graphics/vulkan/vulkan-image.h>
+#include <utility>
+
+namespace Dali
+{
+namespace Graphics
+{
+namespace Vulkan
+{
+
+ImageView::ImageView( Graphics& graphics, RefCountedImage image, vk::ImageViewCreateInfo createInfo )
+        : mGraphics(&graphics),
+          mImage(std::move(image)),
+          mCreateInfo(std::move(createInfo)),
+          mImageView(nullptr)
+{
+}
+
+ImageView::~ImageView() = default;
+
+RefCountedImageView ImageView::New( Graphics& graphics,
+                                           const RefCountedImage& image,
+                                           const vk::ImageViewCreateInfo& createInfo )
+{
+  return RefCountedImageView( new ImageView(graphics, image, createInfo) );
+}
+
+vk::ImageView ImageView::GetVkHandle() const
+{
+  return mImageView;
+}
+
+RefCountedImage ImageView::GetImage() const
+{
+  return mImage;
+}
+
+uint32_t ImageView::GetLayerCount() const
+{
+  return mImage->GetLayerCount();
+}
+
+uint32_t ImageView::GetMipLevelCount() const
+{
+  return mImage->GetMipLevelCount();
+}
+
+vk::ImageAspectFlags ImageView::GetImageAspectMask() const
+{
+  return vk::ImageAspectFlags();
+}
+
+const ImageView& ImageView::ConstRef()
+{
+  return *this;
+}
+
+ImageView& ImageView::Ref()
+{
+  return *this;
+}
+
+ImageView::operator vk::ImageView*()
+{
+  return &mImageView;
+}
+
+} // namespace Vulkan
+} // namespace Graphics
+} // namespace Dali
+
diff --git a/dali/graphics/vulkan/vulkan-image-view.h b/dali/graphics/vulkan/vulkan-image-view.h
new file mode 100644 (file)
index 0000000..f322ca7
--- /dev/null
@@ -0,0 +1,101 @@
+#ifndef DALI_GRAPHICS_VULKAN_IMAGE_VIEW
+#define DALI_GRAPHICS_VULKAN_IMAGE_VIEW
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali/graphics/vulkan/vulkan-types.h>
+
+namespace Dali
+{
+namespace Graphics
+{
+namespace Vulkan
+{
+
+/*
+ * ImageView
+ */
+class ImageView : public VkManaged
+{
+public:
+
+  /**
+   * Creates ImageView according to the given spec
+   * @param graphics
+   * @param image
+   * @param info
+   * @return
+   */
+  static RefCountedImageView New( Graphics& graphics, const RefCountedImage& image, const vk::ImageViewCreateInfo& createInfo);
+
+
+  ~ImageView() override;
+
+  /**
+   *
+   * @return
+   */
+  vk::ImageView GetVkHandle() const;
+
+  /**
+   * Returns bound ImageRef
+   * @return
+   */
+  RefCountedImage GetImage() const;
+
+  /**
+   *
+   * @return
+   */
+  uint32_t GetLayerCount() const;
+
+  /**
+   *
+   * @return
+   */
+  uint32_t GetMipLevelCount() const;
+
+  /**
+   *
+   * @return
+   */
+  vk::ImageAspectFlags GetImageAspectMask() const;
+
+  const ImageView& ConstRef();
+
+  ImageView& Ref();
+
+  operator vk::ImageView*();
+
+private:
+  ImageView( Graphics& graphics,
+             RefCountedImage image,
+             vk::ImageViewCreateInfo createInfo );
+
+private:
+  Graphics*                      mGraphics;
+  RefCountedImage                mImage;
+  vk::ImageViewCreateInfo        mCreateInfo;
+  vk::ImageView                  mImageView;
+};
+
+} //namespace Vulkan
+} //namespace Graphics
+} //namespace Dali
+
+#endif //DALI_GRAPHICS_VULKAN_IMAGE_VIEW
index fe4d5f8..16603b1 100644 (file)
@@ -134,7 +134,7 @@ uint32_t Image::GetLayerCount() const
   return mImpl->mCreateInfo.arrayLayers;
 }
 
-uint32_t Image::GetLevelCount() const
+uint32_t Image::GetMipLevelCount() const
 {
   return mImpl->mCreateInfo.mipLevels;
 }
@@ -164,114 +164,6 @@ vk::ImageUsageFlags Image::GetVkImageUsageFlags() const
   return mImpl->mCreateInfo.usage;
 }
 
-/***************************************************************************
- *
- *  ImageView
- *
- */
-
-struct ImageView::Impl
-{
-  Impl( ImageView& owner, Graphics& graphics, RefCountedImage image, vk::ImageViewCreateInfo createInfo )
-  : mOwner( owner ), mGraphics( graphics ), mImage( image ), mCreateInfo( createInfo )
-  {
-  }
-
-  ~Impl()
-  {
-  }
-
-  bool Initialise()
-  {
-    mVkImageView = VkAssert( mGraphics.GetDevice().createImageView( mCreateInfo, mGraphics.GetAllocator() ) );
-    if( !mVkImageView )
-    {
-      return false;
-    }
-    return true;
-  }
-
-  ImageView&              mOwner;
-  Graphics&               mGraphics;
-  RefCountedImage                mImage;
-  vk::ImageViewCreateInfo mCreateInfo;
-
-  vk::ImageView mVkImageView;
-};
-
-RefCountedImageView ImageView::New( Graphics& graphics, RefCountedImage image, vk::ImageViewCreateInfo info )
-{
-  auto retval = RefCountedImageView( new ImageView( graphics, image, info ) );
-  if( !retval->mImpl->Initialise() )
-  {
-    return RefCountedImageView();
-  }
-  return retval;
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
-RefCountedImageView ImageView::New( Graphics& graphics, RefCountedImage image )
-{
-  vk::ComponentMapping componentsMapping = { vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB,vk::ComponentSwizzle::eA };
-  vk::ImageAspectFlags aspectFlags{};
-  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eColorAttachment )
-  {
-    aspectFlags |= vk::ImageAspectFlagBits::eColor;
-    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB,vk::ComponentSwizzle::eA };
-  }
-  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eDepthStencilAttachment )
-  {
-    aspectFlags |= (vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil);
-  }
-  if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eSampled )
-  {
-    aspectFlags |= (vk::ImageAspectFlagBits::eColor);
-    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eR,vk::ComponentSwizzle::eA };
-  }
-  auto subresourceRange = vk::ImageSubresourceRange{}
-    .setAspectMask( aspectFlags )
-    .setBaseArrayLayer( 0 )
-    .setBaseMipLevel( 0 )
-    .setLevelCount( image->GetLevelCount() )
-    .setLayerCount( image->GetLayerCount() );
-
-  // create reference, image may be null
-  auto retval = RefCountedImageView( new ImageView( graphics,
-                                             image,
-                                             vk::ImageViewCreateInfo{}
-                                               .setViewType( vk::ImageViewType::e2D )
-                                               .setFormat( image->GetVkFormat() )
-                                               .setSubresourceRange(subresourceRange)
-                                               .setComponents( componentsMapping )
-                                                .setImage(image->GetVkHandle() )));
-  if(!retval->mImpl->Initialise())
-  {
-    return RefCountedImageView();
-  }
-
-  return retval;
-}
-#pragma GCC diagnostic pop
-
-ImageView::ImageView( Graphics& graphics, RefCountedImage image, const VkImageViewCreateInfo& createInfo )
-{
-  mImpl = MakeUnique<Impl>( *this, graphics, image, createInfo );
-}
-
-
-ImageView::~ImageView() = default;
-
-const vk::ImageView& ImageView::GetVkImageView() const
-{
-  return mImpl->mVkImageView;
-}
-
-RefCountedImage ImageView::GetImage() const
-{
-  return mImpl->mImage;
-}
-
 } // namespace Vulkan
 
 } // namespace Graphics
index 28cbb1b..1da112b 100644 (file)
@@ -88,7 +88,7 @@ public:
    * Returns number of mipmap levels
    * @return
    */
-  uint32_t GetLevelCount() const;
+  uint32_t GetMipLevelCount() const;
 
   /**
    * Returns pixel format
@@ -138,143 +138,6 @@ private:
   std::unique_ptr<Impl> mImpl;
 };
 
-/*
- * ImageView
- * todo: move it to its own file
- */
-class ImageView : public VkManaged
-{
-public:
-
-  /**
-   * Creates ImageView according to the given spec
-   * @param graphics
-   * @param image
-   * @param info
-   * @return
-   */
-  static RefCountedImageView New( Graphics& graphics, RefCountedImage image, vk::ImageViewCreateInfo info );
-
-  /**
-   * Creates default image view which includes single layer and level, aspect
-   * based on image format, whole area, always 2D
-   * @param graphics
-   * @param image
-   * @return
-   */
-  static RefCountedImageView New( Graphics& graphics, RefCountedImage image = RefCountedImage() );
-
-
-  virtual ~ImageView() override;
-
-  /**
-   *
-   * @return
-   */
-  const vk::ImageView& GetVkImageView() const;
-
-  /**
-   * Returns bound ImageRef
-   * @return
-   */
-  RefCountedImage GetImage() const;
-
-  /**
-   *
-   * @param format
-   */
-  void SetFormat( vk::Format format );
-
-  /**
-   *
-   * @param componentMapping
-   */
-  void SetComponents( vk::ComponentMapping componentMapping );
-
-  /**
-   *
-   * @param viewType
-   */
-  void SetViewType( vk::ImageViewType viewType );
-
-  /**
-   *
-   * @param layerCount
-   */
-  void SetLayerCount( uint32_t layerCount );
-
-  /**
-   *
-   * @param layerCount
-   */
-  void SetLevelCount( uint32_t layerCount );
-
-  /**
-   *
-   * @param layerCount
-   */
-  void SetBaseMipmapLevel( uint32_t layerCount );
-
-  /**
-   *
-   * @param layer
-   */
-  void SetBaseArrayLayer( uint32_t layer );
-
-  /**
-   *
-   * @param aspectMask
-   */
-  void SetImageAspectMask( vk::ImageAspectFlags aspectMask );
-
-  /**
-   *
-   * @return
-   */
-  uint32_t GetLayerCount() const;
-
-  /**
-   *
-   * @return
-   */
-  uint32_t GetLevelCount() const;
-
-  /**
-   *
-   * @return
-   */
-  uint32_t GetBaseMipmapLevel() const;
-
-  /**
-   *
-   * @return
-   */
-  uint32_t GetBaseArrayLayer() const;
-
-  /**
-   *
-   * @return
-   */
-  vk::ImageAspectFlags GetImageAspectMask() const;
-
-  /**
-   * Creates immediately the image view. Otherwise implementation will
-   * pick the right time to create the object. All setters are disabled
-   * once the view has been created
-   * @return
-   */
-  bool Create();
-
-
-
-private:
-
-  ImageView( Graphics& graphics, RefCountedImage image, const VkImageViewCreateInfo& createInfo );
-
-  struct Impl;
-  std::unique_ptr<Impl> mImpl;
-};
-
 } // namespace Vulkan
 
 } // namespace Graphics
index e123642..01f808b 100644 (file)
@@ -247,9 +247,9 @@ ResourceCache& ResourceCache::RemoveSampler( Sampler &sampler )
 
 void ResourceCache::CollectGarbage()
 {
-  for( const auto& functor : mDiscardQueue )
+  for( const auto& deleter : mDiscardQueue )
   {
-    functor();
+    deleter();
   }
 
   mDiscardQueue.clear();
index 3a403a7..9c4a43f 100644 (file)
 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
 #include <dali/graphics/vulkan/vulkan-graphics.h>
 #include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
 #include <dali/graphics/vulkan/vulkan-queue.h>
 #include <dali/graphics/vulkan/vulkan-surface.h>
 #include <dali/graphics/vulkan/vulkan-swapchain.h>
+
 namespace Dali
 {
 namespace Graphics
@@ -197,7 +199,7 @@ struct Swapchain::Impl
 
         vk::ImageSubresourceRange range;
         range.setLayerCount( image->GetLayerCount() )
-          .setLevelCount( image->GetLevelCount() )
+          .setLevelCount( image->GetMipLevelCount() )
           .setBaseMipLevel( 0 )
           .setBaseArrayLayer( 0 )
           .setAspectMask( vk::ImageAspectFlagBits::eColor );
@@ -223,7 +225,7 @@ struct Swapchain::Impl
 
       vk::ImageSubresourceRange range;
       range.setLayerCount( image->GetLayerCount() )
-        .setLevelCount( image->GetLevelCount() )
+        .setLevelCount( image->GetMipLevelCount() )
         .setBaseMipLevel( 0 )
         .setBaseArrayLayer( 0 )
         .setAspectMask( vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil );
@@ -270,12 +272,7 @@ struct Swapchain::Impl
       }
     }
 
-    if( vk::Format::eUndefined == mSwapchainImageFormat )
-    {
-      return false;
-    }
-
-    return true;
+    return vk::Format::eUndefined != mSwapchainImageFormat;
   }
 
   /**
@@ -335,27 +332,30 @@ struct Swapchain::Impl
    */
   RefCountedImageView CreateDepthStencil()
   {
+    //TODO: create the image using the Graphics class
+    auto imageCreateInfo = vk::ImageCreateInfo{}
+            .setFormat( vk::Format::eD24UnormS8Uint )
+            .setMipLevels( 1 )
+            .setTiling( vk::ImageTiling::eOptimal )
+            .setImageType( vk::ImageType::e2D )
+            .setArrayLayers( 1 )
+            .setExtent( {mSwapchainExtent.width, mSwapchainExtent.height, 1} )
+            .setUsage( vk::ImageUsageFlagBits::eDepthStencilAttachment )
+            .setSharingMode( vk::SharingMode::eExclusive )
+            .setInitialLayout( vk::ImageLayout::eUndefined )
+            .setSamples( vk::SampleCountFlagBits::e1 );
+
     // create depth stencil image
-    auto dsImageRef = Image::New( mGraphics,
-                                  vk::ImageCreateInfo{}
-                                    .setFormat( vk::Format::eD24UnormS8Uint )
-                                    .setMipLevels( 1 )
-                                    .setTiling( vk::ImageTiling::eOptimal )
-                                    .setImageType( vk::ImageType::e2D )
-                                    .setArrayLayers( 1 )
-                                    .setExtent( {mSwapchainExtent.width, mSwapchainExtent.height, 1} )
-                                    .setUsage( vk::ImageUsageFlagBits::eDepthStencilAttachment )
-                                    .setSharingMode( vk::SharingMode::eExclusive )
-                                    .setInitialLayout( vk::ImageLayout::eUndefined )
-                                    .setSamples( vk::SampleCountFlagBits::e1 ) );
+    auto dsRefCountedImage = Image::New( mGraphics, imageCreateInfo);
 
     auto memory = mGraphics.GetDeviceMemoryManager().GetDefaultAllocator().Allocate(
-      dsImageRef, vk::MemoryPropertyFlagBits::eDeviceLocal );
+            dsRefCountedImage, vk::MemoryPropertyFlagBits::eDeviceLocal );
 
-    dsImageRef->BindMemory( memory );
+    //TODO: use the graphics class to bind memory. Maybe...
+    dsRefCountedImage->BindMemory( memory );
 
     // create imageview to be used within framebuffer
-    auto dsImageViewRef = ImageView::New( mGraphics, dsImageRef );
+    auto dsImageViewRef = mGraphics.CreateImageView(dsRefCountedImage);
     return dsImageViewRef;
   }
 
@@ -368,25 +368,25 @@ struct Swapchain::Impl
   {
     auto fbRef = Framebuffer::New( mGraphics, mSwapchainExtent.width, mSwapchainExtent.height );
 
+    auto imageCreateInfo = vk::ImageCreateInfo{}
+            .setFormat( mSwapchainImageFormat )
+            .setSamples( vk::SampleCountFlagBits::e1 )
+            .setInitialLayout( vk::ImageLayout::eUndefined )
+            .setSharingMode( vk::SharingMode::eExclusive )
+            .setUsage( vk::ImageUsageFlagBits::eColorAttachment )
+            .setExtent( {mSwapchainExtent.width, mSwapchainExtent.height, 1} )
+            .setArrayLayers( 1 )
+            .setImageType( vk::ImageType::e2D )
+            .setTiling( vk::ImageTiling::eOptimal )
+            .setMipLevels( 1 );
+
     // Create external Image reference
     // Note that despite we don't create VkImage, we still fill the createinfo structure
     // as this data will be used later
-    RefCountedImage imageRef = Image::New( mGraphics,
-                                    vk::ImageCreateInfo{}
-                                      .setFormat( mSwapchainImageFormat )
-                                      .setSamples( vk::SampleCountFlagBits::e1 )
-                                      .setInitialLayout( vk::ImageLayout::eUndefined )
-                                      .setSharingMode( vk::SharingMode::eExclusive )
-                                      .setUsage( vk::ImageUsageFlagBits::eColorAttachment )
-                                      .setExtent( {mSwapchainExtent.width, mSwapchainExtent.height, 1} )
-                                      .setArrayLayers( 1 )
-                                      .setImageType( vk::ImageType::e2D )
-                                      .setTiling( vk::ImageTiling::eOptimal )
-                                      .setMipLevels( 1 ),
-                                    image );
+    auto refCountedImage = Image::New( mGraphics, imageCreateInfo, image );
 
     // Create basic imageview ( all mipmaps, all layers )
-    RefCountedImageView iv = ImageView::New( mGraphics, imageRef );
+    RefCountedImageView iv = mGraphics.CreateImageView(refCountedImage);
 
     fbRef->SetAttachment( iv, Framebuffer::AttachmentType::COLOR, 0u );
 
index 882ef73..9939019 100644 (file)
@@ -242,12 +242,6 @@ Handle< T > NewRef(Args&&... args)
 }
 
 
-template<class T>
-typename T::Impl& GetImpl( Handle<T>& object )
-{
-  return static_cast<typename T::Impl&>(*object->mImpl);
-}
-
 class VkManaged
 {
 public:
@@ -339,11 +333,7 @@ using RefCountedSwapchain = Handle<class Swapchain>;
 using RefCountedSurface = Handle<class Surface>;
 using RefCountedSampler = Handle<class Sampler>;
 using RefCountedTexture = Handle<class Texture>;
-/*
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
-#pragma GCC diagnostic pop
-*/
+
 } // namespace Vulkan
 } // namespace Graphics
 } // namespace Dali