turnip: make possible to create read-only bo with tu_bo_init_new

GPU won't be able to write to such BOs, which would to useful for
cmdstream BOs.

Move "bool dump" to the new flags along the way.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10807>
This commit is contained in:
Danylo Piliaiev 2021-05-14 18:05:02 +03:00 committed by Marge Bot
parent d6f993e5d4
commit 413e7c6dc8
7 changed files with 33 additions and 11 deletions

View File

@ -110,7 +110,8 @@ tu_cs_add_bo(struct tu_cs *cs, uint32_t size)
return VK_ERROR_OUT_OF_HOST_MEMORY;
VkResult result =
tu_bo_init_new(cs->device, new_bo, size * sizeof(uint32_t), true);
tu_bo_init_new(cs->device, new_bo, size * sizeof(uint32_t),
TU_BO_ALLOC_ALLOW_DUMP);
if (result != VK_SUCCESS) {
free(new_bo);
return result;

View File

@ -557,7 +557,7 @@ tu_CreateDescriptorPool(VkDevice _device,
}
if (bo_size) {
ret = tu_bo_init_new(device, &pool->bo, bo_size, true);
ret = tu_bo_init_new(device, &pool->bo, bo_size, TU_BO_ALLOC_ALLOW_DUMP);
if (ret)
goto fail_alloc;

View File

@ -1357,7 +1357,8 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
if (custom_border_colors)
global_size += TU_BORDER_COLOR_COUNT * sizeof(struct bcolor_entry);
result = tu_bo_init_new(device, &device->global_bo, global_size, false);
result = tu_bo_init_new(device, &device->global_bo, global_size,
TU_BO_ALLOC_NO_FLAGS);
if (result != VK_SUCCESS) {
vk_startup_errorf(device->instance, result, "BO init");
goto fail_global_bo;
@ -1588,7 +1589,8 @@ tu_get_scratch_bo(struct tu_device *dev, uint64_t size, struct tu_bo **bo)
}
unsigned bo_size = 1ull << size_log2;
VkResult result = tu_bo_init_new(dev, &dev->scratch_bos[index].bo, bo_size, false);
VkResult result = tu_bo_init_new(dev, &dev->scratch_bos[index].bo, bo_size,
TU_BO_ALLOC_NO_FLAGS);
if (result != VK_SUCCESS) {
mtx_unlock(&dev->scratch_bos[index].construct_mtx);
return result;
@ -1778,7 +1780,8 @@ tu_AllocateMemory(VkDevice _device,
}
} else {
result =
tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize, false);
tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize,
TU_BO_ALLOC_NO_FLAGS);
}
@ -2005,7 +2008,8 @@ tu_CreateEvent(VkDevice _device,
if (!event)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkResult result = tu_bo_init_new(device, &event->bo, 0x1000, false);
VkResult result = tu_bo_init_new(device, &event->bo, 0x1000,
TU_BO_ALLOC_NO_FLAGS);
if (result != VK_SUCCESS)
goto fail_alloc;

View File

@ -279,7 +279,8 @@ tu_bo_init(struct tu_device *dev,
}
VkResult
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size, bool dump)
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size,
enum tu_bo_alloc_flags flags)
{
/* TODO: Choose better flags. As of 2018-11-12, freedreno/drm/msm_bo.c
* always sets `flags = MSM_BO_WC`, and we copy that behavior here.
@ -289,12 +290,15 @@ tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size, bool dump
.flags = MSM_BO_WC
};
if (flags & TU_BO_ALLOC_GPU_READ_ONLY)
req.flags |= MSM_BO_GPU_READONLY;
int ret = drmCommandWriteRead(dev->fd,
DRM_MSM_GEM_NEW, &req, sizeof(req));
if (ret)
return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
return tu_bo_init(dev, bo, req.handle, size, dump);
return tu_bo_init(dev, bo, req.handle, size, flags & TU_BO_ALLOC_ALLOW_DUMP);
}
VkResult

View File

@ -81,11 +81,16 @@ tu_drm_submitqueue_close(const struct tu_device *dev, uint32_t queue_id)
}
VkResult
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size, bool dump)
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size,
enum tu_bo_alloc_flags flags)
{
struct kgsl_gpumem_alloc_id req = {
.size = size,
};
if (flags & TU_BO_ALLOC_GPU_READ_ONLY)
req.flags |= KGSL_MEMFLAGS_GPUREADONLY;
int ret;
ret = safe_ioctl(dev->physical_device->local_fd,

View File

@ -423,8 +423,16 @@ tu_device_is_lost(struct tu_device *device)
VkResult
tu_device_submit_deferred_locked(struct tu_device *dev);
enum tu_bo_alloc_flags
{
TU_BO_ALLOC_NO_FLAGS = 0,
TU_BO_ALLOC_ALLOW_DUMP = 1 << 0,
TU_BO_ALLOC_GPU_READ_ONLY = 1 << 1,
};
VkResult
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size, bool dump);
tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size,
enum tu_bo_alloc_flags flags);
VkResult
tu_bo_init_dmabuf(struct tu_device *dev,
struct tu_bo *bo,

View File

@ -317,7 +317,7 @@ tu_CreateQueryPool(VkDevice _device,
}
VkResult result = tu_bo_init_new(device, &pool->bo,
pCreateInfo->queryCount * slot_size, false);
pCreateInfo->queryCount * slot_size, TU_BO_ALLOC_NO_FLAGS);
if (result != VK_SUCCESS) {
vk_object_free(&device->vk, pAllocator, pool);
return result;