radv: Use given stride for images imported from Android.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 6 May 2019 13:44:04 +0000 (15:44 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 6 May 2019 15:36:39 +0000 (15:36 +0000)
Handled similarly as radeonsi. I checked the offsets are actually used.

Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_android.c
src/amd/vulkan/radv_image.c
src/amd/vulkan/radv_private.h

index 9613eabbe87d1984d2dea761bd8adfcb43de5c4b..a0a35e23e7673b2cb6c54addf274a50d86c1d06b 100644 (file)
@@ -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;
index 92409d147f1f3e3263f60c78bf9a977f0a83f34c..7c9a72c93c1c23bbfe035ca536fa92108f89a211 100644 (file)
@@ -760,6 +760,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->planes[0].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,
index df85d0cf889753c253633f74aa062cd97821d2a4..7fa0b39f2b01860b51b0c334395426de7c7459b0 100644 (file)
@@ -1672,6 +1672,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);
+
 union radv_descriptor {
        struct {
                uint32_t plane0_descriptor[8];