Hello! - You can skip this segment if you're short on time. --->
I was wondering why my game's performance dropped notably and steadily over the last year or 2 despite optimizing it regularly (in an actual level it sometimes only ran as well as DOOM 2016 on max settings on my machine, which is a little ridiculous). After writing a basic profiler and other stuff I found out something strange:

- Everything deactivated, no pp, no (other) functions running. Simple test scene (A), a couple of objects and blocks, most of the screen empty blue sky -> 500 fps (~170 fps with actual game stuff running on the same scene, no pp - I know you have to take the ms into account for best comparison).

- Is A8 that "slow"? No: In another project (B), a first person prototype with full post processing (including SSAO and godrays), movement and other code and over 100k triangles visible - meaning something way more demanding - I get over 400fps on 1920x1080 as well, 500fps on the next lower resolution. -> Problem had to be somewhere else.

- Turns out, when I level_load(NULL) from scene (A) on the press of a button the FPS only jumps up to about 750 with no functions running, not a lot more than in the other actual game (B) on lower resolutions. If I level_load(NULL) immediately or a frame after I get 2500fps. Hm!

-------------------->

This led me to the following self contained example: http://superku.de/materialTest.zip
Click to reveal..
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

BMAP* bmpTest = "tex1024x1024.tga";
BMAP* bmpTestb = "tex1024x1024b.tga";

void levelNull()
{
	level_load(NULL);
}

void main()
{
	fps_max = 9999;
	video_mode = 10;
	level_load(NULL);
	int i;
	for(i = 0; i < 500; i++)
	{
		MATERIAL* matNew = mtl_create();
		if(1)
		{
			you = ent_create(CUBE_MDL,vector(100+random(100),random(100)-50,random(100)-50),NULL); // "testCube.mdl"
			effect_load(matNew,"test.fx");
		}
		else
		{
			you = ent_create("testCube.mdl",vector(100+random(100),random(100)-50,random(100)-50),NULL);
			effect_load(matNew,"testEntSkin.fx");
		}
		your.material = matNew;
	}
	on_space = levelNull;
	def_debug();
	while(1)
	{
		DEBUG_VAR(16.0/time_frame,200);
		wait(1);
	}
}


It takes a couple seconds to create 500 materials but it makes the problem more apparent. Please start it once with if(1), note the performance before and after you press space. Then do it again but change to the second case if(0) first.

- if(1): Two 3MB textures are requested from the materials via _bmap feature.
~290fps -> space -> ~580fps
- if(0): Model with two external 3MB textures and entSkin1/2.
~600fps -> space -> ~3800fps




This leads me to a few questions:
1) Does it make sense that the shader with *_bmap textures is rendering (texture swapping?) slower than the entSkin alternative? If so, why?
2) Why does the application only run at < 600fps in the first case after level_load(NULL)? It seems as if the textures are still being updated for every material. Oh, when you def_move/ [0] and turn the camera around so nothing gets rendered you (more or less obviously) pretty much get the same FPS before and after level_load(NULL).
3) Can this be "fixed"?


I have 816 fx files in my project folder, I guess I use 750+ of them. Most of them share a bunch of textures using the *_bmap feature, and oftentimes 1-4 entSkins as additional textures. The 1700+ models have a corresponding setup. Changing it all to entSkins (where possible because of the amount of textures) would be a pain and I'd highly prefer a code solution.

Thanks in advance for your time.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends