2007-10-29 16:20:45 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2008-08-25 00:48:55 +01:00
|
|
|
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
|
2007-10-29 16:20:45 +00:00
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2007-08-13 16:24:24 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
2007-10-29 16:20:45 +00:00
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
2007-08-13 16:24:24 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
2007-10-29 16:20:45 +00:00
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
2007-08-13 16:24:24 +01:00
|
|
|
|
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
/*
|
2008-08-25 00:48:55 +01:00
|
|
|
* Memory functions
|
|
|
|
*/
|
2008-07-26 01:17:10 +01:00
|
|
|
|
|
|
|
|
2008-08-25 00:48:55 +01:00
|
|
|
#ifndef U_MEMORY_H
|
|
|
|
#define U_MEMORY_H
|
2008-07-26 01:17:10 +01:00
|
|
|
|
|
|
|
|
2008-08-25 00:48:55 +01:00
|
|
|
#include "util/u_pointer.h"
|
2009-02-18 12:05:26 +00:00
|
|
|
#include "util/u_debug.h"
|
2010-02-03 12:13:06 +00:00
|
|
|
#include "os/os_memory.h"
|
2008-07-26 01:17:10 +01:00
|
|
|
|
2007-12-11 15:58:39 +00:00
|
|
|
|
2008-08-31 09:40:08 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
#define MALLOC(_size) os_malloc(_size)
|
2007-10-29 16:20:45 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
#define CALLOC(_count, _size) os_calloc(_count, _size)
|
2007-10-29 16:20:45 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
#define FREE(_ptr ) os_free(_ptr)
|
2007-10-29 16:20:45 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
#define REALLOC(_ptr, _old_size, _size) os_realloc(_ptr, _old_size, _size)
|
2007-10-29 16:20:45 +00:00
|
|
|
|
2008-01-25 10:33:58 +00:00
|
|
|
#define MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T))
|
|
|
|
|
2007-10-29 16:20:45 +00:00
|
|
|
#define CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T))
|
|
|
|
|
CELL: use variant-length fragment ops programs
This is a set of changes that optimizes the memory use of fragment
operation programs (by using and transmitting only as much memory as is
needed for the fragment ops programs, instead of maximal sizes), as well
as eliminate the dependency on hard-coded maximal program sizes. State
that is not dependent on fragment facing (i.e. that isn't using
two-sided stenciling) will only save and transmit a single
fragment operation program, instead of two identical programs.
- Added the ability to emit a LNOP (No Operation (Load)) instruction.
This is used to pad the generated fragment operations programs to
a multiple of 8 bytes, which is necessary for proper operation of
the dual instruction pipeline, and also required for proper SPU-side
decoding.
- Added the ability to allocate and manage a variant-length
struct cell_command_fragment_ops. This structure now puts the
generated function field at the end, where it can be as large
as necessary.
- On the PPU side, we now combine the generated front-facing and
back-facing code into a single variant-length buffer (and only use one
if the two sets of code are identical) for transmission to the SPU.
- On the SPU side, we pull the correct sizes out of the buffer,
allocate a new code buffer if the one we have isn't large enough,
and save the code to that buffer. The buffer is deallocated when
the SPU exits.
- Commented out the emit_fetch() static function, which was not being used.
2008-11-21 18:42:14 +00:00
|
|
|
#define CALLOC_VARIANT_LENGTH_STRUCT(T,more_size) ((struct T *) CALLOC(1, sizeof(struct T) + more_size))
|
|
|
|
|
2007-12-11 15:58:39 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
#define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment)
|
|
|
|
#define align_free(_ptr) os_free_aligned(_ptr)
|
2007-12-11 15:58:39 +00:00
|
|
|
|
|
|
|
|
2008-02-06 16:28:20 +00:00
|
|
|
/**
|
2008-02-07 09:26:08 +00:00
|
|
|
* Duplicate a block of memory.
|
2008-02-06 16:28:20 +00:00
|
|
|
*/
|
|
|
|
static INLINE void *
|
|
|
|
mem_dup(const void *src, uint size)
|
|
|
|
{
|
2008-02-07 09:26:08 +00:00
|
|
|
void *dup = MALLOC(size);
|
2008-02-06 16:28:20 +00:00
|
|
|
if (dup)
|
|
|
|
memcpy(dup, src, size);
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-17 18:40:06 +01:00
|
|
|
/**
|
2008-08-25 00:48:55 +01:00
|
|
|
* Number of elements in an array.
|
2007-08-17 18:40:06 +01:00
|
|
|
*/
|
2008-08-25 00:48:55 +01:00
|
|
|
#ifndef Elements
|
|
|
|
#define Elements(x) (sizeof(x)/sizeof((x)[0]))
|
2007-08-16 19:44:53 +01:00
|
|
|
#endif
|
|
|
|
|
2007-08-13 16:24:24 +01:00
|
|
|
|
2008-08-25 00:48:55 +01:00
|
|
|
/**
|
|
|
|
* Offset of a field in a struct, in bytes.
|
2007-08-13 16:24:24 +01:00
|
|
|
*/
|
2010-03-17 19:50:33 +00:00
|
|
|
#define Offset(TYPE, MEMBER) ((uintptr_t)&(((TYPE *)NULL)->MEMBER))
|
2008-04-21 12:38:14 +01:00
|
|
|
|
|
|
|
|
2008-02-25 11:05:41 +00:00
|
|
|
|
2008-08-31 09:40:08 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-08-25 00:48:55 +01:00
|
|
|
#endif /* U_MEMORY_H */
|