blob: c382a67b111e1b36502e456273b0a33ac4331add [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_SAMPLER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060095 shallow_copy = sizeof(VkSamplerCreateInfo);
Chia-I Wu28b89962014-08-18 14:40:49 +080096 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_OBJECT_TYPE_DESCRIPTOR_SET:
Chia-I Wuf8385062015-01-04 16:27:24 +080098 /* no create info */
Chia-I Wub8d04c82014-08-18 15:51:10 +080099 break;
Tony Barbour2a199c12015-07-09 17:31:46 -0600100 case VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE:
Tony Barbourde4124d2015-07-03 10:33:54 -0600101 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO);
102 shallow_copy = sizeof(VkDynamicViewportStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800103 break;
Cody Northrope4bc6942015-08-26 10:01:32 -0600104 case VK_OBJECT_TYPE_DYNAMIC_LINE_WIDTH_STATE:
105 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_LINE_WIDTH_STATE_CREATE_INFO);
106 shallow_copy = sizeof(VkDynamicLineWidthStateCreateInfo);
Cody Northropf5bd2252015-08-17 11:10:49 -0600107 break;
Cody Northrope4bc6942015-08-26 10:01:32 -0600108 case VK_OBJECT_TYPE_DYNAMIC_DEPTH_BIAS_STATE:
109 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_BIAS_STATE_CREATE_INFO);
110 shallow_copy = sizeof(VkDynamicDepthBiasStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800111 break;
Cody Northrope4bc6942015-08-26 10:01:32 -0600112 case VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE:
113 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_BLEND_STATE_CREATE_INFO);
114 shallow_copy = sizeof(VkDynamicBlendStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800115 break;
Cody Northrope4bc6942015-08-26 10:01:32 -0600116 case VK_OBJECT_TYPE_DYNAMIC_DEPTH_BOUNDS_STATE:
117 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_BOUNDS_STATE_CREATE_INFO);
118 shallow_copy = sizeof(VkDynamicDepthBoundsStateCreateInfo);
Cody Northrop2605cb02015-08-18 15:21:16 -0600119 break;
120 case VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE:
121 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DYNAMIC_STENCIL_STATE_CREATE_INFO);
122 shallow_copy = sizeof(VkDynamicStencilStateCreateInfo);
Chia-I Wua5714e82014-08-11 15:33:42 +0800123 break;
Courtney Goeltzenleuchter445be8d2015-07-24 09:02:54 -0600124 case VK_OBJECT_TYPE_CMD_POOL:
125 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO);
126 shallow_copy = sizeof(VkCmdPoolCreateInfo);
127 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600129 assert(info.header->struct_type == VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130 shallow_copy = sizeof(VkCmdBufferCreateInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800131 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 case VK_OBJECT_TYPE_PIPELINE:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600133 assert(info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600134 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600135 case VK_OBJECT_TYPE_SHADER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 assert(info.header->struct_type == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 shallow_copy = sizeof(VkShaderCreateInfo);
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -0600138 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600139 case VK_OBJECT_TYPE_FRAMEBUFFER:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140 assert(info.header->struct_type == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 shallow_copy = sizeof(VkFramebufferCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700142 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600143 case VK_OBJECT_TYPE_RENDER_PASS:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600144 assert(info.header->struct_type == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600145 shallow_copy = sizeof(VkRenderPassCreateInfo);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700146 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600147 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
Chia-I Wuf8385062015-01-04 16:27:24 +0800149 /* TODO */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 shallow_copy = sizeof(VkDescriptorSetLayoutCreateInfo) * 0;
Chia-I Wuf8385062015-01-04 16:27:24 +0800151 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600152 case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 assert(info.header->struct_type == VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600154 shallow_copy = sizeof(VkDescriptorPoolCreateInfo);
Chia-I Wuf8385062015-01-04 16:27:24 +0800155 break;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800156 default:
Chia-I Wu545c2e12015-02-22 13:19:54 +0800157 assert(!"unknown dbg object type");
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800158 return false;
159 break;
160 }
161
162 if (shallow_copy) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800163 dbg->create_info = intel_alloc(handle, shallow_copy, 0,
Tony Barbour8205d902015-04-16 15:59:00 -0600164 VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800165 if (!dbg->create_info)
166 return false;
167
168 memcpy(dbg->create_info, create_info, shallow_copy);
Chia-I Wue2934f92014-08-16 13:17:22 +0800169 dbg->create_info_size = shallow_copy;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800170 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600172 size_t size;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500173 const VkMemoryAllocInfo *src = info.ptr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600174 VkMemoryAllocInfo *dst;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700175 uint8_t *d;
176 size = sizeof(*src);
177
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700178 dbg->create_info_size = size;
Tony Barbour8205d902015-04-16 15:59:00 -0600179 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700180 if (!dst)
181 return false;
182 memcpy(dst, src, sizeof(*src));
183
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700184 d = (uint8_t *) dst;
185 d += sizeof(*src);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500186
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700187 dbg->create_info = dst;
188 } else if (info.header->struct_type ==
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600189 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600190 const VkDeviceCreateInfo *src = info.ptr;
191 VkDeviceCreateInfo *dst;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800192 uint8_t *d;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600193 size_t size;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800194
195 size = sizeof(*src);
Chia-I Wue2934f92014-08-16 13:17:22 +0800196 dbg->create_info_size = size;
197
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800198 size += sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600199 size += sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
200 for (uint32_t i = 0; i < src->extensionCount; i++) {
201 size += strlen(src->ppEnabledExtensionNames[i]) + 1;
202 }
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800203
Tony Barbour8205d902015-04-16 15:59:00 -0600204 dst = intel_alloc(handle, size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800205 if (!dst)
206 return false;
207
208 memcpy(dst, src, sizeof(*src));
209
210 d = (uint8_t *) dst;
211 d += sizeof(*src);
212
213 size = sizeof(src->pRequestedQueues[0]) * src->queueRecordCount;
214 memcpy(d, src->pRequestedQueues, size);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600215 dst->pRequestedQueues = (const VkDeviceQueueCreateInfo *) d;
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800216 d += size;
217
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600218 size = sizeof(src->ppEnabledExtensionNames[0]) * src->extensionCount;
219 dst->ppEnabledExtensionNames = (const char **) d;
220 memcpy(d, src->ppEnabledExtensionNames, size);
221 d += size;
222 for (uint32_t i = 0; i < src->extensionCount; i++) {
223 char **ptr = (char **) &dst->ppEnabledExtensionNames[i];
224 strcpy((char *) d, src->ppEnabledExtensionNames[i]);
225 *ptr = (char *) d;
226 d += strlen(src->ppEnabledExtensionNames[i]) + 1;
227 }
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800228
Courtney Goeltzenleuchter191b06c2014-10-17 16:21:35 -0600229 dbg->create_info = dst;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600230 } else if (info.header->struct_type == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600231 // TODO: What do we want to copy here?
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800232 }
233
234 return true;
235}
236
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800237/**
Chia-I Wubbf2c932014-08-07 12:20:08 +0800238 * Create an intel_base_dbg. When dbg_size is non-zero, a buffer of that
Chia-I Wu660caf82014-08-07 10:54:26 +0800239 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800240 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800241struct intel_base_dbg *intel_base_dbg_create(const struct intel_handle *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -0600242 VkDbgObjectType type,
Chia-I Wu660caf82014-08-07 10:54:26 +0800243 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 size_t dbg_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800245{
Chia-I Wu660caf82014-08-07 10:54:26 +0800246 struct intel_base_dbg *dbg;
247
Chia-I Wubbf2c932014-08-07 12:20:08 +0800248 if (!dbg_size)
249 dbg_size = sizeof(*dbg);
Chia-I Wu660caf82014-08-07 10:54:26 +0800250
Chia-I Wubbf2c932014-08-07 12:20:08 +0800251 assert(dbg_size >= sizeof(*dbg));
Chia-I Wu660caf82014-08-07 10:54:26 +0800252
Tony Barbour8205d902015-04-16 15:59:00 -0600253 dbg = intel_alloc(handle, dbg_size, 0, VK_SYSTEM_ALLOC_TYPE_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +0800254 if (!dbg)
255 return NULL;
256
Chia-I Wubbf2c932014-08-07 12:20:08 +0800257 memset(dbg, 0, dbg_size);
Chia-I Wu660caf82014-08-07 10:54:26 +0800258
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800259 dbg->type = type;
260
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800261 if (!base_dbg_copy_create_info(handle, dbg, create_info)) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800262 intel_free(handle, dbg);
Chia-I Wu1f8fc7c2014-08-07 11:09:11 +0800263 return NULL;
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800264 }
265
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800266 return dbg;
267}
268
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800269void intel_base_dbg_destroy(const struct intel_handle *handle,
270 struct intel_base_dbg *dbg)
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800271{
Chia-I Wu660caf82014-08-07 10:54:26 +0800272 if (dbg->tag)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800273 intel_free(handle, dbg->tag);
Chia-I Wu660caf82014-08-07 10:54:26 +0800274
275 if (dbg->create_info)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800276 intel_free(handle, dbg->create_info);
Chia-I Wu660caf82014-08-07 10:54:26 +0800277
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800278 intel_free(handle, dbg);
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800279}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800280
Chia-I Wubbf2c932014-08-07 12:20:08 +0800281/**
282 * Create an intel_base. obj_size and dbg_size specify the real sizes of the
283 * object and the debug metadata. Memories are zeroed.
284 */
Chia-I Wu545c2e12015-02-22 13:19:54 +0800285struct intel_base *intel_base_create(const struct intel_handle *handle,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600286 size_t obj_size, bool debug,
Tony Barbourde4124d2015-07-03 10:33:54 -0600287 VkDbgObjectType type,
Chia-I Wubbf2c932014-08-07 12:20:08 +0800288 const void *create_info,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600289 size_t dbg_size)
Chia-I Wubbf2c932014-08-07 12:20:08 +0800290{
291 struct intel_base *base;
292
293 if (!obj_size)
294 obj_size = sizeof(*base);
295
296 assert(obj_size >= sizeof(*base));
297
Tony Barbour8205d902015-04-16 15:59:00 -0600298 base = intel_alloc(handle, obj_size, 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800299 if (!base)
300 return NULL;
301
Chia-I Wu778a80c2015-01-03 22:45:10 +0800302 memset(base, 0, obj_size);
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -0600303 intel_handle_init(&base->handle, type, handle->instance);
Chia-I Wu778a80c2015-01-03 22:45:10 +0800304
Chia-I Wubbf2c932014-08-07 12:20:08 +0800305 if (debug) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800306 base->dbg = intel_base_dbg_create(&base->handle,
Chia-I Wu545c2e12015-02-22 13:19:54 +0800307 type, create_info, dbg_size);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800308 if (!base->dbg) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800309 intel_free(handle, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800310 return NULL;
311 }
312 }
Chia-I Wu6a42c2a2014-08-19 14:36:47 +0800313
Tony Barbour426b9052015-06-24 16:06:58 -0600314 base->get_memory_requirements = intel_base_get_memory_requirements;
Chia-I Wubbf2c932014-08-07 12:20:08 +0800315
316 return base;
317}
318
319void intel_base_destroy(struct intel_base *base)
320{
321 if (base->dbg)
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800322 intel_base_dbg_destroy(&base->handle, base->dbg);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800323 intel_free(base, base);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800324}
325
Tony Barbourde4124d2015-07-03 10:33:54 -0600326ICD_EXPORT VkResult VKAPI vkGetBufferMemoryRequirements(
Mike Stroyan230e6252015-04-17 12:36:38 -0600327 VkDevice device,
Tony Barbourde4124d2015-07-03 10:33:54 -0600328 VkBuffer buffer,
Tony Barbour426b9052015-06-24 16:06:58 -0600329 VkMemoryRequirements* pRequirements)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800330{
Tony Barbourde4124d2015-07-03 10:33:54 -0600331 struct intel_base *base = intel_base(buffer.handle);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800332
Tony Barbour426b9052015-06-24 16:06:58 -0600333 return base->get_memory_requirements(base, pRequirements);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800334}
335
Tony Barbourde4124d2015-07-03 10:33:54 -0600336ICD_EXPORT VkResult VKAPI vkGetImageMemoryRequirements(
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500337 VkDevice device,
Tony Barbourde4124d2015-07-03 10:33:54 -0600338 VkImage image,
339 VkMemoryRequirements* pRequirements)
340{
341 struct intel_base *base = intel_base(image.handle);
342
343 return base->get_memory_requirements(base, pRequirements);
344}
345
346ICD_EXPORT VkResult VKAPI vkBindBufferMemory(
347 VkDevice device,
348 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600349 VkDeviceMemory mem_,
350 VkDeviceSize memOffset)
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800351{
Tony Barbourde4124d2015-07-03 10:33:54 -0600352 struct intel_obj *obj = intel_obj(buffer.handle);
353 struct intel_mem *mem = intel_mem(mem_);
354
355 intel_obj_bind_mem(obj, mem, memOffset);
356
357 return VK_SUCCESS;
358}
359
360ICD_EXPORT VkResult VKAPI vkBindImageMemory(
361 VkDevice device,
362 VkImage image,
363 VkDeviceMemory mem_,
364 VkDeviceSize memOffset)
365{
366 struct intel_obj *obj = intel_obj(image.handle);
Chia-I Wu9e61c0d2014-09-15 15:12:06 +0800367 struct intel_mem *mem = intel_mem(mem_);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800368
Chia-I Wu714df452015-01-01 07:55:04 +0800369 intel_obj_bind_mem(obj, mem, memOffset);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800370
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600371 return VK_SUCCESS;
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800372}
Chia-I Wu7ec9f342014-08-19 10:47:53 +0800373
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500374ICD_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mike Stroyan230e6252015-04-17 12:36:38 -0600375 VkQueue queue,
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500376 VkBuffer buffer,
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600377 uint32_t numBindings,
378 const VkSparseMemoryBindInfo* pBindInfo)
Chia-I Wu714df452015-01-01 07:55:04 +0800379{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600380 assert(0 && "vkQueueBindSparseBufferMemory not supported");
381 return VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +0800382}
383
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600384ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageOpaqueMemory(
385 VkQueue queue,
386 VkImage image,
387 uint32_t numBindings,
388 const VkSparseMemoryBindInfo* pBindInfo)
389{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600390 assert(0 && "vkQueueBindSparseImageOpaqueMemory not supported");
391 return VK_SUCCESS;
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600392}
393
394
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500395ICD_EXPORT VkResult VKAPI vkQueueBindSparseImageMemory(
Tony Barbour8205d902015-04-16 15:59:00 -0600396 VkQueue queue,
397 VkImage image,
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600398 uint32_t numBindings,
399 const VkSparseImageMemoryBindInfo* pBindInfo)
Chia-I Wu714df452015-01-01 07:55:04 +0800400{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600401 assert(0 && "vkQueueBindSparseImageMemory not supported");
402 return VK_SUCCESS;
Chia-I Wu714df452015-01-01 07:55:04 +0800403}
404