[fixed]Performance hit with direct3d 9 driver on latest svn

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
edo9300
Posts: 9
Joined: Sun Dec 29, 2019 10:09 pm

[fixed]Performance hit with direct3d 9 driver on latest svn

Post by edo9300 »

Hi, recently I released a new update of my application after upgrading it from irrlicht 1.8.4 to irrlicht 1.9 (as of the latest svn). I had encountered no issues with that when testing it out before switching the version but once released, I recieved reports from users that said that noew the game didn't even reach double digit fps, whereas the previous version reached a steady 60 fps.
After investigating a bit more with those users, I noticed that the call time to IVideoDriver::draw2DImage increased by more than 100% (on 1.8.4 it took ~84 microseconds, while on 1.9 it took ~18000).
I then managed to find the culprit in this change, done in 2012, https://github.com/edo9300/irrlicht1-8- ... 1ece19db53 (I'm using my mirror's link because i still don't know how sourceforge works).
I don't know why there's this big performance hit, my only supposition is that due to the hardware lacking vertex textures support everything is being emulated in software.
The image below is the system info of one of the users that got this issue.
Image
Last edited by edo9300 on Tue Jun 08, 2021 4:20 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Performance hit with direct3d 9 driver on latest svn

Post by CuteAlien »

Thanks for finding. It seems it got discussed back then here: http://irrlicht.sourceforge.net/forum/v ... 5&start=30
Seems Nadro realized it was overhead, but it unified it with OGL behavior as he didn't want to increase the interface by making it optional. I suppose no one expected it to be _that_ expensive.
Also seems it still has a bug with the <= 4 instead of < 4 which was already mentioned in the thread (only goes up to D3DVERTEXTEXTURESAMPLER3)
I suppose it should at lest test if the feature is available, but I'll have to create some test-case for this to see if how much costs it add when the feature is available (when it costs too much we have to make this a driver or material parameter).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Performance hit with direct3d 9 driver on latest svn

Post by CuteAlien »

Textures now check if support is available. Also it has now a texture flag ETCF_SUPPORT_VERTEXT_TEXTURE and is disabled by default in svn trunk r6219.

Test:

Code: Select all

 
#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace video;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
 
irr::video::ITexture* addColorTexture(video::IVideoDriver * videoDriver, irr::video::SColor c)
{
    SColor bgra(c.getBlue(), c.getGreen(), c.getRed(), c.getAlpha());   // ECF_A8R8G8B8 is BGRA in memory
    ITexture* result = 0;
    dimension2du dim(16,16);
    size_t num = dim.Width*dim.Height;
    SColor* data = new SColor[num];
    for ( size_t i=0; i < num; ++i )
    {
        data[i] = bgra;
    }
    IImage* img = videoDriver->createImageFromData(ECF_A8R8G8B8, dim, (void*)data, true, false);
    result = videoDriver->addTexture(io::path(c.color), img);
    delete img;
    delete[] data;
    return result;
}
 
 
int main(int argc, char* argv[])
{
    IrrlichtDevice *  device = createDevice(irr::video::EDT_DIRECT3D9, irr::core::dimension2d<irr::u32>(800,600));
    if (!device)
        return 0;
 
    scene::ISceneManager* smgr = device->getSceneManager();
    video::IVideoDriver * videoDriver = device->getVideoDriver ();
    IRandomizer* randomizer = device->getRandomizer();
 
    videoDriver->setTextureCreationFlag(ETCF_SUPPORT_VERTEXT_TEXTURE, true);
 
    SMaterial m1, m2;
    for ( irr::u32 t = 0; t < irr::video::MATERIAL_MAX_TEXTURES_USED; ++t )
    {
        ITexture * t1 = addColorTexture(videoDriver, SColor(t*111));
        ITexture * t2 = addColorTexture(videoDriver, SColor(t*5000));
        m1.setTexture(t, t1);
        m2.setTexture(t, t2);
    }
 
    irr::u32 oldTimeDiff = INT_MAX;
    while ( device->run() )
    {
        if ( device->isWindowActive() )
        {
            irr::u32 timeStart = device->getTimer()->getRealTime();
            for ( size_t i=0; i<100000; ++i)    // just loop enough until it number have some meaning
            {
                videoDriver->setMaterial(m1);
                videoDriver->setMaterial(m2);
            }
            irr::u32 timeDiff = device->getTimer()->getRealTime() - timeStart;
 
            
            // update information 
            if ( timeDiff < oldTimeDiff )
            {
                oldTimeDiff = timeDiff;
                core::stringw str(L"MS: ");
                str.append(core::stringw(timeDiff));
                device->setWindowCaption( str.c_str() );
            }
        }
        else
        {
            device->sleep( 5 );
        }
    }
 
    device->closeDevice();
    device->drop();
    device = NULL;
 
    return 0;
}
 
The test makes it seem that it has no big difference (0.0001ms per texture switch here when switching all textures in a material twice), but it seems to have more of an effect when used in combination with rendering meshes (I noticed a drop of 1-2 fps when rendering sufficient meshes which use all texture slots).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
edo9300
Posts: 9
Joined: Sun Dec 29, 2019 10:09 pm

Re: Performance hit with direct3d 9 driver on latest svn

Post by edo9300 »

Thanks for answering and for that fix :D. So if I got it right, now the feature is also automatically disabled if the driver doesn't support it, right? In case I coudl try contacting that guy again to see if the check works properly and performances are stable even if ETCF_SUPPORT_VERTEXT_TEXTURE is set.
Also, unrelated to this, in my custom version of irrlicht I have done various changes and improvements (one of them for example is proper clipboard handling on x11 devices), I'd like to contribute to the project with them but I don't really know how sourceforge works and how to create "Pull requests" (I'm used to work on github), could you give me any tips on how to contribute there?
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Performance hit with direct3d 9 driver on latest svn

Post by CuteAlien »

Yeah, it's also disabled if the driver does not support it. But performance is (a tiny bit) better anyway if it's disabled by default and most people won't need this.

Creating patches - basically make a diff to current version of Irrlicht (or a specific one) and save it as patch. If you use svn you can get it with "svn diff". Then you can add the patch here: https://sourceforge.net/p/irrlicht/_list/tickets
Always good to mention for which revision it is.

About X11 copy/paste...*sigh* I actually got a patch (http://irrlicht.sourceforge.net/forum/v ... =7&t=51248), just never made it to the top my todo list (anyway not a fixed order list and if I have working/tested patches that's always great).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
edo9300
Posts: 9
Joined: Sun Dec 29, 2019 10:09 pm

Re: Performance hit with direct3d 9 driver on latest svn

Post by edo9300 »

CuteAlien wrote:Creating patches - basically make a diff to current version of Irrlicht (or a specific one) and save it as patch. If you use svn you can get it with "svn diff". Then you can add the patch here: https://sourceforge.net/p/irrlicht/_list/tickets
Always good to mention for which revision it is.
Thanks for the tip, it's a bit more convoluted than opening pull requests on github but once you know what to do doesn't seem that hard :D.
CuteAlien wrote:About X11 copy/paste...*sigh* I actually got a patch (http://irrlicht.sourceforge.net/forum/v ... =7&t=51248), just never made it to the top my todo list (anyway not a fixed order list and if I have working/tested patches that's always great).
It seems the patch there was from the guys at minetest, I talked with them some time ago and it seems their version in the end didn't work that well. In fact if you're basing the patch off that, keep in mind that it won't work all the times as it should actually busy wait until it recieves SelectionNotify (otherwise the other application might not have set up the cliepboard yet), thing that I'm doing in my implmementation.
Post Reply