Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/viewer.cc @ 895:bed529c55eda
add alignment of classes in SPU
width and height are automatically set in frame buffer API
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 17:23:49 +0900 |
parents | dd0801f355a2 |
children | 586b4f825f24 |
rev | line source |
---|---|
507 | 1 #include <SDL.h> |
2 #include "viewer.h" | |
3 #include "viewer_types.h" | |
4 #include "SceneGraph.h" | |
5 #include "SceneGraphRoot.h" | |
6 #include "scene_graph_pack.h" | |
7 #include "sys.h" | |
8 #include "Func.h" | |
9 #include "error.h" | |
10 #include "TaskManager.h" | |
11 #include <wchar.h> | |
12 #include "Pad.h" | |
511 | 13 #include "Application.h" |
575
0f13810d4492
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
14 #include "lindaapi.h" |
507 | 15 |
523 | 16 static void post2runLoop(SchedTask *s,void *viewer,void *s1); |
17 static void post2runDraw(SchedTask *s,void *viewer,void *s1); | |
18 static void post2speRendering(SchedTask *s,void *viewer,void *s1); | |
19 static void post2speDraw(SchedTask *s,void *viewer,void *s1); | |
20 static void post2runMoveDrawLoop(SchedTask *s,void *viewer,void *s1); | |
507 | 21 |
22 /* measure for FPS (Frame Per Second) */ | |
23 int start_time; | |
24 int this_time; | |
25 int frames; | |
514 | 26 // static void post2speRunLoop(void *viewer); |
27 //static void post2runMove(void *viewer); | |
28 //static void post2exchange_sgroot(void *viewer); | |
29 //static void post2speRunLoop(void *viewer); | |
507 | 30 |
31 //SceneGraphRootPtr sgroot_2; | |
32 | |
33 /* Data Pack sent to Other CPUs (ex. SPE) */ | |
34 SceneGraphPack *sgpack; | |
35 PolygonPack *ppack; | |
36 SpanPackPtr spackList; | |
37 SpanPackPtr *spackList_ptr; | |
38 | |
39 int spackList_length; | |
40 int spackList_length_align; | |
41 | |
42 /** | |
43 * | |
44 */ | |
45 | |
748 | 46 Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) |
507 | 47 { |
48 spe_num = _num; | |
748 | 49 manager = m; |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
50 |
748 | 51 dev = vd; |
52 pixels = dev->video_init(manager, b, w, h); | |
53 | |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
54 width = dev->width; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
55 height = dev->height; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
56 bpp = dev->bpp; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
57 |
507 | 58 } |
59 | |
60 int | |
61 Viewer::get_ticks(void) | |
62 { | |
63 int time; | |
64 time = SDL_GetTicks(); | |
65 return time; | |
66 } | |
67 | |
68 bool | |
69 Viewer::quit_check(void) | |
70 { | |
71 SDL_Event event; | |
72 | |
73 while(SDL_PollEvent(&event)) { | |
74 if (event.type==SDL_QUIT) { | |
75 return true; | |
76 } | |
77 } | |
78 | |
79 Uint8 *keys=SDL_GetKeyState(NULL); | |
80 | |
81 if (keys[SDLK_q] == SDL_PRESSED) { | |
82 return true; | |
83 } | |
84 | |
85 return false; | |
86 } | |
87 | |
88 void | |
89 Viewer::quit(void) | |
90 { | |
91 SDL_Quit(); | |
92 } | |
93 | |
94 | |
95 void | |
509
8148c81d2660
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
96 Viewer::run_init(TaskManager *manager, Application *app) |
507 | 97 { |
98 this->manager = manager; | |
99 | |
100 start_time = get_ticks(); | |
101 this_time = 0; | |
102 frames = 0; | |
103 | |
748 | 104 if (spe_num == 0) spe_num = 1; |
105 | |
507 | 106 sgroot = new SceneGraphRoot(this->width, this->height); |
572 | 107 sgroot->tmanager = manager; |
792 | 108 |
109 | |
110 int light_num = 4; | |
111 int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) | |
762 | 112 int light_size = size / sizeof(float); |
748 | 113 |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
748
diff
changeset
|
114 light_xyz_stock = (float *)manager->allocate(size); |
748 | 115 light_xyz = (float *)manager->allocate(size); |
762 | 116 |
117 for (int i = 0; i < light_size ; i++) { | |
118 light_xyz[i] = 0.0f; | |
119 } | |
748 | 120 |
792 | 121 for(int i = 0; i < spe_num; i++) { |
826 | 122 |
792 | 123 HTaskPtr data_load = manager->create_task(DataLoad); |
748 | 124 data_load->set_param(0,(memaddr)size); |
125 data_load->set_param(1,(memaddr)Light); | |
126 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
127 data_load->spawn(); | |
128 } | |
509
8148c81d2660
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
129 |
792 | 130 size = light_num * sizeof(int); |
131 light_switch = (int*)manager->allocate(size); | |
793 | 132 |
792 | 133 for (int i = 0; i < light_num; i++) { |
134 light_switch[i] = 0; | |
135 } | |
136 | |
137 for(int i = 0; i < spe_num; i++) { | |
138 HTaskPtr data_load = manager->create_task(DataLoad); | |
139 data_load->set_param(0,(memaddr)size); | |
140 data_load->set_param(1,(memaddr)LightSwitch); | |
141 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
142 data_load->spawn(); | |
143 } | |
144 | |
145 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
146 | |
793 | 147 light_sysswitch = (int*)manager->allocate(size); |
148 | |
843
0c7d885f0c92
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
842
diff
changeset
|
149 for (unsigned int i = 0; i < size / sizeof(int); i++) { |
793 | 150 light_sysswitch[i] = 0; |
151 } | |
152 | |
792 | 153 for(int i = 0; i < spe_num; i++) { |
154 HTaskPtr data_load = manager->create_task(DataLoad); | |
155 data_load->set_param(0,(memaddr)size); | |
156 data_load->set_param(1,(memaddr)LightSysSwitch); | |
157 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
158 data_load->spawn(); | |
159 } | |
160 | |
511 | 161 MainLoop *mainloop = app->init(this, this->width, this->height); |
162 mainloop->mainLoop(); | |
507 | 163 } |
164 | |
165 | |
166 HTaskPtr | |
167 Viewer::initLoop() | |
168 { | |
169 HTaskPtr task_next; | |
170 HTaskPtr task_tex; | |
171 | |
172 sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); | |
173 sgpack->init(); | |
174 ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); | |
175 | |
176 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | |
177 spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); | |
178 | |
179 /** | |
180 * SPU に送る address list は 16 バイト倍数でないといけない。 | |
181 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような | |
182 * length_align を求めている。はみ出した部分は使われない | |
183 * (ex) spackList_length が 13 の場合 | |
184 * spackList_length_align = 16; | |
185 * 実際に送るデータは64バイトになるのでOK | |
186 * 14,15,16 の部分は何も入らない。 | |
187 */ | |
188 spackList_length_align = (spackList_length + 3)&(~3); | |
189 | |
190 /* 各 SPU が持つ、SpanPack の address list */ | |
191 spackList_ptr = | |
192 (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); | |
193 | |
194 for (int i = 0; i < spackList_length; i++) { | |
195 spackList_ptr[i] = &spackList[i]; | |
196 } | |
197 | |
198 for (int i = 1; i <= spackList_length; i++) { | |
199 spackList[i-1].init(i*split_screen_h); | |
200 } | |
201 | |
826 | 202 task_next = manager->create_task(Dummy,0,0,0,0); |
507 | 203 |
652 | 204 // ここは、Iterator を用意するべきだよね |
507 | 205 for (int i = 0; i < spe_num; i++) { |
826 | 206 task_tex = manager->create_task(LoadTexture,0,0,0,0); |
207 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
208 task_next->wait_for(task_tex); | |
748 | 209 task_tex->spawn(); |
507 | 210 } |
211 | |
792 | 212 |
507 | 213 return task_next; |
214 } | |
215 | |
216 | |
217 void | |
218 Viewer::getKey() | |
219 { | |
220 Pad *pad = sgroot->getController(); | |
221 if (pad->right.isHold()) { | |
222 keyPtr->right = HOLD; | |
223 } else if (pad->right.isPush()) { | |
224 keyPtr->right = PUSH; | |
225 } else { | |
226 keyPtr->right = NONE; | |
227 } | |
228 | |
229 if (pad->left.isHold()) { | |
230 keyPtr->left = HOLD; | |
231 } else if (pad->left.isPush()) { | |
232 keyPtr->left = PUSH; | |
233 } else { | |
234 keyPtr->left = NONE; | |
235 } | |
236 | |
237 if (pad->up.isHold()) { | |
238 keyPtr->up = HOLD; | |
239 } else if (pad->up.isPush()) { | |
240 keyPtr->up = PUSH; | |
241 } else { | |
242 keyPtr->up = NONE; | |
243 } | |
244 | |
245 if (pad->down.isHold()) { | |
246 keyPtr->down = HOLD; | |
247 } else if (pad->down.isPush()) { | |
248 keyPtr->down = PUSH; | |
249 } else { | |
250 keyPtr->down = NONE; | |
251 } | |
252 | |
253 if (pad->circle.isHold()) { | |
254 keyPtr->circle = HOLD; | |
255 } else if (pad->circle.isPush()) { | |
256 keyPtr->circle = PUSH; | |
257 } else { | |
258 keyPtr->circle = NONE; | |
259 } | |
260 } | |
261 | |
262 static void | |
514 | 263 post2runMoveDrawLoop(SchedTask *m, void *viewer_, void *arg) |
507 | 264 { |
265 Viewer *viewer = (Viewer*)viewer_; | |
266 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
267 // 同じ PPE 上なので sgroot(ポインタ) を set_param で送る。 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
268 //HTaskPtr send_key_task = viewer->manager->create_task(SendKey); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
269 //send_key_task->set_param((int)sgroot); |
507 | 270 // set input data -> viewer keyPtr |
271 viewer->getKey(); | |
826 | 272 //HTaskPtr update_key = viewer->manager->create_task(UpdateKey,viewer->keyPtr, sizeof(key_stat),0,0); |
273 HTaskPtr update_key = viewer->manager->create_task(UpdateKey,0,0,0,0); | |
507 | 274 update_key->add_inData(viewer->keyPtr, sizeof(key_stat)); |
748 | 275 //update_key->set_cpu(SPE_0); |
507 | 276 update_key->spawn(); |
277 | |
278 /* TASK_MOVE は外から引数で取ってくるべき */ | |
279 //HTaskPtr move_task = viewer->manager->create_task(viewer->app->move_taskid); | |
826 | 280 HTaskPtr move_task = viewer->manager->create_task(Move,0,0,0,0); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
281 //move_task->set_param(sgroot); |
507 | 282 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
283 //HTaskPtr draw_task = viewer->manager->create_task(Draw); |
507 | 284 |
285 /* rendering task test */ | |
826 | 286 HTaskPtr draw_task = viewer->manager->create_task(Dummy,0,0,0,0); |
287 HTaskPtr draw_dummy = viewer->manager->create_task(Dummy,0,0,0,0); | |
507 | 288 |
826 | 289 HTaskPtr switch_task = viewer->manager->create_task(Switch,0,0,0,0); |
507 | 290 viewer->draw_dummy = draw_dummy; |
291 switch_task->wait_for(draw_dummy); | |
514 | 292 draw_task->set_post(post2speRendering, (void*)viewer, 0); |
507 | 293 |
294 switch_task->wait_for(move_task); | |
295 switch_task->wait_for(draw_task); | |
296 move_task->spawn(); | |
297 draw_task->spawn(); | |
298 | |
514 | 299 switch_task->set_post(post2runMoveDrawLoop, (void*)viewer, 0); |
507 | 300 switch_task->spawn(); |
301 | |
302 } | |
303 | |
304 void | |
305 Viewer::mainLoop() | |
306 { | |
307 HTaskPtr task_next = initLoop(); | |
308 | |
514 | 309 task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL) |
507 | 310 task_next->spawn(); |
311 } | |
312 | |
313 void | |
748 | 314 Viewer::run_loop(HTaskPtr task_next) |
507 | 315 { |
748 | 316 dev->clear_screen(); |
317 | |
318 bool quit_flg; | |
319 quit_flg = quit_check(); | |
320 if (quit_flg == true) { | |
321 this_time = get_ticks(); | |
322 run_finish(); | |
323 return; | |
324 } | |
325 | |
326 dev->clean_pixels(); | |
327 | |
328 for (int i = 1; i <= spackList_length; i++) { | |
329 spackList[i-1].reinit(i*split_screen_h); | |
330 } | |
331 | |
332 sgroot->updateControllerState(); | |
333 sgroot->allExecute(width, height); | |
334 light_xyz_stock = sgroot->getLightVector(); | |
792 | 335 light_switch_stock = sgroot->getLightSwitch(); |
793 | 336 light_sysswitch_stock = sgroot->getLightSysSwitch(); |
748 | 337 //sgroot->checkRemove(); |
338 | |
339 // ここから下は Rendering という関数にする | |
340 rendering(task_next); | |
507 | 341 } |
342 | |
343 | |
344 | |
345 void | |
346 Viewer::run_collision() | |
347 { | |
348 } | |
349 | |
350 void | |
514 | 351 post2rendering(SchedTask *s, void *viewer_, void *arg) |
507 | 352 { |
353 Viewer *viewer = (Viewer *)viewer_; | |
826 | 354 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 355 viewer->rendering(task_next); |
356 } | |
357 | |
358 void | |
359 Viewer::rendering(HTaskPtr task_next) | |
360 { | |
748 | 361 common_rendering(task_next, sgroot); |
507 | 362 |
363 // Barrier 同期 | |
364 // run_draw() を呼ぶ post2runDraw | |
514 | 365 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) |
507 | 366 task_next->spawn(); |
367 | |
368 // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ | |
369 } | |
370 | |
371 static void | |
514 | 372 post2runLoop(SchedTask *s, void *viewer_, void *arg) |
507 | 373 { |
374 Viewer *viewer = (Viewer*)viewer_; | |
826 | 375 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 376 viewer->run_loop(task_next); |
575
0f13810d4492
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
377 psx_sync_n(); |
507 | 378 } |
379 | |
380 static void | |
514 | 381 post2runDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 382 { |
383 Viewer *viewer = (Viewer*)viewer_; | |
826 | 384 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 385 viewer->run_draw(task_next); |
386 | |
387 } | |
388 | |
389 void | |
390 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする | |
391 { | |
392 common_draw(task_next); | |
393 | |
514 | 394 task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL) |
507 | 395 task_next->spawn(); |
396 // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ | |
397 | |
398 frames++; | |
399 } | |
400 | |
401 | |
402 static void | |
514 | 403 post2speRendering(SchedTask *s, void *viewer_, void *arg) |
507 | 404 { |
405 Viewer *viewer = (Viewer*)viewer_; | |
826 | 406 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 407 viewer->spe_rendering(task_next); |
408 } | |
409 | |
410 void | |
411 Viewer::spe_rendering(HTaskPtr task_next) | |
412 { | |
748 | 413 common_rendering(task_next, sgroot); |
507 | 414 |
415 this->draw_dummy->wait_for(task_next); | |
514 | 416 task_next->set_post(post2speDraw, (void*)this, 0); |
507 | 417 task_next->spawn(); |
418 | |
419 } | |
420 | |
421 static void | |
514 | 422 post2speDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 423 { |
424 Viewer *viewer = (Viewer*)viewer_; | |
826 | 425 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 426 viewer->spe_draw(task_next); |
427 } | |
428 | |
429 void | |
430 Viewer::spe_draw(HTaskPtr task_next) | |
431 { | |
432 common_draw(task_next); | |
433 | |
434 this->draw_dummy->wait_for(task_next); | |
435 task_next->spawn(); | |
436 this->draw_dummy->spawn(); | |
437 | |
438 frames++; | |
439 } | |
440 | |
861 | 441 #if SPE_CREATE_POLYGON |
442 | |
507 | 443 void |
860 | 444 Viewer::create_pp_task(SceneGraphPtr sg, PolygonPackPtr pp_cur, HTaskPtr create_pp_wait, |
445 int &pp_index, int &sg_index, int tri_num) | |
446 { | |
447 | |
448 HTaskPtr create_pp = manager->create_task(CreatePolygon); | |
449 create_pp->set_inData(0, &sg->tri_pack[sg_index], sizeof(TrianglePack)*tri_num); | |
450 create_pp->set_inData(1, sg->texture_info, sizeof(texture_list)); | |
451 create_pp->set_inData(2, sg->sg_matrix, sizeof(float)*32); //わーい、マジックナンバー | |
452 create_pp->set_outData(0, &pp_cur->tri[pp_index], sizeof(TrianglePack)*tri_num); | |
453 create_pp->set_param(0, (memaddr)tri_num); | |
454 //create_pp->set_cpu(SPE_ANY); | |
455 create_pp_wait->wait_for(create_pp); | |
456 create_pp->spawn(); | |
457 | |
458 pp_index += tri_num; | |
459 sg_index += tri_num; | |
460 } | |
461 | |
861 | 462 #endif |
860 | 463 |
464 void | |
748 | 465 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
507 | 466 { |
860 | 467 |
468 #if SPE_CREATE_POLYGON | |
469 | |
470 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); | |
471 PolygonPackPtr pp_cur = ppack; | |
472 HTaskPtr create_pp_wait = manager->create_task(Dummy); | |
473 int pp_index = 0; | |
474 | |
891 | 475 pp_cur->init(); |
476 | |
885 | 477 task_next->wait_for(create_pp_wait); |
478 | |
860 | 479 while (sg) { |
480 | |
481 if (sg->flag_drawable) { | |
482 | |
483 int sum_size = sg->size; | |
484 int tri_cur_num = MAX_SIZE_TRIANGLE; | |
485 int sg_index = 0; | |
486 | |
487 while (sum_size) { | |
488 | |
489 tri_cur_num -= sg->size/3; | |
490 | |
491 if (tri_cur_num < 0) { | |
492 | |
493 tri_cur_num = MAX_SIZE_TRIANGLE; | |
494 create_pp_task(sg, pp_cur, create_pp_wait, | |
495 pp_index, sg_index, tri_cur_num); | |
496 | |
497 PolygonPackPtr next = (PolygonPackPtr)manager->allocate(sizeof(PolygonPack)); | |
891 | 498 next->init(); |
499 | |
860 | 500 pp_cur->next = next; |
501 pp_cur = next; | |
502 pp_index = 0; | |
503 | |
504 } else { | |
505 | |
506 create_pp_task(sg, pp_cur, create_pp_wait, | |
507 pp_index, sg_index, tri_cur_num); | |
508 | |
509 } | |
510 | |
511 sum_size -= tri_cur_num*3; | |
512 | |
513 } | |
514 | |
515 | |
516 } | |
517 | |
518 | |
519 | |
520 if (sg->children != NULL) { | |
521 sg = sg->children; | |
522 } else if (sg->brother != NULL) { | |
523 sg = sg->brother; | |
524 } else { | |
525 while (sg) { | |
526 if (sg->brother != NULL) { | |
527 sg = sg->brother; | |
528 break; | |
529 } else { | |
530 if (sg->parent == NULL) { | |
531 sg = NULL; | |
532 break; | |
533 } else { | |
534 sg = sg->parent; | |
535 } | |
536 } | |
537 } | |
538 } | |
539 } | |
885 | 540 |
541 | |
542 int range_base = spe_num; | |
543 | |
544 // 切り上げのつもり | |
545 int range = (spackList_length + range_base - 1) / range_base; | |
546 | |
547 for (int i = 0; i < range_base; i++) { | |
548 int index_start = range*i; | |
549 int index_end = (index_start + range >= spackList_length) | |
550 ? spackList_length : index_start + range; | |
860 | 551 |
885 | 552 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
553 | |
554 task_create_sp->set_param(0,index_start); | |
555 | |
556 /** | |
557 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
558 * [ 1.. 80] [ 81..160] [161..240] | |
559 * [241..320] [321..400] [401..480] | |
560 * | |
561 * ex. screen_height が 1080, spenum が 5 の場合、 | |
562 * [ 1..216] [217..432] [433..648] | |
563 * [649..864] [865..1080] | |
564 */ | |
565 | |
566 task_create_sp->set_param(1,index_start*split_screen_h + 1); | |
567 task_create_sp->set_param(2,index_end*split_screen_h); | |
568 | |
569 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); | |
570 task_create_sp->add_inData(spackList_ptr, | |
571 sizeof(SpanPack*)*spackList_length_align); | |
572 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
573 | |
574 task_next->wait_for(task_create_sp); | |
575 task_create_sp->wait_for(create_pp_wait); | |
576 | |
577 task_create_sp->set_cpu(SPE_ANY); | |
578 task_create_sp->spawn(); | |
579 } | |
580 | |
860 | 581 #else |
582 | |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
583 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
507 | 584 |
585 // SceneGraph(木構造) -> PolygonPack | |
586 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
587 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
588 task_create_pp->set_param(1,(memaddr)ppack); |
507 | 589 |
590 task_next->wait_for(task_create_pp); | |
748 | 591 |
592 int range_base = spe_num; | |
593 | |
507 | 594 // 切り上げのつもり |
595 int range = (spackList_length + range_base - 1) / range_base; | |
596 | |
597 for (int i = 0; i < range_base; i++) { | |
598 int index_start = range*i; | |
599 int index_end = (index_start + range >= spackList_length) | |
600 ? spackList_length : index_start + range; | |
601 | |
652 | 602 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
507 | 603 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
604 task_create_sp->set_param(0,index_start); |
748 | 605 |
507 | 606 /** |
607 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
608 * [ 1.. 80] [ 81..160] [161..240] | |
609 * [241..320] [321..400] [401..480] | |
610 * | |
611 * ex. screen_height が 1080, spenum が 5 の場合、 | |
612 * [ 1..216] [217..432] [433..648] | |
613 * [649..864] [865..1080] | |
614 */ | |
748 | 615 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
616 task_create_sp->set_param(1,index_start*split_screen_h + 1); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
617 task_create_sp->set_param(2,index_end*split_screen_h); |
507 | 618 |
652 | 619 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); |
620 task_create_sp->add_inData(spackList_ptr, | |
621 sizeof(SpanPack*)*spackList_length_align); | |
622 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
623 | |
507 | 624 task_next->wait_for(task_create_sp); |
625 task_create_sp->wait_for(task_create_pp); | |
626 | |
748 | 627 task_create_sp->set_cpu(SPE_ANY); |
507 | 628 task_create_sp->spawn(); |
629 } | |
630 | |
860 | 631 task_create_pp->spawn(); |
748 | 632 |
860 | 633 #endif |
634 | |
507 | 635 } |
636 | |
792 | 637 HTaskPtr |
638 Viewer::update_task_create(void *data, int size, | |
639 int load_id, int spe_id, HTaskPtr wait) | |
640 { | |
641 | |
642 HTaskPtr data_update = manager->create_task(DataUpdate); | |
643 data_update->add_inData(data,size); | |
644 data_update->set_param(0,size); | |
645 data_update->set_param(1,load_id); | |
646 data_update->set_cpu((CPU_TYPE)(spe_id)); | |
647 if (wait != NULL) { | |
648 wait->wait_for(data_update); | |
649 } | |
650 data_update->spawn(); | |
651 | |
652 return data_update; | |
653 | |
654 } | |
655 | |
507 | 656 void |
657 Viewer::common_draw(HTaskPtr task_next) | |
658 { | |
659 | |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
660 //task_next = manager->create_task(Dummy); |
507 | 661 //task_next->set_post(post2runLoop, (void*)this); |
662 | |
792 | 663 //Light info update |
748 | 664 |
793 | 665 //HTaskPtr data_update; |
748 | 666 HTaskPtr data_update_wait; |
792 | 667 int light_num = 4; |
668 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) | |
762 | 669 int light_size = size / sizeof(float); |
748 | 670 |
762 | 671 for (int i = 0; i < light_size; i++) { |
792 | 672 light_xyz[i] = light_xyz_stock[i]; |
762 | 673 } |
792 | 674 |
675 for (int i = 0; i < light_num; i++) { | |
676 light_switch[i] = light_switch_stock[i]; | |
677 } | |
793 | 678 |
679 light_sysswitch[0] = light_sysswitch_stock; | |
792 | 680 |
748 | 681 data_update_wait = manager->create_task(DataUpdate); |
682 data_update_wait->add_inData(light_xyz,size); | |
683 data_update_wait->set_param(0,size); | |
684 data_update_wait->set_param(1,Light); | |
685 data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0)); | |
792 | 686 |
748 | 687 for (int i = 1; i < spe_num; i++) { |
792 | 688 update_task_create(light_xyz,size,Light,(int)SPE_0+i,data_update_wait); |
689 } | |
690 | |
691 size = light_num * sizeof(int); | |
692 | |
693 for (int i = 0; i < spe_num; i++) { | |
793 | 694 update_task_create(light_switch,size,LightSwitch,(int)SPE_0+i,data_update_wait); |
792 | 695 } |
696 | |
697 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
698 | |
699 for (int i = 0; i < spe_num; i++) { | |
793 | 700 update_task_create(light_sysswitch,size,LightSysSwitch,(int)SPE_0+i,data_update_wait); |
748 | 701 } |
702 | |
507 | 703 ppack->clear(); |
704 for (int i = 0; i < spackList_length; i++) { | |
705 SpanPack *spack = &spackList[i]; | |
706 int startx = 1; | |
707 int endx = split_screen_w; | |
708 | |
709 int starty = spack->info.y_top - split_screen_h + 1; | |
710 //int endy = spack->info.y_top; | |
711 int rangey = (starty + split_screen_h - 1 > this->height) | |
712 ? this->height - starty + 1 : split_screen_h; | |
713 | |
889
b150914f5976
minor fix. Redering Engine not worked yet.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
885
diff
changeset
|
714 #if 1 |
857 | 715 |
716 if(spack->info.size > 0) { | |
838 | 717 |
857 | 718 int array_task_num = (this->width + split_screen_w - 1) / split_screen_w; |
719 HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey); | |
720 Task *task_draw = 0; | |
721 | |
722 while (startx < this->width) { | |
723 | |
839 | 724 // Draw SpanPack |
857 | 725 |
839 | 726 task_draw = task_draw_array->next_task_array(DrawSpan,task_draw); |
727 task_draw->set_param(0,(memaddr)&pixels[(startx-1) + this->width*(starty-1)]); | |
728 task_draw->set_param(1,this->width); | |
729 task_draw->set_param(2,startx); | |
730 task_draw->set_param(3,endx); | |
731 task_draw->set_param(4,rangey); | |
732 task_draw->set_param(5,spack->info.size); | |
838 | 733 |
839 | 734 task_draw->set_inData(0,spack, sizeof(SpanPack)); |
735 | |
736 for (int i = 0; i < rangey; i++) { | |
857 | 737 task_draw->set_outData(i, |
738 &pixels[(startx-1) + this->width*(starty-1 + i) ], | |
739 (endx-startx+1)*sizeof(int)); | |
839 | 740 } |
741 | |
742 startx += split_screen_w; | |
743 endx += split_screen_w; | |
744 | |
745 if (endx > this->width) { | |
746 endx = this->width; | |
747 } | |
748 | |
857 | 749 } |
750 | |
751 task_draw_array->spawn_task_array(task_draw->next()); | |
752 task_draw_array->set_cpu(SPE_ANY); | |
753 task_next->wait_for(task_draw_array); | |
754 task_draw_array->wait_for(data_update_wait); | |
755 task_draw_array->spawn(); | |
854 | 756 |
857 | 757 } else { |
758 | |
759 memset(&pixels[(startx-1)+this->width*(starty-1)], | |
760 0, (this->width)*sizeof(int)*rangey); | |
838 | 761 |
857 | 762 } |
763 | |
764 #else | |
838 | 765 |
766 HTaskPtr task_draw; | |
767 | |
507 | 768 while (startx < this->width) { |
857 | 769 if (spack->info.size > 0) { |
507 | 770 // Draw SpanPack |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
771 task_draw = manager->create_task(DrawSpan); |
507 | 772 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
773 task_draw->set_param(0, |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
774 (memaddr)&pixels[(startx-1) + this->width*(starty-1)]); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
775 task_draw->set_param(1,this->width); |
652 | 776 task_draw->set_param(2,startx); |
777 task_draw->set_param(3,endx); | |
778 task_draw->set_param(4,rangey); | |
838 | 779 task_draw->set_param(5,spack->info.size); |
652 | 780 |
781 task_draw->add_inData(spack, sizeof(SpanPack)); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
782 |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
783 for (int i = 0; i < rangey; i++) { |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
784 task_draw->add_outData( |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
785 &pixels[(startx-1) + this->width*(starty-1 + i) ], |
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
786 (endx-startx+1)*sizeof(int)); |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
787 } |
838 | 788 |
857 | 789 } else { |
507 | 790 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド |
791 // を使って、DMAでclearするべき... ということは、 | |
792 // それもSPEでやる方が良い? | |
857 | 793 memset(&pixels[(startx-1)+this->width*(starty-1)], |
794 0, (this->width)*sizeof(int)*rangey); | |
795 break; | |
796 } | |
507 | 797 |
748 | 798 task_draw->set_cpu(SPE_ANY); |
507 | 799 task_next->wait_for(task_draw); |
748 | 800 task_draw->wait_for(data_update_wait); |
507 | 801 task_draw->spawn(); |
802 | |
803 startx += split_screen_w; | |
804 endx += split_screen_w; | |
805 | |
806 if (endx > this->width) { | |
807 endx = this->width; | |
808 } | |
809 } | |
838 | 810 #endif |
811 | |
792 | 812 } |
813 | |
814 data_update_wait->spawn(); | |
748 | 815 |
816 } | |
817 | |
818 void | |
819 Viewer::run_finish() | |
820 { | |
821 dev->free_device(); | |
822 if (this_time != start_time) { | |
823 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
824 } | |
825 | |
826 delete sgroot; | |
827 // delete sgroot_2; | |
828 quit(); | |
507 | 829 } |
830 | |
831 /* end */ |