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>
33 #include "anv_private.h"
34 #include "util/strtod.h"
35 #include "util/debug.h"
36 #include "util/build_id.h"
37 #include "util/mesa-sha1.h"
40 #include "genxml/gen7_pack.h"
43 compiler_debug_log(void *data
, const char *fmt
, ...)
47 compiler_perf_log(void *data
, const char *fmt
, ...)
52 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
53 vfprintf(stderr
, fmt
, args
);
59 anv_compute_heap_size(int fd
, uint64_t *heap_size
)
62 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
64 /* If, for whatever reason, we can't actually get the GTT size from the
65 * kernel (too old?) fall back to the aperture size.
67 anv_perf_warn(NULL
, NULL
,
68 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
70 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
71 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
72 "failed to get aperture size: %m");
76 /* Query the total ram from the system */
80 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
82 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
83 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
85 uint64_t available_ram
;
86 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
87 available_ram
= total_ram
/ 2;
89 available_ram
= total_ram
* 3 / 4;
91 /* We also want to leave some padding for things we allocate in the driver,
92 * so don't go over 3/4 of the GTT either.
94 uint64_t available_gtt
= gtt_size
* 3 / 4;
96 *heap_size
= MIN2(available_ram
, available_gtt
);
102 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
104 /* The kernel query only tells us whether or not the kernel supports the
105 * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
106 * hardware has actual 48bit address support.
108 device
->supports_48bit_addresses
=
109 (device
->info
.gen
>= 8) && anv_gem_supports_48b_addresses(fd
);
112 VkResult result
= anv_compute_heap_size(fd
, &heap_size
);
113 if (result
!= VK_SUCCESS
)
116 if (heap_size
<= 3ull * (1ull << 30)) {
117 /* In this case, everything fits nicely into the 32-bit address space,
118 * so there's no need for supporting 48bit addresses on client-allocated
121 device
->memory
.heap_count
= 1;
122 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
124 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
125 .supports_48bit_addresses
= false,
128 /* Not everything will fit nicely into a 32-bit address space. In this
129 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
130 * larger 48-bit heap. If we're in this case, then we have a total heap
131 * size larger than 3GiB which most likely means they have 8 GiB of
132 * video memory and so carving off 1 GiB for the 32-bit heap should be
135 const uint64_t heap_size_32bit
= 1ull << 30;
136 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
138 assert(device
->supports_48bit_addresses
);
140 device
->memory
.heap_count
= 2;
141 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
142 .size
= heap_size_48bit
,
143 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
144 .supports_48bit_addresses
= true,
146 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
147 .size
= heap_size_32bit
,
148 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
149 .supports_48bit_addresses
= false,
153 uint32_t type_count
= 0;
154 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
155 uint32_t valid_buffer_usage
= ~0;
157 /* There appears to be a hardware issue in the VF cache where it only
158 * considers the bottom 32 bits of memory addresses. If you happen to
159 * have two vertex buffers which get placed exactly 4 GiB apart and use
160 * them in back-to-back draw calls, you can get collisions. In order to
161 * solve this problem, we require vertex and index buffers be bound to
162 * memory allocated out of the 32-bit heap.
164 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
165 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
166 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
169 if (device
->info
.has_llc
) {
170 /* Big core GPUs share LLC with the CPU and thus one memory type can be
171 * both cached and coherent at the same time.
173 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
174 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
175 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
176 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
177 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
179 .valid_buffer_usage
= valid_buffer_usage
,
182 /* The spec requires that we expose a host-visible, coherent memory
183 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
184 * to give the application a choice between cached, but not coherent and
185 * coherent but uncached (WC though).
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
,
192 .valid_buffer_usage
= valid_buffer_usage
,
194 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
195 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
196 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
197 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
199 .valid_buffer_usage
= valid_buffer_usage
,
203 device
->memory
.type_count
= type_count
;
209 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
211 const struct build_id_note
*note
= build_id_find_nhdr("libvulkan_intel.so");
213 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
214 "Failed to find build-id");
217 unsigned build_id_len
= build_id_length(note
);
218 if (build_id_len
< 20) {
219 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
220 "build-id too short. It needs to be a SHA");
223 struct mesa_sha1 sha1_ctx
;
225 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
227 /* The pipeline cache UUID is used for determining when a pipeline cache is
228 * invalid. It needs both a driver build and the PCI ID of the device.
230 _mesa_sha1_init(&sha1_ctx
);
231 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
232 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
233 sizeof(device
->chipset_id
));
234 _mesa_sha1_final(&sha1_ctx
, sha1
);
235 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
237 /* The driver UUID is used for determining sharability of images and memory
238 * between two Vulkan instances in separate processes. People who want to
239 * share memory need to also check the device UUID (below) so all this
240 * needs to be is the build-id.
242 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
244 /* The device UUID uniquely identifies the given device within the machine.
245 * Since we never have more than one device, this doesn't need to be a real
246 * UUID. However, on the off-chance that someone tries to use this to
247 * cache pre-tiled images or something of the like, we use the PCI ID and
248 * some bits of ISL info to ensure that this is safe.
250 _mesa_sha1_init(&sha1_ctx
);
251 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
252 sizeof(device
->chipset_id
));
253 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
254 sizeof(device
->isl_dev
.has_bit6_swizzling
));
255 _mesa_sha1_final(&sha1_ctx
, sha1
);
256 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
262 anv_physical_device_init(struct anv_physical_device
*device
,
263 struct anv_instance
*instance
,
269 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
271 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
273 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
274 device
->instance
= instance
;
276 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
277 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
279 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
280 if (!device
->chipset_id
) {
281 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
285 device
->name
= gen_get_device_name(device
->chipset_id
);
286 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
287 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
291 if (device
->info
.is_haswell
) {
292 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
293 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
294 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
295 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
296 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
297 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 9) {
298 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
299 * supported as anything */
301 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
302 "Vulkan not yet supported on %s", device
->name
);
306 device
->cmd_parser_version
= -1;
307 if (device
->info
.gen
== 7) {
308 device
->cmd_parser_version
=
309 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
310 if (device
->cmd_parser_version
== -1) {
311 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
312 "failed to get command parser version");
317 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
318 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
319 "kernel missing gem wait");
323 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
324 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
325 "kernel missing execbuf2");
329 if (!device
->info
.has_llc
&&
330 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
331 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
332 "kernel missing wc mmap");
336 result
= anv_physical_device_init_heaps(device
, fd
);
337 if (result
!= VK_SUCCESS
)
340 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
341 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
342 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
343 device
->has_syncobj_wait
= device
->has_syncobj
&&
344 anv_gem_supports_syncobj_wait(fd
);
346 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
348 /* GENs prior to 8 do not support EU/Subslice info */
349 if (device
->info
.gen
>= 8) {
350 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
351 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
353 /* Without this information, we cannot get the right Braswell
354 * brandstrings, and we have to use conservative numbers for GPGPU on
355 * many platforms, but otherwise, things will just work.
357 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
358 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
359 " query GPU properties.\n");
361 } else if (device
->info
.gen
== 7) {
362 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
365 if (device
->info
.is_cherryview
&&
366 device
->subslice_total
> 0 && device
->eu_total
> 0) {
367 /* Logical CS threads = EUs per subslice * num threads per EU */
368 uint32_t max_cs_threads
=
369 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
371 /* Fuse configurations may give more threads than expected, never less. */
372 if (max_cs_threads
> device
->info
.max_cs_threads
)
373 device
->info
.max_cs_threads
= max_cs_threads
;
376 brw_process_intel_debug_variable();
378 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
379 if (device
->compiler
== NULL
) {
380 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
383 device
->compiler
->shader_debug_log
= compiler_debug_log
;
384 device
->compiler
->shader_perf_log
= compiler_perf_log
;
386 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
388 result
= anv_physical_device_init_uuids(device
);
389 if (result
!= VK_SUCCESS
)
392 result
= anv_init_wsi(device
);
393 if (result
!= VK_SUCCESS
) {
394 ralloc_free(device
->compiler
);
398 device
->local_fd
= fd
;
407 anv_physical_device_finish(struct anv_physical_device
*device
)
409 anv_finish_wsi(device
);
410 ralloc_free(device
->compiler
);
411 close(device
->local_fd
);
415 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
416 VkSystemAllocationScope allocationScope
)
422 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
423 size_t align
, VkSystemAllocationScope allocationScope
)
425 return realloc(pOriginal
, size
);
429 default_free_func(void *pUserData
, void *pMemory
)
434 static const VkAllocationCallbacks default_alloc
= {
436 .pfnAllocation
= default_alloc_func
,
437 .pfnReallocation
= default_realloc_func
,
438 .pfnFree
= default_free_func
,
441 VkResult
anv_CreateInstance(
442 const VkInstanceCreateInfo
* pCreateInfo
,
443 const VkAllocationCallbacks
* pAllocator
,
444 VkInstance
* pInstance
)
446 struct anv_instance
*instance
;
448 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
450 /* Check if user passed a debug report callback to be used during
451 * Create/Destroy of instance.
453 const VkDebugReportCallbackCreateInfoEXT
*ctor_cb
=
454 vk_find_struct_const(pCreateInfo
->pNext
,
455 DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
);
457 uint32_t client_version
;
458 if (pCreateInfo
->pApplicationInfo
&&
459 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
460 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
462 client_version
= VK_MAKE_VERSION(1, 0, 0);
465 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
466 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
468 if (ctor_cb
&& ctor_cb
->flags
& VK_DEBUG_REPORT_ERROR_BIT_EXT
)
469 ctor_cb
->pfnCallback(VK_DEBUG_REPORT_ERROR_BIT_EXT
,
470 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
,
471 VK_NULL_HANDLE
, /* No handle available yet. */
475 "incompatible driver version",
478 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
479 "Client requested version %d.%d.%d",
480 VK_VERSION_MAJOR(client_version
),
481 VK_VERSION_MINOR(client_version
),
482 VK_VERSION_PATCH(client_version
));
485 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
486 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
487 if (!anv_instance_extension_supported(ext_name
))
488 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
491 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
492 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
494 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
496 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
499 instance
->alloc
= *pAllocator
;
501 instance
->alloc
= default_alloc
;
503 instance
->apiVersion
= client_version
;
504 instance
->physicalDeviceCount
= -1;
506 if (pthread_mutex_init(&instance
->callbacks_mutex
, NULL
) != 0) {
507 vk_free2(&default_alloc
, pAllocator
, instance
);
508 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
511 list_inithead(&instance
->callbacks
);
513 /* Store report debug callback to be used during DestroyInstance. */
515 instance
->destroy_debug_cb
.flags
= ctor_cb
->flags
;
516 instance
->destroy_debug_cb
.callback
= ctor_cb
->pfnCallback
;
517 instance
->destroy_debug_cb
.data
= ctor_cb
->pUserData
;
522 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
524 *pInstance
= anv_instance_to_handle(instance
);
529 void anv_DestroyInstance(
530 VkInstance _instance
,
531 const VkAllocationCallbacks
* pAllocator
)
533 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
538 if (instance
->physicalDeviceCount
> 0) {
539 /* We support at most one physical device. */
540 assert(instance
->physicalDeviceCount
== 1);
541 anv_physical_device_finish(&instance
->physicalDevice
);
544 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
546 pthread_mutex_destroy(&instance
->callbacks_mutex
);
550 vk_free(&instance
->alloc
, instance
);
554 anv_enumerate_devices(struct anv_instance
*instance
)
556 /* TODO: Check for more devices ? */
557 drmDevicePtr devices
[8];
558 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
561 instance
->physicalDeviceCount
= 0;
563 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
565 return VK_ERROR_INCOMPATIBLE_DRIVER
;
567 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
568 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
569 devices
[i
]->bustype
== DRM_BUS_PCI
&&
570 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
572 result
= anv_physical_device_init(&instance
->physicalDevice
,
574 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
575 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
579 drmFreeDevices(devices
, max_devices
);
581 if (result
== VK_SUCCESS
)
582 instance
->physicalDeviceCount
= 1;
588 VkResult
anv_EnumeratePhysicalDevices(
589 VkInstance _instance
,
590 uint32_t* pPhysicalDeviceCount
,
591 VkPhysicalDevice
* pPhysicalDevices
)
593 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
594 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
597 if (instance
->physicalDeviceCount
< 0) {
598 result
= anv_enumerate_devices(instance
);
599 if (result
!= VK_SUCCESS
&&
600 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
604 if (instance
->physicalDeviceCount
> 0) {
605 assert(instance
->physicalDeviceCount
== 1);
606 vk_outarray_append(&out
, i
) {
607 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
611 return vk_outarray_status(&out
);
614 void anv_GetPhysicalDeviceFeatures(
615 VkPhysicalDevice physicalDevice
,
616 VkPhysicalDeviceFeatures
* pFeatures
)
618 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
620 *pFeatures
= (VkPhysicalDeviceFeatures
) {
621 .robustBufferAccess
= true,
622 .fullDrawIndexUint32
= true,
623 .imageCubeArray
= true,
624 .independentBlend
= true,
625 .geometryShader
= true,
626 .tessellationShader
= true,
627 .sampleRateShading
= true,
628 .dualSrcBlend
= true,
630 .multiDrawIndirect
= true,
631 .drawIndirectFirstInstance
= true,
633 .depthBiasClamp
= true,
634 .fillModeNonSolid
= true,
635 .depthBounds
= false,
639 .multiViewport
= true,
640 .samplerAnisotropy
= true,
641 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
642 pdevice
->info
.is_baytrail
,
643 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
644 .textureCompressionBC
= true,
645 .occlusionQueryPrecise
= true,
646 .pipelineStatisticsQuery
= true,
647 .fragmentStoresAndAtomics
= true,
648 .shaderTessellationAndGeometryPointSize
= true,
649 .shaderImageGatherExtended
= true,
650 .shaderStorageImageExtendedFormats
= true,
651 .shaderStorageImageMultisample
= false,
652 .shaderStorageImageReadWithoutFormat
= false,
653 .shaderStorageImageWriteWithoutFormat
= true,
654 .shaderUniformBufferArrayDynamicIndexing
= true,
655 .shaderSampledImageArrayDynamicIndexing
= true,
656 .shaderStorageBufferArrayDynamicIndexing
= true,
657 .shaderStorageImageArrayDynamicIndexing
= true,
658 .shaderClipDistance
= true,
659 .shaderCullDistance
= true,
660 .shaderFloat64
= pdevice
->info
.gen
>= 8,
661 .shaderInt64
= pdevice
->info
.gen
>= 8,
662 .shaderInt16
= false,
663 .shaderResourceMinLod
= false,
664 .variableMultisampleRate
= false,
665 .inheritedQueries
= true,
668 /* We can't do image stores in vec4 shaders */
669 pFeatures
->vertexPipelineStoresAndAtomics
=
670 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
671 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
674 void anv_GetPhysicalDeviceFeatures2KHR(
675 VkPhysicalDevice physicalDevice
,
676 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
678 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
680 vk_foreach_struct(ext
, pFeatures
->pNext
) {
681 switch (ext
->sType
) {
682 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
683 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
684 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
685 features
->multiview
= true;
686 features
->multiviewGeometryShader
= true;
687 features
->multiviewTessellationShader
= true;
691 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
692 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
693 features
->variablePointersStorageBuffer
= true;
694 features
->variablePointers
= false;
699 anv_debug_ignored_stype(ext
->sType
);
705 void anv_GetPhysicalDeviceProperties(
706 VkPhysicalDevice physicalDevice
,
707 VkPhysicalDeviceProperties
* pProperties
)
709 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
710 const struct gen_device_info
*devinfo
= &pdevice
->info
;
712 /* See assertions made when programming the buffer surface state. */
713 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
714 (1ul << 30) : (1ul << 27);
716 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
719 VkSampleCountFlags sample_counts
=
720 isl_device_get_sample_counts(&pdevice
->isl_dev
);
722 VkPhysicalDeviceLimits limits
= {
723 .maxImageDimension1D
= (1 << 14),
724 .maxImageDimension2D
= (1 << 14),
725 .maxImageDimension3D
= (1 << 11),
726 .maxImageDimensionCube
= (1 << 14),
727 .maxImageArrayLayers
= (1 << 11),
728 .maxTexelBufferElements
= 128 * 1024 * 1024,
729 .maxUniformBufferRange
= (1ul << 27),
730 .maxStorageBufferRange
= max_raw_buffer_sz
,
731 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
732 .maxMemoryAllocationCount
= UINT32_MAX
,
733 .maxSamplerAllocationCount
= 64 * 1024,
734 .bufferImageGranularity
= 64, /* A cache line */
735 .sparseAddressSpaceSize
= 0,
736 .maxBoundDescriptorSets
= MAX_SETS
,
737 .maxPerStageDescriptorSamplers
= max_samplers
,
738 .maxPerStageDescriptorUniformBuffers
= 64,
739 .maxPerStageDescriptorStorageBuffers
= 64,
740 .maxPerStageDescriptorSampledImages
= max_samplers
,
741 .maxPerStageDescriptorStorageImages
= 64,
742 .maxPerStageDescriptorInputAttachments
= 64,
743 .maxPerStageResources
= 250,
744 .maxDescriptorSetSamplers
= 256,
745 .maxDescriptorSetUniformBuffers
= 256,
746 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
747 .maxDescriptorSetStorageBuffers
= 256,
748 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
749 .maxDescriptorSetSampledImages
= 256,
750 .maxDescriptorSetStorageImages
= 256,
751 .maxDescriptorSetInputAttachments
= 256,
752 .maxVertexInputAttributes
= MAX_VBS
,
753 .maxVertexInputBindings
= MAX_VBS
,
754 .maxVertexInputAttributeOffset
= 2047,
755 .maxVertexInputBindingStride
= 2048,
756 .maxVertexOutputComponents
= 128,
757 .maxTessellationGenerationLevel
= 64,
758 .maxTessellationPatchSize
= 32,
759 .maxTessellationControlPerVertexInputComponents
= 128,
760 .maxTessellationControlPerVertexOutputComponents
= 128,
761 .maxTessellationControlPerPatchOutputComponents
= 128,
762 .maxTessellationControlTotalOutputComponents
= 2048,
763 .maxTessellationEvaluationInputComponents
= 128,
764 .maxTessellationEvaluationOutputComponents
= 128,
765 .maxGeometryShaderInvocations
= 32,
766 .maxGeometryInputComponents
= 64,
767 .maxGeometryOutputComponents
= 128,
768 .maxGeometryOutputVertices
= 256,
769 .maxGeometryTotalOutputComponents
= 1024,
770 .maxFragmentInputComponents
= 128,
771 .maxFragmentOutputAttachments
= 8,
772 .maxFragmentDualSrcAttachments
= 1,
773 .maxFragmentCombinedOutputResources
= 8,
774 .maxComputeSharedMemorySize
= 32768,
775 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
776 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
777 .maxComputeWorkGroupSize
= {
778 16 * devinfo
->max_cs_threads
,
779 16 * devinfo
->max_cs_threads
,
780 16 * devinfo
->max_cs_threads
,
782 .subPixelPrecisionBits
= 4 /* FIXME */,
783 .subTexelPrecisionBits
= 4 /* FIXME */,
784 .mipmapPrecisionBits
= 4 /* FIXME */,
785 .maxDrawIndexedIndexValue
= UINT32_MAX
,
786 .maxDrawIndirectCount
= UINT32_MAX
,
787 .maxSamplerLodBias
= 16,
788 .maxSamplerAnisotropy
= 16,
789 .maxViewports
= MAX_VIEWPORTS
,
790 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
791 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
792 .viewportSubPixelBits
= 13, /* We take a float? */
793 .minMemoryMapAlignment
= 4096, /* A page */
794 .minTexelBufferOffsetAlignment
= 1,
795 .minUniformBufferOffsetAlignment
= 16,
796 .minStorageBufferOffsetAlignment
= 4,
797 .minTexelOffset
= -8,
799 .minTexelGatherOffset
= -32,
800 .maxTexelGatherOffset
= 31,
801 .minInterpolationOffset
= -0.5,
802 .maxInterpolationOffset
= 0.4375,
803 .subPixelInterpolationOffsetBits
= 4,
804 .maxFramebufferWidth
= (1 << 14),
805 .maxFramebufferHeight
= (1 << 14),
806 .maxFramebufferLayers
= (1 << 11),
807 .framebufferColorSampleCounts
= sample_counts
,
808 .framebufferDepthSampleCounts
= sample_counts
,
809 .framebufferStencilSampleCounts
= sample_counts
,
810 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
811 .maxColorAttachments
= MAX_RTS
,
812 .sampledImageColorSampleCounts
= sample_counts
,
813 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
814 .sampledImageDepthSampleCounts
= sample_counts
,
815 .sampledImageStencilSampleCounts
= sample_counts
,
816 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
817 .maxSampleMaskWords
= 1,
818 .timestampComputeAndGraphics
= false,
819 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
820 .maxClipDistances
= 8,
821 .maxCullDistances
= 8,
822 .maxCombinedClipAndCullDistances
= 8,
823 .discreteQueuePriorities
= 1,
824 .pointSizeRange
= { 0.125, 255.875 },
825 .lineWidthRange
= { 0.0, 7.9921875 },
826 .pointSizeGranularity
= (1.0 / 8.0),
827 .lineWidthGranularity
= (1.0 / 128.0),
828 .strictLines
= false, /* FINISHME */
829 .standardSampleLocations
= true,
830 .optimalBufferCopyOffsetAlignment
= 128,
831 .optimalBufferCopyRowPitchAlignment
= 128,
832 .nonCoherentAtomSize
= 64,
835 *pProperties
= (VkPhysicalDeviceProperties
) {
836 .apiVersion
= anv_physical_device_api_version(pdevice
),
837 .driverVersion
= vk_get_driver_version(),
839 .deviceID
= pdevice
->chipset_id
,
840 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
842 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
845 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
846 "%s", pdevice
->name
);
847 memcpy(pProperties
->pipelineCacheUUID
,
848 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
851 void anv_GetPhysicalDeviceProperties2KHR(
852 VkPhysicalDevice physicalDevice
,
853 VkPhysicalDeviceProperties2KHR
* pProperties
)
855 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
857 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
859 vk_foreach_struct(ext
, pProperties
->pNext
) {
860 switch (ext
->sType
) {
861 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
862 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
863 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
865 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
869 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
870 VkPhysicalDeviceIDPropertiesKHR
*id_props
=
871 (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
872 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
873 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
874 /* The LUID is for Windows. */
875 id_props
->deviceLUIDValid
= false;
879 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
880 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
881 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
882 properties
->maxMultiviewViewCount
= 16;
883 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
888 anv_debug_ignored_stype(ext
->sType
);
894 /* We support exactly one queue family. */
895 static const VkQueueFamilyProperties
896 anv_queue_family_properties
= {
897 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
898 VK_QUEUE_COMPUTE_BIT
|
899 VK_QUEUE_TRANSFER_BIT
,
901 .timestampValidBits
= 36, /* XXX: Real value here */
902 .minImageTransferGranularity
= { 1, 1, 1 },
905 void anv_GetPhysicalDeviceQueueFamilyProperties(
906 VkPhysicalDevice physicalDevice
,
908 VkQueueFamilyProperties
* pQueueFamilyProperties
)
910 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
912 vk_outarray_append(&out
, p
) {
913 *p
= anv_queue_family_properties
;
917 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
918 VkPhysicalDevice physicalDevice
,
919 uint32_t* pQueueFamilyPropertyCount
,
920 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
923 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
925 vk_outarray_append(&out
, p
) {
926 p
->queueFamilyProperties
= anv_queue_family_properties
;
928 vk_foreach_struct(s
, p
->pNext
) {
929 anv_debug_ignored_stype(s
->sType
);
934 void anv_GetPhysicalDeviceMemoryProperties(
935 VkPhysicalDevice physicalDevice
,
936 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
938 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
940 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
941 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
942 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
943 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
944 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
948 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
949 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
950 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
951 .size
= physical_device
->memory
.heaps
[i
].size
,
952 .flags
= physical_device
->memory
.heaps
[i
].flags
,
957 void anv_GetPhysicalDeviceMemoryProperties2KHR(
958 VkPhysicalDevice physicalDevice
,
959 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
961 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
962 &pMemoryProperties
->memoryProperties
);
964 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
965 switch (ext
->sType
) {
967 anv_debug_ignored_stype(ext
->sType
);
973 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
977 return anv_lookup_entrypoint(NULL
, pName
);
980 /* With version 1+ of the loader interface the ICD should expose
981 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
984 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
989 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
993 return anv_GetInstanceProcAddr(instance
, pName
);
996 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1000 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1001 return anv_lookup_entrypoint(&device
->info
, pName
);
1005 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1007 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1008 queue
->device
= device
;
1009 queue
->pool
= &device
->surface_state_pool
;
1013 anv_queue_finish(struct anv_queue
*queue
)
1017 static struct anv_state
1018 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1020 struct anv_state state
;
1022 state
= anv_state_pool_alloc(pool
, size
, align
);
1023 memcpy(state
.map
, p
, size
);
1025 anv_state_flush(pool
->block_pool
.device
, state
);
1030 struct gen8_border_color
{
1035 /* Pad out to 64 bytes */
1040 anv_device_init_border_colors(struct anv_device
*device
)
1042 static const struct gen8_border_color border_colors
[] = {
1043 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1044 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1045 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1046 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1047 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1048 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1051 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1052 sizeof(border_colors
), 64,
1057 anv_device_init_trivial_batch(struct anv_device
*device
)
1059 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1061 if (device
->instance
->physicalDevice
.has_exec_async
)
1062 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1064 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1067 struct anv_batch batch
= {
1073 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1074 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1076 if (!device
->info
.has_llc
)
1077 gen_clflush_range(map
, batch
.next
- map
);
1079 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1082 VkResult
anv_CreateDevice(
1083 VkPhysicalDevice physicalDevice
,
1084 const VkDeviceCreateInfo
* pCreateInfo
,
1085 const VkAllocationCallbacks
* pAllocator
,
1088 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1090 struct anv_device
*device
;
1092 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1094 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1095 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1096 if (!anv_physical_device_extension_supported(physical_device
, ext_name
))
1097 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1100 /* Check enabled features */
1101 if (pCreateInfo
->pEnabledFeatures
) {
1102 VkPhysicalDeviceFeatures supported_features
;
1103 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1104 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1105 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1106 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1107 for (uint32_t i
= 0; i
< num_features
; i
++) {
1108 if (enabled_feature
[i
] && !supported_feature
[i
])
1109 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1113 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1115 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1117 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1119 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1120 device
->instance
= physical_device
->instance
;
1121 device
->chipset_id
= physical_device
->chipset_id
;
1122 device
->lost
= false;
1125 device
->alloc
= *pAllocator
;
1127 device
->alloc
= physical_device
->instance
->alloc
;
1129 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1130 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1131 if (device
->fd
== -1) {
1132 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1136 device
->context_id
= anv_gem_create_context(device
);
1137 if (device
->context_id
== -1) {
1138 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1142 device
->info
= physical_device
->info
;
1143 device
->isl_dev
= physical_device
->isl_dev
;
1145 /* On Broadwell and later, we can use batch chaining to more efficiently
1146 * implement growing command buffers. Prior to Haswell, the kernel
1147 * command parser gets in the way and we have to fall back to growing
1150 device
->can_chain_batches
= device
->info
.gen
>= 8;
1152 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1153 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1155 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1156 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1157 goto fail_context_id
;
1160 pthread_condattr_t condattr
;
1161 if (pthread_condattr_init(&condattr
) != 0) {
1162 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1165 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1166 pthread_condattr_destroy(&condattr
);
1167 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1170 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1171 pthread_condattr_destroy(&condattr
);
1172 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1175 pthread_condattr_destroy(&condattr
);
1177 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1179 result
= anv_bo_cache_init(&device
->bo_cache
);
1180 if (result
!= VK_SUCCESS
)
1181 goto fail_batch_bo_pool
;
1183 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384);
1184 if (result
!= VK_SUCCESS
)
1187 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384);
1188 if (result
!= VK_SUCCESS
)
1189 goto fail_dynamic_state_pool
;
1191 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096);
1192 if (result
!= VK_SUCCESS
)
1193 goto fail_instruction_state_pool
;
1195 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1196 if (result
!= VK_SUCCESS
)
1197 goto fail_surface_state_pool
;
1199 anv_device_init_trivial_batch(device
);
1201 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1203 anv_queue_init(device
, &device
->queue
);
1205 switch (device
->info
.gen
) {
1207 if (!device
->info
.is_haswell
)
1208 result
= gen7_init_device_state(device
);
1210 result
= gen75_init_device_state(device
);
1213 result
= gen8_init_device_state(device
);
1216 result
= gen9_init_device_state(device
);
1219 result
= gen10_init_device_state(device
);
1222 /* Shouldn't get here as we don't create physical devices for any other
1224 unreachable("unhandled gen");
1226 if (result
!= VK_SUCCESS
)
1227 goto fail_workaround_bo
;
1229 anv_device_init_blorp(device
);
1231 anv_device_init_border_colors(device
);
1233 *pDevice
= anv_device_to_handle(device
);
1238 anv_queue_finish(&device
->queue
);
1239 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1240 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1241 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1242 fail_surface_state_pool
:
1243 anv_state_pool_finish(&device
->surface_state_pool
);
1244 fail_instruction_state_pool
:
1245 anv_state_pool_finish(&device
->instruction_state_pool
);
1246 fail_dynamic_state_pool
:
1247 anv_state_pool_finish(&device
->dynamic_state_pool
);
1249 anv_bo_cache_finish(&device
->bo_cache
);
1251 anv_bo_pool_finish(&device
->batch_bo_pool
);
1252 pthread_cond_destroy(&device
->queue_submit
);
1254 pthread_mutex_destroy(&device
->mutex
);
1256 anv_gem_destroy_context(device
, device
->context_id
);
1260 vk_free(&device
->alloc
, device
);
1265 void anv_DestroyDevice(
1267 const VkAllocationCallbacks
* pAllocator
)
1269 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1274 anv_device_finish_blorp(device
);
1276 anv_queue_finish(&device
->queue
);
1278 #ifdef HAVE_VALGRIND
1279 /* We only need to free these to prevent valgrind errors. The backing
1280 * BO will go away in a couple of lines so we don't actually leak.
1282 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1285 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1287 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1288 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1290 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1292 anv_state_pool_finish(&device
->surface_state_pool
);
1293 anv_state_pool_finish(&device
->instruction_state_pool
);
1294 anv_state_pool_finish(&device
->dynamic_state_pool
);
1296 anv_bo_cache_finish(&device
->bo_cache
);
1298 anv_bo_pool_finish(&device
->batch_bo_pool
);
1300 pthread_cond_destroy(&device
->queue_submit
);
1301 pthread_mutex_destroy(&device
->mutex
);
1303 anv_gem_destroy_context(device
, device
->context_id
);
1307 vk_free(&device
->alloc
, device
);
1310 VkResult
anv_EnumerateInstanceLayerProperties(
1311 uint32_t* pPropertyCount
,
1312 VkLayerProperties
* pProperties
)
1314 if (pProperties
== NULL
) {
1315 *pPropertyCount
= 0;
1319 /* None supported at this time */
1320 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1323 VkResult
anv_EnumerateDeviceLayerProperties(
1324 VkPhysicalDevice physicalDevice
,
1325 uint32_t* pPropertyCount
,
1326 VkLayerProperties
* pProperties
)
1328 if (pProperties
== NULL
) {
1329 *pPropertyCount
= 0;
1333 /* None supported at this time */
1334 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1337 void anv_GetDeviceQueue(
1339 uint32_t queueNodeIndex
,
1340 uint32_t queueIndex
,
1343 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1345 assert(queueIndex
== 0);
1347 *pQueue
= anv_queue_to_handle(&device
->queue
);
1351 anv_device_query_status(struct anv_device
*device
)
1353 /* This isn't likely as most of the callers of this function already check
1354 * for it. However, it doesn't hurt to check and it potentially lets us
1357 if (unlikely(device
->lost
))
1358 return VK_ERROR_DEVICE_LOST
;
1360 uint32_t active
, pending
;
1361 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1363 /* We don't know the real error. */
1364 device
->lost
= true;
1365 return vk_errorf(VK_ERROR_DEVICE_LOST
, "get_reset_stats failed: %m");
1369 device
->lost
= true;
1370 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1371 "GPU hung on one of our command buffers");
1372 } else if (pending
) {
1373 device
->lost
= true;
1374 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1375 "GPU hung with commands in-flight");
1382 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1384 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1385 * Other usages of the BO (such as on different hardware) will not be
1386 * flagged as "busy" by this ioctl. Use with care.
1388 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1390 return VK_NOT_READY
;
1391 } else if (ret
== -1) {
1392 /* We don't know the real error. */
1393 device
->lost
= true;
1394 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1397 /* Query for device status after the busy call. If the BO we're checking
1398 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1399 * client because it clearly doesn't have valid data. Yes, this most
1400 * likely means an ioctl, but we just did an ioctl to query the busy status
1401 * so it's no great loss.
1403 return anv_device_query_status(device
);
1407 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1410 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1411 if (ret
== -1 && errno
== ETIME
) {
1413 } else if (ret
== -1) {
1414 /* We don't know the real error. */
1415 device
->lost
= true;
1416 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1419 /* Query for device status after the wait. If the BO we're waiting on got
1420 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1421 * because it clearly doesn't have valid data. Yes, this most likely means
1422 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1424 return anv_device_query_status(device
);
1427 VkResult
anv_DeviceWaitIdle(
1430 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1431 if (unlikely(device
->lost
))
1432 return VK_ERROR_DEVICE_LOST
;
1434 struct anv_batch batch
;
1437 batch
.start
= batch
.next
= cmds
;
1438 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1440 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1441 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1443 return anv_device_submit_simple_batch(device
, &batch
);
1447 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1449 uint32_t gem_handle
= anv_gem_create(device
, size
);
1451 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1453 anv_bo_init(bo
, gem_handle
, size
);
1458 VkResult
anv_AllocateMemory(
1460 const VkMemoryAllocateInfo
* pAllocateInfo
,
1461 const VkAllocationCallbacks
* pAllocator
,
1462 VkDeviceMemory
* pMem
)
1464 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1465 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1466 struct anv_device_memory
*mem
;
1467 VkResult result
= VK_SUCCESS
;
1469 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1471 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1472 assert(pAllocateInfo
->allocationSize
> 0);
1474 /* The kernel relocation API has a limitation of a 32-bit delta value
1475 * applied to the address before it is written which, in spite of it being
1476 * unsigned, is treated as signed . Because of the way that this maps to
1477 * the Vulkan API, we cannot handle an offset into a buffer that does not
1478 * fit into a signed 32 bits. The only mechanism we have for dealing with
1479 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1480 * of 2GB each. The Vulkan spec allows us to do this:
1482 * "Some platforms may have a limit on the maximum size of a single
1483 * allocation. For example, certain systems may fail to create
1484 * allocations with a size greater than or equal to 4GB. Such a limit is
1485 * implementation-dependent, and if such a failure occurs then the error
1486 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1488 * We don't use vk_error here because it's not an error so much as an
1489 * indication to the application that the allocation is too large.
1491 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1492 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1494 /* FINISHME: Fail if allocation request exceeds heap size. */
1496 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1497 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1499 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1501 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1502 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1506 const VkImportMemoryFdInfoKHR
*fd_info
=
1507 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1509 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1512 if (fd_info
&& fd_info
->handleType
) {
1513 /* At the moment, we only support the OPAQUE_FD memory type which is
1514 * just a GEM buffer.
1516 assert(fd_info
->handleType
==
1517 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
1519 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1520 fd_info
->fd
, pAllocateInfo
->allocationSize
,
1522 if (result
!= VK_SUCCESS
)
1525 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1526 pAllocateInfo
->allocationSize
,
1528 if (result
!= VK_SUCCESS
)
1532 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
1533 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
1534 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1536 if (pdevice
->has_exec_async
)
1537 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
1539 *pMem
= anv_device_memory_to_handle(mem
);
1544 vk_free2(&device
->alloc
, pAllocator
, mem
);
1549 VkResult
anv_GetMemoryFdKHR(
1551 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
1554 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1555 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
1557 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
1559 /* We support only one handle type. */
1560 assert(pGetFdInfo
->handleType
==
1561 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
1563 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1566 VkResult
anv_GetMemoryFdPropertiesKHR(
1568 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1570 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
1572 /* The valid usage section for this function says:
1574 * "handleType must not be one of the handle types defined as opaque."
1576 * Since we only handle opaque handles for now, there are no FD properties.
1578 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1581 void anv_FreeMemory(
1583 VkDeviceMemory _mem
,
1584 const VkAllocationCallbacks
* pAllocator
)
1586 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1587 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1593 anv_UnmapMemory(_device
, _mem
);
1595 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1597 vk_free2(&device
->alloc
, pAllocator
, mem
);
1600 VkResult
anv_MapMemory(
1602 VkDeviceMemory _memory
,
1603 VkDeviceSize offset
,
1605 VkMemoryMapFlags flags
,
1608 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1609 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1616 if (size
== VK_WHOLE_SIZE
)
1617 size
= mem
->bo
->size
- offset
;
1619 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1621 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1622 * assert(size != 0);
1623 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1624 * equal to the size of the memory minus offset
1627 assert(offset
+ size
<= mem
->bo
->size
);
1629 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1630 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1631 * at a time is valid. We could just mmap up front and return an offset
1632 * pointer here, but that may exhaust virtual memory on 32 bit
1635 uint32_t gem_flags
= 0;
1637 if (!device
->info
.has_llc
&&
1638 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
1639 gem_flags
|= I915_MMAP_WC
;
1641 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1642 uint64_t map_offset
= offset
& ~4095ull;
1643 assert(offset
>= map_offset
);
1644 uint64_t map_size
= (offset
+ size
) - map_offset
;
1646 /* Let's map whole pages */
1647 map_size
= align_u64(map_size
, 4096);
1649 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
1650 map_offset
, map_size
, gem_flags
);
1651 if (map
== MAP_FAILED
)
1652 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1655 mem
->map_size
= map_size
;
1657 *ppData
= mem
->map
+ (offset
- map_offset
);
1662 void anv_UnmapMemory(
1664 VkDeviceMemory _memory
)
1666 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1671 anv_gem_munmap(mem
->map
, mem
->map_size
);
1678 clflush_mapped_ranges(struct anv_device
*device
,
1680 const VkMappedMemoryRange
*ranges
)
1682 for (uint32_t i
= 0; i
< count
; i
++) {
1683 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1684 if (ranges
[i
].offset
>= mem
->map_size
)
1687 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
1688 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1692 VkResult
anv_FlushMappedMemoryRanges(
1694 uint32_t memoryRangeCount
,
1695 const VkMappedMemoryRange
* pMemoryRanges
)
1697 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1699 if (device
->info
.has_llc
)
1702 /* Make sure the writes we're flushing have landed. */
1703 __builtin_ia32_mfence();
1705 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1710 VkResult
anv_InvalidateMappedMemoryRanges(
1712 uint32_t memoryRangeCount
,
1713 const VkMappedMemoryRange
* pMemoryRanges
)
1715 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1717 if (device
->info
.has_llc
)
1720 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1722 /* Make sure no reads get moved up above the invalidate. */
1723 __builtin_ia32_mfence();
1728 void anv_GetBufferMemoryRequirements(
1731 VkMemoryRequirements
* pMemoryRequirements
)
1733 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1734 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1735 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1737 /* The Vulkan spec (git aaed022) says:
1739 * memoryTypeBits is a bitfield and contains one bit set for every
1740 * supported memory type for the resource. The bit `1<<i` is set if and
1741 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1742 * structure for the physical device is supported.
1744 uint32_t memory_types
= 0;
1745 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
1746 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
1747 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
1748 memory_types
|= (1u << i
);
1751 pMemoryRequirements
->size
= buffer
->size
;
1752 pMemoryRequirements
->alignment
= 16;
1753 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1756 void anv_GetBufferMemoryRequirements2KHR(
1758 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
1759 VkMemoryRequirements2KHR
* pMemoryRequirements
)
1761 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
1762 &pMemoryRequirements
->memoryRequirements
);
1764 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
1765 switch (ext
->sType
) {
1766 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
1767 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
1768 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
1769 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
1774 anv_debug_ignored_stype(ext
->sType
);
1780 void anv_GetImageMemoryRequirements(
1783 VkMemoryRequirements
* pMemoryRequirements
)
1785 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1786 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1787 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1789 /* The Vulkan spec (git aaed022) says:
1791 * memoryTypeBits is a bitfield and contains one bit set for every
1792 * supported memory type for the resource. The bit `1<<i` is set if and
1793 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1794 * structure for the physical device is supported.
1796 * All types are currently supported for images.
1798 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
1800 pMemoryRequirements
->size
= image
->size
;
1801 pMemoryRequirements
->alignment
= image
->alignment
;
1802 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1805 void anv_GetImageMemoryRequirements2KHR(
1807 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
1808 VkMemoryRequirements2KHR
* pMemoryRequirements
)
1810 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
1811 &pMemoryRequirements
->memoryRequirements
);
1813 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
1814 switch (ext
->sType
) {
1815 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
1816 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
1817 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
1818 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
1823 anv_debug_ignored_stype(ext
->sType
);
1829 void anv_GetImageSparseMemoryRequirements(
1832 uint32_t* pSparseMemoryRequirementCount
,
1833 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1835 *pSparseMemoryRequirementCount
= 0;
1838 void anv_GetImageSparseMemoryRequirements2KHR(
1840 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
1841 uint32_t* pSparseMemoryRequirementCount
,
1842 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
1844 *pSparseMemoryRequirementCount
= 0;
1847 void anv_GetDeviceMemoryCommitment(
1849 VkDeviceMemory memory
,
1850 VkDeviceSize
* pCommittedMemoryInBytes
)
1852 *pCommittedMemoryInBytes
= 0;
1855 VkResult
anv_BindBufferMemory(
1858 VkDeviceMemory _memory
,
1859 VkDeviceSize memoryOffset
)
1861 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1862 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1865 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
1866 buffer
->bo
= mem
->bo
;
1867 buffer
->offset
= memoryOffset
;
1876 VkResult
anv_QueueBindSparse(
1878 uint32_t bindInfoCount
,
1879 const VkBindSparseInfo
* pBindInfo
,
1882 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1883 if (unlikely(queue
->device
->lost
))
1884 return VK_ERROR_DEVICE_LOST
;
1886 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1891 VkResult
anv_CreateEvent(
1893 const VkEventCreateInfo
* pCreateInfo
,
1894 const VkAllocationCallbacks
* pAllocator
,
1897 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1898 struct anv_state state
;
1899 struct anv_event
*event
;
1901 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1903 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1906 event
->state
= state
;
1907 event
->semaphore
= VK_EVENT_RESET
;
1909 if (!device
->info
.has_llc
) {
1910 /* Make sure the writes we're flushing have landed. */
1911 __builtin_ia32_mfence();
1912 __builtin_ia32_clflush(event
);
1915 *pEvent
= anv_event_to_handle(event
);
1920 void anv_DestroyEvent(
1923 const VkAllocationCallbacks
* pAllocator
)
1925 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1926 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1931 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1934 VkResult
anv_GetEventStatus(
1938 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1939 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1941 if (unlikely(device
->lost
))
1942 return VK_ERROR_DEVICE_LOST
;
1944 if (!device
->info
.has_llc
) {
1945 /* Invalidate read cache before reading event written by GPU. */
1946 __builtin_ia32_clflush(event
);
1947 __builtin_ia32_mfence();
1951 return event
->semaphore
;
1954 VkResult
anv_SetEvent(
1958 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1959 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1961 event
->semaphore
= VK_EVENT_SET
;
1963 if (!device
->info
.has_llc
) {
1964 /* Make sure the writes we're flushing have landed. */
1965 __builtin_ia32_mfence();
1966 __builtin_ia32_clflush(event
);
1972 VkResult
anv_ResetEvent(
1976 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1977 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1979 event
->semaphore
= VK_EVENT_RESET
;
1981 if (!device
->info
.has_llc
) {
1982 /* Make sure the writes we're flushing have landed. */
1983 __builtin_ia32_mfence();
1984 __builtin_ia32_clflush(event
);
1992 VkResult
anv_CreateBuffer(
1994 const VkBufferCreateInfo
* pCreateInfo
,
1995 const VkAllocationCallbacks
* pAllocator
,
1998 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1999 struct anv_buffer
*buffer
;
2001 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2003 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2004 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2006 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2008 buffer
->size
= pCreateInfo
->size
;
2009 buffer
->usage
= pCreateInfo
->usage
;
2013 *pBuffer
= anv_buffer_to_handle(buffer
);
2018 void anv_DestroyBuffer(
2021 const VkAllocationCallbacks
* pAllocator
)
2023 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2024 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2029 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2033 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2034 enum isl_format format
,
2035 uint32_t offset
, uint32_t range
, uint32_t stride
)
2037 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2039 .mocs
= device
->default_mocs
,
2044 anv_state_flush(device
, state
);
2047 void anv_DestroySampler(
2050 const VkAllocationCallbacks
* pAllocator
)
2052 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2053 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2058 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2061 VkResult
anv_CreateFramebuffer(
2063 const VkFramebufferCreateInfo
* pCreateInfo
,
2064 const VkAllocationCallbacks
* pAllocator
,
2065 VkFramebuffer
* pFramebuffer
)
2067 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2068 struct anv_framebuffer
*framebuffer
;
2070 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2072 size_t size
= sizeof(*framebuffer
) +
2073 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2074 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2075 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2076 if (framebuffer
== NULL
)
2077 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2079 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2080 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2081 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2082 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2085 framebuffer
->width
= pCreateInfo
->width
;
2086 framebuffer
->height
= pCreateInfo
->height
;
2087 framebuffer
->layers
= pCreateInfo
->layers
;
2089 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2094 void anv_DestroyFramebuffer(
2097 const VkAllocationCallbacks
* pAllocator
)
2099 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2100 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2105 vk_free2(&device
->alloc
, pAllocator
, fb
);
2108 /* vk_icd.h does not declare this function, so we declare it here to
2109 * suppress Wmissing-prototypes.
2111 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2112 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2114 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2115 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2117 /* For the full details on loader interface versioning, see
2118 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2119 * What follows is a condensed summary, to help you navigate the large and
2120 * confusing official doc.
2122 * - Loader interface v0 is incompatible with later versions. We don't
2125 * - In loader interface v1:
2126 * - The first ICD entrypoint called by the loader is
2127 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2129 * - The ICD must statically expose no other Vulkan symbol unless it is
2130 * linked with -Bsymbolic.
2131 * - Each dispatchable Vulkan handle created by the ICD must be
2132 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2133 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2134 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2135 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2136 * such loader-managed surfaces.
2138 * - Loader interface v2 differs from v1 in:
2139 * - The first ICD entrypoint called by the loader is
2140 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2141 * statically expose this entrypoint.
2143 * - Loader interface v3 differs from v2 in:
2144 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2145 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2146 * because the loader no longer does so.
2148 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);