Attempt to make dali-demo work
authorAngelos Gkountis <a.gkountis@samsung.com>
Tue, 5 Jun 2018 10:49:57 +0000 (11:49 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 11 Jun 2018 17:03:58 +0000 (17:03 +0000)
Change-Id: I9c03f3f3c55bf20895b4282ce69f0dd76b77d218

dali/graphics/vulkan/api/internal/vulkan-ubo-pool.cpp
dali/graphics/vulkan/gpu-memory/vulkan-gpu-memory-manager.cpp
dali/graphics/vulkan/vulkan-command-buffer.cpp
dali/graphics/vulkan/vulkan-graphics-texture.cpp
dali/graphics/vulkan/vulkan-graphics.cpp
dali/graphics/vulkan/vulkan-graphics.h

index abf3f84..c5ff4c5 100644 (file)
@@ -167,13 +167,16 @@ struct UboPool::Impl
     DALI_LOG_STREAM( gVulkanFilter, Debug::General, "[POOL] Allocating new page of block size " << mBlockSize << ", capacity: " << mInitialCapacity);
     // add new Vulkan Buffer object
     auto& graphics = mController.GetGraphics();
-    mBuffers.emplace_back( Vulkan::Buffer::New( graphics, vk::BufferCreateInfo{}
-                                      .setUsage( vk::BufferUsageFlagBits::eUniformBuffer)
-                                      .setSharingMode( vk::SharingMode::eExclusive )
-                                      .setSize( mBlockSize * mInitialCapacity ) ) );
+
+    mBuffers.emplace_back( graphics.CreateBuffer(vk::BufferCreateInfo{}
+                                                         .setUsage( vk::BufferUsageFlagBits::eUniformBuffer)
+                                                         .setSharingMode( vk::SharingMode::eExclusive )
+                                                         .setSize( mBlockSize * mInitialCapacity ) ) );
     mBuffers.back().buffer->BindMemory(
-              graphics.GetDeviceMemoryManager().GetDefaultAllocator().Allocate( mBuffers.back().buffer, vk::MemoryPropertyFlagBits::eHostVisible )
-    );
+              graphics
+                      .GetDeviceMemoryManager()
+                      .GetDefaultAllocator()
+                      .Allocate( mBuffers.back().buffer, vk::MemoryPropertyFlagBits::eHostVisible ) );
 
 
     auto startIndex = ((mBuffers.size()-1)*mInitialCapacity);
index fa23ccf..0edddb9 100644 (file)
@@ -73,7 +73,7 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
     vk::DeviceMemory        memory { nullptr };
   };
 
