1// Copyright 2022-2023 The Khronos Group Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5= VK_EXT_rasterization_order_attachment_access
6:toc: left
7:refpage: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/
8:sectnums:
9
10This proposal extends the mechanism of input attachments to allow access to framebuffer attachments that are used both as input and as
11color or depth/stencil attachments from one fragment to the next, in rasterization order, without explicit synchronization.
12
13== Problem Statement
14
15Renderpasses, and specifically subpass self-dependencies enable much of the same functionality as the framebuffer
16fetch and pixel local storage extensions did for OpenGL ES.
17But certain techniques such as programmable blending are awkward or impractical to implement with these alone, in part because a self-dependency
18is required every time a fragment will read a value at a given sample coordinate.
19For these use-cases, a mechanisms that more closely matches framebuffer fetch is useful.
20
21== Solution Space
22
23For simplicity, this proposal extends the original render pass API and not the link:{refpage}VK_KHR_dynamic_rendering.html[VK_KHR_dynamic_rendering] API.
24Raster order attachment reads are done as input attachment reads (as before), but self-dependencies are no longer required when reading a value written
25by fragments earlier in rasterization order.
26
27Since input attachments are not used in dynamic rendering, a different approach is needed there. This proposal does not address that issue.
28
29== Proposal
30
31The following features are exposed by this extension:
32
33[source,c]
34----
35typedef struct VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT {
36    VkStructureType    sType;
37    void*              pNext;
38    VkBool32           rasterizationOrderColorAttachmentAccess;
39    VkBool32           rasterizationOrderDepthAttachmentAccess;
40    VkBool32           rasterizationOrderStencilAttachmentAccess;
41} VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT;
42----
43These features allow the implementation to expose separately whether rasterization order access is supported
44for color attachments, depth attachments, and stencil attachments.
45
46The application declares at pipeline creation time whether rasterization order access will be used
47for color, depth, or stencil aspects, by setting the appropriate combination of the following flags on the pipeline:
48
49[source,c]
50----
51typedef enum VkPipelineDepthStencilStateCreateFlagBits {
52    VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_EXT = 0x00000001,
53    VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_EXT = 0x00000002,
54    VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
55} VkPipelineDepthStencilStateCreateFlagBits;
56typedef VkFlags VkPipelineDepthStencilStateCreateFlags;
57
58typedef enum VkPipelineColorBlendStateCreateFlagBits {
59    VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_EXT = 0x00000001,
60    VK_PIPELINE_COLOR_BLEND_STATE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
61} VkPipelineColorBlendStateCreateFlagBits;
62----
63
64Additionally, per subpass flags are added to indicate whether a subpass is compatible with
65rasterization order access. The following flags are added to VkSubpassDescriptionFlagBits:
66
67[source,c]
68----
69typedef enum VkSubpassDescriptionFlagBits {
70    /* existing flags not shown */
71    VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_COLOR_ACCESS_BIT_EXT = 0x00000010,
72    VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_EXT = 0x00000020,
73    VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_EXT = 0x00000040,
74    VK_SUBPASS_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
75} VkSubpassDescriptionFlagBits;
76----
77
78== Issues
79
80=== RESOLVED: Is there any interaction with the link:{refpage}VK_KHR_dynamic_rendering.html[VK_KHR_dynamic_rendering] extension?
81
82No. This extension only affects reads from input attachments.
83Render pass instances begun with `vkCmdBeginRenderingKHR` do not have input attachments and a different mechanism will be needed to provide similar functionality in that case.
84
85=== RESOLVED: What are the differences to the link:{refpage}VK_ARM_rasterization_order_attachment_access.html[VK_ARM_rasterization_order_attachment_access] extension?
86
87None. This extension is a multi-vendor version of that extension with no changes.
88The two extensions can be used interchangeably since the API structures and enumeration alias each other.
89