replace imports memory functions with utils memory functions

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3024>
This commit is contained in:
Dylan Baker
2018-09-12 16:31:13 -07:00
parent bb560f2d65
commit c495c3af26
19 changed files with 96 additions and 254 deletions

View File

@@ -95,6 +95,7 @@
#include "util/u_transfer.h"
#include "util/u_upload_mgr.h"
#include "util/u_viewport.h"
#include "util/u_memory.h"
#include "drm-uapi/i915_drm.h"
#include "nir.h"
#include "intel/compiler/brw_compiler.h"

View File

@@ -26,7 +26,6 @@
**************************************************************************/
#include "util/imports.h"
#include "main/mtypes.h"
#include "main/macros.h"
#include "main/bufferobj.h"
@@ -97,7 +96,7 @@ intel_bufferobj_free(struct gl_context * ctx, struct gl_buffer_object *obj)
*/
_mesa_buffer_unmap_all_mappings(ctx, obj);
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
drm_intel_bo_unreference(intel_obj->buffer);
_mesa_delete_buffer_object(ctx, obj);
@@ -134,7 +133,7 @@ intel_bufferobj_data(struct gl_context * ctx,
if (intel_obj->buffer != NULL)
release_buffer(intel_obj);
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
intel_obj->sys_buffer = NULL;
if (size != 0) {
@@ -143,7 +142,7 @@ intel_bufferobj_data(struct gl_context * ctx,
*/
if (target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER) {
intel_obj->sys_buffer =
_mesa_align_malloc(size, ctx->Const.MinMapBufferAlignment);
align_malloc(size, ctx->Const.MinMapBufferAlignment);
if (intel_obj->sys_buffer != NULL) {
if (data != NULL)
memcpy(intel_obj->sys_buffer, data, size);
@@ -194,7 +193,7 @@ intel_bufferobj_subdata(struct gl_context * ctx,
return;
}
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
intel_obj->sys_buffer = NULL;
}
@@ -302,7 +301,7 @@ intel_bufferobj_map_range(struct gl_context * ctx,
return obj->Mappings[index].Pointer;
}
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
intel_obj->sys_buffer = NULL;
}
@@ -351,7 +350,7 @@ intel_bufferobj_map_range(struct gl_context * ctx,
if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {
intel_obj->range_map_buffer[index] =
_mesa_align_malloc(length + extra, alignment);
align_malloc(length + extra, alignment);
obj->Mappings[index].Pointer =
intel_obj->range_map_buffer[index] + extra;
} else {
@@ -446,7 +445,7 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj,
* usage inside of a batchbuffer.
*/
intel_batchbuffer_emit_mi_flush(intel);
_mesa_align_free(intel_obj->range_map_buffer[index]);
align_free(intel_obj->range_map_buffer[index]);
intel_obj->range_map_buffer[index] = NULL;
} else if (intel_obj->range_map_bo[index] != NULL) {
const unsigned extra = obj->Mappings[index].Pointer -
@@ -491,7 +490,7 @@ intel_bufferobj_buffer(struct intel_context *intel,
0, intel_obj->Base.Size,
intel_obj->sys_buffer);
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
intel_obj->sys_buffer = NULL;
intel_obj->offset = 0;
}
@@ -678,7 +677,7 @@ intel_buffer_object_purgeable(struct gl_context * ctx,
return intel_buffer_purgeable(intel_obj->buffer);
if (option == GL_RELEASED_APPLE) {
_mesa_align_free(intel_obj->sys_buffer);
align_free(intel_obj->sys_buffer);
intel_obj->sys_buffer = NULL;
return GL_RELEASED_APPLE;

View File

@@ -76,6 +76,7 @@
#include "util/ralloc.h"
#include "util/debug.h"
#include "util/disk_cache.h"
#include "util/u_memory.h"
#include "isl/isl.h"
#include "common/gen_defines.h"

View File

@@ -47,6 +47,7 @@
#include "main/streaming-load-memcpy.h"
#include "util/format_srgb.h"
#include "util/u_memory.h"
#include "x86/common_x86_asm.h"
@@ -2553,7 +2554,7 @@ intel_miptree_unmap_tiled_memcpy(struct brw_context *brw,
intel_miptree_unmap_raw(mt);
}
_mesa_align_free(map->buffer);
align_free(map->buffer);
map->buffer = map->ptr = NULL;
}
@@ -2635,7 +2636,7 @@ intel_miptree_map_tiled_memcpy(struct brw_context *brw,
* aligned). Here we over-allocate the linear buffer by enough
* bytes to get the proper alignment.
*/
map->buffer = _mesa_align_malloc(map->stride * (y2 - y1) + (x1 & 0xf), 16);
map->buffer = align_malloc(map->stride * (y2 - y1) + (x1 & 0xf), 16);
map->ptr = (char *)map->buffer + (x1 & 0xf);
assert(map->buffer);
@@ -2728,7 +2729,7 @@ intel_miptree_unmap_movntdqa(struct brw_context *brw,
unsigned int level,
unsigned int slice)
{
_mesa_align_free(map->buffer);
align_free(map->buffer);
map->buffer = NULL;
map->ptr = NULL;
}
@@ -2778,7 +2779,7 @@ intel_miptree_map_movntdqa(struct brw_context *brw,
map->stride = ALIGN(misalignment + width_bytes, 16);
map->buffer = _mesa_align_malloc(map->stride * map->h, 16);
map->buffer = align_malloc(map->stride * map->h, 16);
/* Offset the destination so it has the same misalignment as src. */
map->ptr = map->buffer + misalignment;

View File

@@ -36,7 +36,6 @@
#include "glheader.h"
#include "enums.h"
#include "hash.h"
#include "util/imports.h"
#include "context.h"
#include "bufferobj.h"
#include "externalobjects.h"
@@ -483,7 +482,7 @@ _mesa_delete_buffer_object(struct gl_context *ctx,
(void) ctx;
vbo_delete_minmax_cache(bufObj);
_mesa_align_free(bufObj->Data);
align_free(bufObj->Data);
/* assign strange values here to help w/ debugging */
bufObj->RefCount = -1000;
@@ -623,9 +622,9 @@ buffer_data_fallback(struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
(void) target;
_mesa_align_free( bufObj->Data );
align_free( bufObj->Data );
new_data = _mesa_align_malloc( size, ctx->Const.MinMapBufferAlignment );
new_data = align_malloc( size, ctx->Const.MinMapBufferAlignment );
if (new_data) {
bufObj->Data = (GLubyte *) new_data;
bufObj->Size = size;

View File

@@ -30,7 +30,6 @@
#include "main/glheader.h"
#include "main/context.h"
#include "main/macros.h"
#include "util/imports.h"
#include "m_matrix.h"
#include "m_xform.h"
@@ -209,7 +208,7 @@ static int test_norm_function( normal_func func, int mtype, long *cycles )
(void) cycles;
mat->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
mat->m = align_malloc( 16 * sizeof(GLfloat), 16 );
mat->inv = m = mat->m;
init_matrix( m );
@@ -328,7 +327,7 @@ static int test_norm_function( normal_func func, int mtype, long *cycles )
}
}
_mesa_align_free( mat->m );
align_free( mat->m );
return 1;
}

View File

@@ -29,7 +29,6 @@
#include "main/glheader.h"
#include "main/context.h"
#include "main/macros.h"
#include "util/imports.h"
#include "m_matrix.h"
#include "m_xform.h"
@@ -183,7 +182,7 @@ static int test_transform_function( transform_func func, int psize,
return 0;
}
mat->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
mat->m = align_malloc( 16 * sizeof(GLfloat), 16 );
mat->type = mtypes[mtype];
m = mat->m;
@@ -273,7 +272,7 @@ static int test_transform_function( transform_func func, int psize,
}
}
_mesa_align_free( mat->m );
align_free( mat->m );
return 1;
}

View File

@@ -38,13 +38,14 @@
#include "c99_math.h"
#include "main/errors.h"
#include "main/glheader.h"
#include "util/imports.h"
#include "main/macros.h"
#define MATH_ASM_PTR_SIZE sizeof(void *)
#include "math/m_vector_asm.h"
#include "m_matrix.h"
#include "util/u_memory.h"
/**
* \defgroup MatFlags MAT_FLAG_XXX-flags
@@ -1476,10 +1477,10 @@ _math_matrix_loadf( GLmatrix *mat, const GLfloat *m )
void
_math_matrix_ctr( GLmatrix *m )
{
m->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
m->m = align_malloc( 16 * sizeof(GLfloat), 16 );
if (m->m)
memcpy( m->m, Identity, sizeof(Identity) );
m->inv = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
m->inv = align_malloc( 16 * sizeof(GLfloat), 16 );
if (m->inv)
memcpy( m->inv, Identity, sizeof(Identity) );
m->type = MATRIX_IDENTITY;
@@ -1496,10 +1497,10 @@ _math_matrix_ctr( GLmatrix *m )
void
_math_matrix_dtr( GLmatrix *m )
{
_mesa_align_free( m->m );
align_free( m->m );
m->m = NULL;
_mesa_align_free( m->inv );
align_free( m->inv );
m->inv = NULL;
}

View File

@@ -30,11 +30,12 @@
#include <stddef.h>
#include "main/glheader.h"
#include "util/imports.h"
#include "main/macros.h"
#include "m_vector.h"
#include "util/u_memory.h"
/**
@@ -109,7 +110,7 @@ _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, GLuint count,
{
v->stride = 4 * sizeof(GLfloat);
v->size = 2;
v->storage = _mesa_align_malloc( count * 4 * sizeof(GLfloat), alignment );
v->storage = align_malloc( count * 4 * sizeof(GLfloat), alignment );
v->storage_count = count;
v->start = (GLfloat *) v->storage;
v->data = (GLfloat (*)[4]) v->storage;
@@ -127,7 +128,7 @@ void
_mesa_vector4f_free( GLvector4f *v )
{
if (v->flags & VEC_MALLOC) {
_mesa_align_free( v->storage );
align_free( v->storage );
v->data = NULL;
v->start = NULL;
v->storage = NULL;

View File

@@ -30,7 +30,6 @@
#include "main/glheader.h"
#include "util/imports.h"
#include "main/macros.h"
#include "util/u_memory.h"
#include "prog_instruction.h"
@@ -155,12 +154,12 @@ _mesa_new_parameter_list_sized(unsigned size)
p->ParameterValueOffset = (unsigned *) calloc(size, sizeof(unsigned));
p->ParameterValues = (gl_constant_value *)
_mesa_align_malloc(size * 4 *sizeof(gl_constant_value), 16);
align_malloc(size * 4 *sizeof(gl_constant_value), 16);
if ((p->Parameters == NULL) || (p->ParameterValues == NULL)) {
free(p->Parameters);
_mesa_align_free(p->ParameterValues);
align_free(p->ParameterValues);
free(p);
p = NULL;
}
@@ -182,7 +181,7 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
}
free(paramList->Parameters);
free(paramList->ParameterValueOffset);
_mesa_align_free(paramList->ParameterValues);
align_free(paramList->ParameterValues);
free(paramList);
}
@@ -214,7 +213,7 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
paramList->Size * sizeof(unsigned));
paramList->ParameterValues = (gl_constant_value *)
_mesa_align_realloc(paramList->ParameterValues, /* old buf */
align_realloc(paramList->ParameterValues, /* old buf */
oldNum * 4 * sizeof(gl_constant_value),/* old sz */
paramList->Size*4*sizeof(gl_constant_value),/*new*/
16);

View File

@@ -85,6 +85,7 @@
#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "util/u_vbuf.h"
#include "util/u_memory.h"
#include "cso_cache/cso_context.h"
#include "compiler/glsl/glsl_parser_extras.h"

View File

@@ -39,6 +39,7 @@
#include "pipe/p_screen.h"
#include "tgsi/tgsi_from_mesa.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "st_context.h"
#include "st_debug.h"

View File

@@ -100,7 +100,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
_swrast_teximage_slice_height(texImage), 1);
assert(!swImg->Buffer);
swImg->Buffer = _mesa_align_malloc(bytesPerSlice * slices, 512);
swImg->Buffer = align_malloc(bytesPerSlice * slices, 512);
if (!swImg->Buffer)
return GL_FALSE;
@@ -166,7 +166,7 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx,
{
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
_mesa_align_free(swImage->Buffer);
align_free(swImage->Buffer);
swImage->Buffer = NULL;
free(swImage->ImageSlices);

View File

@@ -33,7 +33,6 @@
#include "main/glheader.h"
#include "main/macros.h"
#include "util/imports.h"
#include "main/samplerobj.h"
#include "main/state.h"
#include "math/m_xform.h"
@@ -42,6 +41,7 @@
#include "program/prog_execute.h"
#include "swrast/s_context.h"
#include "util/bitscan.h"
#include "util/u_memory.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
@@ -481,7 +481,7 @@ init_vp(struct gl_context *ctx, struct tnl_pipeline_stage *stage)
/* a few other misc allocations */
_mesa_vector4f_alloc( &store->ndcCoords, 0, size, 32 );
store->clipmask = _mesa_align_malloc(sizeof(GLubyte)*size, 32 );
store->clipmask = align_malloc(sizeof(GLubyte)*size, 32 );
return GL_TRUE;
}
@@ -504,7 +504,7 @@ dtr(struct tnl_pipeline_stage *stage)
/* free misc arrays */
_mesa_vector4f_free( &store->ndcCoords );
_mesa_align_free( store->clipmask );
align_free( store->clipmask );
free( store );
stage->privatePtr = NULL;

View File

@@ -28,12 +28,12 @@
#include "main/glheader.h"
#include "main/macros.h"
#include "util/imports.h"
#include "main/mtypes.h"
#include "math/m_xform.h"
#include "util/bitscan.h"
#include "util/u_memory.h"
#include "t_context.h"
#include "t_pipeline.h"
@@ -247,7 +247,7 @@ static GLboolean init_vertex_stage( struct gl_context *ctx,
_mesa_vector4f_alloc( &store->clip, 0, size, 32 );
_mesa_vector4f_alloc( &store->proj, 0, size, 32 );
store->clipmask = _mesa_align_malloc(sizeof(GLubyte)*size, 32 );
store->clipmask = align_malloc(sizeof(GLubyte)*size, 32 );
if (!store->clipmask ||
!store->eye.data ||
@@ -266,7 +266,7 @@ static void dtr( struct tnl_pipeline_stage *stage )
_mesa_vector4f_free( &store->eye );
_mesa_vector4f_free( &store->clip );
_mesa_vector4f_free( &store->proj );
_mesa_align_free( store->clipmask );
align_free( store->clipmask );
free(store);
stage->privatePtr = NULL;
stage->run = init_vertex_stage;

View File

@@ -512,7 +512,7 @@ void _tnl_init_vertices( struct gl_context *ctx,
if (max_vertex_size > vtx->max_vertex_size) {
_tnl_free_vertices( ctx );
vtx->max_vertex_size = max_vertex_size;
vtx->vertex_buf = _mesa_align_calloc(vb_size * max_vertex_size, 32 );
vtx->vertex_buf = align_calloc(vb_size * max_vertex_size, 32 );
invalidate_funcs(vtx);
}
@@ -558,7 +558,7 @@ void _tnl_free_vertices( struct gl_context *ctx )
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
struct tnl_clipspace_fastpath *fp, *tmp;
_mesa_align_free(vtx->vertex_buf);
align_free(vtx->vertex_buf);
vtx->vertex_buf = NULL;
for (fp = vtx->fastpath ; fp ; fp = tmp) {

View File

@@ -43,6 +43,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/draw_validate.h"
#include "main/dispatch.h"
#include "util/bitscan.h"
#include "util/u_memory.h"
#include "vbo_noop.h"
#include "vbo_private.h"
@@ -1015,7 +1016,7 @@ vbo_exec_vtx_init(struct vbo_exec_context *exec, bool use_buffer_objects)
/* Use allocated memory for immediate mode. */
exec->vtx.bufferobj = NULL;
exec->vtx.buffer_map =
_mesa_align_malloc(ctx->Const.glBeginEndBufferSize, 64);
align_malloc(ctx->Const.glBeginEndBufferSize, 64);
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
}
@@ -1039,7 +1040,7 @@ vbo_exec_vtx_destroy(struct vbo_exec_context *exec)
assert(!exec->vtx.bufferobj ||
exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
if (!exec->vtx.bufferobj) {
_mesa_align_free(exec->vtx.buffer_map);
align_free(exec->vtx.buffer_map);
exec->vtx.buffer_map = NULL;
exec->vtx.buffer_ptr = NULL;
}

View File

@@ -61,154 +61,6 @@
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
#endif
/**********************************************************************/
/** \name Memory */
/*@{*/
/**
* Allocate aligned memory.
*
* \param bytes number of bytes to allocate.
* \param alignment alignment (must be greater than zero).
*
* Allocates extra memory to accommodate rounding up the address for
* alignment and to record the real malloc address.
*
* \sa _mesa_align_free().
*/
void *
_mesa_align_malloc(size_t bytes, unsigned long alignment)
{
#if defined(HAVE_POSIX_MEMALIGN)
void *mem;
int err = posix_memalign(& mem, alignment, bytes);
if (err)
return NULL;
return mem;
#elif defined(_WIN32)
return _aligned_malloc(bytes, alignment);
#else
uintptr_t ptr, buf;
assert( alignment > 0 );
ptr = (uintptr_t)malloc(bytes + alignment + sizeof(void *));
if (!ptr)
return NULL;
buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
*(uintptr_t *)(buf - sizeof(void *)) = ptr;
#ifndef NDEBUG
/* mark the non-aligned area */
while ( ptr < buf - sizeof(void *) ) {
*(unsigned long *)ptr = 0xcdcdcdcd;
ptr += sizeof(unsigned long);
}
#endif
return (void *) buf;
#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
* Same as _mesa_align_malloc(), but using calloc(1, ) instead of
* malloc()
*/
void *
_mesa_align_calloc(size_t bytes, unsigned long alignment)
{
#if defined(HAVE_POSIX_MEMALIGN)
void *mem;
mem = _mesa_align_malloc(bytes, alignment);
if (mem != NULL) {
(void) memset(mem, 0, bytes);
}
return mem;
#elif defined(_WIN32)
void *mem;
mem = _aligned_malloc(bytes, alignment);
if (mem != NULL) {
(void) memset(mem, 0, bytes);
}
return mem;
#else
uintptr_t ptr, buf;
assert( alignment > 0 );
ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *));
if (!ptr)
return NULL;
buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
*(uintptr_t *)(buf - sizeof(void *)) = ptr;
#ifndef NDEBUG
/* mark the non-aligned area */
while ( ptr < buf - sizeof(void *) ) {
*(unsigned long *)ptr = 0xcdcdcdcd;
ptr += sizeof(unsigned long);
}
#endif
return (void *)buf;
#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
* Free memory which was allocated with either _mesa_align_malloc()
* or _mesa_align_calloc().
* \param ptr pointer to the memory to be freed.
* The actual address to free is stored in the word immediately before the
* address the client sees.
* Note that it is legal to pass NULL pointer to this function and will be
* handled accordingly.
*/
void
_mesa_align_free(void *ptr)
{
#if defined(HAVE_POSIX_MEMALIGN)
free(ptr);
#elif defined(_WIN32)
_aligned_free(ptr);
#else
if (ptr) {
void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
void *realAddr = *cubbyHole;
free(realAddr);
}
#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
* Reallocate memory, with alignment.
*/
void *
_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
unsigned long alignment)
{
#if defined(_WIN32)
(void) oldSize;
return _aligned_realloc(oldBuffer, newSize, alignment);
#else
const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
void *newBuf = _mesa_align_malloc(newSize, alignment);
if (newBuf && oldBuffer && copySize > 0) {
memcpy(newBuf, oldBuffer, copySize);
}
_mesa_align_free(oldBuffer);
return newBuf;
#endif
}
/*@}*/
/** Needed due to #ifdef's, above. */
int

View File

@@ -76,19 +76,6 @@ typedef union { float f; int i; unsigned u; } fi_type;
* Functions
*/
extern void *
_mesa_align_malloc( size_t bytes, unsigned long alignment );
extern void *
_mesa_align_calloc( size_t bytes, unsigned long alignment );
extern void
_mesa_align_free( void *ptr );
extern void *
_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
unsigned long alignment);
extern int
_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4);