Skip to content

anv: reduce struct anv_image_memory_range from 32 to 24 bytes

Paulo Zanoni requested to merge pzanoni/mesa:anv_image_memory_range-pack into main
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.

Merge request reports