Sign in to follow this  

ID3D10ShaderResourceView* and std::map

This topic is 2339 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

[size="2"]Hi. I've madea simple Texture Manager for DrectX 10 using ID3D10ShaderResourceView and [/size]
[size="2"]std::map.I just want it be simple for my small demos. Here is how I organazied it:[/size]

[code]class TextureManager
{
private:
static class TextureManager *m_TextureManager;
map<wstring, ID3D10ShaderResourceView*, less<wstring> > textures;
map<wstring, ID3D10ShaderResourceView*, less<wstring> >::iterator iter;
ID3D10Device* md3dDevice;
public:
TextureManager (void);
~TextureManager (void);
static TextureManager *GetManager();
bool addTexture(wstring path);
void deleteTexture(wstring path);
void clearTextures();
void setDevice(ID3D10Device* dev);
void checkDevice();
ID3D10ShaderResourceView* GetTextureView(wstring path);
ID3D10Device* getDevice();
ID3D10ShaderResourceView* TexView;
};[/code]
[size="2"][color="#000000"]it's a singleton class, [/color][/size][size="2"][color="#000000"]addTexture and GetTextureView implemented like this:[/color][/size]
[code]bool TextureManager::addTexture(wstring path)
{
checkDevice();
iter=textures.find(path.c_str());
if(iter==textures.end())
{
HRESULT hr=D3DX10CreateShaderResourceViewFromFile(md3dDevice, path.c_str(), NULL, NULL, &TexView, NULL);
if(hr!=S_OK)
return false;
textures.insert( pair<wstring,ID3D10ShaderResourceView*>(path.c_str(),TexView));
return true;
}

return false;
}

ID3D10ShaderResourceView* TextureManager::GetTextureView(wstring path)
{
checkDevice();
iter=textures.find(path.c_str());
if(iter==textures.end())
if(!addTexture(path.c_str()))
return NULL;
return textures[path.c_str()];
}

[/code]




[size="2"][color="#000000"]The problem is when I'm using my manager's function GetTextureView to set new texture into shader like this:[/color][/size]

[size="2"][color="#000000"]mfxVar->SetResource(txr_man->GetTextureView(filenames[texIndex].c_str()));[/color][/size]

[size="2"][color="#000000"]I got my application 200-300 FPS down :[/color][color="#000000"]( If I use just an [/color][color="#000000"]ID3D10ShaderResourceView*[/color][color="#000000"]array in application,instead of texture manager FPS looks good. Can't understand why putting [/color][color="#000000"]ID3D10ShaderResourceView [/color][color="#000000"]into <map>decreases FPS. Sure I can get rid of <map> just using an array of [/color][color="#000000"]ID3D10ShaderResourceView [/color][color="#000000"]in my manager while keeping it's functionality, but then I can't resize my texture array. Someone have any ideas about? [/color][/size]

Share this post


Link to post
Share on other sites
[quote name='n3Xus' timestamp='1311500894' post='4839534']
200-300 FPS down?? How much FPS do you have, 2k?

Never measure time in fps, always use 1/fps to get the actual time of the frame.
[/quote]




While in release build it's about 3000 but it's because there isn't much things in scene: only textured level, and camera for now. But the question is about [b]why storing ID3D19ShaderResourceView* in std::map slows down the game?[/b] Not about how large my FPS or how do I measure it.


Share this post


Link to post
Share on other sites
[quote name='blackslayer' timestamp='1311519528' post='4839607']
[quote name='n3Xus' timestamp='1311500894' post='4839534']
200-300 FPS down?? How much FPS do you have, 2k?

Never measure time in fps, always use 1/fps to get the actual time of the frame.
[/quote]

While in release build it's about 3000 but it's because there isn't much things in scene: only textured level, and camera for now. But the question is about [b]why storing ID3D19ShaderResourceView* in std::map slows down the game?[/b] Not about how large my FPS or how do I measure it.
[/quote]

It slows down the game because more instructions are executed, it's as simple as that. Not that those 300 fps really matter: 3000 fps is 0.33 ms PER frame. 2700 fps is 0.37 ms PER frame, thus your code takes 0.04 ms longer which is no big deal.


However, why do your methods take wstring by value? That always copies the string that is passed in. Even worse is that you are actually passing a const wchar_t* in to the methods, creating another copy while at it. If you have a wstring already, simply pass it to the method, you don't need and should not call .c_str()! You should also change the signature of your methods from method(wstring) to method(const wstring&), which makes them take a reference to a wstring (and thus no copying is involved).




[code]

bool TextureManager::addTexture(const wstring& path)
{
checkDevice();
iter=textures.find(path);
if(iter==textures.end())
{
HRESULT hr=D3DX10CreateShaderResourceViewFromFile(md3dDevice, path.c_str(), NULL, NULL, &TexView, NULL);
if(hr!=S_OK)
return false;
textures.insert( make_pair(path,TexView));
return true;
}

return false;
}

[/code]

Share this post


Link to post
Share on other sites
[quote name='blackslayer' timestamp='1311525919' post='4839649']
Well tried written above. FPS still falls, maybe I need something else.
[/quote]

What I've been trying to say is that you don't need to worry about that right now. Your game runs in 0.37 ms a frame. You have got another 59 ms to use before you should worry.

Share this post


Link to post
Share on other sites
What we're trying to tell you is that FPS are NOT linear: 120 fps does NOT mean "twice as fast" as 60 fps. On the other hand, 0.4ms per frame is twice as fast as 0.8ms per frame.
The lower the FPS, the slower they get even lower under more work.

This explains why there seems to be a "huge" difference just by doing something as simple as a map insert/read, while it is actually neglectable.

Share this post


Link to post
Share on other sites

This topic is 2339 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this