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
34 static const struct anv_tile_mode_info
{
37 } tile_mode_info
[] = {
39 [XMAJOR
] = { 512, 8 },
40 [YMAJOR
] = { 128, 32 },
41 [WMAJOR
] = { 128, 32 }
44 VkResult
anv_image_create(
46 const VkImageCreateInfo
* pCreateInfo
,
47 const struct anv_image_create_info
* extra
,
50 struct anv_device
*device
= (struct anv_device
*) _device
;
51 struct anv_image
*image
;
52 const struct anv_format
*info
;
53 int32_t aligned_height
;
54 uint32_t stencil_size
;
56 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
58 image
= anv_device_alloc(device
, sizeof(*image
), 8,
59 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
61 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
65 image
->type
= pCreateInfo
->imageType
;
66 image
->format
= pCreateInfo
->format
;
67 image
->extent
= pCreateInfo
->extent
;
68 image
->swap_chain
= NULL
;
70 assert(image
->extent
.width
> 0);
71 assert(image
->extent
.height
> 0);
72 assert(image
->extent
.depth
> 0);
74 switch (pCreateInfo
->tiling
) {
75 case VK_IMAGE_TILING_LINEAR
:
76 image
->tile_mode
= LINEAR
;
78 case VK_IMAGE_TILING_OPTIMAL
:
79 image
->tile_mode
= YMAJOR
;
82 assert(!"bad VKImageTiling");
87 image
->tile_mode
= extra
->tile_mode
;
89 if (image
->tile_mode
== LINEAR
) {
90 /* Linear depth buffers must be 64 byte aligned, which is the strictest
91 * requirement for all kinds of linear surfaces.
93 image
->alignment
= 64;
95 image
->alignment
= 4096;
98 info
= anv_format_for_vk_format(pCreateInfo
->format
);
99 assert(info
->cpp
> 0 || info
->has_stencil
);
102 image
->stride
= ALIGN_I32(image
->extent
.width
* info
->cpp
,
103 tile_mode_info
[image
->tile_mode
].tile_width
);
104 aligned_height
= ALIGN_I32(image
->extent
.height
,
105 tile_mode_info
[image
->tile_mode
].tile_height
);
106 image
->size
= image
->stride
* aligned_height
;
112 if (info
->has_stencil
) {
113 image
->stencil_offset
= ALIGN_U32(image
->size
, 4096);
114 image
->stencil_stride
= ALIGN_I32(image
->extent
.width
,
115 tile_mode_info
[WMAJOR
].tile_width
);
116 aligned_height
= ALIGN_I32(image
->extent
.height
,
117 tile_mode_info
[WMAJOR
].tile_height
);
118 stencil_size
= image
->stencil_stride
* aligned_height
;
119 image
->size
= image
->stencil_offset
+ stencil_size
;
121 image
->stencil_offset
= 0;
122 image
->stencil_stride
= 0;
125 *pImage
= (VkImage
) image
;
130 VkResult
anv_CreateImage(
132 const VkImageCreateInfo
* pCreateInfo
,
135 return anv_image_create(device
, pCreateInfo
, NULL
, pImage
);
138 VkResult
anv_GetImageSubresourceInfo(
141 const VkImageSubresource
* pSubresource
,
142 VkSubresourceInfoType infoType
,
146 stub_return(VK_UNSUPPORTED
);
150 anv_image_view_init(struct anv_surface_view
*view
,
151 struct anv_device
*device
,
152 const VkImageViewCreateInfo
* pCreateInfo
,
153 struct anv_cmd_buffer
*cmd_buffer
)
155 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
156 const struct anv_format
*info
=
157 anv_format_for_vk_format(pCreateInfo
->format
);
158 uint32_t tile_mode
, format
;
160 view
->bo
= image
->bo
;
161 switch (pCreateInfo
->subresourceRange
.aspect
) {
162 case VK_IMAGE_ASPECT_STENCIL
:
163 /* FIXME: How is stencil texturing formed? */
164 view
->offset
= image
->offset
+ image
->stencil_offset
;
168 case VK_IMAGE_ASPECT_DEPTH
:
169 case VK_IMAGE_ASPECT_COLOR
:
170 view
->offset
= image
->offset
;
171 tile_mode
= image
->tile_mode
;
172 format
= info
->format
;
179 /* TODO: Miplevels */
180 view
->extent
= image
->extent
;
182 static const uint32_t vk_to_gen_swizzle
[] = {
183 [VK_CHANNEL_SWIZZLE_ZERO
] = SCS_ZERO
,
184 [VK_CHANNEL_SWIZZLE_ONE
] = SCS_ONE
,
185 [VK_CHANNEL_SWIZZLE_R
] = SCS_RED
,
186 [VK_CHANNEL_SWIZZLE_G
] = SCS_GREEN
,
187 [VK_CHANNEL_SWIZZLE_B
] = SCS_BLUE
,
188 [VK_CHANNEL_SWIZZLE_A
] = SCS_ALPHA
191 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
192 .SurfaceType
= SURFTYPE_2D
,
193 .SurfaceArray
= false,
194 .SurfaceFormat
= format
,
195 .SurfaceVerticalAlignment
= VALIGN4
,
196 .SurfaceHorizontalAlignment
= HALIGN4
,
197 .TileMode
= tile_mode
,
198 .VerticalLineStride
= 0,
199 .VerticalLineStrideOffset
= 0,
200 .SamplerL2BypassModeDisable
= true,
201 .RenderCacheReadWriteMode
= WriteOnlyCache
,
202 .MemoryObjectControlState
= GEN8_MOCS
,
205 .Height
= image
->extent
.height
- 1,
206 .Width
= image
->extent
.width
- 1,
207 .Depth
= image
->extent
.depth
- 1,
208 .SurfacePitch
= image
->stride
- 1,
209 .MinimumArrayElement
= 0,
210 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
215 .AuxiliarySurfaceMode
= AUX_NONE
,
217 .GreenClearColor
= 0,
219 .AlphaClearColor
= 0,
220 .ShaderChannelSelectRed
= vk_to_gen_swizzle
[pCreateInfo
->channels
.r
],
221 .ShaderChannelSelectGreen
= vk_to_gen_swizzle
[pCreateInfo
->channels
.g
],
222 .ShaderChannelSelectBlue
= vk_to_gen_swizzle
[pCreateInfo
->channels
.b
],
223 .ShaderChannelSelectAlpha
= vk_to_gen_swizzle
[pCreateInfo
->channels
.a
],
225 .SurfaceBaseAddress
= { NULL
, view
->offset
},
229 view
->surface_state
=
230 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
232 view
->surface_state
=
233 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
235 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
238 VkResult
anv_CreateImageView(
240 const VkImageViewCreateInfo
* pCreateInfo
,
243 struct anv_device
*device
= (struct anv_device
*) _device
;
244 struct anv_surface_view
*view
;
246 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
248 view
= anv_device_alloc(device
, sizeof(*view
), 8,
249 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
251 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
253 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
255 *pView
= (VkImageView
) view
;
261 anv_color_attachment_view_init(struct anv_surface_view
*view
,
262 struct anv_device
*device
,
263 const VkColorAttachmentViewCreateInfo
* pCreateInfo
,
264 struct anv_cmd_buffer
*cmd_buffer
)
266 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
267 const struct anv_format
*format
=
268 anv_format_for_vk_format(pCreateInfo
->format
);
270 view
->bo
= image
->bo
;
271 view
->offset
= image
->offset
;
272 view
->extent
= image
->extent
;
273 view
->format
= pCreateInfo
->format
;
276 view
->surface_state
=
277 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
279 view
->surface_state
=
280 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
282 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
283 .SurfaceType
= SURFTYPE_2D
,
284 .SurfaceArray
= false,
285 .SurfaceFormat
= format
->format
,
286 .SurfaceVerticalAlignment
= VALIGN4
,
287 .SurfaceHorizontalAlignment
= HALIGN4
,
288 .TileMode
= image
->tile_mode
,
289 .VerticalLineStride
= 0,
290 .VerticalLineStrideOffset
= 0,
291 .SamplerL2BypassModeDisable
= true,
292 .RenderCacheReadWriteMode
= WriteOnlyCache
,
293 .MemoryObjectControlState
= GEN8_MOCS
,
296 .Height
= image
->extent
.height
- 1,
297 .Width
= image
->extent
.width
- 1,
298 .Depth
= image
->extent
.depth
- 1,
299 .SurfacePitch
= image
->stride
- 1,
300 .MinimumArrayElement
= 0,
301 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
306 .AuxiliarySurfaceMode
= AUX_NONE
,
308 .GreenClearColor
= 0,
310 .AlphaClearColor
= 0,
311 .ShaderChannelSelectRed
= SCS_RED
,
312 .ShaderChannelSelectGreen
= SCS_GREEN
,
313 .ShaderChannelSelectBlue
= SCS_BLUE
,
314 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
316 .SurfaceBaseAddress
= { NULL
, view
->offset
},
319 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
322 VkResult
anv_CreateColorAttachmentView(
324 const VkColorAttachmentViewCreateInfo
* pCreateInfo
,
325 VkColorAttachmentView
* pView
)
327 struct anv_device
*device
= (struct anv_device
*) _device
;
328 struct anv_surface_view
*view
;
330 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO
);
332 view
= anv_device_alloc(device
, sizeof(*view
), 8,
333 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
335 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
337 anv_color_attachment_view_init(view
, device
, pCreateInfo
, NULL
);
339 *pView
= (VkColorAttachmentView
) view
;
344 VkResult
anv_CreateDepthStencilView(
346 const VkDepthStencilViewCreateInfo
* pCreateInfo
,
347 VkDepthStencilView
* pView
)
349 struct anv_device
*device
= (struct anv_device
*) _device
;
350 struct anv_depth_stencil_view
*view
;
351 struct anv_image
*image
= (struct anv_image
*) pCreateInfo
->image
;
352 const struct anv_format
*format
=
353 anv_format_for_vk_format(image
->format
);
355 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO
);
357 view
= anv_device_alloc(device
, sizeof(*view
), 8,
358 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
360 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
362 view
->bo
= image
->bo
;
364 view
->depth_stride
= image
->stride
;
365 view
->depth_offset
= image
->offset
;
366 view
->depth_format
= format
->format
;
368 view
->stencil_stride
= image
->stencil_stride
;
369 view
->stencil_offset
= image
->offset
+ image
->stencil_offset
;
371 *pView
= (VkDepthStencilView
) view
;