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 <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17269>
This commit is contained in:
Bas Nieuwenhuizen 2021-12-21 23:29:58 +01:00 committed by Marge Bot
parent b1c1d099a9
commit f27f06d72c
3 changed files with 29 additions and 7 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;