2 * Copyright © 2015 Intel Corporation
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:
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
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
30 #include "anv_private.h"
32 struct anv_image_view_info
{
33 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
34 bool is_array
:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
35 bool is_cube
:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
38 static const uint8_t anv_halign
[] = {
44 static const uint8_t anv_valign
[] = {
50 static const uint8_t anv_surf_type_from_image_type
[] = {
51 [VK_IMAGE_TYPE_1D
] = SURFTYPE_1D
,
52 [VK_IMAGE_TYPE_2D
] = SURFTYPE_2D
,
53 [VK_IMAGE_TYPE_3D
] = SURFTYPE_3D
,
57 static const struct anv_image_view_info
58 anv_image_view_info_table
[] = {
59 #define INFO(s, ...) { .surface_type = s, __VA_ARGS__ }
60 [VK_IMAGE_VIEW_TYPE_1D
] = INFO(SURFTYPE_1D
),
61 [VK_IMAGE_VIEW_TYPE_2D
] = INFO(SURFTYPE_2D
),
62 [VK_IMAGE_VIEW_TYPE_3D
] = INFO(SURFTYPE_3D
),
63 [VK_IMAGE_VIEW_TYPE_CUBE
] = INFO(SURFTYPE_CUBE
, .is_cube
= 1),
64 [VK_IMAGE_VIEW_TYPE_1D_ARRAY
] = INFO(SURFTYPE_1D
, .is_array
= 1),
65 [VK_IMAGE_VIEW_TYPE_2D_ARRAY
] = INFO(SURFTYPE_2D
, .is_array
= 1),
66 [VK_IMAGE_VIEW_TYPE_CUBE_ARRAY
] = INFO(SURFTYPE_CUBE
, .is_array
= 1, .is_cube
= 1),
70 static const struct anv_surf_type_limits
{
74 } anv_surf_type_limits
[] = {
75 [SURFTYPE_1D
] = {16384, 0, 2048},
76 [SURFTYPE_2D
] = {16384, 16384, 2048},
77 [SURFTYPE_3D
] = {2048, 2048, 2048},
78 [SURFTYPE_CUBE
] = {16384, 16384, 340},
79 [SURFTYPE_BUFFER
] = {128, 16384, 64},
80 [SURFTYPE_STRBUF
] = {128, 16384, 64},
83 static const struct anv_tile_info
{
88 * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress.
90 * To simplify calculations, the alignments defined in the table are
91 * sometimes larger than required. For example, Skylake requires that X and
92 * Y tiled buffers be aligned to 4K, but Broadwell permits smaller
93 * alignment. We choose 4K to accomodate both chipsets. The alignment of
94 * a linear buffer depends on its element type and usage. Linear depth
95 * buffers have the largest alignment, 64B, so we choose that for all linear
98 uint32_t surface_alignment
;
99 } anv_tile_info_table
[] = {
100 [LINEAR
] = { 1, 1, 64 },
101 [XMAJOR
] = { 512, 8, 4096 },
102 [YMAJOR
] = { 128, 32, 4096 },
103 [WMAJOR
] = { 128, 32, 4096 },
107 anv_image_choose_tile_mode(const struct anv_image_create_info
*anv_info
)
109 if (anv_info
->force_tile_mode
)
110 return anv_info
->tile_mode
;
112 if (anv_info
->vk_info
->format
== VK_FORMAT_S8_UINT
)
115 switch (anv_info
->vk_info
->tiling
) {
116 case VK_IMAGE_TILING_LINEAR
:
118 case VK_IMAGE_TILING_OPTIMAL
:
121 assert(!"bad VKImageTiling");
128 * The \a format argument is required and overrides any format in
129 * struct anv_image_create_info.
132 anv_image_make_surface(const struct anv_image_create_info
*create_info
,
133 const struct anv_format
*format
,
134 uint64_t *inout_image_size
,
135 uint32_t *inout_image_alignment
,
136 struct anv_surface
*out_surface
)
138 /* See RENDER_SURFACE_STATE.SurfaceQPitch */
139 static const uint16_t min_qpitch UNUSED
= 0x4;
140 static const uint16_t max_qpitch UNUSED
= 0x1ffc;
142 const VkExtent3D
*restrict extent
= &create_info
->vk_info
->extent
;
143 const uint32_t levels
= create_info
->vk_info
->mipLevels
;
144 const uint32_t array_size
= create_info
->vk_info
->arraySize
;
146 const uint8_t tile_mode
= anv_image_choose_tile_mode(create_info
);
148 const struct anv_tile_info
*tile_info
=
149 &anv_tile_info_table
[tile_mode
];
151 const uint32_t i
= 4; /* FINISHME: Stop hardcoding subimage alignment */
152 const uint32_t j
= 4; /* FINISHME: Stop hardcoding subimage alignment */
153 const uint32_t w0
= align_u32(extent
->width
, i
);
154 const uint32_t h0
= align_u32(extent
->height
, j
);
160 if (levels
== 1 && array_size
== 1) {
165 uint32_t w1
= align_u32(anv_minify(extent
->width
, 1), i
);
166 uint32_t h1
= align_u32(anv_minify(extent
->height
, 1), j
);
167 uint32_t w2
= align_u32(anv_minify(extent
->width
, 2), i
);
169 qpitch
= h0
+ h1
+ 11 * j
;
170 mt_width
= MAX(w0
, w1
+ w2
);
171 mt_height
= array_size
* qpitch
;
174 assert(qpitch
>= min_qpitch
);
175 if (qpitch
> max_qpitch
) {
176 anv_loge("image qpitch > 0x%x\n", max_qpitch
);
177 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
180 /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch:
182 * This field must be set an integer multiple of the Surface Vertical
185 assert(anv_is_aligned(qpitch
, j
));
187 uint32_t stride
= align_u32(mt_width
* format
->cpp
, tile_info
->width
);
188 if (create_info
->stride
> 0)
189 stride
= create_info
->stride
;
191 const uint32_t size
= stride
* align_u32(mt_height
, tile_info
->height
);
192 const uint32_t offset
= align_u32(*inout_image_size
,
193 tile_info
->surface_alignment
);
195 *inout_image_size
= offset
+ size
;
196 *inout_image_alignment
= MAX(*inout_image_alignment
,
197 tile_info
->surface_alignment
);
199 *out_surface
= (struct anv_surface
) {
202 .tile_mode
= tile_mode
,
212 anv_image_create(VkDevice _device
,
213 const struct anv_image_create_info
*create_info
,
216 ANV_FROM_HANDLE(anv_device
, device
, _device
);
217 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
218 const VkExtent3D
*restrict extent
= &pCreateInfo
->extent
;
219 struct anv_image
*image
= NULL
;
222 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
224 /* XXX: We don't handle any of these */
225 anv_assert(pCreateInfo
->imageType
== VK_IMAGE_TYPE_2D
);
226 anv_assert(pCreateInfo
->mipLevels
> 0);
227 anv_assert(pCreateInfo
->arraySize
> 0);
228 anv_assert(pCreateInfo
->samples
== 1);
229 anv_assert(pCreateInfo
->extent
.width
> 0);
230 anv_assert(pCreateInfo
->extent
.height
> 0);
231 anv_assert(pCreateInfo
->extent
.depth
> 0);
233 /* TODO(chadv): How should we validate inputs? */
234 const uint8_t surf_type
=
235 anv_surf_type_from_image_type
[pCreateInfo
->imageType
];
237 const struct anv_surf_type_limits
*limits
=
238 &anv_surf_type_limits
[surf_type
];
240 if (extent
->width
> limits
->width
||
241 extent
->height
> limits
->height
||
242 extent
->depth
> limits
->depth
) {
243 /* TODO(chadv): What is the correct error? */
244 anv_loge("image extent is too large");
245 return vk_error(VK_ERROR_INVALID_MEMORY_SIZE
);
248 image
= anv_device_alloc(device
, sizeof(*image
), 8,
249 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
251 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
253 memset(image
, 0, sizeof(*image
));
254 image
->type
= pCreateInfo
->imageType
;
255 image
->extent
= pCreateInfo
->extent
;
256 image
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
257 image
->levels
= pCreateInfo
->mipLevels
;
258 image
->array_size
= pCreateInfo
->arraySize
;
259 image
->surf_type
= surf_type
;
261 if (likely(!image
->format
->has_stencil
|| image
->format
->depth_format
)) {
262 /* The image's primary surface is a color or depth surface. */
263 r
= anv_image_make_surface(create_info
, image
->format
,
264 &image
->size
, &image
->alignment
,
265 &image
->primary_surface
);
270 if (image
->format
->has_stencil
) {
271 /* From the GPU's perspective, the depth buffer and stencil buffer are
272 * separate buffers. From Vulkan's perspective, though, depth and
273 * stencil reside in the same image. To satisfy Vulkan and the GPU, we
274 * place the depth and stencil buffers in the same bo.
276 r
= anv_image_make_surface(create_info
, anv_format_s8_uint
,
277 &image
->size
, &image
->alignment
,
278 &image
->stencil_surface
);
283 *pImage
= anv_image_to_handle(image
);
289 anv_device_free(device
, image
);
295 anv_CreateImage(VkDevice device
,
296 const VkImageCreateInfo
*pCreateInfo
,
299 return anv_image_create(device
,
300 &(struct anv_image_create_info
) {
301 .vk_info
= pCreateInfo
,
307 anv_DestroyImage(VkDevice _device
, VkImage _image
)
309 ANV_FROM_HANDLE(anv_device
, device
, _device
);
311 anv_device_free(device
, anv_image_from_handle(_image
));
316 VkResult
anv_GetImageSubresourceLayout(
319 const VkImageSubresource
* pSubresource
,
320 VkSubresourceLayout
* pLayout
)
322 stub_return(VK_UNSUPPORTED
);
326 anv_surface_view_fini(struct anv_device
*device
,
327 struct anv_surface_view
*view
)
329 anv_state_pool_free(&device
->surface_state_pool
, view
->surface_state
);
333 anv_image_view_init(struct anv_image_view
*iview
,
334 struct anv_device
*device
,
335 const VkImageViewCreateInfo
* pCreateInfo
,
336 struct anv_cmd_buffer
*cmd_buffer
)
338 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
340 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
341 struct anv_surface_view
*view
= &iview
->view
;
342 struct anv_surface
*surface
;
344 const struct anv_image_view_info
*view_type_info
345 = &anv_image_view_info_table
[pCreateInfo
->viewType
];
347 if (pCreateInfo
->viewType
!= VK_IMAGE_VIEW_TYPE_2D
)
348 anv_finishme("non-2D image views");
350 switch (pCreateInfo
->subresourceRange
.aspect
) {
351 case VK_IMAGE_ASPECT_STENCIL
:
352 anv_finishme("stencil image views");
355 case VK_IMAGE_ASPECT_DEPTH
:
356 case VK_IMAGE_ASPECT_COLOR
:
357 view
->offset
= image
->offset
;
358 surface
= &image
->primary_surface
;
365 view
->bo
= image
->bo
;
366 view
->offset
= image
->offset
+ surface
->offset
;
367 view
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
369 iview
->extent
= (VkExtent3D
) {
370 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
371 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
372 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
376 if (range
->arraySize
> 1) {
377 depth
= range
->arraySize
;
378 } else if (image
->extent
.depth
> 1) {
379 depth
= image
->extent
.depth
;
382 static const uint32_t vk_to_gen_swizzle
[] = {
383 [VK_CHANNEL_SWIZZLE_ZERO
] = SCS_ZERO
,
384 [VK_CHANNEL_SWIZZLE_ONE
] = SCS_ONE
,
385 [VK_CHANNEL_SWIZZLE_R
] = SCS_RED
,
386 [VK_CHANNEL_SWIZZLE_G
] = SCS_GREEN
,
387 [VK_CHANNEL_SWIZZLE_B
] = SCS_BLUE
,
388 [VK_CHANNEL_SWIZZLE_A
] = SCS_ALPHA
391 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
392 .SurfaceType
= view_type_info
->surface_type
,
393 .SurfaceArray
= image
->array_size
> 1,
394 .SurfaceFormat
= view
->format
->surface_format
,
395 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
396 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
397 .TileMode
= surface
->tile_mode
,
398 .VerticalLineStride
= 0,
399 .VerticalLineStrideOffset
= 0,
400 .SamplerL2BypassModeDisable
= true,
401 .RenderCacheReadWriteMode
= WriteOnlyCache
,
402 .MemoryObjectControlState
= GEN8_MOCS
,
404 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
405 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
406 * both Base Mip Level fields nonzero".
410 .SurfaceQPitch
= surface
->qpitch
>> 2,
411 .Height
= image
->extent
.height
- 1,
412 .Width
= image
->extent
.width
- 1,
414 .SurfacePitch
= surface
->stride
- 1,
415 .MinimumArrayElement
= range
->baseArraySlice
,
416 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
420 /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
421 * MIPCount. The range of levels accessible by the sampler engine is
422 * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
424 .MIPCountLOD
= range
->mipLevels
- 1,
425 .SurfaceMinLOD
= range
->baseMipLevel
,
427 .AuxiliarySurfaceMode
= AUX_NONE
,
429 .GreenClearColor
= 0,
431 .AlphaClearColor
= 0,
432 .ShaderChannelSelectRed
= vk_to_gen_swizzle
[pCreateInfo
->channels
.r
],
433 .ShaderChannelSelectGreen
= vk_to_gen_swizzle
[pCreateInfo
->channels
.g
],
434 .ShaderChannelSelectBlue
= vk_to_gen_swizzle
[pCreateInfo
->channels
.b
],
435 .ShaderChannelSelectAlpha
= vk_to_gen_swizzle
[pCreateInfo
->channels
.a
],
436 .ResourceMinLOD
= 0.0,
437 .SurfaceBaseAddress
= { NULL
, view
->offset
},
441 view
->surface_state
=
442 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
444 view
->surface_state
=
445 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
448 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
452 anv_validate_CreateImageView(VkDevice _device
,
453 const VkImageViewCreateInfo
*pCreateInfo
,
456 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
457 const VkImageSubresourceRange
*subresource
;
458 const struct anv_image_view_info
*view_info
;
459 const struct anv_format
*view_format_info
;
461 /* Validate structure type before dereferencing it. */
463 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
464 subresource
= &pCreateInfo
->subresourceRange
;
466 /* Validate viewType is in range before using it. */
467 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
468 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
469 view_info
= &anv_image_view_info_table
[pCreateInfo
->viewType
];
471 /* Validate format is in range before using it. */
472 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
473 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
474 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
476 /* Validate channel swizzles. */
477 assert(pCreateInfo
->channels
.r
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
478 assert(pCreateInfo
->channels
.r
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
479 assert(pCreateInfo
->channels
.g
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
480 assert(pCreateInfo
->channels
.g
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
481 assert(pCreateInfo
->channels
.b
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
482 assert(pCreateInfo
->channels
.b
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
483 assert(pCreateInfo
->channels
.a
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
484 assert(pCreateInfo
->channels
.a
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
486 /* Validate subresource. */
487 assert(subresource
->aspect
>= VK_IMAGE_ASPECT_BEGIN_RANGE
);
488 assert(subresource
->aspect
<= VK_IMAGE_ASPECT_END_RANGE
);
489 assert(subresource
->mipLevels
> 0);
490 assert(subresource
->arraySize
> 0);
491 assert(subresource
->baseMipLevel
< image
->levels
);
492 assert(subresource
->baseMipLevel
+ subresource
->mipLevels
<= image
->levels
);
493 assert(subresource
->baseArraySlice
< image
->array_size
);
494 assert(subresource
->baseArraySlice
+ subresource
->arraySize
<= image
->array_size
);
497 if (view_info
->is_cube
) {
498 assert(subresource
->baseArraySlice
% 6 == 0);
499 assert(subresource
->arraySize
% 6 == 0);
502 /* Validate format. */
503 switch (subresource
->aspect
) {
504 case VK_IMAGE_ASPECT_COLOR
:
505 assert(!image
->format
->depth_format
);
506 assert(!image
->format
->has_stencil
);
507 assert(!view_format_info
->depth_format
);
508 assert(!view_format_info
->has_stencil
);
509 assert(view_format_info
->cpp
== image
->format
->cpp
);
511 case VK_IMAGE_ASPECT_DEPTH
:
512 assert(image
->format
->depth_format
);
513 assert(view_format_info
->depth_format
);
514 assert(view_format_info
->cpp
== image
->format
->cpp
);
516 case VK_IMAGE_ASPECT_STENCIL
:
517 /* FINISHME: Is it legal to have an R8 view of S8? */
518 assert(image
->format
->has_stencil
);
519 assert(view_format_info
->has_stencil
);
522 assert(!"bad VkImageAspect");
526 return anv_CreateImageView(_device
, pCreateInfo
, pView
);
530 anv_CreateImageView(VkDevice _device
,
531 const VkImageViewCreateInfo
*pCreateInfo
,
534 ANV_FROM_HANDLE(anv_device
, device
, _device
);
535 struct anv_image_view
*view
;
537 view
= anv_device_alloc(device
, sizeof(*view
), 8,
538 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
540 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
542 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
544 *pView
= anv_image_view_to_handle(view
);
550 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
)
552 ANV_FROM_HANDLE(anv_device
, device
, _device
);
553 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
555 anv_surface_view_fini(device
, &iview
->view
);
556 anv_device_free(device
, iview
);
562 anv_color_attachment_view_init(struct anv_color_attachment_view
*aview
,
563 struct anv_device
*device
,
564 const VkAttachmentViewCreateInfo
* pCreateInfo
,
565 struct anv_cmd_buffer
*cmd_buffer
)
567 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
568 struct anv_surface_view
*view
= &aview
->view
;
569 struct anv_surface
*surface
= &image
->primary_surface
;
571 aview
->base
.attachment_type
= ANV_ATTACHMENT_VIEW_TYPE_COLOR
;
573 anv_assert(pCreateInfo
->arraySize
> 0);
574 anv_assert(pCreateInfo
->mipLevel
< image
->levels
);
575 anv_assert(pCreateInfo
->baseArraySlice
+ pCreateInfo
->arraySize
<= image
->array_size
);
577 view
->bo
= image
->bo
;
578 view
->offset
= image
->offset
+ surface
->offset
;
579 view
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
581 aview
->base
.extent
= (VkExtent3D
) {
582 .width
= anv_minify(image
->extent
.width
, pCreateInfo
->mipLevel
),
583 .height
= anv_minify(image
->extent
.height
, pCreateInfo
->mipLevel
),
584 .depth
= anv_minify(image
->extent
.depth
, pCreateInfo
->mipLevel
),
588 if (pCreateInfo
->arraySize
> 1) {
589 depth
= pCreateInfo
->arraySize
;
590 } else if (image
->extent
.depth
> 1) {
591 depth
= image
->extent
.depth
;
595 view
->surface_state
=
596 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
598 view
->surface_state
=
599 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
602 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
603 .SurfaceType
= SURFTYPE_2D
,
604 .SurfaceArray
= image
->array_size
> 1,
605 .SurfaceFormat
= view
->format
->surface_format
,
606 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
607 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
608 .TileMode
= surface
->tile_mode
,
609 .VerticalLineStride
= 0,
610 .VerticalLineStrideOffset
= 0,
611 .SamplerL2BypassModeDisable
= true,
612 .RenderCacheReadWriteMode
= WriteOnlyCache
,
613 .MemoryObjectControlState
= GEN8_MOCS
,
615 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
616 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
617 * both Base Mip Level fields nonzero".
621 .SurfaceQPitch
= surface
->qpitch
>> 2,
622 .Height
= image
->extent
.height
- 1,
623 .Width
= image
->extent
.width
- 1,
625 .SurfacePitch
= surface
->stride
- 1,
626 .MinimumArrayElement
= pCreateInfo
->baseArraySlice
,
627 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
631 /* For render target surfaces, the hardware interprets field MIPCount/LOD as
632 * LOD. The Broadwell PRM says:
634 * MIPCountLOD defines the LOD that will be rendered into.
635 * SurfaceMinLOD is ignored.
638 .MIPCountLOD
= pCreateInfo
->mipLevel
,
640 .AuxiliarySurfaceMode
= AUX_NONE
,
642 .GreenClearColor
= 0,
644 .AlphaClearColor
= 0,
645 .ShaderChannelSelectRed
= SCS_RED
,
646 .ShaderChannelSelectGreen
= SCS_GREEN
,
647 .ShaderChannelSelectBlue
= SCS_BLUE
,
648 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
649 .ResourceMinLOD
= 0.0,
650 .SurfaceBaseAddress
= { NULL
, view
->offset
},
653 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
657 anv_depth_stencil_view_init(struct anv_depth_stencil_view
*view
,
658 const VkAttachmentViewCreateInfo
*pCreateInfo
)
660 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
661 struct anv_surface
*depth_surface
= &image
->primary_surface
;
662 struct anv_surface
*stencil_surface
= &image
->stencil_surface
;
664 view
->base
.attachment_type
= ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL
;
666 /* XXX: We don't handle any of these */
667 anv_assert(pCreateInfo
->mipLevel
== 0);
668 anv_assert(pCreateInfo
->baseArraySlice
== 0);
669 anv_assert(pCreateInfo
->arraySize
== 1);
671 view
->bo
= image
->bo
;
673 view
->depth_stride
= depth_surface
->stride
;
674 view
->depth_offset
= image
->offset
+ depth_surface
->offset
;
675 view
->depth_format
= image
->format
->depth_format
;
676 view
->depth_qpitch
= 0; /* FINISHME: QPitch */
678 view
->stencil_stride
= stencil_surface
->stride
;
679 view
->stencil_offset
= image
->offset
+ stencil_surface
->offset
;
680 view
->stencil_qpitch
= 0; /* FINISHME: QPitch */
684 anv_CreateAttachmentView(VkDevice _device
,
685 const VkAttachmentViewCreateInfo
*pCreateInfo
,
686 VkAttachmentView
*pView
)
688 ANV_FROM_HANDLE(anv_device
, device
, _device
);
690 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
);
692 const struct anv_format
*format
=
693 anv_format_for_vk_format(pCreateInfo
->format
);
695 if (anv_format_is_depth_or_stencil(format
)) {
696 struct anv_depth_stencil_view
*view
=
697 anv_device_alloc(device
, sizeof(*view
), 8,
698 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
700 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
702 anv_depth_stencil_view_init(view
, pCreateInfo
);
704 *pView
= anv_attachment_view_to_handle(&view
->base
);
706 struct anv_color_attachment_view
*view
=
707 anv_device_alloc(device
, sizeof(*view
), 8,
708 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
710 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
712 anv_color_attachment_view_init(view
, device
, pCreateInfo
, NULL
);
714 *pView
= anv_attachment_view_to_handle(&view
->base
);
721 anv_DestroyAttachmentView(VkDevice _device
, VkAttachmentView _view
)
723 ANV_FROM_HANDLE(anv_device
, device
, _device
);
724 ANV_FROM_HANDLE(anv_attachment_view
, view
, _view
);
726 if (view
->attachment_type
== ANV_ATTACHMENT_VIEW_TYPE_COLOR
) {
727 struct anv_color_attachment_view
*aview
=
728 (struct anv_color_attachment_view
*)view
;
730 anv_surface_view_fini(device
, &aview
->view
);
733 anv_device_free(device
, view
);