anv_device.c 93.9 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <assert.h>
#include <stdbool.h>
#include <string.h>
27
#include <sys/mman.h>
28
#include <sys/sysinfo.h>
Kristian Høgsberg's avatar
Kristian Høgsberg committed
29 30
#include <unistd.h>
#include <fcntl.h>
31
#include <xf86drm.h>
32
#include <drm_fourcc.h>
Kristian Høgsberg's avatar
Kristian Høgsberg committed
33

34
#include "anv_private.h"
35
#include "util/strtod.h"
36
#include "util/debug.h"
37
#include "util/build_id.h"
38
#include "util/mesa-sha1.h"
39
#include "vk_util.h"
40
#include "common/gen_defines.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
41

42
#include "genxml/gen7_pack.h"
43

44 45 46 47 48 49 50 51 52 53 54
static void
compiler_debug_log(void *data, const char *fmt, ...)
{ }

static void
compiler_perf_log(void *data, const char *fmt, ...)
{
   va_list args;
   va_start(args, fmt);

   if (unlikely(INTEL_DEBUG & DEBUG_PERF))
55
      intel_logd_v(fmt, args);
56 57 58 59

   va_end(args);
}

60 61 62 63 64 65 66 67 68
static VkResult
anv_compute_heap_size(int fd, uint64_t *heap_size)
{
   uint64_t gtt_size;
   if (anv_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE,
                                 &gtt_size) == -1) {
      /* If, for whatever reason, we can't actually get the GTT size from the
       * kernel (too old?) fall back to the aperture size.
       */
69 70
      anv_perf_warn(NULL, NULL,
                    "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
71 72

      if (anv_gem_get_aperture(fd, &gtt_size) == -1) {
73
         return vk_errorf(NULL, NULL, VK_ERROR_INITIALIZATION_FAILED,
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
                          "failed to get aperture size: %m");
      }
   }

   /* Query the total ram from the system */
   struct sysinfo info;
   sysinfo(&info);

   uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;

   /* We don't want to burn too much ram with the GPU.  If the user has 4GiB
    * or less, we use at most half.  If they have more than 4GiB, we use 3/4.
    */
   uint64_t available_ram;
   if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
      available_ram = total_ram / 2;
   else
      available_ram = total_ram * 3 / 4;

   /* We also want to leave some padding for things we allocate in the driver,
    * so don't go over 3/4 of the GTT either.
    */
   uint64_t available_gtt = gtt_size * 3 / 4;

   *heap_size = MIN2(available_ram, available_gtt);

   return VK_SUCCESS;
}

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
static VkResult
anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
{
   /* The kernel query only tells us whether or not the kernel supports the
    * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
    * hardware has actual 48bit address support.
    */
   device->supports_48bit_addresses =
      (device->info.gen >= 8) && anv_gem_supports_48b_addresses(fd);

   uint64_t heap_size;
   VkResult result = anv_compute_heap_size(fd, &heap_size);
   if (result != VK_SUCCESS)
      return result;

118 119 120 121 122 123 124 125 126 127 128 129
   if (heap_size > (2ull << 30) && !device->supports_48bit_addresses) {
      /* When running with an overridden PCI ID, we may get a GTT size from
       * the kernel that is greater than 2 GiB but the execbuf check for 48bit
       * address support can still fail.  Just clamp the address space size to
       * 2 GiB if we don't have 48-bit support.
       */
      intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
                        "not support for 48-bit addresses",
                        __FILE__, __LINE__);
      heap_size = 2ull << 30;
   }

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
   if (heap_size <= 3ull * (1ull << 30)) {
      /* In this case, everything fits nicely into the 32-bit address space,
       * so there's no need for supporting 48bit addresses on client-allocated
       * memory objects.
       */
      device->memory.heap_count = 1;
      device->memory.heaps[0] = (struct anv_memory_heap) {
         .size = heap_size,
         .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
         .supports_48bit_addresses = false,
      };
   } else {
      /* Not everything will fit nicely into a 32-bit address space.  In this
       * case we need a 64-bit heap.  Advertise a small 32-bit heap and a
       * larger 48-bit heap.  If we're in this case, then we have a total heap
       * size larger than 3GiB which most likely means they have 8 GiB of
       * video memory and so carving off 1 GiB for the 32-bit heap should be
       * reasonable.
       */
      const uint64_t heap_size_32bit = 1ull << 30;
      const uint64_t heap_size_48bit = heap_size - heap_size_32bit;

      assert(device->supports_48bit_addresses);

      device->memory.heap_count = 2;
      device->memory.heaps[0] = (struct anv_memory_heap) {
         .size = heap_size_48bit,
         .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
         .supports_48bit_addresses = true,
      };
      device->memory.heaps[1] = (struct anv_memory_heap) {
         .size = heap_size_32bit,
         .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
         .supports_48bit_addresses = false,
      };
   }
166

