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
31 #include "anv_private.h"
32 #include "util/strtod.h"
33 #include "util/debug.h"
34 #include "util/build_id.h"
35 #include "util/vk_util.h"
37 #include "genxml/gen7_pack.h"
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_device_get_cache_uuid(void *uuid
)
58 const struct build_id_note
*note
= build_id_find_nhdr("libvulkan_intel.so");
62 unsigned len
= build_id_length(note
);
63 if (len
< VK_UUID_SIZE
)
66 memcpy(uuid
, build_id_data(note
), VK_UUID_SIZE
);
71 anv_physical_device_init(struct anv_physical_device
*device
,
72 struct anv_instance
*instance
,
78 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
80 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
82 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
83 device
->instance
= instance
;
85 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
86 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
88 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
89 if (!device
->chipset_id
) {
90 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
94 device
->name
= gen_get_device_name(device
->chipset_id
);
95 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
96 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
100 if (device
->info
.is_haswell
) {
101 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
102 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
103 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
104 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
105 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
106 } else if (device
->info
.gen
>= 8) {
107 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
108 * supported as anything */
110 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
111 "Vulkan not yet supported on %s", device
->name
);
115 device
->cmd_parser_version
= -1;
116 if (device
->info
.gen
== 7) {
117 device
->cmd_parser_version
=
118 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
119 if (device
->cmd_parser_version
== -1) {
120 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
121 "failed to get command parser version");
126 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
127 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
128 "failed to get aperture size: %m");
132 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
133 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
134 "kernel missing gem wait");
138 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
139 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
140 "kernel missing execbuf2");
144 if (!device
->info
.has_llc
&&
145 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
146 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
147 "kernel missing wc mmap");
151 if (!anv_device_get_cache_uuid(device
->uuid
)) {
152 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
153 "cannot generate UUID");
156 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
158 /* GENs prior to 8 do not support EU/Subslice info */
159 if (device
->info
.gen
>= 8) {
160 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
161 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
163 /* Without this information, we cannot get the right Braswell
164 * brandstrings, and we have to use conservative numbers for GPGPU on
165 * many platforms, but otherwise, things will just work.
167 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
168 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
169 " query GPU properties.\n");
171 } else if (device
->info
.gen
== 7) {
172 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
175 if (device
->info
.is_cherryview
&&
176 device
->subslice_total
> 0 && device
->eu_total
> 0) {
177 /* Logical CS threads = EUs per subslice * 7 threads per EU */
178 uint32_t max_cs_threads
= device
->eu_total
/ device
->subslice_total
* 7;
180 /* Fuse configurations may give more threads than expected, never less. */
181 if (max_cs_threads
> device
->info
.max_cs_threads
)
182 device
->info
.max_cs_threads
= max_cs_threads
;
185 brw_process_intel_debug_variable();
187 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
188 if (device
->compiler
== NULL
) {
189 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
192 device
->compiler
->shader_debug_log
= compiler_debug_log
;
193 device
->compiler
->shader_perf_log
= compiler_perf_log
;
195 result
= anv_init_wsi(device
);
196 if (result
!= VK_SUCCESS
) {
197 ralloc_free(device
->compiler
);
201 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
203 device
->local_fd
= fd
;
212 anv_physical_device_finish(struct anv_physical_device
*device
)
214 anv_finish_wsi(device
);
215 ralloc_free(device
->compiler
);
216 close(device
->local_fd
);
219 static const VkExtensionProperties global_extensions
[] = {
221 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
224 #ifdef VK_USE_PLATFORM_XCB_KHR
226 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
230 #ifdef VK_USE_PLATFORM_XLIB_KHR
232 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
236 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
238 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
243 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
248 static const VkExtensionProperties device_extensions
[] = {
250 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
254 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
258 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
262 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
268 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
269 VkSystemAllocationScope allocationScope
)
275 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
276 size_t align
, VkSystemAllocationScope allocationScope
)
278 return realloc(pOriginal
, size
);
282 default_free_func(void *pUserData
, void *pMemory
)
287 static const VkAllocationCallbacks default_alloc
= {
289 .pfnAllocation
= default_alloc_func
,
290 .pfnReallocation
= default_realloc_func
,
291 .pfnFree
= default_free_func
,
294 VkResult
anv_CreateInstance(
295 const VkInstanceCreateInfo
* pCreateInfo
,
296 const VkAllocationCallbacks
* pAllocator
,
297 VkInstance
* pInstance
)
299 struct anv_instance
*instance
;
301 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
303 uint32_t client_version
;
304 if (pCreateInfo
->pApplicationInfo
&&
305 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
306 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
308 client_version
= VK_MAKE_VERSION(1, 0, 0);
311 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
312 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
313 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
314 "Client requested version %d.%d.%d",
315 VK_VERSION_MAJOR(client_version
),
316 VK_VERSION_MINOR(client_version
),
317 VK_VERSION_PATCH(client_version
));
320 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
322 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
323 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
324 global_extensions
[j
].extensionName
) == 0) {
330 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
333 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
334 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
336 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
338 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
341 instance
->alloc
= *pAllocator
;
343 instance
->alloc
= default_alloc
;
345 instance
->apiVersion
= client_version
;
346 instance
->physicalDeviceCount
= -1;
350 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
352 *pInstance
= anv_instance_to_handle(instance
);
357 void anv_DestroyInstance(
358 VkInstance _instance
,
359 const VkAllocationCallbacks
* pAllocator
)
361 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
366 if (instance
->physicalDeviceCount
> 0) {
367 /* We support at most one physical device. */
368 assert(instance
->physicalDeviceCount
== 1);
369 anv_physical_device_finish(&instance
->physicalDevice
);
372 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
376 vk_free(&instance
->alloc
, instance
);
379 VkResult
anv_EnumeratePhysicalDevices(
380 VkInstance _instance
,
381 uint32_t* pPhysicalDeviceCount
,
382 VkPhysicalDevice
* pPhysicalDevices
)
384 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
387 if (instance
->physicalDeviceCount
< 0) {
389 for (unsigned i
= 0; i
< 8; i
++) {
390 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
391 result
= anv_physical_device_init(&instance
->physicalDevice
,
393 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
397 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
398 instance
->physicalDeviceCount
= 0;
399 } else if (result
== VK_SUCCESS
) {
400 instance
->physicalDeviceCount
= 1;
406 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
407 * otherwise it's an inout parameter.
409 * The Vulkan spec (git aaed022) says:
411 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
412 * that is initialized with the number of devices the application is
413 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
414 * an array of at least this many VkPhysicalDevice handles [...].
416 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
417 * overwrites the contents of the variable pointed to by
418 * pPhysicalDeviceCount with the number of physical devices in in the
419 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
420 * pPhysicalDeviceCount with the number of physical handles written to
423 if (!pPhysicalDevices
) {
424 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
425 } else if (*pPhysicalDeviceCount
>= 1) {
426 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
427 *pPhysicalDeviceCount
= 1;
428 } else if (*pPhysicalDeviceCount
< instance
->physicalDeviceCount
) {
429 return VK_INCOMPLETE
;
431 *pPhysicalDeviceCount
= 0;
437 void anv_GetPhysicalDeviceFeatures(
438 VkPhysicalDevice physicalDevice
,
439 VkPhysicalDeviceFeatures
* pFeatures
)
441 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
443 *pFeatures
= (VkPhysicalDeviceFeatures
) {
444 .robustBufferAccess
= true,
445 .fullDrawIndexUint32
= true,
446 .imageCubeArray
= true,
447 .independentBlend
= true,
448 .geometryShader
= true,
449 .tessellationShader
= true,
450 .sampleRateShading
= true,
451 .dualSrcBlend
= true,
453 .multiDrawIndirect
= false,
454 .drawIndirectFirstInstance
= true,
456 .depthBiasClamp
= true,
457 .fillModeNonSolid
= true,
458 .depthBounds
= false,
462 .multiViewport
= true,
463 .samplerAnisotropy
= true,
464 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
465 pdevice
->info
.is_baytrail
,
466 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
467 .textureCompressionBC
= true,
468 .occlusionQueryPrecise
= true,
469 .pipelineStatisticsQuery
= false,
470 .fragmentStoresAndAtomics
= true,
471 .shaderTessellationAndGeometryPointSize
= true,
472 .shaderImageGatherExtended
= true,
473 .shaderStorageImageExtendedFormats
= true,
474 .shaderStorageImageMultisample
= false,
475 .shaderStorageImageReadWithoutFormat
= false,
476 .shaderStorageImageWriteWithoutFormat
= true,
477 .shaderUniformBufferArrayDynamicIndexing
= true,
478 .shaderSampledImageArrayDynamicIndexing
= true,
479 .shaderStorageBufferArrayDynamicIndexing
= true,
480 .shaderStorageImageArrayDynamicIndexing
= true,
481 .shaderClipDistance
= true,
482 .shaderCullDistance
= true,
483 .shaderFloat64
= pdevice
->info
.gen
>= 8,
484 .shaderInt64
= false,
485 .shaderInt16
= false,
486 .shaderResourceMinLod
= false,
487 .variableMultisampleRate
= false,
488 .inheritedQueries
= false,
491 /* We can't do image stores in vec4 shaders */
492 pFeatures
->vertexPipelineStoresAndAtomics
=
493 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
494 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
497 void anv_GetPhysicalDeviceFeatures2KHR(
498 VkPhysicalDevice physicalDevice
,
499 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
501 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
503 vk_foreach_struct(ext
, pFeatures
->pNext
) {
504 switch (ext
->sType
) {
506 anv_debug_ignored_stype(ext
->sType
);
512 void anv_GetPhysicalDeviceProperties(
513 VkPhysicalDevice physicalDevice
,
514 VkPhysicalDeviceProperties
* pProperties
)
516 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
517 const struct gen_device_info
*devinfo
= &pdevice
->info
;
519 const float time_stamp_base
= devinfo
->gen
>= 9 ? 83.333 : 80.0;
521 /* See assertions made when programming the buffer surface state. */
522 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
523 (1ul << 30) : (1ul << 27);
525 VkSampleCountFlags sample_counts
=
526 isl_device_get_sample_counts(&pdevice
->isl_dev
);
528 VkPhysicalDeviceLimits limits
= {
529 .maxImageDimension1D
= (1 << 14),
530 .maxImageDimension2D
= (1 << 14),
531 .maxImageDimension3D
= (1 << 11),
532 .maxImageDimensionCube
= (1 << 14),
533 .maxImageArrayLayers
= (1 << 11),
534 .maxTexelBufferElements
= 128 * 1024 * 1024,
535 .maxUniformBufferRange
= (1ul << 27),
536 .maxStorageBufferRange
= max_raw_buffer_sz
,
537 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
538 .maxMemoryAllocationCount
= UINT32_MAX
,
539 .maxSamplerAllocationCount
= 64 * 1024,
540 .bufferImageGranularity
= 64, /* A cache line */
541 .sparseAddressSpaceSize
= 0,
542 .maxBoundDescriptorSets
= MAX_SETS
,
543 .maxPerStageDescriptorSamplers
= 64,
544 .maxPerStageDescriptorUniformBuffers
= 64,
545 .maxPerStageDescriptorStorageBuffers
= 64,
546 .maxPerStageDescriptorSampledImages
= 64,
547 .maxPerStageDescriptorStorageImages
= 64,
548 .maxPerStageDescriptorInputAttachments
= 64,
549 .maxPerStageResources
= 128,
550 .maxDescriptorSetSamplers
= 256,
551 .maxDescriptorSetUniformBuffers
= 256,
552 .maxDescriptorSetUniformBuffersDynamic
= 256,
553 .maxDescriptorSetStorageBuffers
= 256,
554 .maxDescriptorSetStorageBuffersDynamic
= 256,
555 .maxDescriptorSetSampledImages
= 256,
556 .maxDescriptorSetStorageImages
= 256,
557 .maxDescriptorSetInputAttachments
= 256,
558 .maxVertexInputAttributes
= MAX_VBS
,
559 .maxVertexInputBindings
= MAX_VBS
,
560 .maxVertexInputAttributeOffset
= 2047,
561 .maxVertexInputBindingStride
= 2048,
562 .maxVertexOutputComponents
= 128,
563 .maxTessellationGenerationLevel
= 64,
564 .maxTessellationPatchSize
= 32,
565 .maxTessellationControlPerVertexInputComponents
= 128,
566 .maxTessellationControlPerVertexOutputComponents
= 128,
567 .maxTessellationControlPerPatchOutputComponents
= 128,
568 .maxTessellationControlTotalOutputComponents
= 2048,
569 .maxTessellationEvaluationInputComponents
= 128,
570 .maxTessellationEvaluationOutputComponents
= 128,
571 .maxGeometryShaderInvocations
= 32,
572 .maxGeometryInputComponents
= 64,
573 .maxGeometryOutputComponents
= 128,
574 .maxGeometryOutputVertices
= 256,
575 .maxGeometryTotalOutputComponents
= 1024,
576 .maxFragmentInputComponents
= 128,
577 .maxFragmentOutputAttachments
= 8,
578 .maxFragmentDualSrcAttachments
= 1,
579 .maxFragmentCombinedOutputResources
= 8,
580 .maxComputeSharedMemorySize
= 32768,
581 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
582 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
583 .maxComputeWorkGroupSize
= {
584 16 * devinfo
->max_cs_threads
,
585 16 * devinfo
->max_cs_threads
,
586 16 * devinfo
->max_cs_threads
,
588 .subPixelPrecisionBits
= 4 /* FIXME */,
589 .subTexelPrecisionBits
= 4 /* FIXME */,
590 .mipmapPrecisionBits
= 4 /* FIXME */,
591 .maxDrawIndexedIndexValue
= UINT32_MAX
,
592 .maxDrawIndirectCount
= UINT32_MAX
,
593 .maxSamplerLodBias
= 16,
594 .maxSamplerAnisotropy
= 16,
595 .maxViewports
= MAX_VIEWPORTS
,
596 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
597 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
598 .viewportSubPixelBits
= 13, /* We take a float? */
599 .minMemoryMapAlignment
= 4096, /* A page */
600 .minTexelBufferOffsetAlignment
= 1,
601 .minUniformBufferOffsetAlignment
= 16,
602 .minStorageBufferOffsetAlignment
= 4,
603 .minTexelOffset
= -8,
605 .minTexelGatherOffset
= -32,
606 .maxTexelGatherOffset
= 31,
607 .minInterpolationOffset
= -0.5,
608 .maxInterpolationOffset
= 0.4375,
609 .subPixelInterpolationOffsetBits
= 4,
610 .maxFramebufferWidth
= (1 << 14),
611 .maxFramebufferHeight
= (1 << 14),
612 .maxFramebufferLayers
= (1 << 11),
613 .framebufferColorSampleCounts
= sample_counts
,
614 .framebufferDepthSampleCounts
= sample_counts
,
615 .framebufferStencilSampleCounts
= sample_counts
,
616 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
617 .maxColorAttachments
= MAX_RTS
,
618 .sampledImageColorSampleCounts
= sample_counts
,
619 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
620 .sampledImageDepthSampleCounts
= sample_counts
,
621 .sampledImageStencilSampleCounts
= sample_counts
,
622 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
623 .maxSampleMaskWords
= 1,
624 .timestampComputeAndGraphics
= false,
625 .timestampPeriod
= time_stamp_base
,
626 .maxClipDistances
= 8,
627 .maxCullDistances
= 8,
628 .maxCombinedClipAndCullDistances
= 8,
629 .discreteQueuePriorities
= 1,
630 .pointSizeRange
= { 0.125, 255.875 },
631 .lineWidthRange
= { 0.0, 7.9921875 },
632 .pointSizeGranularity
= (1.0 / 8.0),
633 .lineWidthGranularity
= (1.0 / 128.0),
634 .strictLines
= false, /* FINISHME */
635 .standardSampleLocations
= true,
636 .optimalBufferCopyOffsetAlignment
= 128,
637 .optimalBufferCopyRowPitchAlignment
= 128,
638 .nonCoherentAtomSize
= 64,
641 *pProperties
= (VkPhysicalDeviceProperties
) {
642 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
645 .deviceID
= pdevice
->chipset_id
,
646 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
648 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
651 strcpy(pProperties
->deviceName
, pdevice
->name
);
652 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
655 void anv_GetPhysicalDeviceProperties2KHR(
656 VkPhysicalDevice physicalDevice
,
657 VkPhysicalDeviceProperties2KHR
* pProperties
)
659 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
661 vk_foreach_struct(ext
, pProperties
->pNext
) {
662 switch (ext
->sType
) {
664 anv_debug_ignored_stype(ext
->sType
);
671 anv_get_queue_family_properties(struct anv_physical_device
*phys_dev
,
672 VkQueueFamilyProperties
*props
)
674 *props
= (VkQueueFamilyProperties
) {
675 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
676 VK_QUEUE_COMPUTE_BIT
|
677 VK_QUEUE_TRANSFER_BIT
,
679 .timestampValidBits
= 36, /* XXX: Real value here */
680 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
684 void anv_GetPhysicalDeviceQueueFamilyProperties(
685 VkPhysicalDevice physicalDevice
,
687 VkQueueFamilyProperties
* pQueueFamilyProperties
)
689 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
691 if (pQueueFamilyProperties
== NULL
) {
696 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
697 * 1.0.38 spec, Section 4.1 Physical Devices:
699 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
706 anv_get_queue_family_properties(phys_dev
, pQueueFamilyProperties
);
709 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
710 VkPhysicalDevice physicalDevice
,
711 uint32_t* pQueueFamilyPropertyCount
,
712 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
715 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
717 if (pQueueFamilyProperties
== NULL
) {
718 *pQueueFamilyPropertyCount
= 1;
722 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
723 * 1.0.38 spec, Section 4.1 Physical Devices:
725 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
728 if (*pQueueFamilyPropertyCount
== 0)
731 /* We support exactly one queue family. So need to traverse only the first
732 * array element's pNext chain.
734 *pQueueFamilyPropertyCount
= 1;
735 anv_get_queue_family_properties(phys_dev
,
736 &pQueueFamilyProperties
->queueFamilyProperties
);
738 vk_foreach_struct(ext
, pQueueFamilyProperties
->pNext
) {
739 switch (ext
->sType
) {
741 anv_debug_ignored_stype(ext
->sType
);
747 void anv_GetPhysicalDeviceMemoryProperties(
748 VkPhysicalDevice physicalDevice
,
749 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
751 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
752 VkDeviceSize heap_size
;
754 /* Reserve some wiggle room for the driver by exposing only 75% of the
755 * aperture to the heap.
757 heap_size
= 3 * physical_device
->aperture_size
/ 4;
759 if (physical_device
->info
.has_llc
) {
760 /* Big core GPUs share LLC with the CPU and thus one memory type can be
761 * both cached and coherent at the same time.
763 pMemoryProperties
->memoryTypeCount
= 1;
764 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
765 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
766 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
767 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
768 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
772 /* The spec requires that we expose a host-visible, coherent memory
773 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
774 * to give the application a choice between cached, but not coherent and
775 * coherent but uncached (WC though).
777 pMemoryProperties
->memoryTypeCount
= 2;
778 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
779 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
780 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
781 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
784 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
785 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
786 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
787 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
792 pMemoryProperties
->memoryHeapCount
= 1;
793 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
795 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
799 void anv_GetPhysicalDeviceMemoryProperties2KHR(
800 VkPhysicalDevice physicalDevice
,
801 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
803 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
804 &pMemoryProperties
->memoryProperties
);
806 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
807 switch (ext
->sType
) {
809 anv_debug_ignored_stype(ext
->sType
);
815 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
819 return anv_lookup_entrypoint(NULL
, pName
);
822 /* With version 1+ of the loader interface the ICD should expose
823 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
826 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
831 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
835 return anv_GetInstanceProcAddr(instance
, pName
);
838 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
842 ANV_FROM_HANDLE(anv_device
, device
, _device
);
843 return anv_lookup_entrypoint(&device
->info
, pName
);
847 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
849 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
850 queue
->device
= device
;
851 queue
->pool
= &device
->surface_state_pool
;
855 anv_queue_finish(struct anv_queue
*queue
)
859 static struct anv_state
860 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
862 struct anv_state state
;
864 state
= anv_state_pool_alloc(pool
, size
, align
);
865 memcpy(state
.map
, p
, size
);
867 anv_state_flush(pool
->block_pool
->device
, state
);
872 struct gen8_border_color
{
877 /* Pad out to 64 bytes */
882 anv_device_init_border_colors(struct anv_device
*device
)
884 static const struct gen8_border_color border_colors
[] = {
885 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
886 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
887 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
888 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
889 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
890 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
893 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
894 sizeof(border_colors
), 64,
899 anv_device_submit_simple_batch(struct anv_device
*device
,
900 struct anv_batch
*batch
)
902 struct drm_i915_gem_execbuffer2 execbuf
;
903 struct drm_i915_gem_exec_object2 exec2_objects
[1];
904 struct anv_bo bo
, *exec_bos
[1];
905 VkResult result
= VK_SUCCESS
;
910 /* Kernel driver requires 8 byte aligned batch length */
911 size
= align_u32(batch
->next
- batch
->start
, 8);
912 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bo
, size
);
913 if (result
!= VK_SUCCESS
)
916 memcpy(bo
.map
, batch
->start
, size
);
917 if (!device
->info
.has_llc
)
918 anv_flush_range(bo
.map
, size
);
921 exec2_objects
[0].handle
= bo
.gem_handle
;
922 exec2_objects
[0].relocation_count
= 0;
923 exec2_objects
[0].relocs_ptr
= 0;
924 exec2_objects
[0].alignment
= 0;
925 exec2_objects
[0].offset
= bo
.offset
;
926 exec2_objects
[0].flags
= 0;
927 exec2_objects
[0].rsvd1
= 0;
928 exec2_objects
[0].rsvd2
= 0;
930 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
931 execbuf
.buffer_count
= 1;
932 execbuf
.batch_start_offset
= 0;
933 execbuf
.batch_len
= size
;
934 execbuf
.cliprects_ptr
= 0;
935 execbuf
.num_cliprects
= 0;
940 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
941 execbuf
.rsvd1
= device
->context_id
;
944 result
= anv_device_execbuf(device
, &execbuf
, exec_bos
);
945 if (result
!= VK_SUCCESS
)
949 ret
= anv_gem_wait(device
, bo
.gem_handle
, &timeout
);
951 /* We don't know the real error. */
952 result
= vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
957 anv_bo_pool_free(&device
->batch_bo_pool
, &bo
);
962 VkResult
anv_CreateDevice(
963 VkPhysicalDevice physicalDevice
,
964 const VkDeviceCreateInfo
* pCreateInfo
,
965 const VkAllocationCallbacks
* pAllocator
,
968 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
970 struct anv_device
*device
;
972 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
974 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
976 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
977 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
978 device_extensions
[j
].extensionName
) == 0) {
984 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
987 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
989 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
991 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
993 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
994 device
->instance
= physical_device
->instance
;
995 device
->chipset_id
= physical_device
->chipset_id
;
998 device
->alloc
= *pAllocator
;
1000 device
->alloc
= physical_device
->instance
->alloc
;
1002 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1003 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1004 if (device
->fd
== -1) {
1005 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1009 device
->context_id
= anv_gem_create_context(device
);
1010 if (device
->context_id
== -1) {
1011 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1015 device
->info
= physical_device
->info
;
1016 device
->isl_dev
= physical_device
->isl_dev
;
1018 /* On Broadwell and later, we can use batch chaining to more efficiently
1019 * implement growing command buffers. Prior to Haswell, the kernel
1020 * command parser gets in the way and we have to fall back to growing
1023 device
->can_chain_batches
= device
->info
.gen
>= 8;
1025 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1026 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1028 pthread_mutex_init(&device
->mutex
, NULL
);
1030 pthread_condattr_t condattr
;
1031 pthread_condattr_init(&condattr
);
1032 pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
);
1033 pthread_cond_init(&device
->queue_submit
, NULL
);
1034 pthread_condattr_destroy(&condattr
);
1036 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1038 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 16384);
1040 anv_state_pool_init(&device
->dynamic_state_pool
,
1041 &device
->dynamic_state_block_pool
);
1043 anv_block_pool_init(&device
->instruction_block_pool
, device
, 1024 * 1024);
1044 anv_state_pool_init(&device
->instruction_state_pool
,
1045 &device
->instruction_block_pool
);
1047 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
1049 anv_state_pool_init(&device
->surface_state_pool
,
1050 &device
->surface_state_block_pool
);
1052 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1054 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1056 anv_queue_init(device
, &device
->queue
);
1058 switch (device
->info
.gen
) {
1060 if (!device
->info
.is_haswell
)
1061 result
= gen7_init_device_state(device
);
1063 result
= gen75_init_device_state(device
);
1066 result
= gen8_init_device_state(device
);
1069 result
= gen9_init_device_state(device
);
1072 /* Shouldn't get here as we don't create physical devices for any other
1074 unreachable("unhandled gen");
1076 if (result
!= VK_SUCCESS
)
1079 anv_device_init_blorp(device
);
1081 anv_device_init_border_colors(device
);
1083 *pDevice
= anv_device_to_handle(device
);
1090 vk_free(&device
->alloc
, device
);
1095 void anv_DestroyDevice(
1097 const VkAllocationCallbacks
* pAllocator
)
1099 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1104 anv_device_finish_blorp(device
);
1106 anv_queue_finish(&device
->queue
);
1108 #ifdef HAVE_VALGRIND
1109 /* We only need to free these to prevent valgrind errors. The backing
1110 * BO will go away in a couple of lines so we don't actually leak.
1112 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1115 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1117 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1118 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1120 anv_state_pool_finish(&device
->surface_state_pool
);
1121 anv_block_pool_finish(&device
->surface_state_block_pool
);
1122 anv_state_pool_finish(&device
->instruction_state_pool
);
1123 anv_block_pool_finish(&device
->instruction_block_pool
);
1124 anv_state_pool_finish(&device
->dynamic_state_pool
);
1125 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
1127 anv_bo_pool_finish(&device
->batch_bo_pool
);
1129 pthread_cond_destroy(&device
->queue_submit
);
1130 pthread_mutex_destroy(&device
->mutex
);
1132 anv_gem_destroy_context(device
, device
->context_id
);
1136 vk_free(&device
->alloc
, device
);
1139 VkResult
anv_EnumerateInstanceExtensionProperties(
1140 const char* pLayerName
,
1141 uint32_t* pPropertyCount
,
1142 VkExtensionProperties
* pProperties
)
1144 if (pProperties
== NULL
) {
1145 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1149 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1150 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1152 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1153 return VK_INCOMPLETE
;
1158 VkResult
anv_EnumerateDeviceExtensionProperties(
1159 VkPhysicalDevice physicalDevice
,
1160 const char* pLayerName
,
1161 uint32_t* pPropertyCount
,
1162 VkExtensionProperties
* pProperties
)
1164 if (pProperties
== NULL
) {
1165 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1169 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1170 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1172 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1173 return VK_INCOMPLETE
;
1178 VkResult
anv_EnumerateInstanceLayerProperties(
1179 uint32_t* pPropertyCount
,
1180 VkLayerProperties
* pProperties
)
1182 if (pProperties
== NULL
) {
1183 *pPropertyCount
= 0;
1187 /* None supported at this time */
1188 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1191 VkResult
anv_EnumerateDeviceLayerProperties(
1192 VkPhysicalDevice physicalDevice
,
1193 uint32_t* pPropertyCount
,
1194 VkLayerProperties
* pProperties
)
1196 if (pProperties
== NULL
) {
1197 *pPropertyCount
= 0;
1201 /* None supported at this time */
1202 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1205 void anv_GetDeviceQueue(
1207 uint32_t queueNodeIndex
,
1208 uint32_t queueIndex
,
1211 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1213 assert(queueIndex
== 0);
1215 *pQueue
= anv_queue_to_handle(&device
->queue
);
1219 anv_device_execbuf(struct anv_device
*device
,
1220 struct drm_i915_gem_execbuffer2
*execbuf
,
1221 struct anv_bo
**execbuf_bos
)
1223 int ret
= anv_gem_execbuffer(device
, execbuf
);
1225 /* We don't know the real error. */
1226 return vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
1229 struct drm_i915_gem_exec_object2
*objects
=
1230 (void *)(uintptr_t)execbuf
->buffers_ptr
;
1231 for (uint32_t k
= 0; k
< execbuf
->buffer_count
; k
++)
1232 execbuf_bos
[k
]->offset
= objects
[k
].offset
;
1237 VkResult
anv_QueueSubmit(
1239 uint32_t submitCount
,
1240 const VkSubmitInfo
* pSubmits
,
1243 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1244 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1245 struct anv_device
*device
= queue
->device
;
1246 VkResult result
= VK_SUCCESS
;
1248 /* We lock around QueueSubmit for three main reasons:
1250 * 1) When a block pool is resized, we create a new gem handle with a
1251 * different size and, in the case of surface states, possibly a
1252 * different center offset but we re-use the same anv_bo struct when
1253 * we do so. If this happens in the middle of setting up an execbuf,
1254 * we could end up with our list of BOs out of sync with our list of
1257 * 2) The algorithm we use for building the list of unique buffers isn't
1258 * thread-safe. While the client is supposed to syncronize around
1259 * QueueSubmit, this would be extremely difficult to debug if it ever
1260 * came up in the wild due to a broken app. It's better to play it
1261 * safe and just lock around QueueSubmit.
1263 * 3) The anv_cmd_buffer_execbuf function may perform relocations in
1264 * userspace. Due to the fact that the surface state buffer is shared
1265 * between batches, we can't afford to have that happen from multiple
1266 * threads at the same time. Even though the user is supposed to
1267 * ensure this doesn't happen, we play it safe as in (2) above.
1269 * Since the only other things that ever take the device lock such as block
1270 * pool resize only rarely happen, this will almost never be contended so
1271 * taking a lock isn't really an expensive operation in this case.
1273 pthread_mutex_lock(&device
->mutex
);
1275 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1276 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1277 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
1278 pSubmits
[i
].pCommandBuffers
[j
]);
1279 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1281 result
= anv_cmd_buffer_execbuf(device
, cmd_buffer
);
1282 if (result
!= VK_SUCCESS
)
1288 struct anv_bo
*fence_bo
= &fence
->bo
;
1289 result
= anv_device_execbuf(device
, &fence
->execbuf
, &fence_bo
);
1290 if (result
!= VK_SUCCESS
)
1293 /* Update the fence and wake up any waiters */
1294 assert(fence
->state
== ANV_FENCE_STATE_RESET
);
1295 fence
->state
= ANV_FENCE_STATE_SUBMITTED
;
1296 pthread_cond_broadcast(&device
->queue_submit
);
1300 pthread_mutex_unlock(&device
->mutex
);
1305 VkResult
anv_QueueWaitIdle(
1308 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1310 return anv_DeviceWaitIdle(anv_device_to_handle(queue
->device
));
1313 VkResult
anv_DeviceWaitIdle(
1316 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1317 struct anv_batch batch
;
1320 batch
.start
= batch
.next
= cmds
;
1321 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1323 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1324 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1326 return anv_device_submit_simple_batch(device
, &batch
);
1330 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1332 uint32_t gem_handle
= anv_gem_create(device
, size
);
1334 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1336 anv_bo_init(bo
, gem_handle
, size
);
1341 VkResult
anv_AllocateMemory(
1343 const VkMemoryAllocateInfo
* pAllocateInfo
,
1344 const VkAllocationCallbacks
* pAllocator
,
1345 VkDeviceMemory
* pMem
)
1347 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1348 struct anv_device_memory
*mem
;
1351 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1353 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1354 assert(pAllocateInfo
->allocationSize
> 0);
1356 /* We support exactly one memory heap. */
1357 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1358 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1360 /* FINISHME: Fail if allocation request exceeds heap size. */
1362 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1363 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1365 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1367 /* The kernel is going to give us whole pages anyway */
1368 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1370 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1371 if (result
!= VK_SUCCESS
)
1374 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1379 *pMem
= anv_device_memory_to_handle(mem
);
1384 vk_free2(&device
->alloc
, pAllocator
, mem
);
1389 void anv_FreeMemory(
1391 VkDeviceMemory _mem
,
1392 const VkAllocationCallbacks
* pAllocator
)
1394 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1395 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1401 anv_UnmapMemory(_device
, _mem
);
1404 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1406 if (mem
->bo
.gem_handle
!= 0)
1407 anv_gem_close(device
, mem
->bo
.gem_handle
);
1409 vk_free2(&device
->alloc
, pAllocator
, mem
);
1412 VkResult
anv_MapMemory(
1414 VkDeviceMemory _memory
,
1415 VkDeviceSize offset
,
1417 VkMemoryMapFlags flags
,
1420 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1421 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1428 if (size
== VK_WHOLE_SIZE
)
1429 size
= mem
->bo
.size
- offset
;
1431 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1433 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1434 * assert(size != 0);
1435 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1436 * equal to the size of the memory minus offset
1439 assert(offset
+ size
<= mem
->bo
.size
);
1441 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1442 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1443 * at a time is valid. We could just mmap up front and return an offset
1444 * pointer here, but that may exhaust virtual memory on 32 bit
1447 uint32_t gem_flags
= 0;
1448 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1449 gem_flags
|= I915_MMAP_WC
;
1451 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1452 uint64_t map_offset
= offset
& ~4095ull;
1453 assert(offset
>= map_offset
);
1454 uint64_t map_size
= (offset
+ size
) - map_offset
;
1456 /* Let's map whole pages */
1457 map_size
= align_u64(map_size
, 4096);
1459 void *map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1460 map_offset
, map_size
, gem_flags
);
1461 if (map
== MAP_FAILED
)
1462 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1465 mem
->map_size
= map_size
;
1467 *ppData
= mem
->map
+ (offset
- map_offset
);
1472 void anv_UnmapMemory(
1474 VkDeviceMemory _memory
)
1476 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1481 anv_gem_munmap(mem
->map
, mem
->map_size
);
1488 clflush_mapped_ranges(struct anv_device
*device
,
1490 const VkMappedMemoryRange
*ranges
)
1492 for (uint32_t i
= 0; i
< count
; i
++) {
1493 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1494 if (ranges
[i
].offset
>= mem
->map_size
)
1497 anv_clflush_range(mem
->map
+ ranges
[i
].offset
,
1498 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1502 VkResult
anv_FlushMappedMemoryRanges(
1504 uint32_t memoryRangeCount
,
1505 const VkMappedMemoryRange
* pMemoryRanges
)
1507 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1509 if (device
->info
.has_llc
)
1512 /* Make sure the writes we're flushing have landed. */
1513 __builtin_ia32_mfence();
1515 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1520 VkResult
anv_InvalidateMappedMemoryRanges(
1522 uint32_t memoryRangeCount
,
1523 const VkMappedMemoryRange
* pMemoryRanges
)
1525 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1527 if (device
->info
.has_llc
)
1530 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1532 /* Make sure no reads get moved up above the invalidate. */
1533 __builtin_ia32_mfence();
1538 void anv_GetBufferMemoryRequirements(
1541 VkMemoryRequirements
* pMemoryRequirements
)
1543 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1544 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1546 /* The Vulkan spec (git aaed022) says:
1548 * memoryTypeBits is a bitfield and contains one bit set for every
1549 * supported memory type for the resource. The bit `1<<i` is set if and
1550 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1551 * structure for the physical device is supported.
1553 * We support exactly one memory type on LLC, two on non-LLC.
1555 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1557 pMemoryRequirements
->size
= buffer
->size
;
1558 pMemoryRequirements
->alignment
= 16;
1561 void anv_GetImageMemoryRequirements(
1564 VkMemoryRequirements
* pMemoryRequirements
)
1566 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1567 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1569 /* The Vulkan spec (git aaed022) says:
1571 * memoryTypeBits is a bitfield and contains one bit set for every
1572 * supported memory type for the resource. The bit `1<<i` is set if and
1573 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1574 * structure for the physical device is supported.
1576 * We support exactly one memory type on LLC, two on non-LLC.
1578 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1580 pMemoryRequirements
->size
= image
->size
;
1581 pMemoryRequirements
->alignment
= image
->alignment
;
1584 void anv_GetImageSparseMemoryRequirements(
1587 uint32_t* pSparseMemoryRequirementCount
,
1588 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1593 void anv_GetDeviceMemoryCommitment(
1595 VkDeviceMemory memory
,
1596 VkDeviceSize
* pCommittedMemoryInBytes
)
1598 *pCommittedMemoryInBytes
= 0;
1601 VkResult
anv_BindBufferMemory(
1604 VkDeviceMemory _memory
,
1605 VkDeviceSize memoryOffset
)
1607 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1608 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1611 buffer
->bo
= &mem
->bo
;
1612 buffer
->offset
= memoryOffset
;
1621 VkResult
anv_QueueBindSparse(
1623 uint32_t bindInfoCount
,
1624 const VkBindSparseInfo
* pBindInfo
,
1627 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1630 VkResult
anv_CreateFence(
1632 const VkFenceCreateInfo
* pCreateInfo
,
1633 const VkAllocationCallbacks
* pAllocator
,
1636 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1637 struct anv_bo fence_bo
;
1638 struct anv_fence
*fence
;
1639 struct anv_batch batch
;
1642 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1644 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &fence_bo
, 4096);
1645 if (result
!= VK_SUCCESS
)
1648 /* Fences are small. Just store the CPU data structure in the BO. */
1649 fence
= fence_bo
.map
;
1650 fence
->bo
= fence_bo
;
1652 /* Place the batch after the CPU data but on its own cache line. */
1653 const uint32_t batch_offset
= align_u32(sizeof(*fence
), CACHELINE_SIZE
);
1654 batch
.next
= batch
.start
= fence
->bo
.map
+ batch_offset
;
1655 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1656 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1657 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1659 if (!device
->info
.has_llc
) {
1660 assert(((uintptr_t) batch
.start
& CACHELINE_MASK
) == 0);
1661 assert(batch
.next
- batch
.start
<= CACHELINE_SIZE
);
1662 __builtin_ia32_mfence();
1663 __builtin_ia32_clflush(batch
.start
);
1666 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1667 fence
->exec2_objects
[0].relocation_count
= 0;
1668 fence
->exec2_objects
[0].relocs_ptr
= 0;
1669 fence
->exec2_objects
[0].alignment
= 0;
1670 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1671 fence
->exec2_objects
[0].flags
= 0;
1672 fence
->exec2_objects
[0].rsvd1
= 0;
1673 fence
->exec2_objects
[0].rsvd2
= 0;
1675 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1676 fence
->execbuf
.buffer_count
= 1;
1677 fence
->execbuf
.batch_start_offset
= batch
.start
- fence
->bo
.map
;
1678 fence
->execbuf
.batch_len
= batch
.next
- batch
.start
;
1679 fence
->execbuf
.cliprects_ptr
= 0;
1680 fence
->execbuf
.num_cliprects
= 0;
1681 fence
->execbuf
.DR1
= 0;
1682 fence
->execbuf
.DR4
= 0;
1684 fence
->execbuf
.flags
=
1685 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1686 fence
->execbuf
.rsvd1
= device
->context_id
;
1687 fence
->execbuf
.rsvd2
= 0;
1689 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
1690 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1692 fence
->state
= ANV_FENCE_STATE_RESET
;
1695 *pFence
= anv_fence_to_handle(fence
);
1700 void anv_DestroyFence(
1703 const VkAllocationCallbacks
* pAllocator
)
1705 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1706 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1711 assert(fence
->bo
.map
== fence
);
1712 anv_bo_pool_free(&device
->batch_bo_pool
, &fence
->bo
);
1715 VkResult
anv_ResetFences(
1717 uint32_t fenceCount
,
1718 const VkFence
* pFences
)
1720 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1721 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1722 fence
->state
= ANV_FENCE_STATE_RESET
;
1728 VkResult
anv_GetFenceStatus(
1732 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1733 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1737 switch (fence
->state
) {
1738 case ANV_FENCE_STATE_RESET
:
1739 /* If it hasn't even been sent off to the GPU yet, it's not ready */
1740 return VK_NOT_READY
;
1742 case ANV_FENCE_STATE_SIGNALED
:
1743 /* It's been signaled, return success */
1746 case ANV_FENCE_STATE_SUBMITTED
:
1747 /* It's been submitted to the GPU but we don't know if it's done yet. */
1748 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1750 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1753 return VK_NOT_READY
;
1756 unreachable("Invalid fence status");
1760 #define NSEC_PER_SEC 1000000000
1761 #define INT_TYPE_MAX(type) ((1ull << (sizeof(type) * 8 - 1)) - 1)
1763 VkResult
anv_WaitForFences(
1765 uint32_t fenceCount
,
1766 const VkFence
* pFences
,
1770 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1773 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1774 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1775 * for a couple of kernel releases. Since there's no way to know
1776 * whether or not the kernel we're using is one of the broken ones, the
1777 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1778 * maximum timeout from 584 years to 292 years - likely not a big deal.
1780 int64_t timeout
= MIN2(_timeout
, INT64_MAX
);
1782 uint32_t pending_fences
= fenceCount
;
1783 while (pending_fences
) {
1785 bool signaled_fences
= false;
1786 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1787 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1788 switch (fence
->state
) {
1789 case ANV_FENCE_STATE_RESET
:
1790 /* This fence hasn't been submitted yet, we'll catch it the next
1791 * time around. Yes, this may mean we dead-loop but, short of
1792 * lots of locking and a condition variable, there's not much that
1793 * we can do about that.
1798 case ANV_FENCE_STATE_SIGNALED
:
1799 /* This fence is not pending. If waitAll isn't set, we can return
1800 * early. Otherwise, we have to keep going.
1806 case ANV_FENCE_STATE_SUBMITTED
:
1807 /* These are the fences we really care about. Go ahead and wait
1808 * on it until we hit a timeout.
1810 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &timeout
);
1811 if (ret
== -1 && errno
== ETIME
) {
1813 } else if (ret
== -1) {
1814 /* We don't know the real error. */
1815 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1817 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1818 signaled_fences
= true;
1826 if (pending_fences
&& !signaled_fences
) {
1827 /* If we've hit this then someone decided to vkWaitForFences before
1828 * they've actually submitted any of them to a queue. This is a
1829 * fairly pessimal case, so it's ok to lock here and use a standard
1830 * pthreads condition variable.
1832 pthread_mutex_lock(&device
->mutex
);
1834 /* It's possible that some of the fences have changed state since the
1835 * last time we checked. Now that we have the lock, check for
1836 * pending fences again and don't wait if it's changed.
1838 uint32_t now_pending_fences
= 0;
1839 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1840 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1841 if (fence
->state
== ANV_FENCE_STATE_RESET
)
1842 now_pending_fences
++;
1844 assert(now_pending_fences
<= pending_fences
);
1846 if (now_pending_fences
== pending_fences
) {
1847 struct timespec before
;
1848 clock_gettime(CLOCK_MONOTONIC
, &before
);
1850 uint32_t abs_nsec
= before
.tv_nsec
+ timeout
% NSEC_PER_SEC
;
1851 uint64_t abs_sec
= before
.tv_sec
+ (abs_nsec
/ NSEC_PER_SEC
) +
1852 (timeout
/ NSEC_PER_SEC
);
1853 abs_nsec
%= NSEC_PER_SEC
;
1855 /* Avoid roll-over in tv_sec on 32-bit systems if the user
1856 * provided timeout is UINT64_MAX
1858 struct timespec abstime
;
1859 abstime
.tv_nsec
= abs_nsec
;
1860 abstime
.tv_sec
= MIN2(abs_sec
, INT_TYPE_MAX(abstime
.tv_sec
));
1862 ret
= pthread_cond_timedwait(&device
->queue_submit
,
1863 &device
->mutex
, &abstime
);
1864 assert(ret
!= EINVAL
);
1866 struct timespec after
;
1867 clock_gettime(CLOCK_MONOTONIC
, &after
);
1868 uint64_t time_elapsed
=
1869 ((uint64_t)after
.tv_sec
* NSEC_PER_SEC
+ after
.tv_nsec
) -
1870 ((uint64_t)before
.tv_sec
* NSEC_PER_SEC
+ before
.tv_nsec
);
1872 if (time_elapsed
>= timeout
) {
1873 pthread_mutex_unlock(&device
->mutex
);
1877 timeout
-= time_elapsed
;
1880 pthread_mutex_unlock(&device
->mutex
);
1887 // Queue semaphore functions
1889 VkResult
anv_CreateSemaphore(
1891 const VkSemaphoreCreateInfo
* pCreateInfo
,
1892 const VkAllocationCallbacks
* pAllocator
,
1893 VkSemaphore
* pSemaphore
)
1895 /* The DRM execbuffer ioctl always execute in-oder, even between different
1896 * rings. As such, there's nothing to do for the user space semaphore.
1899 *pSemaphore
= (VkSemaphore
)1;
1904 void anv_DestroySemaphore(
1906 VkSemaphore semaphore
,
1907 const VkAllocationCallbacks
* pAllocator
)
1913 VkResult
anv_CreateEvent(
1915 const VkEventCreateInfo
* pCreateInfo
,
1916 const VkAllocationCallbacks
* pAllocator
,
1919 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1920 struct anv_state state
;
1921 struct anv_event
*event
;
1923 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1925 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1928 event
->state
= state
;
1929 event
->semaphore
= VK_EVENT_RESET
;
1931 if (!device
->info
.has_llc
) {
1932 /* Make sure the writes we're flushing have landed. */
1933 __builtin_ia32_mfence();
1934 __builtin_ia32_clflush(event
);
1937 *pEvent
= anv_event_to_handle(event
);
1942 void anv_DestroyEvent(
1945 const VkAllocationCallbacks
* pAllocator
)
1947 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1948 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1953 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1956 VkResult
anv_GetEventStatus(
1960 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1961 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1963 if (!device
->info
.has_llc
) {
1964 /* Invalidate read cache before reading event written by GPU. */
1965 __builtin_ia32_clflush(event
);
1966 __builtin_ia32_mfence();
1970 return event
->semaphore
;
1973 VkResult
anv_SetEvent(
1977 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1978 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1980 event
->semaphore
= VK_EVENT_SET
;
1982 if (!device
->info
.has_llc
) {
1983 /* Make sure the writes we're flushing have landed. */
1984 __builtin_ia32_mfence();
1985 __builtin_ia32_clflush(event
);
1991 VkResult
anv_ResetEvent(
1995 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1996 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1998 event
->semaphore
= VK_EVENT_RESET
;
2000 if (!device
->info
.has_llc
) {
2001 /* Make sure the writes we're flushing have landed. */
2002 __builtin_ia32_mfence();
2003 __builtin_ia32_clflush(event
);
2011 VkResult
anv_CreateBuffer(
2013 const VkBufferCreateInfo
* pCreateInfo
,
2014 const VkAllocationCallbacks
* pAllocator
,
2017 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2018 struct anv_buffer
*buffer
;
2020 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2022 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2023 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2025 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2027 buffer
->size
= pCreateInfo
->size
;
2028 buffer
->usage
= pCreateInfo
->usage
;
2032 *pBuffer
= anv_buffer_to_handle(buffer
);
2037 void anv_DestroyBuffer(
2040 const VkAllocationCallbacks
* pAllocator
)
2042 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2043 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2048 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2052 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2053 enum isl_format format
,
2054 uint32_t offset
, uint32_t range
, uint32_t stride
)
2056 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2058 .mocs
= device
->default_mocs
,
2063 anv_state_flush(device
, state
);
2066 void anv_DestroySampler(
2069 const VkAllocationCallbacks
* pAllocator
)
2071 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2072 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2077 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2080 VkResult
anv_CreateFramebuffer(
2082 const VkFramebufferCreateInfo
* pCreateInfo
,
2083 const VkAllocationCallbacks
* pAllocator
,
2084 VkFramebuffer
* pFramebuffer
)
2086 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2087 struct anv_framebuffer
*framebuffer
;
2089 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2091 size_t size
= sizeof(*framebuffer
) +
2092 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2093 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2094 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2095 if (framebuffer
== NULL
)
2096 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2098 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2099 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2100 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2101 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2104 framebuffer
->width
= pCreateInfo
->width
;
2105 framebuffer
->height
= pCreateInfo
->height
;
2106 framebuffer
->layers
= pCreateInfo
->layers
;
2108 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2113 void anv_DestroyFramebuffer(
2116 const VkAllocationCallbacks
* pAllocator
)
2118 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2119 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2124 vk_free2(&device
->alloc
, pAllocator
, fb
);
2127 /* vk_icd.h does not declare this function, so we declare it here to
2128 * suppress Wmissing-prototypes.
2130 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2131 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2133 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2134 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2136 /* For the full details on loader interface versioning, see
2137 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2138 * What follows is a condensed summary, to help you navigate the large and
2139 * confusing official doc.
2141 * - Loader interface v0 is incompatible with later versions. We don't
2144 * - In loader interface v1:
2145 * - The first ICD entrypoint called by the loader is
2146 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2148 * - The ICD must statically expose no other Vulkan symbol unless it is
2149 * linked with -Bsymbolic.
2150 * - Each dispatchable Vulkan handle created by the ICD must be
2151 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2152 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2153 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2154 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2155 * such loader-managed surfaces.
2157 * - Loader interface v2 differs from v1 in:
2158 * - The first ICD entrypoint called by the loader is
2159 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2160 * statically expose this entrypoint.
2162 * - Loader interface v3 differs from v2 in:
2163 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2164 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2165 * because the loader no longer does so.
2167 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);