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 *heap_size
)
64 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
66 /* If, for whatever reason, we can't actually get the GTT size from the
67 * kernel (too old?) fall back to the aperture size.
69 anv_perf_warn(NULL
, NULL
,
70 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
72 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
73 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
74 "failed to get aperture size: %m");
78 /* Query the total ram from the system */
82 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
84 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
85 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
87 uint64_t available_ram
;
88 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
89 available_ram
= total_ram
/ 2;
91 available_ram
= total_ram
* 3 / 4;
93 /* We also want to leave some padding for things we allocate in the driver,
94 * so don't go over 3/4 of the GTT either.
96 uint64_t available_gtt
= gtt_size
* 3 / 4;
98 *heap_size
= MIN2(available_ram
, available_gtt
);
104 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
106 /* The kernel query only tells us whether or not the kernel supports the
107 * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
108 * hardware has actual 48bit address support.
110 device
->supports_48bit_addresses
=
111 (device
->info
.gen
>= 8) && anv_gem_supports_48b_addresses(fd
);
114 VkResult result
= anv_compute_heap_size(fd
, &heap_size
);
115 if (result
!= VK_SUCCESS
)
118 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
119 /* When running with an overridden PCI ID, we may get a GTT size from
120 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
121 * address support can still fail. Just clamp the address space size to
122 * 2 GiB if we don't have 48-bit support.
124 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
125 "not support for 48-bit addresses",
127 heap_size
= 2ull << 30;
130 if (heap_size
<= 3ull * (1ull << 30)) {
131 /* In this case, everything fits nicely into the 32-bit address space,
132 * so there's no need for supporting 48bit addresses on client-allocated
135 device
->memory
.heap_count
= 1;
136 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
138 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
139 .supports_48bit_addresses
= false,
142 /* Not everything will fit nicely into a 32-bit address space. In this
143 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
144 * larger 48-bit heap. If we're in this case, then we have a total heap
145 * size larger than 3GiB which most likely means they have 8 GiB of
146 * video memory and so carving off 1 GiB for the 32-bit heap should be
149 const uint64_t heap_size_32bit
= 1ull << 30;
150 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
152 assert(device
->supports_48bit_addresses
);
154 device
->memory
.heap_count
= 2;
155 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
156 .size
= heap_size_48bit
,
157 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
158 .supports_48bit_addresses
= true,
160 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
161 .size
= heap_size_32bit
,
162 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
163 .supports_48bit_addresses
= false,
167 uint32_t type_count
= 0;
168 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
169 uint32_t valid_buffer_usage
= ~0;
171 /* There appears to be a hardware issue in the VF cache where it only
172 * considers the bottom 32 bits of memory addresses. If you happen to
173 * have two vertex buffers which get placed exactly 4 GiB apart and use
174 * them in back-to-back draw calls, you can get collisions. In order to
175 * solve this problem, we require vertex and index buffers be bound to
176 * memory allocated out of the 32-bit heap.
178 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
179 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
180 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
183 if (device
->info
.has_llc
) {
184 /* Big core GPUs share LLC with the CPU and thus one memory type can be
185 * both cached and coherent at the same time.
187 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
188 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
189 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
191 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
193 .valid_buffer_usage
= valid_buffer_usage
,
196 /* The spec requires that we expose a host-visible, coherent memory
197 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
198 * to give the application a choice between cached, but not coherent and
199 * coherent but uncached (WC though).
201 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
202 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
203 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
204 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
206 .valid_buffer_usage
= valid_buffer_usage
,
208 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
209 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
210 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
211 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
213 .valid_buffer_usage
= valid_buffer_usage
,
217 device
->memory
.type_count
= type_count
;
223 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
225 const struct build_id_note
*note
=
226 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
228 return vk_errorf(device
->instance
, device
,
229 VK_ERROR_INITIALIZATION_FAILED
,
230 "Failed to find build-id");
233 unsigned build_id_len
= build_id_length(note
);
234 if (build_id_len
< 20) {
235 return vk_errorf(device
->instance
, device
,
236 VK_ERROR_INITIALIZATION_FAILED
,
237 "build-id too short. It needs to be a SHA");
240 struct mesa_sha1 sha1_ctx
;
242 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
244 /* The pipeline cache UUID is used for determining when a pipeline cache is
245 * invalid. It needs both a driver build and the PCI ID of the device.
247 _mesa_sha1_init(&sha1_ctx
);
248 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
249 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
250 sizeof(device
->chipset_id
));
251 _mesa_sha1_final(&sha1_ctx
, sha1
);
252 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
254 /* The driver UUID is used for determining sharability of images and memory
255 * between two Vulkan instances in separate processes. People who want to
256 * share memory need to also check the device UUID (below) so all this
257 * needs to be is the build-id.
259 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
261 /* The device UUID uniquely identifies the given device within the machine.
262 * Since we never have more than one device, this doesn't need to be a real
263 * UUID. However, on the off-chance that someone tries to use this to
264 * cache pre-tiled images or something of the like, we use the PCI ID and
265 * some bits of ISL info to ensure that this is safe.
267 _mesa_sha1_init(&sha1_ctx
);
268 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
269 sizeof(device
->chipset_id
));
270 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
271 sizeof(device
->isl_dev
.has_bit6_swizzling
));
272 _mesa_sha1_final(&sha1_ctx
, sha1
);
273 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
279 anv_physical_device_init(struct anv_physical_device
*device
,
280 struct anv_instance
*instance
,
286 brw_process_intel_debug_variable();
288 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
290 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
292 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
293 device
->instance
= instance
;
295 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
296 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
298 device
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
300 const int pci_id_override
= gen_get_pci_device_id_override();
301 if (pci_id_override
< 0) {
302 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
303 if (!device
->chipset_id
) {
304 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
308 device
->chipset_id
= pci_id_override
;
309 device
->no_hw
= true;
312 device
->name
= gen_get_device_name(device
->chipset_id
);
313 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
314 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
318 if (device
->info
.is_haswell
) {
319 intel_logw("Haswell Vulkan support is incomplete");
320 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
321 intel_logw("Ivy Bridge Vulkan support is incomplete");
322 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
323 intel_logw("Bay Trail Vulkan support is incomplete");
324 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 10) {
325 /* Gen8-10 fully supported */
327 result
= vk_errorf(device
->instance
, device
,
328 VK_ERROR_INCOMPATIBLE_DRIVER
,
329 "Vulkan not yet supported on %s", device
->name
);
333 device
->cmd_parser_version
= -1;
334 if (device
->info
.gen
== 7) {
335 device
->cmd_parser_version
=
336 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
337 if (device
->cmd_parser_version
== -1) {
338 result
= vk_errorf(device
->instance
, device
,
339 VK_ERROR_INITIALIZATION_FAILED
,
340 "failed to get command parser version");
345 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
346 result
= vk_errorf(device
->instance
, device
,
347 VK_ERROR_INITIALIZATION_FAILED
,
348 "kernel missing gem wait");
352 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
353 result
= vk_errorf(device
->instance
, device
,
354 VK_ERROR_INITIALIZATION_FAILED
,
355 "kernel missing execbuf2");
359 if (!device
->info
.has_llc
&&
360 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
361 result
= vk_errorf(device
->instance
, device
,
362 VK_ERROR_INITIALIZATION_FAILED
,
363 "kernel missing wc mmap");
367 result
= anv_physical_device_init_heaps(device
, fd
);
368 if (result
!= VK_SUCCESS
)
371 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
372 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
373 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
374 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
375 device
->has_syncobj_wait
= device
->has_syncobj
&&
376 anv_gem_supports_syncobj_wait(fd
);
378 if (anv_gem_has_context_priority(fd
))
379 device
->has_context_priority
= true;
381 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
383 /* Starting with Gen10, the timestamp frequency of the command streamer may
384 * vary from one part to another. We can query the value from the kernel.
386 if (device
->info
.gen
>= 10) {
387 int timestamp_frequency
=
388 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
390 if (timestamp_frequency
< 0)
391 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
393 device
->info
.timestamp_frequency
= timestamp_frequency
;
396 /* GENs prior to 8 do not support EU/Subslice info */
397 if (device
->info
.gen
>= 8) {
398 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
399 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
401 /* Without this information, we cannot get the right Braswell
402 * brandstrings, and we have to use conservative numbers for GPGPU on
403 * many platforms, but otherwise, things will just work.
405 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
406 intel_logw("Kernel 4.1 required to properly query GPU properties");
408 } else if (device
->info
.gen
== 7) {
409 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
412 if (device
->info
.is_cherryview
&&
413 device
->subslice_total
> 0 && device
->eu_total
> 0) {
414 /* Logical CS threads = EUs per subslice * num threads per EU */
415 uint32_t max_cs_threads
=
416 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
418 /* Fuse configurations may give more threads than expected, never less. */
419 if (max_cs_threads
> device
->info
.max_cs_threads
)
420 device
->info
.max_cs_threads
= max_cs_threads
;
423 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
424 if (device
->compiler
== NULL
) {
425 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
428 device
->compiler
->shader_debug_log
= compiler_debug_log
;
429 device
->compiler
->shader_perf_log
= compiler_perf_log
;
430 device
->compiler
->supports_pull_constants
= false;
431 device
->compiler
->constant_buffer_0_is_relative
= true;
433 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
435 result
= anv_physical_device_init_uuids(device
);
436 if (result
!= VK_SUCCESS
)
439 result
= anv_init_wsi(device
);
440 if (result
!= VK_SUCCESS
) {
441 ralloc_free(device
->compiler
);
445 anv_physical_device_get_supported_extensions(device
,
446 &device
->supported_extensions
);
448 device
->local_fd
= fd
;
457 anv_physical_device_finish(struct anv_physical_device
*device
)
459 anv_finish_wsi(device
);
460 ralloc_free(device
->compiler
);
461 close(device
->local_fd
);
465 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
466 VkSystemAllocationScope allocationScope
)
472 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
473 size_t align
, VkSystemAllocationScope allocationScope
)
475 return realloc(pOriginal
, size
);
479 default_free_func(void *pUserData
, void *pMemory
)
484 static const VkAllocationCallbacks default_alloc
= {
486 .pfnAllocation
= default_alloc_func
,
487 .pfnReallocation
= default_realloc_func
,
488 .pfnFree
= default_free_func
,
491 VkResult
anv_EnumerateInstanceExtensionProperties(
492 const char* pLayerName
,
493 uint32_t* pPropertyCount
,
494 VkExtensionProperties
* pProperties
)
496 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
498 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
499 if (anv_instance_extensions_supported
.extensions
[i
]) {
500 vk_outarray_append(&out
, prop
) {
501 *prop
= anv_instance_extensions
[i
];
506 return vk_outarray_status(&out
);
509 VkResult
anv_CreateInstance(
510 const VkInstanceCreateInfo
* pCreateInfo
,
511 const VkAllocationCallbacks
* pAllocator
,
512 VkInstance
* pInstance
)
514 struct anv_instance
*instance
;
517 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
519 /* Check if user passed a debug report callback to be used during
520 * Create/Destroy of instance.
522 const VkDebugReportCallbackCreateInfoEXT
*ctor_cb
=
523 vk_find_struct_const(pCreateInfo
->pNext
,
524 DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
);
526 uint32_t client_version
;
527 if (pCreateInfo
->pApplicationInfo
&&
528 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
529 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
531 client_version
= VK_MAKE_VERSION(1, 0, 0);
534 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
535 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
537 if (ctor_cb
&& ctor_cb
->flags
& VK_DEBUG_REPORT_ERROR_BIT_EXT
)
538 ctor_cb
->pfnCallback(VK_DEBUG_REPORT_ERROR_BIT_EXT
,
539 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
,
540 VK_NULL_HANDLE
, /* No handle available yet. */
544 "incompatible driver version",
547 return vk_errorf(NULL
, NULL
, VK_ERROR_INCOMPATIBLE_DRIVER
,
548 "Client requested version %d.%d.%d",
549 VK_VERSION_MAJOR(client_version
),
550 VK_VERSION_MINOR(client_version
),
551 VK_VERSION_PATCH(client_version
));
554 struct anv_instance_extension_table enabled_extensions
= {};
555 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
557 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
558 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
559 anv_instance_extensions
[idx
].extensionName
) == 0)
563 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
564 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
566 if (!anv_instance_extensions_supported
.extensions
[idx
])
567 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
569 enabled_extensions
.extensions
[idx
] = true;
572 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
573 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
575 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
577 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
580 instance
->alloc
= *pAllocator
;
582 instance
->alloc
= default_alloc
;
584 instance
->apiVersion
= client_version
;
585 instance
->enabled_extensions
= enabled_extensions
;
587 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
588 /* Vulkan requires that entrypoints for extensions which have not been
589 * enabled must not be advertised.
591 if (!anv_entrypoint_is_enabled(i
, instance
->apiVersion
,
592 &instance
->enabled_extensions
, NULL
)) {
593 instance
->dispatch
.entrypoints
[i
] = NULL
;
594 } else if (anv_dispatch_table
.entrypoints
[i
] != NULL
) {
595 instance
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
597 instance
->dispatch
.entrypoints
[i
] =
598 anv_tramp_dispatch_table
.entrypoints
[i
];
602 instance
->physicalDeviceCount
= -1;
604 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
605 if (result
!= VK_SUCCESS
) {
606 vk_free2(&default_alloc
, pAllocator
, instance
);
607 return vk_error(result
);
612 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
614 *pInstance
= anv_instance_to_handle(instance
);
619 void anv_DestroyInstance(
620 VkInstance _instance
,
621 const VkAllocationCallbacks
* pAllocator
)
623 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
628 if (instance
->physicalDeviceCount
> 0) {
629 /* We support at most one physical device. */
630 assert(instance
->physicalDeviceCount
== 1);
631 anv_physical_device_finish(&instance
->physicalDevice
);
634 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
636 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
640 vk_free(&instance
->alloc
, instance
);
644 anv_enumerate_devices(struct anv_instance
*instance
)
646 /* TODO: Check for more devices ? */
647 drmDevicePtr devices
[8];
648 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
651 instance
->physicalDeviceCount
= 0;
653 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
655 return VK_ERROR_INCOMPATIBLE_DRIVER
;
657 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
658 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
659 devices
[i
]->bustype
== DRM_BUS_PCI
&&
660 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
662 result
= anv_physical_device_init(&instance
->physicalDevice
,
664 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
665 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
669 drmFreeDevices(devices
, max_devices
);
671 if (result
== VK_SUCCESS
)
672 instance
->physicalDeviceCount
= 1;
678 VkResult
anv_EnumeratePhysicalDevices(
679 VkInstance _instance
,
680 uint32_t* pPhysicalDeviceCount
,
681 VkPhysicalDevice
* pPhysicalDevices
)
683 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
684 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
687 if (instance
->physicalDeviceCount
< 0) {
688 result
= anv_enumerate_devices(instance
);
689 if (result
!= VK_SUCCESS
&&
690 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
694 if (instance
->physicalDeviceCount
> 0) {
695 assert(instance
->physicalDeviceCount
== 1);
696 vk_outarray_append(&out
, i
) {
697 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
701 return vk_outarray_status(&out
);
704 void anv_GetPhysicalDeviceFeatures(
705 VkPhysicalDevice physicalDevice
,
706 VkPhysicalDeviceFeatures
* pFeatures
)
708 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
710 *pFeatures
= (VkPhysicalDeviceFeatures
) {
711 .robustBufferAccess
= true,
712 .fullDrawIndexUint32
= true,
713 .imageCubeArray
= true,
714 .independentBlend
= true,
715 .geometryShader
= true,
716 .tessellationShader
= true,
717 .sampleRateShading
= true,
718 .dualSrcBlend
= true,
720 .multiDrawIndirect
= true,
721 .drawIndirectFirstInstance
= true,
723 .depthBiasClamp
= true,
724 .fillModeNonSolid
= true,
725 .depthBounds
= false,
729 .multiViewport
= true,
730 .samplerAnisotropy
= true,
731 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
732 pdevice
->info
.is_baytrail
,
733 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
734 .textureCompressionBC
= true,
735 .occlusionQueryPrecise
= true,
736 .pipelineStatisticsQuery
= true,
737 .fragmentStoresAndAtomics
= true,
738 .shaderTessellationAndGeometryPointSize
= true,
739 .shaderImageGatherExtended
= true,
740 .shaderStorageImageExtendedFormats
= true,
741 .shaderStorageImageMultisample
= false,
742 .shaderStorageImageReadWithoutFormat
= false,
743 .shaderStorageImageWriteWithoutFormat
= true,
744 .shaderUniformBufferArrayDynamicIndexing
= true,
745 .shaderSampledImageArrayDynamicIndexing
= true,
746 .shaderStorageBufferArrayDynamicIndexing
= true,
747 .shaderStorageImageArrayDynamicIndexing
= true,
748 .shaderClipDistance
= true,
749 .shaderCullDistance
= true,
750 .shaderFloat64
= pdevice
->info
.gen
>= 8,
751 .shaderInt64
= pdevice
->info
.gen
>= 8,
752 .shaderInt16
= false,
753 .shaderResourceMinLod
= false,
754 .variableMultisampleRate
= false,
755 .inheritedQueries
= true,
758 /* We can't do image stores in vec4 shaders */
759 pFeatures
->vertexPipelineStoresAndAtomics
=
760 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
761 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
764 void anv_GetPhysicalDeviceFeatures2KHR(
765 VkPhysicalDevice physicalDevice
,
766 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
768 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
770 vk_foreach_struct(ext
, pFeatures
->pNext
) {
771 switch (ext
->sType
) {
772 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
773 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
774 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
775 features
->multiview
= true;
776 features
->multiviewGeometryShader
= true;
777 features
->multiviewTessellationShader
= true;
781 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
782 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
783 features
->variablePointersStorageBuffer
= true;
784 features
->variablePointers
= true;
788 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR
: {
789 VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*features
=
790 (VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*) ext
;
791 features
->samplerYcbcrConversion
= true;
795 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
: {
796 VkPhysicalDevice16BitStorageFeaturesKHR
*features
=
797 (VkPhysicalDevice16BitStorageFeaturesKHR
*)ext
;
799 features
->storageBuffer16BitAccess
= false;
800 features
->uniformAndStorageBuffer16BitAccess
= false;
801 features
->storagePushConstant16
= false;
802 features
->storageInputOutput16
= false;
807 anv_debug_ignored_stype(ext
->sType
);
813 void anv_GetPhysicalDeviceProperties(
814 VkPhysicalDevice physicalDevice
,
815 VkPhysicalDeviceProperties
* pProperties
)
817 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
818 const struct gen_device_info
*devinfo
= &pdevice
->info
;
820 /* See assertions made when programming the buffer surface state. */
821 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
822 (1ul << 30) : (1ul << 27);
824 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
827 VkSampleCountFlags sample_counts
=
828 isl_device_get_sample_counts(&pdevice
->isl_dev
);
830 VkPhysicalDeviceLimits limits
= {
831 .maxImageDimension1D
= (1 << 14),
832 .maxImageDimension2D
= (1 << 14),
833 .maxImageDimension3D
= (1 << 11),
834 .maxImageDimensionCube
= (1 << 14),
835 .maxImageArrayLayers
= (1 << 11),
836 .maxTexelBufferElements
= 128 * 1024 * 1024,
837 .maxUniformBufferRange
= (1ul << 27),
838 .maxStorageBufferRange
= max_raw_buffer_sz
,
839 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
840 .maxMemoryAllocationCount
= UINT32_MAX
,
841 .maxSamplerAllocationCount
= 64 * 1024,
842 .bufferImageGranularity
= 64, /* A cache line */
843 .sparseAddressSpaceSize
= 0,
844 .maxBoundDescriptorSets
= MAX_SETS
,
845 .maxPerStageDescriptorSamplers
= max_samplers
,
846 .maxPerStageDescriptorUniformBuffers
= 64,
847 .maxPerStageDescriptorStorageBuffers
= 64,
848 .maxPerStageDescriptorSampledImages
= max_samplers
,
849 .maxPerStageDescriptorStorageImages
= 64,
850 .maxPerStageDescriptorInputAttachments
= 64,
851 .maxPerStageResources
= 250,
852 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
853 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
854 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
855 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
856 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
857 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
858 .maxDescriptorSetStorageImages
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
859 .maxDescriptorSetInputAttachments
= 256,
860 .maxVertexInputAttributes
= MAX_VBS
,
861 .maxVertexInputBindings
= MAX_VBS
,
862 .maxVertexInputAttributeOffset
= 2047,
863 .maxVertexInputBindingStride
= 2048,
864 .maxVertexOutputComponents
= 128,
865 .maxTessellationGenerationLevel
= 64,
866 .maxTessellationPatchSize
= 32,
867 .maxTessellationControlPerVertexInputComponents
= 128,
868 .maxTessellationControlPerVertexOutputComponents
= 128,
869 .maxTessellationControlPerPatchOutputComponents
= 128,
870 .maxTessellationControlTotalOutputComponents
= 2048,
871 .maxTessellationEvaluationInputComponents
= 128,
872 .maxTessellationEvaluationOutputComponents
= 128,
873 .maxGeometryShaderInvocations
= 32,
874 .maxGeometryInputComponents
= 64,
875 .maxGeometryOutputComponents
= 128,
876 .maxGeometryOutputVertices
= 256,
877 .maxGeometryTotalOutputComponents
= 1024,
878 .maxFragmentInputComponents
= 128,
879 .maxFragmentOutputAttachments
= 8,
880 .maxFragmentDualSrcAttachments
= 1,
881 .maxFragmentCombinedOutputResources
= 8,
882 .maxComputeSharedMemorySize
= 32768,
883 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
884 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
885 .maxComputeWorkGroupSize
= {
886 16 * devinfo
->max_cs_threads
,
887 16 * devinfo
->max_cs_threads
,
888 16 * devinfo
->max_cs_threads
,
890 .subPixelPrecisionBits
= 4 /* FIXME */,
891 .subTexelPrecisionBits
= 4 /* FIXME */,
892 .mipmapPrecisionBits
= 4 /* FIXME */,
893 .maxDrawIndexedIndexValue
= UINT32_MAX
,
894 .maxDrawIndirectCount
= UINT32_MAX
,
895 .maxSamplerLodBias
= 16,
896 .maxSamplerAnisotropy
= 16,
897 .maxViewports
= MAX_VIEWPORTS
,
898 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
899 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
900 .viewportSubPixelBits
= 13, /* We take a float? */
901 .minMemoryMapAlignment
= 4096, /* A page */
902 .minTexelBufferOffsetAlignment
= 1,
903 /* We need 16 for UBO block reads to work and 32 for push UBOs */
904 .minUniformBufferOffsetAlignment
= 32,
905 .minStorageBufferOffsetAlignment
= 4,
906 .minTexelOffset
= -8,
908 .minTexelGatherOffset
= -32,
909 .maxTexelGatherOffset
= 31,
910 .minInterpolationOffset
= -0.5,
911 .maxInterpolationOffset
= 0.4375,
912 .subPixelInterpolationOffsetBits
= 4,
913 .maxFramebufferWidth
= (1 << 14),
914 .maxFramebufferHeight
= (1 << 14),
915 .maxFramebufferLayers
= (1 << 11),
916 .framebufferColorSampleCounts
= sample_counts
,
917 .framebufferDepthSampleCounts
= sample_counts
,
918 .framebufferStencilSampleCounts
= sample_counts
,
919 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
920 .maxColorAttachments
= MAX_RTS
,
921 .sampledImageColorSampleCounts
= sample_counts
,
922 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
923 .sampledImageDepthSampleCounts
= sample_counts
,
924 .sampledImageStencilSampleCounts
= sample_counts
,
925 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
926 .maxSampleMaskWords
= 1,
927 .timestampComputeAndGraphics
= false,
928 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
929 .maxClipDistances
= 8,
930 .maxCullDistances
= 8,
931 .maxCombinedClipAndCullDistances
= 8,
932 .discreteQueuePriorities
= 1,
933 .pointSizeRange
= { 0.125, 255.875 },
934 .lineWidthRange
= { 0.0, 7.9921875 },
935 .pointSizeGranularity
= (1.0 / 8.0),
936 .lineWidthGranularity
= (1.0 / 128.0),
937 .strictLines
= false, /* FINISHME */
938 .standardSampleLocations
= true,
939 .optimalBufferCopyOffsetAlignment
= 128,
940 .optimalBufferCopyRowPitchAlignment
= 128,
941 .nonCoherentAtomSize
= 64,
944 *pProperties
= (VkPhysicalDeviceProperties
) {
945 .apiVersion
= anv_physical_device_api_version(pdevice
),
946 .driverVersion
= vk_get_driver_version(),
948 .deviceID
= pdevice
->chipset_id
,
949 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
951 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
954 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
955 "%s", pdevice
->name
);
956 memcpy(pProperties
->pipelineCacheUUID
,
957 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
960 void anv_GetPhysicalDeviceProperties2KHR(
961 VkPhysicalDevice physicalDevice
,
962 VkPhysicalDeviceProperties2KHR
* pProperties
)
964 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
966 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
968 vk_foreach_struct(ext
, pProperties
->pNext
) {
969 switch (ext
->sType
) {
970 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
971 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
972 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
974 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
978 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
979 VkPhysicalDeviceIDPropertiesKHR
*id_props
=
980 (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
981 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
982 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
983 /* The LUID is for Windows. */
984 id_props
->deviceLUIDValid
= false;
988 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
989 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
990 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
991 properties
->maxMultiviewViewCount
= 16;
992 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
996 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
997 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
998 (VkPhysicalDevicePointClippingPropertiesKHR
*) ext
;
999 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
1000 anv_finishme("Implement pop-free point clipping");
1005 anv_debug_ignored_stype(ext
->sType
);
1011 /* We support exactly one queue family. */
1012 static const VkQueueFamilyProperties
1013 anv_queue_family_properties
= {
1014 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1015 VK_QUEUE_COMPUTE_BIT
|
1016 VK_QUEUE_TRANSFER_BIT
,
1018 .timestampValidBits
= 36, /* XXX: Real value here */
1019 .minImageTransferGranularity
= { 1, 1, 1 },
1022 void anv_GetPhysicalDeviceQueueFamilyProperties(
1023 VkPhysicalDevice physicalDevice
,
1025 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1027 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1029 vk_outarray_append(&out
, p
) {
1030 *p
= anv_queue_family_properties
;
1034 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
1035 VkPhysicalDevice physicalDevice
,
1036 uint32_t* pQueueFamilyPropertyCount
,
1037 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
1040 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1042 vk_outarray_append(&out
, p
) {
1043 p
->queueFamilyProperties
= anv_queue_family_properties
;
1045 vk_foreach_struct(s
, p
->pNext
) {
1046 anv_debug_ignored_stype(s
->sType
);
1051 void anv_GetPhysicalDeviceMemoryProperties(
1052 VkPhysicalDevice physicalDevice
,
1053 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1055 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1057 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1058 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1059 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1060 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1061 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1065 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1066 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1067 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1068 .size
= physical_device
->memory
.heaps
[i
].size
,
1069 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1074 void anv_GetPhysicalDeviceMemoryProperties2KHR(
1075 VkPhysicalDevice physicalDevice
,
1076 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
1078 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1079 &pMemoryProperties
->memoryProperties
);
1081 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1082 switch (ext
->sType
) {
1084 anv_debug_ignored_stype(ext
->sType
);
1090 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1091 VkInstance _instance
,
1094 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1096 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1097 * when we have to return valid function pointers, NULL, or it's left
1098 * undefined. See the table for exact details.
1103 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1104 if (strcmp(pName, "vk" #entrypoint) == 0) \
1105 return (PFN_vkVoidFunction)anv_##entrypoint
1107 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1108 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1109 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1111 #undef LOOKUP_ANV_ENTRYPOINT
1113 if (instance
== NULL
)
1116 int idx
= anv_get_entrypoint_index(pName
);
1120 return instance
->dispatch
.entrypoints
[idx
];
1123 /* With version 1+ of the loader interface the ICD should expose
1124 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1127 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1128 VkInstance instance
,
1132 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1133 VkInstance instance
,
1136 return anv_GetInstanceProcAddr(instance
, pName
);
1139 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1143 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1145 if (!device
|| !pName
)
1148 int idx
= anv_get_entrypoint_index(pName
);
1152 return device
->dispatch
.entrypoints
[idx
];
1156 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1157 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1158 const VkAllocationCallbacks
* pAllocator
,
1159 VkDebugReportCallbackEXT
* pCallback
)
1161 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1162 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1163 pCreateInfo
, pAllocator
, &instance
->alloc
,
1168 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1169 VkDebugReportCallbackEXT _callback
,
1170 const VkAllocationCallbacks
* pAllocator
)
1172 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1173 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1174 _callback
, pAllocator
, &instance
->alloc
);
1178 anv_DebugReportMessageEXT(VkInstance _instance
,
1179 VkDebugReportFlagsEXT flags
,
1180 VkDebugReportObjectTypeEXT objectType
,
1183 int32_t messageCode
,
1184 const char* pLayerPrefix
,
1185 const char* pMessage
)
1187 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1188 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1189 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1193 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1195 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1196 queue
->device
= device
;
1197 queue
->pool
= &device
->surface_state_pool
;
1201 anv_queue_finish(struct anv_queue
*queue
)
1205 static struct anv_state
1206 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1208 struct anv_state state
;
1210 state
= anv_state_pool_alloc(pool
, size
, align
);
1211 memcpy(state
.map
, p
, size
);
1213 anv_state_flush(pool
->block_pool
.device
, state
);
1218 struct gen8_border_color
{
1223 /* Pad out to 64 bytes */
1228 anv_device_init_border_colors(struct anv_device
*device
)
1230 static const struct gen8_border_color border_colors
[] = {
1231 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1232 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1233 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1234 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1235 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1236 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1239 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1240 sizeof(border_colors
), 64,
1245 anv_device_init_trivial_batch(struct anv_device
*device
)
1247 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1249 if (device
->instance
->physicalDevice
.has_exec_async
)
1250 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1252 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1255 struct anv_batch batch
= {
1261 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1262 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1264 if (!device
->info
.has_llc
)
1265 gen_clflush_range(map
, batch
.next
- map
);
1267 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1270 VkResult
anv_EnumerateDeviceExtensionProperties(
1271 VkPhysicalDevice physicalDevice
,
1272 const char* pLayerName
,
1273 uint32_t* pPropertyCount
,
1274 VkExtensionProperties
* pProperties
)
1276 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1277 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1280 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1281 if (device
->supported_extensions
.extensions
[i
]) {
1282 vk_outarray_append(&out
, prop
) {
1283 *prop
= anv_device_extensions
[i
];
1288 return vk_outarray_status(&out
);
1292 anv_device_init_dispatch(struct anv_device
*device
)
1294 const struct anv_dispatch_table
*genX_table
;
1295 switch (device
->info
.gen
) {
1297 genX_table
= &gen10_dispatch_table
;
1300 genX_table
= &gen9_dispatch_table
;
1303 genX_table
= &gen8_dispatch_table
;
1306 if (device
->info
.is_haswell
)
1307 genX_table
= &gen75_dispatch_table
;
1309 genX_table
= &gen7_dispatch_table
;
1312 unreachable("unsupported gen\n");
1315 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1316 /* Vulkan requires that entrypoints for extensions which have not been
1317 * enabled must not be advertised.
1319 if (!anv_entrypoint_is_enabled(i
, device
->instance
->apiVersion
,
1320 &device
->instance
->enabled_extensions
,
1321 &device
->enabled_extensions
)) {
1322 device
->dispatch
.entrypoints
[i
] = NULL
;
1323 } else if (genX_table
->entrypoints
[i
]) {
1324 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1326 device
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
1332 vk_priority_to_gen(int priority
)
1335 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1336 return GEN_CONTEXT_LOW_PRIORITY
;
1337 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1338 return GEN_CONTEXT_MEDIUM_PRIORITY
;
1339 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1340 return GEN_CONTEXT_HIGH_PRIORITY
;
1341 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1342 return GEN_CONTEXT_REALTIME_PRIORITY
;
1344 unreachable("Invalid priority");
1348 VkResult
anv_CreateDevice(
1349 VkPhysicalDevice physicalDevice
,
1350 const VkDeviceCreateInfo
* pCreateInfo
,
1351 const VkAllocationCallbacks
* pAllocator
,
1354 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1356 struct anv_device
*device
;
1358 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1360 struct anv_device_extension_table enabled_extensions
= { };
1361 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1363 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1364 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1365 anv_device_extensions
[idx
].extensionName
) == 0)
1369 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1370 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1372 if (!physical_device
->supported_extensions
.extensions
[idx
])
1373 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1375 enabled_extensions
.extensions
[idx
] = true;
1378 /* Check enabled features */
1379 if (pCreateInfo
->pEnabledFeatures
) {
1380 VkPhysicalDeviceFeatures supported_features
;
1381 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1382 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1383 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1384 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1385 for (uint32_t i
= 0; i
< num_features
; i
++) {
1386 if (enabled_feature
[i
] && !supported_feature
[i
])
1387 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1391 /* Check if client specified queue priority. */
1392 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
1393 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
1394 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1396 VkQueueGlobalPriorityEXT priority
=
1397 queue_priority
? queue_priority
->globalPriority
:
1398 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
1400 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1402 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1404 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1406 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1407 device
->instance
= physical_device
->instance
;
1408 device
->chipset_id
= physical_device
->chipset_id
;
1409 device
->no_hw
= physical_device
->no_hw
;
1410 device
->lost
= false;
1413 device
->alloc
= *pAllocator
;
1415 device
->alloc
= physical_device
->instance
->alloc
;
1417 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1418 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1419 if (device
->fd
== -1) {
1420 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1424 device
->context_id
= anv_gem_create_context(device
);
1425 if (device
->context_id
== -1) {
1426 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1430 /* As per spec, the driver implementation may deny requests to acquire
1431 * a priority above the default priority (MEDIUM) if the caller does not
1432 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
1435 if (physical_device
->has_context_priority
) {
1436 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
1437 I915_CONTEXT_PARAM_PRIORITY
,
1438 vk_priority_to_gen(priority
));
1439 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
1440 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
1445 device
->info
= physical_device
->info
;
1446 device
->isl_dev
= physical_device
->isl_dev
;
1448 /* On Broadwell and later, we can use batch chaining to more efficiently
1449 * implement growing command buffers. Prior to Haswell, the kernel
1450 * command parser gets in the way and we have to fall back to growing
1453 device
->can_chain_batches
= device
->info
.gen
>= 8;
1455 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1456 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1457 device
->enabled_extensions
= enabled_extensions
;
1459 anv_device_init_dispatch(device
);
1461 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1462 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1463 goto fail_context_id
;
1466 pthread_condattr_t condattr
;
1467 if (pthread_condattr_init(&condattr
) != 0) {
1468 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1471 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1472 pthread_condattr_destroy(&condattr
);
1473 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1476 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1477 pthread_condattr_destroy(&condattr
);
1478 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1481 pthread_condattr_destroy(&condattr
);
1484 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1485 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1486 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1488 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1490 result
= anv_bo_cache_init(&device
->bo_cache
);
1491 if (result
!= VK_SUCCESS
)
1492 goto fail_batch_bo_pool
;
1494 /* For the state pools we explicitly disable 48bit. */
1495 bo_flags
= (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1496 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1498 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384,
1500 if (result
!= VK_SUCCESS
)
1503 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384,
1505 if (result
!= VK_SUCCESS
)
1506 goto fail_dynamic_state_pool
;
1508 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096,
1510 if (result
!= VK_SUCCESS
)
1511 goto fail_instruction_state_pool
;
1513 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1514 if (result
!= VK_SUCCESS
)
1515 goto fail_surface_state_pool
;
1517 anv_device_init_trivial_batch(device
);
1519 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1521 anv_queue_init(device
, &device
->queue
);
1523 switch (device
->info
.gen
) {
1525 if (!device
->info
.is_haswell
)
1526 result
= gen7_init_device_state(device
);
1528 result
= gen75_init_device_state(device
);
1531 result
= gen8_init_device_state(device
);
1534 result
= gen9_init_device_state(device
);
1537 result
= gen10_init_device_state(device
);
1540 result
= gen11_init_device_state(device
);
1543 /* Shouldn't get here as we don't create physical devices for any other
1545 unreachable("unhandled gen");
1547 if (result
!= VK_SUCCESS
)
1548 goto fail_workaround_bo
;
1550 anv_device_init_blorp(device
);
1552 anv_device_init_border_colors(device
);
1554 *pDevice
= anv_device_to_handle(device
);
1559 anv_queue_finish(&device
->queue
);
1560 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1561 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1562 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1563 fail_surface_state_pool
:
1564 anv_state_pool_finish(&device
->surface_state_pool
);
1565 fail_instruction_state_pool
:
1566 anv_state_pool_finish(&device
->instruction_state_pool
);
1567 fail_dynamic_state_pool
:
1568 anv_state_pool_finish(&device
->dynamic_state_pool
);
1570 anv_bo_cache_finish(&device
->bo_cache
);
1572 anv_bo_pool_finish(&device
->batch_bo_pool
);
1573 pthread_cond_destroy(&device
->queue_submit
);
1575 pthread_mutex_destroy(&device
->mutex
);
1577 anv_gem_destroy_context(device
, device
->context_id
);
1581 vk_free(&device
->alloc
, device
);
1586 void anv_DestroyDevice(
1588 const VkAllocationCallbacks
* pAllocator
)
1590 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1595 anv_device_finish_blorp(device
);
1597 anv_queue_finish(&device
->queue
);
1599 #ifdef HAVE_VALGRIND
1600 /* We only need to free these to prevent valgrind errors. The backing
1601 * BO will go away in a couple of lines so we don't actually leak.
1603 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1606 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1608 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1609 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1611 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1613 anv_state_pool_finish(&device
->surface_state_pool
);
1614 anv_state_pool_finish(&device
->instruction_state_pool
);
1615 anv_state_pool_finish(&device
->dynamic_state_pool
);
1617 anv_bo_cache_finish(&device
->bo_cache
);
1619 anv_bo_pool_finish(&device
->batch_bo_pool
);
1621 pthread_cond_destroy(&device
->queue_submit
);
1622 pthread_mutex_destroy(&device
->mutex
);
1624 anv_gem_destroy_context(device
, device
->context_id
);
1628 vk_free(&device
->alloc
, device
);
1631 VkResult
anv_EnumerateInstanceLayerProperties(
1632 uint32_t* pPropertyCount
,
1633 VkLayerProperties
* pProperties
)
1635 if (pProperties
== NULL
) {
1636 *pPropertyCount
= 0;
1640 /* None supported at this time */
1641 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1644 VkResult
anv_EnumerateDeviceLayerProperties(
1645 VkPhysicalDevice physicalDevice
,
1646 uint32_t* pPropertyCount
,
1647 VkLayerProperties
* pProperties
)
1649 if (pProperties
== NULL
) {
1650 *pPropertyCount
= 0;
1654 /* None supported at this time */
1655 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1658 void anv_GetDeviceQueue(
1660 uint32_t queueNodeIndex
,
1661 uint32_t queueIndex
,
1664 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1666 assert(queueIndex
== 0);
1668 *pQueue
= anv_queue_to_handle(&device
->queue
);
1672 anv_device_query_status(struct anv_device
*device
)
1674 /* This isn't likely as most of the callers of this function already check
1675 * for it. However, it doesn't hurt to check and it potentially lets us
1678 if (unlikely(device
->lost
))
1679 return VK_ERROR_DEVICE_LOST
;
1681 uint32_t active
, pending
;
1682 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1684 /* We don't know the real error. */
1685 device
->lost
= true;
1686 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1687 "get_reset_stats failed: %m");
1691 device
->lost
= true;
1692 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1693 "GPU hung on one of our command buffers");
1694 } else if (pending
) {
1695 device
->lost
= true;
1696 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1697 "GPU hung with commands in-flight");
1704 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1706 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1707 * Other usages of the BO (such as on different hardware) will not be
1708 * flagged as "busy" by this ioctl. Use with care.
1710 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1712 return VK_NOT_READY
;
1713 } else if (ret
== -1) {
1714 /* We don't know the real error. */
1715 device
->lost
= true;
1716 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1717 "gem wait failed: %m");
1720 /* Query for device status after the busy call. If the BO we're checking
1721 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1722 * client because it clearly doesn't have valid data. Yes, this most
1723 * likely means an ioctl, but we just did an ioctl to query the busy status
1724 * so it's no great loss.
1726 return anv_device_query_status(device
);
1730 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1733 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1734 if (ret
== -1 && errno
== ETIME
) {
1736 } else if (ret
== -1) {
1737 /* We don't know the real error. */
1738 device
->lost
= true;
1739 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1740 "gem wait failed: %m");
1743 /* Query for device status after the wait. If the BO we're waiting on got
1744 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1745 * because it clearly doesn't have valid data. Yes, this most likely means
1746 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1748 return anv_device_query_status(device
);
1751 VkResult
anv_DeviceWaitIdle(
1754 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1755 if (unlikely(device
->lost
))
1756 return VK_ERROR_DEVICE_LOST
;
1758 struct anv_batch batch
;
1761 batch
.start
= batch
.next
= cmds
;
1762 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1764 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1765 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1767 return anv_device_submit_simple_batch(device
, &batch
);
1771 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1773 uint32_t gem_handle
= anv_gem_create(device
, size
);
1775 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1777 anv_bo_init(bo
, gem_handle
, size
);
1782 VkResult
anv_AllocateMemory(
1784 const VkMemoryAllocateInfo
* pAllocateInfo
,
1785 const VkAllocationCallbacks
* pAllocator
,
1786 VkDeviceMemory
* pMem
)
1788 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1789 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1790 struct anv_device_memory
*mem
;
1791 VkResult result
= VK_SUCCESS
;
1793 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1795 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1796 assert(pAllocateInfo
->allocationSize
> 0);
1798 /* The kernel relocation API has a limitation of a 32-bit delta value
1799 * applied to the address before it is written which, in spite of it being
1800 * unsigned, is treated as signed . Because of the way that this maps to
1801 * the Vulkan API, we cannot handle an offset into a buffer that does not
1802 * fit into a signed 32 bits. The only mechanism we have for dealing with
1803 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1804 * of 2GB each. The Vulkan spec allows us to do this:
1806 * "Some platforms may have a limit on the maximum size of a single
1807 * allocation. For example, certain systems may fail to create
1808 * allocations with a size greater than or equal to 4GB. Such a limit is
1809 * implementation-dependent, and if such a failure occurs then the error
1810 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1812 * We don't use vk_error here because it's not an error so much as an
1813 * indication to the application that the allocation is too large.
1815 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1816 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1818 /* FINISHME: Fail if allocation request exceeds heap size. */
1820 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1821 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1823 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1825 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1826 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1830 const VkImportMemoryFdInfoKHR
*fd_info
=
1831 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1833 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1836 if (fd_info
&& fd_info
->handleType
) {
1837 /* At the moment, we support only the below handle types. */
1838 assert(fd_info
->handleType
==
1839 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
1840 fd_info
->handleType
==
1841 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1843 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1844 fd_info
->fd
, &mem
->bo
);
1845 if (result
!= VK_SUCCESS
)
1848 VkDeviceSize aligned_alloc_size
=
1849 align_u64(pAllocateInfo
->allocationSize
, 4096);
1851 /* For security purposes, we reject importing the bo if it's smaller
1852 * than the requested allocation size. This prevents a malicious client
1853 * from passing a buffer to a trusted client, lying about the size, and
1854 * telling the trusted client to try and texture from an image that goes
1855 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
1856 * in the trusted client. The trusted client can protect itself against
1857 * this sort of attack but only if it can trust the buffer size.
1859 if (mem
->bo
->size
< aligned_alloc_size
) {
1860 result
= vk_errorf(device
->instance
, device
,
1861 VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
,
1862 "aligned allocationSize too large for "
1863 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR: "
1864 "%"PRIu64
"B > %"PRIu64
"B",
1865 aligned_alloc_size
, mem
->bo
->size
);
1866 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1870 /* From the Vulkan spec:
1872 * "Importing memory from a file descriptor transfers ownership of
1873 * the file descriptor from the application to the Vulkan
1874 * implementation. The application must not perform any operations on
1875 * the file descriptor after a successful import."
1877 * If the import fails, we leave the file descriptor open.
1881 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1882 pAllocateInfo
->allocationSize
,
1884 if (result
!= VK_SUCCESS
)
1887 const VkMemoryDedicatedAllocateInfoKHR
*dedicated_info
=
1888 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
1889 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
1890 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
1892 /* Some legacy (non-modifiers) consumers need the tiling to be set on
1893 * the BO. In this case, we have a dedicated allocation.
1895 if (image
->needs_set_tiling
) {
1896 const uint32_t i915_tiling
=
1897 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
1898 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
1899 image
->planes
[0].surface
.isl
.row_pitch
,
1902 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1903 return vk_errorf(device
->instance
, NULL
,
1904 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1905 "failed to set BO tiling: %m");
1911 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
1912 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
1913 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1915 const struct wsi_memory_allocate_info
*wsi_info
=
1916 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
1917 if (wsi_info
&& wsi_info
->implicit_sync
) {
1918 /* We need to set the WRITE flag on window system buffers so that GEM
1919 * will know we're writing to them and synchronize uses on other rings
1920 * (eg if the display server uses the blitter ring).
1922 mem
->bo
->flags
|= EXEC_OBJECT_WRITE
;
1923 } else if (pdevice
->has_exec_async
) {
1924 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
1927 *pMem
= anv_device_memory_to_handle(mem
);
1932 vk_free2(&device
->alloc
, pAllocator
, mem
);
1937 VkResult
anv_GetMemoryFdKHR(
1939 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
1942 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1943 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
1945 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
1947 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
1948 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1950 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1953 VkResult
anv_GetMemoryFdPropertiesKHR(
1955 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1957 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
1959 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1960 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1962 switch (handleType
) {
1963 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1964 /* dma-buf can be imported as any memory type */
1965 pMemoryFdProperties
->memoryTypeBits
=
1966 (1 << pdevice
->memory
.type_count
) - 1;
1970 /* The valid usage section for this function says:
1972 * "handleType must not be one of the handle types defined as
1975 * So opaque handle types fall into the default "unsupported" case.
1977 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
1981 void anv_FreeMemory(
1983 VkDeviceMemory _mem
,
1984 const VkAllocationCallbacks
* pAllocator
)
1986 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1987 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1993 anv_UnmapMemory(_device
, _mem
);
1995 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1997 vk_free2(&device
->alloc
, pAllocator
, mem
);
2000 VkResult
anv_MapMemory(
2002 VkDeviceMemory _memory
,
2003 VkDeviceSize offset
,
2005 VkMemoryMapFlags flags
,
2008 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2009 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2016 if (size
== VK_WHOLE_SIZE
)
2017 size
= mem
->bo
->size
- offset
;
2019 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
2021 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
2022 * assert(size != 0);
2023 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
2024 * equal to the size of the memory minus offset
2027 assert(offset
+ size
<= mem
->bo
->size
);
2029 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
2030 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
2031 * at a time is valid. We could just mmap up front and return an offset
2032 * pointer here, but that may exhaust virtual memory on 32 bit
2035 uint32_t gem_flags
= 0;
2037 if (!device
->info
.has_llc
&&
2038 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
2039 gem_flags
|= I915_MMAP_WC
;
2041 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
2042 uint64_t map_offset
= offset
& ~4095ull;
2043 assert(offset
>= map_offset
);
2044 uint64_t map_size
= (offset
+ size
) - map_offset
;
2046 /* Let's map whole pages */
2047 map_size
= align_u64(map_size
, 4096);
2049 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2050 map_offset
, map_size
, gem_flags
);
2051 if (map
== MAP_FAILED
)
2052 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2055 mem
->map_size
= map_size
;
2057 *ppData
= mem
->map
+ (offset
- map_offset
);
2062 void anv_UnmapMemory(
2064 VkDeviceMemory _memory
)
2066 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2071 anv_gem_munmap(mem
->map
, mem
->map_size
);
2078 clflush_mapped_ranges(struct anv_device
*device
,
2080 const VkMappedMemoryRange
*ranges
)
2082 for (uint32_t i
= 0; i
< count
; i
++) {
2083 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2084 if (ranges
[i
].offset
>= mem
->map_size
)
2087 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2088 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2092 VkResult
anv_FlushMappedMemoryRanges(
2094 uint32_t memoryRangeCount
,
2095 const VkMappedMemoryRange
* pMemoryRanges
)
2097 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2099 if (device
->info
.has_llc
)
2102 /* Make sure the writes we're flushing have landed. */
2103 __builtin_ia32_mfence();
2105 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2110 VkResult
anv_InvalidateMappedMemoryRanges(
2112 uint32_t memoryRangeCount
,
2113 const VkMappedMemoryRange
* pMemoryRanges
)
2115 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2117 if (device
->info
.has_llc
)
2120 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2122 /* Make sure no reads get moved up above the invalidate. */
2123 __builtin_ia32_mfence();
2128 void anv_GetBufferMemoryRequirements(
2131 VkMemoryRequirements
* pMemoryRequirements
)
2133 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2134 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2135 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2137 /* The Vulkan spec (git aaed022) says:
2139 * memoryTypeBits is a bitfield and contains one bit set for every
2140 * supported memory type for the resource. The bit `1<<i` is set if and
2141 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2142 * structure for the physical device is supported.
2144 uint32_t memory_types
= 0;
2145 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2146 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2147 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2148 memory_types
|= (1u << i
);
2151 /* Base alignment requirement of a cache line */
2152 uint32_t alignment
= 16;
2154 /* We need an alignment of 32 for pushing UBOs */
2155 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2156 alignment
= MAX2(alignment
, 32);
2158 pMemoryRequirements
->size
= buffer
->size
;
2159 pMemoryRequirements
->alignment
= alignment
;
2160 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2163 void anv_GetBufferMemoryRequirements2KHR(
2165 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2166 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2168 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2169 &pMemoryRequirements
->memoryRequirements
);
2171 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2172 switch (ext
->sType
) {
2173 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2174 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
2175 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2176 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2181 anv_debug_ignored_stype(ext
->sType
);
2187 void anv_GetImageMemoryRequirements(
2190 VkMemoryRequirements
* pMemoryRequirements
)
2192 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2193 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2194 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2196 /* The Vulkan spec (git aaed022) says:
2198 * memoryTypeBits is a bitfield and contains one bit set for every
2199 * supported memory type for the resource. The bit `1<<i` is set if and
2200 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2201 * structure for the physical device is supported.
2203 * All types are currently supported for images.
2205 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2207 pMemoryRequirements
->size
= image
->size
;
2208 pMemoryRequirements
->alignment
= image
->alignment
;
2209 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2212 void anv_GetImageMemoryRequirements2KHR(
2214 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2215 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2217 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2218 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2220 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2221 &pMemoryRequirements
->memoryRequirements
);
2223 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2224 switch (ext
->sType
) {
2225 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO_KHR
: {
2226 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2227 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
2228 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
2229 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2230 plane_reqs
->planeAspect
);
2232 assert(image
->planes
[plane
].offset
== 0);
2234 /* The Vulkan spec (git aaed022) says:
2236 * memoryTypeBits is a bitfield and contains one bit set for every
2237 * supported memory type for the resource. The bit `1<<i` is set
2238 * if and only if the memory type `i` in the
2239 * VkPhysicalDeviceMemoryProperties structure for the physical
2240 * device is supported.
2242 * All types are currently supported for images.
2244 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2245 (1ull << pdevice
->memory
.type_count
) - 1;
2247 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2248 pMemoryRequirements
->memoryRequirements
.alignment
=
2249 image
->planes
[plane
].alignment
;
2254 anv_debug_ignored_stype(ext
->sType
);
2259 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2260 switch (ext
->sType
) {
2261 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2262 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
2263 if (image
->needs_set_tiling
) {
2264 /* If we need to set the tiling for external consumers, we need a
2265 * dedicated allocation.
2267 * See also anv_AllocateMemory.
2269 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2270 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2272 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2273 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2279 anv_debug_ignored_stype(ext
->sType
);
2285 void anv_GetImageSparseMemoryRequirements(
2288 uint32_t* pSparseMemoryRequirementCount
,
2289 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2291 *pSparseMemoryRequirementCount
= 0;
2294 void anv_GetImageSparseMemoryRequirements2KHR(
2296 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2297 uint32_t* pSparseMemoryRequirementCount
,
2298 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2300 *pSparseMemoryRequirementCount
= 0;
2303 void anv_GetDeviceMemoryCommitment(
2305 VkDeviceMemory memory
,
2306 VkDeviceSize
* pCommittedMemoryInBytes
)
2308 *pCommittedMemoryInBytes
= 0;
2312 anv_bind_buffer_memory(const VkBindBufferMemoryInfoKHR
*pBindInfo
)
2314 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2315 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2317 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
);
2320 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2321 buffer
->bo
= mem
->bo
;
2322 buffer
->offset
= pBindInfo
->memoryOffset
;
2329 VkResult
anv_BindBufferMemory(
2332 VkDeviceMemory memory
,
2333 VkDeviceSize memoryOffset
)
2335 anv_bind_buffer_memory(
2336 &(VkBindBufferMemoryInfoKHR
) {
2337 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2340 .memoryOffset
= memoryOffset
,
2346 VkResult
anv_BindBufferMemory2KHR(
2348 uint32_t bindInfoCount
,
2349 const VkBindBufferMemoryInfoKHR
* pBindInfos
)
2351 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2352 anv_bind_buffer_memory(&pBindInfos
[i
]);
2357 VkResult
anv_QueueBindSparse(
2359 uint32_t bindInfoCount
,
2360 const VkBindSparseInfo
* pBindInfo
,
2363 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2364 if (unlikely(queue
->device
->lost
))
2365 return VK_ERROR_DEVICE_LOST
;
2367 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2372 VkResult
anv_CreateEvent(
2374 const VkEventCreateInfo
* pCreateInfo
,
2375 const VkAllocationCallbacks
* pAllocator
,
2378 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2379 struct anv_state state
;
2380 struct anv_event
*event
;
2382 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2384 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2387 event
->state
= state
;
2388 event
->semaphore
= VK_EVENT_RESET
;
2390 if (!device
->info
.has_llc
) {
2391 /* Make sure the writes we're flushing have landed. */
2392 __builtin_ia32_mfence();
2393 __builtin_ia32_clflush(event
);
2396 *pEvent
= anv_event_to_handle(event
);
2401 void anv_DestroyEvent(
2404 const VkAllocationCallbacks
* pAllocator
)
2406 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2407 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2412 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2415 VkResult
anv_GetEventStatus(
2419 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2420 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2422 if (unlikely(device
->lost
))
2423 return VK_ERROR_DEVICE_LOST
;
2425 if (!device
->info
.has_llc
) {
2426 /* Invalidate read cache before reading event written by GPU. */
2427 __builtin_ia32_clflush(event
);
2428 __builtin_ia32_mfence();
2432 return event
->semaphore
;
2435 VkResult
anv_SetEvent(
2439 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2440 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2442 event
->semaphore
= VK_EVENT_SET
;
2444 if (!device
->info
.has_llc
) {
2445 /* Make sure the writes we're flushing have landed. */
2446 __builtin_ia32_mfence();
2447 __builtin_ia32_clflush(event
);
2453 VkResult
anv_ResetEvent(
2457 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2458 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2460 event
->semaphore
= VK_EVENT_RESET
;
2462 if (!device
->info
.has_llc
) {
2463 /* Make sure the writes we're flushing have landed. */
2464 __builtin_ia32_mfence();
2465 __builtin_ia32_clflush(event
);
2473 VkResult
anv_CreateBuffer(
2475 const VkBufferCreateInfo
* pCreateInfo
,
2476 const VkAllocationCallbacks
* pAllocator
,
2479 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2480 struct anv_buffer
*buffer
;
2482 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2484 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2485 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2487 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2489 buffer
->size
= pCreateInfo
->size
;
2490 buffer
->usage
= pCreateInfo
->usage
;
2494 *pBuffer
= anv_buffer_to_handle(buffer
);
2499 void anv_DestroyBuffer(
2502 const VkAllocationCallbacks
* pAllocator
)
2504 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2505 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2510 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2514 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2515 enum isl_format format
,
2516 uint32_t offset
, uint32_t range
, uint32_t stride
)
2518 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2520 .mocs
= device
->default_mocs
,
2525 anv_state_flush(device
, state
);
2528 void anv_DestroySampler(
2531 const VkAllocationCallbacks
* pAllocator
)
2533 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2534 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2539 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2542 VkResult
anv_CreateFramebuffer(
2544 const VkFramebufferCreateInfo
* pCreateInfo
,
2545 const VkAllocationCallbacks
* pAllocator
,
2546 VkFramebuffer
* pFramebuffer
)
2548 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2549 struct anv_framebuffer
*framebuffer
;
2551 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2553 size_t size
= sizeof(*framebuffer
) +
2554 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2555 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2556 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2557 if (framebuffer
== NULL
)
2558 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2560 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2561 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2562 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2563 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2566 framebuffer
->width
= pCreateInfo
->width
;
2567 framebuffer
->height
= pCreateInfo
->height
;
2568 framebuffer
->layers
= pCreateInfo
->layers
;
2570 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2575 void anv_DestroyFramebuffer(
2578 const VkAllocationCallbacks
* pAllocator
)
2580 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2581 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2586 vk_free2(&device
->alloc
, pAllocator
, fb
);
2589 /* vk_icd.h does not declare this function, so we declare it here to
2590 * suppress Wmissing-prototypes.
2592 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2593 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2595 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2596 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2598 /* For the full details on loader interface versioning, see
2599 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2600 * What follows is a condensed summary, to help you navigate the large and
2601 * confusing official doc.
2603 * - Loader interface v0 is incompatible with later versions. We don't
2606 * - In loader interface v1:
2607 * - The first ICD entrypoint called by the loader is
2608 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2610 * - The ICD must statically expose no other Vulkan symbol unless it is
2611 * linked with -Bsymbolic.
2612 * - Each dispatchable Vulkan handle created by the ICD must be
2613 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2614 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2615 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2616 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2617 * such loader-managed surfaces.
2619 * - Loader interface v2 differs from v1 in:
2620 * - The first ICD entrypoint called by the loader is
2621 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2622 * statically expose this entrypoint.
2624 * - Loader interface v3 differs from v2 in:
2625 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2626 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2627 * because the loader no longer does so.
2629 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);