Jump to content
  • Advertisement
Sign in to follow this  
Ncyphe

More CPU Intrusive? Shader question

This topic is 2863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, I've been here several times.

I'm working on a ShaderCtrl class that allows for shader parameter setting.
note: This class is a class to handle loading and managing of shaders. The class does not know what is in the shader, as the shader is added at a later date. This class will become part of a core.

Here's the question up front. Which requires more CPU upkeep, GetParameterByName(...) or map::find(...).


Here was my idea, I would, upon shader file loading, store (using info about the shader passed to it) D3DXHandles. When a parameter would need to be set, a string would be searched up in the map returning the handle.

Now, my goal is to make the class use as few cpu resources as possible.


I'm hoping to get an answer soon. I'm still a student at this, and have found these forums very helpful in expanding my knowledge.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Ncyphe
Here's the question up front. Which requires more CPU upkeep, GetParameterByName(...) or map::find(...).
You'd have to profile it to be sure, but...
Quote:
When a parameter would need to be set, a string would be searched up in the map returning the handle.
Now, my goal is to make the class use as few cpu resources as possible.
If your goal is performance, then you should strive to remove all string comparisons from the rendering code. You should perform string-comparisons when loading a new shader, to get handles/indices, but that's it. During the actual rendering, you use the handle/index to set the parameter without any string compares or map lookups.

If you don't want to return D3DXHandles to your user, then instead of putting them into a map, put them into a vector. The user of the shader class can then search the vector for a particular string once (at load-time) and get back a numeric index. When they want to update a parameter, they give you the index, which you can use to get the D3DXHandle.

Share this post


Link to post
Share on other sites
A D3DXHandle isn't really a string, it just looks like one. But that aside, I was paranoid about the same thing for a long time, until I eventually decided to just run with it and see what happened. And there was no performance difference.

Share this post


Link to post
Share on other sites
/facepalm

My professor just explained it in his lecture.

Never knew Map:: used hash tables.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!