blob: fc70a30850e6e91a8e1c77712467431b9babc6fc [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"
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060032#include "vk_debug_marker_lunarg.h"
Chia-I Wu82f50aa2014-08-05 10:43:03 +080033
Tony Barbour426b9052015-06-24 16:06:58 -060034VkResult intel_base_get_memory_requirements(struct intel_base *base, VkMemoryRequirements* pRequirements)
Chia-I Wu26f0bd02014-08-07 10:38:40 +080035{
Tony Barbour426b9052015-06-24 16:06:58 -060036 memset(pRequirements, 0, sizeof(VkMemoryRequirements));
Mark Lobodzinski72346292015-07-02 16:49:40 -060037 pRequirements->memoryTypeBits = (1<< INTEL_MEMORY_TYPE_COUNT) - 1;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080038
Tony Barbour426b9052015-06-24 16:06:58 -060039 return VK_SUCCESS;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080040}
41
Chia-I Wuf13ed3c2015-02-22 14:09:00 +080042static bool base_dbg_copy_create_info(const struct intel_handle *handle,
43 struct intel_base_dbg *dbg,
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080044 const void *create_info)
45{
46 const union {
47 const void *ptr;
48 const struct {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060049 VkStructureType struct_type;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060050 void *next;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080051 } *header;
52 } info = { .ptr = create_info };
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060053 size_t shallow_copy = 0;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080054
55 if (!create_info)
56 return true;
57
Chia-I Wub1076d72014-08-18 16:10:20 +080058 switch (dbg->type) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060059 case VK_OBJECT_TYPE_DEVICE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060060 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080061 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060062 case VK_OBJECT_TYPE_DEVICE_MEMORY:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063 assert(info.header->struct_type == VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080064 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060065 case VK_OBJECT_TYPE_EVENT:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060066 assert(info.header->struct_type == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060067 shallow_copy = sizeof(VkEventCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080068 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060069 case VK_OBJECT_TYPE_FENCE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060070 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060071 shallow_copy = sizeof(VkFenceCreateInfo);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +080072 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060073 case VK_OBJECT_TYPE_QUERY_POOL:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060074 assert(info.header->struct_type == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060075 shallow_copy = sizeof(VkQueryPoolCreateInfo);
Courtney Goeltzenleuchter850d12c2014-08-07 18:13:10 -060076 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060077 case VK_OBJECT_TYPE_BUFFER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060079 shallow_copy = sizeof(VkBufferCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +080080 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060081 case VK_OBJECT_TYPE_BUFFER_VIEW:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060082 assert(info.header->struct_type == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060083 shallow_copy = sizeof(VkBufferViewCreateInfo);
Chia-I Wu714df452015-01-01 07:55:04 +080084 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060085 case VK_OBJECT_TYPE_IMAGE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060086 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060087 shallow_copy = sizeof(VkImageCreateInfo);
Chia-I Wufeb441f2014-08-08 21:27:38 +080088 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060089 case VK_OBJECT_TYPE_IMAGE_VIEW:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090 assert(info.header->struct_type == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091 shallow_copy = sizeof(VkImageViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +080092 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060093 case VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 assert(info.header->struct_type == VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060095 shallow_copy = sizeof(VkColorAttachmentViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +080096 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060099 shallow_copy = sizeof(VkDepthStencilViewCreateInfo);
Chia-I Wu5a323262014-08-11 10:31:53 +0800100 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600101 case VK_OBJECT_TYPE_SAMPLER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600103 shallow_copy = sizeof(VkSamplerCreateInfo);
Chia-I Wu28b89962014-08-18 14:40:49 +0800104 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 case VK_OBJECT_TYPE_DESCRIPTOR_SET:
Chia-I Wuf8385062015-01-04 16:27:24 +0800106 /* no create info */
Chia-I Wub8d04c82014-08-18 15:51:10 +0800107 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600108 case VK_OBJECT_TYPE_DYNAMIC_VP_STATE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600109 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600110 shallow_copy = sizeof(VkDynamicVpStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800111 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600112 case VK_OBJECT_TYPE_DYNAMIC_RS_STATE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600114 shallow_copy = sizeof(VkDynamicRsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800115 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600116 case VK_OBJECT_TYPE_DYNAMIC_CB_STATE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600117 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600118 shallow_copy = sizeof(VkDynamicCbStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800119 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600120 case VK_OBJECT_TYPE_DYNAMIC_DS_STATE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600121 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 shallow_copy = sizeof(VkDynamicDsStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800123 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600124 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600125 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600126 shallow_copy = sizeof(VkCmdBufferCreateInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800127 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128 case VK_OBJECT_TYPE_PIPELINE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600129 assert(info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600130 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600131 case VK_OBJECT_TYPE_SHADER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600132 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600133 shallow_copy = sizeof(VkShaderCreateInfo);
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -0600134 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600135 case VK_OBJECT_TYPE_FRAMEBUFFER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 shallow_copy = sizeof(VkFramebufferCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700138 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600139 case VK_OBJECT_TYPE_RENDER_PASS:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140 assert(info.header->struct_type == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 shallow_copy = sizeof(VkRenderPassCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700142 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600143 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600144 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
Chia-I Wuf8385062015-01-04 16:27:24 +0800145 /* TODO */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600146 shallow_copy = sizeof(VkDescriptorSetLayoutCreateInfo) * 0;
Chia-I Wuf8385062015-01-04 16:27:24 +0800147 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600148 case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600149 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 shallow_copy = sizeof(VkDescriptorPoolCreateInfo);
Chia-I Wuf8385062015-01-04 16:27:24 +0800151 break;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800152 default:
Chia-I Wu545c2e12015-02-22 13:19:54 +0800153 assert(!"unknown dbg object type");
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800154 return false;
155 break;
156 }
157
158 if (shallow_copy) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800159 dbg->create_info = intel_alloc(handle, shallow_copy, 0,
Tony Barbour8205d902015-04-16 15:59:00 -0600160 VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800161 if (!dbg->create_info)
162 return false;
163
164 memcpy(dbg->create_info, create_info, shallow_copy);
Chia-I Wue2934f92014-08-16 13:17:22 +0800165 dbg->create_info_size = shallow_copy;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800166 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600167 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600168 size_t size;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500169 const VkMemoryAllocInfo *src = info.ptr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600170 VkMemoryAllocInfo *dst;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700171 uint8_t *d;
172 size = sizeof(*src);
173
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700174 dbg->create_info_size = size;
Tony Barbour8205d902015-04-16 15:59:00 -0600175 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700176 if (!dst)
177 return false;
178 memcpy(dst, src, sizeof(*src));
179
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700180 d = (uint8_t *) dst;
181 d += sizeof(*src);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500182
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700183 dbg->create_info = dst;
184 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600185 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600186 const VkDeviceCreateInfo *src = info.ptr;
187 VkDeviceCreateInfo *dst;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800188 uint8_t *d;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600189 size_t size;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800190
191 size = sizeof(*src);
Chia-I Wue2934f92014-08-16 13:17:22 +0800192 dbg->create_info_size = size;
193
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800194 size += sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600195 size += sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
196 for (uint32_t i = 0; i < src->extensionCount; i++) {
197 size += strlen(src->ppEnabledExtensionNames[i]) + 1;
198 }
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800199
Tony Barbour8205d902015-04-16 15:59:00 -0600200 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800201 if (!dst)
202 return false;
203
204 memcpy(dst, src, sizeof(*src));
205
206 d = (uint8_t *) dst;
207 d += sizeof(*src);
208
209 size = sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
210 memcpy(d, src->pRequestedQueues, size);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600211 dst->pRequestedQueues = (const VkDeviceQueueCreateInfo *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800212 d += size;
213
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600214 size = sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
215 dst->ppEnabledExtensionNames = (const char **) d;
216 memcpy(d, src->ppEnabledExtensionNames, size);
217 d += size;
218 for (uint32_t i = 0; i < src->extensionCount; i++) {
219 char **ptr = (char **) &dst->ppEnabledExtensionNames[i];
220 strcpy((char *) d, src->ppEnabledExtensionNames[i]);
221 *ptr = (char *) d;
222 d += strlen(src->ppEnabledExtensionNames[i]) + 1;
223 }
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800224
Courtney Goeltzenleuchter191b06c2014-10-17 16:21:35 -0600225 dbg->create_info = dst;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600226 } else if (info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600227 // TODO: What do we want to copy here?
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800228 }
229
230 return true;
231}
232
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800233/**
Chia-I Wubbf2c932014-08-07 12:20:08 +0800234 * Create an intel_base_dbg. When dbg_size is non-zero, a buffer of that
Chia-I Wu660caf82014-08-07 10:54:26 +0800235 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800236 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800237struct intel_base_dbg *intel_base_dbg_create(const struct intel_handle *handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600238 VkObjectType type,
Chia-I Wu660caf82014-08-07 10:54:26 +0800239 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600240 size_t dbg_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800241{
Chia-I Wu660caf82014-08-07 10:54:26 +0800242 struct intel_base_dbg *dbg;
243
Chia-I Wubbf2c932014-08-07 12:20:08 +0800244 if (!dbg_size)
245 dbg_size = sizeof(*dbg);
Chia-I Wu660caf82014-08-07 10:54:26 +0800246
Chia-I Wubbf2c932014-08-07 12:20:08 +0800247 assert(dbg_size >= sizeof(*dbg));
Chia-I Wu660caf82014-08-07 10:54:26 +0800248
Tony Barbour8205d902015-04-16 15:59:00 -0600249 dbg = intel_alloc(handle, dbg_size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +0800250 if (!dbg)
251 return NULL;
252
Chia-I Wubbf2c932014-08-07 12:20:08 +0800253 memset(dbg, 0, dbg_size);
Chia-I Wu660caf82014-08-07 10:54:26 +0800254
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800255 dbg->type = type;
256
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800257 if (!base_dbg_copy_create_info(handle, dbg, create_info)) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800258 intel_free(handle, dbg);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800259 return NULL;
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800260 }
261
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800262 return dbg;
263}
264
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800265void intel_base_dbg_destroy(const struct intel_handle *handle,
266 struct intel_base_dbg *dbg)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800267{
Chia-I Wu660caf82014-08-07 10:54:26 +0800268 if (dbg->tag)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800269 intel_free(handle, dbg->tag);
Chia-I Wu660caf82014-08-07 10:54:26 +0800270
271 if (dbg->create_info)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800272 intel_free(handle, dbg->create_info);
Chia-I Wu660caf82014-08-07 10:54:26 +0800273
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800274 intel_free(handle, dbg);
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800275}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800276
Chia-I Wubbf2c932014-08-07 12:20:08 +0800277/**
278 * Create an intel_base. obj_size and dbg_size specify the real sizes of the
279 * object and the debug metadata. Memories are zeroed.
280 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800281struct intel_base *intel_base_create(const struct intel_handle *handle,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600282 size_t obj_size, bool debug,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600283 VkObjectType type,
Chia-I Wubbf2c932014-08-07 12:20:08 +0800284 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600285 size_t dbg_size)
Chia-I Wubbf2c932014-08-07 12:20:08 +0800286{
287 struct intel_base *base;
288
289 if (!obj_size)
290 obj_size = sizeof(*base);
291
292 assert(obj_size >= sizeof(*base));
293
Tony Barbour8205d902015-04-16 15:59:00 -0600294 base = intel_alloc(handle, obj_size, 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800295 if (!base)
296 return NULL;
297
Chia-I Wu778a80c2015-01-03 22:45:10 +0800298 memset(base, 0, obj_size);
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -0600299 intel_handle_init(&base->handle, type, handle->instance);
Chia-I Wu778a80c2015-01-03 22:45:10 +0800300
Chia-I Wubbf2c932014-08-07 12:20:08 +0800301 if (debug) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800302 base->dbg = intel_base_dbg_create(&base->handle,
Chia-I Wu545c2e12015-02-22 13:19:54 +0800303 type, create_info, dbg_size);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800304 if (!base->dbg) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800305 intel_free(handle, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800306 return NULL;
307 }
308 }
Chia-I Wu6a42c2a2014-08-19 14:36:47 +0800309
Tony Barbour426b9052015-06-24 16:06:58 -0600310 base->get_memory_requirements = intel_base_get_memory_requirements;
Chia-I Wubbf2c932014-08-07 12:20:08 +0800311
312 return base;
313}
314
315void intel_base_destroy(struct intel_base *base)
316{
317 if (base->dbg)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800318 intel_base_dbg_destroy(&base->handle, base->dbg);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800319 intel_free(base, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800320}
321
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600322ICD_EXPORT VkResult VKAPI vkDestroyObject(
Mike Stroyan230e6252015-04-17 12:36:38 -0600323 VkDevice device,
324 VkObjectType objType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600325 VkObject object)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800326{
327 struct intel_obj *obj = intel_obj(object);
328
329 obj->destroy(obj);
330
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600331 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800332}
333
Tony Barbour426b9052015-06-24 16:06:58 -0600334ICD_EXPORT VkResult VKAPI vkGetObjectMemoryRequirements(
Mike Stroyan230e6252015-04-17 12:36:38 -0600335 VkDevice device,
336 VkObjectType objType,
337 VkObject object,
Tony Barbour426b9052015-06-24 16:06:58 -0600338 VkMemoryRequirements* pRequirements)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800339{
340 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800341
Tony Barbour426b9052015-06-24 16:06:58 -0600342 return base->get_memory_requirements(base, pRequirements);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800343}
344
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500345ICD_EXPORT VkResult VKAPI vkBindObjectMemory(
346 VkDevice device,
Mike Stroyan230e6252015-04-17 12:36:38 -0600347 VkObjectType objType,
348 VkObject object,
Tony Barbour8205d902015-04-16 15:59:00 -0600349 VkDeviceMemory mem_,
350 VkDeviceSize memOffset)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800351{
352 struct intel_obj *obj = intel_obj(object);
Chia-I Wu9e61c0d2014-09-15 15:12:06 +0800353 struct intel_mem *mem = intel_mem(mem_);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800354
Chia-I Wu714df452015-01-01 07:55:04 +0800355 intel_obj_bind_mem(obj, mem, memOffset);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800356
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600357 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800358}
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800359
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500360ICD_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -0600361 VkQueue queue,
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500362 VkBuffer buffer,
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600363 uint32_t numBindings,
364 const VkSparseMemoryBindInfo* pBindInfo)
Chia-I Wu714df452015-01-01 07:55:04 +0800365{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800367}
368
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600369ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageOpaqueMemory(
370 VkQueue queue,
371 VkImage image,
372 uint32_t numBindings,
373 const VkSparseMemoryBindInfo* pBindInfo)
374{
375 return VK_ERROR_UNKNOWN;
376}
377
378
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500379ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageMemory(
Tony Barbour8205d902015-04-16 15:59:00 -0600380 VkQueue queue,
381 VkImage image,
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600382 uint32_t numBindings,
383 const VkSparseImageMemoryBindInfo* pBindInfo)
Chia-I Wu714df452015-01-01 07:55:04 +0800384{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385 return VK_ERROR_UNKNOWN;
Chia-I Wu714df452015-01-01 07:55:04 +0800386}
387