167 168 169 170
   uint32_t type_count = 0;
   for (uint32_t heap = 0; heap < device->memory.heap_count; heap++) {
      uint32_t valid_buffer_usage = ~0;

171 172 173 174 175 176 177 178 179 180 181 182
      /* There appears to be a hardware issue in the VF cache where it only
       * considers the bottom 32 bits of memory addresses.  If you happen to
       * have two vertex buffers which get placed exactly 4 GiB apart and use
       * them in back-to-back draw calls, you can get collisions.  In order to
       * solve this problem, we require vertex and index buffers be bound to
       * memory allocated out of the 32-bit heap.
       */
      if (device->memory.heaps[heap].supports_48bit_addresses) {
         valid_buffer_usage &= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
                                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
      }

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
      if (device->info.has_llc) {
         /* Big core GPUs share LLC with the CPU and thus one memory type can be
          * both cached and coherent at the same time.
          */
         device->memory.types[type_count++] = (struct anv_memory_type) {
            .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                             VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                             VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
                             VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
            .heapIndex = heap,
            .valid_buffer_usage = valid_buffer_usage,
         };
      } else {
         /* The spec requires that we expose a host-visible, coherent memory
          * type, but Atom GPUs don't share LLC. Thus we offer two memory types
          * to give the application a choice between cached, but not coherent and
          * coherent but uncached (WC though).
          */
         device->memory.types[type_count++] = (struct anv_memory_type) {
            .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                             VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                             VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
            .heapIndex = heap,
            .valid_buffer_usage = valid_buffer_usage,
         };
         device->memory.types[type_count++] = (struct anv_memory_type) {
            .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                             VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                             VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
            .heapIndex = heap,
            .valid_buffer_usage = valid_buffer_usage,
         };
      }
   }
   device->memory.type_count = type_count;

219 220 221
   return VK_SUCCESS;
}

222 223
static VkResult
anv_physical_device_init_uuids(struct anv_physical_device *device)
224
{
225 226
   const struct build_id_note *note =
      build_id_find_nhdr_for_addr(anv_physical_device_init_uuids);
227
   if (!note) {
228 229
      return vk_errorf(device->instance, device,
                       VK_ERROR_INITIALIZATION_FAILED,
230 231
                       "Failed to find build-id");
   }
232

233
   unsigned build_id_len = build_id_length(note);
234
   if (build_id_len < 20) {
235 236
      return vk_errorf(device->instance, device,
                       VK_ERROR_INITIALIZATION_FAILED,
237 238
                       "build-id too short.  It needs to be a SHA");
   }
239

240 241 242 243
   struct mesa_sha1 sha1_ctx;
   uint8_t sha1[20];
   STATIC_ASSERT(VK_UUID_SIZE <= sizeof(sha1));

244 245 246
   /* The pipeline cache UUID is used for determining when a pipeline cache is
    * invalid.  It needs both a driver build and the PCI ID of the device.
    */
247 248
   _mesa_sha1_init(&sha1_ctx);
   _mesa_sha1_update(&sha1_ctx, build_id_data(note), build_id_len);
249 250
   _mesa_sha1_update(&sha1_ctx, &device->chipset_id,
                     sizeof(device->chipset_id));
251
   _mesa_sha1_final(&sha1_ctx, sha1);
252
   memcpy(device->pipeline_cache_uuid, sha1, VK_UUID_SIZE);
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
   /* The driver UUID is used for determining sharability of images and memory
    * between two Vulkan instances in separate processes.  People who want to
    * share memory need to also check the device UUID (below) so all this
    * needs to be is the build-id.
    */
   memcpy(device->driver_uuid, build_id_data(note), VK_UUID_SIZE);

   /* The device UUID uniquely identifies the given device within the machine.
    * Since we never have more than one device, this doesn't need to be a real
    * UUID.  However, on the off-chance that someone tries to use this to
    * cache pre-tiled images or something of the like, we use the PCI ID and
    * some bits of ISL info to ensure that this is safe.
    */
   _mesa_sha1_init(&sha1_ctx);
   _mesa_sha1_update(&sha1_ctx, &device->chipset_id,
                     sizeof(device->chipset_id));
   _mesa_sha1_update(&sha1_ctx, &device->isl_dev.has_bit6_swizzling,
                     sizeof(device->isl_dev.has_bit6_swizzling));
   _mesa_sha1_final(&sha1_ctx, sha1);
   memcpy(device->device_uuid, sha1, VK_UUID_SIZE);

275
   return VK_SUCCESS;
276 277
}

Kristian Høgsberg's avatar
Kristian Høgsberg committed
278
static VkResult
279 280 281
anv_physical_device_init(struct anv_physical_device *device,
                         struct anv_instance *instance,
                         const char *path)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
282
{
283
   VkResult result;
284 285
   int fd;

286 287
   brw_process_intel_debug_variable();

288 289
   fd = open(path, O_RDWR | O_CLOEXEC);
   if (fd < 0)
290
      return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
291

292
   device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
293
   device->instance = instance;
294 295 296

   assert(strlen(path) < ARRAY_SIZE(device->path));
   strncpy(device->path, path, ARRAY_SIZE(device->path));
Chad Versace's avatar
Chad Versace committed
297

298 299
   device->no_hw = getenv("INTEL_NO_HW") != NULL;

300 301 302 303 304 305 306 307 308 309
   const int pci_id_override = gen_get_pci_device_id_override();
   if (pci_id_override < 0) {
      device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID);
      if (!device->chipset_id) {
         result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
         goto fail;
      }
   } else {
      device->chipset_id = pci_id_override;
      device->no_hw = true;
310
   }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
311

312
   device->name = gen_get_device_name(device->chipset_id);
313
   if (!gen_get_device_info(device->chipset_id, &device->info)) {
314
      result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
315
      goto fail;
316
   }
317

