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
>= 8) {
93 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
94 * supported as anything */
96 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
97 "Vulkan not yet supported on %s", device
->name
);
101 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
102 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
103 "failed to get aperture size: %m");
107 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
108 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
109 "kernel missing gem wait");
113 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
114 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
115 "kernel missing execbuf2");
119 if (!device
->info
->has_llc
&&
120 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
121 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
122 "kernel missing wc mmap");
128 brw_process_intel_debug_variable();
130 device
->compiler
= brw_compiler_create(NULL
, device
->info
);
131 if (device
->compiler
== NULL
) {
132 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
135 device
->compiler
->shader_debug_log
= compiler_debug_log
;
136 device
->compiler
->shader_perf_log
= compiler_perf_log
;
138 isl_device_init(&device
->isl_dev
, device
->info
);
148 anv_physical_device_finish(struct anv_physical_device
*device
)
150 ralloc_free(device
->compiler
);
153 static const VkExtensionProperties global_extensions
[] = {
155 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
159 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
162 #ifdef HAVE_WAYLAND_PLATFORM
164 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
170 static const VkExtensionProperties device_extensions
[] = {
172 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
178 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
179 VkSystemAllocationScope allocationScope
)
185 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
186 size_t align
, VkSystemAllocationScope allocationScope
)
188 return realloc(pOriginal
, size
);
192 default_free_func(void *pUserData
, void *pMemory
)
197 static const VkAllocationCallbacks default_alloc
= {
199 .pfnAllocation
= default_alloc_func
,
200 .pfnReallocation
= default_realloc_func
,
201 .pfnFree
= default_free_func
,
204 VkResult
anv_CreateInstance(
205 const VkInstanceCreateInfo
* pCreateInfo
,
206 const VkAllocationCallbacks
* pAllocator
,
207 VkInstance
* pInstance
)
209 struct anv_instance
*instance
;
211 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
213 if (pCreateInfo
->pApplicationInfo
->apiVersion
!= VK_MAKE_VERSION(0, 210, 1))
214 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
216 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
218 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
219 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
220 global_extensions
[j
].extensionName
) == 0) {
226 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
229 instance
= anv_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
230 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
232 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
234 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
237 instance
->alloc
= *pAllocator
;
239 instance
->alloc
= default_alloc
;
241 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
242 instance
->physicalDeviceCount
= -1;
246 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
248 anv_init_wsi(instance
);
250 *pInstance
= anv_instance_to_handle(instance
);
255 void anv_DestroyInstance(
256 VkInstance _instance
,
257 const VkAllocationCallbacks
* pAllocator
)
259 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
261 if (instance
->physicalDeviceCount
> 0) {
262 /* We support at most one physical device. */
263 assert(instance
->physicalDeviceCount
== 1);
264 anv_physical_device_finish(&instance
->physicalDevice
);
267 anv_finish_wsi(instance
);
269 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
273 anv_free(&instance
->alloc
, instance
);
276 VkResult
anv_EnumeratePhysicalDevices(
277 VkInstance _instance
,
278 uint32_t* pPhysicalDeviceCount
,
279 VkPhysicalDevice
* pPhysicalDevices
)
281 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
284 if (instance
->physicalDeviceCount
< 0) {
285 result
= anv_physical_device_init(&instance
->physicalDevice
,
286 instance
, "/dev/dri/renderD128");
287 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
288 instance
->physicalDeviceCount
= 0;
289 } else if (result
== VK_SUCCESS
) {
290 instance
->physicalDeviceCount
= 1;
296 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
297 * otherwise it's an inout parameter.
299 * The Vulkan spec (git aaed022) says:
301 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
302 * that is initialized with the number of devices the application is
303 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
304 * an array of at least this many VkPhysicalDevice handles [...].
306 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
307 * overwrites the contents of the variable pointed to by
308 * pPhysicalDeviceCount with the number of physical devices in in the
309 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
310 * pPhysicalDeviceCount with the number of physical handles written to
313 if (!pPhysicalDevices
) {
314 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
315 } else if (*pPhysicalDeviceCount
>= 1) {
316 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
317 *pPhysicalDeviceCount
= 1;
319 *pPhysicalDeviceCount
= 0;
325 void anv_GetPhysicalDeviceFeatures(
326 VkPhysicalDevice physicalDevice
,
327 VkPhysicalDeviceFeatures
* pFeatures
)
329 anv_finishme("Get correct values for PhysicalDeviceFeatures");
331 *pFeatures
= (VkPhysicalDeviceFeatures
) {
332 .robustBufferAccess
= false,
333 .fullDrawIndexUint32
= false,
334 .imageCubeArray
= false,
335 .independentBlend
= false,
336 .geometryShader
= true,
337 .tessellationShader
= false,
338 .sampleRateShading
= false,
339 .dualSrcBlend
= true,
341 .multiDrawIndirect
= true,
343 .depthBiasClamp
= false,
344 .fillModeNonSolid
= true,
345 .depthBounds
= false,
349 .multiViewport
= true,
350 .samplerAnisotropy
= false, /* FINISHME */
351 .textureCompressionETC2
= true,
352 .textureCompressionASTC_LDR
= true,
353 .textureCompressionBC
= true,
354 .occlusionQueryPrecise
= false, /* FINISHME */
355 .pipelineStatisticsQuery
= true,
356 .vertexPipelineStoresAndAtomics
= false,
357 .fragmentStoresAndAtomics
= true,
358 .shaderTessellationAndGeometryPointSize
= true,
359 .shaderImageGatherExtended
= true,
360 .shaderStorageImageExtendedFormats
= false,
361 .shaderStorageImageMultisample
= false,
362 .shaderUniformBufferArrayDynamicIndexing
= true,
363 .shaderSampledImageArrayDynamicIndexing
= false,
364 .shaderStorageBufferArrayDynamicIndexing
= false,
365 .shaderStorageImageArrayDynamicIndexing
= false,
366 .shaderStorageImageReadWithoutFormat
= false,
367 .shaderStorageImageWriteWithoutFormat
= true,
368 .shaderClipDistance
= false,
369 .shaderCullDistance
= false,
370 .shaderFloat64
= false,
371 .shaderInt64
= false,
372 .shaderInt16
= false,
374 .variableMultisampleRate
= false,
378 void anv_GetPhysicalDeviceProperties(
379 VkPhysicalDevice physicalDevice
,
380 VkPhysicalDeviceProperties
* pProperties
)
382 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
383 const struct brw_device_info
*devinfo
= pdevice
->info
;
385 anv_finishme("Get correct values for VkPhysicalDeviceLimits");
387 const float time_stamp_base
= devinfo
->gen
>= 9 ? 83.333 : 80.0;
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
= 4096, /* A page */
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
= time_stamp_base
/ (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
= 36, /* 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
);
667 struct anv_device
*device
;
669 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
671 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
673 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
674 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
675 device_extensions
[j
].extensionName
) == 0) {
681 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
684 anv_set_dispatch_devinfo(physical_device
->info
);
686 device
= anv_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
688 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
690 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
692 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
693 device
->instance
= physical_device
->instance
;
696 device
->alloc
= *pAllocator
;
698 device
->alloc
= physical_device
->instance
->alloc
;
700 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
701 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
702 if (device
->fd
== -1) {
703 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
707 device
->context_id
= anv_gem_create_context(device
);
708 if (device
->context_id
== -1) {
709 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
713 device
->info
= *physical_device
->info
;
714 device
->isl_dev
= physical_device
->isl_dev
;
716 pthread_mutex_init(&device
->mutex
, NULL
);
718 anv_bo_pool_init(&device
->batch_bo_pool
, device
, ANV_CMD_BUFFER_BATCH_SIZE
);
720 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 16384);
722 anv_state_pool_init(&device
->dynamic_state_pool
,
723 &device
->dynamic_state_block_pool
);
725 anv_block_pool_init(&device
->instruction_block_pool
, device
, 64 * 1024);
726 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
);
728 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
730 anv_state_pool_init(&device
->surface_state_pool
,
731 &device
->surface_state_block_pool
);
733 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
735 anv_block_pool_init(&device
->scratch_block_pool
, device
, 0x10000);
737 anv_queue_init(device
, &device
->queue
);
739 result
= anv_device_init_meta(device
);
740 if (result
!= VK_SUCCESS
)
743 anv_device_init_border_colors(device
);
745 *pDevice
= anv_device_to_handle(device
);
752 anv_free(&device
->alloc
, device
);
757 void anv_DestroyDevice(
759 const VkAllocationCallbacks
* pAllocator
)
761 ANV_FROM_HANDLE(anv_device
, device
, _device
);
763 anv_queue_finish(&device
->queue
);
765 anv_device_finish_meta(device
);
768 /* We only need to free these to prevent valgrind errors. The backing
769 * BO will go away in a couple of lines so we don't actually leak.
771 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
774 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
775 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
777 anv_bo_pool_finish(&device
->batch_bo_pool
);
778 anv_state_pool_finish(&device
->dynamic_state_pool
);
779 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
780 anv_block_pool_finish(&device
->instruction_block_pool
);
781 anv_state_pool_finish(&device
->surface_state_pool
);
782 anv_block_pool_finish(&device
->surface_state_block_pool
);
783 anv_block_pool_finish(&device
->scratch_block_pool
);
787 pthread_mutex_destroy(&device
->mutex
);
789 anv_free(&device
->alloc
, device
);
792 VkResult
anv_EnumerateInstanceExtensionProperties(
793 const char* pLayerName
,
794 uint32_t* pPropertyCount
,
795 VkExtensionProperties
* pProperties
)
797 if (pProperties
== NULL
) {
798 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
802 assert(*pPropertyCount
>= ARRAY_SIZE(global_extensions
));
804 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
805 memcpy(pProperties
, global_extensions
, sizeof(global_extensions
));
810 VkResult
anv_EnumerateDeviceExtensionProperties(
811 VkPhysicalDevice physicalDevice
,
812 const char* pLayerName
,
813 uint32_t* pPropertyCount
,
814 VkExtensionProperties
* pProperties
)
816 if (pProperties
== NULL
) {
817 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
821 assert(*pPropertyCount
>= ARRAY_SIZE(device_extensions
));
823 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
824 memcpy(pProperties
, device_extensions
, sizeof(device_extensions
));
829 VkResult
anv_EnumerateInstanceLayerProperties(
830 uint32_t* pPropertyCount
,
831 VkLayerProperties
* pProperties
)
833 if (pProperties
== NULL
) {
838 /* None supported at this time */
839 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
842 VkResult
anv_EnumerateDeviceLayerProperties(
843 VkPhysicalDevice physicalDevice
,
844 uint32_t* pPropertyCount
,
845 VkLayerProperties
* pProperties
)
847 if (pProperties
== NULL
) {
852 /* None supported at this time */
853 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
856 void anv_GetDeviceQueue(
858 uint32_t queueNodeIndex
,
862 ANV_FROM_HANDLE(anv_device
, device
, _device
);
864 assert(queueIndex
== 0);
866 *pQueue
= anv_queue_to_handle(&device
->queue
);
869 VkResult
anv_QueueSubmit(
871 uint32_t submitCount
,
872 const VkSubmitInfo
* pSubmits
,
875 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
876 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
877 struct anv_device
*device
= queue
->device
;
880 for (uint32_t i
= 0; i
< submitCount
; i
++) {
881 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
882 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
883 pSubmits
[i
].pCommandBuffers
[j
]);
884 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
886 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf2
.execbuf
);
888 /* We don't know the real error. */
889 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
890 "execbuf2 failed: %m");
894 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
896 /* We don't know the real error. */
897 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
898 "execbuf2 failed: %m");
902 for (uint32_t k
= 0; k
< cmd_buffer
->execbuf2
.bo_count
; k
++)
903 cmd_buffer
->execbuf2
.bos
[k
]->offset
= cmd_buffer
->execbuf2
.objects
[k
].offset
;
910 VkResult
anv_QueueWaitIdle(
913 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
915 return ANV_CALL(DeviceWaitIdle
)(anv_device_to_handle(queue
->device
));
918 VkResult
anv_DeviceWaitIdle(
921 ANV_FROM_HANDLE(anv_device
, device
, _device
);
922 struct anv_state state
;
923 struct anv_batch batch
;
924 struct drm_i915_gem_execbuffer2 execbuf
;
925 struct drm_i915_gem_exec_object2 exec2_objects
[1];
926 struct anv_bo
*bo
= NULL
;
931 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
932 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
933 batch
.start
= batch
.next
= state
.map
;
934 batch
.end
= state
.map
+ 32;
935 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
936 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
938 if (!device
->info
.has_llc
)
939 anv_state_clflush(state
);
941 exec2_objects
[0].handle
= bo
->gem_handle
;
942 exec2_objects
[0].relocation_count
= 0;
943 exec2_objects
[0].relocs_ptr
= 0;
944 exec2_objects
[0].alignment
= 0;
945 exec2_objects
[0].offset
= bo
->offset
;
946 exec2_objects
[0].flags
= 0;
947 exec2_objects
[0].rsvd1
= 0;
948 exec2_objects
[0].rsvd2
= 0;
950 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
951 execbuf
.buffer_count
= 1;
952 execbuf
.batch_start_offset
= state
.offset
;
953 execbuf
.batch_len
= batch
.next
- state
.map
;
954 execbuf
.cliprects_ptr
= 0;
955 execbuf
.num_cliprects
= 0;
960 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
961 execbuf
.rsvd1
= device
->context_id
;
964 ret
= anv_gem_execbuffer(device
, &execbuf
);
966 /* We don't know the real error. */
967 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
972 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
974 /* We don't know the real error. */
975 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
979 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
984 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
990 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
992 bo
->gem_handle
= anv_gem_create(device
, size
);
994 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1004 VkResult
anv_AllocateMemory(
1006 const VkMemoryAllocateInfo
* pAllocateInfo
,
1007 const VkAllocationCallbacks
* pAllocator
,
1008 VkDeviceMemory
* pMem
)
1010 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1011 struct anv_device_memory
*mem
;
1014 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1016 if (pAllocateInfo
->allocationSize
== 0) {
1017 /* Apparently, this is allowed */
1018 *pMem
= VK_NULL_HANDLE
;
1022 /* We support exactly one memory heap. */
1023 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1024 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1026 /* FINISHME: Fail if allocation request exceeds heap size. */
1028 mem
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1029 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1031 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1033 /* The kernel is going to give us whole pages anyway */
1034 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1036 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1037 if (result
!= VK_SUCCESS
)
1040 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1042 *pMem
= anv_device_memory_to_handle(mem
);
1047 anv_free2(&device
->alloc
, pAllocator
, mem
);
1052 void anv_FreeMemory(
1054 VkDeviceMemory _mem
,
1055 const VkAllocationCallbacks
* pAllocator
)
1057 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1058 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1064 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1066 if (mem
->bo
.gem_handle
!= 0)
1067 anv_gem_close(device
, mem
->bo
.gem_handle
);
1069 anv_free2(&device
->alloc
, pAllocator
, mem
);
1072 VkResult
anv_MapMemory(
1074 VkDeviceMemory _memory
,
1075 VkDeviceSize offset
,
1077 VkMemoryMapFlags flags
,
1080 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1081 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1088 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1089 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1090 * at a time is valid. We could just mmap up front and return an offset
1091 * pointer here, but that may exhaust virtual memory on 32 bit
1094 uint32_t gem_flags
= 0;
1095 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1096 gem_flags
|= I915_MMAP_WC
;
1098 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1099 uint64_t map_offset
= offset
& ~4095ull;
1100 assert(offset
>= map_offset
);
1101 uint64_t map_size
= (offset
+ size
) - map_offset
;
1103 /* Let's map whole pages */
1104 map_size
= align_u64(map_size
, 4096);
1106 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1107 map_offset
, map_size
, gem_flags
);
1108 mem
->map_size
= map_size
;
1110 *ppData
= mem
->map
+ (offset
- map_offset
);
1115 void anv_UnmapMemory(
1117 VkDeviceMemory _memory
)
1119 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1124 anv_gem_munmap(mem
->map
, mem
->map_size
);
1128 clflush_mapped_ranges(struct anv_device
*device
,
1130 const VkMappedMemoryRange
*ranges
)
1132 for (uint32_t i
= 0; i
< count
; i
++) {
1133 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1134 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1135 void *end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1138 __builtin_ia32_clflush(p
);
1139 p
+= CACHELINE_SIZE
;
1144 VkResult
anv_FlushMappedMemoryRanges(
1146 uint32_t memoryRangeCount
,
1147 const VkMappedMemoryRange
* pMemoryRanges
)
1149 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1151 if (device
->info
.has_llc
)
1154 /* Make sure the writes we're flushing have landed. */
1155 __builtin_ia32_sfence();
1157 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1162 VkResult
anv_InvalidateMappedMemoryRanges(
1164 uint32_t memoryRangeCount
,
1165 const VkMappedMemoryRange
* pMemoryRanges
)
1167 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1169 if (device
->info
.has_llc
)
1172 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1174 /* Make sure no reads get moved up above the invalidate. */
1175 __builtin_ia32_lfence();
1180 void anv_GetBufferMemoryRequirements(
1183 VkMemoryRequirements
* pMemoryRequirements
)
1185 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1187 /* The Vulkan spec (git aaed022) says:
1189 * memoryTypeBits is a bitfield and contains one bit set for every
1190 * supported memory type for the resource. The bit `1<<i` is set if and
1191 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1192 * structure for the physical device is supported.
1194 * We support exactly one memory type.
1196 pMemoryRequirements
->memoryTypeBits
= 1;
1198 pMemoryRequirements
->size
= buffer
->size
;
1199 pMemoryRequirements
->alignment
= 16;
1202 void anv_GetImageMemoryRequirements(
1205 VkMemoryRequirements
* pMemoryRequirements
)
1207 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1209 /* The Vulkan spec (git aaed022) says:
1211 * memoryTypeBits is a bitfield and contains one bit set for every
1212 * supported memory type for the resource. The bit `1<<i` is set if and
1213 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1214 * structure for the physical device is supported.
1216 * We support exactly one memory type.
1218 pMemoryRequirements
->memoryTypeBits
= 1;
1220 pMemoryRequirements
->size
= image
->size
;
1221 pMemoryRequirements
->alignment
= image
->alignment
;
1224 void anv_GetImageSparseMemoryRequirements(
1227 uint32_t* pSparseMemoryRequirementCount
,
1228 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1233 void anv_GetDeviceMemoryCommitment(
1235 VkDeviceMemory memory
,
1236 VkDeviceSize
* pCommittedMemoryInBytes
)
1238 *pCommittedMemoryInBytes
= 0;
1241 VkResult
anv_BindBufferMemory(
1244 VkDeviceMemory _memory
,
1245 VkDeviceSize memoryOffset
)
1247 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1248 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1251 buffer
->bo
= &mem
->bo
;
1252 buffer
->offset
= memoryOffset
;
1261 VkResult
anv_BindImageMemory(
1264 VkDeviceMemory _memory
,
1265 VkDeviceSize memoryOffset
)
1267 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1268 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1271 image
->bo
= &mem
->bo
;
1272 image
->offset
= memoryOffset
;
1281 VkResult
anv_QueueBindSparse(
1283 uint32_t bindInfoCount
,
1284 const VkBindSparseInfo
* pBindInfo
,
1287 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1290 VkResult
anv_CreateFence(
1292 const VkFenceCreateInfo
* pCreateInfo
,
1293 const VkAllocationCallbacks
* pAllocator
,
1296 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1297 struct anv_fence
*fence
;
1298 struct anv_batch batch
;
1301 const uint32_t fence_size
= 128;
1303 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1305 fence
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*fence
), 8,
1306 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1308 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1310 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1311 if (result
!= VK_SUCCESS
)
1315 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
, 0);
1316 batch
.next
= batch
.start
= fence
->bo
.map
;
1317 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1318 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
1319 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
1321 if (!device
->info
.has_llc
) {
1322 assert(((uintptr_t) fence
->bo
.map
& CACHELINE_MASK
) == 0);
1323 assert(batch
.next
- fence
->bo
.map
<= CACHELINE_SIZE
);
1324 __builtin_ia32_sfence();
1325 __builtin_ia32_clflush(fence
->bo
.map
);
1328 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1329 fence
->exec2_objects
[0].relocation_count
= 0;
1330 fence
->exec2_objects
[0].relocs_ptr
= 0;
1331 fence
->exec2_objects
[0].alignment
= 0;
1332 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1333 fence
->exec2_objects
[0].flags
= 0;
1334 fence
->exec2_objects
[0].rsvd1
= 0;
1335 fence
->exec2_objects
[0].rsvd2
= 0;
1337 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1338 fence
->execbuf
.buffer_count
= 1;
1339 fence
->execbuf
.batch_start_offset
= 0;
1340 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1341 fence
->execbuf
.cliprects_ptr
= 0;
1342 fence
->execbuf
.num_cliprects
= 0;
1343 fence
->execbuf
.DR1
= 0;
1344 fence
->execbuf
.DR4
= 0;
1346 fence
->execbuf
.flags
=
1347 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1348 fence
->execbuf
.rsvd1
= device
->context_id
;
1349 fence
->execbuf
.rsvd2
= 0;
1351 *pFence
= anv_fence_to_handle(fence
);
1356 anv_free2(&device
->alloc
, pAllocator
, fence
);
1361 void anv_DestroyFence(
1364 const VkAllocationCallbacks
* pAllocator
)
1366 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1367 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1369 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1370 anv_gem_close(device
, fence
->bo
.gem_handle
);
1371 anv_free2(&device
->alloc
, pAllocator
, fence
);
1374 VkResult
anv_ResetFences(
1376 uint32_t fenceCount
,
1377 const VkFence
* pFences
)
1379 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1380 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1381 fence
->ready
= false;
1387 VkResult
anv_GetFenceStatus(
1391 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1392 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1399 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1401 fence
->ready
= true;
1405 return VK_NOT_READY
;
1408 VkResult
anv_WaitForFences(
1410 uint32_t fenceCount
,
1411 const VkFence
* pFences
,
1415 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1417 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1418 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1419 * for a couple of kernel releases. Since there's no way to know
1420 * whether or not the kernel we're using is one of the broken ones, the
1421 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1422 * maximum timeout from 584 years to 292 years - likely not a big deal.
1424 if (timeout
> INT64_MAX
)
1425 timeout
= INT64_MAX
;
1427 int64_t t
= timeout
;
1429 /* FIXME: handle !waitAll */
1431 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1432 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1433 int ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1434 if (ret
== -1 && errno
== ETIME
) {
1436 } else if (ret
== -1) {
1437 /* We don't know the real error. */
1438 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1439 "gem wait failed: %m");
1446 // Queue semaphore functions
1448 VkResult
anv_CreateSemaphore(
1450 const VkSemaphoreCreateInfo
* pCreateInfo
,
1451 const VkAllocationCallbacks
* pAllocator
,
1452 VkSemaphore
* pSemaphore
)
1454 /* The DRM execbuffer ioctl always execute in-oder, even between different
1455 * rings. As such, there's nothing to do for the user space semaphore.
1458 *pSemaphore
= (VkSemaphore
)1;
1463 void anv_DestroySemaphore(
1465 VkSemaphore semaphore
,
1466 const VkAllocationCallbacks
* pAllocator
)
1472 VkResult
anv_CreateEvent(
1474 const VkEventCreateInfo
* pCreateInfo
,
1475 const VkAllocationCallbacks
* pAllocator
,
1478 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1479 struct anv_state state
;
1480 struct anv_event
*event
;
1482 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1484 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1487 event
->state
= state
;
1488 event
->semaphore
= VK_EVENT_RESET
;
1490 if (!device
->info
.has_llc
) {
1491 /* Make sure the writes we're flushing have landed. */
1492 __builtin_ia32_sfence();
1493 __builtin_ia32_clflush(event
);
1496 *pEvent
= anv_event_to_handle(event
);
1501 void anv_DestroyEvent(
1504 const VkAllocationCallbacks
* pAllocator
)
1506 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1507 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1509 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1512 VkResult
anv_GetEventStatus(
1516 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1517 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1519 if (!device
->info
.has_llc
) {
1520 /* Make sure the writes we're flushing have landed. */
1521 __builtin_ia32_clflush(event
);
1522 __builtin_ia32_lfence();
1525 return event
->semaphore
;
1528 VkResult
anv_SetEvent(
1532 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1533 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1535 event
->semaphore
= VK_EVENT_SET
;
1537 if (!device
->info
.has_llc
) {
1538 /* Make sure the writes we're flushing have landed. */
1539 __builtin_ia32_sfence();
1540 __builtin_ia32_clflush(event
);
1546 VkResult
anv_ResetEvent(
1550 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1551 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1553 event
->semaphore
= VK_EVENT_RESET
;
1555 if (!device
->info
.has_llc
) {
1556 /* Make sure the writes we're flushing have landed. */
1557 __builtin_ia32_sfence();
1558 __builtin_ia32_clflush(event
);
1566 VkResult
anv_CreateBuffer(
1568 const VkBufferCreateInfo
* pCreateInfo
,
1569 const VkAllocationCallbacks
* pAllocator
,
1572 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1573 struct anv_buffer
*buffer
;
1575 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1577 buffer
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1578 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1580 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1582 buffer
->size
= pCreateInfo
->size
;
1583 buffer
->usage
= pCreateInfo
->usage
;
1587 *pBuffer
= anv_buffer_to_handle(buffer
);
1592 void anv_DestroyBuffer(
1595 const VkAllocationCallbacks
* pAllocator
)
1597 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1598 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1600 anv_free2(&device
->alloc
, pAllocator
, buffer
);
1604 anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1605 enum isl_format format
,
1606 uint32_t offset
, uint32_t range
, uint32_t stride
)
1608 switch (device
->info
.gen
) {
1610 if (device
->info
.is_haswell
)
1611 gen75_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1613 gen7_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1616 gen8_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1619 gen9_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1622 unreachable("unsupported gen\n");
1626 void anv_DestroySampler(
1629 const VkAllocationCallbacks
* pAllocator
)
1631 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1632 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1634 anv_free2(&device
->alloc
, pAllocator
, sampler
);
1637 VkResult
anv_CreateFramebuffer(
1639 const VkFramebufferCreateInfo
* pCreateInfo
,
1640 const VkAllocationCallbacks
* pAllocator
,
1641 VkFramebuffer
* pFramebuffer
)
1643 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1644 struct anv_framebuffer
*framebuffer
;
1646 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1648 size_t size
= sizeof(*framebuffer
) +
1649 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
1650 framebuffer
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1651 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1652 if (framebuffer
== NULL
)
1653 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1655 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1656 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1657 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1658 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
1661 framebuffer
->width
= pCreateInfo
->width
;
1662 framebuffer
->height
= pCreateInfo
->height
;
1663 framebuffer
->layers
= pCreateInfo
->layers
;
1665 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
1670 void anv_DestroyFramebuffer(
1673 const VkAllocationCallbacks
* pAllocator
)
1675 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1676 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
1678 anv_free2(&device
->alloc
, pAllocator
, fb
);
1681 void vkCmdDbgMarkerBegin(
1682 VkCommandBuffer commandBuffer
,
1683 const char* pMarker
)
1684 __attribute__ ((visibility ("default")));
1686 void vkCmdDbgMarkerEnd(
1687 VkCommandBuffer commandBuffer
)
1688 __attribute__ ((visibility ("default")));
1690 void vkCmdDbgMarkerBegin(
1691 VkCommandBuffer commandBuffer
,
1692 const char* pMarker
)
1696 void vkCmdDbgMarkerEnd(
1697 VkCommandBuffer commandBuffer
)