blob: d6cf6e45e7f63dba00c525d86eb6dca1644132be [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) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060041 case VK_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);
Jon Ashburnd8031332015-01-22 10:52:13 -070048 break;
49 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050 case VK_INFO_TYPE_MEMORY_ALLOCATION_COUNT:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060051 *size = sizeof(uint32_t);
Jon Ashburna9ae3832015-01-16 09:37:43 -070052 if (data == NULL)
53 return ret;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060054 count = (uint32_t *) data;
Jon Ashburna9ae3832015-01-16 09:37:43 -070055 *count = 1;
56 break;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080057 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060058 ret = VK_ERROR_INVALID_VALUE;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080059 break;
60 }
61
62 return ret;
63}
64
Chia-I Wuf13ed3c2015-02-22 14:09:00 +080065static bool base_dbg_copy_create_info(const struct intel_handle *handle,
66 struct intel_base_dbg *dbg,
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080067 const void *create_info)
68{
69 const union {
70 const void *ptr;
71 const struct {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060072 VkStructureType struct_type;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060073 void *next;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080074 } *header;
75 } info = { .ptr = create_info };
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060076 size_t shallow_copy = 0;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080077
78 if (!create_info)
79 return true;
80
Chia-I Wub1076d72014-08-18 16:10:20 +080081 switch (dbg->type) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060082 case VK_DBG_OBJECT_DEVICE:
83 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080084 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060085 case VK_DBG_OBJECT_GPU_MEMORY:
86 assert(info.header->struct_type == VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080087 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060088 case VK_DBG_OBJECT_EVENT:
89 assert(info.header->struct_type == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060090 shallow_copy = sizeof(VkEventCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080091 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060092 case VK_DBG_OBJECT_FENCE:
93 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060094 shallow_copy = sizeof(VkFenceCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080095 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 case VK_DBG_OBJECT_QUERY_POOL:
97 assert(info.header->struct_type == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060098 shallow_copy = sizeof(VkQueryPoolCreateInfo);
Courtney Goeltzenleuchter850d12c2014-08-07 18:13:10 -060099 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600100 case VK_DBG_OBJECT_BUFFER:
101 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600102 shallow_copy = sizeof(VkBufferCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +0800103 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600104 case VK_DBG_OBJECT_BUFFER_VIEW:
105 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600106 shallow_copy = sizeof(VkBufferViewCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +0800107 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 case VK_DBG_OBJECT_IMAGE:
109 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600110 shallow_copy = sizeof(VkImageCreateInfo);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800111 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 case VK_DBG_OBJECT_IMAGE_VIEW:
113 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600114 shallow_copy = sizeof(VkImageViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800115 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600116 case VK_DBG_OBJECT_COLOR_TARGET_VIEW:
117 assert(info.header->struct_type == VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600118 shallow_copy = sizeof(VkColorAttachmentViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800119 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600120 case VK_DBG_OBJECT_DEPTH_STENCIL_VIEW:
121 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 shallow_copy = sizeof(VkDepthStencilViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800123 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600124 case VK_DBG_OBJECT_SAMPLER:
125 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600126 shallow_copy = sizeof(VkSamplerCreateInfo);
Chia-I Wu28b89962014-08-18 14:40:49 +0800127 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600128 case VK_DBG_OBJECT_DESCRIPTOR_SET:
Chia-I Wuf8385062015-01-04 16:27:24 +0800129 /* no create info */
Chia-I Wub8d04c82014-08-18 15:51:10 +0800130 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131 case VK_DBG_OBJECT_VIEWPORT_STATE:
132 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600133 shallow_copy = sizeof(VkDynamicVpStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800134 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135 case VK_DBG_OBJECT_RASTER_STATE:
136 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 shallow_copy = sizeof(VkDynamicRsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800138 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139 case VK_DBG_OBJECT_COLOR_BLEND_STATE:
140 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 shallow_copy = sizeof(VkDynamicCbStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800142 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 case VK_DBG_OBJECT_DEPTH_STENCIL_STATE:
144 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600145 shallow_copy = sizeof(VkDynamicDsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800146 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600147 case VK_DBG_OBJECT_CMD_BUFFER:
148 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600149 shallow_copy = sizeof(VkCmdBufferCreateInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800150 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600151 case VK_DBG_OBJECT_GRAPHICS_PIPELINE:
152 assert(info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600153 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600154 case VK_DBG_OBJECT_SHADER:
155 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 shallow_copy = sizeof(VkShaderCreateInfo);
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -0600157 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600158 case VK_DBG_OBJECT_FRAMEBUFFER:
159 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600160 shallow_copy = sizeof(VkFramebufferCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700161 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600162 case VK_DBG_OBJECT_RENDER_PASS:
163 assert(info.header->struct_type == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600164 shallow_copy = sizeof(VkRenderPassCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700165 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600166 case VK_DBG_OBJECT_DESCRIPTOR_SET_LAYOUT:
167 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
Chia-I Wuf8385062015-01-04 16:27:24 +0800168 /* TODO */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600169 shallow_copy = sizeof(VkDescriptorSetLayoutCreateInfo) * 0;
Chia-I Wuf8385062015-01-04 16:27:24 +0800170 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 case VK_DBG_OBJECT_DESCRIPTOR_POOL:
172 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600173 shallow_copy = sizeof(VkDescriptorPoolCreateInfo);
Chia-I Wuf8385062015-01-04 16:27:24 +0800174 break;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800175 default:
Chia-I Wu545c2e12015-02-22 13:19:54 +0800176 assert(!"unknown dbg object type");
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800177 return false;
178 break;
179 }
180
181 if (shallow_copy) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800182 dbg->create_info = intel_alloc(handle, shallow_copy, 0,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600183 VK_SYSTEM_ALLOC_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800184 if (!dbg->create_info)
185 return false;
186
187 memcpy(dbg->create_info, create_info, shallow_copy);
Chia-I Wue2934f92014-08-16 13:17:22 +0800188 dbg->create_info_size = shallow_copy;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800189 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600191 size_t size;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500192 const VkMemoryAllocInfo *src = info.ptr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600193 VkMemoryAllocInfo *dst;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700194 uint8_t *d;
195 size = sizeof(*src);
196
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700197 dbg->create_info_size = size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_DEBUG);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700199 if (!dst)
200 return false;
201 memcpy(dst, src, sizeof(*src));
202
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700203 d = (uint8_t *) dst;
204 d += sizeof(*src);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500205
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700206 dbg->create_info = dst;
207 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600209 const VkDeviceCreateInfo *src = info.ptr;
210 VkDeviceCreateInfo *dst;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800211 uint8_t *d;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600212 size_t size;
213 uint32_t i;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800214
215 size = sizeof(*src);
Chia-I Wue2934f92014-08-16 13:17:22 +0800216 dbg->create_info_size = size;
217
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800218 size += sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
219 size += sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
220 for (i = 0; i < src->extensionCount; i++) {
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800221 size += 1 + strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800222 }
223
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600224 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800225 if (!dst)
226 return false;
227
228 memcpy(dst, src, sizeof(*src));
229
230 d = (uint8_t *) dst;
231 d += sizeof(*src);
232
233 size = sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
234 memcpy(d, src->pRequestedQueues, size);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600235 dst->pRequestedQueues = (const VkDeviceQueueCreateInfo *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800236 d += size;
237
238 size = sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600239 dst->ppEnabledExtensionNames = (const char * const *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800240
241 for (i = 0; i < src->extensionCount; i++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600242 const size_t len = strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800243
244 memcpy(d + size, src->ppEnabledExtensionNames[i], len + 1);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600245 ((const char **) d)[i] = (const char *) (d + size);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800246
247 size += len + 1;
248 }
Courtney Goeltzenleuchter191b06c2014-10-17 16:21:35 -0600249 dbg->create_info = dst;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250 } else if (info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600251 // TODO: What do we want to copy here?
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800252 }
253
254 return true;
255}
256
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800257/**
Chia-I Wubbf2c932014-08-07 12:20:08 +0800258 * Create an intel_base_dbg. When dbg_size is non-zero, a buffer of that
Chia-I Wu660caf82014-08-07 10:54:26 +0800259 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800260 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800261struct intel_base_dbg *intel_base_dbg_create(const struct intel_handle *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600262 VK_DBG_OBJECT_TYPE type,
Chia-I Wu660caf82014-08-07 10:54:26 +0800263 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600264 size_t dbg_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800265{
Chia-I Wu660caf82014-08-07 10:54:26 +0800266 struct intel_base_dbg *dbg;
267
Chia-I Wubbf2c932014-08-07 12:20:08 +0800268 if (!dbg_size)
269 dbg_size = sizeof(*dbg);
Chia-I Wu660caf82014-08-07 10:54:26 +0800270
Chia-I Wubbf2c932014-08-07 12:20:08 +0800271 assert(dbg_size >= sizeof(*dbg));
Chia-I Wu660caf82014-08-07 10:54:26 +0800272
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 dbg = intel_alloc(handle, dbg_size, 0, VK_SYSTEM_ALLOC_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +0800274 if (!dbg)
275 return NULL;
276
Chia-I Wubbf2c932014-08-07 12:20:08 +0800277 memset(dbg, 0, dbg_size);
Chia-I Wu660caf82014-08-07 10:54:26 +0800278
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800279 dbg->type = type;
280
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800281 if (!base_dbg_copy_create_info(handle, dbg, create_info)) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800282 intel_free(handle, dbg);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800283 return NULL;
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800284 }
285
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800286 return dbg;
287}
288
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800289void intel_base_dbg_destroy(const struct intel_handle *handle,
290 struct intel_base_dbg *dbg)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800291{
Chia-I Wu660caf82014-08-07 10:54:26 +0800292 if (dbg->tag)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800293 intel_free(handle, dbg->tag);
Chia-I Wu660caf82014-08-07 10:54:26 +0800294
295 if (dbg->create_info)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800296 intel_free(handle, dbg->create_info);
Chia-I Wu660caf82014-08-07 10:54:26 +0800297
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800298 intel_free(handle, dbg);
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800299}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800300
Chia-I Wubbf2c932014-08-07 12:20:08 +0800301/**
302 * Create an intel_base. obj_size and dbg_size specify the real sizes of the
303 * object and the debug metadata. Memories are zeroed.
304 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800305struct intel_base *intel_base_create(const struct intel_handle *handle,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600306 size_t obj_size, bool debug,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600307 VK_DBG_OBJECT_TYPE type,
Chia-I Wubbf2c932014-08-07 12:20:08 +0800308 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600309 size_t dbg_size)
Chia-I Wubbf2c932014-08-07 12:20:08 +0800310{
311 struct intel_base *base;
312
313 if (!obj_size)
314 obj_size = sizeof(*base);
315
316 assert(obj_size >= sizeof(*base));
317
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318 base = intel_alloc(handle, obj_size, 0, VK_SYSTEM_ALLOC_API_OBJECT);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800319 if (!base)
320 return NULL;
321
Chia-I Wu778a80c2015-01-03 22:45:10 +0800322 memset(base, 0, obj_size);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800323 intel_handle_init(&base->handle, type, handle->icd);
Chia-I Wu778a80c2015-01-03 22:45:10 +0800324
Chia-I Wubbf2c932014-08-07 12:20:08 +0800325 if (debug) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800326 base->dbg = intel_base_dbg_create(&base->handle,
Chia-I Wu545c2e12015-02-22 13:19:54 +0800327 type, create_info, dbg_size);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800328 if (!base->dbg) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800329 intel_free(handle, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800330 return NULL;
331 }
332 }
Chia-I Wu6a42c2a2014-08-19 14:36:47 +0800333
Chia-I Wubbf2c932014-08-07 12:20:08 +0800334 base->get_info = intel_base_get_info;
335
336 return base;
337}
338
339void intel_base_destroy(struct intel_base *base)
340{
341 if (base->dbg)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800342 intel_base_dbg_destroy(&base->handle, base->dbg);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800343 intel_free(base, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800344}
345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600346ICD_EXPORT VkResult VKAPI vkDestroyObject(
347 VkObject object)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800348{
349 struct intel_obj *obj = intel_obj(object);
350
351 obj->destroy(obj);
352
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600353 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800354}
355
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600356ICD_EXPORT VkResult VKAPI vkGetObjectInfo(
357 VkBaseObject object,
358 VkObjectInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600359 size_t* pDataSize,
360 void* pData)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800361{
362 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800363
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800364 return base->get_info(base, infoType, pDataSize, pData);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800365}
366
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600367ICD_EXPORT VkResult VKAPI vkBindObjectMemory(
368 VkObject object,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600369 uint32_t allocationIdx,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600370 VkGpuMemory mem_,
371 VkGpuSize memOffset)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800372{
373 struct intel_obj *obj = intel_obj(object);
Chia-I Wu9e61c0d2014-09-15 15:12:06 +0800374 struct intel_mem *mem = intel_mem(mem_);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800375
Chia-I Wu714df452015-01-01 07:55:04 +0800376 intel_obj_bind_mem(obj, mem, memOffset);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800379}
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800380
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600381ICD_EXPORT VkResult VKAPI vkBindObjectMemoryRange(
382 VkObject object,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600383 uint32_t allocationIdx,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384 VkGpuSize rangeOffset,
385 VkGpuSize rangeSize,
386 VkGpuMemory mem,
387 VkGpuSize memOffset)
Chia-I Wu714df452015-01-01 07:55:04 +0800388{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800390}
391
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600392ICD_EXPORT VkResult VKAPI vkBindImageMemoryRange(
393 VkImage image,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600394 uint32_t allocationIdx,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600395 const VkImageMemoryBindInfo* bindInfo,
396 VkGpuMemory mem,
397 VkGpuSize memOffset)
Chia-I Wu714df452015-01-01 07:55:04 +0800398{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600399 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800400}
401
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600402ICD_EXPORT VkResult VKAPI vkDbgSetObjectTag(
403 VkBaseObject object,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600404 size_t tagSize,
405 const void* pTag)
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800406{
407 struct intel_base *base = intel_base(object);
408 struct intel_base_dbg *dbg = base->dbg;
409 void *tag;
410
411 if (!dbg)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412 return VK_SUCCESS;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800413
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600414 tag = intel_alloc(base, tagSize, 0, VK_SYSTEM_ALLOC_DEBUG);
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800415 if (!tag)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600416 return VK_ERROR_OUT_OF_MEMORY;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800417
418 memcpy(tag, pTag, tagSize);
419
420 if (dbg->tag)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800421 intel_free(base, dbg->tag);
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800422
423 dbg->tag = tag;
424 dbg->tag_size = tagSize;
425
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600426 return VK_SUCCESS;
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800427}