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
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 const uint32_t stride
= align_u32(mt_width
* format_info
->cpp
,
186 const uint32_t size
= stride
* align_u32(mt_height
, tile_info
->height
);
187 const uint32_t offset
= align_u32(*inout_image_size
,
188 tile_info
->surface_alignment
);
190 *inout_image_size
= offset
+ size
;
191 *inout_image_alignment
= MAX(*inout_image_alignment
,
192 tile_info
->surface_alignment
);
194 *out_surface
= (struct anv_surface
) {
197 .tile_mode
= tile_mode
,
207 anv_image_create(VkDevice _device
,
208 const struct anv_image_create_info
*create_info
,
211 ANV_FROM_HANDLE(anv_device
, device
, _device
);
212 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
213 const VkExtent3D
*restrict extent
= &pCreateInfo
->extent
;
214 struct anv_image
*image
= NULL
;
217 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
219 /* XXX: We don't handle any of these */
220 anv_assert(pCreateInfo
->imageType
== VK_IMAGE_TYPE_2D
);
221 anv_assert(pCreateInfo
->mipLevels
> 0);
222 anv_assert(pCreateInfo
->arraySize
> 0);
223 anv_assert(pCreateInfo
->samples
== 1);
224 anv_assert(pCreateInfo
->extent
.width
> 0);
225 anv_assert(pCreateInfo
->extent
.height
> 0);
226 anv_assert(pCreateInfo
->extent
.depth
> 0);
228 /* TODO(chadv): How should we validate inputs? */
229 const uint8_t surf_type
=
230 anv_surf_type_from_image_type
[pCreateInfo
->imageType
];
232 const struct anv_surf_type_limits
*limits
=
233 &anv_surf_type_limits
[surf_type
];
235 if (extent
->width
> limits
->width
||
236 extent
->height
> limits
->height
||
237 extent
->depth
> limits
->depth
) {
238 /* TODO(chadv): What is the correct error? */
239 anv_loge("image extent is too large");
240 return vk_error(VK_ERROR_INVALID_MEMORY_SIZE
);
243 const struct anv_format
*format_info
=
244 anv_format_for_vk_format(pCreateInfo
->format
);
246 image
= anv_device_alloc(device
, sizeof(*image
), 8,
247 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
249 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
251 memset(image
, 0, sizeof(*image
));
252 image
->type
= pCreateInfo
->imageType
;
253 image
->extent
= pCreateInfo
->extent
;
254 image
->format
= pCreateInfo
->format
;
255 image
->levels
= pCreateInfo
->mipLevels
;
256 image
->array_size
= pCreateInfo
->arraySize
;
257 image
->surf_type
= surf_type
;
259 if (likely(!format_info
->has_stencil
|| format_info
->depth_format
)) {
260 /* The image's primary surface is a color or depth surface. */
261 r
= anv_image_make_surface(create_info
, &image
->size
, &image
->alignment
,
262 &image
->primary_surface
);
267 if (format_info
->has_stencil
) {
268 /* From the GPU's perspective, the depth buffer and stencil buffer are
269 * separate buffers. From Vulkan's perspective, though, depth and
270 * stencil reside in the same image. To satisfy Vulkan and the GPU, we
271 * place the depth and stencil buffers in the same bo.
273 VkImageCreateInfo stencil_info
= *pCreateInfo
;
274 stencil_info
.format
= VK_FORMAT_S8_UINT
;
276 r
= anv_image_make_surface(
277 &(struct anv_image_create_info
) {
278 .vk_info
= &stencil_info
,
280 &image
->size
, &image
->alignment
, &image
->stencil_surface
);
286 *pImage
= anv_image_to_handle(image
);
292 anv_device_free(device
, image
);
298 anv_CreateImage(VkDevice device
,
299 const VkImageCreateInfo
*pCreateInfo
,
302 return anv_image_create(device
,
303 &(struct anv_image_create_info
) {
304 .vk_info
= pCreateInfo
,
310 anv_DestroyImage(VkDevice _device
, VkImage _image
)
312 ANV_FROM_HANDLE(anv_device
, device
, _device
);
314 anv_device_free(device
, anv_image_from_handle(_image
));
319 VkResult
anv_GetImageSubresourceLayout(
322 const VkImageSubresource
* pSubresource
,
323 VkSubresourceLayout
* pLayout
)
325 stub_return(VK_UNSUPPORTED
);
329 anv_surface_view_fini(struct anv_device
*device
,
330 struct anv_surface_view
*view
)
332 anv_state_pool_free(&device
->surface_state_pool
, view
->surface_state
);
336 anv_image_view_init(struct anv_surface_view
*view
,
337 struct anv_device
*device
,
338 const VkImageViewCreateInfo
* pCreateInfo
,
339 struct anv_cmd_buffer
*cmd_buffer
)
341 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
342 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
343 struct anv_surface
*surface
;
345 const struct anv_format
*format_info
=
346 anv_format_for_vk_format(pCreateInfo
->format
);
348 const struct anv_image_view_info
*view_type_info
349 = &anv_image_view_info_table
[pCreateInfo
->viewType
];
351 if (pCreateInfo
->viewType
!= VK_IMAGE_VIEW_TYPE_2D
)
352 anv_finishme("non-2D image views");
354 switch (pCreateInfo
->subresourceRange
.aspect
) {
355 case VK_IMAGE_ASPECT_STENCIL
:
356 anv_finishme("stencil image views");
359 case VK_IMAGE_ASPECT_DEPTH
:
360 case VK_IMAGE_ASPECT_COLOR
:
361 view
->offset
= image
->offset
;
362 surface
= &image
->primary_surface
;
369 view
->bo
= image
->bo
;
370 view
->offset
= image
->offset
+ surface
->offset
;
371 view
->format
= pCreateInfo
->format
;
373 view
->extent
= (VkExtent3D
) {
374 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
375 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
376 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
380 if (range
->arraySize
> 1) {
381 depth
= range
->arraySize
;
382 } else if (image
->extent
.depth
> 1) {
383 depth
= image
->extent
.depth
;
386 static const uint32_t vk_to_gen_swizzle
[] = {
387 [VK_CHANNEL_SWIZZLE_ZERO
] = SCS_ZERO
,
388 [VK_CHANNEL_SWIZZLE_ONE
] = SCS_ONE
,
389 [VK_CHANNEL_SWIZZLE_R
] = SCS_RED
,
390 [VK_CHANNEL_SWIZZLE_G
] = SCS_GREEN
,
391 [VK_CHANNEL_SWIZZLE_B
] = SCS_BLUE
,
392 [VK_CHANNEL_SWIZZLE_A
] = SCS_ALPHA
395 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
396 .SurfaceType
= view_type_info
->surface_type
,
397 .SurfaceArray
= image
->array_size
> 1,
398 .SurfaceFormat
= format_info
->surface_format
,
399 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
400 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
401 .TileMode
= surface
->tile_mode
,
402 .VerticalLineStride
= 0,
403 .VerticalLineStrideOffset
= 0,
404 .SamplerL2BypassModeDisable
= true,
405 .RenderCacheReadWriteMode
= WriteOnlyCache
,
406 .MemoryObjectControlState
= GEN8_MOCS
,
408 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
409 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
410 * both Base Mip Level fields nonzero".
414 .SurfaceQPitch
= surface
->qpitch
>> 2,
415 .Height
= image
->extent
.height
- 1,
416 .Width
= image
->extent
.width
- 1,
418 .SurfacePitch
= surface
->stride
- 1,
419 .MinimumArrayElement
= range
->baseArraySlice
,
420 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
424 /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
425 * MIPCount. The range of levels accessible by the sampler engine is
426 * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
428 .MIPCountLOD
= range
->mipLevels
- 1,
429 .SurfaceMinLOD
= range
->baseMipLevel
,
431 .AuxiliarySurfaceMode
= AUX_NONE
,
433 .GreenClearColor
= 0,
435 .AlphaClearColor
= 0,
436 .ShaderChannelSelectRed
= vk_to_gen_swizzle
[pCreateInfo
->channels
.r
],
437 .ShaderChannelSelectGreen
= vk_to_gen_swizzle
[pCreateInfo
->channels
.g
],
438 .ShaderChannelSelectBlue
= vk_to_gen_swizzle
[pCreateInfo
->channels
.b
],
439 .ShaderChannelSelectAlpha
= vk_to_gen_swizzle
[pCreateInfo
->channels
.a
],
440 .ResourceMinLOD
= 0.0,
441 .SurfaceBaseAddress
= { NULL
, view
->offset
},
445 view
->surface_state
=
446 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
448 view
->surface_state
=
449 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
451 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
455 anv_validate_CreateImageView(VkDevice _device
,
456 const VkImageViewCreateInfo
*pCreateInfo
,
459 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
460 const VkImageSubresourceRange
*subresource
;
461 const struct anv_image_view_info
*view_info
;
462 const struct anv_format
*view_format_info
;
463 const struct anv_format
*image_format_info
;
465 /* Validate structure type before dereferencing it. */
467 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
468 subresource
= &pCreateInfo
->subresourceRange
;
470 /* Validate viewType is in range before using it. */
471 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
472 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
473 view_info
= &anv_image_view_info_table
[pCreateInfo
->viewType
];
475 /* Validate format is in range before using it. */
476 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
477 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
478 image_format_info
= anv_format_for_vk_format(image
->format
);
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_info
->depth_format
);
511 assert(!image_format_info
->has_stencil
);
512 assert(!view_format_info
->depth_format
);
513 assert(!view_format_info
->has_stencil
);
514 assert(view_format_info
->cpp
== image_format_info
->cpp
);
516 case VK_IMAGE_ASPECT_DEPTH
:
517 assert(image_format_info
->depth_format
);
518 assert(view_format_info
->depth_format
);
519 assert(view_format_info
->cpp
== image_format_info
->cpp
);
521 case VK_IMAGE_ASPECT_STENCIL
:
522 /* FINISHME: Is it legal to have an R8 view of S8? */
523 assert(image_format_info
->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_surface_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
= (VkImageView
) view
;
555 anv_DestroyImageView(VkDevice _device
, VkImageView _view
)
557 ANV_FROM_HANDLE(anv_device
, device
, _device
);
558 struct anv_surface_view
*view
= (struct anv_surface_view
*)_view
;
560 anv_surface_view_fini(device
, view
);
561 anv_device_free(device
, view
);
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 view
->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);
608 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
609 .SurfaceType
= SURFTYPE_2D
,
610 .SurfaceArray
= image
->array_size
> 1,
611 .SurfaceFormat
= format_info
->surface_format
,
612 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
613 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
614 .TileMode
= surface
->tile_mode
,
615 .VerticalLineStride
= 0,
616 .VerticalLineStrideOffset
= 0,
617 .SamplerL2BypassModeDisable
= true,
618 .RenderCacheReadWriteMode
= WriteOnlyCache
,
619 .MemoryObjectControlState
= GEN8_MOCS
,
621 /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
622 * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
623 * both Base Mip Level fields nonzero".
627 .SurfaceQPitch
= surface
->qpitch
>> 2,
628 .Height
= image
->extent
.height
- 1,
629 .Width
= image
->extent
.width
- 1,
631 .SurfacePitch
= surface
->stride
- 1,
632 .MinimumArrayElement
= pCreateInfo
->baseArraySlice
,
633 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
637 /* For render target surfaces, the hardware interprets field MIPCount/LOD as
638 * LOD. The Broadwell PRM says:
640 * MIPCountLOD defines the LOD that will be rendered into.
641 * SurfaceMinLOD is ignored.
644 .MIPCountLOD
= pCreateInfo
->mipLevel
,
646 .AuxiliarySurfaceMode
= AUX_NONE
,
648 .GreenClearColor
= 0,
650 .AlphaClearColor
= 0,
651 .ShaderChannelSelectRed
= SCS_RED
,
652 .ShaderChannelSelectGreen
= SCS_GREEN
,
653 .ShaderChannelSelectBlue
= SCS_BLUE
,
654 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
655 .ResourceMinLOD
= 0.0,
656 .SurfaceBaseAddress
= { NULL
, view
->offset
},
659 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
663 anv_depth_stencil_view_init(struct anv_depth_stencil_view
*view
,
664 const VkAttachmentViewCreateInfo
*pCreateInfo
)
666 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
667 struct anv_surface
*depth_surface
= &image
->primary_surface
;
668 struct anv_surface
*stencil_surface
= &image
->stencil_surface
;
669 const struct anv_format
*format
=
670 anv_format_for_vk_format(image
->format
);
672 view
->base
.attachment_type
= ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL
;
674 /* XXX: We don't handle any of these */
675 anv_assert(pCreateInfo
->mipLevel
== 0);
676 anv_assert(pCreateInfo
->baseArraySlice
== 0);
677 anv_assert(pCreateInfo
->arraySize
== 1);
679 view
->bo
= image
->bo
;
681 view
->depth_stride
= depth_surface
->stride
;
682 view
->depth_offset
= image
->offset
+ depth_surface
->offset
;
683 view
->depth_format
= format
->depth_format
;
684 view
->depth_qpitch
= 0; /* FINISHME: QPitch */
686 view
->stencil_stride
= stencil_surface
->stride
;
687 view
->stencil_offset
= image
->offset
+ stencil_surface
->offset
;
688 view
->stencil_qpitch
= 0; /* FINISHME: QPitch */
692 anv_CreateAttachmentView(VkDevice _device
,
693 const VkAttachmentViewCreateInfo
*pCreateInfo
,
694 VkAttachmentView
*pView
)
696 ANV_FROM_HANDLE(anv_device
, device
, _device
);
698 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
);
700 if (anv_is_vk_format_depth_or_stencil(pCreateInfo
->format
)) {
701 struct anv_depth_stencil_view
*view
=
702 anv_device_alloc(device
, sizeof(*view
), 8,
703 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
705 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
707 anv_depth_stencil_view_init(view
, pCreateInfo
);
709 *pView
= anv_attachment_view_to_handle(&view
->base
);
711 struct anv_color_attachment_view
*view
=
712 anv_device_alloc(device
, sizeof(*view
), 8,
713 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
715 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
717 anv_color_attachment_view_init(view
, device
, pCreateInfo
, NULL
);
719 *pView
= anv_attachment_view_to_handle(&view
->base
);
726 anv_DestroyAttachmentView(VkDevice _device
, VkAttachmentView _view
)
728 ANV_FROM_HANDLE(anv_device
, device
, _device
);
729 ANV_FROM_HANDLE(anv_attachment_view
, view
, _view
);
731 if (view
->attachment_type
== ANV_ATTACHMENT_VIEW_TYPE_COLOR
) {
732 struct anv_color_attachment_view
*aview
=
733 (struct anv_color_attachment_view
*)view
;
735 anv_surface_view_fini(device
, &aview
->view
);
738 anv_device_free(device
, view
);