我要发帖 回复

正式会员

6

主题

32

积分

0

专家分

:

私信
发表时间 : 2007-10-12 00:36:01 | 浏览 : 2821    评论 : 17
#include <vpSearchPath.h>
#include <vpApp.h>
#include "vuAllocTracer.h"
#include "vuDistributed.h"
vuAllocTracer tracer(true, true);


// #########################################################
// # To run this distributed rendering sample, use the     #
// # Distributed Rendering Utilites to setup a master and  #
// # a slave system                                        #
// #########################################################

class myApp : public vpApp {

public:
    myApp() : vpApp() {};
    ~myApp() {};
   
    virtual void run();

private:

};

void myApp::run()
{

    ////vuNotify::setLevel( vuNotify::LEVEL_INFO );
        // Setting the vuNotify level this high (LEVEL_INFO) causes performance problems,
        // and was reported as a color or flicker problem in Mantis Bug #0010767 --pmh
        vuNotify::setLevel( vuNotify::LEVEL_FATAL );
   
    uint frameNum;
    if( vuDistributed::getMode() == vuDistributed::MODE_SLAVE ) {
        uint seed = 13;
        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Slave setting seed to = %d\n",
                          seed ) );
        srand(seed);
    } else {
        
        uint seed = 5;
        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Master setting seed to = %d\n",
                          seed ) );
        srand(seed);
    }

    // rendering loop
    while ( (frameNum = vpKernel::instance()->beginFrame()) > 0 ) {

        int myframenum = frameNum;

        // basic sync mechanism.  masters and slaves wait.  no data is exchanged.
        vuDistributed::sync();

        int randomNum = rand();

        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Original Random Number = %d\n",
                          randomNum ) );

        int masterData;

        // if master, cache the random number and send it to the slaves.
        if( vuDistributed::getMode() == vuDistributed::MODE_MASTER ) {
            masterData = randomNum;
        }

        // slaves wait for master to receive data.  if master gets here first, it sends data and immediately moves on.
        // if slaves get here first, slaves block waiting for master's data.
        vuDistributed::sync( (char*) &masterData, sizeof(masterData), vuDistributed::SYNC_LABEL_USER, vuDistributed::WAIT_SLAVES );

   
        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Data sent from master = %d\n",
                          masterData ) );

        int randBuf[64];

        // master and slaves swap data.  notice no wait enum is required.  by definition all dr apps wait until
        // all data has been exchanged.
        vuDistributed::sync( (char*) &randomNum, sizeof(randomNum), (char*) &randBuf, sizeof(int)*vuDistributed::getNumParticipants(),vuDistributed::SYNC_LABEL_USER );

        int lowRand = INT_MAX;
        for( int i = 0; i < vuDistributed::getNumParticipants(); i++ ) {

            if( randBuf < lowRand )
                lowRand = randBuf;
        }

        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Lowest Random Number = %d\n",
                          lowRand ) );


        assert( myframenum == frameNum );        
        
        double time   = vpKernel::instance()->getSimulationTime();        

        static double previousTime = -1;
        static double maxTime = DBL_MIN;
        static double minTime = DBL_MAX;
        static double totalTime = 0;


        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Frame Number = %d, time = %f\n",
                          frameNum,
                          time ) );
        
        if( previousTime != -1 ) {


            double deltaTime = time - previousTime;

            if( deltaTime > maxTime )
                maxTime = deltaTime;
            if( deltaTime < minTime )
                minTime = deltaTime;

            totalTime += deltaTime;


            VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                              NULL,
                              "Delta = %.3f sec, Max = %.3f, Min = %.3f, Avg = %.3f\n",
                              deltaTime, maxTime, minTime, totalTime/double(frameNum) ) );
        }
        previousTime = time;

        vpKernel::instance()->endFrame();
        
    }

    unconfigure();
}

