blob: 22d12897614ed63d658fe987ad16fdf652f516e8 [file] [log] [blame]
From 769af5bee24c6f1420ccc423165aaf77f97c6beb Mon Sep 17 00:00:00 2001
From: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Date: Mon, 6 May 2019 15:44:04 +0200
Subject: [PATCH] radv: Use given stride for images imported from Android.
Handled similarly as radeonsi. I checked the offsets are actually used.
Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
(cherry picked from commit 8139efbbbd2f07cd4d88488ca5c34c2c19ef10d4)
Change-Id: I7357e651abf838d15166564800d4894c8db430d7
---
src/amd/vulkan/radv_android.c | 2 ++
src/amd/vulkan/radv_image.c | 28 ++++++++++++++++++++++++++++
src/amd/vulkan/radv_private.h | 5 +++++
3 files changed, 35 insertions(+)
diff --git a/src/amd/vulkan/radv_android.c b/src/amd/vulkan/radv_android.c
index 9613eabbe87..a0a35e23e76 100644
--- a/src/amd/vulkan/radv_android.c
+++ b/src/amd/vulkan/radv_android.c
@@ -191,6 +191,8 @@ radv_image_from_gralloc(VkDevice device_h,
image = radv_image_from_handle(image_h);
+ radv_image_override_offset_stride(device, image, 0, gralloc_info->stride);
+
radv_BindImageMemory(device_h, image_h, memory_h, 0);
image->owned_memory = memory_h;
diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index fc8c6a2ebfe..e3eafdd5fbe 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -749,6 +749,34 @@ radv_init_metadata(struct radv_device *device,
radv_query_opaque_metadata(device, image, metadata);
}
+void
+radv_image_override_offset_stride(struct radv_device *device,
+ struct radv_image *image,
+ uint64_t offset, uint32_t stride)
+{
+ struct radeon_surf *surface = &image->surface;
+ unsigned bpe = vk_format_get_blocksizebits(image->vk_format) / 8;
+
+ if (device->physical_device->rad_info.chip_class >= GFX9) {
+ if (stride) {
+ surface->u.gfx9.surf_pitch = stride;
+ surface->u.gfx9.surf_slice_size =
+ (uint64_t)stride * surface->u.gfx9.surf_height * bpe;
+ }
+ surface->u.gfx9.surf_offset = offset;
+ } else {
+ surface->u.legacy.level[0].nblk_x = stride;
+ surface->u.legacy.level[0].slice_size_dw =
+ ((uint64_t)stride * surface->u.legacy.level[0].nblk_y * bpe) / 4;
+
+ if (offset) {
+ for (unsigned i = 0; i < ARRAY_SIZE(surface->u.legacy.level); ++i)
+ surface->u.legacy.level[i].offset += offset;
+ }
+
+ }
+}
+
/* The number of samples can be specified independently of the texture. */
static void
radv_image_get_fmask_info(struct radv_device *device,
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 8714052e4a0..632038dd6b9 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1652,6 +1652,11 @@ radv_init_metadata(struct radv_device *device,
struct radv_image *image,
struct radeon_bo_metadata *metadata);
+void
+radv_image_override_offset_stride(struct radv_device *device,
+ struct radv_image *image,
+ uint64_t offset, uint32_t stride);
+
struct radv_image_view {
struct radv_image *image; /**< VkImageViewCreateInfo::image */
struct radeon_winsys_bo *bo;
--
2.21.0.1020.gf2820cf01a-goog