1 /*
2  * Copyright © 2021 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 #ifndef VK_RENDER_PASS_H
24 #define VK_RENDER_PASS_H
25 
26 #include "vk_object.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /**
33  * Pseudo-extension struct that may be chained into VkRenderingInfo,
34  * VkCommandBufferInheritanceRenderingInfo, or VkPipelineRenderingCreateInfo
35  * to provide self-dependency information.
36  */
37 typedef struct VkRenderingSelfDependencyInfoMESA {
38     VkStructureType    sType;
39 #define VK_STRUCTURE_TYPE_RENDERING_SELF_DEPENDENCY_INFO_MESA (VkStructureType)1000044900
40     const void*        pNext;
41 
42     /** Bitset of which color attachments have self-dependencies */
43     uint32_t           colorSelfDependencies;
44 
45     /** True if there is a depth self-dependency */
46     VkBool32           depthSelfDependency;
47 
48     /** True if there is a stencil self-dependency */
49     VkBool32           stencilSelfDependency;
50 } VkRenderingSelfDependencyInfoMESA;
51 
52 /**
53  * Pseudo-extension struct that may be chained into VkRenderingAttachmentInfo
54  * to indicate an initial layout for the attachment.  This is only allowed if
55  * all of the following conditions are met:
56  *
57  *    1. VkRenderingAttachmentInfo::loadOp == LOAD_OP_CLEAR
58  *
59  *    2. VkRenderingInfo::renderArea is tne entire image view LOD
60  *
61  *    3. For 3D image attachments, VkRenderingInfo::viewMask == 0 AND
62  *       VkRenderingInfo::layerCount references the entire bound image view
63  *       OR VkRenderingInfo::viewMask is dense (no holes) and references the
64  *       entire bound image view.  (2D and 2D array images have no such
65  *       requirement.)
66  *
67  * If this struct is included in the pNext chain of a
68  * VkRenderingAttachmentInfo, the driver is responsible for transitioning the
69  * bound region of the image from
70  * VkRenderingAttachmentInitialLayoutInfoMESA::initialLayout to
71  * VkRenderingAttachmentInfo::imageLayout prior to rendering.
72  */
73 typedef struct VkRenderingAttachmentInitialLayoutInfoMESA {
74     VkStructureType    sType;
75 #define VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INITIAL_LAYOUT_INFO_MESA (VkStructureType)1000044901
76     const void*        pNext;
77 
78     /** Initial layout of the attachment */
79     VkImageLayout      initialLayout;
80 } VkRenderingAttachmentInitialLayoutInfoMESA;
81 
82 struct vk_subpass_attachment {
83    /** VkAttachmentReference2::attachment */
84    uint32_t attachment;
85 
86    /** Aspects referenced by this attachment
87     *
88     * For an input attachment, this is VkAttachmentReference2::aspectMask.
89     * For all others, it's equal to the vk_render_pass_attachment::aspects.
90     */
91    VkImageAspectFlags aspects;
92 
93    /** Usage for this attachment
94     *
95     * This is a single VK_IMAGE_USAGE_* describing the usage of this subpass
96     * attachment.  Resolve attachments are VK_IMAGE_USAGE_TRANSFER_DST_BIT.
97     */
98    VkImageUsageFlagBits usage;
99 
100    /** VkAttachmentReference2::layout */
101    VkImageLayout layout;
102 
103    /** VkAttachmentReferenceStencilLayout::stencilLayout
104     *
105     * If VK_KHR_separate_depth_stencil_layouts is not used, this will be
106     * layout if the attachment contains stencil and VK_IMAGE_LAYOUT_UNDEFINED
107     * otherwise.
108     */
109    VkImageLayout stencil_layout;
110 
111    /** A per-view mask for if this is the last use of this attachment
112     *
113     * If the same render pass attachment is used multiple ways within a
114     * subpass, corresponding last_subpass bits will be set in all of them.
115     * For the non-multiview case, only the first bit is used.
116     */
117    uint32_t last_subpass;
118 
119    /** Resolve attachment, if any */
120    struct vk_subpass_attachment *resolve;
121 };
122 
123 struct vk_subpass {
124    /** Count of all attachments referenced by this subpass */
125    uint32_t attachment_count;
126 
127    /** Array of all attachments referenced by this subpass */
128    struct vk_subpass_attachment *attachments;
129 
130    /** VkSubpassDescription2::inputAttachmentCount */
131    uint32_t input_count;
132 
133    /** VkSubpassDescription2::pInputAttachments */
134    struct vk_subpass_attachment *input_attachments;
135 
136    /** VkSubpassDescription2::colorAttachmentCount */
137    uint32_t color_count;
138 
139    /** VkSubpassDescription2::pColorAttachments */
140    struct vk_subpass_attachment *color_attachments;
141 
142    /** VkSubpassDescription2::colorAttachmentCount or zero */
143    uint32_t color_resolve_count;
144 
145    /** VkSubpassDescription2::pResolveAttachments */
146    struct vk_subpass_attachment *color_resolve_attachments;
147 
148    /** VkSubpassDescription2::pDepthStencilAttachment */
149    struct vk_subpass_attachment *depth_stencil_attachment;
150 
151    /** VkSubpassDescriptionDepthStencilResolve::pDepthStencilResolveAttachment */
152    struct vk_subpass_attachment *depth_stencil_resolve_attachment;
153 
154    /** VkFragmentShadingRateAttachmentInfoKHR::pFragmentShadingRateAttachment */
155    struct vk_subpass_attachment *fragment_shading_rate_attachment;
156 
157    /** VkSubpassDescription2::viewMask or 1 for non-multiview
158     *
159     * For all view masks in the vk_render_pass data structure, we use a mask
160     * of 1 for non-multiview instead of a mask of 0.  To determine if the
161     * render pass is multiview or not, see vk_render_pass::is_multiview.
162     */
163    uint32_t view_mask;
164 
165    /** VkSubpassDescriptionDepthStencilResolve::depthResolveMode */
166    VkResolveModeFlagBitsKHR depth_resolve_mode;
167 
168    /** VkSubpassDescriptionDepthStencilResolve::stencilResolveMode */
169    VkResolveModeFlagBitsKHR stencil_resolve_mode;
170 
171    /** VkFragmentShadingRateAttachmentInfoKHR::shadingRateAttachmentTexelSize */
172    VkExtent2D fragment_shading_rate_attachment_texel_size;
173 
174    /** VkRenderingSelfDependencyInfoMESA for this subpass
175     *
176     * This is in the pNext chain of pipeline_info and inheritance_info.
177     */
178    VkRenderingSelfDependencyInfoMESA self_dep_info;
179 
180    /** VkPipelineRenderingCreateInfo for this subpass
181     *
182     * Returned by vk_get_pipeline_rendering_create_info() if
183     * VkGraphicsPipelineCreateInfo::renderPass != VK_NULL_HANDLE.
184     */
185    VkPipelineRenderingCreateInfo pipeline_info;
186 
187    /** VkCommandBufferInheritanceRenderingInfo for this subpass
188     *
189     * Returned by vk_get_command_buffer_inheritance_rendering_info() if
190     * VkCommandBufferInheritanceInfo::renderPass != VK_NULL_HANDLE.
191     */
192    VkCommandBufferInheritanceRenderingInfo inheritance_info;
193 };
194 
195 struct vk_render_pass_attachment {
196    /** VkAttachmentDescription2::format */
197    VkFormat format;
198 
199    /** Aspects contained in format */
200    VkImageAspectFlags aspects;
201 
202    /** VkAttachmentDescription2::samples */
203    uint32_t samples;
204 
205    /** Views in which this attachment is used, 0 for unused
206     *
207     * For non-multiview, this will be 1 if the attachment is used.
208     */
209    uint32_t view_mask;
210 
211    /** VkAttachmentDescription2::loadOp */
212    VkAttachmentLoadOp load_op;
213 
214    /** VkAttachmentDescription2::storeOp */
215    VkAttachmentStoreOp store_op;
216 
217    /** VkAttachmentDescription2::stencilLoadOp */
218    VkAttachmentLoadOp stencil_load_op;
219 
220    /** VkAttachmentDescription2::stencilStoreOp */
221    VkAttachmentStoreOp stencil_store_op;
222 
223    /** VkAttachmentDescription2::initialLayout */
224    VkImageLayout initial_layout;
225 
226    /** VkAttachmentDescription2::finalLayout */
227    VkImageLayout final_layout;
228 
229    /** VkAttachmentDescriptionStencilLayout::stencilInitialLayout
230     *
231     * If VK_KHR_separate_depth_stencil_layouts is not used, this will be
232     * initial_layout if format contains stencil and VK_IMAGE_LAYOUT_UNDEFINED
233     * otherwise.
234     */
235    VkImageLayout initial_stencil_layout;
236 
237    /** VkAttachmentDescriptionStencilLayout::stencilFinalLayout
238     *
239     * If VK_KHR_separate_depth_stencil_layouts is not used, this will be
240     * final_layout if format contains stencil and VK_IMAGE_LAYOUT_UNDEFINED
241     * otherwise.
242     */
243    VkImageLayout final_stencil_layout;
244 };
245 
246 struct vk_subpass_dependency {
247    /** VkSubpassDependency2::dependencyFlags */
248    VkDependencyFlags flags;
249 
250    /** VkSubpassDependency2::srcSubpass */
251    uint32_t src_subpass;
252 
253    /** VkSubpassDependency2::dstSubpass */
254    uint32_t dst_subpass;
255 
256    /** VkSubpassDependency2::srcStageMask */
257    VkPipelineStageFlags2 src_stage_mask;
258 
259    /** VkSubpassDependency2::dstStageMask */
260    VkPipelineStageFlags2 dst_stage_mask;
261 
262    /** VkSubpassDependency2::srcAccessMask */
263    VkAccessFlags2 src_access_mask;
264 
265    /** VkSubpassDependency2::dstAccessMask */
266    VkAccessFlags2 dst_access_mask;
267 
268    /** VkSubpassDependency2::viewOffset */
269    int32_t view_offset;
270 };
271 
272 struct vk_render_pass {
273    struct vk_object_base base;
274 
275    /** True if this render pass uses multiview
276     *
277     * This is true if all subpasses have viewMask != 0.
278     */
279    bool is_multiview;
280 
281    /** Views used by this render pass or 1 for non-multiview */
282    uint32_t view_mask;
283 
284    /** VkRenderPassCreateInfo2::attachmentCount */
285    uint32_t attachment_count;
286 
287    /** VkRenderPassCreateInfo2::pAttachments */
288    struct vk_render_pass_attachment *attachments;
289 
290    /** VkRenderPassCreateInfo2::subpassCount */
291    uint32_t subpass_count;
292 
293    /** VkRenderPassCreateInfo2::subpasses */
294    struct vk_subpass *subpasses;
295 
296    /** VkRenderPassCreateInfo2::dependencyCount */
297    uint32_t dependency_count;
298 
299    /** VkRenderPassCreateInfo2::pDependencies */
300    struct vk_subpass_dependency *dependencies;
301 };
302 
303 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_render_pass, base, VkRenderPass,
304                                VK_OBJECT_TYPE_RENDER_PASS);
305 
306 /** Returns the VkPipelineRenderingCreateInfo for a graphics pipeline
307  *
308  * For render-pass-free drivers, this can be used in the implementaiton of
309  * vkCreateGraphicsPipelines to get the VkPipelineRenderingCreateInfo.  If
310  * VkGraphicsPipelineCreateInfo::renderPass is not VK_NULL_HANDLE, it will
311  * return a representation of the specified subpass as a
312  * VkPipelineRenderingCreateInfo.  If VkGraphicsPipelineCreateInfo::renderPass
313  * is VK_NULL_HANDLE and there is a VkPipelineRenderingCreateInfo in the pNext
314  * chain of VkGraphicsPipelineCreateInfo, it will return that.
315  *
316  * @param[in]  info  One of the pCreateInfos from vkCreateGraphicsPipelines
317  */
318 const VkPipelineRenderingCreateInfo *
319 vk_get_pipeline_rendering_create_info(const VkGraphicsPipelineCreateInfo *info);
320 
321 /**
322  * Returns the VkCommandBufferInheritanceRenderingInfo for secondary command
323  * buffer execution
324  *
325  * For render-pass-free drivers, this can be used in the implementaiton of
326  * vkCmdExecuteCommands to get the VkCommandBufferInheritanceRenderingInfo.
327  * If VkCommandBufferInheritanceInfo::renderPass is not VK_NULL_HANDLE, it
328  * will return a representation of the specified subpass as a
329  * VkCommandBufferInheritanceRenderingInfo.  If
330  * VkCommandBufferInheritanceInfo::renderPass is not VK_NULL_HANDLE and there
331  * is a VkCommandBufferInheritanceRenderingInfo in the pNext chain of
332  * VkCommandBufferBeginInfo, it will return that.
333  *
334  * @param[in]  level       The nesting level of this command buffer
335  * @param[in]  pBeginInfo  The pBeginInfo from vkBeginCommandBuffer
336  */
337 const VkCommandBufferInheritanceRenderingInfo *
338 vk_get_command_buffer_inheritance_rendering_info(
339    VkCommandBufferLevel level,
340    const VkCommandBufferBeginInfo *pBeginInfo);
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif /* VK_RENDER_PASS_H */
347