 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
johnmph
Joined: 23 Jul 2005 Posts: 119
|
Posted: Fri Jan 06, 2006 6:05 am Post subject: Vram |
|
|
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 |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Fri Jan 06, 2006 10:49 am Post subject: |
|
|
| VRAM = EDRAM = GE's local memory, which is used for framebuffers, textures and vertex info |
|
| Back to top |
|
 |
johnmph
Joined: 23 Jul 2005 Posts: 119
|
Posted: Fri Jan 06, 2006 9:04 pm Post subject: |
|
|
| jsgf wrote: | | VRAM = EDRAM = GE's local memory, which is used for framebuffers, textures and vertex info |
Thanks, i have found what i sought :
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 |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Sat Jan 07, 2006 3:23 am Post subject: |
|
|
| 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. |
Yep, and its just carved out of the memory you passed into gu in the first place.
| Quote: | 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 ? |
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. |
|
| Back to top |
|
 |
johnmph
Joined: 23 Jul 2005 Posts: 119
|
Posted: Sat Jan 07, 2006 6:51 am Post subject: |
|
|
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 :
| Code: |
#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
|
Vram functions source :
| Code: |
/* 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 |
|
| Back to top |
|
 |
johnmph
Joined: 23 Jul 2005 Posts: 119
|
Posted: Thu Jan 26, 2006 4:05 am Post subject: |
|
|
I have corrected the vramalloc function (corrected in red) and i have added the vramfreeall function, these functions works perfectly now :
| Quote: |
/* 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);
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|