Adding command buffer implementations 09/317309/7
authorDavid Steele <david.steele@samsung.com>
Fri, 6 Sep 2024 17:33:09 +0000 (18:33 +0100)
committerAdam Bialogonski <adam.b@samsung.com>
Fri, 13 Sep 2024 12:39:22 +0000 (13:39 +0100)
Implementations or binding buffers and textures,
drawing, setting stencil & viewport.

Note, we require further changes to implement texture
binding, as this requires the sampler descriptor sets
for the assoc program.

Changed default buffer memory type to be host coherent - this
ensures that the validation layers don't complain on flush,
but may slow down the system. Consider using staging buffers
to transfer memory to GPU.

Change-Id: I50d56f886dca80a65ba03f9f8b3261b1cca75236

build/tizen/deps-check.cmake
dali/internal/graphics/common/shader-parser.cpp
dali/internal/graphics/vulkan-impl/vulkan-buffer-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-command-buffer-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-command-buffer-impl.h
dali/internal/graphics/vulkan-impl/vulkan-command-buffer.cpp
dali/internal/graphics/vulkan-impl/vulkan-image-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-memory-impl.cpp
dali/internal/graphics/vulkan-impl/vulkan-memory-impl.h
dali/internal/graphics/vulkan-impl/vulkan-sampler.cpp
dali/internal/graphics/vulkan-impl/vulkan-sampler.h

index e350c04fb8d53b6ea6bfd2a68b67a116d9a3e347..3de7eba8312bcbd02d4c8502dbfced09b2d8dfc0 100644 (file)
@@ -541,7 +541,7 @@ IF(enable_glslang)
     # all needed deps and SPIRV-Tools package is needed
     SET(DALI_LDFLAGS ${DALI_LDFLAGS} ${GLSLANG_LDFLAGS} -lSPIRV ${SPIRVTOOLS_LDFLAGS} -lglslang-default-resource-limits)
   ENDIF()
-
+  LIST(APPEND DALI_CFLAGS ${GLSLANG_CFLAGS})
 ENDIF()
 
 IF(LIBUV_X11_PROFILE)
index 1cb10c07e2182c04575011a848bcb911166be9d8..8bc27399fb7b83331d1cc93fb45ffc8400ed2f0c 100644 (file)
@@ -1,19 +1,19 @@
 /*
-* Copyright (c) 2024 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.
-*
-*/
+ * Copyright (c) 2024 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/integration-api/debug.h>
 #include <dali/internal/graphics/common/shader-parser.h>
@@ -575,4 +575,4 @@ void Parse(const ShaderParserInfo& parseInfo, std::vector<std::string>& output)
   }
 }
 
-} // namespace Dali::Internal::ShaderParser
\ No newline at end of file
+} // namespace Dali::Internal::ShaderParser
index 9e70eb6be806413de4bcf8c7b299efb86f31e852..48a952d4d0756712a81769de4420c1514bd3593e 100644 (file)
@@ -28,7 +28,7 @@ namespace Dali::Graphics::Vulkan
 {
 BufferImpl* BufferImpl::New(Device& device, size_t size, vk::BufferUsageFlags usageFlags)
 {
-  return New(device, size, vk::SharingMode(vk::SharingMode::eExclusive), usageFlags, vk::MemoryPropertyFlags(vk::MemoryPropertyFlagBits::eHostVisible));
+  return New(device, size, vk::SharingMode(vk::SharingMode::eExclusive), usageFlags, vk::MemoryPropertyFlags(vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent));
 }
 
 BufferImpl* BufferImpl::New(Device& device, size_t size, vk::SharingMode sharingMode, vk::BufferUsageFlags usageFlags, vk::MemoryPropertyFlags memoryProperties)
@@ -62,7 +62,7 @@ void BufferImpl::Initialize(vk::MemoryPropertyFlags memoryProperties)
                                                 requirements.memoryTypeBits,
                                                 memoryProperties);
 
