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