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
== 7 && device
->info
->is_baytrail
) {
91 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
92 } else if (device
->info
->gen
== 9 && !device
->info
->is_broxton
) {
93 fprintf(stderr
, "WARNING: Skylake Vulkan support is incomplete\n");
94 } else if (device
->info
->gen
== 9 && device
->info
->is_broxton
) {
95 fprintf(stderr
, "WARNING: Broxton Vulkan support is incomplete\n");
96 } else if (device
->info
->gen
== 8) {
97 /* Broadwell/Cherryview is as fully supported as anything */
99 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
100 "Vulkan not yet supported on %s", device
->name
);
104 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
105 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
106 "failed to get aperture size: %m");
110 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
111 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
112 "kernel missing gem wait");
116 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
117 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
118 "kernel missing execbuf2");
122 if (anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
< 1)) {
123 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
124 "kernel missing wc mmap");
130 brw_process_intel_debug_variable();
132 device
->compiler
= brw_compiler_create(NULL
, device
->info
);
133 if (device
->compiler
== NULL
) {
134 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
137 device
->compiler
->shader_debug_log
= compiler_debug_log
;
138 device
->compiler
->shader_perf_log
= compiler_perf_log
;
140 isl_device_init(&device
->isl_dev
, device
->info
);
150 anv_physical_device_finish(struct anv_physical_device
*device
)
152 ralloc_free(device
->compiler
);
155 static const VkExtensionProperties global_extensions
[] = {
157 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
161 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
164 #ifdef HAVE_WAYLAND_PLATFORM
166 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
172 static const VkExtensionProperties device_extensions
[] = {
174 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
180 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
181 VkSystemAllocationScope allocationScope
)
187 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
188 size_t align
, VkSystemAllocationScope allocationScope
)
190 return realloc(pOriginal
, size
);
194 default_free_func(void *pUserData
, void *pMemory
)
199 static const VkAllocationCallbacks default_alloc
= {
201 .pfnAllocation
= default_alloc_func
,
202 .pfnReallocation
= default_realloc_func
,
203 .pfnFree
= default_free_func
,
206 VkResult
anv_CreateInstance(
207 const VkInstanceCreateInfo
* pCreateInfo
,
208 const VkAllocationCallbacks
* pAllocator
,
209 VkInstance
* pInstance
)
211 struct anv_instance
*instance
;
213 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
215 if (pCreateInfo
->pApplicationInfo
->apiVersion
!= VK_MAKE_VERSION(0, 210, 1))
216 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
218 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
220 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
221 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
222 global_extensions
[j
].extensionName
) == 0) {
228 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
231 instance
= anv_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
232 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
234 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
236 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
239 instance
->alloc
= *pAllocator
;
241 instance
->alloc
= default_alloc
;
243 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
244 instance
->physicalDeviceCount
= -1;
248 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
250 anv_init_wsi(instance
);
252 *pInstance
= anv_instance_to_handle(instance
);
257 void anv_DestroyInstance(
258 VkInstance _instance
,
259 const VkAllocationCallbacks
* pAllocator
)
261 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
263 if (instance
->physicalDeviceCount
> 0) {
264 /* We support at most one physical device. */
265 assert(instance
->physicalDeviceCount
== 1);
266 anv_physical_device_finish(&instance
->physicalDevice
);
269 anv_finish_wsi(instance
);
271 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
275 anv_free(&instance
->alloc
, instance
);
278 VkResult
anv_EnumeratePhysicalDevices(
279 VkInstance _instance
,
280 uint32_t* pPhysicalDeviceCount
,
281 VkPhysicalDevice
* pPhysicalDevices
)
283 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
286 if (instance
->physicalDeviceCount
< 0) {
287 result
= anv_physical_device_init(&instance
->physicalDevice
,
288 instance
, "/dev/dri/renderD128");
289 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
290 instance
->physicalDeviceCount
= 0;
291 } else if (result
== VK_SUCCESS
) {
292 instance
->physicalDeviceCount
= 1;
298 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
299 * otherwise it's an inout parameter.
301 * The Vulkan spec (git aaed022) says:
303 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
304 * that is initialized with the number of devices the application is
305 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
306 * an array of at least this many VkPhysicalDevice handles [...].
308 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
309 * overwrites the contents of the variable pointed to by
310 * pPhysicalDeviceCount with the number of physical devices in in the
311 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
312 * pPhysicalDeviceCount with the number of physical handles written to
315 if (!pPhysicalDevices
) {
316 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
317 } else if (*pPhysicalDeviceCount
>= 1) {
318 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
319 *pPhysicalDeviceCount
= 1;
321 *pPhysicalDeviceCount
= 0;
327 void anv_GetPhysicalDeviceFeatures(
328 VkPhysicalDevice physicalDevice
,
329 VkPhysicalDeviceFeatures
* pFeatures
)
331 anv_finishme("Get correct values for PhysicalDeviceFeatures");
333 *pFeatures
= (VkPhysicalDeviceFeatures
) {
334 .robustBufferAccess
= false,
335 .fullDrawIndexUint32
= false,
336 .imageCubeArray
= false,
337 .independentBlend
= false,
338 .geometryShader
= true,
339 .tessellationShader
= false,
340 .sampleRateShading
= false,
341 .dualSrcBlend
= true,
343 .multiDrawIndirect
= true,
345 .depthBiasClamp
= false,
346 .fillModeNonSolid
= true,
347 .depthBounds
= false,
351 .multiViewport
= true,
352 .samplerAnisotropy
= false, /* FINISHME */
353 .textureCompressionETC2
= true,
354 .textureCompressionASTC_LDR
= true,
355 .textureCompressionBC
= true,
356 .occlusionQueryPrecise
= false, /* FINISHME */
357 .pipelineStatisticsQuery
= true,
358 .vertexPipelineStoresAndAtomics
= false,
359 .fragmentStoresAndAtomics
= true,
360 .shaderTessellationAndGeometryPointSize
= true,
361 .shaderImageGatherExtended
= true,
362 .shaderStorageImageExtendedFormats
= false,
363 .shaderStorageImageMultisample
= false,
364 .shaderUniformBufferArrayDynamicIndexing
= true,
365 .shaderSampledImageArrayDynamicIndexing
= false,
366 .shaderStorageBufferArrayDynamicIndexing
= false,
367 .shaderStorageImageArrayDynamicIndexing
= false,
368 .shaderStorageImageReadWithoutFormat
= false,
369 .shaderStorageImageWriteWithoutFormat
= true,
370 .shaderClipDistance
= false,
371 .shaderCullDistance
= false,
372 .shaderFloat64
= false,
373 .shaderInt64
= false,
374 .shaderInt16
= false,
376 .variableMultisampleRate
= false,
380 void anv_GetPhysicalDeviceProperties(
381 VkPhysicalDevice physicalDevice
,
382 VkPhysicalDeviceProperties
* pProperties
)
384 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
385 const struct brw_device_info
*devinfo
= pdevice
->info
;
387 anv_finishme("Get correct values for VkPhysicalDeviceLimits");
389 VkSampleCountFlags sample_counts
=
390 VK_SAMPLE_COUNT_1_BIT
|
391 VK_SAMPLE_COUNT_2_BIT
|
392 VK_SAMPLE_COUNT_4_BIT
|
393 VK_SAMPLE_COUNT_8_BIT
;
395 VkPhysicalDeviceLimits limits
= {
396 .maxImageDimension1D
= (1 << 14),
397 .maxImageDimension2D
= (1 << 14),
398 .maxImageDimension3D
= (1 << 10),
399 .maxImageDimensionCube
= (1 << 14),
400 .maxImageArrayLayers
= (1 << 10),
401 .maxTexelBufferElements
= (1 << 14),
402 .maxUniformBufferRange
= UINT32_MAX
,
403 .maxStorageBufferRange
= UINT32_MAX
,
404 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
405 .maxMemoryAllocationCount
= UINT32_MAX
,
406 .maxSamplerAllocationCount
= UINT32_MAX
,
407 .bufferImageGranularity
= 64, /* A cache line */
408 .sparseAddressSpaceSize
= 0,
409 .maxBoundDescriptorSets
= MAX_SETS
,
410 .maxPerStageDescriptorSamplers
= 64,
411 .maxPerStageDescriptorUniformBuffers
= 64,
412 .maxPerStageDescriptorStorageBuffers
= 64,
413 .maxPerStageDescriptorSampledImages
= 64,
414 .maxPerStageDescriptorStorageImages
= 64,
415 .maxPerStageDescriptorInputAttachments
= 64,
416 .maxPerStageResources
= 128,
417 .maxDescriptorSetSamplers
= 256,
418 .maxDescriptorSetUniformBuffers
= 256,
419 .maxDescriptorSetUniformBuffersDynamic
= 256,
420 .maxDescriptorSetStorageBuffers
= 256,
421 .maxDescriptorSetStorageBuffersDynamic
= 256,
422 .maxDescriptorSetSampledImages
= 256,
423 .maxDescriptorSetStorageImages
= 256,
424 .maxDescriptorSetInputAttachments
= 256,
425 .maxVertexInputAttributes
= 32,
426 .maxVertexInputBindings
= 32,
427 .maxVertexInputAttributeOffset
= 256,
428 .maxVertexInputBindingStride
= 256,
429 .maxVertexOutputComponents
= 32,
430 .maxTessellationGenerationLevel
= 0,
431 .maxTessellationPatchSize
= 0,
432 .maxTessellationControlPerVertexInputComponents
= 0,
433 .maxTessellationControlPerVertexOutputComponents
= 0,
434 .maxTessellationControlPerPatchOutputComponents
= 0,
435 .maxTessellationControlTotalOutputComponents
= 0,
436 .maxTessellationEvaluationInputComponents
= 0,
437 .maxTessellationEvaluationOutputComponents
= 0,
438 .maxGeometryShaderInvocations
= 6,
439 .maxGeometryInputComponents
= 16,
440 .maxGeometryOutputComponents
= 16,
441 .maxGeometryOutputVertices
= 16,
442 .maxGeometryTotalOutputComponents
= 16,
443 .maxFragmentInputComponents
= 16,
444 .maxFragmentOutputAttachments
= 8,
445 .maxFragmentDualSrcAttachments
= 2,
446 .maxFragmentCombinedOutputResources
= 8,
447 .maxComputeSharedMemorySize
= 1024,
448 .maxComputeWorkGroupCount
= {
449 16 * devinfo
->max_cs_threads
,
450 16 * devinfo
->max_cs_threads
,
451 16 * devinfo
->max_cs_threads
,
453 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
454 .maxComputeWorkGroupSize
= {
455 16 * devinfo
->max_cs_threads
,
456 16 * devinfo
->max_cs_threads
,
457 16 * devinfo
->max_cs_threads
,
459 .subPixelPrecisionBits
= 4 /* FIXME */,
460 .subTexelPrecisionBits
= 4 /* FIXME */,
461 .mipmapPrecisionBits
= 4 /* FIXME */,
462 .maxDrawIndexedIndexValue
= UINT32_MAX
,
463 .maxDrawIndirectCount
= UINT32_MAX
,
464 .maxSamplerLodBias
= 16,
465 .maxSamplerAnisotropy
= 16,
466 .maxViewports
= MAX_VIEWPORTS
,
467 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
468 .viewportBoundsRange
= { -1.0, 1.0 }, /* FIXME */
469 .viewportSubPixelBits
= 13, /* We take a float? */
470 .minMemoryMapAlignment
= 64, /* A cache line */
471 .minTexelBufferOffsetAlignment
= 1,
472 .minUniformBufferOffsetAlignment
= 1,
473 .minStorageBufferOffsetAlignment
= 1,
474 .minTexelOffset
= 0, /* FIXME */
475 .maxTexelOffset
= 0, /* FIXME */
476 .minTexelGatherOffset
= 0, /* FIXME */
477 .maxTexelGatherOffset
= 0, /* FIXME */
478 .minInterpolationOffset
= 0, /* FIXME */
479 .maxInterpolationOffset
= 0, /* FIXME */
480 .subPixelInterpolationOffsetBits
= 0, /* FIXME */
481 .maxFramebufferWidth
= (1 << 14),
482 .maxFramebufferHeight
= (1 << 14),
483 .maxFramebufferLayers
= (1 << 10),
484 .framebufferColorSampleCounts
= sample_counts
,
485 .framebufferDepthSampleCounts
= sample_counts
,
486 .framebufferStencilSampleCounts
= sample_counts
,
487 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
488 .maxColorAttachments
= MAX_RTS
,
489 .sampledImageColorSampleCounts
= sample_counts
,
490 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
491 .sampledImageDepthSampleCounts
= sample_counts
,
492 .sampledImageStencilSampleCounts
= sample_counts
,
493 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
494 .maxSampleMaskWords
= 1,
495 .timestampPeriod
= 80.0 / (1000 * 1000 * 1000),
496 .maxClipDistances
= 0 /* FIXME */,
497 .maxCullDistances
= 0 /* FIXME */,
498 .maxCombinedClipAndCullDistances
= 0 /* FIXME */,
499 .discreteQueuePriorities
= 1,
500 .pointSizeRange
= { 0.125, 255.875 },
501 .lineWidthRange
= { 0.0, 7.9921875 },
502 .pointSizeGranularity
= (1.0 / 8.0),
503 .lineWidthGranularity
= (1.0 / 128.0),
504 .strictLines
= false, /* FINISHME */
505 .standardSampleLocations
= true, /* FINISHME */
506 .optimalBufferCopyOffsetAlignment
= 128,
507 .optimalBufferCopyRowPitchAlignment
= 128,
508 .nonCoherentAtomSize
= 64,
511 *pProperties
= (VkPhysicalDeviceProperties
) {
512 .apiVersion
= VK_MAKE_VERSION(0, 210, 1),
515 .deviceID
= pdevice
->chipset_id
,
516 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
518 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
521 strcpy(pProperties
->deviceName
, pdevice
->name
);
522 snprintf((char *)pProperties
->pipelineCacheUUID
, VK_UUID_SIZE
,
523 "anv-%s", MESA_GIT_SHA1
+ 4);
526 void anv_GetPhysicalDeviceQueueFamilyProperties(
527 VkPhysicalDevice physicalDevice
,
529 VkQueueFamilyProperties
* pQueueFamilyProperties
)
531 if (pQueueFamilyProperties
== NULL
) {
536 assert(*pCount
>= 1);
538 *pQueueFamilyProperties
= (VkQueueFamilyProperties
) {
539 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
540 VK_QUEUE_COMPUTE_BIT
|
541 VK_QUEUE_TRANSFER_BIT
,
543 .timestampValidBits
= 0, /* XXX: Real value here */
544 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
548 void anv_GetPhysicalDeviceMemoryProperties(
549 VkPhysicalDevice physicalDevice
,
550 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
552 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
553 VkDeviceSize heap_size
;
555 /* Reserve some wiggle room for the driver by exposing only 75% of the
556 * aperture to the heap.
558 heap_size
= 3 * physical_device
->aperture_size
/ 4;
560 if (physical_device
->info
->has_llc
) {
561 /* Big core GPUs share LLC with the CPU and thus one memory type can be
562 * both cached and coherent at the same time.
564 pMemoryProperties
->memoryTypeCount
= 1;
565 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
566 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
567 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
568 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
569 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
573 /* The spec requires that we expose a host-visible, coherent memory
574 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
575 * to give the application a choice between cached, but not coherent and
576 * coherent but uncached (WC though).
578 pMemoryProperties
->memoryTypeCount
= 2;
579 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
580 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
581 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
582 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
585 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
586 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
587 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
588 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
593 pMemoryProperties
->memoryHeapCount
= 1;
594 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
596 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
600 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
604 return anv_lookup_entrypoint(pName
);
607 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
611 return anv_lookup_entrypoint(pName
);
615 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
617 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
618 queue
->device
= device
;
619 queue
->pool
= &device
->surface_state_pool
;
625 anv_queue_finish(struct anv_queue
*queue
)
629 static struct anv_state
630 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
632 struct anv_state state
;
634 state
= anv_state_pool_alloc(pool
, size
, align
);
635 memcpy(state
.map
, p
, size
);
637 if (!pool
->block_pool
->device
->info
.has_llc
)
638 anv_state_clflush(state
);
644 anv_device_init_border_colors(struct anv_device
*device
)
646 static const VkClearColorValue border_colors
[] = {
647 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
648 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
649 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
650 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
651 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
652 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
655 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
656 sizeof(border_colors
), 32, border_colors
);
659 VkResult
anv_CreateDevice(
660 VkPhysicalDevice physicalDevice
,
661 const VkDeviceCreateInfo
* pCreateInfo
,
662 const VkAllocationCallbacks
* pAllocator
,
665 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
666 struct anv_device
*device
;
668 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
670 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
672 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
673 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
674 device_extensions
[j
].extensionName
) == 0) {
680 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
683 anv_set_dispatch_devinfo(physical_device
->info
);
685 device
= anv_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
687 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
689 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
691 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
692 device
->instance
= physical_device
->instance
;
695 device
->alloc
= *pAllocator
;
697 device
->alloc
= physical_device
->instance
->alloc
;
699 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
700 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
701 if (device
->fd
== -1)
704 device
->context_id
= anv_gem_create_context(device
);
705 if (device
->context_id
== -1)
708 pthread_mutex_init(&device
->mutex
, NULL
);
710 anv_bo_pool_init(&device
->batch_bo_pool
, device
, ANV_CMD_BUFFER_BATCH_SIZE
);
712 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
714 anv_state_pool_init(&device
->dynamic_state_pool
,
715 &device
->dynamic_state_block_pool
);
717 anv_block_pool_init(&device
->instruction_block_pool
, device
, 4096);
718 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
720 anv_state_pool_init(&device
->surface_state_pool
,
721 &device
->surface_state_block_pool
);
723 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
725 anv_block_pool_init(&device
->scratch_block_pool
, device
, 0x10000);
727 device
->info
= *physical_device
->info
;
728 device
->isl_dev
= physical_device
->isl_dev
;
730 anv_queue_init(device
, &device
->queue
);
732 anv_device_init_meta(device
);
734 anv_device_init_border_colors(device
);
736 *pDevice
= anv_device_to_handle(device
);
743 anv_free(&device
->alloc
, device
);
745 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
748 void anv_DestroyDevice(
750 const VkAllocationCallbacks
* pAllocator
)
752 ANV_FROM_HANDLE(anv_device
, device
, _device
);
754 anv_queue_finish(&device
->queue
);
756 anv_device_finish_meta(device
);
759 /* We only need to free these to prevent valgrind errors. The backing
760 * BO will go away in a couple of lines so we don't actually leak.
762 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
765 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
766 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
768 anv_bo_pool_finish(&device
->batch_bo_pool
);
769 anv_state_pool_finish(&device
->dynamic_state_pool
);
770 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
771 anv_block_pool_finish(&device
->instruction_block_pool
);
772 anv_state_pool_finish(&device
->surface_state_pool
);
773 anv_block_pool_finish(&device
->surface_state_block_pool
);
774 anv_block_pool_finish(&device
->scratch_block_pool
);
778 anv_free(&device
->alloc
, device
);
781 VkResult
anv_EnumerateInstanceExtensionProperties(
782 const char* pLayerName
,
783 uint32_t* pPropertyCount
,
784 VkExtensionProperties
* pProperties
)
786 if (pProperties
== NULL
) {
787 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
791 assert(*pPropertyCount
>= ARRAY_SIZE(global_extensions
));
793 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
794 memcpy(pProperties
, global_extensions
, sizeof(global_extensions
));
799 VkResult
anv_EnumerateDeviceExtensionProperties(
800 VkPhysicalDevice physicalDevice
,
801 const char* pLayerName
,
802 uint32_t* pPropertyCount
,
803 VkExtensionProperties
* pProperties
)
805 if (pProperties
== NULL
) {
806 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
810 assert(*pPropertyCount
>= ARRAY_SIZE(device_extensions
));
812 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
813 memcpy(pProperties
, device_extensions
, sizeof(device_extensions
));
818 VkResult
anv_EnumerateInstanceLayerProperties(
819 uint32_t* pPropertyCount
,
820 VkLayerProperties
* pProperties
)
822 if (pProperties
== NULL
) {
827 /* None supported at this time */
828 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
831 VkResult
anv_EnumerateDeviceLayerProperties(
832 VkPhysicalDevice physicalDevice
,
833 uint32_t* pPropertyCount
,
834 VkLayerProperties
* pProperties
)
836 if (pProperties
== NULL
) {
841 /* None supported at this time */
842 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
845 void anv_GetDeviceQueue(
847 uint32_t queueNodeIndex
,
851 ANV_FROM_HANDLE(anv_device
, device
, _device
);
853 assert(queueIndex
== 0);
855 *pQueue
= anv_queue_to_handle(&device
->queue
);
858 VkResult
anv_QueueSubmit(
860 uint32_t submitCount
,
861 const VkSubmitInfo
* pSubmits
,
864 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
865 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
866 struct anv_device
*device
= queue
->device
;
869 for (uint32_t i
= 0; i
< submitCount
; i
++) {
870 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
871 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
872 pSubmits
[i
].pCommandBuffers
[j
]);
873 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
875 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf2
.execbuf
);
877 /* We don't know the real error. */
878 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
879 "execbuf2 failed: %m");
883 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
885 /* We don't know the real error. */
886 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
887 "execbuf2 failed: %m");
891 for (uint32_t k
= 0; k
< cmd_buffer
->execbuf2
.bo_count
; k
++)
892 cmd_buffer
->execbuf2
.bos
[k
]->offset
= cmd_buffer
->execbuf2
.objects
[k
].offset
;
899 VkResult
anv_QueueWaitIdle(
902 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
904 return ANV_CALL(DeviceWaitIdle
)(anv_device_to_handle(queue
->device
));
907 VkResult
anv_DeviceWaitIdle(
910 ANV_FROM_HANDLE(anv_device
, device
, _device
);
911 struct anv_state state
;
912 struct anv_batch batch
;
913 struct drm_i915_gem_execbuffer2 execbuf
;
914 struct drm_i915_gem_exec_object2 exec2_objects
[1];
915 struct anv_bo
*bo
= NULL
;
920 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
921 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
922 batch
.start
= batch
.next
= state
.map
;
923 batch
.end
= state
.map
+ 32;
924 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
925 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
927 if (!device
->info
.has_llc
)
928 anv_state_clflush(state
);
930 exec2_objects
[0].handle
= bo
->gem_handle
;
931 exec2_objects
[0].relocation_count
= 0;
932 exec2_objects
[0].relocs_ptr
= 0;
933 exec2_objects
[0].alignment
= 0;
934 exec2_objects
[0].offset
= bo
->offset
;
935 exec2_objects
[0].flags
= 0;
936 exec2_objects
[0].rsvd1
= 0;
937 exec2_objects
[0].rsvd2
= 0;
939 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
940 execbuf
.buffer_count
= 1;
941 execbuf
.batch_start_offset
= state
.offset
;
942 execbuf
.batch_len
= batch
.next
- state
.map
;
943 execbuf
.cliprects_ptr
= 0;
944 execbuf
.num_cliprects
= 0;
949 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
950 execbuf
.rsvd1
= device
->context_id
;
953 ret
= anv_gem_execbuffer(device
, &execbuf
);
955 /* We don't know the real error. */
956 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
961 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
963 /* We don't know the real error. */
964 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
968 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
973 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
979 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
981 bo
->gem_handle
= anv_gem_create(device
, size
);
983 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
993 VkResult
anv_AllocateMemory(
995 const VkMemoryAllocateInfo
* pAllocateInfo
,
996 const VkAllocationCallbacks
* pAllocator
,
997 VkDeviceMemory
* pMem
)
999 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1000 struct anv_device_memory
*mem
;
1003 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1005 /* We support exactly one memory heap. */
1006 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1007 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1009 /* FINISHME: Fail if allocation request exceeds heap size. */
1011 mem
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1012 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1014 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1016 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocateInfo
->allocationSize
);
1017 if (result
!= VK_SUCCESS
)
1020 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1022 *pMem
= anv_device_memory_to_handle(mem
);
1027 anv_free2(&device
->alloc
, pAllocator
, mem
);
1032 void anv_FreeMemory(
1034 VkDeviceMemory _mem
,
1035 const VkAllocationCallbacks
* pAllocator
)
1037 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1038 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1041 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1043 if (mem
->bo
.gem_handle
!= 0)
1044 anv_gem_close(device
, mem
->bo
.gem_handle
);
1046 anv_free2(&device
->alloc
, pAllocator
, mem
);
1049 VkResult
anv_MapMemory(
1051 VkDeviceMemory _memory
,
1052 VkDeviceSize offset
,
1054 VkMemoryMapFlags flags
,
1057 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1058 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1060 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1061 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1062 * at a time is valid. We could just mmap up front and return an offset
1063 * pointer here, but that may exhaust virtual memory on 32 bit
1066 uint32_t gem_flags
= 0;
1067 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1068 gem_flags
|= I915_MMAP_WC
;
1070 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
, gem_flags
);
1071 mem
->map_size
= size
;
1078 void anv_UnmapMemory(
1080 VkDeviceMemory _memory
)
1082 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1084 anv_gem_munmap(mem
->map
, mem
->map_size
);
1088 clflush_mapped_ranges(struct anv_device
*device
,
1090 const VkMappedMemoryRange
*ranges
)
1092 for (uint32_t i
= 0; i
< count
; i
++) {
1093 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1094 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1095 void *end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1098 __builtin_ia32_clflush(p
);
1099 p
+= CACHELINE_SIZE
;
1104 VkResult
anv_FlushMappedMemoryRanges(
1106 uint32_t memoryRangeCount
,
1107 const VkMappedMemoryRange
* pMemoryRanges
)
1109 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1111 if (device
->info
.has_llc
)
1114 /* Make sure the writes we're flushing have landed. */
1115 __builtin_ia32_sfence();
1117 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1122 VkResult
anv_InvalidateMappedMemoryRanges(
1124 uint32_t memoryRangeCount
,
1125 const VkMappedMemoryRange
* pMemoryRanges
)
1127 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1129 if (device
->info
.has_llc
)
1132 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1134 /* Make sure no reads get moved up above the invalidate. */
1135 __builtin_ia32_lfence();
1140 void anv_GetBufferMemoryRequirements(
1143 VkMemoryRequirements
* pMemoryRequirements
)
1145 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1147 /* The Vulkan spec (git aaed022) says:
1149 * memoryTypeBits is a bitfield and contains one bit set for every
1150 * supported memory type for the resource. The bit `1<<i` is set if and
1151 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1152 * structure for the physical device is supported.
1154 * We support exactly one memory type.
1156 pMemoryRequirements
->memoryTypeBits
= 1;
1158 pMemoryRequirements
->size
= buffer
->size
;
1159 pMemoryRequirements
->alignment
= 16;
1162 void anv_GetImageMemoryRequirements(
1165 VkMemoryRequirements
* pMemoryRequirements
)
1167 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1169 /* The Vulkan spec (git aaed022) says:
1171 * memoryTypeBits is a bitfield and contains one bit set for every
1172 * supported memory type for the resource. The bit `1<<i` is set if and
1173 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1174 * structure for the physical device is supported.
1176 * We support exactly one memory type.
1178 pMemoryRequirements
->memoryTypeBits
= 1;
1180 pMemoryRequirements
->size
= image
->size
;
1181 pMemoryRequirements
->alignment
= image
->alignment
;
1184 void anv_GetImageSparseMemoryRequirements(
1187 uint32_t* pSparseMemoryRequirementCount
,
1188 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1193 void anv_GetDeviceMemoryCommitment(
1195 VkDeviceMemory memory
,
1196 VkDeviceSize
* pCommittedMemoryInBytes
)
1198 *pCommittedMemoryInBytes
= 0;
1201 VkResult
anv_BindBufferMemory(
1204 VkDeviceMemory _memory
,
1205 VkDeviceSize memoryOffset
)
1207 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1208 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1210 buffer
->bo
= &mem
->bo
;
1211 buffer
->offset
= memoryOffset
;
1216 VkResult
anv_BindImageMemory(
1219 VkDeviceMemory _memory
,
1220 VkDeviceSize memoryOffset
)
1222 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1223 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1225 image
->bo
= &mem
->bo
;
1226 image
->offset
= memoryOffset
;
1231 VkResult
anv_QueueBindSparse(
1233 uint32_t bindInfoCount
,
1234 const VkBindSparseInfo
* pBindInfo
,
1237 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1240 VkResult
anv_CreateFence(
1242 const VkFenceCreateInfo
* pCreateInfo
,
1243 const VkAllocationCallbacks
* pAllocator
,
1246 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1247 struct anv_fence
*fence
;
1248 struct anv_batch batch
;
1251 const uint32_t fence_size
= 128;
1253 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1255 fence
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*fence
), 8,
1256 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1258 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1260 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1261 if (result
!= VK_SUCCESS
)
1265 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
, 0);
1266 batch
.next
= batch
.start
= fence
->bo
.map
;
1267 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1268 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
1269 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
1271 if (!device
->info
.has_llc
) {
1272 assert(((uintptr_t) fence
->bo
.map
& CACHELINE_MASK
) == 0);
1273 assert(batch
.next
- fence
->bo
.map
<= CACHELINE_SIZE
);
1274 __builtin_ia32_sfence();
1275 __builtin_ia32_clflush(fence
->bo
.map
);
1278 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1279 fence
->exec2_objects
[0].relocation_count
= 0;
1280 fence
->exec2_objects
[0].relocs_ptr
= 0;
1281 fence
->exec2_objects
[0].alignment
= 0;
1282 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1283 fence
->exec2_objects
[0].flags
= 0;
1284 fence
->exec2_objects
[0].rsvd1
= 0;
1285 fence
->exec2_objects
[0].rsvd2
= 0;
1287 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1288 fence
->execbuf
.buffer_count
= 1;
1289 fence
->execbuf
.batch_start_offset
= 0;
1290 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1291 fence
->execbuf
.cliprects_ptr
= 0;
1292 fence
->execbuf
.num_cliprects
= 0;
1293 fence
->execbuf
.DR1
= 0;
1294 fence
->execbuf
.DR4
= 0;
1296 fence
->execbuf
.flags
=
1297 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1298 fence
->execbuf
.rsvd1
= device
->context_id
;
1299 fence
->execbuf
.rsvd2
= 0;
1301 *pFence
= anv_fence_to_handle(fence
);
1306 anv_free2(&device
->alloc
, pAllocator
, fence
);
1311 void anv_DestroyFence(
1314 const VkAllocationCallbacks
* pAllocator
)
1316 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1317 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1319 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1320 anv_gem_close(device
, fence
->bo
.gem_handle
);
1321 anv_free2(&device
->alloc
, pAllocator
, fence
);
1324 VkResult
anv_ResetFences(
1326 uint32_t fenceCount
,
1327 const VkFence
* pFences
)
1329 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1330 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1331 fence
->ready
= false;
1337 VkResult
anv_GetFenceStatus(
1341 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1342 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1349 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1351 fence
->ready
= true;
1355 return VK_NOT_READY
;
1358 VkResult
anv_WaitForFences(
1360 uint32_t fenceCount
,
1361 const VkFence
* pFences
,
1365 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1367 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1368 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1369 * for a couple of kernel releases. Since there's no way to know
1370 * whether or not the kernel we're using is one of the broken ones, the
1371 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1372 * maximum timeout from 584 years to 292 years - likely not a big deal.
1374 if (timeout
> INT64_MAX
)
1375 timeout
= INT64_MAX
;
1377 int64_t t
= timeout
;
1379 /* FIXME: handle !waitAll */
1381 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1382 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1383 int ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1384 if (ret
== -1 && errno
== ETIME
) {
1386 } else if (ret
== -1) {
1387 /* We don't know the real error. */
1388 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1389 "gem wait failed: %m");
1396 // Queue semaphore functions
1398 VkResult
anv_CreateSemaphore(
1400 const VkSemaphoreCreateInfo
* pCreateInfo
,
1401 const VkAllocationCallbacks
* pAllocator
,
1402 VkSemaphore
* pSemaphore
)
1404 *pSemaphore
= (VkSemaphore
)1;
1405 stub_return(VK_SUCCESS
);
1408 void anv_DestroySemaphore(
1410 VkSemaphore semaphore
,
1411 const VkAllocationCallbacks
* pAllocator
)
1418 VkResult
anv_CreateEvent(
1420 const VkEventCreateInfo
* pCreateInfo
,
1421 const VkAllocationCallbacks
* pAllocator
,
1424 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1427 void anv_DestroyEvent(
1430 const VkAllocationCallbacks
* pAllocator
)
1435 VkResult
anv_GetEventStatus(
1439 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1442 VkResult
anv_SetEvent(
1446 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1449 VkResult
anv_ResetEvent(
1453 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1458 VkResult
anv_CreateBuffer(
1460 const VkBufferCreateInfo
* pCreateInfo
,
1461 const VkAllocationCallbacks
* pAllocator
,
1464 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1465 struct anv_buffer
*buffer
;
1467 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1469 buffer
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1470 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1472 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1474 buffer
->size
= pCreateInfo
->size
;
1478 *pBuffer
= anv_buffer_to_handle(buffer
);
1483 void anv_DestroyBuffer(
1486 const VkAllocationCallbacks
* pAllocator
)
1488 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1489 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1491 anv_free2(&device
->alloc
, pAllocator
, buffer
);
1495 anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1496 const struct anv_format
*format
,
1497 uint32_t offset
, uint32_t range
, uint32_t stride
)
1499 switch (device
->info
.gen
) {
1501 if (device
->info
.is_haswell
)
1502 gen75_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1504 gen7_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1507 gen8_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1510 gen9_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1513 unreachable("unsupported gen\n");
1517 VkResult
anv_CreateBufferView(
1519 const VkBufferViewCreateInfo
* pCreateInfo
,
1520 const VkAllocationCallbacks
* pAllocator
,
1521 VkBufferView
* pView
)
1523 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1526 void anv_DestroyBufferView(
1528 VkBufferView _bview
,
1529 const VkAllocationCallbacks
* pAllocator
)
1534 void anv_DestroySampler(
1537 const VkAllocationCallbacks
* pAllocator
)
1539 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1540 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1542 anv_free2(&device
->alloc
, pAllocator
, sampler
);
1545 VkResult
anv_CreateFramebuffer(
1547 const VkFramebufferCreateInfo
* pCreateInfo
,
1548 const VkAllocationCallbacks
* pAllocator
,
1549 VkFramebuffer
* pFramebuffer
)
1551 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1552 struct anv_framebuffer
*framebuffer
;
1554 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1556 size_t size
= sizeof(*framebuffer
) +
1557 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
1558 framebuffer
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1559 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1560 if (framebuffer
== NULL
)
1561 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1563 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1564 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1565 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1566 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
1569 framebuffer
->width
= pCreateInfo
->width
;
1570 framebuffer
->height
= pCreateInfo
->height
;
1571 framebuffer
->layers
= pCreateInfo
->layers
;
1573 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
1578 void anv_DestroyFramebuffer(
1581 const VkAllocationCallbacks
* pAllocator
)
1583 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1584 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
1586 anv_free2(&device
->alloc
, pAllocator
, fb
);
1589 void vkCmdDbgMarkerBegin(
1590 VkCommandBuffer commandBuffer
,
1591 const char* pMarker
)
1592 __attribute__ ((visibility ("default")));
1594 void vkCmdDbgMarkerEnd(
1595 VkCommandBuffer commandBuffer
)
1596 __attribute__ ((visibility ("default")));
1598 void vkCmdDbgMarkerBegin(
1599 VkCommandBuffer commandBuffer
,
1600 const char* pMarker
)
1604 void vkCmdDbgMarkerEnd(
1605 VkCommandBuffer commandBuffer
)