blob: 427d35ea91b5af345af736861cd23810dac8526d [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;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080038
39 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -060040 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS:
Jon Ashburnd8031332015-01-22 10:52:13 -070041 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060042 s = sizeof(VkMemoryRequirements);
Jon Ashburnd8031332015-01-22 10:52:13 -070043 *size = s;
44 if (data == NULL)
45 return ret;
46 memset(data, 0, s);
Jeremy Hayesd02809a2015-04-15 14:17:56 -060047 VkMemoryRequirements *mem_req = data;
48 mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL;
Jon Ashburnd8031332015-01-22 10:52:13 -070049 break;
50 }
Chia-I Wu26f0bd02014-08-07 10:38:40 +080051 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060052 ret = VK_ERROR_INVALID_VALUE;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080053 break;
54 }
55
56 return ret;
57}
58
Chia-I Wuf13ed3c2015-02-22 14:09:00 +080059static bool base_dbg_copy_create_info(const struct intel_handle *handle,
60 struct intel_base_dbg *dbg,
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080061 const void *create_info)
62{
63 const union {
64 const void *ptr;
65 const struct {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060066 VkStructureType struct_type;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060067 void *next;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080068 } *header;
69 } info = { .ptr = create_info };
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060070 size_t shallow_copy = 0;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080071
72 if (!create_info)
73 return true;
74
Chia-I Wub1076d72014-08-18 16:10:20 +080075 switch (dbg->type) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060076 case VK_DBG_OBJECT_DEVICE:
77 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080078 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060079 case VK_DBG_OBJECT_GPU_MEMORY:
80 assert(info.header->struct_type == VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080081 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060082 case VK_DBG_OBJECT_EVENT:
83 assert(info.header->struct_type == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060084 shallow_copy = sizeof(VkEventCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080085 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060086 case VK_DBG_OBJECT_FENCE:
87 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060088 shallow_copy = sizeof(VkFenceCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080089 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090 case VK_DBG_OBJECT_QUERY_POOL:
91 assert(info.header->struct_type == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060092 shallow_copy = sizeof(VkQueryPoolCreateInfo);
Courtney Goeltzenleuchter850d12c2014-08-07 18:13:10 -060093 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_OBJECT_BUFFER:
95 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060096 shallow_copy = sizeof(VkBufferCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +080097 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 case VK_DBG_OBJECT_BUFFER_VIEW:
99 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600100 shallow_copy = sizeof(VkBufferViewCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +0800101 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 case VK_DBG_OBJECT_IMAGE:
103 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600104 shallow_copy = sizeof(VkImageCreateInfo);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800105 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600106 case VK_DBG_OBJECT_IMAGE_VIEW:
107 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600108 shallow_copy = sizeof(VkImageViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800109 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 case VK_DBG_OBJECT_COLOR_TARGET_VIEW:
111 assert(info.header->struct_type == VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600112 shallow_copy = sizeof(VkColorAttachmentViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800113 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 case VK_DBG_OBJECT_DEPTH_STENCIL_VIEW:
115 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600116 shallow_copy = sizeof(VkDepthStencilViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800117 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118 case VK_DBG_OBJECT_SAMPLER:
119 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120 shallow_copy = sizeof(VkSamplerCreateInfo);
Chia-I Wu28b89962014-08-18 14:40:49 +0800121 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600122 case VK_DBG_OBJECT_DESCRIPTOR_SET:
Chia-I Wuf8385062015-01-04 16:27:24 +0800123 /* no create info */
Chia-I Wub8d04c82014-08-18 15:51:10 +0800124 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600125 case VK_DBG_OBJECT_VIEWPORT_STATE:
126 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600127 shallow_copy = sizeof(VkDynamicVpStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800128 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600129 case VK_DBG_OBJECT_RASTER_STATE:
130 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600131 shallow_copy = sizeof(VkDynamicRsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800132 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600133 case VK_DBG_OBJECT_COLOR_BLEND_STATE:
134 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600135 shallow_copy = sizeof(VkDynamicCbStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800136 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137 case VK_DBG_OBJECT_DEPTH_STENCIL_STATE:
138 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 shallow_copy = sizeof(VkDynamicDsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800140 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600141 case VK_DBG_OBJECT_CMD_BUFFER:
142 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143 shallow_copy = sizeof(VkCmdBufferCreateInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800144 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145 case VK_DBG_OBJECT_GRAPHICS_PIPELINE:
146 assert(info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600147 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148 case VK_DBG_OBJECT_SHADER:
149 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 shallow_copy = sizeof(VkShaderCreateInfo);
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -0600151 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600152 case VK_DBG_OBJECT_FRAMEBUFFER:
153 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600154 shallow_copy = sizeof(VkFramebufferCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700155 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156 case VK_DBG_OBJECT_RENDER_PASS:
157 assert(info.header->struct_type == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600158 shallow_copy = sizeof(VkRenderPassCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700159 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600160 case VK_DBG_OBJECT_DESCRIPTOR_SET_LAYOUT:
161 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
Chia-I Wuf8385062015-01-04 16:27:24 +0800162 /* TODO */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600163 shallow_copy = sizeof(VkDescriptorSetLayoutCreateInfo) * 0;
Chia-I Wuf8385062015-01-04 16:27:24 +0800164 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600165 case VK_DBG_OBJECT_DESCRIPTOR_POOL:
166 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600167 shallow_copy = sizeof(VkDescriptorPoolCreateInfo);
Chia-I Wuf8385062015-01-04 16:27:24 +0800168 break;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800169 default:
Chia-I Wu545c2e12015-02-22 13:19:54 +0800170 assert(!"unknown dbg object type");
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800171 return false;
172 break;
173 }
174
175 if (shallow_copy) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800176 dbg->create_info = intel_alloc(handle, shallow_copy, 0,
Tony Barbour8205d902015-04-16 15:59:00 -0600177 VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800178 if (!dbg->create_info)
179 return false;
180
181 memcpy(dbg->create_info, create_info, shallow_copy);
Chia-I Wue2934f92014-08-16 13:17:22 +0800182 dbg->create_info_size = shallow_copy;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800183 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600184 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600185 size_t size;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500186 const VkMemoryAllocInfo *src = info.ptr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600187 VkMemoryAllocInfo *dst;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700188 uint8_t *d;
189 size = sizeof(*src);
190
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700191 dbg->create_info_size = size;
Tony Barbour8205d902015-04-16 15:59:00 -0600192 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700193 if (!dst)
194 return false;
195 memcpy(dst, src, sizeof(*src));
196
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700197 d = (uint8_t *) dst;
198 d += sizeof(*src);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500199
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700200 dbg->create_info = dst;
201 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600203 const VkDeviceCreateInfo *src = info.ptr;
204 VkDeviceCreateInfo *dst;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800205 uint8_t *d;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600206 size_t size;
207 uint32_t i;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800208
209 size = sizeof(*src);
Chia-I Wue2934f92014-08-16 13:17:22 +0800210 dbg->create_info_size = size;
211
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800212 size += sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
213 size += sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
214 for (i = 0; i < src->extensionCount; i++) {
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800215 size += 1 + strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800216 }
217
Tony Barbour8205d902015-04-16 15:59:00 -0600218 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800219 if (!dst)
220 return false;
221
222 memcpy(dst, src, sizeof(*src));
223
224 d = (uint8_t *) dst;
225 d += sizeof(*src);
226
227 size = sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
228 memcpy(d, src->pRequestedQueues, size);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600229 dst->pRequestedQueues = (const VkDeviceQueueCreateInfo *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800230 d += size;
231
232 size = sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600233 dst->ppEnabledExtensionNames = (const char * const *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800234
235 for (i = 0; i < src->extensionCount; i++) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600236 const size_t len = strlen(src->ppEnabledExtensionNames[i]);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800237
238 memcpy(d + size, src->ppEnabledExtensionNames[i], len + 1);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600239 ((const char **) d)[i] = (const char *) (d + size);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800240
241 size += len + 1;
242 }
Courtney Goeltzenleuchter191b06c2014-10-17 16:21:35 -0600243 dbg->create_info = dst;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600244 } else if (info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600245 // TODO: What do we want to copy here?
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800246 }
247
248 return true;
249}
250
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800251/**
Chia-I Wubbf2c932014-08-07 12:20:08 +0800252 * Create an intel_base_dbg. When dbg_size is non-zero, a buffer of that
Chia-I Wu660caf82014-08-07 10:54:26 +0800253 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800254 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800255struct intel_base_dbg *intel_base_dbg_create(const struct intel_handle *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256 VK_DBG_OBJECT_TYPE type,
Chia-I Wu660caf82014-08-07 10:54:26 +0800257 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600258 size_t dbg_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800259{
Chia-I Wu660caf82014-08-07 10:54:26 +0800260 struct intel_base_dbg *dbg;
261
Chia-I Wubbf2c932014-08-07 12:20:08 +0800262 if (!dbg_size)
263 dbg_size = sizeof(*dbg);
Chia-I Wu660caf82014-08-07 10:54:26 +0800264
Chia-I Wubbf2c932014-08-07 12:20:08 +0800265 assert(dbg_size >= sizeof(*dbg));
Chia-I Wu660caf82014-08-07 10:54:26 +0800266
Tony Barbour8205d902015-04-16 15:59:00 -0600267 dbg = intel_alloc(handle, dbg_size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +0800268 if (!dbg)
269 return NULL;
270
Chia-I Wubbf2c932014-08-07 12:20:08 +0800271 memset(dbg, 0, dbg_size);
Chia-I Wu660caf82014-08-07 10:54:26 +0800272
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800273 dbg->type = type;
274
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800275 if (!base_dbg_copy_create_info(handle, dbg, create_info)) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800276 intel_free(handle, dbg);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800277 return NULL;
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800278 }
279
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800280 return dbg;
281}
282
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800283void intel_base_dbg_destroy(const struct intel_handle *handle,
284 struct intel_base_dbg *dbg)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800285{
Chia-I Wu660caf82014-08-07 10:54:26 +0800286 if (dbg->tag)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800287 intel_free(handle, dbg->tag);
Chia-I Wu660caf82014-08-07 10:54:26 +0800288
289 if (dbg->create_info)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800290 intel_free(handle, dbg->create_info);
Chia-I Wu660caf82014-08-07 10:54:26 +0800291
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800292 intel_free(handle, dbg);
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800293}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800294
Chia-I Wubbf2c932014-08-07 12:20:08 +0800295/**
296 * Create an intel_base. obj_size and dbg_size specify the real sizes of the
297 * object and the debug metadata. Memories are zeroed.
298 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800299struct intel_base *intel_base_create(const struct intel_handle *handle,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600300 size_t obj_size, bool debug,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600301 VK_DBG_OBJECT_TYPE type,
Chia-I Wubbf2c932014-08-07 12:20:08 +0800302 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600303 size_t dbg_size)
Chia-I Wubbf2c932014-08-07 12:20:08 +0800304{
305 struct intel_base *base;
306
307 if (!obj_size)
308 obj_size = sizeof(*base);
309
310 assert(obj_size >= sizeof(*base));
311
Tony Barbour8205d902015-04-16 15:59:00 -0600312 base = intel_alloc(handle, obj_size, 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800313 if (!base)
314 return NULL;
315
Chia-I Wu778a80c2015-01-03 22:45:10 +0800316 memset(base, 0, obj_size);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800317 intel_handle_init(&base->handle, type, handle->icd);
Chia-I Wu778a80c2015-01-03 22:45:10 +0800318
Chia-I Wubbf2c932014-08-07 12:20:08 +0800319 if (debug) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800320 base->dbg = intel_base_dbg_create(&base->handle,
Chia-I Wu545c2e12015-02-22 13:19:54 +0800321 type, create_info, dbg_size);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800322 if (!base->dbg) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800323 intel_free(handle, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800324 return NULL;
325 }
326 }
Chia-I Wu6a42c2a2014-08-19 14:36:47 +0800327
Chia-I Wubbf2c932014-08-07 12:20:08 +0800328 base->get_info = intel_base_get_info;
329
330 return base;
331}
332
333void intel_base_destroy(struct intel_base *base)
334{
335 if (base->dbg)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800336 intel_base_dbg_destroy(&base->handle, base->dbg);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800337 intel_free(base, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800338}
339
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600340ICD_EXPORT VkResult VKAPI vkDestroyObject(
Mike Stroyan230e6252015-04-17 12:36:38 -0600341 VkDevice device,
342 VkObjectType objType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600343 VkObject object)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800344{
345 struct intel_obj *obj = intel_obj(object);
346
347 obj->destroy(obj);
348
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800350}
351
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600352ICD_EXPORT VkResult VKAPI vkGetObjectInfo(
Mike Stroyan230e6252015-04-17 12:36:38 -0600353 VkDevice device,
354 VkObjectType objType,
355 VkObject object,
356 VkObjectInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600357 size_t* pDataSize,
358 void* pData)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800359{
360 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800361
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800362 return base->get_info(base, infoType, pDataSize, pData);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800363}
364
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500365ICD_EXPORT VkResult VKAPI vkBindObjectMemory(
366 VkDevice device,
Mike Stroyan230e6252015-04-17 12:36:38 -0600367 VkObjectType objType,
368 VkObject object,
Tony Barbour8205d902015-04-16 15:59:00 -0600369 VkDeviceMemory mem_,
370 VkDeviceSize memOffset)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800371{
372 struct intel_obj *obj = intel_obj(object);
Chia-I Wu9e61c0d2014-09-15 15:12:06 +0800373 struct intel_mem *mem = intel_mem(mem_);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800374
Chia-I Wu714df452015-01-01 07:55:04 +0800375 intel_obj_bind_mem(obj, mem, memOffset);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800376
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800378}
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800379
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500380ICD_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -0600381 VkQueue queue,
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500382 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600383 VkDeviceSize rangeOffset,
384 VkDeviceSize rangeSize,
385 VkDeviceMemory mem,
386 VkDeviceSize memOffset)
Chia-I Wu714df452015-01-01 07:55:04 +0800387{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800389}
390
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500391ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageMemory(
Tony Barbour8205d902015-04-16 15:59:00 -0600392 VkQueue queue,
393 VkImage image,
Tony Barbour8205d902015-04-16 15:59:00 -0600394 const VkImageMemoryBindInfo* pBindInfo,
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
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600401ICD_EXPORT VkResult VKAPI vkDbgSetObjectTag(
Mike Stroyan230e6252015-04-17 12:36:38 -0600402 VkDevice device,
403 VkObject object,
Tony Barbour8205d902015-04-16 15:59:00 -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
Tony Barbour8205d902015-04-16 15:59:00 -0600414 tag = intel_alloc(base, tagSize, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800415 if (!tag)
Tony Barbour8205d902015-04-16 15:59:00 -0600416 return VK_ERROR_OUT_OF_HOST_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}