mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-05 01:30:31 +01:00
util: Add align_uintptr and use it treewide to replace ALIGN that works on size_t and uintptr_t
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26866>
This commit is contained in:
parent
aa8ea0f1b9
commit
d6c258d9ee
11 changed files with 36 additions and 21 deletions
|
|
@ -167,7 +167,7 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
|
|||
/* Store block of offsets first, followed by the conversion descriptors (padded to the struct
|
||||
* alignment) */
|
||||
size += num_bindings * sizeof(uint32_t);
|
||||
size = ALIGN(size, alignof(struct vk_ycbcr_conversion_state));
|
||||
size = align_uintptr(size, alignof(struct vk_ycbcr_conversion_state));
|
||||
size += ycbcr_sampler_count * sizeof(struct vk_ycbcr_conversion_state);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
|
|||
set_layout->ycbcr_sampler_offsets_offset = (char *)ycbcr_sampler_offsets - (char *)set_layout;
|
||||
|
||||
uintptr_t first_ycbcr_sampler_offset = (uintptr_t)ycbcr_sampler_offsets + sizeof(uint32_t) * num_bindings;
|
||||
first_ycbcr_sampler_offset = ALIGN(first_ycbcr_sampler_offset, alignof(struct vk_ycbcr_conversion_state));
|
||||
first_ycbcr_sampler_offset = align_uintptr(first_ycbcr_sampler_offset, alignof(struct vk_ycbcr_conversion_state));
|
||||
ycbcr_samplers = (struct vk_ycbcr_conversion_state *)first_ycbcr_sampler_offset;
|
||||
} else
|
||||
set_layout->ycbcr_sampler_offsets_offset = 0;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "util/hash_table.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
#include "etnaviv_drmif.h"
|
||||
#include "etnaviv_priv.h"
|
||||
|
|
@ -59,7 +60,7 @@ void etna_cmd_stream_realloc(struct etna_cmd_stream *stream, size_t n)
|
|||
* Increase the command buffer size by 4 kiB. Here we pick 4 kiB
|
||||
* increment to prevent it from growing too much too quickly.
|
||||
*/
|
||||
size = ALIGN(stream->size + n, 1024);
|
||||
size = align_uintptr(stream->size + n, 1024);
|
||||
|
||||
/* Command buffer is too big for older kernel versions */
|
||||
if (size > 0x4000)
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ static bool si_update_shaders(struct si_context *sctx)
|
|||
shader->binary.code_size,
|
||||
pipeline_code_hash);
|
||||
|
||||
total_size += ALIGN(shader->binary.uploaded_code_size, 256);
|
||||
total_size += (uint32_t)align_uintptr(shader->binary.uploaded_code_size, 256);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@ size_t
|
|||
vmw_svga_winsys_stats_len(void)
|
||||
{
|
||||
const size_t pg_size = getpagesize();
|
||||
const size_t area_size_stat_pg = ALIGN(mksstat_area_size_stat, pg_size);
|
||||
const size_t area_size_info_pg = ALIGN(mksstat_area_size_info, pg_size);
|
||||
const size_t area_size_stat_pg = align_uintptr(mksstat_area_size_stat, pg_size);
|
||||
const size_t area_size_info_pg = align_uintptr(mksstat_area_size_info, pg_size);
|
||||
const size_t area_size_strs = vmw_svga_winsys_stats_names_len();
|
||||
const size_t area_size = area_size_stat_pg + area_size_info_pg + area_size_strs;
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ vmw_mksstat_get_pstat_time(uint8_t *page_addr, size_t page_size)
|
|||
static inline MKSGuestStatInfoEntry *
|
||||
vmw_mksstat_get_pinfo(uint8_t *page_addr, size_t page_size)
|
||||
{
|
||||
const size_t area_size_stat_pg = ALIGN(mksstat_area_size_stat, page_size);
|
||||
const size_t area_size_stat_pg = align_uintptr(mksstat_area_size_stat, page_size);
|
||||
return (MKSGuestStatInfoEntry *)(page_addr + area_size_stat_pg);
|
||||
}
|
||||
|
||||
|
|
@ -203,8 +203,8 @@ vmw_mksstat_get_pinfo(uint8_t *page_addr, size_t page_size)
|
|||
static inline char *
|
||||
vmw_mksstat_get_pstrs(uint8_t *page_addr, const size_t page_size)
|
||||
{
|
||||
const size_t area_size_info_pg = ALIGN(mksstat_area_size_info, page_size);
|
||||
const size_t area_size_stat_pg = ALIGN(mksstat_area_size_stat, page_size);
|
||||
const size_t area_size_info_pg = align_uintptr(mksstat_area_size_info, page_size);
|
||||
const size_t area_size_stat_pg = align_uintptr(mksstat_area_size_stat, page_size);
|
||||
return (char *)(page_addr + area_size_info_pg + area_size_stat_pg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ get_geometry(const VkAccelerationStructureBuildGeometryInfoKHR *pInfo,
|
|||
|
||||
static size_t align_transient_size(size_t bytes)
|
||||
{
|
||||
return ALIGN(bytes, 64);
|
||||
return align_uintptr(bytes, 64);
|
||||
}
|
||||
|
||||
static size_t align_private_size(size_t bytes)
|
||||
{
|
||||
return ALIGN(bytes, 64);
|
||||
return align_uintptr(bytes, 64);
|
||||
}
|
||||
|
||||
static size_t get_scheduler_size(size_t num_builds)
|
||||
|
|
@ -696,7 +696,7 @@ cmd_build_acceleration_structures(
|
|||
}
|
||||
|
||||
size_t geom_struct_size = bs->num_geometries * sizeof(struct Geo);
|
||||
size_t geom_prefix_sum_size = ALIGN(sizeof(uint32_t) * (bs->num_geometries + 1), 64);
|
||||
size_t geom_prefix_sum_size = align_uintptr(sizeof(uint32_t) * (bs->num_geometries + 1), 64);
|
||||
|
||||
bs->transient_size = geom_prefix_sum_size + geom_struct_size;
|
||||
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ _mesa_make_extension_string(struct gl_context *ctx)
|
|||
if (unrecognized_extensions.names[k])
|
||||
length += 1 + strlen(unrecognized_extensions.names[k]); /* +1 for space */
|
||||
|
||||
exts = calloc(ALIGN(length + 1, 4), sizeof(char));
|
||||
exts = calloc(align_uintptr(length + 1, 4), sizeof(char));
|
||||
if (exts == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ grow_to_fit(struct blob *blob, size_t additional)
|
|||
bool
|
||||
blob_align(struct blob *blob, size_t alignment)
|
||||
{
|
||||
const size_t new_size = ALIGN(blob->size, alignment);
|
||||
const size_t new_size = align_uintptr(blob->size, alignment);
|
||||
|
||||
if (blob->size < new_size) {
|
||||
if (!grow_to_fit(blob, new_size - blob->size))
|
||||
|
|
@ -102,7 +102,7 @@ blob_align(struct blob *blob, size_t alignment)
|
|||
void
|
||||
blob_reader_align(struct blob_reader *blob, size_t alignment)
|
||||
{
|
||||
blob->current = blob->data + ALIGN(blob->current - blob->data, alignment);
|
||||
blob->current = blob->data + align_uintptr(blob->current - blob->data, alignment);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -212,7 +212,7 @@ BLOB_WRITE_TYPE(blob_write_uint64, uint64_t)
|
|||
BLOB_WRITE_TYPE(blob_write_intptr, intptr_t)
|
||||
|
||||
#define ASSERT_ALIGNED(_offset, _align) \
|
||||
assert(ALIGN((_offset), (_align)) == (_offset))
|
||||
assert(align_uintptr((_offset), (_align)) == (_offset))
|
||||
|
||||
bool
|
||||
blob_overwrite_uint8 (struct blob *blob,
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ util_streaming_load_memcpy(void *restrict dst, void *restrict src, size_t len)
|
|||
|
||||
memcpy(d, s, MIN2(bytes_before_alignment_boundary, len));
|
||||
|
||||
d = (char *)ALIGN((uintptr_t)d, 16);
|
||||
s = (char *)ALIGN((uintptr_t)s, 16);
|
||||
d = (char *)align_uintptr((uintptr_t)d, 16);
|
||||
s = (char *)align_uintptr((uintptr_t)s, 16);
|
||||
len -= MIN2(bytes_before_alignment_boundary, len);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -685,6 +685,20 @@ align64(uint64_t value, uint64_t alignment)
|
|||
return ALIGN_POT(value, alignment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Align a value(uintptr_t, intptr_t, ptrdiff_t), only works pot alignemnts.
|
||||
*/
|
||||
static inline uintptr_t
|
||||
align_uintptr(uintptr_t value, uintptr_t alignment)
|
||||
{
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
assert(util_is_power_of_two_nonzero64(alignment));
|
||||
#else
|
||||
assert(util_is_power_of_two_nonzero(alignment));
|
||||
#endif
|
||||
return ALIGN_POT(value, alignment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Works like align but on npot alignments.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ u_printf_impl(FILE *out, const char *buffer, size_t buffer_size,
|
|||
free(print_str);
|
||||
|
||||
buf_pos += arg_size;
|
||||
buf_pos = ALIGN(buf_pos, 4);
|
||||
buf_pos = align_uintptr(buf_pos, 4);
|
||||
}
|
||||
|
||||
/* print remaining */
|
||||
|
|
|
|||
|
|
@ -1225,8 +1225,8 @@ static struct overlay_draw *render_swapchain_display(struct swapchain_data *data
|
|||
VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
/* Create/Resize vertex & index buffers */
|
||||
size_t vertex_size = ALIGN(draw_data->TotalVtxCount * sizeof(ImDrawVert), device_data->properties.limits.nonCoherentAtomSize);
|
||||
size_t index_size = ALIGN(draw_data->TotalIdxCount * sizeof(ImDrawIdx), device_data->properties.limits.nonCoherentAtomSize);
|
||||
size_t vertex_size = align_uintptr(draw_data->TotalVtxCount * sizeof(ImDrawVert), device_data->properties.limits.nonCoherentAtomSize);
|
||||
size_t index_size = align_uintptr(draw_data->TotalIdxCount * sizeof(ImDrawIdx), device_data->properties.limits.nonCoherentAtomSize);
|
||||
if (draw->vertex_buffer_size < vertex_size) {
|
||||
CreateOrResizeBuffer(device_data,
|
||||
&draw->vertex_buffer,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue