hi guys, i found the first two RenderOneFrame will take more time than others, and "handleSchemeNotFound" is called several times when rendering started , is it possible to reduce the time taked by the first two frame ?
because my application is time-sensitive , thanks in advance !
why the first two frame take much more times than others ?
-
- Greenskin
- Posts: 129
- Joined: Fri Oct 31, 2014 4:22 am
-
- OGRE Expert User
- Posts: 1119
- Joined: Sat Jan 01, 2011 7:57 pm
- x 216
Re: why the first two frame take much more times than others
This must be something your app is doing. handleSchemeNotFound isn't used by default in Ogre (that is, by default there are no listeners registered that can handle a not found scheme).
-
- Greenskin
- Posts: 129
- Joined: Fri Oct 31, 2014 4:22 am
Re: why the first two frame take much more times than others
hi scrawl, i using ogre on android , and init the RTShaderSystem as following :
bool OgreRender::initialiseRTShaderSystem(Ogre::SceneManager* sceneMgr)
{
if (Ogre::RTShader::ShaderGenerator::initialize())
{
mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
// Create and register the material manager listener if it doesn't exist yet.
if (mMaterialMgrListener == NULL) {
mMaterialMgrListener = new ShaderGeneratorTechniqueResolverListener(mShaderGenerator);
Ogre::MaterialManager::getSingleton().addListener(mMaterialMgrListener);
}
}
return true;
}
class ShaderGeneratorTechniqueResolverListener {
...
virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex,
const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex,
const Ogre::Renderable* rend)
{
// Case this is the default shader generator scheme.
if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
{
MaterialRegisterIterator itFind = mRegisteredMaterials.find(originalMaterial);
bool techniqueCreated = false;
// This material was not registered before.
if (itFind == mRegisteredMaterials.end())
{
techniqueCreated = mShaderGenerator->createShaderBasedTechnique(
originalMaterial->getName(),
Ogre::MaterialManager::DEFAULT_SCHEME_NAME,
schemeName);
}
mRegisteredMaterials[originalMaterial] = techniqueCreated;
}
LOGI("handleSchemeNotFound return NULL !");
return NULL;
}
}
if don't call initialiseRTShaderSystem when system initialize, nothing can be renderd on the screen .
most of my material is create by code ,like so :
material = MaterialManager::getSingleton().create(spriteName,"Popular");
Could somebody give me some suggestion ? thanks !
bool OgreRender::initialiseRTShaderSystem(Ogre::SceneManager* sceneMgr)
{
if (Ogre::RTShader::ShaderGenerator::initialize())
{
mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
// Create and register the material manager listener if it doesn't exist yet.
if (mMaterialMgrListener == NULL) {
mMaterialMgrListener = new ShaderGeneratorTechniqueResolverListener(mShaderGenerator);
Ogre::MaterialManager::getSingleton().addListener(mMaterialMgrListener);
}
}
return true;
}
class ShaderGeneratorTechniqueResolverListener {
...
virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex,
const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex,
const Ogre::Renderable* rend)
{
// Case this is the default shader generator scheme.
if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
{
MaterialRegisterIterator itFind = mRegisteredMaterials.find(originalMaterial);
bool techniqueCreated = false;
// This material was not registered before.
if (itFind == mRegisteredMaterials.end())
{
techniqueCreated = mShaderGenerator->createShaderBasedTechnique(
originalMaterial->getName(),
Ogre::MaterialManager::DEFAULT_SCHEME_NAME,
schemeName);
}
mRegisteredMaterials[originalMaterial] = techniqueCreated;
}
LOGI("handleSchemeNotFound return NULL !");
return NULL;
}
}
if don't call initialiseRTShaderSystem when system initialize, nothing can be renderd on the screen .
most of my material is create by code ,like so :
material = MaterialManager::getSingleton().create(spriteName,"Popular");
Could somebody give me some suggestion ? thanks !
-
- Greenskin
- Posts: 129
- Joined: Fri Oct 31, 2014 4:22 am
Re: why the first two frame take much more times than others
the stange problem is the first two RenderOneFrame take about 900ms on N5 mobie phone , i think may be the time is spend by RT shader generate to emulation the fix pipline, right ?
and if use shader cache can resolve this problem ? needs experts help.
and if use shader cache can resolve this problem ? needs experts help.
- Kojack
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 534
Re: why the first two frame take much more times than others
The RTShader system will need time to generate the shaders on their first use. That could be the performance hit.
Ogre also loads resources on demand. The first frame will take longer because the meshes and stuff haven't actually been loaded yet, when the renderOneFrame hits things it hasn't rendered before it has to load them.
The same will happen anytime a new thing appears, such as the first time an explosion particle effect or a new mesh appears on screen, there will be a performance hit as that thing gets loaded.
To avoid that, you need to preload everything you might render. Materials are loaded in advance for you, but textures and meshes aren't. You need to tell the various managers (TextureManager, MeshManager) to manually load them.
Something like: TextureManager::getSingleton().load("cloud.png","General");
But for every mesh and texture you want.
You can also use resource groups to batch load things, but it needs a little extra work to set up. You need to manually declare resources before initialising the resource groups. It's a bit complicated.
Ogre also loads resources on demand. The first frame will take longer because the meshes and stuff haven't actually been loaded yet, when the renderOneFrame hits things it hasn't rendered before it has to load them.
The same will happen anytime a new thing appears, such as the first time an explosion particle effect or a new mesh appears on screen, there will be a performance hit as that thing gets loaded.
To avoid that, you need to preload everything you might render. Materials are loaded in advance for you, but textures and meshes aren't. You need to tell the various managers (TextureManager, MeshManager) to manually load them.
Something like: TextureManager::getSingleton().load("cloud.png","General");
But for every mesh and texture you want.
You can also use resource groups to batch load things, but it needs a little extra work to set up. You need to manually declare resources before initialising the resource groups. It's a bit complicated.
-
- Greenskin
- Posts: 129
- Joined: Fri Oct 31, 2014 4:22 am
Re: why the first two frame take much more times than others
even if i loaded every thing manually, i.e. tell texture manager and mesh manager to load all stuff needed , the total time can be more less than the origin automate late loading way ?
in fact , i don't just care the firsrt renderOneFrame's long time, i want to shorten the total loading time before the first scene can be displayed on the screen .
can you give some suggestion on optimize the time between engine start to first scene appear ?
in fact , i don't just care the firsrt renderOneFrame's long time, i want to shorten the total loading time before the first scene can be displayed on the screen .
can you give some suggestion on optimize the time between engine start to first scene appear ?
- syedhs
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: why the first two frame take much more times than others
Well obvious answer is: the fastest way to load a scene is not to load anything.. and entities are loaded slowly one by one.
To make it slightly more complicated, the engine may discover the nearest objects within certain radius to camera (or controller) and then have it saved somewhere. The next load, engine will load only those nearest objects and then scene is rendered (so scene loading is quick). The further objects can then be loaded slowly over certain frame - to avoid hiccups.
To make it slightly more complicated, the engine may discover the nearest objects within certain radius to camera (or controller) and then have it saved somewhere. The next load, engine will load only those nearest objects and then scene is rendered (so scene loading is quick). The further objects can then be loaded slowly over certain frame - to avoid hiccups.
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me