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 | |
7 | #include "vulkan_command_buffer.h" |
8 | #include "vulkan_proc_table.h" |
9 | |
10 | namespace vulkan { |
11 | |
12 | VulkanImage::VulkanImage(VulkanHandle<VkImage> image) |
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 | |
30 | bool VulkanImage::InsertImageMemoryBarrier( |
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 |
70 | |