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/mesa-sha1.h"
40 #include "common/gen_defines.h"
42 #include "genxml/gen7_pack.h"
45 compiler_debug_log(void *data
, const char *fmt
, ...)
49 compiler_perf_log(void *data
, const char *fmt
, ...)
54 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
55 intel_logd_v(fmt
, args
);
61 anv_compute_heap_size(int fd
, uint64_t gtt_size
, uint64_t *heap_size
)
63 /* Query the total ram from the system */
67 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
69 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
70 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
72 uint64_t available_ram
;
73 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
74 available_ram
= total_ram
/ 2;
76 available_ram
= total_ram
* 3 / 4;
78 /* We also want to leave some padding for things we allocate in the driver,
79 * so don't go over 3/4 of the GTT either.
81 uint64_t available_gtt
= gtt_size
* 3 / 4;
83 *heap_size
= MIN2(available_ram
, available_gtt
);
89 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
92 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
94 /* If, for whatever reason, we can't actually get the GTT size from the
95 * kernel (too old?) fall back to the aperture size.
97 anv_perf_warn(NULL
, NULL
,
98 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
100 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
101 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
102 "failed to get aperture size: %m");
106 device
->supports_48bit_addresses
= (device
->info
.gen
>= 8) &&
107 gtt_size
> (4ULL << 30 /* GiB */);
109 uint64_t heap_size
= 0;
110 VkResult result
= anv_compute_heap_size(fd
, gtt_size
, &heap_size
);
111 if (result
!= VK_SUCCESS
)
114 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
115 /* When running with an overridden PCI ID, we may get a GTT size from
116 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
117 * address support can still fail. Just clamp the address space size to
118 * 2 GiB if we don't have 48-bit support.
120 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
121 "not support for 48-bit addresses",
123 heap_size
= 2ull << 30;
126 if (heap_size
<= 3ull * (1ull << 30)) {
127 /* In this case, everything fits nicely into the 32-bit address space,
128 * so there's no need for supporting 48bit addresses on client-allocated
131 device
->memory
.heap_count
= 1;
132 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
134 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
135 .supports_48bit_addresses
= false,
138 /* Not everything will fit nicely into a 32-bit address space. In this
139 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
140 * larger 48-bit heap. If we're in this case, then we have a total heap
141 * size larger than 3GiB which most likely means they have 8 GiB of
142 * video memory and so carving off 1 GiB for the 32-bit heap should be
145 const uint64_t heap_size_32bit
= 1ull << 30;
146 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
148 assert(device
->supports_48bit_addresses
);
150 device
->memory
.heap_count
= 2;
151 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
152 .size
= heap_size_48bit
,
153 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
154 .supports_48bit_addresses
= true,
156 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
157 .size
= heap_size_32bit
,
158 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
159 .supports_48bit_addresses
= false,
163 uint32_t type_count
= 0;
164 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
165 uint32_t valid_buffer_usage
= ~0;
167 /* There appears to be a hardware issue in the VF cache where it only
168 * considers the bottom 32 bits of memory addresses. If you happen to
169 * have two vertex buffers which get placed exactly 4 GiB apart and use
170 * them in back-to-back draw calls, you can get collisions. In order to
171 * solve this problem, we require vertex and index buffers be bound to
172 * memory allocated out of the 32-bit heap.
174 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
175 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
176 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
179 if (device
->info
.has_llc
) {
180 /* Big core GPUs share LLC with the CPU and thus one memory type can be
181 * both cached and coherent at the same time.
183 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
184 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
185 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
186 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
187 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
189 .valid_buffer_usage
= valid_buffer_usage
,
192 /* The spec requires that we expose a host-visible, coherent memory
193 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
194 * to give the application a choice between cached, but not coherent and
195 * coherent but uncached (WC though).
197 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
198 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
199 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
200 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
202 .valid_buffer_usage
= valid_buffer_usage
,
204 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
205 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
206 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
207 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
209 .valid_buffer_usage
= valid_buffer_usage
,
213 device
->memory
.type_count
= type_count
;
219 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
221 const struct build_id_note
*note
=
222 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
224 return vk_errorf(device
->instance
, device
,
225 VK_ERROR_INITIALIZATION_FAILED
,
226 "Failed to find build-id");
229 unsigned build_id_len
= build_id_length(note
);
230 if (build_id_len
< 20) {
231 return vk_errorf(device
->instance
, device
,
232 VK_ERROR_INITIALIZATION_FAILED
,
233 "build-id too short. It needs to be a SHA");
236 struct mesa_sha1 sha1_ctx
;
238 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
240 /* The pipeline cache UUID is used for determining when a pipeline cache is
241 * invalid. It needs both a driver build and the PCI ID of the device.
243 _mesa_sha1_init(&sha1_ctx
);
244 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
245 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
246 sizeof(device
->chipset_id
));
247 _mesa_sha1_final(&sha1_ctx
, sha1
);
248 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
250 /* The driver UUID is used for determining sharability of images and memory
251 * between two Vulkan instances in separate processes. People who want to
252 * share memory need to also check the device UUID (below) so all this
253 * needs to be is the build-id.
255 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
257 /* The device UUID uniquely identifies the given device within the machine.
258 * Since we never have more than one device, this doesn't need to be a real
259 * UUID. However, on the off-chance that someone tries to use this to
260 * cache pre-tiled images or something of the like, we use the PCI ID and
261 * some bits of ISL info to ensure that this is safe.
263 _mesa_sha1_init(&sha1_ctx
);
264 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
265 sizeof(device
->chipset_id
));
266 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
267 sizeof(device
->isl_dev
.has_bit6_swizzling
));
268 _mesa_sha1_final(&sha1_ctx
, sha1
);
269 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
275 anv_physical_device_init(struct anv_physical_device
*device
,
276 struct anv_instance
*instance
,
282 brw_process_intel_debug_variable();
284 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
286 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
288 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
289 device
->instance
= instance
;
291 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
292 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
294 device
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
296 const int pci_id_override
= gen_get_pci_device_id_override();
297 if (pci_id_override
< 0) {
298 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
299 if (!device
->chipset_id
) {
300 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
304 device
->chipset_id
= pci_id_override
;
305 device
->no_hw
= true;
308 device
->name
= gen_get_device_name(device
->chipset_id
);
309 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
310 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
314 if (device
->info
.is_haswell
) {
315 intel_logw("Haswell Vulkan support is incomplete");
316 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
317 intel_logw("Ivy Bridge Vulkan support is incomplete");
318 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
319 intel_logw("Bay Trail Vulkan support is incomplete");
320 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 10) {
321 /* Gen8-10 fully supported */
322 } else if (device
->info
.gen
== 11) {
323 intel_logw("Vulkan is not yet fully supported on gen11.");
325 result
= vk_errorf(device
->instance
, device
,
326 VK_ERROR_INCOMPATIBLE_DRIVER
,
327 "Vulkan not yet supported on %s", device
->name
);
331 device
->cmd_parser_version
= -1;
332 if (device
->info
.gen
== 7) {
333 device
->cmd_parser_version
=
334 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
335 if (device
->cmd_parser_version
== -1) {
336 result
= vk_errorf(device
->instance
, device
,
337 VK_ERROR_INITIALIZATION_FAILED
,
338 "failed to get command parser version");
343 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
344 result
= vk_errorf(device
->instance
, device
,
345 VK_ERROR_INITIALIZATION_FAILED
,
346 "kernel missing gem wait");
350 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
351 result
= vk_errorf(device
->instance
, device
,
352 VK_ERROR_INITIALIZATION_FAILED
,
353 "kernel missing execbuf2");
357 if (!device
->info
.has_llc
&&
358 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
359 result
= vk_errorf(device
->instance
, device
,
360 VK_ERROR_INITIALIZATION_FAILED
,
361 "kernel missing wc mmap");
365 result
= anv_physical_device_init_heaps(device
, fd
);
366 if (result
!= VK_SUCCESS
)
369 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
370 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
371 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
372 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
373 device
->has_syncobj_wait
= device
->has_syncobj
&&
374 anv_gem_supports_syncobj_wait(fd
);
375 device
->has_context_priority
= anv_gem_has_context_priority(fd
);
377 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
379 /* Starting with Gen10, the timestamp frequency of the command streamer may
380 * vary from one part to another. We can query the value from the kernel.
382 if (device
->info
.gen
>= 10) {
383 int timestamp_frequency
=
384 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
386 if (timestamp_frequency
< 0)
387 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
389 device
->info
.timestamp_frequency
= timestamp_frequency
;
392 /* GENs prior to 8 do not support EU/Subslice info */
393 if (device
->info
.gen
>= 8) {
394 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
395 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
397 /* Without this information, we cannot get the right Braswell
398 * brandstrings, and we have to use conservative numbers for GPGPU on
399 * many platforms, but otherwise, things will just work.
401 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
402 intel_logw("Kernel 4.1 required to properly query GPU properties");
404 } else if (device
->info
.gen
== 7) {
405 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
408 if (device
->info
.is_cherryview
&&
409 device
->subslice_total
> 0 && device
->eu_total
> 0) {
410 /* Logical CS threads = EUs per subslice * num threads per EU */
411 uint32_t max_cs_threads
=
412 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
414 /* Fuse configurations may give more threads than expected, never less. */
415 if (max_cs_threads
> device
->info
.max_cs_threads
)
416 device
->info
.max_cs_threads
= max_cs_threads
;
419 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
420 if (device
->compiler
== NULL
) {
421 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
424 device
->compiler
->shader_debug_log
= compiler_debug_log
;
425 device
->compiler
->shader_perf_log
= compiler_perf_log
;
426 device
->compiler
->supports_pull_constants
= false;
427 device
->compiler
->constant_buffer_0_is_relative
= true;
429 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
431 result
= anv_physical_device_init_uuids(device
);
432 if (result
!= VK_SUCCESS
)
435 result
= anv_init_wsi(device
);
436 if (result
!= VK_SUCCESS
) {
437 ralloc_free(device
->compiler
);
441 anv_physical_device_get_supported_extensions(device
,
442 &device
->supported_extensions
);
444 device
->local_fd
= fd
;
453 anv_physical_device_finish(struct anv_physical_device
*device
)
455 anv_finish_wsi(device
);
456 ralloc_free(device
->compiler
);
457 close(device
->local_fd
);
461 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
462 VkSystemAllocationScope allocationScope
)
468 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
469 size_t align
, VkSystemAllocationScope allocationScope
)
471 return realloc(pOriginal
, size
);
475 default_free_func(void *pUserData
, void *pMemory
)
480 static const VkAllocationCallbacks default_alloc
= {
482 .pfnAllocation
= default_alloc_func
,
483 .pfnReallocation
= default_realloc_func
,
484 .pfnFree
= default_free_func
,
487 VkResult
anv_EnumerateInstanceExtensionProperties(
488 const char* pLayerName
,
489 uint32_t* pPropertyCount
,
490 VkExtensionProperties
* pProperties
)
492 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
494 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
495 if (anv_instance_extensions_supported
.extensions
[i
]) {
496 vk_outarray_append(&out
, prop
) {
497 *prop
= anv_instance_extensions
[i
];
502 return vk_outarray_status(&out
);
505 VkResult
anv_CreateInstance(
506 const VkInstanceCreateInfo
* pCreateInfo
,
507 const VkAllocationCallbacks
* pAllocator
,
508 VkInstance
* pInstance
)
510 struct anv_instance
*instance
;
513 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
515 struct anv_instance_extension_table enabled_extensions
= {};
516 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
518 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
519 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
520 anv_instance_extensions
[idx
].extensionName
) == 0)
524 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
525 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
527 if (!anv_instance_extensions_supported
.extensions
[idx
])
528 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
530 enabled_extensions
.extensions
[idx
] = true;
533 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
534 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
536 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
538 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
541 instance
->alloc
= *pAllocator
;
543 instance
->alloc
= default_alloc
;
545 if (pCreateInfo
->pApplicationInfo
&&
546 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
547 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
549 anv_EnumerateInstanceVersion(&instance
->apiVersion
);
552 instance
->enabled_extensions
= enabled_extensions
;
554 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
555 /* Vulkan requires that entrypoints for extensions which have not been
556 * enabled must not be advertised.
558 if (!anv_entrypoint_is_enabled(i
, instance
->apiVersion
,
559 &instance
->enabled_extensions
, NULL
)) {
560 instance
->dispatch
.entrypoints
[i
] = NULL
;
561 } else if (anv_dispatch_table
.entrypoints
[i
] != NULL
) {
562 instance
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
564 instance
->dispatch
.entrypoints
[i
] =
565 anv_tramp_dispatch_table
.entrypoints
[i
];
569 instance
->physicalDeviceCount
= -1;
571 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
572 if (result
!= VK_SUCCESS
) {
573 vk_free2(&default_alloc
, pAllocator
, instance
);
574 return vk_error(result
);
579 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
581 *pInstance
= anv_instance_to_handle(instance
);
586 void anv_DestroyInstance(
587 VkInstance _instance
,
588 const VkAllocationCallbacks
* pAllocator
)
590 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
595 if (instance
->physicalDeviceCount
> 0) {
596 /* We support at most one physical device. */
597 assert(instance
->physicalDeviceCount
== 1);
598 anv_physical_device_finish(&instance
->physicalDevice
);
601 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
603 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
607 vk_free(&instance
->alloc
, instance
);
611 anv_enumerate_devices(struct anv_instance
*instance
)
613 /* TODO: Check for more devices ? */
614 drmDevicePtr devices
[8];
615 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
618 instance
->physicalDeviceCount
= 0;
620 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
622 return VK_ERROR_INCOMPATIBLE_DRIVER
;
624 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
625 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
626 devices
[i
]->bustype
== DRM_BUS_PCI
&&
627 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
629 result
= anv_physical_device_init(&instance
->physicalDevice
,
631 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
632 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
636 drmFreeDevices(devices
, max_devices
);
638 if (result
== VK_SUCCESS
)
639 instance
->physicalDeviceCount
= 1;
645 anv_instance_ensure_physical_device(struct anv_instance
*instance
)
647 if (instance
->physicalDeviceCount
< 0) {
648 VkResult result
= anv_enumerate_devices(instance
);
649 if (result
!= VK_SUCCESS
&&
650 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
657 VkResult
anv_EnumeratePhysicalDevices(
658 VkInstance _instance
,
659 uint32_t* pPhysicalDeviceCount
,
660 VkPhysicalDevice
* pPhysicalDevices
)
662 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
663 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
665 VkResult result
= anv_instance_ensure_physical_device(instance
);
666 if (result
!= VK_SUCCESS
)
669 if (instance
->physicalDeviceCount
== 0)
672 assert(instance
->physicalDeviceCount
== 1);
673 vk_outarray_append(&out
, i
) {
674 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
677 return vk_outarray_status(&out
);
680 VkResult
anv_EnumeratePhysicalDeviceGroups(
681 VkInstance _instance
,
682 uint32_t* pPhysicalDeviceGroupCount
,
683 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
685 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
686 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
687 pPhysicalDeviceGroupCount
);
689 VkResult result
= anv_instance_ensure_physical_device(instance
);
690 if (result
!= VK_SUCCESS
)
693 if (instance
->physicalDeviceCount
== 0)
696 assert(instance
->physicalDeviceCount
== 1);
698 vk_outarray_append(&out
, p
) {
699 p
->physicalDeviceCount
= 1;
700 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
701 p
->physicalDevices
[0] =
702 anv_physical_device_to_handle(&instance
->physicalDevice
);
703 p
->subsetAllocation
= VK_FALSE
;
705 vk_foreach_struct(ext
, p
->pNext
)
706 anv_debug_ignored_stype(ext
->sType
);
709 return vk_outarray_status(&out
);
712 void anv_GetPhysicalDeviceFeatures(
713 VkPhysicalDevice physicalDevice
,
714 VkPhysicalDeviceFeatures
* pFeatures
)
716 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
718 *pFeatures
= (VkPhysicalDeviceFeatures
) {
719 .robustBufferAccess
= true,
720 .fullDrawIndexUint32
= true,
721 .imageCubeArray
= true,
722 .independentBlend
= true,
723 .geometryShader
= true,
724 .tessellationShader
= true,
725 .sampleRateShading
= true,
726 .dualSrcBlend
= true,
728 .multiDrawIndirect
= true,
729 .drawIndirectFirstInstance
= true,
731 .depthBiasClamp
= true,
732 .fillModeNonSolid
= true,
733 .depthBounds
= false,
737 .multiViewport
= true,
738 .samplerAnisotropy
= true,
739 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
740 pdevice
->info
.is_baytrail
,
741 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
742 .textureCompressionBC
= true,
743 .occlusionQueryPrecise
= true,
744 .pipelineStatisticsQuery
= true,
745 .fragmentStoresAndAtomics
= true,
746 .shaderTessellationAndGeometryPointSize
= true,
747 .shaderImageGatherExtended
= true,
748 .shaderStorageImageExtendedFormats
= true,
749 .shaderStorageImageMultisample
= false,
750 .shaderStorageImageReadWithoutFormat
= false,
751 .shaderStorageImageWriteWithoutFormat
= true,
752 .shaderUniformBufferArrayDynamicIndexing
= true,
753 .shaderSampledImageArrayDynamicIndexing
= true,
754 .shaderStorageBufferArrayDynamicIndexing
= true,
755 .shaderStorageImageArrayDynamicIndexing
= true,
756 .shaderClipDistance
= true,
757 .shaderCullDistance
= true,
758 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
759 pdevice
->info
.has_64bit_types
,
760 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
761 pdevice
->info
.has_64bit_types
,
762 .shaderInt16
= pdevice
->info
.gen
>= 8,
763 .shaderResourceMinLod
= false,
764 .variableMultisampleRate
= true,
765 .inheritedQueries
= true,
768 /* We can't do image stores in vec4 shaders */
769 pFeatures
->vertexPipelineStoresAndAtomics
=
770 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
771 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
774 void anv_GetPhysicalDeviceFeatures2(
775 VkPhysicalDevice physicalDevice
,
776 VkPhysicalDeviceFeatures2
* pFeatures
)
778 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
780 vk_foreach_struct(ext
, pFeatures
->pNext
) {
781 switch (ext
->sType
) {
782 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
783 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
784 features
->protectedMemory
= VK_FALSE
;
788 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
789 VkPhysicalDeviceMultiviewFeatures
*features
=
790 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
791 features
->multiview
= true;
792 features
->multiviewGeometryShader
= true;
793 features
->multiviewTessellationShader
= true;
797 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
798 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
799 features
->variablePointersStorageBuffer
= true;
800 features
->variablePointers
= true;
804 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
805 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
806 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
807 features
->samplerYcbcrConversion
= true;
811 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
812 VkPhysicalDeviceShaderDrawParameterFeatures
*features
= (void *)ext
;
813 features
->shaderDrawParameters
= true;
817 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
: {
818 VkPhysicalDevice16BitStorageFeaturesKHR
*features
=
819 (VkPhysicalDevice16BitStorageFeaturesKHR
*)ext
;
820 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
822 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
823 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
824 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
825 features
->storageInputOutput16
= false;
830 anv_debug_ignored_stype(ext
->sType
);
836 void anv_GetPhysicalDeviceProperties(
837 VkPhysicalDevice physicalDevice
,
838 VkPhysicalDeviceProperties
* pProperties
)
840 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
841 const struct gen_device_info
*devinfo
= &pdevice
->info
;
843 /* See assertions made when programming the buffer surface state. */
844 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
845 (1ul << 30) : (1ul << 27);
847 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
850 VkSampleCountFlags sample_counts
=
851 isl_device_get_sample_counts(&pdevice
->isl_dev
);
853 VkPhysicalDeviceLimits limits
= {
854 .maxImageDimension1D
= (1 << 14),
855 .maxImageDimension2D
= (1 << 14),
856 .maxImageDimension3D
= (1 << 11),
857 .maxImageDimensionCube
= (1 << 14),
858 .maxImageArrayLayers
= (1 << 11),
859 .maxTexelBufferElements
= 128 * 1024 * 1024,
860 .maxUniformBufferRange
= (1ul << 27),
861 .maxStorageBufferRange
= max_raw_buffer_sz
,
862 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
863 .maxMemoryAllocationCount
= UINT32_MAX
,
864 .maxSamplerAllocationCount
= 64 * 1024,
865 .bufferImageGranularity
= 64, /* A cache line */
866 .sparseAddressSpaceSize
= 0,
867 .maxBoundDescriptorSets
= MAX_SETS
,
868 .maxPerStageDescriptorSamplers
= max_samplers
,
869 .maxPerStageDescriptorUniformBuffers
= 64,
870 .maxPerStageDescriptorStorageBuffers
= 64,
871 .maxPerStageDescriptorSampledImages
= max_samplers
,
872 .maxPerStageDescriptorStorageImages
= 64,
873 .maxPerStageDescriptorInputAttachments
= 64,
874 .maxPerStageResources
= 250,
875 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
876 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
877 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
878 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
879 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
880 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
881 .maxDescriptorSetStorageImages
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
882 .maxDescriptorSetInputAttachments
= 256,
883 .maxVertexInputAttributes
= MAX_VBS
,
884 .maxVertexInputBindings
= MAX_VBS
,
885 .maxVertexInputAttributeOffset
= 2047,
886 .maxVertexInputBindingStride
= 2048,
887 .maxVertexOutputComponents
= 128,
888 .maxTessellationGenerationLevel
= 64,
889 .maxTessellationPatchSize
= 32,
890 .maxTessellationControlPerVertexInputComponents
= 128,
891 .maxTessellationControlPerVertexOutputComponents
= 128,
892 .maxTessellationControlPerPatchOutputComponents
= 128,
893 .maxTessellationControlTotalOutputComponents
= 2048,
894 .maxTessellationEvaluationInputComponents
= 128,
895 .maxTessellationEvaluationOutputComponents
= 128,
896 .maxGeometryShaderInvocations
= 32,
897 .maxGeometryInputComponents
= 64,
898 .maxGeometryOutputComponents
= 128,
899 .maxGeometryOutputVertices
= 256,
900 .maxGeometryTotalOutputComponents
= 1024,
901 .maxFragmentInputComponents
= 128,
902 .maxFragmentOutputAttachments
= 8,
903 .maxFragmentDualSrcAttachments
= 1,
904 .maxFragmentCombinedOutputResources
= 8,
905 .maxComputeSharedMemorySize
= 32768,
906 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
907 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
908 .maxComputeWorkGroupSize
= {
909 16 * devinfo
->max_cs_threads
,
910 16 * devinfo
->max_cs_threads
,
911 16 * devinfo
->max_cs_threads
,
913 .subPixelPrecisionBits
= 4 /* FIXME */,
914 .subTexelPrecisionBits
= 4 /* FIXME */,
915 .mipmapPrecisionBits
= 4 /* FIXME */,
916 .maxDrawIndexedIndexValue
= UINT32_MAX
,
917 .maxDrawIndirectCount
= UINT32_MAX
,
918 .maxSamplerLodBias
= 16,
919 .maxSamplerAnisotropy
= 16,
920 .maxViewports
= MAX_VIEWPORTS
,
921 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
922 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
923 .viewportSubPixelBits
= 13, /* We take a float? */
924 .minMemoryMapAlignment
= 4096, /* A page */
925 .minTexelBufferOffsetAlignment
= 1,
926 /* We need 16 for UBO block reads to work and 32 for push UBOs */
927 .minUniformBufferOffsetAlignment
= 32,
928 .minStorageBufferOffsetAlignment
= 4,
929 .minTexelOffset
= -8,
931 .minTexelGatherOffset
= -32,
932 .maxTexelGatherOffset
= 31,
933 .minInterpolationOffset
= -0.5,
934 .maxInterpolationOffset
= 0.4375,
935 .subPixelInterpolationOffsetBits
= 4,
936 .maxFramebufferWidth
= (1 << 14),
937 .maxFramebufferHeight
= (1 << 14),
938 .maxFramebufferLayers
= (1 << 11),
939 .framebufferColorSampleCounts
= sample_counts
,
940 .framebufferDepthSampleCounts
= sample_counts
,
941 .framebufferStencilSampleCounts
= sample_counts
,
942 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
943 .maxColorAttachments
= MAX_RTS
,
944 .sampledImageColorSampleCounts
= sample_counts
,
945 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
946 .sampledImageDepthSampleCounts
= sample_counts
,
947 .sampledImageStencilSampleCounts
= sample_counts
,
948 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
949 .maxSampleMaskWords
= 1,
950 .timestampComputeAndGraphics
= false,
951 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
952 .maxClipDistances
= 8,
953 .maxCullDistances
= 8,
954 .maxCombinedClipAndCullDistances
= 8,
955 .discreteQueuePriorities
= 1,
956 .pointSizeRange
= { 0.125, 255.875 },
957 .lineWidthRange
= { 0.0, 7.9921875 },
958 .pointSizeGranularity
= (1.0 / 8.0),
959 .lineWidthGranularity
= (1.0 / 128.0),
960 .strictLines
= false, /* FINISHME */
961 .standardSampleLocations
= true,
962 .optimalBufferCopyOffsetAlignment
= 128,
963 .optimalBufferCopyRowPitchAlignment
= 128,
964 .nonCoherentAtomSize
= 64,
967 *pProperties
= (VkPhysicalDeviceProperties
) {
968 .apiVersion
= anv_physical_device_api_version(pdevice
),
969 .driverVersion
= vk_get_driver_version(),
971 .deviceID
= pdevice
->chipset_id
,
972 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
974 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
977 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
978 "%s", pdevice
->name
);
979 memcpy(pProperties
->pipelineCacheUUID
,
980 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
983 void anv_GetPhysicalDeviceProperties2(
984 VkPhysicalDevice physicalDevice
,
985 VkPhysicalDeviceProperties2
* pProperties
)
987 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
989 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
991 vk_foreach_struct(ext
, pProperties
->pNext
) {
992 switch (ext
->sType
) {
993 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
994 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
995 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
997 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1001 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1002 VkPhysicalDeviceIDProperties
*id_props
=
1003 (VkPhysicalDeviceIDProperties
*)ext
;
1004 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1005 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1006 /* The LUID is for Windows. */
1007 id_props
->deviceLUIDValid
= false;
1011 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1012 VkPhysicalDeviceMaintenance3Properties
*props
=
1013 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1014 /* This value doesn't matter for us today as our per-stage
1015 * descriptors are the real limit.
1017 props
->maxPerSetDescriptors
= 1024;
1018 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1022 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1023 VkPhysicalDeviceMultiviewProperties
*properties
=
1024 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1025 properties
->maxMultiviewViewCount
= 16;
1026 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1031 VkPhysicalDevicePointClippingProperties
*properties
=
1032 (VkPhysicalDevicePointClippingProperties
*) ext
;
1033 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1034 anv_finishme("Implement pop-free point clipping");
1038 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1039 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1041 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1043 VkShaderStageFlags scalar_stages
= 0;
1044 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1045 if (pdevice
->compiler
->scalar_stage
[stage
])
1046 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1048 properties
->supportedStages
= scalar_stages
;
1050 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1051 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1052 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1053 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1054 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1055 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1056 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1057 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1058 properties
->quadOperationsInAllStages
= VK_TRUE
;
1063 anv_debug_ignored_stype(ext
->sType
);
1069 /* We support exactly one queue family. */
1070 static const VkQueueFamilyProperties
1071 anv_queue_family_properties
= {
1072 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1073 VK_QUEUE_COMPUTE_BIT
|
1074 VK_QUEUE_TRANSFER_BIT
,
1076 .timestampValidBits
= 36, /* XXX: Real value here */
1077 .minImageTransferGranularity
= { 1, 1, 1 },
1080 void anv_GetPhysicalDeviceQueueFamilyProperties(
1081 VkPhysicalDevice physicalDevice
,
1083 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1085 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1087 vk_outarray_append(&out
, p
) {
1088 *p
= anv_queue_family_properties
;
1092 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1093 VkPhysicalDevice physicalDevice
,
1094 uint32_t* pQueueFamilyPropertyCount
,
1095 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1098 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1100 vk_outarray_append(&out
, p
) {
1101 p
->queueFamilyProperties
= anv_queue_family_properties
;
1103 vk_foreach_struct(s
, p
->pNext
) {
1104 anv_debug_ignored_stype(s
->sType
);
1109 void anv_GetPhysicalDeviceMemoryProperties(
1110 VkPhysicalDevice physicalDevice
,
1111 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1113 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1115 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1116 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1117 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1118 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1119 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1123 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1124 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1125 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1126 .size
= physical_device
->memory
.heaps
[i
].size
,
1127 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1132 void anv_GetPhysicalDeviceMemoryProperties2(
1133 VkPhysicalDevice physicalDevice
,
1134 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1136 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1137 &pMemoryProperties
->memoryProperties
);
1139 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1140 switch (ext
->sType
) {
1142 anv_debug_ignored_stype(ext
->sType
);
1149 anv_GetDeviceGroupPeerMemoryFeatures(
1152 uint32_t localDeviceIndex
,
1153 uint32_t remoteDeviceIndex
,
1154 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1156 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1157 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1158 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1159 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1160 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1163 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1164 VkInstance _instance
,
1167 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1169 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1170 * when we have to return valid function pointers, NULL, or it's left
1171 * undefined. See the table for exact details.
1176 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1177 if (strcmp(pName, "vk" #entrypoint) == 0) \
1178 return (PFN_vkVoidFunction)anv_##entrypoint
1180 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1181 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1182 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1183 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1185 #undef LOOKUP_ANV_ENTRYPOINT
1187 if (instance
== NULL
)
1190 int idx
= anv_get_entrypoint_index(pName
);
1194 return instance
->dispatch
.entrypoints
[idx
];
1197 /* With version 1+ of the loader interface the ICD should expose
1198 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1201 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1202 VkInstance instance
,
1206 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1207 VkInstance instance
,
1210 return anv_GetInstanceProcAddr(instance
, pName
);
1213 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1217 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1219 if (!device
|| !pName
)
1222 int idx
= anv_get_entrypoint_index(pName
);
1226 return device
->dispatch
.entrypoints
[idx
];
1230 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1231 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1232 const VkAllocationCallbacks
* pAllocator
,
1233 VkDebugReportCallbackEXT
* pCallback
)
1235 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1236 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1237 pCreateInfo
, pAllocator
, &instance
->alloc
,
1242 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1243 VkDebugReportCallbackEXT _callback
,
1244 const VkAllocationCallbacks
* pAllocator
)
1246 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1247 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1248 _callback
, pAllocator
, &instance
->alloc
);
1252 anv_DebugReportMessageEXT(VkInstance _instance
,
1253 VkDebugReportFlagsEXT flags
,
1254 VkDebugReportObjectTypeEXT objectType
,
1257 int32_t messageCode
,
1258 const char* pLayerPrefix
,
1259 const char* pMessage
)
1261 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1262 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1263 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1267 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1269 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1270 queue
->device
= device
;
1275 anv_queue_finish(struct anv_queue
*queue
)
1279 static struct anv_state
1280 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1282 struct anv_state state
;
1284 state
= anv_state_pool_alloc(pool
, size
, align
);
1285 memcpy(state
.map
, p
, size
);
1287 anv_state_flush(pool
->block_pool
.device
, state
);
1292 struct gen8_border_color
{
1297 /* Pad out to 64 bytes */
1302 anv_device_init_border_colors(struct anv_device
*device
)
1304 static const struct gen8_border_color border_colors
[] = {
1305 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1306 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1307 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1308 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1309 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1310 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1313 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1314 sizeof(border_colors
), 64,
1319 anv_device_init_trivial_batch(struct anv_device
*device
)
1321 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1323 if (device
->instance
->physicalDevice
.has_exec_async
)
1324 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1326 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1329 struct anv_batch batch
= {
1335 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1336 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1338 if (!device
->info
.has_llc
)
1339 gen_clflush_range(map
, batch
.next
- map
);
1341 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1344 VkResult
anv_EnumerateDeviceExtensionProperties(
1345 VkPhysicalDevice physicalDevice
,
1346 const char* pLayerName
,
1347 uint32_t* pPropertyCount
,
1348 VkExtensionProperties
* pProperties
)
1350 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1351 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1354 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1355 if (device
->supported_extensions
.extensions
[i
]) {
1356 vk_outarray_append(&out
, prop
) {
1357 *prop
= anv_device_extensions
[i
];
1362 return vk_outarray_status(&out
);
1366 anv_device_init_dispatch(struct anv_device
*device
)
1368 const struct anv_dispatch_table
*genX_table
;
1369 switch (device
->info
.gen
) {
1371 genX_table
= &gen11_dispatch_table
;
1374 genX_table
= &gen10_dispatch_table
;
1377 genX_table
= &gen9_dispatch_table
;
1380 genX_table
= &gen8_dispatch_table
;
1383 if (device
->info
.is_haswell
)
1384 genX_table
= &gen75_dispatch_table
;
1386 genX_table
= &gen7_dispatch_table
;
1389 unreachable("unsupported gen\n");
1392 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1393 /* Vulkan requires that entrypoints for extensions which have not been
1394 * enabled must not be advertised.
1396 if (!anv_entrypoint_is_enabled(i
, device
->instance
->apiVersion
,
1397 &device
->instance
->enabled_extensions
,
1398 &device
->enabled_extensions
)) {
1399 device
->dispatch
.entrypoints
[i
] = NULL
;
1400 } else if (genX_table
->entrypoints
[i
]) {
1401 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1403 device
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
1409 vk_priority_to_gen(int priority
)
1412 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1413 return GEN_CONTEXT_LOW_PRIORITY
;
1414 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1415 return GEN_CONTEXT_MEDIUM_PRIORITY
;
1416 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1417 return GEN_CONTEXT_HIGH_PRIORITY
;
1418 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1419 return GEN_CONTEXT_REALTIME_PRIORITY
;
1421 unreachable("Invalid priority");
1426 anv_device_init_hiz_clear_batch(struct anv_device
*device
)
1428 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
1429 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
1432 union isl_color_value hiz_clear
= { .u32
= { 0, } };
1433 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
1435 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
1436 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
1439 VkResult
anv_CreateDevice(
1440 VkPhysicalDevice physicalDevice
,
1441 const VkDeviceCreateInfo
* pCreateInfo
,
1442 const VkAllocationCallbacks
* pAllocator
,
1445 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1447 struct anv_device
*device
;
1449 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1451 struct anv_device_extension_table enabled_extensions
= { };
1452 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1454 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1455 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1456 anv_device_extensions
[idx
].extensionName
) == 0)
1460 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1461 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1463 if (!physical_device
->supported_extensions
.extensions
[idx
])
1464 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1466 enabled_extensions
.extensions
[idx
] = true;
1469 /* Check enabled features */
1470 if (pCreateInfo
->pEnabledFeatures
) {
1471 VkPhysicalDeviceFeatures supported_features
;
1472 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1473 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1474 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1475 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1476 for (uint32_t i
= 0; i
< num_features
; i
++) {
1477 if (enabled_feature
[i
] && !supported_feature
[i
])
1478 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1482 /* Check requested queues and fail if we are requested to create any
1483 * queues with flags we don't support.
1485 assert(pCreateInfo
->queueCreateInfoCount
> 0);
1486 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1487 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
1488 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1491 /* Check if client specified queue priority. */
1492 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
1493 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
1494 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1496 VkQueueGlobalPriorityEXT priority
=
1497 queue_priority
? queue_priority
->globalPriority
:
1498 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
1500 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1502 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1504 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1506 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1507 device
->instance
= physical_device
->instance
;
1508 device
->chipset_id
= physical_device
->chipset_id
;
1509 device
->no_hw
= physical_device
->no_hw
;
1510 device
->lost
= false;
1513 device
->alloc
= *pAllocator
;
1515 device
->alloc
= physical_device
->instance
->alloc
;
1517 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1518 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1519 if (device
->fd
== -1) {
1520 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1524 device
->context_id
= anv_gem_create_context(device
);
1525 if (device
->context_id
== -1) {
1526 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1530 /* As per spec, the driver implementation may deny requests to acquire
1531 * a priority above the default priority (MEDIUM) if the caller does not
1532 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
1535 if (physical_device
->has_context_priority
) {
1536 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
1537 I915_CONTEXT_PARAM_PRIORITY
,
1538 vk_priority_to_gen(priority
));
1539 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
1540 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
1545 device
->info
= physical_device
->info
;
1546 device
->isl_dev
= physical_device
->isl_dev
;
1548 /* On Broadwell and later, we can use batch chaining to more efficiently
1549 * implement growing command buffers. Prior to Haswell, the kernel
1550 * command parser gets in the way and we have to fall back to growing
1553 device
->can_chain_batches
= device
->info
.gen
>= 8;
1555 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1556 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1557 device
->enabled_extensions
= enabled_extensions
;
1559 anv_device_init_dispatch(device
);
1561 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1562 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1563 goto fail_context_id
;
1566 pthread_condattr_t condattr
;
1567 if (pthread_condattr_init(&condattr
) != 0) {
1568 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1571 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1572 pthread_condattr_destroy(&condattr
);
1573 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1576 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1577 pthread_condattr_destroy(&condattr
);
1578 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1581 pthread_condattr_destroy(&condattr
);
1584 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1585 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1586 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1588 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1590 result
= anv_bo_cache_init(&device
->bo_cache
);
1591 if (result
!= VK_SUCCESS
)
1592 goto fail_batch_bo_pool
;
1594 /* For the state pools we explicitly disable 48bit. */
1595 bo_flags
= (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1596 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1598 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384,
1600 if (result
!= VK_SUCCESS
)
1603 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384,
1605 if (result
!= VK_SUCCESS
)
1606 goto fail_dynamic_state_pool
;
1608 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096,
1610 if (result
!= VK_SUCCESS
)
1611 goto fail_instruction_state_pool
;
1613 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1614 if (result
!= VK_SUCCESS
)
1615 goto fail_surface_state_pool
;
1617 anv_device_init_trivial_batch(device
);
1619 if (device
->info
.gen
>= 10)
1620 anv_device_init_hiz_clear_batch(device
);
1622 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1624 anv_queue_init(device
, &device
->queue
);
1626 switch (device
->info
.gen
) {
1628 if (!device
->info
.is_haswell
)
1629 result
= gen7_init_device_state(device
);
1631 result
= gen75_init_device_state(device
);
1634 result
= gen8_init_device_state(device
);
1637 result
= gen9_init_device_state(device
);
1640 result
= gen10_init_device_state(device
);
1643 result
= gen11_init_device_state(device
);
1646 /* Shouldn't get here as we don't create physical devices for any other
1648 unreachable("unhandled gen");
1650 if (result
!= VK_SUCCESS
)
1651 goto fail_workaround_bo
;
1653 anv_device_init_blorp(device
);
1655 anv_device_init_border_colors(device
);
1657 *pDevice
= anv_device_to_handle(device
);
1662 anv_queue_finish(&device
->queue
);
1663 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1664 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1665 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1666 fail_surface_state_pool
:
1667 anv_state_pool_finish(&device
->surface_state_pool
);
1668 fail_instruction_state_pool
:
1669 anv_state_pool_finish(&device
->instruction_state_pool
);
1670 fail_dynamic_state_pool
:
1671 anv_state_pool_finish(&device
->dynamic_state_pool
);
1673 anv_bo_cache_finish(&device
->bo_cache
);
1675 anv_bo_pool_finish(&device
->batch_bo_pool
);
1676 pthread_cond_destroy(&device
->queue_submit
);
1678 pthread_mutex_destroy(&device
->mutex
);
1680 anv_gem_destroy_context(device
, device
->context_id
);
1684 vk_free(&device
->alloc
, device
);
1689 void anv_DestroyDevice(
1691 const VkAllocationCallbacks
* pAllocator
)
1693 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1698 anv_device_finish_blorp(device
);
1700 anv_queue_finish(&device
->queue
);
1702 #ifdef HAVE_VALGRIND
1703 /* We only need to free these to prevent valgrind errors. The backing
1704 * BO will go away in a couple of lines so we don't actually leak.
1706 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1709 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1711 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1712 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1714 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1715 if (device
->info
.gen
>= 10)
1716 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
1718 anv_state_pool_finish(&device
->surface_state_pool
);
1719 anv_state_pool_finish(&device
->instruction_state_pool
);
1720 anv_state_pool_finish(&device
->dynamic_state_pool
);
1722 anv_bo_cache_finish(&device
->bo_cache
);
1724 anv_bo_pool_finish(&device
->batch_bo_pool
);
1726 pthread_cond_destroy(&device
->queue_submit
);
1727 pthread_mutex_destroy(&device
->mutex
);
1729 anv_gem_destroy_context(device
, device
->context_id
);
1733 vk_free(&device
->alloc
, device
);
1736 VkResult
anv_EnumerateInstanceLayerProperties(
1737 uint32_t* pPropertyCount
,
1738 VkLayerProperties
* pProperties
)
1740 if (pProperties
== NULL
) {
1741 *pPropertyCount
= 0;
1745 /* None supported at this time */
1746 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1749 VkResult
anv_EnumerateDeviceLayerProperties(
1750 VkPhysicalDevice physicalDevice
,
1751 uint32_t* pPropertyCount
,
1752 VkLayerProperties
* pProperties
)
1754 if (pProperties
== NULL
) {
1755 *pPropertyCount
= 0;
1759 /* None supported at this time */
1760 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1763 void anv_GetDeviceQueue(
1765 uint32_t queueNodeIndex
,
1766 uint32_t queueIndex
,
1769 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1771 assert(queueIndex
== 0);
1773 *pQueue
= anv_queue_to_handle(&device
->queue
);
1776 void anv_GetDeviceQueue2(
1778 const VkDeviceQueueInfo2
* pQueueInfo
,
1781 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1783 assert(pQueueInfo
->queueIndex
== 0);
1785 if (pQueueInfo
->flags
== device
->queue
.flags
)
1786 *pQueue
= anv_queue_to_handle(&device
->queue
);
1792 anv_device_query_status(struct anv_device
*device
)
1794 /* This isn't likely as most of the callers of this function already check
1795 * for it. However, it doesn't hurt to check and it potentially lets us
1798 if (unlikely(device
->lost
))
1799 return VK_ERROR_DEVICE_LOST
;
1801 uint32_t active
, pending
;
1802 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1804 /* We don't know the real error. */
1805 device
->lost
= true;
1806 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1807 "get_reset_stats failed: %m");
1811 device
->lost
= true;
1812 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1813 "GPU hung on one of our command buffers");
1814 } else if (pending
) {
1815 device
->lost
= true;
1816 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1817 "GPU hung with commands in-flight");
1824 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1826 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1827 * Other usages of the BO (such as on different hardware) will not be
1828 * flagged as "busy" by this ioctl. Use with care.
1830 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1832 return VK_NOT_READY
;
1833 } else if (ret
== -1) {
1834 /* We don't know the real error. */
1835 device
->lost
= true;
1836 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1837 "gem wait failed: %m");
1840 /* Query for device status after the busy call. If the BO we're checking
1841 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1842 * client because it clearly doesn't have valid data. Yes, this most
1843 * likely means an ioctl, but we just did an ioctl to query the busy status
1844 * so it's no great loss.
1846 return anv_device_query_status(device
);
1850 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1853 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1854 if (ret
== -1 && errno
== ETIME
) {
1856 } else if (ret
== -1) {
1857 /* We don't know the real error. */
1858 device
->lost
= true;
1859 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1860 "gem wait failed: %m");
1863 /* Query for device status after the wait. If the BO we're waiting on got
1864 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1865 * because it clearly doesn't have valid data. Yes, this most likely means
1866 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1868 return anv_device_query_status(device
);
1871 VkResult
anv_DeviceWaitIdle(
1874 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1875 if (unlikely(device
->lost
))
1876 return VK_ERROR_DEVICE_LOST
;
1878 struct anv_batch batch
;
1881 batch
.start
= batch
.next
= cmds
;
1882 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1884 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1885 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1887 return anv_device_submit_simple_batch(device
, &batch
);
1891 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1893 uint32_t gem_handle
= anv_gem_create(device
, size
);
1895 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1897 anv_bo_init(bo
, gem_handle
, size
);
1902 VkResult
anv_AllocateMemory(
1904 const VkMemoryAllocateInfo
* pAllocateInfo
,
1905 const VkAllocationCallbacks
* pAllocator
,
1906 VkDeviceMemory
* pMem
)
1908 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1909 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1910 struct anv_device_memory
*mem
;
1911 VkResult result
= VK_SUCCESS
;
1913 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1915 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1916 assert(pAllocateInfo
->allocationSize
> 0);
1918 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
1919 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1921 /* FINISHME: Fail if allocation request exceeds heap size. */
1923 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1924 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1926 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1928 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1929 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1933 const VkImportMemoryFdInfoKHR
*fd_info
=
1934 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1936 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1939 if (fd_info
&& fd_info
->handleType
) {
1940 /* At the moment, we support only the below handle types. */
1941 assert(fd_info
->handleType
==
1942 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1943 fd_info
->handleType
==
1944 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1946 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1947 fd_info
->fd
, &mem
->bo
);
1948 if (result
!= VK_SUCCESS
)
1951 VkDeviceSize aligned_alloc_size
=
1952 align_u64(pAllocateInfo
->allocationSize
, 4096);
1954 /* For security purposes, we reject importing the bo if it's smaller
1955 * than the requested allocation size. This prevents a malicious client
1956 * from passing a buffer to a trusted client, lying about the size, and
1957 * telling the trusted client to try and texture from an image that goes
1958 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
1959 * in the trusted client. The trusted client can protect itself against
1960 * this sort of attack but only if it can trust the buffer size.
1962 if (mem
->bo
->size
< aligned_alloc_size
) {
1963 result
= vk_errorf(device
->instance
, device
,
1964 VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
,
1965 "aligned allocationSize too large for "
1966 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR: "
1967 "%"PRIu64
"B > %"PRIu64
"B",
1968 aligned_alloc_size
, mem
->bo
->size
);
1969 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1973 /* From the Vulkan spec:
1975 * "Importing memory from a file descriptor transfers ownership of
1976 * the file descriptor from the application to the Vulkan
1977 * implementation. The application must not perform any operations on
1978 * the file descriptor after a successful import."
1980 * If the import fails, we leave the file descriptor open.
1984 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1985 pAllocateInfo
->allocationSize
,
1987 if (result
!= VK_SUCCESS
)
1990 const VkMemoryDedicatedAllocateInfoKHR
*dedicated_info
=
1991 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
1992 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
1993 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
1995 /* Some legacy (non-modifiers) consumers need the tiling to be set on
1996 * the BO. In this case, we have a dedicated allocation.
1998 if (image
->needs_set_tiling
) {
1999 const uint32_t i915_tiling
=
2000 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
2001 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
2002 image
->planes
[0].surface
.isl
.row_pitch
,
2005 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2006 return vk_errorf(device
->instance
, NULL
,
2007 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
2008 "failed to set BO tiling: %m");
2014 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2015 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2016 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2018 const struct wsi_memory_allocate_info
*wsi_info
=
2019 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2020 if (wsi_info
&& wsi_info
->implicit_sync
) {
2021 /* We need to set the WRITE flag on window system buffers so that GEM
2022 * will know we're writing to them and synchronize uses on other rings
2023 * (eg if the display server uses the blitter ring).
2025 mem
->bo
->flags
|= EXEC_OBJECT_WRITE
;
2026 } else if (pdevice
->has_exec_async
) {
2027 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
2030 *pMem
= anv_device_memory_to_handle(mem
);
2035 vk_free2(&device
->alloc
, pAllocator
, mem
);
2040 VkResult
anv_GetMemoryFdKHR(
2042 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
2045 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
2046 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
2048 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2050 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2051 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2053 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
2056 VkResult
anv_GetMemoryFdPropertiesKHR(
2058 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
2060 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
2062 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2063 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2065 switch (handleType
) {
2066 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
2067 /* dma-buf can be imported as any memory type */
2068 pMemoryFdProperties
->memoryTypeBits
=
2069 (1 << pdevice
->memory
.type_count
) - 1;
2073 /* The valid usage section for this function says:
2075 * "handleType must not be one of the handle types defined as
2078 * So opaque handle types fall into the default "unsupported" case.
2080 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2084 void anv_FreeMemory(
2086 VkDeviceMemory _mem
,
2087 const VkAllocationCallbacks
* pAllocator
)
2089 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2090 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
2096 anv_UnmapMemory(_device
, _mem
);
2098 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2100 vk_free2(&device
->alloc
, pAllocator
, mem
);
2103 VkResult
anv_MapMemory(
2105 VkDeviceMemory _memory
,
2106 VkDeviceSize offset
,
2108 VkMemoryMapFlags flags
,
2111 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2112 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2119 if (size
== VK_WHOLE_SIZE
)
2120 size
= mem
->bo
->size
- offset
;
2122 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
2124 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
2125 * assert(size != 0);
2126 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
2127 * equal to the size of the memory minus offset
2130 assert(offset
+ size
<= mem
->bo
->size
);
2132 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
2133 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
2134 * at a time is valid. We could just mmap up front and return an offset
2135 * pointer here, but that may exhaust virtual memory on 32 bit
2138 uint32_t gem_flags
= 0;
2140 if (!device
->info
.has_llc
&&
2141 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
2142 gem_flags
|= I915_MMAP_WC
;
2144 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
2145 uint64_t map_offset
= offset
& ~4095ull;
2146 assert(offset
>= map_offset
);
2147 uint64_t map_size
= (offset
+ size
) - map_offset
;
2149 /* Let's map whole pages */
2150 map_size
= align_u64(map_size
, 4096);
2152 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2153 map_offset
, map_size
, gem_flags
);
2154 if (map
== MAP_FAILED
)
2155 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2158 mem
->map_size
= map_size
;
2160 *ppData
= mem
->map
+ (offset
- map_offset
);
2165 void anv_UnmapMemory(
2167 VkDeviceMemory _memory
)
2169 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2174 anv_gem_munmap(mem
->map
, mem
->map_size
);
2181 clflush_mapped_ranges(struct anv_device
*device
,
2183 const VkMappedMemoryRange
*ranges
)
2185 for (uint32_t i
= 0; i
< count
; i
++) {
2186 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2187 if (ranges
[i
].offset
>= mem
->map_size
)
2190 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2191 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2195 VkResult
anv_FlushMappedMemoryRanges(
2197 uint32_t memoryRangeCount
,
2198 const VkMappedMemoryRange
* pMemoryRanges
)
2200 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2202 if (device
->info
.has_llc
)
2205 /* Make sure the writes we're flushing have landed. */
2206 __builtin_ia32_mfence();
2208 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2213 VkResult
anv_InvalidateMappedMemoryRanges(
2215 uint32_t memoryRangeCount
,
2216 const VkMappedMemoryRange
* pMemoryRanges
)
2218 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2220 if (device
->info
.has_llc
)
2223 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2225 /* Make sure no reads get moved up above the invalidate. */
2226 __builtin_ia32_mfence();
2231 void anv_GetBufferMemoryRequirements(
2234 VkMemoryRequirements
* pMemoryRequirements
)
2236 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2237 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2238 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2240 /* The Vulkan spec (git aaed022) says:
2242 * memoryTypeBits is a bitfield and contains one bit set for every
2243 * supported memory type for the resource. The bit `1<<i` is set if and
2244 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2245 * structure for the physical device is supported.
2247 uint32_t memory_types
= 0;
2248 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2249 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2250 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2251 memory_types
|= (1u << i
);
2254 /* Base alignment requirement of a cache line */
2255 uint32_t alignment
= 16;
2257 /* We need an alignment of 32 for pushing UBOs */
2258 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2259 alignment
= MAX2(alignment
, 32);
2261 pMemoryRequirements
->size
= buffer
->size
;
2262 pMemoryRequirements
->alignment
= alignment
;
2264 /* Storage and Uniform buffers should have their size aligned to
2265 * 32-bits to avoid boundary checks when last DWord is not complete.
2266 * This would ensure that not internal padding would be needed for
2269 if (device
->robust_buffer_access
&&
2270 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
2271 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
2272 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
2274 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2277 void anv_GetBufferMemoryRequirements2(
2279 const VkBufferMemoryRequirementsInfo2
* pInfo
,
2280 VkMemoryRequirements2
* pMemoryRequirements
)
2282 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2283 &pMemoryRequirements
->memoryRequirements
);
2285 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2286 switch (ext
->sType
) {
2287 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2288 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2289 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2290 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2295 anv_debug_ignored_stype(ext
->sType
);
2301 void anv_GetImageMemoryRequirements(
2304 VkMemoryRequirements
* pMemoryRequirements
)
2306 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2307 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2308 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2310 /* The Vulkan spec (git aaed022) says:
2312 * memoryTypeBits is a bitfield and contains one bit set for every
2313 * supported memory type for the resource. The bit `1<<i` is set if and
2314 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2315 * structure for the physical device is supported.
2317 * All types are currently supported for images.
2319 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2321 pMemoryRequirements
->size
= image
->size
;
2322 pMemoryRequirements
->alignment
= image
->alignment
;
2323 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2326 void anv_GetImageMemoryRequirements2(
2328 const VkImageMemoryRequirementsInfo2
* pInfo
,
2329 VkMemoryRequirements2
* pMemoryRequirements
)
2331 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2332 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2334 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2335 &pMemoryRequirements
->memoryRequirements
);
2337 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2338 switch (ext
->sType
) {
2339 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
2340 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2341 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
2342 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
2343 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2344 plane_reqs
->planeAspect
);
2346 assert(image
->planes
[plane
].offset
== 0);
2348 /* The Vulkan spec (git aaed022) says:
2350 * memoryTypeBits is a bitfield and contains one bit set for every
2351 * supported memory type for the resource. The bit `1<<i` is set
2352 * if and only if the memory type `i` in the
2353 * VkPhysicalDeviceMemoryProperties structure for the physical
2354 * device is supported.
2356 * All types are currently supported for images.
2358 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2359 (1ull << pdevice
->memory
.type_count
) - 1;
2361 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2362 pMemoryRequirements
->memoryRequirements
.alignment
=
2363 image
->planes
[plane
].alignment
;
2368 anv_debug_ignored_stype(ext
->sType
);
2373 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2374 switch (ext
->sType
) {
2375 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2376 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2377 if (image
->needs_set_tiling
) {
2378 /* If we need to set the tiling for external consumers, we need a
2379 * dedicated allocation.
2381 * See also anv_AllocateMemory.
2383 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2384 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2386 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2387 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2393 anv_debug_ignored_stype(ext
->sType
);
2399 void anv_GetImageSparseMemoryRequirements(
2402 uint32_t* pSparseMemoryRequirementCount
,
2403 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2405 *pSparseMemoryRequirementCount
= 0;
2408 void anv_GetImageSparseMemoryRequirements2(
2410 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
2411 uint32_t* pSparseMemoryRequirementCount
,
2412 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
2414 *pSparseMemoryRequirementCount
= 0;
2417 void anv_GetDeviceMemoryCommitment(
2419 VkDeviceMemory memory
,
2420 VkDeviceSize
* pCommittedMemoryInBytes
)
2422 *pCommittedMemoryInBytes
= 0;
2426 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
2428 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2429 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2431 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
2434 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2435 buffer
->bo
= mem
->bo
;
2436 buffer
->offset
= pBindInfo
->memoryOffset
;
2443 VkResult
anv_BindBufferMemory(
2446 VkDeviceMemory memory
,
2447 VkDeviceSize memoryOffset
)
2449 anv_bind_buffer_memory(
2450 &(VkBindBufferMemoryInfo
) {
2451 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2454 .memoryOffset
= memoryOffset
,
2460 VkResult
anv_BindBufferMemory2(
2462 uint32_t bindInfoCount
,
2463 const VkBindBufferMemoryInfo
* pBindInfos
)
2465 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2466 anv_bind_buffer_memory(&pBindInfos
[i
]);
2471 VkResult
anv_QueueBindSparse(
2473 uint32_t bindInfoCount
,
2474 const VkBindSparseInfo
* pBindInfo
,
2477 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2478 if (unlikely(queue
->device
->lost
))
2479 return VK_ERROR_DEVICE_LOST
;
2481 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2486 VkResult
anv_CreateEvent(
2488 const VkEventCreateInfo
* pCreateInfo
,
2489 const VkAllocationCallbacks
* pAllocator
,
2492 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2493 struct anv_state state
;
2494 struct anv_event
*event
;
2496 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2498 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2501 event
->state
= state
;
2502 event
->semaphore
= VK_EVENT_RESET
;
2504 if (!device
->info
.has_llc
) {
2505 /* Make sure the writes we're flushing have landed. */
2506 __builtin_ia32_mfence();
2507 __builtin_ia32_clflush(event
);
2510 *pEvent
= anv_event_to_handle(event
);
2515 void anv_DestroyEvent(
2518 const VkAllocationCallbacks
* pAllocator
)
2520 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2521 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2526 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2529 VkResult
anv_GetEventStatus(
2533 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2534 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2536 if (unlikely(device
->lost
))
2537 return VK_ERROR_DEVICE_LOST
;
2539 if (!device
->info
.has_llc
) {
2540 /* Invalidate read cache before reading event written by GPU. */
2541 __builtin_ia32_clflush(event
);
2542 __builtin_ia32_mfence();
2546 return event
->semaphore
;
2549 VkResult
anv_SetEvent(
2553 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2554 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2556 event
->semaphore
= VK_EVENT_SET
;
2558 if (!device
->info
.has_llc
) {
2559 /* Make sure the writes we're flushing have landed. */
2560 __builtin_ia32_mfence();
2561 __builtin_ia32_clflush(event
);
2567 VkResult
anv_ResetEvent(
2571 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2572 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2574 event
->semaphore
= VK_EVENT_RESET
;
2576 if (!device
->info
.has_llc
) {
2577 /* Make sure the writes we're flushing have landed. */
2578 __builtin_ia32_mfence();
2579 __builtin_ia32_clflush(event
);
2587 VkResult
anv_CreateBuffer(
2589 const VkBufferCreateInfo
* pCreateInfo
,
2590 const VkAllocationCallbacks
* pAllocator
,
2593 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2594 struct anv_buffer
*buffer
;
2596 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2598 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2599 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2601 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2603 buffer
->size
= pCreateInfo
->size
;
2604 buffer
->usage
= pCreateInfo
->usage
;
2608 *pBuffer
= anv_buffer_to_handle(buffer
);
2613 void anv_DestroyBuffer(
2616 const VkAllocationCallbacks
* pAllocator
)
2618 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2619 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2624 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2628 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2629 enum isl_format format
,
2630 uint32_t offset
, uint32_t range
, uint32_t stride
)
2632 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2634 .mocs
= device
->default_mocs
,
2639 anv_state_flush(device
, state
);
2642 void anv_DestroySampler(
2645 const VkAllocationCallbacks
* pAllocator
)
2647 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2648 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2653 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2656 VkResult
anv_CreateFramebuffer(
2658 const VkFramebufferCreateInfo
* pCreateInfo
,
2659 const VkAllocationCallbacks
* pAllocator
,
2660 VkFramebuffer
* pFramebuffer
)
2662 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2663 struct anv_framebuffer
*framebuffer
;
2665 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2667 size_t size
= sizeof(*framebuffer
) +
2668 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2669 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2670 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2671 if (framebuffer
== NULL
)
2672 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2674 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2675 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2676 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2677 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2680 framebuffer
->width
= pCreateInfo
->width
;
2681 framebuffer
->height
= pCreateInfo
->height
;
2682 framebuffer
->layers
= pCreateInfo
->layers
;
2684 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2689 void anv_DestroyFramebuffer(
2692 const VkAllocationCallbacks
* pAllocator
)
2694 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2695 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2700 vk_free2(&device
->alloc
, pAllocator
, fb
);
2703 /* vk_icd.h does not declare this function, so we declare it here to
2704 * suppress Wmissing-prototypes.
2706 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2707 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2709 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2710 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2712 /* For the full details on loader interface versioning, see
2713 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2714 * What follows is a condensed summary, to help you navigate the large and
2715 * confusing official doc.
2717 * - Loader interface v0 is incompatible with later versions. We don't
2720 * - In loader interface v1:
2721 * - The first ICD entrypoint called by the loader is
2722 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2724 * - The ICD must statically expose no other Vulkan symbol unless it is
2725 * linked with -Bsymbolic.
2726 * - Each dispatchable Vulkan handle created by the ICD must be
2727 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2728 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2729 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2730 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2731 * such loader-managed surfaces.
2733 * - Loader interface v2 differs from v1 in:
2734 * - The first ICD entrypoint called by the loader is
2735 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2736 * statically expose this entrypoint.
2738 * - Loader interface v3 differs from v2 in:
2739 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2740 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2741 * because the loader no longer does so.
2743 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);