318
   if (device->info.is_haswell) {
319
      intel_logw("Haswell Vulkan support is incomplete");
320
   } else if (device->info.gen == 7 && !device->info.is_baytrail) {
321
      intel_logw("Ivy Bridge Vulkan support is incomplete");
322
   } else if (device->info.gen == 7 && device->info.is_baytrail) {
323
      intel_logw("Bay Trail Vulkan support is incomplete");
324 325
   } else if (device->info.gen >= 8 && device->info.gen <= 10) {
      /* Gen8-10 fully supported */
326
   } else {
327 328
      result = vk_errorf(device->instance, device,
                         VK_ERROR_INCOMPATIBLE_DRIVER,
329 330 331 332
                         "Vulkan not yet supported on %s", device->name);
      goto fail;
   }

333
   device->cmd_parser_version = -1;
334
   if (device->info.gen == 7) {
335 336 337
      device->cmd_parser_version =
         anv_gem_get_param(fd, I915_PARAM_CMD_PARSER_VERSION);
      if (device->cmd_parser_version == -1) {
338 339
         result = vk_errorf(device->instance, device,
                            VK_ERROR_INITIALIZATION_FAILED,
340 341 342 343 344
                            "failed to get command parser version");
         goto fail;
      }
   }

345
   if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) {
346 347
      result = vk_errorf(device->instance, device,
                         VK_ERROR_INITIALIZATION_FAILED,
Chad Versace's avatar
Chad Versace committed
348
                         "kernel missing gem wait");
Kristian Høgsberg's avatar
Kristian Høgsberg committed
349
      goto fail;
350
   }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
351

352
   if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) {
353 354
      result = vk_errorf(device->instance, device,
                         VK_ERROR_INITIALIZATION_FAILED,
Chad Versace's avatar
Chad Versace committed
355
                         "kernel missing execbuf2");
Kristian Høgsberg's avatar
Kristian Høgsberg committed
356
      goto fail;
357
   }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
358

359
   if (!device->info.has_llc &&
360
       anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) {
361 362
      result = vk_errorf(device->instance, device,
                         VK_ERROR_INITIALIZATION_FAILED,
363 364 365 366
                         "kernel missing wc mmap");
      goto fail;
   }

367
   result = anv_physical_device_init_heaps(device, fd);
368 369 370
   if (result != VK_SUCCESS)
      goto fail;

371
   device->has_exec_async = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_ASYNC);
372
   device->has_exec_capture = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CAPTURE);
373
   device->has_exec_fence = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_FENCE);
374
   device->has_syncobj = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_FENCE_ARRAY);
375 376
   device->has_syncobj_wait = device->has_syncobj &&
                              anv_gem_supports_syncobj_wait(fd);
377
   device->has_context_priority = anv_gem_has_context_priority(fd);
378

379 380
   bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X);

381 382 383 384 385 386 387 388 389 390 391 392 393
   /* Starting with Gen10, the timestamp frequency of the command streamer may
    * vary from one part to another. We can query the value from the kernel.
    */
   if (device->info.gen >= 10) {
      int timestamp_frequency =
         anv_gem_get_param(fd, I915_PARAM_CS_TIMESTAMP_FREQUENCY);

      if (timestamp_frequency < 0)
         intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
      else
         device->info.timestamp_frequency = timestamp_frequency;
   }

394
   /* GENs prior to 8 do not support EU/Subslice info */
395
   if (device->info.gen >= 8) {
396 397 398 399 400 401 402 403
      device->subslice_total = anv_gem_get_param(fd, I915_PARAM_SUBSLICE_TOTAL);
      device->eu_total = anv_gem_get_param(fd, I915_PARAM_EU_TOTAL);

      /* Without this information, we cannot get the right Braswell
       * brandstrings, and we have to use conservative numbers for GPGPU on
       * many platforms, but otherwise, things will just work.
       */
      if (device->subslice_total < 1 || device->eu_total < 1) {
404
         intel_logw("Kernel 4.1 required to properly query GPU properties");
405
      }
406 407
   } else if (device->info.gen == 7) {
      device->subslice_total = 1 << (device->info.gt - 1);
408 409
   }

410
   if (device->info.is_cherryview &&
411
       device->subslice_total > 0 && device->eu_total > 0) {
412 413 414
      /* Logical CS threads = EUs per subslice * num threads per EU */
      uint32_t max_cs_threads =
         device->eu_total / device->subslice_total * device->info.num_thread_per_eu;
415 416

      /* Fuse configurations may give more threads than expected, never less. */
417 418
      if (max_cs_threads > device->info.max_cs_threads)
         device->info.max_cs_threads = max_cs_threads;
419 420
   }

421
   device->compiler = brw_compiler_create(NULL, &device->info);
422 423 424 425
   if (device->compiler == NULL) {
      result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
      goto fail;
   }
426 427
   device->compiler->shader_debug_log = compiler_debug_log;
   device->compiler->shader_perf_log = compiler_perf_log;
428
   device->compiler->supports_pull_constants = false;
Jason Ekstrand's avatar
Jason Ekstrand committed
429
   device->compiler->constant_buffer_0_is_relative = true;
430

431 432 433 434 435 436
   isl_device_init(&device->isl_dev, &device->info, swizzled);

   result = anv_physical_device_init_uuids(device);
   if (result != VK_SUCCESS)
      goto fail;

437
   result = anv_init_wsi(device);
438 439 440 441
   if (result != VK_SUCCESS) {
      ralloc_free(device->compiler);
      goto fail;
   }
442

443 444 445
   anv_physical_device_get_supported_extensions(device,
                                                &device->supported_extensions);

446
   device->local_fd = fd;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
447
   return VK_SUCCESS;
448

449
fail:
450
   close(fd);
451
   return result;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
452 453
}

