anv: Add get/set_tiling helpers
These are only required WSI cases and Android but still better to have them in a central place. Reviwed-by: Paulo Zanoni <paulo.r.zanoni@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13610>
This commit is contained in:

committed by
Marge Bot

parent
135cac5c9c
commit
0967584549
@@ -2019,6 +2019,38 @@ anv_device_export_bo(struct anv_device *device,
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
anv_device_get_bo_tiling(struct anv_device *device,
|
||||
struct anv_bo *bo,
|
||||
enum isl_tiling *tiling_out)
|
||||
{
|
||||
int i915_tiling = anv_gem_get_tiling(device, bo->gem_handle);
|
||||
if (i915_tiling < 0) {
|
||||
return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
|
||||
"failed to get BO tiling: %m");
|
||||
}
|
||||
|
||||
*tiling_out = isl_tiling_from_i915_tiling(i915_tiling);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
anv_device_set_bo_tiling(struct anv_device *device,
|
||||
struct anv_bo *bo,
|
||||
uint32_t row_pitch_B,
|
||||
enum isl_tiling tiling)
|
||||
{
|
||||
int ret = anv_gem_set_tiling(device, bo->gem_handle, row_pitch_B,
|
||||
isl_tiling_to_i915_tiling(tiling));
|
||||
if (ret) {
|
||||
return vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
||||
"failed to set BO tiling: %m");
|
||||
}
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static bool
|
||||
atomic_dec_not_one(uint32_t *counter)
|
||||
{
|
||||
|
@@ -522,28 +522,13 @@ anv_image_init_from_gralloc(struct anv_device *device,
|
||||
"failed to import dma-buf from VkNativeBufferANDROID");
|
||||
}
|
||||
|
||||
int i915_tiling = anv_gem_get_tiling(device, bo->gem_handle);
|
||||
switch (i915_tiling) {
|
||||
case I915_TILING_NONE:
|
||||
anv_info.isl_tiling_flags = ISL_TILING_LINEAR_BIT;
|
||||
break;
|
||||
case I915_TILING_X:
|
||||
anv_info.isl_tiling_flags = ISL_TILING_X_BIT;
|
||||
break;
|
||||
case I915_TILING_Y:
|
||||
anv_info.isl_tiling_flags = ISL_TILING_Y0_BIT;
|
||||
break;
|
||||
case -1:
|
||||
result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
|
||||
"DRM_IOCTL_I915_GEM_GET_TILING failed for "
|
||||
"VkNativeBufferANDROID");
|
||||
goto fail_tiling;
|
||||
default:
|
||||
result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
|
||||
"DRM_IOCTL_I915_GEM_GET_TILING returned unknown "
|
||||
"tiling %d for VkNativeBufferANDROID", i915_tiling);
|
||||
goto fail_tiling;
|
||||
enum isl_tiling tiling;
|
||||
result = anv_device_get_bo_tiling(device, bo, &tiling);
|
||||
if (result != VK_SUCCESS) {
|
||||
return vk_errorf(device, result,
|
||||
"failed to get tiling from VkNativeBufferANDROID");
|
||||
}
|
||||
anv_info.isl_tiling_flags = 1u << tiling;
|
||||
|
||||
enum isl_format format = anv_get_isl_format(&device->info,
|
||||
base_info->format,
|
||||
|
@@ -3866,15 +3866,12 @@ VkResult anv_AllocateMemory(
|
||||
* the BO. In this case, we have a dedicated allocation.
|
||||
*/
|
||||
if (image->vk.wsi_legacy_scanout) {
|
||||
const uint32_t i915_tiling =
|
||||
isl_tiling_to_i915_tiling(image->planes[0].primary_surface.isl.tiling);
|
||||
int ret = anv_gem_set_tiling(device, mem->bo->gem_handle,
|
||||
image->planes[0].primary_surface.isl.row_pitch_B,
|
||||
i915_tiling);
|
||||
if (ret) {
|
||||
const struct isl_surf *surf = &image->planes[0].primary_surface.isl;
|
||||
result = anv_device_set_bo_tiling(device, mem->bo,
|
||||
surf->row_pitch_B,
|
||||
surf->tiling);
|
||||
if (result != VK_SUCCESS) {
|
||||
anv_device_release_bo(device, mem->bo);
|
||||
result = vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
||||
"failed to set BO tiling: %m");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
@@ -1569,30 +1569,14 @@ resolve_ahw_image(struct anv_device *device,
|
||||
VkResult result;
|
||||
|
||||
/* Check tiling. */
|
||||
int i915_tiling = anv_gem_get_tiling(device, mem->bo->gem_handle);
|
||||
VkImageTiling vk_tiling;
|
||||
isl_tiling_flags_t isl_tiling_flags = 0;
|
||||
enum isl_tiling tiling;
|
||||
result = anv_device_get_bo_tiling(device, mem->bo, &tiling);
|
||||
assert(result == VK_SUCCESS);
|
||||
|
||||
switch (i915_tiling) {
|
||||
case I915_TILING_NONE:
|
||||
vk_tiling = VK_IMAGE_TILING_LINEAR;
|
||||
isl_tiling_flags = ISL_TILING_LINEAR_BIT;
|
||||
break;
|
||||
case I915_TILING_X:
|
||||
vk_tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
isl_tiling_flags = ISL_TILING_X_BIT;
|
||||
break;
|
||||
case I915_TILING_Y:
|
||||
vk_tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
isl_tiling_flags = ISL_TILING_Y0_BIT;
|
||||
break;
|
||||
case -1:
|
||||
default:
|
||||
unreachable("Invalid tiling flags.");
|
||||
}
|
||||
|
||||
assert(vk_tiling == VK_IMAGE_TILING_LINEAR ||
|
||||
vk_tiling == VK_IMAGE_TILING_OPTIMAL);
|
||||
VkImageTiling vk_tiling =
|
||||
tiling == ISL_TILING_LINEAR ? VK_IMAGE_TILING_LINEAR :
|
||||
VK_IMAGE_TILING_OPTIMAL;
|
||||
isl_tiling_flags_t isl_tiling_flags = (1u << tiling);
|
||||
|
||||
/* Check format. */
|
||||
VkFormat vk_format = vk_format_from_android(desc.format, desc.usage);
|
||||
|
@@ -1390,6 +1390,13 @@ VkResult anv_device_import_bo(struct anv_device *device, int fd,
|
||||
struct anv_bo **bo);
|
||||
VkResult anv_device_export_bo(struct anv_device *device,
|
||||
struct anv_bo *bo, int *fd_out);
|
||||
VkResult anv_device_get_bo_tiling(struct anv_device *device,
|
||||
struct anv_bo *bo,
|
||||
enum isl_tiling *tiling_out);
|
||||
VkResult anv_device_set_bo_tiling(struct anv_device *device,
|
||||
struct anv_bo *bo,
|
||||
uint32_t row_pitch_B,
|
||||
enum isl_tiling tiling);
|
||||
void anv_device_release_bo(struct anv_device *device,
|
||||
struct anv_bo *bo);
|
||||
|
||||
|
Reference in New Issue
Block a user