Hello, in psdevwiki (http://wiki.ps2dev.org/psp:memory_map), it is showed :
VRAM size = 0x00200000
but is what the memory of GE (for the vertices allocated and context list) is included in the VRAM or GE has separate memory ?
Thanks
Vram
Thanks, i have found what i sought :jsgf wrote:VRAM = EDRAM = GE's local memory, which is used for framebuffers, textures and vertex info
For the vertex info allocated with sceGuGetMemory, the memory is allocated in memory of context list ORed with 0x40000000 for non using cache.
I wanted to know that because i wrote a small function to allocate / free memory on VRAM (like malloc and free functions) for buffers allocation.
Now, if the context list is allocated in VRAM directly, the render will be more faster ?
Thanks
Yep, and its just carved out of the memory you passed into gu in the first place.johnmph wrote:For the vertex info allocated with sceGuGetMemory, the memory is allocated in memory of context list ORed with 0x40000000 for non using cache.
You mean the command list? It's probably better to have it in system memory. It only gets written then read once. While its slower for the GE to read from system memory, the GE should be spending far more time drawing stuff than fetching commands, and command fetch can be overlapped with rendering. In other words, it would only make a difference if actual command reading and processing is a significant bottleneck.I wanted to know that because i wrote a small function to allocate / free memory on VRAM (like malloc and free functions) for buffers allocation.
Now, if the context list is allocated in VRAM directly, the render will be more faster ?
Thanks, it's that i wanted to know.
This is my small functions for allocate / free in VRAM for those which that interests.
Vram functions header :
Vram functions source :
If you use it, don't forget to allocate draw and display buffer with theses functions else you will overwrite memory of buffer with your allocations
This is my small functions for allocate / free in VRAM for those which that interests.
Vram functions header :
Code: Select all
#ifndef VRAM_INCLUDED
#define VRAM_INCLUDED
/* VRAM simple allocation header */
// INCLUDES
#include <psptypes.h>
#include <malloc.h>
// DEFINES
#define VRAM_BASE 0x04000000
#define VRAM_SIZE 0x00200000
// STRUCTURES
typedef struct VramAlloc // Vram allocation structure
{
u32 address; // Address of allocation
u32 size; // Size of allocation
u32 used; // Use flag
struct VramAlloc *prev, *next; // Chained list
} VramAlloc;
// FUNCTIONS DECLARATIONS
void *vramalloc (u32);
void vramfree (void *);
#endif
Code: Select all
/* VRAM simple allocation functions source */
// INCLUDES
#include "vram.h"
// GLOBALS VARIABLES
VramAlloc vramTable = { VRAM_BASE, VRAM_SIZE, 0, NULL, NULL };
// FUNCTIONS
void *vramalloc (u32 size)
/*
Allocate a memory block in VRAM
Parameters : size -> Size to allocate in bytes
Return : Pointer to memory allocated or NULL if error
*/
{
VramAlloc *item, *pointer, *temp;
// Init variables
item = NULL;
pointer = &vramTable;
// Item loop
while (pointer)
{
// Find a valid item
if ((!(pointer->used)) && (pointer->size >= size))
{
// Find the smaller item for avoid many small blocks
if (item)
{
if (pointer->size < item->size) item = pointer;
}
else
item = pointer;
}
// Go to the next item
pointer = pointer->next;
}
// If valid item found
if (item)
{
// If memory remaining
if (item->size > size)
{
// Allocate new item
temp = malloc(sizeof(VramAlloc));
if (!(temp)) return NULL;
// Init new item
temp->prev = item;
temp->next = item->next;
temp->address = item->address + size;
temp->size = item->size - size;
// Init current item
if (item->next) item->next->prev = temp;
item->next = temp;
item->size = size;
}
// Current item used
item->used = 1;
// return good item address
return (void *) item->address;
}
// Not valid item found
return NULL;
}
void vramfree (void *address)
/*
Free a memory block in VRAM
Parameters : address -> Address of allocated block to free
Return : None
*/
{
VramAlloc *item, *pointer;
// Init variable
pointer = &vramTable;
// Item loop
while (pointer)
{
// Find the good item
if (pointer->address == (u32) address)
{
// Check if we can regroup with previous block
item = pointer->prev;
if (item)
{
if (!(item->used))
{
// Regroup with previous block
item->next = pointer->next;
if (pointer->next) pointer->next->prev = item;
item->size += pointer->size;
// Delete item
free(pointer);
// Point pointer to good item
pointer = item;
}
}
// Check if we can regroup with next block
item = pointer->next;
if (item)
{
if (!(item->used))
{
// Regroup with next block
pointer->next = item->next;
if (item->next) item->next->prev = pointer;
pointer->size += item->size;
// Delete item
free(item);
}
}
// Current item not used
pointer->used = 0;
return;
}
// Go to the next item
pointer = pointer->next;
}
}
If you use it, don't forget to allocate draw and display buffer with theses functions else you will overwrite memory of buffer with your allocations
I have corrected the vramalloc function (corrected in red) and i have added the vramfreeall function, these functions works perfectly now :
/* VRAM simple allocation functions source */
// INCLUDES
#include "vram.h"
// GLOBALS VARIABLES
VramAlloc vramTable = { VRAM_BASE, VRAM_SIZE, 0, NULL, NULL };
// FUNCTIONS
void *vramalloc (u32 size)
/*
Allocate a memory block in VRAM
Parameters : size -> Size to allocate in bytes
Return : Pointer to memory allocated or NULL if error
*/
{
VramAlloc *item, *pointer, *temp;
// Init variables
item = NULL;
pointer = &vramTable;
// Item loop
while (pointer)
{
// Find a valid item
if ((!(pointer->used)) && (pointer->size >= size))
{
// Find the smaller item for avoid many small blocks
if (item)
{
if (pointer->size < item->size) item = pointer;
}
else
item = pointer;
}
// Go to the next item
pointer = pointer->next;
}
// If valid item found
if (item)
{
// If memory remaining
if (item->size > size)
{
// Allocate new item
temp = malloc(sizeof(VramAlloc));
if (!(temp)) return NULL;
// Init new item
temp->prev = item;
temp->next = item->next;
temp->address = item->address + size;
temp->size = item->size - size;
temp->used = 0;
// Init current item
if (item->next) item->next->prev = temp;
item->next = temp;
item->size = size;
}
// Current item used
item->used = 1;
// return good item address
return (void *) item->address;
}
// Not valid item found
return NULL;
}
void vramFreeAll (void)
/*
Free all memory blocks in VRAM
Parameters : None
Return : None
*/
{
// Delete main item
vramTable.used = 0;
// Delete all items after main item
while (vramTable.next) vramFree((void *) vramTable.next->address);
}