454 455 456
static void
anv_physical_device_finish(struct anv_physical_device *device)
{
457
   anv_finish_wsi(device);
458
   ralloc_free(device->compiler);
459
   close(device->local_fd);
460 461
}

462
static void *
463
default_alloc_func(void *pUserData, size_t size, size_t align,
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
                   VkSystemAllocationScope allocationScope)
{
   return malloc(size);
}

static void *
default_realloc_func(void *pUserData, void *pOriginal, size_t size,
                     size_t align, VkSystemAllocationScope allocationScope)
{
   return realloc(pOriginal, size);
}

static void
default_free_func(void *pUserData, void *pMemory)
{
   free(pMemory);
}

static const VkAllocationCallbacks default_alloc = {
   .pUserData = NULL,
   .pfnAllocation = default_alloc_func,
   .pfnReallocation = default_realloc_func,
   .pfnFree = default_free_func,
};

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
VkResult anv_EnumerateInstanceExtensionProperties(
    const char*                                 pLayerName,
    uint32_t*                                   pPropertyCount,
    VkExtensionProperties*                      pProperties)
{
   VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);

   for (int i = 0; i < ANV_INSTANCE_EXTENSION_COUNT; i++) {
      if (anv_instance_extensions_supported.extensions[i]) {
         vk_outarray_append(&out, prop) {
            *prop = anv_instance_extensions[i];
         }
      }
   }

   return vk_outarray_status(&out);
}

507
VkResult anv_CreateInstance(
Kristian Høgsberg's avatar
Kristian Høgsberg committed
508
    const VkInstanceCreateInfo*                 pCreateInfo,
509
    const VkAllocationCallbacks*                pAllocator,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
510 511 512
    VkInstance*                                 pInstance)
{
   struct anv_instance *instance;
513
   VkResult result;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
514 515 516

   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);

517 518 519 520 521 522 523
   /* Check if user passed a debug report callback to be used during
    * Create/Destroy of instance.
    */
   const VkDebugReportCallbackCreateInfoEXT *ctor_cb =
      vk_find_struct_const(pCreateInfo->pNext,
                           DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT);

524 525 526 527 528 529 530 531
   uint32_t client_version;
   if (pCreateInfo->pApplicationInfo &&
       pCreateInfo->pApplicationInfo->apiVersion != 0) {
      client_version = pCreateInfo->pApplicationInfo->apiVersion;
   } else {
      client_version = VK_MAKE_VERSION(1, 0, 0);
   }

Jason Ekstrand's avatar
Jason Ekstrand committed
532
   if (VK_MAKE_VERSION(1, 0, 0) > client_version ||
533
       client_version > VK_MAKE_VERSION(1, 0, 0xfff)) {
534 535 536 537 538 539 540 541 542 543 544

      if (ctor_cb && ctor_cb->flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
         ctor_cb->pfnCallback(VK_DEBUG_REPORT_ERROR_BIT_EXT,
                              VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
                              VK_NULL_HANDLE, /* No handle available yet. */
                              __LINE__,
                              0,
                              "anv",
                              "incompatible driver version",
                              ctor_cb->pUserData);

545
      return vk_errorf(NULL, NULL, VK_ERROR_INCOMPATIBLE_DRIVER,
546 547 548 549
                       "Client requested version %d.%d.%d",
                       VK_VERSION_MAJOR(client_version),
                       VK_VERSION_MINOR(client_version),
                       VK_VERSION_PATCH(client_version));
550
   }
551

552
   struct anv_instance_extension_table enabled_extensions = {};
553
   for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
554 555 556 557 558 559 560 561 562 563 564
      int idx;
      for (idx = 0; idx < ANV_INSTANCE_EXTENSION_COUNT; idx++) {
         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
                    anv_instance_extensions[idx].extensionName) == 0)
            break;
      }

      if (idx >= ANV_INSTANCE_EXTENSION_COUNT)
         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);

      if (!anv_instance_extensions_supported.extensions[idx])
Chad Versace's avatar
Chad Versace committed
565
         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
566 567

      enabled_extensions.extensions[idx] = true;
568 569
   }

570
   instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
571
                         VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
572 573 574
   if (!instance)
      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);

575
   instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
576 577 578 579 580 581

   if (pAllocator)
      instance->alloc = *pAllocator;
   else
      instance->alloc = default_alloc;

582
   instance->apiVersion = client_version;
583
   instance->enabled_extensions = enabled_extensions;
584 585 586 587 588 589 590 591

   for (unsigned i = 0; i < ARRAY_SIZE(instance->dispatch.entrypoints); i++) {
      /* Vulkan requires that entrypoints for extensions which have not been
       * enabled must not be advertised.
       */
      if (!anv_entrypoint_is_enabled(i, instance->apiVersion,
                                     &instance->enabled_extensions, NULL)) {
         instance->dispatch.entrypoints[i] = NULL;
592
      } else if (anv_dispatch_table.entrypoints[i] != NULL) {
593
         instance->dispatch.entrypoints[i] = anv_dispatch_table.entrypoints[i];
594 595 596
      } else {
         instance->dispatch.entrypoints[i] =
            anv_tramp_dispatch_table.entrypoints[i];
597 598 599
      }
   }

600
   instance->physicalDeviceCount = -1;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
601

602 603
   result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
   if (result != VK_SUCCESS) {
604
      vk_free2(&default_alloc, pAllocator, instance);
605
      return vk_error(result);
606 607
   }

608 609
   _mesa_locale_init();

610 611
   VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));

