From f27f06d72cf6f2b79cd4fbb96dd5adc408df3719 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Tue, 21 Dec 2021 23:29:58 +0100 Subject: [PATCH] radv: Add a 32bit memory type. Got to put the commandbuffers & uploadbuffers there. With DGC those can be allocated by the application. Excluding it from all other buffers/images to avoid using the precious 32bit address space. Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_android.c | 5 +++-- src/amd/vulkan/radv_device.c | 28 +++++++++++++++++++++++----- src/amd/vulkan/radv_private.h | 3 +++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/amd/vulkan/radv_android.c b/src/amd/vulkan/radv_android.c index e8ceef1495f..2f691f7917b 100644 --- a/src/amd/vulkan/radv_android.c +++ b/src/amd/vulkan/radv_android.c @@ -146,7 +146,8 @@ radv_image_from_gralloc(VkDevice device_h, const VkImageCreateInfo *base_info, for (int i = 0; i < device->physical_device->memory_properties.memoryTypeCount; ++i) { bool is_local = !!(device->physical_device->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - if (is_local) { + bool is_32bit = !!(device->physical_device->memory_types_32bit & (1u << i)); + if (is_local && !is_32bit) { memory_type_index = i; break; } @@ -645,7 +646,7 @@ radv_GetAndroidHardwareBufferPropertiesANDROID(VkDevice device_h, uint32_t memory_types = (1u << pdevice->memory_properties.memoryTypeCount) - 1; pProperties->allocationSize = lseek(dma_buf, 0, SEEK_END); - pProperties->memoryTypeBits = memory_types; + pProperties->memoryTypeBits = memory_types & ~pdevice->memory_types_32bit; return VK_SUCCESS; } diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 15f6d6d2aa2..c7966eab1c6 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -248,6 +248,13 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device) .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, .heapIndex = vram_index >= 0 ? vram_index : visible_vram_index, }; + + device->memory_domains[type_count] = RADEON_DOMAIN_VRAM; + device->memory_flags[type_count] = RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_32BIT; + device->memory_properties.memoryTypes[type_count++] = (VkMemoryType){ + .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + .heapIndex = vram_index >= 0 ? vram_index : visible_vram_index, + }; } if (gart_index >= 0) { @@ -285,9 +292,10 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device) for (int i = 0; i < device->memory_properties.memoryTypeCount; i++) { VkMemoryType mem_type = device->memory_properties.memoryTypes[i]; - if ((mem_type.propertyFlags & - (VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) || - mem_type.propertyFlags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { + if (((mem_type.propertyFlags & + (VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) || + mem_type.propertyFlags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) && + !(device->memory_flags[i] & RADEON_FLAG_32BIT)) { VkMemoryPropertyFlags property_flags = mem_type.propertyFlags | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | @@ -303,6 +311,11 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device) } device->memory_properties.memoryTypeCount = type_count; } + + for (unsigned i = 0; i < type_count; ++i) { + if (device->memory_flags[i] & RADEON_FLAG_32BIT) + device->memory_types_32bit |= BITFIELD_BIT(i); + } } static const char * @@ -5462,7 +5475,8 @@ radv_get_buffer_memory_requirements(struct radv_device *device, VkDeviceSize siz VkMemoryRequirements2 *pMemoryRequirements) { pMemoryRequirements->memoryRequirements.memoryTypeBits = - (1u << device->physical_device->memory_properties.memoryTypeCount) - 1; + ((1u << device->physical_device->memory_properties.memoryTypeCount) - 1u) & + ~device->physical_device->memory_types_32bit; if (flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) pMemoryRequirements->memoryRequirements.alignment = 4096; @@ -5525,7 +5539,8 @@ radv_GetImageMemoryRequirements2(VkDevice _device, const VkImageMemoryRequiremen RADV_FROM_HANDLE(radv_image, image, pInfo->image); pMemoryRequirements->memoryRequirements.memoryTypeBits = - (1u << device->physical_device->memory_properties.memoryTypeCount) - 1; + ((1u << device->physical_device->memory_properties.memoryTypeCount) - 1u) & + ~device->physical_device->memory_types_32bit; pMemoryRequirements->memoryRequirements.size = image->size; pMemoryRequirements->memoryRequirements.alignment = image->alignment; @@ -6849,6 +6864,9 @@ radv_compute_valid_memory_types(struct radv_physical_device *dev, enum radeon_bo bits = radv_compute_valid_memory_types_attempt(dev, domains, flags, ignore_flags); } + /* Avoid 32-bit memory types for shared memory. */ + bits &= ~dev->memory_types_32bit; + return bits; } VKAPI_ATTR VkResult VKAPI_CALL diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 435824a1341..5c8122be9e9 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -318,6 +318,9 @@ struct radv_physical_device { enum radeon_bo_flag memory_flags[VK_MAX_MEMORY_TYPES]; unsigned heaps; + /* Bitmask of memory types that use the 32-bit address space. */ + uint32_t memory_types_32bit; + #ifndef _WIN32 int available_nodes; drmPciBusInfo bus_info;