#include "util/build_id.h"
#include "util/mesa-sha1.h"
#include "vk_util.h"
+#include "common/gen_defines.h"
#include "genxml/gen7_pack.h"
assert(strlen(path) < ARRAY_SIZE(device->path));
strncpy(device->path, path, ARRAY_SIZE(device->path));
- device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID);
- if (!device->chipset_id) {
- result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
- goto fail;
+ device->no_hw = getenv("INTEL_NO_HW") != NULL;
+
+ const int pci_id_override = gen_get_pci_device_id_override();
+ if (pci_id_override < 0) {
+ device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID);
+ if (!device->chipset_id) {
+ result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
+ goto fail;
+ }
+ } else {
+ device->chipset_id = pci_id_override;
+ device->no_hw = true;
}
device->name = gen_get_device_name(device->chipset_id);
intel_logw("Ivy Bridge Vulkan support is incomplete");
} else if (device->info.gen == 7 && device->info.is_baytrail) {
intel_logw("Bay Trail Vulkan support is incomplete");
- } else if (device->info.gen >= 8 && device->info.gen <= 9) {
- /* Broadwell, Cherryview, Skylake, Broxton, Kabylake, Coffelake is as
- * fully supported as anything */
- } else if (device->info.gen == 10) {
- intel_logw("Cannonlake Vulkan support is alpha");
+ } else if (device->info.gen >= 8 && device->info.gen <= 10) {
+ /* Gen8-10 fully supported */
} else {
result = vk_errorf(device->instance, device,
VK_ERROR_INCOMPATIBLE_DRIVER,
device->has_syncobj_wait = device->has_syncobj &&
anv_gem_supports_syncobj_wait(fd);
+ if (anv_gem_has_context_priority(fd))
+ device->has_context_priority = true;
+
bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X);
/* Starting with Gen10, the timestamp frequency of the command streamer may
device->compiler->shader_debug_log = compiler_debug_log;
device->compiler->shader_perf_log = compiler_perf_log;
device->compiler->supports_pull_constants = false;
+ device->compiler->constant_buffer_0_is_relative = true;
isl_device_init(&device->isl_dev, &device->info, swizzled);
goto fail;
}
+ anv_physical_device_get_supported_extensions(device,
+ &device->supported_extensions);
+
device->local_fd = fd;
return VK_SUCCESS;
.pfnFree = default_free_func,
};
+VkResult anv_EnumerateInstanceExtensionProperties(
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties)
+{
+ VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+
+ for (int i = 0; i < ANV_INSTANCE_EXTENSION_COUNT; i++) {
+ if (anv_instance_extensions_supported.extensions[i]) {
+ vk_outarray_append(&out, prop) {
+ *prop = anv_instance_extensions[i];
+ }
+ }
+ }
+
+ return vk_outarray_status(&out);
+}
+
VkResult anv_CreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance)
{
struct anv_instance *instance;
+ VkResult result;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
VK_VERSION_PATCH(client_version));
}
+ struct anv_instance_extension_table enabled_extensions = {};
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
- const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
- if (!anv_instance_extension_supported(ext_name))
+ int idx;
+ for (idx = 0; idx < ANV_INSTANCE_EXTENSION_COUNT; idx++) {
+ if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+ anv_instance_extensions[idx].extensionName) == 0)
+ break;
+ }
+
+ if (idx >= ANV_INSTANCE_EXTENSION_COUNT)
+ return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+ if (!anv_instance_extensions_supported.extensions[idx])
return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+ enabled_extensions.extensions[idx] = true;
}
instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
instance->alloc = default_alloc;
instance->apiVersion = client_version;
- instance->physicalDeviceCount = -1;
+ instance->enabled_extensions = enabled_extensions;
- if (pthread_mutex_init(&instance->callbacks_mutex, NULL) != 0) {
- vk_free2(&default_alloc, pAllocator, instance);
- return vk_error(VK_ERROR_INITIALIZATION_FAILED);
+ for (unsigned i = 0; i < ARRAY_SIZE(instance->dispatch.entrypoints); i++) {
+ /* Vulkan requires that entrypoints for extensions which have not been
+ * enabled must not be advertised.
+ */
+ if (!anv_entrypoint_is_enabled(i, instance->apiVersion,
+ &instance->enabled_extensions, NULL)) {
+ instance->dispatch.entrypoints[i] = NULL;
+ } else if (anv_dispatch_table.entrypoints[i] != NULL) {
+ instance->dispatch.entrypoints[i] = anv_dispatch_table.entrypoints[i];
+ } else {
+ instance->dispatch.entrypoints[i] =
+ anv_tramp_dispatch_table.entrypoints[i];
+ }
}
- list_inithead(&instance->callbacks);
+ instance->physicalDeviceCount = -1;
- /* Store report debug callback to be used during DestroyInstance. */
- if (ctor_cb) {
- instance->destroy_debug_cb.flags = ctor_cb->flags;
- instance->destroy_debug_cb.callback = ctor_cb->pfnCallback;
- instance->destroy_debug_cb.data = ctor_cb->pUserData;
+ result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
+ if (result != VK_SUCCESS) {
+ vk_free2(&default_alloc, pAllocator, instance);
+ return vk_error(result);
}
_mesa_locale_init();
VG(VALGRIND_DESTROY_MEMPOOL(instance));
- pthread_mutex_destroy(&instance->callbacks_mutex);
+ vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
_mesa_locale_fini();
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR: {
VkPhysicalDeviceVariablePointerFeaturesKHR *features = (void *)ext;
features->variablePointersStorageBuffer = true;
- features->variablePointers = false;
+ features->variablePointers = true;
break;
}
break;
}
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR: {
+ VkPhysicalDevice16BitStorageFeaturesKHR *features =
+ (VkPhysicalDevice16BitStorageFeaturesKHR *)ext;
+
+ features->storageBuffer16BitAccess = false;
+ features->uniformAndStorageBuffer16BitAccess = false;
+ features->storagePushConstant16 = false;
+ features->storageInputOutput16 = false;
+ break;
+ }
+
default:
anv_debug_ignored_stype(ext->sType);
break;
.maxPerStageDescriptorStorageImages = 64,
.maxPerStageDescriptorInputAttachments = 64,
.maxPerStageResources = 250,
- .maxDescriptorSetSamplers = 256,
- .maxDescriptorSetUniformBuffers = 256,
+ .maxDescriptorSetSamplers = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSamplers */
+ .maxDescriptorSetUniformBuffers = 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
.maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2,
- .maxDescriptorSetStorageBuffers = 256,
+ .maxDescriptorSetStorageBuffers = 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
.maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2,
- .maxDescriptorSetSampledImages = 256,
- .maxDescriptorSetStorageImages = 256,
+ .maxDescriptorSetSampledImages = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSampledImages */
+ .maxDescriptorSetStorageImages = 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
.maxDescriptorSetInputAttachments = 256,
.maxVertexInputAttributes = MAX_VBS,
.maxVertexInputBindings = MAX_VBS,
.viewportSubPixelBits = 13, /* We take a float? */
.minMemoryMapAlignment = 4096, /* A page */
.minTexelBufferOffsetAlignment = 1,
- .minUniformBufferOffsetAlignment = 16,
+ /* We need 16 for UBO block reads to work and 32 for push UBOs */
+ .minUniformBufferOffsetAlignment = 32,
.minStorageBufferOffsetAlignment = 4,
.minTexelOffset = -8,
.maxTexelOffset = 7,
}
PFN_vkVoidFunction anv_GetInstanceProcAddr(
- VkInstance instance,
+ VkInstance _instance,
const char* pName)
{
- return anv_lookup_entrypoint(NULL, pName);
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);
+
+ /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
+ * when we have to return valid function pointers, NULL, or it's left
+ * undefined. See the table for exact details.
+ */
+ if (pName == NULL)
+ return NULL;
+
+#define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
+ if (strcmp(pName, "vk" #entrypoint) == 0) \
+ return (PFN_vkVoidFunction)anv_##entrypoint
+
+ LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties);
+ LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties);
+ LOOKUP_ANV_ENTRYPOINT(CreateInstance);
+
+#undef LOOKUP_ANV_ENTRYPOINT
+
+ if (instance == NULL)
+ return NULL;
+
+ int idx = anv_get_entrypoint_index(pName);
+ if (idx < 0)
+ return NULL;
+
+ return instance->dispatch.entrypoints[idx];
}
/* With version 1+ of the loader interface the ICD should expose
const char* pName)
{
ANV_FROM_HANDLE(anv_device, device, _device);
- return anv_lookup_entrypoint(&device->info, pName);
+
+ if (!device || !pName)
+ return NULL;
+
+ int idx = anv_get_entrypoint_index(pName);
+ if (idx < 0)
+ return NULL;
+
+ return device->dispatch.entrypoints[idx];
+}
+
+VkResult
+anv_CreateDebugReportCallbackEXT(VkInstance _instance,
+ const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDebugReportCallbackEXT* pCallback)
+{
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);
+ return vk_create_debug_report_callback(&instance->debug_report_callbacks,
+ pCreateInfo, pAllocator, &instance->alloc,
+ pCallback);
+}
+
+void
+anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
+ VkDebugReportCallbackEXT _callback,
+ const VkAllocationCallbacks* pAllocator)
+{
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);
+ vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
+ _callback, pAllocator, &instance->alloc);
+}
+
+void
+anv_DebugReportMessageEXT(VkInstance _instance,
+ VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT objectType,
+ uint64_t object,
+ size_t location,
+ int32_t messageCode,
+ const char* pLayerPrefix,
+ const char* pMessage)
+{
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);
+ vk_debug_report(&instance->debug_report_callbacks, flags, objectType,
+ object, location, messageCode, pLayerPrefix, pMessage);
}
static void
anv_gem_munmap(map, device->trivial_batch_bo.size);
}
+VkResult anv_EnumerateDeviceExtensionProperties(
+ VkPhysicalDevice physicalDevice,
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties)
+{
+ ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+ VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+ (void)device;
+
+ for (int i = 0; i < ANV_DEVICE_EXTENSION_COUNT; i++) {
+ if (device->supported_extensions.extensions[i]) {
+ vk_outarray_append(&out, prop) {
+ *prop = anv_device_extensions[i];
+ }
+ }
+ }
+
+ return vk_outarray_status(&out);
+}
+
+static void
+anv_device_init_dispatch(struct anv_device *device)
+{
+ const struct anv_dispatch_table *genX_table;
+ switch (device->info.gen) {
+ case 10:
+ genX_table = &gen10_dispatch_table;
+ break;
+ case 9:
+ genX_table = &gen9_dispatch_table;
+ break;
+ case 8:
+ genX_table = &gen8_dispatch_table;
+ break;
+ case 7:
+ if (device->info.is_haswell)
+ genX_table = &gen75_dispatch_table;
+ else
+ genX_table = &gen7_dispatch_table;
+ break;
+ default:
+ unreachable("unsupported gen\n");
+ }
+
+ for (unsigned i = 0; i < ARRAY_SIZE(device->dispatch.entrypoints); i++) {
+ /* Vulkan requires that entrypoints for extensions which have not been
+ * enabled must not be advertised.
+ */
+ if (!anv_entrypoint_is_enabled(i, device->instance->apiVersion,
+ &device->instance->enabled_extensions,
+ &device->enabled_extensions)) {
+ device->dispatch.entrypoints[i] = NULL;
+ } else if (genX_table->entrypoints[i]) {
+ device->dispatch.entrypoints[i] = genX_table->entrypoints[i];
+ } else {
+ device->dispatch.entrypoints[i] = anv_dispatch_table.entrypoints[i];
+ }
+ }
+}
+
+static int
+vk_priority_to_gen(int priority)
+{
+ switch (priority) {
+ case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT:
+ return GEN_CONTEXT_LOW_PRIORITY;
+ case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT:
+ return GEN_CONTEXT_MEDIUM_PRIORITY;
+ case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT:
+ return GEN_CONTEXT_HIGH_PRIORITY;
+ case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT:
+ return GEN_CONTEXT_REALTIME_PRIORITY;
+ default:
+ unreachable("Invalid priority");
+ }
+}
+
VkResult anv_CreateDevice(
VkPhysicalDevice physicalDevice,
const VkDeviceCreateInfo* pCreateInfo,
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
+ struct anv_device_extension_table enabled_extensions = { };
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
- const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
- if (!anv_physical_device_extension_supported(physical_device, ext_name))
+ int idx;
+ for (idx = 0; idx < ANV_DEVICE_EXTENSION_COUNT; idx++) {
+ if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+ anv_device_extensions[idx].extensionName) == 0)
+ break;
+ }
+
+ if (idx >= ANV_DEVICE_EXTENSION_COUNT)
return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+ if (!physical_device->supported_extensions.extensions[idx])
+ return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+ enabled_extensions.extensions[idx] = true;
}
/* Check enabled features */
}
}
+ /* Check if client specified queue priority. */
+ const VkDeviceQueueGlobalPriorityCreateInfoEXT *queue_priority =
+ vk_find_struct_const(pCreateInfo->pQueueCreateInfos[0].pNext,
+ DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT);
+
+ VkQueueGlobalPriorityEXT priority =
+ queue_priority ? queue_priority->globalPriority :
+ VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
+
device = vk_alloc2(&physical_device->instance->alloc, pAllocator,
sizeof(*device), 8,
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
device->instance = physical_device->instance;
device->chipset_id = physical_device->chipset_id;
+ device->no_hw = physical_device->no_hw;
device->lost = false;
if (pAllocator)
goto fail_fd;
}
+ /* As per spec, the driver implementation may deny requests to acquire
+ * a priority above the default priority (MEDIUM) if the caller does not
+ * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
+ * is returned.
+ */
+ if (physical_device->has_context_priority) {
+ int err =
+ anv_gem_set_context_priority(device, vk_priority_to_gen(priority));
+ if (err != 0 && priority > VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT) {
+ result = vk_error(VK_ERROR_NOT_PERMITTED_EXT);
+ goto fail_fd;
+ }
+ }
+
device->info = physical_device->info;
device->isl_dev = physical_device->isl_dev;
device->robust_buffer_access = pCreateInfo->pEnabledFeatures &&
pCreateInfo->pEnabledFeatures->robustBufferAccess;
+ device->enabled_extensions = enabled_extensions;
+
+ anv_device_init_dispatch(device);
if (pthread_mutex_init(&device->mutex, NULL) != 0) {
result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
goto fail_batch_bo_pool;
/* For the state pools we explicitly disable 48bit. */
- bo_flags = physical_device->has_exec_async ? EXEC_OBJECT_ASYNC : 0;
+ bo_flags = (physical_device->has_exec_async ? EXEC_OBJECT_ASYNC : 0) |
+ (physical_device->has_exec_capture ? EXEC_OBJECT_CAPTURE : 0);
result = anv_state_pool_init(&device->dynamic_state_pool, device, 16384,
bo_flags);
goto fail_bo_cache;
result = anv_state_pool_init(&device->instruction_state_pool, device, 16384,
- bo_flags |
- (physical_device->has_exec_capture ? EXEC_OBJECT_CAPTURE : 0));
+ bo_flags);
if (result != VK_SUCCESS)
goto fail_dynamic_state_pool;
case 10:
result = gen10_init_device_state(device);
break;
+ case 11:
+ result = gen11_init_device_state(device);
+ break;
default:
/* Shouldn't get here as we don't create physical devices for any other
* gens. */
if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) {
ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
- /* For images using modifiers, we require a dedicated allocation
- * and we set the BO tiling to match the tiling of the underlying
- * modifier. This is a bit unfortunate as this is completely
- * pointless for Vulkan. However, GL needs to be able to map things
- * so it needs the tiling to be set. The only way to do this in a
- * non-racy way is to set the tiling in the creator of the BO so that
- * makes it our job.
- *
- * One of these days, once the GL driver learns to not map things
- * through the GTT in random places, we can drop this and start
- * allowing multiple modified images in the same BO.
+ /* Some legacy (non-modifiers) consumers need the tiling to be set on
+ * the BO. In this case, we have a dedicated allocation.
*/
- if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID) {
- assert(isl_drm_modifier_get_info(image->drm_format_mod)->tiling ==
- image->planes[0].surface.isl.tiling);
+ if (image->needs_set_tiling) {
const uint32_t i915_tiling =
isl_tiling_to_i915_tiling(image->planes[0].surface.isl.tiling);
int ret = anv_gem_set_tiling(device, mem->bo->gem_handle,
struct anv_physical_device *pdevice = &device->instance->physicalDevice;
switch (handleType) {
- case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+ case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
/* dma-buf can be imported as any memory type */
pMemoryFdProperties->memoryTypeBits =
(1 << pdevice->memory.type_count) - 1;
memory_types |= (1u << i);
}
+ /* Base alignment requirement of a cache line */
+ uint32_t alignment = 16;
+
+ /* We need an alignment of 32 for pushing UBOs */
+ if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
+ alignment = MAX2(alignment, 32);
+
pMemoryRequirements->size = buffer->size;
- pMemoryRequirements->alignment = 16;
+ pMemoryRequirements->alignment = alignment;
pMemoryRequirements->memoryTypeBits = memory_types;
}
switch (ext->sType) {
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR: {
VkMemoryDedicatedRequirementsKHR *requirements = (void *)ext;
- if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID) {
- /* Require a dedicated allocation for images with modifiers.
+ if (image->needs_set_tiling) {
+ /* If we need to set the tiling for external consumers, we need a
+ * dedicated allocation.
*
* See also anv_AllocateMemory.
*/