diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c b/src/gallium/auxiliary/tgsi/tgsi_info.c index 7cac984..d4529b1 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_info.c +++ b/src/gallium/auxiliary/tgsi/tgsi_info.c @@ -308,7 +308,7 @@ tgsi_get_opcode_info( uint opcode ) if (firsttime) { unsigned i; firsttime = 0; - for (i = 0; i < Elements(opcode_info); i++) + for (i = 0; i < ARRAY_SIZE(opcode_info); i++) assert(opcode_info[i].opcode == i); } diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c index df7adb1..f88ac7c 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_scan.c +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c @@ -61,7 +61,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens, memset(info, 0, sizeof(*info)); for (i = 0; i < TGSI_FILE_COUNT; i++) info->file_max[i] = -1; - for (i = 0; i < Elements(info->const_file_max); i++) + for (i = 0; i < ARRAY_SIZE(info->const_file_max); i++) info->const_file_max[i] = -1; info->properties[TGSI_PROPERTY_GS_INVOCATIONS] = 1; @@ -209,7 +209,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens, /* MSAA samplers */ if (src->Register.File == TGSI_FILE_SAMPLER) { assert(fullinst->Instruction.Texture); - assert((unsigned)src->Register.Index < Elements(info->is_msaa_sampler)); + assert((unsigned)src->Register.Index < ARRAY_SIZE(info->is_msaa_sampler)); if (fullinst->Instruction.Texture && (fullinst->Texture.Texture == TGSI_TEXTURE_2D_MSAA || @@ -430,7 +430,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens, unsigned name = fullprop->Property.PropertyName; unsigned value = fullprop->u[0].Data; - assert(name < Elements(info->properties)); + assert(name < ARRAY_SIZE(info->properties)); info->properties[name] = value; switch (name) { diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c b/src/gallium/auxiliary/tgsi/tgsi_strings.c index ae6efb7..b5fd8f0 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_strings.c +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c @@ -231,12 +231,12 @@ const char *tgsi_memory_names[3] = static inline void UNUSED tgsi_strings_check(void) { - STATIC_ASSERT(Elements(tgsi_semantic_names) == TGSI_SEMANTIC_COUNT); - STATIC_ASSERT(Elements(tgsi_texture_names) == TGSI_TEXTURE_COUNT); - STATIC_ASSERT(Elements(tgsi_property_names) == TGSI_PROPERTY_COUNT); - STATIC_ASSERT(Elements(tgsi_primitive_names) == PIPE_PRIM_MAX); - STATIC_ASSERT(Elements(tgsi_interpolate_names) == TGSI_INTERPOLATE_COUNT); - STATIC_ASSERT(Elements(tgsi_return_type_names) == TGSI_RETURN_TYPE_COUNT); + STATIC_ASSERT(ARRAY_SIZE(tgsi_semantic_names) == TGSI_SEMANTIC_COUNT); + STATIC_ASSERT(ARRAY_SIZE(tgsi_texture_names) == TGSI_TEXTURE_COUNT); + STATIC_ASSERT(ARRAY_SIZE(tgsi_property_names) == TGSI_PROPERTY_COUNT); + STATIC_ASSERT(ARRAY_SIZE(tgsi_primitive_names) == PIPE_PRIM_MAX); + STATIC_ASSERT(ARRAY_SIZE(tgsi_interpolate_names) == TGSI_INTERPOLATE_COUNT); + STATIC_ASSERT(ARRAY_SIZE(tgsi_return_type_names) == TGSI_RETURN_TYPE_COUNT); (void) tgsi_processor_type_names; (void) tgsi_return_type_names; (void) tgsi_immediate_type_names; @@ -248,8 +248,8 @@ tgsi_strings_check(void) const char * tgsi_file_name(unsigned file) { - STATIC_ASSERT(Elements(tgsi_file_names) == TGSI_FILE_COUNT); - if (file < Elements(tgsi_file_names)) + STATIC_ASSERT(ARRAY_SIZE(tgsi_file_names) == TGSI_FILE_COUNT); + if (file < ARRAY_SIZE(tgsi_file_names)) return tgsi_file_names[file]; else return "invalid file"; diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index 0d0a9a3..805f932 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -1642,11 +1642,11 @@ static boolean parse_immediate( struct translate_ctx *ctx ) report_error( ctx, "Syntax error" ); return FALSE; } - for (type = 0; type < Elements(tgsi_immediate_type_names); ++type) { + for (type = 0; type < ARRAY_SIZE(tgsi_immediate_type_names); ++type) { if (str_match_nocase_whole(&ctx->cur, tgsi_immediate_type_names[type])) break; } - if (type == Elements(tgsi_immediate_type_names)) { + if (type == ARRAY_SIZE(tgsi_immediate_type_names)) { report_error( ctx, "Expected immediate type" ); return FALSE; } @@ -1692,7 +1692,7 @@ parse_fs_coord_origin( const char **pcur, uint *fs_coord_origin ) { uint i; - for (i = 0; i < Elements(tgsi_fs_coord_origin_names); i++) { + for (i = 0; i < ARRAY_SIZE(tgsi_fs_coord_origin_names); i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_fs_coord_origin_names[i])) { @@ -1709,7 +1709,7 @@ parse_fs_coord_pixel_center( const char **pcur, uint *fs_coord_pixel_center ) { uint i; - for (i = 0; i < Elements(tgsi_fs_coord_pixel_center_names); i++) { + for (i = 0; i < ARRAY_SIZE(tgsi_fs_coord_pixel_center_names); i++) { const char *cur = *pcur; if (str_match_nocase_whole( &cur, tgsi_fs_coord_pixel_center_names[i])) { diff --git a/src/gallium/auxiliary/util/u_hash_table.c b/src/gallium/auxiliary/util/u_hash_table.c index 6281003..40c721b 100644 --- a/src/gallium/auxiliary/util/u_hash_table.c +++ b/src/gallium/auxiliary/util/u_hash_table.c @@ -44,6 +44,7 @@ #include "cso_cache/cso_hash.h" #include "util/u_memory.h" +#include "util/u_pointer.h" #include "util/u_hash_table.h" #define XXH_INLINE_ALL diff --git a/src/gallium/meson.build b/src/gallium/meson.build index 72175fa..33d1992 100644 --- a/src/gallium/meson.build +++ b/src/gallium/meson.build @@ -30,7 +30,6 @@ sources_libgallium = [ 'include/pipe/p_screen.h', 'include/pipe/p_video_enums.h', 'auxiliary/util/u_format.h', - 'auxiliary/util/u_memory.h', 'auxiliary/util/u_rect.h', 'auxiliary/util/u_surface.h', 'auxiliary/util/u_math.h', diff --git a/src/gallium/auxiliary/util/u_memory.h b/src/mesa/util/u_memory.h similarity index 87% rename from src/gallium/auxiliary/util/u_memory.h rename to src/mesa/util/u_memory.h index 70a75ac..4cdccb6 100644 --- a/src/gallium/auxiliary/util/u_memory.h +++ b/src/mesa/util/u_memory.h @@ -34,8 +34,6 @@ #ifndef U_MEMORY_H #define U_MEMORY_H - -#include "util/u_pointer.h" #include "util/u_debug.h" #include "util/os_memory.h" @@ -62,13 +60,22 @@ extern "C" { #define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment) #define align_free(_ptr) os_free_aligned(_ptr) +#define align_realloc(_ptr, _oldsize, _newsize, _alignment) os_realloc_aligned(_ptr, _oldsize, _newsize, _alignment) +static inline void * +align_calloc(size_t size, unsigned long alignment) +{ + void *ptr = align_malloc(size, alignment); + if (ptr) + memset(ptr, 0, size); + return ptr; +} /** * Duplicate a block of memory. */ static inline void * -mem_dup(const void *src, uint size) +mem_dup(const void *src, size_t size) { void *dup = MALLOC(size); if (dup) @@ -77,18 +84,6 @@ mem_dup(const void *src, uint size) } -/** - * Number of elements in an array. - */ -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) -#endif - -#ifndef Elements -#define Elements(x) (sizeof(x)/sizeof((x)[0])) -#endif - - /** * Offset of a field in a struct, in bytes. */ diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index da314c6..9d27ec5 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -53,6 +53,7 @@ #include "util/u_double_list.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pointer.h" #include "util/u_hash_table.h" #define VTEST_MAX_SYNC_QUEUE_COUNT 64