-  mMemory = std::make_unique<MemoryImpl>(mDevice, size_t(requirements.size), size_t(requirements.alignment), ((memoryProperties & vk::MemoryPropertyFlagBits::eHostVisible) == vk::MemoryPropertyFlagBits::eHostVisible));
+  mMemory = std::make_unique<MemoryImpl>(mDevice, size_t(requirements.size), size_t(requirements.alignment), memoryProperties);
 
   auto allocateInfo = vk::MemoryAllocateInfo{}
                         .setMemoryTypeIndex(memoryTypeIndex)
index c1b931aff1bdf4fa4deb37ba17e8a897fc08e522..dd5ec9183bd1bb02f3a61e8278244e78a9ee4da9 100644 (file)
 #include <dali/internal/graphics/vulkan-impl/vulkan-command-pool-impl.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-framebuffer-impl.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-image-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-image-view-impl.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-pipeline-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-sampler-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-sampler.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-swapchain-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-texture.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-types.h>
 #include <dali/internal/graphics/vulkan/vulkan-device.h>
 
@@ -115,6 +119,79 @@ void CommandBufferImpl::BindPipeline(const Graphics::Pipeline* pipeline)
   }
 }
 
+void CommandBufferImpl::BindVertexBuffers(
+  uint32_t                        firstBinding,
+  const std::vector<BufferImpl*>& buffers,
+  const std::vector<uint32_t>&    offsets)
+{
+  // update list of used resources and create an array of VkBuffers
+  std::vector<vk::Buffer> vkBuffers;
+  vkBuffers.reserve(buffers.size());
+  for(auto&& buffer : buffers)
+  {
+    vkBuffers.emplace_back(buffer->GetVkHandle());
+  }
+  std::vector<vk::DeviceSize> vkOffsets;
+  vkOffsets.reserve(offsets.size());
+  for(auto&& offset : offsets)
+  {
+    vkOffsets.emplace_back(static_cast<vk::DeviceSize>(offset));
+  }
+  mCommandBuffer.bindVertexBuffers(firstBinding, vkBuffers.size(), vkBuffers.data(), vkOffsets.data());
+}
+
+void CommandBufferImpl::BindIndexBuffer(
+  BufferImpl& buffer,
+  uint32_t    offset,
+  Format      format)
+{
+  if(format == Graphics::Format::R16_UINT)
+  {
+    mCommandBuffer.bindIndexBuffer(buffer.GetVkHandle(), offset, vk::IndexType::eUint16);
+  }
+  else if(format == Graphics::Format::R32_UINT)
+  {
+    mCommandBuffer.bindIndexBuffer(buffer.GetVkHandle(), offset, vk::IndexType::eUint32);
+  }
+}
+
+void CommandBufferImpl::BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings)
+{
+  // Needs descriptor set pools.
+}
+
+void CommandBufferImpl::BindTextures(const std::vector<TextureBinding>& textureBindings)
+{
+  for(const auto& textureBinding : textureBindings)
+  {
+    auto texture   = static_cast<const Vulkan::Texture*>(textureBinding.texture);
+    auto sampler   = const_cast<Vulkan::Sampler*>(static_cast<const Vulkan::Sampler*>(textureBinding.sampler));
+    auto vkSampler = sampler ? sampler->GetImpl()->GetVkHandle() : nullptr;
+
+    auto image     = texture->GetImage();
+    auto imageView = texture->GetImageView();
+
+    // test if image is valid, skip invalid image
+    if(!image || !image->GetVkHandle())
+    {
+      continue;
+    }
+
+    // Store: imageView, sampler & texture.binding for later use
+    // We don't know at this point what pipeline is bound (As dali-core
+    // binds the pipeline after calling this API)
+    mDeferredTextureBindings.emplace_back();
+    mDeferredTextureBindings.back().imageView = imageView->GetVkHandle();
+    mDeferredTextureBindings.back().sampler   = vkSampler;
+    mDeferredTextureBindings.back().binding   = textureBinding.binding;
+  }
+}
+
+void CommandBufferImpl::BindSamplers(const std::vector<SamplerBinding>& samplerBindings)
+{
+  // Unused in core
+}
+
 vk::CommandBuffer CommandBufferImpl::GetVkHandle() const
 {
   return mCommandBuffer;
@@ -182,6 +259,7 @@ void CommandBufferImpl::Draw(uint32_t vertexCount,
                              uint32_t firstVertex,
                              uint32_t firstInstance)
 {
+  mCommandBuffer.draw(vertexCount, instanceCount, firstVertex, firstInstance);
 }
 
 void CommandBufferImpl::DrawIndexed(uint32_t indexCount,
@@ -190,17 +268,34 @@ void CommandBufferImpl::DrawIndexed(uint32_t indexCount,
                                     int32_t  vertexOffset,
                                     uint32_t firstInstance)
 {
+  mCommandBuffer.drawIndexed(indexCount,
+                             instanceCount,
+                             firstIndex,
+                             static_cast<int32_t>(vertexOffset),
+                             firstInstance);
+}
+
+void CommandBufferImpl::DrawIndexedIndirect(BufferImpl& buffer,
+                                            uint32_t    offset,
+                                            uint32_t    drawCount,
+                                            uint32_t    stride)
+{
+  mCommandBuffer.drawIndexedIndirect(buffer.GetVkHandle(), static_cast<vk::DeviceSize>(offset), drawCount, stride);
+}
+
+void CommandBufferImpl::ExecuteCommandBuffers(std::vector<vk::CommandBuffer>& commandBuffers)
+{
+  mCommandBuffer.executeCommands(commandBuffers);
 }
 
-void CommandBufferImpl::DrawIndexedIndirect(Graphics::Buffer& buffer,
-                                            uint32_t          offset,
-                                            uint32_t          drawCount,
-                                            uint32_t          stride)
+void CommandBufferImpl::SetScissor(Rect2D value)
 {
+  mCommandBuffer.setScissor(0, 1, reinterpret_cast<vk::Rect2D*>(&value));
 }
 
-void CommandBufferImpl::ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers)
+void CommandBufferImpl::SetViewport(Viewport value)
 {
+  mCommandBuffer.setViewport(0, 1, reinterpret_cast<vk::Viewport*>(&value));
 }
 
 } // namespace Vulkan
