Skip to main content
gamedev.net
🔒 Locked

slow Effects

Started by treeway 3 replies 1.1k views
Original Post
treeway
treeway
Hi I have my engine managed so that it groups visible subsets by material and renders one material at a time. A material can be just a colour or a texture or an effect. The problem is that when I render effects, my engine realy slows down. In my ID3DXEffect wrapper class, I read in all the SAS semantics into a vector then when i come to rendering i loop through the semantics and set them to those from the engine. i.e i set the viewMatrix to the cameras view matrix and the world matrix to that of the current subset. The thing is that to do this i have to strcompi the perameter with a list of supported values:

	viewMatrix = base->camera->getViewMatrix();
	projectionMatrix = base->camera->getProjectionMatrix();

	for(UINT i = 0; i < Semantics.size(); i ++)
	{	
		matrix   = NULL;
		currentSemantic = Semantics;
		
		if(strcmpi(currentSemantic->semantic,"View") == 0)
		{
			matrix = viewMatrix;

			pEffect->SetMatrix(currentSemantic->name,matrix);
			
		}
		else if(strcmpi(currentSemantic->semantic,"ViewInverse") == 0)
		{
			matrix = viewMatrix;
			D3DXMatrixInverse(matrix,NULL,matrix);

			pEffect->SetMatrix(currentSemantic->name,matrix);
		}
		else if(strcmpi(currentSemantic->semantic,"ViewInverseTranspose") == 0)

//etc for loads of possible values..... 
	
whats more i have to do this once for every subset which has the effect every frame. This works but its SLLLOOOWWWWW. So im asking how do other people chose how to update their effect semantics? thanks [Edited by - treeway on September 10, 2006 6:14:10 PM]
superpig
superpig
Are you sure that it's this section of code that is taking the time? Have you profiled it?

If it's really this bit, then the obvious choice would be to do the string comparions when you load the effect, and instead of storing the actual semantics, just store enumerated constants (i.e. EFFECT_SEMANTIC_VIEW, EFFECT_SEMANTIC_VIEW_INVERSE, etc). Then, the code you've shown here can be changed to use a big switch() statement.

I'd also recommend using effect pools so that most of these parameters can be shared between effects - you'll only need to set them once per frame that way, instead of once per subset/shader.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
sirob
sirob
Also, for that bit of code I'd probably use a std::map or similar container, instead of the vector or list you're using now. You'd map each SemanticName to a value. This would both help you in eliminating duplicates, and let you just do one run through the map and apply all semantics to the effect.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
MrSparkle
MrSparkle
Quote:
Original post by superpig
I'd also recommend using effect pools so that most of these parameters can be shared between effects - you'll only need to set them once per frame that way, instead of once per subset/shader.


This sounds very promising, how can I make use of the EffectPools class?
I cound't find any information about that, and the DirectX documentation of this topic is not very helpful.
superpig
superpig
Quote:
Original post by MrSparkle
Quote:
Original post by superpig
I'd also recommend using effect pools so that most of these parameters can be shared between effects - you'll only need to set them once per frame that way, instead of once per subset/shader.


This sounds very promising, how can I make use of the EffectPools class?
I cound't find any information about that, and the DirectX documentation of this topic is not very helpful.


It's fairly straightforward. You have a number of parameters in different effects that all have the same name and semantic, and are declared with the 'shared' keyword. Then, before creating any effects, call D3DXCreateEffectPool to create an effect pool object. Pass that pool interface to the D3DXCreateEffect* functions when creating effects with shared parameters.

The effect pool will look at the 'shared' parameters on each effect you add to it, and pair up ones that have the same name and semantic. Setting that parameter on any one effect in the pool will cause all the others to be simultaneously updated.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.