2 * Copyright © 2015 Intel Corporation
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:
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
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
28 #include <sys/sysinfo.h>
32 #include <drm_fourcc.h>
34 #include "anv_private.h"
35 #include "util/strtod.h"
36 #include "util/debug.h"
37 #include "util/build_id.h"
38 #include "util/disk_cache.h"
39 #include "util/mesa-sha1.h"
40 #include "util/u_string.h"
43 #include "common/gen_defines.h"
45 #include "genxml/gen7_pack.h"
48 compiler_debug_log(void *data
, const char *fmt
, ...)
52 compiler_perf_log(void *data
, const char *fmt
, ...)
57 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
58 intel_logd_v(fmt
, args
);
64 anv_compute_heap_size(int fd
, uint64_t gtt_size
, uint64_t *heap_size
)
66 /* Query the total ram from the system */
70 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
72 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
73 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
75 uint64_t available_ram
;
76 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
77 available_ram
= total_ram
/ 2;
79 available_ram
= total_ram
* 3 / 4;
81 /* We also want to leave some padding for things we allocate in the driver,
82 * so don't go over 3/4 of the GTT either.
84 uint64_t available_gtt
= gtt_size
* 3 / 4;
86 *heap_size
= MIN2(available_ram
, available_gtt
);
92 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
95 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
97 /* If, for whatever reason, we can't actually get the GTT size from the
98 * kernel (too old?) fall back to the aperture size.
100 anv_perf_warn(NULL
, NULL
,
101 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
103 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
104 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
105 "failed to get aperture size: %m");
109 device
->supports_48bit_addresses
= (device
->info
.gen
>= 8) &&
110 gtt_size
> (4ULL << 30 /* GiB */);
112 uint64_t heap_size
= 0;
113 VkResult result
= anv_compute_heap_size(fd
, gtt_size
, &heap_size
);
114 if (result
!= VK_SUCCESS
)
117 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
118 /* When running with an overridden PCI ID, we may get a GTT size from
119 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
120 * address support can still fail. Just clamp the address space size to
121 * 2 GiB if we don't have 48-bit support.
123 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
124 "not support for 48-bit addresses",
126 heap_size
= 2ull << 30;
129 if (heap_size
<= 3ull * (1ull << 30)) {
130 /* In this case, everything fits nicely into the 32-bit address space,
131 * so there's no need for supporting 48bit addresses on client-allocated
134 device
->memory
.heap_count
= 1;
135 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
137 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
138 .supports_48bit_addresses
= false,
141 /* Not everything will fit nicely into a 32-bit address space. In this
142 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
143 * larger 48-bit heap. If we're in this case, then we have a total heap
144 * size larger than 3GiB which most likely means they have 8 GiB of
145 * video memory and so carving off 1 GiB for the 32-bit heap should be
148 const uint64_t heap_size_32bit
= 1ull << 30;
149 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
151 assert(device
->supports_48bit_addresses
);
153 device
->memory
.heap_count
= 2;
154 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
155 .size
= heap_size_48bit
,
156 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
157 .supports_48bit_addresses
= true,
159 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
160 .size
= heap_size_32bit
,
161 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
162 .supports_48bit_addresses
= false,
166 uint32_t type_count
= 0;
167 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
168 uint32_t valid_buffer_usage
= ~0;
170 /* There appears to be a hardware issue in the VF cache where it only
171 * considers the bottom 32 bits of memory addresses. If you happen to
172 * have two vertex buffers which get placed exactly 4 GiB apart and use
173 * them in back-to-back draw calls, you can get collisions. In order to
174 * solve this problem, we require vertex and index buffers be bound to
175 * memory allocated out of the 32-bit heap.
177 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
178 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
179 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
182 if (device
->info
.has_llc
) {
183 /* Big core GPUs share LLC with the CPU and thus one memory type can be
184 * both cached and coherent at the same time.
186 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
187 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
188 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
189 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
190 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
192 .valid_buffer_usage
= valid_buffer_usage
,
195 /* The spec requires that we expose a host-visible, coherent memory
196 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
197 * to give the application a choice between cached, but not coherent and
198 * coherent but uncached (WC though).
200 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
201 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
202 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
203 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
205 .valid_buffer_usage
= valid_buffer_usage
,
207 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
208 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
209 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
210 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
212 .valid_buffer_usage
= valid_buffer_usage
,
216 device
->memory
.type_count
= type_count
;
222 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
224 const struct build_id_note
*note
=
225 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
227 return vk_errorf(device
->instance
, device
,
228 VK_ERROR_INITIALIZATION_FAILED
,
229 "Failed to find build-id");
232 unsigned build_id_len
= build_id_length(note
);
233 if (build_id_len
< 20) {
234 return vk_errorf(device
->instance
, device
,
235 VK_ERROR_INITIALIZATION_FAILED
,
236 "build-id too short. It needs to be a SHA");
239 memcpy(device
->driver_build_sha1
, build_id_data(note
), 20);
241 struct mesa_sha1 sha1_ctx
;
243 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
245 /* The pipeline cache UUID is used for determining when a pipeline cache is
246 * invalid. It needs both a driver build and the PCI ID of the device.
248 _mesa_sha1_init(&sha1_ctx
);
249 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
250 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
251 sizeof(device
->chipset_id
));
252 _mesa_sha1_final(&sha1_ctx
, sha1
);
253 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
255 /* The driver UUID is used for determining sharability of images and memory
256 * between two Vulkan instances in separate processes. People who want to
257 * share memory need to also check the device UUID (below) so all this
258 * needs to be is the build-id.
260 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
262 /* The device UUID uniquely identifies the given device within the machine.
263 * Since we never have more than one device, this doesn't need to be a real
264 * UUID. However, on the off-chance that someone tries to use this to
265 * cache pre-tiled images or something of the like, we use the PCI ID and
266 * some bits of ISL info to ensure that this is safe.
268 _mesa_sha1_init(&sha1_ctx
);
269 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
270 sizeof(device
->chipset_id
));
271 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
272 sizeof(device
->isl_dev
.has_bit6_swizzling
));
273 _mesa_sha1_final(&sha1_ctx
, sha1
);
274 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
280 anv_physical_device_init_disk_cache(struct anv_physical_device
*device
)
282 #ifdef ENABLE_SHADER_CACHE
284 MAYBE_UNUSED
int len
= snprintf(renderer
, sizeof(renderer
), "anv_%04x",
286 assert(len
== sizeof(renderer
) - 2);
289 _mesa_sha1_format(timestamp
, device
->driver_build_sha1
);
291 const uint64_t driver_flags
=
292 brw_get_compiler_config_value(device
->compiler
);
293 device
->disk_cache
= disk_cache_create(renderer
, timestamp
, driver_flags
);
295 device
->disk_cache
= NULL
;
300 anv_physical_device_free_disk_cache(struct anv_physical_device
*device
)
302 #ifdef ENABLE_SHADER_CACHE
303 if (device
->disk_cache
)
304 disk_cache_destroy(device
->disk_cache
);
306 assert(device
->disk_cache
== NULL
);
311 anv_physical_device_init(struct anv_physical_device
*device
,
312 struct anv_instance
*instance
,
313 drmDevicePtr drm_device
)
315 const char *primary_path
= drm_device
->nodes
[DRM_NODE_PRIMARY
];
316 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
321 brw_process_intel_debug_variable();
323 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
325 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
327 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
328 device
->instance
= instance
;
330 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
331 snprintf(device
->path
, ARRAY_SIZE(device
->path
), "%s", path
);
333 device
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
335 const int pci_id_override
= gen_get_pci_device_id_override();
336 if (pci_id_override
< 0) {
337 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
338 if (!device
->chipset_id
) {
339 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
343 device
->chipset_id
= pci_id_override
;
344 device
->no_hw
= true;
347 device
->pci_info
.domain
= drm_device
->businfo
.pci
->domain
;
348 device
->pci_info
.bus
= drm_device
->businfo
.pci
->bus
;
349 device
->pci_info
.device
= drm_device
->businfo
.pci
->dev
;
350 device
->pci_info
.function
= drm_device
->businfo
.pci
->func
;
352 device
->name
= gen_get_device_name(device
->chipset_id
);
353 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
354 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
358 if (device
->info
.is_haswell
) {
359 intel_logw("Haswell Vulkan support is incomplete");
360 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
361 intel_logw("Ivy Bridge Vulkan support is incomplete");
362 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
363 intel_logw("Bay Trail Vulkan support is incomplete");
364 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 10) {
365 /* Gen8-10 fully supported */
366 } else if (device
->info
.gen
== 11) {
367 intel_logw("Vulkan is not yet fully supported on gen11.");
369 result
= vk_errorf(device
->instance
, device
,
370 VK_ERROR_INCOMPATIBLE_DRIVER
,
371 "Vulkan not yet supported on %s", device
->name
);
375 device
->cmd_parser_version
= -1;
376 if (device
->info
.gen
== 7) {
377 device
->cmd_parser_version
=
378 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
379 if (device
->cmd_parser_version
== -1) {
380 result
= vk_errorf(device
->instance
, device
,
381 VK_ERROR_INITIALIZATION_FAILED
,
382 "failed to get command parser version");
387 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
388 result
= vk_errorf(device
->instance
, device
,
389 VK_ERROR_INITIALIZATION_FAILED
,
390 "kernel missing gem wait");
394 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
395 result
= vk_errorf(device
->instance
, device
,
396 VK_ERROR_INITIALIZATION_FAILED
,
397 "kernel missing execbuf2");
401 if (!device
->info
.has_llc
&&
402 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
403 result
= vk_errorf(device
->instance
, device
,
404 VK_ERROR_INITIALIZATION_FAILED
,
405 "kernel missing wc mmap");
409 result
= anv_physical_device_init_heaps(device
, fd
);
410 if (result
!= VK_SUCCESS
)
413 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
414 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
415 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
416 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
417 device
->has_syncobj_wait
= device
->has_syncobj
&&
418 anv_gem_supports_syncobj_wait(fd
);
419 device
->has_context_priority
= anv_gem_has_context_priority(fd
);
421 device
->use_softpin
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_SOFTPIN
)
422 && device
->supports_48bit_addresses
;
424 device
->has_context_isolation
=
425 anv_gem_get_param(fd
, I915_PARAM_HAS_CONTEXT_ISOLATION
);
427 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
429 /* Starting with Gen10, the timestamp frequency of the command streamer may
430 * vary from one part to another. We can query the value from the kernel.
432 if (device
->info
.gen
>= 10) {
433 int timestamp_frequency
=
434 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
436 if (timestamp_frequency
< 0)
437 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
439 device
->info
.timestamp_frequency
= timestamp_frequency
;
442 /* GENs prior to 8 do not support EU/Subslice info */
443 if (device
->info
.gen
>= 8) {
444 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
445 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
447 /* Without this information, we cannot get the right Braswell
448 * brandstrings, and we have to use conservative numbers for GPGPU on
449 * many platforms, but otherwise, things will just work.
451 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
452 intel_logw("Kernel 4.1 required to properly query GPU properties");
454 } else if (device
->info
.gen
== 7) {
455 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
458 if (device
->info
.is_cherryview
&&
459 device
->subslice_total
> 0 && device
->eu_total
> 0) {
460 /* Logical CS threads = EUs per subslice * num threads per EU */
461 uint32_t max_cs_threads
=
462 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
464 /* Fuse configurations may give more threads than expected, never less. */
465 if (max_cs_threads
> device
->info
.max_cs_threads
)
466 device
->info
.max_cs_threads
= max_cs_threads
;
469 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
470 if (device
->compiler
== NULL
) {
471 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
474 device
->compiler
->shader_debug_log
= compiler_debug_log
;
475 device
->compiler
->shader_perf_log
= compiler_perf_log
;
476 device
->compiler
->supports_pull_constants
= false;
477 device
->compiler
->constant_buffer_0_is_relative
=
478 device
->info
.gen
< 8 || !device
->has_context_isolation
;
479 device
->compiler
->supports_shader_constants
= true;
481 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
483 result
= anv_physical_device_init_uuids(device
);
484 if (result
!= VK_SUCCESS
)
487 anv_physical_device_init_disk_cache(device
);
489 if (instance
->enabled_extensions
.KHR_display
) {
490 master_fd
= open(primary_path
, O_RDWR
| O_CLOEXEC
);
491 if (master_fd
>= 0) {
492 /* prod the device with a GETPARAM call which will fail if
493 * we don't have permission to even render on this device
495 if (anv_gem_get_param(master_fd
, I915_PARAM_CHIPSET_ID
) == 0) {
501 device
->master_fd
= master_fd
;
503 result
= anv_init_wsi(device
);
504 if (result
!= VK_SUCCESS
) {
505 ralloc_free(device
->compiler
);
506 anv_physical_device_free_disk_cache(device
);
510 anv_physical_device_get_supported_extensions(device
,
511 &device
->supported_extensions
);
514 device
->local_fd
= fd
;
526 anv_physical_device_finish(struct anv_physical_device
*device
)
528 anv_finish_wsi(device
);
529 anv_physical_device_free_disk_cache(device
);
530 ralloc_free(device
->compiler
);
531 close(device
->local_fd
);
532 if (device
->master_fd
>= 0)
533 close(device
->master_fd
);
537 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
538 VkSystemAllocationScope allocationScope
)
544 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
545 size_t align
, VkSystemAllocationScope allocationScope
)
547 return realloc(pOriginal
, size
);
551 default_free_func(void *pUserData
, void *pMemory
)
556 static const VkAllocationCallbacks default_alloc
= {
558 .pfnAllocation
= default_alloc_func
,
559 .pfnReallocation
= default_realloc_func
,
560 .pfnFree
= default_free_func
,
563 VkResult
anv_EnumerateInstanceExtensionProperties(
564 const char* pLayerName
,
565 uint32_t* pPropertyCount
,
566 VkExtensionProperties
* pProperties
)
568 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
570 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
571 if (anv_instance_extensions_supported
.extensions
[i
]) {
572 vk_outarray_append(&out
, prop
) {
573 *prop
= anv_instance_extensions
[i
];
578 return vk_outarray_status(&out
);
581 VkResult
anv_CreateInstance(
582 const VkInstanceCreateInfo
* pCreateInfo
,
583 const VkAllocationCallbacks
* pAllocator
,
584 VkInstance
* pInstance
)
586 struct anv_instance
*instance
;
589 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
591 struct anv_instance_extension_table enabled_extensions
= {};
592 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
594 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
595 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
596 anv_instance_extensions
[idx
].extensionName
) == 0)
600 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
601 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
603 if (!anv_instance_extensions_supported
.extensions
[idx
])
604 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
606 enabled_extensions
.extensions
[idx
] = true;
609 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
610 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
612 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
614 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
617 instance
->alloc
= *pAllocator
;
619 instance
->alloc
= default_alloc
;
621 instance
->app_info
= (struct anv_app_info
) { .api_version
= 0 };
622 if (pCreateInfo
->pApplicationInfo
) {
623 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
625 instance
->app_info
.app_name
=
626 vk_strdup(&instance
->alloc
, app
->pApplicationName
,
627 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
628 instance
->app_info
.app_version
= app
->applicationVersion
;
630 instance
->app_info
.engine_name
=
631 vk_strdup(&instance
->alloc
, app
->pEngineName
,
632 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
633 instance
->app_info
.engine_version
= app
->engineVersion
;
635 instance
->app_info
.api_version
= app
->apiVersion
;
638 if (instance
->app_info
.api_version
== 0)
639 anv_EnumerateInstanceVersion(&instance
->app_info
.api_version
);
641 instance
->enabled_extensions
= enabled_extensions
;
643 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
644 /* Vulkan requires that entrypoints for extensions which have not been
645 * enabled must not be advertised.
647 if (!anv_instance_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
648 &instance
->enabled_extensions
)) {
649 instance
->dispatch
.entrypoints
[i
] = NULL
;
651 instance
->dispatch
.entrypoints
[i
] =
652 anv_instance_dispatch_table
.entrypoints
[i
];
656 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
657 /* Vulkan requires that entrypoints for extensions which have not been
658 * enabled must not be advertised.
660 if (!anv_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
661 &instance
->enabled_extensions
, NULL
)) {
662 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
664 instance
->device_dispatch
.entrypoints
[i
] =
665 anv_device_dispatch_table
.entrypoints
[i
];
669 instance
->physicalDeviceCount
= -1;
671 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
672 if (result
!= VK_SUCCESS
) {
673 vk_free2(&default_alloc
, pAllocator
, instance
);
674 return vk_error(result
);
677 instance
->pipeline_cache_enabled
=
678 env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
682 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
684 *pInstance
= anv_instance_to_handle(instance
);
689 void anv_DestroyInstance(
690 VkInstance _instance
,
691 const VkAllocationCallbacks
* pAllocator
)
693 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
698 if (instance
->physicalDeviceCount
> 0) {
699 /* We support at most one physical device. */
700 assert(instance
->physicalDeviceCount
== 1);
701 anv_physical_device_finish(&instance
->physicalDevice
);
704 vk_free(&instance
->alloc
, (char *)instance
->app_info
.app_name
);
705 vk_free(&instance
->alloc
, (char *)instance
->app_info
.engine_name
);
707 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
709 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
713 vk_free(&instance
->alloc
, instance
);
717 anv_enumerate_devices(struct anv_instance
*instance
)
719 /* TODO: Check for more devices ? */
720 drmDevicePtr devices
[8];
721 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
724 instance
->physicalDeviceCount
= 0;
726 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
728 return VK_ERROR_INCOMPATIBLE_DRIVER
;
730 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
731 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
732 devices
[i
]->bustype
== DRM_BUS_PCI
&&
733 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
735 result
= anv_physical_device_init(&instance
->physicalDevice
,
736 instance
, devices
[i
]);
737 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
741 drmFreeDevices(devices
, max_devices
);
743 if (result
== VK_SUCCESS
)
744 instance
->physicalDeviceCount
= 1;
750 anv_instance_ensure_physical_device(struct anv_instance
*instance
)
752 if (instance
->physicalDeviceCount
< 0) {
753 VkResult result
= anv_enumerate_devices(instance
);
754 if (result
!= VK_SUCCESS
&&
755 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
762 VkResult
anv_EnumeratePhysicalDevices(
763 VkInstance _instance
,
764 uint32_t* pPhysicalDeviceCount
,
765 VkPhysicalDevice
* pPhysicalDevices
)
767 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
768 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
770 VkResult result
= anv_instance_ensure_physical_device(instance
);
771 if (result
!= VK_SUCCESS
)
774 if (instance
->physicalDeviceCount
== 0)
777 assert(instance
->physicalDeviceCount
== 1);
778 vk_outarray_append(&out
, i
) {
779 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
782 return vk_outarray_status(&out
);
785 VkResult
anv_EnumeratePhysicalDeviceGroups(
786 VkInstance _instance
,
787 uint32_t* pPhysicalDeviceGroupCount
,
788 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
790 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
791 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
792 pPhysicalDeviceGroupCount
);
794 VkResult result
= anv_instance_ensure_physical_device(instance
);
795 if (result
!= VK_SUCCESS
)
798 if (instance
->physicalDeviceCount
== 0)
801 assert(instance
->physicalDeviceCount
== 1);
803 vk_outarray_append(&out
, p
) {
804 p
->physicalDeviceCount
= 1;
805 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
806 p
->physicalDevices
[0] =
807 anv_physical_device_to_handle(&instance
->physicalDevice
);
808 p
->subsetAllocation
= VK_FALSE
;
810 vk_foreach_struct(ext
, p
->pNext
)
811 anv_debug_ignored_stype(ext
->sType
);
814 return vk_outarray_status(&out
);
817 void anv_GetPhysicalDeviceFeatures(
818 VkPhysicalDevice physicalDevice
,
819 VkPhysicalDeviceFeatures
* pFeatures
)
821 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
823 *pFeatures
= (VkPhysicalDeviceFeatures
) {
824 .robustBufferAccess
= true,
825 .fullDrawIndexUint32
= true,
826 .imageCubeArray
= true,
827 .independentBlend
= true,
828 .geometryShader
= true,
829 .tessellationShader
= true,
830 .sampleRateShading
= true,
831 .dualSrcBlend
= true,
833 .multiDrawIndirect
= true,
834 .drawIndirectFirstInstance
= true,
836 .depthBiasClamp
= true,
837 .fillModeNonSolid
= true,
838 .depthBounds
= false,
842 .multiViewport
= true,
843 .samplerAnisotropy
= true,
844 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
845 pdevice
->info
.is_baytrail
,
846 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
847 .textureCompressionBC
= true,
848 .occlusionQueryPrecise
= true,
849 .pipelineStatisticsQuery
= true,
850 .fragmentStoresAndAtomics
= true,
851 .shaderTessellationAndGeometryPointSize
= true,
852 .shaderImageGatherExtended
= true,
853 .shaderStorageImageExtendedFormats
= true,
854 .shaderStorageImageMultisample
= false,
855 .shaderStorageImageReadWithoutFormat
= false,
856 .shaderStorageImageWriteWithoutFormat
= true,
857 .shaderUniformBufferArrayDynamicIndexing
= true,
858 .shaderSampledImageArrayDynamicIndexing
= true,
859 .shaderStorageBufferArrayDynamicIndexing
= true,
860 .shaderStorageImageArrayDynamicIndexing
= true,
861 .shaderClipDistance
= true,
862 .shaderCullDistance
= true,
863 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
864 pdevice
->info
.has_64bit_types
,
865 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
866 pdevice
->info
.has_64bit_types
,
867 .shaderInt16
= pdevice
->info
.gen
>= 8,
868 .shaderResourceMinLod
= false,
869 .variableMultisampleRate
= true,
870 .inheritedQueries
= true,
873 /* We can't do image stores in vec4 shaders */
874 pFeatures
->vertexPipelineStoresAndAtomics
=
875 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
876 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
878 struct anv_app_info
*app_info
= &pdevice
->instance
->app_info
;
880 /* The new DOOM and Wolfenstein games require depthBounds without
881 * checking for it. They seem to run fine without it so just claim it's
882 * there and accept the consequences.
884 if (app_info
->engine_name
&& strcmp(app_info
->engine_name
, "idTech") == 0)
885 pFeatures
->depthBounds
= true;
888 void anv_GetPhysicalDeviceFeatures2(
889 VkPhysicalDevice physicalDevice
,
890 VkPhysicalDeviceFeatures2
* pFeatures
)
892 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
894 vk_foreach_struct(ext
, pFeatures
->pNext
) {
895 switch (ext
->sType
) {
896 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
897 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
898 features
->protectedMemory
= VK_FALSE
;
902 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
903 VkPhysicalDeviceMultiviewFeatures
*features
=
904 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
905 features
->multiview
= true;
906 features
->multiviewGeometryShader
= true;
907 features
->multiviewTessellationShader
= true;
911 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
912 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
913 features
->variablePointersStorageBuffer
= true;
914 features
->variablePointers
= true;
918 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
919 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
920 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
921 features
->samplerYcbcrConversion
= true;
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
926 VkPhysicalDeviceShaderDrawParameterFeatures
*features
= (void *)ext
;
927 features
->shaderDrawParameters
= true;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
: {
932 VkPhysicalDevice16BitStorageFeaturesKHR
*features
=
933 (VkPhysicalDevice16BitStorageFeaturesKHR
*)ext
;
934 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
936 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
937 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
938 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
939 features
->storageInputOutput16
= false;
943 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
944 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
945 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
946 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
948 features
->storageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
949 features
->uniformAndStorageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
950 features
->storagePushConstant8
= pdevice
->info
.gen
>= 8;
954 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
955 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
956 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
957 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
958 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
963 anv_debug_ignored_stype(ext
->sType
);
969 void anv_GetPhysicalDeviceProperties(
970 VkPhysicalDevice physicalDevice
,
971 VkPhysicalDeviceProperties
* pProperties
)
973 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
974 const struct gen_device_info
*devinfo
= &pdevice
->info
;
976 /* See assertions made when programming the buffer surface state. */
977 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
978 (1ul << 30) : (1ul << 27);
980 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
983 VkSampleCountFlags sample_counts
=
984 isl_device_get_sample_counts(&pdevice
->isl_dev
);
986 VkPhysicalDeviceLimits limits
= {
987 .maxImageDimension1D
= (1 << 14),
988 .maxImageDimension2D
= (1 << 14),
989 .maxImageDimension3D
= (1 << 11),
990 .maxImageDimensionCube
= (1 << 14),
991 .maxImageArrayLayers
= (1 << 11),
992 .maxTexelBufferElements
= 128 * 1024 * 1024,
993 .maxUniformBufferRange
= (1ul << 27),
994 .maxStorageBufferRange
= max_raw_buffer_sz
,
995 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
996 .maxMemoryAllocationCount
= UINT32_MAX
,
997 .maxSamplerAllocationCount
= 64 * 1024,
998 .bufferImageGranularity
= 64, /* A cache line */
999 .sparseAddressSpaceSize
= 0,
1000 .maxBoundDescriptorSets
= MAX_SETS
,
1001 .maxPerStageDescriptorSamplers
= max_samplers
,
1002 .maxPerStageDescriptorUniformBuffers
= 64,
1003 .maxPerStageDescriptorStorageBuffers
= 64,
1004 .maxPerStageDescriptorSampledImages
= max_samplers
,
1005 .maxPerStageDescriptorStorageImages
= 64,
1006 .maxPerStageDescriptorInputAttachments
= 64,
1007 .maxPerStageResources
= 250,
1008 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1009 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
1010 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1011 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
1012 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1013 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
1014 .maxDescriptorSetStorageImages
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
1015 .maxDescriptorSetInputAttachments
= 256,
1016 .maxVertexInputAttributes
= MAX_VBS
,
1017 .maxVertexInputBindings
= MAX_VBS
,
1018 .maxVertexInputAttributeOffset
= 2047,
1019 .maxVertexInputBindingStride
= 2048,
1020 .maxVertexOutputComponents
= 128,
1021 .maxTessellationGenerationLevel
= 64,
1022 .maxTessellationPatchSize
= 32,
1023 .maxTessellationControlPerVertexInputComponents
= 128,
1024 .maxTessellationControlPerVertexOutputComponents
= 128,
1025 .maxTessellationControlPerPatchOutputComponents
= 128,
1026 .maxTessellationControlTotalOutputComponents
= 2048,
1027 .maxTessellationEvaluationInputComponents
= 128,
1028 .maxTessellationEvaluationOutputComponents
= 128,
1029 .maxGeometryShaderInvocations
= 32,
1030 .maxGeometryInputComponents
= 64,
1031 .maxGeometryOutputComponents
= 128,
1032 .maxGeometryOutputVertices
= 256,
1033 .maxGeometryTotalOutputComponents
= 1024,
1034 .maxFragmentInputComponents
= 112, /* 128 components - (POS, PSIZ, CLIP_DIST0, CLIP_DIST1) */
1035 .maxFragmentOutputAttachments
= 8,
1036 .maxFragmentDualSrcAttachments
= 1,
1037 .maxFragmentCombinedOutputResources
= 8,
1038 .maxComputeSharedMemorySize
= 32768,
1039 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1040 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
1041 .maxComputeWorkGroupSize
= {
1042 16 * devinfo
->max_cs_threads
,
1043 16 * devinfo
->max_cs_threads
,
1044 16 * devinfo
->max_cs_threads
,
1046 .subPixelPrecisionBits
= 4 /* FIXME */,
1047 .subTexelPrecisionBits
= 4 /* FIXME */,
1048 .mipmapPrecisionBits
= 4 /* FIXME */,
1049 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1050 .maxDrawIndirectCount
= UINT32_MAX
,
1051 .maxSamplerLodBias
= 16,
1052 .maxSamplerAnisotropy
= 16,
1053 .maxViewports
= MAX_VIEWPORTS
,
1054 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1055 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1056 .viewportSubPixelBits
= 13, /* We take a float? */
1057 .minMemoryMapAlignment
= 4096, /* A page */
1058 .minTexelBufferOffsetAlignment
= 1,
1059 /* We need 16 for UBO block reads to work and 32 for push UBOs */
1060 .minUniformBufferOffsetAlignment
= 32,
1061 .minStorageBufferOffsetAlignment
= 4,
1062 .minTexelOffset
= -8,
1063 .maxTexelOffset
= 7,
1064 .minTexelGatherOffset
= -32,
1065 .maxTexelGatherOffset
= 31,
1066 .minInterpolationOffset
= -0.5,
1067 .maxInterpolationOffset
= 0.4375,
1068 .subPixelInterpolationOffsetBits
= 4,
1069 .maxFramebufferWidth
= (1 << 14),
1070 .maxFramebufferHeight
= (1 << 14),
1071 .maxFramebufferLayers
= (1 << 11),
1072 .framebufferColorSampleCounts
= sample_counts
,
1073 .framebufferDepthSampleCounts
= sample_counts
,
1074 .framebufferStencilSampleCounts
= sample_counts
,
1075 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1076 .maxColorAttachments
= MAX_RTS
,
1077 .sampledImageColorSampleCounts
= sample_counts
,
1078 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1079 .sampledImageDepthSampleCounts
= sample_counts
,
1080 .sampledImageStencilSampleCounts
= sample_counts
,
1081 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1082 .maxSampleMaskWords
= 1,
1083 .timestampComputeAndGraphics
= false,
1084 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1085 .maxClipDistances
= 8,
1086 .maxCullDistances
= 8,
1087 .maxCombinedClipAndCullDistances
= 8,
1088 .discreteQueuePriorities
= 2,
1089 .pointSizeRange
= { 0.125, 255.875 },
1090 .lineWidthRange
= { 0.0, 7.9921875 },
1091 .pointSizeGranularity
= (1.0 / 8.0),
1092 .lineWidthGranularity
= (1.0 / 128.0),
1093 .strictLines
= false, /* FINISHME */
1094 .standardSampleLocations
= true,
1095 .optimalBufferCopyOffsetAlignment
= 128,
1096 .optimalBufferCopyRowPitchAlignment
= 128,
1097 .nonCoherentAtomSize
= 64,
1100 *pProperties
= (VkPhysicalDeviceProperties
) {
1101 .apiVersion
= anv_physical_device_api_version(pdevice
),
1102 .driverVersion
= vk_get_driver_version(),
1104 .deviceID
= pdevice
->chipset_id
,
1105 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1107 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1110 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1111 "%s", pdevice
->name
);
1112 memcpy(pProperties
->pipelineCacheUUID
,
1113 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1116 void anv_GetPhysicalDeviceProperties2(
1117 VkPhysicalDevice physicalDevice
,
1118 VkPhysicalDeviceProperties2
* pProperties
)
1120 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1122 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1124 vk_foreach_struct(ext
, pProperties
->pNext
) {
1125 switch (ext
->sType
) {
1126 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1127 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1128 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1130 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1134 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1135 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1136 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1138 driver_props
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1139 util_snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1140 "Intel open-source Mesa driver");
1142 util_snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1143 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1145 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1154 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1155 VkPhysicalDeviceIDProperties
*id_props
=
1156 (VkPhysicalDeviceIDProperties
*)ext
;
1157 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1158 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1159 /* The LUID is for Windows. */
1160 id_props
->deviceLUIDValid
= false;
1164 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1165 VkPhysicalDeviceMaintenance3Properties
*props
=
1166 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1167 /* This value doesn't matter for us today as our per-stage
1168 * descriptors are the real limit.
1170 props
->maxPerSetDescriptors
= 1024;
1171 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1175 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1176 VkPhysicalDeviceMultiviewProperties
*properties
=
1177 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1178 properties
->maxMultiviewViewCount
= 16;
1179 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1183 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1184 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1185 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1186 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1187 properties
->pciBus
= pdevice
->pci_info
.bus
;
1188 properties
->pciDevice
= pdevice
->pci_info
.device
;
1189 properties
->pciFunction
= pdevice
->pci_info
.function
;
1193 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1194 VkPhysicalDevicePointClippingProperties
*properties
=
1195 (VkPhysicalDevicePointClippingProperties
*) ext
;
1196 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1197 anv_finishme("Implement pop-free point clipping");
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1202 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1203 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1204 properties
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1205 properties
->filterMinmaxSingleComponentFormats
= true;
1209 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1210 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1212 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1214 VkShaderStageFlags scalar_stages
= 0;
1215 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1216 if (pdevice
->compiler
->scalar_stage
[stage
])
1217 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1219 properties
->supportedStages
= scalar_stages
;
1221 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1222 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1223 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1224 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1225 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1226 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1227 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1228 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1229 properties
->quadOperationsInAllStages
= VK_TRUE
;
1233 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1234 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1235 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1236 /* We have to restrict this a bit for multiview */
1237 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
1241 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1242 VkPhysicalDeviceProtectedMemoryProperties
*props
=
1243 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1244 props
->protectedNoFault
= false;
1249 anv_debug_ignored_stype(ext
->sType
);
1255 /* We support exactly one queue family. */
1256 static const VkQueueFamilyProperties
1257 anv_queue_family_properties
= {
1258 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1259 VK_QUEUE_COMPUTE_BIT
|
1260 VK_QUEUE_TRANSFER_BIT
,
1262 .timestampValidBits
= 36, /* XXX: Real value here */
1263 .minImageTransferGranularity
= { 1, 1, 1 },
1266 void anv_GetPhysicalDeviceQueueFamilyProperties(
1267 VkPhysicalDevice physicalDevice
,
1269 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1271 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1273 vk_outarray_append(&out
, p
) {
1274 *p
= anv_queue_family_properties
;
1278 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1279 VkPhysicalDevice physicalDevice
,
1280 uint32_t* pQueueFamilyPropertyCount
,
1281 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1284 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1286 vk_outarray_append(&out
, p
) {
1287 p
->queueFamilyProperties
= anv_queue_family_properties
;
1289 vk_foreach_struct(s
, p
->pNext
) {
1290 anv_debug_ignored_stype(s
->sType
);
1295 void anv_GetPhysicalDeviceMemoryProperties(
1296 VkPhysicalDevice physicalDevice
,
1297 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1299 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1301 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1302 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1303 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1304 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1305 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1309 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1310 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1311 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1312 .size
= physical_device
->memory
.heaps
[i
].size
,
1313 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1318 void anv_GetPhysicalDeviceMemoryProperties2(
1319 VkPhysicalDevice physicalDevice
,
1320 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1322 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1323 &pMemoryProperties
->memoryProperties
);
1325 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1326 switch (ext
->sType
) {
1328 anv_debug_ignored_stype(ext
->sType
);
1335 anv_GetDeviceGroupPeerMemoryFeatures(
1338 uint32_t localDeviceIndex
,
1339 uint32_t remoteDeviceIndex
,
1340 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1342 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1343 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1344 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1345 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1346 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1349 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1350 VkInstance _instance
,
1353 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1355 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1356 * when we have to return valid function pointers, NULL, or it's left
1357 * undefined. See the table for exact details.
1362 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1363 if (strcmp(pName, "vk" #entrypoint) == 0) \
1364 return (PFN_vkVoidFunction)anv_##entrypoint
1366 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1367 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1368 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1369 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1371 #undef LOOKUP_ANV_ENTRYPOINT
1373 if (instance
== NULL
)
1376 int idx
= anv_get_instance_entrypoint_index(pName
);
1378 return instance
->dispatch
.entrypoints
[idx
];
1380 idx
= anv_get_device_entrypoint_index(pName
);
1382 return instance
->device_dispatch
.entrypoints
[idx
];
1387 /* With version 1+ of the loader interface the ICD should expose
1388 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1391 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1392 VkInstance instance
,
1396 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1397 VkInstance instance
,
1400 return anv_GetInstanceProcAddr(instance
, pName
);
1403 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1407 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1409 if (!device
|| !pName
)
1412 int idx
= anv_get_device_entrypoint_index(pName
);
1416 return device
->dispatch
.entrypoints
[idx
];
1420 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1421 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1422 const VkAllocationCallbacks
* pAllocator
,
1423 VkDebugReportCallbackEXT
* pCallback
)
1425 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1426 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1427 pCreateInfo
, pAllocator
, &instance
->alloc
,
1432 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1433 VkDebugReportCallbackEXT _callback
,
1434 const VkAllocationCallbacks
* pAllocator
)
1436 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1437 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1438 _callback
, pAllocator
, &instance
->alloc
);
1442 anv_DebugReportMessageEXT(VkInstance _instance
,
1443 VkDebugReportFlagsEXT flags
,
1444 VkDebugReportObjectTypeEXT objectType
,
1447 int32_t messageCode
,
1448 const char* pLayerPrefix
,
1449 const char* pMessage
)
1451 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1452 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1453 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1457 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1459 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1460 queue
->device
= device
;
1465 anv_queue_finish(struct anv_queue
*queue
)
1469 static struct anv_state
1470 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1472 struct anv_state state
;
1474 state
= anv_state_pool_alloc(pool
, size
, align
);
1475 memcpy(state
.map
, p
, size
);
1477 anv_state_flush(pool
->block_pool
.device
, state
);
1482 struct gen8_border_color
{
1487 /* Pad out to 64 bytes */
1492 anv_device_init_border_colors(struct anv_device
*device
)
1494 static const struct gen8_border_color border_colors
[] = {
1495 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1496 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1497 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1498 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1499 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1500 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1503 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1504 sizeof(border_colors
), 64,
1509 anv_device_init_trivial_batch(struct anv_device
*device
)
1511 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1513 if (device
->instance
->physicalDevice
.has_exec_async
)
1514 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1516 if (device
->instance
->physicalDevice
.use_softpin
)
1517 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_PINNED
;
1519 anv_vma_alloc(device
, &device
->trivial_batch_bo
);
1521 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1524 struct anv_batch batch
= {
1530 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1531 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1533 if (!device
->info
.has_llc
)
1534 gen_clflush_range(map
, batch
.next
- map
);
1536 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1539 VkResult
anv_EnumerateDeviceExtensionProperties(
1540 VkPhysicalDevice physicalDevice
,
1541 const char* pLayerName
,
1542 uint32_t* pPropertyCount
,
1543 VkExtensionProperties
* pProperties
)
1545 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1546 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1548 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1549 if (device
->supported_extensions
.extensions
[i
]) {
1550 vk_outarray_append(&out
, prop
) {
1551 *prop
= anv_device_extensions
[i
];
1556 return vk_outarray_status(&out
);
1560 anv_device_init_dispatch(struct anv_device
*device
)
1562 const struct anv_device_dispatch_table
*genX_table
;
1563 switch (device
->info
.gen
) {
1565 genX_table
= &gen11_device_dispatch_table
;
1568 genX_table
= &gen10_device_dispatch_table
;
1571 genX_table
= &gen9_device_dispatch_table
;
1574 genX_table
= &gen8_device_dispatch_table
;
1577 if (device
->info
.is_haswell
)
1578 genX_table
= &gen75_device_dispatch_table
;
1580 genX_table
= &gen7_device_dispatch_table
;
1583 unreachable("unsupported gen\n");
1586 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1587 /* Vulkan requires that entrypoints for extensions which have not been
1588 * enabled must not be advertised.
1590 if (!anv_device_entrypoint_is_enabled(i
, device
->instance
->app_info
.api_version
,
1591 &device
->instance
->enabled_extensions
,
1592 &device
->enabled_extensions
)) {
1593 device
->dispatch
.entrypoints
[i
] = NULL
;
1594 } else if (genX_table
->entrypoints
[i
]) {
1595 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1597 device
->dispatch
.entrypoints
[i
] =
1598 anv_device_dispatch_table
.entrypoints
[i
];
1604 vk_priority_to_gen(int priority
)
1607 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1608 return GEN_CONTEXT_LOW_PRIORITY
;
1609 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1610 return GEN_CONTEXT_MEDIUM_PRIORITY
;
1611 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1612 return GEN_CONTEXT_HIGH_PRIORITY
;
1613 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1614 return GEN_CONTEXT_REALTIME_PRIORITY
;
1616 unreachable("Invalid priority");
1621 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
1623 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
1625 if (device
->instance
->physicalDevice
.has_exec_async
)
1626 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1628 if (device
->instance
->physicalDevice
.use_softpin
)
1629 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_PINNED
;
1631 anv_vma_alloc(device
, &device
->hiz_clear_bo
);
1633 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
1636 union isl_color_value hiz_clear
= { .u32
= { 0, } };
1637 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
1639 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
1640 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
1643 VkResult
anv_CreateDevice(
1644 VkPhysicalDevice physicalDevice
,
1645 const VkDeviceCreateInfo
* pCreateInfo
,
1646 const VkAllocationCallbacks
* pAllocator
,
1649 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1651 struct anv_device
*device
;
1653 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1655 struct anv_device_extension_table enabled_extensions
= { };
1656 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1658 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1659 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1660 anv_device_extensions
[idx
].extensionName
) == 0)
1664 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1665 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1667 if (!physical_device
->supported_extensions
.extensions
[idx
])
1668 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1670 enabled_extensions
.extensions
[idx
] = true;
1673 /* Check enabled features */
1674 if (pCreateInfo
->pEnabledFeatures
) {
1675 VkPhysicalDeviceFeatures supported_features
;
1676 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1677 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1678 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1679 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1680 for (uint32_t i
= 0; i
< num_features
; i
++) {
1681 if (enabled_feature
[i
] && !supported_feature
[i
])
1682 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1686 /* Check requested queues and fail if we are requested to create any
1687 * queues with flags we don't support.
1689 assert(pCreateInfo
->queueCreateInfoCount
> 0);
1690 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1691 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
1692 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1695 /* Check if client specified queue priority. */
1696 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
1697 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
1698 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1700 VkQueueGlobalPriorityEXT priority
=
1701 queue_priority
? queue_priority
->globalPriority
:
1702 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
1704 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1706 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1708 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1710 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1711 device
->instance
= physical_device
->instance
;
1712 device
->chipset_id
= physical_device
->chipset_id
;
1713 device
->no_hw
= physical_device
->no_hw
;
1714 device
->lost
= false;
1717 device
->alloc
= *pAllocator
;
1719 device
->alloc
= physical_device
->instance
->alloc
;
1721 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1722 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1723 if (device
->fd
== -1) {
1724 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1728 device
->context_id
= anv_gem_create_context(device
);
1729 if (device
->context_id
== -1) {
1730 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1734 if (physical_device
->use_softpin
) {
1735 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
1736 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1740 /* keep the page with address zero out of the allocator */
1741 util_vma_heap_init(&device
->vma_lo
, LOW_HEAP_MIN_ADDRESS
, LOW_HEAP_SIZE
);
1742 device
->vma_lo_available
=
1743 physical_device
->memory
.heaps
[physical_device
->memory
.heap_count
- 1].size
;
1745 /* Leave the last 4GiB out of the high vma range, so that no state base
1746 * address + size can overflow 48 bits. For more information see the
1747 * comment about Wa32bitGeneralStateOffset in anv_allocator.c
1749 util_vma_heap_init(&device
->vma_hi
, HIGH_HEAP_MIN_ADDRESS
,
1751 device
->vma_hi_available
= physical_device
->memory
.heap_count
== 1 ? 0 :
1752 physical_device
->memory
.heaps
[0].size
;
1755 /* As per spec, the driver implementation may deny requests to acquire
1756 * a priority above the default priority (MEDIUM) if the caller does not
1757 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
1760 if (physical_device
->has_context_priority
) {
1761 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
1762 I915_CONTEXT_PARAM_PRIORITY
,
1763 vk_priority_to_gen(priority
));
1764 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
1765 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
1770 device
->info
= physical_device
->info
;
1771 device
->isl_dev
= physical_device
->isl_dev
;
1773 /* On Broadwell and later, we can use batch chaining to more efficiently
1774 * implement growing command buffers. Prior to Haswell, the kernel
1775 * command parser gets in the way and we have to fall back to growing
1778 device
->can_chain_batches
= device
->info
.gen
>= 8;
1780 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1781 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1782 device
->enabled_extensions
= enabled_extensions
;
1784 anv_device_init_dispatch(device
);
1786 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1787 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1788 goto fail_context_id
;
1791 pthread_condattr_t condattr
;
1792 if (pthread_condattr_init(&condattr
) != 0) {
1793 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1796 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1797 pthread_condattr_destroy(&condattr
);
1798 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1801 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1802 pthread_condattr_destroy(&condattr
);
1803 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1806 pthread_condattr_destroy(&condattr
);
1809 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1810 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1811 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0) |
1812 (physical_device
->use_softpin
? EXEC_OBJECT_PINNED
: 0);
1814 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1816 result
= anv_bo_cache_init(&device
->bo_cache
);
1817 if (result
!= VK_SUCCESS
)
1818 goto fail_batch_bo_pool
;
1820 if (!physical_device
->use_softpin
)
1821 bo_flags
&= ~EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1823 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
1824 DYNAMIC_STATE_POOL_MIN_ADDRESS
,
1827 if (result
!= VK_SUCCESS
)
1830 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
1831 INSTRUCTION_STATE_POOL_MIN_ADDRESS
,
1834 if (result
!= VK_SUCCESS
)
1835 goto fail_dynamic_state_pool
;
1837 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
1838 SURFACE_STATE_POOL_MIN_ADDRESS
,
1841 if (result
!= VK_SUCCESS
)
1842 goto fail_instruction_state_pool
;
1844 if (physical_device
->use_softpin
) {
1845 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
1846 BINDING_TABLE_POOL_MIN_ADDRESS
,
1849 if (result
!= VK_SUCCESS
)
1850 goto fail_surface_state_pool
;
1853 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1854 if (result
!= VK_SUCCESS
)
1855 goto fail_binding_table_pool
;
1857 if (physical_device
->use_softpin
)
1858 device
->workaround_bo
.flags
|= EXEC_OBJECT_PINNED
;
1860 if (!anv_vma_alloc(device
, &device
->workaround_bo
))
1861 goto fail_workaround_bo
;
1863 anv_device_init_trivial_batch(device
);
1865 if (device
->info
.gen
>= 10)
1866 anv_device_init_hiz_clear_value_bo(device
);
1868 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1870 anv_queue_init(device
, &device
->queue
);
1872 switch (device
->info
.gen
) {
1874 if (!device
->info
.is_haswell
)
1875 result
= gen7_init_device_state(device
);
1877 result
= gen75_init_device_state(device
);
1880 result
= gen8_init_device_state(device
);
1883 result
= gen9_init_device_state(device
);
1886 result
= gen10_init_device_state(device
);
1889 result
= gen11_init_device_state(device
);
1892 /* Shouldn't get here as we don't create physical devices for any other
1894 unreachable("unhandled gen");
1896 if (result
!= VK_SUCCESS
)
1897 goto fail_workaround_bo
;
1899 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
, true);
1901 anv_device_init_blorp(device
);
1903 anv_device_init_border_colors(device
);
1905 *pDevice
= anv_device_to_handle(device
);
1910 anv_queue_finish(&device
->queue
);
1911 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1912 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1913 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1914 fail_binding_table_pool
:
1915 if (physical_device
->use_softpin
)
1916 anv_state_pool_finish(&device
->binding_table_pool
);
1917 fail_surface_state_pool
:
1918 anv_state_pool_finish(&device
->surface_state_pool
);
1919 fail_instruction_state_pool
:
1920 anv_state_pool_finish(&device
->instruction_state_pool
);
1921 fail_dynamic_state_pool
:
1922 anv_state_pool_finish(&device
->dynamic_state_pool
);
1924 anv_bo_cache_finish(&device
->bo_cache
);
1926 anv_bo_pool_finish(&device
->batch_bo_pool
);
1927 pthread_cond_destroy(&device
->queue_submit
);
1929 pthread_mutex_destroy(&device
->mutex
);
1931 anv_gem_destroy_context(device
, device
->context_id
);
1935 vk_free(&device
->alloc
, device
);
1940 void anv_DestroyDevice(
1942 const VkAllocationCallbacks
* pAllocator
)
1944 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1945 struct anv_physical_device
*physical_device
;
1950 physical_device
= &device
->instance
->physicalDevice
;
1952 anv_device_finish_blorp(device
);
1954 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
1956 anv_queue_finish(&device
->queue
);
1958 #ifdef HAVE_VALGRIND
1959 /* We only need to free these to prevent valgrind errors. The backing
1960 * BO will go away in a couple of lines so we don't actually leak.
1962 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1965 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1967 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1968 anv_vma_free(device
, &device
->workaround_bo
);
1969 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1971 anv_vma_free(device
, &device
->trivial_batch_bo
);
1972 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1973 if (device
->info
.gen
>= 10)
1974 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
1976 if (physical_device
->use_softpin
)
1977 anv_state_pool_finish(&device
->binding_table_pool
);
1978 anv_state_pool_finish(&device
->surface_state_pool
);
1979 anv_state_pool_finish(&device
->instruction_state_pool
);
1980 anv_state_pool_finish(&device
->dynamic_state_pool
);
1982 anv_bo_cache_finish(&device
->bo_cache
);
1984 anv_bo_pool_finish(&device
->batch_bo_pool
);
1986 pthread_cond_destroy(&device
->queue_submit
);
1987 pthread_mutex_destroy(&device
->mutex
);
1989 anv_gem_destroy_context(device
, device
->context_id
);
1993 vk_free(&device
->alloc
, device
);
1996 VkResult
anv_EnumerateInstanceLayerProperties(
1997 uint32_t* pPropertyCount
,
1998 VkLayerProperties
* pProperties
)
2000 if (pProperties
== NULL
) {
2001 *pPropertyCount
= 0;
2005 /* None supported at this time */
2006 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2009 VkResult
anv_EnumerateDeviceLayerProperties(
2010 VkPhysicalDevice physicalDevice
,
2011 uint32_t* pPropertyCount
,
2012 VkLayerProperties
* pProperties
)
2014 if (pProperties
== NULL
) {
2015 *pPropertyCount
= 0;
2019 /* None supported at this time */
2020 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2023 void anv_GetDeviceQueue(
2025 uint32_t queueNodeIndex
,
2026 uint32_t queueIndex
,
2029 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2031 assert(queueIndex
== 0);
2033 *pQueue
= anv_queue_to_handle(&device
->queue
);
2036 void anv_GetDeviceQueue2(
2038 const VkDeviceQueueInfo2
* pQueueInfo
,
2041 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2043 assert(pQueueInfo
->queueIndex
== 0);
2045 if (pQueueInfo
->flags
== device
->queue
.flags
)
2046 *pQueue
= anv_queue_to_handle(&device
->queue
);
2052 anv_device_query_status(struct anv_device
*device
)
2054 /* This isn't likely as most of the callers of this function already check
2055 * for it. However, it doesn't hurt to check and it potentially lets us
2058 if (unlikely(device
->lost
))
2059 return VK_ERROR_DEVICE_LOST
;
2061 uint32_t active
, pending
;
2062 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
2064 /* We don't know the real error. */
2065 device
->lost
= true;
2066 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
2067 "get_reset_stats failed: %m");
2071 device
->lost
= true;
2072 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
2073 "GPU hung on one of our command buffers");
2074 } else if (pending
) {
2075 device
->lost
= true;
2076 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
2077 "GPU hung with commands in-flight");
2084 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
2086 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
2087 * Other usages of the BO (such as on different hardware) will not be
2088 * flagged as "busy" by this ioctl. Use with care.
2090 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
2092 return VK_NOT_READY
;
2093 } else if (ret
== -1) {
2094 /* We don't know the real error. */
2095 device
->lost
= true;
2096 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
2097 "gem wait failed: %m");
2100 /* Query for device status after the busy call. If the BO we're checking
2101 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
2102 * client because it clearly doesn't have valid data. Yes, this most
2103 * likely means an ioctl, but we just did an ioctl to query the busy status
2104 * so it's no great loss.
2106 return anv_device_query_status(device
);
2110 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
2113 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
2114 if (ret
== -1 && errno
== ETIME
) {
2116 } else if (ret
== -1) {
2117 /* We don't know the real error. */
2118 device
->lost
= true;
2119 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
2120 "gem wait failed: %m");
2123 /* Query for device status after the wait. If the BO we're waiting on got
2124 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
2125 * because it clearly doesn't have valid data. Yes, this most likely means
2126 * an ioctl, but we just did an ioctl to wait so it's no great loss.
2128 return anv_device_query_status(device
);
2131 VkResult
anv_DeviceWaitIdle(
2134 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2135 if (unlikely(device
->lost
))
2136 return VK_ERROR_DEVICE_LOST
;
2138 struct anv_batch batch
;
2141 batch
.start
= batch
.next
= cmds
;
2142 batch
.end
= (void *) cmds
+ sizeof(cmds
);
2144 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2145 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2147 return anv_device_submit_simple_batch(device
, &batch
);
2151 anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
)
2153 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2156 pthread_mutex_lock(&device
->vma_mutex
);
2160 if (bo
->flags
& EXEC_OBJECT_SUPPORTS_48B_ADDRESS
&&
2161 device
->vma_hi_available
>= bo
->size
) {
2162 uint64_t addr
= util_vma_heap_alloc(&device
->vma_hi
, bo
->size
, 4096);
2164 bo
->offset
= gen_canonical_address(addr
);
2165 assert(addr
== gen_48b_address(bo
->offset
));
2166 device
->vma_hi_available
-= bo
->size
;
2170 if (bo
->offset
== 0 && device
->vma_lo_available
>= bo
->size
) {
2171 uint64_t addr
= util_vma_heap_alloc(&device
->vma_lo
, bo
->size
, 4096);
2173 bo
->offset
= gen_canonical_address(addr
);
2174 assert(addr
== gen_48b_address(bo
->offset
));
2175 device
->vma_lo_available
-= bo
->size
;
2179 pthread_mutex_unlock(&device
->vma_mutex
);
2181 return bo
->offset
!= 0;
2185 anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
)
2187 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2190 const uint64_t addr_48b
= gen_48b_address(bo
->offset
);
2192 pthread_mutex_lock(&device
->vma_mutex
);
2194 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
2195 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
2196 util_vma_heap_free(&device
->vma_lo
, addr_48b
, bo
->size
);
2197 device
->vma_lo_available
+= bo
->size
;
2199 assert(addr_48b
>= HIGH_HEAP_MIN_ADDRESS
&&
2200 addr_48b
<= HIGH_HEAP_MAX_ADDRESS
);
2201 util_vma_heap_free(&device
->vma_hi
, addr_48b
, bo
->size
);
2202 device
->vma_hi_available
+= bo
->size
;
2205 pthread_mutex_unlock(&device
->vma_mutex
);
2211 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
2213 uint32_t gem_handle
= anv_gem_create(device
, size
);
2215 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2217 anv_bo_init(bo
, gem_handle
, size
);
2222 VkResult
anv_AllocateMemory(
2224 const VkMemoryAllocateInfo
* pAllocateInfo
,
2225 const VkAllocationCallbacks
* pAllocator
,
2226 VkDeviceMemory
* pMem
)
2228 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2229 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2230 struct anv_device_memory
*mem
;
2231 VkResult result
= VK_SUCCESS
;
2233 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2235 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
2236 assert(pAllocateInfo
->allocationSize
> 0);
2238 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
2239 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2241 /* FINISHME: Fail if allocation request exceeds heap size. */
2243 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2244 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2246 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2248 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
2249 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
2253 uint64_t bo_flags
= 0;
2255 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2256 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2257 bo_flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2259 const struct wsi_memory_allocate_info
*wsi_info
=
2260 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2261 if (wsi_info
&& wsi_info
->implicit_sync
) {
2262 /* We need to set the WRITE flag on window system buffers so that GEM
2263 * will know we're writing to them and synchronize uses on other rings
2264 * (eg if the display server uses the blitter ring).
2266 bo_flags
|= EXEC_OBJECT_WRITE
;
2267 } else if (pdevice
->has_exec_async
) {
2268 bo_flags
|= EXEC_OBJECT_ASYNC
;
2271 if (pdevice
->use_softpin
)
2272 bo_flags
|= EXEC_OBJECT_PINNED
;
2274 const VkImportMemoryFdInfoKHR
*fd_info
=
2275 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2277 /* The Vulkan spec permits handleType to be 0, in which case the struct is
2280 if (fd_info
&& fd_info
->handleType
) {
2281 /* At the moment, we support only the below handle types. */
2282 assert(fd_info
->handleType
==
2283 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2284 fd_info
->handleType
==
2285 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2287 result
= anv_bo_cache_import(device
, &device
->bo_cache
, fd_info
->fd
,
2288 bo_flags
| ANV_BO_EXTERNAL
, &mem
->bo
);
2289 if (result
!= VK_SUCCESS
)
2292 VkDeviceSize aligned_alloc_size
=
2293 align_u64(pAllocateInfo
->allocationSize
, 4096);
2295 /* For security purposes, we reject importing the bo if it's smaller
2296 * than the requested allocation size. This prevents a malicious client
2297 * from passing a buffer to a trusted client, lying about the size, and
2298 * telling the trusted client to try and texture from an image that goes
2299 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
2300 * in the trusted client. The trusted client can protect itself against
2301 * this sort of attack but only if it can trust the buffer size.
2303 if (mem
->bo
->size
< aligned_alloc_size
) {
2304 result
= vk_errorf(device
->instance
, device
,
2305 VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
,
2306 "aligned allocationSize too large for "
2307 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR: "
2308 "%"PRIu64
"B > %"PRIu64
"B",
2309 aligned_alloc_size
, mem
->bo
->size
);
2310 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2314 /* From the Vulkan spec:
2316 * "Importing memory from a file descriptor transfers ownership of
2317 * the file descriptor from the application to the Vulkan
2318 * implementation. The application must not perform any operations on
2319 * the file descriptor after a successful import."
2321 * If the import fails, we leave the file descriptor open.
2325 const VkExportMemoryAllocateInfoKHR
*fd_info
=
2326 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2327 if (fd_info
&& fd_info
->handleTypes
)
2328 bo_flags
|= ANV_BO_EXTERNAL
;
2330 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
2331 pAllocateInfo
->allocationSize
, bo_flags
,
2333 if (result
!= VK_SUCCESS
)
2336 const VkMemoryDedicatedAllocateInfoKHR
*dedicated_info
=
2337 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2338 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
2339 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
2341 /* Some legacy (non-modifiers) consumers need the tiling to be set on
2342 * the BO. In this case, we have a dedicated allocation.
2344 if (image
->needs_set_tiling
) {
2345 const uint32_t i915_tiling
=
2346 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
2347 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
2348 image
->planes
[0].surface
.isl
.row_pitch_B
,
2351 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2352 return vk_errorf(device
->instance
, NULL
,
2353 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
2354 "failed to set BO tiling: %m");
2360 *pMem
= anv_device_memory_to_handle(mem
);
2365 vk_free2(&device
->alloc
, pAllocator
, mem
);
2370 VkResult
anv_GetMemoryFdKHR(
2372 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
2375 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
2376 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
2378 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2380 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2381 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2383 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
2386 VkResult
anv_GetMemoryFdPropertiesKHR(
2388 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
2390 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
2392 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2393 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2395 switch (handleType
) {
2396 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
2397 /* dma-buf can be imported as any memory type */
2398 pMemoryFdProperties
->memoryTypeBits
=
2399 (1 << pdevice
->memory
.type_count
) - 1;
2403 /* The valid usage section for this function says:
2405 * "handleType must not be one of the handle types defined as
2408 * So opaque handle types fall into the default "unsupported" case.
2410 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2414 void anv_FreeMemory(
2416 VkDeviceMemory _mem
,
2417 const VkAllocationCallbacks
* pAllocator
)
2419 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2420 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
2426 anv_UnmapMemory(_device
, _mem
);
2428 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2430 vk_free2(&device
->alloc
, pAllocator
, mem
);
2433 VkResult
anv_MapMemory(
2435 VkDeviceMemory _memory
,
2436 VkDeviceSize offset
,
2438 VkMemoryMapFlags flags
,
2441 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2442 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2449 if (size
== VK_WHOLE_SIZE
)
2450 size
= mem
->bo
->size
- offset
;
2452 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
2454 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
2455 * assert(size != 0);
2456 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
2457 * equal to the size of the memory minus offset
2460 assert(offset
+ size
<= mem
->bo
->size
);
2462 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
2463 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
2464 * at a time is valid. We could just mmap up front and return an offset
2465 * pointer here, but that may exhaust virtual memory on 32 bit
2468 uint32_t gem_flags
= 0;
2470 if (!device
->info
.has_llc
&&
2471 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
2472 gem_flags
|= I915_MMAP_WC
;
2474 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
2475 uint64_t map_offset
= offset
& ~4095ull;
2476 assert(offset
>= map_offset
);
2477 uint64_t map_size
= (offset
+ size
) - map_offset
;
2479 /* Let's map whole pages */
2480 map_size
= align_u64(map_size
, 4096);
2482 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2483 map_offset
, map_size
, gem_flags
);
2484 if (map
== MAP_FAILED
)
2485 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2488 mem
->map_size
= map_size
;
2490 *ppData
= mem
->map
+ (offset
- map_offset
);
2495 void anv_UnmapMemory(
2497 VkDeviceMemory _memory
)
2499 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2504 anv_gem_munmap(mem
->map
, mem
->map_size
);
2511 clflush_mapped_ranges(struct anv_device
*device
,
2513 const VkMappedMemoryRange
*ranges
)
2515 for (uint32_t i
= 0; i
< count
; i
++) {
2516 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2517 if (ranges
[i
].offset
>= mem
->map_size
)
2520 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2521 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2525 VkResult
anv_FlushMappedMemoryRanges(
2527 uint32_t memoryRangeCount
,
2528 const VkMappedMemoryRange
* pMemoryRanges
)
2530 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2532 if (device
->info
.has_llc
)
2535 /* Make sure the writes we're flushing have landed. */
2536 __builtin_ia32_mfence();
2538 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2543 VkResult
anv_InvalidateMappedMemoryRanges(
2545 uint32_t memoryRangeCount
,
2546 const VkMappedMemoryRange
* pMemoryRanges
)
2548 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2550 if (device
->info
.has_llc
)
2553 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2555 /* Make sure no reads get moved up above the invalidate. */
2556 __builtin_ia32_mfence();
2561 void anv_GetBufferMemoryRequirements(
2564 VkMemoryRequirements
* pMemoryRequirements
)
2566 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2567 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2568 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2570 /* The Vulkan spec (git aaed022) says:
2572 * memoryTypeBits is a bitfield and contains one bit set for every
2573 * supported memory type for the resource. The bit `1<<i` is set if and
2574 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2575 * structure for the physical device is supported.
2577 uint32_t memory_types
= 0;
2578 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2579 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2580 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2581 memory_types
|= (1u << i
);
2584 /* Base alignment requirement of a cache line */
2585 uint32_t alignment
= 16;
2587 /* We need an alignment of 32 for pushing UBOs */
2588 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2589 alignment
= MAX2(alignment
, 32);
2591 pMemoryRequirements
->size
= buffer
->size
;
2592 pMemoryRequirements
->alignment
= alignment
;
2594 /* Storage and Uniform buffers should have their size aligned to
2595 * 32-bits to avoid boundary checks when last DWord is not complete.
2596 * This would ensure that not internal padding would be needed for
2599 if (device
->robust_buffer_access
&&
2600 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
2601 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
2602 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
2604 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2607 void anv_GetBufferMemoryRequirements2(
2609 const VkBufferMemoryRequirementsInfo2
* pInfo
,
2610 VkMemoryRequirements2
* pMemoryRequirements
)
2612 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2613 &pMemoryRequirements
->memoryRequirements
);
2615 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2616 switch (ext
->sType
) {
2617 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2618 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2619 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2620 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2625 anv_debug_ignored_stype(ext
->sType
);
2631 void anv_GetImageMemoryRequirements(
2634 VkMemoryRequirements
* pMemoryRequirements
)
2636 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2637 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2638 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2640 /* The Vulkan spec (git aaed022) says:
2642 * memoryTypeBits is a bitfield and contains one bit set for every
2643 * supported memory type for the resource. The bit `1<<i` is set if and
2644 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2645 * structure for the physical device is supported.
2647 * All types are currently supported for images.
2649 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2651 pMemoryRequirements
->size
= image
->size
;
2652 pMemoryRequirements
->alignment
= image
->alignment
;
2653 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2656 void anv_GetImageMemoryRequirements2(
2658 const VkImageMemoryRequirementsInfo2
* pInfo
,
2659 VkMemoryRequirements2
* pMemoryRequirements
)
2661 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2662 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2664 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2665 &pMemoryRequirements
->memoryRequirements
);
2667 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2668 switch (ext
->sType
) {
2669 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
2670 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2671 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
2672 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
2673 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2674 plane_reqs
->planeAspect
);
2676 assert(image
->planes
[plane
].offset
== 0);
2678 /* The Vulkan spec (git aaed022) says:
2680 * memoryTypeBits is a bitfield and contains one bit set for every
2681 * supported memory type for the resource. The bit `1<<i` is set
2682 * if and only if the memory type `i` in the
2683 * VkPhysicalDeviceMemoryProperties structure for the physical
2684 * device is supported.
2686 * All types are currently supported for images.
2688 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2689 (1ull << pdevice
->memory
.type_count
) - 1;
2691 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2692 pMemoryRequirements
->memoryRequirements
.alignment
=
2693 image
->planes
[plane
].alignment
;
2698 anv_debug_ignored_stype(ext
->sType
);
2703 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2704 switch (ext
->sType
) {
2705 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2706 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2707 if (image
->needs_set_tiling
) {
2708 /* If we need to set the tiling for external consumers, we need a
2709 * dedicated allocation.
2711 * See also anv_AllocateMemory.
2713 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2714 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2716 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2717 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2723 anv_debug_ignored_stype(ext
->sType
);
2729 void anv_GetImageSparseMemoryRequirements(
2732 uint32_t* pSparseMemoryRequirementCount
,
2733 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2735 *pSparseMemoryRequirementCount
= 0;
2738 void anv_GetImageSparseMemoryRequirements2(
2740 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
2741 uint32_t* pSparseMemoryRequirementCount
,
2742 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
2744 *pSparseMemoryRequirementCount
= 0;
2747 void anv_GetDeviceMemoryCommitment(
2749 VkDeviceMemory memory
,
2750 VkDeviceSize
* pCommittedMemoryInBytes
)
2752 *pCommittedMemoryInBytes
= 0;
2756 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
2758 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2759 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2761 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
2764 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2765 buffer
->address
= (struct anv_address
) {
2767 .offset
= pBindInfo
->memoryOffset
,
2770 buffer
->address
= ANV_NULL_ADDRESS
;
2774 VkResult
anv_BindBufferMemory(
2777 VkDeviceMemory memory
,
2778 VkDeviceSize memoryOffset
)
2780 anv_bind_buffer_memory(
2781 &(VkBindBufferMemoryInfo
) {
2782 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2785 .memoryOffset
= memoryOffset
,
2791 VkResult
anv_BindBufferMemory2(
2793 uint32_t bindInfoCount
,
2794 const VkBindBufferMemoryInfo
* pBindInfos
)
2796 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2797 anv_bind_buffer_memory(&pBindInfos
[i
]);
2802 VkResult
anv_QueueBindSparse(
2804 uint32_t bindInfoCount
,
2805 const VkBindSparseInfo
* pBindInfo
,
2808 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2809 if (unlikely(queue
->device
->lost
))
2810 return VK_ERROR_DEVICE_LOST
;
2812 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2817 VkResult
anv_CreateEvent(
2819 const VkEventCreateInfo
* pCreateInfo
,
2820 const VkAllocationCallbacks
* pAllocator
,
2823 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2824 struct anv_state state
;
2825 struct anv_event
*event
;
2827 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2829 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2832 event
->state
= state
;
2833 event
->semaphore
= VK_EVENT_RESET
;
2835 if (!device
->info
.has_llc
) {
2836 /* Make sure the writes we're flushing have landed. */
2837 __builtin_ia32_mfence();
2838 __builtin_ia32_clflush(event
);
2841 *pEvent
= anv_event_to_handle(event
);
2846 void anv_DestroyEvent(
2849 const VkAllocationCallbacks
* pAllocator
)
2851 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2852 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2857 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2860 VkResult
anv_GetEventStatus(
2864 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2865 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2867 if (unlikely(device
->lost
))
2868 return VK_ERROR_DEVICE_LOST
;
2870 if (!device
->info
.has_llc
) {
2871 /* Invalidate read cache before reading event written by GPU. */
2872 __builtin_ia32_clflush(event
);
2873 __builtin_ia32_mfence();
2877 return event
->semaphore
;
2880 VkResult
anv_SetEvent(
2884 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2885 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2887 event
->semaphore
= VK_EVENT_SET
;
2889 if (!device
->info
.has_llc
) {
2890 /* Make sure the writes we're flushing have landed. */
2891 __builtin_ia32_mfence();
2892 __builtin_ia32_clflush(event
);
2898 VkResult
anv_ResetEvent(
2902 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2903 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2905 event
->semaphore
= VK_EVENT_RESET
;
2907 if (!device
->info
.has_llc
) {
2908 /* Make sure the writes we're flushing have landed. */
2909 __builtin_ia32_mfence();
2910 __builtin_ia32_clflush(event
);
2918 VkResult
anv_CreateBuffer(
2920 const VkBufferCreateInfo
* pCreateInfo
,
2921 const VkAllocationCallbacks
* pAllocator
,
2924 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2925 struct anv_buffer
*buffer
;
2927 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2929 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2930 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2932 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2934 buffer
->size
= pCreateInfo
->size
;
2935 buffer
->usage
= pCreateInfo
->usage
;
2936 buffer
->address
= ANV_NULL_ADDRESS
;
2938 *pBuffer
= anv_buffer_to_handle(buffer
);
2943 void anv_DestroyBuffer(
2946 const VkAllocationCallbacks
* pAllocator
)
2948 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2949 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2954 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2958 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2959 enum isl_format format
,
2960 struct anv_address address
,
2961 uint32_t range
, uint32_t stride
)
2963 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2964 .address
= anv_address_physical(address
),
2965 .mocs
= device
->default_mocs
,
2968 .stride_B
= stride
);
2970 anv_state_flush(device
, state
);
2973 void anv_DestroySampler(
2976 const VkAllocationCallbacks
* pAllocator
)
2978 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2979 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2984 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2987 VkResult
anv_CreateFramebuffer(
2989 const VkFramebufferCreateInfo
* pCreateInfo
,
2990 const VkAllocationCallbacks
* pAllocator
,
2991 VkFramebuffer
* pFramebuffer
)
2993 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2994 struct anv_framebuffer
*framebuffer
;
2996 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2998 size_t size
= sizeof(*framebuffer
) +
2999 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
3000 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3001 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3002 if (framebuffer
== NULL
)
3003 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3005 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3006 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3007 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3008 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
3011 framebuffer
->width
= pCreateInfo
->width
;
3012 framebuffer
->height
= pCreateInfo
->height
;
3013 framebuffer
->layers
= pCreateInfo
->layers
;
3015 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
3020 void anv_DestroyFramebuffer(
3023 const VkAllocationCallbacks
* pAllocator
)
3025 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3026 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
3031 vk_free2(&device
->alloc
, pAllocator
, fb
);
3034 static const VkTimeDomainEXT anv_time_domains
[] = {
3035 VK_TIME_DOMAIN_DEVICE_EXT
,
3036 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
3037 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
3040 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
3041 VkPhysicalDevice physicalDevice
,
3042 uint32_t *pTimeDomainCount
,
3043 VkTimeDomainEXT
*pTimeDomains
)
3046 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
3048 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
3049 vk_outarray_append(&out
, i
) {
3050 *i
= anv_time_domains
[d
];
3054 return vk_outarray_status(&out
);
3058 anv_clock_gettime(clockid_t clock_id
)
3060 struct timespec current
;
3063 ret
= clock_gettime(clock_id
, ¤t
);
3064 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
3065 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3069 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
3072 #define TIMESTAMP 0x2358
3074 VkResult
anv_GetCalibratedTimestampsEXT(
3076 uint32_t timestampCount
,
3077 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
3078 uint64_t *pTimestamps
,
3079 uint64_t *pMaxDeviation
)
3081 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3082 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
3085 uint64_t begin
, end
;
3086 uint64_t max_clock_period
= 0;
3088 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3090 for (d
= 0; d
< timestampCount
; d
++) {
3091 switch (pTimestampInfos
[d
].timeDomain
) {
3092 case VK_TIME_DOMAIN_DEVICE_EXT
:
3093 ret
= anv_gem_reg_read(device
, TIMESTAMP
| 1,
3097 device
->lost
= TRUE
;
3098 return VK_ERROR_DEVICE_LOST
;
3100 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
3101 max_clock_period
= MAX2(max_clock_period
, device_period
);
3103 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
3104 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
3105 max_clock_period
= MAX2(max_clock_period
, 1);
3108 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
3109 pTimestamps
[d
] = begin
;
3117 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3120 * The maximum deviation is the sum of the interval over which we
3121 * perform the sampling and the maximum period of any sampled
3122 * clock. That's because the maximum skew between any two sampled
3123 * clock edges is when the sampled clock with the largest period is
3124 * sampled at the end of that period but right at the beginning of the
3125 * sampling interval and some other clock is sampled right at the
3126 * begining of its sampling period and right at the end of the
3127 * sampling interval. Let's assume the GPU has the longest clock
3128 * period and that the application is sampling GPU and monotonic:
3131 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
3132 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3136 * GPU -----_____-----_____-----_____-----_____
3139 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
3140 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3142 * Interval <----------------->
3143 * Deviation <-------------------------->
3147 * m = read(monotonic) 2
3150 * We round the sample interval up by one tick to cover sampling error
3151 * in the interval clock
3154 uint64_t sample_interval
= end
- begin
+ 1;
3156 *pMaxDeviation
= sample_interval
+ max_clock_period
;
3161 /* vk_icd.h does not declare this function, so we declare it here to
3162 * suppress Wmissing-prototypes.
3164 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3165 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
3167 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3168 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
3170 /* For the full details on loader interface versioning, see
3171 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3172 * What follows is a condensed summary, to help you navigate the large and
3173 * confusing official doc.
3175 * - Loader interface v0 is incompatible with later versions. We don't
3178 * - In loader interface v1:
3179 * - The first ICD entrypoint called by the loader is
3180 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3182 * - The ICD must statically expose no other Vulkan symbol unless it is
3183 * linked with -Bsymbolic.
3184 * - Each dispatchable Vulkan handle created by the ICD must be
3185 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3186 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3187 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3188 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3189 * such loader-managed surfaces.
3191 * - Loader interface v2 differs from v1 in:
3192 * - The first ICD entrypoint called by the loader is
3193 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3194 * statically expose this entrypoint.
3196 * - Loader interface v3 differs from v2 in:
3197 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3198 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3199 * because the loader no longer does so.
3201 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);