Added more stats for the LLViewerTextureList::dump and fixed bug

Added table to show horizonal size X vertical size counts
Added table to show discard level vs size counts

Added -1 as a valid discard level (this was causing possible crashes by not handling)
Added extra # of discard levels to handle larger texture sizes (2048 can scale down to 7, 4096 to 8 and invalid sizes can go +1 more)

Fixed out of bounds and possible buffer overflow issue due to getCurrentDiscard having -1 to > MAX_DISCARD_LEVEL + 1 be outputs.
master
minerjr 2025-04-03 08:33:06 -03:00
parent 005483536b
commit 9312c6aa2d
1 changed files with 117 additions and 5 deletions

View File

@ -387,8 +387,22 @@ void LLViewerTextureList::dump()
// <FS:minerjr> [FIRE-35081] Blurry prims not changing with graphics settings, not happening with SL Viewer
S32 texture_count = 0;
S32 textures_close_to_camera = 0;
S32 image_counts[MAX_DISCARD_LEVEL + 1];
for (S32 index = 0; index <= MAX_DISCARD_LEVEL; index++)
S32 image_counts[MAX_DISCARD_LEVEL * 2 + 2]; // Double the size for higher discards from textures < 1024 (2048 can make a 7 and 4096 could make an 8)
S32 size_counts[12 * 12]; // Track the 12 possible sizes (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048)
S32 discard_counts[(MAX_DISCARD_LEVEL * 2 + 2) * 12]; // Also need to an 1 additional as -1 is a valid discard level (not loaded by reported as a 1x1 texture)
// Init the buffers with 0's
for (S32 y = 0; y < 12; y++)
{
for (S32 x = 0; x < 12; x++)
{
size_counts[x + y * 12] = 0;
}
for (S32 x = 0; x < (MAX_DISCARD_LEVEL * 2 + 2); x++)
{
discard_counts[x + y * (MAX_DISCARD_LEVEL * 2 + 2)] = 0;
}
}
for (S32 index = 0; index < MAX_DISCARD_LEVEL * 2 + 2; index++)
{
image_counts[index] = 0;
}
@ -426,7 +440,12 @@ void LLViewerTextureList::dump()
<< " http://asset.siva.lindenlab.com/" << image->getID() << ".texture"
<< LL_ENDL;
// <FS:minerjr> [FIRE-35081] Blurry prims not changing with graphics settings, not happening with SL Viewer
image_counts[image->getDiscardLevel()] += 1;
image_counts[(image->getDiscardLevel() + 1)] += 1; // Need to add +1 to make up for -1 being a possible value
S32 x_index = (S32)log2(image->getWidth()); // Calculate the power of 2 (index) from the width
S32 y_index = (S32)log2(image->getHeight()); // Calculate the power of 2 (index) from the width
size_counts[x_index + y_index * 12] += 1; // Add this texture's dimensions to the size count
// Onlyuse the largest size for the texture's discard level(for non-square textures)
discard_counts[(image->getDiscardLevel() + 1) + (y_index > x_index ? y_index : x_index) * (MAX_DISCARD_LEVEL * 2 + 2)] += 1;
texture_count++;
textures_close_to_camera += S32(image->getCloseToCamera());
// </FS:minerjr> [FIRE-35081]
@ -435,10 +454,103 @@ void LLViewerTextureList::dump()
// Add overal texture totals
LL_INFOS() << "Texture Stats: Textures in Close to Camera " << textures_close_to_camera << " of " << texture_count << " : " << LL_ENDL;
for (S32 index = 0; index <= MAX_DISCARD_LEVEL; index++)
// Fix for the -1 discard level as well as higher possible discard levels (for 2048+ size textures)
for (S32 index = 0; index < MAX_DISCARD_LEVEL * 2 + 2; index++)
{
LL_INFOS() << " Discard Level: " << index << " Number of Textures: " << image_counts[index] << LL_ENDL;
LL_INFOS() << " Discard Level: " << (index - 1) << " Number of Textures: " << image_counts[index] << LL_ENDL;
}
// Create a header that for the Sizes
std::string header = "Size ";
for (S32 x = 0; x < 12; x++)
{
std::string newValue = std::to_string((S32)pow(2, x));
header += newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
header += " ";
}
}
// Create a line to break up the header from the content of the table
std::string header_break = "";
for (S32 x = 0; x < header.length(); x++)
{
header_break += "-";
}
LL_INFOS() << header_break << LL_ENDL;
LL_INFOS() << header << LL_ENDL; // Size vs Size counts header
LL_INFOS() << header_break << LL_ENDL;
// Y Axis is the size of the height of the texture
for (S32 y = 0; y < 12; y++)
{
std::string newValue = std::to_string((S32)pow(2, y));
std::string size_count_string = "" + newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
size_count_string += " ";
}
//X Axis is the size of the width of the texture
for (S32 x = 0; x < 12; x++)
{
newValue = std::to_string(size_counts[x + y * 12]);
size_count_string += newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
size_count_string += " ";
}
}
LL_INFOS() << size_count_string << LL_ENDL;
}
LL_INFOS() << header_break << LL_ENDL;
LL_INFOS() << header << LL_ENDL; // Size vs Size counts footer
LL_INFOS() << header_break << LL_ENDL;
LL_INFOS() << "" << LL_ENDL;
// This is the Discard Level Vs Size counts table
header = "Discard: ";
for (S32 x = 0; x < MAX_DISCARD_LEVEL * 2 + 2; x++)
{
std::string newValue = std::to_string(x - 1);
header += newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
header += " ";
}
}
LL_INFOS() << header_break << LL_ENDL;
LL_INFOS() << header << LL_ENDL; // Discard Level Vs Size counts header
LL_INFOS() << header_break << LL_ENDL;
// Y Axis is the current possible max dimension of the textures (X or Y, which ever is larger is used)
for (S32 y = 0; y < 12; y++)
{
std::string newValue = std::to_string((S32)pow(2, y));
std::string discard_count_string = "" + newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
discard_count_string += " ";
}
// X Axis is the discard level starging from -1 up to 10 (2 x MAX_DISCARD_LEVEL + 1 (for negative number) + 1 additional for the fact that the last value actuauly used on not < but <=)
for (S32 x = 0; x < (MAX_DISCARD_LEVEL * 2 + 2); x++)
{
std::string newValue = std::to_string(discard_counts[x + y * (MAX_DISCARD_LEVEL * 2 + 2)]);
discard_count_string += newValue;
for (S32 tab = 0; tab <= 8 - newValue.length(); tab++)
{
discard_count_string += " ";
}
}
LL_INFOS() << discard_count_string << LL_ENDL;
}
LL_INFOS() << header_break << LL_ENDL;
LL_INFOS() << header << LL_ENDL; // Discard Level Vs Size counts footer
LL_INFOS() << header_break << LL_ENDL;
// </FS:minerjr> [FIRE-35081]
}