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"
32 #include "util/strtod.h"
33 #include "util/debug.h"
35 #include "genxml/gen7_pack.h"
37 struct anv_dispatch_table dtable
;
40 compiler_debug_log(void *data
, const char *fmt
, ...)
44 compiler_perf_log(void *data
, const char *fmt
, ...)
49 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
50 vfprintf(stderr
, fmt
, args
);
56 anv_physical_device_init(struct anv_physical_device
*device
,
57 struct anv_instance
*instance
,
63 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
65 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
66 "failed to open %s: %m", path
);
68 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
69 device
->instance
= instance
;
71 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
72 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
74 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
75 if (!device
->chipset_id
) {
76 result
= VK_ERROR_INITIALIZATION_FAILED
;
80 device
->name
= brw_get_device_name(device
->chipset_id
);
81 device
->info
= brw_get_device_info(device
->chipset_id
);
83 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
84 "failed to get device info");
88 if (device
->info
->is_haswell
) {
89 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
90 } else if (device
->info
->gen
== 7 && !device
->info
->is_baytrail
) {
91 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
92 } else if (device
->info
->gen
== 7 && device
->info
->is_baytrail
) {
93 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
94 } else if (device
->info
->gen
>= 8) {
95 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
96 * supported as anything */
98 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
99 "Vulkan not yet supported on %s", device
->name
);
103 device
->cmd_parser_version
= -1;
104 if (device
->info
->gen
== 7) {
105 device
->cmd_parser_version
=
106 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
107 if (device
->cmd_parser_version
== -1) {
108 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
109 "failed to get command parser version");
114 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
115 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
116 "failed to get aperture size: %m");
120 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
121 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
122 "kernel missing gem wait");
126 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
127 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
128 "kernel missing execbuf2");
132 if (!device
->info
->has_llc
&&
133 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
134 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
135 "kernel missing wc mmap");
139 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
143 brw_process_intel_debug_variable();
145 device
->compiler
= brw_compiler_create(NULL
, device
->info
);
146 if (device
->compiler
== NULL
) {
147 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
150 device
->compiler
->shader_debug_log
= compiler_debug_log
;
151 device
->compiler
->shader_perf_log
= compiler_perf_log
;
153 result
= anv_init_wsi(device
);
154 if (result
!= VK_SUCCESS
)
157 /* XXX: Actually detect bit6 swizzling */
158 isl_device_init(&device
->isl_dev
, device
->info
, swizzled
);
168 anv_physical_device_finish(struct anv_physical_device
*device
)
170 anv_finish_wsi(device
);
171 ralloc_free(device
->compiler
);
174 static const VkExtensionProperties global_extensions
[] = {
176 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
179 #ifdef VK_USE_PLATFORM_XCB_KHR
181 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
185 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
187 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
193 static const VkExtensionProperties device_extensions
[] = {
195 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
201 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
202 VkSystemAllocationScope allocationScope
)
208 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
209 size_t align
, VkSystemAllocationScope allocationScope
)
211 return realloc(pOriginal
, size
);
215 default_free_func(void *pUserData
, void *pMemory
)
220 static const VkAllocationCallbacks default_alloc
= {
222 .pfnAllocation
= default_alloc_func
,
223 .pfnReallocation
= default_realloc_func
,
224 .pfnFree
= default_free_func
,
227 VkResult
anv_CreateInstance(
228 const VkInstanceCreateInfo
* pCreateInfo
,
229 const VkAllocationCallbacks
* pAllocator
,
230 VkInstance
* pInstance
)
232 struct anv_instance
*instance
;
234 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
236 uint32_t client_version
;
237 if (pCreateInfo
->pApplicationInfo
&&
238 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
239 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
241 client_version
= VK_MAKE_VERSION(1, 0, 0);
244 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
245 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
246 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
247 "Client requested version %d.%d.%d",
248 VK_VERSION_MAJOR(client_version
),
249 VK_VERSION_MINOR(client_version
),
250 VK_VERSION_PATCH(client_version
));
253 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
255 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
256 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
257 global_extensions
[j
].extensionName
) == 0) {
263 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
266 instance
= anv_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
267 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
269 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
271 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
274 instance
->alloc
= *pAllocator
;
276 instance
->alloc
= default_alloc
;
278 instance
->apiVersion
= client_version
;
279 instance
->physicalDeviceCount
= -1;
283 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
285 *pInstance
= anv_instance_to_handle(instance
);
290 void anv_DestroyInstance(
291 VkInstance _instance
,
292 const VkAllocationCallbacks
* pAllocator
)
294 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
296 if (instance
->physicalDeviceCount
> 0) {
297 /* We support at most one physical device. */
298 assert(instance
->physicalDeviceCount
== 1);
299 anv_physical_device_finish(&instance
->physicalDevice
);
302 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
306 anv_free(&instance
->alloc
, instance
);
309 VkResult
anv_EnumeratePhysicalDevices(
310 VkInstance _instance
,
311 uint32_t* pPhysicalDeviceCount
,
312 VkPhysicalDevice
* pPhysicalDevices
)
314 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
317 if (instance
->physicalDeviceCount
< 0) {
319 for (unsigned i
= 0; i
< 8; i
++) {
320 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
321 result
= anv_physical_device_init(&instance
->physicalDevice
,
323 if (result
== VK_SUCCESS
)
327 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
328 instance
->physicalDeviceCount
= 0;
329 } else if (result
== VK_SUCCESS
) {
330 instance
->physicalDeviceCount
= 1;
336 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
337 * otherwise it's an inout parameter.
339 * The Vulkan spec (git aaed022) says:
341 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
342 * that is initialized with the number of devices the application is
343 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
344 * an array of at least this many VkPhysicalDevice handles [...].
346 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
347 * overwrites the contents of the variable pointed to by
348 * pPhysicalDeviceCount with the number of physical devices in in the
349 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
350 * pPhysicalDeviceCount with the number of physical handles written to
353 if (!pPhysicalDevices
) {
354 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
355 } else if (*pPhysicalDeviceCount
>= 1) {
356 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
357 *pPhysicalDeviceCount
= 1;
359 *pPhysicalDeviceCount
= 0;
365 void anv_GetPhysicalDeviceFeatures(
366 VkPhysicalDevice physicalDevice
,
367 VkPhysicalDeviceFeatures
* pFeatures
)
369 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
371 *pFeatures
= (VkPhysicalDeviceFeatures
) {
372 .robustBufferAccess
= true,
373 .fullDrawIndexUint32
= true,
374 .imageCubeArray
= false,
375 .independentBlend
= pdevice
->info
->gen
>= 8,
376 .geometryShader
= true,
377 .tessellationShader
= false,
378 .sampleRateShading
= false,
379 .dualSrcBlend
= true,
381 .multiDrawIndirect
= false,
382 .drawIndirectFirstInstance
= false,
384 .depthBiasClamp
= false,
385 .fillModeNonSolid
= true,
386 .depthBounds
= false,
390 .multiViewport
= true,
391 .samplerAnisotropy
= false, /* FINISHME */
392 .textureCompressionETC2
= pdevice
->info
->gen
>= 8 ||
393 pdevice
->info
->is_baytrail
,
394 .textureCompressionASTC_LDR
= pdevice
->info
->gen
>= 9, /* FINISHME CHV */
395 .textureCompressionBC
= true,
396 .occlusionQueryPrecise
= true,
397 .pipelineStatisticsQuery
= false,
398 .fragmentStoresAndAtomics
= true,
399 .shaderTessellationAndGeometryPointSize
= true,
400 .shaderImageGatherExtended
= false,
401 .shaderStorageImageExtendedFormats
= false,
402 .shaderStorageImageMultisample
= false,
403 .shaderUniformBufferArrayDynamicIndexing
= true,
404 .shaderSampledImageArrayDynamicIndexing
= true,
405 .shaderStorageBufferArrayDynamicIndexing
= true,
406 .shaderStorageImageArrayDynamicIndexing
= true,
407 .shaderStorageImageReadWithoutFormat
= false,
408 .shaderStorageImageWriteWithoutFormat
= true,
409 .shaderClipDistance
= false,
410 .shaderCullDistance
= false,
411 .shaderFloat64
= false,
412 .shaderInt64
= false,
413 .shaderInt16
= false,
415 .variableMultisampleRate
= false,
416 .inheritedQueries
= false,
419 /* We can't do image stores in vec4 shaders */
420 pFeatures
->vertexPipelineStoresAndAtomics
=
421 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
422 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
426 anv_device_get_cache_uuid(void *uuid
)
428 memset(uuid
, 0, VK_UUID_SIZE
);
429 snprintf(uuid
, VK_UUID_SIZE
, "anv-%s", MESA_GIT_SHA1
+ 4);
432 void anv_GetPhysicalDeviceProperties(
433 VkPhysicalDevice physicalDevice
,
434 VkPhysicalDeviceProperties
* pProperties
)
436 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
437 const struct brw_device_info
*devinfo
= pdevice
->info
;
439 const float time_stamp_base
= devinfo
->gen
>= 9 ? 83.333 : 80.0;
441 VkSampleCountFlags sample_counts
=
442 isl_device_get_sample_counts(&pdevice
->isl_dev
);
444 VkPhysicalDeviceLimits limits
= {
445 .maxImageDimension1D
= (1 << 14),
446 .maxImageDimension2D
= (1 << 14),
447 .maxImageDimension3D
= (1 << 11),
448 .maxImageDimensionCube
= (1 << 14),
449 .maxImageArrayLayers
= (1 << 11),
450 .maxTexelBufferElements
= 128 * 1024 * 1024,
451 .maxUniformBufferRange
= UINT32_MAX
,
452 .maxStorageBufferRange
= UINT32_MAX
,
453 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
454 .maxMemoryAllocationCount
= UINT32_MAX
,
455 .maxSamplerAllocationCount
= 64 * 1024,
456 .bufferImageGranularity
= 64, /* A cache line */
457 .sparseAddressSpaceSize
= 0,
458 .maxBoundDescriptorSets
= MAX_SETS
,
459 .maxPerStageDescriptorSamplers
= 64,
460 .maxPerStageDescriptorUniformBuffers
= 64,
461 .maxPerStageDescriptorStorageBuffers
= 64,
462 .maxPerStageDescriptorSampledImages
= 64,
463 .maxPerStageDescriptorStorageImages
= 64,
464 .maxPerStageDescriptorInputAttachments
= 64,
465 .maxPerStageResources
= 128,
466 .maxDescriptorSetSamplers
= 256,
467 .maxDescriptorSetUniformBuffers
= 256,
468 .maxDescriptorSetUniformBuffersDynamic
= 256,
469 .maxDescriptorSetStorageBuffers
= 256,
470 .maxDescriptorSetStorageBuffersDynamic
= 256,
471 .maxDescriptorSetSampledImages
= 256,
472 .maxDescriptorSetStorageImages
= 256,
473 .maxDescriptorSetInputAttachments
= 256,
474 .maxVertexInputAttributes
= 32,
475 .maxVertexInputBindings
= 32,
476 .maxVertexInputAttributeOffset
= 2047,
477 .maxVertexInputBindingStride
= 2048,
478 .maxVertexOutputComponents
= 128,
479 .maxTessellationGenerationLevel
= 0,
480 .maxTessellationPatchSize
= 0,
481 .maxTessellationControlPerVertexInputComponents
= 0,
482 .maxTessellationControlPerVertexOutputComponents
= 0,
483 .maxTessellationControlPerPatchOutputComponents
= 0,
484 .maxTessellationControlTotalOutputComponents
= 0,
485 .maxTessellationEvaluationInputComponents
= 0,
486 .maxTessellationEvaluationOutputComponents
= 0,
487 .maxGeometryShaderInvocations
= 32,
488 .maxGeometryInputComponents
= 64,
489 .maxGeometryOutputComponents
= 128,
490 .maxGeometryOutputVertices
= 256,
491 .maxGeometryTotalOutputComponents
= 1024,
492 .maxFragmentInputComponents
= 128,
493 .maxFragmentOutputAttachments
= 8,
494 .maxFragmentDualSrcAttachments
= 2,
495 .maxFragmentCombinedOutputResources
= 8,
496 .maxComputeSharedMemorySize
= 32768,
497 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
498 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
499 .maxComputeWorkGroupSize
= {
500 16 * devinfo
->max_cs_threads
,
501 16 * devinfo
->max_cs_threads
,
502 16 * devinfo
->max_cs_threads
,
504 .subPixelPrecisionBits
= 4 /* FIXME */,
505 .subTexelPrecisionBits
= 4 /* FIXME */,
506 .mipmapPrecisionBits
= 4 /* FIXME */,
507 .maxDrawIndexedIndexValue
= UINT32_MAX
,
508 .maxDrawIndirectCount
= UINT32_MAX
,
509 .maxSamplerLodBias
= 16,
510 .maxSamplerAnisotropy
= 16,
511 .maxViewports
= MAX_VIEWPORTS
,
512 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
513 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
514 .viewportSubPixelBits
= 13, /* We take a float? */
515 .minMemoryMapAlignment
= 4096, /* A page */
516 .minTexelBufferOffsetAlignment
= 1,
517 .minUniformBufferOffsetAlignment
= 1,
518 .minStorageBufferOffsetAlignment
= 1,
519 .minTexelOffset
= -8,
521 .minTexelGatherOffset
= -8,
522 .maxTexelGatherOffset
= 7,
523 .minInterpolationOffset
= 0, /* FIXME */
524 .maxInterpolationOffset
= 0, /* FIXME */
525 .subPixelInterpolationOffsetBits
= 0, /* FIXME */
526 .maxFramebufferWidth
= (1 << 14),
527 .maxFramebufferHeight
= (1 << 14),
528 .maxFramebufferLayers
= (1 << 10),
529 .framebufferColorSampleCounts
= sample_counts
,
530 .framebufferDepthSampleCounts
= sample_counts
,
531 .framebufferStencilSampleCounts
= sample_counts
,
532 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
533 .maxColorAttachments
= MAX_RTS
,
534 .sampledImageColorSampleCounts
= sample_counts
,
535 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
536 .sampledImageDepthSampleCounts
= sample_counts
,
537 .sampledImageStencilSampleCounts
= sample_counts
,
538 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
539 .maxSampleMaskWords
= 1,
540 .timestampComputeAndGraphics
= false,
541 .timestampPeriod
= time_stamp_base
/ (1000 * 1000 * 1000),
542 .maxClipDistances
= 0 /* FIXME */,
543 .maxCullDistances
= 0 /* FIXME */,
544 .maxCombinedClipAndCullDistances
= 0 /* FIXME */,
545 .discreteQueuePriorities
= 1,
546 .pointSizeRange
= { 0.125, 255.875 },
547 .lineWidthRange
= { 0.0, 7.9921875 },
548 .pointSizeGranularity
= (1.0 / 8.0),
549 .lineWidthGranularity
= (1.0 / 128.0),
550 .strictLines
= false, /* FINISHME */
551 .standardSampleLocations
= true,
552 .optimalBufferCopyOffsetAlignment
= 128,
553 .optimalBufferCopyRowPitchAlignment
= 128,
554 .nonCoherentAtomSize
= 64,
557 *pProperties
= (VkPhysicalDeviceProperties
) {
558 .apiVersion
= VK_MAKE_VERSION(1, 0, 5),
561 .deviceID
= pdevice
->chipset_id
,
562 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
564 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
567 strcpy(pProperties
->deviceName
, pdevice
->name
);
568 anv_device_get_cache_uuid(pProperties
->pipelineCacheUUID
);
571 void anv_GetPhysicalDeviceQueueFamilyProperties(
572 VkPhysicalDevice physicalDevice
,
574 VkQueueFamilyProperties
* pQueueFamilyProperties
)
576 if (pQueueFamilyProperties
== NULL
) {
581 assert(*pCount
>= 1);
583 *pQueueFamilyProperties
= (VkQueueFamilyProperties
) {
584 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
585 VK_QUEUE_COMPUTE_BIT
|
586 VK_QUEUE_TRANSFER_BIT
,
588 .timestampValidBits
= 36, /* XXX: Real value here */
589 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
593 void anv_GetPhysicalDeviceMemoryProperties(
594 VkPhysicalDevice physicalDevice
,
595 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
597 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
598 VkDeviceSize heap_size
;
600 /* Reserve some wiggle room for the driver by exposing only 75% of the
601 * aperture to the heap.
603 heap_size
= 3 * physical_device
->aperture_size
/ 4;
605 if (physical_device
->info
->has_llc
) {
606 /* Big core GPUs share LLC with the CPU and thus one memory type can be
607 * both cached and coherent at the same time.
609 pMemoryProperties
->memoryTypeCount
= 1;
610 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
611 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
612 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
613 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
614 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
618 /* The spec requires that we expose a host-visible, coherent memory
619 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
620 * to give the application a choice between cached, but not coherent and
621 * coherent but uncached (WC though).
623 pMemoryProperties
->memoryTypeCount
= 2;
624 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
625 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
626 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
627 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
630 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
631 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
632 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
633 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
638 pMemoryProperties
->memoryHeapCount
= 1;
639 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
641 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
645 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
649 return anv_lookup_entrypoint(pName
);
652 /* The loader wants us to expose a second GetInstanceProcAddr function
653 * to work around certain LD_PRELOAD issues seen in apps.
655 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
659 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
663 return anv_GetInstanceProcAddr(instance
, pName
);
666 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
670 return anv_lookup_entrypoint(pName
);
674 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
676 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
677 queue
->device
= device
;
678 queue
->pool
= &device
->surface_state_pool
;
684 anv_queue_finish(struct anv_queue
*queue
)
688 static struct anv_state
689 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
691 struct anv_state state
;
693 state
= anv_state_pool_alloc(pool
, size
, align
);
694 memcpy(state
.map
, p
, size
);
696 if (!pool
->block_pool
->device
->info
.has_llc
)
697 anv_state_clflush(state
);
702 struct gen8_border_color
{
707 /* Pad out to 64 bytes */
712 anv_device_init_border_colors(struct anv_device
*device
)
714 static const struct gen8_border_color border_colors
[] = {
715 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
716 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
717 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
718 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
719 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
720 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
723 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
724 sizeof(border_colors
), 64,
729 anv_device_submit_simple_batch(struct anv_device
*device
,
730 struct anv_batch
*batch
)
732 struct drm_i915_gem_execbuffer2 execbuf
;
733 struct drm_i915_gem_exec_object2 exec2_objects
[1];
735 VkResult result
= VK_SUCCESS
;
740 /* Kernel driver requires 8 byte aligned batch length */
741 size
= align_u32(batch
->next
- batch
->start
, 8);
742 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bo
, size
);
743 if (result
!= VK_SUCCESS
)
746 memcpy(bo
.map
, batch
->start
, size
);
747 if (!device
->info
.has_llc
)
748 anv_clflush_range(bo
.map
, size
);
750 exec2_objects
[0].handle
= bo
.gem_handle
;
751 exec2_objects
[0].relocation_count
= 0;
752 exec2_objects
[0].relocs_ptr
= 0;
753 exec2_objects
[0].alignment
= 0;
754 exec2_objects
[0].offset
= bo
.offset
;
755 exec2_objects
[0].flags
= 0;
756 exec2_objects
[0].rsvd1
= 0;
757 exec2_objects
[0].rsvd2
= 0;
759 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
760 execbuf
.buffer_count
= 1;
761 execbuf
.batch_start_offset
= 0;
762 execbuf
.batch_len
= size
;
763 execbuf
.cliprects_ptr
= 0;
764 execbuf
.num_cliprects
= 0;
769 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
770 execbuf
.rsvd1
= device
->context_id
;
773 ret
= anv_gem_execbuffer(device
, &execbuf
);
775 /* We don't know the real error. */
776 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
781 ret
= anv_gem_wait(device
, bo
.gem_handle
, &timeout
);
783 /* We don't know the real error. */
784 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
789 anv_bo_pool_free(&device
->batch_bo_pool
, &bo
);
794 VkResult
anv_CreateDevice(
795 VkPhysicalDevice physicalDevice
,
796 const VkDeviceCreateInfo
* pCreateInfo
,
797 const VkAllocationCallbacks
* pAllocator
,
800 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
802 struct anv_device
*device
;
804 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
806 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
808 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
809 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
810 device_extensions
[j
].extensionName
) == 0) {
816 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
819 anv_set_dispatch_devinfo(physical_device
->info
);
821 device
= anv_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
823 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
825 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
827 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
828 device
->instance
= physical_device
->instance
;
829 device
->chipset_id
= physical_device
->chipset_id
;
832 device
->alloc
= *pAllocator
;
834 device
->alloc
= physical_device
->instance
->alloc
;
836 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
837 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
838 if (device
->fd
== -1) {
839 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
843 device
->context_id
= anv_gem_create_context(device
);
844 if (device
->context_id
== -1) {
845 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
849 device
->info
= *physical_device
->info
;
850 device
->isl_dev
= physical_device
->isl_dev
;
852 /* On Broadwell and later, we can use batch chaining to more efficiently
853 * implement growing command buffers. Prior to Haswell, the kernel
854 * command parser gets in the way and we have to fall back to growing
857 device
->can_chain_batches
= device
->info
.gen
>= 8;
859 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
860 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
862 pthread_mutex_init(&device
->mutex
, NULL
);
864 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
866 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 16384);
868 anv_state_pool_init(&device
->dynamic_state_pool
,
869 &device
->dynamic_state_block_pool
);
871 anv_block_pool_init(&device
->instruction_block_pool
, device
, 128 * 1024);
872 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
);
874 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
876 anv_state_pool_init(&device
->surface_state_pool
,
877 &device
->surface_state_block_pool
);
879 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
881 anv_block_pool_init(&device
->scratch_block_pool
, device
, 0x10000);
883 anv_queue_init(device
, &device
->queue
);
885 switch (device
->info
.gen
) {
887 if (!device
->info
.is_haswell
)
888 result
= gen7_init_device_state(device
);
890 result
= gen75_init_device_state(device
);
893 result
= gen8_init_device_state(device
);
896 result
= gen9_init_device_state(device
);
899 /* Shouldn't get here as we don't create physical devices for any other
901 unreachable("unhandled gen");
903 if (result
!= VK_SUCCESS
)
906 result
= anv_device_init_meta(device
);
907 if (result
!= VK_SUCCESS
)
910 anv_device_init_border_colors(device
);
912 *pDevice
= anv_device_to_handle(device
);
919 anv_free(&device
->alloc
, device
);
924 void anv_DestroyDevice(
926 const VkAllocationCallbacks
* pAllocator
)
928 ANV_FROM_HANDLE(anv_device
, device
, _device
);
930 anv_queue_finish(&device
->queue
);
932 anv_device_finish_meta(device
);
935 /* We only need to free these to prevent valgrind errors. The backing
936 * BO will go away in a couple of lines so we don't actually leak.
938 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
941 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
942 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
944 anv_bo_pool_finish(&device
->batch_bo_pool
);
945 anv_state_pool_finish(&device
->dynamic_state_pool
);
946 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
947 anv_block_pool_finish(&device
->instruction_block_pool
);
948 anv_state_pool_finish(&device
->surface_state_pool
);
949 anv_block_pool_finish(&device
->surface_state_block_pool
);
950 anv_block_pool_finish(&device
->scratch_block_pool
);
954 pthread_mutex_destroy(&device
->mutex
);
956 anv_free(&device
->alloc
, device
);
959 VkResult
anv_EnumerateInstanceExtensionProperties(
960 const char* pLayerName
,
961 uint32_t* pPropertyCount
,
962 VkExtensionProperties
* pProperties
)
964 if (pProperties
== NULL
) {
965 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
969 assert(*pPropertyCount
>= ARRAY_SIZE(global_extensions
));
971 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
972 memcpy(pProperties
, global_extensions
, sizeof(global_extensions
));
977 VkResult
anv_EnumerateDeviceExtensionProperties(
978 VkPhysicalDevice physicalDevice
,
979 const char* pLayerName
,
980 uint32_t* pPropertyCount
,
981 VkExtensionProperties
* pProperties
)
983 if (pProperties
== NULL
) {
984 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
988 assert(*pPropertyCount
>= ARRAY_SIZE(device_extensions
));
990 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
991 memcpy(pProperties
, device_extensions
, sizeof(device_extensions
));
996 VkResult
anv_EnumerateInstanceLayerProperties(
997 uint32_t* pPropertyCount
,
998 VkLayerProperties
* pProperties
)
1000 if (pProperties
== NULL
) {
1001 *pPropertyCount
= 0;
1005 /* None supported at this time */
1006 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1009 VkResult
anv_EnumerateDeviceLayerProperties(
1010 VkPhysicalDevice physicalDevice
,
1011 uint32_t* pPropertyCount
,
1012 VkLayerProperties
* pProperties
)
1014 if (pProperties
== NULL
) {
1015 *pPropertyCount
= 0;
1019 /* None supported at this time */
1020 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1023 void anv_GetDeviceQueue(
1025 uint32_t queueNodeIndex
,
1026 uint32_t queueIndex
,
1029 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1031 assert(queueIndex
== 0);
1033 *pQueue
= anv_queue_to_handle(&device
->queue
);
1036 VkResult
anv_QueueSubmit(
1038 uint32_t submitCount
,
1039 const VkSubmitInfo
* pSubmits
,
1042 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1043 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1044 struct anv_device
*device
= queue
->device
;
1047 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1048 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1049 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
1050 pSubmits
[i
].pCommandBuffers
[j
]);
1051 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1053 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf2
.execbuf
);
1055 /* We don't know the real error. */
1056 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1057 "execbuf2 failed: %m");
1060 for (uint32_t k
= 0; k
< cmd_buffer
->execbuf2
.bo_count
; k
++)
1061 cmd_buffer
->execbuf2
.bos
[k
]->offset
= cmd_buffer
->execbuf2
.objects
[k
].offset
;
1066 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
1068 /* We don't know the real error. */
1069 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1070 "execbuf2 failed: %m");
1077 VkResult
anv_QueueWaitIdle(
1080 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1082 return ANV_CALL(DeviceWaitIdle
)(anv_device_to_handle(queue
->device
));
1085 VkResult
anv_DeviceWaitIdle(
1088 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1089 struct anv_batch batch
;
1092 batch
.start
= batch
.next
= cmds
;
1093 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1095 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1096 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1098 return anv_device_submit_simple_batch(device
, &batch
);
1102 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1104 bo
->gem_handle
= anv_gem_create(device
, size
);
1105 if (!bo
->gem_handle
)
1106 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1112 bo
->is_winsys_bo
= false;
1117 VkResult
anv_AllocateMemory(
1119 const VkMemoryAllocateInfo
* pAllocateInfo
,
1120 const VkAllocationCallbacks
* pAllocator
,
1121 VkDeviceMemory
* pMem
)
1123 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1124 struct anv_device_memory
*mem
;
1127 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1129 if (pAllocateInfo
->allocationSize
== 0) {
1130 /* Apparently, this is allowed */
1131 *pMem
= VK_NULL_HANDLE
;
1135 /* We support exactly one memory heap. */
1136 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1137 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1139 /* FINISHME: Fail if allocation request exceeds heap size. */
1141 mem
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1142 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1144 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1146 /* The kernel is going to give us whole pages anyway */
1147 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1149 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1150 if (result
!= VK_SUCCESS
)
1153 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1155 *pMem
= anv_device_memory_to_handle(mem
);
1160 anv_free2(&device
->alloc
, pAllocator
, mem
);
1165 void anv_FreeMemory(
1167 VkDeviceMemory _mem
,
1168 const VkAllocationCallbacks
* pAllocator
)
1170 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1171 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1177 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1179 if (mem
->bo
.gem_handle
!= 0)
1180 anv_gem_close(device
, mem
->bo
.gem_handle
);
1182 anv_free2(&device
->alloc
, pAllocator
, mem
);
1185 VkResult
anv_MapMemory(
1187 VkDeviceMemory _memory
,
1188 VkDeviceSize offset
,
1190 VkMemoryMapFlags flags
,
1193 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1194 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1201 if (size
== VK_WHOLE_SIZE
)
1202 size
= mem
->bo
.size
- offset
;
1204 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1205 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1206 * at a time is valid. We could just mmap up front and return an offset
1207 * pointer here, but that may exhaust virtual memory on 32 bit
1210 uint32_t gem_flags
= 0;
1211 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1212 gem_flags
|= I915_MMAP_WC
;
1214 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1215 uint64_t map_offset
= offset
& ~4095ull;
1216 assert(offset
>= map_offset
);
1217 uint64_t map_size
= (offset
+ size
) - map_offset
;
1219 /* Let's map whole pages */
1220 map_size
= align_u64(map_size
, 4096);
1222 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1223 map_offset
, map_size
, gem_flags
);
1224 mem
->map_size
= map_size
;
1226 *ppData
= mem
->map
+ (offset
- map_offset
);
1231 void anv_UnmapMemory(
1233 VkDeviceMemory _memory
)
1235 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1240 anv_gem_munmap(mem
->map
, mem
->map_size
);
1244 clflush_mapped_ranges(struct anv_device
*device
,
1246 const VkMappedMemoryRange
*ranges
)
1248 for (uint32_t i
= 0; i
< count
; i
++) {
1249 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1250 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1253 if (ranges
[i
].offset
+ ranges
[i
].size
> mem
->map_size
)
1254 end
= mem
->map
+ mem
->map_size
;
1256 end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1259 __builtin_ia32_clflush(p
);
1260 p
+= CACHELINE_SIZE
;
1265 VkResult
anv_FlushMappedMemoryRanges(
1267 uint32_t memoryRangeCount
,
1268 const VkMappedMemoryRange
* pMemoryRanges
)
1270 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1272 if (device
->info
.has_llc
)
1275 /* Make sure the writes we're flushing have landed. */
1276 __builtin_ia32_mfence();
1278 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1283 VkResult
anv_InvalidateMappedMemoryRanges(
1285 uint32_t memoryRangeCount
,
1286 const VkMappedMemoryRange
* pMemoryRanges
)
1288 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1290 if (device
->info
.has_llc
)
1293 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1295 /* Make sure no reads get moved up above the invalidate. */
1296 __builtin_ia32_mfence();
1301 void anv_GetBufferMemoryRequirements(
1304 VkMemoryRequirements
* pMemoryRequirements
)
1306 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1308 /* The Vulkan spec (git aaed022) says:
1310 * memoryTypeBits is a bitfield and contains one bit set for every
1311 * supported memory type for the resource. The bit `1<<i` is set if and
1312 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1313 * structure for the physical device is supported.
1315 * We support exactly one memory type.
1317 pMemoryRequirements
->memoryTypeBits
= 1;
1319 pMemoryRequirements
->size
= buffer
->size
;
1320 pMemoryRequirements
->alignment
= 16;
1323 void anv_GetImageMemoryRequirements(
1326 VkMemoryRequirements
* pMemoryRequirements
)
1328 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1330 /* The Vulkan spec (git aaed022) says:
1332 * memoryTypeBits is a bitfield and contains one bit set for every
1333 * supported memory type for the resource. The bit `1<<i` is set if and
1334 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1335 * structure for the physical device is supported.
1337 * We support exactly one memory type.
1339 pMemoryRequirements
->memoryTypeBits
= 1;
1341 pMemoryRequirements
->size
= image
->size
;
1342 pMemoryRequirements
->alignment
= image
->alignment
;
1345 void anv_GetImageSparseMemoryRequirements(
1348 uint32_t* pSparseMemoryRequirementCount
,
1349 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1354 void anv_GetDeviceMemoryCommitment(
1356 VkDeviceMemory memory
,
1357 VkDeviceSize
* pCommittedMemoryInBytes
)
1359 *pCommittedMemoryInBytes
= 0;
1362 VkResult
anv_BindBufferMemory(
1365 VkDeviceMemory _memory
,
1366 VkDeviceSize memoryOffset
)
1368 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1369 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1372 buffer
->bo
= &mem
->bo
;
1373 buffer
->offset
= memoryOffset
;
1382 VkResult
anv_BindImageMemory(
1385 VkDeviceMemory _memory
,
1386 VkDeviceSize memoryOffset
)
1388 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1389 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1392 image
->bo
= &mem
->bo
;
1393 image
->offset
= memoryOffset
;
1402 VkResult
anv_QueueBindSparse(
1404 uint32_t bindInfoCount
,
1405 const VkBindSparseInfo
* pBindInfo
,
1408 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1411 VkResult
anv_CreateFence(
1413 const VkFenceCreateInfo
* pCreateInfo
,
1414 const VkAllocationCallbacks
* pAllocator
,
1417 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1418 struct anv_bo fence_bo
;
1419 struct anv_fence
*fence
;
1420 struct anv_batch batch
;
1423 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1425 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &fence_bo
, 4096);
1426 if (result
!= VK_SUCCESS
)
1429 /* Fences are small. Just store the CPU data structure in the BO. */
1430 fence
= fence_bo
.map
;
1431 fence
->bo
= fence_bo
;
1433 /* Place the batch after the CPU data but on its own cache line. */
1434 const uint32_t batch_offset
= align_u32(sizeof(*fence
), CACHELINE_SIZE
);
1435 batch
.next
= batch
.start
= fence
->bo
.map
+ batch_offset
;
1436 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1437 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1438 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1440 if (!device
->info
.has_llc
) {
1441 assert(((uintptr_t) batch
.start
& CACHELINE_MASK
) == 0);
1442 assert(batch
.next
- batch
.start
<= CACHELINE_SIZE
);
1443 __builtin_ia32_mfence();
1444 __builtin_ia32_clflush(batch
.start
);
1447 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1448 fence
->exec2_objects
[0].relocation_count
= 0;
1449 fence
->exec2_objects
[0].relocs_ptr
= 0;
1450 fence
->exec2_objects
[0].alignment
= 0;
1451 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1452 fence
->exec2_objects
[0].flags
= 0;
1453 fence
->exec2_objects
[0].rsvd1
= 0;
1454 fence
->exec2_objects
[0].rsvd2
= 0;
1456 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1457 fence
->execbuf
.buffer_count
= 1;
1458 fence
->execbuf
.batch_start_offset
= batch
.start
- fence
->bo
.map
;
1459 fence
->execbuf
.batch_len
= batch
.next
- batch
.start
;
1460 fence
->execbuf
.cliprects_ptr
= 0;
1461 fence
->execbuf
.num_cliprects
= 0;
1462 fence
->execbuf
.DR1
= 0;
1463 fence
->execbuf
.DR4
= 0;
1465 fence
->execbuf
.flags
=
1466 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1467 fence
->execbuf
.rsvd1
= device
->context_id
;
1468 fence
->execbuf
.rsvd2
= 0;
1470 fence
->ready
= false;
1472 *pFence
= anv_fence_to_handle(fence
);
1477 void anv_DestroyFence(
1480 const VkAllocationCallbacks
* pAllocator
)
1482 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1483 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1485 assert(fence
->bo
.map
== fence
);
1486 anv_bo_pool_free(&device
->batch_bo_pool
, &fence
->bo
);
1489 VkResult
anv_ResetFences(
1491 uint32_t fenceCount
,
1492 const VkFence
* pFences
)
1494 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1495 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1496 fence
->ready
= false;
1502 VkResult
anv_GetFenceStatus(
1506 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1507 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1514 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1516 fence
->ready
= true;
1520 return VK_NOT_READY
;
1523 VkResult
anv_WaitForFences(
1525 uint32_t fenceCount
,
1526 const VkFence
* pFences
,
1530 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1532 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1533 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1534 * for a couple of kernel releases. Since there's no way to know
1535 * whether or not the kernel we're using is one of the broken ones, the
1536 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1537 * maximum timeout from 584 years to 292 years - likely not a big deal.
1539 if (timeout
> INT64_MAX
)
1540 timeout
= INT64_MAX
;
1542 int64_t t
= timeout
;
1544 /* FIXME: handle !waitAll */
1546 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1547 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1548 int ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1549 if (ret
== -1 && errno
== ETIME
) {
1551 } else if (ret
== -1) {
1552 /* We don't know the real error. */
1553 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1554 "gem wait failed: %m");
1561 // Queue semaphore functions
1563 VkResult
anv_CreateSemaphore(
1565 const VkSemaphoreCreateInfo
* pCreateInfo
,
1566 const VkAllocationCallbacks
* pAllocator
,
1567 VkSemaphore
* pSemaphore
)
1569 /* The DRM execbuffer ioctl always execute in-oder, even between different
1570 * rings. As such, there's nothing to do for the user space semaphore.
1573 *pSemaphore
= (VkSemaphore
)1;
1578 void anv_DestroySemaphore(
1580 VkSemaphore semaphore
,
1581 const VkAllocationCallbacks
* pAllocator
)
1587 VkResult
anv_CreateEvent(
1589 const VkEventCreateInfo
* pCreateInfo
,
1590 const VkAllocationCallbacks
* pAllocator
,
1593 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1594 struct anv_state state
;
1595 struct anv_event
*event
;
1597 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1599 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1602 event
->state
= state
;
1603 event
->semaphore
= VK_EVENT_RESET
;
1605 if (!device
->info
.has_llc
) {
1606 /* Make sure the writes we're flushing have landed. */
1607 __builtin_ia32_mfence();
1608 __builtin_ia32_clflush(event
);
1611 *pEvent
= anv_event_to_handle(event
);
1616 void anv_DestroyEvent(
1619 const VkAllocationCallbacks
* pAllocator
)
1621 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1622 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1624 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1627 VkResult
anv_GetEventStatus(
1631 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1632 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1634 if (!device
->info
.has_llc
) {
1635 /* Invalidate read cache before reading event written by GPU. */
1636 __builtin_ia32_clflush(event
);
1637 __builtin_ia32_mfence();
1641 return event
->semaphore
;
1644 VkResult
anv_SetEvent(
1648 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1649 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1651 event
->semaphore
= VK_EVENT_SET
;
1653 if (!device
->info
.has_llc
) {
1654 /* Make sure the writes we're flushing have landed. */
1655 __builtin_ia32_mfence();
1656 __builtin_ia32_clflush(event
);
1662 VkResult
anv_ResetEvent(
1666 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1667 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1669 event
->semaphore
= VK_EVENT_RESET
;
1671 if (!device
->info
.has_llc
) {
1672 /* Make sure the writes we're flushing have landed. */
1673 __builtin_ia32_mfence();
1674 __builtin_ia32_clflush(event
);
1682 VkResult
anv_CreateBuffer(
1684 const VkBufferCreateInfo
* pCreateInfo
,
1685 const VkAllocationCallbacks
* pAllocator
,
1688 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1689 struct anv_buffer
*buffer
;
1691 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1693 buffer
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1694 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1696 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1698 buffer
->size
= pCreateInfo
->size
;
1699 buffer
->usage
= pCreateInfo
->usage
;
1703 *pBuffer
= anv_buffer_to_handle(buffer
);
1708 void anv_DestroyBuffer(
1711 const VkAllocationCallbacks
* pAllocator
)
1713 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1714 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1716 anv_free2(&device
->alloc
, pAllocator
, buffer
);
1720 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
1721 enum isl_format format
,
1722 uint32_t offset
, uint32_t range
, uint32_t stride
)
1724 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
1726 .mocs
= device
->default_mocs
,
1731 if (!device
->info
.has_llc
)
1732 anv_state_clflush(state
);
1735 void anv_DestroySampler(
1738 const VkAllocationCallbacks
* pAllocator
)
1740 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1741 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1743 anv_free2(&device
->alloc
, pAllocator
, sampler
);
1746 VkResult
anv_CreateFramebuffer(
1748 const VkFramebufferCreateInfo
* pCreateInfo
,
1749 const VkAllocationCallbacks
* pAllocator
,
1750 VkFramebuffer
* pFramebuffer
)
1752 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1753 struct anv_framebuffer
*framebuffer
;
1755 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1757 size_t size
= sizeof(*framebuffer
) +
1758 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
1759 framebuffer
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1760 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1761 if (framebuffer
== NULL
)
1762 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1764 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1765 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1766 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1767 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
1770 framebuffer
->width
= pCreateInfo
->width
;
1771 framebuffer
->height
= pCreateInfo
->height
;
1772 framebuffer
->layers
= pCreateInfo
->layers
;
1774 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
1779 void anv_DestroyFramebuffer(
1782 const VkAllocationCallbacks
* pAllocator
)
1784 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1785 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
1787 anv_free2(&device
->alloc
, pAllocator
, fb
);
1790 void vkCmdDbgMarkerBegin(
1791 VkCommandBuffer commandBuffer
,
1792 const char* pMarker
)
1793 __attribute__ ((visibility ("default")));
1795 void vkCmdDbgMarkerEnd(
1796 VkCommandBuffer commandBuffer
)
1797 __attribute__ ((visibility ("default")));
1799 void vkCmdDbgMarkerBegin(
1800 VkCommandBuffer commandBuffer
,
1801 const char* pMarker
)
1805 void vkCmdDbgMarkerEnd(
1806 VkCommandBuffer commandBuffer
)