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
30 #include "anv_private.h"
31 #include "mesa/main/git_sha1.h"
32 #include "util/strtod.h"
34 #include "gen7_pack.h"
36 struct anv_dispatch_table dtable
;
39 compiler_debug_log(void *data
, const char *fmt
, ...)
43 compiler_perf_log(void *data
, const char *fmt
, ...)
48 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
49 vfprintf(stderr
, fmt
, args
);
55 anv_physical_device_init(struct anv_physical_device
*device
,
56 struct anv_instance
*instance
,
62 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
64 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
65 "failed to open %s: %m", path
);
67 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
68 device
->instance
= instance
;
71 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
72 if (!device
->chipset_id
) {
73 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
74 "failed to get chipset id: %m");
78 device
->name
= brw_get_device_name(device
->chipset_id
);
79 device
->info
= brw_get_device_info(device
->chipset_id
);
81 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
82 "failed to get device info");
86 if (device
->info
->is_haswell
) {
87 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
88 } else if (device
->info
->gen
== 7 && !device
->info
->is_baytrail
) {
89 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
90 } else if (device
->info
->gen
== 9) {
91 fprintf(stderr
, "WARNING: Skylake Vulkan support is incomplete\n");
92 } else if (device
->info
->gen
== 8 && !device
->info
->is_cherryview
) {
93 /* Broadwell is as fully supported as anything */
95 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
96 "Vulkan not yet supported on %s", device
->name
);
100 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
101 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
102 "failed to get aperture size: %m");
106 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
107 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
108 "kernel missing gem wait");
112 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
113 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
114 "kernel missing execbuf2");
118 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_LLC
)) {
119 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
124 if (anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
< 1)) {
125 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
126 "kernel missing wc mmap");
132 brw_process_intel_debug_variable();
134 device
->compiler
= brw_compiler_create(NULL
, device
->info
);
135 if (device
->compiler
== NULL
) {
136 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
139 device
->compiler
->shader_debug_log
= compiler_debug_log
;
140 device
->compiler
->shader_perf_log
= compiler_perf_log
;
142 isl_device_init(&device
->isl_dev
, device
->info
);
152 anv_physical_device_finish(struct anv_physical_device
*device
)
154 ralloc_free(device
->compiler
);
157 static const VkExtensionProperties global_extensions
[] = {
159 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
163 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
166 #ifdef HAVE_WAYLAND_PLATFORM
168 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
174 static const VkExtensionProperties device_extensions
[] = {
176 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
182 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
183 VkSystemAllocationScope allocationScope
)
189 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
190 size_t align
, VkSystemAllocationScope allocationScope
)
192 return realloc(pOriginal
, size
);
196 default_free_func(void *pUserData
, void *pMemory
)
201 static const VkAllocationCallbacks default_alloc
= {
203 .pfnAllocation
= default_alloc_func
,
204 .pfnReallocation
= default_realloc_func
,
205 .pfnFree
= default_free_func
,
208 VkResult
anv_CreateInstance(
209 const VkInstanceCreateInfo
* pCreateInfo
,
210 const VkAllocationCallbacks
* pAllocator
,
211 VkInstance
* pInstance
)
213 struct anv_instance
*instance
;
215 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
217 if (pCreateInfo
->pApplicationInfo
->apiVersion
!= VK_MAKE_VERSION(0, 210, 1))
218 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
220 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
222 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
223 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
224 global_extensions
[j
].extensionName
) == 0) {
230 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
233 instance
= anv_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
234 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
236 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
238 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
241 instance
->alloc
= *pAllocator
;
243 instance
->alloc
= default_alloc
;
245 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
246 instance
->physicalDeviceCount
= -1;
250 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
252 anv_init_wsi(instance
);
254 *pInstance
= anv_instance_to_handle(instance
);
259 void anv_DestroyInstance(
260 VkInstance _instance
,
261 const VkAllocationCallbacks
* pAllocator
)
263 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
265 if (instance
->physicalDeviceCount
> 0) {
266 /* We support at most one physical device. */
267 assert(instance
->physicalDeviceCount
== 1);
268 anv_physical_device_finish(&instance
->physicalDevice
);
271 anv_finish_wsi(instance
);
273 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
277 anv_free(&instance
->alloc
, instance
);
280 VkResult
anv_EnumeratePhysicalDevices(
281 VkInstance _instance
,
282 uint32_t* pPhysicalDeviceCount
,
283 VkPhysicalDevice
* pPhysicalDevices
)
285 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
288 if (instance
->physicalDeviceCount
< 0) {
289 result
= anv_physical_device_init(&instance
->physicalDevice
,
290 instance
, "/dev/dri/renderD128");
291 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
292 instance
->physicalDeviceCount
= 0;
293 } else if (result
== VK_SUCCESS
) {
294 instance
->physicalDeviceCount
= 1;
300 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
301 * otherwise it's an inout parameter.
303 * The Vulkan spec (git aaed022) says:
305 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
306 * that is initialized with the number of devices the application is
307 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
308 * an array of at least this many VkPhysicalDevice handles [...].
310 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
311 * overwrites the contents of the variable pointed to by
312 * pPhysicalDeviceCount with the number of physical devices in in the
313 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
314 * pPhysicalDeviceCount with the number of physical handles written to
317 if (!pPhysicalDevices
) {
318 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
319 } else if (*pPhysicalDeviceCount
>= 1) {
320 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
321 *pPhysicalDeviceCount
= 1;
323 *pPhysicalDeviceCount
= 0;
329 void anv_GetPhysicalDeviceFeatures(
330 VkPhysicalDevice physicalDevice
,
331 VkPhysicalDeviceFeatures
* pFeatures
)
333 anv_finishme("Get correct values for PhysicalDeviceFeatures");
335 *pFeatures
= (VkPhysicalDeviceFeatures
) {
336 .robustBufferAccess
= false,
337 .fullDrawIndexUint32
= false,
338 .imageCubeArray
= false,
339 .independentBlend
= false,
340 .geometryShader
= true,
341 .tessellationShader
= false,
342 .sampleRateShading
= false,
343 .dualSrcBlend
= true,
345 .multiDrawIndirect
= true,
347 .depthBiasClamp
= false,
348 .fillModeNonSolid
= true,
349 .depthBounds
= false,
353 .multiViewport
= true,
354 .samplerAnisotropy
= false, /* FINISHME */
355 .textureCompressionETC2
= true,
356 .textureCompressionASTC_LDR
= true,
357 .textureCompressionBC
= true,
358 .occlusionQueryPrecise
= false, /* FINISHME */
359 .pipelineStatisticsQuery
= true,
360 .vertexPipelineStoresAndAtomics
= false,
361 .fragmentStoresAndAtomics
= true,
362 .shaderTessellationAndGeometryPointSize
= true,
363 .shaderImageGatherExtended
= true,
364 .shaderStorageImageExtendedFormats
= false,
365 .shaderStorageImageMultisample
= false,
366 .shaderUniformBufferArrayDynamicIndexing
= true,
367 .shaderSampledImageArrayDynamicIndexing
= false,
368 .shaderStorageBufferArrayDynamicIndexing
= false,
369 .shaderStorageImageArrayDynamicIndexing
= false,
370 .shaderStorageImageReadWithoutFormat
= false,
371 .shaderStorageImageWriteWithoutFormat
= true,
372 .shaderClipDistance
= false,
373 .shaderCullDistance
= false,
374 .shaderFloat64
= false,
375 .shaderInt64
= false,
376 .shaderInt16
= false,
378 .variableMultisampleRate
= false,
382 void anv_GetPhysicalDeviceProperties(
383 VkPhysicalDevice physicalDevice
,
384 VkPhysicalDeviceProperties
* pProperties
)
386 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
387 const struct brw_device_info
*devinfo
= pdevice
->info
;
389 anv_finishme("Get correct values for VkPhysicalDeviceLimits");
391 VkSampleCountFlags sample_counts
=
392 VK_SAMPLE_COUNT_1_BIT
|
393 VK_SAMPLE_COUNT_2_BIT
|
394 VK_SAMPLE_COUNT_4_BIT
|
395 VK_SAMPLE_COUNT_8_BIT
;
397 VkPhysicalDeviceLimits limits
= {
398 .maxImageDimension1D
= (1 << 14),
399 .maxImageDimension2D
= (1 << 14),
400 .maxImageDimension3D
= (1 << 10),
401 .maxImageDimensionCube
= (1 << 14),
402 .maxImageArrayLayers
= (1 << 10),
403 .maxTexelBufferElements
= (1 << 14),
404 .maxUniformBufferRange
= UINT32_MAX
,
405 .maxStorageBufferRange
= UINT32_MAX
,
406 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
407 .maxMemoryAllocationCount
= UINT32_MAX
,
408 .maxSamplerAllocationCount
= UINT32_MAX
,
409 .bufferImageGranularity
= 64, /* A cache line */
410 .sparseAddressSpaceSize
= 0,
411 .maxBoundDescriptorSets
= MAX_SETS
,
412 .maxPerStageDescriptorSamplers
= 64,
413 .maxPerStageDescriptorUniformBuffers
= 64,
414 .maxPerStageDescriptorStorageBuffers
= 64,
415 .maxPerStageDescriptorSampledImages
= 64,
416 .maxPerStageDescriptorStorageImages
= 64,
417 .maxPerStageDescriptorInputAttachments
= 64,
418 .maxPerStageResources
= 128,
419 .maxDescriptorSetSamplers
= 256,
420 .maxDescriptorSetUniformBuffers
= 256,
421 .maxDescriptorSetUniformBuffersDynamic
= 256,
422 .maxDescriptorSetStorageBuffers
= 256,
423 .maxDescriptorSetStorageBuffersDynamic
= 256,
424 .maxDescriptorSetSampledImages
= 256,
425 .maxDescriptorSetStorageImages
= 256,
426 .maxDescriptorSetInputAttachments
= 256,
427 .maxVertexInputAttributes
= 32,
428 .maxVertexInputBindings
= 32,
429 .maxVertexInputAttributeOffset
= 256,
430 .maxVertexInputBindingStride
= 256,
431 .maxVertexOutputComponents
= 32,
432 .maxTessellationGenerationLevel
= 0,
433 .maxTessellationPatchSize
= 0,
434 .maxTessellationControlPerVertexInputComponents
= 0,
435 .maxTessellationControlPerVertexOutputComponents
= 0,
436 .maxTessellationControlPerPatchOutputComponents
= 0,
437 .maxTessellationControlTotalOutputComponents
= 0,
438 .maxTessellationEvaluationInputComponents
= 0,
439 .maxTessellationEvaluationOutputComponents
= 0,
440 .maxGeometryShaderInvocations
= 6,
441 .maxGeometryInputComponents
= 16,
442 .maxGeometryOutputComponents
= 16,
443 .maxGeometryOutputVertices
= 16,
444 .maxGeometryTotalOutputComponents
= 16,
445 .maxFragmentInputComponents
= 16,
446 .maxFragmentOutputAttachments
= 8,
447 .maxFragmentDualSrcAttachments
= 2,
448 .maxFragmentCombinedOutputResources
= 8,
449 .maxComputeSharedMemorySize
= 1024,
450 .maxComputeWorkGroupCount
= {
451 16 * devinfo
->max_cs_threads
,
452 16 * devinfo
->max_cs_threads
,
453 16 * devinfo
->max_cs_threads
,
455 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
456 .maxComputeWorkGroupSize
= {
457 16 * devinfo
->max_cs_threads
,
458 16 * devinfo
->max_cs_threads
,
459 16 * devinfo
->max_cs_threads
,
461 .subPixelPrecisionBits
= 4 /* FIXME */,
462 .subTexelPrecisionBits
= 4 /* FIXME */,
463 .mipmapPrecisionBits
= 4 /* FIXME */,
464 .maxDrawIndexedIndexValue
= UINT32_MAX
,
465 .maxDrawIndirectCount
= UINT32_MAX
,
466 .maxSamplerLodBias
= 16,
467 .maxSamplerAnisotropy
= 16,
468 .maxViewports
= MAX_VIEWPORTS
,
469 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
470 .viewportBoundsRange
= { -1.0, 1.0 }, /* FIXME */
471 .viewportSubPixelBits
= 13, /* We take a float? */
472 .minMemoryMapAlignment
= 64, /* A cache line */
473 .minTexelBufferOffsetAlignment
= 1,
474 .minUniformBufferOffsetAlignment
= 1,
475 .minStorageBufferOffsetAlignment
= 1,
476 .minTexelOffset
= 0, /* FIXME */
477 .maxTexelOffset
= 0, /* FIXME */
478 .minTexelGatherOffset
= 0, /* FIXME */
479 .maxTexelGatherOffset
= 0, /* FIXME */
480 .minInterpolationOffset
= 0, /* FIXME */
481 .maxInterpolationOffset
= 0, /* FIXME */
482 .subPixelInterpolationOffsetBits
= 0, /* FIXME */
483 .maxFramebufferWidth
= (1 << 14),
484 .maxFramebufferHeight
= (1 << 14),
485 .maxFramebufferLayers
= (1 << 10),
486 .framebufferColorSampleCounts
= sample_counts
,
487 .framebufferDepthSampleCounts
= sample_counts
,
488 .framebufferStencilSampleCounts
= sample_counts
,
489 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
490 .maxColorAttachments
= MAX_RTS
,
491 .sampledImageColorSampleCounts
= sample_counts
,
492 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
493 .sampledImageDepthSampleCounts
= sample_counts
,
494 .sampledImageStencilSampleCounts
= sample_counts
,
495 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
496 .maxSampleMaskWords
= 1,
497 .timestampPeriod
= 80.0 / (1000 * 1000 * 1000),
498 .maxClipDistances
= 0 /* FIXME */,
499 .maxCullDistances
= 0 /* FIXME */,
500 .maxCombinedClipAndCullDistances
= 0 /* FIXME */,
501 .discreteQueuePriorities
= 1,
502 .pointSizeRange
= { 0.125, 255.875 },
503 .lineWidthRange
= { 0.0, 7.9921875 },
504 .pointSizeGranularity
= (1.0 / 8.0),
505 .lineWidthGranularity
= (1.0 / 128.0),
506 .strictLines
= false, /* FINISHME */
507 .standardSampleLocations
= true, /* FINISHME */
508 .optimalBufferCopyOffsetAlignment
= 128,
509 .optimalBufferCopyRowPitchAlignment
= 128,
510 .nonCoherentAtomSize
= 64,
513 *pProperties
= (VkPhysicalDeviceProperties
) {
514 .apiVersion
= VK_MAKE_VERSION(0, 210, 1),
517 .deviceID
= pdevice
->chipset_id
,
518 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
520 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
523 strcpy(pProperties
->deviceName
, pdevice
->name
);
524 snprintf((char *)pProperties
->pipelineCacheUUID
, VK_UUID_SIZE
,
525 "anv-%s", MESA_GIT_SHA1
+ 4);
528 void anv_GetPhysicalDeviceQueueFamilyProperties(
529 VkPhysicalDevice physicalDevice
,
531 VkQueueFamilyProperties
* pQueueFamilyProperties
)
533 if (pQueueFamilyProperties
== NULL
) {
538 assert(*pCount
>= 1);
540 *pQueueFamilyProperties
= (VkQueueFamilyProperties
) {
541 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
542 VK_QUEUE_COMPUTE_BIT
|
543 VK_QUEUE_TRANSFER_BIT
,
545 .timestampValidBits
= 0, /* XXX: Real value here */
546 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
550 void anv_GetPhysicalDeviceMemoryProperties(
551 VkPhysicalDevice physicalDevice
,
552 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
554 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
555 VkDeviceSize heap_size
;
557 /* Reserve some wiggle room for the driver by exposing only 75% of the
558 * aperture to the heap.
560 heap_size
= 3 * physical_device
->aperture_size
/ 4;
562 if (physical_device
->info
->has_llc
) {
563 /* Big core GPUs share LLC with the CPU and thus one memory type can be
564 * both cached and coherent at the same time.
566 pMemoryProperties
->memoryTypeCount
= 1;
567 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
568 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
569 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
570 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
571 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
575 /* The spec requires that we expose a host-visible, coherent memory
576 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
577 * to give the application a choice between cached, but not coherent and
578 * coherent but uncached (WC though).
580 pMemoryProperties
->memoryTypeCount
= 2;
581 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
582 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
583 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
584 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
587 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
588 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
589 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
590 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
595 pMemoryProperties
->memoryHeapCount
= 1;
596 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
598 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
602 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
606 return anv_lookup_entrypoint(pName
);
609 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
613 return anv_lookup_entrypoint(pName
);
617 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
619 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
620 queue
->device
= device
;
621 queue
->pool
= &device
->surface_state_pool
;
627 anv_queue_finish(struct anv_queue
*queue
)
631 static struct anv_state
632 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
634 struct anv_state state
;
636 state
= anv_state_pool_alloc(pool
, size
, align
);
637 memcpy(state
.map
, p
, size
);
639 if (!pool
->block_pool
->device
->info
.has_llc
)
640 anv_state_clflush(state
);
646 anv_device_init_border_colors(struct anv_device
*device
)
648 static const VkClearColorValue border_colors
[] = {
649 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
650 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
651 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
652 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
653 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
654 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
657 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
658 sizeof(border_colors
), 32, border_colors
);
661 VkResult
anv_CreateDevice(
662 VkPhysicalDevice physicalDevice
,
663 const VkDeviceCreateInfo
* pCreateInfo
,
664 const VkAllocationCallbacks
* pAllocator
,
667 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
668 struct anv_device
*device
;
670 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
672 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
674 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
675 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
676 device_extensions
[j
].extensionName
) == 0) {
682 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
685 anv_set_dispatch_devinfo(physical_device
->info
);
687 device
= anv_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
689 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
691 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
693 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
694 device
->instance
= physical_device
->instance
;
697 device
->alloc
= *pAllocator
;
699 device
->alloc
= physical_device
->instance
->alloc
;
701 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
702 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
703 if (device
->fd
== -1)
706 device
->context_id
= anv_gem_create_context(device
);
707 if (device
->context_id
== -1)
710 pthread_mutex_init(&device
->mutex
, NULL
);
712 anv_bo_pool_init(&device
->batch_bo_pool
, device
, ANV_CMD_BUFFER_BATCH_SIZE
);
714 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
716 anv_state_pool_init(&device
->dynamic_state_pool
,
717 &device
->dynamic_state_block_pool
);
719 anv_block_pool_init(&device
->instruction_block_pool
, device
, 4096);
720 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
722 anv_state_pool_init(&device
->surface_state_pool
,
723 &device
->surface_state_block_pool
);
725 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
727 anv_block_pool_init(&device
->scratch_block_pool
, device
, 0x10000);
729 device
->info
= *physical_device
->info
;
730 device
->isl_dev
= physical_device
->isl_dev
;
732 anv_queue_init(device
, &device
->queue
);
734 anv_device_init_meta(device
);
736 anv_device_init_border_colors(device
);
738 *pDevice
= anv_device_to_handle(device
);
745 anv_free(&device
->alloc
, device
);
747 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
750 void anv_DestroyDevice(
752 const VkAllocationCallbacks
* pAllocator
)
754 ANV_FROM_HANDLE(anv_device
, device
, _device
);
756 anv_queue_finish(&device
->queue
);
758 anv_device_finish_meta(device
);
761 /* We only need to free these to prevent valgrind errors. The backing
762 * BO will go away in a couple of lines so we don't actually leak.
764 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
767 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
768 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
770 anv_bo_pool_finish(&device
->batch_bo_pool
);
771 anv_state_pool_finish(&device
->dynamic_state_pool
);
772 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
773 anv_block_pool_finish(&device
->instruction_block_pool
);
774 anv_state_pool_finish(&device
->surface_state_pool
);
775 anv_block_pool_finish(&device
->surface_state_block_pool
);
776 anv_block_pool_finish(&device
->scratch_block_pool
);
780 anv_free(&device
->alloc
, device
);
783 VkResult
anv_EnumerateInstanceExtensionProperties(
784 const char* pLayerName
,
785 uint32_t* pPropertyCount
,
786 VkExtensionProperties
* pProperties
)
788 if (pProperties
== NULL
) {
789 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
793 assert(*pPropertyCount
>= ARRAY_SIZE(global_extensions
));
795 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
796 memcpy(pProperties
, global_extensions
, sizeof(global_extensions
));
801 VkResult
anv_EnumerateDeviceExtensionProperties(
802 VkPhysicalDevice physicalDevice
,
803 const char* pLayerName
,
804 uint32_t* pPropertyCount
,
805 VkExtensionProperties
* pProperties
)
807 if (pProperties
== NULL
) {
808 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
812 assert(*pPropertyCount
>= ARRAY_SIZE(device_extensions
));
814 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
815 memcpy(pProperties
, device_extensions
, sizeof(device_extensions
));
820 VkResult
anv_EnumerateInstanceLayerProperties(
821 uint32_t* pPropertyCount
,
822 VkLayerProperties
* pProperties
)
824 if (pProperties
== NULL
) {
829 /* None supported at this time */
830 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
833 VkResult
anv_EnumerateDeviceLayerProperties(
834 VkPhysicalDevice physicalDevice
,
835 uint32_t* pPropertyCount
,
836 VkLayerProperties
* pProperties
)
838 if (pProperties
== NULL
) {
843 /* None supported at this time */
844 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
847 void anv_GetDeviceQueue(
849 uint32_t queueNodeIndex
,
853 ANV_FROM_HANDLE(anv_device
, device
, _device
);
855 assert(queueIndex
== 0);
857 *pQueue
= anv_queue_to_handle(&device
->queue
);
860 VkResult
anv_QueueSubmit(
862 uint32_t submitCount
,
863 const VkSubmitInfo
* pSubmits
,
866 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
867 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
868 struct anv_device
*device
= queue
->device
;
871 for (uint32_t i
= 0; i
< submitCount
; i
++) {
872 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
873 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
874 pSubmits
[i
].pCommandBuffers
[j
]);
875 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
877 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf2
.execbuf
);
879 /* We don't know the real error. */
880 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
881 "execbuf2 failed: %m");
885 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
887 /* We don't know the real error. */
888 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
889 "execbuf2 failed: %m");
893 for (uint32_t k
= 0; k
< cmd_buffer
->execbuf2
.bo_count
; k
++)
894 cmd_buffer
->execbuf2
.bos
[k
]->offset
= cmd_buffer
->execbuf2
.objects
[k
].offset
;
901 VkResult
anv_QueueWaitIdle(
904 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
906 return ANV_CALL(DeviceWaitIdle
)(anv_device_to_handle(queue
->device
));
909 VkResult
anv_DeviceWaitIdle(
912 ANV_FROM_HANDLE(anv_device
, device
, _device
);
913 struct anv_state state
;
914 struct anv_batch batch
;
915 struct drm_i915_gem_execbuffer2 execbuf
;
916 struct drm_i915_gem_exec_object2 exec2_objects
[1];
917 struct anv_bo
*bo
= NULL
;
922 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
923 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
924 batch
.start
= batch
.next
= state
.map
;
925 batch
.end
= state
.map
+ 32;
926 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
927 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
929 if (!device
->info
.has_llc
)
930 anv_state_clflush(state
);
932 exec2_objects
[0].handle
= bo
->gem_handle
;
933 exec2_objects
[0].relocation_count
= 0;
934 exec2_objects
[0].relocs_ptr
= 0;
935 exec2_objects
[0].alignment
= 0;
936 exec2_objects
[0].offset
= bo
->offset
;
937 exec2_objects
[0].flags
= 0;
938 exec2_objects
[0].rsvd1
= 0;
939 exec2_objects
[0].rsvd2
= 0;
941 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
942 execbuf
.buffer_count
= 1;
943 execbuf
.batch_start_offset
= state
.offset
;
944 execbuf
.batch_len
= batch
.next
- state
.map
;
945 execbuf
.cliprects_ptr
= 0;
946 execbuf
.num_cliprects
= 0;
951 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
952 execbuf
.rsvd1
= device
->context_id
;
955 ret
= anv_gem_execbuffer(device
, &execbuf
);
957 /* We don't know the real error. */
958 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
963 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
965 /* We don't know the real error. */
966 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
970 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
975 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
981 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
983 bo
->gem_handle
= anv_gem_create(device
, size
);
985 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
995 VkResult
anv_AllocateMemory(
997 const VkMemoryAllocateInfo
* pAllocateInfo
,
998 const VkAllocationCallbacks
* pAllocator
,
999 VkDeviceMemory
* pMem
)
1001 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1002 struct anv_device_memory
*mem
;
1005 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1007 /* We support exactly one memory heap. */
1008 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1009 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1011 /* FINISHME: Fail if allocation request exceeds heap size. */
1013 mem
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1014 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1016 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1018 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocateInfo
->allocationSize
);
1019 if (result
!= VK_SUCCESS
)
1022 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1024 *pMem
= anv_device_memory_to_handle(mem
);
1029 anv_free2(&device
->alloc
, pAllocator
, mem
);
1034 void anv_FreeMemory(
1036 VkDeviceMemory _mem
,
1037 const VkAllocationCallbacks
* pAllocator
)
1039 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1040 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1043 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1045 if (mem
->bo
.gem_handle
!= 0)
1046 anv_gem_close(device
, mem
->bo
.gem_handle
);
1048 anv_free2(&device
->alloc
, pAllocator
, mem
);
1051 VkResult
anv_MapMemory(
1053 VkDeviceMemory _memory
,
1054 VkDeviceSize offset
,
1056 VkMemoryMapFlags flags
,
1059 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1060 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1062 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1063 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1064 * at a time is valid. We could just mmap up front and return an offset
1065 * pointer here, but that may exhaust virtual memory on 32 bit
1068 uint32_t gem_flags
= 0;
1069 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1070 gem_flags
|= I915_MMAP_WC
;
1072 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
, gem_flags
);
1073 mem
->map_size
= size
;
1080 void anv_UnmapMemory(
1082 VkDeviceMemory _memory
)
1084 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1086 anv_gem_munmap(mem
->map
, mem
->map_size
);
1090 clflush_mapped_ranges(struct anv_device
*device
,
1092 const VkMappedMemoryRange
*ranges
)
1094 for (uint32_t i
= 0; i
< count
; i
++) {
1095 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1096 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1097 void *end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1100 __builtin_ia32_clflush(p
);
1101 p
+= CACHELINE_SIZE
;
1106 VkResult
anv_FlushMappedMemoryRanges(
1108 uint32_t memoryRangeCount
,
1109 const VkMappedMemoryRange
* pMemoryRanges
)
1111 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1113 if (device
->info
.has_llc
)
1116 /* Make sure the writes we're flushing have landed. */
1117 __builtin_ia32_sfence();
1119 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1124 VkResult
anv_InvalidateMappedMemoryRanges(
1126 uint32_t memoryRangeCount
,
1127 const VkMappedMemoryRange
* pMemoryRanges
)
1129 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1131 if (device
->info
.has_llc
)
1134 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1136 /* Make sure no reads get moved up above the invalidate. */
1137 __builtin_ia32_lfence();
1142 void anv_GetBufferMemoryRequirements(
1145 VkMemoryRequirements
* pMemoryRequirements
)
1147 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1149 /* The Vulkan spec (git aaed022) says:
1151 * memoryTypeBits is a bitfield and contains one bit set for every
1152 * supported memory type for the resource. The bit `1<<i` is set if and
1153 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1154 * structure for the physical device is supported.
1156 * We support exactly one memory type.
1158 pMemoryRequirements
->memoryTypeBits
= 1;
1160 pMemoryRequirements
->size
= buffer
->size
;
1161 pMemoryRequirements
->alignment
= 16;
1164 void anv_GetImageMemoryRequirements(
1167 VkMemoryRequirements
* pMemoryRequirements
)
1169 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1171 /* The Vulkan spec (git aaed022) says:
1173 * memoryTypeBits is a bitfield and contains one bit set for every
1174 * supported memory type for the resource. The bit `1<<i` is set if and
1175 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1176 * structure for the physical device is supported.
1178 * We support exactly one memory type.
1180 pMemoryRequirements
->memoryTypeBits
= 1;
1182 pMemoryRequirements
->size
= image
->size
;
1183 pMemoryRequirements
->alignment
= image
->alignment
;
1186 void anv_GetImageSparseMemoryRequirements(
1189 uint32_t* pSparseMemoryRequirementCount
,
1190 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1195 void anv_GetDeviceMemoryCommitment(
1197 VkDeviceMemory memory
,
1198 VkDeviceSize
* pCommittedMemoryInBytes
)
1200 *pCommittedMemoryInBytes
= 0;
1203 VkResult
anv_BindBufferMemory(
1206 VkDeviceMemory _memory
,
1207 VkDeviceSize memoryOffset
)
1209 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1210 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1212 buffer
->bo
= &mem
->bo
;
1213 buffer
->offset
= memoryOffset
;
1218 VkResult
anv_BindImageMemory(
1221 VkDeviceMemory _memory
,
1222 VkDeviceSize memoryOffset
)
1224 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1225 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1227 image
->bo
= &mem
->bo
;
1228 image
->offset
= memoryOffset
;
1233 VkResult
anv_QueueBindSparse(
1235 uint32_t bindInfoCount
,
1236 const VkBindSparseInfo
* pBindInfo
,
1239 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1242 VkResult
anv_CreateFence(
1244 const VkFenceCreateInfo
* pCreateInfo
,
1245 const VkAllocationCallbacks
* pAllocator
,
1248 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1249 struct anv_fence
*fence
;
1250 struct anv_batch batch
;
1253 const uint32_t fence_size
= 128;
1255 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1257 fence
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*fence
), 8,
1258 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1260 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1262 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1263 if (result
!= VK_SUCCESS
)
1267 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
, 0);
1268 batch
.next
= batch
.start
= fence
->bo
.map
;
1269 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1270 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
1271 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
1273 if (!device
->info
.has_llc
) {
1274 assert(((uintptr_t) fence
->bo
.map
& CACHELINE_MASK
) == 0);
1275 assert(batch
.next
- fence
->bo
.map
<= CACHELINE_SIZE
);
1276 __builtin_ia32_sfence();
1277 __builtin_ia32_clflush(fence
->bo
.map
);
1280 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1281 fence
->exec2_objects
[0].relocation_count
= 0;
1282 fence
->exec2_objects
[0].relocs_ptr
= 0;
1283 fence
->exec2_objects
[0].alignment
= 0;
1284 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1285 fence
->exec2_objects
[0].flags
= 0;
1286 fence
->exec2_objects
[0].rsvd1
= 0;
1287 fence
->exec2_objects
[0].rsvd2
= 0;
1289 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1290 fence
->execbuf
.buffer_count
= 1;
1291 fence
->execbuf
.batch_start_offset
= 0;
1292 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1293 fence
->execbuf
.cliprects_ptr
= 0;
1294 fence
->execbuf
.num_cliprects
= 0;
1295 fence
->execbuf
.DR1
= 0;
1296 fence
->execbuf
.DR4
= 0;
1298 fence
->execbuf
.flags
=
1299 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1300 fence
->execbuf
.rsvd1
= device
->context_id
;
1301 fence
->execbuf
.rsvd2
= 0;
1303 *pFence
= anv_fence_to_handle(fence
);
1308 anv_free2(&device
->alloc
, pAllocator
, fence
);
1313 void anv_DestroyFence(
1316 const VkAllocationCallbacks
* pAllocator
)
1318 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1319 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1321 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1322 anv_gem_close(device
, fence
->bo
.gem_handle
);
1323 anv_free2(&device
->alloc
, pAllocator
, fence
);
1326 VkResult
anv_ResetFences(
1328 uint32_t fenceCount
,
1329 const VkFence
* pFences
)
1331 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1332 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1333 fence
->ready
= false;
1339 VkResult
anv_GetFenceStatus(
1343 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1344 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1351 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1353 fence
->ready
= true;
1357 return VK_NOT_READY
;
1360 VkResult
anv_WaitForFences(
1362 uint32_t fenceCount
,
1363 const VkFence
* pFences
,
1367 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1369 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1370 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1371 * for a couple of kernel releases. Since there's no way to know
1372 * whether or not the kernel we're using is one of the broken ones, the
1373 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1374 * maximum timeout from 584 years to 292 years - likely not a big deal.
1376 if (timeout
> INT64_MAX
)
1377 timeout
= INT64_MAX
;
1379 int64_t t
= timeout
;
1381 /* FIXME: handle !waitAll */
1383 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1384 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1385 int ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1386 if (ret
== -1 && errno
== ETIME
) {
1388 } else if (ret
== -1) {
1389 /* We don't know the real error. */
1390 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1391 "gem wait failed: %m");
1398 // Queue semaphore functions
1400 VkResult
anv_CreateSemaphore(
1402 const VkSemaphoreCreateInfo
* pCreateInfo
,
1403 const VkAllocationCallbacks
* pAllocator
,
1404 VkSemaphore
* pSemaphore
)
1406 *pSemaphore
= (VkSemaphore
)1;
1407 stub_return(VK_SUCCESS
);
1410 void anv_DestroySemaphore(
1412 VkSemaphore semaphore
,
1413 const VkAllocationCallbacks
* pAllocator
)
1420 VkResult
anv_CreateEvent(
1422 const VkEventCreateInfo
* pCreateInfo
,
1423 const VkAllocationCallbacks
* pAllocator
,
1426 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1429 void anv_DestroyEvent(
1432 const VkAllocationCallbacks
* pAllocator
)
1437 VkResult
anv_GetEventStatus(
1441 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1444 VkResult
anv_SetEvent(
1448 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1451 VkResult
anv_ResetEvent(
1455 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1460 VkResult
anv_CreateBuffer(
1462 const VkBufferCreateInfo
* pCreateInfo
,
1463 const VkAllocationCallbacks
* pAllocator
,
1466 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1467 struct anv_buffer
*buffer
;
1469 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1471 buffer
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1472 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1474 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1476 buffer
->size
= pCreateInfo
->size
;
1480 *pBuffer
= anv_buffer_to_handle(buffer
);
1485 void anv_DestroyBuffer(
1488 const VkAllocationCallbacks
* pAllocator
)
1490 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1491 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1493 anv_free2(&device
->alloc
, pAllocator
, buffer
);
1497 anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1498 const struct anv_format
*format
,
1499 uint32_t offset
, uint32_t range
, uint32_t stride
)
1501 switch (device
->info
.gen
) {
1503 if (device
->info
.is_haswell
)
1504 gen75_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1506 gen7_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1509 gen8_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1512 gen9_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1515 unreachable("unsupported gen\n");
1519 VkResult
anv_CreateBufferView(
1521 const VkBufferViewCreateInfo
* pCreateInfo
,
1522 const VkAllocationCallbacks
* pAllocator
,
1523 VkBufferView
* pView
)
1525 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1528 void anv_DestroyBufferView(
1530 VkBufferView _bview
,
1531 const VkAllocationCallbacks
* pAllocator
)
1536 void anv_DestroySampler(
1539 const VkAllocationCallbacks
* pAllocator
)
1541 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1542 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1544 anv_free2(&device
->alloc
, pAllocator
, sampler
);
1547 VkResult
anv_CreateFramebuffer(
1549 const VkFramebufferCreateInfo
* pCreateInfo
,
1550 const VkAllocationCallbacks
* pAllocator
,
1551 VkFramebuffer
* pFramebuffer
)
1553 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1554 struct anv_framebuffer
*framebuffer
;
1556 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1558 size_t size
= sizeof(*framebuffer
) +
1559 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
1560 framebuffer
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1561 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1562 if (framebuffer
== NULL
)
1563 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1565 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1566 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1567 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1568 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
1571 framebuffer
->width
= pCreateInfo
->width
;
1572 framebuffer
->height
= pCreateInfo
->height
;
1573 framebuffer
->layers
= pCreateInfo
->layers
;
1575 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
1580 void anv_DestroyFramebuffer(
1583 const VkAllocationCallbacks
* pAllocator
)
1585 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1586 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
1588 anv_free2(&device
->alloc
, pAllocator
, fb
);
1591 void vkCmdDbgMarkerBegin(
1592 VkCommandBuffer commandBuffer
,
1593 const char* pMarker
)
1594 __attribute__ ((visibility ("default")));
1596 void vkCmdDbgMarkerEnd(
1597 VkCommandBuffer commandBuffer
)
1598 __attribute__ ((visibility ("default")));
1600 void vkCmdDbgMarkerBegin(
1601 VkCommandBuffer commandBuffer
,
1602 const char* pMarker
)
1606 void vkCmdDbgMarkerEnd(
1607 VkCommandBuffer commandBuffer
)