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 instance
->app_info
.api_version
= VK_API_VERSION_1_0
;
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
= pdevice
->info
.gen
>= 9,
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_8BIT_STORAGE_FEATURES_KHR
: {
897 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
898 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
899 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
901 features
->storageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
902 features
->uniformAndStorageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
903 features
->storagePushConstant8
= pdevice
->info
.gen
>= 8;
907 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
908 VkPhysicalDevice16BitStorageFeatures
*features
=
909 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
910 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
912 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
913 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
914 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
915 features
->storageInputOutput16
= false;
919 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
920 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
921 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
922 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
924 features
->conditionalRendering
= pdevice
->info
.gen
>= 8 ||
925 pdevice
->info
.is_haswell
;
926 features
->inheritedConditionalRendering
= pdevice
->info
.gen
>= 8 ||
927 pdevice
->info
.is_haswell
;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
932 VkPhysicalDeviceMultiviewFeatures
*features
=
933 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
934 features
->multiview
= true;
935 features
->multiviewGeometryShader
= true;
936 features
->multiviewTessellationShader
= true;
940 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
941 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
942 features
->protectedMemory
= VK_FALSE
;
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
947 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
948 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
949 features
->samplerYcbcrConversion
= true;
953 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
954 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
955 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
956 features
->scalarBlockLayout
= true;
960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
961 VkPhysicalDeviceShaderDrawParameterFeatures
*features
= (void *)ext
;
962 features
->shaderDrawParameters
= true;
966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
967 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
968 features
->variablePointersStorageBuffer
= true;
969 features
->variablePointers
= true;
973 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
974 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
975 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
976 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
977 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
982 anv_debug_ignored_stype(ext
->sType
);
988 void anv_GetPhysicalDeviceProperties(
989 VkPhysicalDevice physicalDevice
,
990 VkPhysicalDeviceProperties
* pProperties
)
992 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
993 const struct gen_device_info
*devinfo
= &pdevice
->info
;
995 /* See assertions made when programming the buffer surface state. */
996 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
997 (1ul << 30) : (1ul << 27);
999 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
1002 const uint32_t max_images
= devinfo
->gen
< 9 ? MAX_GEN8_IMAGES
: MAX_IMAGES
;
1004 VkSampleCountFlags sample_counts
=
1005 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1008 VkPhysicalDeviceLimits limits
= {
1009 .maxImageDimension1D
= (1 << 14),
1010 .maxImageDimension2D
= (1 << 14),
1011 .maxImageDimension3D
= (1 << 11),
1012 .maxImageDimensionCube
= (1 << 14),
1013 .maxImageArrayLayers
= (1 << 11),
1014 .maxTexelBufferElements
= 128 * 1024 * 1024,
1015 .maxUniformBufferRange
= (1ul << 27),
1016 .maxStorageBufferRange
= max_raw_buffer_sz
,
1017 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1018 .maxMemoryAllocationCount
= UINT32_MAX
,
1019 .maxSamplerAllocationCount
= 64 * 1024,
1020 .bufferImageGranularity
= 64, /* A cache line */
1021 .sparseAddressSpaceSize
= 0,
1022 .maxBoundDescriptorSets
= MAX_SETS
,
1023 .maxPerStageDescriptorSamplers
= max_samplers
,
1024 .maxPerStageDescriptorUniformBuffers
= 64,
1025 .maxPerStageDescriptorStorageBuffers
= 64,
1026 .maxPerStageDescriptorSampledImages
= max_samplers
,
1027 .maxPerStageDescriptorStorageImages
= max_images
,
1028 .maxPerStageDescriptorInputAttachments
= 64,
1029 .maxPerStageResources
= 250,
1030 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1031 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
1032 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1033 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
1034 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1035 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
1036 .maxDescriptorSetStorageImages
= 6 * max_images
, /* number of stages * maxPerStageDescriptorStorageImages */
1037 .maxDescriptorSetInputAttachments
= 256,
1038 .maxVertexInputAttributes
= MAX_VBS
,
1039 .maxVertexInputBindings
= MAX_VBS
,
1040 .maxVertexInputAttributeOffset
= 2047,
1041 .maxVertexInputBindingStride
= 2048,
1042 .maxVertexOutputComponents
= 128,
1043 .maxTessellationGenerationLevel
= 64,
1044 .maxTessellationPatchSize
= 32,
1045 .maxTessellationControlPerVertexInputComponents
= 128,
1046 .maxTessellationControlPerVertexOutputComponents
= 128,
1047 .maxTessellationControlPerPatchOutputComponents
= 128,
1048 .maxTessellationControlTotalOutputComponents
= 2048,
1049 .maxTessellationEvaluationInputComponents
= 128,
1050 .maxTessellationEvaluationOutputComponents
= 128,
1051 .maxGeometryShaderInvocations
= 32,
1052 .maxGeometryInputComponents
= 64,
1053 .maxGeometryOutputComponents
= 128,
1054 .maxGeometryOutputVertices
= 256,
1055 .maxGeometryTotalOutputComponents
= 1024,
1056 .maxFragmentInputComponents
= 112, /* 128 components - (POS, PSIZ, CLIP_DIST0, CLIP_DIST1) */
1057 .maxFragmentOutputAttachments
= 8,
1058 .maxFragmentDualSrcAttachments
= 1,
1059 .maxFragmentCombinedOutputResources
= 8,
1060 .maxComputeSharedMemorySize
= 32768,
1061 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1062 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
1063 .maxComputeWorkGroupSize
= {
1064 16 * devinfo
->max_cs_threads
,
1065 16 * devinfo
->max_cs_threads
,
1066 16 * devinfo
->max_cs_threads
,
1068 .subPixelPrecisionBits
= 4 /* FIXME */,
1069 .subTexelPrecisionBits
= 4 /* FIXME */,
1070 .mipmapPrecisionBits
= 4 /* FIXME */,
1071 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1072 .maxDrawIndirectCount
= UINT32_MAX
,
1073 .maxSamplerLodBias
= 16,
1074 .maxSamplerAnisotropy
= 16,
1075 .maxViewports
= MAX_VIEWPORTS
,
1076 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1077 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1078 .viewportSubPixelBits
= 13, /* We take a float? */
1079 .minMemoryMapAlignment
= 4096, /* A page */
1080 .minTexelBufferOffsetAlignment
= 1,
1081 /* We need 16 for UBO block reads to work and 32 for push UBOs */
1082 .minUniformBufferOffsetAlignment
= 32,
1083 .minStorageBufferOffsetAlignment
= 4,
1084 .minTexelOffset
= -8,
1085 .maxTexelOffset
= 7,
1086 .minTexelGatherOffset
= -32,
1087 .maxTexelGatherOffset
= 31,
1088 .minInterpolationOffset
= -0.5,
1089 .maxInterpolationOffset
= 0.4375,
1090 .subPixelInterpolationOffsetBits
= 4,
1091 .maxFramebufferWidth
= (1 << 14),
1092 .maxFramebufferHeight
= (1 << 14),
1093 .maxFramebufferLayers
= (1 << 11),
1094 .framebufferColorSampleCounts
= sample_counts
,
1095 .framebufferDepthSampleCounts
= sample_counts
,
1096 .framebufferStencilSampleCounts
= sample_counts
,
1097 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1098 .maxColorAttachments
= MAX_RTS
,
1099 .sampledImageColorSampleCounts
= sample_counts
,
1100 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1101 .sampledImageDepthSampleCounts
= sample_counts
,
1102 .sampledImageStencilSampleCounts
= sample_counts
,
1103 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1104 .maxSampleMaskWords
= 1,
1105 .timestampComputeAndGraphics
= false,
1106 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1107 .maxClipDistances
= 8,
1108 .maxCullDistances
= 8,
1109 .maxCombinedClipAndCullDistances
= 8,
1110 .discreteQueuePriorities
= 2,
1111 .pointSizeRange
= { 0.125, 255.875 },
1112 .lineWidthRange
= { 0.0, 7.9921875 },
1113 .pointSizeGranularity
= (1.0 / 8.0),
1114 .lineWidthGranularity
= (1.0 / 128.0),
1115 .strictLines
= false, /* FINISHME */
1116 .standardSampleLocations
= true,
1117 .optimalBufferCopyOffsetAlignment
= 128,
1118 .optimalBufferCopyRowPitchAlignment
= 128,
1119 .nonCoherentAtomSize
= 64,
1122 *pProperties
= (VkPhysicalDeviceProperties
) {
1123 .apiVersion
= anv_physical_device_api_version(pdevice
),
1124 .driverVersion
= vk_get_driver_version(),
1126 .deviceID
= pdevice
->chipset_id
,
1127 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1129 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1132 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1133 "%s", pdevice
->name
);
1134 memcpy(pProperties
->pipelineCacheUUID
,
1135 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1138 void anv_GetPhysicalDeviceProperties2(
1139 VkPhysicalDevice physicalDevice
,
1140 VkPhysicalDeviceProperties2
* pProperties
)
1142 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1144 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1146 vk_foreach_struct(ext
, pProperties
->pNext
) {
1147 switch (ext
->sType
) {
1148 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1149 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*props
=
1150 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1152 /* We support all of the depth resolve modes */
1153 props
->supportedDepthResolveModes
=
1154 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1155 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1156 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1157 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1159 /* Average doesn't make sense for stencil so we don't support that */
1160 props
->supportedStencilResolveModes
=
1161 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
;
1162 if (pdevice
->info
.gen
>= 8) {
1163 /* The advanced stencil resolve modes currently require stencil
1164 * sampling be supported by the hardware.
1166 props
->supportedStencilResolveModes
|=
1167 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1168 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1171 props
->independentResolveNone
= VK_TRUE
;
1172 props
->independentResolve
= VK_TRUE
;
1176 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1177 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1178 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1180 driver_props
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1181 util_snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1182 "Intel open-source Mesa driver");
1184 util_snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1185 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1187 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1196 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1197 VkPhysicalDeviceIDProperties
*id_props
=
1198 (VkPhysicalDeviceIDProperties
*)ext
;
1199 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1200 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1201 /* The LUID is for Windows. */
1202 id_props
->deviceLUIDValid
= false;
1206 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1207 VkPhysicalDeviceMaintenance3Properties
*props
=
1208 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1209 /* This value doesn't matter for us today as our per-stage
1210 * descriptors are the real limit.
1212 props
->maxPerSetDescriptors
= 1024;
1213 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1217 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1218 VkPhysicalDeviceMultiviewProperties
*properties
=
1219 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1220 properties
->maxMultiviewViewCount
= 16;
1221 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1225 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1226 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1227 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1228 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1229 properties
->pciBus
= pdevice
->pci_info
.bus
;
1230 properties
->pciDevice
= pdevice
->pci_info
.device
;
1231 properties
->pciFunction
= pdevice
->pci_info
.function
;
1235 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1236 VkPhysicalDevicePointClippingProperties
*properties
=
1237 (VkPhysicalDevicePointClippingProperties
*) ext
;
1238 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1239 anv_finishme("Implement pop-free point clipping");
1243 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1244 VkPhysicalDeviceProtectedMemoryProperties
*props
=
1245 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1246 props
->protectedNoFault
= false;
1250 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1251 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1252 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1254 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1258 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1259 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1260 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1261 properties
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1262 properties
->filterMinmaxSingleComponentFormats
= true;
1266 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1267 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1269 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1271 VkShaderStageFlags scalar_stages
= 0;
1272 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1273 if (pdevice
->compiler
->scalar_stage
[stage
])
1274 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1276 properties
->supportedStages
= scalar_stages
;
1278 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1279 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1280 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1281 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1282 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1283 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1284 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1285 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1286 properties
->quadOperationsInAllStages
= VK_TRUE
;
1290 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1291 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1292 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1293 /* We have to restrict this a bit for multiview */
1294 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
1299 anv_debug_ignored_stype(ext
->sType
);
1305 /* We support exactly one queue family. */
1306 static const VkQueueFamilyProperties
1307 anv_queue_family_properties
= {
1308 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1309 VK_QUEUE_COMPUTE_BIT
|
1310 VK_QUEUE_TRANSFER_BIT
,
1312 .timestampValidBits
= 36, /* XXX: Real value here */
1313 .minImageTransferGranularity
= { 1, 1, 1 },
1316 void anv_GetPhysicalDeviceQueueFamilyProperties(
1317 VkPhysicalDevice physicalDevice
,
1319 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1321 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1323 vk_outarray_append(&out
, p
) {
1324 *p
= anv_queue_family_properties
;
1328 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1329 VkPhysicalDevice physicalDevice
,
1330 uint32_t* pQueueFamilyPropertyCount
,
1331 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1334 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1336 vk_outarray_append(&out
, p
) {
1337 p
->queueFamilyProperties
= anv_queue_family_properties
;
1339 vk_foreach_struct(s
, p
->pNext
) {
1340 anv_debug_ignored_stype(s
->sType
);
1345 void anv_GetPhysicalDeviceMemoryProperties(
1346 VkPhysicalDevice physicalDevice
,
1347 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1349 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1351 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1352 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1353 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1354 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1355 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1359 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1360 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1361 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1362 .size
= physical_device
->memory
.heaps
[i
].size
,
1363 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1368 void anv_GetPhysicalDeviceMemoryProperties2(
1369 VkPhysicalDevice physicalDevice
,
1370 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1372 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1373 &pMemoryProperties
->memoryProperties
);
1375 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1376 switch (ext
->sType
) {
1378 anv_debug_ignored_stype(ext
->sType
);
1385 anv_GetDeviceGroupPeerMemoryFeatures(
1388 uint32_t localDeviceIndex
,
1389 uint32_t remoteDeviceIndex
,
1390 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1392 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1393 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1394 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1395 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1396 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1399 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1400 VkInstance _instance
,
1403 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1405 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1406 * when we have to return valid function pointers, NULL, or it's left
1407 * undefined. See the table for exact details.
1412 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1413 if (strcmp(pName, "vk" #entrypoint) == 0) \
1414 return (PFN_vkVoidFunction)anv_##entrypoint
1416 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1417 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1418 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1419 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1421 #undef LOOKUP_ANV_ENTRYPOINT
1423 if (instance
== NULL
)
1426 int idx
= anv_get_instance_entrypoint_index(pName
);
1428 return instance
->dispatch
.entrypoints
[idx
];
1430 idx
= anv_get_device_entrypoint_index(pName
);
1432 return instance
->device_dispatch
.entrypoints
[idx
];
1437 /* With version 1+ of the loader interface the ICD should expose
1438 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1441 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1442 VkInstance instance
,
1446 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1447 VkInstance instance
,
1450 return anv_GetInstanceProcAddr(instance
, pName
);
1453 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1457 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1459 if (!device
|| !pName
)
1462 int idx
= anv_get_device_entrypoint_index(pName
);
1466 return device
->dispatch
.entrypoints
[idx
];
1470 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1471 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1472 const VkAllocationCallbacks
* pAllocator
,
1473 VkDebugReportCallbackEXT
* pCallback
)
1475 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1476 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1477 pCreateInfo
, pAllocator
, &instance
->alloc
,
1482 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1483 VkDebugReportCallbackEXT _callback
,
1484 const VkAllocationCallbacks
* pAllocator
)
1486 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1487 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1488 _callback
, pAllocator
, &instance
->alloc
);
1492 anv_DebugReportMessageEXT(VkInstance _instance
,
1493 VkDebugReportFlagsEXT flags
,
1494 VkDebugReportObjectTypeEXT objectType
,
1497 int32_t messageCode
,
1498 const char* pLayerPrefix
,
1499 const char* pMessage
)
1501 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1502 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1503 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1507 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1509 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1510 queue
->device
= device
;
1515 anv_queue_finish(struct anv_queue
*queue
)
1519 static struct anv_state
1520 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1522 struct anv_state state
;
1524 state
= anv_state_pool_alloc(pool
, size
, align
);
1525 memcpy(state
.map
, p
, size
);
1530 struct gen8_border_color
{
1535 /* Pad out to 64 bytes */
1540 anv_device_init_border_colors(struct anv_device
*device
)
1542 static const struct gen8_border_color border_colors
[] = {
1543 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1544 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1545 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1546 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1547 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1548 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1551 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1552 sizeof(border_colors
), 64,
1557 anv_device_init_trivial_batch(struct anv_device
*device
)
1559 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1561 if (device
->instance
->physicalDevice
.has_exec_async
)
1562 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1564 if (device
->instance
->physicalDevice
.use_softpin
)
1565 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_PINNED
;
1567 anv_vma_alloc(device
, &device
->trivial_batch_bo
);
1569 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1572 struct anv_batch batch
= {
1578 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1579 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1581 if (!device
->info
.has_llc
)
1582 gen_clflush_range(map
, batch
.next
- map
);
1584 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1587 VkResult
anv_EnumerateDeviceExtensionProperties(
1588 VkPhysicalDevice physicalDevice
,
1589 const char* pLayerName
,
1590 uint32_t* pPropertyCount
,
1591 VkExtensionProperties
* pProperties
)
1593 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1594 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1596 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1597 if (device
->supported_extensions
.extensions
[i
]) {
1598 vk_outarray_append(&out
, prop
) {
1599 *prop
= anv_device_extensions
[i
];
1604 return vk_outarray_status(&out
);
1608 anv_device_init_dispatch(struct anv_device
*device
)
1610 const struct anv_device_dispatch_table
*genX_table
;
1611 switch (device
->info
.gen
) {
1613 genX_table
= &gen11_device_dispatch_table
;
1616 genX_table
= &gen10_device_dispatch_table
;
1619 genX_table
= &gen9_device_dispatch_table
;
1622 genX_table
= &gen8_device_dispatch_table
;
1625 if (device
->info
.is_haswell
)
1626 genX_table
= &gen75_device_dispatch_table
;
1628 genX_table
= &gen7_device_dispatch_table
;
1631 unreachable("unsupported gen\n");
1634 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1635 /* Vulkan requires that entrypoints for extensions which have not been
1636 * enabled must not be advertised.
1638 if (!anv_device_entrypoint_is_enabled(i
, device
->instance
->app_info
.api_version
,
1639 &device
->instance
->enabled_extensions
,
1640 &device
->enabled_extensions
)) {
1641 device
->dispatch
.entrypoints
[i
] = NULL
;
1642 } else if (genX_table
->entrypoints
[i
]) {
1643 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1645 device
->dispatch
.entrypoints
[i
] =
1646 anv_device_dispatch_table
.entrypoints
[i
];
1652 vk_priority_to_gen(int priority
)
1655 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1656 return GEN_CONTEXT_LOW_PRIORITY
;
1657 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1658 return GEN_CONTEXT_MEDIUM_PRIORITY
;
1659 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1660 return GEN_CONTEXT_HIGH_PRIORITY
;
1661 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1662 return GEN_CONTEXT_REALTIME_PRIORITY
;
1664 unreachable("Invalid priority");
1669 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
1671 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
1673 if (device
->instance
->physicalDevice
.has_exec_async
)
1674 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1676 if (device
->instance
->physicalDevice
.use_softpin
)
1677 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_PINNED
;
1679 anv_vma_alloc(device
, &device
->hiz_clear_bo
);
1681 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
1684 union isl_color_value hiz_clear
= { .u32
= { 0, } };
1685 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
1687 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
1688 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
1691 VkResult
anv_CreateDevice(
1692 VkPhysicalDevice physicalDevice
,
1693 const VkDeviceCreateInfo
* pCreateInfo
,
1694 const VkAllocationCallbacks
* pAllocator
,
1697 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1699 struct anv_device
*device
;
1701 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1703 struct anv_device_extension_table enabled_extensions
= { };
1704 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1706 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1707 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1708 anv_device_extensions
[idx
].extensionName
) == 0)
1712 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1713 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1715 if (!physical_device
->supported_extensions
.extensions
[idx
])
1716 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1718 enabled_extensions
.extensions
[idx
] = true;
1721 /* Check enabled features */
1722 if (pCreateInfo
->pEnabledFeatures
) {
1723 VkPhysicalDeviceFeatures supported_features
;
1724 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1725 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1726 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1727 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1728 for (uint32_t i
= 0; i
< num_features
; i
++) {
1729 if (enabled_feature
[i
] && !supported_feature
[i
])
1730 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1734 /* Check requested queues and fail if we are requested to create any
1735 * queues with flags we don't support.
1737 assert(pCreateInfo
->queueCreateInfoCount
> 0);
1738 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1739 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
1740 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1743 /* Check if client specified queue priority. */
1744 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
1745 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
1746 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1748 VkQueueGlobalPriorityEXT priority
=
1749 queue_priority
? queue_priority
->globalPriority
:
1750 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
1752 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1754 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1756 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1758 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1759 device
->instance
= physical_device
->instance
;
1760 device
->chipset_id
= physical_device
->chipset_id
;
1761 device
->no_hw
= physical_device
->no_hw
;
1762 device
->_lost
= false;
1765 device
->alloc
= *pAllocator
;
1767 device
->alloc
= physical_device
->instance
->alloc
;
1769 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1770 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1771 if (device
->fd
== -1) {
1772 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1776 device
->context_id
= anv_gem_create_context(device
);
1777 if (device
->context_id
== -1) {
1778 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1782 if (physical_device
->use_softpin
) {
1783 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
1784 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1788 /* keep the page with address zero out of the allocator */
1789 util_vma_heap_init(&device
->vma_lo
, LOW_HEAP_MIN_ADDRESS
, LOW_HEAP_SIZE
);
1790 device
->vma_lo_available
=
1791 physical_device
->memory
.heaps
[physical_device
->memory
.heap_count
- 1].size
;
1793 /* Leave the last 4GiB out of the high vma range, so that no state base
1794 * address + size can overflow 48 bits. For more information see the
1795 * comment about Wa32bitGeneralStateOffset in anv_allocator.c
1797 util_vma_heap_init(&device
->vma_hi
, HIGH_HEAP_MIN_ADDRESS
,
1799 device
->vma_hi_available
= physical_device
->memory
.heap_count
== 1 ? 0 :
1800 physical_device
->memory
.heaps
[0].size
;
1803 /* As per spec, the driver implementation may deny requests to acquire
1804 * a priority above the default priority (MEDIUM) if the caller does not
1805 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
1808 if (physical_device
->has_context_priority
) {
1809 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
1810 I915_CONTEXT_PARAM_PRIORITY
,
1811 vk_priority_to_gen(priority
));
1812 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
1813 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
1818 device
->info
= physical_device
->info
;
1819 device
->isl_dev
= physical_device
->isl_dev
;
1821 /* On Broadwell and later, we can use batch chaining to more efficiently
1822 * implement growing command buffers. Prior to Haswell, the kernel
1823 * command parser gets in the way and we have to fall back to growing
1826 device
->can_chain_batches
= device
->info
.gen
>= 8;
1828 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1829 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1830 device
->enabled_extensions
= enabled_extensions
;
1832 anv_device_init_dispatch(device
);
1834 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1835 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1836 goto fail_context_id
;
1839 pthread_condattr_t condattr
;
1840 if (pthread_condattr_init(&condattr
) != 0) {
1841 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1844 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1845 pthread_condattr_destroy(&condattr
);
1846 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1849 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1850 pthread_condattr_destroy(&condattr
);
1851 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1854 pthread_condattr_destroy(&condattr
);
1857 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1858 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1859 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0) |
1860 (physical_device
->use_softpin
? EXEC_OBJECT_PINNED
: 0);
1862 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1864 result
= anv_bo_cache_init(&device
->bo_cache
);
1865 if (result
!= VK_SUCCESS
)
1866 goto fail_batch_bo_pool
;
1868 if (!physical_device
->use_softpin
)
1869 bo_flags
&= ~EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1871 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
1872 DYNAMIC_STATE_POOL_MIN_ADDRESS
,
1875 if (result
!= VK_SUCCESS
)
1878 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
1879 INSTRUCTION_STATE_POOL_MIN_ADDRESS
,
1882 if (result
!= VK_SUCCESS
)
1883 goto fail_dynamic_state_pool
;
1885 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
1886 SURFACE_STATE_POOL_MIN_ADDRESS
,
1889 if (result
!= VK_SUCCESS
)
1890 goto fail_instruction_state_pool
;
1892 if (physical_device
->use_softpin
) {
1893 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
1894 BINDING_TABLE_POOL_MIN_ADDRESS
,
1897 if (result
!= VK_SUCCESS
)
1898 goto fail_surface_state_pool
;
1901 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1902 if (result
!= VK_SUCCESS
)
1903 goto fail_binding_table_pool
;
1905 if (physical_device
->use_softpin
)
1906 device
->workaround_bo
.flags
|= EXEC_OBJECT_PINNED
;
1908 if (!anv_vma_alloc(device
, &device
->workaround_bo
))
1909 goto fail_workaround_bo
;
1911 anv_device_init_trivial_batch(device
);
1913 if (device
->info
.gen
>= 10)
1914 anv_device_init_hiz_clear_value_bo(device
);
1916 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1918 anv_queue_init(device
, &device
->queue
);
1920 switch (device
->info
.gen
) {
1922 if (!device
->info
.is_haswell
)
1923 result
= gen7_init_device_state(device
);
1925 result
= gen75_init_device_state(device
);
1928 result
= gen8_init_device_state(device
);
1931 result
= gen9_init_device_state(device
);
1934 result
= gen10_init_device_state(device
);
1937 result
= gen11_init_device_state(device
);
1940 /* Shouldn't get here as we don't create physical devices for any other
1942 unreachable("unhandled gen");
1944 if (result
!= VK_SUCCESS
)
1945 goto fail_workaround_bo
;
1947 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
, true);
1949 anv_device_init_blorp(device
);
1951 anv_device_init_border_colors(device
);
1953 *pDevice
= anv_device_to_handle(device
);
1958 anv_queue_finish(&device
->queue
);
1959 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1960 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1961 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1962 fail_binding_table_pool
:
1963 if (physical_device
->use_softpin
)
1964 anv_state_pool_finish(&device
->binding_table_pool
);
1965 fail_surface_state_pool
:
1966 anv_state_pool_finish(&device
->surface_state_pool
);
1967 fail_instruction_state_pool
:
1968 anv_state_pool_finish(&device
->instruction_state_pool
);
1969 fail_dynamic_state_pool
:
1970 anv_state_pool_finish(&device
->dynamic_state_pool
);
1972 anv_bo_cache_finish(&device
->bo_cache
);
1974 anv_bo_pool_finish(&device
->batch_bo_pool
);
1975 pthread_cond_destroy(&device
->queue_submit
);
1977 pthread_mutex_destroy(&device
->mutex
);
1979 anv_gem_destroy_context(device
, device
->context_id
);
1983 vk_free(&device
->alloc
, device
);
1988 void anv_DestroyDevice(
1990 const VkAllocationCallbacks
* pAllocator
)
1992 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1993 struct anv_physical_device
*physical_device
;
1998 physical_device
= &device
->instance
->physicalDevice
;
2000 anv_device_finish_blorp(device
);
2002 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
2004 anv_queue_finish(&device
->queue
);
2006 #ifdef HAVE_VALGRIND
2007 /* We only need to free these to prevent valgrind errors. The backing
2008 * BO will go away in a couple of lines so we don't actually leak.
2010 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
2013 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
2015 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
2016 anv_vma_free(device
, &device
->workaround_bo
);
2017 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
2019 anv_vma_free(device
, &device
->trivial_batch_bo
);
2020 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
2021 if (device
->info
.gen
>= 10)
2022 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
2024 if (physical_device
->use_softpin
)
2025 anv_state_pool_finish(&device
->binding_table_pool
);
2026 anv_state_pool_finish(&device
->surface_state_pool
);
2027 anv_state_pool_finish(&device
->instruction_state_pool
);
2028 anv_state_pool_finish(&device
->dynamic_state_pool
);
2030 anv_bo_cache_finish(&device
->bo_cache
);
2032 anv_bo_pool_finish(&device
->batch_bo_pool
);
2034 pthread_cond_destroy(&device
->queue_submit
);
2035 pthread_mutex_destroy(&device
->mutex
);
2037 anv_gem_destroy_context(device
, device
->context_id
);
2041 vk_free(&device
->alloc
, device
);
2044 VkResult
anv_EnumerateInstanceLayerProperties(
2045 uint32_t* pPropertyCount
,
2046 VkLayerProperties
* pProperties
)
2048 if (pProperties
== NULL
) {
2049 *pPropertyCount
= 0;
2053 /* None supported at this time */
2054 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2057 VkResult
anv_EnumerateDeviceLayerProperties(
2058 VkPhysicalDevice physicalDevice
,
2059 uint32_t* pPropertyCount
,
2060 VkLayerProperties
* pProperties
)
2062 if (pProperties
== NULL
) {
2063 *pPropertyCount
= 0;
2067 /* None supported at this time */
2068 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2071 void anv_GetDeviceQueue(
2073 uint32_t queueNodeIndex
,
2074 uint32_t queueIndex
,
2077 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2079 assert(queueIndex
== 0);
2081 *pQueue
= anv_queue_to_handle(&device
->queue
);
2084 void anv_GetDeviceQueue2(
2086 const VkDeviceQueueInfo2
* pQueueInfo
,
2089 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2091 assert(pQueueInfo
->queueIndex
== 0);
2093 if (pQueueInfo
->flags
== device
->queue
.flags
)
2094 *pQueue
= anv_queue_to_handle(&device
->queue
);
2100 _anv_device_set_lost(struct anv_device
*device
,
2101 const char *file
, int line
,
2102 const char *msg
, ...)
2107 device
->_lost
= true;
2110 err
= __vk_errorv(device
->instance
, device
,
2111 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
2112 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
2115 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
2122 anv_device_query_status(struct anv_device
*device
)
2124 /* This isn't likely as most of the callers of this function already check
2125 * for it. However, it doesn't hurt to check and it potentially lets us
2128 if (anv_device_is_lost(device
))
2129 return VK_ERROR_DEVICE_LOST
;
2131 uint32_t active
, pending
;
2132 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
2134 /* We don't know the real error. */
2135 return anv_device_set_lost(device
, "get_reset_stats failed: %m");
2139 return anv_device_set_lost(device
, "GPU hung on one of our command buffers");
2140 } else if (pending
) {
2141 return anv_device_set_lost(device
, "GPU hung with commands in-flight");
2148 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
2150 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
2151 * Other usages of the BO (such as on different hardware) will not be
2152 * flagged as "busy" by this ioctl. Use with care.
2154 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
2156 return VK_NOT_READY
;
2157 } else if (ret
== -1) {
2158 /* We don't know the real error. */
2159 return anv_device_set_lost(device
, "gem wait failed: %m");
2162 /* Query for device status after the busy call. If the BO we're checking
2163 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
2164 * client because it clearly doesn't have valid data. Yes, this most
2165 * likely means an ioctl, but we just did an ioctl to query the busy status
2166 * so it's no great loss.
2168 return anv_device_query_status(device
);
2172 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
2175 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
2176 if (ret
== -1 && errno
== ETIME
) {
2178 } else if (ret
== -1) {
2179 /* We don't know the real error. */
2180 return anv_device_set_lost(device
, "gem wait failed: %m");
2183 /* Query for device status after the wait. If the BO we're waiting on got
2184 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
2185 * because it clearly doesn't have valid data. Yes, this most likely means
2186 * an ioctl, but we just did an ioctl to wait so it's no great loss.
2188 return anv_device_query_status(device
);
2191 VkResult
anv_DeviceWaitIdle(
2194 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2195 if (anv_device_is_lost(device
))
2196 return VK_ERROR_DEVICE_LOST
;
2198 struct anv_batch batch
;
2201 batch
.start
= batch
.next
= cmds
;
2202 batch
.end
= (void *) cmds
+ sizeof(cmds
);
2204 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2205 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2207 return anv_device_submit_simple_batch(device
, &batch
);
2211 anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
)
2213 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2216 pthread_mutex_lock(&device
->vma_mutex
);
2220 if (bo
->flags
& EXEC_OBJECT_SUPPORTS_48B_ADDRESS
&&
2221 device
->vma_hi_available
>= bo
->size
) {
2222 uint64_t addr
= util_vma_heap_alloc(&device
->vma_hi
, bo
->size
, 4096);
2224 bo
->offset
= gen_canonical_address(addr
);
2225 assert(addr
== gen_48b_address(bo
->offset
));
2226 device
->vma_hi_available
-= bo
->size
;
2230 if (bo
->offset
== 0 && device
->vma_lo_available
>= bo
->size
) {
2231 uint64_t addr
= util_vma_heap_alloc(&device
->vma_lo
, bo
->size
, 4096);
2233 bo
->offset
= gen_canonical_address(addr
);
2234 assert(addr
== gen_48b_address(bo
->offset
));
2235 device
->vma_lo_available
-= bo
->size
;
2239 pthread_mutex_unlock(&device
->vma_mutex
);
2241 return bo
->offset
!= 0;
2245 anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
)
2247 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2250 const uint64_t addr_48b
= gen_48b_address(bo
->offset
);
2252 pthread_mutex_lock(&device
->vma_mutex
);
2254 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
2255 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
2256 util_vma_heap_free(&device
->vma_lo
, addr_48b
, bo
->size
);
2257 device
->vma_lo_available
+= bo
->size
;
2259 assert(addr_48b
>= HIGH_HEAP_MIN_ADDRESS
&&
2260 addr_48b
<= HIGH_HEAP_MAX_ADDRESS
);
2261 util_vma_heap_free(&device
->vma_hi
, addr_48b
, bo
->size
);
2262 device
->vma_hi_available
+= bo
->size
;
2265 pthread_mutex_unlock(&device
->vma_mutex
);
2271 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
2273 uint32_t gem_handle
= anv_gem_create(device
, size
);
2275 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2277 anv_bo_init(bo
, gem_handle
, size
);
2282 VkResult
anv_AllocateMemory(
2284 const VkMemoryAllocateInfo
* pAllocateInfo
,
2285 const VkAllocationCallbacks
* pAllocator
,
2286 VkDeviceMemory
* pMem
)
2288 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2289 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2290 struct anv_device_memory
*mem
;
2291 VkResult result
= VK_SUCCESS
;
2293 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2295 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
2296 assert(pAllocateInfo
->allocationSize
> 0);
2298 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
2299 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2301 /* FINISHME: Fail if allocation request exceeds heap size. */
2303 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2304 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2306 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2308 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
2309 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
2314 uint64_t bo_flags
= 0;
2316 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2317 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2318 bo_flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2320 const struct wsi_memory_allocate_info
*wsi_info
=
2321 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2322 if (wsi_info
&& wsi_info
->implicit_sync
) {
2323 /* We need to set the WRITE flag on window system buffers so that GEM
2324 * will know we're writing to them and synchronize uses on other rings
2325 * (eg if the display server uses the blitter ring).
2327 bo_flags
|= EXEC_OBJECT_WRITE
;
2328 } else if (pdevice
->has_exec_async
) {
2329 bo_flags
|= EXEC_OBJECT_ASYNC
;
2332 if (pdevice
->use_softpin
)
2333 bo_flags
|= EXEC_OBJECT_PINNED
;
2335 const VkExportMemoryAllocateInfo
*export_info
=
2336 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
2338 /* Check if we need to support Android HW buffer export. If so,
2339 * create AHardwareBuffer and import memory from it.
2341 bool android_export
= false;
2342 if (export_info
&& export_info
->handleTypes
&
2343 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)
2344 android_export
= true;
2346 /* Android memory import. */
2347 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahw_import_info
=
2348 vk_find_struct_const(pAllocateInfo
->pNext
,
2349 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
2351 if (ahw_import_info
) {
2352 result
= anv_import_ahw_memory(_device
, mem
, ahw_import_info
);
2353 if (result
!= VK_SUCCESS
)
2357 } else if (android_export
) {
2358 result
= anv_create_ahw_memory(_device
, mem
, pAllocateInfo
);
2359 if (result
!= VK_SUCCESS
)
2362 const struct VkImportAndroidHardwareBufferInfoANDROID import_info
= {
2365 result
= anv_import_ahw_memory(_device
, mem
, &import_info
);
2366 if (result
!= VK_SUCCESS
)
2372 const VkImportMemoryFdInfoKHR
*fd_info
=
2373 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2375 /* The Vulkan spec permits handleType to be 0, in which case the struct is
2378 if (fd_info
&& fd_info
->handleType
) {
2379 /* At the moment, we support only the below handle types. */
2380 assert(fd_info
->handleType
==
2381 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2382 fd_info
->handleType
==
2383 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2385 result
= anv_bo_cache_import(device
, &device
->bo_cache
, fd_info
->fd
,
2386 bo_flags
| ANV_BO_EXTERNAL
, &mem
->bo
);
2387 if (result
!= VK_SUCCESS
)
2390 VkDeviceSize aligned_alloc_size
=
2391 align_u64(pAllocateInfo
->allocationSize
, 4096);
2393 /* For security purposes, we reject importing the bo if it's smaller
2394 * than the requested allocation size. This prevents a malicious client
2395 * from passing a buffer to a trusted client, lying about the size, and
2396 * telling the trusted client to try and texture from an image that goes
2397 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
2398 * in the trusted client. The trusted client can protect itself against
2399 * this sort of attack but only if it can trust the buffer size.
2401 if (mem
->bo
->size
< aligned_alloc_size
) {
2402 result
= vk_errorf(device
->instance
, device
,
2403 VK_ERROR_INVALID_EXTERNAL_HANDLE
,
2404 "aligned allocationSize too large for "
2405 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
2406 "%"PRIu64
"B > %"PRIu64
"B",
2407 aligned_alloc_size
, mem
->bo
->size
);
2408 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2412 /* From the Vulkan spec:
2414 * "Importing memory from a file descriptor transfers ownership of
2415 * the file descriptor from the application to the Vulkan
2416 * implementation. The application must not perform any operations on
2417 * the file descriptor after a successful import."
2419 * If the import fails, we leave the file descriptor open.
2425 /* Regular allocate (not importing memory). */
2427 if (export_info
&& export_info
->handleTypes
)
2428 bo_flags
|= ANV_BO_EXTERNAL
;
2430 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
2431 pAllocateInfo
->allocationSize
, bo_flags
,
2433 if (result
!= VK_SUCCESS
)
2436 const VkMemoryDedicatedAllocateInfo
*dedicated_info
=
2437 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
2438 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
2439 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
2441 /* Some legacy (non-modifiers) consumers need the tiling to be set on
2442 * the BO. In this case, we have a dedicated allocation.
2444 if (image
->needs_set_tiling
) {
2445 const uint32_t i915_tiling
=
2446 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
2447 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
2448 image
->planes
[0].surface
.isl
.row_pitch_B
,
2451 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2452 return vk_errorf(device
->instance
, NULL
,
2453 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
2454 "failed to set BO tiling: %m");
2460 *pMem
= anv_device_memory_to_handle(mem
);
2465 vk_free2(&device
->alloc
, pAllocator
, mem
);
2470 VkResult
anv_GetMemoryFdKHR(
2472 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
2475 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
2476 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
2478 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2480 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2481 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2483 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
2486 VkResult
anv_GetMemoryFdPropertiesKHR(
2488 VkExternalMemoryHandleTypeFlagBits handleType
,
2490 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
2492 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2493 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2495 switch (handleType
) {
2496 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
2497 /* dma-buf can be imported as any memory type */
2498 pMemoryFdProperties
->memoryTypeBits
=
2499 (1 << pdevice
->memory
.type_count
) - 1;
2503 /* The valid usage section for this function says:
2505 * "handleType must not be one of the handle types defined as
2508 * So opaque handle types fall into the default "unsupported" case.
2510 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2514 void anv_FreeMemory(
2516 VkDeviceMemory _mem
,
2517 const VkAllocationCallbacks
* pAllocator
)
2519 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2520 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
2526 anv_UnmapMemory(_device
, _mem
);
2528 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2532 AHardwareBuffer_release(mem
->ahw
);
2535 vk_free2(&device
->alloc
, pAllocator
, mem
);
2538 VkResult
anv_MapMemory(
2540 VkDeviceMemory _memory
,
2541 VkDeviceSize offset
,
2543 VkMemoryMapFlags flags
,
2546 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2547 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2554 if (size
== VK_WHOLE_SIZE
)
2555 size
= mem
->bo
->size
- offset
;
2557 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
2559 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
2560 * assert(size != 0);
2561 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
2562 * equal to the size of the memory minus offset
2565 assert(offset
+ size
<= mem
->bo
->size
);
2567 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
2568 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
2569 * at a time is valid. We could just mmap up front and return an offset
2570 * pointer here, but that may exhaust virtual memory on 32 bit
2573 uint32_t gem_flags
= 0;
2575 if (!device
->info
.has_llc
&&
2576 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
2577 gem_flags
|= I915_MMAP_WC
;
2579 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
2580 uint64_t map_offset
= offset
& ~4095ull;
2581 assert(offset
>= map_offset
);
2582 uint64_t map_size
= (offset
+ size
) - map_offset
;
2584 /* Let's map whole pages */
2585 map_size
= align_u64(map_size
, 4096);
2587 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2588 map_offset
, map_size
, gem_flags
);
2589 if (map
== MAP_FAILED
)
2590 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2593 mem
->map_size
= map_size
;
2595 *ppData
= mem
->map
+ (offset
- map_offset
);
2600 void anv_UnmapMemory(
2602 VkDeviceMemory _memory
)
2604 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2609 anv_gem_munmap(mem
->map
, mem
->map_size
);
2616 clflush_mapped_ranges(struct anv_device
*device
,
2618 const VkMappedMemoryRange
*ranges
)
2620 for (uint32_t i
= 0; i
< count
; i
++) {
2621 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2622 if (ranges
[i
].offset
>= mem
->map_size
)
2625 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2626 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2630 VkResult
anv_FlushMappedMemoryRanges(
2632 uint32_t memoryRangeCount
,
2633 const VkMappedMemoryRange
* pMemoryRanges
)
2635 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2637 if (device
->info
.has_llc
)
2640 /* Make sure the writes we're flushing have landed. */
2641 __builtin_ia32_mfence();
2643 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2648 VkResult
anv_InvalidateMappedMemoryRanges(
2650 uint32_t memoryRangeCount
,
2651 const VkMappedMemoryRange
* pMemoryRanges
)
2653 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2655 if (device
->info
.has_llc
)
2658 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2660 /* Make sure no reads get moved up above the invalidate. */
2661 __builtin_ia32_mfence();
2666 void anv_GetBufferMemoryRequirements(
2669 VkMemoryRequirements
* pMemoryRequirements
)
2671 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2672 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2673 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2675 /* The Vulkan spec (git aaed022) says:
2677 * memoryTypeBits is a bitfield and contains one bit set for every
2678 * supported memory type for the resource. The bit `1<<i` is set if and
2679 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2680 * structure for the physical device is supported.
2682 uint32_t memory_types
= 0;
2683 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2684 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2685 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2686 memory_types
|= (1u << i
);
2689 /* Base alignment requirement of a cache line */
2690 uint32_t alignment
= 16;
2692 /* We need an alignment of 32 for pushing UBOs */
2693 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2694 alignment
= MAX2(alignment
, 32);
2696 pMemoryRequirements
->size
= buffer
->size
;
2697 pMemoryRequirements
->alignment
= alignment
;
2699 /* Storage and Uniform buffers should have their size aligned to
2700 * 32-bits to avoid boundary checks when last DWord is not complete.
2701 * This would ensure that not internal padding would be needed for
2704 if (device
->robust_buffer_access
&&
2705 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
2706 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
2707 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
2709 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2712 void anv_GetBufferMemoryRequirements2(
2714 const VkBufferMemoryRequirementsInfo2
* pInfo
,
2715 VkMemoryRequirements2
* pMemoryRequirements
)
2717 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2718 &pMemoryRequirements
->memoryRequirements
);
2720 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2721 switch (ext
->sType
) {
2722 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2723 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2724 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2725 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2730 anv_debug_ignored_stype(ext
->sType
);
2736 void anv_GetImageMemoryRequirements(
2739 VkMemoryRequirements
* pMemoryRequirements
)
2741 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2742 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2743 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2745 /* The Vulkan spec (git aaed022) says:
2747 * memoryTypeBits is a bitfield and contains one bit set for every
2748 * supported memory type for the resource. The bit `1<<i` is set if and
2749 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2750 * structure for the physical device is supported.
2752 * All types are currently supported for images.
2754 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2756 /* We must have image allocated or imported at this point. According to the
2757 * specification, external images must have been bound to memory before
2758 * calling GetImageMemoryRequirements.
2760 assert(image
->size
> 0);
2762 pMemoryRequirements
->size
= image
->size
;
2763 pMemoryRequirements
->alignment
= image
->alignment
;
2764 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2767 void anv_GetImageMemoryRequirements2(
2769 const VkImageMemoryRequirementsInfo2
* pInfo
,
2770 VkMemoryRequirements2
* pMemoryRequirements
)
2772 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2773 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2775 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2776 &pMemoryRequirements
->memoryRequirements
);
2778 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2779 switch (ext
->sType
) {
2780 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
2781 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2782 const VkImagePlaneMemoryRequirementsInfo
*plane_reqs
=
2783 (const VkImagePlaneMemoryRequirementsInfo
*) ext
;
2784 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2785 plane_reqs
->planeAspect
);
2787 assert(image
->planes
[plane
].offset
== 0);
2789 /* The Vulkan spec (git aaed022) says:
2791 * memoryTypeBits is a bitfield and contains one bit set for every
2792 * supported memory type for the resource. The bit `1<<i` is set
2793 * if and only if the memory type `i` in the
2794 * VkPhysicalDeviceMemoryProperties structure for the physical
2795 * device is supported.
2797 * All types are currently supported for images.
2799 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2800 (1ull << pdevice
->memory
.type_count
) - 1;
2802 /* We must have image allocated or imported at this point. According to the
2803 * specification, external images must have been bound to memory before
2804 * calling GetImageMemoryRequirements.
2806 assert(image
->planes
[plane
].size
> 0);
2808 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2809 pMemoryRequirements
->memoryRequirements
.alignment
=
2810 image
->planes
[plane
].alignment
;
2815 anv_debug_ignored_stype(ext
->sType
);
2820 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2821 switch (ext
->sType
) {
2822 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2823 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2824 if (image
->needs_set_tiling
|| image
->external_format
) {
2825 /* If we need to set the tiling for external consumers, we need a
2826 * dedicated allocation.
2828 * See also anv_AllocateMemory.
2830 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2831 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2833 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2834 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2840 anv_debug_ignored_stype(ext
->sType
);
2846 void anv_GetImageSparseMemoryRequirements(
2849 uint32_t* pSparseMemoryRequirementCount
,
2850 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2852 *pSparseMemoryRequirementCount
= 0;
2855 void anv_GetImageSparseMemoryRequirements2(
2857 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
2858 uint32_t* pSparseMemoryRequirementCount
,
2859 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
2861 *pSparseMemoryRequirementCount
= 0;
2864 void anv_GetDeviceMemoryCommitment(
2866 VkDeviceMemory memory
,
2867 VkDeviceSize
* pCommittedMemoryInBytes
)
2869 *pCommittedMemoryInBytes
= 0;
2873 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
2875 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2876 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2878 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
2881 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2882 buffer
->address
= (struct anv_address
) {
2884 .offset
= pBindInfo
->memoryOffset
,
2887 buffer
->address
= ANV_NULL_ADDRESS
;
2891 VkResult
anv_BindBufferMemory(
2894 VkDeviceMemory memory
,
2895 VkDeviceSize memoryOffset
)
2897 anv_bind_buffer_memory(
2898 &(VkBindBufferMemoryInfo
) {
2899 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2902 .memoryOffset
= memoryOffset
,
2908 VkResult
anv_BindBufferMemory2(
2910 uint32_t bindInfoCount
,
2911 const VkBindBufferMemoryInfo
* pBindInfos
)
2913 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2914 anv_bind_buffer_memory(&pBindInfos
[i
]);
2919 VkResult
anv_QueueBindSparse(
2921 uint32_t bindInfoCount
,
2922 const VkBindSparseInfo
* pBindInfo
,
2925 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2926 if (anv_device_is_lost(queue
->device
))
2927 return VK_ERROR_DEVICE_LOST
;
2929 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2934 VkResult
anv_CreateEvent(
2936 const VkEventCreateInfo
* pCreateInfo
,
2937 const VkAllocationCallbacks
* pAllocator
,
2940 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2941 struct anv_state state
;
2942 struct anv_event
*event
;
2944 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2946 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2949 event
->state
= state
;
2950 event
->semaphore
= VK_EVENT_RESET
;
2952 if (!device
->info
.has_llc
) {
2953 /* Make sure the writes we're flushing have landed. */
2954 __builtin_ia32_mfence();
2955 __builtin_ia32_clflush(event
);
2958 *pEvent
= anv_event_to_handle(event
);
2963 void anv_DestroyEvent(
2966 const VkAllocationCallbacks
* pAllocator
)
2968 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2969 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2974 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2977 VkResult
anv_GetEventStatus(
2981 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2982 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2984 if (anv_device_is_lost(device
))
2985 return VK_ERROR_DEVICE_LOST
;
2987 if (!device
->info
.has_llc
) {
2988 /* Invalidate read cache before reading event written by GPU. */
2989 __builtin_ia32_clflush(event
);
2990 __builtin_ia32_mfence();
2994 return event
->semaphore
;
2997 VkResult
anv_SetEvent(
3001 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3002 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3004 event
->semaphore
= VK_EVENT_SET
;
3006 if (!device
->info
.has_llc
) {
3007 /* Make sure the writes we're flushing have landed. */
3008 __builtin_ia32_mfence();
3009 __builtin_ia32_clflush(event
);
3015 VkResult
anv_ResetEvent(
3019 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3020 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3022 event
->semaphore
= VK_EVENT_RESET
;
3024 if (!device
->info
.has_llc
) {
3025 /* Make sure the writes we're flushing have landed. */
3026 __builtin_ia32_mfence();
3027 __builtin_ia32_clflush(event
);
3035 VkResult
anv_CreateBuffer(
3037 const VkBufferCreateInfo
* pCreateInfo
,
3038 const VkAllocationCallbacks
* pAllocator
,
3041 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3042 struct anv_buffer
*buffer
;
3044 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3046 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3047 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3049 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3051 buffer
->size
= pCreateInfo
->size
;
3052 buffer
->usage
= pCreateInfo
->usage
;
3053 buffer
->address
= ANV_NULL_ADDRESS
;
3055 *pBuffer
= anv_buffer_to_handle(buffer
);
3060 void anv_DestroyBuffer(
3063 const VkAllocationCallbacks
* pAllocator
)
3065 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3066 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3071 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3075 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
3076 enum isl_format format
,
3077 struct anv_address address
,
3078 uint32_t range
, uint32_t stride
)
3080 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
3081 .address
= anv_address_physical(address
),
3082 .mocs
= device
->default_mocs
,
3085 .stride_B
= stride
);
3088 void anv_DestroySampler(
3091 const VkAllocationCallbacks
* pAllocator
)
3093 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3094 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
3099 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3102 VkResult
anv_CreateFramebuffer(
3104 const VkFramebufferCreateInfo
* pCreateInfo
,
3105 const VkAllocationCallbacks
* pAllocator
,
3106 VkFramebuffer
* pFramebuffer
)
3108 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3109 struct anv_framebuffer
*framebuffer
;
3111 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3113 size_t size
= sizeof(*framebuffer
) +
3114 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
3115 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3116 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3117 if (framebuffer
== NULL
)
3118 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3120 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3121 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3122 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3123 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
3126 framebuffer
->width
= pCreateInfo
->width
;
3127 framebuffer
->height
= pCreateInfo
->height
;
3128 framebuffer
->layers
= pCreateInfo
->layers
;
3130 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
3135 void anv_DestroyFramebuffer(
3138 const VkAllocationCallbacks
* pAllocator
)
3140 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3141 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
3146 vk_free2(&device
->alloc
, pAllocator
, fb
);
3149 static const VkTimeDomainEXT anv_time_domains
[] = {
3150 VK_TIME_DOMAIN_DEVICE_EXT
,
3151 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
3152 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
3155 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
3156 VkPhysicalDevice physicalDevice
,
3157 uint32_t *pTimeDomainCount
,
3158 VkTimeDomainEXT
*pTimeDomains
)
3161 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
3163 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
3164 vk_outarray_append(&out
, i
) {
3165 *i
= anv_time_domains
[d
];
3169 return vk_outarray_status(&out
);
3173 anv_clock_gettime(clockid_t clock_id
)
3175 struct timespec current
;
3178 ret
= clock_gettime(clock_id
, ¤t
);
3179 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
3180 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3184 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
3187 #define TIMESTAMP 0x2358
3189 VkResult
anv_GetCalibratedTimestampsEXT(
3191 uint32_t timestampCount
,
3192 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
3193 uint64_t *pTimestamps
,
3194 uint64_t *pMaxDeviation
)
3196 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3197 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
3200 uint64_t begin
, end
;
3201 uint64_t max_clock_period
= 0;
3203 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3205 for (d
= 0; d
< timestampCount
; d
++) {
3206 switch (pTimestampInfos
[d
].timeDomain
) {
3207 case VK_TIME_DOMAIN_DEVICE_EXT
:
3208 ret
= anv_gem_reg_read(device
, TIMESTAMP
| 1,
3212 return anv_device_set_lost(device
, "Failed to read the TIMESTAMP "
3215 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
3216 max_clock_period
= MAX2(max_clock_period
, device_period
);
3218 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
3219 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
3220 max_clock_period
= MAX2(max_clock_period
, 1);
3223 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
3224 pTimestamps
[d
] = begin
;
3232 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3235 * The maximum deviation is the sum of the interval over which we
3236 * perform the sampling and the maximum period of any sampled
3237 * clock. That's because the maximum skew between any two sampled
3238 * clock edges is when the sampled clock with the largest period is
3239 * sampled at the end of that period but right at the beginning of the
3240 * sampling interval and some other clock is sampled right at the
3241 * begining of its sampling period and right at the end of the
3242 * sampling interval. Let's assume the GPU has the longest clock
3243 * period and that the application is sampling GPU and monotonic:
3246 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
3247 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3251 * GPU -----_____-----_____-----_____-----_____
3254 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
3255 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3257 * Interval <----------------->
3258 * Deviation <-------------------------->
3262 * m = read(monotonic) 2
3265 * We round the sample interval up by one tick to cover sampling error
3266 * in the interval clock
3269 uint64_t sample_interval
= end
- begin
+ 1;
3271 *pMaxDeviation
= sample_interval
+ max_clock_period
;
3276 /* vk_icd.h does not declare this function, so we declare it here to
3277 * suppress Wmissing-prototypes.
3279 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3280 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
3282 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3283 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
3285 /* For the full details on loader interface versioning, see
3286 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3287 * What follows is a condensed summary, to help you navigate the large and
3288 * confusing official doc.
3290 * - Loader interface v0 is incompatible with later versions. We don't
3293 * - In loader interface v1:
3294 * - The first ICD entrypoint called by the loader is
3295 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3297 * - The ICD must statically expose no other Vulkan symbol unless it is
3298 * linked with -Bsymbolic.
3299 * - Each dispatchable Vulkan handle created by the ICD must be
3300 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3301 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3302 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3303 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3304 * such loader-managed surfaces.
3306 * - Loader interface v2 differs from v1 in:
3307 * - The first ICD entrypoint called by the loader is
3308 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3309 * statically expose this entrypoint.
3311 * - Loader interface v3 differs from v2 in:
3312 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3313 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3314 * because the loader no longer does so.
3316 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);