blob: e1185c2a3cf0a2872de42dea891236b5b79426ca [file] [log] [blame]
Chia-I Wu4ea339e2014-08-08 21:56:26 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu4ea339e2014-08-08 21:56:26 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu4ea339e2014-08-08 21:56:26 +080026 */
27
Chia-I Wue46da3e2014-08-08 21:52:48 +080028#include "kmd/winsys.h"
29#include "dev.h"
30#include "gpu.h"
Chia-I Wu41858c82015-04-04 16:39:25 +080031#include "wsi.h"
Chia-I Wue46da3e2014-08-08 21:52:48 +080032#include "img.h"
Chia-I Wu4ea339e2014-08-08 21:56:26 +080033
Chia-I Wu4ea339e2014-08-08 21:56:26 +080034/*
35 * From the Ivy Bridge PRM, volume 1 part 1, page 105:
36 *
37 * "In addition to restrictions on maximum height, width, and depth,
38 * surfaces are also restricted to a maximum size in bytes. This
39 * maximum is 2 GB for all products and all surface types."
40 */
Chia-I Wue46da3e2014-08-08 21:52:48 +080041static const size_t intel_max_resource_size = 1u << 31;
Chia-I Wu4ea339e2014-08-08 21:56:26 +080042
Chia-I Wufeb441f2014-08-08 21:27:38 +080043static void img_destroy(struct intel_obj *obj)
44{
45 struct intel_img *img = intel_img_from_obj(obj);
46
47 intel_img_destroy(img);
48}
49
Tony Barbour426b9052015-06-24 16:06:58 -060050static VkResult img_get_memory_requirements(struct intel_base *base, VkMemoryRequirements *pRequirements)
Chia-I Wufeb441f2014-08-08 21:27:38 +080051{
52 struct intel_img *img = intel_img_from_base(base);
Chia-I Wufeb441f2014-08-08 21:27:38 +080053
Tony Barbour426b9052015-06-24 16:06:58 -060054 pRequirements->size = img->total_size;
55 pRequirements->alignment = 4096;
Mark Lobodzinski72346292015-07-02 16:49:40 -060056 pRequirements->memoryTypeBits = (1 << INTEL_MEMORY_TYPE_COUNT) - 1;
Chia-I Wufeb441f2014-08-08 21:27:38 +080057
Tony Barbour426b9052015-06-24 16:06:58 -060058 return VK_SUCCESS;
Chia-I Wufeb441f2014-08-08 21:27:38 +080059}
60
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060061VkResult intel_img_create(struct intel_dev *dev,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060062 const VkImageCreateInfo *info,
63 bool scanout,
64 struct intel_img **img_ret)
Chia-I Wufeb441f2014-08-08 21:27:38 +080065{
Chia-I Wufeb441f2014-08-08 21:27:38 +080066 struct intel_img *img;
Chia-I Wu37cba152014-08-15 16:03:10 +080067 struct intel_layout *layout;
Chia-I Wufeb441f2014-08-08 21:27:38 +080068
Chia-I Wu545c2e12015-02-22 13:19:54 +080069 img = (struct intel_img *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060070 sizeof(*img), dev->base.dbg, VK_OBJECT_TYPE_IMAGE, info, 0);
Chia-I Wufeb441f2014-08-08 21:27:38 +080071 if (!img)
Tony Barbour8205d902015-04-16 15:59:00 -060072 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wufeb441f2014-08-08 21:27:38 +080073
Chia-I Wu37cba152014-08-15 16:03:10 +080074 layout = &img->layout;
75
Chia-I Wueb2da592014-08-16 14:19:39 +080076 img->type = info->imageType;
Chia-I Wu73e326f2014-08-21 11:07:57 +080077 img->depth = info->extent.depth;
Chia-I Wuaa759372014-10-18 12:47:35 +080078 img->mip_levels = info->mipLevels;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -060079 img->array_size = info->arrayLayers;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -070080 img->usage = info->usage;
Chia-I Wueb2da592014-08-16 14:19:39 +080081 img->samples = info->samples;
Chia-I Wu794d12a2014-09-15 14:55:25 +080082 intel_layout_init(layout, dev, info, scanout);
Chia-I Wu37cba152014-08-15 16:03:10 +080083
Chia-I Wu9b752e12014-08-15 16:21:44 +080084 img->total_size = img->layout.bo_stride * img->layout.bo_height;
85
Chia-I Wu457d0a62014-08-18 13:02:26 +080086 if (layout->aux != INTEL_LAYOUT_AUX_NONE) {
Chia-I Wu9b752e12014-08-15 16:21:44 +080087 img->aux_offset = u_align(img->total_size, 4096);
88 img->total_size = img->aux_offset +
89 layout->aux_stride * layout->aux_height;
90 }
91
92 if (layout->separate_stencil) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093 VkImageCreateInfo s8_info;
Chia-I Wu9b752e12014-08-15 16:21:44 +080094
Chia-I Wuf9c81ef2015-02-22 13:49:15 +080095 img->s8_layout = intel_alloc(img, sizeof(*img->s8_layout), 0,
Tony Barbour8205d902015-04-16 15:59:00 -060096 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu9b752e12014-08-15 16:21:44 +080097 if (!img->s8_layout) {
98 intel_img_destroy(img);
Tony Barbour8205d902015-04-16 15:59:00 -060099 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu9b752e12014-08-15 16:21:44 +0800100 }
101
102 s8_info = *info;
Tony Barbour8205d902015-04-16 15:59:00 -0600103 s8_info.format = VK_FORMAT_S8_UINT;
Chia-I Wud1eb90c2015-03-07 06:01:45 +0800104 /* no stencil texturing */
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600105 s8_info.usage &= ~VK_IMAGE_USAGE_SAMPLED_BIT;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700106 assert(icd_format_is_ds(info->format));
Chia-I Wu9b752e12014-08-15 16:21:44 +0800107
Chia-I Wu794d12a2014-09-15 14:55:25 +0800108 intel_layout_init(img->s8_layout, dev, &s8_info, scanout);
Chia-I Wu9b752e12014-08-15 16:21:44 +0800109
110 img->s8_offset = u_align(img->total_size, 4096);
111 img->total_size = img->s8_offset +
112 img->s8_layout->bo_stride * img->s8_layout->bo_height;
Chia-I Wufeb441f2014-08-08 21:27:38 +0800113 }
114
Chia-I Wu41858c82015-04-04 16:39:25 +0800115 if (scanout) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600116 VkResult ret = intel_wsi_img_init(img);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600117 if (ret != VK_SUCCESS) {
Chia-I Wu41858c82015-04-04 16:39:25 +0800118 intel_img_destroy(img);
119 return ret;
120 }
121 }
122
Chia-I Wufeb441f2014-08-08 21:27:38 +0800123 img->obj.destroy = img_destroy;
Tony Barbour426b9052015-06-24 16:06:58 -0600124 img->obj.base.get_memory_requirements = img_get_memory_requirements;
Chia-I Wufeb441f2014-08-08 21:27:38 +0800125
126 *img_ret = img;
127
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600128 return VK_SUCCESS;
Chia-I Wufeb441f2014-08-08 21:27:38 +0800129}
130
131void intel_img_destroy(struct intel_img *img)
132{
Chia-I Wu41858c82015-04-04 16:39:25 +0800133 if (img->wsi_data)
134 intel_wsi_img_cleanup(img);
Chia-I Wu1db76e02014-09-15 14:21:14 +0800135
Chia-I Wu9b752e12014-08-15 16:21:44 +0800136 if (img->s8_layout)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800137 intel_free(img, img->s8_layout);
Chia-I Wu9b752e12014-08-15 16:21:44 +0800138
Chia-I Wufeb441f2014-08-08 21:27:38 +0800139 intel_base_destroy(&img->obj.base);
140}
141
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600142ICD_EXPORT VkResult VKAPI vkCreateImage(
143 VkDevice device,
144 const VkImageCreateInfo* pCreateInfo,
145 VkImage* pImage)
Chia-I Wufeb441f2014-08-08 21:27:38 +0800146{
147 struct intel_dev *dev = intel_dev(device);
148
Chia-I Wu794d12a2014-09-15 14:55:25 +0800149 return intel_img_create(dev, pCreateInfo, false,
150 (struct intel_img **) pImage);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800151}
152
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600153ICD_EXPORT void VKAPI vkDestroyImage(
Tony Barbourde4124d2015-07-03 10:33:54 -0600154 VkDevice device,
155 VkImage image)
156
157 {
158 struct intel_obj *obj = intel_obj(image.handle);
159
160 obj->destroy(obj);
Tony Barbourde4124d2015-07-03 10:33:54 -0600161 }
162
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600163ICD_EXPORT void VKAPI vkGetImageSubresourceLayout(
Mike Stroyan230e6252015-04-17 12:36:38 -0600164 VkDevice device,
165 VkImage image,
166 const VkImageSubresource* pSubresource,
Tony Barbour426b9052015-06-24 16:06:58 -0600167 VkSubresourceLayout* pLayout)
Chia-I Wufeb441f2014-08-08 21:27:38 +0800168{
169 const struct intel_img *img = intel_img(image);
Tony Barbour426b9052015-06-24 16:06:58 -0600170 unsigned x, y;
Chia-I Wufeb441f2014-08-08 21:27:38 +0800171
Tony Barbour426b9052015-06-24 16:06:58 -0600172 intel_layout_get_slice_pos(&img->layout, pSubresource->mipLevel,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600173 pSubresource->arrayLayer, &x, &y);
Tony Barbour426b9052015-06-24 16:06:58 -0600174 intel_layout_pos_to_mem(&img->layout, x, y, &x, &y);
Chia-I Wu2b685d72014-08-14 13:45:37 +0800175
Tony Barbour426b9052015-06-24 16:06:58 -0600176 pLayout->offset = intel_layout_mem_to_linear(&img->layout, x, y);
177 pLayout->size = intel_layout_get_slice_size(&img->layout,
178 pSubresource->mipLevel);
179 pLayout->rowPitch = img->layout.bo_stride;
180 pLayout->depthPitch = intel_layout_get_slice_stride(&img->layout,
181 pSubresource->mipLevel);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800182}
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600183
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600184void VKAPI vkGetImageSparseMemoryRequirements(
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600185 VkDevice device,
186 VkImage image,
187 uint32_t* pNumRequirements,
188 VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
189{
190 *pNumRequirements = 0;
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600191}