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
32 #include "anv_private.h"
33 #include "util/strtod.h"
34 #include "util/debug.h"
35 #include "util/build_id.h"
36 #include "util/vk_util.h"
38 #include "genxml/gen7_pack.h"
41 compiler_debug_log(void *data
, const char *fmt
, ...)
45 compiler_perf_log(void *data
, const char *fmt
, ...)
50 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
51 vfprintf(stderr
, fmt
, args
);
57 anv_device_get_cache_uuid(void *uuid
)
59 const struct build_id_note
*note
= build_id_find_nhdr("libvulkan_intel.so");
63 unsigned len
= build_id_length(note
);
64 if (len
< VK_UUID_SIZE
)
67 memcpy(uuid
, build_id_data(note
), VK_UUID_SIZE
);
72 anv_physical_device_init(struct anv_physical_device
*device
,
73 struct anv_instance
*instance
,
79 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
81 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
83 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
84 device
->instance
= instance
;
86 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
87 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
89 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
90 if (!device
->chipset_id
) {
91 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
95 device
->name
= gen_get_device_name(device
->chipset_id
);
96 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
97 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
101 if (device
->info
.is_haswell
) {
102 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
103 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
104 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
105 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
106 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
107 } else if (device
->info
.gen
>= 8) {
108 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
109 * supported as anything */
111 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
112 "Vulkan not yet supported on %s", device
->name
);
116 device
->cmd_parser_version
= -1;
117 if (device
->info
.gen
== 7) {
118 device
->cmd_parser_version
=
119 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
120 if (device
->cmd_parser_version
== -1) {
121 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
122 "failed to get command parser version");
127 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
128 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
129 "failed to get aperture size: %m");
133 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
134 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
135 "kernel missing gem wait");
139 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
140 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
141 "kernel missing execbuf2");
145 if (!device
->info
.has_llc
&&
146 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
147 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
148 "kernel missing wc mmap");
152 if (!anv_device_get_cache_uuid(device
->uuid
)) {
153 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
154 "cannot generate UUID");
157 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
159 /* GENs prior to 8 do not support EU/Subslice info */
160 if (device
->info
.gen
>= 8) {
161 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
162 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
164 /* Without this information, we cannot get the right Braswell
165 * brandstrings, and we have to use conservative numbers for GPGPU on
166 * many platforms, but otherwise, things will just work.
168 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
169 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
170 " query GPU properties.\n");
172 } else if (device
->info
.gen
== 7) {
173 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
176 if (device
->info
.is_cherryview
&&
177 device
->subslice_total
> 0 && device
->eu_total
> 0) {
178 /* Logical CS threads = EUs per subslice * 7 threads per EU */
179 uint32_t max_cs_threads
= device
->eu_total
/ device
->subslice_total
* 7;
181 /* Fuse configurations may give more threads than expected, never less. */
182 if (max_cs_threads
> device
->info
.max_cs_threads
)
183 device
->info
.max_cs_threads
= max_cs_threads
;
186 brw_process_intel_debug_variable();
188 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
189 if (device
->compiler
== NULL
) {
190 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
193 device
->compiler
->shader_debug_log
= compiler_debug_log
;
194 device
->compiler
->shader_perf_log
= compiler_perf_log
;
196 result
= anv_init_wsi(device
);
197 if (result
!= VK_SUCCESS
) {
198 ralloc_free(device
->compiler
);
202 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
204 device
->local_fd
= fd
;
213 anv_physical_device_finish(struct anv_physical_device
*device
)
215 anv_finish_wsi(device
);
216 ralloc_free(device
->compiler
);
217 close(device
->local_fd
);
220 static const VkExtensionProperties global_extensions
[] = {
222 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
225 #ifdef VK_USE_PLATFORM_XCB_KHR
227 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
231 #ifdef VK_USE_PLATFORM_XLIB_KHR
233 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
237 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
239 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
244 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
249 static const VkExtensionProperties device_extensions
[] = {
251 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
255 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
259 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
263 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
267 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
271 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
277 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
278 VkSystemAllocationScope allocationScope
)
284 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
285 size_t align
, VkSystemAllocationScope allocationScope
)
287 return realloc(pOriginal
, size
);
291 default_free_func(void *pUserData
, void *pMemory
)
296 static const VkAllocationCallbacks default_alloc
= {
298 .pfnAllocation
= default_alloc_func
,
299 .pfnReallocation
= default_realloc_func
,
300 .pfnFree
= default_free_func
,
303 VkResult
anv_CreateInstance(
304 const VkInstanceCreateInfo
* pCreateInfo
,
305 const VkAllocationCallbacks
* pAllocator
,
306 VkInstance
* pInstance
)
308 struct anv_instance
*instance
;
310 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
312 uint32_t client_version
;
313 if (pCreateInfo
->pApplicationInfo
&&
314 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
315 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
317 client_version
= VK_MAKE_VERSION(1, 0, 0);
320 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
321 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
322 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
323 "Client requested version %d.%d.%d",
324 VK_VERSION_MAJOR(client_version
),
325 VK_VERSION_MINOR(client_version
),
326 VK_VERSION_PATCH(client_version
));
329 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
331 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
332 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
333 global_extensions
[j
].extensionName
) == 0) {
339 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
342 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
343 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
345 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
347 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
350 instance
->alloc
= *pAllocator
;
352 instance
->alloc
= default_alloc
;
354 instance
->apiVersion
= client_version
;
355 instance
->physicalDeviceCount
= -1;
359 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
361 *pInstance
= anv_instance_to_handle(instance
);
366 void anv_DestroyInstance(
367 VkInstance _instance
,
368 const VkAllocationCallbacks
* pAllocator
)
370 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
375 if (instance
->physicalDeviceCount
> 0) {
376 /* We support at most one physical device. */
377 assert(instance
->physicalDeviceCount
== 1);
378 anv_physical_device_finish(&instance
->physicalDevice
);
381 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
385 vk_free(&instance
->alloc
, instance
);
389 anv_enumerate_devices(struct anv_instance
*instance
)
391 /* TODO: Check for more devices ? */
392 drmDevicePtr devices
[8];
393 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
396 instance
->physicalDeviceCount
= 0;
398 max_devices
= drmGetDevices2(0, devices
, sizeof(devices
));
400 return VK_ERROR_INCOMPATIBLE_DRIVER
;
402 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
403 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
404 devices
[i
]->bustype
== DRM_BUS_PCI
&&
405 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
407 result
= anv_physical_device_init(&instance
->physicalDevice
,
409 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
410 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
415 if (result
== VK_SUCCESS
)
416 instance
->physicalDeviceCount
= 1;
422 VkResult
anv_EnumeratePhysicalDevices(
423 VkInstance _instance
,
424 uint32_t* pPhysicalDeviceCount
,
425 VkPhysicalDevice
* pPhysicalDevices
)
427 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
428 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
431 if (instance
->physicalDeviceCount
< 0) {
432 result
= anv_enumerate_devices(instance
);
433 if (result
!= VK_SUCCESS
&&
434 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
438 if (instance
->physicalDeviceCount
> 0) {
439 assert(instance
->physicalDeviceCount
== 1);
440 vk_outarray_append(&out
, i
) {
441 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
445 return vk_outarray_status(&out
);
448 void anv_GetPhysicalDeviceFeatures(
449 VkPhysicalDevice physicalDevice
,
450 VkPhysicalDeviceFeatures
* pFeatures
)
452 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
454 *pFeatures
= (VkPhysicalDeviceFeatures
) {
455 .robustBufferAccess
= true,
456 .fullDrawIndexUint32
= true,
457 .imageCubeArray
= true,
458 .independentBlend
= true,
459 .geometryShader
= true,
460 .tessellationShader
= true,
461 .sampleRateShading
= true,
462 .dualSrcBlend
= true,
464 .multiDrawIndirect
= false,
465 .drawIndirectFirstInstance
= true,
467 .depthBiasClamp
= true,
468 .fillModeNonSolid
= true,
469 .depthBounds
= false,
473 .multiViewport
= true,
474 .samplerAnisotropy
= true,
475 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
476 pdevice
->info
.is_baytrail
,
477 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
478 .textureCompressionBC
= true,
479 .occlusionQueryPrecise
= true,
480 .pipelineStatisticsQuery
= false,
481 .fragmentStoresAndAtomics
= true,
482 .shaderTessellationAndGeometryPointSize
= true,
483 .shaderImageGatherExtended
= true,
484 .shaderStorageImageExtendedFormats
= true,
485 .shaderStorageImageMultisample
= false,
486 .shaderStorageImageReadWithoutFormat
= false,
487 .shaderStorageImageWriteWithoutFormat
= true,
488 .shaderUniformBufferArrayDynamicIndexing
= true,
489 .shaderSampledImageArrayDynamicIndexing
= true,
490 .shaderStorageBufferArrayDynamicIndexing
= true,
491 .shaderStorageImageArrayDynamicIndexing
= true,
492 .shaderClipDistance
= true,
493 .shaderCullDistance
= true,
494 .shaderFloat64
= pdevice
->info
.gen
>= 8,
495 .shaderInt64
= pdevice
->info
.gen
>= 8,
496 .shaderInt16
= false,
497 .shaderResourceMinLod
= false,
498 .variableMultisampleRate
= false,
499 .inheritedQueries
= false,
502 /* We can't do image stores in vec4 shaders */
503 pFeatures
->vertexPipelineStoresAndAtomics
=
504 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
505 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
508 void anv_GetPhysicalDeviceFeatures2KHR(
509 VkPhysicalDevice physicalDevice
,
510 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
512 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
514 vk_foreach_struct(ext
, pFeatures
->pNext
) {
515 switch (ext
->sType
) {
516 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
517 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
518 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
520 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
525 anv_debug_ignored_stype(ext
->sType
);
531 void anv_GetPhysicalDeviceProperties(
532 VkPhysicalDevice physicalDevice
,
533 VkPhysicalDeviceProperties
* pProperties
)
535 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
536 const struct gen_device_info
*devinfo
= &pdevice
->info
;
538 /* See assertions made when programming the buffer surface state. */
539 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
540 (1ul << 30) : (1ul << 27);
542 VkSampleCountFlags sample_counts
=
543 isl_device_get_sample_counts(&pdevice
->isl_dev
);
545 VkPhysicalDeviceLimits limits
= {
546 .maxImageDimension1D
= (1 << 14),
547 .maxImageDimension2D
= (1 << 14),
548 .maxImageDimension3D
= (1 << 11),
549 .maxImageDimensionCube
= (1 << 14),
550 .maxImageArrayLayers
= (1 << 11),
551 .maxTexelBufferElements
= 128 * 1024 * 1024,
552 .maxUniformBufferRange
= (1ul << 27),
553 .maxStorageBufferRange
= max_raw_buffer_sz
,
554 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
555 .maxMemoryAllocationCount
= UINT32_MAX
,
556 .maxSamplerAllocationCount
= 64 * 1024,
557 .bufferImageGranularity
= 64, /* A cache line */
558 .sparseAddressSpaceSize
= 0,
559 .maxBoundDescriptorSets
= MAX_SETS
,
560 .maxPerStageDescriptorSamplers
= 64,
561 .maxPerStageDescriptorUniformBuffers
= 64,
562 .maxPerStageDescriptorStorageBuffers
= 64,
563 .maxPerStageDescriptorSampledImages
= 64,
564 .maxPerStageDescriptorStorageImages
= 64,
565 .maxPerStageDescriptorInputAttachments
= 64,
566 .maxPerStageResources
= 128,
567 .maxDescriptorSetSamplers
= 256,
568 .maxDescriptorSetUniformBuffers
= 256,
569 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
570 .maxDescriptorSetStorageBuffers
= 256,
571 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
572 .maxDescriptorSetSampledImages
= 256,
573 .maxDescriptorSetStorageImages
= 256,
574 .maxDescriptorSetInputAttachments
= 256,
575 .maxVertexInputAttributes
= MAX_VBS
,
576 .maxVertexInputBindings
= MAX_VBS
,
577 .maxVertexInputAttributeOffset
= 2047,
578 .maxVertexInputBindingStride
= 2048,
579 .maxVertexOutputComponents
= 128,
580 .maxTessellationGenerationLevel
= 64,
581 .maxTessellationPatchSize
= 32,
582 .maxTessellationControlPerVertexInputComponents
= 128,
583 .maxTessellationControlPerVertexOutputComponents
= 128,
584 .maxTessellationControlPerPatchOutputComponents
= 128,
585 .maxTessellationControlTotalOutputComponents
= 2048,
586 .maxTessellationEvaluationInputComponents
= 128,
587 .maxTessellationEvaluationOutputComponents
= 128,
588 .maxGeometryShaderInvocations
= 32,
589 .maxGeometryInputComponents
= 64,
590 .maxGeometryOutputComponents
= 128,
591 .maxGeometryOutputVertices
= 256,
592 .maxGeometryTotalOutputComponents
= 1024,
593 .maxFragmentInputComponents
= 128,
594 .maxFragmentOutputAttachments
= 8,
595 .maxFragmentDualSrcAttachments
= 1,
596 .maxFragmentCombinedOutputResources
= 8,
597 .maxComputeSharedMemorySize
= 32768,
598 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
599 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
600 .maxComputeWorkGroupSize
= {
601 16 * devinfo
->max_cs_threads
,
602 16 * devinfo
->max_cs_threads
,
603 16 * devinfo
->max_cs_threads
,
605 .subPixelPrecisionBits
= 4 /* FIXME */,
606 .subTexelPrecisionBits
= 4 /* FIXME */,
607 .mipmapPrecisionBits
= 4 /* FIXME */,
608 .maxDrawIndexedIndexValue
= UINT32_MAX
,
609 .maxDrawIndirectCount
= UINT32_MAX
,
610 .maxSamplerLodBias
= 16,
611 .maxSamplerAnisotropy
= 16,
612 .maxViewports
= MAX_VIEWPORTS
,
613 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
614 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
615 .viewportSubPixelBits
= 13, /* We take a float? */
616 .minMemoryMapAlignment
= 4096, /* A page */
617 .minTexelBufferOffsetAlignment
= 1,
618 .minUniformBufferOffsetAlignment
= 16,
619 .minStorageBufferOffsetAlignment
= 4,
620 .minTexelOffset
= -8,
622 .minTexelGatherOffset
= -32,
623 .maxTexelGatherOffset
= 31,
624 .minInterpolationOffset
= -0.5,
625 .maxInterpolationOffset
= 0.4375,
626 .subPixelInterpolationOffsetBits
= 4,
627 .maxFramebufferWidth
= (1 << 14),
628 .maxFramebufferHeight
= (1 << 14),
629 .maxFramebufferLayers
= (1 << 11),
630 .framebufferColorSampleCounts
= sample_counts
,
631 .framebufferDepthSampleCounts
= sample_counts
,
632 .framebufferStencilSampleCounts
= sample_counts
,
633 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
634 .maxColorAttachments
= MAX_RTS
,
635 .sampledImageColorSampleCounts
= sample_counts
,
636 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
637 .sampledImageDepthSampleCounts
= sample_counts
,
638 .sampledImageStencilSampleCounts
= sample_counts
,
639 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
640 .maxSampleMaskWords
= 1,
641 .timestampComputeAndGraphics
= false,
642 .timestampPeriod
= devinfo
->timebase_scale
,
643 .maxClipDistances
= 8,
644 .maxCullDistances
= 8,
645 .maxCombinedClipAndCullDistances
= 8,
646 .discreteQueuePriorities
= 1,
647 .pointSizeRange
= { 0.125, 255.875 },
648 .lineWidthRange
= { 0.0, 7.9921875 },
649 .pointSizeGranularity
= (1.0 / 8.0),
650 .lineWidthGranularity
= (1.0 / 128.0),
651 .strictLines
= false, /* FINISHME */
652 .standardSampleLocations
= true,
653 .optimalBufferCopyOffsetAlignment
= 128,
654 .optimalBufferCopyRowPitchAlignment
= 128,
655 .nonCoherentAtomSize
= 64,
658 *pProperties
= (VkPhysicalDeviceProperties
) {
659 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
662 .deviceID
= pdevice
->chipset_id
,
663 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
665 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
668 strcpy(pProperties
->deviceName
, pdevice
->name
);
669 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
672 void anv_GetPhysicalDeviceProperties2KHR(
673 VkPhysicalDevice physicalDevice
,
674 VkPhysicalDeviceProperties2KHR
* pProperties
)
676 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
678 vk_foreach_struct(ext
, pProperties
->pNext
) {
679 switch (ext
->sType
) {
681 anv_debug_ignored_stype(ext
->sType
);
687 /* We support exactly one queue family. */
688 static const VkQueueFamilyProperties
689 anv_queue_family_properties
= {
690 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
691 VK_QUEUE_COMPUTE_BIT
|
692 VK_QUEUE_TRANSFER_BIT
,
694 .timestampValidBits
= 36, /* XXX: Real value here */
695 .minImageTransferGranularity
= { 1, 1, 1 },
698 void anv_GetPhysicalDeviceQueueFamilyProperties(
699 VkPhysicalDevice physicalDevice
,
701 VkQueueFamilyProperties
* pQueueFamilyProperties
)
703 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
705 vk_outarray_append(&out
, p
) {
706 *p
= anv_queue_family_properties
;
710 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
711 VkPhysicalDevice physicalDevice
,
712 uint32_t* pQueueFamilyPropertyCount
,
713 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
716 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
718 vk_outarray_append(&out
, p
) {
719 p
->queueFamilyProperties
= anv_queue_family_properties
;
721 vk_foreach_struct(s
, p
->pNext
) {
722 anv_debug_ignored_stype(s
->sType
);
727 void anv_GetPhysicalDeviceMemoryProperties(
728 VkPhysicalDevice physicalDevice
,
729 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
731 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
732 VkDeviceSize heap_size
;
734 /* Reserve some wiggle room for the driver by exposing only 75% of the
735 * aperture to the heap.
737 heap_size
= 3 * physical_device
->aperture_size
/ 4;
739 if (physical_device
->info
.has_llc
) {
740 /* Big core GPUs share LLC with the CPU and thus one memory type can be
741 * both cached and coherent at the same time.
743 pMemoryProperties
->memoryTypeCount
= 1;
744 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
745 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
746 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
747 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
748 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
752 /* The spec requires that we expose a host-visible, coherent memory
753 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
754 * to give the application a choice between cached, but not coherent and
755 * coherent but uncached (WC though).
757 pMemoryProperties
->memoryTypeCount
= 2;
758 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
759 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
760 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
761 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
764 pMemoryProperties
->memoryTypes
[1] = (VkMemoryType
) {
765 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
766 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
767 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
772 pMemoryProperties
->memoryHeapCount
= 1;
773 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
775 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
779 void anv_GetPhysicalDeviceMemoryProperties2KHR(
780 VkPhysicalDevice physicalDevice
,
781 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
783 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
784 &pMemoryProperties
->memoryProperties
);
786 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
787 switch (ext
->sType
) {
789 anv_debug_ignored_stype(ext
->sType
);
795 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
799 return anv_lookup_entrypoint(NULL
, pName
);
802 /* With version 1+ of the loader interface the ICD should expose
803 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
806 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
811 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
815 return anv_GetInstanceProcAddr(instance
, pName
);
818 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
822 ANV_FROM_HANDLE(anv_device
, device
, _device
);
823 return anv_lookup_entrypoint(&device
->info
, pName
);
827 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
829 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
830 queue
->device
= device
;
831 queue
->pool
= &device
->surface_state_pool
;
835 anv_queue_finish(struct anv_queue
*queue
)
839 static struct anv_state
840 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
842 struct anv_state state
;
844 state
= anv_state_pool_alloc(pool
, size
, align
);
845 memcpy(state
.map
, p
, size
);
847 anv_state_flush(pool
->block_pool
->device
, state
);
852 struct gen8_border_color
{
857 /* Pad out to 64 bytes */
862 anv_device_init_border_colors(struct anv_device
*device
)
864 static const struct gen8_border_color border_colors
[] = {
865 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
866 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
867 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
868 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
869 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
870 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
873 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
874 sizeof(border_colors
), 64,
879 anv_device_submit_simple_batch(struct anv_device
*device
,
880 struct anv_batch
*batch
)
882 struct drm_i915_gem_execbuffer2 execbuf
;
883 struct drm_i915_gem_exec_object2 exec2_objects
[1];
884 struct anv_bo bo
, *exec_bos
[1];
885 VkResult result
= VK_SUCCESS
;
890 /* Kernel driver requires 8 byte aligned batch length */
891 size
= align_u32(batch
->next
- batch
->start
, 8);
892 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bo
, size
);
893 if (result
!= VK_SUCCESS
)
896 memcpy(bo
.map
, batch
->start
, size
);
897 if (!device
->info
.has_llc
)
898 anv_flush_range(bo
.map
, size
);
901 exec2_objects
[0].handle
= bo
.gem_handle
;
902 exec2_objects
[0].relocation_count
= 0;
903 exec2_objects
[0].relocs_ptr
= 0;
904 exec2_objects
[0].alignment
= 0;
905 exec2_objects
[0].offset
= bo
.offset
;
906 exec2_objects
[0].flags
= 0;
907 exec2_objects
[0].rsvd1
= 0;
908 exec2_objects
[0].rsvd2
= 0;
910 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
911 execbuf
.buffer_count
= 1;
912 execbuf
.batch_start_offset
= 0;
913 execbuf
.batch_len
= size
;
914 execbuf
.cliprects_ptr
= 0;
915 execbuf
.num_cliprects
= 0;
920 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
921 execbuf
.rsvd1
= device
->context_id
;
924 result
= anv_device_execbuf(device
, &execbuf
, exec_bos
);
925 if (result
!= VK_SUCCESS
)
929 ret
= anv_gem_wait(device
, bo
.gem_handle
, &timeout
);
931 /* We don't know the real error. */
932 result
= vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
937 anv_bo_pool_free(&device
->batch_bo_pool
, &bo
);
942 VkResult
anv_CreateDevice(
943 VkPhysicalDevice physicalDevice
,
944 const VkDeviceCreateInfo
* pCreateInfo
,
945 const VkAllocationCallbacks
* pAllocator
,
948 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
950 struct anv_device
*device
;
952 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
954 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
956 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
957 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
958 device_extensions
[j
].extensionName
) == 0) {
964 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
967 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
969 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
971 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
973 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
974 device
->instance
= physical_device
->instance
;
975 device
->chipset_id
= physical_device
->chipset_id
;
978 device
->alloc
= *pAllocator
;
980 device
->alloc
= physical_device
->instance
->alloc
;
982 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
983 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
984 if (device
->fd
== -1) {
985 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
989 device
->context_id
= anv_gem_create_context(device
);
990 if (device
->context_id
== -1) {
991 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
995 device
->info
= physical_device
->info
;
996 device
->isl_dev
= physical_device
->isl_dev
;
998 /* On Broadwell and later, we can use batch chaining to more efficiently
999 * implement growing command buffers. Prior to Haswell, the kernel
1000 * command parser gets in the way and we have to fall back to growing
1003 device
->can_chain_batches
= device
->info
.gen
>= 8;
1005 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1006 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1008 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1009 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1010 goto fail_context_id
;
1013 pthread_condattr_t condattr
;
1014 if (pthread_condattr_init(&condattr
) != 0) {
1015 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1018 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1019 pthread_condattr_destroy(&condattr
);
1020 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1023 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1024 pthread_condattr_destroy(&condattr
);
1025 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1028 pthread_condattr_destroy(&condattr
);
1030 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1032 result
= anv_block_pool_init(&device
->dynamic_state_block_pool
, device
,
1034 if (result
!= VK_SUCCESS
)
1035 goto fail_batch_bo_pool
;
1037 anv_state_pool_init(&device
->dynamic_state_pool
,
1038 &device
->dynamic_state_block_pool
);
1040 result
= anv_block_pool_init(&device
->instruction_block_pool
, device
,
1042 if (result
!= VK_SUCCESS
)
1043 goto fail_dynamic_state_pool
;
1045 anv_state_pool_init(&device
->instruction_state_pool
,
1046 &device
->instruction_block_pool
);
1048 result
= anv_block_pool_init(&device
->surface_state_block_pool
, device
,
1050 if (result
!= VK_SUCCESS
)
1051 goto fail_instruction_state_pool
;
1053 anv_state_pool_init(&device
->surface_state_pool
,
1054 &device
->surface_state_block_pool
);
1056 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1057 if (result
!= VK_SUCCESS
)
1058 goto fail_surface_state_pool
;
1060 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1062 anv_queue_init(device
, &device
->queue
);
1064 switch (device
->info
.gen
) {
1066 if (!device
->info
.is_haswell
)
1067 result
= gen7_init_device_state(device
);
1069 result
= gen75_init_device_state(device
);
1072 result
= gen8_init_device_state(device
);
1075 result
= gen9_init_device_state(device
);
1078 /* Shouldn't get here as we don't create physical devices for any other
1080 unreachable("unhandled gen");
1082 if (result
!= VK_SUCCESS
)
1083 goto fail_workaround_bo
;
1085 anv_device_init_blorp(device
);
1087 anv_device_init_border_colors(device
);
1089 *pDevice
= anv_device_to_handle(device
);
1094 anv_queue_finish(&device
->queue
);
1095 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1096 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1097 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1098 fail_surface_state_pool
:
1099 anv_state_pool_finish(&device
->surface_state_pool
);
1100 anv_block_pool_finish(&device
->surface_state_block_pool
);
1101 fail_instruction_state_pool
:
1102 anv_state_pool_finish(&device
->instruction_state_pool
);
1103 anv_block_pool_finish(&device
->instruction_block_pool
);
1104 fail_dynamic_state_pool
:
1105 anv_state_pool_finish(&device
->dynamic_state_pool
);
1106 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
1108 anv_bo_pool_finish(&device
->batch_bo_pool
);
1109 pthread_cond_destroy(&device
->queue_submit
);
1111 pthread_mutex_destroy(&device
->mutex
);
1113 anv_gem_destroy_context(device
, device
->context_id
);
1117 vk_free(&device
->alloc
, device
);
1122 void anv_DestroyDevice(
1124 const VkAllocationCallbacks
* pAllocator
)
1126 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1131 anv_device_finish_blorp(device
);
1133 anv_queue_finish(&device
->queue
);
1135 #ifdef HAVE_VALGRIND
1136 /* We only need to free these to prevent valgrind errors. The backing
1137 * BO will go away in a couple of lines so we don't actually leak.
1139 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1142 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1144 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1145 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1147 anv_state_pool_finish(&device
->surface_state_pool
);
1148 anv_block_pool_finish(&device
->surface_state_block_pool
);
1149 anv_state_pool_finish(&device
->instruction_state_pool
);
1150 anv_block_pool_finish(&device
->instruction_block_pool
);
1151 anv_state_pool_finish(&device
->dynamic_state_pool
);
1152 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
1154 anv_bo_pool_finish(&device
->batch_bo_pool
);
1156 pthread_cond_destroy(&device
->queue_submit
);
1157 pthread_mutex_destroy(&device
->mutex
);
1159 anv_gem_destroy_context(device
, device
->context_id
);
1163 vk_free(&device
->alloc
, device
);
1166 VkResult
anv_EnumerateInstanceExtensionProperties(
1167 const char* pLayerName
,
1168 uint32_t* pPropertyCount
,
1169 VkExtensionProperties
* pProperties
)
1171 if (pProperties
== NULL
) {
1172 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1176 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1177 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1179 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1180 return VK_INCOMPLETE
;
1185 VkResult
anv_EnumerateDeviceExtensionProperties(
1186 VkPhysicalDevice physicalDevice
,
1187 const char* pLayerName
,
1188 uint32_t* pPropertyCount
,
1189 VkExtensionProperties
* pProperties
)
1191 if (pProperties
== NULL
) {
1192 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1196 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1197 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1199 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1200 return VK_INCOMPLETE
;
1205 VkResult
anv_EnumerateInstanceLayerProperties(
1206 uint32_t* pPropertyCount
,
1207 VkLayerProperties
* pProperties
)
1209 if (pProperties
== NULL
) {
1210 *pPropertyCount
= 0;
1214 /* None supported at this time */
1215 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1218 VkResult
anv_EnumerateDeviceLayerProperties(
1219 VkPhysicalDevice physicalDevice
,
1220 uint32_t* pPropertyCount
,
1221 VkLayerProperties
* pProperties
)
1223 if (pProperties
== NULL
) {
1224 *pPropertyCount
= 0;
1228 /* None supported at this time */
1229 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1232 void anv_GetDeviceQueue(
1234 uint32_t queueNodeIndex
,
1235 uint32_t queueIndex
,
1238 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1240 assert(queueIndex
== 0);
1242 *pQueue
= anv_queue_to_handle(&device
->queue
);
1246 anv_device_execbuf(struct anv_device
*device
,
1247 struct drm_i915_gem_execbuffer2
*execbuf
,
1248 struct anv_bo
**execbuf_bos
)
1250 int ret
= anv_gem_execbuffer(device
, execbuf
);
1252 /* We don't know the real error. */
1253 return vk_errorf(VK_ERROR_DEVICE_LOST
, "execbuf2 failed: %m");
1256 struct drm_i915_gem_exec_object2
*objects
=
1257 (void *)(uintptr_t)execbuf
->buffers_ptr
;
1258 for (uint32_t k
= 0; k
< execbuf
->buffer_count
; k
++)
1259 execbuf_bos
[k
]->offset
= objects
[k
].offset
;
1264 VkResult
anv_QueueSubmit(
1266 uint32_t submitCount
,
1267 const VkSubmitInfo
* pSubmits
,
1270 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1271 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1272 struct anv_device
*device
= queue
->device
;
1273 VkResult result
= VK_SUCCESS
;
1275 /* We lock around QueueSubmit for three main reasons:
1277 * 1) When a block pool is resized, we create a new gem handle with a
1278 * different size and, in the case of surface states, possibly a
1279 * different center offset but we re-use the same anv_bo struct when
1280 * we do so. If this happens in the middle of setting up an execbuf,
1281 * we could end up with our list of BOs out of sync with our list of
1284 * 2) The algorithm we use for building the list of unique buffers isn't
1285 * thread-safe. While the client is supposed to syncronize around
1286 * QueueSubmit, this would be extremely difficult to debug if it ever
1287 * came up in the wild due to a broken app. It's better to play it
1288 * safe and just lock around QueueSubmit.
1290 * 3) The anv_cmd_buffer_execbuf function may perform relocations in
1291 * userspace. Due to the fact that the surface state buffer is shared
1292 * between batches, we can't afford to have that happen from multiple
1293 * threads at the same time. Even though the user is supposed to
1294 * ensure this doesn't happen, we play it safe as in (2) above.
1296 * Since the only other things that ever take the device lock such as block
1297 * pool resize only rarely happen, this will almost never be contended so
1298 * taking a lock isn't really an expensive operation in this case.
1300 pthread_mutex_lock(&device
->mutex
);
1302 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1303 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1304 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
1305 pSubmits
[i
].pCommandBuffers
[j
]);
1306 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1307 assert(!anv_batch_has_error(&cmd_buffer
->batch
));
1309 result
= anv_cmd_buffer_execbuf(device
, cmd_buffer
);
1310 if (result
!= VK_SUCCESS
)
1316 struct anv_bo
*fence_bo
= &fence
->bo
;
1317 result
= anv_device_execbuf(device
, &fence
->execbuf
, &fence_bo
);
1318 if (result
!= VK_SUCCESS
)
1321 /* Update the fence and wake up any waiters */
1322 assert(fence
->state
== ANV_FENCE_STATE_RESET
);
1323 fence
->state
= ANV_FENCE_STATE_SUBMITTED
;
1324 pthread_cond_broadcast(&device
->queue_submit
);
1328 pthread_mutex_unlock(&device
->mutex
);
1333 VkResult
anv_QueueWaitIdle(
1336 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1338 return anv_DeviceWaitIdle(anv_device_to_handle(queue
->device
));
1341 VkResult
anv_DeviceWaitIdle(
1344 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1345 struct anv_batch batch
;
1348 batch
.start
= batch
.next
= cmds
;
1349 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1351 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1352 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1354 return anv_device_submit_simple_batch(device
, &batch
);
1358 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1360 uint32_t gem_handle
= anv_gem_create(device
, size
);
1362 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1364 anv_bo_init(bo
, gem_handle
, size
);
1369 VkResult
anv_AllocateMemory(
1371 const VkMemoryAllocateInfo
* pAllocateInfo
,
1372 const VkAllocationCallbacks
* pAllocator
,
1373 VkDeviceMemory
* pMem
)
1375 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1376 struct anv_device_memory
*mem
;
1379 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1381 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1382 assert(pAllocateInfo
->allocationSize
> 0);
1384 /* We support exactly one memory heap. */
1385 assert(pAllocateInfo
->memoryTypeIndex
== 0 ||
1386 (!device
->info
.has_llc
&& pAllocateInfo
->memoryTypeIndex
< 2));
1388 /* FINISHME: Fail if allocation request exceeds heap size. */
1390 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1391 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1393 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1395 /* The kernel is going to give us whole pages anyway */
1396 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1398 result
= anv_bo_init_new(&mem
->bo
, device
, alloc_size
);
1399 if (result
!= VK_SUCCESS
)
1402 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1407 *pMem
= anv_device_memory_to_handle(mem
);
1412 vk_free2(&device
->alloc
, pAllocator
, mem
);
1417 void anv_FreeMemory(
1419 VkDeviceMemory _mem
,
1420 const VkAllocationCallbacks
* pAllocator
)
1422 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1423 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1429 anv_UnmapMemory(_device
, _mem
);
1432 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1434 if (mem
->bo
.gem_handle
!= 0)
1435 anv_gem_close(device
, mem
->bo
.gem_handle
);
1437 vk_free2(&device
->alloc
, pAllocator
, mem
);
1440 VkResult
anv_MapMemory(
1442 VkDeviceMemory _memory
,
1443 VkDeviceSize offset
,
1445 VkMemoryMapFlags flags
,
1448 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1449 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1456 if (size
== VK_WHOLE_SIZE
)
1457 size
= mem
->bo
.size
- offset
;
1459 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1461 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1462 * assert(size != 0);
1463 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1464 * equal to the size of the memory minus offset
1467 assert(offset
+ size
<= mem
->bo
.size
);
1469 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1470 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1471 * at a time is valid. We could just mmap up front and return an offset
1472 * pointer here, but that may exhaust virtual memory on 32 bit
1475 uint32_t gem_flags
= 0;
1476 if (!device
->info
.has_llc
&& mem
->type_index
== 0)
1477 gem_flags
|= I915_MMAP_WC
;
1479 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1480 uint64_t map_offset
= offset
& ~4095ull;
1481 assert(offset
>= map_offset
);
1482 uint64_t map_size
= (offset
+ size
) - map_offset
;
1484 /* Let's map whole pages */
1485 map_size
= align_u64(map_size
, 4096);
1487 void *map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
,
1488 map_offset
, map_size
, gem_flags
);
1489 if (map
== MAP_FAILED
)
1490 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1493 mem
->map_size
= map_size
;
1495 *ppData
= mem
->map
+ (offset
- map_offset
);
1500 void anv_UnmapMemory(
1502 VkDeviceMemory _memory
)
1504 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1509 anv_gem_munmap(mem
->map
, mem
->map_size
);
1516 clflush_mapped_ranges(struct anv_device
*device
,
1518 const VkMappedMemoryRange
*ranges
)
1520 for (uint32_t i
= 0; i
< count
; i
++) {
1521 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1522 if (ranges
[i
].offset
>= mem
->map_size
)
1525 anv_clflush_range(mem
->map
+ ranges
[i
].offset
,
1526 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1530 VkResult
anv_FlushMappedMemoryRanges(
1532 uint32_t memoryRangeCount
,
1533 const VkMappedMemoryRange
* pMemoryRanges
)
1535 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1537 if (device
->info
.has_llc
)
1540 /* Make sure the writes we're flushing have landed. */
1541 __builtin_ia32_mfence();
1543 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1548 VkResult
anv_InvalidateMappedMemoryRanges(
1550 uint32_t memoryRangeCount
,
1551 const VkMappedMemoryRange
* pMemoryRanges
)
1553 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1555 if (device
->info
.has_llc
)
1558 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1560 /* Make sure no reads get moved up above the invalidate. */
1561 __builtin_ia32_mfence();
1566 void anv_GetBufferMemoryRequirements(
1569 VkMemoryRequirements
* pMemoryRequirements
)
1571 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1572 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1574 /* The Vulkan spec (git aaed022) says:
1576 * memoryTypeBits is a bitfield and contains one bit set for every
1577 * supported memory type for the resource. The bit `1<<i` is set if and
1578 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1579 * structure for the physical device is supported.
1581 * We support exactly one memory type on LLC, two on non-LLC.
1583 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1585 pMemoryRequirements
->size
= buffer
->size
;
1586 pMemoryRequirements
->alignment
= 16;
1589 void anv_GetImageMemoryRequirements(
1592 VkMemoryRequirements
* pMemoryRequirements
)
1594 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1595 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1597 /* The Vulkan spec (git aaed022) says:
1599 * memoryTypeBits is a bitfield and contains one bit set for every
1600 * supported memory type for the resource. The bit `1<<i` is set if and
1601 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1602 * structure for the physical device is supported.
1604 * We support exactly one memory type on LLC, two on non-LLC.
1606 pMemoryRequirements
->memoryTypeBits
= device
->info
.has_llc
? 1 : 3;
1608 pMemoryRequirements
->size
= image
->size
;
1609 pMemoryRequirements
->alignment
= image
->alignment
;
1612 void anv_GetImageSparseMemoryRequirements(
1615 uint32_t* pSparseMemoryRequirementCount
,
1616 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1618 *pSparseMemoryRequirementCount
= 0;
1621 void anv_GetDeviceMemoryCommitment(
1623 VkDeviceMemory memory
,
1624 VkDeviceSize
* pCommittedMemoryInBytes
)
1626 *pCommittedMemoryInBytes
= 0;
1629 VkResult
anv_BindBufferMemory(
1632 VkDeviceMemory _memory
,
1633 VkDeviceSize memoryOffset
)
1635 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1636 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1639 buffer
->bo
= &mem
->bo
;
1640 buffer
->offset
= memoryOffset
;
1649 VkResult
anv_QueueBindSparse(
1651 uint32_t bindInfoCount
,
1652 const VkBindSparseInfo
* pBindInfo
,
1655 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1658 VkResult
anv_CreateFence(
1660 const VkFenceCreateInfo
* pCreateInfo
,
1661 const VkAllocationCallbacks
* pAllocator
,
1664 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1665 struct anv_bo fence_bo
;
1666 struct anv_fence
*fence
;
1667 struct anv_batch batch
;
1670 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1672 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &fence_bo
, 4096);
1673 if (result
!= VK_SUCCESS
)
1676 /* Fences are small. Just store the CPU data structure in the BO. */
1677 fence
= fence_bo
.map
;
1678 fence
->bo
= fence_bo
;
1680 /* Place the batch after the CPU data but on its own cache line. */
1681 const uint32_t batch_offset
= align_u32(sizeof(*fence
), CACHELINE_SIZE
);
1682 batch
.next
= batch
.start
= fence
->bo
.map
+ batch_offset
;
1683 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1684 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1685 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1687 if (!device
->info
.has_llc
) {
1688 assert(((uintptr_t) batch
.start
& CACHELINE_MASK
) == 0);
1689 assert(batch
.next
- batch
.start
<= CACHELINE_SIZE
);
1690 __builtin_ia32_mfence();
1691 __builtin_ia32_clflush(batch
.start
);
1694 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1695 fence
->exec2_objects
[0].relocation_count
= 0;
1696 fence
->exec2_objects
[0].relocs_ptr
= 0;
1697 fence
->exec2_objects
[0].alignment
= 0;
1698 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1699 fence
->exec2_objects
[0].flags
= 0;
1700 fence
->exec2_objects
[0].rsvd1
= 0;
1701 fence
->exec2_objects
[0].rsvd2
= 0;
1703 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1704 fence
->execbuf
.buffer_count
= 1;
1705 fence
->execbuf
.batch_start_offset
= batch
.start
- fence
->bo
.map
;
1706 fence
->execbuf
.batch_len
= batch
.next
- batch
.start
;
1707 fence
->execbuf
.cliprects_ptr
= 0;
1708 fence
->execbuf
.num_cliprects
= 0;
1709 fence
->execbuf
.DR1
= 0;
1710 fence
->execbuf
.DR4
= 0;
1712 fence
->execbuf
.flags
=
1713 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1714 fence
->execbuf
.rsvd1
= device
->context_id
;
1715 fence
->execbuf
.rsvd2
= 0;
1717 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
1718 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1720 fence
->state
= ANV_FENCE_STATE_RESET
;
1723 *pFence
= anv_fence_to_handle(fence
);
1728 void anv_DestroyFence(
1731 const VkAllocationCallbacks
* pAllocator
)
1733 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1734 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1739 assert(fence
->bo
.map
== fence
);
1740 anv_bo_pool_free(&device
->batch_bo_pool
, &fence
->bo
);
1743 VkResult
anv_ResetFences(
1745 uint32_t fenceCount
,
1746 const VkFence
* pFences
)
1748 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1749 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1750 fence
->state
= ANV_FENCE_STATE_RESET
;
1756 VkResult
anv_GetFenceStatus(
1760 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1761 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1765 switch (fence
->state
) {
1766 case ANV_FENCE_STATE_RESET
:
1767 /* If it hasn't even been sent off to the GPU yet, it's not ready */
1768 return VK_NOT_READY
;
1770 case ANV_FENCE_STATE_SIGNALED
:
1771 /* It's been signaled, return success */
1774 case ANV_FENCE_STATE_SUBMITTED
:
1775 /* It's been submitted to the GPU but we don't know if it's done yet. */
1776 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1778 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1781 return VK_NOT_READY
;
1784 unreachable("Invalid fence status");
1788 #define NSEC_PER_SEC 1000000000
1789 #define INT_TYPE_MAX(type) ((1ull << (sizeof(type) * 8 - 1)) - 1)
1791 VkResult
anv_WaitForFences(
1793 uint32_t fenceCount
,
1794 const VkFence
* pFences
,
1798 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1801 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1802 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1803 * for a couple of kernel releases. Since there's no way to know
1804 * whether or not the kernel we're using is one of the broken ones, the
1805 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1806 * maximum timeout from 584 years to 292 years - likely not a big deal.
1808 int64_t timeout
= MIN2(_timeout
, INT64_MAX
);
1810 uint32_t pending_fences
= fenceCount
;
1811 while (pending_fences
) {
1813 bool signaled_fences
= false;
1814 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1815 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1816 switch (fence
->state
) {
1817 case ANV_FENCE_STATE_RESET
:
1818 /* This fence hasn't been submitted yet, we'll catch it the next
1819 * time around. Yes, this may mean we dead-loop but, short of
1820 * lots of locking and a condition variable, there's not much that
1821 * we can do about that.
1826 case ANV_FENCE_STATE_SIGNALED
:
1827 /* This fence is not pending. If waitAll isn't set, we can return
1828 * early. Otherwise, we have to keep going.
1834 case ANV_FENCE_STATE_SUBMITTED
:
1835 /* These are the fences we really care about. Go ahead and wait
1836 * on it until we hit a timeout.
1838 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &timeout
);
1839 if (ret
== -1 && errno
== ETIME
) {
1841 } else if (ret
== -1) {
1842 /* We don't know the real error. */
1843 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1845 fence
->state
= ANV_FENCE_STATE_SIGNALED
;
1846 signaled_fences
= true;
1854 if (pending_fences
&& !signaled_fences
) {
1855 /* If we've hit this then someone decided to vkWaitForFences before
1856 * they've actually submitted any of them to a queue. This is a
1857 * fairly pessimal case, so it's ok to lock here and use a standard
1858 * pthreads condition variable.
1860 pthread_mutex_lock(&device
->mutex
);
1862 /* It's possible that some of the fences have changed state since the
1863 * last time we checked. Now that we have the lock, check for
1864 * pending fences again and don't wait if it's changed.
1866 uint32_t now_pending_fences
= 0;
1867 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1868 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1869 if (fence
->state
== ANV_FENCE_STATE_RESET
)
1870 now_pending_fences
++;
1872 assert(now_pending_fences
<= pending_fences
);
1874 if (now_pending_fences
== pending_fences
) {
1875 struct timespec before
;
1876 clock_gettime(CLOCK_MONOTONIC
, &before
);
1878 uint32_t abs_nsec
= before
.tv_nsec
+ timeout
% NSEC_PER_SEC
;
1879 uint64_t abs_sec
= before
.tv_sec
+ (abs_nsec
/ NSEC_PER_SEC
) +
1880 (timeout
/ NSEC_PER_SEC
);
1881 abs_nsec
%= NSEC_PER_SEC
;
1883 /* Avoid roll-over in tv_sec on 32-bit systems if the user
1884 * provided timeout is UINT64_MAX
1886 struct timespec abstime
;
1887 abstime
.tv_nsec
= abs_nsec
;
1888 abstime
.tv_sec
= MIN2(abs_sec
, INT_TYPE_MAX(abstime
.tv_sec
));
1890 ret
= pthread_cond_timedwait(&device
->queue_submit
,
1891 &device
->mutex
, &abstime
);
1892 assert(ret
!= EINVAL
);
1894 struct timespec after
;
1895 clock_gettime(CLOCK_MONOTONIC
, &after
);
1896 uint64_t time_elapsed
=
1897 ((uint64_t)after
.tv_sec
* NSEC_PER_SEC
+ after
.tv_nsec
) -
1898 ((uint64_t)before
.tv_sec
* NSEC_PER_SEC
+ before
.tv_nsec
);
1900 if (time_elapsed
>= timeout
) {
1901 pthread_mutex_unlock(&device
->mutex
);
1905 timeout
-= time_elapsed
;
1908 pthread_mutex_unlock(&device
->mutex
);
1915 // Queue semaphore functions
1917 VkResult
anv_CreateSemaphore(
1919 const VkSemaphoreCreateInfo
* pCreateInfo
,
1920 const VkAllocationCallbacks
* pAllocator
,
1921 VkSemaphore
* pSemaphore
)
1923 /* The DRM execbuffer ioctl always execute in-oder, even between different
1924 * rings. As such, there's nothing to do for the user space semaphore.
1927 *pSemaphore
= (VkSemaphore
)1;
1932 void anv_DestroySemaphore(
1934 VkSemaphore semaphore
,
1935 const VkAllocationCallbacks
* pAllocator
)
1941 VkResult
anv_CreateEvent(
1943 const VkEventCreateInfo
* pCreateInfo
,
1944 const VkAllocationCallbacks
* pAllocator
,
1947 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1948 struct anv_state state
;
1949 struct anv_event
*event
;
1951 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1953 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1956 event
->state
= state
;
1957 event
->semaphore
= VK_EVENT_RESET
;
1959 if (!device
->info
.has_llc
) {
1960 /* Make sure the writes we're flushing have landed. */
1961 __builtin_ia32_mfence();
1962 __builtin_ia32_clflush(event
);
1965 *pEvent
= anv_event_to_handle(event
);
1970 void anv_DestroyEvent(
1973 const VkAllocationCallbacks
* pAllocator
)
1975 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1976 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1981 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1984 VkResult
anv_GetEventStatus(
1988 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1989 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1991 if (!device
->info
.has_llc
) {
1992 /* Invalidate read cache before reading event written by GPU. */
1993 __builtin_ia32_clflush(event
);
1994 __builtin_ia32_mfence();
1998 return event
->semaphore
;
2001 VkResult
anv_SetEvent(
2005 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2006 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2008 event
->semaphore
= VK_EVENT_SET
;
2010 if (!device
->info
.has_llc
) {
2011 /* Make sure the writes we're flushing have landed. */
2012 __builtin_ia32_mfence();
2013 __builtin_ia32_clflush(event
);
2019 VkResult
anv_ResetEvent(
2023 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2024 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2026 event
->semaphore
= VK_EVENT_RESET
;
2028 if (!device
->info
.has_llc
) {
2029 /* Make sure the writes we're flushing have landed. */
2030 __builtin_ia32_mfence();
2031 __builtin_ia32_clflush(event
);
2039 VkResult
anv_CreateBuffer(
2041 const VkBufferCreateInfo
* pCreateInfo
,
2042 const VkAllocationCallbacks
* pAllocator
,
2045 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2046 struct anv_buffer
*buffer
;
2048 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2050 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2051 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2053 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2055 buffer
->size
= pCreateInfo
->size
;
2056 buffer
->usage
= pCreateInfo
->usage
;
2060 *pBuffer
= anv_buffer_to_handle(buffer
);
2065 void anv_DestroyBuffer(
2068 const VkAllocationCallbacks
* pAllocator
)
2070 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2071 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2076 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2080 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2081 enum isl_format format
,
2082 uint32_t offset
, uint32_t range
, uint32_t stride
)
2084 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2086 .mocs
= device
->default_mocs
,
2091 anv_state_flush(device
, state
);
2094 void anv_DestroySampler(
2097 const VkAllocationCallbacks
* pAllocator
)
2099 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2100 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2105 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2108 VkResult
anv_CreateFramebuffer(
2110 const VkFramebufferCreateInfo
* pCreateInfo
,
2111 const VkAllocationCallbacks
* pAllocator
,
2112 VkFramebuffer
* pFramebuffer
)
2114 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2115 struct anv_framebuffer
*framebuffer
;
2117 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2119 size_t size
= sizeof(*framebuffer
) +
2120 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2121 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2122 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2123 if (framebuffer
== NULL
)
2124 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2126 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2127 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2128 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2129 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2132 framebuffer
->width
= pCreateInfo
->width
;
2133 framebuffer
->height
= pCreateInfo
->height
;
2134 framebuffer
->layers
= pCreateInfo
->layers
;
2136 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2141 void anv_DestroyFramebuffer(
2144 const VkAllocationCallbacks
* pAllocator
)
2146 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2147 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2152 vk_free2(&device
->alloc
, pAllocator
, fb
);
2155 /* vk_icd.h does not declare this function, so we declare it here to
2156 * suppress Wmissing-prototypes.
2158 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2159 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2161 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2162 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2164 /* For the full details on loader interface versioning, see
2165 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2166 * What follows is a condensed summary, to help you navigate the large and
2167 * confusing official doc.
2169 * - Loader interface v0 is incompatible with later versions. We don't
2172 * - In loader interface v1:
2173 * - The first ICD entrypoint called by the loader is
2174 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2176 * - The ICD must statically expose no other Vulkan symbol unless it is
2177 * linked with -Bsymbolic.
2178 * - Each dispatchable Vulkan handle created by the ICD must be
2179 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2180 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2181 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2182 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2183 * such loader-managed surfaces.
2185 * - Loader interface v2 differs from v1 in:
2186 * - The first ICD entrypoint called by the loader is
2187 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2188 * statically expose this entrypoint.
2190 * - Loader interface v3 differs from v2 in:
2191 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2192 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2193 * because the loader no longer does so.
2195 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);