2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "anv_private.h"
31 #include "mesa/main/git_sha1.h"
32 #include "util/strtod.h"
34 #include "gen7_pack.h"
36 struct anv_dispatch_table dtable
;
39 compiler_debug_log(void *data
, const char *fmt
, ...)
43 compiler_perf_log(void *data
, const char *fmt
, ...)
48 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
49 vfprintf(stderr
, fmt
, args
);
55 anv_physical_device_init(struct anv_physical_device
*device
,
56 struct anv_instance
*instance
,
62 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
64 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
65 "failed to open %s: %m", path
);
67 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
68 device
->instance
= instance
;
71 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
72 if (!device
->chipset_id
) {
73 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
74 "failed to get chipset id: %m");
78 device
->name
= brw_get_device_name(device
->chipset_id
);
79 device
->info
= brw_get_device_info(device
->chipset_id
);
81 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
82 "failed to get device info");
86 if (device
->info
->is_haswell
) {
87 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
88 } else if (device
->info
->gen
== 7 && !device
->info
->is_baytrail
) {
89 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
90 } else if (device
->info
->gen
== 9) {
91 fprintf(stderr
, "WARNING: Skylake Vulkan support is incomplete\n");
92 } else if (device
->info
->gen
== 8 && !device
->info
->is_cherryview
) {
93 /* Broadwell is as fully supported as anything */
95 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
96 "Vulkan not yet supported on %s", device
->name
);
100 if (anv_gem_get_aperture(fd
, &device
->aperture_size
) == -1) {
101 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
102 "failed to get aperture size: %m");
106 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
107 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
108 "kernel missing gem wait");
112 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
113 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
114 "kernel missing execbuf2");
118 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_LLC
)) {
119 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
126 brw_process_intel_debug_variable();
128 device
->compiler
= brw_compiler_create(NULL
, device
->info
);
129 if (device
->compiler
== NULL
) {
130 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
133 device
->compiler
->shader_debug_log
= compiler_debug_log
;
134 device
->compiler
->shader_perf_log
= compiler_perf_log
;
136 isl_device_init(&device
->isl_dev
, device
->info
);
146 anv_physical_device_finish(struct anv_physical_device
*device
)
148 ralloc_free(device
->compiler
);
151 static const VkExtensionProperties global_extensions
[] = {
153 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
157 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
160 #ifdef HAVE_WAYLAND_PLATFORM
162 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
168 static const VkExtensionProperties device_extensions
[] = {
170 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
176 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
177 VkSystemAllocationScope allocationScope
)
183 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
184 size_t align
, VkSystemAllocationScope allocationScope
)
186 return realloc(pOriginal
, size
);
190 default_free_func(void *pUserData
, void *pMemory
)
195 static const VkAllocationCallbacks default_alloc
= {
197 .pfnAllocation
= default_alloc_func
,
198 .pfnReallocation
= default_realloc_func
,
199 .pfnFree
= default_free_func
,
202 VkResult
anv_CreateInstance(
203 const VkInstanceCreateInfo
* pCreateInfo
,
204 const VkAllocationCallbacks
* pAllocator
,
205 VkInstance
* pInstance
)
207 struct anv_instance
*instance
;
209 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
211 if (pCreateInfo
->pApplicationInfo
->apiVersion
!= VK_MAKE_VERSION(0, 210, 1))
212 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
214 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
216 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
217 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
218 global_extensions
[j
].extensionName
) == 0) {
224 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
227 instance
= anv_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
228 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
230 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
232 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
235 instance
->alloc
= *pAllocator
;
237 instance
->alloc
= default_alloc
;
239 instance
->apiVersion
= pCreateInfo
->pApplicationInfo
->apiVersion
;
240 instance
->physicalDeviceCount
= -1;
244 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
246 anv_init_wsi(instance
);
248 *pInstance
= anv_instance_to_handle(instance
);
253 void anv_DestroyInstance(
254 VkInstance _instance
,
255 const VkAllocationCallbacks
* pAllocator
)
257 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
259 if (instance
->physicalDeviceCount
> 0) {
260 /* We support at most one physical device. */
261 assert(instance
->physicalDeviceCount
== 1);
262 anv_physical_device_finish(&instance
->physicalDevice
);
265 anv_finish_wsi(instance
);
267 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
271 anv_free(&instance
->alloc
, instance
);
274 VkResult
anv_EnumeratePhysicalDevices(
275 VkInstance _instance
,
276 uint32_t* pPhysicalDeviceCount
,
277 VkPhysicalDevice
* pPhysicalDevices
)
279 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
282 if (instance
->physicalDeviceCount
< 0) {
283 result
= anv_physical_device_init(&instance
->physicalDevice
,
284 instance
, "/dev/dri/renderD128");
285 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
286 instance
->physicalDeviceCount
= 0;
287 } else if (result
== VK_SUCCESS
) {
288 instance
->physicalDeviceCount
= 1;
294 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
295 * otherwise it's an inout parameter.
297 * The Vulkan spec (git aaed022) says:
299 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
300 * that is initialized with the number of devices the application is
301 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
302 * an array of at least this many VkPhysicalDevice handles [...].
304 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
305 * overwrites the contents of the variable pointed to by
306 * pPhysicalDeviceCount with the number of physical devices in in the
307 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
308 * pPhysicalDeviceCount with the number of physical handles written to
311 if (!pPhysicalDevices
) {
312 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
313 } else if (*pPhysicalDeviceCount
>= 1) {
314 pPhysicalDevices
[0] = anv_physical_device_to_handle(&instance
->physicalDevice
);
315 *pPhysicalDeviceCount
= 1;
317 *pPhysicalDeviceCount
= 0;
323 void anv_GetPhysicalDeviceFeatures(
324 VkPhysicalDevice physicalDevice
,
325 VkPhysicalDeviceFeatures
* pFeatures
)
327 anv_finishme("Get correct values for PhysicalDeviceFeatures");
329 *pFeatures
= (VkPhysicalDeviceFeatures
) {
330 .robustBufferAccess
= false,
331 .fullDrawIndexUint32
= false,
332 .imageCubeArray
= false,
333 .independentBlend
= false,
334 .geometryShader
= true,
335 .tessellationShader
= false,
336 .sampleRateShading
= false,
337 .dualSrcBlend
= true,
339 .multiDrawIndirect
= true,
341 .depthBiasClamp
= false,
342 .fillModeNonSolid
= true,
343 .depthBounds
= false,
347 .multiViewport
= true,
348 .samplerAnisotropy
= false, /* FINISHME */
349 .textureCompressionETC2
= true,
350 .textureCompressionASTC_LDR
= true,
351 .textureCompressionBC
= true,
352 .occlusionQueryPrecise
= false, /* FINISHME */
353 .pipelineStatisticsQuery
= true,
354 .vertexPipelineStoresAndAtomics
= false,
355 .fragmentStoresAndAtomics
= true,
356 .shaderTessellationAndGeometryPointSize
= true,
357 .shaderImageGatherExtended
= true,
358 .shaderStorageImageExtendedFormats
= false,
359 .shaderStorageImageMultisample
= false,
360 .shaderUniformBufferArrayDynamicIndexing
= true,
361 .shaderSampledImageArrayDynamicIndexing
= false,
362 .shaderStorageBufferArrayDynamicIndexing
= false,
363 .shaderStorageImageArrayDynamicIndexing
= false,
364 .shaderStorageImageReadWithoutFormat
= false,
365 .shaderStorageImageWriteWithoutFormat
= true,
366 .shaderClipDistance
= false,
367 .shaderCullDistance
= false,
368 .shaderFloat64
= false,
369 .shaderInt64
= false,
370 .shaderInt16
= false,
372 .variableMultisampleRate
= false,
376 void anv_GetPhysicalDeviceProperties(
377 VkPhysicalDevice physicalDevice
,
378 VkPhysicalDeviceProperties
* pProperties
)
380 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
381 const struct brw_device_info
*devinfo
= pdevice
->info
;
383 anv_finishme("Get correct values for VkPhysicalDeviceLimits");
385 VkSampleCountFlags sample_counts
=
386 VK_SAMPLE_COUNT_1_BIT
|
387 VK_SAMPLE_COUNT_2_BIT
|
388 VK_SAMPLE_COUNT_4_BIT
|
389 VK_SAMPLE_COUNT_8_BIT
;
391 VkPhysicalDeviceLimits limits
= {
392 .maxImageDimension1D
= (1 << 14),
393 .maxImageDimension2D
= (1 << 14),
394 .maxImageDimension3D
= (1 << 10),
395 .maxImageDimensionCube
= (1 << 14),
396 .maxImageArrayLayers
= (1 << 10),
397 .maxTexelBufferElements
= (1 << 14),
398 .maxUniformBufferRange
= UINT32_MAX
,
399 .maxStorageBufferRange
= UINT32_MAX
,
400 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
401 .maxMemoryAllocationCount
= UINT32_MAX
,
402 .maxSamplerAllocationCount
= UINT32_MAX
,
403 .bufferImageGranularity
= 64, /* A cache line */
404 .sparseAddressSpaceSize
= 0,
405 .maxBoundDescriptorSets
= MAX_SETS
,
406 .maxPerStageDescriptorSamplers
= 64,
407 .maxPerStageDescriptorUniformBuffers
= 64,
408 .maxPerStageDescriptorStorageBuffers
= 64,
409 .maxPerStageDescriptorSampledImages
= 64,
410 .maxPerStageDescriptorStorageImages
= 64,
411 .maxPerStageDescriptorInputAttachments
= 64,
412 .maxPerStageResources
= 128,
413 .maxDescriptorSetSamplers
= 256,
414 .maxDescriptorSetUniformBuffers
= 256,
415 .maxDescriptorSetUniformBuffersDynamic
= 256,
416 .maxDescriptorSetStorageBuffers
= 256,
417 .maxDescriptorSetStorageBuffersDynamic
= 256,
418 .maxDescriptorSetSampledImages
= 256,
419 .maxDescriptorSetStorageImages
= 256,
420 .maxDescriptorSetInputAttachments
= 256,
421 .maxVertexInputAttributes
= 32,
422 .maxVertexInputBindings
= 32,
423 .maxVertexInputAttributeOffset
= 256,
424 .maxVertexInputBindingStride
= 256,
425 .maxVertexOutputComponents
= 32,
426 .maxTessellationGenerationLevel
= 0,
427 .maxTessellationPatchSize
= 0,
428 .maxTessellationControlPerVertexInputComponents
= 0,
429 .maxTessellationControlPerVertexOutputComponents
= 0,
430 .maxTessellationControlPerPatchOutputComponents
= 0,
431 .maxTessellationControlTotalOutputComponents
= 0,
432 .maxTessellationEvaluationInputComponents
= 0,
433 .maxTessellationEvaluationOutputComponents
= 0,
434 .maxGeometryShaderInvocations
= 6,
435 .maxGeometryInputComponents
= 16,
436 .maxGeometryOutputComponents
= 16,
437 .maxGeometryOutputVertices
= 16,
438 .maxGeometryTotalOutputComponents
= 16,
439 .maxFragmentInputComponents
= 16,
440 .maxFragmentOutputAttachments
= 8,
441 .maxFragmentDualSrcAttachments
= 2,
442 .maxFragmentCombinedOutputResources
= 8,
443 .maxComputeSharedMemorySize
= 1024,
444 .maxComputeWorkGroupCount
= {
445 16 * devinfo
->max_cs_threads
,
446 16 * devinfo
->max_cs_threads
,
447 16 * devinfo
->max_cs_threads
,
449 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
450 .maxComputeWorkGroupSize
= {
451 16 * devinfo
->max_cs_threads
,
452 16 * devinfo
->max_cs_threads
,
453 16 * devinfo
->max_cs_threads
,
455 .subPixelPrecisionBits
= 4 /* FIXME */,
456 .subTexelPrecisionBits
= 4 /* FIXME */,
457 .mipmapPrecisionBits
= 4 /* FIXME */,
458 .maxDrawIndexedIndexValue
= UINT32_MAX
,
459 .maxDrawIndirectCount
= UINT32_MAX
,
460 .maxSamplerLodBias
= 16,
461 .maxSamplerAnisotropy
= 16,
462 .maxViewports
= MAX_VIEWPORTS
,
463 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
464 .viewportBoundsRange
= { -1.0, 1.0 }, /* FIXME */
465 .viewportSubPixelBits
= 13, /* We take a float? */
466 .minMemoryMapAlignment
= 64, /* A cache line */
467 .minTexelBufferOffsetAlignment
= 1,
468 .minUniformBufferOffsetAlignment
= 1,
469 .minStorageBufferOffsetAlignment
= 1,
470 .minTexelOffset
= 0, /* FIXME */
471 .maxTexelOffset
= 0, /* FIXME */
472 .minTexelGatherOffset
= 0, /* FIXME */
473 .maxTexelGatherOffset
= 0, /* FIXME */
474 .minInterpolationOffset
= 0, /* FIXME */
475 .maxInterpolationOffset
= 0, /* FIXME */
476 .subPixelInterpolationOffsetBits
= 0, /* FIXME */
477 .maxFramebufferWidth
= (1 << 14),
478 .maxFramebufferHeight
= (1 << 14),
479 .maxFramebufferLayers
= (1 << 10),
480 .framebufferColorSampleCounts
= sample_counts
,
481 .framebufferDepthSampleCounts
= sample_counts
,
482 .framebufferStencilSampleCounts
= sample_counts
,
483 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
484 .maxColorAttachments
= MAX_RTS
,
485 .sampledImageColorSampleCounts
= sample_counts
,
486 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
487 .sampledImageDepthSampleCounts
= sample_counts
,
488 .sampledImageStencilSampleCounts
= sample_counts
,
489 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
490 .maxSampleMaskWords
= 1,
491 .timestampPeriod
= 80.0 / (1000 * 1000 * 1000),
492 .maxClipDistances
= 0 /* FIXME */,
493 .maxCullDistances
= 0 /* FIXME */,
494 .maxCombinedClipAndCullDistances
= 0 /* FIXME */,
495 .discreteQueuePriorities
= 1,
496 .pointSizeRange
= { 0.125, 255.875 },
497 .lineWidthRange
= { 0.0, 7.9921875 },
498 .pointSizeGranularity
= (1.0 / 8.0),
499 .lineWidthGranularity
= (1.0 / 128.0),
500 .strictLines
= false, /* FINISHME */
501 .standardSampleLocations
= true, /* FINISHME */
502 .optimalBufferCopyOffsetAlignment
= 128,
503 .optimalBufferCopyRowPitchAlignment
= 128,
504 .nonCoherentAtomSize
= 64,
507 *pProperties
= (VkPhysicalDeviceProperties
) {
508 .apiVersion
= VK_MAKE_VERSION(0, 210, 1),
511 .deviceID
= pdevice
->chipset_id
,
512 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
514 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
517 strcpy(pProperties
->deviceName
, pdevice
->name
);
518 snprintf((char *)pProperties
->pipelineCacheUUID
, VK_UUID_SIZE
,
519 "anv-%s", MESA_GIT_SHA1
+ 4);
522 void anv_GetPhysicalDeviceQueueFamilyProperties(
523 VkPhysicalDevice physicalDevice
,
525 VkQueueFamilyProperties
* pQueueFamilyProperties
)
527 if (pQueueFamilyProperties
== NULL
) {
532 assert(*pCount
>= 1);
534 *pQueueFamilyProperties
= (VkQueueFamilyProperties
) {
535 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
536 VK_QUEUE_COMPUTE_BIT
|
537 VK_QUEUE_TRANSFER_BIT
,
539 .timestampValidBits
= 0, /* XXX: Real value here */
540 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
544 void anv_GetPhysicalDeviceMemoryProperties(
545 VkPhysicalDevice physicalDevice
,
546 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
548 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
549 VkDeviceSize heap_size
;
551 /* Reserve some wiggle room for the driver by exposing only 75% of the
552 * aperture to the heap.
554 heap_size
= 3 * physical_device
->aperture_size
/ 4;
556 /* The property flags below are valid only for llc platforms. */
557 pMemoryProperties
->memoryTypeCount
= 1;
558 pMemoryProperties
->memoryTypes
[0] = (VkMemoryType
) {
559 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
560 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
561 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
562 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
566 pMemoryProperties
->memoryHeapCount
= 1;
567 pMemoryProperties
->memoryHeaps
[0] = (VkMemoryHeap
) {
569 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
573 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
577 return anv_lookup_entrypoint(pName
);
580 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
584 return anv_lookup_entrypoint(pName
);
588 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
590 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
591 queue
->device
= device
;
592 queue
->pool
= &device
->surface_state_pool
;
598 anv_queue_finish(struct anv_queue
*queue
)
602 static struct anv_state
603 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
605 struct anv_state state
;
607 state
= anv_state_pool_alloc(pool
, size
, align
);
608 memcpy(state
.map
, p
, size
);
610 if (!pool
->block_pool
->device
->info
.has_llc
)
611 anv_state_clflush(state
);
617 anv_device_init_border_colors(struct anv_device
*device
)
619 static const VkClearColorValue border_colors
[] = {
620 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
621 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
622 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
623 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
624 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
625 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
628 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
629 sizeof(border_colors
), 32, border_colors
);
632 VkResult
anv_CreateDevice(
633 VkPhysicalDevice physicalDevice
,
634 const VkDeviceCreateInfo
* pCreateInfo
,
635 const VkAllocationCallbacks
* pAllocator
,
638 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
639 struct anv_device
*device
;
641 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
643 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionNameCount
; i
++) {
645 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
646 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
647 device_extensions
[j
].extensionName
) == 0) {
653 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
656 anv_set_dispatch_devinfo(physical_device
->info
);
658 device
= anv_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
660 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
662 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
664 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
665 device
->instance
= physical_device
->instance
;
668 device
->alloc
= *pAllocator
;
670 device
->alloc
= physical_device
->instance
->alloc
;
672 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
673 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
674 if (device
->fd
== -1)
677 device
->context_id
= anv_gem_create_context(device
);
678 if (device
->context_id
== -1)
681 pthread_mutex_init(&device
->mutex
, NULL
);
683 anv_bo_pool_init(&device
->batch_bo_pool
, device
, ANV_CMD_BUFFER_BATCH_SIZE
);
685 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
687 anv_state_pool_init(&device
->dynamic_state_pool
,
688 &device
->dynamic_state_block_pool
);
690 anv_block_pool_init(&device
->instruction_block_pool
, device
, 4096);
691 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 4096);
693 anv_state_pool_init(&device
->surface_state_pool
,
694 &device
->surface_state_block_pool
);
696 anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
698 anv_block_pool_init(&device
->scratch_block_pool
, device
, 0x10000);
700 device
->info
= *physical_device
->info
;
701 device
->isl_dev
= physical_device
->isl_dev
;
703 anv_queue_init(device
, &device
->queue
);
705 anv_device_init_meta(device
);
707 anv_device_init_border_colors(device
);
709 *pDevice
= anv_device_to_handle(device
);
716 anv_free(&device
->alloc
, device
);
718 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
721 void anv_DestroyDevice(
723 const VkAllocationCallbacks
* pAllocator
)
725 ANV_FROM_HANDLE(anv_device
, device
, _device
);
727 anv_queue_finish(&device
->queue
);
729 anv_device_finish_meta(device
);
732 /* We only need to free these to prevent valgrind errors. The backing
733 * BO will go away in a couple of lines so we don't actually leak.
735 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
738 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
739 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
741 anv_bo_pool_finish(&device
->batch_bo_pool
);
742 anv_state_pool_finish(&device
->dynamic_state_pool
);
743 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
744 anv_block_pool_finish(&device
->instruction_block_pool
);
745 anv_state_pool_finish(&device
->surface_state_pool
);
746 anv_block_pool_finish(&device
->surface_state_block_pool
);
747 anv_block_pool_finish(&device
->scratch_block_pool
);
751 anv_free(&device
->alloc
, device
);
754 VkResult
anv_EnumerateInstanceExtensionProperties(
755 const char* pLayerName
,
756 uint32_t* pPropertyCount
,
757 VkExtensionProperties
* pProperties
)
759 if (pProperties
== NULL
) {
760 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
764 assert(*pPropertyCount
>= ARRAY_SIZE(global_extensions
));
766 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
767 memcpy(pProperties
, global_extensions
, sizeof(global_extensions
));
772 VkResult
anv_EnumerateDeviceExtensionProperties(
773 VkPhysicalDevice physicalDevice
,
774 const char* pLayerName
,
775 uint32_t* pPropertyCount
,
776 VkExtensionProperties
* pProperties
)
778 if (pProperties
== NULL
) {
779 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
783 assert(*pPropertyCount
>= ARRAY_SIZE(device_extensions
));
785 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
786 memcpy(pProperties
, device_extensions
, sizeof(device_extensions
));
791 VkResult
anv_EnumerateInstanceLayerProperties(
792 uint32_t* pPropertyCount
,
793 VkLayerProperties
* pProperties
)
795 if (pProperties
== NULL
) {
800 /* None supported at this time */
801 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
804 VkResult
anv_EnumerateDeviceLayerProperties(
805 VkPhysicalDevice physicalDevice
,
806 uint32_t* pPropertyCount
,
807 VkLayerProperties
* pProperties
)
809 if (pProperties
== NULL
) {
814 /* None supported at this time */
815 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
818 void anv_GetDeviceQueue(
820 uint32_t queueNodeIndex
,
824 ANV_FROM_HANDLE(anv_device
, device
, _device
);
826 assert(queueIndex
== 0);
828 *pQueue
= anv_queue_to_handle(&device
->queue
);
831 VkResult
anv_QueueSubmit(
833 uint32_t submitCount
,
834 const VkSubmitInfo
* pSubmits
,
837 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
838 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
839 struct anv_device
*device
= queue
->device
;
842 for (uint32_t i
= 0; i
< submitCount
; i
++) {
843 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
844 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
,
845 pSubmits
[i
].pCommandBuffers
[j
]);
846 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
848 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf2
.execbuf
);
850 /* We don't know the real error. */
851 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
852 "execbuf2 failed: %m");
856 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
858 /* We don't know the real error. */
859 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
860 "execbuf2 failed: %m");
864 for (uint32_t k
= 0; k
< cmd_buffer
->execbuf2
.bo_count
; k
++)
865 cmd_buffer
->execbuf2
.bos
[k
]->offset
= cmd_buffer
->execbuf2
.objects
[k
].offset
;
872 VkResult
anv_QueueWaitIdle(
875 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
877 return ANV_CALL(DeviceWaitIdle
)(anv_device_to_handle(queue
->device
));
880 VkResult
anv_DeviceWaitIdle(
883 ANV_FROM_HANDLE(anv_device
, device
, _device
);
884 struct anv_state state
;
885 struct anv_batch batch
;
886 struct drm_i915_gem_execbuffer2 execbuf
;
887 struct drm_i915_gem_exec_object2 exec2_objects
[1];
888 struct anv_bo
*bo
= NULL
;
893 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
894 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
895 batch
.start
= batch
.next
= state
.map
;
896 batch
.end
= state
.map
+ 32;
897 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
898 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
900 if (!device
->info
.has_llc
)
901 anv_state_clflush(state
);
903 exec2_objects
[0].handle
= bo
->gem_handle
;
904 exec2_objects
[0].relocation_count
= 0;
905 exec2_objects
[0].relocs_ptr
= 0;
906 exec2_objects
[0].alignment
= 0;
907 exec2_objects
[0].offset
= bo
->offset
;
908 exec2_objects
[0].flags
= 0;
909 exec2_objects
[0].rsvd1
= 0;
910 exec2_objects
[0].rsvd2
= 0;
912 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
913 execbuf
.buffer_count
= 1;
914 execbuf
.batch_start_offset
= state
.offset
;
915 execbuf
.batch_len
= batch
.next
- state
.map
;
916 execbuf
.cliprects_ptr
= 0;
917 execbuf
.num_cliprects
= 0;
922 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
923 execbuf
.rsvd1
= device
->context_id
;
926 ret
= anv_gem_execbuffer(device
, &execbuf
);
928 /* We don't know the real error. */
929 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
934 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
936 /* We don't know the real error. */
937 result
= vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
, "execbuf2 failed: %m");
941 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
946 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
952 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
954 bo
->gem_handle
= anv_gem_create(device
, size
);
956 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
966 VkResult
anv_AllocateMemory(
968 const VkMemoryAllocateInfo
* pAllocateInfo
,
969 const VkAllocationCallbacks
* pAllocator
,
970 VkDeviceMemory
* pMem
)
972 ANV_FROM_HANDLE(anv_device
, device
, _device
);
973 struct anv_device_memory
*mem
;
976 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
978 /* We support exactly one memory heap. */
979 assert(pAllocateInfo
->memoryTypeIndex
== 0);
981 /* FINISHME: Fail if allocation request exceeds heap size. */
983 mem
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
984 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
986 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
988 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocateInfo
->allocationSize
);
989 if (result
!= VK_SUCCESS
)
992 *pMem
= anv_device_memory_to_handle(mem
);
997 anv_free2(&device
->alloc
, pAllocator
, mem
);
1002 void anv_FreeMemory(
1004 VkDeviceMemory _mem
,
1005 const VkAllocationCallbacks
* pAllocator
)
1007 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1008 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1011 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
1013 if (mem
->bo
.gem_handle
!= 0)
1014 anv_gem_close(device
, mem
->bo
.gem_handle
);
1016 anv_free2(&device
->alloc
, pAllocator
, mem
);
1019 VkResult
anv_MapMemory(
1021 VkDeviceMemory _memory
,
1022 VkDeviceSize offset
,
1024 VkMemoryMapFlags flags
,
1027 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1028 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1030 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1031 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1032 * at a time is valid. We could just mmap up front and return an offset
1033 * pointer here, but that may exhaust virtual memory on 32 bit
1036 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
);
1037 mem
->map_size
= size
;
1044 void anv_UnmapMemory(
1046 VkDeviceMemory _memory
)
1048 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1050 anv_gem_munmap(mem
->map
, mem
->map_size
);
1054 clflush_mapped_ranges(struct anv_device
*device
,
1056 const VkMappedMemoryRange
*ranges
)
1058 for (uint32_t i
= 0; i
< count
; i
++) {
1059 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1060 void *p
= mem
->map
+ (ranges
[i
].offset
& ~CACHELINE_MASK
);
1061 void *end
= mem
->map
+ ranges
[i
].offset
+ ranges
[i
].size
;
1064 __builtin_ia32_clflush(p
);
1065 p
+= CACHELINE_SIZE
;
1070 VkResult
anv_FlushMappedMemoryRanges(
1072 uint32_t memoryRangeCount
,
1073 const VkMappedMemoryRange
* pMemoryRanges
)
1075 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1077 if (device
->info
.has_llc
)
1080 /* Make sure the writes we're flushing have landed. */
1081 __builtin_ia32_sfence();
1083 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1088 VkResult
anv_InvalidateMappedMemoryRanges(
1090 uint32_t memoryRangeCount
,
1091 const VkMappedMemoryRange
* pMemoryRanges
)
1093 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1095 if (device
->info
.has_llc
)
1098 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1100 /* Make sure no reads get moved up above the invalidate. */
1101 __builtin_ia32_lfence();
1106 void anv_GetBufferMemoryRequirements(
1109 VkMemoryRequirements
* pMemoryRequirements
)
1111 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1113 /* The Vulkan spec (git aaed022) says:
1115 * memoryTypeBits is a bitfield and contains one bit set for every
1116 * supported memory type for the resource. The bit `1<<i` is set if and
1117 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1118 * structure for the physical device is supported.
1120 * We support exactly one memory type.
1122 pMemoryRequirements
->memoryTypeBits
= 1;
1124 pMemoryRequirements
->size
= buffer
->size
;
1125 pMemoryRequirements
->alignment
= 16;
1128 void anv_GetImageMemoryRequirements(
1131 VkMemoryRequirements
* pMemoryRequirements
)
1133 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1135 /* The Vulkan spec (git aaed022) says:
1137 * memoryTypeBits is a bitfield and contains one bit set for every
1138 * supported memory type for the resource. The bit `1<<i` is set if and
1139 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1140 * structure for the physical device is supported.
1142 * We support exactly one memory type.
1144 pMemoryRequirements
->memoryTypeBits
= 1;
1146 pMemoryRequirements
->size
= image
->size
;
1147 pMemoryRequirements
->alignment
= image
->alignment
;
1150 void anv_GetImageSparseMemoryRequirements(
1153 uint32_t* pSparseMemoryRequirementCount
,
1154 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1159 void anv_GetDeviceMemoryCommitment(
1161 VkDeviceMemory memory
,
1162 VkDeviceSize
* pCommittedMemoryInBytes
)
1164 *pCommittedMemoryInBytes
= 0;
1167 VkResult
anv_BindBufferMemory(
1170 VkDeviceMemory _memory
,
1171 VkDeviceSize memoryOffset
)
1173 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1174 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1176 buffer
->bo
= &mem
->bo
;
1177 buffer
->offset
= memoryOffset
;
1182 VkResult
anv_BindImageMemory(
1185 VkDeviceMemory _memory
,
1186 VkDeviceSize memoryOffset
)
1188 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1189 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1191 image
->bo
= &mem
->bo
;
1192 image
->offset
= memoryOffset
;
1197 VkResult
anv_QueueBindSparse(
1199 uint32_t bindInfoCount
,
1200 const VkBindSparseInfo
* pBindInfo
,
1203 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1206 VkResult
anv_CreateFence(
1208 const VkFenceCreateInfo
* pCreateInfo
,
1209 const VkAllocationCallbacks
* pAllocator
,
1212 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1213 struct anv_fence
*fence
;
1214 struct anv_batch batch
;
1217 const uint32_t fence_size
= 128;
1219 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1221 fence
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*fence
), 8,
1222 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1224 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1226 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1227 if (result
!= VK_SUCCESS
)
1231 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
);
1232 batch
.next
= batch
.start
= fence
->bo
.map
;
1233 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1234 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
);
1235 anv_batch_emit(&batch
, GEN7_MI_NOOP
);
1237 if (!device
->info
.has_llc
) {
1238 assert(((uintptr_t) fence
->bo
.map
& CACHELINE_MASK
) == 0);
1239 assert(batch
.next
- fence
->bo
.map
<= CACHELINE_SIZE
);
1240 __builtin_ia32_sfence();
1241 __builtin_ia32_clflush(fence
->bo
.map
);
1244 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1245 fence
->exec2_objects
[0].relocation_count
= 0;
1246 fence
->exec2_objects
[0].relocs_ptr
= 0;
1247 fence
->exec2_objects
[0].alignment
= 0;
1248 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1249 fence
->exec2_objects
[0].flags
= 0;
1250 fence
->exec2_objects
[0].rsvd1
= 0;
1251 fence
->exec2_objects
[0].rsvd2
= 0;
1253 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1254 fence
->execbuf
.buffer_count
= 1;
1255 fence
->execbuf
.batch_start_offset
= 0;
1256 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1257 fence
->execbuf
.cliprects_ptr
= 0;
1258 fence
->execbuf
.num_cliprects
= 0;
1259 fence
->execbuf
.DR1
= 0;
1260 fence
->execbuf
.DR4
= 0;
1262 fence
->execbuf
.flags
=
1263 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1264 fence
->execbuf
.rsvd1
= device
->context_id
;
1265 fence
->execbuf
.rsvd2
= 0;
1267 *pFence
= anv_fence_to_handle(fence
);
1272 anv_free2(&device
->alloc
, pAllocator
, fence
);
1277 void anv_DestroyFence(
1280 const VkAllocationCallbacks
* pAllocator
)
1282 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1283 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1285 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1286 anv_gem_close(device
, fence
->bo
.gem_handle
);
1287 anv_free2(&device
->alloc
, pAllocator
, fence
);
1290 VkResult
anv_ResetFences(
1292 uint32_t fenceCount
,
1293 const VkFence
* pFences
)
1295 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1296 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1297 fence
->ready
= false;
1303 VkResult
anv_GetFenceStatus(
1307 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1308 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
1315 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1317 fence
->ready
= true;
1321 return VK_NOT_READY
;
1324 VkResult
anv_WaitForFences(
1326 uint32_t fenceCount
,
1327 const VkFence
* pFences
,
1331 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1333 /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
1334 * to block indefinitely timeouts <= 0. Unfortunately, this was broken
1335 * for a couple of kernel releases. Since there's no way to know
1336 * whether or not the kernel we're using is one of the broken ones, the
1337 * best we can do is to clamp the timeout to INT64_MAX. This limits the
1338 * maximum timeout from 584 years to 292 years - likely not a big deal.
1340 if (timeout
> INT64_MAX
)
1341 timeout
= INT64_MAX
;
1343 int64_t t
= timeout
;
1345 /* FIXME: handle !waitAll */
1347 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1348 ANV_FROM_HANDLE(anv_fence
, fence
, pFences
[i
]);
1349 int ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1350 if (ret
== -1 && errno
== ETIME
) {
1352 } else if (ret
== -1) {
1353 /* We don't know the real error. */
1354 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1355 "gem wait failed: %m");
1362 // Queue semaphore functions
1364 VkResult
anv_CreateSemaphore(
1366 const VkSemaphoreCreateInfo
* pCreateInfo
,
1367 const VkAllocationCallbacks
* pAllocator
,
1368 VkSemaphore
* pSemaphore
)
1370 *pSemaphore
= (VkSemaphore
)1;
1371 stub_return(VK_SUCCESS
);
1374 void anv_DestroySemaphore(
1376 VkSemaphore semaphore
,
1377 const VkAllocationCallbacks
* pAllocator
)
1384 VkResult
anv_CreateEvent(
1386 const VkEventCreateInfo
* pCreateInfo
,
1387 const VkAllocationCallbacks
* pAllocator
,
1390 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1393 void anv_DestroyEvent(
1396 const VkAllocationCallbacks
* pAllocator
)
1401 VkResult
anv_GetEventStatus(
1405 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1408 VkResult
anv_SetEvent(
1412 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1415 VkResult
anv_ResetEvent(
1419 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1424 VkResult
anv_CreateBuffer(
1426 const VkBufferCreateInfo
* pCreateInfo
,
1427 const VkAllocationCallbacks
* pAllocator
,
1430 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1431 struct anv_buffer
*buffer
;
1433 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1435 buffer
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1436 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1438 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1440 buffer
->size
= pCreateInfo
->size
;
1444 *pBuffer
= anv_buffer_to_handle(buffer
);
1449 void anv_DestroyBuffer(
1452 const VkAllocationCallbacks
* pAllocator
)
1454 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1455 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1457 anv_free2(&device
->alloc
, pAllocator
, buffer
);
1461 anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1462 const struct anv_format
*format
,
1463 uint32_t offset
, uint32_t range
, uint32_t stride
)
1465 switch (device
->info
.gen
) {
1467 if (device
->info
.is_haswell
)
1468 gen75_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1470 gen7_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1473 gen8_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1476 gen9_fill_buffer_surface_state(state
, format
, offset
, range
, stride
);
1479 unreachable("unsupported gen\n");
1483 VkResult
anv_CreateBufferView(
1485 const VkBufferViewCreateInfo
* pCreateInfo
,
1486 const VkAllocationCallbacks
* pAllocator
,
1487 VkBufferView
* pView
)
1489 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1492 void anv_DestroyBufferView(
1494 VkBufferView _bview
,
1495 const VkAllocationCallbacks
* pAllocator
)
1500 void anv_DestroySampler(
1503 const VkAllocationCallbacks
* pAllocator
)
1505 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1506 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1508 anv_free2(&device
->alloc
, pAllocator
, sampler
);
1511 VkResult
anv_CreateFramebuffer(
1513 const VkFramebufferCreateInfo
* pCreateInfo
,
1514 const VkAllocationCallbacks
* pAllocator
,
1515 VkFramebuffer
* pFramebuffer
)
1517 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1518 struct anv_framebuffer
*framebuffer
;
1520 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1522 size_t size
= sizeof(*framebuffer
) +
1523 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
1524 framebuffer
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1525 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1526 if (framebuffer
== NULL
)
1527 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1529 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1530 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1531 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1532 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
1535 framebuffer
->width
= pCreateInfo
->width
;
1536 framebuffer
->height
= pCreateInfo
->height
;
1537 framebuffer
->layers
= pCreateInfo
->layers
;
1539 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
1544 void anv_DestroyFramebuffer(
1547 const VkAllocationCallbacks
* pAllocator
)
1549 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1550 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
1552 anv_free2(&device
->alloc
, pAllocator
, fb
);
1555 void vkCmdDbgMarkerBegin(
1556 VkCommandBuffer commandBuffer
,
1557 const char* pMarker
)
1558 __attribute__ ((visibility ("default")));
1560 void vkCmdDbgMarkerEnd(
1561 VkCommandBuffer commandBuffer
)
1562 __attribute__ ((visibility ("default")));
1564 void vkCmdDbgMarkerBegin(
1565 VkCommandBuffer commandBuffer
,
1566 const char* pMarker
)
1570 void vkCmdDbgMarkerEnd(
1571 VkCommandBuffer commandBuffer
)