GFXDevice::formatByteSize returns F32?
by Tom Spilman · in Torque Game Engine Advanced · 03/27/2007 (4:14 pm) · 9 replies
This seems stupid...
Lets ignore the fact that this function doesn't belong in GFXDevice and the silly less than if block, but why does it return an F32?
The code should look like so...
F32 GFXDevice::formatByteSize(GFXFormat format)
{
if(format < GFXFormat_16BIT)
return 1.0f;// 8 bit...
else if(format < GFXFormat_24BIT)
return 2.0f;// 16 bit...
else if(format < GFXFormat_32BIT)
return 3.0f;// 24 bit...
else if(format < GFXFormat_64BIT)
return 4.0f;// 32 bit...
else if(format < GFXFormat_128BIT)
return 8.0f;// 64 bit...
else if(format < GFXFormat_UNKNOWNSIZE)
return 16.0f;// 128 bit...
return 4.0;// default...
}Lets ignore the fact that this function doesn't belong in GFXDevice and the silly less than if block, but why does it return an F32?
The code should look like so...
U32 GFXDevice::formatByteSize(GFXFormat format)
{
switch ( format )
{
case GFXFormat_8BIT:
return 1;
case GFXFormat_16BIT:
return 2;
case GFXFormat_24BIT:
return 3;
case GFXFormat_32BIT:
return 4;
case GFXFormat_64BIT:
return 8;
case GFXFormat_128BIT:
return 16;
};
// We got an unknown size...
return 0;
}About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.
#2
Not sure why. Perhaps there is a hidden reason why GG coded it as F32 instead of U32?
03/27/2007 (11:22 pm)
For some reason, I experience a sudden drop in FPS when adding this revision code. Not only me, but my users are seeing the drop too.Not sure why. Perhaps there is a hidden reason why GG coded it as F32 instead of U32?
#3
I suggest taking a closer look at any changes you've made. Are you maybe running a debug build instead of a release build?
03/27/2007 (11:35 pm)
I don't often say this... but it is impossible that this change would effect framerate. If you do a search in the code you'll see that it is only used from one place... sgShadowTextureCache::sgPrintStats()... and it isn't called during normal gameplay.I suggest taking a closer look at any changes you've made. Are you maybe running a debug build instead of a release build?
#4
I don't know what manner of compiler voodoo would cause this function to run faster with an if-else and float data type, than a switch and an integer data type.
03/28/2007 (10:24 am)
^ What he said.I don't know what manner of compiler voodoo would cause this function to run faster with an if-else and float data type, than a switch and an integer data type.
#5
- Atlas Terrain
- Water block added
- fxFoliageReplicator added
- fxShapeReplicator added
And as soon as I get near any of these things, such as the waterblock, my FPS (and others) drop all the way down to 20-30. For me personally, it went from 140 down to 20-30fps.
With this change FPS: 20-30fps
Without this change: 140fps
03/28/2007 (3:14 pm)
Yeah it's very weird. I even tested this with STOCK TGEA and the same thing happened. I am testing this on:- Atlas Terrain
- Water block added
- fxFoliageReplicator added
- fxShapeReplicator added
And as soon as I get near any of these things, such as the waterblock, my FPS (and others) drop all the way down to 20-30. For me personally, it went from 140 down to 20-30fps.
With this change FPS: 20-30fps
Without this change: 140fps
#6
The enum formats are sorted so all texture types < a size definition but greater than the previous size definition are of the same size. Check the comments in GFXFormat for details.
Also the method returns a float to support various compressed texture formats.
04/01/2007 (7:25 pm)
Guys you can't change the code like that - those types are strategically placed in the GFXFormat enum to define the texture texel byte size.The enum formats are sorted so all texture types < a size definition but greater than the previous size definition are of the same size. Check the comments in GFXFormat for details.
Also the method returns a float to support various compressed texture formats.
#7
Update: Ok... i was that drunk.... i suck.
I see what your saying about the if vs. case statement thing. My change breaks things... it should be...
I don't really understand what you mean about compressed formats. You mean for future changes... because it doesn't return any floating point values that i can see. And what will it return... fractional bytes? How would you deal with a fractional byte?
04/01/2007 (8:01 pm)
I'm drunk... but i'm not that drunk. :PUpdate: Ok... i was that drunk.... i suck.
I see what your saying about the if vs. case statement thing. My change breaks things... it should be...
U32 GFXDevice::formatByteSize(GFXFormat format)
{
// GFXFormat is organized by format size which
// allows this function to return the right size for
// the other GFXFormat enums.
if(format < GFXFormat_16BIT)
return 1;// 8 bit...
else if(format < GFXFormat_24BIT)
return 2;// 16 bit...
else if(format < GFXFormat_32BIT)
return 3;// 24 bit...
else if(format < GFXFormat_64BIT)
return 4;// 32 bit...
else if(format < GFXFormat_128BIT)
return 8;// 64 bit...
else if(format < GFXFormat_UNKNOWNSIZE)
return 16;// 128 bit...
return 4;// default...
}I don't really understand what you mean about compressed formats. You mean for future changes... because it doesn't return any floating point values that i can see. And what will it return... fractional bytes? How would you deal with a fractional byte?
#8
04/02/2007 (2:42 am)
I'm gonna give this a try and see if it gives me that weird FPS problem I was having.
#9
04/02/2007 (5:01 am)
Queries against the compressed formats are not yet implemented, but as an example DXT1 compresses down to 4 bits per-texel, which would return 0.5 bytes per-lexel from the method. Not that I'm recommending use of the DXT formats, but future compressed formats could have similar partial byte sizes.
Torque 3D Owner Pat Wilson
I had to check the blame log to make sure that wasn't me. (The guilty party may identify themselves should they wish ;) ) You are totally correct on all counts though.