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");
127 anv_image_make_surface(const struct anv_image_create_info
*create_info
,
128 uint64_t *inout_image_size
,
129 uint32_t *inout_image_alignment
,
130 struct anv_surface
*out_surface
)
132 /* See RENDER_SURFACE_STATE.SurfaceQPitch */
133 static const uint16_t min_qpitch UNUSED
= 0x4;
134 static const uint16_t max_qpitch UNUSED
= 0x1ffc;
136 const VkExtent3D
*restrict extent
= &create_info
->vk_info
->extent
;
137 const uint32_t levels
= create_info
->vk_info
->mipLevels
;
138 const uint32_t array_size
= create_info
->vk_info
->arraySize
;
140 const uint8_t tile_mode
= anv_image_choose_tile_mode(create_info
);
142 const struct anv_tile_info
*tile_info
=
143 &anv_tile_info_table
[tile_mode
];
145 const struct anv_format
*format_info
=
146 anv_format_for_vk_format(create_info
->vk_info
->format
);
148 const uint32_t i
= 4; /* FINISHME: Stop hardcoding subimage alignment */
149 const uint32_t j
= 4; /* FINISHME: Stop hardcoding subimage alignment */
150 const uint32_t w0
= align_u32(extent
->width
, i
);
151 const uint32_t h0
= align_u32(extent
->height
, j
);
157 if (levels
== 1 && array_size
== 1) {
162 uint32_t w1
= align_u32(anv_minify(extent
->width
, 1), i
);
163 uint32_t h1
= align_u32(anv_minify(extent
->height
, 1), j
);
164 uint32_t w2
= align_u32(anv_minify(extent
->width
, 2), i
);
166 qpitch
= h0
+ h1
+ 11 * j
;
167 mt_width
= MAX(w0
, w1
+ w2
);
168 mt_height
= array_size
* qpitch
;
171 assert(qpitch
>= min_qpitch
);
172 if (qpitch
> max_qpitch
) {
173 anv_loge("image qpitch > 0x%x\n", max_qpitch
);
174 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
177 /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch:
179 * This field must be set an integer multiple of the Surface Vertical
182 assert(anv_is_aligned(qpitch
, j
));
184 uint32_t stride
= align_u32(mt_width
* format_info
->cpp
, tile_info
->width
);
185 if (create_info
->stride
> 0)
186 stride
= create_info
->stride
;
188 const uint32_t size
= stride
* align_u32(mt_height
, tile_info
->height
);
189 const uint32_t offset
= align_u32(*inout_image_size
,
190 tile_info
->surface_alignment
);
192 *inout_image_size
= offset
+ size
;
193 *inout_image_alignment
= MAX(*inout_image_alignment
,
194 tile_info
->surface_alignment
);
196 *out_surface
= (struct anv_surface
) {
199 .tile_mode
= tile_mode
,
209 anv_image_create(VkDevice _device
,
210 const struct anv_image_create_info
*create_info
,
213 ANV_FROM_HANDLE(anv_device
, device
, _device
);
214 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
215 const VkExtent3D
*restrict extent
= &pCreateInfo
->extent
;
216 struct anv_image
*image
= NULL
;
219 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
221 /* XXX: We don't handle any of these */
222 anv_assert(pCreateInfo
->imageType
== VK_IMAGE_TYPE_2D
);
223 anv_assert(pCreateInfo
->mipLevels
> 0);
224 anv_assert(pCreateInfo
->arraySize
> 0);
225 anv_assert(pCreateInfo
->samples
== 1);
226 anv_assert(pCreateInfo
->extent
.width
> 0);
227 anv_assert(pCreateInfo
->extent
.height
> 0);
228 anv_assert(pCreateInfo
->extent
.depth
> 0);
230 /* TODO(chadv): How should we validate inputs? */
231 const uint8_t surf_type
=
232 anv_surf_type_from_image_type
[pCreateInfo
->imageType
];
234 const struct anv_surf_type_limits
*limits
=
235 &anv_surf_type_limits
[surf_type
];
237 if (extent
->width
> limits
->width
||
238 extent
->height
> limits
->height
||
239 extent
->depth
> limits
->depth
) {
240 /* TODO(chadv): What is the correct error? */
241 anv_loge("image extent is too large");
242 return vk_error(VK_ERROR_INVALID_MEMORY_SIZE
);
245 image
= anv_device_alloc(device
, sizeof(*image
), 8,
246 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
248 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
250 memset(image
, 0, sizeof(*image
));
251 image
->type
= pCreateInfo
->imageType
;
252 image
->extent
= pCreateInfo
->extent
;
253 image
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
254 image
->levels
= pCreateInfo
->mipLevels
;
255 image
->array_size
= pCreateInfo
->arraySize
;
256 image
->surf_type
= surf_type
;
258 if (likely(!image
->format
->has_stencil
|| image
->format
->depth_format
)) {
259 /* The image's primary surface is a color or depth surface. */
260 r
= anv_image_make_surface(create_info
, &image
->size
, &image
->alignment
,
261 &image
->primary_surface
);
266 if (image
->format
->has_stencil
) {
267 /* From the GPU's perspective, the depth buffer and stencil buffer are
268 * separate buffers. From Vulkan's perspective, though, depth and
269 * stencil reside in the same image. To satisfy Vulkan and the GPU, we
270 * place the depth and stencil buffers in the same bo.
272 VkImageCreateInfo stencil_info
= *pCreateInfo
;
273 stencil_info
.format
= VK_FORMAT_S8_UINT
;
275 r
= anv_image_make_surface(
276 &(struct anv_image_create_info
) {
277 .vk_info
= &stencil_info
,
279 &image
->size
, &image
->alignment
, &image
->stencil_surface
);
285 *pImage
= anv_image_to_handle(image
);
291 anv_device_free(device
, image
);
297 anv_CreateImage(VkDevice device
,
298 const VkImageCreateInfo
*pCreateInfo
,
301 return anv_image_create(device
,
302 &(struct anv_image_create_info
) {
303 .vk_info
= pCreateInfo
,
309 anv_DestroyImage(VkDevice _device
, VkImage _image
)
311 ANV_FROM_HANDLE(anv_device
, device
, _device
);
313 anv_device_free(device
, anv_image_from_handle(_image
));
318 VkResult
anv_GetImageSubresourceLayout(
321 const VkImageSubresource
* pSubresource
,
322 VkSubresourceLayout
* pLayout
)
324 stub_return(VK_UNSUPPORTED
);
328 anv_surface_view_fini(struct anv_device
*device
,
329 struct anv_surface_view
*view
)
331 anv_state_pool_free(&device
->surface_state_pool
, view
->surface_state
);
335 anv_image_view_init(struct anv_image_view
*iview
,
336 struct anv_device
*device
,
337 const VkImageViewCreateInfo
* pCreateInfo
,
338 struct anv_cmd_buffer
*cmd_buffer
)
340 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
342 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
343 struct anv_surface_view
*view
= &iview
->view
;
344 struct anv_surface
*surface
;
346 const struct anv_format
*format_info
=
347 anv_format_for_vk_format(pCreateInfo
->format
);
349 const struct anv_image_view_info
*view_type_info
350 = &anv_image_view_info_table
[pCreateInfo
->viewType
];
352 if (pCreateInfo
->viewType
!= VK_IMAGE_VIEW_TYPE_2D
)
353 anv_finishme("non-2D image views");
355 switch (pCreateInfo
->subresourceRange
.aspect
) {
356 case VK_IMAGE_ASPECT_STENCIL
:
357 anv_finishme("stencil image views");
360 case VK_IMAGE_ASPECT_DEPTH
:
361 case VK_IMAGE_ASPECT_COLOR
:
362 view
->offset
= image
->offset
;
363 surface
= &image
->primary_surface
;
370 view
->bo
= image
->bo
;
371 view
->offset
= image
->offset
+ surface
->offset
;
372 view
->format
= pCreateInfo
->format
;
374 iview
->extent
= (VkExtent3D
) {
375 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
376 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
377 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
381 if (range
->arraySize
> 1) {
382 depth
= range
->arraySize
;
383 } else if (image
->extent
.depth
> 1) {
384 depth
= image
->extent
.depth
;
387 static const uint32_t vk_to_gen_swizzle
[] = {
388 [VK_CHANNEL_SWIZZLE_ZERO
] = SCS_ZERO
,
389 [VK_CHANNEL_SWIZZLE_ONE
] = SCS_ONE
,
390 [VK_CHANNEL_SWIZZLE_R
] = SCS_RED
,
391 [VK_CHANNEL_SWIZZLE_G
] = SCS_GREEN
,
392 [VK_CHANNEL_SWIZZLE_B
] = SCS_BLUE
,
393 [VK_CHANNEL_SWIZZLE_A
] = SCS_ALPHA
396 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
397 .SurfaceType
= view_type_info
->surface_type
,
398 .SurfaceArray
= image
->array_size
> 1,
399 .SurfaceFormat
= format_info
->surface_format
,
400 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
401 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
402 .TileMode
= surface
->tile_mode
,
403 .VerticalLineStride
= 0,
404 .VerticalLineStrideOffset
= 0,
405 .SamplerL2BypassModeDisable
= true,
406 .RenderCacheReadWriteMode
= WriteOnlyCache
,
407 .MemoryObjectControlState
= GEN8_MOCS
,
409 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
410 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
411 * both Base Mip Level fields nonzero".
415 .SurfaceQPitch
= surface
->qpitch
>> 2,
416 .Height
= image
->extent
.height
- 1,
417 .Width
= image
->extent
.width
- 1,
419 .SurfacePitch
= surface
->stride
- 1,
420 .MinimumArrayElement
= range
->baseArraySlice
,
421 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
425 /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
426 * MIPCount. The range of levels accessible by the sampler engine is
427 * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
429 .MIPCountLOD
= range
->mipLevels
- 1,
430 .SurfaceMinLOD
= range
->baseMipLevel
,
432 .AuxiliarySurfaceMode
= AUX_NONE
,
434 .GreenClearColor
= 0,
436 .AlphaClearColor
= 0,
437 .ShaderChannelSelectRed
= vk_to_gen_swizzle
[pCreateInfo
->channels
.r
],
438 .ShaderChannelSelectGreen
= vk_to_gen_swizzle
[pCreateInfo
->channels
.g
],
439 .ShaderChannelSelectBlue
= vk_to_gen_swizzle
[pCreateInfo
->channels
.b
],
440 .ShaderChannelSelectAlpha
= vk_to_gen_swizzle
[pCreateInfo
->channels
.a
],
441 .ResourceMinLOD
= 0.0,
442 .SurfaceBaseAddress
= { NULL
, view
->offset
},
446 view
->surface_state
=
447 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
449 view
->surface_state
=
450 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
453 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
457 anv_validate_CreateImageView(VkDevice _device
,
458 const VkImageViewCreateInfo
*pCreateInfo
,
461 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
462 const VkImageSubresourceRange
*subresource
;
463 const struct anv_image_view_info
*view_info
;
464 const struct anv_format
*view_format_info
;
466 /* Validate structure type before dereferencing it. */
468 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
469 subresource
= &pCreateInfo
->subresourceRange
;
471 /* Validate viewType is in range before using it. */
472 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
473 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
474 view_info
= &anv_image_view_info_table
[pCreateInfo
->viewType
];
476 /* Validate format is in range before using it. */
477 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
478 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
479 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
481 /* Validate channel swizzles. */
482 assert(pCreateInfo
->channels
.r
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
483 assert(pCreateInfo
->channels
.r
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
484 assert(pCreateInfo
->channels
.g
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
485 assert(pCreateInfo
->channels
.g
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
486 assert(pCreateInfo
->channels
.b
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
487 assert(pCreateInfo
->channels
.b
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
488 assert(pCreateInfo
->channels
.a
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
489 assert(pCreateInfo
->channels
.a
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
491 /* Validate subresource. */
492 assert(subresource
->aspect
>= VK_IMAGE_ASPECT_BEGIN_RANGE
);
493 assert(subresource
->aspect
<= VK_IMAGE_ASPECT_END_RANGE
);
494 assert(subresource
->mipLevels
> 0);
495 assert(subresource
->arraySize
> 0);
496 assert(subresource
->baseMipLevel
< image
->levels
);
497 assert(subresource
->baseMipLevel
+ subresource
->mipLevels
<= image
->levels
);
498 assert(subresource
->baseArraySlice
< image
->array_size
);
499 assert(subresource
->baseArraySlice
+ subresource
->arraySize
<= image
->array_size
);
502 if (view_info
->is_cube
) {
503 assert(subresource
->baseArraySlice
% 6 == 0);
504 assert(subresource
->arraySize
% 6 == 0);
507 /* Validate format. */
508 switch (subresource
->aspect
) {
509 case VK_IMAGE_ASPECT_COLOR
:
510 assert(!image
->format
->depth_format
);
511 assert(!image
->format
->has_stencil
);
512 assert(!view_format_info
->depth_format
);
513 assert(!view_format_info
->has_stencil
);
514 assert(view_format_info
->cpp
== image
->format
->cpp
);
516 case VK_IMAGE_ASPECT_DEPTH
:
517 assert(image
->format
->depth_format
);
518 assert(view_format_info
->depth_format
);
519 assert(view_format_info
->cpp
== image
->format
->cpp
);
521 case VK_IMAGE_ASPECT_STENCIL
:
522 /* FINISHME: Is it legal to have an R8 view of S8? */
523 assert(image
->format
->has_stencil
);
524 assert(view_format_info
->has_stencil
);
527 assert(!"bad VkImageAspect");
531 return anv_CreateImageView(_device
, pCreateInfo
, pView
);
535 anv_CreateImageView(VkDevice _device
,
536 const VkImageViewCreateInfo
*pCreateInfo
,
539 ANV_FROM_HANDLE(anv_device
, device
, _device
);
540 struct anv_image_view
*view
;
542 view
= anv_device_alloc(device
, sizeof(*view
), 8,
543 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
545 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
547 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
549 *pView
= anv_image_view_to_handle(view
);
555 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
)
557 ANV_FROM_HANDLE(anv_device
, device
, _device
);
558 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
560 anv_surface_view_fini(device
, &iview
->view
);
561 anv_device_free(device
, iview
);
567 anv_color_attachment_view_init(struct anv_color_attachment_view
*aview
,
568 struct anv_device
*device
,
569 const VkAttachmentViewCreateInfo
* pCreateInfo
,
570 struct anv_cmd_buffer
*cmd_buffer
)
572 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
573 struct anv_surface_view
*view
= &aview
->view
;
574 struct anv_surface
*surface
= &image
->primary_surface
;
575 const struct anv_format
*format_info
=
576 anv_format_for_vk_format(pCreateInfo
->format
);
578 aview
->base
.attachment_type
= ANV_ATTACHMENT_VIEW_TYPE_COLOR
;
580 anv_assert(pCreateInfo
->arraySize
> 0);
581 anv_assert(pCreateInfo
->mipLevel
< image
->levels
);
582 anv_assert(pCreateInfo
->baseArraySlice
+ pCreateInfo
->arraySize
<= image
->array_size
);
584 view
->bo
= image
->bo
;
585 view
->offset
= image
->offset
+ surface
->offset
;
586 view
->format
= pCreateInfo
->format
;
588 aview
->base
.extent
= (VkExtent3D
) {
589 .width
= anv_minify(image
->extent
.width
, pCreateInfo
->mipLevel
),
590 .height
= anv_minify(image
->extent
.height
, pCreateInfo
->mipLevel
),
591 .depth
= anv_minify(image
->extent
.depth
, pCreateInfo
->mipLevel
),
595 if (pCreateInfo
->arraySize
> 1) {
596 depth
= pCreateInfo
->arraySize
;
597 } else if (image
->extent
.depth
> 1) {
598 depth
= image
->extent
.depth
;
602 view
->surface_state
=
603 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
605 view
->surface_state
=
606 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
609 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
610 .SurfaceType
= SURFTYPE_2D
,
611 .SurfaceArray
= image
->array_size
> 1,
612 .SurfaceFormat
= format_info
->surface_format
,
613 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
614 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
615 .TileMode
= surface
->tile_mode
,
616 .VerticalLineStride
= 0,
617 .VerticalLineStrideOffset
= 0,
618 .SamplerL2BypassModeDisable
= true,
619 .RenderCacheReadWriteMode
= WriteOnlyCache
,
620 .MemoryObjectControlState
= GEN8_MOCS
,
622 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
623 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
624 * both Base Mip Level fields nonzero".
628 .SurfaceQPitch
= surface
->qpitch
>> 2,
629 .Height
= image
->extent
.height
- 1,
630 .Width
= image
->extent
.width
- 1,
632 .SurfacePitch
= surface
->stride
- 1,
633 .MinimumArrayElement
= pCreateInfo
->baseArraySlice
,
634 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
638 /* For render target surfaces, the hardware interprets field MIPCount/LOD as
639 * LOD. The Broadwell PRM says:
641 * MIPCountLOD defines the LOD that will be rendered into.
642 * SurfaceMinLOD is ignored.
645 .MIPCountLOD
= pCreateInfo
->mipLevel
,
647 .AuxiliarySurfaceMode
= AUX_NONE
,
649 .GreenClearColor
= 0,
651 .AlphaClearColor
= 0,
652 .ShaderChannelSelectRed
= SCS_RED
,
653 .ShaderChannelSelectGreen
= SCS_GREEN
,
654 .ShaderChannelSelectBlue
= SCS_BLUE
,
655 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
656 .ResourceMinLOD
= 0.0,
657 .SurfaceBaseAddress
= { NULL
, view
->offset
},
660 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
664 anv_depth_stencil_view_init(struct anv_depth_stencil_view
*view
,
665 const VkAttachmentViewCreateInfo
*pCreateInfo
)
667 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
668 struct anv_surface
*depth_surface
= &image
->primary_surface
;
669 struct anv_surface
*stencil_surface
= &image
->stencil_surface
;
671 view
->base
.attachment_type
= ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL
;
673 /* XXX: We don't handle any of these */
674 anv_assert(pCreateInfo
->mipLevel
== 0);
675 anv_assert(pCreateInfo
->baseArraySlice
== 0);
676 anv_assert(pCreateInfo
->arraySize
== 1);
678 view
->bo
= image
->bo
;
680 view
->depth_stride
= depth_surface
->stride
;
681 view
->depth_offset
= image
->offset
+ depth_surface
->offset
;
682 view
->depth_format
= image
->format
->depth_format
;
683 view
->depth_qpitch
= 0; /* FINISHME: QPitch */
685 view
->stencil_stride
= stencil_surface
->stride
;
686 view
->stencil_offset
= image
->offset
+ stencil_surface
->offset
;
687 view
->stencil_qpitch
= 0; /* FINISHME: QPitch */
691 anv_CreateAttachmentView(VkDevice _device
,
692 const VkAttachmentViewCreateInfo
*pCreateInfo
,
693 VkAttachmentView
*pView
)
695 ANV_FROM_HANDLE(anv_device
, device
, _device
);
697 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
);
699 if (anv_is_vk_format_depth_or_stencil(pCreateInfo
->format
)) {
700 struct anv_depth_stencil_view
*view
=
701 anv_device_alloc(device
, sizeof(*view
), 8,
702 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
704 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
706 anv_depth_stencil_view_init(view
, pCreateInfo
);
708 *pView
= anv_attachment_view_to_handle(&view
->base
);
710 struct anv_color_attachment_view
*view
=
711 anv_device_alloc(device
, sizeof(*view
), 8,
712 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
714 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
716 anv_color_attachment_view_init(view
, device
, pCreateInfo
, NULL
);
718 *pView
= anv_attachment_view_to_handle(&view
->base
);
725 anv_DestroyAttachmentView(VkDevice _device
, VkAttachmentView _view
)
727 ANV_FROM_HANDLE(anv_device
, device
, _device
);
728 ANV_FROM_HANDLE(anv_attachment_view
, view
, _view
);
730 if (view
->attachment_type
== ANV_ATTACHMENT_VIEW_TYPE_COLOR
) {
731 struct anv_color_attachment_view
*aview
=
732 (struct anv_color_attachment_view
*)view
;
734 anv_surface_view_fini(device
, &aview
->view
);
737 anv_device_free(device
, view
);