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 build_id_read(note
, uuid
, 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
);
363 if (instance
->physicalDeviceCount
> 0) {
364 /* We support at most one physical device. */
365 assert(instance
->physicalDeviceCount
== 1);
366 anv_physical_device_finish(&instance
->physicalDevice
);
369 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
373 vk_free(&instance
->alloc
, instance
);
376 VkResult
anv_EnumeratePhysicalDevices(
377 VkInstance _instance
,
378 uint32_t* pPhysicalDeviceCount
,
379 VkPhysicalDevice
* pPhysicalDevices
)
381 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
384 if (instance
->physicalDeviceCount
< 0) {
386 for (unsigned i
= 0; i
< 8; i
++) {
387 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
388 result
= anv_physical_device_init(&instance
->physicalDevice
,
390 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
394 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
395 instance
->physicalDeviceCount
= 0;
396 } else if (result
== VK_SUCCESS
) {
397 instance
->physicalDeviceCount
= 1;
403 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
404 * otherwise it's an inout parameter.
406 * The Vulkan spec (git aaed022) says:
408 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
409 * that is initialized with the number of devices the application is
410 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
411 * an array of at least this many VkPhysicalDevice handles [...].
413 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
414 * overwrites the contents of the variable pointed to by
415 * pPhysicalDeviceCount with the number of physical devices in in the
416 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
417 * pPhysicalDeviceCount with the number of physical handles written to
420 if (!pPhysicalDevices
) {
421 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
422 } else if (*pPhysicalDeviceCount
>= 1) {
423 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
424 *pPhysicalDeviceCount
= 1;
425 } else if (*pPhysicalDeviceCount
< instance
->physicalDeviceCount
) {
426 return VK_INCOMPLETE
;
428 *pPhysicalDeviceCount
= 0;
434 void anv_GetPhysicalDeviceFeatures(
435 VkPhysicalDevice physicalDevice
,
436 VkPhysicalDeviceFeatures
* pFeatures
)
438 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
440 *pFeatures
= (VkPhysicalDeviceFeatures
) {
441 .robustBufferAccess
= true,
442 .fullDrawIndexUint32
= true,
443 .imageCubeArray
= true,
444 .independentBlend
= true,
445 .geometryShader
= true,
446 .tessellationShader
= true,
447 .sampleRateShading
= true,
448 .dualSrcBlend
= true,
450 .multiDrawIndirect
= false,
451 .drawIndirectFirstInstance
= true,
453 .depthBiasClamp
= true,
454 .fillModeNonSolid
= true,
455 .depthBounds
= false,
459 .multiViewport
= true,
460 .samplerAnisotropy
= true,
461 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
462 pdevice
->info
.is_baytrail
,
463 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
464 .textureCompressionBC
= true,
465 .occlusionQueryPrecise
= true,
466 .pipelineStatisticsQuery
= false,
467 .fragmentStoresAndAtomics
= true,
468 .shaderTessellationAndGeometryPointSize
= true,
469 .shaderImageGatherExtended
= true,
470 .shaderStorageImageExtendedFormats
= true,
471 .shaderStorageImageMultisample
= false,
472 .shaderStorageImageReadWithoutFormat
= false,
473 .shaderStorageImageWriteWithoutFormat
= true,
474 .shaderUniformBufferArrayDynamicIndexing
= true,
475 .shaderSampledImageArrayDynamicIndexing
= true,
476 .shaderStorageBufferArrayDynamicIndexing
= true,
477 .shaderStorageImageArrayDynamicIndexing
= true,
478 .shaderClipDistance
= true,
479 .shaderCullDistance
= true,
480 .shaderFloat64
= pdevice
->info
.gen
>= 8,
481 .shaderInt64
= false,
482 .shaderInt16
= false,
483 .shaderResourceMinLod
= false,
484 .variableMultisampleRate
= false,
485 .inheritedQueries
= false,
488 /* We can't do image stores in vec4 shaders */
489 pFeatures
->vertexPipelineStoresAndAtomics
=
490 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
491 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
494 void anv_GetPhysicalDeviceFeatures2KHR(
495 VkPhysicalDevice physicalDevice
,
496 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
498 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
500 vk_foreach_struct(ext
, pFeatures
->pNext
) {
501 switch (ext
->sType
) {
503 anv_debug_ignored_stype(ext
->sType
);
509 void anv_GetPhysicalDeviceProperties(
510 VkPhysicalDevice physicalDevice
,
511 VkPhysicalDeviceProperties
* pProperties
)
513 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
514 const struct gen_device_info
*devinfo
= &pdevice
->info
;
516 const float time_stamp_base
= devinfo
->gen
>= 9 ? 83.333 : 80.0;
518 /* See assertions made when programming the buffer surface state. */
519 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
520 (1ul << 30) : (1ul << 27);
522 VkSampleCountFlags sample_counts
=
523 isl_device_get_sample_counts(&pdevice
->isl_dev
);
525 VkPhysicalDeviceLimits limits
= {
526 .maxImageDimension1D
= (1 << 14),
527 .maxImageDimension2D
= (1 << 14),
528 .maxImageDimension3D
= (1 << 11),
529 .maxImageDimensionCube
= (1 << 14),
530 .maxImageArrayLayers
= (1 << 11),
531 .maxTexelBufferElements
= 128 * 1024 * 1024,
532 .maxUniformBufferRange
= (1ul << 27),
533 .maxStorageBufferRange
= max_raw_buffer_sz
,
534 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
535 .maxMemoryAllocationCount
= UINT32_MAX
,
536 .maxSamplerAllocationCount
= 64 * 1024,
537 .bufferImageGranularity
= 64, /* A cache line */
538 .sparseAddressSpaceSize
= 0,
539 .maxBoundDescriptorSets
= MAX_SETS
,
540 .maxPerStageDescriptorSamplers
= 64,
541 .maxPerStageDescriptorUniformBuffers
= 64,
542 .maxPerStageDescriptorStorageBuffers
= 64,
543 .maxPerStageDescriptorSampledImages
= 64,
544 .maxPerStageDescriptorStorageImages
= 64,
545 .maxPerStageDescriptorInputAttachments
= 64,
546 .maxPerStageResources
= 128,
547 .maxDescriptorSetSamplers
= 256,
548 .maxDescriptorSetUniformBuffers
= 256,
549 .maxDescriptorSetUniformBuffersDynamic
= 256,
550 .maxDescriptorSetStorageBuffers
= 256,
551 .maxDescriptorSetStorageBuffersDynamic
= 256,
552 .maxDescriptorSetSampledImages
= 256,
553 .maxDescriptorSetStorageImages
= 256,
554 .maxDescriptorSetInputAttachments
= 256,
555 .maxVertexInputAttributes
= MAX_VBS
,
556 .maxVertexInputBindings
= MAX_VBS
,
557 .maxVertexInputAttributeOffset
= 2047,
558 .maxVertexInputBindingStride
= 2048,
559 .maxVertexOutputComponents
= 128,
560 .maxTessellationGenerationLevel
= 64,
561 .maxTessellationPatchSize
= 32,
562 .maxTessellationControlPerVertexInputComponents
= 128,
563 .maxTessellationControlPerVertexOutputComponents
= 128,
564 .maxTessellationControlPerPatchOutputComponents
= 128,
565 .maxTessellationControlTotalOutputComponents
= 2048,
566 .maxTessellationEvaluationInputComponents
= 128,
567 .maxTessellationEvaluationOutputComponents
= 128,
568 .maxGeometryShaderInvocations
= 32,
569 .maxGeometryInputComponents
= 64,
570 .maxGeometryOutputComponents
= 128,
571 .maxGeometryOutputVertices
= 256,
572 .maxGeometryTotalOutputComponents
= 1024,
573 .maxFragmentInputComponents
= 128,
574 .maxFragmentOutputAttachments
= 8,
575 .maxFragmentDualSrcAttachments
= 1,
576 .maxFragmentCombinedOutputResources
= 8,
577 .maxComputeSharedMemorySize
= 32768,
578 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
579 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
580 .maxComputeWorkGroupSize
= {
581 16 * devinfo
->max_cs_threads
,
582 16 * devinfo
->max_cs_threads
,
583 16 * devinfo
->max_cs_threads
,
585 .subPixelPrecisionBits
= 4 /* FIXME */,
586 .subTexelPrecisionBits
= 4 /* FIXME */,
587 .mipmapPrecisionBits
= 4 /* FIXME */,
588 .maxDrawIndexedIndexValue
= UINT32_MAX
,
589 .maxDrawIndirectCount
= UINT32_MAX
,
590 .maxSamplerLodBias
= 16,
591 .maxSamplerAnisotropy
= 16,
592 .maxViewports
= MAX_VIEWPORTS
,
593 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
594 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
595 .viewportSubPixelBits
= 13, /* We take a float? */
596 .minMemoryMapAlignment
= 4096, /* A page */
597 .minTexelBufferOffsetAlignment
= 1,
598 .minUniformBufferOffsetAlignment
= 16,
599 .minStorageBufferOffsetAlignment
= 4,
600 .minTexelOffset
= -8,
602 .minTexelGatherOffset
= -32,
603 .maxTexelGatherOffset
= 31,
604 .minInterpolationOffset
= -0.5,
605 .maxInterpolationOffset
= 0.4375,
606 .subPixelInterpolationOffsetBits
= 4,
607 .maxFramebufferWidth
= (1 << 14),
608 .maxFramebufferHeight
= (1 << 14),
609 .maxFramebufferLayers
= (1 << 11),
610 .framebufferColorSampleCounts
= sample_counts
,
611 .framebufferDepthSampleCounts
= sample_counts
,
612 .framebufferStencilSampleCounts
= sample_counts
,
613 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
614 .maxColorAttachments
= MAX_RTS
,
615 .sampledImageColorSampleCounts
= sample_counts
,
616 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
617 .sampledImageDepthSampleCounts
= sample_counts
,
618 .sampledImageStencilSampleCounts
= sample_counts
,
619 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
620 .maxSampleMaskWords
= 1,
621 .timestampComputeAndGraphics
= false,
622 .timestampPeriod
= time_stamp_base
,
623 .maxClipDistances
= 8,
624 .maxCullDistances
= 8,
625 .maxCombinedClipAndCullDistances
= 8,
626 .discreteQueuePriorities
= 1,
627 .pointSizeRange
= { 0.125, 255.875 },
628 .lineWidthRange
= { 0.0, 7.9921875 },
629 .pointSizeGranularity
= (1.0 / 8.0),
630 .lineWidthGranularity
= (1.0 / 128.0),
631 .strictLines
= false, /* FINISHME */
632 .standardSampleLocations
= true,
633 .optimalBufferCopyOffsetAlignment
= 128,
634 .optimalBufferCopyRowPitchAlignment
= 128,
635 .nonCoherentAtomSize
= 64,
638 *pProperties
= (VkPhysicalDeviceProperties
) {
639 .apiVersion
= VK_MAKE_VERSION(1, 0, 39),
642 .deviceID
= pdevice
->chipset_id
,
643 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
645 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
648 strcpy(pProperties
->deviceName
, pdevice
->name
);
649 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
652 void anv_GetPhysicalDeviceProperties2KHR(
653 VkPhysicalDevice physicalDevice
,
654 VkPhysicalDeviceProperties2KHR
* pProperties
)
656 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
658 vk_foreach_struct(ext
, pProperties
->pNext
) {
659 switch (ext
->sType
) {
661 anv_debug_ignored_stype(ext
->sType
);
668 anv_get_queue_family_properties(struct anv_physical_device
*phys_dev
,
669 VkQueueFamilyProperties
*props
)
671 *props
= (VkQueueFamilyProperties
) {
672 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
673 VK_QUEUE_COMPUTE_BIT
|
674 VK_QUEUE_TRANSFER_BIT
,
676 .timestampValidBits
= 36, /* XXX: Real value here */
677 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
681 void anv_GetPhysicalDeviceQueueFamilyProperties(
682 VkPhysicalDevice physicalDevice
,
684 VkQueueFamilyProperties
* pQueueFamilyProperties
)
686 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
688 if (pQueueFamilyProperties
== NULL
) {
693 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
694 * 1.0.38 spec, Section 4.1 Physical Devices:
696 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
703 anv_get_queue_family_properties(phys_dev
, pQueueFamilyProperties
);
706 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
707 VkPhysicalDevice physicalDevice
,
708 uint32_t* pQueueFamilyPropertyCount
,
709 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
712 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
714 if (pQueueFamilyProperties
== NULL
) {
715 *pQueueFamilyPropertyCount
= 1;
719 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
720 * 1.0.38 spec, Section 4.1 Physical Devices:
722 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
725 if (*pQueueFamilyPropertyCount
== 0)
728 /* We support exactly one queue family. So need to traverse only the first
729 * array element's pNext chain.
731 *pQueueFamilyPropertyCount
= 1;
732 anv_get_queue_family_properties(phys_dev
,
733 &pQueueFamilyProperties
->queueFamilyProperties
);
735 vk_foreach_struct(ext
, pQueueFamilyProperties
->pNext
) {
736 switch (ext
->sType
) {
738 anv_debug_ignored_stype(ext
->sType
);
744 void anv_GetPhysicalDeviceMemoryProperties(
745 VkPhysicalDevice physicalDevice
,
746 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
748 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
749 VkDeviceSize heap_size
;
751 /* Reserve some wiggle room for the driver by exposing only 75% of the
752 * aperture to the heap.
754 heap_size
= 3 * physical_device
->aperture_size
/ 4;
756 if (physical_device
->info
.has_llc
) {
757 /* Big core GPUs share LLC with the CPU and thus one memory type can be
758 * both cached and coherent at the same time.
760 pMemoryProperties
->memoryTypeCount
= 1;
761 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
762 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
763 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
764 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
765 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
769 /* The spec requires that we expose a host-visible, coherent memory
770 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
771 * to give the application a choice between cached, but not coherent and
772 * coherent but uncached (WC though).
774 pMemoryProperties
->memoryTypeCount
= 2;
775 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
776 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
777 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
778 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
781 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
782 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
783 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
784 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
789 pMemoryProperties
->memoryHeapCount
= 1;
790 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
792 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
796 void anv_GetPhysicalDeviceMemoryProperties2KHR(
797 VkPhysicalDevice physicalDevice
,
798 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
800 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
801 &pMemoryProperties
->memoryProperties
);
803 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
804 switch (ext
->sType
) {
806 anv_debug_ignored_stype(ext
->sType
);
812 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
816 return anv_lookup_entrypoint(NULL
, pName
);
819 /* With version 1+ of the loader interface the ICD should expose
820 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
823 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
828 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
832 return anv_GetInstanceProcAddr(instance
, pName
);
835 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
839 ANV_FROM_HANDLE(anv_device
, device
, _device
);
840 return anv_lookup_entrypoint(&device
->info
, pName
);
844 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
846 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
847 queue
->device
= device
;
848 queue
->pool
= &device
->surface_state_pool
;
852 anv_queue_finish(struct anv_queue
*queue
)
856 static struct anv_state
857 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
859 struct anv_state state
;
861 state
= anv_state_pool_alloc(pool
, size
, align
);
862 memcpy(state
.map
, p
, size
);
864 anv_state_flush(pool
->block_pool
->device
, state
);
869 struct gen8_border_color
{
874 /* Pad out to 64 bytes */
879 anv_device_init_border_colors(struct anv_device
*device
)
881 static const struct gen8_border_color border_colors
[] = {
882 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
883 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
884 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
885 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
886 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
887 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
890 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
891 sizeof(border_colors
), 64,
896 anv_device_submit_simple_batch(struct anv_device
*device
,
897 struct anv_batch
*batch
)
899 struct drm_i915_gem_execbuffer2 execbuf
;
900 struct drm_i915_gem_exec_object2 exec2_objects
[1];
901 struct anv_bo bo
, *exec_bos
[1];
902 VkResult result
= VK_SUCCESS
;
907 /* Kernel driver requires 8 byte aligned batch length */
908 size
= align_u32(batch
->next
- batch
->start
, 8);
909 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bo
, size
);
910 if (result
!= VK_SUCCESS
)
913 memcpy(bo
.map
, batch
->start
, size
);
914 if (!device
->info
.has_llc
)
915 anv_flush_range(bo
.map
, size
);
918 exec2_objects
[0].handle
= bo
.gem_handle
;
919 exec2_objects
[0].relocation_count
= 0;
920 exec2_objects
[0].relocs_ptr
= 0;
921 exec2_objects
[0].alignment
= 0;
922 exec2_objects
[0].offset
= bo
.offset
;
923 exec2_objects
[0].flags
= 0;
924 exec2_objects
[0].rsvd1
= 0;
925 exec2_objects
[0].rsvd2
= 0;
927 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
928 execbuf
.buffer_count
= 1;
929 execbuf
.batch_start_offset
= 0;
930 execbuf
.batch_len
= size
;
931 execbuf
.cliprects_ptr
= 0;
932 execbuf
.num_cliprects
= 0;
937 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
938 execbuf
.rsvd1
= device
->context_id
;
941 result
= anv_device_execbuf(device
, &execbuf
, exec_bos
);
942 if (result
!= VK_SUCCESS
)
946 ret
= anv_gem_wait(device
, bo
.gem_handle
, &timeout
);
948 /* We don't know the real error. */
949 result
= vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
954 anv_bo_pool_free(&device
->batch_bo_pool
, &bo
);
959 VkResult
anv_CreateDevice(
960 VkPhysicalDevice physicalDevice
,
961 const VkDeviceCreateInfo
* pCreateInfo
,
962 const VkAllocationCallbacks
* pAllocator
,
965 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
967 struct anv_device
*device
;
969 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
971 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
973 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
974 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
975 device_extensions
[j
].extensionName
) == 0) {
981 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
984 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
986 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
988 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
990 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
991 device
->instance
= physical_device
->instance
;
992 device
->chipset_id
= physical_device
->chipset_id
;
995 device
->alloc
= *pAllocator
;
997 device
->alloc
= physical_device
->instance
->alloc
;
999 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1000 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1001 if (device
->fd
== -1) {
1002 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1006 device
->context_id
= anv_gem_create_context(device
);
1007 if (device
->context_id
== -1) {
1008 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1012 device
->info
= physical_device
->info
;
1013 device
->isl_dev
= physical_device
->isl_dev
;
1015 /* On Broadwell and later, we can use batch chaining to more efficiently
1016 * implement growing command buffers. Prior to Haswell, the kernel
1017 * command parser gets in the way and we have to fall back to growing
1020 device
->can_chain_batches
= device
->info
.gen
>= 8;
1022 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1023 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1025 pthread_mutex_init(&device
->mutex
, NULL
);
1027 pthread_condattr_t condattr
;
1028 pthread_condattr_init(&condattr
);
1029 pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
);
1030 pthread_cond_init(&device
->queue_submit
, NULL
);
1031 pthread_condattr_destroy(&condattr
);
1033 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1035 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 16384);
1037 anv_state_pool_init(&device
->dynamic_state_pool
,
1038 &device
->dynamic_state_block_pool
);
1040 anv_block_pool_init(&device
->instruction_block_pool
, device
, 1024 * 1024);
1041 anv_state_pool_init(&device
->instruction_state_pool
,
1042 &device
->instruction_block_pool
);
1044 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
1046 anv_state_pool_init(&device
->surface_state_pool
,
1047 &device
->surface_state_block_pool
);
1049 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1051 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1053 anv_queue_init(device
, &device
->queue
);
1055 switch (device
->info
.gen
) {
1057 if (!device
->info
.is_haswell
)
1058 result
= gen7_init_device_state(device
);
1060 result
= gen75_init_device_state(device
);
1063 result
= gen8_init_device_state(device
);
1066 result
= gen9_init_device_state(device
);
1069 /* Shouldn't get here as we don't create physical devices for any other
1071 unreachable("unhandled gen");
1073 if (result
!= VK_SUCCESS
)
1076 anv_device_init_blorp(device
);
1078 anv_device_init_border_colors(device
);
1080 *pDevice
= anv_device_to_handle(device
);
1087 vk_free(&device
->alloc
, device
);
1092 void anv_DestroyDevice(
1094 const VkAllocationCallbacks
* pAllocator
)
1096 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1098 anv_device_finish_blorp(device
);
1100 anv_queue_finish(&device
->queue
);
1102 #ifdef HAVE_VALGRIND
1103 /* We only need to free these to prevent valgrind errors. The backing
1104 * BO will go away in a couple of lines so we don't actually leak.
1106 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1109 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1111 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1112 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1114 anv_state_pool_finish(&device
->surface_state_pool
);
1115 anv_block_pool_finish(&device
->surface_state_block_pool
);
1116 anv_state_pool_finish(&device
->instruction_state_pool
);
1117 anv_block_pool_finish(&device
->instruction_block_pool
);
1118 anv_state_pool_finish(&device
->dynamic_state_pool
);
1119 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
1121 anv_bo_pool_finish(&device
->batch_bo_pool
);
1123 pthread_cond_destroy(&device
->queue_submit
);
1124 pthread_mutex_destroy(&device
->mutex
);
1126 anv_gem_destroy_context(device
, device
->context_id
);
1130 vk_free(&device
->alloc
, device
);
1133 VkResult
anv_EnumerateInstanceExtensionProperties(
1134 const char* pLayerName
,
1135 uint32_t* pPropertyCount
,
1136 VkExtensionProperties
* pProperties
)
1138 if (pProperties
== NULL
) {
1139 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1143 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1144 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1146 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1147 return VK_INCOMPLETE
;
1152 VkResult
anv_EnumerateDeviceExtensionProperties(
1153 VkPhysicalDevice physicalDevice
,
1154 const char* pLayerName
,
1155 uint32_t* pPropertyCount
,
1156 VkExtensionProperties
* pProperties
)
1158 if (pProperties
== NULL
) {
1159 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1163 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1164 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1166 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1167 return VK_INCOMPLETE
;
1172 VkResult
anv_EnumerateInstanceLayerProperties(
1173 uint32_t* pPropertyCount
,
1174 VkLayerProperties
* pProperties
)
1176 if (pProperties
== NULL
) {
1177 *pPropertyCount
= 0;
1181 /* None supported at this time */
1182 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1185 VkResult
anv_EnumerateDeviceLayerProperties(
1186 VkPhysicalDevice physicalDevice
,
1187 uint32_t* pPropertyCount
,
1188 VkLayerProperties
* pProperties
)
1190 if (pProperties
== NULL
) {
1191 *pPropertyCount
= 0;
1195 /* None supported at this time */
1196 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1199 void anv_GetDeviceQueue(
1201 uint32_t queueNodeIndex
,
1202 uint32_t queueIndex
,
1205 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1207 assert(queueIndex
== 0);
1209 *pQueue
= anv_queue_to_handle(&device
->queue
);
1213 anv_device_execbuf(struct anv_device
*device
,
1214 struct drm_i915_gem_execbuffer2
*execbuf
,
1215 struct anv_bo
**execbuf_bos
)
1217 int ret
= anv_gem_execbuffer(device
, execbuf
);
1219 /* We don't know the real error. */
1220 return vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
1223 struct drm_i915_gem_exec_object2
*objects
=
1224 (void *)(uintptr_t)execbuf
->buffers_ptr
;
1225 for (uint32_t k
= 0; k
< execbuf
->buffer_count
; k
++)
1226 execbuf_bos
[k
]->offset
= objects
[k
].offset
;
1231 VkResult
anv_QueueSubmit(
1233 uint32_t submitCount
,
1234 const VkSubmitInfo
* pSubmits
,
1237 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1238 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1239 struct anv_device
*device
= queue
->device
;
1240 VkResult result
= VK_SUCCESS
;
1242 /* We lock around QueueSubmit for three main reasons:
1244 * 1) When a block pool is resized, we create a new gem handle with a
1245 * different size and, in the case of surface states, possibly a
1246 * different center offset but we re-use the same anv_bo struct when
1247 * we do so. If this happens in the middle of setting up an execbuf,
1248 * we could end up with our list of BOs out of sync with our list of
1251 * 2) The algorithm we use for building the list of unique buffers isn't
1252 * thread-safe. While the client is supposed to syncronize around
1253 * QueueSubmit, this would be extremely difficult to debug if it ever
1254 * came up in the wild due to a broken app. It's better to play it
1255 * safe and just lock around QueueSubmit.
1257 * 3) The anv_cmd_buffer_execbuf function may perform relocations in
1258 * userspace. Due to the fact that the surface state buffer is shared
1259 * between batches, we can't afford to have that happen from multiple
1260 * threads at the same time. Even though the user is supposed to
1261 * ensure this doesn't happen, we play it safe as in (2) above.
1263 * Since the only other things that ever take the device lock such as block
1264 * pool resize only rarely happen, this will almost never be contended so
1265 * taking a lock isn't really an expensive operation in this case.
1267 pthread_mutex_lock(&device
->mutex
);
1269 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1270 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1271 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
1272 pSubmits
[i
].pCommandBuffers
[j
]);
1273 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1275 result
= anv_cmd_buffer_execbuf(device
, cmd_buffer
);
1276 if (result
!= VK_SUCCESS
)
1282 struct anv_bo
*fence_bo
= &fence
->bo
;
1283 result
= anv_device_execbuf(device
, &fence
->execbuf
, &fence_bo
);
1284 if (result
!= VK_SUCCESS
)
1287 /* Update the fence and wake up any waiters */
1288 assert(fence
->state
== ANV_FENCE_STATE_RESET
);
1289 fence
->state
= ANV_FENCE_STATE_SUBMITTED
;
1290 pthread_cond_broadcast(&device
->queue_submit
);
1294 pthread_mutex_unlock(&device
->mutex
);
1299 VkResult
anv_QueueWaitIdle(
1302 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1304 return anv_DeviceWaitIdle(anv_device_to_handle(queue
->device
));
1307 VkResult
anv_DeviceWaitIdle(
1310 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1311 struct anv_batch batch
;
1314 batch
.start
= batch
.next
= cmds
;
1315 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1317 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1318 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1320 return anv_device_submit_simple_batch(device
, &batch
);
1324 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1326 uint32_t gem_handle
= anv_gem_create(device
, size
);
1328 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1330 anv_bo_init(bo
, gem_handle
, size
);
1335 VkResult
anv_AllocateMemory(
1337 const VkMemoryAllocateInfo
* pAllocateInfo
,
1338 const VkAllocationCallbacks
* pAllocator
,
1339 VkDeviceMemory
* pMem
)
1341 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1342 struct anv_device_memory
*mem
;
1345 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1347 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1348 assert(pAllocateInfo
->allocationSize
> 0);
1350 /* We support exactly one memory heap. */
1351 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1352 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1354 /* FINISHME: Fail if allocation request exceeds heap size. */
1356 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1357 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1359 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1361 /* The kernel is going to give us whole pages anyway */
1362 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1364 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1365 if (result
!= VK_SUCCESS
)
1368 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1373 *pMem
= anv_device_memory_to_handle(mem
);
1378 vk_free2(&device
->alloc
, pAllocator
, mem
);
1383 void anv_FreeMemory(
1385 VkDeviceMemory _mem
,
1386 const VkAllocationCallbacks
* pAllocator
)
1388 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1389 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1395 anv_UnmapMemory(_device
, _mem
);
1398 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1400 if (mem
->bo
.gem_handle
!= 0)
1401 anv_gem_close(device
, mem
->bo
.gem_handle
);
1403 vk_free2(&device
->alloc
, pAllocator
, mem
);
1406 VkResult
anv_MapMemory(
1408 VkDeviceMemory _memory
,
1409 VkDeviceSize offset
,
1411 VkMemoryMapFlags flags
,
1414 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1415 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1422 if (size
== VK_WHOLE_SIZE
)
1423 size
= mem
->bo
.size
- offset
;
1425 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1427 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1428 * assert(size != 0);
1429 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1430 * equal to the size of the memory minus offset
1433 assert(offset
+ size
<= mem
->bo
.size
);
1435 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1436 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1437 * at a time is valid. We could just mmap up front and return an offset
1438 * pointer here, but that may exhaust virtual memory on 32 bit
1441 uint32_t gem_flags
= 0;
1442 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1443 gem_flags
|= I915_MMAP_WC
;
1445 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1446 uint64_t map_offset
= offset
& ~4095ull;
1447 assert(offset
>= map_offset
);
1448 uint64_t map_size
= (offset
+ size
) - map_offset
;
1450 /* Let's map whole pages */
1451 map_size
= align_u64(map_size
, 4096);
1453 void *map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1454 map_offset
, map_size
, gem_flags
);
1455 if (map
== MAP_FAILED
)
1456 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1459 mem
->map_size
= map_size
;
1461 *ppData
= mem
->map
+ (offset
- map_offset
);
1466 void anv_UnmapMemory(
1468 VkDeviceMemory _memory
)
1470 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1475 anv_gem_munmap(mem
->map
, mem
->map_size
);
1482 clflush_mapped_ranges(struct anv_device
*device
,
1484 const VkMappedMemoryRange
*ranges
)
1486 for (uint32_t i
= 0; i
< count
; i
++) {
1487 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1488 if (ranges
[i
].offset
>= mem
->map_size
)
1491 anv_clflush_range(mem
->map
+ ranges
[i
].offset
,
1492 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1496 VkResult
anv_FlushMappedMemoryRanges(
1498 uint32_t memoryRangeCount
,
1499 const VkMappedMemoryRange
* pMemoryRanges
)
1501 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1503 if (device
->info
.has_llc
)
1506 /* Make sure the writes we're flushing have landed. */
1507 __builtin_ia32_mfence();
1509 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1514 VkResult
anv_InvalidateMappedMemoryRanges(
1516 uint32_t memoryRangeCount
,
1517 const VkMappedMemoryRange
* pMemoryRanges
)
1519 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1521 if (device
->info
.has_llc
)
1524 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1526 /* Make sure no reads get moved up above the invalidate. */
1527 __builtin_ia32_mfence();
1532 void anv_GetBufferMemoryRequirements(
1535 VkMemoryRequirements
* pMemoryRequirements
)
1537 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1538 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1540 /* The Vulkan spec (git aaed022) says:
1542 * memoryTypeBits is a bitfield and contains one bit set for every
1543 * supported memory type for the resource. The bit `1<<i` is set if and
1544 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1545 * structure for the physical device is supported.
1547 * We support exactly one memory type on LLC, two on non-LLC.
1549 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1551 pMemoryRequirements
->size
= buffer
->size
;
1552 pMemoryRequirements
->alignment
= 16;
1555 void anv_GetImageMemoryRequirements(
1558 VkMemoryRequirements
* pMemoryRequirements
)
1560 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1561 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1563 /* The Vulkan spec (git aaed022) says:
1565 * memoryTypeBits is a bitfield and contains one bit set for every
1566 * supported memory type for the resource. The bit `1<<i` is set if and
1567 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1568 * structure for the physical device is supported.
1570 * We support exactly one memory type on LLC, two on non-LLC.
1572 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1574 pMemoryRequirements
->size
= image
->size
;
1575 pMemoryRequirements
->alignment
= image
->alignment
;
1578 void anv_GetImageSparseMemoryRequirements(
1581 uint32_t* pSparseMemoryRequirementCount
,
1582 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1587 void anv_GetDeviceMemoryCommitment(
1589 VkDeviceMemory memory
,
1590 VkDeviceSize
* pCommittedMemoryInBytes
)
1592 *pCommittedMemoryInBytes
= 0;
1595 VkResult
anv_BindBufferMemory(
1598 VkDeviceMemory _memory
,
1599 VkDeviceSize memoryOffset
)
1601 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1602 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1605 buffer
->bo
= &mem
->bo
;
1606 buffer
->offset
= memoryOffset
;
1615 VkResult
anv_QueueBindSparse(
1617 uint32_t bindInfoCount
,
1618 const VkBindSparseInfo
* pBindInfo
,
1621 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1624 VkResult
anv_CreateFence(
1626 const VkFenceCreateInfo
* pCreateInfo
,
1627 const VkAllocationCallbacks
* pAllocator
,
1630 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1631 struct anv_bo fence_bo
;
1632 struct anv_fence
*fence
;
1633 struct anv_batch batch
;
1636 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1638 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &fence_bo
, 4096);
1639 if (result
!= VK_SUCCESS
)
1642 /* Fences are small. Just store the CPU data structure in the BO. */
1643 fence
= fence_bo
.map
;
1644 fence
->bo
= fence_bo
;
1646 /* Place the batch after the CPU data but on its own cache line. */
1647 const uint32_t batch_offset
= align_u32(sizeof(*fence
), CACHELINE_SIZE
);
1648 batch
.next
= batch
.start
= fence
->bo
.map
+ batch_offset
;
1649 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1650 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1651 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1653 if (!device
->info
.has_llc
) {
1654 assert(((uintptr_t) batch
.start
& CACHELINE_MASK
) == 0);
1655 assert(batch
.next
- batch
.start
<= CACHELINE_SIZE
);
1656 __builtin_ia32_mfence();
1657 __builtin_ia32_clflush(batch
.start
);
1660 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1661 fence
->exec2_objects
[0].relocation_count
= 0;
1662 fence
->exec2_objects
[0].relocs_ptr
= 0;
1663 fence
->exec2_objects
[0].alignment
= 0;
1664 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1665 fence
->exec2_objects
[0].flags
= 0;
1666 fence
->exec2_objects
[0].rsvd1
= 0;
1667 fence
->exec2_objects
[0].rsvd2
= 0;
1669 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1670 fence
->execbuf
.buffer_count
= 1;
1671 fence
->execbuf
.batch_start_offset
= batch
.start
- fence
->bo
.map
;
1672 fence
->execbuf
.batch_len
= batch
.next
- batch
.start
;
1673 fence
->execbuf
.cliprects_ptr
= 0;
1674 fence
->execbuf
.num_cliprects
= 0;
1675 fence
->execbuf
.DR1
= 0;
1676 fence
->execbuf
.DR4
= 0;
1678 fence
->execbuf
.flags
=
1679 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1680 fence
->execbuf
.rsvd1
= device
->context_id
;
1681 fence
->execbuf
.rsvd2
= 0;
1683 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
1684 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1686 fence
->state
= ANV_FENCE_STATE_RESET
;
1689 *pFence
= anv_fence_to_handle(fence
);
1694 void anv_DestroyFence(
1697 const VkAllocationCallbacks
* pAllocator
)
1699 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1700 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1705 assert(fence
->bo
.map
== fence
);
1706 anv_bo_pool_free(&device
->batch_bo_pool
, &fence
->bo
);
1709 VkResult
anv_ResetFences(
1711 uint32_t fenceCount
,
1712 const VkFence
* pFences
)
1714 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1715 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1716 fence
->state
= ANV_FENCE_STATE_RESET
;
1722 VkResult
anv_GetFenceStatus(
1726 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1727 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1731 switch (fence
->state
) {
1732 case ANV_FENCE_STATE_RESET
:
1733 /* If it hasn't even been sent off to the GPU yet, it's not ready */
1734 return VK_NOT_READY
;
1736 case ANV_FENCE_STATE_SIGNALED
:
1737 /* It's been signaled, return success */
1740 case ANV_FENCE_STATE_SUBMITTED
:
1741 /* It's been submitted to the GPU but we don't know if it's done yet. */
1742 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1744 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1747 return VK_NOT_READY
;
1750 unreachable("Invalid fence status");
1754 #define NSEC_PER_SEC 1000000000
1755 #define INT_TYPE_MAX(type) ((1ull << (sizeof(type) * 8 - 1)) - 1)
1757 VkResult
anv_WaitForFences(
1759 uint32_t fenceCount
,
1760 const VkFence
* pFences
,
1764 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1767 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1768 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1769 * for a couple of kernel releases. Since there's no way to know
1770 * whether or not the kernel we're using is one of the broken ones, the
1771 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1772 * maximum timeout from 584 years to 292 years - likely not a big deal.
1774 int64_t timeout
= MIN2(_timeout
, INT64_MAX
);
1776 uint32_t pending_fences
= fenceCount
;
1777 while (pending_fences
) {
1779 bool signaled_fences
= false;
1780 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1781 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1782 switch (fence
->state
) {
1783 case ANV_FENCE_STATE_RESET
:
1784 /* This fence hasn't been submitted yet, we'll catch it the next
1785 * time around. Yes, this may mean we dead-loop but, short of
1786 * lots of locking and a condition variable, there's not much that
1787 * we can do about that.
1792 case ANV_FENCE_STATE_SIGNALED
:
1793 /* This fence is not pending. If waitAll isn't set, we can return
1794 * early. Otherwise, we have to keep going.
1800 case ANV_FENCE_STATE_SUBMITTED
:
1801 /* These are the fences we really care about. Go ahead and wait
1802 * on it until we hit a timeout.
1804 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &timeout
);
1805 if (ret
== -1 && errno
== ETIME
) {
1807 } else if (ret
== -1) {
1808 /* We don't know the real error. */
1809 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1811 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1812 signaled_fences
= true;
1820 if (pending_fences
&& !signaled_fences
) {
1821 /* If we've hit this then someone decided to vkWaitForFences before
1822 * they've actually submitted any of them to a queue. This is a
1823 * fairly pessimal case, so it's ok to lock here and use a standard
1824 * pthreads condition variable.
1826 pthread_mutex_lock(&device
->mutex
);
1828 /* It's possible that some of the fences have changed state since the
1829 * last time we checked. Now that we have the lock, check for
1830 * pending fences again and don't wait if it's changed.
1832 uint32_t now_pending_fences
= 0;
1833 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1834 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1835 if (fence
->state
== ANV_FENCE_STATE_RESET
)
1836 now_pending_fences
++;
1838 assert(now_pending_fences
<= pending_fences
);
1840 if (now_pending_fences
== pending_fences
) {
1841 struct timespec before
;
1842 clock_gettime(CLOCK_MONOTONIC
, &before
);
1844 uint32_t abs_nsec
= before
.tv_nsec
+ timeout
% NSEC_PER_SEC
;
1845 uint64_t abs_sec
= before
.tv_sec
+ (abs_nsec
/ NSEC_PER_SEC
) +
1846 (timeout
/ NSEC_PER_SEC
);
1847 abs_nsec
%= NSEC_PER_SEC
;
1849 /* Avoid roll-over in tv_sec on 32-bit systems if the user
1850 * provided timeout is UINT64_MAX
1852 struct timespec abstime
;
1853 abstime
.tv_nsec
= abs_nsec
;
1854 abstime
.tv_sec
= MIN2(abs_sec
, INT_TYPE_MAX(abstime
.tv_sec
));
1856 ret
= pthread_cond_timedwait(&device
->queue_submit
,
1857 &device
->mutex
, &abstime
);
1858 assert(ret
!= EINVAL
);
1860 struct timespec after
;
1861 clock_gettime(CLOCK_MONOTONIC
, &after
);
1862 uint64_t time_elapsed
=
1863 ((uint64_t)after
.tv_sec
* NSEC_PER_SEC
+ after
.tv_nsec
) -
1864 ((uint64_t)before
.tv_sec
* NSEC_PER_SEC
+ before
.tv_nsec
);
1866 if (time_elapsed
>= timeout
) {
1867 pthread_mutex_unlock(&device
->mutex
);
1871 timeout
-= time_elapsed
;
1874 pthread_mutex_unlock(&device
->mutex
);
1881 // Queue semaphore functions
1883 VkResult
anv_CreateSemaphore(
1885 const VkSemaphoreCreateInfo
* pCreateInfo
,
1886 const VkAllocationCallbacks
* pAllocator
,
1887 VkSemaphore
* pSemaphore
)
1889 /* The DRM execbuffer ioctl always execute in-oder, even between different
1890 * rings. As such, there's nothing to do for the user space semaphore.
1893 *pSemaphore
= (VkSemaphore
)1;
1898 void anv_DestroySemaphore(
1900 VkSemaphore semaphore
,
1901 const VkAllocationCallbacks
* pAllocator
)
1907 VkResult
anv_CreateEvent(
1909 const VkEventCreateInfo
* pCreateInfo
,
1910 const VkAllocationCallbacks
* pAllocator
,
1913 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1914 struct anv_state state
;
1915 struct anv_event
*event
;
1917 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1919 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1922 event
->state
= state
;
1923 event
->semaphore
= VK_EVENT_RESET
;
1925 if (!device
->info
.has_llc
) {
1926 /* Make sure the writes we're flushing have landed. */
1927 __builtin_ia32_mfence();
1928 __builtin_ia32_clflush(event
);
1931 *pEvent
= anv_event_to_handle(event
);
1936 void anv_DestroyEvent(
1939 const VkAllocationCallbacks
* pAllocator
)
1941 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1942 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1947 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1950 VkResult
anv_GetEventStatus(
1954 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1955 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1957 if (!device
->info
.has_llc
) {
1958 /* Invalidate read cache before reading event written by GPU. */
1959 __builtin_ia32_clflush(event
);
1960 __builtin_ia32_mfence();
1964 return event
->semaphore
;
1967 VkResult
anv_SetEvent(
1971 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1972 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1974 event
->semaphore
= VK_EVENT_SET
;
1976 if (!device
->info
.has_llc
) {
1977 /* Make sure the writes we're flushing have landed. */
1978 __builtin_ia32_mfence();
1979 __builtin_ia32_clflush(event
);
1985 VkResult
anv_ResetEvent(
1989 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1990 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1992 event
->semaphore
= VK_EVENT_RESET
;
1994 if (!device
->info
.has_llc
) {
1995 /* Make sure the writes we're flushing have landed. */
1996 __builtin_ia32_mfence();
1997 __builtin_ia32_clflush(event
);
2005 VkResult
anv_CreateBuffer(
2007 const VkBufferCreateInfo
* pCreateInfo
,
2008 const VkAllocationCallbacks
* pAllocator
,
2011 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2012 struct anv_buffer
*buffer
;
2014 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2016 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2017 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2019 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2021 buffer
->size
= pCreateInfo
->size
;
2022 buffer
->usage
= pCreateInfo
->usage
;
2026 *pBuffer
= anv_buffer_to_handle(buffer
);
2031 void anv_DestroyBuffer(
2034 const VkAllocationCallbacks
* pAllocator
)
2036 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2037 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2042 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2046 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2047 enum isl_format format
,
2048 uint32_t offset
, uint32_t range
, uint32_t stride
)
2050 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2052 .mocs
= device
->default_mocs
,
2057 anv_state_flush(device
, state
);
2060 void anv_DestroySampler(
2063 const VkAllocationCallbacks
* pAllocator
)
2065 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2066 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2071 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2074 VkResult
anv_CreateFramebuffer(
2076 const VkFramebufferCreateInfo
* pCreateInfo
,
2077 const VkAllocationCallbacks
* pAllocator
,
2078 VkFramebuffer
* pFramebuffer
)
2080 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2081 struct anv_framebuffer
*framebuffer
;
2083 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2085 size_t size
= sizeof(*framebuffer
) +
2086 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2087 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2088 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2089 if (framebuffer
== NULL
)
2090 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2092 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2093 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2094 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2095 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2098 framebuffer
->width
= pCreateInfo
->width
;
2099 framebuffer
->height
= pCreateInfo
->height
;
2100 framebuffer
->layers
= pCreateInfo
->layers
;
2102 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2107 void anv_DestroyFramebuffer(
2110 const VkAllocationCallbacks
* pAllocator
)
2112 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2113 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2118 vk_free2(&device
->alloc
, pAllocator
, fb
);
2121 /* vk_icd.h does not declare this function, so we declare it here to
2122 * suppress Wmissing-prototypes.
2124 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2125 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2127 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2128 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2130 /* For the full details on loader interface versioning, see
2131 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2132 * What follows is a condensed summary, to help you navigate the large and
2133 * confusing official doc.
2135 * - Loader interface v0 is incompatible with later versions. We don't
2138 * - In loader interface v1:
2139 * - The first ICD entrypoint called by the loader is
2140 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2142 * - The ICD must statically expose no other Vulkan symbol unless it is
2143 * linked with -Bsymbolic.
2144 * - Each dispatchable Vulkan handle created by the ICD must be
2145 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2146 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2147 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2148 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2149 * such loader-managed surfaces.
2151 * - Loader interface v2 differs from v1 in:
2152 * - The first ICD entrypoint called by the loader is
2153 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2154 * statically expose this entrypoint.
2156 * - Loader interface v3 differs from v2 in:
2157 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2158 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2159 * because the loader no longer does so.
2161 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);