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
,
283 brw_process_intel_debug_variable();
285 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
287 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
289 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
290 device
->instance
= instance
;
292 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
293 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
295 device
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
297 const int pci_id_override
= gen_get_pci_device_id_override();
298 if (pci_id_override
< 0) {
299 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
300 if (!device
->chipset_id
) {
301 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
305 device
->chipset_id
= pci_id_override
;
306 device
->no_hw
= true;
309 device
->name
= gen_get_device_name(device
->chipset_id
);
310 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
311 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
315 if (device
->info
.is_haswell
) {
316 intel_logw("Haswell Vulkan support is incomplete");
317 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
318 intel_logw("Ivy Bridge Vulkan support is incomplete");
319 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
320 intel_logw("Bay Trail Vulkan support is incomplete");
321 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 10) {
322 /* Gen8-10 fully supported */
323 } else if (device
->info
.gen
== 11) {
324 intel_logw("Vulkan is not yet fully supported on gen11.");
326 result
= vk_errorf(device
->instance
, device
,
327 VK_ERROR_INCOMPATIBLE_DRIVER
,
328 "Vulkan not yet supported on %s", device
->name
);
332 device
->cmd_parser_version
= -1;
333 if (device
->info
.gen
== 7) {
334 device
->cmd_parser_version
=
335 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
336 if (device
->cmd_parser_version
== -1) {
337 result
= vk_errorf(device
->instance
, device
,
338 VK_ERROR_INITIALIZATION_FAILED
,
339 "failed to get command parser version");
344 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
345 result
= vk_errorf(device
->instance
, device
,
346 VK_ERROR_INITIALIZATION_FAILED
,
347 "kernel missing gem wait");
351 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
352 result
= vk_errorf(device
->instance
, device
,
353 VK_ERROR_INITIALIZATION_FAILED
,
354 "kernel missing execbuf2");
358 if (!device
->info
.has_llc
&&
359 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
360 result
= vk_errorf(device
->instance
, device
,
361 VK_ERROR_INITIALIZATION_FAILED
,
362 "kernel missing wc mmap");
366 result
= anv_physical_device_init_heaps(device
, fd
);
367 if (result
!= VK_SUCCESS
)
370 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
371 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
372 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
373 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
374 device
->has_syncobj_wait
= device
->has_syncobj
&&
375 anv_gem_supports_syncobj_wait(fd
);
376 device
->has_context_priority
= anv_gem_has_context_priority(fd
);
378 device
->use_softpin
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_SOFTPIN
)
379 && device
->supports_48bit_addresses
;
381 device
->has_context_isolation
=
382 anv_gem_get_param(fd
, I915_PARAM_HAS_CONTEXT_ISOLATION
);
384 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
386 /* Starting with Gen10, the timestamp frequency of the command streamer may
387 * vary from one part to another. We can query the value from the kernel.
389 if (device
->info
.gen
>= 10) {
390 int timestamp_frequency
=
391 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
393 if (timestamp_frequency
< 0)
394 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
396 device
->info
.timestamp_frequency
= timestamp_frequency
;
399 /* GENs prior to 8 do not support EU/Subslice info */
400 if (device
->info
.gen
>= 8) {
401 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
402 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
404 /* Without this information, we cannot get the right Braswell
405 * brandstrings, and we have to use conservative numbers for GPGPU on
406 * many platforms, but otherwise, things will just work.
408 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
409 intel_logw("Kernel 4.1 required to properly query GPU properties");
411 } else if (device
->info
.gen
== 7) {
412 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
415 if (device
->info
.is_cherryview
&&
416 device
->subslice_total
> 0 && device
->eu_total
> 0) {
417 /* Logical CS threads = EUs per subslice * num threads per EU */
418 uint32_t max_cs_threads
=
419 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
421 /* Fuse configurations may give more threads than expected, never less. */
422 if (max_cs_threads
> device
->info
.max_cs_threads
)
423 device
->info
.max_cs_threads
= max_cs_threads
;
426 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
427 if (device
->compiler
== NULL
) {
428 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
431 device
->compiler
->shader_debug_log
= compiler_debug_log
;
432 device
->compiler
->shader_perf_log
= compiler_perf_log
;
433 device
->compiler
->supports_pull_constants
= false;
434 device
->compiler
->constant_buffer_0_is_relative
=
435 device
->info
.gen
< 8 || !device
->has_context_isolation
;
437 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
439 result
= anv_physical_device_init_uuids(device
);
440 if (result
!= VK_SUCCESS
)
443 result
= anv_init_wsi(device
);
444 if (result
!= VK_SUCCESS
) {
445 ralloc_free(device
->compiler
);
449 anv_physical_device_get_supported_extensions(device
,
450 &device
->supported_extensions
);
452 device
->local_fd
= fd
;
453 device
->master_fd
= master_fd
;
464 anv_physical_device_finish(struct anv_physical_device
*device
)
466 anv_finish_wsi(device
);
467 ralloc_free(device
->compiler
);
468 close(device
->local_fd
);
472 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
473 VkSystemAllocationScope allocationScope
)
479 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
480 size_t align
, VkSystemAllocationScope allocationScope
)
482 return realloc(pOriginal
, size
);
486 default_free_func(void *pUserData
, void *pMemory
)
491 static const VkAllocationCallbacks default_alloc
= {
493 .pfnAllocation
= default_alloc_func
,
494 .pfnReallocation
= default_realloc_func
,
495 .pfnFree
= default_free_func
,
498 VkResult
anv_EnumerateInstanceExtensionProperties(
499 const char* pLayerName
,
500 uint32_t* pPropertyCount
,
501 VkExtensionProperties
* pProperties
)
503 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
505 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
506 if (anv_instance_extensions_supported
.extensions
[i
]) {
507 vk_outarray_append(&out
, prop
) {
508 *prop
= anv_instance_extensions
[i
];
513 return vk_outarray_status(&out
);
516 VkResult
anv_CreateInstance(
517 const VkInstanceCreateInfo
* pCreateInfo
,
518 const VkAllocationCallbacks
* pAllocator
,
519 VkInstance
* pInstance
)
521 struct anv_instance
*instance
;
524 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
526 struct anv_instance_extension_table enabled_extensions
= {};
527 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
529 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
530 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
531 anv_instance_extensions
[idx
].extensionName
) == 0)
535 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
536 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
538 if (!anv_instance_extensions_supported
.extensions
[idx
])
539 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
541 enabled_extensions
.extensions
[idx
] = true;
544 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
545 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
547 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
549 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
552 instance
->alloc
= *pAllocator
;
554 instance
->alloc
= default_alloc
;
556 if (pCreateInfo
->pApplicationInfo
&&
557 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
558 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
560 anv_EnumerateInstanceVersion(&instance
->apiVersion
);
563 instance
->enabled_extensions
= enabled_extensions
;
565 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
566 /* Vulkan requires that entrypoints for extensions which have not been
567 * enabled must not be advertised.
569 if (!anv_entrypoint_is_enabled(i
, instance
->apiVersion
,
570 &instance
->enabled_extensions
, NULL
)) {
571 instance
->dispatch
.entrypoints
[i
] = NULL
;
572 } else if (anv_dispatch_table
.entrypoints
[i
] != NULL
) {
573 instance
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
575 instance
->dispatch
.entrypoints
[i
] =
576 anv_tramp_dispatch_table
.entrypoints
[i
];
580 instance
->physicalDeviceCount
= -1;
582 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
583 if (result
!= VK_SUCCESS
) {
584 vk_free2(&default_alloc
, pAllocator
, instance
);
585 return vk_error(result
);
590 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
592 *pInstance
= anv_instance_to_handle(instance
);
597 void anv_DestroyInstance(
598 VkInstance _instance
,
599 const VkAllocationCallbacks
* pAllocator
)
601 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
606 if (instance
->physicalDeviceCount
> 0) {
607 /* We support at most one physical device. */
608 assert(instance
->physicalDeviceCount
== 1);
609 anv_physical_device_finish(&instance
->physicalDevice
);
612 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
614 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
618 vk_free(&instance
->alloc
, instance
);
622 anv_enumerate_devices(struct anv_instance
*instance
)
624 /* TODO: Check for more devices ? */
625 drmDevicePtr devices
[8];
626 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
629 instance
->physicalDeviceCount
= 0;
631 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
633 return VK_ERROR_INCOMPATIBLE_DRIVER
;
635 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
636 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
637 devices
[i
]->bustype
== DRM_BUS_PCI
&&
638 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
640 result
= anv_physical_device_init(&instance
->physicalDevice
,
642 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
643 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
647 drmFreeDevices(devices
, max_devices
);
649 if (result
== VK_SUCCESS
)
650 instance
->physicalDeviceCount
= 1;
656 anv_instance_ensure_physical_device(struct anv_instance
*instance
)
658 if (instance
->physicalDeviceCount
< 0) {
659 VkResult result
= anv_enumerate_devices(instance
);
660 if (result
!= VK_SUCCESS
&&
661 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
668 VkResult
anv_EnumeratePhysicalDevices(
669 VkInstance _instance
,
670 uint32_t* pPhysicalDeviceCount
,
671 VkPhysicalDevice
* pPhysicalDevices
)
673 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
674 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
676 VkResult result
= anv_instance_ensure_physical_device(instance
);
677 if (result
!= VK_SUCCESS
)
680 if (instance
->physicalDeviceCount
== 0)
683 assert(instance
->physicalDeviceCount
== 1);
684 vk_outarray_append(&out
, i
) {
685 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
688 return vk_outarray_status(&out
);
691 VkResult
anv_EnumeratePhysicalDeviceGroups(
692 VkInstance _instance
,
693 uint32_t* pPhysicalDeviceGroupCount
,
694 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
696 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
697 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
698 pPhysicalDeviceGroupCount
);
700 VkResult result
= anv_instance_ensure_physical_device(instance
);
701 if (result
!= VK_SUCCESS
)
704 if (instance
->physicalDeviceCount
== 0)
707 assert(instance
->physicalDeviceCount
== 1);
709 vk_outarray_append(&out
, p
) {
710 p
->physicalDeviceCount
= 1;
711 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
712 p
->physicalDevices
[0] =
713 anv_physical_device_to_handle(&instance
->physicalDevice
);
714 p
->subsetAllocation
= VK_FALSE
;
716 vk_foreach_struct(ext
, p
->pNext
)
717 anv_debug_ignored_stype(ext
->sType
);
720 return vk_outarray_status(&out
);
723 void anv_GetPhysicalDeviceFeatures(
724 VkPhysicalDevice physicalDevice
,
725 VkPhysicalDeviceFeatures
* pFeatures
)
727 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
729 *pFeatures
= (VkPhysicalDeviceFeatures
) {
730 .robustBufferAccess
= true,
731 .fullDrawIndexUint32
= true,
732 .imageCubeArray
= true,
733 .independentBlend
= true,
734 .geometryShader
= true,
735 .tessellationShader
= true,
736 .sampleRateShading
= true,
737 .dualSrcBlend
= true,
739 .multiDrawIndirect
= true,
740 .drawIndirectFirstInstance
= true,
742 .depthBiasClamp
= true,
743 .fillModeNonSolid
= true,
744 .depthBounds
= false,
748 .multiViewport
= true,
749 .samplerAnisotropy
= true,
750 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
751 pdevice
->info
.is_baytrail
,
752 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
753 .textureCompressionBC
= true,
754 .occlusionQueryPrecise
= true,
755 .pipelineStatisticsQuery
= true,
756 .fragmentStoresAndAtomics
= true,
757 .shaderTessellationAndGeometryPointSize
= true,
758 .shaderImageGatherExtended
= true,
759 .shaderStorageImageExtendedFormats
= true,
760 .shaderStorageImageMultisample
= false,
761 .shaderStorageImageReadWithoutFormat
= false,
762 .shaderStorageImageWriteWithoutFormat
= true,
763 .shaderUniformBufferArrayDynamicIndexing
= true,
764 .shaderSampledImageArrayDynamicIndexing
= true,
765 .shaderStorageBufferArrayDynamicIndexing
= true,
766 .shaderStorageImageArrayDynamicIndexing
= true,
767 .shaderClipDistance
= true,
768 .shaderCullDistance
= true,
769 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
770 pdevice
->info
.has_64bit_types
,
771 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
772 pdevice
->info
.has_64bit_types
,
773 .shaderInt16
= pdevice
->info
.gen
>= 8,
774 .shaderResourceMinLod
= false,
775 .variableMultisampleRate
= true,
776 .inheritedQueries
= true,
779 /* We can't do image stores in vec4 shaders */
780 pFeatures
->vertexPipelineStoresAndAtomics
=
781 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
782 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
785 void anv_GetPhysicalDeviceFeatures2(
786 VkPhysicalDevice physicalDevice
,
787 VkPhysicalDeviceFeatures2
* pFeatures
)
789 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
791 vk_foreach_struct(ext
, pFeatures
->pNext
) {
792 switch (ext
->sType
) {
793 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
794 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
795 features
->protectedMemory
= VK_FALSE
;
799 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
800 VkPhysicalDeviceMultiviewFeatures
*features
=
801 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
802 features
->multiview
= true;
803 features
->multiviewGeometryShader
= true;
804 features
->multiviewTessellationShader
= true;
808 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
809 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
810 features
->variablePointersStorageBuffer
= true;
811 features
->variablePointers
= true;
815 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
816 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
817 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
818 features
->samplerYcbcrConversion
= true;
822 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
823 VkPhysicalDeviceShaderDrawParameterFeatures
*features
= (void *)ext
;
824 features
->shaderDrawParameters
= true;
828 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
: {
829 VkPhysicalDevice16BitStorageFeaturesKHR
*features
=
830 (VkPhysicalDevice16BitStorageFeaturesKHR
*)ext
;
831 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
833 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
834 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
835 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
836 features
->storageInputOutput16
= false;
841 anv_debug_ignored_stype(ext
->sType
);
847 void anv_GetPhysicalDeviceProperties(
848 VkPhysicalDevice physicalDevice
,
849 VkPhysicalDeviceProperties
* pProperties
)
851 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
852 const struct gen_device_info
*devinfo
= &pdevice
->info
;
854 /* See assertions made when programming the buffer surface state. */
855 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
856 (1ul << 30) : (1ul << 27);
858 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
861 VkSampleCountFlags sample_counts
=
862 isl_device_get_sample_counts(&pdevice
->isl_dev
);
864 VkPhysicalDeviceLimits limits
= {
865 .maxImageDimension1D
= (1 << 14),
866 .maxImageDimension2D
= (1 << 14),
867 .maxImageDimension3D
= (1 << 11),
868 .maxImageDimensionCube
= (1 << 14),
869 .maxImageArrayLayers
= (1 << 11),
870 .maxTexelBufferElements
= 128 * 1024 * 1024,
871 .maxUniformBufferRange
= (1ul << 27),
872 .maxStorageBufferRange
= max_raw_buffer_sz
,
873 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
874 .maxMemoryAllocationCount
= UINT32_MAX
,
875 .maxSamplerAllocationCount
= 64 * 1024,
876 .bufferImageGranularity
= 64, /* A cache line */
877 .sparseAddressSpaceSize
= 0,
878 .maxBoundDescriptorSets
= MAX_SETS
,
879 .maxPerStageDescriptorSamplers
= max_samplers
,
880 .maxPerStageDescriptorUniformBuffers
= 64,
881 .maxPerStageDescriptorStorageBuffers
= 64,
882 .maxPerStageDescriptorSampledImages
= max_samplers
,
883 .maxPerStageDescriptorStorageImages
= 64,
884 .maxPerStageDescriptorInputAttachments
= 64,
885 .maxPerStageResources
= 250,
886 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
887 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
888 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
889 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
890 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
891 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
892 .maxDescriptorSetStorageImages
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
893 .maxDescriptorSetInputAttachments
= 256,
894 .maxVertexInputAttributes
= MAX_VBS
,
895 .maxVertexInputBindings
= MAX_VBS
,
896 .maxVertexInputAttributeOffset
= 2047,
897 .maxVertexInputBindingStride
= 2048,
898 .maxVertexOutputComponents
= 128,
899 .maxTessellationGenerationLevel
= 64,
900 .maxTessellationPatchSize
= 32,
901 .maxTessellationControlPerVertexInputComponents
= 128,
902 .maxTessellationControlPerVertexOutputComponents
= 128,
903 .maxTessellationControlPerPatchOutputComponents
= 128,
904 .maxTessellationControlTotalOutputComponents
= 2048,
905 .maxTessellationEvaluationInputComponents
= 128,
906 .maxTessellationEvaluationOutputComponents
= 128,
907 .maxGeometryShaderInvocations
= 32,
908 .maxGeometryInputComponents
= 64,
909 .maxGeometryOutputComponents
= 128,
910 .maxGeometryOutputVertices
= 256,
911 .maxGeometryTotalOutputComponents
= 1024,
912 .maxFragmentInputComponents
= 112, /* 128 components - (POS, PSIZ, CLIP_DIST0, CLIP_DIST1) */
913 .maxFragmentOutputAttachments
= 8,
914 .maxFragmentDualSrcAttachments
= 1,
915 .maxFragmentCombinedOutputResources
= 8,
916 .maxComputeSharedMemorySize
= 32768,
917 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
918 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
919 .maxComputeWorkGroupSize
= {
920 16 * devinfo
->max_cs_threads
,
921 16 * devinfo
->max_cs_threads
,
922 16 * devinfo
->max_cs_threads
,
924 .subPixelPrecisionBits
= 4 /* FIXME */,
925 .subTexelPrecisionBits
= 4 /* FIXME */,
926 .mipmapPrecisionBits
= 4 /* FIXME */,
927 .maxDrawIndexedIndexValue
= UINT32_MAX
,
928 .maxDrawIndirectCount
= UINT32_MAX
,
929 .maxSamplerLodBias
= 16,
930 .maxSamplerAnisotropy
= 16,
931 .maxViewports
= MAX_VIEWPORTS
,
932 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
933 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
934 .viewportSubPixelBits
= 13, /* We take a float? */
935 .minMemoryMapAlignment
= 4096, /* A page */
936 .minTexelBufferOffsetAlignment
= 1,
937 /* We need 16 for UBO block reads to work and 32 for push UBOs */
938 .minUniformBufferOffsetAlignment
= 32,
939 .minStorageBufferOffsetAlignment
= 4,
940 .minTexelOffset
= -8,
942 .minTexelGatherOffset
= -32,
943 .maxTexelGatherOffset
= 31,
944 .minInterpolationOffset
= -0.5,
945 .maxInterpolationOffset
= 0.4375,
946 .subPixelInterpolationOffsetBits
= 4,
947 .maxFramebufferWidth
= (1 << 14),
948 .maxFramebufferHeight
= (1 << 14),
949 .maxFramebufferLayers
= (1 << 11),
950 .framebufferColorSampleCounts
= sample_counts
,
951 .framebufferDepthSampleCounts
= sample_counts
,
952 .framebufferStencilSampleCounts
= sample_counts
,
953 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
954 .maxColorAttachments
= MAX_RTS
,
955 .sampledImageColorSampleCounts
= sample_counts
,
956 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
957 .sampledImageDepthSampleCounts
= sample_counts
,
958 .sampledImageStencilSampleCounts
= sample_counts
,
959 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
960 .maxSampleMaskWords
= 1,
961 .timestampComputeAndGraphics
= false,
962 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
963 .maxClipDistances
= 8,
964 .maxCullDistances
= 8,
965 .maxCombinedClipAndCullDistances
= 8,
966 .discreteQueuePriorities
= 1,
967 .pointSizeRange
= { 0.125, 255.875 },
968 .lineWidthRange
= { 0.0, 7.9921875 },
969 .pointSizeGranularity
= (1.0 / 8.0),
970 .lineWidthGranularity
= (1.0 / 128.0),
971 .strictLines
= false, /* FINISHME */
972 .standardSampleLocations
= true,
973 .optimalBufferCopyOffsetAlignment
= 128,
974 .optimalBufferCopyRowPitchAlignment
= 128,
975 .nonCoherentAtomSize
= 64,
978 *pProperties
= (VkPhysicalDeviceProperties
) {
979 .apiVersion
= anv_physical_device_api_version(pdevice
),
980 .driverVersion
= vk_get_driver_version(),
982 .deviceID
= pdevice
->chipset_id
,
983 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
985 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
988 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
989 "%s", pdevice
->name
);
990 memcpy(pProperties
->pipelineCacheUUID
,
991 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
994 void anv_GetPhysicalDeviceProperties2(
995 VkPhysicalDevice physicalDevice
,
996 VkPhysicalDeviceProperties2
* pProperties
)
998 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1000 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1002 vk_foreach_struct(ext
, pProperties
->pNext
) {
1003 switch (ext
->sType
) {
1004 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1005 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1006 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1008 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1012 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1013 VkPhysicalDeviceIDProperties
*id_props
=
1014 (VkPhysicalDeviceIDProperties
*)ext
;
1015 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1016 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1017 /* The LUID is for Windows. */
1018 id_props
->deviceLUIDValid
= false;
1022 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1023 VkPhysicalDeviceMaintenance3Properties
*props
=
1024 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1025 /* This value doesn't matter for us today as our per-stage
1026 * descriptors are the real limit.
1028 props
->maxPerSetDescriptors
= 1024;
1029 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1033 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1034 VkPhysicalDeviceMultiviewProperties
*properties
=
1035 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1036 properties
->maxMultiviewViewCount
= 16;
1037 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1041 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1042 VkPhysicalDevicePointClippingProperties
*properties
=
1043 (VkPhysicalDevicePointClippingProperties
*) ext
;
1044 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1045 anv_finishme("Implement pop-free point clipping");
1049 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1050 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1052 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1054 VkShaderStageFlags scalar_stages
= 0;
1055 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1056 if (pdevice
->compiler
->scalar_stage
[stage
])
1057 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1059 properties
->supportedStages
= scalar_stages
;
1061 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1062 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1063 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1064 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1065 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1066 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1067 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1068 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1069 properties
->quadOperationsInAllStages
= VK_TRUE
;
1074 anv_debug_ignored_stype(ext
->sType
);
1080 /* We support exactly one queue family. */
1081 static const VkQueueFamilyProperties
1082 anv_queue_family_properties
= {
1083 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1084 VK_QUEUE_COMPUTE_BIT
|
1085 VK_QUEUE_TRANSFER_BIT
,
1087 .timestampValidBits
= 36, /* XXX: Real value here */
1088 .minImageTransferGranularity
= { 1, 1, 1 },
1091 void anv_GetPhysicalDeviceQueueFamilyProperties(
1092 VkPhysicalDevice physicalDevice
,
1094 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1096 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1098 vk_outarray_append(&out
, p
) {
1099 *p
= anv_queue_family_properties
;
1103 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1104 VkPhysicalDevice physicalDevice
,
1105 uint32_t* pQueueFamilyPropertyCount
,
1106 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1109 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1111 vk_outarray_append(&out
, p
) {
1112 p
->queueFamilyProperties
= anv_queue_family_properties
;
1114 vk_foreach_struct(s
, p
->pNext
) {
1115 anv_debug_ignored_stype(s
->sType
);
1120 void anv_GetPhysicalDeviceMemoryProperties(
1121 VkPhysicalDevice physicalDevice
,
1122 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1124 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1126 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1127 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1128 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1129 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1130 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1134 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1135 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1136 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1137 .size
= physical_device
->memory
.heaps
[i
].size
,
1138 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1143 void anv_GetPhysicalDeviceMemoryProperties2(
1144 VkPhysicalDevice physicalDevice
,
1145 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1147 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1148 &pMemoryProperties
->memoryProperties
);
1150 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1151 switch (ext
->sType
) {
1153 anv_debug_ignored_stype(ext
->sType
);
1160 anv_GetDeviceGroupPeerMemoryFeatures(
1163 uint32_t localDeviceIndex
,
1164 uint32_t remoteDeviceIndex
,
1165 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1167 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1168 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1169 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1170 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1171 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1174 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1175 VkInstance _instance
,
1178 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1180 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1181 * when we have to return valid function pointers, NULL, or it's left
1182 * undefined. See the table for exact details.
1187 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1188 if (strcmp(pName, "vk" #entrypoint) == 0) \
1189 return (PFN_vkVoidFunction)anv_##entrypoint
1191 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1192 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1193 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1194 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1196 #undef LOOKUP_ANV_ENTRYPOINT
1198 if (instance
== NULL
)
1201 int idx
= anv_get_entrypoint_index(pName
);
1205 return instance
->dispatch
.entrypoints
[idx
];
1208 /* With version 1+ of the loader interface the ICD should expose
1209 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1212 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1213 VkInstance instance
,
1217 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1218 VkInstance instance
,
1221 return anv_GetInstanceProcAddr(instance
, pName
);
1224 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1228 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1230 if (!device
|| !pName
)
1233 int idx
= anv_get_entrypoint_index(pName
);
1237 return device
->dispatch
.entrypoints
[idx
];
1241 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1242 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1243 const VkAllocationCallbacks
* pAllocator
,
1244 VkDebugReportCallbackEXT
* pCallback
)
1246 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1247 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1248 pCreateInfo
, pAllocator
, &instance
->alloc
,
1253 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1254 VkDebugReportCallbackEXT _callback
,
1255 const VkAllocationCallbacks
* pAllocator
)
1257 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1258 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1259 _callback
, pAllocator
, &instance
->alloc
);
1263 anv_DebugReportMessageEXT(VkInstance _instance
,
1264 VkDebugReportFlagsEXT flags
,
1265 VkDebugReportObjectTypeEXT objectType
,
1268 int32_t messageCode
,
1269 const char* pLayerPrefix
,
1270 const char* pMessage
)
1272 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1273 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1274 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1278 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1280 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1281 queue
->device
= device
;
1286 anv_queue_finish(struct anv_queue
*queue
)
1290 static struct anv_state
1291 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1293 struct anv_state state
;
1295 state
= anv_state_pool_alloc(pool
, size
, align
);
1296 memcpy(state
.map
, p
, size
);
1298 anv_state_flush(pool
->block_pool
.device
, state
);
1303 struct gen8_border_color
{
1308 /* Pad out to 64 bytes */
1313 anv_device_init_border_colors(struct anv_device
*device
)
1315 static const struct gen8_border_color border_colors
[] = {
1316 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1317 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1318 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1319 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1320 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1321 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1324 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1325 sizeof(border_colors
), 64,
1330 anv_device_init_trivial_batch(struct anv_device
*device
)
1332 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1334 if (device
->instance
->physicalDevice
.has_exec_async
)
1335 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1337 if (device
->instance
->physicalDevice
.use_softpin
)
1338 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_PINNED
;
1340 anv_vma_alloc(device
, &device
->trivial_batch_bo
);
1342 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1345 struct anv_batch batch
= {
1351 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1352 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1354 if (!device
->info
.has_llc
)
1355 gen_clflush_range(map
, batch
.next
- map
);
1357 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1360 VkResult
anv_EnumerateDeviceExtensionProperties(
1361 VkPhysicalDevice physicalDevice
,
1362 const char* pLayerName
,
1363 uint32_t* pPropertyCount
,
1364 VkExtensionProperties
* pProperties
)
1366 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1367 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1370 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1371 if (device
->supported_extensions
.extensions
[i
]) {
1372 vk_outarray_append(&out
, prop
) {
1373 *prop
= anv_device_extensions
[i
];
1378 return vk_outarray_status(&out
);
1382 anv_device_init_dispatch(struct anv_device
*device
)
1384 const struct anv_dispatch_table
*genX_table
;
1385 switch (device
->info
.gen
) {
1387 genX_table
= &gen11_dispatch_table
;
1390 genX_table
= &gen10_dispatch_table
;
1393 genX_table
= &gen9_dispatch_table
;
1396 genX_table
= &gen8_dispatch_table
;
1399 if (device
->info
.is_haswell
)
1400 genX_table
= &gen75_dispatch_table
;
1402 genX_table
= &gen7_dispatch_table
;
1405 unreachable("unsupported gen\n");
1408 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1409 /* Vulkan requires that entrypoints for extensions which have not been
1410 * enabled must not be advertised.
1412 if (!anv_entrypoint_is_enabled(i
, device
->instance
->apiVersion
,
1413 &device
->instance
->enabled_extensions
,
1414 &device
->enabled_extensions
)) {
1415 device
->dispatch
.entrypoints
[i
] = NULL
;
1416 } else if (genX_table
->entrypoints
[i
]) {
1417 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1419 device
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
1425 vk_priority_to_gen(int priority
)
1428 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1429 return GEN_CONTEXT_LOW_PRIORITY
;
1430 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1431 return GEN_CONTEXT_MEDIUM_PRIORITY
;
1432 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1433 return GEN_CONTEXT_HIGH_PRIORITY
;
1434 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1435 return GEN_CONTEXT_REALTIME_PRIORITY
;
1437 unreachable("Invalid priority");
1442 anv_device_init_hiz_clear_batch(struct anv_device
*device
)
1444 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
1445 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
1448 union isl_color_value hiz_clear
= { .u32
= { 0, } };
1449 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
1451 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
1452 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
1455 VkResult
anv_CreateDevice(
1456 VkPhysicalDevice physicalDevice
,
1457 const VkDeviceCreateInfo
* pCreateInfo
,
1458 const VkAllocationCallbacks
* pAllocator
,
1461 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1463 struct anv_device
*device
;
1465 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1467 struct anv_device_extension_table enabled_extensions
= { };
1468 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1470 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1471 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1472 anv_device_extensions
[idx
].extensionName
) == 0)
1476 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1477 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1479 if (!physical_device
->supported_extensions
.extensions
[idx
])
1480 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1482 enabled_extensions
.extensions
[idx
] = true;
1485 /* Check enabled features */
1486 if (pCreateInfo
->pEnabledFeatures
) {
1487 VkPhysicalDeviceFeatures supported_features
;
1488 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1489 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1490 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1491 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1492 for (uint32_t i
= 0; i
< num_features
; i
++) {
1493 if (enabled_feature
[i
] && !supported_feature
[i
])
1494 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1498 /* Check requested queues and fail if we are requested to create any
1499 * queues with flags we don't support.
1501 assert(pCreateInfo
->queueCreateInfoCount
> 0);
1502 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1503 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
1504 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1507 /* Check if client specified queue priority. */
1508 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
1509 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
1510 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1512 VkQueueGlobalPriorityEXT priority
=
1513 queue_priority
? queue_priority
->globalPriority
:
1514 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
1516 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1518 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1520 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1522 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1523 device
->instance
= physical_device
->instance
;
1524 device
->chipset_id
= physical_device
->chipset_id
;
1525 device
->no_hw
= physical_device
->no_hw
;
1526 device
->lost
= false;
1529 device
->alloc
= *pAllocator
;
1531 device
->alloc
= physical_device
->instance
->alloc
;
1533 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1534 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1535 if (device
->fd
== -1) {
1536 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1540 device
->context_id
= anv_gem_create_context(device
);
1541 if (device
->context_id
== -1) {
1542 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1546 if (physical_device
->use_softpin
) {
1547 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
1548 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1552 /* keep the page with address zero out of the allocator */
1553 util_vma_heap_init(&device
->vma_lo
, LOW_HEAP_MIN_ADDRESS
, LOW_HEAP_SIZE
);
1554 device
->vma_lo_available
=
1555 physical_device
->memory
.heaps
[physical_device
->memory
.heap_count
- 1].size
;
1557 /* Leave the last 4GiB out of the high vma range, so that no state base
1558 * address + size can overflow 48 bits. For more information see the
1559 * comment about Wa32bitGeneralStateOffset in anv_allocator.c
1561 util_vma_heap_init(&device
->vma_hi
, HIGH_HEAP_MIN_ADDRESS
,
1563 device
->vma_hi_available
= physical_device
->memory
.heap_count
== 1 ? 0 :
1564 physical_device
->memory
.heaps
[0].size
;
1567 /* As per spec, the driver implementation may deny requests to acquire
1568 * a priority above the default priority (MEDIUM) if the caller does not
1569 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
1572 if (physical_device
->has_context_priority
) {
1573 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
1574 I915_CONTEXT_PARAM_PRIORITY
,
1575 vk_priority_to_gen(priority
));
1576 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
1577 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
1582 device
->info
= physical_device
->info
;
1583 device
->isl_dev
= physical_device
->isl_dev
;
1585 /* On Broadwell and later, we can use batch chaining to more efficiently
1586 * implement growing command buffers. Prior to Haswell, the kernel
1587 * command parser gets in the way and we have to fall back to growing
1590 device
->can_chain_batches
= device
->info
.gen
>= 8;
1592 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1593 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1594 device
->enabled_extensions
= enabled_extensions
;
1596 anv_device_init_dispatch(device
);
1598 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1599 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1600 goto fail_context_id
;
1603 pthread_condattr_t condattr
;
1604 if (pthread_condattr_init(&condattr
) != 0) {
1605 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1608 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1609 pthread_condattr_destroy(&condattr
);
1610 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1613 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1614 pthread_condattr_destroy(&condattr
);
1615 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1618 pthread_condattr_destroy(&condattr
);
1621 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1622 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1623 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0) |
1624 (physical_device
->use_softpin
? EXEC_OBJECT_PINNED
: 0);
1626 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1628 result
= anv_bo_cache_init(&device
->bo_cache
);
1629 if (result
!= VK_SUCCESS
)
1630 goto fail_batch_bo_pool
;
1632 if (!physical_device
->use_softpin
)
1633 bo_flags
&= ~EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1635 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
1636 DYNAMIC_STATE_POOL_MIN_ADDRESS
,
1639 if (result
!= VK_SUCCESS
)
1642 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
1643 INSTRUCTION_STATE_POOL_MIN_ADDRESS
,
1646 if (result
!= VK_SUCCESS
)
1647 goto fail_dynamic_state_pool
;
1649 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
1650 SURFACE_STATE_POOL_MIN_ADDRESS
,
1653 if (result
!= VK_SUCCESS
)
1654 goto fail_instruction_state_pool
;
1656 if (physical_device
->use_softpin
) {
1657 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
1658 BINDING_TABLE_POOL_MIN_ADDRESS
,
1661 if (result
!= VK_SUCCESS
)
1662 goto fail_surface_state_pool
;
1665 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1666 if (result
!= VK_SUCCESS
)
1667 goto fail_binding_table_pool
;
1669 if (physical_device
->use_softpin
)
1670 device
->workaround_bo
.flags
|= EXEC_OBJECT_PINNED
;
1672 if (!anv_vma_alloc(device
, &device
->workaround_bo
))
1673 goto fail_workaround_bo
;
1675 anv_device_init_trivial_batch(device
);
1677 if (device
->info
.gen
>= 10)
1678 anv_device_init_hiz_clear_batch(device
);
1680 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1682 anv_queue_init(device
, &device
->queue
);
1684 switch (device
->info
.gen
) {
1686 if (!device
->info
.is_haswell
)
1687 result
= gen7_init_device_state(device
);
1689 result
= gen75_init_device_state(device
);
1692 result
= gen8_init_device_state(device
);
1695 result
= gen9_init_device_state(device
);
1698 result
= gen10_init_device_state(device
);
1701 result
= gen11_init_device_state(device
);
1704 /* Shouldn't get here as we don't create physical devices for any other
1706 unreachable("unhandled gen");
1708 if (result
!= VK_SUCCESS
)
1709 goto fail_workaround_bo
;
1711 anv_device_init_blorp(device
);
1713 anv_device_init_border_colors(device
);
1715 *pDevice
= anv_device_to_handle(device
);
1720 anv_queue_finish(&device
->queue
);
1721 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1722 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1723 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1724 fail_binding_table_pool
:
1725 if (physical_device
->use_softpin
)
1726 anv_state_pool_finish(&device
->binding_table_pool
);
1727 fail_surface_state_pool
:
1728 anv_state_pool_finish(&device
->surface_state_pool
);
1729 fail_instruction_state_pool
:
1730 anv_state_pool_finish(&device
->instruction_state_pool
);
1731 fail_dynamic_state_pool
:
1732 anv_state_pool_finish(&device
->dynamic_state_pool
);
1734 anv_bo_cache_finish(&device
->bo_cache
);
1736 anv_bo_pool_finish(&device
->batch_bo_pool
);
1737 pthread_cond_destroy(&device
->queue_submit
);
1739 pthread_mutex_destroy(&device
->mutex
);
1741 anv_gem_destroy_context(device
, device
->context_id
);
1745 vk_free(&device
->alloc
, device
);
1750 void anv_DestroyDevice(
1752 const VkAllocationCallbacks
* pAllocator
)
1754 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1759 anv_device_finish_blorp(device
);
1761 anv_queue_finish(&device
->queue
);
1763 #ifdef HAVE_VALGRIND
1764 /* We only need to free these to prevent valgrind errors. The backing
1765 * BO will go away in a couple of lines so we don't actually leak.
1767 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1770 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1772 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1773 anv_vma_free(device
, &device
->workaround_bo
);
1774 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1776 anv_vma_free(device
, &device
->trivial_batch_bo
);
1777 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1778 if (device
->info
.gen
>= 10)
1779 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
1781 anv_state_pool_finish(&device
->surface_state_pool
);
1782 anv_state_pool_finish(&device
->instruction_state_pool
);
1783 anv_state_pool_finish(&device
->dynamic_state_pool
);
1785 anv_bo_cache_finish(&device
->bo_cache
);
1787 anv_bo_pool_finish(&device
->batch_bo_pool
);
1789 pthread_cond_destroy(&device
->queue_submit
);
1790 pthread_mutex_destroy(&device
->mutex
);
1792 anv_gem_destroy_context(device
, device
->context_id
);
1796 vk_free(&device
->alloc
, device
);
1799 VkResult
anv_EnumerateInstanceLayerProperties(
1800 uint32_t* pPropertyCount
,
1801 VkLayerProperties
* pProperties
)
1803 if (pProperties
== NULL
) {
1804 *pPropertyCount
= 0;
1808 /* None supported at this time */
1809 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1812 VkResult
anv_EnumerateDeviceLayerProperties(
1813 VkPhysicalDevice physicalDevice
,
1814 uint32_t* pPropertyCount
,
1815 VkLayerProperties
* pProperties
)
1817 if (pProperties
== NULL
) {
1818 *pPropertyCount
= 0;
1822 /* None supported at this time */
1823 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1826 void anv_GetDeviceQueue(
1828 uint32_t queueNodeIndex
,
1829 uint32_t queueIndex
,
1832 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1834 assert(queueIndex
== 0);
1836 *pQueue
= anv_queue_to_handle(&device
->queue
);
1839 void anv_GetDeviceQueue2(
1841 const VkDeviceQueueInfo2
* pQueueInfo
,
1844 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1846 assert(pQueueInfo
->queueIndex
== 0);
1848 if (pQueueInfo
->flags
== device
->queue
.flags
)
1849 *pQueue
= anv_queue_to_handle(&device
->queue
);
1855 anv_device_query_status(struct anv_device
*device
)
1857 /* This isn't likely as most of the callers of this function already check
1858 * for it. However, it doesn't hurt to check and it potentially lets us
1861 if (unlikely(device
->lost
))
1862 return VK_ERROR_DEVICE_LOST
;
1864 uint32_t active
, pending
;
1865 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1867 /* We don't know the real error. */
1868 device
->lost
= true;
1869 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1870 "get_reset_stats failed: %m");
1874 device
->lost
= true;
1875 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1876 "GPU hung on one of our command buffers");
1877 } else if (pending
) {
1878 device
->lost
= true;
1879 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1880 "GPU hung with commands in-flight");
1887 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1889 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1890 * Other usages of the BO (such as on different hardware) will not be
1891 * flagged as "busy" by this ioctl. Use with care.
1893 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1895 return VK_NOT_READY
;
1896 } else if (ret
== -1) {
1897 /* We don't know the real error. */
1898 device
->lost
= true;
1899 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1900 "gem wait failed: %m");
1903 /* Query for device status after the busy call. If the BO we're checking
1904 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1905 * client because it clearly doesn't have valid data. Yes, this most
1906 * likely means an ioctl, but we just did an ioctl to query the busy status
1907 * so it's no great loss.
1909 return anv_device_query_status(device
);
1913 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1916 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1917 if (ret
== -1 && errno
== ETIME
) {
1919 } else if (ret
== -1) {
1920 /* We don't know the real error. */
1921 device
->lost
= true;
1922 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1923 "gem wait failed: %m");
1926 /* Query for device status after the wait. If the BO we're waiting on got
1927 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1928 * because it clearly doesn't have valid data. Yes, this most likely means
1929 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1931 return anv_device_query_status(device
);
1934 VkResult
anv_DeviceWaitIdle(
1937 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1938 if (unlikely(device
->lost
))
1939 return VK_ERROR_DEVICE_LOST
;
1941 struct anv_batch batch
;
1944 batch
.start
= batch
.next
= cmds
;
1945 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1947 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1948 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1950 return anv_device_submit_simple_batch(device
, &batch
);
1954 anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
)
1956 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
1959 pthread_mutex_lock(&device
->vma_mutex
);
1963 if (bo
->flags
& EXEC_OBJECT_SUPPORTS_48B_ADDRESS
&&
1964 device
->vma_hi_available
>= bo
->size
) {
1965 uint64_t addr
= util_vma_heap_alloc(&device
->vma_hi
, bo
->size
, 4096);
1967 bo
->offset
= gen_canonical_address(addr
);
1968 assert(addr
== gen_48b_address(bo
->offset
));
1969 device
->vma_hi_available
-= bo
->size
;
1973 if (bo
->offset
== 0 && device
->vma_lo_available
>= bo
->size
) {
1974 uint64_t addr
= util_vma_heap_alloc(&device
->vma_lo
, bo
->size
, 4096);
1976 bo
->offset
= gen_canonical_address(addr
);
1977 assert(addr
== gen_48b_address(bo
->offset
));
1978 device
->vma_lo_available
-= bo
->size
;
1982 pthread_mutex_unlock(&device
->vma_mutex
);
1984 return bo
->offset
!= 0;
1988 anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
)
1990 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
1993 const uint64_t addr_48b
= gen_48b_address(bo
->offset
);
1995 pthread_mutex_lock(&device
->vma_mutex
);
1997 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
1998 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
1999 util_vma_heap_free(&device
->vma_lo
, addr_48b
, bo
->size
);
2000 device
->vma_lo_available
+= bo
->size
;
2002 assert(addr_48b
>= HIGH_HEAP_MIN_ADDRESS
&&
2003 addr_48b
<= HIGH_HEAP_MAX_ADDRESS
);
2004 util_vma_heap_free(&device
->vma_hi
, addr_48b
, bo
->size
);
2005 device
->vma_hi_available
+= bo
->size
;
2008 pthread_mutex_unlock(&device
->vma_mutex
);
2014 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
2016 uint32_t gem_handle
= anv_gem_create(device
, size
);
2018 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2020 anv_bo_init(bo
, gem_handle
, size
);
2025 VkResult
anv_AllocateMemory(
2027 const VkMemoryAllocateInfo
* pAllocateInfo
,
2028 const VkAllocationCallbacks
* pAllocator
,
2029 VkDeviceMemory
* pMem
)
2031 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2032 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2033 struct anv_device_memory
*mem
;
2034 VkResult result
= VK_SUCCESS
;
2036 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2038 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
2039 assert(pAllocateInfo
->allocationSize
> 0);
2041 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
2042 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2044 /* FINISHME: Fail if allocation request exceeds heap size. */
2046 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2047 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2049 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2051 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
2052 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
2056 uint64_t bo_flags
= 0;
2058 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2059 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2060 bo_flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2062 const struct wsi_memory_allocate_info
*wsi_info
=
2063 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2064 if (wsi_info
&& wsi_info
->implicit_sync
) {
2065 /* We need to set the WRITE flag on window system buffers so that GEM
2066 * will know we're writing to them and synchronize uses on other rings
2067 * (eg if the display server uses the blitter ring).
2069 bo_flags
|= EXEC_OBJECT_WRITE
;
2070 } else if (pdevice
->has_exec_async
) {
2071 bo_flags
|= EXEC_OBJECT_ASYNC
;
2074 if (pdevice
->use_softpin
)
2075 bo_flags
|= EXEC_OBJECT_PINNED
;
2077 const VkImportMemoryFdInfoKHR
*fd_info
=
2078 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2080 /* The Vulkan spec permits handleType to be 0, in which case the struct is
2083 if (fd_info
&& fd_info
->handleType
) {
2084 /* At the moment, we support only the below handle types. */
2085 assert(fd_info
->handleType
==
2086 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2087 fd_info
->handleType
==
2088 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2090 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
2091 fd_info
->fd
, bo_flags
, &mem
->bo
);
2092 if (result
!= VK_SUCCESS
)
2095 VkDeviceSize aligned_alloc_size
=
2096 align_u64(pAllocateInfo
->allocationSize
, 4096);
2098 /* For security purposes, we reject importing the bo if it's smaller
2099 * than the requested allocation size. This prevents a malicious client
2100 * from passing a buffer to a trusted client, lying about the size, and
2101 * telling the trusted client to try and texture from an image that goes
2102 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
2103 * in the trusted client. The trusted client can protect itself against
2104 * this sort of attack but only if it can trust the buffer size.
2106 if (mem
->bo
->size
< aligned_alloc_size
) {
2107 result
= vk_errorf(device
->instance
, device
,
2108 VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
,
2109 "aligned allocationSize too large for "
2110 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR: "
2111 "%"PRIu64
"B > %"PRIu64
"B",
2112 aligned_alloc_size
, mem
->bo
->size
);
2113 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2117 /* From the Vulkan spec:
2119 * "Importing memory from a file descriptor transfers ownership of
2120 * the file descriptor from the application to the Vulkan
2121 * implementation. The application must not perform any operations on
2122 * the file descriptor after a successful import."
2124 * If the import fails, we leave the file descriptor open.
2128 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
2129 pAllocateInfo
->allocationSize
, bo_flags
,
2131 if (result
!= VK_SUCCESS
)
2134 const VkMemoryDedicatedAllocateInfoKHR
*dedicated_info
=
2135 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2136 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
2137 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
2139 /* Some legacy (non-modifiers) consumers need the tiling to be set on
2140 * the BO. In this case, we have a dedicated allocation.
2142 if (image
->needs_set_tiling
) {
2143 const uint32_t i915_tiling
=
2144 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
2145 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
2146 image
->planes
[0].surface
.isl
.row_pitch
,
2149 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2150 return vk_errorf(device
->instance
, NULL
,
2151 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
2152 "failed to set BO tiling: %m");
2158 *pMem
= anv_device_memory_to_handle(mem
);
2163 vk_free2(&device
->alloc
, pAllocator
, mem
);
2168 VkResult
anv_GetMemoryFdKHR(
2170 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
2173 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
2174 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
2176 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2178 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2179 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2181 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
2184 VkResult
anv_GetMemoryFdPropertiesKHR(
2186 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
2188 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
2190 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2191 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2193 switch (handleType
) {
2194 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
2195 /* dma-buf can be imported as any memory type */
2196 pMemoryFdProperties
->memoryTypeBits
=
2197 (1 << pdevice
->memory
.type_count
) - 1;
2201 /* The valid usage section for this function says:
2203 * "handleType must not be one of the handle types defined as
2206 * So opaque handle types fall into the default "unsupported" case.
2208 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2212 void anv_FreeMemory(
2214 VkDeviceMemory _mem
,
2215 const VkAllocationCallbacks
* pAllocator
)
2217 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2218 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
2224 anv_UnmapMemory(_device
, _mem
);
2226 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
2228 vk_free2(&device
->alloc
, pAllocator
, mem
);
2231 VkResult
anv_MapMemory(
2233 VkDeviceMemory _memory
,
2234 VkDeviceSize offset
,
2236 VkMemoryMapFlags flags
,
2239 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2240 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2247 if (size
== VK_WHOLE_SIZE
)
2248 size
= mem
->bo
->size
- offset
;
2250 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
2252 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
2253 * assert(size != 0);
2254 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
2255 * equal to the size of the memory minus offset
2258 assert(offset
+ size
<= mem
->bo
->size
);
2260 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
2261 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
2262 * at a time is valid. We could just mmap up front and return an offset
2263 * pointer here, but that may exhaust virtual memory on 32 bit
2266 uint32_t gem_flags
= 0;
2268 if (!device
->info
.has_llc
&&
2269 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
2270 gem_flags
|= I915_MMAP_WC
;
2272 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
2273 uint64_t map_offset
= offset
& ~4095ull;
2274 assert(offset
>= map_offset
);
2275 uint64_t map_size
= (offset
+ size
) - map_offset
;
2277 /* Let's map whole pages */
2278 map_size
= align_u64(map_size
, 4096);
2280 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2281 map_offset
, map_size
, gem_flags
);
2282 if (map
== MAP_FAILED
)
2283 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2286 mem
->map_size
= map_size
;
2288 *ppData
= mem
->map
+ (offset
- map_offset
);
2293 void anv_UnmapMemory(
2295 VkDeviceMemory _memory
)
2297 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2302 anv_gem_munmap(mem
->map
, mem
->map_size
);
2309 clflush_mapped_ranges(struct anv_device
*device
,
2311 const VkMappedMemoryRange
*ranges
)
2313 for (uint32_t i
= 0; i
< count
; i
++) {
2314 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2315 if (ranges
[i
].offset
>= mem
->map_size
)
2318 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2319 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2323 VkResult
anv_FlushMappedMemoryRanges(
2325 uint32_t memoryRangeCount
,
2326 const VkMappedMemoryRange
* pMemoryRanges
)
2328 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2330 if (device
->info
.has_llc
)
2333 /* Make sure the writes we're flushing have landed. */
2334 __builtin_ia32_mfence();
2336 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2341 VkResult
anv_InvalidateMappedMemoryRanges(
2343 uint32_t memoryRangeCount
,
2344 const VkMappedMemoryRange
* pMemoryRanges
)
2346 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2348 if (device
->info
.has_llc
)
2351 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2353 /* Make sure no reads get moved up above the invalidate. */
2354 __builtin_ia32_mfence();
2359 void anv_GetBufferMemoryRequirements(
2362 VkMemoryRequirements
* pMemoryRequirements
)
2364 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2365 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2366 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2368 /* The Vulkan spec (git aaed022) says:
2370 * memoryTypeBits is a bitfield and contains one bit set for every
2371 * supported memory type for the resource. The bit `1<<i` is set if and
2372 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2373 * structure for the physical device is supported.
2375 uint32_t memory_types
= 0;
2376 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2377 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2378 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2379 memory_types
|= (1u << i
);
2382 /* Base alignment requirement of a cache line */
2383 uint32_t alignment
= 16;
2385 /* We need an alignment of 32 for pushing UBOs */
2386 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2387 alignment
= MAX2(alignment
, 32);
2389 pMemoryRequirements
->size
= buffer
->size
;
2390 pMemoryRequirements
->alignment
= alignment
;
2392 /* Storage and Uniform buffers should have their size aligned to
2393 * 32-bits to avoid boundary checks when last DWord is not complete.
2394 * This would ensure that not internal padding would be needed for
2397 if (device
->robust_buffer_access
&&
2398 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
2399 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
2400 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
2402 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2405 void anv_GetBufferMemoryRequirements2(
2407 const VkBufferMemoryRequirementsInfo2
* pInfo
,
2408 VkMemoryRequirements2
* pMemoryRequirements
)
2410 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2411 &pMemoryRequirements
->memoryRequirements
);
2413 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2414 switch (ext
->sType
) {
2415 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2416 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2417 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2418 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2423 anv_debug_ignored_stype(ext
->sType
);
2429 void anv_GetImageMemoryRequirements(
2432 VkMemoryRequirements
* pMemoryRequirements
)
2434 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2435 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2436 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2438 /* The Vulkan spec (git aaed022) says:
2440 * memoryTypeBits is a bitfield and contains one bit set for every
2441 * supported memory type for the resource. The bit `1<<i` is set if and
2442 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2443 * structure for the physical device is supported.
2445 * All types are currently supported for images.
2447 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2449 pMemoryRequirements
->size
= image
->size
;
2450 pMemoryRequirements
->alignment
= image
->alignment
;
2451 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2454 void anv_GetImageMemoryRequirements2(
2456 const VkImageMemoryRequirementsInfo2
* pInfo
,
2457 VkMemoryRequirements2
* pMemoryRequirements
)
2459 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2460 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2462 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2463 &pMemoryRequirements
->memoryRequirements
);
2465 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2466 switch (ext
->sType
) {
2467 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
2468 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2469 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
2470 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
2471 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2472 plane_reqs
->planeAspect
);
2474 assert(image
->planes
[plane
].offset
== 0);
2476 /* The Vulkan spec (git aaed022) says:
2478 * memoryTypeBits is a bitfield and contains one bit set for every
2479 * supported memory type for the resource. The bit `1<<i` is set
2480 * if and only if the memory type `i` in the
2481 * VkPhysicalDeviceMemoryProperties structure for the physical
2482 * device is supported.
2484 * All types are currently supported for images.
2486 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2487 (1ull << pdevice
->memory
.type_count
) - 1;
2489 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2490 pMemoryRequirements
->memoryRequirements
.alignment
=
2491 image
->planes
[plane
].alignment
;
2496 anv_debug_ignored_stype(ext
->sType
);
2501 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2502 switch (ext
->sType
) {
2503 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
2504 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
2505 if (image
->needs_set_tiling
) {
2506 /* If we need to set the tiling for external consumers, we need a
2507 * dedicated allocation.
2509 * See also anv_AllocateMemory.
2511 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2512 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2514 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2515 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2521 anv_debug_ignored_stype(ext
->sType
);
2527 void anv_GetImageSparseMemoryRequirements(
2530 uint32_t* pSparseMemoryRequirementCount
,
2531 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2533 *pSparseMemoryRequirementCount
= 0;
2536 void anv_GetImageSparseMemoryRequirements2(
2538 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
2539 uint32_t* pSparseMemoryRequirementCount
,
2540 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
2542 *pSparseMemoryRequirementCount
= 0;
2545 void anv_GetDeviceMemoryCommitment(
2547 VkDeviceMemory memory
,
2548 VkDeviceSize
* pCommittedMemoryInBytes
)
2550 *pCommittedMemoryInBytes
= 0;
2554 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
2556 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2557 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2559 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
2562 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2563 buffer
->address
= (struct anv_address
) {
2565 .offset
= pBindInfo
->memoryOffset
,
2568 buffer
->address
= ANV_NULL_ADDRESS
;
2572 VkResult
anv_BindBufferMemory(
2575 VkDeviceMemory memory
,
2576 VkDeviceSize memoryOffset
)
2578 anv_bind_buffer_memory(
2579 &(VkBindBufferMemoryInfo
) {
2580 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2583 .memoryOffset
= memoryOffset
,
2589 VkResult
anv_BindBufferMemory2(
2591 uint32_t bindInfoCount
,
2592 const VkBindBufferMemoryInfo
* pBindInfos
)
2594 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2595 anv_bind_buffer_memory(&pBindInfos
[i
]);
2600 VkResult
anv_QueueBindSparse(
2602 uint32_t bindInfoCount
,
2603 const VkBindSparseInfo
* pBindInfo
,
2606 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2607 if (unlikely(queue
->device
->lost
))
2608 return VK_ERROR_DEVICE_LOST
;
2610 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2615 VkResult
anv_CreateEvent(
2617 const VkEventCreateInfo
* pCreateInfo
,
2618 const VkAllocationCallbacks
* pAllocator
,
2621 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2622 struct anv_state state
;
2623 struct anv_event
*event
;
2625 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2627 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2630 event
->state
= state
;
2631 event
->semaphore
= VK_EVENT_RESET
;
2633 if (!device
->info
.has_llc
) {
2634 /* Make sure the writes we're flushing have landed. */
2635 __builtin_ia32_mfence();
2636 __builtin_ia32_clflush(event
);
2639 *pEvent
= anv_event_to_handle(event
);
2644 void anv_DestroyEvent(
2647 const VkAllocationCallbacks
* pAllocator
)
2649 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2650 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2655 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2658 VkResult
anv_GetEventStatus(
2662 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2663 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2665 if (unlikely(device
->lost
))
2666 return VK_ERROR_DEVICE_LOST
;
2668 if (!device
->info
.has_llc
) {
2669 /* Invalidate read cache before reading event written by GPU. */
2670 __builtin_ia32_clflush(event
);
2671 __builtin_ia32_mfence();
2675 return event
->semaphore
;
2678 VkResult
anv_SetEvent(
2682 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2683 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2685 event
->semaphore
= VK_EVENT_SET
;
2687 if (!device
->info
.has_llc
) {
2688 /* Make sure the writes we're flushing have landed. */
2689 __builtin_ia32_mfence();
2690 __builtin_ia32_clflush(event
);
2696 VkResult
anv_ResetEvent(
2700 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2701 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2703 event
->semaphore
= VK_EVENT_RESET
;
2705 if (!device
->info
.has_llc
) {
2706 /* Make sure the writes we're flushing have landed. */
2707 __builtin_ia32_mfence();
2708 __builtin_ia32_clflush(event
);
2716 VkResult
anv_CreateBuffer(
2718 const VkBufferCreateInfo
* pCreateInfo
,
2719 const VkAllocationCallbacks
* pAllocator
,
2722 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2723 struct anv_buffer
*buffer
;
2725 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2727 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2728 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2730 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2732 buffer
->size
= pCreateInfo
->size
;
2733 buffer
->usage
= pCreateInfo
->usage
;
2734 buffer
->address
= ANV_NULL_ADDRESS
;
2736 *pBuffer
= anv_buffer_to_handle(buffer
);
2741 void anv_DestroyBuffer(
2744 const VkAllocationCallbacks
* pAllocator
)
2746 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2747 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2752 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2756 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2757 enum isl_format format
,
2758 struct anv_address address
,
2759 uint32_t range
, uint32_t stride
)
2761 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2762 .address
= anv_address_physical(address
),
2763 .mocs
= device
->default_mocs
,
2768 anv_state_flush(device
, state
);
2771 void anv_DestroySampler(
2774 const VkAllocationCallbacks
* pAllocator
)
2776 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2777 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2782 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2785 VkResult
anv_CreateFramebuffer(
2787 const VkFramebufferCreateInfo
* pCreateInfo
,
2788 const VkAllocationCallbacks
* pAllocator
,
2789 VkFramebuffer
* pFramebuffer
)
2791 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2792 struct anv_framebuffer
*framebuffer
;
2794 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2796 size_t size
= sizeof(*framebuffer
) +
2797 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2798 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2799 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2800 if (framebuffer
== NULL
)
2801 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2803 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2804 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2805 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2806 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2809 framebuffer
->width
= pCreateInfo
->width
;
2810 framebuffer
->height
= pCreateInfo
->height
;
2811 framebuffer
->layers
= pCreateInfo
->layers
;
2813 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2818 void anv_DestroyFramebuffer(
2821 const VkAllocationCallbacks
* pAllocator
)
2823 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2824 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2829 vk_free2(&device
->alloc
, pAllocator
, fb
);
2832 /* vk_icd.h does not declare this function, so we declare it here to
2833 * suppress Wmissing-prototypes.
2835 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2836 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2838 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2839 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2841 /* For the full details on loader interface versioning, see
2842 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2843 * What follows is a condensed summary, to help you navigate the large and
2844 * confusing official doc.
2846 * - Loader interface v0 is incompatible with later versions. We don't
2849 * - In loader interface v1:
2850 * - The first ICD entrypoint called by the loader is
2851 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2853 * - The ICD must statically expose no other Vulkan symbol unless it is
2854 * linked with -Bsymbolic.
2855 * - Each dispatchable Vulkan handle created by the ICD must be
2856 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2857 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2858 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2859 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2860 * such loader-managed surfaces.
2862 * - Loader interface v2 differs from v1 in:
2863 * - The first ICD entrypoint called by the loader is
2864 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2865 * statically expose this entrypoint.
2867 * - Loader interface v3 differs from v2 in:
2868 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2869 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2870 * because the loader no longer does so.
2872 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);