index 6f9cda2f873113eb56daf4b7e9a7c7ea994aaac4..ac046ee4dd92088a3a7153b0e0ab94c5cf927d75 100644 (file)
@@ -60,6 +60,15 @@ public:
   /** Final validation of the pipeline */
   void ValidatePipeline();
 
+  void BindVertexBuffers(
+    uint32_t                                firstBinding,
+    const std::vector<Vulkan::BufferImpl*>& buffers,
+    const std::vector<uint32_t>&            offsets);
+  void BindIndexBuffer(Vulkan::BufferImpl& buffer, uint32_t offset, Format format);
+  void BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings);
+  void BindTextures(const std::vector<TextureBinding>& textureBindings);
+  void BindSamplers(const std::vector<SamplerBinding>& samplerBindings);
+
   /** Returns Vulkan object associated with the buffer */
   [[nodiscard]] vk::CommandBuffer GetVkHandle() const;
 
@@ -68,7 +77,6 @@ public:
    * @return Returns true if the command buffer is primary
    */
   [[nodiscard]] bool IsPrimary() const;
-
   /**
    * Allows to issue custom VkRenderPassBeginInfo structure
    * @param renderPassBeginInfo
@@ -98,6 +106,9 @@ public:
    */
   bool OnDestroy() override;
 
+  void SetScissor(Rect2D value);
+  void SetViewport(Viewport value);
+
   void Draw(
     uint32_t vertexCount,
     uint32_t instanceCount,
@@ -112,12 +123,12 @@ public:
     uint32_t firstInstance);
 
   void DrawIndexedIndirect(
-    Graphics::Buffer& buffer,
-    uint32_t          offset,
-    uint32_t          drawCount,
-    uint32_t          stride);
+    BufferImpl& buffer,
+    uint32_t    offset,
+    uint32_t    drawCount,
+    uint32_t    stride);
 
