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 struct anv_device
*device
= (struct anv_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
= (VkImage
) 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
,
309 VkResult
anv_GetImageSubresourceLayout(
312 const VkImageSubresource
* pSubresource
,
313 VkSubresourceLayout
* pLayout
)
315 stub_return(VK_UNSUPPORTED
);
319 anv_surface_view_destroy(struct anv_device
*device
,
320 struct anv_object
*obj
, VkObjectType obj_type
)
322 struct anv_surface_view
*view
= (struct anv_surface_view
*)obj
;
324 assert(obj_type
== VK_OBJECT_TYPE_BUFFER_VIEW
||
325 obj_type
== VK_OBJECT_TYPE_IMAGE_VIEW
||
326 obj_type
== VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW
);
328 anv_state_pool_free(&device
->surface_state_pool
, view
->surface_state
);
330 anv_device_free(device
, view
);
334 anv_image_view_init(struct anv_surface_view
*view
,
335 struct anv_device
*device
,
336 const VkImageViewCreateInfo
* pCreateInfo
,
337 struct anv_cmd_buffer
*cmd_buffer
)
339 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
340 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
341 struct anv_surface
*surface
;
343 const struct anv_format
*format_info
=
344 anv_format_for_vk_format(pCreateInfo
->format
);
346 const struct anv_image_view_info
*view_type_info
347 = &anv_image_view_info_table
[pCreateInfo
->viewType
];
349 if (pCreateInfo
->viewType
!= VK_IMAGE_VIEW_TYPE_2D
)
350 anv_finishme("non-2D image views");
352 switch (pCreateInfo
->subresourceRange
.aspect
) {
353 case VK_IMAGE_ASPECT_STENCIL
:
354 anv_finishme("stencil image views");
357 case VK_IMAGE_ASPECT_DEPTH
:
358 case VK_IMAGE_ASPECT_COLOR
:
359 view
->offset
= image
->offset
;
360 surface
= &image
->primary_surface
;
367 view
->bo
= image
->bo
;
368 view
->offset
= image
->offset
+ surface
->offset
;
369 view
->format
= pCreateInfo
->format
;
371 view
->extent
= (VkExtent3D
) {
372 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
373 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
374 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
378 if (range
->arraySize
> 1) {
379 depth
= range
->arraySize
;
380 } else if (image
->extent
.depth
> 1) {
381 depth
= image
->extent
.depth
;
384 static const uint32_t vk_to_gen_swizzle
[] = {
385 [VK_CHANNEL_SWIZZLE_ZERO
] = SCS_ZERO
,
386 [VK_CHANNEL_SWIZZLE_ONE
] = SCS_ONE
,
387 [VK_CHANNEL_SWIZZLE_R
] = SCS_RED
,
388 [VK_CHANNEL_SWIZZLE_G
] = SCS_GREEN
,
389 [VK_CHANNEL_SWIZZLE_B
] = SCS_BLUE
,
390 [VK_CHANNEL_SWIZZLE_A
] = SCS_ALPHA
393 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
394 .SurfaceType
= view_type_info
->surface_type
,
395 .SurfaceArray
= image
->array_size
> 1,
396 .SurfaceFormat
= format_info
->surface_format
,
397 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
398 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
399 .TileMode
= surface
->tile_mode
,
400 .VerticalLineStride
= 0,
401 .VerticalLineStrideOffset
= 0,
402 .SamplerL2BypassModeDisable
= true,
403 .RenderCacheReadWriteMode
= WriteOnlyCache
,
404 .MemoryObjectControlState
= GEN8_MOCS
,
405 .BaseMipLevel
= (float) pCreateInfo
->minLod
,
406 .SurfaceQPitch
= surface
->qpitch
>> 2,
407 .Height
= image
->extent
.height
- 1,
408 .Width
= image
->extent
.width
- 1,
410 .SurfacePitch
= surface
->stride
- 1,
411 .MinimumArrayElement
= range
->baseArraySlice
,
412 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
416 /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
417 * MIPCount. The range of levels accessible by the sampler engine is
418 * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
420 .MIPCountLOD
= range
->mipLevels
- 1,
421 .SurfaceMinLOD
= range
->baseMipLevel
,
423 .AuxiliarySurfaceMode
= AUX_NONE
,
425 .GreenClearColor
= 0,
427 .AlphaClearColor
= 0,
428 .ShaderChannelSelectRed
= vk_to_gen_swizzle
[pCreateInfo
->channels
.r
],
429 .ShaderChannelSelectGreen
= vk_to_gen_swizzle
[pCreateInfo
->channels
.g
],
430 .ShaderChannelSelectBlue
= vk_to_gen_swizzle
[pCreateInfo
->channels
.b
],
431 .ShaderChannelSelectAlpha
= vk_to_gen_swizzle
[pCreateInfo
->channels
.a
],
432 .ResourceMinLOD
= 0.0,
433 .SurfaceBaseAddress
= { NULL
, view
->offset
},
437 view
->surface_state
=
438 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
440 view
->surface_state
=
441 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
443 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
447 anv_validate_CreateImageView(VkDevice _device
,
448 const VkImageViewCreateInfo
*pCreateInfo
,
451 const struct anv_image
*image
;
452 const VkImageSubresourceRange
*subresource
;
453 const struct anv_image_view_info
*view_info
;
454 const struct anv_format
*view_format_info
;
455 const struct anv_format
*image_format_info
;
457 /* Validate structure type before dereferencing it. */
459 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
460 subresource
= &pCreateInfo
->subresourceRange
;
462 /* Validate image pointer before dereferencing it. */
463 assert(pCreateInfo
->image
!= 0);
464 image
= (struct anv_image
*) pCreateInfo
->image
;
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 image_format_info
= anv_format_for_vk_format(image
->format
);
475 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
477 /* Validate channel swizzles. */
478 assert(pCreateInfo
->channels
.r
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
479 assert(pCreateInfo
->channels
.r
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
480 assert(pCreateInfo
->channels
.g
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
481 assert(pCreateInfo
->channels
.g
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
482 assert(pCreateInfo
->channels
.b
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
483 assert(pCreateInfo
->channels
.b
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
484 assert(pCreateInfo
->channels
.a
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
485 assert(pCreateInfo
->channels
.a
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
487 /* Validate subresource. */
488 assert(subresource
->aspect
>= VK_IMAGE_ASPECT_BEGIN_RANGE
);
489 assert(subresource
->aspect
<= VK_IMAGE_ASPECT_END_RANGE
);
490 assert(subresource
->mipLevels
> 0);
491 assert(subresource
->arraySize
> 0);
492 assert(subresource
->baseMipLevel
< image
->levels
);
493 assert(subresource
->baseMipLevel
+ subresource
->mipLevels
<= image
->levels
);
494 assert(subresource
->baseArraySlice
< image
->array_size
);
495 assert(subresource
->baseArraySlice
+ subresource
->arraySize
<= image
->array_size
);
496 assert(pCreateInfo
->minLod
>= 0);
497 assert(pCreateInfo
->minLod
< image
->levels
);
500 if (view_info
->is_cube
) {
501 assert(subresource
->baseArraySlice
% 6 == 0);
502 assert(subresource
->arraySize
% 6 == 0);
505 /* Validate format. */
506 switch (subresource
->aspect
) {
507 case VK_IMAGE_ASPECT_COLOR
:
508 assert(!image_format_info
->depth_format
);
509 assert(!image_format_info
->has_stencil
);
510 assert(!view_format_info
->depth_format
);
511 assert(!view_format_info
->has_stencil
);
512 assert(view_format_info
->cpp
== image_format_info
->cpp
);
514 case VK_IMAGE_ASPECT_DEPTH
:
515 assert(image_format_info
->depth_format
);
516 assert(view_format_info
->depth_format
);
517 assert(view_format_info
->cpp
== image_format_info
->cpp
);
519 case VK_IMAGE_ASPECT_STENCIL
:
520 /* FINISHME: Is it legal to have an R8 view of S8? */
521 assert(image_format_info
->has_stencil
);
522 assert(view_format_info
->has_stencil
);
525 assert(!"bad VkImageAspect");
529 return anv_CreateImageView(_device
, pCreateInfo
, pView
);
533 anv_CreateImageView(VkDevice _device
,
534 const VkImageViewCreateInfo
*pCreateInfo
,
537 struct anv_device
*device
= (struct anv_device
*) _device
;
538 struct anv_surface_view
*view
;
540 view
= anv_device_alloc(device
, sizeof(*view
), 8,
541 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
543 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
545 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
547 view
->base
.destructor
= anv_surface_view_destroy
;
549 *pView
= (VkImageView
) view
;
555 anv_color_attachment_view_init(struct anv_surface_view
*view
,
556 struct anv_device
*device
,
557 const VkColorAttachmentViewCreateInfo
* pCreateInfo
,
558 struct anv_cmd_buffer
*cmd_buffer
)
560 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
561 struct anv_surface
*surface
= &image
->primary_surface
;
562 const struct anv_format
*format_info
=
563 anv_format_for_vk_format(pCreateInfo
->format
);
565 anv_assert(pCreateInfo
->arraySize
> 0);
566 anv_assert(pCreateInfo
->mipLevel
< image
->levels
);
567 anv_assert(pCreateInfo
->baseArraySlice
+ pCreateInfo
->arraySize
<= image
->array_size
);
569 if (pCreateInfo
->msaaResolveImage
)
570 anv_finishme("msaaResolveImage");
572 view
->bo
= image
->bo
;
573 view
->offset
= image
->offset
+ surface
->offset
;
574 view
->format
= pCreateInfo
->format
;
576 view
->extent
= (VkExtent3D
) {
577 .width
= anv_minify(image
->extent
.width
, pCreateInfo
->mipLevel
),
578 .height
= anv_minify(image
->extent
.height
, pCreateInfo
->mipLevel
),
579 .depth
= anv_minify(image
->extent
.depth
, pCreateInfo
->mipLevel
),
583 if (pCreateInfo
->arraySize
> 1) {
584 depth
= pCreateInfo
->arraySize
;
585 } else if (image
->extent
.depth
> 1) {
586 depth
= image
->extent
.depth
;
590 view
->surface_state
=
591 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
593 view
->surface_state
=
594 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
596 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
597 .SurfaceType
= SURFTYPE_2D
,
598 .SurfaceArray
= image
->array_size
> 1,
599 .SurfaceFormat
= format_info
->surface_format
,
600 .SurfaceVerticalAlignment
= anv_valign
[surface
->v_align
],
601 .SurfaceHorizontalAlignment
= anv_halign
[surface
->h_align
],
602 .TileMode
= surface
->tile_mode
,
603 .VerticalLineStride
= 0,
604 .VerticalLineStrideOffset
= 0,
605 .SamplerL2BypassModeDisable
= true,
606 .RenderCacheReadWriteMode
= WriteOnlyCache
,
607 .MemoryObjectControlState
= GEN8_MOCS
,
609 .SurfaceQPitch
= surface
->qpitch
>> 2,
610 .Height
= image
->extent
.height
- 1,
611 .Width
= image
->extent
.width
- 1,
613 .SurfacePitch
= surface
->stride
- 1,
614 .MinimumArrayElement
= pCreateInfo
->baseArraySlice
,
615 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
619 /* For render target surfaces, the hardware interprets field MIPCount/LOD as
620 * LOD. The Broadwell PRM says:
622 * MIPCountLOD defines the LOD that will be rendered into.
623 * SurfaceMinLOD is ignored.
626 .MIPCountLOD
= pCreateInfo
->mipLevel
,
628 .AuxiliarySurfaceMode
= AUX_NONE
,
630 .GreenClearColor
= 0,
632 .AlphaClearColor
= 0,
633 .ShaderChannelSelectRed
= SCS_RED
,
634 .ShaderChannelSelectGreen
= SCS_GREEN
,
635 .ShaderChannelSelectBlue
= SCS_BLUE
,
636 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
637 .ResourceMinLOD
= 0.0,
638 .SurfaceBaseAddress
= { NULL
, view
->offset
},
641 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
645 anv_CreateColorAttachmentView(VkDevice _device
,
646 const VkColorAttachmentViewCreateInfo
*pCreateInfo
,
647 VkColorAttachmentView
*pView
)
649 struct anv_device
*device
= (struct anv_device
*) _device
;
650 struct anv_surface_view
*view
;
652 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO
);
654 view
= anv_device_alloc(device
, sizeof(*view
), 8,
655 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
657 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
659 anv_color_attachment_view_init(view
, device
, pCreateInfo
, NULL
);
661 view
->base
.destructor
= anv_surface_view_destroy
;
663 *pView
= (VkColorAttachmentView
) view
;
669 anv_CreateDepthStencilView(VkDevice _device
,
670 const VkDepthStencilViewCreateInfo
*pCreateInfo
,
671 VkDepthStencilView
*pView
)
673 struct anv_device
*device
= (struct anv_device
*) _device
;
674 struct anv_depth_stencil_view
*view
;
675 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
676 struct anv_surface
*depth_surface
= &image
->primary_surface
;
677 struct anv_surface
*stencil_surface
= &image
->stencil_surface
;
678 const struct anv_format
*format
=
679 anv_format_for_vk_format(image
->format
);
681 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO
);
683 view
= anv_device_alloc(device
, sizeof(*view
), 8,
684 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
686 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
688 /* XXX: We don't handle any of these */
689 anv_assert(pCreateInfo
->mipLevel
== 0);
690 anv_assert(pCreateInfo
->baseArraySlice
== 0);
691 anv_assert(pCreateInfo
->arraySize
== 1);
692 anv_assert(pCreateInfo
->msaaResolveImage
== 0);
694 view
->bo
= image
->bo
;
696 view
->depth_stride
= depth_surface
->stride
;
697 view
->depth_offset
= image
->offset
+ depth_surface
->offset
;
698 view
->depth_format
= format
->depth_format
;
699 view
->depth_qpitch
= 0; /* FINISHME: QPitch */
701 view
->stencil_stride
= stencil_surface
->stride
;
702 view
->stencil_offset
= image
->offset
+ stencil_surface
->offset
;
703 view
->stencil_qpitch
= 0; /* FINISHME: QPitch */
705 *pView
= (VkDepthStencilView
) view
;