Flutter Engine
vulkan_image.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "vulkan_image.h"
6 
8 #include "vulkan_proc_table.h"
9 
10 namespace vulkan {
11 
13  : handle_(std::move(image)),
14  layout_(VK_IMAGE_LAYOUT_UNDEFINED),
15  access_flags_(0),
16  valid_(false) {
17  if (!handle_) {
18  return;
19  }
20 
21  valid_ = true;
22 }
23 
24 VulkanImage::~VulkanImage() = default;
25 
26 bool VulkanImage::IsValid() const {
27  return valid_;
28 }
29 
31  const VulkanCommandBuffer& command_buffer,
32  VkPipelineStageFlagBits src_pipline_bits,
33  VkPipelineStageFlagBits dest_pipline_bits,
34  VkAccessFlagBits dest_access_flags,
35  VkImageLayout dest_layout) {
36  const VkImageMemoryBarrier image_memory_barrier = {
37  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
38  .pNext = nullptr,
39  .srcAccessMask = access_flags_,
40  .dstAccessMask = dest_access_flags,
41  .oldLayout = layout_,
42  .newLayout = dest_layout,
43  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
44  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
45  .image = handle_,
46  .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
47  };
48 
49  bool success = command_buffer.InsertPipelineBarrier(
50  src_pipline_bits, // src_stage_flags
51  dest_pipline_bits, // dest_stage_flags
52  0, // dependency_flags
53  0, // memory_barrier_count
54  nullptr, // memory_barriers
55  0, // buffer_memory_barrier_count
56  nullptr, // buffer_memory_barriers
57  1, // image_memory_barrier_count
58  &image_memory_barrier // image_memory_barriers
59  );
60 
61  if (success) {
62  access_flags_ = dest_access_flags;
63  layout_ = dest_layout;
64  }
65 
66  return success;
67 }
68 
69 } // namespace vulkan
Definition: ref_ptr.h:252
VulkanImage(VulkanHandle< VkImage > image)
Definition: vulkan_image.cc:12
bool InsertImageMemoryBarrier(const VulkanCommandBuffer &command_buffer, VkPipelineStageFlagBits src_pipline_bits, VkPipelineStageFlagBits dest_pipline_bits, VkAccessFlagBits dest_access_flags, VkImageLayout dest_layout)
Definition: vulkan_image.cc:30
bool IsValid() const
Definition: vulkan_image.cc:26
bool InsertPipelineBarrier(VkPipelineStageFlagBits src_stage_flags, VkPipelineStageFlagBits dest_stage_flags, uint32_t dependency_flags, uint32_t memory_barrier_count, const VkMemoryBarrier *memory_barriers, uint32_t buffer_memory_barrier_count, const VkBufferMemoryBarrier *buffer_memory_barriers, uint32_t image_memory_barrier_count, const VkImageMemoryBarrier *image_memory_barriers) const