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
33 #include "anv_private.h"
34 #include "util/strtod.h"
35 #include "util/debug.h"
37 #include "genxml/gen7_pack.h"
39 struct anv_dispatch_table dtable
;
42 compiler_debug_log(void *data
, const char *fmt
, ...)
46 compiler_perf_log(void *data
, const char *fmt
, ...)
51 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
52 vfprintf(stderr
, fmt
, args
);
58 anv_get_function_timestamp(void *ptr
, uint32_t* timestamp
)
62 if (!dladdr(ptr
, &info
) || !info
.dli_fname
)
65 if (stat(info
.dli_fname
, &st
))
68 *timestamp
= st
.st_mtim
.tv_sec
;
73 anv_device_get_cache_uuid(void *uuid
)
77 memset(uuid
, 0, VK_UUID_SIZE
);
78 if (!anv_get_function_timestamp(anv_device_get_cache_uuid
, ×tamp
))
81 snprintf(uuid
, VK_UUID_SIZE
, "anv-%d", timestamp
);
86 anv_physical_device_init(struct anv_physical_device
*device
,
87 struct anv_instance
*instance
,
93 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
95 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
97 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
98 device
->instance
= instance
;
100 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
101 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
103 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
104 if (!device
->chipset_id
) {
105 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
109 device
->name
= gen_get_device_name(device
->chipset_id
);
110 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
111 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
115 if (device
->info
.is_haswell
) {
116 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
117 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
118 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
119 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
120 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
121 } else if (device
->info
.gen
>= 8) {
122 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
123 * supported as anything */
125 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
126 "Vulkan not yet supported on %s", device
->name
);
130 device
->cmd_parser_version
= -1;
131 if (device
->info
.gen
== 7) {
132 device
->cmd_parser_version
=
133 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
134 if (device
->cmd_parser_version
== -1) {
135 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
136 "failed to get command parser version");
141 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
142 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
143 "failed to get aperture size: %m");
147 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
148 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
149 "kernel missing gem wait");
153 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
154 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
155 "kernel missing execbuf2");
159 if (!device
->info
.has_llc
&&
160 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
161 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
162 "kernel missing wc mmap");
166 if (!anv_device_get_cache_uuid(device
->uuid
)) {
167 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
168 "cannot generate UUID");
171 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
173 /* GENs prior to 8 do not support EU/Subslice info */
174 if (device
->info
.gen
>= 8) {
175 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
176 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
178 /* Without this information, we cannot get the right Braswell
179 * brandstrings, and we have to use conservative numbers for GPGPU on
180 * many platforms, but otherwise, things will just work.
182 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
183 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
184 " query GPU properties.\n");
186 } else if (device
->info
.gen
== 7) {
187 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
190 if (device
->info
.is_cherryview
&&
191 device
->subslice_total
> 0 && device
->eu_total
> 0) {
192 /* Logical CS threads = EUs per subslice * 7 threads per EU */
193 uint32_t max_cs_threads
= device
->eu_total
/ device
->subslice_total
* 7;
195 /* Fuse configurations may give more threads than expected, never less. */
196 if (max_cs_threads
> device
->info
.max_cs_threads
)
197 device
->info
.max_cs_threads
= max_cs_threads
;
200 brw_process_intel_debug_variable();
202 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
203 if (device
->compiler
== NULL
) {
204 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
207 device
->compiler
->shader_debug_log
= compiler_debug_log
;
208 device
->compiler
->shader_perf_log
= compiler_perf_log
;
210 result
= anv_init_wsi(device
);
211 if (result
!= VK_SUCCESS
) {
212 ralloc_free(device
->compiler
);
216 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
227 anv_physical_device_finish(struct anv_physical_device
*device
)
229 anv_finish_wsi(device
);
230 ralloc_free(device
->compiler
);
233 static const VkExtensionProperties global_extensions
[] = {
235 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
238 #ifdef VK_USE_PLATFORM_XCB_KHR
240 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
244 #ifdef VK_USE_PLATFORM_XLIB_KHR
246 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
250 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
252 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
257 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
262 static const VkExtensionProperties device_extensions
[] = {
264 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
268 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
272 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
278 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
279 VkSystemAllocationScope allocationScope
)
285 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
286 size_t align
, VkSystemAllocationScope allocationScope
)
288 return realloc(pOriginal
, size
);
292 default_free_func(void *pUserData
, void *pMemory
)
297 static const VkAllocationCallbacks default_alloc
= {
299 .pfnAllocation
= default_alloc_func
,
300 .pfnReallocation
= default_realloc_func
,
301 .pfnFree
= default_free_func
,
304 VkResult
anv_CreateInstance(
305 const VkInstanceCreateInfo
* pCreateInfo
,
306 const VkAllocationCallbacks
* pAllocator
,
307 VkInstance
* pInstance
)
309 struct anv_instance
*instance
;
311 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
313 uint32_t client_version
;
314 if (pCreateInfo
->pApplicationInfo
&&
315 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
316 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
318 client_version
= VK_MAKE_VERSION(1, 0, 0);
321 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
322 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
323 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
324 "Client requested version %d.%d.%d",
325 VK_VERSION_MAJOR(client_version
),
326 VK_VERSION_MINOR(client_version
),
327 VK_VERSION_PATCH(client_version
));
330 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
332 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
333 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
334 global_extensions
[j
].extensionName
) == 0) {
340 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
343 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
344 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
346 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
348 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
351 instance
->alloc
= *pAllocator
;
353 instance
->alloc
= default_alloc
;
355 instance
->apiVersion
= client_version
;
356 instance
->physicalDeviceCount
= -1;
360 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
362 *pInstance
= anv_instance_to_handle(instance
);
367 void anv_DestroyInstance(
368 VkInstance _instance
,
369 const VkAllocationCallbacks
* pAllocator
)
371 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
373 if (instance
->physicalDeviceCount
> 0) {
374 /* We support at most one physical device. */
375 assert(instance
->physicalDeviceCount
== 1);
376 anv_physical_device_finish(&instance
->physicalDevice
);
379 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
383 vk_free(&instance
->alloc
, instance
);
386 VkResult
anv_EnumeratePhysicalDevices(
387 VkInstance _instance
,
388 uint32_t* pPhysicalDeviceCount
,
389 VkPhysicalDevice
* pPhysicalDevices
)
391 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
394 if (instance
->physicalDeviceCount
< 0) {
396 for (unsigned i
= 0; i
< 8; i
++) {
397 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
398 result
= anv_physical_device_init(&instance
->physicalDevice
,
400 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
404 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
405 instance
->physicalDeviceCount
= 0;
406 } else if (result
== VK_SUCCESS
) {
407 instance
->physicalDeviceCount
= 1;
413 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
414 * otherwise it's an inout parameter.
416 * The Vulkan spec (git aaed022) says:
418 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
419 * that is initialized with the number of devices the application is
420 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
421 * an array of at least this many VkPhysicalDevice handles [...].
423 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
424 * overwrites the contents of the variable pointed to by
425 * pPhysicalDeviceCount with the number of physical devices in in the
426 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
427 * pPhysicalDeviceCount with the number of physical handles written to
430 if (!pPhysicalDevices
) {
431 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
432 } else if (*pPhysicalDeviceCount
>= 1) {
433 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
434 *pPhysicalDeviceCount
= 1;
435 } else if (*pPhysicalDeviceCount
< instance
->physicalDeviceCount
) {
436 return VK_INCOMPLETE
;
438 *pPhysicalDeviceCount
= 0;
444 void anv_GetPhysicalDeviceFeatures(
445 VkPhysicalDevice physicalDevice
,
446 VkPhysicalDeviceFeatures
* pFeatures
)
448 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
450 *pFeatures
= (VkPhysicalDeviceFeatures
) {
451 .robustBufferAccess
= true,
452 .fullDrawIndexUint32
= true,
453 .imageCubeArray
= true,
454 .independentBlend
= true,
455 .geometryShader
= true,
456 .tessellationShader
= true,
457 .sampleRateShading
= true,
458 .dualSrcBlend
= true,
460 .multiDrawIndirect
= false,
461 .drawIndirectFirstInstance
= true,
463 .depthBiasClamp
= true,
464 .fillModeNonSolid
= true,
465 .depthBounds
= false,
469 .multiViewport
= true,
470 .samplerAnisotropy
= true,
471 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
472 pdevice
->info
.is_baytrail
,
473 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
474 .textureCompressionBC
= true,
475 .occlusionQueryPrecise
= true,
476 .pipelineStatisticsQuery
= false,
477 .fragmentStoresAndAtomics
= true,
478 .shaderTessellationAndGeometryPointSize
= true,
479 .shaderImageGatherExtended
= true,
480 .shaderStorageImageExtendedFormats
= true,
481 .shaderStorageImageMultisample
= false,
482 .shaderStorageImageReadWithoutFormat
= false,
483 .shaderStorageImageWriteWithoutFormat
= false,
484 .shaderUniformBufferArrayDynamicIndexing
= true,
485 .shaderSampledImageArrayDynamicIndexing
= true,
486 .shaderStorageBufferArrayDynamicIndexing
= true,
487 .shaderStorageImageArrayDynamicIndexing
= true,
488 .shaderClipDistance
= true,
489 .shaderCullDistance
= true,
490 .shaderFloat64
= pdevice
->info
.gen
>= 8,
491 .shaderInt64
= false,
492 .shaderInt16
= false,
493 .shaderResourceMinLod
= false,
494 .variableMultisampleRate
= false,
495 .inheritedQueries
= false,
498 /* We can't do image stores in vec4 shaders */
499 pFeatures
->vertexPipelineStoresAndAtomics
=
500 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
501 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
504 void anv_GetPhysicalDeviceFeatures2KHR(
505 VkPhysicalDevice physicalDevice
,
506 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
508 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
510 for (struct anv_common
*c
= pFeatures
->pNext
; c
!= NULL
; c
= c
->pNext
) {
513 anv_debug_ignored_stype(c
->sType
);
519 void anv_GetPhysicalDeviceProperties(
520 VkPhysicalDevice physicalDevice
,
521 VkPhysicalDeviceProperties
* pProperties
)
523 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
524 const struct gen_device_info
*devinfo
= &pdevice
->info
;
526 const float time_stamp_base
= devinfo
->gen
>= 9 ? 83.333 : 80.0;
528 /* See assertions made when programming the buffer surface state. */
529 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
530 (1ul << 30) : (1ul << 27);
532 VkSampleCountFlags sample_counts
=
533 isl_device_get_sample_counts(&pdevice
->isl_dev
);
535 VkPhysicalDeviceLimits limits
= {
536 .maxImageDimension1D
= (1 << 14),
537 .maxImageDimension2D
= (1 << 14),
538 .maxImageDimension3D
= (1 << 11),
539 .maxImageDimensionCube
= (1 << 14),
540 .maxImageArrayLayers
= (1 << 11),
541 .maxTexelBufferElements
= 128 * 1024 * 1024,
542 .maxUniformBufferRange
= (1ul << 27),
543 .maxStorageBufferRange
= max_raw_buffer_sz
,
544 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
545 .maxMemoryAllocationCount
= UINT32_MAX
,
546 .maxSamplerAllocationCount
= 64 * 1024,
547 .bufferImageGranularity
= 64, /* A cache line */
548 .sparseAddressSpaceSize
= 0,
549 .maxBoundDescriptorSets
= MAX_SETS
,
550 .maxPerStageDescriptorSamplers
= 64,
551 .maxPerStageDescriptorUniformBuffers
= 64,
552 .maxPerStageDescriptorStorageBuffers
= 64,
553 .maxPerStageDescriptorSampledImages
= 64,
554 .maxPerStageDescriptorStorageImages
= 64,
555 .maxPerStageDescriptorInputAttachments
= 64,
556 .maxPerStageResources
= 128,
557 .maxDescriptorSetSamplers
= 256,
558 .maxDescriptorSetUniformBuffers
= 256,
559 .maxDescriptorSetUniformBuffersDynamic
= 256,
560 .maxDescriptorSetStorageBuffers
= 256,
561 .maxDescriptorSetStorageBuffersDynamic
= 256,
562 .maxDescriptorSetSampledImages
= 256,
563 .maxDescriptorSetStorageImages
= 256,
564 .maxDescriptorSetInputAttachments
= 256,
565 .maxVertexInputAttributes
= MAX_VBS
,
566 .maxVertexInputBindings
= MAX_VBS
,
567 .maxVertexInputAttributeOffset
= 2047,
568 .maxVertexInputBindingStride
= 2048,
569 .maxVertexOutputComponents
= 128,
570 .maxTessellationGenerationLevel
= 64,
571 .maxTessellationPatchSize
= 32,
572 .maxTessellationControlPerVertexInputComponents
= 128,
573 .maxTessellationControlPerVertexOutputComponents
= 128,
574 .maxTessellationControlPerPatchOutputComponents
= 128,
575 .maxTessellationControlTotalOutputComponents
= 2048,
576 .maxTessellationEvaluationInputComponents
= 128,
577 .maxTessellationEvaluationOutputComponents
= 128,
578 .maxGeometryShaderInvocations
= 32,
579 .maxGeometryInputComponents
= 64,
580 .maxGeometryOutputComponents
= 128,
581 .maxGeometryOutputVertices
= 256,
582 .maxGeometryTotalOutputComponents
= 1024,
583 .maxFragmentInputComponents
= 128,
584 .maxFragmentOutputAttachments
= 8,
585 .maxFragmentDualSrcAttachments
= 1,
586 .maxFragmentCombinedOutputResources
= 8,
587 .maxComputeSharedMemorySize
= 32768,
588 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
589 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
590 .maxComputeWorkGroupSize
= {
591 16 * devinfo
->max_cs_threads
,
592 16 * devinfo
->max_cs_threads
,
593 16 * devinfo
->max_cs_threads
,
595 .subPixelPrecisionBits
= 4 /* FIXME */,
596 .subTexelPrecisionBits
= 4 /* FIXME */,
597 .mipmapPrecisionBits
= 4 /* FIXME */,
598 .maxDrawIndexedIndexValue
= UINT32_MAX
,
599 .maxDrawIndirectCount
= UINT32_MAX
,
600 .maxSamplerLodBias
= 16,
601 .maxSamplerAnisotropy
= 16,
602 .maxViewports
= MAX_VIEWPORTS
,
603 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
604 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
605 .viewportSubPixelBits
= 13, /* We take a float? */
606 .minMemoryMapAlignment
= 4096, /* A page */
607 .minTexelBufferOffsetAlignment
= 1,
608 .minUniformBufferOffsetAlignment
= 16,
609 .minStorageBufferOffsetAlignment
= 4,
610 .minTexelOffset
= -8,
612 .minTexelGatherOffset
= -32,
613 .maxTexelGatherOffset
= 31,
614 .minInterpolationOffset
= -0.5,
615 .maxInterpolationOffset
= 0.4375,
616 .subPixelInterpolationOffsetBits
= 4,
617 .maxFramebufferWidth
= (1 << 14),
618 .maxFramebufferHeight
= (1 << 14),
619 .maxFramebufferLayers
= (1 << 11),
620 .framebufferColorSampleCounts
= sample_counts
,
621 .framebufferDepthSampleCounts
= sample_counts
,
622 .framebufferStencilSampleCounts
= sample_counts
,
623 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
624 .maxColorAttachments
= MAX_RTS
,
625 .sampledImageColorSampleCounts
= sample_counts
,
626 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
627 .sampledImageDepthSampleCounts
= sample_counts
,
628 .sampledImageStencilSampleCounts
= sample_counts
,
629 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
630 .maxSampleMaskWords
= 1,
631 .timestampComputeAndGraphics
= false,
632 .timestampPeriod
= time_stamp_base
,
633 .maxClipDistances
= 8,
634 .maxCullDistances
= 8,
635 .maxCombinedClipAndCullDistances
= 8,
636 .discreteQueuePriorities
= 1,
637 .pointSizeRange
= { 0.125, 255.875 },
638 .lineWidthRange
= { 0.0, 7.9921875 },
639 .pointSizeGranularity
= (1.0 / 8.0),
640 .lineWidthGranularity
= (1.0 / 128.0),
641 .strictLines
= false, /* FINISHME */
642 .standardSampleLocations
= true,
643 .optimalBufferCopyOffsetAlignment
= 128,
644 .optimalBufferCopyRowPitchAlignment
= 128,
645 .nonCoherentAtomSize
= 64,
648 *pProperties
= (VkPhysicalDeviceProperties
) {
649 .apiVersion
= VK_MAKE_VERSION(1, 0, 39),
652 .deviceID
= pdevice
->chipset_id
,
653 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
655 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
658 strcpy(pProperties
->deviceName
, pdevice
->name
);
659 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
662 void anv_GetPhysicalDeviceProperties2KHR(
663 VkPhysicalDevice physicalDevice
,
664 VkPhysicalDeviceProperties2KHR
* pProperties
)
666 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
668 for (struct anv_common
*c
= pProperties
->pNext
; c
!= NULL
; c
= c
->pNext
) {
671 anv_debug_ignored_stype(c
->sType
);
678 anv_get_queue_family_properties(struct anv_physical_device
*phys_dev
,
679 VkQueueFamilyProperties
*props
)
681 *props
= (VkQueueFamilyProperties
) {
682 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
683 VK_QUEUE_COMPUTE_BIT
|
684 VK_QUEUE_TRANSFER_BIT
,
686 .timestampValidBits
= 36, /* XXX: Real value here */
687 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
691 void anv_GetPhysicalDeviceQueueFamilyProperties(
692 VkPhysicalDevice physicalDevice
,
694 VkQueueFamilyProperties
* pQueueFamilyProperties
)
696 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
698 if (pQueueFamilyProperties
== NULL
) {
703 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
704 * 1.0.38 spec, Section 4.1 Physical Devices:
706 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
713 anv_get_queue_family_properties(phys_dev
, pQueueFamilyProperties
);
716 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
717 VkPhysicalDevice physicalDevice
,
718 uint32_t* pQueueFamilyPropertyCount
,
719 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
722 ANV_FROM_HANDLE(anv_physical_device
, phys_dev
, physicalDevice
);
724 if (pQueueFamilyProperties
== NULL
) {
725 *pQueueFamilyPropertyCount
= 1;
729 /* The spec implicitly allows the incoming count to be 0. From the Vulkan
730 * 1.0.38 spec, Section 4.1 Physical Devices:
732 * If the value referenced by pQueueFamilyPropertyCount is not 0 [then
735 if (*pQueueFamilyPropertyCount
== 0)
738 /* We support exactly one queue family. So need to traverse only the first
739 * array element's pNext chain.
741 *pQueueFamilyPropertyCount
= 1;
742 anv_get_queue_family_properties(phys_dev
,
743 &pQueueFamilyProperties
->queueFamilyProperties
);
745 for (struct anv_common
*c
= pQueueFamilyProperties
->pNext
;
746 c
!= NULL
; c
= c
->pNext
) {
749 anv_debug_ignored_stype(c
->sType
);
755 void anv_GetPhysicalDeviceMemoryProperties(
756 VkPhysicalDevice physicalDevice
,
757 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
759 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
760 VkDeviceSize heap_size
;
762 /* Reserve some wiggle room for the driver by exposing only 75% of the
763 * aperture to the heap.
765 heap_size
= 3 * physical_device
->aperture_size
/ 4;
767 if (physical_device
->info
.has_llc
) {
768 /* Big core GPUs share LLC with the CPU and thus one memory type can be
769 * both cached and coherent at the same time.
771 pMemoryProperties
->memoryTypeCount
= 1;
772 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
773 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
774 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
775 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
776 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
780 /* The spec requires that we expose a host-visible, coherent memory
781 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
782 * to give the application a choice between cached, but not coherent and
783 * coherent but uncached (WC though).
785 pMemoryProperties
->memoryTypeCount
= 2;
786 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
787 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
788 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
789 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
792 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
793 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
794 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
795 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
800 pMemoryProperties
->memoryHeapCount
= 1;
801 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
803 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
807 void anv_GetPhysicalDeviceMemoryProperties2KHR(
808 VkPhysicalDevice physicalDevice
,
809 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
811 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
812 &pMemoryProperties
->memoryProperties
);
814 for (struct anv_common
*c
= pMemoryProperties
->pNext
;
815 c
!= NULL
; c
= c
->pNext
) {
818 anv_debug_ignored_stype(c
->sType
);
824 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
828 return anv_lookup_entrypoint(NULL
, pName
);
831 /* With version 1+ of the loader interface the ICD should expose
832 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
835 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
840 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
844 return anv_GetInstanceProcAddr(instance
, pName
);
847 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
851 ANV_FROM_HANDLE(anv_device
, device
, _device
);
852 return anv_lookup_entrypoint(&device
->info
, pName
);
856 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
858 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
859 queue
->device
= device
;
860 queue
->pool
= &device
->surface_state_pool
;
864 anv_queue_finish(struct anv_queue
*queue
)
868 static struct anv_state
869 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
871 struct anv_state state
;
873 state
= anv_state_pool_alloc(pool
, size
, align
);
874 memcpy(state
.map
, p
, size
);
876 if (!pool
->block_pool
->device
->info
.has_llc
)
877 anv_state_clflush(state
);
882 struct gen8_border_color
{
887 /* Pad out to 64 bytes */
892 anv_device_init_border_colors(struct anv_device
*device
)
894 static const struct gen8_border_color border_colors
[] = {
895 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
896 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
897 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
898 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
899 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
900 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
903 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
904 sizeof(border_colors
), 64,
909 anv_device_submit_simple_batch(struct anv_device
*device
,
910 struct anv_batch
*batch
)
912 struct drm_i915_gem_execbuffer2 execbuf
;
913 struct drm_i915_gem_exec_object2 exec2_objects
[1];
914 struct anv_bo bo
, *exec_bos
[1];
915 VkResult result
= VK_SUCCESS
;
920 /* Kernel driver requires 8 byte aligned batch length */
921 size
= align_u32(batch
->next
- batch
->start
, 8);
922 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bo
, size
);
923 if (result
!= VK_SUCCESS
)
926 memcpy(bo
.map
, batch
->start
, size
);
927 if (!device
->info
.has_llc
)
928 anv_clflush_range(bo
.map
, size
);
931 exec2_objects
[0].handle
= bo
.gem_handle
;
932 exec2_objects
[0].relocation_count
= 0;
933 exec2_objects
[0].relocs_ptr
= 0;
934 exec2_objects
[0].alignment
= 0;
935 exec2_objects
[0].offset
= bo
.offset
;
936 exec2_objects
[0].flags
= 0;
937 exec2_objects
[0].rsvd1
= 0;
938 exec2_objects
[0].rsvd2
= 0;
940 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
941 execbuf
.buffer_count
= 1;
942 execbuf
.batch_start_offset
= 0;
943 execbuf
.batch_len
= size
;
944 execbuf
.cliprects_ptr
= 0;
945 execbuf
.num_cliprects
= 0;
950 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
951 execbuf
.rsvd1
= device
->context_id
;
954 result
= anv_device_execbuf(device
, &execbuf
, exec_bos
);
955 if (result
!= VK_SUCCESS
)
959 ret
= anv_gem_wait(device
, bo
.gem_handle
, &timeout
);
961 /* We don't know the real error. */
962 result
= vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
967 anv_bo_pool_free(&device
->batch_bo_pool
, &bo
);
972 VkResult
anv_CreateDevice(
973 VkPhysicalDevice physicalDevice
,
974 const VkDeviceCreateInfo
* pCreateInfo
,
975 const VkAllocationCallbacks
* pAllocator
,
978 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
980 struct anv_device
*device
;
982 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
984 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
986 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
987 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
988 device_extensions
[j
].extensionName
) == 0) {
994 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
997 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
999 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1001 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1003 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1004 device
->instance
= physical_device
->instance
;
1005 device
->chipset_id
= physical_device
->chipset_id
;
1008 device
->alloc
= *pAllocator
;
1010 device
->alloc
= physical_device
->instance
->alloc
;
1012 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1013 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1014 if (device
->fd
== -1) {
1015 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1019 device
->context_id
= anv_gem_create_context(device
);
1020 if (device
->context_id
== -1) {
1021 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1025 device
->info
= physical_device
->info
;
1026 device
->isl_dev
= physical_device
->isl_dev
;
1028 /* On Broadwell and later, we can use batch chaining to more efficiently
1029 * implement growing command buffers. Prior to Haswell, the kernel
1030 * command parser gets in the way and we have to fall back to growing
1033 device
->can_chain_batches
= device
->info
.gen
>= 8;
1035 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1036 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1038 pthread_mutex_init(&device
->mutex
, NULL
);
1040 pthread_condattr_t condattr
;
1041 pthread_condattr_init(&condattr
);
1042 pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
);
1043 pthread_cond_init(&device
->queue_submit
, NULL
);
1044 pthread_condattr_destroy(&condattr
);
1046 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1048 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 16384);
1050 anv_state_pool_init(&device
->dynamic_state_pool
,
1051 &device
->dynamic_state_block_pool
);
1053 anv_block_pool_init(&device
->instruction_block_pool
, device
, 1024 * 1024);
1054 anv_state_pool_init(&device
->instruction_state_pool
,
1055 &device
->instruction_block_pool
);
1057 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
1059 anv_state_pool_init(&device
->surface_state_pool
,
1060 &device
->surface_state_block_pool
);
1062 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1064 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1066 anv_queue_init(device
, &device
->queue
);
1068 switch (device
->info
.gen
) {
1070 if (!device
->info
.is_haswell
)
1071 result
= gen7_init_device_state(device
);
1073 result
= gen75_init_device_state(device
);
1076 result
= gen8_init_device_state(device
);
1079 result
= gen9_init_device_state(device
);
1082 /* Shouldn't get here as we don't create physical devices for any other
1084 unreachable("unhandled gen");
1086 if (result
!= VK_SUCCESS
)
1089 anv_device_init_blorp(device
);
1091 anv_device_init_border_colors(device
);
1093 *pDevice
= anv_device_to_handle(device
);
1100 vk_free(&device
->alloc
, device
);
1105 void anv_DestroyDevice(
1107 const VkAllocationCallbacks
* pAllocator
)
1109 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1111 anv_device_finish_blorp(device
);
1113 anv_queue_finish(&device
->queue
);
1115 #ifdef HAVE_VALGRIND
1116 /* We only need to free these to prevent valgrind errors. The backing
1117 * BO will go away in a couple of lines so we don't actually leak.
1119 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1122 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1124 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1125 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1127 anv_state_pool_finish(&device
->surface_state_pool
);
1128 anv_block_pool_finish(&device
->surface_state_block_pool
);
1129 anv_state_pool_finish(&device
->instruction_state_pool
);
1130 anv_block_pool_finish(&device
->instruction_block_pool
);
1131 anv_state_pool_finish(&device
->dynamic_state_pool
);
1132 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
1134 anv_bo_pool_finish(&device
->batch_bo_pool
);
1136 pthread_cond_destroy(&device
->queue_submit
);
1137 pthread_mutex_destroy(&device
->mutex
);
1139 anv_gem_destroy_context(device
, device
->context_id
);
1143 vk_free(&device
->alloc
, device
);
1146 VkResult
anv_EnumerateInstanceExtensionProperties(
1147 const char* pLayerName
,
1148 uint32_t* pPropertyCount
,
1149 VkExtensionProperties
* pProperties
)
1151 if (pProperties
== NULL
) {
1152 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1156 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1157 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1159 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1160 return VK_INCOMPLETE
;
1165 VkResult
anv_EnumerateDeviceExtensionProperties(
1166 VkPhysicalDevice physicalDevice
,
1167 const char* pLayerName
,
1168 uint32_t* pPropertyCount
,
1169 VkExtensionProperties
* pProperties
)
1171 if (pProperties
== NULL
) {
1172 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1176 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1177 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1179 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1180 return VK_INCOMPLETE
;
1185 VkResult
anv_EnumerateInstanceLayerProperties(
1186 uint32_t* pPropertyCount
,
1187 VkLayerProperties
* pProperties
)
1189 if (pProperties
== NULL
) {
1190 *pPropertyCount
= 0;
1194 /* None supported at this time */
1195 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1198 VkResult
anv_EnumerateDeviceLayerProperties(
1199 VkPhysicalDevice physicalDevice
,
1200 uint32_t* pPropertyCount
,
1201 VkLayerProperties
* pProperties
)
1203 if (pProperties
== NULL
) {
1204 *pPropertyCount
= 0;
1208 /* None supported at this time */
1209 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1212 void anv_GetDeviceQueue(
1214 uint32_t queueNodeIndex
,
1215 uint32_t queueIndex
,
1218 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1220 assert(queueIndex
== 0);
1222 *pQueue
= anv_queue_to_handle(&device
->queue
);
1226 anv_device_execbuf(struct anv_device
*device
,
1227 struct drm_i915_gem_execbuffer2
*execbuf
,
1228 struct anv_bo
**execbuf_bos
)
1230 int ret
= anv_gem_execbuffer(device
, execbuf
);
1232 /* We don't know the real error. */
1233 return vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
1236 struct drm_i915_gem_exec_object2
*objects
=
1237 (void *)(uintptr_t)execbuf
->buffers_ptr
;
1238 for (uint32_t k
= 0; k
< execbuf
->buffer_count
; k
++)
1239 execbuf_bos
[k
]->offset
= objects
[k
].offset
;
1244 VkResult
anv_QueueSubmit(
1246 uint32_t submitCount
,
1247 const VkSubmitInfo
* pSubmits
,
1250 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1251 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1252 struct anv_device
*device
= queue
->device
;
1253 VkResult result
= VK_SUCCESS
;
1255 /* We lock around QueueSubmit for three main reasons:
1257 * 1) When a block pool is resized, we create a new gem handle with a
1258 * different size and, in the case of surface states, possibly a
1259 * different center offset but we re-use the same anv_bo struct when
1260 * we do so. If this happens in the middle of setting up an execbuf,
1261 * we could end up with our list of BOs out of sync with our list of
1264 * 2) The algorithm we use for building the list of unique buffers isn't
1265 * thread-safe. While the client is supposed to syncronize around
1266 * QueueSubmit, this would be extremely difficult to debug if it ever
1267 * came up in the wild due to a broken app. It's better to play it
1268 * safe and just lock around QueueSubmit.
1270 * 3) The anv_cmd_buffer_execbuf function may perform relocations in
1271 * userspace. Due to the fact that the surface state buffer is shared
1272 * between batches, we can't afford to have that happen from multiple
1273 * threads at the same time. Even though the user is supposed to
1274 * ensure this doesn't happen, we play it safe as in (2) above.
1276 * Since the only other things that ever take the device lock such as block
1277 * pool resize only rarely happen, this will almost never be contended so
1278 * taking a lock isn't really an expensive operation in this case.
1280 pthread_mutex_lock(&device
->mutex
);
1282 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1283 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1284 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
1285 pSubmits
[i
].pCommandBuffers
[j
]);
1286 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1288 result
= anv_cmd_buffer_execbuf(device
, cmd_buffer
);
1289 if (result
!= VK_SUCCESS
)
1295 struct anv_bo
*fence_bo
= &fence
->bo
;
1296 result
= anv_device_execbuf(device
, &fence
->execbuf
, &fence_bo
);
1297 if (result
!= VK_SUCCESS
)
1300 /* Update the fence and wake up any waiters */
1301 assert(fence
->state
== ANV_FENCE_STATE_RESET
);
1302 fence
->state
= ANV_FENCE_STATE_SUBMITTED
;
1303 pthread_cond_broadcast(&device
->queue_submit
);
1307 pthread_mutex_unlock(&device
->mutex
);
1312 VkResult
anv_QueueWaitIdle(
1315 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1317 return anv_DeviceWaitIdle(anv_device_to_handle(queue
->device
));
1320 VkResult
anv_DeviceWaitIdle(
1323 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1324 struct anv_batch batch
;
1327 batch
.start
= batch
.next
= cmds
;
1328 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1330 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1331 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1333 return anv_device_submit_simple_batch(device
, &batch
);
1337 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1339 uint32_t gem_handle
= anv_gem_create(device
, size
);
1341 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1343 anv_bo_init(bo
, gem_handle
, size
);
1348 VkResult
anv_AllocateMemory(
1350 const VkMemoryAllocateInfo
* pAllocateInfo
,
1351 const VkAllocationCallbacks
* pAllocator
,
1352 VkDeviceMemory
* pMem
)
1354 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1355 struct anv_device_memory
*mem
;
1358 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1360 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1361 assert(pAllocateInfo
->allocationSize
> 0);
1363 /* We support exactly one memory heap. */
1364 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1365 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1367 /* FINISHME: Fail if allocation request exceeds heap size. */
1369 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1370 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1372 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1374 /* The kernel is going to give us whole pages anyway */
1375 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1377 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1378 if (result
!= VK_SUCCESS
)
1381 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1386 *pMem
= anv_device_memory_to_handle(mem
);
1391 vk_free2(&device
->alloc
, pAllocator
, mem
);
1396 void anv_FreeMemory(
1398 VkDeviceMemory _mem
,
1399 const VkAllocationCallbacks
* pAllocator
)
1401 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1402 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1408 anv_UnmapMemory(_device
, _mem
);
1411 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1413 if (mem
->bo
.gem_handle
!= 0)
1414 anv_gem_close(device
, mem
->bo
.gem_handle
);
1416 vk_free2(&device
->alloc
, pAllocator
, mem
);
1419 VkResult
anv_MapMemory(
1421 VkDeviceMemory _memory
,
1422 VkDeviceSize offset
,
1424 VkMemoryMapFlags flags
,
1427 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1428 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1435 if (size
== VK_WHOLE_SIZE
)
1436 size
= mem
->bo
.size
- offset
;
1438 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1440 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1441 * assert(size != 0);
1442 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1443 * equal to the size of the memory minus offset
1446 assert(offset
+ size
<= mem
->bo
.size
);
1448 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1449 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1450 * at a time is valid. We could just mmap up front and return an offset
1451 * pointer here, but that may exhaust virtual memory on 32 bit
1454 uint32_t gem_flags
= 0;
1455 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1456 gem_flags
|= I915_MMAP_WC
;
1458 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1459 uint64_t map_offset
= offset
& ~4095ull;
1460 assert(offset
>= map_offset
);
1461 uint64_t map_size
= (offset
+ size
) - map_offset
;
1463 /* Let's map whole pages */
1464 map_size
= align_u64(map_size
, 4096);
1466 void *map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1467 map_offset
, map_size
, gem_flags
);
1468 if (map
== MAP_FAILED
)
1469 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1472 mem
->map_size
= map_size
;
1474 *ppData
= mem
->map
+ (offset
- map_offset
);
1479 void anv_UnmapMemory(
1481 VkDeviceMemory _memory
)
1483 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1488 anv_gem_munmap(mem
->map
, mem
->map_size
);
1495 clflush_mapped_ranges(struct anv_device
*device
,
1497 const VkMappedMemoryRange
*ranges
)
1499 for (uint32_t i
= 0; i
< count
; i
++) {
1500 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1501 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1504 if (ranges
[i
].offset
+ ranges
[i
].size
> mem
->map_size
)
1505 end
= mem
->map
+ mem
->map_size
;
1507 end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1510 __builtin_ia32_clflush(p
);
1511 p
+= CACHELINE_SIZE
;
1516 VkResult
anv_FlushMappedMemoryRanges(
1518 uint32_t memoryRangeCount
,
1519 const VkMappedMemoryRange
* pMemoryRanges
)
1521 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1523 if (device
->info
.has_llc
)
1526 /* Make sure the writes we're flushing have landed. */
1527 __builtin_ia32_mfence();
1529 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1534 VkResult
anv_InvalidateMappedMemoryRanges(
1536 uint32_t memoryRangeCount
,
1537 const VkMappedMemoryRange
* pMemoryRanges
)
1539 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1541 if (device
->info
.has_llc
)
1544 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1546 /* Make sure no reads get moved up above the invalidate. */
1547 __builtin_ia32_mfence();
1552 void anv_GetBufferMemoryRequirements(
1555 VkMemoryRequirements
* pMemoryRequirements
)
1557 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1559 /* The Vulkan spec (git aaed022) says:
1561 * memoryTypeBits is a bitfield and contains one bit set for every
1562 * supported memory type for the resource. The bit `1<<i` is set if and
1563 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1564 * structure for the physical device is supported.
1566 * We support exactly one memory type.
1568 pMemoryRequirements
->memoryTypeBits
= 1;
1570 pMemoryRequirements
->size
= buffer
->size
;
1571 pMemoryRequirements
->alignment
= 16;
1574 void anv_GetImageMemoryRequirements(
1577 VkMemoryRequirements
* pMemoryRequirements
)
1579 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1581 /* The Vulkan spec (git aaed022) says:
1583 * memoryTypeBits is a bitfield and contains one bit set for every
1584 * supported memory type for the resource. The bit `1<<i` is set if and
1585 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1586 * structure for the physical device is supported.
1588 * We support exactly one memory type.
1590 pMemoryRequirements
->memoryTypeBits
= 1;
1592 pMemoryRequirements
->size
= image
->size
;
1593 pMemoryRequirements
->alignment
= image
->alignment
;
1596 void anv_GetImageSparseMemoryRequirements(
1599 uint32_t* pSparseMemoryRequirementCount
,
1600 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1605 void anv_GetDeviceMemoryCommitment(
1607 VkDeviceMemory memory
,
1608 VkDeviceSize
* pCommittedMemoryInBytes
)
1610 *pCommittedMemoryInBytes
= 0;
1613 VkResult
anv_BindBufferMemory(
1616 VkDeviceMemory _memory
,
1617 VkDeviceSize memoryOffset
)
1619 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1620 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1623 buffer
->bo
= &mem
->bo
;
1624 buffer
->offset
= memoryOffset
;
1633 VkResult
anv_QueueBindSparse(
1635 uint32_t bindInfoCount
,
1636 const VkBindSparseInfo
* pBindInfo
,
1639 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1642 VkResult
anv_CreateFence(
1644 const VkFenceCreateInfo
* pCreateInfo
,
1645 const VkAllocationCallbacks
* pAllocator
,
1648 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1649 struct anv_bo fence_bo
;
1650 struct anv_fence
*fence
;
1651 struct anv_batch batch
;
1654 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1656 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &fence_bo
, 4096);
1657 if (result
!= VK_SUCCESS
)
1660 /* Fences are small. Just store the CPU data structure in the BO. */
1661 fence
= fence_bo
.map
;
1662 fence
->bo
= fence_bo
;
1664 /* Place the batch after the CPU data but on its own cache line. */
1665 const uint32_t batch_offset
= align_u32(sizeof(*fence
), CACHELINE_SIZE
);
1666 batch
.next
= batch
.start
= fence
->bo
.map
+ batch_offset
;
1667 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1668 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1669 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1671 if (!device
->info
.has_llc
) {
1672 assert(((uintptr_t) batch
.start
& CACHELINE_MASK
) == 0);
1673 assert(batch
.next
- batch
.start
<= CACHELINE_SIZE
);
1674 __builtin_ia32_mfence();
1675 __builtin_ia32_clflush(batch
.start
);
1678 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1679 fence
->exec2_objects
[0].relocation_count
= 0;
1680 fence
->exec2_objects
[0].relocs_ptr
= 0;
1681 fence
->exec2_objects
[0].alignment
= 0;
1682 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1683 fence
->exec2_objects
[0].flags
= 0;
1684 fence
->exec2_objects
[0].rsvd1
= 0;
1685 fence
->exec2_objects
[0].rsvd2
= 0;
1687 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1688 fence
->execbuf
.buffer_count
= 1;
1689 fence
->execbuf
.batch_start_offset
= batch
.start
- fence
->bo
.map
;
1690 fence
->execbuf
.batch_len
= batch
.next
- batch
.start
;
1691 fence
->execbuf
.cliprects_ptr
= 0;
1692 fence
->execbuf
.num_cliprects
= 0;
1693 fence
->execbuf
.DR1
= 0;
1694 fence
->execbuf
.DR4
= 0;
1696 fence
->execbuf
.flags
=
1697 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1698 fence
->execbuf
.rsvd1
= device
->context_id
;
1699 fence
->execbuf
.rsvd2
= 0;
1701 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
1702 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1704 fence
->state
= ANV_FENCE_STATE_RESET
;
1707 *pFence
= anv_fence_to_handle(fence
);
1712 void anv_DestroyFence(
1715 const VkAllocationCallbacks
* pAllocator
)
1717 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1718 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1723 assert(fence
->bo
.map
== fence
);
1724 anv_bo_pool_free(&device
->batch_bo_pool
, &fence
->bo
);
1727 VkResult
anv_ResetFences(
1729 uint32_t fenceCount
,
1730 const VkFence
* pFences
)
1732 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1733 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1734 fence
->state
= ANV_FENCE_STATE_RESET
;
1740 VkResult
anv_GetFenceStatus(
1744 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1745 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1749 switch (fence
->state
) {
1750 case ANV_FENCE_STATE_RESET
:
1751 /* If it hasn't even been sent off to the GPU yet, it's not ready */
1752 return VK_NOT_READY
;
1754 case ANV_FENCE_STATE_SIGNALED
:
1755 /* It's been signaled, return success */
1758 case ANV_FENCE_STATE_SUBMITTED
:
1759 /* It's been submitted to the GPU but we don't know if it's done yet. */
1760 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1762 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1765 return VK_NOT_READY
;
1768 unreachable("Invalid fence status");
1772 #define NSEC_PER_SEC 1000000000
1773 #define INT_TYPE_MAX(type) ((1ull << (sizeof(type) * 8 - 1)) - 1)
1775 VkResult
anv_WaitForFences(
1777 uint32_t fenceCount
,
1778 const VkFence
* pFences
,
1782 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1785 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1786 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1787 * for a couple of kernel releases. Since there's no way to know
1788 * whether or not the kernel we're using is one of the broken ones, the
1789 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1790 * maximum timeout from 584 years to 292 years - likely not a big deal.
1792 int64_t timeout
= MIN2(_timeout
, INT64_MAX
);
1794 uint32_t pending_fences
= fenceCount
;
1795 while (pending_fences
) {
1797 bool signaled_fences
= false;
1798 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1799 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1800 switch (fence
->state
) {
1801 case ANV_FENCE_STATE_RESET
:
1802 /* This fence hasn't been submitted yet, we'll catch it the next
1803 * time around. Yes, this may mean we dead-loop but, short of
1804 * lots of locking and a condition variable, there's not much that
1805 * we can do about that.
1810 case ANV_FENCE_STATE_SIGNALED
:
1811 /* This fence is not pending. If waitAll isn't set, we can return
1812 * early. Otherwise, we have to keep going.
1818 case ANV_FENCE_STATE_SUBMITTED
:
1819 /* These are the fences we really care about. Go ahead and wait
1820 * on it until we hit a timeout.
1822 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &timeout
);
1823 if (ret
== -1 && errno
== ETIME
) {
1825 } else if (ret
== -1) {
1826 /* We don't know the real error. */
1827 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1829 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1830 signaled_fences
= true;
1838 if (pending_fences
&& !signaled_fences
) {
1839 /* If we've hit this then someone decided to vkWaitForFences before
1840 * they've actually submitted any of them to a queue. This is a
1841 * fairly pessimal case, so it's ok to lock here and use a standard
1842 * pthreads condition variable.
1844 pthread_mutex_lock(&device
->mutex
);
1846 /* It's possible that some of the fences have changed state since the
1847 * last time we checked. Now that we have the lock, check for
1848 * pending fences again and don't wait if it's changed.
1850 uint32_t now_pending_fences
= 0;
1851 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1852 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1853 if (fence
->state
== ANV_FENCE_STATE_RESET
)
1854 now_pending_fences
++;
1856 assert(now_pending_fences
<= pending_fences
);
1858 if (now_pending_fences
== pending_fences
) {
1859 struct timespec before
;
1860 clock_gettime(CLOCK_MONOTONIC
, &before
);
1862 uint32_t abs_nsec
= before
.tv_nsec
+ timeout
% NSEC_PER_SEC
;
1863 uint64_t abs_sec
= before
.tv_sec
+ (abs_nsec
/ NSEC_PER_SEC
) +
1864 (timeout
/ NSEC_PER_SEC
);
1865 abs_nsec
%= NSEC_PER_SEC
;
1867 /* Avoid roll-over in tv_sec on 32-bit systems if the user
1868 * provided timeout is UINT64_MAX
1870 struct timespec abstime
;
1871 abstime
.tv_nsec
= abs_nsec
;
1872 abstime
.tv_sec
= MIN2(abs_sec
, INT_TYPE_MAX(abstime
.tv_sec
));
1874 ret
= pthread_cond_timedwait(&device
->queue_submit
,
1875 &device
->mutex
, &abstime
);
1876 assert(ret
!= EINVAL
);
1878 struct timespec after
;
1879 clock_gettime(CLOCK_MONOTONIC
, &after
);
1880 uint64_t time_elapsed
=
1881 ((uint64_t)after
.tv_sec
* NSEC_PER_SEC
+ after
.tv_nsec
) -
1882 ((uint64_t)before
.tv_sec
* NSEC_PER_SEC
+ before
.tv_nsec
);
1884 if (time_elapsed
>= timeout
) {
1885 pthread_mutex_unlock(&device
->mutex
);
1889 timeout
-= time_elapsed
;
1892 pthread_mutex_unlock(&device
->mutex
);
1899 // Queue semaphore functions
1901 VkResult
anv_CreateSemaphore(
1903 const VkSemaphoreCreateInfo
* pCreateInfo
,
1904 const VkAllocationCallbacks
* pAllocator
,
1905 VkSemaphore
* pSemaphore
)
1907 /* The DRM execbuffer ioctl always execute in-oder, even between different
1908 * rings. As such, there's nothing to do for the user space semaphore.
1911 *pSemaphore
= (VkSemaphore
)1;
1916 void anv_DestroySemaphore(
1918 VkSemaphore semaphore
,
1919 const VkAllocationCallbacks
* pAllocator
)
1925 VkResult
anv_CreateEvent(
1927 const VkEventCreateInfo
* pCreateInfo
,
1928 const VkAllocationCallbacks
* pAllocator
,
1931 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1932 struct anv_state state
;
1933 struct anv_event
*event
;
1935 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1937 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1940 event
->state
= state
;
1941 event
->semaphore
= VK_EVENT_RESET
;
1943 if (!device
->info
.has_llc
) {
1944 /* Make sure the writes we're flushing have landed. */
1945 __builtin_ia32_mfence();
1946 __builtin_ia32_clflush(event
);
1949 *pEvent
= anv_event_to_handle(event
);
1954 void anv_DestroyEvent(
1957 const VkAllocationCallbacks
* pAllocator
)
1959 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1960 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1965 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1968 VkResult
anv_GetEventStatus(
1972 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1973 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1975 if (!device
->info
.has_llc
) {
1976 /* Invalidate read cache before reading event written by GPU. */
1977 __builtin_ia32_clflush(event
);
1978 __builtin_ia32_mfence();
1982 return event
->semaphore
;
1985 VkResult
anv_SetEvent(
1989 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1990 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1992 event
->semaphore
= VK_EVENT_SET
;
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
);
2003 VkResult
anv_ResetEvent(
2007 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2008 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2010 event
->semaphore
= VK_EVENT_RESET
;
2012 if (!device
->info
.has_llc
) {
2013 /* Make sure the writes we're flushing have landed. */
2014 __builtin_ia32_mfence();
2015 __builtin_ia32_clflush(event
);
2023 VkResult
anv_CreateBuffer(
2025 const VkBufferCreateInfo
* pCreateInfo
,
2026 const VkAllocationCallbacks
* pAllocator
,
2029 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2030 struct anv_buffer
*buffer
;
2032 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2034 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2035 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2037 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2039 buffer
->size
= pCreateInfo
->size
;
2040 buffer
->usage
= pCreateInfo
->usage
;
2044 *pBuffer
= anv_buffer_to_handle(buffer
);
2049 void anv_DestroyBuffer(
2052 const VkAllocationCallbacks
* pAllocator
)
2054 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2055 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2060 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2064 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2065 enum isl_format format
,
2066 uint32_t offset
, uint32_t range
, uint32_t stride
)
2068 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2070 .mocs
= device
->default_mocs
,
2075 if (!device
->info
.has_llc
)
2076 anv_state_clflush(state
);
2079 void anv_DestroySampler(
2082 const VkAllocationCallbacks
* pAllocator
)
2084 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2085 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2090 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2093 VkResult
anv_CreateFramebuffer(
2095 const VkFramebufferCreateInfo
* pCreateInfo
,
2096 const VkAllocationCallbacks
* pAllocator
,
2097 VkFramebuffer
* pFramebuffer
)
2099 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2100 struct anv_framebuffer
*framebuffer
;
2102 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2104 size_t size
= sizeof(*framebuffer
) +
2105 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2106 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2107 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2108 if (framebuffer
== NULL
)
2109 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2111 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2112 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2113 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2114 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2117 framebuffer
->width
= pCreateInfo
->width
;
2118 framebuffer
->height
= pCreateInfo
->height
;
2119 framebuffer
->layers
= pCreateInfo
->layers
;
2121 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2126 void anv_DestroyFramebuffer(
2129 const VkAllocationCallbacks
* pAllocator
)
2131 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2132 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2137 vk_free2(&device
->alloc
, pAllocator
, fb
);
2140 /* vk_icd.h does not declare this function, so we declare it here to
2141 * suppress Wmissing-prototypes.
2143 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2144 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2146 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2147 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2149 /* For the full details on loader interface versioning, see
2150 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2151 * What follows is a condensed summary, to help you navigate the large and
2152 * confusing official doc.
2154 * - Loader interface v0 is incompatible with later versions. We don't
2157 * - In loader interface v1:
2158 * - The first ICD entrypoint called by the loader is
2159 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2161 * - The ICD must statically expose no other Vulkan symbol unless it is
2162 * linked with -Bsymbolic.
2163 * - Each dispatchable Vulkan handle created by the ICD must be
2164 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2165 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2166 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2167 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2168 * such loader-managed surfaces.
2170 * - Loader interface v2 differs from v1 in:
2171 * - The first ICD entrypoint called by the loader is
2172 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2173 * statically expose this entrypoint.
2175 * - Loader interface v3 differs from v2 in:
2176 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2177 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2178 * because the loader no longer does so.
2180 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);