anv/image: Stop including gen8_pack.h in common file
[mesa.git] / src / vulkan / anv_image.c
1 /*
2 * Copyright © 2015 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
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "anv_private.h"
31
32 /**
33 * The \a format argument is required and overrides any format found in struct
34 * anv_image_create_info. Exactly one bit must be set in \a aspect.
35 */
36 static isl_surf_usage_flags_t
37 choose_isl_surf_usage(const struct anv_image_create_info *info,
38 VkImageAspectFlags aspect)
39 {
40 const VkImageCreateInfo *vk_info = info->vk_info;
41 isl_surf_usage_flags_t isl_flags = 0;
42
43 /* FINISHME: Support aux surfaces */
44 isl_flags |= ISL_SURF_USAGE_DISABLE_AUX_BIT;
45
46 if (vk_info->usage & VK_IMAGE_USAGE_SAMPLED_BIT)
47 isl_flags |= ISL_SURF_USAGE_TEXTURE_BIT;
48
49 if (vk_info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)
50 isl_flags |= ISL_SURF_USAGE_TEXTURE_BIT;
51
52 if (vk_info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
53 isl_flags |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
54
55 if (vk_info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
56 isl_flags |= ISL_SURF_USAGE_CUBE_BIT;
57
58 if (vk_info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
59 switch (aspect) {
60 default:
61 unreachable("bad VkImageAspect");
62 case VK_IMAGE_ASPECT_DEPTH_BIT:
63 isl_flags |= ISL_SURF_USAGE_DEPTH_BIT;
64 break;
65 case VK_IMAGE_ASPECT_STENCIL_BIT:
66 isl_flags |= ISL_SURF_USAGE_STENCIL_BIT;
67 break;
68 }
69 }
70
71 if (vk_info->usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
72 /* Meta implements transfers by sampling from the source image. */
73 isl_flags |= ISL_SURF_USAGE_TEXTURE_BIT;
74 }
75
76 if (vk_info->usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
77 /* Meta implements transfers by rendering into the destination image. */
78 isl_flags |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
79 }
80
81 return isl_flags;
82 }
83
84 /**
85 * Exactly one bit must be set in \a aspect.
86 */
87 static struct anv_surface *
88 get_surface(struct anv_image *image, VkImageAspectFlags aspect)
89 {
90 switch (aspect) {
91 default:
92 unreachable("bad VkImageAspect");
93 case VK_IMAGE_ASPECT_COLOR_BIT:
94 return &image->color_surface;
95 case VK_IMAGE_ASPECT_DEPTH_BIT:
96 return &image->depth_surface;
97 case VK_IMAGE_ASPECT_STENCIL_BIT:
98 return &image->stencil_surface;
99 }
100 }
101
102 /**
103 * Initialize the anv_image::*_surface selected by \a aspect. Then update the
104 * image's memory requirements (that is, the image's size and alignment).
105 *
106 * Exactly one bit must be set in \a aspect.
107 */
108 static VkResult
109 make_surface(const struct anv_device *dev,
110 struct anv_image *image,
111 const struct anv_image_create_info *anv_info,
112 VkImageAspectFlags aspect)
113 {
114 const VkImageCreateInfo *vk_info = anv_info->vk_info;
115 bool ok UNUSED;
116
117 static const enum isl_surf_dim vk_to_isl_surf_dim[] = {
118 [VK_IMAGE_TYPE_1D] = ISL_SURF_DIM_1D,
119 [VK_IMAGE_TYPE_2D] = ISL_SURF_DIM_2D,
120 [VK_IMAGE_TYPE_3D] = ISL_SURF_DIM_3D,
121 };
122
123 isl_tiling_flags_t tiling_flags = anv_info->isl_tiling_flags;
124 if (vk_info->tiling == VK_IMAGE_TILING_LINEAR)
125 tiling_flags &= ISL_TILING_LINEAR_BIT;
126
127 struct anv_surface *anv_surf = get_surface(image, aspect);
128
129 ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl,
130 .dim = vk_to_isl_surf_dim[vk_info->imageType],
131 .format = anv_get_isl_format(vk_info->format, aspect, vk_info->tiling),
132 .width = vk_info->extent.width,
133 .height = vk_info->extent.height,
134 .depth = vk_info->extent.depth,
135 .levels = vk_info->mipLevels,
136 .array_len = vk_info->arrayLayers,
137 .samples = vk_info->samples,
138 .min_alignment = 0,
139 .min_pitch = 0,
140 .usage = choose_isl_surf_usage(anv_info, aspect),
141 .tiling_flags = tiling_flags);
142
143 /* isl_surf_init() will fail only if provided invalid input. Invalid input
144 * is illegal in Vulkan.
145 */
146 assert(ok);
147
148 anv_surf->offset = align_u32(image->size, anv_surf->isl.alignment);
149 image->size = anv_surf->offset + anv_surf->isl.size;
150 image->alignment = MAX(image->alignment, anv_surf->isl.alignment);
151
152 return VK_SUCCESS;
153 }
154
155 static VkImageUsageFlags
156 anv_image_get_full_usage(const VkImageCreateInfo *info)
157 {
158 VkImageUsageFlags usage = info->usage;
159
160 if (usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
161 /* Meta will transfer from the image by binding it as a texture. */
162 usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
163 }
164
165 if (usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
166 /* Meta will transfer to the image by binding it as a color attachment,
167 * even if the image format is not a color format.
168 */
169 usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
170 }
171
172 return usage;
173 }
174
175 VkResult
176 anv_image_create(VkDevice _device,
177 const struct anv_image_create_info *create_info,
178 const VkAllocationCallbacks* alloc,
179 VkImage *pImage)
180 {
181 ANV_FROM_HANDLE(anv_device, device, _device);
182 const VkImageCreateInfo *pCreateInfo = create_info->vk_info;
183 struct anv_image *image = NULL;
184 VkResult r;
185
186 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
187
188 anv_assert(pCreateInfo->mipLevels > 0);
189 anv_assert(pCreateInfo->arrayLayers > 0);
190 anv_assert(pCreateInfo->samples == VK_SAMPLE_COUNT_1_BIT);
191 anv_assert(pCreateInfo->extent.width > 0);
192 anv_assert(pCreateInfo->extent.height > 0);
193 anv_assert(pCreateInfo->extent.depth > 0);
194
195 image = anv_alloc2(&device->alloc, alloc, sizeof(*image), 8,
196 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
197 if (!image)
198 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
199
200 memset(image, 0, sizeof(*image));
201 image->type = pCreateInfo->imageType;
202 image->extent = pCreateInfo->extent;
203 image->vk_format = pCreateInfo->format;
204 image->format = anv_format_for_vk_format(pCreateInfo->format);
205 image->levels = pCreateInfo->mipLevels;
206 image->array_size = pCreateInfo->arrayLayers;
207 image->usage = anv_image_get_full_usage(pCreateInfo);
208 image->tiling = pCreateInfo->tiling;
209
210 if (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
211 image->needs_nonrt_surface_state = true;
212 }
213
214 if (image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
215 image->needs_color_rt_surface_state = true;
216 }
217
218 if (image->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
219 image->needs_storage_surface_state = true;
220 }
221
222 if (likely(anv_format_is_color(image->format))) {
223 r = make_surface(device, image, create_info,
224 VK_IMAGE_ASPECT_COLOR_BIT);
225 if (r != VK_SUCCESS)
226 goto fail;
227 } else {
228 if (image->format->depth_format) {
229 r = make_surface(device, image, create_info,
230 VK_IMAGE_ASPECT_DEPTH_BIT);
231 if (r != VK_SUCCESS)
232 goto fail;
233 }
234
235 if (image->format->has_stencil) {
236 r = make_surface(device, image, create_info,
237 VK_IMAGE_ASPECT_STENCIL_BIT);
238 if (r != VK_SUCCESS)
239 goto fail;
240 }
241 }
242
243 *pImage = anv_image_to_handle(image);
244
245 return VK_SUCCESS;
246
247 fail:
248 if (image)
249 anv_free2(&device->alloc, alloc, image);
250
251 return r;
252 }
253
254 VkResult
255 anv_CreateImage(VkDevice device,
256 const VkImageCreateInfo *pCreateInfo,
257 const VkAllocationCallbacks *pAllocator,
258 VkImage *pImage)
259 {
260 return anv_image_create(device,
261 &(struct anv_image_create_info) {
262 .vk_info = pCreateInfo,
263 .isl_tiling_flags = ISL_TILING_ANY_MASK,
264 },
265 pAllocator,
266 pImage);
267 }
268
269 void
270 anv_DestroyImage(VkDevice _device, VkImage _image,
271 const VkAllocationCallbacks *pAllocator)
272 {
273 ANV_FROM_HANDLE(anv_device, device, _device);
274
275 anv_free2(&device->alloc, pAllocator, anv_image_from_handle(_image));
276 }
277
278 static void
279 anv_surface_get_subresource_layout(struct anv_image *image,
280 struct anv_surface *surface,
281 const VkImageSubresource *subresource,
282 VkSubresourceLayout *layout)
283 {
284 /* If we are on a non-zero mip level or array slice, we need to
285 * calculate a real offset.
286 */
287 anv_assert(subresource->mipLevel == 0);
288 anv_assert(subresource->arrayLayer == 0);
289
290 layout->offset = surface->offset;
291 layout->rowPitch = surface->isl.row_pitch;
292 layout->depthPitch = isl_surf_get_array_pitch(&surface->isl);
293 layout->arrayPitch = isl_surf_get_array_pitch(&surface->isl);
294 layout->size = surface->isl.size;
295 }
296
297 void anv_GetImageSubresourceLayout(
298 VkDevice device,
299 VkImage _image,
300 const VkImageSubresource* pSubresource,
301 VkSubresourceLayout* pLayout)
302 {
303 ANV_FROM_HANDLE(anv_image, image, _image);
304
305 assert(__builtin_popcount(pSubresource->aspectMask) == 1);
306
307 switch (pSubresource->aspectMask) {
308 case VK_IMAGE_ASPECT_COLOR_BIT:
309 anv_surface_get_subresource_layout(image, &image->color_surface,
310 pSubresource, pLayout);
311 break;
312 case VK_IMAGE_ASPECT_DEPTH_BIT:
313 anv_surface_get_subresource_layout(image, &image->depth_surface,
314 pSubresource, pLayout);
315 break;
316 case VK_IMAGE_ASPECT_STENCIL_BIT:
317 anv_surface_get_subresource_layout(image, &image->stencil_surface,
318 pSubresource, pLayout);
319 break;
320 default:
321 assert(!"Invalid image aspect");
322 }
323 }
324
325 VkResult
326 anv_validate_CreateImageView(VkDevice _device,
327 const VkImageViewCreateInfo *pCreateInfo,
328 const VkAllocationCallbacks *pAllocator,
329 VkImageView *pView)
330 {
331 ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
332 const VkImageSubresourceRange *subresource;
333 const struct anv_format *view_format_info;
334
335 /* Validate structure type before dereferencing it. */
336 assert(pCreateInfo);
337 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
338 subresource = &pCreateInfo->subresourceRange;
339
340 /* Validate viewType is in range before using it. */
341 assert(pCreateInfo->viewType >= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE);
342 assert(pCreateInfo->viewType <= VK_IMAGE_VIEW_TYPE_END_RANGE);
343
344 /* Validate format is in range before using it. */
345 assert(pCreateInfo->format >= VK_FORMAT_BEGIN_RANGE);
346 assert(pCreateInfo->format <= VK_FORMAT_END_RANGE);
347 view_format_info = anv_format_for_vk_format(pCreateInfo->format);
348
349 /* Validate channel swizzles. */
350 assert(pCreateInfo->components.r >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
351 assert(pCreateInfo->components.r <= VK_COMPONENT_SWIZZLE_END_RANGE);
352 assert(pCreateInfo->components.g >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
353 assert(pCreateInfo->components.g <= VK_COMPONENT_SWIZZLE_END_RANGE);
354 assert(pCreateInfo->components.b >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
355 assert(pCreateInfo->components.b <= VK_COMPONENT_SWIZZLE_END_RANGE);
356 assert(pCreateInfo->components.a >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
357 assert(pCreateInfo->components.a <= VK_COMPONENT_SWIZZLE_END_RANGE);
358
359 /* Validate subresource. */
360 assert(subresource->aspectMask != 0);
361 assert(subresource->levelCount > 0);
362 assert(subresource->layerCount > 0);
363 assert(subresource->baseMipLevel < image->levels);
364 assert(subresource->baseMipLevel + subresource->levelCount <= image->levels);
365 assert(subresource->baseArrayLayer < image->array_size);
366 assert(subresource->baseArrayLayer + subresource->layerCount <= image->array_size);
367 assert(pView);
368
369 const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT
370 | VK_IMAGE_ASPECT_STENCIL_BIT;
371
372 /* Validate format. */
373 if (subresource->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
374 assert(subresource->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
375 assert(!image->format->depth_format);
376 assert(!image->format->has_stencil);
377 assert(!view_format_info->depth_format);
378 assert(!view_format_info->has_stencil);
379 assert(view_format_info->isl_layout->bs ==
380 image->format->isl_layout->bs);
381 } else if (subresource->aspectMask & ds_flags) {
382 assert((subresource->aspectMask & ~ds_flags) == 0);
383
384 if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
385 assert(image->format->depth_format);
386 assert(view_format_info->depth_format);
387 assert(view_format_info->isl_layout->bs ==
388 image->format->isl_layout->bs);
389 }
390
391 if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
392 /* FINISHME: Is it legal to have an R8 view of S8? */
393 assert(image->format->has_stencil);
394 assert(view_format_info->has_stencil);
395 }
396 } else {
397 assert(!"bad VkImageSubresourceRange::aspectFlags");
398 }
399
400 return anv_CreateImageView(_device, pCreateInfo, pAllocator, pView);
401 }
402
403 void
404 anv_image_view_init(struct anv_image_view *iview,
405 struct anv_device *device,
406 const VkImageViewCreateInfo* pCreateInfo,
407 struct anv_cmd_buffer *cmd_buffer)
408 {
409 ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
410 const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
411
412 assert(range->layerCount > 0);
413 assert(range->baseMipLevel < image->levels);
414 assert(image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
415 VK_IMAGE_USAGE_STORAGE_BIT |
416 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
417 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT));
418
419 switch (image->type) {
420 default:
421 unreachable("bad VkImageType");
422 case VK_IMAGE_TYPE_1D:
423 case VK_IMAGE_TYPE_2D:
424 assert(range->baseArrayLayer + range->layerCount - 1 <= image->array_size);
425 break;
426 case VK_IMAGE_TYPE_3D:
427 assert(range->baseArrayLayer + range->layerCount - 1
428 <= anv_minify(image->extent.depth, range->baseMipLevel));
429 break;
430 }
431
432 struct anv_surface *surface =
433 anv_image_get_surface_for_aspect_mask(image, range->aspectMask);
434
435 iview->image = image;
436 iview->bo = image->bo;
437 iview->offset = image->offset + surface->offset;
438
439 iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
440 iview->vk_format = pCreateInfo->format;
441 iview->format = anv_get_isl_format(pCreateInfo->format, iview->aspect_mask,
442 image->tiling);
443
444 iview->extent = (VkExtent3D) {
445 .width = anv_minify(image->extent.width, range->baseMipLevel),
446 .height = anv_minify(image->extent.height, range->baseMipLevel),
447 .depth = anv_minify(image->extent.depth, range->baseMipLevel),
448 };
449
450 switch (device->info.gen) {
451 case 7:
452 if (device->info.is_haswell)
453 gen75_image_view_init(iview, device, pCreateInfo, cmd_buffer);
454 else
455 gen7_image_view_init(iview, device, pCreateInfo, cmd_buffer);
456 break;
457 case 8:
458 gen8_image_view_init(iview, device, pCreateInfo, cmd_buffer);
459 break;
460 case 9:
461 gen9_image_view_init(iview, device, pCreateInfo, cmd_buffer);
462 break;
463 default:
464 unreachable("unsupported gen\n");
465 }
466 }
467
468 VkResult
469 anv_CreateImageView(VkDevice _device,
470 const VkImageViewCreateInfo *pCreateInfo,
471 const VkAllocationCallbacks *pAllocator,
472 VkImageView *pView)
473 {
474 ANV_FROM_HANDLE(anv_device, device, _device);
475 struct anv_image_view *view;
476
477 view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
478 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
479 if (view == NULL)
480 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
481
482 anv_image_view_init(view, device, pCreateInfo, NULL);
483
484 *pView = anv_image_view_to_handle(view);
485
486 return VK_SUCCESS;
487 }
488
489 void
490 anv_DestroyImageView(VkDevice _device, VkImageView _iview,
491 const VkAllocationCallbacks *pAllocator)
492 {
493 ANV_FROM_HANDLE(anv_device, device, _device);
494 ANV_FROM_HANDLE(anv_image_view, iview, _iview);
495
496 if (iview->image->needs_color_rt_surface_state) {
497 anv_state_pool_free(&device->surface_state_pool,
498 iview->color_rt_surface_state);
499 }
500
501 if (iview->image->needs_nonrt_surface_state) {
502 anv_state_pool_free(&device->surface_state_pool,
503 iview->nonrt_surface_state);
504 }
505
506 if (iview->image->needs_storage_surface_state) {
507 anv_state_pool_free(&device->surface_state_pool,
508 iview->storage_surface_state);
509 }
510
511 anv_free2(&device->alloc, pAllocator, iview);
512 }
513
514 VkResult
515 anv_CreateBufferView(VkDevice _device,
516 const VkBufferViewCreateInfo *pCreateInfo,
517 const VkAllocationCallbacks *pAllocator,
518 VkBufferView *pView)
519 {
520 ANV_FROM_HANDLE(anv_device, device, _device);
521 ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
522 struct anv_buffer_view *view;
523
524 view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
525 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
526 if (!view)
527 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
528
529 const struct anv_format *format =
530 anv_format_for_vk_format(pCreateInfo->format);
531
532 view->format = format->surface_format;
533 view->bo = buffer->bo;
534 view->offset = buffer->offset + pCreateInfo->offset;
535 view->range = pCreateInfo->range == VK_WHOLE_SIZE ?
536 buffer->size - view->offset : pCreateInfo->range;
537
538 if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
539 view->surface_state =
540 anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
541
542 anv_fill_buffer_surface_state(device, view->surface_state.map,
543 view->format,
544 view->offset, view->range,
545 format->isl_layout->bs);
546 } else {
547 view->surface_state = (struct anv_state){ 0 };
548 }
549
550 if (buffer->usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) {
551 view->storage_surface_state =
552 anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
553
554 enum isl_format storage_format =
555 isl_lower_storage_image_format(&device->isl_dev, view->format);
556
557 anv_fill_buffer_surface_state(device, view->storage_surface_state.map,
558 storage_format,
559 view->offset, view->range,
560 format->isl_layout->bs);
561 } else {
562 view->storage_surface_state = (struct anv_state){ 0 };
563 }
564
565 *pView = anv_buffer_view_to_handle(view);
566
567 return VK_SUCCESS;
568 }
569
570 void
571 anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
572 const VkAllocationCallbacks *pAllocator)
573 {
574 ANV_FROM_HANDLE(anv_device, device, _device);
575 ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
576
577 if (view->surface_state.alloc_size > 0)
578 anv_state_pool_free(&device->surface_state_pool,
579 view->surface_state);
580
581 if (view->storage_surface_state.alloc_size > 0)
582 anv_state_pool_free(&device->surface_state_pool,
583 view->storage_surface_state);
584
585 anv_free2(&device->alloc, pAllocator, view);
586 }
587
588 struct anv_surface *
589 anv_image_get_surface_for_aspect_mask(struct anv_image *image, VkImageAspectFlags aspect_mask)
590 {
591 switch (aspect_mask) {
592 case VK_IMAGE_ASPECT_COLOR_BIT:
593 /* Dragons will eat you.
594 *
595 * Meta attaches all destination surfaces as color render targets. Guess
596 * what surface the Meta Dragons really want.
597 */
598 if (image->format->depth_format && image->format->has_stencil) {
599 anv_finishme("combined depth stencil formats");
600 return &image->depth_surface;
601 } else if (image->format->depth_format) {
602 return &image->depth_surface;
603 } else if (image->format->has_stencil) {
604 return &image->stencil_surface;
605 } else {
606 return &image->color_surface;
607 }
608 break;
609 case VK_IMAGE_ASPECT_DEPTH_BIT:
610 assert(image->format->depth_format);
611 return &image->depth_surface;
612 case VK_IMAGE_ASPECT_STENCIL_BIT:
613 assert(image->format->has_stencil);
614 return &image->stencil_surface;
615 case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT:
616 if (image->format->depth_format && image->format->has_stencil) {
617 /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined
618 * depth stencil formats. Specifically, it states:
619 *
620 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
621 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
622 */
623 anv_finishme("combined depthstencil aspect");
624 return &image->depth_surface;
625 } else if (image->format->depth_format) {
626 return &image->depth_surface;
627 } else if (image->format->has_stencil) {
628 return &image->stencil_surface;
629 }
630 /* fallthrough */
631 default:
632 unreachable("image does not have aspect");
633 return NULL;
634 }
635 }
636
637 void
638 anv_image_view_fill_image_param(struct anv_device *device,
639 struct anv_image_view *view,
640 struct brw_image_param *param)
641 {
642 memset(param, 0, sizeof *param);
643 anv_finishme("Actually fill out brw_image_param");
644 }
645
646 void
647 anv_buffer_view_fill_image_param(struct anv_device *device,
648 struct anv_buffer_view *view,
649 struct brw_image_param *param)
650 {
651 /* Set the swizzling shifts to all-ones to effectively disable swizzling --
652 * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
653 * detailed explanation of these parameters.
654 */
655 param->swizzling[0] = 0xff;
656 param->swizzling[1] = 0xff;
657
658 param->stride[0] = isl_format_layouts[view->format].bs;
659 param->size[0] = view->range / param->stride[0];
660 }