28
28
#include "radv_private.h"
31
radv_device_memory_init(struct radv_device_memory *mem, struct radv_device *device,
32
struct radeon_winsys_bo *bo)
31
radv_device_memory_init(struct radv_device_memory *mem, struct radv_device *device, struct radeon_winsys_bo *bo)
34
33
memset(mem, 0, sizeof(*mem));
35
34
vk_object_base_init(&device->vk, &mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY);
47
radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator,
48
struct radv_device_memory *mem)
46
radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator, struct radv_device_memory *mem)
87
85
assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
89
const VkImportMemoryFdInfoKHR *import_info =
90
vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
87
const VkImportMemoryFdInfoKHR *import_info = vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
91
88
const VkMemoryDedicatedAllocateInfo *dedicate_info =
92
89
vk_find_struct_const(pAllocateInfo->pNext, MEMORY_DEDICATED_ALLOCATE_INFO);
93
90
const VkExportMemoryAllocateInfo *export_info =
103
100
vk_find_struct_const(pAllocateInfo->pNext, WSI_MEMORY_ALLOCATE_INFO_MESA);
105
102
if (pAllocateInfo->allocationSize == 0 && !ahb_import_info &&
106
!(export_info && (export_info->handleTypes &
107
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID))) {
104
(export_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID))) {
108
105
/* Apparently, this is allowed */
109
106
*pMem = VK_NULL_HANDLE;
110
107
return VK_SUCCESS;
114
vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
110
mem = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
116
112
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
147
143
if (replay_info && replay_info->opaqueCaptureAddress)
148
144
replay_address = replay_info->opaqueCaptureAddress;
150
unsigned priority = MIN2(RADV_BO_PRIORITY_APPLICATION_MAX - 1,
151
(int)(priority_float * RADV_BO_PRIORITY_APPLICATION_MAX));
147
MIN2(RADV_BO_PRIORITY_APPLICATION_MAX - 1, (int)(priority_float * RADV_BO_PRIORITY_APPLICATION_MAX));
153
149
mem->user_ptr = NULL;
160
156
result = radv_import_ahb_memory(device, mem, priority, ahb_import_info);
161
157
if (result != VK_SUCCESS)
163
} else if (export_info && (export_info->handleTypes &
164
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
159
} else if (export_info &&
160
(export_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
165
161
result = radv_create_ahb_memory(device, mem, priority, pAllocateInfo);
166
162
if (result != VK_SUCCESS)
175
171
close(import_info->fd);
178
if (mem->image && mem->image->plane_count == 1 &&
179
!vk_format_is_depth_or_stencil(mem->image->vk.format) && mem->image->info.samples == 1 &&
180
mem->image->vk.tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
174
if (mem->image && mem->image->plane_count == 1 && !vk_format_is_depth_or_stencil(mem->image->vk.format) &&
175
mem->image->vk.samples == 1 && mem->image->vk.tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
181
176
struct radeon_bo_metadata metadata;
182
177
device->ws->buffer_get_metadata(device->ws, mem->bo, &metadata);
184
struct radv_image_create_info create_info = {.no_metadata_planes = true,
185
.bo_metadata = &metadata};
179
struct radv_image_create_info create_info = {.no_metadata_planes = true, .bo_metadata = &metadata};
187
181
/* This gives a basic ability to import radeonsi images
188
182
* that don't have DCC. This is not guaranteed by any
189
183
* spec and can be removed after we support modifiers. */
190
result = radv_image_create_layout(device, create_info, NULL, mem->image);
184
result = radv_image_create_layout(device, create_info, NULL, NULL, mem->image);
191
185
if (result != VK_SUCCESS) {
192
186
device->ws->buffer_destroy(device->ws, mem->bo);
196
190
} else if (host_ptr_info) {
197
191
assert(host_ptr_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT);
198
result = device->ws->buffer_from_ptr(device->ws, host_ptr_info->pHostPointer,
199
pAllocateInfo->allocationSize, priority, &mem->bo);
192
result = device->ws->buffer_from_ptr(device->ws, host_ptr_info->pHostPointer, pAllocateInfo->allocationSize,
200
194
if (result != VK_SUCCESS) {
206
200
uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096);
207
201
uint32_t heap_index;
210
device->physical_device->memory_properties.memoryTypes[pAllocateInfo->memoryTypeIndex]
203
heap_index = device->physical_device->memory_properties.memoryTypes[pAllocateInfo->memoryTypeIndex].heapIndex;
212
204
domain = device->physical_device->memory_domains[pAllocateInfo->memoryTypeIndex];
213
205
flags |= device->physical_device->memory_flags[pAllocateInfo->memoryTypeIndex];
236
228
flags |= RADEON_FLAG_ZERO_VRAM;
238
230
if (device->overallocation_disallowed) {
239
uint64_t total_size =
240
device->physical_device->memory_properties.memoryHeaps[heap_index].size;
231
uint64_t total_size = device->physical_device->memory_properties.memoryHeaps[heap_index].size;
242
233
mtx_lock(&device->overallocation_mutex);
243
234
if (device->allocated_memory_size[heap_index] + alloc_size > total_size) {
249
240
mtx_unlock(&device->overallocation_mutex);
252
result = device->ws->buffer_create(device->ws, alloc_size,
253
device->physical_device->rad_info.max_alignment, domain,
254
flags, priority, replay_address, &mem->bo);
243
result = device->ws->buffer_create(device->ws, alloc_size, device->physical_device->rad_info.max_alignment,
244
domain, flags, priority, replay_address, &mem->bo);
256
246
if (result != VK_SUCCESS) {
257
247
if (device->overallocation_disallowed) {
337
327
VKAPI_ATTR VkResult VKAPI_CALL
338
radv_FlushMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount,
339
const VkMappedMemoryRange *pMemoryRanges)
328
radv_FlushMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges)
341
330
return VK_SUCCESS;
344
333
VKAPI_ATTR VkResult VKAPI_CALL
345
radv_InvalidateMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount,
346
const VkMappedMemoryRange *pMemoryRanges)
334
radv_InvalidateMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges)
348
336
return VK_SUCCESS;
351
339
VKAPI_ATTR uint64_t VKAPI_CALL
352
radv_GetDeviceMemoryOpaqueCaptureAddress(VkDevice device,
353
const VkDeviceMemoryOpaqueCaptureAddressInfo *pInfo)
340
radv_GetDeviceMemoryOpaqueCaptureAddress(VkDevice device, const VkDeviceMemoryOpaqueCaptureAddressInfo *pInfo)
355
342
RADV_FROM_HANDLE(radv_device_memory, mem, pInfo->memory);
356
343
return radv_buffer_get_va(mem->bo);
359
346
VKAPI_ATTR void VKAPI_CALL
360
radv_GetDeviceMemoryCommitment(VkDevice device, VkDeviceMemory memory,
361
VkDeviceSize *pCommittedMemoryInBytes)
347
radv_GetDeviceMemoryCommitment(VkDevice device, VkDeviceMemory memory, VkDeviceSize *pCommittedMemoryInBytes)
363
349
*pCommittedMemoryInBytes = 0;