broadcom: replace redefined ALIGN() macro with common util functions

`cl_aligned_packet_length()` expand literals, so use ALIGN_POT to compute it
at compile time.

`v3dv_AllocateMemory()` uses a 64-bit `allocationSize`, so use `align64()`.

`v3d_lower_nir()` uses a 32-bit `shared_size`, so use `align()`.

Extracted out of https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23932
for easier review.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23938>
This commit is contained in:
Yonggang Luo 2023-06-29 11:32:05 +08:00 committed by Marge Bot
parent 9a8a7aaf1d
commit 38935d9789
3 changed files with 4 additions and 9 deletions

View file

@ -660,7 +660,7 @@ v3d_lower_nir(struct v3d_compile *c)
*/
const unsigned chunk_size = 16; /* max single store size */
NIR_PASS(_, c->s, nir_zero_initialize_shared_memory,
ALIGN(c->s->info.shared_size, chunk_size), chunk_size);
align(c->s->info.shared_size, chunk_size), chunk_size);
}
NIR_PASS(_, c->s, nir_lower_compute_system_values, NULL);

View file

@ -27,6 +27,7 @@
#include "broadcom/cle/v3d_packet_helpers.h"
#include "util/list.h"
#include "util/macros.h"
struct v3dv_bo;
struct v3dv_job;
@ -150,15 +151,9 @@ cl_aligned_reloc(struct v3dv_cl *cl,
uint32_t v3dv_cl_ensure_space(struct v3dv_cl *cl, uint32_t space, uint32_t alignment);
void v3dv_cl_ensure_space_with_branch(struct v3dv_cl *cl, uint32_t space);
/* We redefine ALIGN as a macro as we want to use cl_aligned_packet_length for
* struct fields
*/
#define ALIGN(value, alignment) \
(((value) + (alignment) - 1) & ~((alignment) - 1))
#define cl_packet_header(packet) V3DX(packet ## _header)
#define cl_packet_length(packet) V3DX(packet ## _length)
#define cl_aligned_packet_length(packet, alignment) ALIGN(cl_packet_length(packet), alignment)
#define cl_aligned_packet_length(packet, alignment) ALIGN_POT(cl_packet_length(packet), alignment)
#define cl_packet_pack(packet) V3DX(packet ## _pack)
#define cl_packet_struct(packet) V3DX(packet)

View file

@ -2357,7 +2357,7 @@ v3dv_AllocateMemory(VkDevice _device,
/* We always allocate device memory in multiples of a page, so round up
* requested size to that.
*/
const VkDeviceSize alloc_size = ALIGN(pAllocateInfo->allocationSize, 4096);
const VkDeviceSize alloc_size = align64(pAllocateInfo->allocationSize, 4096);
if (unlikely(alloc_size > MAX_MEMORY_ALLOCATION_SIZE))
return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);