blob: da7a39471c17868c19fb7d39ce2485437cdede69 [file] [log] [blame]
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001/*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include <assert.h>
25#include <stdbool.h>
26#include <string.h>
27#include <unistd.h>
28#include <fcntl.h>
29
Chad Versace2c2233e2015-07-17 15:04:27 -070030#include "anv_private.h"
Jason Ekstrand977a4692015-07-09 15:53:03 -070031#include "mesa/main/git_sha1.h"
Jason Ekstrand6a7ca4e2015-08-14 17:25:04 -070032#include "util/strtod.h"
Jason Ekstrande45748b2016-01-20 11:16:44 -080033#include "util/debug.h"
Kristian Høgsberg769785c2015-05-08 22:32:37 -070034
Jason Ekstrandf6d95872016-02-18 10:19:02 -080035#include "genxml/gen7_pack.h"
Jason Ekstrandde54b4b2015-11-16 12:29:07 -080036
Jason Ekstranda95f51c2015-09-24 14:20:35 -070037struct anv_dispatch_table dtable;
38
Jason Ekstranda71e6142015-10-19 22:06:59 -070039static void
40compiler_debug_log(void *data, const char *fmt, ...)
41{ }
42
43static void
44compiler_perf_log(void *data, const char *fmt, ...)
45{
46 va_list args;
47 va_start(args, fmt);
48
49 if (unlikely(INTEL_DEBUG & DEBUG_PERF))
50 vfprintf(stderr, fmt, args);
51
52 va_end(args);
53}
54
Kristian Høgsberg769785c2015-05-08 22:32:37 -070055static VkResult
Chad Versace4422bd42015-07-09 16:22:18 -070056anv_physical_device_init(struct anv_physical_device *device,
57 struct anv_instance *instance,
58 const char *path)
Kristian Høgsberg769785c2015-05-08 22:32:37 -070059{
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -070060 VkResult result;
Kristian Høgsberg Kristensen9564dd32015-07-21 13:09:25 -070061 int fd;
62
63 fd = open(path, O_RDWR | O_CLOEXEC);
64 if (fd < 0)
Chad Versacef9c948e2015-10-07 11:36:51 -070065 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
66 "failed to open %s: %m", path);
Kristian Høgsberg769785c2015-05-08 22:32:37 -070067
Jason Ekstrand39cd3782015-09-24 13:51:40 -070068 device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
Kristian Høgsberg769785c2015-05-08 22:32:37 -070069 device->instance = instance;
Jason Ekstrande023c102016-05-24 11:02:18 -070070
71 assert(strlen(path) < ARRAY_SIZE(device->path));
72 strncpy(device->path, path, ARRAY_SIZE(device->path));
Chad Versacef9c948e2015-10-07 11:36:51 -070073
Kristian Høgsberg Kristensenaac6f7c2015-08-14 09:39:01 -070074 device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID);
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -070075 if (!device->chipset_id) {
Jason Ekstrandb93b5932016-05-24 12:06:35 -070076 result = VK_ERROR_INITIALIZATION_FAILED;
Kristian Høgsberg769785c2015-05-08 22:32:37 -070077 goto fail;
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -070078 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -070079
80 device->name = brw_get_device_name(device->chipset_id);
Jason Ekstrandb00e3f22015-11-03 15:45:04 -080081 device->info = brw_get_device_info(device->chipset_id);
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -070082 if (!device->info) {
Chad Versacef9c948e2015-10-07 11:36:51 -070083 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
84 "failed to get device info");
Kristian Høgsberg769785c2015-05-08 22:32:37 -070085 goto fail;
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -070086 }
Jason Ekstrand584f9d42015-11-02 12:14:37 -080087
Jason Ekstrandf0390bc2015-11-17 07:07:02 -080088 if (device->info->is_haswell) {
89 fprintf(stderr, "WARNING: Haswell Vulkan support is incomplete\n");
90 } else if (device->info->gen == 7 && !device->info->is_baytrail) {
Jason Ekstrand862da6a2015-11-09 12:18:12 -080091 fprintf(stderr, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
Kristian Høgsbergdac57752015-12-01 15:39:30 -080092 } else if (device->info->gen == 7 && device->info->is_baytrail) {
93 fprintf(stderr, "WARNING: Bay Trail Vulkan support is incomplete\n");
Kristian Høgsberg Kristensen7c5e1fd2016-01-08 22:24:58 -080094 } else if (device->info->gen >= 8) {
95 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
96 * supported as anything */
Jason Ekstrand584f9d42015-11-02 12:14:37 -080097 } else {
Jason Ekstrandfed35862015-12-02 16:14:58 -080098 result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
Jason Ekstrand584f9d42015-11-02 12:14:37 -080099 "Vulkan not yet supported on %s", device->name);
100 goto fail;
101 }
102
Jordan Justen1a3adae2016-03-28 14:45:24 -0700103 device->cmd_parser_version = -1;
104 if (device->info->gen == 7) {
105 device->cmd_parser_version =
106 anv_gem_get_param(fd, I915_PARAM_CMD_PARSER_VERSION);
107 if (device->cmd_parser_version == -1) {
108 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
109 "failed to get command parser version");
110 goto fail;
111 }
112 }
113
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700114 if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) {
Chad Versacef9c948e2015-10-07 11:36:51 -0700115 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
116 "failed to get aperture size: %m");
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700117 goto fail;
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700118 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700119
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700120 if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) {
Chad Versacef9c948e2015-10-07 11:36:51 -0700121 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
122 "kernel missing gem wait");
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700123 goto fail;
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700124 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700125
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700126 if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) {
Chad Versacef9c948e2015-10-07 11:36:51 -0700127 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
128 "kernel missing execbuf2");
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700129 goto fail;
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700130 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700131
Kristian Høgsberg Kristensen220ac932015-12-19 22:25:57 -0800132 if (!device->info->has_llc &&
133 anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) {
Kristian Høgsberg Kristensenbbb68752015-12-03 23:58:05 -0800134 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
135 "kernel missing wc mmap");
136 goto fail;
137 }
138
Jason Ekstrand580b2e82016-01-05 13:53:05 -0800139 bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X);
140
Kristian Høgsberg Kristensen9564dd32015-07-21 13:09:25 -0700141 close(fd);
142
Jason Ekstranda71e6142015-10-19 22:06:59 -0700143 brw_process_intel_debug_variable();
144
Jason Ekstrand6fb44692015-10-19 20:21:45 -0700145 device->compiler = brw_compiler_create(NULL, device->info);
146 if (device->compiler == NULL) {
147 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
148 goto fail;
149 }
Jason Ekstranda71e6142015-10-19 22:06:59 -0700150 device->compiler->shader_debug_log = compiler_debug_log;
151 device->compiler->shader_perf_log = compiler_perf_log;
Jason Ekstrand6fb44692015-10-19 20:21:45 -0700152
Jason Ekstrandeb6baa32016-05-15 22:21:24 -0700153 anv_init_wsi(device);
154
Jason Ekstrand580b2e82016-01-05 13:53:05 -0800155 /* XXX: Actually detect bit6 swizzling */
156 isl_device_init(&device->isl_dev, device->info, swizzled);
Chad Versaceaf392912015-11-13 10:12:51 -0800157
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700158 return VK_SUCCESS;
Chad Versace477383e2015-11-13 10:12:18 -0800159
Chad Versace8cda3e92015-07-09 16:31:39 -0700160fail:
Kristian Høgsberg Kristensen9564dd32015-07-21 13:09:25 -0700161 close(fd);
Kristian Høgsberg Kristensenc4b30e72015-08-26 04:03:38 -0700162 return result;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700163}
164
Jason Ekstrand6fb44692015-10-19 20:21:45 -0700165static void
166anv_physical_device_finish(struct anv_physical_device *device)
167{
Jason Ekstrandeb6baa32016-05-15 22:21:24 -0700168 anv_finish_wsi(device);
Jason Ekstrand6fb44692015-10-19 20:21:45 -0700169 ralloc_free(device->compiler);
170}
171
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700172static const VkExtensionProperties global_extensions[] = {
173 {
Jason Ekstrandd6664872015-12-02 16:28:36 -0800174 .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
Jason Ekstrandc688e4d2016-01-28 15:34:22 -0800175 .specVersion = 25,
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700176 },
Emil Velikov6dc169e2016-04-20 19:15:18 +0100177#ifdef VK_USE_PLATFORM_XCB_KHR
Jason Ekstrandd6664872015-12-02 16:28:36 -0800178 {
179 .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
180 .specVersion = 5,
181 },
Emil Velikov6dc169e2016-04-20 19:15:18 +0100182#endif
Emil Velikovcbc48372016-04-20 19:01:00 +0100183#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jason Ekstrandd6664872015-12-02 16:28:36 -0800184 {
185 .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
186 .specVersion = 4,
187 },
188#endif
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700189};
190
191static const VkExtensionProperties device_extensions[] = {
192 {
Jason Ekstrandd6664872015-12-02 16:28:36 -0800193 .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME,
194 .specVersion = 67,
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700195 },
196};
197
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800198static void *
199default_alloc_func(void *pUserData, size_t size, size_t align,
200 VkSystemAllocationScope allocationScope)
201{
202 return malloc(size);
203}
204
205static void *
206default_realloc_func(void *pUserData, void *pOriginal, size_t size,
207 size_t align, VkSystemAllocationScope allocationScope)
208{
209 return realloc(pOriginal, size);
210}
211
212static void
213default_free_func(void *pUserData, void *pMemory)
214{
215 free(pMemory);
216}
217
218static const VkAllocationCallbacks default_alloc = {
219 .pUserData = NULL,
220 .pfnAllocation = default_alloc_func,
221 .pfnReallocation = default_realloc_func,
222 .pfnFree = default_free_func,
223};
224
Kristian Høgsberg454345d2015-05-17 16:33:48 -0700225VkResult anv_CreateInstance(
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700226 const VkInstanceCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800227 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700228 VkInstance* pInstance)
229{
230 struct anv_instance *instance;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700231
232 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
233
Jason Ekstrandc32273d2016-02-25 08:52:35 -0800234 uint32_t client_version;
235 if (pCreateInfo->pApplicationInfo &&
236 pCreateInfo->pApplicationInfo->apiVersion != 0) {
237 client_version = pCreateInfo->pApplicationInfo->apiVersion;
238 } else {
239 client_version = VK_MAKE_VERSION(1, 0, 0);
240 }
241
Jason Ekstranda19ceee2016-01-28 15:43:44 -0800242 if (VK_MAKE_VERSION(1, 0, 0) > client_version ||
Jason Ekstrand204d9372016-03-22 16:17:09 -0700243 client_version > VK_MAKE_VERSION(1, 0, 0xfff)) {
Jason Ekstrandfd99f3d2016-02-02 13:15:18 -0800244 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
245 "Client requested version %d.%d.%d",
246 VK_VERSION_MAJOR(client_version),
247 VK_VERSION_MINOR(client_version),
248 VK_VERSION_PATCH(client_version));
Jason Ekstrand608b4112016-01-28 08:18:50 -0800249 }
Jason Ekstrande21ecb82015-10-12 18:25:19 -0700250
Jason Ekstrandaab95172016-01-14 07:41:45 -0800251 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700252 bool found = false;
253 for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) {
254 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
Jason Ekstrandaadb7dc2015-11-30 21:10:14 -0800255 global_extensions[j].extensionName) == 0) {
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700256 found = true;
257 break;
258 }
259 }
260 if (!found)
Chad Versacef9c948e2015-10-07 11:36:51 -0700261 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700262 }
263
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800264 instance = anv_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
Jason Ekstrand45d17fc2016-01-18 14:04:13 -0800265 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700266 if (!instance)
267 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
268
Jason Ekstrand39cd3782015-09-24 13:51:40 -0700269 instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800270
271 if (pAllocator)
272 instance->alloc = *pAllocator;
273 else
274 instance->alloc = default_alloc;
275
Philipp Zabelecd1d942016-02-16 22:55:33 +0100276 instance->apiVersion = client_version;
Jason Ekstrand584f9d42015-11-02 12:14:37 -0800277 instance->physicalDeviceCount = -1;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700278
Jason Ekstrand6a7ca4e2015-08-14 17:25:04 -0700279 _mesa_locale_init();
280
Jason Ekstrand930598a2015-07-31 10:18:00 -0700281 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
282
Jason Ekstrand098209e2015-07-09 18:41:27 -0700283 *pInstance = anv_instance_to_handle(instance);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700284
285 return VK_SUCCESS;
286}
287
Jason Ekstrand05a26a62015-10-05 20:50:51 -0700288void anv_DestroyInstance(
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800289 VkInstance _instance,
290 const VkAllocationCallbacks* pAllocator)
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700291{
Jason Ekstrand73f91872015-07-09 18:41:27 -0700292 ANV_FROM_HANDLE(anv_instance, instance, _instance);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700293
Chad Versace0ab926d2015-10-21 11:36:39 -0700294 if (instance->physicalDeviceCount > 0) {
295 /* We support at most one physical device. */
296 assert(instance->physicalDeviceCount == 1);
297 anv_physical_device_finish(&instance->physicalDevice);
298 }
299
Jason Ekstrand930598a2015-07-31 10:18:00 -0700300 VG(VALGRIND_DESTROY_MEMPOOL(instance));
301
Jason Ekstrand6a7ca4e2015-08-14 17:25:04 -0700302 _mesa_locale_fini();
303
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800304 anv_free(&instance->alloc, instance);
Jason Ekstrande40bdce2015-07-31 10:13:24 -0700305}
306
Kristian Høgsberg454345d2015-05-17 16:33:48 -0700307VkResult anv_EnumeratePhysicalDevices(
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700308 VkInstance _instance,
309 uint32_t* pPhysicalDeviceCount,
310 VkPhysicalDevice* pPhysicalDevices)
311{
Jason Ekstrand73f91872015-07-09 18:41:27 -0700312 ANV_FROM_HANDLE(anv_instance, instance, _instance);
Chad Versacefa915b62015-07-09 15:38:58 -0700313 VkResult result;
314
Jason Ekstrand584f9d42015-11-02 12:14:37 -0800315 if (instance->physicalDeviceCount < 0) {
Jason Ekstrandb93b5932016-05-24 12:06:35 -0700316 char path[20];
317 for (unsigned i = 0; i < 8; i++) {
318 snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i);
319 result = anv_physical_device_init(&instance->physicalDevice,
320 instance, path);
321 if (result == VK_SUCCESS)
322 break;
323 }
324
Jason Ekstrandfed35862015-12-02 16:14:58 -0800325 if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
Jason Ekstrand584f9d42015-11-02 12:14:37 -0800326 instance->physicalDeviceCount = 0;
327 } else if (result == VK_SUCCESS) {
328 instance->physicalDeviceCount = 1;
329 } else {
Chad Versacefa915b62015-07-09 15:38:58 -0700330 return result;
Jason Ekstrand584f9d42015-11-02 12:14:37 -0800331 }
Chad Versacefa915b62015-07-09 15:38:58 -0700332 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700333
Chad Versace5b75dff2015-07-09 15:51:06 -0700334 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
335 * otherwise it's an inout parameter.
336 *
337 * The Vulkan spec (git aaed022) says:
338 *
339 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
340 * that is initialized with the number of devices the application is
341 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
342 * an array of at least this many VkPhysicalDevice handles [...].
343 *
344 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
345 * overwrites the contents of the variable pointed to by
346 * pPhysicalDeviceCount with the number of physical devices in in the
347 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
348 * pPhysicalDeviceCount with the number of physical handles written to
349 * pPhysicalDevices.
350 */
351 if (!pPhysicalDevices) {
352 *pPhysicalDeviceCount = instance->physicalDeviceCount;
353 } else if (*pPhysicalDeviceCount >= 1) {
Jason Ekstrand098209e2015-07-09 18:41:27 -0700354 pPhysicalDevices[0] = anv_physical_device_to_handle(&instance->physicalDevice);
Chad Versace5b75dff2015-07-09 15:51:06 -0700355 *pPhysicalDeviceCount = 1;
356 } else {
357 *pPhysicalDeviceCount = 0;
358 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700359
360 return VK_SUCCESS;
361}
362
Jason Ekstrandf1a7c782015-11-30 12:21:19 -0800363void anv_GetPhysicalDeviceFeatures(
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700364 VkPhysicalDevice physicalDevice,
365 VkPhysicalDeviceFeatures* pFeatures)
366{
Kristian Høgsberg Kristensen4a2d17f2016-02-15 21:24:40 -0800367 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700368
369 *pFeatures = (VkPhysicalDeviceFeatures) {
Kristian Høgsberg Kristensendc5fdcd2016-02-01 11:54:40 -0800370 .robustBufferAccess = true,
Kristian Høgsberg Kristensen4a2d17f2016-02-15 21:24:40 -0800371 .fullDrawIndexUint32 = true,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700372 .imageCubeArray = false,
Kristian Høgsberg Kristensen4a2d17f2016-02-15 21:24:40 -0800373 .independentBlend = pdevice->info->gen >= 8,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700374 .geometryShader = true,
375 .tessellationShader = false,
376 .sampleRateShading = false,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800377 .dualSrcBlend = true,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700378 .logicOp = true,
Jason Ekstrand802f0022016-01-14 06:58:11 -0800379 .multiDrawIndirect = false,
380 .drawIndirectFirstInstance = false,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800381 .depthClamp = false,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700382 .depthBiasClamp = false,
383 .fillModeNonSolid = true,
384 .depthBounds = false,
385 .wideLines = true,
386 .largePoints = true,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800387 .alphaToOne = true,
388 .multiViewport = true,
389 .samplerAnisotropy = false, /* FINISHME */
Nanley Chery5f7e8ea2016-04-15 13:36:31 -0700390 .textureCompressionETC2 = pdevice->info->gen >= 8 ||
391 pdevice->info->is_baytrail,
Nanley Chery9b8c4002016-05-18 10:50:48 -0700392 .textureCompressionASTC_LDR = pdevice->info->gen >= 9, /* FINISHME CHV */
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700393 .textureCompressionBC = true,
Kristian Høgsberg Kristensen4a2d17f2016-02-15 21:24:40 -0800394 .occlusionQueryPrecise = true,
Kristian Høgsberg Kristensen9d8bae62016-02-29 10:55:39 -0800395 .pipelineStatisticsQuery = false,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800396 .fragmentStoresAndAtomics = true,
397 .shaderTessellationAndGeometryPointSize = true,
Jason Ekstrand51865452016-05-12 10:56:58 -0700398 .shaderImageGatherExtended = false,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700399 .shaderStorageImageExtendedFormats = false,
400 .shaderStorageImageMultisample = false,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700401 .shaderUniformBufferArrayDynamicIndexing = true,
Kristian Høgsberg Kristensen4a2d17f2016-02-15 21:24:40 -0800402 .shaderSampledImageArrayDynamicIndexing = true,
403 .shaderStorageBufferArrayDynamicIndexing = true,
404 .shaderStorageImageArrayDynamicIndexing = true,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800405 .shaderStorageImageReadWithoutFormat = false,
406 .shaderStorageImageWriteWithoutFormat = true,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700407 .shaderClipDistance = false,
408 .shaderCullDistance = false,
409 .shaderFloat64 = false,
410 .shaderInt64 = false,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700411 .shaderInt16 = false,
Chad Versace545f5cc2015-10-07 10:05:02 -0700412 .alphaToOne = true,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800413 .variableMultisampleRate = false,
Jason Ekstrand802f0022016-01-14 06:58:11 -0800414 .inheritedQueries = false,
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700415 };
Jason Ekstrand5ec4ecc2016-04-15 14:53:16 -0700416
417 /* We can't do image stores in vec4 shaders */
418 pFeatures->vertexPipelineStoresAndAtomics =
Jason Ekstrand93db8282016-04-15 16:39:17 -0700419 pdevice->compiler->scalar_stage[MESA_SHADER_VERTEX] &&
420 pdevice->compiler->scalar_stage[MESA_SHADER_GEOMETRY];
Jason Ekstrandf6d51f32015-07-09 13:54:08 -0700421}
422
Kristian Høgsberg Kristensen39a120a2016-02-10 09:43:03 -0800423void
424anv_device_get_cache_uuid(void *uuid)
425{
426 memset(uuid, 0, VK_UUID_SIZE);
427 snprintf(uuid, VK_UUID_SIZE, "anv-%s", MESA_GIT_SHA1 + 4);
428}
429
Jason Ekstrandf1a7c782015-11-30 12:21:19 -0800430void anv_GetPhysicalDeviceProperties(
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700431 VkPhysicalDevice physicalDevice,
Chad Versaced48e71c2015-10-07 10:36:46 -0700432 VkPhysicalDeviceProperties* pProperties)
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700433{
Chad Versaced48e71c2015-10-07 10:36:46 -0700434 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
435 const struct brw_device_info *devinfo = pdevice->info;
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700436
Chad Versaced48e71c2015-10-07 10:36:46 -0700437 anv_finishme("Get correct values for VkPhysicalDeviceLimits");
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700438
Kristian Høgsberg Kristensendae800d2016-01-09 00:50:04 -0800439 const float time_stamp_base = devinfo->gen >= 9 ? 83.333 : 80.0;
440
Jason Ekstrandd6897452015-12-02 16:58:54 -0800441 VkSampleCountFlags sample_counts =
Chad Versace1c5d7b32016-01-20 16:04:28 -0800442 isl_device_get_sample_counts(&pdevice->isl_dev);
Jason Ekstrandd6897452015-12-02 16:58:54 -0800443
Chad Versaced48e71c2015-10-07 10:36:46 -0700444 VkPhysicalDeviceLimits limits = {
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700445 .maxImageDimension1D = (1 << 14),
446 .maxImageDimension2D = (1 << 14),
Nanley Chery181b1422016-03-05 15:17:00 -0800447 .maxImageDimension3D = (1 << 11),
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700448 .maxImageDimensionCube = (1 << 14),
Nanley Chery181b1422016-03-05 15:17:00 -0800449 .maxImageArrayLayers = (1 << 11),
Kenneth Graunke38a3a532016-01-26 23:09:45 -0800450 .maxTexelBufferElements = 128 * 1024 * 1024,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800451 .maxUniformBufferRange = UINT32_MAX,
452 .maxStorageBufferRange = UINT32_MAX,
Jason Ekstrand5446bf32015-08-26 15:01:38 -0700453 .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700454 .maxMemoryAllocationCount = UINT32_MAX,
Kristian Høgsberg Kristensen7b7a7c22016-01-20 14:36:52 -0800455 .maxSamplerAllocationCount = 64 * 1024,
Jason Ekstrande5db2092015-07-14 17:10:37 -0700456 .bufferImageGranularity = 64, /* A cache line */
Chad Versace033a37f2015-10-07 09:57:51 -0700457 .sparseAddressSpaceSize = 0,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700458 .maxBoundDescriptorSets = MAX_SETS,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700459 .maxPerStageDescriptorSamplers = 64,
460 .maxPerStageDescriptorUniformBuffers = 64,
461 .maxPerStageDescriptorStorageBuffers = 64,
462 .maxPerStageDescriptorSampledImages = 64,
463 .maxPerStageDescriptorStorageImages = 64,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800464 .maxPerStageDescriptorInputAttachments = 64,
465 .maxPerStageResources = 128,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700466 .maxDescriptorSetSamplers = 256,
467 .maxDescriptorSetUniformBuffers = 256,
Chad Versace033a37f2015-10-07 09:57:51 -0700468 .maxDescriptorSetUniformBuffersDynamic = 256,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700469 .maxDescriptorSetStorageBuffers = 256,
Chad Versace033a37f2015-10-07 09:57:51 -0700470 .maxDescriptorSetStorageBuffersDynamic = 256,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700471 .maxDescriptorSetSampledImages = 256,
472 .maxDescriptorSetStorageImages = 256,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800473 .maxDescriptorSetInputAttachments = 256,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700474 .maxVertexInputAttributes = 32,
Chad Versace033a37f2015-10-07 09:57:51 -0700475 .maxVertexInputBindings = 32,
Kenneth Graunke38a3a532016-01-26 23:09:45 -0800476 .maxVertexInputAttributeOffset = 2047,
477 .maxVertexInputBindingStride = 2048,
478 .maxVertexOutputComponents = 128,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800479 .maxTessellationGenerationLevel = 0,
480 .maxTessellationPatchSize = 0,
481 .maxTessellationControlPerVertexInputComponents = 0,
482 .maxTessellationControlPerVertexOutputComponents = 0,
483 .maxTessellationControlPerPatchOutputComponents = 0,
484 .maxTessellationControlTotalOutputComponents = 0,
485 .maxTessellationEvaluationInputComponents = 0,
486 .maxTessellationEvaluationOutputComponents = 0,
Kenneth Graunke38a3a532016-01-26 23:09:45 -0800487 .maxGeometryShaderInvocations = 32,
488 .maxGeometryInputComponents = 64,
489 .maxGeometryOutputComponents = 128,
490 .maxGeometryOutputVertices = 256,
491 .maxGeometryTotalOutputComponents = 1024,
492 .maxFragmentInputComponents = 128,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800493 .maxFragmentOutputAttachments = 8,
494 .maxFragmentDualSrcAttachments = 2,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700495 .maxFragmentCombinedOutputResources = 8,
Kenneth Graunke38a3a532016-01-26 23:09:45 -0800496 .maxComputeSharedMemorySize = 32768,
497 .maxComputeWorkGroupCount = { 65535, 65535, 65535 },
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700498 .maxComputeWorkGroupInvocations = 16 * devinfo->max_cs_threads,
499 .maxComputeWorkGroupSize = {
500 16 * devinfo->max_cs_threads,
501 16 * devinfo->max_cs_threads,
502 16 * devinfo->max_cs_threads,
503 },
504 .subPixelPrecisionBits = 4 /* FIXME */,
505 .subTexelPrecisionBits = 4 /* FIXME */,
506 .mipmapPrecisionBits = 4 /* FIXME */,
507 .maxDrawIndexedIndexValue = UINT32_MAX,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800508 .maxDrawIndirectCount = UINT32_MAX,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700509 .maxSamplerLodBias = 16,
510 .maxSamplerAnisotropy = 16,
Jason Ekstranddaf68a92015-10-06 17:21:44 -0700511 .maxViewports = MAX_VIEWPORTS,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700512 .maxViewportDimensions = { (1 << 14), (1 << 14) },
Nanley Chery7ac08ad2016-05-17 15:28:01 -0700513 .viewportBoundsRange = { INT16_MIN, INT16_MAX },
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700514 .viewportSubPixelBits = 13, /* We take a float? */
Jason Ekstrandf076d532016-01-01 09:26:06 -0800515 .minMemoryMapAlignment = 4096, /* A page */
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700516 .minTexelBufferOffsetAlignment = 1,
517 .minUniformBufferOffsetAlignment = 1,
518 .minStorageBufferOffsetAlignment = 1,
Kenneth Graunke38a3a532016-01-26 23:09:45 -0800519 .minTexelOffset = -8,
520 .maxTexelOffset = 7,
521 .minTexelGatherOffset = -8,
522 .maxTexelGatherOffset = 7,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700523 .minInterpolationOffset = 0, /* FIXME */
524 .maxInterpolationOffset = 0, /* FIXME */
525 .subPixelInterpolationOffsetBits = 0, /* FIXME */
526 .maxFramebufferWidth = (1 << 14),
527 .maxFramebufferHeight = (1 << 14),
528 .maxFramebufferLayers = (1 << 10),
Jason Ekstrandd6897452015-12-02 16:58:54 -0800529 .framebufferColorSampleCounts = sample_counts,
530 .framebufferDepthSampleCounts = sample_counts,
531 .framebufferStencilSampleCounts = sample_counts,
532 .framebufferNoAttachmentsSampleCounts = sample_counts,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700533 .maxColorAttachments = MAX_RTS,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800534 .sampledImageColorSampleCounts = sample_counts,
535 .sampledImageIntegerSampleCounts = VK_SAMPLE_COUNT_1_BIT,
536 .sampledImageDepthSampleCounts = sample_counts,
537 .sampledImageStencilSampleCounts = sample_counts,
538 .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700539 .maxSampleMaskWords = 1,
Jason Ekstrand802f0022016-01-14 06:58:11 -0800540 .timestampComputeAndGraphics = false,
Kristian Høgsberg Kristensendae800d2016-01-09 00:50:04 -0800541 .timestampPeriod = time_stamp_base / (1000 * 1000 * 1000),
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700542 .maxClipDistances = 0 /* FIXME */,
543 .maxCullDistances = 0 /* FIXME */,
544 .maxCombinedClipAndCullDistances = 0 /* FIXME */,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800545 .discreteQueuePriorities = 1,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700546 .pointSizeRange = { 0.125, 255.875 },
547 .lineWidthRange = { 0.0, 7.9921875 },
548 .pointSizeGranularity = (1.0 / 8.0),
549 .lineWidthGranularity = (1.0 / 128.0),
Jason Ekstrandd6897452015-12-02 16:58:54 -0800550 .strictLines = false, /* FINISHME */
Chad Versace8cc6f052016-01-26 10:56:06 -0800551 .standardSampleLocations = true,
Jason Ekstrandd6897452015-12-02 16:58:54 -0800552 .optimalBufferCopyOffsetAlignment = 128,
553 .optimalBufferCopyRowPitchAlignment = 128,
554 .nonCoherentAtomSize = 64,
Jason Ekstrand65e0b302015-07-09 15:38:30 -0700555 };
556
Jason Ekstrand977a4692015-07-09 15:53:03 -0700557 *pProperties = (VkPhysicalDeviceProperties) {
Jason Ekstrand20417b22016-03-22 16:21:21 -0700558 .apiVersion = VK_MAKE_VERSION(1, 0, 5),
Jason Ekstrand977a4692015-07-09 15:53:03 -0700559 .driverVersion = 1,
Jason Ekstrandaadb7dc2015-11-30 21:10:14 -0800560 .vendorID = 0x8086,
561 .deviceID = pdevice->chipset_id,
Jason Ekstrand977a4692015-07-09 15:53:03 -0700562 .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
Chad Versaced48e71c2015-10-07 10:36:46 -0700563 .limits = limits,
564 .sparseProperties = {0}, /* Broadwell doesn't do sparse. */
Jason Ekstrand977a4692015-07-09 15:53:03 -0700565 };
566
567 strcpy(pProperties->deviceName, pdevice->name);
Kristian Høgsberg Kristensen39a120a2016-02-10 09:43:03 -0800568 anv_device_get_cache_uuid(pProperties->pipelineCacheUUID);
Jason Ekstrand977a4692015-07-09 15:53:03 -0700569}
570
Jason Ekstrandf1a7c782015-11-30 12:21:19 -0800571void anv_GetPhysicalDeviceQueueFamilyProperties(
Jason Ekstrand1f907012015-07-09 16:11:24 -0700572 VkPhysicalDevice physicalDevice,
Jason Ekstranda6eba402015-10-05 21:17:12 -0700573 uint32_t* pCount,
574 VkQueueFamilyProperties* pQueueFamilyProperties)
Jason Ekstrand1f907012015-07-09 16:11:24 -0700575{
Jason Ekstranda6eba402015-10-05 21:17:12 -0700576 if (pQueueFamilyProperties == NULL) {
577 *pCount = 1;
Jason Ekstrandf1a7c782015-11-30 12:21:19 -0800578 return;
Jason Ekstranda6eba402015-10-05 21:17:12 -0700579 }
Jason Ekstrand1f907012015-07-09 16:11:24 -0700580
Jason Ekstranda6eba402015-10-05 21:17:12 -0700581 assert(*pCount >= 1);
Jason Ekstrand1f907012015-07-09 16:11:24 -0700582
Jason Ekstranda6eba402015-10-05 21:17:12 -0700583 *pQueueFamilyProperties = (VkQueueFamilyProperties) {
Jason Ekstrand1f907012015-07-09 16:11:24 -0700584 .queueFlags = VK_QUEUE_GRAPHICS_BIT |
585 VK_QUEUE_COMPUTE_BIT |
Jason Ekstrand6a8a5422015-11-30 11:12:44 -0800586 VK_QUEUE_TRANSFER_BIT,
Jason Ekstrand1f907012015-07-09 16:11:24 -0700587 .queueCount = 1,
Kristian Høgsberg Kristensen925ad842016-01-09 00:51:14 -0800588 .timestampValidBits = 36, /* XXX: Real value here */
Jason Ekstrand74c4c4a2015-12-02 16:20:40 -0800589 .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
Jason Ekstrand1f907012015-07-09 16:11:24 -0700590 };
Jason Ekstrand1f907012015-07-09 16:11:24 -0700591}
592
Jason Ekstrandf1a7c782015-11-30 12:21:19 -0800593void anv_GetPhysicalDeviceMemoryProperties(
Chad Versacedf2a0132015-07-09 19:49:19 -0700594 VkPhysicalDevice physicalDevice,
595 VkPhysicalDeviceMemoryProperties* pMemoryProperties)
596{
597 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
Kristian Høgsberg Kristensen9564dd32015-07-21 13:09:25 -0700598 VkDeviceSize heap_size;
Chad Versacedf2a0132015-07-09 19:49:19 -0700599
600 /* Reserve some wiggle room for the driver by exposing only 75% of the
601 * aperture to the heap.
602 */
Kristian Høgsberg Kristensen9564dd32015-07-21 13:09:25 -0700603 heap_size = 3 * physical_device->aperture_size / 4;
Chad Versacedf2a0132015-07-09 19:49:19 -0700604
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -0800605 if (physical_device->info->has_llc) {
606 /* Big core GPUs share LLC with the CPU and thus one memory type can be
607 * both cached and coherent at the same time.
608 */
609 pMemoryProperties->memoryTypeCount = 1;
610 pMemoryProperties->memoryTypes[0] = (VkMemoryType) {
611 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
612 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
613 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
614 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
Jason Ekstrand3421ba12015-12-30 19:32:41 -0800615 .heapIndex = 0,
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -0800616 };
617 } else {
618 /* The spec requires that we expose a host-visible, coherent memory
619 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
620 * to give the application a choice between cached, but not coherent and
621 * coherent but uncached (WC though).
622 */
623 pMemoryProperties->memoryTypeCount = 2;
624 pMemoryProperties->memoryTypes[0] = (VkMemoryType) {
625 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
626 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
627 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
Jason Ekstrand3421ba12015-12-30 19:32:41 -0800628 .heapIndex = 0,
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -0800629 };
630 pMemoryProperties->memoryTypes[1] = (VkMemoryType) {
631 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
632 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
633 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
Jason Ekstrand3421ba12015-12-30 19:32:41 -0800634 .heapIndex = 0,
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -0800635 };
636 }
Chad Versacedf2a0132015-07-09 19:49:19 -0700637
638 pMemoryProperties->memoryHeapCount = 1;
639 pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) {
640 .size = heap_size,
Jason Ekstrande6ab06a2015-12-02 10:39:15 -0800641 .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
Chad Versacedf2a0132015-07-09 19:49:19 -0700642 };
Chad Versacedf2a0132015-07-09 19:49:19 -0700643}
644
Jason Ekstrande7acdda2015-07-07 18:51:53 -0700645PFN_vkVoidFunction anv_GetInstanceProcAddr(
646 VkInstance instance,
647 const char* pName)
648{
649 return anv_lookup_entrypoint(pName);
650}
651
Jason Ekstrand3a2b23a2016-02-11 21:18:02 -0800652/* The loader wants us to expose a second GetInstanceProcAddr function
653 * to work around certain LD_PRELOAD issues seen in apps.
654 */
655VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
656 VkInstance instance,
657 const char* pName);
658
659VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
660 VkInstance instance,
661 const char* pName)
662{
663 return anv_GetInstanceProcAddr(instance, pName);
664}
665
Jason Ekstrande7acdda2015-07-07 18:51:53 -0700666PFN_vkVoidFunction anv_GetDeviceProcAddr(
667 VkDevice device,
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700668 const char* pName)
669{
Kristian Høgsberg454345d2015-05-17 16:33:48 -0700670 return anv_lookup_entrypoint(pName);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700671}
672
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700673static VkResult
674anv_queue_init(struct anv_device *device, struct anv_queue *queue)
675{
Jason Ekstrand39cd3782015-09-24 13:51:40 -0700676 queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700677 queue->device = device;
678 queue->pool = &device->surface_state_pool;
679
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700680 return VK_SUCCESS;
681}
682
683static void
684anv_queue_finish(struct anv_queue *queue)
685{
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700686}
687
Kristian Høgsberg77359202015-12-01 15:37:12 -0800688static struct anv_state
689anv_state_pool_emit_data(struct anv_state_pool *pool, size_t size, size_t align, const void *p)
690{
691 struct anv_state state;
692
693 state = anv_state_pool_alloc(pool, size, align);
694 memcpy(state.map, p, size);
695
696 if (!pool->block_pool->device->info.has_llc)
697 anv_state_clflush(state);
698
699 return state;
700}
701
Jason Ekstrandd49298c2016-01-18 12:16:31 -0800702struct gen8_border_color {
703 union {
704 float float32[4];
705 uint32_t uint32[4];
706 };
707 /* Pad out to 64 bytes */
708 uint32_t _pad[12];
709};
710
Kristian Høgsberg Kristensendc56e4f2015-05-29 16:06:06 -0700711static void
712anv_device_init_border_colors(struct anv_device *device)
713{
Jason Ekstrandd49298c2016-01-18 12:16:31 -0800714 static const struct gen8_border_color border_colors[] = {
Jason Ekstrandbd4cde72015-10-06 10:07:47 -0700715 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } },
716 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } },
717 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } },
718 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } },
719 [VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } },
720 [VK_BORDER_COLOR_INT_OPAQUE_WHITE] = { .uint32 = { 1, 1, 1, 1 } },
Kristian Høgsberg Kristensendc56e4f2015-05-29 16:06:06 -0700721 };
722
Kristian Høgsberg77359202015-12-01 15:37:12 -0800723 device->border_colors = anv_state_pool_emit_data(&device->dynamic_state_pool,
Jason Ekstrandd49298c2016-01-18 12:16:31 -0800724 sizeof(border_colors), 64,
725 border_colors);
Kristian Høgsberg Kristensendc56e4f2015-05-29 16:06:06 -0700726}
727
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -0800728VkResult
729anv_device_submit_simple_batch(struct anv_device *device,
730 struct anv_batch *batch)
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800731{
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800732 struct drm_i915_gem_execbuffer2 execbuf;
733 struct drm_i915_gem_exec_object2 exec2_objects[1];
Jason Ekstrandea930412016-02-11 18:41:04 -0800734 struct anv_bo bo;
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800735 VkResult result = VK_SUCCESS;
736 uint32_t size;
737 int64_t timeout;
738 int ret;
739
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -0800740 /* Kernel driver requires 8 byte aligned batch length */
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800741 size = align_u32(batch->next - batch->start, 8);
Jason Ekstrandecfb0742016-03-18 13:06:08 -0700742 result = anv_bo_pool_alloc(&device->batch_bo_pool, &bo, size);
Jason Ekstrandea930412016-02-11 18:41:04 -0800743 if (result != VK_SUCCESS)
744 return result;
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800745
Jason Ekstrandea930412016-02-11 18:41:04 -0800746 memcpy(bo.map, batch->start, size);
Jason Ekstrand699f2122016-02-12 11:00:42 -0800747 if (!device->info.has_llc)
748 anv_clflush_range(bo.map, size);
Jason Ekstrandea930412016-02-11 18:41:04 -0800749
750 exec2_objects[0].handle = bo.gem_handle;
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800751 exec2_objects[0].relocation_count = 0;
752 exec2_objects[0].relocs_ptr = 0;
753 exec2_objects[0].alignment = 0;
Jason Ekstrandea930412016-02-11 18:41:04 -0800754 exec2_objects[0].offset = bo.offset;
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800755 exec2_objects[0].flags = 0;
756 exec2_objects[0].rsvd1 = 0;
757 exec2_objects[0].rsvd2 = 0;
758
759 execbuf.buffers_ptr = (uintptr_t) exec2_objects;
760 execbuf.buffer_count = 1;
Jason Ekstrandea930412016-02-11 18:41:04 -0800761 execbuf.batch_start_offset = 0;
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -0800762 execbuf.batch_len = size;
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800763 execbuf.cliprects_ptr = 0;
764 execbuf.num_cliprects = 0;
765 execbuf.DR1 = 0;
766 execbuf.DR4 = 0;
767
768 execbuf.flags =
769 I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER;
770 execbuf.rsvd1 = device->context_id;
771 execbuf.rsvd2 = 0;
772
773 ret = anv_gem_execbuffer(device, &execbuf);
774 if (ret != 0) {
775 /* We don't know the real error. */
776 result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m");
777 goto fail;
778 }
779
780 timeout = INT64_MAX;
Jason Ekstrandea930412016-02-11 18:41:04 -0800781 ret = anv_gem_wait(device, bo.gem_handle, &timeout);
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800782 if (ret != 0) {
783 /* We don't know the real error. */
784 result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m");
785 goto fail;
786 }
787
788 fail:
Jason Ekstrandea930412016-02-11 18:41:04 -0800789 anv_bo_pool_free(&device->batch_bo_pool, &bo);
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -0800790
791 return result;
792}
793
Kristian Høgsberg454345d2015-05-17 16:33:48 -0700794VkResult anv_CreateDevice(
Jason Ekstrandc95f9b62015-07-09 18:20:10 -0700795 VkPhysicalDevice physicalDevice,
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700796 const VkDeviceCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800797 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700798 VkDevice* pDevice)
799{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -0700800 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800801 VkResult result;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700802 struct anv_device *device;
803
804 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
805
Jason Ekstrandaab95172016-01-14 07:41:45 -0800806 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700807 bool found = false;
808 for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) {
809 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
Jason Ekstrandaadb7dc2015-11-30 21:10:14 -0800810 device_extensions[j].extensionName) == 0) {
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700811 found = true;
812 break;
813 }
814 }
815 if (!found)
Chad Versacef9c948e2015-10-07 11:36:51 -0700816 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
Jason Ekstrandb5f68892015-09-17 11:19:16 -0700817 }
818
Jason Ekstrandaa3002b2015-11-17 06:30:02 -0800819 anv_set_dispatch_devinfo(physical_device->info);
Kristian Høgsberg Kristensenee978892015-07-30 14:44:01 -0700820
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800821 device = anv_alloc2(&physical_device->instance->alloc, pAllocator,
822 sizeof(*device), 8,
Jason Ekstrand45d17fc2016-01-18 14:04:13 -0800823 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700824 if (!device)
825 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
826
Jason Ekstrand39cd3782015-09-24 13:51:40 -0700827 device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
Jason Ekstrandc95f9b62015-07-09 18:20:10 -0700828 device->instance = physical_device->instance;
Kristian Høgsberg Kristensen39a120a2016-02-10 09:43:03 -0800829 device->chipset_id = physical_device->chipset_id;
Chad Versace8cda3e92015-07-09 16:31:39 -0700830
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800831 if (pAllocator)
832 device->alloc = *pAllocator;
833 else
834 device->alloc = physical_device->instance->alloc;
835
Chad Versace8cda3e92015-07-09 16:31:39 -0700836 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
Jason Ekstrandc95f9b62015-07-09 18:20:10 -0700837 device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800838 if (device->fd == -1) {
839 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700840 goto fail_device;
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800841 }
Chad Versace477383e2015-11-13 10:12:18 -0800842
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700843 device->context_id = anv_gem_create_context(device);
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800844 if (device->context_id == -1) {
845 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700846 goto fail_fd;
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800847 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700848
Jason Ekstrand9c84b6c2015-12-28 13:26:49 -0800849 device->info = *physical_device->info;
850 device->isl_dev = physical_device->isl_dev;
851
Jason Ekstrand869e3932016-03-18 16:32:46 -0700852 /* On Broadwell and later, we can use batch chaining to more efficiently
853 * implement growing command buffers. Prior to Haswell, the kernel
854 * command parser gets in the way and we have to fall back to growing
855 * the batch.
856 */
857 device->can_chain_batches = device->info.gen >= 8;
858
Jason Ekstrandc29ffea2016-05-14 14:52:36 -0700859 device->robust_buffer_access = pCreateInfo->pEnabledFeatures &&
860 pCreateInfo->pEnabledFeatures->robustBufferAccess;
861
Jason Ekstranda788e7c2015-09-17 18:23:21 -0700862 pthread_mutex_init(&device->mutex, NULL);
863
Jason Ekstrandecfb0742016-03-18 13:06:08 -0700864 anv_bo_pool_init(&device->batch_bo_pool, device);
Jason Ekstrand5ef81f02015-05-25 15:46:48 -0700865
Jordan Justenc7f6e422016-01-08 12:15:29 -0800866 anv_block_pool_init(&device->dynamic_state_block_pool, device, 16384);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700867
Kristian Høgsberg0a775e12015-05-13 15:34:34 -0700868 anv_state_pool_init(&device->dynamic_state_pool,
869 &device->dynamic_state_block_pool);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700870
Jason Ekstrandaee970c2016-01-12 13:48:32 -0800871 anv_block_pool_init(&device->instruction_block_pool, device, 128 * 1024);
Kristian Høgsberg Kristensen30521fb2016-01-05 12:00:54 -0800872 anv_pipeline_cache_init(&device->default_pipeline_cache, device);
873
Jason Ekstrand0e944462015-09-22 16:36:00 -0700874 anv_block_pool_init(&device->surface_state_block_pool, device, 4096);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700875
876 anv_state_pool_init(&device->surface_state_pool,
877 &device->surface_state_block_pool);
878
Jason Ekstrand3a3d79b2015-11-10 16:42:34 -0800879 anv_bo_init_new(&device->workaround_bo, device, 1024);
880
Kristian Høgsberg Kristensen9b9f9732015-06-19 15:41:30 -0700881 anv_block_pool_init(&device->scratch_block_pool, device, 0x10000);
882
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700883 anv_queue_init(device, &device->queue);
884
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -0800885 switch (device->info.gen) {
886 case 7:
887 if (!device->info.is_haswell)
888 result = gen7_init_device_state(device);
889 else
890 result = gen75_init_device_state(device);
891 break;
892 case 8:
893 result = gen8_init_device_state(device);
894 break;
895 case 9:
896 result = gen9_init_device_state(device);
897 break;
Kristian Høgsberg Kristensen5d72d7b2016-02-14 13:20:06 -0800898 default:
899 /* Shouldn't get here as we don't create physical devices for any other
900 * gens. */
901 unreachable("unhandled gen");
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -0800902 }
903 if (result != VK_SUCCESS)
904 goto fail_fd;
905
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800906 result = anv_device_init_meta(device);
907 if (result != VK_SUCCESS)
908 goto fail_fd;
Kristian Høgsbergd77c34d2015-05-11 23:25:06 -0700909
Kristian Høgsberg Kristensendc56e4f2015-05-29 16:06:06 -0700910 anv_device_init_border_colors(device);
911
Jason Ekstrand098209e2015-07-09 18:41:27 -0700912 *pDevice = anv_device_to_handle(device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700913
914 return VK_SUCCESS;
915
916 fail_fd:
917 close(device->fd);
918 fail_device:
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800919 anv_free(&device->alloc, device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700920
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800921 return result;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700922}
923
Jason Ekstrand05a26a62015-10-05 20:50:51 -0700924void anv_DestroyDevice(
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800925 VkDevice _device,
926 const VkAllocationCallbacks* pAllocator)
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700927{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -0700928 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700929
Jason Ekstrand66b00d52015-06-09 12:28:58 -0700930 anv_queue_finish(&device->queue);
931
Jason Ekstrand3a38b0d2015-06-09 11:08:51 -0700932 anv_device_finish_meta(device);
Jason Ekstrand5ef81f02015-05-25 15:46:48 -0700933
Jason Ekstrand38f5eef2015-06-09 11:41:31 -0700934#ifdef HAVE_VALGRIND
935 /* We only need to free these to prevent valgrind errors. The backing
936 * BO will go away in a couple of lines so we don't actually leak.
937 */
Jason Ekstrand522ab832015-07-08 11:44:52 -0700938 anv_state_pool_free(&device->dynamic_state_pool, device->border_colors);
Jason Ekstrand38f5eef2015-06-09 11:41:31 -0700939#endif
940
Jason Ekstrand3a3d79b2015-11-10 16:42:34 -0800941 anv_gem_munmap(device->workaround_bo.map, device->workaround_bo.size);
942 anv_gem_close(device, device->workaround_bo.gem_handle);
943
Jason Ekstrand5ef81f02015-05-25 15:46:48 -0700944 anv_bo_pool_finish(&device->batch_bo_pool);
Jason Ekstrand1920ef92015-07-31 10:30:57 -0700945 anv_state_pool_finish(&device->dynamic_state_pool);
Kristian Høgsberg0a775e12015-05-13 15:34:34 -0700946 anv_block_pool_finish(&device->dynamic_state_block_pool);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700947 anv_block_pool_finish(&device->instruction_block_pool);
Jason Ekstrand1920ef92015-07-31 10:30:57 -0700948 anv_state_pool_finish(&device->surface_state_pool);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700949 anv_block_pool_finish(&device->surface_state_block_pool);
Jason Ekstrand3460e6c2015-07-22 17:51:14 -0700950 anv_block_pool_finish(&device->scratch_block_pool);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700951
952 close(device->fd);
953
Kristian Høgsberg Kristensenf5510472016-01-05 11:43:25 -0800954 pthread_mutex_destroy(&device->mutex);
955
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800956 anv_free(&device->alloc, device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700957}
958
Jason Ekstrand8ba684c2015-10-06 09:25:03 -0700959VkResult anv_EnumerateInstanceExtensionProperties(
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700960 const char* pLayerName,
Jason Ekstrandfe644722015-11-30 16:28:36 -0800961 uint32_t* pPropertyCount,
Jason Ekstrand8e05bbe2015-07-08 10:38:07 -0700962 VkExtensionProperties* pProperties)
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700963{
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700964 if (pProperties == NULL) {
Jason Ekstrandfe644722015-11-30 16:28:36 -0800965 *pPropertyCount = ARRAY_SIZE(global_extensions);
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700966 return VK_SUCCESS;
967 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700968
Jason Ekstrandfe644722015-11-30 16:28:36 -0800969 assert(*pPropertyCount >= ARRAY_SIZE(global_extensions));
Kristian Høgsberg783e6212015-05-17 19:22:52 -0700970
Jason Ekstrandfe644722015-11-30 16:28:36 -0800971 *pPropertyCount = ARRAY_SIZE(global_extensions);
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700972 memcpy(pProperties, global_extensions, sizeof(global_extensions));
Jason Ekstrand8e05bbe2015-07-08 10:38:07 -0700973
974 return VK_SUCCESS;
975}
976
Jason Ekstrand8ba684c2015-10-06 09:25:03 -0700977VkResult anv_EnumerateDeviceExtensionProperties(
Jason Ekstrand8e05bbe2015-07-08 10:38:07 -0700978 VkPhysicalDevice physicalDevice,
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700979 const char* pLayerName,
Jason Ekstrandfe644722015-11-30 16:28:36 -0800980 uint32_t* pPropertyCount,
Jason Ekstrand8e05bbe2015-07-08 10:38:07 -0700981 VkExtensionProperties* pProperties)
982{
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700983 if (pProperties == NULL) {
Jason Ekstrandfe644722015-11-30 16:28:36 -0800984 *pPropertyCount = ARRAY_SIZE(device_extensions);
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700985 return VK_SUCCESS;
986 }
987
Jason Ekstrandfe644722015-11-30 16:28:36 -0800988 assert(*pPropertyCount >= ARRAY_SIZE(device_extensions));
Jason Ekstrand9a7600c2015-09-01 16:44:42 -0700989
Jason Ekstrandfe644722015-11-30 16:28:36 -0800990 *pPropertyCount = ARRAY_SIZE(device_extensions);
Jason Ekstrand9a7600c2015-09-01 16:44:42 -0700991 memcpy(pProperties, device_extensions, sizeof(device_extensions));
992
993 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700994}
995
Jason Ekstrand8ba684c2015-10-06 09:25:03 -0700996VkResult anv_EnumerateInstanceLayerProperties(
Jason Ekstrandfe644722015-11-30 16:28:36 -0800997 uint32_t* pPropertyCount,
Jason Ekstrand02db21a2015-07-14 16:11:21 -0700998 VkLayerProperties* pProperties)
Kristian Høgsberg769785c2015-05-08 22:32:37 -0700999{
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001000 if (pProperties == NULL) {
Jason Ekstrandfe644722015-11-30 16:28:36 -08001001 *pPropertyCount = 0;
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001002 return VK_SUCCESS;
1003 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001004
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001005 /* None supported at this time */
Chad Versacef9c948e2015-10-07 11:36:51 -07001006 return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001007}
1008
Jason Ekstrand8ba684c2015-10-06 09:25:03 -07001009VkResult anv_EnumerateDeviceLayerProperties(
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001010 VkPhysicalDevice physicalDevice,
Jason Ekstrandfe644722015-11-30 16:28:36 -08001011 uint32_t* pPropertyCount,
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001012 VkLayerProperties* pProperties)
1013{
1014 if (pProperties == NULL) {
Jason Ekstrandfe644722015-11-30 16:28:36 -08001015 *pPropertyCount = 0;
Jason Ekstrand02db21a2015-07-14 16:11:21 -07001016 return VK_SUCCESS;
1017 }
1018
1019 /* None supported at this time */
Chad Versacef9c948e2015-10-07 11:36:51 -07001020 return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001021}
1022
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001023void anv_GetDeviceQueue(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001024 VkDevice _device,
1025 uint32_t queueNodeIndex,
1026 uint32_t queueIndex,
1027 VkQueue* pQueue)
1028{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001029 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001030
Jason Ekstrand66b00d52015-06-09 12:28:58 -07001031 assert(queueIndex == 0);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001032
Jason Ekstrand098209e2015-07-09 18:41:27 -07001033 *pQueue = anv_queue_to_handle(&device->queue);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001034}
1035
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001036VkResult anv_QueueSubmit(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001037 VkQueue _queue,
Jason Ekstrand4e904a02015-12-02 17:18:41 -08001038 uint32_t submitCount,
1039 const VkSubmitInfo* pSubmits,
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001040 VkFence _fence)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001041{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001042 ANV_FROM_HANDLE(anv_queue, queue, _queue);
1043 ANV_FROM_HANDLE(anv_fence, fence, _fence);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001044 struct anv_device *device = queue->device;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001045 int ret;
1046
Jason Ekstrand4e904a02015-12-02 17:18:41 -08001047 for (uint32_t i = 0; i < submitCount; i++) {
1048 for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) {
1049 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer,
1050 pSubmits[i].pCommandBuffers[j]);
1051 assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001052
Jason Ekstrand4e904a02015-12-02 17:18:41 -08001053 ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf);
Chad Versacef9c948e2015-10-07 11:36:51 -07001054 if (ret != 0) {
1055 /* We don't know the real error. */
1056 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
1057 "execbuf2 failed: %m");
1058 }
Kristian Høgsberg Kristensenaac6f7c2015-08-14 09:39:01 -07001059
Jason Ekstrand4e904a02015-12-02 17:18:41 -08001060 for (uint32_t k = 0; k < cmd_buffer->execbuf2.bo_count; k++)
1061 cmd_buffer->execbuf2.bos[k]->offset = cmd_buffer->execbuf2.objects[k].offset;
1062 }
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001063 }
1064
Kristian Høgsberg Kristensenb0c30b72016-02-12 15:08:09 -08001065 if (fence) {
1066 ret = anv_gem_execbuffer(device, &fence->execbuf);
1067 if (ret != 0) {
1068 /* We don't know the real error. */
1069 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
1070 "execbuf2 failed: %m");
1071 }
1072 }
1073
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001074 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001075}
1076
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001077VkResult anv_QueueWaitIdle(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001078 VkQueue _queue)
1079{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001080 ANV_FROM_HANDLE(anv_queue, queue, _queue);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001081
Jason Ekstranda95f51c2015-09-24 14:20:35 -07001082 return ANV_CALL(DeviceWaitIdle)(anv_device_to_handle(queue->device));
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001083}
1084
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001085VkResult anv_DeviceWaitIdle(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001086 VkDevice _device)
1087{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001088 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001089 struct anv_batch batch;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001090
Kristian Høgsberg Kristensenc9c33442016-02-05 15:23:38 -08001091 uint32_t cmds[8];
1092 batch.start = batch.next = cmds;
1093 batch.end = (void *) cmds + sizeof(cmds);
1094
Jason Ekstrand50018522016-04-18 17:03:00 -07001095 anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END, bbe);
1096 anv_batch_emit(&batch, GEN7_MI_NOOP, noop);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001097
Kristian Høgsberg Kristensen6cdada02016-02-05 16:11:12 -08001098 return anv_device_submit_simple_batch(device, &batch);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001099}
1100
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001101VkResult
1102anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size)
1103{
1104 bo->gem_handle = anv_gem_create(device, size);
1105 if (!bo->gem_handle)
1106 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
1107
1108 bo->map = NULL;
1109 bo->index = 0;
1110 bo->offset = 0;
1111 bo->size = size;
Kristian Høgsberg Kristensenb63e28c2016-02-17 11:19:56 -08001112 bo->is_winsys_bo = false;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001113
1114 return VK_SUCCESS;
1115}
1116
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001117VkResult anv_AllocateMemory(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001118 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001119 const VkMemoryAllocateInfo* pAllocateInfo,
1120 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001121 VkDeviceMemory* pMem)
1122{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001123 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001124 struct anv_device_memory *mem;
1125 VkResult result;
1126
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001127 assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001128
Jason Ekstrandb1325402015-12-17 11:00:38 -08001129 if (pAllocateInfo->allocationSize == 0) {
1130 /* Apparently, this is allowed */
1131 *pMem = VK_NULL_HANDLE;
1132 return VK_SUCCESS;
1133 }
1134
Chad Versacef9c948e2015-10-07 11:36:51 -07001135 /* We support exactly one memory heap. */
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -08001136 assert(pAllocateInfo->memoryTypeIndex == 0 ||
1137 (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2));
Chad Versacef43a3042015-07-09 19:59:44 -07001138
1139 /* FINISHME: Fail if allocation request exceeds heap size. */
1140
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001141 mem = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
1142 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001143 if (mem == NULL)
1144 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1145
Jason Ekstrand6b0b5722016-01-02 07:52:22 -08001146 /* The kernel is going to give us whole pages anyway */
1147 uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096);
1148
1149 result = anv_bo_init_new(&mem->bo, device, alloc_size);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001150 if (result != VK_SUCCESS)
1151 goto fail;
1152
Kristian Høgsberg Kristensenc3c61d22015-12-03 23:09:09 -08001153 mem->type_index = pAllocateInfo->memoryTypeIndex;
1154
Jason Ekstrand098209e2015-07-09 18:41:27 -07001155 *pMem = anv_device_memory_to_handle(mem);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001156
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001157 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001158
1159 fail:
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001160 anv_free2(&device->alloc, pAllocator, mem);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001161
1162 return result;
1163}
1164
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001165void anv_FreeMemory(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001166 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001167 VkDeviceMemory _mem,
1168 const VkAllocationCallbacks* pAllocator)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001169{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001170 ANV_FROM_HANDLE(anv_device, device, _device);
1171 ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001172
Jason Ekstrandb1325402015-12-17 11:00:38 -08001173 if (mem == NULL)
1174 return;
1175
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001176 if (mem->bo.map)
1177 anv_gem_munmap(mem->bo.map, mem->bo.size);
1178
1179 if (mem->bo.gem_handle != 0)
1180 anv_gem_close(device, mem->bo.gem_handle);
1181
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001182 anv_free2(&device->alloc, pAllocator, mem);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001183}
1184
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001185VkResult anv_MapMemory(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001186 VkDevice _device,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001187 VkDeviceMemory _memory,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001188 VkDeviceSize offset,
1189 VkDeviceSize size,
1190 VkMemoryMapFlags flags,
1191 void** ppData)
1192{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001193 ANV_FROM_HANDLE(anv_device, device, _device);
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001194 ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001195
Jason Ekstrandb1325402015-12-17 11:00:38 -08001196 if (mem == NULL) {
1197 *ppData = NULL;
1198 return VK_SUCCESS;
1199 }
1200
Jason Ekstrand56dbf132016-01-19 15:01:10 -08001201 if (size == VK_WHOLE_SIZE)
1202 size = mem->bo.size - offset;
1203
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001204 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1205 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1206 * at a time is valid. We could just mmap up front and return an offset
1207 * pointer here, but that may exhaust virtual memory on 32 bit
1208 * userspace. */
1209
Kristian Høgsberg Kristensenbbb68752015-12-03 23:58:05 -08001210 uint32_t gem_flags = 0;
1211 if (!device->info.has_llc && mem->type_index == 0)
1212 gem_flags |= I915_MMAP_WC;
1213
Jason Ekstrandf076d532016-01-01 09:26:06 -08001214 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1215 uint64_t map_offset = offset & ~4095ull;
1216 assert(offset >= map_offset);
1217 uint64_t map_size = (offset + size) - map_offset;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001218
Jason Ekstrandf076d532016-01-01 09:26:06 -08001219 /* Let's map whole pages */
Jason Ekstrand6b0b5722016-01-02 07:52:22 -08001220 map_size = align_u64(map_size, 4096);
Jason Ekstrandf076d532016-01-01 09:26:06 -08001221
1222 mem->map = anv_gem_mmap(device, mem->bo.gem_handle,
1223 map_offset, map_size, gem_flags);
1224 mem->map_size = map_size;
1225
1226 *ppData = mem->map + (offset - map_offset);
Chad Versace477383e2015-11-13 10:12:18 -08001227
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001228 return VK_SUCCESS;
1229}
1230
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001231void anv_UnmapMemory(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001232 VkDevice _device,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001233 VkDeviceMemory _memory)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001234{
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001235 ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001236
Jason Ekstrandb1325402015-12-17 11:00:38 -08001237 if (mem == NULL)
1238 return;
1239
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001240 anv_gem_munmap(mem->map, mem->map_size);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001241}
1242
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001243static void
1244clflush_mapped_ranges(struct anv_device *device,
1245 uint32_t count,
1246 const VkMappedMemoryRange *ranges)
1247{
1248 for (uint32_t i = 0; i < count; i++) {
1249 ANV_FROM_HANDLE(anv_device_memory, mem, ranges[i].memory);
1250 void *p = mem->map + (ranges[i].offset & ~CACHELINE_MASK);
Kristian Høgsberg Kristensen31d34862016-01-29 12:07:34 -08001251 void *end;
1252
1253 if (ranges[i].offset + ranges[i].size > mem->map_size)
1254 end = mem->map + mem->map_size;
1255 else
1256 end = mem->map + ranges[i].offset + ranges[i].size;
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001257
1258 while (p < end) {
1259 __builtin_ia32_clflush(p);
1260 p += CACHELINE_SIZE;
1261 }
1262 }
1263}
1264
Jason Ekstrandd9c2cae2015-07-07 17:22:29 -07001265VkResult anv_FlushMappedMemoryRanges(
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001266 VkDevice _device,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001267 uint32_t memoryRangeCount,
1268 const VkMappedMemoryRange* pMemoryRanges)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001269{
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001270 ANV_FROM_HANDLE(anv_device, device, _device);
1271
1272 if (device->info.has_llc)
1273 return VK_SUCCESS;
1274
1275 /* Make sure the writes we're flushing have landed. */
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001276 __builtin_ia32_mfence();
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001277
1278 clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001279
1280 return VK_SUCCESS;
1281}
1282
Jason Ekstrandd9c2cae2015-07-07 17:22:29 -07001283VkResult anv_InvalidateMappedMemoryRanges(
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001284 VkDevice _device,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001285 uint32_t memoryRangeCount,
1286 const VkMappedMemoryRange* pMemoryRanges)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001287{
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001288 ANV_FROM_HANDLE(anv_device, device, _device);
1289
1290 if (device->info.has_llc)
1291 return VK_SUCCESS;
1292
1293 clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges);
1294
1295 /* Make sure no reads get moved up above the invalidate. */
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001296 __builtin_ia32_mfence();
Kristian Høgsberge0b5f032015-12-01 15:25:07 -08001297
1298 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001299}
1300
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001301void anv_GetBufferMemoryRequirements(
Jason Ekstrandef8980e2015-07-07 18:16:42 -07001302 VkDevice device,
Jason Ekstrand55723e92015-07-14 14:59:39 -07001303 VkBuffer _buffer,
Jason Ekstrandef8980e2015-07-07 18:16:42 -07001304 VkMemoryRequirements* pMemoryRequirements)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001305{
Jason Ekstrand55723e92015-07-14 14:59:39 -07001306 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001307
Chad Versacef43a3042015-07-09 19:59:44 -07001308 /* The Vulkan spec (git aaed022) says:
1309 *
1310 * memoryTypeBits is a bitfield and contains one bit set for every
1311 * supported memory type for the resource. The bit `1<<i` is set if and
1312 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1313 * structure for the physical device is supported.
1314 *
1315 * We support exactly one memory type.
1316 */
1317 pMemoryRequirements->memoryTypeBits = 1;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001318
Jason Ekstrand55723e92015-07-14 14:59:39 -07001319 pMemoryRequirements->size = buffer->size;
1320 pMemoryRequirements->alignment = 16;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001321}
1322
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001323void anv_GetImageMemoryRequirements(
Jason Ekstrandbb6567f2015-07-08 09:04:16 -07001324 VkDevice device,
Jason Ekstrand55723e92015-07-14 14:59:39 -07001325 VkImage _image,
1326 VkMemoryRequirements* pMemoryRequirements)
1327{
1328 ANV_FROM_HANDLE(anv_image, image, _image);
1329
1330 /* The Vulkan spec (git aaed022) says:
1331 *
1332 * memoryTypeBits is a bitfield and contains one bit set for every
1333 * supported memory type for the resource. The bit `1<<i` is set if and
1334 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1335 * structure for the physical device is supported.
1336 *
1337 * We support exactly one memory type.
1338 */
1339 pMemoryRequirements->memoryTypeBits = 1;
1340
1341 pMemoryRequirements->size = image->size;
1342 pMemoryRequirements->alignment = image->alignment;
Jason Ekstrand55723e92015-07-14 14:59:39 -07001343}
1344
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001345void anv_GetImageSparseMemoryRequirements(
Jason Ekstrandc7fcfeb2015-07-14 17:06:11 -07001346 VkDevice device,
1347 VkImage image,
Jason Ekstrand5a024412015-12-02 03:34:43 -08001348 uint32_t* pSparseMemoryRequirementCount,
Jason Ekstrandc7fcfeb2015-07-14 17:06:11 -07001349 VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
1350{
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001351 stub();
Jason Ekstrandc7fcfeb2015-07-14 17:06:11 -07001352}
1353
Jason Ekstrandf1a7c782015-11-30 12:21:19 -08001354void anv_GetDeviceMemoryCommitment(
Jason Ekstrandc7fcfeb2015-07-14 17:06:11 -07001355 VkDevice device,
1356 VkDeviceMemory memory,
1357 VkDeviceSize* pCommittedMemoryInBytes)
1358{
1359 *pCommittedMemoryInBytes = 0;
Jason Ekstrandc7fcfeb2015-07-14 17:06:11 -07001360}
1361
Jason Ekstrand55723e92015-07-14 14:59:39 -07001362VkResult anv_BindBufferMemory(
1363 VkDevice device,
1364 VkBuffer _buffer,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001365 VkDeviceMemory _memory,
1366 VkDeviceSize memoryOffset)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001367{
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001368 ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
Jason Ekstrand55723e92015-07-14 14:59:39 -07001369 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001370
Jason Ekstrandb1325402015-12-17 11:00:38 -08001371 if (mem) {
1372 buffer->bo = &mem->bo;
1373 buffer->offset = memoryOffset;
1374 } else {
1375 buffer->bo = NULL;
1376 buffer->offset = 0;
1377 }
Jason Ekstrand55723e92015-07-14 14:59:39 -07001378
1379 return VK_SUCCESS;
1380}
1381
1382VkResult anv_BindImageMemory(
1383 VkDevice device,
1384 VkImage _image,
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001385 VkDeviceMemory _memory,
1386 VkDeviceSize memoryOffset)
Jason Ekstrand55723e92015-07-14 14:59:39 -07001387{
Jason Ekstrand6a6da542015-11-30 21:18:12 -08001388 ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
Jason Ekstrand55723e92015-07-14 14:59:39 -07001389 ANV_FROM_HANDLE(anv_image, image, _image);
1390
Jason Ekstrandb1325402015-12-17 11:00:38 -08001391 if (mem) {
1392 image->bo = &mem->bo;
1393 image->offset = memoryOffset;
1394 } else {
1395 image->bo = NULL;
1396 image->offset = 0;
1397 }
Jason Ekstrandbb6567f2015-07-08 09:04:16 -07001398
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001399 return VK_SUCCESS;
1400}
1401
Jason Ekstrandfd536032015-11-30 16:42:12 -08001402VkResult anv_QueueBindSparse(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001403 VkQueue queue,
Jason Ekstrandfd536032015-11-30 16:42:12 -08001404 uint32_t bindInfoCount,
1405 const VkBindSparseInfo* pBindInfo,
1406 VkFence fence)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001407{
Jason Ekstrandfed35862015-12-02 16:14:58 -08001408 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001409}
1410
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001411VkResult anv_CreateFence(
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001412 VkDevice _device,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001413 const VkFenceCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001414 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001415 VkFence* pFence)
1416{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001417 ANV_FROM_HANDLE(anv_device, device, _device);
Jason Ekstrand23088912016-03-07 13:45:25 -08001418 struct anv_bo fence_bo;
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001419 struct anv_fence *fence;
1420 struct anv_batch batch;
1421 VkResult result;
1422
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001423 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
1424
Jason Ekstrandb1c5d452016-03-18 11:50:53 -07001425 result = anv_bo_pool_alloc(&device->batch_bo_pool, &fence_bo, 4096);
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001426 if (result != VK_SUCCESS)
Jason Ekstrand23088912016-03-07 13:45:25 -08001427 return result;
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001428
Jason Ekstrand23088912016-03-07 13:45:25 -08001429 /* Fences are small. Just store the CPU data structure in the BO. */
1430 fence = fence_bo.map;
1431 fence->bo = fence_bo;
1432
1433 /* Place the batch after the CPU data but on its own cache line. */
1434 const uint32_t batch_offset = align_u32(sizeof(*fence), CACHELINE_SIZE);
1435 batch.next = batch.start = fence->bo.map + batch_offset;
Jason Ekstrandda8f1482015-05-27 11:42:55 -07001436 batch.end = fence->bo.map + fence->bo.size;
Jason Ekstrand50018522016-04-18 17:03:00 -07001437 anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END, bbe);
1438 anv_batch_emit(&batch, GEN7_MI_NOOP, noop);
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001439
Kristian Høgsberg77359202015-12-01 15:37:12 -08001440 if (!device->info.has_llc) {
Jason Ekstrand23088912016-03-07 13:45:25 -08001441 assert(((uintptr_t) batch.start & CACHELINE_MASK) == 0);
1442 assert(batch.next - batch.start <= CACHELINE_SIZE);
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001443 __builtin_ia32_mfence();
Jason Ekstrandabaa3be2016-03-15 15:24:24 -07001444 __builtin_ia32_clflush(batch.start);
Kristian Høgsberg77359202015-12-01 15:37:12 -08001445 }
1446
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001447 fence->exec2_objects[0].handle = fence->bo.gem_handle;
1448 fence->exec2_objects[0].relocation_count = 0;
1449 fence->exec2_objects[0].relocs_ptr = 0;
1450 fence->exec2_objects[0].alignment = 0;
1451 fence->exec2_objects[0].offset = fence->bo.offset;
1452 fence->exec2_objects[0].flags = 0;
1453 fence->exec2_objects[0].rsvd1 = 0;
1454 fence->exec2_objects[0].rsvd2 = 0;
1455
1456 fence->execbuf.buffers_ptr = (uintptr_t) fence->exec2_objects;
1457 fence->execbuf.buffer_count = 1;
Jason Ekstrand23088912016-03-07 13:45:25 -08001458 fence->execbuf.batch_start_offset = batch.start - fence->bo.map;
1459 fence->execbuf.batch_len = batch.next - batch.start;
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001460 fence->execbuf.cliprects_ptr = 0;
1461 fence->execbuf.num_cliprects = 0;
1462 fence->execbuf.DR1 = 0;
1463 fence->execbuf.DR4 = 0;
1464
1465 fence->execbuf.flags =
1466 I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER;
1467 fence->execbuf.rsvd1 = device->context_id;
1468 fence->execbuf.rsvd2 = 0;
1469
Jason Ekstrand0d2145b2016-02-02 12:22:00 -08001470 fence->ready = false;
1471
Jason Ekstrand098209e2015-07-09 18:41:27 -07001472 *pFence = anv_fence_to_handle(fence);
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001473
1474 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001475}
1476
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001477void anv_DestroyFence(
Chad Versaceebb191f2015-07-14 09:29:35 -07001478 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001479 VkFence _fence,
1480 const VkAllocationCallbacks* pAllocator)
Chad Versaceebb191f2015-07-14 09:29:35 -07001481{
1482 ANV_FROM_HANDLE(anv_device, device, _device);
1483 ANV_FROM_HANDLE(anv_fence, fence, _fence);
1484
Jason Ekstrand23088912016-03-07 13:45:25 -08001485 assert(fence->bo.map == fence);
Jason Ekstrand23de7872016-03-06 14:16:51 -08001486 anv_bo_pool_free(&device->batch_bo_pool, &fence->bo);
Chad Versaceebb191f2015-07-14 09:29:35 -07001487}
1488
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001489VkResult anv_ResetFences(
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001490 VkDevice _device,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001491 uint32_t fenceCount,
Jason Ekstrandd5349b12015-07-07 17:18:00 -07001492 const VkFence* pFences)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001493{
Chad Versace169251b2015-07-17 13:59:48 -07001494 for (uint32_t i = 0; i < fenceCount; i++) {
1495 ANV_FROM_HANDLE(anv_fence, fence, pFences[i]);
1496 fence->ready = false;
1497 }
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001498
1499 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001500}
1501
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001502VkResult anv_GetFenceStatus(
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001503 VkDevice _device,
1504 VkFence _fence)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001505{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001506 ANV_FROM_HANDLE(anv_device, device, _device);
1507 ANV_FROM_HANDLE(anv_fence, fence, _fence);
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001508 int64_t t = 0;
1509 int ret;
1510
1511 if (fence->ready)
1512 return VK_SUCCESS;
1513
1514 ret = anv_gem_wait(device, fence->bo.gem_handle, &t);
1515 if (ret == 0) {
1516 fence->ready = true;
1517 return VK_SUCCESS;
1518 }
Jason Ekstrand5c497302015-07-09 18:20:28 -07001519
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001520 return VK_NOT_READY;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001521}
1522
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001523VkResult anv_WaitForFences(
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001524 VkDevice _device,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001525 uint32_t fenceCount,
1526 const VkFence* pFences,
Chad Versace8f3b2182015-07-13 12:59:42 -07001527 VkBool32 waitAll,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001528 uint64_t timeout)
1529{
Jason Ekstrandc8577b52015-07-08 14:24:12 -07001530 ANV_FROM_HANDLE(anv_device, device, _device);
Jason Ekstrandaafc8742015-11-10 11:24:08 -08001531
1532 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1533 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1534 * for a couple of kernel releases. Since there's no way to know
1535 * whether or not the kernel we're using is one of the broken ones, the
1536 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1537 * maximum timeout from 584 years to 292 years - likely not a big deal.
1538 */
1539 if (timeout > INT64_MAX)
1540 timeout = INT64_MAX;
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001541
Jason Ekstrand427978d2015-11-10 15:02:52 -08001542 int64_t t = timeout;
1543
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001544 /* FIXME: handle !waitAll */
1545
1546 for (uint32_t i = 0; i < fenceCount; i++) {
Jason Ekstrandc8577b52015-07-08 14:24:12 -07001547 ANV_FROM_HANDLE(anv_fence, fence, pFences[i]);
Jason Ekstrand427978d2015-11-10 15:02:52 -08001548 int ret = anv_gem_wait(device, fence->bo.gem_handle, &t);
Chad Versacef9c948e2015-10-07 11:36:51 -07001549 if (ret == -1 && errno == ETIME) {
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001550 return VK_TIMEOUT;
Chad Versacef9c948e2015-10-07 11:36:51 -07001551 } else if (ret == -1) {
1552 /* We don't know the real error. */
1553 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
1554 "gem wait failed: %m");
1555 }
Jason Ekstrand5c497302015-07-09 18:20:28 -07001556 }
Kristian Høgsberg6afb2642015-05-18 08:49:15 -07001557
1558 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001559}
1560
1561// Queue semaphore functions
1562
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001563VkResult anv_CreateSemaphore(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001564 VkDevice device,
1565 const VkSemaphoreCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001566 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001567 VkSemaphore* pSemaphore)
1568{
Kristian Høgsberg Kristensena00524a2015-12-20 22:58:38 -08001569 /* The DRM execbuffer ioctl always execute in-oder, even between different
1570 * rings. As such, there's nothing to do for the user space semaphore.
1571 */
1572
Jason Ekstrand3db43e82015-11-30 10:31:44 -08001573 *pSemaphore = (VkSemaphore)1;
Kristian Høgsberg Kristensena00524a2015-12-20 22:58:38 -08001574
1575 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001576}
1577
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001578void anv_DestroySemaphore(
Chad Versace549070b2015-07-14 09:31:34 -07001579 VkDevice device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001580 VkSemaphore semaphore,
1581 const VkAllocationCallbacks* pAllocator)
Chad Versace549070b2015-07-14 09:31:34 -07001582{
Chad Versace549070b2015-07-14 09:31:34 -07001583}
1584
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001585// Event functions
1586
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001587VkResult anv_CreateEvent(
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001588 VkDevice _device,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001589 const VkEventCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001590 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001591 VkEvent* pEvent)
1592{
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001593 ANV_FROM_HANDLE(anv_device, device, _device);
1594 struct anv_state state;
1595 struct anv_event *event;
1596
1597 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
1598
1599 state = anv_state_pool_alloc(&device->dynamic_state_pool,
Jason Ekstrand25b09d12016-02-11 18:57:37 -08001600 sizeof(*event), 8);
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001601 event = state.map;
1602 event->state = state;
1603 event->semaphore = VK_EVENT_RESET;
1604
1605 if (!device->info.has_llc) {
1606 /* Make sure the writes we're flushing have landed. */
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001607 __builtin_ia32_mfence();
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001608 __builtin_ia32_clflush(event);
1609 }
1610
1611 *pEvent = anv_event_to_handle(event);
1612
1613 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001614}
1615
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001616void anv_DestroyEvent(
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001617 VkDevice _device,
1618 VkEvent _event,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001619 const VkAllocationCallbacks* pAllocator)
Chad Versace68c7ef52015-07-14 09:33:47 -07001620{
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001621 ANV_FROM_HANDLE(anv_device, device, _device);
1622 ANV_FROM_HANDLE(anv_event, event, _event);
1623
1624 anv_state_pool_free(&device->dynamic_state_pool, event->state);
Chad Versace68c7ef52015-07-14 09:33:47 -07001625}
1626
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001627VkResult anv_GetEventStatus(
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001628 VkDevice _device,
1629 VkEvent _event)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001630{
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001631 ANV_FROM_HANDLE(anv_device, device, _device);
1632 ANV_FROM_HANDLE(anv_event, event, _event);
1633
1634 if (!device->info.has_llc) {
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001635 /* Invalidate read cache before reading event written by GPU. */
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001636 __builtin_ia32_clflush(event);
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001637 __builtin_ia32_mfence();
1638
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001639 }
1640
1641 return event->semaphore;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001642}
1643
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001644VkResult anv_SetEvent(
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001645 VkDevice _device,
1646 VkEvent _event)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001647{
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001648 ANV_FROM_HANDLE(anv_device, device, _device);
1649 ANV_FROM_HANDLE(anv_event, event, _event);
1650
1651 event->semaphore = VK_EVENT_SET;
1652
1653 if (!device->info.has_llc) {
1654 /* Make sure the writes we're flushing have landed. */
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001655 __builtin_ia32_mfence();
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001656 __builtin_ia32_clflush(event);
1657 }
1658
1659 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001660}
1661
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001662VkResult anv_ResetEvent(
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001663 VkDevice _device,
1664 VkEvent _event)
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001665{
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001666 ANV_FROM_HANDLE(anv_device, device, _device);
1667 ANV_FROM_HANDLE(anv_event, event, _event);
1668
1669 event->semaphore = VK_EVENT_RESET;
1670
1671 if (!device->info.has_llc) {
1672 /* Make sure the writes we're flushing have landed. */
Kristian Høgsberg Kristensen0c4ef362016-01-29 12:10:12 -08001673 __builtin_ia32_mfence();
Kristian Høgsberg Kristensenc4802bc2015-12-19 22:17:19 -08001674 __builtin_ia32_clflush(event);
1675 }
1676
1677 return VK_SUCCESS;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001678}
1679
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001680// Buffer functions
1681
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001682VkResult anv_CreateBuffer(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001683 VkDevice _device,
1684 const VkBufferCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001685 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001686 VkBuffer* pBuffer)
1687{
Jason Ekstrandc8577b52015-07-08 14:24:12 -07001688 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001689 struct anv_buffer *buffer;
1690
1691 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
1692
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001693 buffer = anv_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
1694 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001695 if (buffer == NULL)
1696 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1697
1698 buffer->size = pCreateInfo->size;
Jason Ekstrand783a2112015-12-14 16:51:12 -08001699 buffer->usage = pCreateInfo->usage;
Kristian Høgsberg099faa12015-05-11 22:19:58 -07001700 buffer->bo = NULL;
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001701 buffer->offset = 0;
1702
Jason Ekstrand098209e2015-07-09 18:41:27 -07001703 *pBuffer = anv_buffer_to_handle(buffer);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001704
1705 return VK_SUCCESS;
1706}
1707
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001708void anv_DestroyBuffer(
Chad Versacee93b6d82015-07-14 09:47:45 -07001709 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001710 VkBuffer _buffer,
1711 const VkAllocationCallbacks* pAllocator)
Chad Versacee93b6d82015-07-14 09:47:45 -07001712{
1713 ANV_FROM_HANDLE(anv_device, device, _device);
1714 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
1715
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001716 anv_free2(&device->alloc, pAllocator, buffer);
Chad Versacee93b6d82015-07-14 09:47:45 -07001717}
1718
Kristian Høgsberg Kristensen8fe74ec2015-08-19 16:01:33 -07001719void
Francisco Jerez6840cc12016-01-26 14:50:52 -08001720anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state,
Jason Ekstrand1f98bf82015-12-14 16:14:20 -08001721 enum isl_format format,
Jason Ekstrand399d5312015-11-06 15:14:10 -08001722 uint32_t offset, uint32_t range, uint32_t stride)
Kristian Høgsberg Kristensen8fe74ec2015-08-19 16:01:33 -07001723{
Jason Ekstrandeb19d642016-02-22 16:54:25 -08001724 isl_buffer_fill_state(&device->isl_dev, state.map,
1725 .address = offset,
1726 .mocs = device->default_mocs,
1727 .size = range,
1728 .format = format,
1729 .stride = stride);
Francisco Jerez6840cc12016-01-26 14:50:52 -08001730
1731 if (!device->info.has_llc)
1732 anv_state_clflush(state);
Kristian Høgsberg Kristensen8fe74ec2015-08-19 16:01:33 -07001733}
1734
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001735void anv_DestroySampler(
Chad Versaceec5e2f42015-07-14 10:34:00 -07001736 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001737 VkSampler _sampler,
1738 const VkAllocationCallbacks* pAllocator)
Chad Versaceec5e2f42015-07-14 10:34:00 -07001739{
1740 ANV_FROM_HANDLE(anv_device, device, _device);
1741 ANV_FROM_HANDLE(anv_sampler, sampler, _sampler);
1742
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001743 anv_free2(&device->alloc, pAllocator, sampler);
Chad Versaceec5e2f42015-07-14 10:34:00 -07001744}
1745
Kristian Høgsberg454345d2015-05-17 16:33:48 -07001746VkResult anv_CreateFramebuffer(
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001747 VkDevice _device,
1748 const VkFramebufferCreateInfo* pCreateInfo,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001749 const VkAllocationCallbacks* pAllocator,
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001750 VkFramebuffer* pFramebuffer)
1751{
Jason Ekstrandc95f9b62015-07-09 18:20:10 -07001752 ANV_FROM_HANDLE(anv_device, device, _device);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001753 struct anv_framebuffer *framebuffer;
1754
1755 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
1756
Jason Ekstrand84783502015-07-10 20:18:52 -07001757 size_t size = sizeof(*framebuffer) +
Chad Versaced4446a72015-10-06 11:42:43 -07001758 sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount;
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001759 framebuffer = anv_alloc2(&device->alloc, pAllocator, size, 8,
1760 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001761 if (framebuffer == NULL)
1762 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1763
Jason Ekstrand84783502015-07-10 20:18:52 -07001764 framebuffer->attachment_count = pCreateInfo->attachmentCount;
1765 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
Chad Versace6dea1a92015-10-07 07:30:52 -07001766 VkImageView _iview = pCreateInfo->pAttachments[i];
Chad Versaced4446a72015-10-06 11:42:43 -07001767 framebuffer->attachments[i] = anv_image_view_from_handle(_iview);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001768 }
1769
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001770 framebuffer->width = pCreateInfo->width;
1771 framebuffer->height = pCreateInfo->height;
1772 framebuffer->layers = pCreateInfo->layers;
1773
Jason Ekstrand098209e2015-07-09 18:41:27 -07001774 *pFramebuffer = anv_framebuffer_to_handle(framebuffer);
Kristian Høgsberg769785c2015-05-08 22:32:37 -07001775
1776 return VK_SUCCESS;
1777}
1778
Jason Ekstrand05a26a62015-10-05 20:50:51 -07001779void anv_DestroyFramebuffer(
Chad Versace08f77312015-07-14 10:59:30 -07001780 VkDevice _device,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001781 VkFramebuffer _fb,
1782 const VkAllocationCallbacks* pAllocator)
Chad Versace08f77312015-07-14 10:59:30 -07001783{
1784 ANV_FROM_HANDLE(anv_device, device, _device);
1785 ANV_FROM_HANDLE(anv_framebuffer, fb, _fb);
1786
Jason Ekstrandfcfb4042015-12-02 03:28:27 -08001787 anv_free2(&device->alloc, pAllocator, fb);
Chad Versace08f77312015-07-14 10:59:30 -07001788}
1789
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001790void vkCmdDbgMarkerBegin(
Jason Ekstranda89a4852015-11-30 11:48:08 -08001791 VkCommandBuffer commandBuffer,
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001792 const char* pMarker)
1793 __attribute__ ((visibility ("default")));
1794
1795void vkCmdDbgMarkerEnd(
Jason Ekstranda89a4852015-11-30 11:48:08 -08001796 VkCommandBuffer commandBuffer)
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001797 __attribute__ ((visibility ("default")));
1798
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001799void vkCmdDbgMarkerBegin(
Jason Ekstranda89a4852015-11-30 11:48:08 -08001800 VkCommandBuffer commandBuffer,
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001801 const char* pMarker)
1802{
1803}
1804
1805void vkCmdDbgMarkerEnd(
Jason Ekstranda89a4852015-11-30 11:48:08 -08001806 VkCommandBuffer commandBuffer)
Kristian Høgsbergf8866472015-05-15 22:04:15 -07001807{
1808}