First thing, thanks a lot to have a look at my question. You are a very gentle person.
Second thing, i follow up all the threads you talking about.
Your 3D work is impressive, especially the one with light maps !
For our memory investigation :
I followed what you wrote. I saw the line in pvr_internal.h introducing the pvr_state_t structure.
Code: Select all
uint32 texture_base; // Start of texture RAM
The field texture_base is the starting texture PVR memory address location.
This is why the value of this field never change, even after loading a bunch of textures.
It 's certainly populated in init function depending the init parameters.
FIRST TEST
Code: Select all
void TestTextureLoading()
{
printf("AVAILABLE MEMORY IN PVR AT START IN BYTES IS : %"PRIu32" \n", PVRMemoryAvailableAtStart());
printf("LOADING IN PVR A 64 *64 SQUARED 565 BLUE TEXTURE\n");
Texture blue = GetBlueTexture();
printf("AVAILABLE MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVRFreeMemoryAvailable());
printf("USED MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVR_TEX_BYTES_ALLOCATED);
printf("LOADING IN PVR A 64 *64 SQUARED 565 BLACK TEXTURE\n");
Texture black = GetBlackTexture();
printf("AVAILABLE MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVRFreeMemoryAvailable());
printf("USED MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVR_TEX_BYTES_ALLOCATED);
printf("LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE\n");
Texture red = GetRedTexture();
printf("AVAILABLE MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVRFreeMemoryAvailable());
printf("USED MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVR_TEX_BYTES_ALLOCATED);
printf("LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE\n");
Texture red2 = GetRedTexture();
printf("AVAILABLE MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVRFreeMemoryAvailable());
printf("USED MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVR_TEX_BYTES_ALLOCATED);
}
AVAILABLE MEMORY IN PVR AT START IN BYTES IS : 4626688
LOADING IN PVR A 64 *64 SQUARED 565 BLUE TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 4618496
USED MEMORY IN PVR IN BYTES IS : 8192
LOADING IN PVR A 64 *64 SQUARED 565 BLACK TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 4610304
USED MEMORY IN PVR IN BYTES IS : 16384
LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 4602112
USED MEMORY IN PVR IN BYTES IS : 24576
LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 4593920
USED MEMORY IN PVR IN BYTES IS : 32768
I just made the same code you provided to see effectively the "magic number" appears 4626688.
It means that after the default init (16*16 tiles size + Vertex Buffer of size 512 * 1024 byte), it remains in PVR 4626688 bytes for texture according to KOS
formula's : 0x800000 - pvr_state.texture_base.
It's rather strange for me because 4626688 represents 4518,25 KB or 4,412353515625 MB : it's not a round number ...
According to what you said we have :
PVR Vertex Buffer = 512 * 1024 = 524288
+
PVR Frame Buffer = 3237632
+
PVR Texture Data = 4626688
= Total PVR Memory = 1024*1024*8 = 8388608
So Frame buffer is 3,087646484375 MB wide.
We can image its' a a melting, something like N * 640 * 320 * 2 bytes (N * 614400 bytes) :
in this case N is more than 5.
As the free memory, used memory values are calculated by ourselves refering to what KOS say, the code works as expected.
SECOND TEST
I start a loop to load all the textures i can to fill up the 4626688 bytes magic number.
Purpose is simple, verify that this space is really to be filled as the lenght expected.
I used as one month ago the same 64*64 RGB565 texture wich means 8192 bytes to be used each load time.
So we expect 4626688 / 8192 = 564 textures to be loaded !
A simple for loop is used.
Code: Select all
void TestMassTextureLoading(int round)
{
printf("AVAILABLE MEMORY IN PVR AT START IN BYTES IS : %"PRIu32" \n", PVRMemoryAvailableAtStart());
int index;
for(index = 0; index < round; ++index)
{
printf("PASS %d\n", index);
GetBlueTexture();
printf("AVAILABLE MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVRFreeMemoryAvailable());
printf("USED MEMORY IN PVR IN BYTES IS : %"PRIu32" \n", PVR_TEX_BYTES_ALLOCATED);
}
}
AVAILABLE MEMORY IN PVR AT START IN BYTES IS : 4626688
PASS 0
AVAILABLE MEMORY IN PVR IN BYTES IS : 4618496
USED MEMORY IN PVR IN BYTES IS : 8192
....
PASS 561
AVAILABLE MEMORY IN PVR IN BYTES IS : 22784
USED MEMORY IN PVR IN BYTES IS : 4603904
PASS 562
pvr_mem: ERROR -- out of PVR memory; texture heap probably corrupted
But it does not work ... PASS 562 IE 563th texture allocation fails ....
So we can only allocate 562 * 8192 = 4603904.
There is something using 4626688 - 4603904 = 22784 bytes for 562 allocations.
Some 40 bytes each allocation ...perhaps for internal reason ?
So we do not have the whole 4626688 / 4518,25 KB / 4,412353515625 MB for textures.
THIRD TEST
I have make it for default, but for non default inits ?
There is a function to do so :
Code: Select all
int pvr_init (pvr_init_params_t * params)
I use these struct to init :
Code: Select all
pvr_init_params_t params =
{
/* Enable opaque and translucent polygons with size 16 */
{ PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_0 },
/* Vertex buffer size 1024K */
1024* 1024,
/* No DMA */
0,
/* No FSAA */
0
};
AVAILABLE MEMORY IN PVR AT START IN BYTES IS : 3578112
LOADING IN PVR A 64 *64 SQUARED 565 BLUE TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 3569920
USED MEMORY IN PVR IN BYTES IS : 8192
LOADING IN PVR A 64 *64 SQUARED 565 BLACK TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 3561728
USED MEMORY IN PVR IN BYTES IS : 16384
LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 3553536
USED MEMORY IN PVR IN BYTES IS : 24576
LOADING IN PVR A 64 *64 SQUARED 565 RED TEXTURE
AVAILABLE MEMORY IN PVR IN BYTES IS : 3545344
USED MEMORY IN PVR IN BYTES IS : 32768
The magic number is now 3578112 bytes for a vertex buffer enhanced by 512KB.
But, 3578112 (custom mode) + 524288 (512 * 1024) = 4102400 wich is not 4626688 (of default mode)
So the function reports less texture ram size because we have enhanced vertex buffer but there is something more consumming ram ....