From ad4d13f184db930da7ac782e9afa270bb0939ae0 Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Wed, 10 Apr 2024 20:56:39 -0700 Subject: [PATCH] anv: reduce struct anv_image_memory_range from 32 to 24 bytes Reorder its members to fill the current padding hole, reducing the struct size from 32 to 24. This struct appears multiple times inside struct anv_image and its members, so this change brings down sizeof(struct anv_image) from 1744 to 1600. We went from: struct anv_image_memory_range { enum anv_image_memory_binding binding; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ uint64_t offset; /* 8 8 */ uint64_t size; /* 16 8 */ uint32_t alignment; /* 24 4 */ /* size: 32, cachelines: 1, members: 4 */ /* sum members: 24, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 32 bytes */ }; to: struct anv_image_memory_range { enum anv_image_memory_binding binding; /* 0 4 */ uint32_t alignment; /* 4 4 */ uint64_t size; /* 8 8 */ uint64_t offset; /* 16 8 */ /* size: 24, cachelines: 1, members: 4 */ /* last cacheline: 24 bytes */ }; Considering we can have tens of thousands of anv_image structs allocated at the same time on gaming workloads, this can save us a few MB of memory. It ain't much but it's honest work. Reviewed-by: Lionel Landwerlin Signed-off-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_image.c | 8 ++++---- src/intel/vulkan/anv_private.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 4925f689e90..3af8cb97243 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -170,9 +170,9 @@ image_binding_grow(const struct anv_device *device, *out_range = (struct anv_image_memory_range) { .binding = binding, - .offset = offset, - .size = size, .alignment = alignment, + .size = size, + .offset = offset, }; return VK_SUCCESS; @@ -1044,9 +1044,9 @@ memory_ranges_equal(struct anv_image_memory_range a, struct anv_image_memory_range b) { return a.binding == b.binding && - a.offset == b.offset && + a.alignment == b.alignment && a.size == b.size && - a.alignment == b.alignment; + a.offset == b.offset; } #endif diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index c7ad35125f3..641330f11c4 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -4987,14 +4987,14 @@ struct anv_image_memory_range { ANV_IMAGE_MEMORY_BINDING_END, } binding; + uint32_t alignment; + uint64_t size; + /** * Offset is relative to the start of the binding created by * vkBindImageMemory, not to the start of the bo. */ uint64_t offset; - - uint64_t size; - uint32_t alignment; }; /**