summaryrefslogtreecommitdiff
path: root/proposals/VK_EXT_dynamic_rendering_unused_attachments.adoc
blob: 95d2c1ae4d79432b58e8901c1d3b3e31839732bf (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2021-2024 The Khronos Group Inc.
//
// SPDX-License-Identifier: CC-BY-4.0

= VK_EXT_dynamic_rendering_unused_attachments
:toc: left
:refpage: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/
:sectnums:

This document describes a limitation with `apiext:VK_KHR_dynamic_rendering` that limits what
pipelines can be used with render pass instances, and may subsequently require
many more pipeline objects to be created to work around the limitation.

== Problem Statement

The `apiext:VK_KHR_dynamic_rendering` has several restrictions on what pipelines can be
bound within a render pass instance which may cause the application to have to create
multiple variants of the pipeline object in order to be compatible with the render
pass instance.
These restrictions were put in place to accommodate hardware that uses the pipeline
state to program the framebuffer layout for the render pass instance and cannot easily
change the framebuffer layout during the render pass instance, requiring all pipeline
state bound in the render pass instance to match, even if the mismatch is only between
a consistent valid format and unused attachments.

The consequence of this limitation is that the following sequence is invalid:
```c++
vkCmdBeginRendering(); // Only uses color attachment 0, with VK_FORMAT_R8G8B8A8_UNORM
vkCmdBindPipeline(A); // A was created with color attachments 0, 1, 2 with VK_FORMAT_R8G8B8A8_UNORM
vkCmdDraw();
vkCmdBindPipeline(B); // B was created with only color attachment 0 with VK_FORMAT_R8G8B8A8_UNORM
vkCmdDraw();
vkCmdEndRendering();
```

This can cause a combinatorial explosion of pipeline objects, depending on the
application, or require pipeline objects to be generated just-in-time to
be compatible with the active render pass instance.
Alternatively it forces applications to split the render pass instance any time the
framebuffer layout in the pipeline state changes.

The current restrictions require there to be an exact match between the bound pipeline
and the render pass instance attachment formats, including matching unused attachments
with undefined formats.

The VUIDs that contribute to this limitation are:

<dt>[VUID-vkCmdDraw-colorAttachmentCount-07616](https://www.khronos.org/registry/vulkan/specs/1.3/html/vkspec.html#VUID-vkCmdDraw-colorAttachmentCount-07616)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::colorAttachmentCount greater than 0, then each element of the VkRenderingInfo::pColorAttachments array with an imageView equal to VK_NULL_HANDLE must have the corresponding element of VkPipelineRenderingCreateInfo::pColorAttachmentFormats used to create the currently bound pipeline equal to VK_FORMAT_UNDEFINED</dd>

<dt>[VUID-vkCmdDraw-pDepthAttachment-07617](https://www.khronos.org/registry/vulkan/specs/1.3/html/vkspec.html#VUID-vkCmdDraw-pDepthAttachment-07617)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::pDepthAttachment->imageView was VK_NULL_HANDLE, the value of VkPipelineRenderingCreateInfo::depthAttachmentFormat used to create the currently bound graphics pipeline must be equal to VK_FORMAT_UNDEFINED</dd>

<dt>[VUID-vkCmdDraw-pStencilAttachment-07618](https://www.khronos.org/registry/vulkan/specs/1.3/html/vkspec.html#VUID-vkCmdDraw-pStencilAttachment-07618)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::pStencilAttachment->imageView was VK_NULL_HANDLE, the value of VkPipelineRenderingCreateInfo::stencilAttachmentFormat used to create the currently bound graphics pipeline must be equal to VK_FORMAT_UNDEFINED</dd>

<dt>[VUID-vkCmdExecuteCommands-imageView-07606](https://www.khronos.org/registry/vulkan/specs/1.3/html/vkspec.html#VUID-vkCmdExecuteCommands-imageView-07606)</dt>
<dd>If vkCmdExecuteCommands is being called within a render pass instance begun with vkCmdBeginRendering, if the imageView member of an element of the VkRenderingInfo::pColorAttachments parameter to vkCmdBeginRendering is VK_NULL_HANDLE, the corresponding element of the pColorAttachmentFormats member of the VkCommandBufferInheritanceRenderingInfo structure included in the pNext chain of VkCommandBufferBeginInfo::pInheritanceInfo used to begin recording each element of pCommandBuffers must be VK_FORMAT_UNDEFINED</dd>

<dt>[VUID-vkCmdDraw-colorAttachmentCount-06180](https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDraw-colorAttachmentCount-06180)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::colorAttachmentCount greater than 0, then each element of the VkRenderingInfo::pColorAttachments array with an imageView not equal to VK_NULL_HANDLE must have been created with a VkFormat equal to the corresponding element of VkPipelineRenderingCreateInfo::pColorAttachmentFormats used to create the currently bound graphics pipeline</dd>

<dt>[VUID-vkCmdDraw-pDepthAttachment-06181](https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDraw-pDepthAttachment-06181)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::pDepthAttachment->imageView was not VK_NULL_HANDLE, the value of VkPipelineRenderingCreateInfo::depthAttachmentFormat used to create the currently bound graphics pipeline must be equal to the VkFormat used to create VkRenderingInfo::pDepthAttachment->imageView</dd>

<dt>[VUID-vkCmdDraw-pStencilAttachment-06182](https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDraw-pStencilAttachment-06182)</dt>
<dd>If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::pStencilAttachment->imageView was not VK_NULL_HANDLE, the value of VkPipelineRenderingCreateInfo::stencilAttachmentFormat used to create the currently bound graphics pipeline must be equal to the VkFormat used to create VkRenderingInfo::pStencilAttachment->imageView</dd>

DX12 does not have these limitations, which makes implementing DX12 translation on top of Vulkan
with these limitations difficult.

== Solution Space

Since these limitations do not apply to all implementations, we need a simple
extension that lifts these restrictions and allows pipelines to be bound to render
pass instances where the attachment formats may match with the same format or
unused, and where it matches with unused the writes are discarded.

== Proposal

Implementations may expose the `apiext:VK_EXT_dynamic_rendering_unused_attachments` extension
and the slink:VkPhysicalDeviceDynamicRenderingUnusedAttachmentsFeaturesEXT::pname:dynamicRenderingUnusedAttachments
feature which allows apps to bind pipelines to render pass instances where attachment
formats can match with unused attachments.