612
   *pInstance = anv_instance_to_handle(instance);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
613 614 615 616

   return VK_SUCCESS;
}

617
void anv_DestroyInstance(
618 619
    VkInstance                                  _instance,
    const VkAllocationCallbacks*                pAllocator)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
620
{
621
   ANV_FROM_HANDLE(anv_instance, instance, _instance);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
622

623 624 625
   if (!instance)
      return;

626 627 628 629 630 631
   if (instance->physicalDeviceCount > 0) {
      /* We support at most one physical device. */
      assert(instance->physicalDeviceCount == 1);
      anv_physical_device_finish(&instance->physicalDevice);
   }

632 633
   VG(VALGRIND_DESTROY_MEMPOOL(instance));

634
   vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
635

636 637
   _mesa_locale_fini();

638
   vk_free(&instance->alloc, instance);
639 640
}

641 642 643 644 645 646 647 648 649 650
static VkResult
anv_enumerate_devices(struct anv_instance *instance)
{
   /* TODO: Check for more devices ? */
   drmDevicePtr devices[8];
   VkResult result = VK_ERROR_INCOMPATIBLE_DRIVER;
   int max_devices;

   instance->physicalDeviceCount = 0;

651
   max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
   if (max_devices < 1)
      return VK_ERROR_INCOMPATIBLE_DRIVER;

   for (unsigned i = 0; i < (unsigned)max_devices; i++) {
      if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
          devices[i]->bustype == DRM_BUS_PCI &&
          devices[i]->deviceinfo.pci->vendor_id == 0x8086) {

         result = anv_physical_device_init(&instance->physicalDevice,
                        instance,
                        devices[i]->nodes[DRM_NODE_RENDER]);
         if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
            break;
      }
   }
667
   drmFreeDevices(devices, max_devices);
668 669 670 671 672 673 674 675

   if (result == VK_SUCCESS)
      instance->physicalDeviceCount = 1;

   return result;
}


676
VkResult anv_EnumeratePhysicalDevices(
Kristian Høgsberg's avatar
Kristian Høgsberg committed
677 678 679 680
    VkInstance                                  _instance,
    uint32_t*                                   pPhysicalDeviceCount,
    VkPhysicalDevice*                           pPhysicalDevices)
{
681
   ANV_FROM_HANDLE(anv_instance, instance, _instance);
682
   VK_OUTARRAY_MAKE(out, pPhysicalDevices, pPhysicalDeviceCount);
683 684
   VkResult result;

685
   if (instance->physicalDeviceCount < 0) {
686 687 688
      result = anv_enumerate_devices(instance);
      if (result != VK_SUCCESS &&
          result != VK_ERROR_INCOMPATIBLE_DRIVER)
689 690
         return result;
   }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
691

692 693 694 695 696
   if (instance->physicalDeviceCount > 0) {
      assert(instance->physicalDeviceCount == 1);
      vk_outarray_append(&out, i) {
         *i = anv_physical_device_to_handle(&instance->physicalDevice);
      }
697
   }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
698

699
   return vk_outarray_status(&out);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
700 701
}

702
void anv_GetPhysicalDeviceFeatures(
703 704 705
    VkPhysicalDevice                            physicalDevice,
    VkPhysicalDeviceFeatures*                   pFeatures)
{
706
   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
707 708

   *pFeatures = (VkPhysicalDeviceFeatures) {
709
      .robustBufferAccess                       = true,
710
      .fullDrawIndexUint32                      = true,
711
      .imageCubeArray                           = true,
712
      .independentBlend                         = true,
713
      .geometryShader                           = true,
714
      .tessellationShader                       = true,
715
      .sampleRateShading                        = true,
716
      .dualSrcBlend                             = true,
717
      .logicOp                                  = true,
718
      .multiDrawIndirect                        = true,
719
      .drawIndirectFirstInstance                = true,
720
      .depthClamp                               = true,
721
      .depthBiasClamp                           = true,
722 723 724 725
      .fillModeNonSolid                         = true,
      .depthBounds                              = false,
      .wideLines                                = true,
      .largePoints                              = true,
726 727
      .alphaToOne                               = true,
      .multiViewport                            = true,
728
      .samplerAnisotropy                        = true,
729 730 731
      .textureCompressionETC2                   = pdevice->info.gen >= 8 ||
                                                  pdevice->info.is_baytrail,
      .textureCompressionASTC_LDR               = pdevice->info.gen >= 9, /* FINISHME CHV */
732
      .textureCompressionBC                     = true,
733
      .occlusionQueryPrecise                    = true,
734
      .pipelineStatisticsQuery                  = true,
735 736
      .fragmentStoresAndAtomics                 = true,
      .shaderTessellationAndGeometryPointSize   = true,
737
      .shaderImageGatherExtended                = true,
738
      .shaderStorageImageExtendedFormats        = true,
739
      .shaderStorageImageMultisample            = false,
740
      .shaderStorageImageReadWithoutFormat      = false,
741
      .shaderStorageImageWriteWithoutFormat     = true,
742
      .shaderUniformBufferArrayDynamicIndexing  = true,
743 744 745
      .shaderSampledImageArrayDynamicIndexing   = true,
      .shaderStorageBufferArrayDynamicIndexing  = true,
      .shaderStorageImageArrayDynamicIndexing   = true,
746 747
      .shaderClipDistance                       = true,
      .shaderCullDistance                       = true,
748
      .shaderFloat64                            = pdevice->info.gen >= 8,
749
      .shaderInt64                              = pdevice->info.gen >= 8,
750
      .shaderInt16                              = false,
751
      .shaderResourceMinLod                     = false,
752
      .variableMultisampleRate                  = false,
753
      .inheritedQueries                         = true,
754
   };
755 756 757

   /* We can't do image stores in vec4 shaders */
   pFeatures->vertexPipelineStoresAndAtomics =
758 759
      pdevice->compiler->scalar_stage[MESA_SHADER_VERTEX] &&
      pdevice->compiler->scalar_stage[MESA_SHADER_GEOMETRY];
760 761
}

