{multi-threaded Mesh skinning Showing Promise}

Source: Internet
Author: User

from:http://www.garagegames.com/community/blogs/view/14899

Multi-threaded mesh skin Display conventions

Mesh skinning is part of the object rendering process, which is done by Tsskinmesh::render () . Tsskinmesh::render ( ) calls Updateskin ( ) and then calls Parent::render () . Parent::render () creates a rendering instance. However, the vertex cache (vertex buffer) is created and will not be used immediately. According to this, the idea of using a "Promise" to denote something that is not yet ready but will eventually be ready is born. Similar to many network cases, so does the skin of the grid.

#ifndef _promise_h_#define_promise_h_//This is a rough draftTemplate <typename t>classPromise {protected:    //Return the promised data. Undefined results if IsReady () is false.    Virtualt*Get() =0; Public:    Virtual~Promise () {}//Returns True if the promised data is ready.VritualBOOLIsReady ()Const=0; //Blocks until the promised data is ready, and returns it.    Virtualt*Resolve () { while(!IsReady ()) {            return Get(); }    }};#endif

Then, a promise* pointer is stored in the render instance object instead of a vertex cache (vertex buffer) pointer. Before sending the drawing data to the device, the Resolve () method of a promise instance is called to achieve a wait operation before it is ready.

#ifndef _simple_promise_h#define_simple_promise_hTemplate<typename t>classSimplepromise: PublicPromise<t> {    protected: T*mptr; VirtualTGet() {returnMptr;}  Public: Simplepromise (T*PTR): Mptr =ptr {}Virtual BOOLIsReady ()Const{return true; } VirtualBoidSet(T *ptr) {mptr =ptr;}};#endif

You can then create a threadedpromise class to represent a single thread to complete a contract (promise). Then, when you create a Promisedfulfilerthread class, the class can manipulate a collection of Threadedpromise class instances. Because locking, release locks also take time, it is not appropriate to perform simple operations on a collection, that is, it is inappropriate to place locks in the Promisedfulfilerthread class. It is more appropriate to place the mutex (mutex) in the Promisedpromise class by re-considering the issue. The test found that the main thread (thread main) takes a batch operation on the rendered instance, starts drawing, and stops idling when it enters a Promise that is not yet ready. If the main thread can pick several promise instances when needed, and then complete it, the rendering performance can be improved.

Tsskinbatcher-- threaded Skin Promise Metrics     13405091382          42668 [ 31.83%]        15065 [35.31%]        27603 [64.69 

It can be found that in 134k skin requests, 91k times are processed in the worker thread before the main thread request, and 42k times of promise block the main thread. In this 42k request, 15k promise are processed in the worker thread before the main thread prepares to access them ...

#ifndef _threadedpromise_h#define_threadedpromise_hTemplate<typename t>classThreadedpromise: PublicPromise<t> {     Public:    Virtualt*Resolve () {profile_scope (threadedpromise_resolve); #ifdef Enable_threaded_promise_metricsif(_isready ()) {atomic::value32::increment (&smnoblockresolves); return Get(); }        #else        if(_isready ()) {returngGet(); }        #endif        //Interlock op, take control of promise        if(Minterlockstate = = Ilspromisenostate &&(Atomic::value32::increment (&minterlockstate) = =ilspromiseacquired)) {#ifdef enable_threaded_promise_metrics atomic::value32::increment (&smmainthreadresolveblocks); #endif               return Set(reinterpret_cast<t*>(Mfulfilerfunction (Mfunctiondata))); }         while(!_isready ()) {Platform::sleep (0); } #ifdef enable_threaded_promise_metrics Atomic::value32::increment (&smworkerthreadresolveblocks); #endif        return Get(); }
// ...

{multi-threaded Mesh skinning Showing Promise}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.