int main(int argc, char *argv[])
{
    // initialize vega prime
    vp::initialize(argc, argv);   

    // initialize addition modules here
    // vpModule::initializeModule(modulename);


    // Set the syncEnable bits *prior* to configure().
    // DR ignores changes to setSyncEnable() after configure().

    // Pre swapbuffers synchronization.  Setting to "true" forces the master
    // and slaves to sync before swapbuffers.  Setting to "false" will result
    // in systems swapping their buffers independently.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_PRE_SWAPBUFFERS, true );

    // Post swapbuffers synchronization.  Setting to "true" forces the master
    // and slaves to sync after swapping their buffers.  
    // This typically results in slower framerates, but can ensure all systems
    // have the same amount of draw time.
    // Default is "false."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_POST_SWAPBUFFERS, false );

    // ACF synchronization across DR slaves.  Setting to "true" will send the
    // master's version of an ACF to the slaves (slaves will ignore their local
    // copy).  Setting to "false" will force slaves to use their local copy of
    // the ACF passed into ::define().
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_ACF, true );

    // Time synchronization across DR slaves. Setting to "true" will give every
    // system the same frame time.  Setting to "false" will let each system
    // use its system's clock for time.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_TIME, true );

    // Window messages synchronization.  Setting to "true" will send the
    // master's messages to all the slaves.  Setting to "false" will prevent
    // sending the master's window messages to the slaves.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_MESSAGES, true );
  
    // Virtual Texture synchronization.  Setting to "true" will force all
    // systems to page virtual texture at the same time.  Setting to "false"
    // will cause systems to page virtual texture independently.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_VT, true );

    // Synchronize paging.  Setting to "true" will force all systems to page
    // texture and geometry at the same time.  Setting to "false" will cause
    // systems to page texture and geometry independently.
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_PAGING, true );

    // Synchronize input devices.  Setting to "true" will make each system
    // react as if the master's input device is connected to the slave.  
    // Setting to "false" will not pass input device updates from the master
    // to the slaves.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_INPUT, true );

    // Synchronize Level of Detail Stress.  Setting to "true" will ensure all
    // LOD changes are synchronized.  Setting to "false" let each system
    // determine independently when LOD's should change.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_LOD_STRESS, true );

    // User defined synchronization.  Setting to "true" will enable user
    // defined synchronization.  Setting to "false" disables all user
    // defined synchronization.  In this example, disabling user defined sync
    // result in different lowest random numbers for each system.
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_USER, true );


    // create a vpApp instance
    myApp *app = new myApp;

    // load acf file
    if (argc <= 1)
        app->define("vp_distributed.acf");
    else
        app->define(argv[1]);
        

    // configure my app
    app->configure();

    // runtime loop
    app->run();
   
    // unref my app instance
    app->unref();
   
    // shutdown vega prime
    vp::shutdown();

    return 0;
}

最近VR访客

obuil 评论于2007-10-12 00:44:56
这个不是例子中的么?
daiyulianghg 评论于2007-10-27 00:12:16
不错,值得学习
z4318055 评论于2007-10-27 20:13:39
留名。。。
wsxtgly 评论于2007-11-9 20:45:58
很好谢谢!
winsome 评论于2007-12-2 22:07:07
好东西我来顶
297006329 评论于2007-12-4 20:14:45
怎么有想法把samples贴出来,,,
blanktree 评论于2008-2-22 10:08:08
没看懂
plazhaowei 评论于2008-4-16 14:44:47
帖sample也得帖对呀!你这是分布式渲染呢。。。。。我还以为是分布式仿真呢
lifegoing 评论于2008-4-16 16:59:00
ding
ming1223 评论于2008-5-13 21:14:02
支持!!
fisheep2008 评论于2008-5-26 17:46:41
正是需要的,顶了
lbbbbl01410401 评论于2008-5-27 16:16:47
看一下
perfect_ren 评论于2008-5-28 16:50:16
渲染仿真有什么区别啊?为什么说就是渲染呢?
caoun1015 评论于2008-5-29 18:10:40
提示: 作者被禁止或删除 内容自动屏蔽
走过四月
amutieer2006 评论于2008-6-1 22:46:31
来学习
perfect_ren 评论于2008-6-16 15:14:17
大家讨论讨论这个例子代码的含义,我没看懂,app::run()里面帧循环之前是在干什么?我把自己的可以用的分布式渲染acf文件加到这个程序里面来,程序退出,诡异:(,如果用mfc程序,是把上面的sample拷过去就行么?还有,分布式渲染和多屏卡输出区别只在性能上么?也就是如果单机多屏卡能达到性能要求,没必要要分布式渲染,可以这样理解么?请高手指点
只要做些什么,就会有所不同:)

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2021-10-16 04:12 PM

返回顶部