762
void anv_GetPhysicalDeviceFeatures2(
763
    VkPhysicalDevice                            physicalDevice,
764
    VkPhysicalDeviceFeatures2*                  pFeatures)
765 766 767
{
   anv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);

768 769
   vk_foreach_struct(ext, pFeatures->pNext) {
      switch (ext->sType) {
770 771 772
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
         VkPhysicalDeviceMultiviewFeatures *features =
            (VkPhysicalDeviceMultiviewFeatures *)ext;
773 774 775 776 777 778
         features->multiview = true;
         features->multiviewGeometryShader = true;
         features->multiviewTessellationShader = true;
         break;
      }

779 780
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES: {
         VkPhysicalDeviceVariablePointerFeatures *features = (void *)ext;
781
         features->variablePointersStorageBuffer = true;
782
         features->variablePointers = true;
783 784 785
         break;
      }

786 787 788
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
         VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
            (VkPhysicalDeviceSamplerYcbcrConversionFeatures *) ext;
789 790 791 792
         features->samplerYcbcrConversion = true;
         break;
      }

793 794 795
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR: {
         VkPhysicalDevice16BitStorageFeaturesKHR *features =
            (VkPhysicalDevice16BitStorageFeaturesKHR *)ext;
796
         ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
797

798 799
         features->storageBuffer16BitAccess = pdevice->info.gen >= 8;
         features->uniformAndStorageBuffer16BitAccess = pdevice->info.gen >= 8;
800
         features->storagePushConstant16 = pdevice->info.gen >= 8;
801 802 803 804
         features->storageInputOutput16 = false;
         break;
      }

805
      default:
806
         anv_debug_ignored_stype(ext->sType);
807 808 809 810 811
         break;
      }
   }
}

812
void anv_GetPhysicalDeviceProperties(
813
    VkPhysicalDevice                            physicalDevice,
814
    VkPhysicalDeviceProperties*                 pProperties)
