Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 3 | * |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | e46da3e | 2014-08-08 21:52:48 +0800 | [diff] [blame] | 28 | #include "kmd/winsys.h" |
| 29 | #include "dev.h" |
| 30 | #include "gpu.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 31 | #include "wsi.h" |
Chia-I Wu | e46da3e | 2014-08-08 21:52:48 +0800 | [diff] [blame] | 32 | #include "img.h" |
Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 33 | |
Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 34 | /* |
| 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 Wu | e46da3e | 2014-08-08 21:52:48 +0800 | [diff] [blame] | 41 | static const size_t intel_max_resource_size = 1u << 31; |
Chia-I Wu | 4ea339e | 2014-08-08 21:56:26 +0800 | [diff] [blame] | 42 | |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 43 | static 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 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 50 | static VkResult img_get_info(struct intel_base *base, int type, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 51 | size_t *size, void *data) |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 52 | { |
| 53 | struct intel_img *img = intel_img_from_base(base); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 54 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 55 | |
| 56 | switch (type) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 57 | case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS: |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 58 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 59 | VkMemoryRequirements *mem_req = data; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 60 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 61 | *size = sizeof(VkMemoryRequirements); |
Jon Ashburn | 408daec | 2014-12-05 09:23:52 -0700 | [diff] [blame] | 62 | if (data == NULL) |
| 63 | return ret; |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 64 | mem_req->size = img->total_size; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 65 | mem_req->alignment = 4096; |
Jeremy Hayes | d02809a | 2015-04-15 14:17:56 -0600 | [diff] [blame] | 66 | mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL; |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 67 | } |
| 68 | break; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 69 | default: |
| 70 | ret = intel_base_get_info(base, type, size, data); |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | return ret; |
| 75 | } |
| 76 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 77 | VkResult intel_img_create(struct intel_dev *dev, |
| 78 | const VkImageCreateInfo *info, |
Chia-I Wu | 794d12a | 2014-09-15 14:55:25 +0800 | [diff] [blame] | 79 | bool scanout, |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 80 | struct intel_img **img_ret) |
| 81 | { |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 82 | struct intel_img *img; |
Chia-I Wu | 37cba15 | 2014-08-15 16:03:10 +0800 | [diff] [blame] | 83 | struct intel_layout *layout; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 84 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 85 | img = (struct intel_img *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 86 | sizeof(*img), dev->base.dbg, VK_DBG_OBJECT_IMAGE, info, 0); |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 87 | if (!img) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 88 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 89 | |
Chia-I Wu | 37cba15 | 2014-08-15 16:03:10 +0800 | [diff] [blame] | 90 | layout = &img->layout; |
| 91 | |
Chia-I Wu | eb2da59 | 2014-08-16 14:19:39 +0800 | [diff] [blame] | 92 | img->type = info->imageType; |
Chia-I Wu | 73e326f | 2014-08-21 11:07:57 +0800 | [diff] [blame] | 93 | img->depth = info->extent.depth; |
Chia-I Wu | aa75937 | 2014-10-18 12:47:35 +0800 | [diff] [blame] | 94 | img->mip_levels = info->mipLevels; |
Chia-I Wu | eb2da59 | 2014-08-16 14:19:39 +0800 | [diff] [blame] | 95 | img->array_size = info->arraySize; |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 96 | img->usage = info->usage; |
Chia-I Wu | eb2da59 | 2014-08-16 14:19:39 +0800 | [diff] [blame] | 97 | img->samples = info->samples; |
Chia-I Wu | 794d12a | 2014-09-15 14:55:25 +0800 | [diff] [blame] | 98 | intel_layout_init(layout, dev, info, scanout); |
Chia-I Wu | 37cba15 | 2014-08-15 16:03:10 +0800 | [diff] [blame] | 99 | |
| 100 | if (layout->bo_stride > intel_max_resource_size / layout->bo_height) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 101 | intel_dev_log(dev, VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, |
| 102 | VK_NULL_HANDLE, 0, 0, "image too big"); |
Chia-I Wu | 37cba15 | 2014-08-15 16:03:10 +0800 | [diff] [blame] | 103 | intel_img_destroy(img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | return VK_ERROR_INVALID_MEMORY_SIZE; |
Chia-I Wu | 37cba15 | 2014-08-15 16:03:10 +0800 | [diff] [blame] | 105 | } |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 106 | |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 107 | img->total_size = img->layout.bo_stride * img->layout.bo_height; |
| 108 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame] | 109 | if (layout->aux != INTEL_LAYOUT_AUX_NONE) { |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 110 | img->aux_offset = u_align(img->total_size, 4096); |
| 111 | img->total_size = img->aux_offset + |
| 112 | layout->aux_stride * layout->aux_height; |
| 113 | } |
| 114 | |
| 115 | if (layout->separate_stencil) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 116 | VkImageCreateInfo s8_info; |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 117 | |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 118 | img->s8_layout = intel_alloc(img, sizeof(*img->s8_layout), 0, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 119 | VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 120 | if (!img->s8_layout) { |
| 121 | intel_img_destroy(img); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 122 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | s8_info = *info; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 126 | s8_info.format = VK_FORMAT_S8_UINT; |
Chia-I Wu | d1eb90c | 2015-03-07 06:01:45 +0800 | [diff] [blame] | 127 | /* no stencil texturing */ |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 128 | s8_info.usage &= ~VK_IMAGE_USAGE_SAMPLED_BIT; |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 129 | assert(icd_format_is_ds(info->format)); |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 130 | |
Chia-I Wu | 794d12a | 2014-09-15 14:55:25 +0800 | [diff] [blame] | 131 | intel_layout_init(img->s8_layout, dev, &s8_info, scanout); |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 132 | |
| 133 | img->s8_offset = u_align(img->total_size, 4096); |
| 134 | img->total_size = img->s8_offset + |
| 135 | img->s8_layout->bo_stride * img->s8_layout->bo_height; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 136 | } |
| 137 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 138 | if (scanout) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 139 | VkResult ret = intel_wsi_img_init(img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 140 | if (ret != VK_SUCCESS) { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 141 | intel_img_destroy(img); |
| 142 | return ret; |
| 143 | } |
| 144 | } |
| 145 | |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 146 | img->obj.destroy = img_destroy; |
| 147 | img->obj.base.get_info = img_get_info; |
| 148 | |
| 149 | *img_ret = img; |
| 150 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 151 | return VK_SUCCESS; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void intel_img_destroy(struct intel_img *img) |
| 155 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 156 | if (img->wsi_data) |
| 157 | intel_wsi_img_cleanup(img); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 158 | |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 159 | if (img->s8_layout) |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 160 | intel_free(img, img->s8_layout); |
Chia-I Wu | 9b752e1 | 2014-08-15 16:21:44 +0800 | [diff] [blame] | 161 | |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 162 | intel_base_destroy(&img->obj.base); |
| 163 | } |
| 164 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 165 | ICD_EXPORT VkResult VKAPI vkOpenPeerImage( |
| 166 | VkDevice device, |
| 167 | const VkPeerImageOpenInfo* pOpenInfo, |
| 168 | VkImage* pImage, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 169 | VkDeviceMemory* pMem) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 170 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 171 | return VK_ERROR_UNAVAILABLE; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 174 | ICD_EXPORT VkResult VKAPI vkCreateImage( |
| 175 | VkDevice device, |
| 176 | const VkImageCreateInfo* pCreateInfo, |
| 177 | VkImage* pImage) |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 178 | { |
| 179 | struct intel_dev *dev = intel_dev(device); |
| 180 | |
Chia-I Wu | 794d12a | 2014-09-15 14:55:25 +0800 | [diff] [blame] | 181 | return intel_img_create(dev, pCreateInfo, false, |
| 182 | (struct intel_img **) pImage); |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 183 | } |
| 184 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 185 | ICD_EXPORT VkResult VKAPI vkGetImageSubresourceInfo( |
| 186 | VkImage image, |
| 187 | const VkImageSubresource* pSubresource, |
| 188 | VkSubresourceInfoType infoType, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 189 | size_t* pDataSize, |
| 190 | void* pData) |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 191 | { |
| 192 | const struct intel_img *img = intel_img(image); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 193 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 194 | |
| 195 | switch (infoType) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 196 | case VK_SUBRESOURCE_INFO_TYPE_LAYOUT: |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 197 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 198 | VkSubresourceLayout *layout = (VkSubresourceLayout *) pData; |
Chia-I Wu | 2b685d7 | 2014-08-14 13:45:37 +0800 | [diff] [blame] | 199 | unsigned x, y; |
| 200 | |
| 201 | intel_layout_get_slice_pos(&img->layout, pSubresource->mipLevel, |
| 202 | pSubresource->arraySlice, &x, &y); |
| 203 | intel_layout_pos_to_mem(&img->layout, x, y, &x, &y); |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 204 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 205 | *pDataSize = sizeof(VkSubresourceLayout); |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 206 | |
Jon Ashburn | bf4182c | 2014-12-04 15:22:01 -0700 | [diff] [blame] | 207 | if (pData == NULL) |
| 208 | return ret; |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame] | 209 | layout->offset = intel_layout_mem_to_linear(&img->layout, x, y); |
Chia-I Wu | 2b685d7 | 2014-08-14 13:45:37 +0800 | [diff] [blame] | 210 | layout->size = intel_layout_get_slice_size(&img->layout, |
| 211 | pSubresource->mipLevel); |
| 212 | layout->rowPitch = img->layout.bo_stride; |
| 213 | layout->depthPitch = intel_layout_get_slice_stride(&img->layout, |
| 214 | pSubresource->mipLevel); |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 215 | } |
| 216 | break; |
| 217 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 218 | ret = VK_ERROR_INVALID_VALUE; |
Chia-I Wu | feb441f | 2014-08-08 21:27:38 +0800 | [diff] [blame] | 219 | break; |
| 220 | } |
| 221 | |
| 222 | return ret; |
| 223 | } |