X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fintel%2Fvulkan%2Fanv_device.c;h=8c60b917050c111f3f2e6c73ae5a6d48cf73b206;hb=e7a1e8f7356922726ec38326b65e81a99d7ff96e;hp=f44b046cf5daa065754cacc82fc7ab873b15c9d9;hpb=9af77fcf98bd8084ff117ebbd9abfc1b695397d2;p=mesa.git diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index f44b046cf5d..8c60b917050 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include "drm-uapi/drm_fourcc.h" #include "anv_private.h" #include "util/strtod.h" @@ -41,12 +41,34 @@ #include "git_sha1.h" #include "vk_util.h" #include "common/gen_defines.h" +#include "compiler/glsl_types.h" #include "genxml/gen7_pack.h" +/* This is probably far to big but it reflects the max size used for messages + * in OpenGLs KHR_debug. + */ +#define MAX_DEBUG_MESSAGE_LENGTH 4096 + static void compiler_debug_log(void *data, const char *fmt, ...) -{ } +{ + char str[MAX_DEBUG_MESSAGE_LENGTH]; + struct anv_device *device = (struct anv_device *)data; + + if (list_empty(&device->instance->debug_report_callbacks.callbacks)) + return; + + va_list args; + va_start(args, fmt); + (void) vsnprintf(str, MAX_DEBUG_MESSAGE_LENGTH, fmt, args); + va_end(args); + + vk_debug_report(&device->instance->debug_report_callbacks, + VK_DEBUG_REPORT_DEBUG_BIT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, + 0, 0, 0, "anv", str); +} static void compiler_perf_log(void *data, const char *fmt, ...) @@ -128,6 +150,8 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd) */ device->memory.heap_count = 1; device->memory.heaps[0] = (struct anv_memory_heap) { + .vma_start = LOW_HEAP_MIN_ADDRESS, + .vma_size = LOW_HEAP_SIZE, .size = heap_size, .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, .supports_48bit_addresses = false, @@ -147,11 +171,19 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd) device->memory.heap_count = 2; device->memory.heaps[0] = (struct anv_memory_heap) { + .vma_start = HIGH_HEAP_MIN_ADDRESS, + /* Leave the last 4GiB out of the high vma range, so that no state + * base address + size can overflow 48 bits. For more information see + * the comment about Wa32bitGeneralStateOffset in anv_allocator.c + */ + .vma_size = gtt_size - (1ull << 32) - HIGH_HEAP_MIN_ADDRESS, .size = heap_size_48bit, .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, .supports_48bit_addresses = true, }; device->memory.heaps[1] = (struct anv_memory_heap) { + .vma_start = LOW_HEAP_MIN_ADDRESS, + .vma_size = LOW_HEAP_SIZE, .size = heap_size_32bit, .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, .supports_48bit_addresses = false, @@ -244,6 +276,8 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) _mesa_sha1_update(&sha1_ctx, build_id_data(note), build_id_len); _mesa_sha1_update(&sha1_ctx, &device->chipset_id, sizeof(device->chipset_id)); + _mesa_sha1_update(&sha1_ctx, &device->always_use_bindless, + sizeof(device->always_use_bindless)); _mesa_sha1_final(&sha1_ctx, sha1); memcpy(device->pipeline_cache_uuid, sha1, VK_UUID_SIZE); @@ -419,7 +453,14 @@ anv_physical_device_init(struct anv_physical_device *device, device->has_context_isolation = anv_gem_get_param(fd, I915_PARAM_HAS_CONTEXT_ISOLATION); - bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X); + device->always_use_bindless = + env_var_as_boolean("ANV_ALWAYS_BINDLESS", false); + + /* We first got the A64 messages on broadwell and we can only use them if + * we can pass addresses directly into the shader which requires softpin. + */ + device->has_a64_buffer_access = device->info.gen >= 8 && + device->use_softpin; /* Starting with Gen10, the timestamp frequency of the command streamer may * vary from one part to another. We can query the value from the kernel. @@ -473,6 +514,20 @@ anv_physical_device_init(struct anv_physical_device *device, device->info.gen < 8 || !device->has_context_isolation; device->compiler->supports_shader_constants = true; + /* Broadwell PRM says: + * + * "Before Gen8, there was a historical configuration control field to + * swizzle address bit[6] for in X/Y tiling modes. This was set in three + * different places: TILECTL[1:0], ARB_MODE[5:4], and + * DISP_ARB_CTL[14:13]. + * + * For Gen8 and subsequent generations, the swizzle fields are all + * reserved, and the CPU's memory controller performs all address + * swizzling modifications." + */ + bool swizzled = + device->info.gen < 8 && anv_gem_get_bit6_swizzle(fd, I915_TILING_X); + isl_device_init(&device->isl_dev, &device->info, swizzled); result = anv_physical_device_init_uuids(device); @@ -673,6 +728,7 @@ VkResult anv_CreateInstance( env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true); _mesa_locale_init(); + glsl_type_singleton_init_or_ref(); VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); @@ -703,6 +759,7 @@ void anv_DestroyInstance( vk_debug_report_instance_destroy(&instance->debug_report_callbacks); + glsl_type_singleton_decref(); _mesa_locale_fini(); vk_free(&instance->alloc, instance); @@ -800,7 +857,7 @@ VkResult anv_EnumeratePhysicalDeviceGroups( memset(p->physicalDevices, 0, sizeof(p->physicalDevices)); p->physicalDevices[0] = anv_physical_device_to_handle(&instance->physicalDevice); - p->subsetAllocation = VK_FALSE; + p->subsetAllocation = false; vk_foreach_struct(ext, p->pNext) anv_debug_ignored_stype(ext->sType); @@ -884,6 +941,7 @@ void anv_GetPhysicalDeviceFeatures2( VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures) { + ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); anv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features); vk_foreach_struct(ext, pFeatures->pNext) { @@ -891,8 +949,6 @@ void anv_GetPhysicalDeviceFeatures2( case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR: { VkPhysicalDevice8BitStorageFeaturesKHR *features = (VkPhysicalDevice8BitStorageFeaturesKHR *)ext; - ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); - features->storageBuffer8BitAccess = pdevice->info.gen >= 8; features->uniformAndStorageBuffer8BitAccess = pdevice->info.gen >= 8; features->storagePushConstant8 = pdevice->info.gen >= 8; @@ -902,8 +958,6 @@ void anv_GetPhysicalDeviceFeatures2( case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: { VkPhysicalDevice16BitStorageFeatures *features = (VkPhysicalDevice16BitStorageFeatures *)ext; - ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); - features->storageBuffer16BitAccess = pdevice->info.gen >= 8; features->uniformAndStorageBuffer16BitAccess = pdevice->info.gen >= 8; features->storagePushConstant16 = pdevice->info.gen >= 8; @@ -911,11 +965,25 @@ void anv_GetPhysicalDeviceFeatures2( break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT: { + VkPhysicalDeviceBufferDeviceAddressFeaturesEXT *features = (void *)ext; + features->bufferDeviceAddress = pdevice->has_a64_buffer_access; + features->bufferDeviceAddressCaptureReplay = false; + features->bufferDeviceAddressMultiDevice = false; + break; + } + + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: { + VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features = + (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext; + features->computeDerivativeGroupQuads = true; + features->computeDerivativeGroupLinear = true; + break; + } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: { VkPhysicalDeviceConditionalRenderingFeaturesEXT *features = (VkPhysicalDeviceConditionalRenderingFeaturesEXT*)ext; - ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); - features->conditionalRendering = pdevice->info.gen >= 8 || pdevice->info.is_haswell; features->inheritedConditionalRendering = pdevice->info.gen >= 8 || @@ -923,6 +991,35 @@ void anv_GetPhysicalDeviceFeatures2( break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: { + VkPhysicalDeviceDepthClipEnableFeaturesEXT *features = + (VkPhysicalDeviceDepthClipEnableFeaturesEXT *)ext; + features->depthClipEnable = true; + break; + } + + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: { + VkPhysicalDeviceFloat16Int8FeaturesKHR *features = (void *)ext; + features->shaderFloat16 = pdevice->info.gen >= 8; + features->shaderInt8 = pdevice->info.gen >= 8; + break; + } + + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT: { + VkPhysicalDeviceHostQueryResetFeaturesEXT *features = + (VkPhysicalDeviceHostQueryResetFeaturesEXT *)ext; + features->hostQueryReset = true; + break; + } + + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: { + VkPhysicalDeviceInlineUniformBlockFeaturesEXT *features = + (VkPhysicalDeviceInlineUniformBlockFeaturesEXT *)ext; + features->inlineUniformBlock = true; + features->descriptorBindingInlineUniformBlockUpdateAfterBind = false; + break; + } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: { VkPhysicalDeviceMultiviewFeatures *features = (VkPhysicalDeviceMultiviewFeatures *)ext; @@ -934,7 +1031,7 @@ void anv_GetPhysicalDeviceFeatures2( case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: { VkPhysicalDeviceProtectedMemoryFeatures *features = (void *)ext; - features->protectedMemory = VK_FALSE; + features->protectedMemory = false; break; } @@ -952,14 +1049,14 @@ void anv_GetPhysicalDeviceFeatures2( break; } - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES: { - VkPhysicalDeviceShaderDrawParameterFeatures *features = (void *)ext; + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES: { + VkPhysicalDeviceShaderDrawParametersFeatures *features = (void *)ext; features->shaderDrawParameters = true; break; } - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES: { - VkPhysicalDeviceVariablePointerFeatures *features = (void *)ext; + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES: { + VkPhysicalDeviceVariablePointersFeatures *features = (void *)ext; features->variablePointersStorageBuffer = true; features->variablePointers = true; break; @@ -968,16 +1065,23 @@ void anv_GetPhysicalDeviceFeatures2( case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT: { VkPhysicalDeviceTransformFeedbackFeaturesEXT *features = (VkPhysicalDeviceTransformFeedbackFeaturesEXT *)ext; - features->transformFeedback = VK_TRUE; - features->geometryStreams = VK_TRUE; + features->transformFeedback = true; + features->geometryStreams = true; break; } case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: { VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features = (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *)ext; - features->vertexAttributeInstanceRateDivisor = VK_TRUE; - features->vertexAttributeInstanceRateZeroDivisor = VK_TRUE; + features->vertexAttributeInstanceRateDivisor = true; + features->vertexAttributeInstanceRateZeroDivisor = true; + break; + } + + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT: { + VkPhysicalDeviceYcbcrImageArraysFeaturesEXT *features = + (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT *)ext; + features->ycbcrImageArrays = true; break; } @@ -1002,8 +1106,6 @@ void anv_GetPhysicalDeviceProperties( const uint32_t max_samplers = (devinfo->gen >= 8 || devinfo->is_haswell) ? 128 : 16; - const uint32_t max_images = devinfo->gen < 9 ? MAX_GEN8_IMAGES : MAX_IMAGES; - VkSampleCountFlags sample_counts = isl_device_get_sample_counts(&pdevice->isl_dev); @@ -1027,16 +1129,16 @@ void anv_GetPhysicalDeviceProperties( .maxPerStageDescriptorUniformBuffers = 64, .maxPerStageDescriptorStorageBuffers = 64, .maxPerStageDescriptorSampledImages = max_samplers, - .maxPerStageDescriptorStorageImages = max_images, + .maxPerStageDescriptorStorageImages = MAX_IMAGES, .maxPerStageDescriptorInputAttachments = 64, - .maxPerStageResources = 250, + .maxPerStageResources = MAX_BINDING_TABLE_SIZE - MAX_RTS, .maxDescriptorSetSamplers = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSamplers */ .maxDescriptorSetUniformBuffers = 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */ .maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2, .maxDescriptorSetStorageBuffers = 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */ .maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2, .maxDescriptorSetSampledImages = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSampledImages */ - .maxDescriptorSetStorageImages = 6 * max_images, /* number of stages * maxPerStageDescriptorStorageImages */ + .maxDescriptorSetStorageImages = 6 * MAX_IMAGES, /* number of stages * maxPerStageDescriptorStorageImages */ .maxDescriptorSetInputAttachments = 256, .maxVertexInputAttributes = MAX_VBS, .maxVertexInputBindings = MAX_VBS, @@ -1062,15 +1164,15 @@ void anv_GetPhysicalDeviceProperties( .maxFragmentCombinedOutputResources = 8, .maxComputeSharedMemorySize = 32768, .maxComputeWorkGroupCount = { 65535, 65535, 65535 }, - .maxComputeWorkGroupInvocations = 16 * devinfo->max_cs_threads, + .maxComputeWorkGroupInvocations = 32 * devinfo->max_cs_threads, .maxComputeWorkGroupSize = { 16 * devinfo->max_cs_threads, 16 * devinfo->max_cs_threads, 16 * devinfo->max_cs_threads, }, - .subPixelPrecisionBits = 4 /* FIXME */, - .subTexelPrecisionBits = 4 /* FIXME */, - .mipmapPrecisionBits = 4 /* FIXME */, + .subPixelPrecisionBits = 8, + .subTexelPrecisionBits = 8, + .mipmapPrecisionBits = 8, .maxDrawIndexedIndexValue = UINT32_MAX, .maxDrawIndirectCount = UINT32_MAX, .maxSamplerLodBias = 16, @@ -1171,8 +1273,8 @@ void anv_GetPhysicalDeviceProperties2( VK_RESOLVE_MODE_MAX_BIT_KHR; } - props->independentResolveNone = VK_TRUE; - props->independentResolve = VK_TRUE; + props->independentResolveNone = true; + props->independentResolve = true; break; } @@ -1196,6 +1298,14 @@ void anv_GetPhysicalDeviceProperties2( break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT: { + VkPhysicalDeviceExternalMemoryHostPropertiesEXT *props = + (VkPhysicalDeviceExternalMemoryHostPropertiesEXT *) ext; + /* Userptr needs page aligned memory. */ + props->minImportedHostPointerAlignment = 4096; + break; + } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: { VkPhysicalDeviceIDProperties *id_props = (VkPhysicalDeviceIDProperties *)ext; @@ -1206,6 +1316,21 @@ void anv_GetPhysicalDeviceProperties2( break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT: { + VkPhysicalDeviceInlineUniformBlockPropertiesEXT *props = + (VkPhysicalDeviceInlineUniformBlockPropertiesEXT *)ext; + props->maxInlineUniformBlockSize = MAX_INLINE_UNIFORM_BLOCK_SIZE; + props->maxPerStageDescriptorInlineUniformBlocks = + MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS; + props->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = + MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS; + props->maxDescriptorSetInlineUniformBlocks = + MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS; + props->maxDescriptorSetUpdateAfterBindInlineUniformBlocks = + MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS; + break; + } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: { VkPhysicalDeviceMaintenance3Properties *props = (VkPhysicalDeviceMaintenance3Properties *)ext; @@ -1286,7 +1411,7 @@ void anv_GetPhysicalDeviceProperties2( VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT | VK_SUBGROUP_FEATURE_CLUSTERED_BIT | VK_SUBGROUP_FEATURE_QUAD_BIT; - properties->quadOperationsInAllStages = VK_TRUE; + properties->quadOperationsInAllStages = true; break; } @@ -1300,10 +1425,10 @@ void anv_GetPhysicalDeviceProperties2( props->maxTransformFeedbackStreamDataSize = 128 * 4; props->maxTransformFeedbackBufferDataSize = 128 * 4; props->maxTransformFeedbackBufferDataStride = 2048; - props->transformFeedbackQueries = VK_TRUE; - props->transformFeedbackStreamsLinesTriangles = VK_FALSE; - props->transformFeedbackRasterizationStreamSelect = VK_FALSE; - props->transformFeedbackDraw = VK_TRUE; + props->transformFeedbackQueries = true; + props->transformFeedbackStreamsLinesTriangles = false; + props->transformFeedbackRasterizationStreamSelect = false; + props->transformFeedbackDraw = true; break; } @@ -1708,6 +1833,65 @@ anv_device_init_hiz_clear_value_bo(struct anv_device *device) anv_gem_munmap(map, device->hiz_clear_bo.size); } +static bool +get_bo_from_pool(struct gen_batch_decode_bo *ret, + struct anv_block_pool *pool, + uint64_t address) +{ + for (uint32_t i = 0; i < pool->nbos; i++) { + uint64_t bo_address = pool->bos[i].offset & (~0ull >> 16); + uint32_t bo_size = pool->bos[i].size; + if (address >= bo_address && address < (bo_address + bo_size)) { + *ret = (struct gen_batch_decode_bo) { + .addr = bo_address, + .size = bo_size, + .map = pool->bos[i].map, + }; + return true; + } + } + return false; +} + +/* Finding a buffer for batch decoding */ +static struct gen_batch_decode_bo +decode_get_bo(void *v_batch, bool ppgtt, uint64_t address) +{ + struct anv_device *device = v_batch; + struct gen_batch_decode_bo ret_bo = {}; + + assert(ppgtt); + + if (get_bo_from_pool(&ret_bo, &device->dynamic_state_pool.block_pool, address)) + return ret_bo; + if (get_bo_from_pool(&ret_bo, &device->instruction_state_pool.block_pool, address)) + return ret_bo; + if (get_bo_from_pool(&ret_bo, &device->binding_table_pool.block_pool, address)) + return ret_bo; + if (get_bo_from_pool(&ret_bo, &device->surface_state_pool.block_pool, address)) + return ret_bo; + + if (!device->cmd_buffer_being_decoded) + return (struct gen_batch_decode_bo) { }; + + struct anv_batch_bo **bo; + + u_vector_foreach(bo, &device->cmd_buffer_being_decoded->seen_bbos) { + /* The decoder zeroes out the top 16 bits, so we need to as well */ + uint64_t bo_address = (*bo)->bo.offset & (~0ull >> 16); + + if (address >= bo_address && address < bo_address + (*bo)->bo.size) { + return (struct gen_batch_decode_bo) { + .addr = bo_address, + .size = (*bo)->bo.size, + .map = (*bo)->bo.map, + }; + } + } + + return (struct gen_batch_decode_bo) { }; +} + VkResult anv_CreateDevice( VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, @@ -1775,6 +1959,17 @@ VkResult anv_CreateDevice( if (!device) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + const unsigned decode_flags = + GEN_BATCH_DECODE_FULL | + ((INTEL_DEBUG & DEBUG_COLOR) ? GEN_BATCH_DECODE_IN_COLOR : 0) | + GEN_BATCH_DECODE_OFFSETS | + GEN_BATCH_DECODE_FLOATS; + + gen_batch_decode_ctx_init(&device->decoder_ctx, + &physical_device->info, + stderr, decode_flags, NULL, + decode_get_bo, NULL, device); + device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; device->instance = physical_device->instance; device->chipset_id = physical_device->chipset_id; @@ -1806,20 +2001,20 @@ VkResult anv_CreateDevice( } /* keep the page with address zero out of the allocator */ - util_vma_heap_init(&device->vma_lo, LOW_HEAP_MIN_ADDRESS, LOW_HEAP_SIZE); - device->vma_lo_available = - physical_device->memory.heaps[physical_device->memory.heap_count - 1].size; - - /* Leave the last 4GiB out of the high vma range, so that no state base - * address + size can overflow 48 bits. For more information see the - * comment about Wa32bitGeneralStateOffset in anv_allocator.c - */ - util_vma_heap_init(&device->vma_hi, HIGH_HEAP_MIN_ADDRESS, - HIGH_HEAP_SIZE); + struct anv_memory_heap *low_heap = + &physical_device->memory.heaps[physical_device->memory.heap_count - 1]; + util_vma_heap_init(&device->vma_lo, low_heap->vma_start, low_heap->vma_size); + device->vma_lo_available = low_heap->size; + + struct anv_memory_heap *high_heap = + &physical_device->memory.heaps[0]; + util_vma_heap_init(&device->vma_hi, high_heap->vma_start, high_heap->vma_size); device->vma_hi_available = physical_device->memory.heap_count == 1 ? 0 : - physical_device->memory.heaps[0].size; + high_heap->size; } + list_inithead(&device->memory_objects); + /* 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 @@ -1866,7 +2061,7 @@ VkResult anv_CreateDevice( result = vk_error(VK_ERROR_INITIALIZATION_FAILED); goto fail_mutex; } - if (pthread_cond_init(&device->queue_submit, NULL) != 0) { + if (pthread_cond_init(&device->queue_submit, &condattr) != 0) { pthread_condattr_destroy(&condattr); result = vk_error(VK_ERROR_INITIALIZATION_FAILED); goto fail_mutex; @@ -2056,6 +2251,8 @@ void anv_DestroyDevice( anv_gem_destroy_context(device, device->context_id); + gen_batch_decode_ctx_finish(&device->decoder_ctx); + close(device->fd); vk_free(&device->alloc, device); @@ -2276,8 +2473,11 @@ anv_vma_free(struct anv_device *device, struct anv_bo *bo) util_vma_heap_free(&device->vma_lo, addr_48b, bo->size); device->vma_lo_available += bo->size; } else { - assert(addr_48b >= HIGH_HEAP_MIN_ADDRESS && - addr_48b <= HIGH_HEAP_MAX_ADDRESS); + MAYBE_UNUSED const struct anv_physical_device *physical_device = + &device->instance->physicalDevice; + assert(addr_48b >= physical_device->memory.heaps[0].vma_start && + addr_48b < (physical_device->memory.heaps[0].vma_start + + physical_device->memory.heaps[0].vma_size)); util_vma_heap_free(&device->vma_hi, addr_48b, bo->size); device->vma_hi_available += bo->size; } @@ -2330,6 +2530,7 @@ VkResult anv_AllocateMemory( mem->map = NULL; mem->map_size = 0; mem->ahw = NULL; + mem->host_ptr = NULL; uint64_t bo_flags = 0; @@ -2442,6 +2643,30 @@ VkResult anv_AllocateMemory( goto success; } + const VkImportMemoryHostPointerInfoEXT *host_ptr_info = + vk_find_struct_const(pAllocateInfo->pNext, + IMPORT_MEMORY_HOST_POINTER_INFO_EXT); + if (host_ptr_info && host_ptr_info->handleType) { + if (host_ptr_info->handleType == + VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT) { + result = vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE); + goto fail; + } + + assert(host_ptr_info->handleType == + VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT); + + result = anv_bo_cache_import_host_ptr( + device, &device->bo_cache, host_ptr_info->pHostPointer, + pAllocateInfo->allocationSize, bo_flags, &mem->bo); + + if (result != VK_SUCCESS) + goto fail; + + mem->host_ptr = host_ptr_info->pHostPointer; + goto success; + } + /* Regular allocate (not importing memory). */ if (export_info && export_info->handleTypes) @@ -2477,6 +2702,10 @@ VkResult anv_AllocateMemory( } success: + pthread_mutex_lock(&device->mutex); + list_addtail(&mem->link, &device->memory_objects); + pthread_mutex_unlock(&device->mutex); + *pMem = anv_device_memory_to_handle(mem); return VK_SUCCESS; @@ -2531,6 +2760,32 @@ VkResult anv_GetMemoryFdPropertiesKHR( } } +VkResult anv_GetMemoryHostPointerPropertiesEXT( + VkDevice _device, + VkExternalMemoryHandleTypeFlagBits handleType, + const void* pHostPointer, + VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + + assert(pMemoryHostPointerProperties->sType == + VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT); + + switch (handleType) { + case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT: { + struct anv_physical_device *pdevice = &device->instance->physicalDevice; + + /* Host memory can be imported as any memory type. */ + pMemoryHostPointerProperties->memoryTypeBits = + (1ull << pdevice->memory.type_count) - 1; + + return VK_SUCCESS; + } + default: + return VK_ERROR_INVALID_EXTERNAL_HANDLE; + } +} + void anv_FreeMemory( VkDevice _device, VkDeviceMemory _mem, @@ -2542,12 +2797,16 @@ void anv_FreeMemory( if (mem == NULL) return; + pthread_mutex_lock(&device->mutex); + list_del(&mem->link); + pthread_mutex_unlock(&device->mutex); + if (mem->map) anv_UnmapMemory(_device, _mem); anv_bo_cache_release(device, &device->bo_cache, mem->bo); -#ifdef ANDROID +#if defined(ANDROID) && ANDROID_API_LEVEL >= 26 if (mem->ahw) AHardwareBuffer_release(mem->ahw); #endif @@ -2571,6 +2830,11 @@ VkResult anv_MapMemory( return VK_SUCCESS; } + if (mem->host_ptr) { + *ppData = mem->host_ptr + offset; + return VK_SUCCESS; + } + if (size == VK_WHOLE_SIZE) size = mem->bo->size - offset; @@ -2623,7 +2887,7 @@ void anv_UnmapMemory( { ANV_FROM_HANDLE(anv_device_memory, mem, _memory); - if (mem == NULL) + if (mem == NULL || mem->host_ptr) return; anv_gem_munmap(mem->map, mem->map_size); @@ -2741,8 +3005,8 @@ void anv_GetBufferMemoryRequirements2( switch (ext->sType) { case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: { VkMemoryDedicatedRequirements *requirements = (void *)ext; - requirements->prefersDedicatedAllocation = VK_FALSE; - requirements->requiresDedicatedAllocation = VK_FALSE; + requirements->prefersDedicatedAllocation = false; + requirements->requiresDedicatedAllocation = false; break; } @@ -2847,11 +3111,11 @@ void anv_GetImageMemoryRequirements2( * * See also anv_AllocateMemory. */ - requirements->prefersDedicatedAllocation = VK_TRUE; - requirements->requiresDedicatedAllocation = VK_TRUE; + requirements->prefersDedicatedAllocation = true; + requirements->requiresDedicatedAllocation = true; } else { - requirements->prefersDedicatedAllocation = VK_FALSE; - requirements->requiresDedicatedAllocation = VK_FALSE; + requirements->prefersDedicatedAllocation = false; + requirements->requiresDedicatedAllocation = false; } break; } @@ -3091,6 +3355,17 @@ void anv_DestroyBuffer( vk_free2(&device->alloc, pAllocator, buffer); } +VkDeviceAddress anv_GetBufferDeviceAddressEXT( + VkDevice device, + const VkBufferDeviceAddressInfoEXT* pInfo) +{ + ANV_FROM_HANDLE(anv_buffer, buffer, pInfo->buffer); + + assert(buffer->address.bo->flags & EXEC_OBJECT_PINNED); + + return anv_address_physical(buffer->address); +} + void anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state, enum isl_format format, @@ -3102,6 +3377,7 @@ anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state, .mocs = device->default_mocs, .size_B = range, .format = format, + .swizzle = ISL_SWIZZLE_IDENTITY, .stride_B = stride); }