mirror of
https://github.com/jndean/IPUDOOM.git
synced 2026-08-20 01:08:52 +00:00
Reorgnise IPU_malloc and IPU_free
This commit is contained in:
@@ -26,13 +26,12 @@ extern "C" {
|
||||
#define IPUCOLSPERRENDERTILE (SCREENWIDTH / IPUNUMRENDERTILES)
|
||||
|
||||
#define IPUTEXTURETILESPERRENDERTILE (10)
|
||||
#define IPUTEXTURETILEBUFSIZE (1024)
|
||||
#define IPUTEXTURETILEBUFSIZE (1024 * 1)
|
||||
#define IPUFIRSTTEXTURETILE (IPUFIRSTRENDERTILE + IPUNUMRENDERTILES)
|
||||
#define IPUNUMTEXTURETILES (IPUTEXTURETILESPERRENDERTILE * IPUNUMRENDERTILES)
|
||||
#define IPUNUMTEXTURECACHELINES (1)
|
||||
#define IPUTEXTURECACHELINESIZE (128 / sizeof(int))
|
||||
|
||||
// #define IPUREDUCTIONPERIOD (2)
|
||||
#define IPUCOMMSBUFSIZE (IPUNUMRENDERTILES)
|
||||
|
||||
|
||||
|
||||
+74
-67
@@ -8,88 +8,93 @@
|
||||
|
||||
// #define IPUMALLOC_DEBUGPRINT 0
|
||||
|
||||
enum {
|
||||
PU_STATIC_max_size = 10000,
|
||||
PU_LEVEL_max_size = 200000,
|
||||
PU_TMP_max_size = 512 // This is a category I made up, for fleeting allocations
|
||||
|
||||
static unsigned char IPUMALLOC_STATIC_pool[10000];
|
||||
static unsigned char IPUMALLOC_LEVEL_pool[200000];
|
||||
static unsigned char IPUMALLOC_TMP_pool[512]; // This is a category I made up, for fleeting allocations
|
||||
|
||||
static unsigned char* pools[IPUMALLOC_NUMPOOLS] = {
|
||||
IPUMALLOC_STATIC_pool,
|
||||
IPUMALLOC_LEVEL_pool,
|
||||
IPUMALLOC_TMP_pool,
|
||||
};
|
||||
static int poolSizes[IPUMALLOC_NUMPOOLS] = {
|
||||
sizeof(IPUMALLOC_STATIC_pool),
|
||||
sizeof(IPUMALLOC_LEVEL_pool),
|
||||
sizeof(IPUMALLOC_TMP_pool)
|
||||
};
|
||||
static int poolPositions[IPUMALLOC_NUMPOOLS] = {0};
|
||||
|
||||
static char* poolNames[IPUMALLOC_NUMPOOLS] = {
|
||||
"STATIC pool",
|
||||
"LEVEL pool",
|
||||
"TMP pool"
|
||||
};
|
||||
|
||||
static unsigned PU_STATIC_size = 0;
|
||||
static unsigned PU_LEVEL_size = 0;
|
||||
static unsigned PU_TMP_size = 0;
|
||||
static unsigned char PU_STATIC_pool[PU_STATIC_max_size];
|
||||
static unsigned char PU_LEVEL_pool[PU_LEVEL_max_size];
|
||||
static unsigned char PU_TMP_pool[PU_TMP_max_size];
|
||||
static unsigned tmpStackHeight = 0;
|
||||
|
||||
__SUPER__
|
||||
void* IPU_level_malloc(int size, const char* name) {
|
||||
void* ret = (void*)(&PU_LEVEL_pool[PU_LEVEL_size]);
|
||||
PU_LEVEL_size = ALIGN32(PU_LEVEL_size + size);
|
||||
void* IPU_malloc(int size, IPUMallocPool_t pool, const char* name) {
|
||||
char* errStr;
|
||||
|
||||
if (name == NULL) {
|
||||
name = "Unnamed";
|
||||
}
|
||||
|
||||
if (pool >= IPUMALLOC_NUMPOOLS || pool < 0) {
|
||||
errStr = "Bad Pool Index";
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
void* ret = (void*) &pools[pool][poolPositions[pool]];
|
||||
poolPositions[pool] = ALIGN32(poolPositions[pool] + size);
|
||||
|
||||
#ifdef IPUMALLOC_DEBUGPRINT
|
||||
if (tileID == IPUMALLOC_DEBUGPRINT)
|
||||
printf("LEVEL_ALLOC: %s = %dK, total = %dK\n", name, size / 1000, PU_LEVEL_size / 1000);
|
||||
printf("IPUMALLOC: %s = %dK (%s @ %dK)\n",
|
||||
name, size / 1000, poolNames[pool], poolPositions[pool] / 1000);
|
||||
#endif
|
||||
|
||||
if (PU_LEVEL_size > PU_LEVEL_max_size) {
|
||||
printf("### ERROR ###: PU_LEVEL_max_size is %d, but IPU_level_malloc wants %d\n",
|
||||
PU_LEVEL_max_size, PU_LEVEL_size);
|
||||
// exit(1701);
|
||||
if (poolPositions[pool] > poolSizes[pool]) {
|
||||
errStr = "No Space Left";
|
||||
goto ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__SUPER__
|
||||
void IPU_level_free() {
|
||||
PU_LEVEL_size = 0;
|
||||
}
|
||||
|
||||
__SUPER__
|
||||
void* IPU_static_malloc(int size, const char* name) {
|
||||
void* ret = (void*)(&PU_STATIC_pool[PU_STATIC_size]);
|
||||
PU_STATIC_size = ALIGN32(PU_STATIC_size + size);
|
||||
|
||||
#ifdef IPUMALLOC_DEBUGPRINT
|
||||
if (tileID == IPUMALLOC_DEBUGPRINT)
|
||||
printf("STATIC_ALLOC: %s = %d, total = %dK\n", name, size, PU_STATIC_size / 1000);
|
||||
#endif
|
||||
|
||||
if (PU_STATIC_size > PU_STATIC_max_size) {
|
||||
printf("### ERROR ###: PU_STATIC_max_size is %d, but IPU_static_malloc wants %d\n",
|
||||
PU_STATIC_max_size, PU_STATIC_size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// There is no IPU_static_free :)
|
||||
|
||||
|
||||
static unsigned PU_TMP_count = 0;
|
||||
__SUPER__
|
||||
void* IPU_tmp_malloc(int size, const char* name) {
|
||||
void* ret = (void*)(&PU_TMP_pool[PU_TMP_size]);
|
||||
PU_TMP_size = ALIGN32(PU_TMP_size + size);
|
||||
|
||||
#ifdef IPUMALLOC_DEBUGPRINT
|
||||
if (tileID == IPUMALLOC_DEBUGPRINT)
|
||||
printf("TMP_ALLOC: %s = %dK, total = %dK\n", name, size / 1000, PU_TMP_size / 1000);
|
||||
#endif
|
||||
|
||||
if (PU_TMP_size > PU_TMP_max_size) {
|
||||
printf("### ERROR ###: PU_TMP_max_size is %d, but IPU_tmp_malloc wants %d\n",
|
||||
PU_TMP_max_size, PU_TMP_size);
|
||||
if (pool == IPUMALLOC_TMP) {
|
||||
tmpStackHeight += 1;
|
||||
}
|
||||
|
||||
PU_TMP_count += 1;
|
||||
return ret;
|
||||
|
||||
ERROR:
|
||||
printf("\n# # # # IPUMALLOC FAILED # # # \nReason: %s\n Request: size=%d, pool=%d, name=%s\n",
|
||||
errStr, size, pool, name);
|
||||
asm volatile(
|
||||
"setzi $m0, 0xa110c\n"
|
||||
"setzi $m1, 0xa110c\n"
|
||||
"setzi $m2, 0xa110c\n"
|
||||
"setzi $m3, 0xa110c\n"
|
||||
"setzi $m4, 0xa110c\n"
|
||||
"trap 0\n"
|
||||
);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
||||
__SUPER__
|
||||
void IPU_tmp_free(void* ptr) {
|
||||
(void) ptr;
|
||||
PU_TMP_count -= 1;
|
||||
if (PU_TMP_count == 0) {
|
||||
PU_TMP_size = 0;
|
||||
void IPU_free(IPUMallocPool_t pool) {
|
||||
switch (pool) {
|
||||
case IPUMALLOC_LEVEL:
|
||||
poolPositions[IPUMALLOC_LEVEL] = 0;
|
||||
break;
|
||||
case IPUMALLOC_TMP:
|
||||
tmpStackHeight -= 1;
|
||||
if (tmpStackHeight == 0) {
|
||||
poolPositions[IPUMALLOC_TMP] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("IPUMALLOC ERROR: tried to free pool %d\n", pool);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +107,10 @@ void IPU_summarise_malloc() {
|
||||
printf(
|
||||
"IPU Dynamic Allocation Summary:\n"
|
||||
"Static: %dK/%dK, Level: %dK/%dK, Tmp: %d/%d\n",
|
||||
PU_STATIC_size / 1000, PU_STATIC_max_size / 1000,
|
||||
PU_LEVEL_size / 1000, PU_LEVEL_size/ 1000,
|
||||
PU_TMP_size / 1000, PU_TMP_size/ 1000
|
||||
poolPositions[IPUMALLOC_STATIC] / 1000, poolSizes[IPUMALLOC_STATIC] / 1000,
|
||||
poolPositions[IPUMALLOC_LEVEL] / 1000, poolSizes[IPUMALLOC_LEVEL] / 1000,
|
||||
poolPositions[IPUMALLOC_TMP], poolSizes[IPUMALLOC_TMP]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-6
@@ -7,18 +7,22 @@ extern "C" {
|
||||
#include "ipu_utils.h"
|
||||
|
||||
|
||||
__SUPER__ void* IPU_static_malloc(int size, const char* name);
|
||||
// There is no IPU_static_free() :D
|
||||
typedef enum IPUMallocPool {
|
||||
IPUMALLOC_STATIC,
|
||||
IPUMALLOC_LEVEL,
|
||||
IPUMALLOC_TMP, // This is a category I made up, for fleeting allocations
|
||||
|
||||
__SUPER__ void* IPU_level_malloc(int size, const char* name);
|
||||
__SUPER__ void IPU_level_free(void);
|
||||
IPUMALLOC_NUMPOOLS
|
||||
} IPUMallocPool_t;
|
||||
|
||||
__SUPER__ void* IPU_tmp_malloc(int size, const char* name);
|
||||
__SUPER__ void IPU_tmp_free(void* ptr);
|
||||
|
||||
__SUPER__ void* IPU_malloc(int size, IPUMallocPool_t pool, const char* name);
|
||||
__SUPER__ void IPU_free(IPUMallocPool_t pool);
|
||||
|
||||
__SUPER__ void IPU_summarise_malloc(void);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
unsigned* tileLocalProgBuf;
|
||||
unsigned* tileLocalCommsBuf;
|
||||
unsigned* tileLocalTextureBuf;
|
||||
int textureFetchCount = 0;
|
||||
|
||||
const int tmpRepeatCount = 4;
|
||||
|
||||
// -------- Components for the tiles that serve textures ------------ //
|
||||
|
||||
|
||||
+1
-1
@@ -454,7 +454,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) {
|
||||
state_t *st;
|
||||
mobjinfo_t *info;
|
||||
|
||||
mobj = IPU_level_malloc(sizeof(*mobj), "SpawnMobj");
|
||||
mobj = IPU_malloc(sizeof(*mobj), IPUMALLOC_LEVEL, "SpawnMobj");
|
||||
memset(mobj, 0, sizeof(*mobj));
|
||||
|
||||
// JOSEF: Just allocate the mem for now
|
||||
|
||||
+11
-11
@@ -93,7 +93,7 @@ void P_LoadVertexes(const unsigned char *buf) {
|
||||
numvertexes = lumplen / sizeof(mapvertex_t);
|
||||
|
||||
// Allocate zone memory for buffer.
|
||||
vertexes = IPU_level_malloc(numvertexes * sizeof(vertex_t), "P_LoadVertexes");
|
||||
vertexes = IPU_malloc(numvertexes * sizeof(vertex_t), IPUMALLOC_LEVEL, "P_LoadVertexes");
|
||||
|
||||
// Load data into cache.
|
||||
// JOSEF: data = W_CacheLumpNum(lump, PU_STATIC);
|
||||
@@ -144,7 +144,7 @@ void P_LoadSegs(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numsegs = lumplen / sizeof(mapseg_t);
|
||||
segs = IPU_level_malloc(numsegs * sizeof(seg_t), "P_LoadSegs");
|
||||
segs = IPU_malloc(numsegs * sizeof(seg_t), IPUMALLOC_LEVEL, "P_LoadSegs");
|
||||
memset(segs, 0, numsegs * sizeof(seg_t));
|
||||
|
||||
ml = (mapseg_t *)(&buf[sizeof(int)]);
|
||||
@@ -206,7 +206,7 @@ void P_LoadSectors(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numsectors = lumplen / sizeof(mapsector_t);
|
||||
sectors = IPU_level_malloc(numsectors * sizeof(sector_t), "P_LoadSectors");
|
||||
sectors = IPU_malloc(numsectors * sizeof(sector_t), IPUMALLOC_LEVEL, "P_LoadSectors");
|
||||
memset(sectors, 0, numsectors * sizeof(sector_t));
|
||||
|
||||
ms = (mapsector_t *)(&buf[sizeof(int)]);
|
||||
@@ -238,7 +238,7 @@ void P_LoadNodes(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numnodes = lumplen / sizeof(mapnode_t);
|
||||
nodes = IPU_level_malloc(numnodes * sizeof(node_t), "P_LoadNodes");
|
||||
nodes = IPU_malloc(numnodes * sizeof(node_t), IPUMALLOC_LEVEL, "P_LoadNodes");
|
||||
memset(nodes, 0, numnodes * sizeof(node_t));
|
||||
|
||||
mn = (mapnode_t *)(&buf[sizeof(int)]);
|
||||
@@ -322,7 +322,7 @@ void P_LoadSideDefs(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numsides = lumplen / sizeof(mapsidedef_t);
|
||||
sides = IPU_level_malloc(numsides * sizeof(side_t), "P_LoadSideDefs");
|
||||
sides = IPU_malloc(numsides * sizeof(side_t), IPUMALLOC_LEVEL, "P_LoadSideDefs");
|
||||
memset(sides, 0, numsides * sizeof(side_t));
|
||||
|
||||
msd = (mapsidedef_t *)(&buf[sizeof(int)]);
|
||||
@@ -352,7 +352,7 @@ void P_LoadLineDefs(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numlines = lumplen / sizeof(maplinedef_t);
|
||||
lines = IPU_level_malloc(numlines * sizeof(line_t), "P_LoadLineDefs");
|
||||
lines = IPU_malloc(numlines * sizeof(line_t), IPUMALLOC_LEVEL, "P_LoadLineDefs");
|
||||
memset(lines, 0, numlines * sizeof(line_t));
|
||||
|
||||
mld = (maplinedef_t *)(&buf[sizeof(int)]);
|
||||
@@ -420,7 +420,7 @@ void P_LoadSubsectors(const unsigned char *buf) {
|
||||
|
||||
int lumplen = ((int*)buf)[0];
|
||||
numsubsectors = lumplen / sizeof(mapsubsector_t);
|
||||
subsectors = IPU_level_malloc(numsubsectors * sizeof(subsector_t), "P_LoadSubsectors");
|
||||
subsectors = IPU_malloc(numsubsectors * sizeof(subsector_t), IPUMALLOC_LEVEL, "P_LoadSubsectors");
|
||||
|
||||
ms = (mapsubsector_t *)(&buf[sizeof(int)]);
|
||||
memset(subsectors, 0, numsubsectors * sizeof(subsector_t));
|
||||
@@ -456,7 +456,7 @@ void P_SetupLevel_pt0(const unsigned char unused) {
|
||||
*/
|
||||
|
||||
// JOSEF, replaced; Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
|
||||
IPU_level_free(); // LATER: free other tags, here not just level
|
||||
IPU_free(IPUMALLOC_LEVEL);
|
||||
|
||||
/* LATER
|
||||
// UNUSED W_Profile ();
|
||||
@@ -537,7 +537,7 @@ void P_LoadBlockMap(const unsigned char *buf) {
|
||||
int lumplen;
|
||||
|
||||
lumplen = ((int*)buf)[0];
|
||||
blockmaplump = IPU_level_malloc(lumplen, "P_LoadBlockMap");
|
||||
blockmaplump = IPU_malloc(lumplen, IPUMALLOC_LEVEL, "P_LoadBlockMap");
|
||||
memcpy(blockmaplump, &buf[4], lumplen);
|
||||
blockmap = blockmaplump + 4;
|
||||
|
||||
@@ -554,7 +554,7 @@ void P_LoadBlockMap(const unsigned char *buf) {
|
||||
// Clear out mobj chains
|
||||
|
||||
count = sizeof(*blocklinks) * bmapwidth * bmapheight;
|
||||
blocklinks = IPU_level_malloc(count, "P_LoadBlockMap");
|
||||
blocklinks = IPU_malloc(count, IPUMALLOC_LEVEL, "P_LoadBlockMap");
|
||||
memset(blocklinks, 0, count);
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ void P_GroupLines(const unsigned char *buf) {
|
||||
|
||||
// build line tables for each sector
|
||||
// linebuffer = Z_Malloc(totallines * sizeof(line_t *), PU_LEVEL, 0);
|
||||
linebuffer = IPU_level_malloc(totallines * sizeof(line_t *), "P_GroupLines");
|
||||
linebuffer = IPU_malloc(totallines * sizeof(line_t *), IPUMALLOC_LEVEL, "P_GroupLines");
|
||||
|
||||
for (i = 0; i < numsectors; ++i) {
|
||||
// Assign the line buffer for this sector
|
||||
|
||||
+11
-7
@@ -379,8 +379,9 @@ static void GenerateTextureHashTable(void) {
|
||||
int i;
|
||||
int key;
|
||||
|
||||
textures_hashtable = IPU_static_malloc(
|
||||
textures_hashtable = IPU_malloc(
|
||||
sizeof(IPUpatchlesstexture_t *) * numtextures,
|
||||
IPUMALLOC_STATIC,
|
||||
"textures_hashtable"
|
||||
);
|
||||
|
||||
@@ -490,13 +491,13 @@ void R_InitTextures(int* maptex, R_Init_MiscValues_t* miscVals) {
|
||||
// }
|
||||
numtextures = numtextures1 + numtextures2;
|
||||
|
||||
patchlesstextures = IPU_static_malloc(numtextures * sizeof(IPUpatchlesstexture_t), "patchlesstextures");
|
||||
patchlesstextures = IPU_malloc(numtextures * sizeof(IPUpatchlesstexture_t), IPUMALLOC_STATIC, "patchlesstextures");
|
||||
// LATER: texturecolumnlump = IPU_static_malloc(numtextures * sizeof(*texturecolumnlump), "texturecolumnlump");
|
||||
// LATER: texturecolumnofs = IPU_static_malloc(numtextures * sizeof(*texturecolumnofs), "texturecolumnofs");
|
||||
// LATER: texturecomposite = IPU_static_malloc(numtextures * sizeof(*texturecomposite), "texturecomposite");
|
||||
// LATER: texturecompositesize = IPU_static_malloc(numtextures * sizeof(*texturecompositesize), "texturecompositesize");
|
||||
texturewidthmask = IPU_static_malloc(numtextures * sizeof(*texturewidthmask), "texturewidthmask");
|
||||
textureheight = IPU_static_malloc(numtextures * sizeof(*textureheight), "textureheight");
|
||||
texturewidthmask = IPU_malloc(numtextures * sizeof(*texturewidthmask), IPUMALLOC_STATIC, "texturewidthmask");
|
||||
textureheight = IPU_malloc(numtextures * sizeof(*textureheight), IPUMALLOC_STATIC, "textureheight");
|
||||
|
||||
// totalwidth = 0; // JOSEF: Unused?
|
||||
|
||||
@@ -537,8 +538,9 @@ void R_InitTextures(int* maptex, R_Init_MiscValues_t* miscVals) {
|
||||
mtexture = (maptexture_t *)((byte *)maptex + offset);
|
||||
|
||||
texture = &patchlesstextures[i];
|
||||
// texture = patchlesstextures[i] = IPU_static_malloc(
|
||||
// texture = patchlesstextures[i] = IPU_malloc(
|
||||
// sizeof(texture_t) + sizeof(texpatch_t) * (SHORT(mtexture->patchcount) - 1),
|
||||
// IPUMALLOC_STATIC,
|
||||
// "textures[i]"
|
||||
// );
|
||||
|
||||
@@ -589,8 +591,9 @@ void R_InitTextures(int* maptex, R_Init_MiscValues_t* miscVals) {
|
||||
// R_GenerateLookup(i);
|
||||
|
||||
// Create translation table for global animation.
|
||||
texturetranslation = IPU_static_malloc(
|
||||
texturetranslation = IPU_malloc(
|
||||
(numtextures + 1) * sizeof(*texturetranslation),
|
||||
IPUMALLOC_STATIC,
|
||||
"texturetranslation"
|
||||
);
|
||||
for (i = 0; i < numtextures; i++)
|
||||
@@ -860,4 +863,5 @@ void R_PrecacheLevel(void) {
|
||||
Z_Free(spritepresent);
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
@@ -318,8 +318,6 @@ void IpuDoom::buildIpuGraph() {
|
||||
});
|
||||
m_ipuGraph.setTileMapping(vtx, tile);
|
||||
}
|
||||
// Cache line is used as the aggregation buffer, make sure it's big enough
|
||||
assert(IPUTEXTURECACHELINESIZE >= IPUNUMRENDERTILES);
|
||||
|
||||
poplar::program::Sequence R_RenderPlayerView_prog({
|
||||
poplar::program::Copy(miscValuesStream, m_miscValuesBuf),
|
||||
|
||||
Reference in New Issue
Block a user