[solved][1.12.3] background loading Topic is solved

Problems building or running the engine, queries about how to use features etc.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

[solved][1.12.3] background loading

Post by loath »

did background loading change in 1.12.3 vs 1.11.5? (i'm using dx9)

i background load pretty much everything in my project as the player moves around the world. after queuing a resource load on 1.12.3 i never get a completion notification. i.e. callback via operationCompleted (...results...). this worked correctly on 1.11.5.

Code: Select all

auto& queue = Ogre::ResourceBackgroundQueue::getSingleton ();
resource->setBackgroundLoaded (true); // ex. a terrain texture resource
auto ticket = queue.load (resource->getCreator ()->getResourceType (), resource->getName (), resource->getGroup (), false, NULL, NULL, this);

...

// sometime later this should be called but is not on 1.12.3:
void operationCompleted (Ogre::BackgroundProcessTicket id, const Ogre::BackgroundProcessResult& result);
i will debug into this but thought i would ask up front.

thanks!
Last edited by loath on Fri Nov 15, 2019 2:04 am, edited 1 time in total.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [1.12.3] background loading

Post by loath »

looks like i set OGRE_CONFIG_THREADS == 2 in 1.11.5 and OGRE_CONFIG_THREADS == 3 in 1.12.3.

if option 2 is deprecated does that mean i need to implement my own background loader support in the future? what should i be using moving forward? i will return to option 2 for now.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [1.12.3] background loading

Post by loath »

switched to thread model 2 and everything works. awesome!

i would still be curious to know from @paroj if i should be moving away from ogre background loading (down the road) since it's now deprecated.
paroj
OGRE Team Member
OGRE Team Member
Posts: 2151
Joined: Sun Mar 30, 2014 2:51 pm
x 1156

Re: [solved][1.12.3] background loading

Post by paroj »

thread model 2 was deprecated based on this
https://github.com/OGRECave/ogre/issues/454

I do not know how you do background loading, but the idea is that you perform locking yourself and should be able to continue using ogre as before otherwise.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [solved][1.12.3] background loading

Post by loath »

great writeup - love getting rid of these unnecessary locks.

if i configure ogre with option 3 then OGRE_THREAD_SUPPORT is disabled:

Code: Select all

#if OGRE_THREAD_SUPPORT == 3 // resource system is not threadsafe
#undef OGRE_THREAD_SUPPORT
#define OGRE_THREAD_SUPPORT 0
#endif
this means the ResourceBackgroundQueue::load() call becomes synchronous:

Code: Select all

BackgroundProcessTicket ResourceBackgroundQueue::load(
        const String& resType, const String& name, 
        const String& group, bool isManual, 
        ManualResourceLoader* loader, 
        const NameValuePairList* loadParams, 
        ResourceBackgroundQueue::Listener* listener)
    {
#if OGRE_THREAD_SUPPORT
        // queue a request
        ResourceRequest req;
        req.type = RT_LOAD_RESOURCE;
        req.resourceType = resType;
        req.resourceName = name;
        req.groupName = group;
        req.isManual = isManual;
        req.loader = loader;
        // Make instance copy of loadParams for thread independence
        req.loadParams = ( loadParams ? OGRE_NEW_T(NameValuePairList, MEMCATEGORY_GENERAL)( *loadParams ) : 0 );
        req.listener = listener;
        return addRequest(req);
#else
        // synchronous
        ResourceManager* rm = 
            ResourceGroupManager::getSingleton()._getResourceManager(resType);
        rm->load(name, group, isManual, loader, loadParams);
        return 0; 
#endif
    }
all i really care about is calling resource->prepare() on a background thread. i can just handle this myself but wanted to make sure i understood the goal before switching to a custom implementation.

thanks!
paroj
OGRE Team Member
OGRE Team Member
Posts: 2151
Joined: Sun Mar 30, 2014 2:51 pm
x 1156

Re: [solved][1.12.3] background loading

Post by paroj »

so reverting https://github.com/OGRECave/ogre/pull/4 ... 054c59369c would suit you?

I think that it is safe to assume that nobody accidentally calls ResourceBackgroundQueue.

Unfortunately there was no background loading test in the ogre codebase to think that through in the first place..
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [solved][1.12.3] background loading

Post by loath »

yes that works very well for me.

i would switch:

Code: Select all

auto ticket = queue.load (...);
to:

Code: Select all

auto ticket = queue.prepare(...);
(i should have been using prepare anyway)

awesome getting rid of those unnecessary locks. i use this all over so if it breaks something i will know quickly. i will try this out tomorrow and let you know.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 294
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [solved][1.12.3] background loading

Post by loath »

i verified the fix and it works great.

for future reference, i just needed to call:

Code: Select all

auto ticket = queue.prepare(resource, ...);
and then in the completion callback on the main thread:

Code: Select all

void operationCompleted (Ogre::BackgroundProcessTicket id, const Ogre::BackgroundProcessResult& result)
{
     auto resource = resources_[id];
     if (!result.error) resource->load (true);
}
... to get the "old" behavior. i like that it's explicit that i'm preparing on the background and not loading. (i.e. since in dx9 i can't complete the load on a worker thread)

thanks so much!