diff --git a/src/freedreno/vulkan/tu_cs.c b/src/freedreno/vulkan/tu_cs.c index e356b35cb2c..d29fca13f8b 100644 --- a/src/freedreno/vulkan/tu_cs.c +++ b/src/freedreno/vulkan/tu_cs.c @@ -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; diff --git a/src/freedreno/vulkan/tu_descriptor_set.c b/src/freedreno/vulkan/tu_descriptor_set.c index 4a89271a908..04f3673b1bb 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.c +++ b/src/freedreno/vulkan/tu_descriptor_set.c @@ -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; diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index a003a4c6911..677c67563ab 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -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; diff --git a/src/freedreno/vulkan/tu_drm.c b/src/freedreno/vulkan/tu_drm.c index a668556eca3..08dffeac5f7 100644 --- a/src/freedreno/vulkan/tu_drm.c +++ b/src/freedreno/vulkan/tu_drm.c @@ -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 diff --git a/src/freedreno/vulkan/tu_kgsl.c b/src/freedreno/vulkan/tu_kgsl.c index 6d968415f46..697c212c6b5 100644 --- a/src/freedreno/vulkan/tu_kgsl.c +++ b/src/freedreno/vulkan/tu_kgsl.c @@ -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, diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index 341c7c90a7c..8d3c5bc5a7d 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -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, diff --git a/src/freedreno/vulkan/tu_query.c b/src/freedreno/vulkan/tu_query.c index da8330057a6..b83b4f4bb70 100644 --- a/src/freedreno/vulkan/tu_query.c +++ b/src/freedreno/vulkan/tu_query.c @@ -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;