Vram

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Vram

Post by johnmph »

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
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

VRAM = EDRAM = GE's local memory, which is used for framebuffers, textures and vertex info
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Post by johnmph »

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
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

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.
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.
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Post by johnmph »

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: 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
&#123;
 u32 address;						// Address of allocation
 u32 size;							// Size of allocation
 u32 used;							// Use flag
 struct VramAlloc *prev, *next;		// Chained list
&#125; VramAlloc;


// FUNCTIONS DECLARATIONS

void *vramalloc &#40;u32&#41;;
void vramfree &#40;void *&#41;;

#endif

Vram functions source :

Code: Select all


/* VRAM simple allocation functions source */


// INCLUDES

#include "vram.h"


// GLOBALS VARIABLES

VramAlloc vramTable = &#123; VRAM_BASE, VRAM_SIZE, 0, NULL, NULL &#125;;


// FUNCTIONS

void *vramalloc &#40;u32 size&#41;

/*

  Allocate a memory block in VRAM

  Parameters &#58;	size		->	Size to allocate in bytes

  Return &#58;		Pointer to memory allocated or NULL if error

*/

&#123;
 VramAlloc *item, *pointer, *temp;


 // Init variables
 item = NULL;
 pointer = &vramTable;

 // Item loop
 while &#40;pointer&#41;
 &#123;
  // Find a valid item
  if &#40;&#40;!&#40;pointer->used&#41;&#41; && &#40;pointer->size >= size&#41;&#41;
  &#123;
   // Find the smaller item for avoid many small blocks
   if &#40;item&#41;
   &#123;
    if &#40;pointer->size < item->size&#41; item = pointer;
   &#125;
   else
	item = pointer;
  &#125;

  // Go to the next item
  pointer = pointer->next;
 &#125;

 // If valid item found
 if &#40;item&#41;
 &#123;
  // If memory remaining
  if &#40;item->size > size&#41;
  &#123;
   // Allocate new item
   temp = malloc&#40;sizeof&#40;VramAlloc&#41;&#41;;
   if &#40;!&#40;temp&#41;&#41; 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 &#40;item->next&#41; item->next->prev = temp;
   item->next = temp;
   item->size = size;
  &#125;

  // Current item used
  item->used = 1;

  // return good item address
  return &#40;void *&#41; item->address;
 &#125;

 // Not valid item found
 return NULL;
&#125;


void vramfree &#40;void *address&#41;

/*

  Free a memory block in VRAM

  Parameters &#58;	address		->	Address of allocated block to free

  Return &#58;		None

*/

&#123;
 VramAlloc *item, *pointer;


 // Init variable
 pointer = &vramTable;

 // Item loop
 while &#40;pointer&#41;
 &#123;
  // Find the good item
  if &#40;pointer->address == &#40;u32&#41; address&#41;
  &#123;
   // Check if we can regroup with previous block
   item = pointer->prev;

   if &#40;item&#41;
   &#123;
    if &#40;!&#40;item->used&#41;&#41;
	&#123;
	 // Regroup with previous block
	 item->next = pointer->next;
	 if &#40;pointer->next&#41; pointer->next->prev = item;
	 item->size += pointer->size;

	 // Delete item
	 free&#40;pointer&#41;;

	 // Point pointer to good item
	 pointer = item;
	&#125;
   &#125;

   // Check if we can regroup with next block
   item = pointer->next;

   if &#40;item&#41;
   &#123;
    if &#40;!&#40;item->used&#41;&#41;
	&#123;
	 // Regroup with next block
	 pointer->next = item->next;
	 if &#40;item->next&#41; item->next->prev = pointer;
	 pointer->size += item->size;

	 // Delete item
	 free&#40;item&#41;;
	&#125;
   &#125;

   // Current item not used
   pointer->used = 0;

   return;
  &#125;

  // Go to the next item
  pointer = pointer->next;
 &#125;
&#125;


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
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Post by johnmph »

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);
}
Post Reply