815
{
816
   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
817
   const struct gen_device_info *devinfo = &pdevice->info;
818

819 820 821 822
   /* See assertions made when programming the buffer surface state. */
   const uint32_t max_raw_buffer_sz = devinfo->gen >= 7 ?
                                      (1ul << 30) : (1ul << 27);

823 824 825
   const uint32_t max_samplers = (devinfo->gen >= 8 || devinfo->is_haswell) ?
                                 128 : 16;

826
   VkSampleCountFlags sample_counts =
827
      isl_device_get_sample_counts(&pdevice->isl_dev);
828

829
   VkPhysicalDeviceLimits limits = {
830 831
      .maxImageDimension1D                      = (1 << 14),
      .maxImageDimension2D                      = (1 << 14),
832
      .maxImageDimension3D                      = (1 << 11),
833
      .maxImageDimensionCube                    = (1 << 14),
834
      .maxImageArrayLayers                      = (1 << 11),
835
      .maxTexelBufferElements                   = 128 * 1024 * 1024,
836 837
      .maxUniformBufferRange                    = (1ul << 27),
      .maxStorageBufferRange                    = max_raw_buffer_sz,
838
      .maxPushConstantsSize                     = MAX_PUSH_CONSTANTS_SIZE,
839
      .maxMemoryAllocationCount                 = UINT32_MAX,
840
      .maxSamplerAllocationCount                = 64 * 1024,
841
      .bufferImageGranularity                   = 64, /* A cache line */
842
      .sparseAddressSpaceSize                   = 0,
843
      .maxBoundDescriptorSets                   = MAX_SETS,
844
      .maxPerStageDescriptorSamplers            = max_samplers,
845 846
      .maxPerStageDescriptorUniformBuffers      = 64,
      .maxPerStageDescriptorStorageBuffers      = 64,
847
      .maxPerStageDescriptorSampledImages       = max_samplers,
848
      .maxPerStageDescriptorStorageImages       = 64,
849
      .maxPerStageDescriptorInputAttachments    = 64,
850
      .maxPerStageResources                     = 250,
851 852
      .maxDescriptorSetSamplers                 = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSamplers */
      .maxDescriptorSetUniformBuffers           = 6 * 64,           /* number of stages * maxPerStageDescriptorUniformBuffers */
853
      .maxDescriptorSetUniformBuffersDynamic    = MAX_DYNAMIC_BUFFERS / 2,
854
      .maxDescriptorSetStorageBuffers           = 6 * 64,           /* number of stages * maxPerStageDescriptorStorageBuffers */
855
      .maxDescriptorSetStorageBuffersDynamic    = MAX_DYNAMIC_BUFFERS / 2,
856 857
      .maxDescriptorSetSampledImages            = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSampledImages */
      .maxDescriptorSetStorageImages            = 6 * 64,           /* number of stages * maxPerStageDescriptorStorageImages */
858
      .maxDescriptorSetInputAttachments         = 256,
859 860
      .maxVertexInputAttributes                 = MAX_VBS,
      .maxVertexInputBindings                   = MAX_VBS,
861 862 863
      .maxVertexInputAttributeOffset            = 2047,
      .maxVertexInputBindingStride              = 2048,
      .maxVertexOutputComponents                = 128,
864 865 866 867 868 869 870 871
      .maxTessellationGenerationLevel           = 64,
      .maxTessellationPatchSize                 = 32,
      .maxTessellationControlPerVertexInputComponents = 128,
      .maxTessellationControlPerVertexOutputComponents = 128,
      .maxTessellationControlPerPatchOutputComponents = 128,
      .maxTessellationControlTotalOutputComponents = 2048,
      .maxTessellationEvaluationInputComponents = 128,
      .maxTessellationEvaluationOutputComponents = 128,
872 873 874 875 876 877
      .maxGeometryShaderInvocations             = 32,
      .maxGeometryInputComponents               = 64,
      .maxGeometryOutputComponents              = 128,
      .maxGeometryOutputVertices                = 256,
      .maxGeometryTotalOutputComponents         = 1024,
      .maxFragmentInputComponents               = 128,
878
      .maxFragmentOutputAttachments             = 8,
879
      .maxFragmentDualSrcAttachments            = 1,
880
      .maxFragmentCombinedOutputResources       = 8,
881 882
      .maxComputeSharedMemorySize               = 32768,
      .maxComputeWorkGroupCount                 = { 65535, 65535, 65535 },
883
      .maxComputeWorkGroupInvocations           = 16 * devinfo->max_cs_threads,
884
      .maxComputeWorkGroupSize = {
885 886 887
         16 * devinfo->max_cs_threads,
         16 * devinfo->max_cs_threads,
         16 * devinfo->max_cs_threads,
888 889 890 891 892
      },
      .subPixelPrecisionBits                    = 4 /* FIXME */,
      .subTexelPrecisionBits                    = 4 /* FIXME */,
      .mipmapPrecisionBits                      = 4 /* FIXME */,
      .maxDrawIndexedIndexValue                 = UINT32_MAX,
893
      .maxDrawIndirectCount                     = UINT32_MAX,
894 895
      .maxSamplerLodBias                        = 16,
      .maxSamplerAnisotropy                     = 16,
896
      .maxViewports                             = MAX_VIEWPORTS,
897
      .maxViewportDimensions                    = { (1 << 14), (1 << 14) },
898
      .viewportBoundsRange                      = { INT16_MIN, INT16_MAX },
899
      .viewportSubPixelBits                     = 13, /* We take a float? */
900
      .minMemoryMapAlignment                    = 4096, /* A page */
901
      .minTexelBufferOffsetAlignment            = 1,
902 903
      /* We need 16 for UBO block reads to work and 32 for push UBOs */
      .minUniformBufferOffsetAlignment          = 32,
904
      .minStorageBufferOffsetAlignment          = 4,
905 906
      .minTexelOffset                           = -8,
      .maxTexelOffset                           = 7,
907 908
      .minTexelGatherOffset                     = -32,
      .maxTexelGatherOffset                     = 31,
909 910 911
      .minInterpolationOffset                   = -0.5,
      .maxInterpolationOffset                   = 0.4375,
      .subPixelInterpolationOffsetBits          = 4,
912 913
      .maxFramebufferWidth                      = (1 << 14),
      .maxFramebufferHeight                     = (1 << 14),
914
      .maxFramebufferLayers                     = (1 << 11),
915 916 917 918
      .framebufferColorSampleCounts             = sample_counts,
      .framebufferDepthSampleCounts             = sample_counts,
      .framebufferStencilSampleCounts           = sample_counts,
      .framebufferNoAttachmentsSampleCounts     = sample_counts,
919
      .maxColorAttachments                      = MAX_RTS,
920 921 922 923 924
      .sampledImageColorSampleCounts            = sample_counts,
      .sampledImageIntegerSampleCounts          = VK_SAMPLE_COUNT_1_BIT,
      .sampledImageDepthSampleCounts            = sample_counts,
      .sampledImageStencilSampleCounts          = sample_counts,
      .storageImageSampleCounts                 = VK_SAMPLE_COUNT_1_BIT,
925
      .maxSampleMaskWords                       = 1,
926
      .timestampComputeAndGraphics              = false,
927
      .timestampPeriod                          = 1000000000.0 / devinfo->timestamp_frequency,
928 929 930
      .maxClipDistances                         = 8,
      .maxCullDistances                         = 8,
      .maxCombinedClipAndCullDistances          = 8,
931
      .discreteQueuePriorities                  = 1,
932 933 934 935
      .pointSizeRange                           = { 0.125, 255.875 },
      .lineWidthRange                           = { 0.0, 7.9921875 },
      .pointSizeGranularity                     = (1.0 / 8.0),
      .lineWidthGranularity                     = (1.0 / 128.0),
936
      .strictLines                              = false, /* FINISHME */
937
      .standardSampleLocations                  = true,
938 939 940
      .optimalBufferCopyOffsetAlignment         = 128,
      .optimalBufferCopyRowPitchAlignment       = 128,
      .nonCoherentAtomSize                      = 64,
941 942
   };

943
   *pProperties = (VkPhysicalDeviceProperties) {
944
      .apiVersion = anv_physical_device_api_version(pdevice),
945
      .driverVersion = vk_get_driver_version(),
946 947
      .vendorID = 0x8086,
      .deviceID = pdevice->chipset_id,
948
      .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
949 950
      .limits = limits,
      .sparseProperties = {0}, /* Broadwell doesn't do sparse. */
951 952
   };

953 954
   snprintf(pProperties->deviceName, sizeof(pProperties->deviceName),
            "%s", pdevice->name);
955 956
   memcpy(pProperties->pipelineCacheUUID,
          pdevice->pipeline_cache_uuid, VK_UUID_SIZE);
957 958
}