-  void ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers);
+  void ExecuteCommandBuffers(std::vector<vk::CommandBuffer>& commandBuffers);
 
 private:
   /**
@@ -134,11 +145,20 @@ private:
     const vk::CommandBufferAllocateInfo& allocateInfo,
     vk::CommandBuffer                    vulkanHandle);
 
+private: // Struct for deferring texture binding
+  struct DeferredTextureBinding
+  {
+    vk::ImageView imageView;
+    vk::Sampler   sampler;
+    uint32_t      binding;
+  };
+
 private:
-  CommandPool*                  mOwnerCommandPool;
-  Device*                       mGraphicsDevice;
-  uint32_t                      mPoolAllocationIndex;
-  vk::CommandBufferAllocateInfo mAllocateInfo{};
+  CommandPool*                        mOwnerCommandPool;
+  Device*                             mGraphicsDevice;
+  uint32_t                            mPoolAllocationIndex;
+  vk::CommandBufferAllocateInfo       mAllocateInfo{};
+  std::vector<DeferredTextureBinding> mDeferredTextureBindings;
 
   vk::CommandBuffer mCommandBuffer{};
 
index 89043db2afb1745a68dd3f08261aa6214fbcfaff..6e8989e7d3c30505c94094a8a466351bf628100e 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <dali/internal/graphics/vulkan-impl/vulkan-buffer-impl.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-buffer.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-command-buffer.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-command-pool-impl.h>
 #include <dali/internal/graphics/vulkan-impl/vulkan-framebuffer-impl.h>
 
 namespace Dali::Graphics::Vulkan
 {
+template<typename VT, typename GT>
+VT* ConstGraphicsCast(const GT* object)
+{
+  return const_cast<VT*>(static_cast<const VT*>(object));
+}
+
 CommandBuffer::CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, VulkanGraphicsController& controller)
 : CommandBufferResource(createInfo, controller),
   mCommandBufferImpl(nullptr)
@@ -82,13 +90,30 @@ void CommandBuffer::Reset()
 }
 
 void CommandBuffer::BindVertexBuffers(uint32_t                                    firstBinding,
-                                      const std::vector<const Graphics::Buffer*>& buffers,
+                                      const std::vector<const Graphics::Buffer*>& gfxBuffers,
                                       const std::vector<uint32_t>&                offsets)
 {
+  std::vector<BufferImpl*> buffers;
+  buffers.reserve(gfxBuffers.size());
+  for(auto& gfxBuffer : gfxBuffers)
+  {
+    buffers.push_back(ConstGraphicsCast<Buffer, Graphics::Buffer>(gfxBuffer)->GetImpl());
+  }
+  mCommandBufferImpl->BindVertexBuffers(firstBinding, buffers, offsets);
+}
+
+void CommandBuffer::BindIndexBuffer(const Graphics::Buffer& gfxBuffer,
+                                    uint32_t                offset,
+                                    Format                  format)
+{
+  auto indexBuffer = ConstGraphicsCast<Buffer, Graphics::Buffer>(&gfxBuffer);
+  DALI_ASSERT_DEBUG(indexBuffer && indexBuffer->GetImpl());
+  mCommandBufferImpl->BindIndexBuffer(*indexBuffer->GetImpl(), offset, format);
 }
 
 void CommandBuffer::BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings)
 {
+  mCommandBufferImpl->BindUniformBuffers(bindings);
 }
 
 void CommandBuffer::BindPipeline(const Graphics::Pipeline& pipeline)
@@ -98,10 +123,12 @@ void CommandBuffer::BindPipeline(const Graphics::Pipeline& pipeline)
 
 void CommandBuffer::BindTextures(const std::vector<TextureBinding>& textureBindings)
 {
+  mCommandBufferImpl->BindTextures(textureBindings);
 }
 
 void CommandBuffer::BindSamplers(const std::vector<SamplerBinding>& samplerBindings)
 {
+  mCommandBufferImpl->BindSamplers(samplerBindings);
 }
 
 void CommandBuffer::BindPushConstants(void*    data,
@@ -110,12 +137,6 @@ void CommandBuffer::BindPushConstants(void*    data,
 {
 }
 
-void CommandBuffer::BindIndexBuffer(const Graphics::Buffer& buffer,
-                                    uint32_t                offset,
-                                    Format                  format)
-{
-}
-
 void CommandBuffer::BeginRenderPass(Graphics::RenderPass*          gfxRenderPass,
                                     Graphics::RenderTarget*        gfxRenderTarget,
                                     Rect2D                         renderArea,
@@ -175,8 +196,15 @@ void CommandBuffer::EndRenderPass(Graphics::SyncObject* syncObject)
   mCommandBufferImpl->EndRenderPass();
 }
 
-void CommandBuffer::ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers)
+void CommandBuffer::ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& gfxCommandBuffers)
 {
+  std::vector<vk::CommandBuffer> vkCommandBuffers;
+  vkCommandBuffers.reserve(gfxCommandBuffers.size());
+  for(auto& gfxCmdBuf : gfxCommandBuffers)
+  {
+    vkCommandBuffers.push_back(ConstGraphicsCast<CommandBuffer, Graphics::CommandBuffer>(gfxCmdBuf)->GetImpl()->GetVkHandle());
+  }
+  mCommandBufferImpl->ExecuteCommandBuffers(vkCommandBuffers);
 }
 
 void CommandBuffer::Draw(uint32_t vertexCount,
@@ -196,12 +224,14 @@ void CommandBuffer::DrawIndexed(uint32_t indexCount,
   mCommandBufferImpl->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
 }
 
-void CommandBuffer::DrawIndexedIndirect(Graphics::Buffer& buffer,
+void CommandBuffer::DrawIndexedIndirect(Graphics::Buffer& gfxBuffer,
                                         uint32_t          offset,
                                         uint32_t          drawCount,
                                         uint32_t          stride)
 {
-  mCommandBufferImpl->DrawIndexedIndirect(buffer, offset, drawCount, stride);
+  auto buffer = ConstGraphicsCast<Buffer, Graphics::Buffer>(&gfxBuffer)->GetImpl();
+
+  mCommandBufferImpl->DrawIndexedIndirect(*buffer, offset, drawCount, stride);
 }
 
 void CommandBuffer::DrawNative(const DrawNativeInfo* drawInfo)
@@ -210,18 +240,25 @@ void CommandBuffer::DrawNative(const DrawNativeInfo* drawInfo)
 
 void CommandBuffer::SetScissor(Rect2D value)
 {
+  // @todo Vulkan accepts array of scissors... add to API
+  mCommandBufferImpl->SetScissor(value);
 }
 
 void CommandBuffer::SetScissorTestEnable(bool value)
 {
+  // Enabled by default. What does disabling test do?!
+  // Probably should force pipeline to not use dynamic scissor state
 }
 
 void CommandBuffer::SetViewport(Viewport value)
 {
+  mCommandBufferImpl->SetViewport(value);
 }
 
 void CommandBuffer::SetViewportEnable(bool value)
 {
+  // Enabled by default. What does disabling test do?!
+  // Probably should force pipeline to not use dynamic viewport state
 }
 
 void CommandBuffer::SetColorMask(bool enabled)
index 9d0dbe6626c76dd131c852a7b5006417e0039c2e..20b95d12d90e46f02169399fe6e90ac8db9c782b 100644 (file)
@@ -30,7 +30,6 @@ namespace Graphics
 {
 namespace Vulkan
 {
-
 Image* Image::New(Device& graphicsDevice, const vk::ImageCreateInfo& createInfo)
 {
   auto image = new Image(graphicsDevice, createInfo, nullptr);
@@ -94,7 +93,7 @@ void Image::AllocateAndBind(vk::MemoryPropertyFlags memoryProperties)
   mMemory = std::make_unique<MemoryImpl>(mDevice,
                                          size_t(requirements.size),
                                          size_t(requirements.alignment),
-                                         (memoryProperties & vk::MemoryPropertyFlagBits::eHostVisible) == vk::MemoryPropertyFlagBits::eHostVisible);
+                                         memoryProperties);
 
   auto allocateInfo = vk::MemoryAllocateInfo{}
                         .setMemoryTypeIndex(memoryTypeIndex)
@@ -274,8 +273,7 @@ bool Image::OnDestroy()
       auto allocator = &mDevice.GetAllocator();
       auto memory    = mMemory->ReleaseVkObject();
 
-      mDevice.DiscardResource([device, image, memory, allocator]()
-                              { DestroyVulkanResources(device, image, memory, allocator); });
+      mDevice.DiscardResource([device, image, memory, allocator]() { DestroyVulkanResources(device, image, memory, allocator); });
     }
   }
 
index fc1b3dfd500fb7cdfafae1e2d4778db7d713640e..83bcf5d7200d107584c4b7e55e6869cc46c56e2e 100644 (file)
 
 namespace Dali::Graphics::Vulkan
 {
-
-MemoryImpl::MemoryImpl(Device& device, size_t memSize, size_t memAlign, bool isHostVisible)
+MemoryImpl::MemoryImpl(Device& device, size_t memSize, size_t memAlign, vk::MemoryPropertyFlags memoryProperties)
 : mDevice(device),
   deviceMemory(nullptr),
   size(memSize),
   alignment(memAlign),
   mappedPtr(nullptr),
   mappedSize(0u),
-  hostVisible(isHostVisible)
+  mMemoryProperties(memoryProperties)
 {
 }
 
@@ -87,11 +86,16 @@ vk::DeviceMemory MemoryImpl::ReleaseVkObject()
 
 void MemoryImpl::Flush()
 {
-  vk::Result result = mDevice.GetLogicalDevice().flushMappedMemoryRanges({vk::MappedMemoryRange{}
-                                                                            .setSize(mappedSize)
-                                                                            .setMemory(deviceMemory)
-                                                                            .setOffset(0u)});
-  DALI_ASSERT_ALWAYS(result == vk::Result::eSuccess); // If it's out of memory, may as well crash.
+  // Don't flush if we are using host coherent memory - it's un-necessary
+  if((mMemoryProperties & vk::MemoryPropertyFlagBits::eHostCoherent) != vk::MemoryPropertyFlagBits::eHostCoherent)
+  {
+    vk::Result result = mDevice.GetLogicalDevice().flushMappedMemoryRanges({vk::MappedMemoryRange{}
+                                                                              .setSize(mappedSize ? mappedSize : VK_WHOLE_SIZE)
+                                                                              .setMemory(deviceMemory)
+                                                                              .setOffset(0u)});
+
+    DALI_ASSERT_ALWAYS(result == vk::Result::eSuccess); // If it's out of memory, may as well crash.
+  }
 }
 
 vk::DeviceMemory MemoryImpl::GetVkHandle() const
index 73e5f52bdc1c767cbe368f8a09c3110966816038..c9a2e47f1e7dd2fbe054f852e1ca80b16ecd9be8 100644 (file)
 
 namespace Dali::Graphics::Vulkan
 {
-
 class MemoryImpl
 {
 public:
-  MemoryImpl(Device& device, size_t memSize, size_t memAlign, bool hostVisible);
+  MemoryImpl(Device& device, size_t memSize, size_t memAlign, vk::MemoryPropertyFlags memoryProperties);
 
   ~MemoryImpl();
 
@@ -39,7 +38,7 @@ public:
   }
 
   // No copy constructor or assignment operator
-  MemoryImpl(MemoryImpl&)            = delete;
+  MemoryImpl(MemoryImpl&) = delete;
   MemoryImpl& operator=(MemoryImpl&) = delete;
 
   void* Map();
@@ -60,13 +59,13 @@ public:
   [[nodiscard]] vk::DeviceMemory GetVkHandle() const;
 
 private:
-  Device&          mDevice;
-  vk::DeviceMemory deviceMemory;
-  size_t           size;
-  size_t           alignment;
-  void*            mappedPtr;
-  size_t           mappedSize;
-  bool             hostVisible;
+  Device&                 mDevice;
+  vk::DeviceMemory        deviceMemory;
+  size_t                  size;
+  size_t                  alignment;
+  void*                   mappedPtr;
+  size_t                  mappedSize;
+  vk::MemoryPropertyFlags mMemoryProperties;
 };
 
 } // namespace Dali::Graphics::Vulkan
index bf881da610c263b1b77986960de3482971d5bb31..ffc2b5b8da220339c8ce9fa7435c98eed04b0547 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali/internal/graphics/vulkan-impl/vulkan-graphics-controller.h>
+#include <dali/internal/graphics/vulkan-impl/vulkan-sampler-impl.h>
 
 namespace Dali::Graphics::Vulkan
 {
+
+namespace
+{
+constexpr vk::Filter ConvertFilter(Dali::Graphics::SamplerFilter filter)
+{
+  switch(filter)
+  {
+    case Dali::Graphics::SamplerFilter::LINEAR:
+      return vk::Filter::eLinear;
+    case Dali::Graphics::SamplerFilter::NEAREST:
+      return vk::Filter::eNearest;
+  }
+  return vk::Filter{};
+}
+
+constexpr vk::SamplerAddressMode ConvertAddressMode(Dali::Graphics::SamplerAddressMode mode)
+{
+  switch(mode)
+  {
+    case Dali::Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
+      return vk::SamplerAddressMode::eClampToEdge;
+    case Dali::Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
+      return vk::SamplerAddressMode::eClampToBorder;
+    case Dali::Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
+      return vk::SamplerAddressMode::eMirrorClampToEdge;
+    case Dali::Graphics::SamplerAddressMode::MIRRORED_REPEAT:
+      return vk::SamplerAddressMode::eMirroredRepeat;
+    case Dali::Graphics::SamplerAddressMode::REPEAT:
+      return vk::SamplerAddressMode::eRepeat;
+  }
+  return vk::SamplerAddressMode{};
+}
+
+constexpr vk::SamplerMipmapMode ConvertMipmapMode(Dali::Graphics::SamplerMipmapMode mode)
+{
+  switch(mode)
+  {
+    case Dali::Graphics::SamplerMipmapMode::NONE:
+      return vk::SamplerMipmapMode::eNearest;
+    case Dali::Graphics::SamplerMipmapMode::LINEAR:
+      return vk::SamplerMipmapMode::eLinear;
+    case Dali::Graphics::SamplerMipmapMode::NEAREST:
+      return vk::SamplerMipmapMode::eNearest;
+  }
+  return vk::SamplerMipmapMode{};
+}
+
+} // namespace
+
 Sampler::Sampler(const Graphics::SamplerCreateInfo& createInfo, VulkanGraphicsController& controller)
 : SamplerResource(createInfo, controller)
 {
@@ -37,6 +87,23 @@ void Sampler::DestroyResource()
 
 bool Sampler::InitializeResource()
 {
+  vk::SamplerCreateInfo createInfo{};
+  createInfo.setMinFilter(ConvertFilter(mCreateInfo.minFilter))
+    .setMagFilter(ConvertFilter(mCreateInfo.magFilter))
+    .setAddressModeU(ConvertAddressMode(mCreateInfo.addressModeU))
+    .setAddressModeV(ConvertAddressMode(mCreateInfo.addressModeV))
+    .setAddressModeW(ConvertAddressMode(mCreateInfo.addressModeW))
+    .setMipmapMode(ConvertMipmapMode(mCreateInfo.mipMapMode))
+    .setCompareEnable(vk::Bool32(mCreateInfo.compareEnable))
+    .setUnnormalizedCoordinates(vk::Bool32(mCreateInfo.unnormalizeCoordinates))
+    .setBorderColor(vk::BorderColor::eFloatOpaqueBlack)
+    .setAnisotropyEnable(vk::Bool32(mCreateInfo.anisotropyEnable))
+    .setMaxAnisotropy(mCreateInfo.maxAnisotropy)
+    .setMinLod(mCreateInfo.minLod)
+    .setMaxLod(mCreateInfo.maxLod);
+
+  mSamplerImpl = SamplerImpl::New(mController.GetGraphicsDevice(), createInfo);
+
   return true;
 }
 
index d575b050379e9e800e8162e9a07c29662d335fb7..ac42ac0d9044b4c6469eaa19857aa8c7e94aac83 100644 (file)
@@ -28,6 +28,7 @@
 namespace Dali::Graphics::Vulkan
 {
 using SamplerResource = Resource<Graphics::Sampler, Graphics::SamplerCreateInfo>;
+class SamplerImpl;
 
 class Sampler : public SamplerResource
 {
@@ -60,6 +61,14 @@ public:
    * @brief Called when UniquePtr<> on client-side dies
    */
   void DiscardResource() override;
+
+  SamplerImpl* GetImpl()
+  {
+    return mSamplerImpl;
+  }
+
+private:
+  SamplerImpl* mSamplerImpl;
 };
 
 } // namespace Dali::Graphics::Vulkan