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