959
void anv_GetPhysicalDeviceProperties2(
960
    VkPhysicalDevice                            physicalDevice,
961
    VkPhysicalDeviceProperties2*                pProperties)
962
{
963 964
   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);

965 966
   anv_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);

967 968
   vk_foreach_struct(ext, pProperties->pNext) {
      switch (ext->sType) {
969 970 971 972 973 974 975 976
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
         VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
            (VkPhysicalDevicePushDescriptorPropertiesKHR *) ext;

         properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
         break;
      }

977 978 979
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
         VkPhysicalDeviceIDProperties *id_props =
            (VkPhysicalDeviceIDProperties *)ext;
980 981 982 983 984 985 986
         memcpy(id_props->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
         memcpy(id_props->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
         /* The LUID is for Windows. */
         id_props->deviceLUIDValid = false;
         break;
      }

987 988 989
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES: {
         VkPhysicalDeviceMultiviewProperties *properties =
            (VkPhysicalDeviceMultiviewProperties *)ext;
990 991 992 993 994
         properties->maxMultiviewViewCount = 16;
         properties->maxMultiviewInstanceIndex = UINT32_MAX / 16;
         break;
      }

995 996 997 998
      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES: {
         VkPhysicalDevicePointClippingProperties *properties =
            (VkPhysicalDevicePointClippingProperties *) ext;
         properties->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
999 1000 1001 1002
         anv_finishme("Implement pop-free point clipping");
         break;
      }

1003
      default:
1004
         anv_debug_ignored_stype(ext->sType);
1005 1006 1007 1008 1009
         break;
      }
   }
}

1010 1011 1012 1013 1014 1015 1016 1017
/* We support exactly one queue family. */
static const VkQueueFamilyProperties
anv_queue_family_properties = {
   .queueFlags = VK_QUEUE_GRAPHICS_BIT |
                 VK_QUEUE_COMPUTE_BIT |
                 VK_QUEUE_TRANSFER_BIT,
   .queueCount = 1,
   .timestampValidBits = 36, /* XXX: Real value here */
1018
   .minImageTransferGranularity = { 1, 1, 1 },
1019
};
1020

1021
void anv_GetPhysicalDeviceQueueFamilyProperties(
1022
    VkPhysicalDevice                            physicalDevice,
1023 1024
    uint32_t*                                   pCount,
    VkQueueFamilyProperties*                    pQueueFamilyProperties)
1025
{
1026
   VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pCount);
1027

1028 1029
   vk_outarray_append(&out, p) {
      *p = anv_queue_family_properties;
1030
   }
1031 1032
}

1033
void anv_GetPhysicalDeviceQueueFamilyProperties2(
1034 1035
    VkPhysicalDevice                            physicalDevice,
    uint32_t*                                   pQueueFamilyPropertyCount,
1036
    VkQueueFamilyProperties2*                   pQueueFamilyProperties)
1037 1038
{

1039
   VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
1040

1041 1042
   vk_outarray_append(&out, p) {
      p->queueFamilyProperties = anv_queue_family_properties;
1043

1044 1045
      vk_foreach_struct(s, p->pNext) {
         anv_debug_ignored_stype(s->sType);
1046 1047 1048 1049
      }
   }
}

1050
void anv_GetPhysicalDeviceMemoryProperties(
1051 1052 1053 1054 1055
    VkPhysicalDevice                            physicalDevice,
    VkPhysicalDeviceMemoryProperties*           pMemoryProperties)
{
   ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);

1056 1057 1058 1059 1060
   pMemoryProperties->memoryTypeCount = physical_device->memory.type_count;
   for (uint32_t i = 0; i < physical_device->memory.type_count; i++) {
      pMemoryProperties->memoryTypes[i] = (VkMemoryType) {
         .propertyFlags = physical_device->memory.types[i].propertyFlags,
         .heapIndex     = physical_device->memory.types[i].heapIndex,
1061 1062
      };
   }
1063

1064 1065 1066 1067 1068 1069 1070
   pMemoryProperties->memoryHeapCount = physical_device->memory.heap_count;
   for (uint32_t i = 0; i < physical_device->memory.heap_count; i++) {
      pMemoryProperties->memoryHeaps[i] = (VkMemoryHeap) {
         .size    = physical_device->memory.heaps[i].size,
         .flags   = physical_device->memory.heaps[i].flags,
      };
   }
1071 1072
}

1073
void anv_GetPhysicalDeviceMemoryProperties2(
1074
    VkPhysicalDevice                            physicalDevice,
1075
    VkPhysicalDeviceMemoryProperties2*          pMemoryProperties)
1076 1077 1078 1079
{
   anv_GetPhysicalDeviceMemoryProperties(physicalDevice,
                                         &pMemoryProperties->memoryProperties);

1080 1081
   vk_foreach_struct(ext, pMemoryProperties->pNext) {
      switch (ext->sType) {
1082
      default:
1083
         anv_debug_ignored_stype(ext->sType);
1084 1085 1086 1087 1088
         break;
      }
   }
}

1089
PFN_vkVoidFunction anv_GetInstanceProcAddr(
1090
    VkInstance                                  _instance,
1091 1092
    const char*                                 pName)
{
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111