00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "test_compute.h"
00010
00011 #ifdef USE_CL
00012
00013
00014 TestCompute::TestCompute(int _duration, int _type, TScene *s) : Test(_duration, _type, s)
00015 {
00016
00017 if(type == COMPUTE_NBODY)
00018 {
00019 testname = "nbody";
00020 weight = 1.0;
00021 splits = 1;
00022 halfbody = BODIES/2;
00023
00024 s->SetLoadList(7);
00025
00026 try
00027 {
00028 nbody = new NBodySim();
00029 if(!nbody->Init())
00030 throw ERR;
00031 if(!nbody->SetupKernel("data/kernels/NBody.cl","nbody_sim"))
00032 throw ERR;
00033
00034
00035 s->CreateRenderTarget(-1,-1,GL_RGBA,GL_UNSIGNED_BYTE);
00036 s->UseHDR();
00037
00038
00039 s->MoveCamera(0.0,0.0,-150.0);
00040 s->RotateCamera(15.0, A_X);
00041
00042 s->AddMaterial("mat",black,white,black,0.0,0.0,0.0,NONE);
00043 s->AddMaterial("mat2",black,TVector(1.0f,0.8f,0.6f),black,0.0,0.0,0.0,NONE);
00044
00045
00046 s->AddObject("space",SPHERE,500.0,0.0,8,8);
00047 s->AddMaterial("mat_space",white,white,white,0.0,0.0,0.0,NONE);
00048 s->AddTexture("mat_space","data/tex/stars.tga",BASE,MODULATE,1.0,6.0,4.0);
00049 s->SetMaterial("space","mat_space");
00050
00051
00052
00053 s->AddObject("1_star0",SPHERE,0.3f,0.0f,4,4);
00054 s->SetMaterial("1_star0","mat");
00055 for(int i=0; i<BODIES/2; i++)
00056 {
00057 string name = "1_star" + num2str(i + 1);
00058 s->AddObjectInstance("1_star0",name.c_str());
00059 }
00060
00061 s->AddObject("2_star0",SPHERE,0.6f,0.0f,4,4);
00062 s->SetMaterial("2_star0","mat2");
00063 for(int i=0; i<BODIES/2; i++)
00064 {
00065 string name = "2_star" + num2str(i + 1);
00066 s->AddObjectInstance("2_star0",name.c_str());
00067 }
00068
00069
00070 s->SetUniform("mat_bloom_hdr","THRESHOLD",0.2);
00071 s->SetUniform("mat_tonemap","exposure",1.5);
00072 s->SetUniform("mat_tonemap","bloomFactor",1.0);
00073 s->SetUniform("mat_tonemap","brightMax",1.0);
00074
00075
00076 s->SetUniform("mat_blur_horiz","kernel_size",15);
00077 s->SetUniform("mat_blur_horiz","blur_radius",0.003);
00078 s->SetUniform("mat_blur_vert","kernel_size",15);
00079 s->SetUniform("mat_blur_vert","blur_radius",0.003);
00080 }
00081 catch(int err)
00082 {
00083 stopbit = true;
00084 throw ERR;
00085 return;
00086 }
00087 }
00088
00089 if(!s->PostInit())
00090 stopbit = true;
00091 InitTime();
00092 }
00093
00094
00095
00096 TestCompute::~TestCompute()
00097 {
00098 s->Destroy();
00099 }
00100
00101
00102
00103 void TestCompute::Run()
00104 {
00105 Test::Run();
00106 if(!draw_scene)
00107 return;
00108
00110
00111 if(type == COMPUTE_NBODY)
00112 {
00113
00114 nbody->Run();
00115
00116 body = 0;
00117 for(int i=0; i<halfbody; i++)
00118 {
00119 sprintf(objname,"1_star%d",i);
00120 s->MoveObjAbs(objname,nbody->GetPos(body*4 + 0), nbody->GetPos(body*4 + 1), nbody->GetPos(body*4 + 2));
00121 body++;
00122 }
00123 for(int i=0; i<halfbody; i++)
00124 {
00125 sprintf(objname,"2_star%d",i);
00126 s->MoveObjAbs(objname,nbody->GetPos(body*4 + 0), nbody->GetPos(body*4 + 1), nbody->GetPos(body*4 + 2));
00127 body++;
00128 }
00129
00130 s->RotateCameraAbs(anim*5.0f, A_Y);
00131 s->Redraw();
00132 msg = "Perf: " + num2str(nbody->GetFLOPS()) + " GFLOPS";
00133 s->DrawScreenText(msg.c_str(),90.0,1.0);
00134 }
00135 }
00136
00137
00138
00139 void TestCompute::Animate()
00140 {
00141 Test::Animate();
00142 }
00143
00144
00145
00146 void TestCompute::SaveResults()
00147 {
00148 Test::SaveResults();
00149
00150
00151
00152
00153 test_score += nbody->GetTotalFLOPS()/total_frames * 15;
00154 cout<<"SCORE: "<<test_score<<endl;
00155 results<<"<compute>"
00156 "<"<<testname<<">\n"
00157 "<fps>"<<avg_fps<<"</fps>\n"
00158 "<GFLOPS>"<<nbody->GetTotalFLOPS()/total_frames<<"</GFLOPS>\n"
00159 "<score>"<<test_score<<"</score>"
00160 "</"<<testname<<">\n"
00161 "</compute>\n";
00162 }
00163 #endif
00164