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

vsg 1.1.10 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
20#ifdef _M_ARM64
21#pragma push_macro("MemoryBarrier")
22#undef MemoryBarrier
23#endif
24
25namespace vsg
26{
27
29 struct VSG_DECLSPEC VulkanInfo : public Inherit<Object, VulkanInfo>
30 {
31 ref_ptr<VulkanInfo> next;
32
33 virtual void* assign(CommandBuffer& commandBuffer) const = 0;
34 };
35
37 struct VSG_DECLSPEC MemoryBarrier : public Inherit<Object, MemoryBarrier>
38 {
39 explicit MemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
40 VkAccessFlags in_dstAccessMask = 0) :
41 srcAccessMask(in_srcAccessMask),
42 dstAccessMask(in_dstAccessMask) {}
43
44 ref_ptr<VulkanInfo> next;
45 VkAccessFlags srcAccessMask = 0;
46 VkAccessFlags dstAccessMask = 0;
47
48 void assign(CommandBuffer& commandBuffer, VkMemoryBarrier& info) const;
49 };
50 VSG_type_name(vsg::MemoryBarrier);
51 using MemoryBarriers = std::vector<ref_ptr<MemoryBarrier>>;
52
54 struct VSG_DECLSPEC BufferMemoryBarrier : public Inherit<Object, BufferMemoryBarrier>
55 {
56 explicit BufferMemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
57 VkAccessFlags in_dstAccessMask = 0,
58 uint32_t in_srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
59 uint32_t in_dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
60 ref_ptr<Buffer> in_buffer = {},
61 VkDeviceSize in_offset = 0,
62 VkDeviceSize in_size = 0) :
63 srcAccessMask(in_srcAccessMask),
64 dstAccessMask(in_dstAccessMask),
65 srcQueueFamilyIndex(in_srcQueueFamilyIndex),
66 dstQueueFamilyIndex(in_dstQueueFamilyIndex),
67 buffer(in_buffer),
68 offset(in_offset),
69 size(in_size) {}
70
71 ref_ptr<VulkanInfo> next;
72 VkAccessFlags srcAccessMask = 0;
73 VkAccessFlags dstAccessMask = 0;
74 uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; // Queue::queueFamilyIndex() or VK_QUEUE_FAMILY_IGNORED
75 uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; // Queue::queueFamilyIndex() or VK_QUEUE_FAMILY_IGNORED
76 ref_ptr<Buffer> buffer;
77 VkDeviceSize offset = 0;
78 VkDeviceSize size = 0;
79
80 void assign(CommandBuffer& commandBuffer, VkBufferMemoryBarrier& info) const;
81 };
82 VSG_type_name(vsg::BufferMemoryBarrier);
83 using BufferMemoryBarriers = std::vector<ref_ptr<BufferMemoryBarrier>>;
84
86 struct VSG_DECLSPEC ImageMemoryBarrier : public Inherit<Object, ImageMemoryBarrier>
87 {
88 explicit ImageMemoryBarrier(VkAccessFlags in_srcAccessMask = 0,
89 VkAccessFlags in_dstAccessMask = 0,
90 VkImageLayout in_oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
91 VkImageLayout in_newLayout = VK_IMAGE_LAYOUT_UNDEFINED,
92 uint32_t in_srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
93 uint32_t in_dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
94 ref_ptr<Image> in_image = {},
95 VkImageSubresourceRange in_subresourceRange = {0, 0, 0, 0, 0}) :
96 srcAccessMask(in_srcAccessMask),
97 dstAccessMask(in_dstAccessMask),
98 oldLayout(in_oldLayout),
99 newLayout(in_newLayout),
100 srcQueueFamilyIndex(in_srcQueueFamilyIndex),
101 dstQueueFamilyIndex(in_dstQueueFamilyIndex),
102 image(in_image),
103 subresourceRange(in_subresourceRange) {}
104
105 ref_ptr<VulkanInfo> next;
106 VkAccessFlags srcAccessMask = 0;
107 VkAccessFlags dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
108 VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
109 VkImageLayout newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
110 uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
111 uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
112 ref_ptr<Image> image;
113 VkImageSubresourceRange subresourceRange = {0, 0, 0, 0, 0};
114
115 void assign(CommandBuffer& commandBuffer, VkImageMemoryBarrier& info) const;
116 };
117 VSG_type_name(vsg::ImageMemoryBarrier);
118 using ImageMemoryBarriers = std::vector<ref_ptr<ImageMemoryBarrier>>;
119
121 struct VSG_DECLSPEC SampleLocations : public Inherit<VulkanInfo, SampleLocations>
122 {
123 VkSampleCountFlagBits sampleLocationsPerPixel = VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM;
124 VkExtent2D sampleLocationGridSize = {0, 0};
125 std::vector<vec2> sampleLocations;
126
127 void* assign(CommandBuffer& commandBuffer) const override;
128 };
129
131 class VSG_DECLSPEC PipelineBarrier : public Inherit<Command, PipelineBarrier>
132 {
133 public:
134 PipelineBarrier();
135
136 template<typename... Args>
137 PipelineBarrier(VkPipelineStageFlags in_srcStageMask, VkPipelineStageFlags in_destStageMask, VkDependencyFlags in_dependencyFlags, Args&&... args) :
138 srcStageMask(in_srcStageMask),
139 dstStageMask(in_destStageMask),
140 dependencyFlags(in_dependencyFlags)
141 {
142 (add(args), ...);
143 }
144
145 void record(CommandBuffer& commandBuffer) const override;
146
147 void add(ref_ptr<MemoryBarrier> mb) { memoryBarriers.emplace_back(mb); }
148 void add(ref_ptr<BufferMemoryBarrier> bmb) { bufferMemoryBarriers.emplace_back(bmb); }
149 void add(ref_ptr<ImageMemoryBarrier> imb) { imageMemoryBarriers.emplace_back(imb); }
150
151 VkPipelineStageFlags srcStageMask;
152 VkPipelineStageFlags dstStageMask;
153 VkDependencyFlags dependencyFlags;
154
155 MemoryBarriers memoryBarriers;
156 BufferMemoryBarriers bufferMemoryBarriers;
157 ImageMemoryBarriers imageMemoryBarriers;
158
159 protected:
160 virtual ~PipelineBarrier();
161 };
162 VSG_type_name(vsg::PipelineBarrier);
163
164} // namespace vsg
165
166#ifdef _M_ARM64
167#pragma pop_macro("MemoryBarrier")
168#endif
vsg::CommandBuffer
CommandBuffer encapsulates VkCommandBuffer.
Definition CommandBuffer.h:27
vsg::PipelineBarrier
PipelineBarrier command encapsulates vkCmdPipelineBarrier call and associated lists of MemoryBarrier,...
Definition PipelineBarrier.h:132
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::BufferMemoryBarrier
BufferMemoryBarrier encapsulates VkBufferMemoryBarrier settings.
Definition PipelineBarrier.h:55
vsg::ImageMemoryBarrier
ImageMemoryBarrier encapsulates vkImageMemoryBarrier settings.
Definition PipelineBarrier.h:87
vsg::MemoryBarrier
MemoryBarrier encapsulates VkMemoryBarrier settings.
Definition PipelineBarrier.h:38
vsg::SampleLocations
SampleLocations encapsulates the VkSampleLocationsInfoEXT settings associated with VK_EXT_sample_loca...
Definition PipelineBarrier.h:122
vsg::VulkanInfo
VulkanInfo is a base class for extensions assigned via next pointer in Vulkan structures.
Definition PipelineBarrier.h:30