blob: 06889177feb0766d5add9df0788a526a16ab4ab8 [file] [log] [blame]
Chia-I Wu82f50aa2014-08-05 10:43:03 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu82f50aa2014-08-05 10:43:03 +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 Wu82f50aa2014-08-05 10:43:03 +080026 */
27
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060028#include "dev.h"
Chia-I Wu9e61c0d2014-09-15 15:12:06 +080029#include "gpu.h"
30#include "mem.h"
Chia-I Wu82f50aa2014-08-05 10:43:03 +080031#include "obj.h"
Chia-I Wu82f50aa2014-08-05 10:43:03 +080032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060033VkResult intel_base_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060034 size_t *size, void *data)
Chia-I Wu26f0bd02014-08-07 10:38:40 +080035{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060036 VkResult ret = VK_SUCCESS;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060037 size_t s;
38 uint32_t *count;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080039
40 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -060041 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS:
Jon Ashburnd8031332015-01-22 10:52:13 -070042 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060043 s = sizeof(VkMemoryRequirements);
Jon Ashburnd8031332015-01-22 10:52:13 -070044 *size = s;
45 if (data == NULL)
46 return ret;
47 memset(data, 0, s);
Jeremy Hayesd02809a2015-04-15 14:17:56 -060048 VkMemoryRequirements *mem_req = data;
49 mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL;
Jon Ashburnd8031332015-01-22 10:52:13 -070050 break;
51 }
Tony Barbour8205d902015-04-16 15:59:00 -060052 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060053 *size = sizeof(uint32_t);
Jon Ashburna9ae3832015-01-16 09:37:43 -070054 if (data == NULL)
55 return ret;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060056 count = (uint32_t *) data;
Jon Ashburna9ae3832015-01-16 09:37:43 -070057 *count = 1;
58 break;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080059 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060060 ret = VK_ERROR_INVALID_VALUE;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080061 break;
62 }
63
64 return ret;
65}
66
Chia-I Wuf13ed3c2015-02-22 14:09:00 +080067static bool base_dbg_copy_create_info(const struct intel_handle *handle,
68 struct intel_base_dbg *dbg,
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080069 const void *create_info)
70{
71 const union {
72 const void *ptr;
73 const struct {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060074 VkStructureType struct_type;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060075 void *next;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080076 } *header;
77 } info = { .ptr = create_info };
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060078 size_t shallow_copy = 0;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080079
80 if (!create_info)
81 return true;
82
Chia-I Wub1076d72014-08-18 16:10:20 +080083 switch (dbg->type) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060084 case VK_DBG_OBJECT_DEVICE:
85 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080086 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060087 case VK_DBG_OBJECT_GPU_MEMORY:
88 assert(info.header->struct_type == VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080089 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090 case VK_DBG_OBJECT_EVENT:
91 assert(info.header->struct_type == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060092 shallow_copy = sizeof(VkEventCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080093 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_OBJECT_FENCE:
95 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060096 shallow_copy = sizeof(VkFenceCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080097 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 case VK_DBG_OBJECT_QUERY_POOL:
99 assert(info.header->struct_type == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600100 shallow_copy = sizeof(VkQueryPoolCreateInfo);
Courtney Goeltzenleuchter850d12c2014-08-07 18:13:10 -0600101 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 case VK_DBG_OBJECT_BUFFER:
103 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600104 shallow_copy = sizeof(VkBufferCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +0800105 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600106 case VK_DBG_OBJECT_BUFFER_VIEW:
107 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600108 shallow_copy = sizeof(VkBufferViewCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +0800109 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 case VK_DBG_OBJECT_IMAGE:
111 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600112 shallow_copy = sizeof(VkImageCreateInfo);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800113 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 case VK_DBG_OBJECT_IMAGE_VIEW:
115 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600116 shallow_copy = sizeof(VkImageViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800117 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118 case VK_DBG_OBJECT_COLOR_TARGET_VIEW:
119 assert(info.header->struct_type == VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120 shallow_copy = sizeof(VkColorAttachmentViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800121 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600122 case VK_DBG_OBJECT_DEPTH_STENCIL_VIEW:
123 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600124 shallow_copy = sizeof(VkDepthStencilViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800125 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600126 case VK_DBG_OBJECT_SAMPLER:
127 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600128 shallow_copy = sizeof(VkSamplerCreateInfo);
Chia-I Wu28b89962014-08-18 14:40:49 +0800129 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600130 case VK_DBG_OBJECT_DESCRIPTOR_SET:
Chia-I Wuf8385062015-01-04 16:27:24 +0800131 /* no create info */
Chia-I Wub8d04c82014-08-18 15:51:10 +0800132 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600133 case VK_DBG_OBJECT_VIEWPORT_STATE:
134 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600135 shallow_copy = sizeof(VkDynamicVpStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800136 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137 case VK_DBG_OBJECT_RASTER_STATE:
138 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 shallow_copy = sizeof(VkDynamicRsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800140 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600141 case VK_DBG_OBJECT_COLOR_BLEND_STATE:
142 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143 shallow_copy = sizeof(VkDynamicCbStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800144 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145 case VK_DBG_OBJECT_DEPTH_STENCIL_STATE:
146 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600147 shallow_copy = sizeof(VkDynamicDsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800148 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600149 case VK_DBG_OBJECT_CMD_BUFFER:
150 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600151 shallow_copy = sizeof(VkCmdBufferCreateInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800152 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 case VK_DBG_OBJECT_GRAPHICS_PIPELINE:
154 assert(info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600155 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156 case VK_DBG_OBJECT_SHADER:
157 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600158 shallow_copy = sizeof(VkShaderCreateInfo);
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -0600159 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600160 case VK_DBG_OBJECT_FRAMEBUFFER:
161 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600162 shallow_copy = sizeof(VkFramebufferCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700163 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600164 case VK_DBG_OBJECT_RENDER_PASS:
165 assert(info.header->struct_type == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600166 shallow_copy = sizeof(VkRenderPassCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700167 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600168 case VK_DBG_OBJECT_DESCRIPTOR_SET_LAYOUT:
169 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
Chia-I Wuf8385062015-01-04 16:27:24 +0800170 /* TODO */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600171 shallow_copy = sizeof(VkDescriptorSetLayoutCreateInfo) * 0;
Chia-I Wuf8385062015-01-04 16:27:24 +0800172 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173 case VK_DBG_OBJECT_DESCRIPTOR_POOL:
174 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600175 shallow_copy = sizeof(VkDescriptorPoolCreateInfo);
Chia-I Wuf8385062015-01-04 16:27:24 +0800176 break;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800177 default:
Chia-I Wu545c2e12015-02-22 13:19:54 +0800178 assert(!"unknown dbg object type");
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800179 return false;
180 break;
181 }
182
183 if (shallow_copy) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800184 dbg->create_info = intel_alloc(handle, shallow_copy, 0,
Tony Barbour8205d902015-04-16 15:59:00 -0600185 VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800186 if (!dbg->create_info)
187 return false;
188
189 memcpy(dbg->create_info, create_info, shallow_copy);
Chia-I Wue2934f92014-08-16 13:17:22 +0800190 dbg->create_info_size = shallow_copy;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800191 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600193 size_t size;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500194 const VkMemoryAllocInfo *src = info.ptr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600195 VkMemoryAllocInfo *dst;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700196 uint8_t *d;
197 size = sizeof(*src);
198
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700199 dbg->create_info_size = size;
Tony Barbour8205d902015-04-16 15:59:00 -0600200 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700201 if (!dst)
202 return false;
203 memcpy(dst, src, sizeof(*src));
204
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700205 d = (uint8_t *) dst;
206 d += sizeof(*src);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500207
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700208 dbg->create_info = dst;
209 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600210 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600211 const VkDeviceCreateInfo *src = info.ptr;
212 VkDeviceCreateInfo *dst;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800213 uint8_t *d;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600214 size_t size;
215 uint32_t i;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800216
217 size = sizeof(*src);
Chia-I Wue2934f92014-08-16 13:17:22 +0800218 dbg->create_info_size = size;
219
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800220 size += sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
221 size += sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
222 for (i = 0; i < src->extensionCount; i++) {
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800223 size += 1 + strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800224 }
225
Tony Barbour8205d902015-04-16 15:59:00 -0600226 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800227 if (!dst)
228 return false;
229
230 memcpy(dst, src, sizeof(*src));
231
232 d = (uint8_t *) dst;
233 d += sizeof(*src);
234
235 size = sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
236 memcpy(d, src->pRequestedQueues, size);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600237 dst->pRequestedQueues = (const VkDeviceQueueCreateInfo *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800238 d += size;
239
240 size = sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600241 dst->ppEnabledExtensionNames = (const char * const *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800242
243 for (i = 0; i < src->extensionCount; i++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 const size_t len = strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800245
246 memcpy(d + size, src->ppEnabledExtensionNames[i], len + 1);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 ((const char **) d)[i] = (const char *) (d + size);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800248
249 size += len + 1;
250 }
Courtney Goeltzenleuchter191b06c2014-10-17 16:21:35 -0600251 dbg->create_info = dst;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600252 } else if (info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600253 // TODO: What do we want to copy here?
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800254 }
255
256 return true;
257}
258
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800259/**
Chia-I Wubbf2c932014-08-07 12:20:08 +0800260 * Create an intel_base_dbg. When dbg_size is non-zero, a buffer of that
Chia-I Wu660caf82014-08-07 10:54:26 +0800261 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800262 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800263struct intel_base_dbg *intel_base_dbg_create(const struct intel_handle *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600264 VK_DBG_OBJECT_TYPE type,
Chia-I Wu660caf82014-08-07 10:54:26 +0800265 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600266 size_t dbg_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800267{
Chia-I Wu660caf82014-08-07 10:54:26 +0800268 struct intel_base_dbg *dbg;
269
Chia-I Wubbf2c932014-08-07 12:20:08 +0800270 if (!dbg_size)
271 dbg_size = sizeof(*dbg);
Chia-I Wu660caf82014-08-07 10:54:26 +0800272
Chia-I Wubbf2c932014-08-07 12:20:08 +0800273 assert(dbg_size >= sizeof(*dbg));
Chia-I Wu660caf82014-08-07 10:54:26 +0800274
Tony Barbour8205d902015-04-16 15:59:00 -0600275 dbg = intel_alloc(handle, dbg_size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +0800276 if (!dbg)
277 return NULL;
278
Chia-I Wubbf2c932014-08-07 12:20:08 +0800279 memset(dbg, 0, dbg_size);
Chia-I Wu660caf82014-08-07 10:54:26 +0800280
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800281 dbg->type = type;
282
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800283 if (!base_dbg_copy_create_info(handle, dbg, create_info)) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800284 intel_free(handle, dbg);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800285 return NULL;
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800286 }
287
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800288 return dbg;
289}
290
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800291void intel_base_dbg_destroy(const struct intel_handle *handle,
292 struct intel_base_dbg *dbg)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800293{
Chia-I Wu660caf82014-08-07 10:54:26 +0800294 if (dbg->tag)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800295 intel_free(handle, dbg->tag);
Chia-I Wu660caf82014-08-07 10:54:26 +0800296
297 if (dbg->create_info)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800298 intel_free(handle, dbg->create_info);
Chia-I Wu660caf82014-08-07 10:54:26 +0800299
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800300 intel_free(handle, dbg);
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800301}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800302
Chia-I Wubbf2c932014-08-07 12:20:08 +0800303/**
304 * Create an intel_base. obj_size and dbg_size specify the real sizes of the
305 * object and the debug metadata. Memories are zeroed.
306 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800307struct intel_base *intel_base_create(const struct intel_handle *handle,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600308 size_t obj_size, bool debug,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600309 VK_DBG_OBJECT_TYPE type,
Chia-I Wubbf2c932014-08-07 12:20:08 +0800310 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600311 size_t dbg_size)
Chia-I Wubbf2c932014-08-07 12:20:08 +0800312{
313 struct intel_base *base;
314
315 if (!obj_size)
316 obj_size = sizeof(*base);
317
318 assert(obj_size >= sizeof(*base));
319
Tony Barbour8205d902015-04-16 15:59:00 -0600320 base = intel_alloc(handle, obj_size, 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800321 if (!base)
322 return NULL;
323
Chia-I Wu778a80c2015-01-03 22:45:10 +0800324 memset(base, 0, obj_size);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800325 intel_handle_init(&base->handle, type, handle->icd);
Chia-I Wu778a80c2015-01-03 22:45:10 +0800326
Chia-I Wubbf2c932014-08-07 12:20:08 +0800327 if (debug) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800328 base->dbg = intel_base_dbg_create(&base->handle,
Chia-I Wu545c2e12015-02-22 13:19:54 +0800329 type, create_info, dbg_size);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800330 if (!base->dbg) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800331 intel_free(handle, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800332 return NULL;
333 }
334 }
Chia-I Wu6a42c2a2014-08-19 14:36:47 +0800335
Chia-I Wubbf2c932014-08-07 12:20:08 +0800336 base->get_info = intel_base_get_info;
337
338 return base;
339}
340
341void intel_base_destroy(struct intel_base *base)
342{
343 if (base->dbg)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800344 intel_base_dbg_destroy(&base->handle, base->dbg);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800345 intel_free(base, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800346}
347
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600348ICD_EXPORT VkResult VKAPI vkDestroyObject(
Mike Stroyan230e6252015-04-17 12:36:38 -0600349 VkDevice device,
350 VkObjectType objType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600351 VkObject object)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800352{
353 struct intel_obj *obj = intel_obj(object);
354
355 obj->destroy(obj);
356
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600357 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800358}
359
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600360ICD_EXPORT VkResult VKAPI vkGetObjectInfo(
Mike Stroyan230e6252015-04-17 12:36:38 -0600361 VkDevice device,
362 VkObjectType objType,
363 VkObject object,
364 VkObjectInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600365 size_t* pDataSize,
366 void* pData)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800367{
368 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800369
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800370 return base->get_info(base, infoType, pDataSize, pData);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800371}
372
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500373ICD_EXPORT VkResult VKAPI vkBindObjectMemory(
374 VkDevice device,
Mike Stroyan230e6252015-04-17 12:36:38 -0600375 VkObjectType objType,
376 VkObject object,
377 uint32_t allocationIdx,
Tony Barbour8205d902015-04-16 15:59:00 -0600378 VkDeviceMemory mem_,
379 VkDeviceSize memOffset)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800380{
381 struct intel_obj *obj = intel_obj(object);
Chia-I Wu9e61c0d2014-09-15 15:12:06 +0800382 struct intel_mem *mem = intel_mem(mem_);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800383
Chia-I Wu714df452015-01-01 07:55:04 +0800384 intel_obj_bind_mem(obj, mem, memOffset);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800385
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800387}
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800388
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500389ICD_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -0600390 VkQueue queue,
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500391 VkBuffer buffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600392 uint32_t allocationIdx,
Tony Barbour8205d902015-04-16 15:59:00 -0600393 VkDeviceSize rangeOffset,
394 VkDeviceSize rangeSize,
395 VkDeviceMemory mem,
396 VkDeviceSize memOffset)
Chia-I Wu714df452015-01-01 07:55:04 +0800397{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800399}
400
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500401ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageMemory(
Tony Barbour8205d902015-04-16 15:59:00 -0600402 VkQueue queue,
403 VkImage image,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600404 uint32_t allocationIdx,
Tony Barbour8205d902015-04-16 15:59:00 -0600405 const VkImageMemoryBindInfo* pBindInfo,
406 VkDeviceMemory mem,
407 VkDeviceSize memOffset)
Chia-I Wu714df452015-01-01 07:55:04 +0800408{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800410}
411
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600412ICD_EXPORT VkResult VKAPI vkDbgSetObjectTag(
Mike Stroyan230e6252015-04-17 12:36:38 -0600413 VkDevice device,
414 VkObject object,
Tony Barbour8205d902015-04-16 15:59:00 -0600415 size_t tagSize,
416 const void* pTag)
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800417{
418 struct intel_base *base = intel_base(object);
419 struct intel_base_dbg *dbg = base->dbg;
420 void *tag;
421
422 if (!dbg)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 return VK_SUCCESS;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800424
Tony Barbour8205d902015-04-16 15:59:00 -0600425 tag = intel_alloc(base, tagSize, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800426 if (!tag)
Tony Barbour8205d902015-04-16 15:59:00 -0600427 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800428
429 memcpy(tag, pTag, tagSize);
430
431 if (dbg->tag)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800432 intel_free(base, dbg->tag);
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800433
434 dbg->tag = tag;
435 dbg->tag_size = tagSize;
436
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600437 return VK_SUCCESS;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800438}