This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0004-anv-patch-shit.patch
executable file
·249 lines (236 loc) · 9.87 KB
/
0004-anv-patch-shit.patch
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
From 70ce634dc6d9c61db8af4dc5cb888b3ef51deef8 Mon Sep 17 00:00:00 2001
From: Sviatoslav Peleshko <[email protected]>
Date: Tue, 7 Jun 2022 18:42:34 +0300
Subject: [PATCH] anv: Improve image/view usage bits verification
This change makes usage bits verification closer to the Vulkan spec.
i.e. VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT does not always require all formats
to support all the requested usage bits.
Also, VK_IMAGE_CREATE_EXTENDED_USAGE_BIT, when combined with
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT can relax the requirements for the
usage supported by the original image format.
v2: Removed strict verification of the format_list_info formats usage
per chadversary's suggestion. Other minor style/comments tweaks.
Signed-off-by: Sviatoslav Peleshko <[email protected]>
---
src/intel/vulkan/anv_formats.c | 166 ++++++++++++++++-----------------
1 file changed, 81 insertions(+), 85 deletions(-)
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index ec9ba0745e61..efd926cda5a5 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -988,6 +988,61 @@ void anv_GetPhysicalDeviceFormatProperties2(
}
}
+static bool anv_format_supports_usage(
+ VkFormatFeatureFlags2KHR format_feature_flags,
+ VkImageUsageFlags usage_flags)
+{
+ if (usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
+ if (!(format_feature_flags & (VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT_KHR |
+ VK_FORMAT_FEATURE_2_BLIT_SRC_BIT_KHR))) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
+ if (!(format_feature_flags & (VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT_KHR |
+ VK_FORMAT_FEATURE_2_BLIT_DST_BIT_KHR))) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_SAMPLED_BIT) {
+ if (!(format_feature_flags & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT_KHR)) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_STORAGE_BIT) {
+ if (!(format_feature_flags & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
+ if (!(format_feature_flags & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT_KHR)) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
+ if (!(format_feature_flags & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT_KHR)) {
+ return false;
+ }
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
+ /* Nothing to check. */
+ }
+
+ if (usage_flags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
+ /* Ignore this flag because it was removed from the
+ * provisional_I_20150910 header.
+ */
+ }
+
+ return true;
+}
+
static VkResult
anv_get_image_format_properties(
struct anv_physical_device *physical_device,
@@ -1019,29 +1074,6 @@ anv_get_image_format_properties(
}
assert(format->vk_format == info->format);
- format_feature_flags = anv_get_image_format_features2(devinfo, info->format,
- format, info->tiling,
- isl_mod_info);
-
- /* Remove the VkFormatFeatureFlags that are incompatible with any declared
- * image view format. (Removals are more likely to occur when a DRM format
- * modifier is present).
- */
- if ((info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) && format_list_info) {
- for (uint32_t i = 0; i < format_list_info->viewFormatCount; ++i) {
- VkFormat vk_view_format = format_list_info->pViewFormats[i];
- const struct anv_format *anv_view_format = anv_get_format(vk_view_format);
- VkFormatFeatureFlags2KHR view_format_features =
- anv_get_image_format_features2(devinfo, vk_view_format,
- anv_view_format,
- info->tiling,
- isl_mod_info);
- format_feature_flags &= view_format_features;
- }
- }
-
- if (!format_feature_flags)
- goto unsupported;
switch (info->type) {
default:
@@ -1083,21 +1115,33 @@ anv_get_image_format_properties(
break;
}
- /* From the Vulkan 1.2.199 spec:
+ /* From the Vulkan 1.3.218 spec:
+ *
+ * "For images created without VK_IMAGE_CREATE_EXTENDED_USAGE_BIT a usage bit
+ * is valid if it is supported for the format the image is created with.
+ * For images created with VK_IMAGE_CREATE_EXTENDED_USAGE_BIT a usage bit
+ * is valid if it is supported for at least one of the formats a VkImageView created
+ * from the image can have."
*
- * "VK_IMAGE_CREATE_EXTENDED_USAGE_BIT specifies that the image can be
- * created with usage flags that are not supported for the format the
- * image is created with but are supported for at least one format a
- * VkImageView created from the image can have."
+ * "VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT specifies that the image can be used
+ * to create a VkImageView with a different format from the image."
*
- * If VK_IMAGE_CREATE_EXTENDED_USAGE_BIT is set, views can be created with
- * different usage than the image so we can't always filter on usage.
+ * So, if both VK_IMAGE_CREATE_EXTENDED_USAGE_BIT and VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT are set,
+ * views can be created with different usage than the image, so we can't always filter on usage.
* There is one exception to this below for storage.
*/
- const VkImageUsageFlags image_usage = info->usage;
- VkImageUsageFlags view_usage = image_usage;
- if (info->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)
- view_usage = 0;
+ format_feature_flags = anv_get_image_format_features2(devinfo, info->format,
+ format, info->tiling,
+ isl_mod_info);
+
+ if (!anv_format_supports_usage(format_feature_flags, info->usage) &&
+ (info->flags & (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)) !=
+ (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)) {
+ /* If image format itself does not support the usage, and we don't allow
+ * the view formats to support it, then we can't support this usage at all.
+ */
+ goto unsupported;
+ }
if (info->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
/* We support modifiers only for "simple" (that is, non-array
@@ -1116,7 +1160,7 @@ anv_get_image_format_properties(
if (isl_mod_info->aux_usage == ISL_AUX_USAGE_CCS_E &&
!anv_formats_ccs_e_compatible(devinfo, info->flags, info->format,
- info->tiling, image_usage,
+ info->tiling, info->usage,
format_list_info)) {
goto unsupported;
}
@@ -1138,32 +1182,12 @@ anv_get_image_format_properties(
(format_feature_flags & (VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT_KHR |
VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT_KHR)) &&
!(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
- !(image_usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
+ !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
isl_format_supports_multisampling(devinfo, format->planes[0].isl_format)) {
sampleCounts = isl_device_get_sample_counts(&physical_device->isl_dev);
}
- if (view_usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
- if (!(format_feature_flags & (VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT_KHR |
- VK_FORMAT_FEATURE_2_BLIT_SRC_BIT_KHR))) {
- goto unsupported;
- }
- }
-
- if (view_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
- if (!(format_feature_flags & (VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT_KHR |
- VK_FORMAT_FEATURE_2_BLIT_DST_BIT_KHR))) {
- goto unsupported;
- }
- }
-
- if (view_usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
- if (!(format_feature_flags & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT_KHR)) {
- goto unsupported;
- }
- }
-
- if (image_usage & VK_IMAGE_USAGE_STORAGE_BIT) {
+ if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
/* Non-power-of-two formats can never be used as storage images. We
* only check plane 0 because there are no YCbCr formats with
* non-power-of-two planes.
@@ -1174,24 +1198,6 @@ anv_get_image_format_properties(
goto unsupported;
}
- if (view_usage & VK_IMAGE_USAGE_STORAGE_BIT) {
- if (!(format_feature_flags & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)) {
- goto unsupported;
- }
- }
-
- if (view_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
- if (!(format_feature_flags & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT_KHR)) {
- goto unsupported;
- }
- }
-
- if (view_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
- if (!(format_feature_flags & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT_KHR)) {
- goto unsupported;
- }
- }
-
if (info->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
/* From the Vulkan 1.2.149 spec, VkImageCreateInfo:
*
@@ -1243,16 +1249,6 @@ anv_get_image_format_properties(
}
}
- if (image_usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
- /* Nothing to check. */
- }
-
- if (image_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
- /* Ignore this flag because it was removed from the
- * provisional_I_20150910 header.
- */
- }
-
/* From the bspec section entitled "Surface Layout and Tiling",
* pre-gfx9 has a 2 GB limitation of the size in bytes,
* gfx9 and gfx10 have a 256 GB limitation and gfx11+
--
GitLab