-  GpuMemoryDefaultAllocator( GpuMemoryManager& manager )
+  explicit GpuMemoryDefaultAllocator( GpuMemoryManager& manager )
     : GpuMemoryAllocator(), mGpuManager( manager ),
       mGraphics(manager.GetGraphics())
   {
@@ -117,7 +117,9 @@ struct GpuMemoryDefaultAllocator : public GpuMemoryAllocator
    */
   virtual RefCountedGpuMemoryBlock Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) override
   {
-    return Allocate( mGraphics.GetDevice().getBufferMemoryRequirements(buffer->GetVkHandle() ),
+    vk::Buffer handle = buffer->GetVkHandle();
+    vk::MemoryRequirements memReqs = mGraphics.GetDevice().getBufferMemoryRequirements( handle );
+    return Allocate( memReqs,
                      memoryProperties );
   }
 
index a673117..9755d08 100644 (file)
@@ -233,12 +233,16 @@ void CommandBuffer::EndRenderPass()
 
 void CommandBuffer::ExecuteCommands( std::vector< Dali::Graphics::Vulkan::Handle< CommandBuffer>> commandBuffers )
 {
+  assert( mAllocateInfo.level == vk::CommandBufferLevel::ePrimary
+          && "Cannot record command: ExecuteCommands\tReason: The command buffer recording this command is not primary" );
+
   auto vkBuffers = std::vector< vk::CommandBuffer >{};
   vkBuffers.reserve( commandBuffers.size());
   for( auto&& buf : commandBuffers )
   {
-    assert( mAllocateInfo.level == vk::CommandBufferLevel::eSecondary &&
-            "Cannot Execute Commands. Command buffer level not secondary" );
+    assert(buf->mAllocateInfo.level == vk::CommandBufferLevel::eSecondary &&
+            "Cannot record command: Execute Commands\tReason: A command buffer provided for execution is not secondary" );
+
     vkBuffers.emplace_back( buf->GetVkHandle());
   }
 
index 1df8d80..196885c 100644 (file)
@@ -90,13 +90,14 @@ struct Texture::Impl
                                                  .setSharingMode( vk::SharingMode::eExclusive )
                                                  .setSize( size ));
 
-    buffer->BindMemory( allocator.Allocate( buffer, vk::MemoryPropertyFlagBits::eHostVisible ) );
+    buffer->BindMemory( allocator.Allocate( buffer, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
 
     // copy pixels to the buffer
     auto ptr = buffer->GetMemoryHandle()->MapTyped<char>();
     std::copy( reinterpret_cast<const char*>(data),
                reinterpret_cast<const char*>(data) + sizeInBytes,
                ptr );
+
     buffer->GetMemoryHandle()->Unmap();
 
     // record copy and layout change
@@ -149,8 +150,8 @@ struct Texture::Impl
 
     // submit and wait till image is uploaded so temporary buffer can be destroyed safely
     auto fence = mGraphics.CreateFence({});
-    mGraphics.Submit( mGraphics.GetGraphicsQueue( 0u ), { SubmissionData{}.SetCommandBuffers( { mCommandBuffer } ) }, fence );
-    VkAssert(mGraphics.WaitForFence(fence));
+    VkAssert(mGraphics.Submit( mGraphics.GetGraphicsQueue( 0u ), { SubmissionData{}.SetCommandBuffers( { mCommandBuffer } ) }, fence ));
+    VkAssert(mGraphics.WaitForFence(fence, std::numeric_limits<uint32_t>::max()));
     return true;
   }
 
index 885f9d7..bd2d16c 100644 (file)
@@ -331,7 +331,6 @@ RefCountedImageView Graphics::CreateImageView( RefCountedImage image )
   if( image->GetUsageFlags() & vk::ImageUsageFlagBits::eColorAttachment )
   {
     aspectFlags |= vk::ImageAspectFlagBits::eColor;
-    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB,vk::ComponentSwizzle::eA };
   }
   if( image->GetUsageFlags() & vk::ImageUsageFlagBits::eDepthStencilAttachment )
   {
@@ -339,8 +338,7 @@ RefCountedImageView Graphics::CreateImageView( RefCountedImage image )
   }
   if( image->GetUsageFlags() & vk::ImageUsageFlagBits::eSampled )
   {
-    aspectFlags |= ( vk::ImageAspectFlagBits::eColor );
-    //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eR,vk::ComponentSwizzle::eA };
+    aspectFlags |= vk::ImageAspectFlagBits::eColor;
   }
 
   auto subresourceRange = vk::ImageSubresourceRange{}
@@ -453,20 +451,21 @@ vk::Result Graphics::BindImageMemory( RefCountedImage image, RefCountedGpuMemory
 vk::Result Graphics::Submit( Queue& queue, const std::vector< SubmissionData >& submissionData, RefCountedFence fence )
 {
   std::vector< vk::SubmitInfo > submitInfos;
+  std::vector< vk::CommandBuffer > commandBufferHandles;
 
   // Transform SubmissionData to vk::SubmitInfo
   std::transform(submissionData.begin(),
                  submissionData.end(),
                  std::back_inserter( submitInfos ),
-                 []( SubmissionData subData )
+                 [&]( SubmissionData subData )
                  {
-                   std::vector< vk::CommandBuffer > commandBufferHandles;
+
 
                    //Extract the command buffer handles
                    std::transform(subData.commandBuffers.begin(),
                                   subData.commandBuffers.end(),
                                   std::back_inserter(commandBufferHandles),
-                                  []( RefCountedCommandBuffer& entry )
+                                  [&]( RefCountedCommandBuffer& entry )
                                   {
                                     return entry->GetVkHandle();
                                   });
index d881c65..51d4515 100644 (file)
@@ -30,7 +30,7 @@
 #include <mutex>
 #include <map>
 #include <functional>
-#include "vulkan-queue.h"
+#include <dali/graphics/vulkan/vulkan-queue.h>
 
 namespace Dali
 {