Mercurial > hg > Members > kono > Cerium
comparison Renderer/Engine/viewer.cc @ 986:ac437c3cf766 akira
double buffering of spanpack/polgonpack
not yet worked.
author | root@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 01 Oct 2010 03:42:25 +0900 |
parents | e40dd2384357 |
children | 0b6f8c82625a |
comparison
equal
deleted
inserted
replaced
985:e40dd2384357 | 986:ac437c3cf766 |
---|---|
18 static void post2speRendering(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); | 19 static void post2speDraw(SchedTask *s,void *viewer,void *s1); |
20 static void post2runMoveDrawLoop(SchedTask *s,void *viewer,void *s1); | 20 static void post2runMoveDrawLoop(SchedTask *s,void *viewer,void *s1); |
21 | 21 |
22 /* measure for FPS (Frame Per Second) */ | 22 /* measure for FPS (Frame Per Second) */ |
23 int start_time; | 23 static int start_time; |
24 int this_time; | 24 static int this_time; |
25 int frames; | 25 int frames; |
26 // static void post2speRunLoop(void *viewer); | 26 // static void post2speRunLoop(void *viewer); |
27 //static void post2runMove(void *viewer); | 27 //static void post2runMove(void *viewer); |
28 //static void post2exchange_sgroot(void *viewer); | 28 //static void post2exchange_sgroot(void *viewer); |
29 //static void post2speRunLoop(void *viewer); | 29 //static void post2speRunLoop(void *viewer); |
30 | 30 |
31 //SceneGraphRootPtr sgroot_2; | 31 //SceneGraphRootPtr sgroot_2; |
32 | 32 |
33 /* Data Pack sent to Other CPUs (ex. SPE) */ | 33 /* Data Pack sent to Other CPUs (ex. SPE) */ |
34 SceneGraphPack *sgpack; | 34 |
35 PolygonPack *ppack; | 35 RederingData r[2]; |
36 SpanPackPtr spackList; | 36 |
37 SpanPackPtr *spackList_ptr; | 37 int ppi, spi; |
38 | |
39 int spackList_length; | |
40 int spackList_length_align; | |
41 | |
42 | 38 |
43 /** | 39 /** |
44 * | 40 * |
45 */ | 41 */ |
46 | 42 |
115 light_xyz[i] = 0.0f; | 111 light_xyz[i] = 0.0f; |
116 } | 112 } |
117 | 113 |
118 | 114 |
119 for(int i = 0; i < spe_num; i++) { | 115 for(int i = 0; i < spe_num; i++) { |
120 | 116 HTaskPtr data_load = manager->create_task(DataAllocate); |
121 HTaskPtr data_load = manager->create_task(DataAllocate); | 117 data_load->set_param(0,(memaddr)3); // num of allocate block |
122 data_load->set_param(0,(memaddr)size); | 118 data_load->set_param(0,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size |
123 data_load->set_param(1,(memaddr)Light); | 119 data_load->set_param(1,(memaddr)Light); // 1st id |
120 data_load->set_param(0,(memaddr)(light_num * sizeof(int))); // 2nd size | |
121 data_load->set_param(1,(memaddr)LightSwitch); // 2nd id | |
122 data_load->set_param(0,(memaddr)16); // 3rd size | |
123 data_load->set_param(1,(memaddr)LightSysSwitch); // 3rd id | |
124 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | 124 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
125 data_load->spawn(); | 125 data_load->spawn(); |
126 } | 126 } |
127 | 127 |
128 size = light_num * sizeof(int); | |
129 light_switch = (int*)manager->allocate(size); | 128 light_switch = (int*)manager->allocate(size); |
130 | 129 |
131 for (int i = 0; i < light_num; i++) { | 130 for (int i = 0; i < light_num; i++) { |
132 light_switch[i] = 0; | 131 light_switch[i] = 0; |
133 } | 132 } |
134 | 133 |
135 for(int i = 0; i < spe_num; i++) { | |
136 HTaskPtr data_load = manager->create_task(DataAllocate); | |
137 data_load->set_param(0,(memaddr)size); | |
138 data_load->set_param(1,(memaddr)LightSwitch); | |
139 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
140 data_load->spawn(); | |
141 } | |
142 | |
143 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | 134 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング |
144 | 135 |
145 light_sysswitch = (int*)manager->allocate(size); | 136 light_sysswitch = (int*)manager->allocate(size); |
146 | 137 |
147 for (unsigned int i = 0; i < size / sizeof(int); i++) { | 138 for (unsigned int i = 0; i < size / sizeof(int); i++) { |
148 light_sysswitch[i] = 0; | 139 light_sysswitch[i] = 0; |
149 } | 140 } |
150 | 141 |
151 for(int i = 0; i < spe_num; i++) { | |
152 HTaskPtr data_load = manager->create_task(DataAllocate); | |
153 data_load->set_param(0,(memaddr)size); | |
154 data_load->set_param(1,(memaddr)LightSysSwitch); | |
155 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
156 data_load->spawn(); | |
157 } | |
158 | |
159 start_time = get_ticks(); | 142 start_time = get_ticks(); |
160 this_time = 0; | 143 this_time = 0; |
161 frames = 0; | 144 frames = 0; |
162 | 145 |
163 MainLoop *mainloop = app->init(this, this->width, this->height); | 146 MainLoop *mainloop = app->init(this, this->width, this->height); |
169 Viewer::initLoop() | 152 Viewer::initLoop() |
170 { | 153 { |
171 HTaskPtr task_next; | 154 HTaskPtr task_next; |
172 HTaskPtr task_tex; | 155 HTaskPtr task_tex; |
173 | 156 |
174 sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); | 157 for(int i=0;i<2;i++) { |
175 sgpack->init(); | 158 r[i].ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); |
176 ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); | 159 |
177 | 160 r[i].spackList_length = (this->height + split_screen_h - 1) / split_screen_h; |
178 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | 161 r[i].spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*r[i].spackList_length); |
179 spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); | 162 // printf("spackList %0lx height %d\n",(unsigned long)r[i].spackList, this->height); |
180 // printf("spackList %0lx height %d\n",(unsigned long)spackList, this->height); | 163 |
181 | 164 /** |
182 /** | 165 * SPU に送る address list は 16 バイト倍数でないといけない。 |
183 * SPU に送る address list は 16 バイト倍数でないといけない。 | 166 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような |
184 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような | 167 * length_align を求めている。はみ出した部分は使われない |
185 * length_align を求めている。はみ出した部分は使われない | 168 * (ex) spackList_length が 13 の場合 |
186 * (ex) spackList_length が 13 の場合 | 169 * spackList_length_align = 16; |
187 * spackList_length_align = 16; | 170 * 実際に送るデータは64バイトになるのでOK |
188 * 実際に送るデータは64バイトになるのでOK | 171 * 14,15,16 の部分は何も入らない。 |
189 * 14,15,16 の部分は何も入らない。 | 172 */ |
190 */ | 173 r[i].spackList_length_align = (r[i].spackList_length + 3)&(~3); |
191 spackList_length_align = (spackList_length + 3)&(~3); | 174 |
192 | 175 /* 各 SPU が持つ、SpanPack の address list */ |
193 /* 各 SPU が持つ、SpanPack の address list */ | 176 r[i].spackList_ptr = |
194 spackList_ptr = | 177 (SpanPack**)manager->allocate(sizeof(SpanPack*)*r[i].spackList_length_align); |
195 (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); | 178 |
196 | 179 for (int j = 0; i < r[i].spackList_length; i++) { |
197 for (int i = 0; i < spackList_length; i++) { | 180 r[i].spackList_ptr[j] = &r[i].spackList[j]; |
198 spackList_ptr[i] = &spackList[i]; | 181 } |
199 } | 182 |
200 | 183 for (int j = 1; j <= r[i].spackList_length; i++) { |
201 for (int i = 1; i <= spackList_length; i++) { | 184 r[i].spackList[j-1].init(j*split_screen_h); |
202 spackList[i-1].init(i*split_screen_h); | 185 } |
203 } | 186 } |
204 | 187 |
205 task_next = manager->create_task(Dummy,0,0,0,0); | 188 task_next = manager->create_task(Dummy,0,0,0,0); |
206 | 189 |
207 // ここは、Iterator を用意するべきだよね | 190 // ここは、Iterator を用意するべきだよね |
208 for (int i = 0; i < spe_num; i++) { | 191 for (int j = 0; j < spe_num; j++) { |
209 task_tex = manager->create_task(LoadTexture,0,0,0,0); | 192 task_tex = manager->create_task(LoadTexture,0,0,0,0); |
210 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | 193 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + j)); |
211 task_next->wait_for(task_tex); | 194 task_next->wait_for(task_tex); |
212 task_tex->spawn(); | 195 task_tex->spawn(); |
213 } | 196 } |
214 | 197 |
215 | 198 |
326 return; | 309 return; |
327 } | 310 } |
328 | 311 |
329 dev->clean_pixels(); | 312 dev->clean_pixels(); |
330 pixels = dev->flip_screen(pixels); | 313 pixels = dev->flip_screen(pixels); |
331 | |
332 for (int i = 1; i <= spackList_length; i++) { | |
333 spackList[i-1].reinit(i*split_screen_h); | |
334 } | |
335 | 314 |
336 /* ここでGameTaskの終了を待つTaskを生成しておく */ | 315 /* ここでGameTaskの終了を待つTaskを生成しておく */ |
337 sgroot->wait_game_task = manager->create_task(Dummy,0,0,0,0); | 316 sgroot->wait_game_task = manager->create_task(Dummy,0,0,0,0); |
338 sgroot->updateControllerState(); | 317 sgroot->updateControllerState(); |
339 sgroot->allExecute(width, height); | 318 sgroot->allExecute(width, height); |
709 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); | 688 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
710 HTaskPtr game_task = sgroot->wait_game_task; | 689 HTaskPtr game_task = sgroot->wait_game_task; |
711 // SceneGraph(木構造) -> PolygonPack | 690 // SceneGraph(木構造) -> PolygonPack |
712 | 691 |
713 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); | 692 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
714 task_create_pp->set_param(1,(memaddr)ppack); | 693 task_create_pp->set_param(1,(memaddr)r[ppi].ppack); |
715 /* GameTaskの終了を待ってからポリゴンを作る */ | 694 /* GameTaskの終了を待ってからポリゴンを作る */ |
716 task_create_pp->wait_for(game_task); | 695 task_create_pp->wait_for(game_task); |
717 | 696 |
718 task_next->wait_for(task_create_pp); | 697 task_next->wait_for(task_create_pp); |
719 | 698 |
720 #endif | 699 #endif |
721 | 700 |
722 int range_base = spe_num; | 701 int range_base = spe_num; |
723 | 702 |
724 // 切り上げのつもり | 703 // 切り上げのつもり |
725 int range = (spackList_length + range_base - 1) / range_base; | 704 int range = (r[spi].spackList_length + range_base - 1) / range_base; |
726 | 705 |
727 for (int i = 0; i < range_base; i++) { | 706 for (int i = 0; i < range_base; i++) { |
728 int index_start = range*i; | 707 int index_start = range*i; |
729 int index_end = (index_start + range >= spackList_length) | 708 int index_end = (index_start + range >= r[spi].spackList_length) |
730 ? spackList_length : index_start + range; | 709 ? r[spi].spackList_length : index_start + range; |
731 | 710 |
732 HTaskPtr task_create_sp = manager->create_task(CreateSpan); | 711 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
733 | 712 |
734 task_create_sp->set_param(0,index_start); | 713 task_create_sp->set_param(0,index_start); |
735 | 714 |
744 */ | 723 */ |
745 | 724 |
746 task_create_sp->set_param(1,index_start*split_screen_h + 1); | 725 task_create_sp->set_param(1,index_start*split_screen_h + 1); |
747 task_create_sp->set_param(2,index_end*split_screen_h); | 726 task_create_sp->set_param(2,index_end*split_screen_h); |
748 | 727 |
749 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); | 728 task_create_sp->add_inData(r[ppi].ppack, sizeof(PolygonPack)); |
750 task_create_sp->add_inData(spackList_ptr, | 729 task_create_sp->add_inData(r[spi].spackList_ptr, |
751 sizeof(SpanPack*)*spackList_length_align); | 730 sizeof(SpanPack*)*r[spi].spackList_length_align); |
752 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | 731 task_create_sp->add_inData(&r[spi].spackList[index_start], sizeof(SpanPack)); |
753 | 732 |
754 task_next->wait_for(task_create_sp); | 733 task_next->wait_for(task_create_sp); |
755 task_create_sp->wait_for(task_create_pp); | 734 task_create_sp->wait_for(task_create_pp); |
756 | 735 |
757 task_create_sp->set_cpu(SPE_ANY); | 736 task_create_sp->set_cpu(SPE_ANY); |
797 data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 | 776 data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 |
798 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); | 777 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); |
799 data_update_wait->spawn(); | 778 data_update_wait->spawn(); |
800 } | 779 } |
801 | 780 |
802 | 781 ppi ^= 1; |
803 ppack->clear(); | 782 r[ppi].ppack->clear(); |
804 | 783 |
805 for (int i = 0; i < spackList_length; i++) { | 784 for (int i = 0; i < r[spi].spackList_length; i++) { |
806 SpanPack *spack = &spackList[i]; | 785 SpanPack *spack = &r[spi].spackList[i]; |
807 int startx = 1; | 786 int startx = 1; |
808 int endx = split_screen_w; | 787 int endx = split_screen_w; |
809 | 788 |
810 int starty = spack->info.y_top - split_screen_h + 1; | 789 int starty = spack->info.y_top - split_screen_h + 1; |
811 //int endy = spack->info.y_top; | 790 //int endy = spack->info.y_top; |
911 } | 890 } |
912 } | 891 } |
913 #endif | 892 #endif |
914 | 893 |
915 } | 894 } |
895 spi ^= 1; | |
896 for (int i = 1; i <= r[spi].spackList_length; i++) { | |
897 r[spi].spackList[i-1].reinit(i*split_screen_h); | |
898 } | |
899 | |
916 | 900 |
917 if (profile) { | 901 if (profile) { |
918 if (frames % 50 == 49) { | 902 if (frames % 50 == 49) { |
919 manager->show_profile(); | 903 manager->show_profile(); |
920 this_time = get_ticks(); | 904 this_time = get_ticks(); |