vsg: include/vsg/commands/PipelineBarrier.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
PipelineBarrier.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/commands/Command.h>
16#include <vsg/core/ScratchMemory.h>
17#include <vsg/state/Buffer.h>
18#include <vsg/state/Image.h>
19
20namespace vsg
21{
22
24 struct VSG_DECLSPEC VulkanInfo : public Inherit<Object, VulkanInfo>
25 {
26 ref_ptr<VulkanInfo> next;
27
28 virtual void* assign(CommandBuffer& commandBuffer) const = 0;
29 };
30
32 struct VSG_DECLSPEC MemoryBarrier : public Inherit<Object, MemoryBarrier>
33 {
34 MemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
35 VkAccessFlags in_dstAccessMask = 0) :
36 srcAccessMask(in_srcAccessMask),
37 dstAccessMask(in_dstAccessMask) {}
38
39 ref_ptr<VulkanInfo> next;
40 VkAccessFlags srcAccessMask = 0;
41 VkAccessFlags dstAccessMask = 0;
42
43 void assign(CommandBuffer& commandBuffer, VkMemoryBarrier& info) const;
44 };
45 VSG_type_name(vsg::MemoryBarrier);
46 using MemoryBarriers = std::vector<ref_ptr<MemoryBarrier>>;
47
49 struct VSG_DECLSPEC BufferMemoryBarrier : public Inherit<Object, BufferMemoryBarrier>
50 {
51 BufferMemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
52 VkAccessFlags in_dstAccessMask = 0,
53 uint32_t in_srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
54 uint32_t in_dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
55 ref_ptr<Buffer> in_buffer = {},
56 VkDeviceSize in_offset = 0,
57 VkDeviceSize in_size = 0) :
58 srcAccessMask(in_srcAccessMask),
59 dstAccessMask(in_dstAccessMask),
60 srcQueueFamilyIndex(in_srcQueueFamilyIndex),
61 dstQueueFamilyIndex(in_dstQueueFamilyIndex),
62 buffer(in_buffer),
63 offset(in_offset),
64 size(in_size) {}
65
66 ref_ptr<VulkanInfo> next;
67 VkAccessFlags srcAccessMask = 0;
68 VkAccessFlags dstAccessMask = 0;
69 uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; // Queue::queueFamilyIndex() or VK_QUEUE_FAMILY_IGNORED
70 uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; // Queue::queueFamilyIndex() or VK_QUEUE_FAMILY_IGNORED
71 ref_ptr<Buffer> buffer;
72 VkDeviceSize offset = 0;
73 VkDeviceSize size = 0;
74
75 void assign(CommandBuffer& commandBuffer, VkBufferMemoryBarrier& info) const;
76 };
77 VSG_type_name(vsg::BufferMemoryBarrier);
78 using BufferMemoryBarriers = std::vector<ref_ptr<BufferMemoryBarrier>>;
79
81 struct VSG_DECLSPEC ImageMemoryBarrier : public Inherit<Object, ImageMemoryBarrier>
82 {
83 ImageMemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
84 VkAccessFlags in_dstAccessMask = 0,
85 VkImageLayout in_oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
86 VkImageLayout in_newLayout = VK_IMAGE_LAYOUT_UNDEFINED,
87 uint32_t in_srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
88 uint32_t in_dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
89 ref_ptr<Image> in_image = {},
90 VkImageSubresourceRange in_subresourceRange = {0, 0, 0, 0, 0}) :
91 srcAccessMask(in_srcAccessMask),
92 dstAccessMask(in_dstAccessMask),
93 oldLayout(in_oldLayout),
94 newLayout(in_newLayout),
95 srcQueueFamilyIndex(in_srcQueueFamilyIndex),
96 dstQueueFamilyIndex(in_dstQueueFamilyIndex),
97 image(in_image),
98 subresourceRange(in_subresourceRange) {}
99
100 ref_ptr<VulkanInfo> next;
101 VkAccessFlags srcAccessMask = 0;
102 VkAccessFlags dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
103 VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
104 VkImageLayout newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
105 uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
106 uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
107 ref_ptr<Image> image;
108 VkImageSubresourceRange subresourceRange = {0, 0, 0, 0, 0};
109
110 void assign(CommandBuffer& commandBuffer, VkImageMemoryBarrier& info) const;
111 };
112 VSG_type_name(vsg::ImageMemoryBarrier);
113 using ImageMemoryBarriers = std::vector<ref_ptr<ImageMemoryBarrier>>;
114
116 struct VSG_DECLSPEC SampleLocations : public Inherit<VulkanInfo, SampleLocations>
117 {
118 VkSampleCountFlagBits sampleLocationsPerPixel = VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM;
119 VkExtent2D sampleLocationGridSize = {0, 0};
120 std::vector<vec2> sampleLocations;
121
122 void* assign(CommandBuffer& commandBuffer) const override;
123 };
124
126 class VSG_DECLSPEC PipelineBarrier : public Inherit<Command, PipelineBarrier>
127 {
128 public:
129 PipelineBarrier();
130
131 template<typename... Args>
132 PipelineBarrier(VkPipelineStageFlags in_srcStageMask, VkPipelineStageFlags in_destStageMask, VkDependencyFlags in_dependencyFlags, Args&&... args) :
133 srcStageMask(in_srcStageMask),
134 dstStageMask(in_destStageMask),
135 dependencyFlags(in_dependencyFlags)
136 {
137 (add(args), ...);
138 }
139
140 void record(CommandBuffer& commandBuffer) const override;
141
142 void add(ref_ptr<MemoryBarrier> mb) { memoryBarriers.emplace_back(mb); }
143 void add(ref_ptr<BufferMemoryBarrier> bmb) { bufferMemoryBarriers.emplace_back(bmb); }
144 void add(ref_ptr<ImageMemoryBarrier> imb) { imageMemoryBarriers.emplace_back(imb); }
145
146 VkPipelineStageFlags srcStageMask;
147 VkPipelineStageFlags dstStageMask;
148 VkDependencyFlags dependencyFlags;
149
150 MemoryBarriers memoryBarriers;
151 BufferMemoryBarriers bufferMemoryBarriers;
152 ImageMemoryBarriers imageMemoryBarriers;
153
154 protected:
155 virtual ~PipelineBarrier();
156 };
157 VSG_type_name(vsg::PipelineBarrier);
158
159} // namespace vsg
vsg::CommandBuffer
CommandBuffer encapsulates VkCommandBuffer.
Definition CommandBuffer.h:27
vsg::Inherit
Definition Inherit.h:28
vsg::PipelineBarrier
PipelineBarrier command encapsulates vkCmdPipelineBarrier call and associated lists of MemoryBarrier,...
Definition PipelineBarrier.h:127
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::BufferMemoryBarrier
BufferMemoryBarrier encapsulates VkBufferMemoryBarrier settings.
Definition PipelineBarrier.h:50
vsg::ImageMemoryBarrier
ImageMemoryBarrier encapsulates vkImageMemoryBarrier settings.
Definition PipelineBarrier.h:82
vsg::MemoryBarrier
MemoryBarrier encapsulates VkMemoryBarrier settings.
Definition PipelineBarrier.h:33
vsg::SampleLocations
SampleLocations encapsulates the VkSampleLocationsInfoEXT settings associated with VK_EXT_sample_loca...
Definition PipelineBarrier.h:117
vsg::VulkanInfo
VulkanInfo is a base class for extensions assigned via next pointer in Vulkan structures.
Definition PipelineBarrier.h:25