Mercurial > hg > Game > Cerium
changeset 1326:64b54c99d895 draft
merge
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 20 Dec 2011 18:10:08 +0900 |
parents | d4f83f5d2d32 (current diff) 68373985b251 (diff) |
children | 0f41ff4ca2ab 035e8c39508c |
files | Renderer/Engine/SceneGraphRoot.cc |
diffstat | 8 files changed, 329 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc Tue Dec 20 01:34:59 2011 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Tue Dec 20 18:10:08 2011 +0900 @@ -1,4 +1,3 @@ - #include <SDL_image.h> #include <libxml/parser.h> #include "SceneGraphRoot.h" @@ -278,8 +277,11 @@ typedef struct source { char *id; + union { + float *array; + char *alias; + }u; int count; - float *array; struct source *next; } SOURCE; typedef SOURCE *SOURCE_P; @@ -290,6 +292,7 @@ } LIST; typedef LIST *LIST_P; +/* add source list */ static void addSource(LIST_P list, SOURCE_P src) { if (list->first == NULL && list->end == NULL) { @@ -300,13 +303,176 @@ list->end = src; } +/* compare a with b. Using to compare id */ +static int +strcmp_a(const char *a, const char *b) +{ + while (*a && *a++ == *b++); + if (*a) return 0; + return a[-1] > b[-1] ? 1:-1; +} + +static float +get_point(char *id, int position, LIST_P list) +{ + SOURCE_P cur = list->first; + for (;cur ; cur=cur->next) { + if (!strcmp_a(id, cur->id)) { + if (cur->count == 0) //alias + return get_point(cur->u.alias, position, list); + float *a = cur->u.array; + if (position <= cur->count) { + return a[position]; + } + } + } +} + +/** + * co + */ +static SOURCE_P +most_match(const char *id , LIST_P list) +{ + SOURCE_P src,cur; + int tmplength; + int strlength; + for (cur=list->first ;cur!=list->end ;cur=cur->next) { + for (strlength=0;id[strlength+1]==cur->id[strlength];strlength++); + if (tmplength < strlength) { + tmplength = strlength; + src = cur; + } + } + return src; +} + +struct collada_state { + int polylist; + + const char *polylist_normal; + const char *polylist_vertex; + + xmlChar *pid; + + char *vertex_src; + int vertex_offset; + int vertex_count; + + char *normal_src; + int normal_offset; + int normal_count; + + float *vcount; + float *pcount; + + SOURCE_P normal_float; + SOURCE_P vertex_float; + + char *vertices_src; + int polylist_count; + + +}; + static void -xml_walk( SceneGraphRoot* self, xmlNodePtr cur, LIST_P list) +xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list) { - /*get float array.*/ + int in_polylist=0; + printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); - if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { + printf("s->polylist = %d\n",s->polylist); + + if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { + + s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); + + s->polylist=1; + in_polylist=1; + + } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) { + + s->pid = xmlGetProp(cur, (xmlChar*)"id"); + + } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { + + char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); + if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) { + s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + } + + } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { + char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); + + if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) { + s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); + + s->vertex_float = most_match(s->vertices_src, list); + + } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) { + + s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); + s->normal_float = most_match(s->normal_src, list); + } + + } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) { + char *vcont = (char*)xmlNodeGetContent(cur); + + s->vcount = (float*)malloc(sizeof(float)*s->polylist_count); + + for (int i=0; vcont!=NULL; i++) { + /* store vcount list */ + vcont = pickup_float(vcont, s->vcount+i); + } + + } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { + + /* only case is nothing input of source="TEXCOORD" */ + + char *pcont = (char*)xmlNodeGetContent(cur); + + s->pcount = (float*)malloc(sizeof(float)*(int)s->polylist_count); + + for (int i=0; pcont != NULL; i++) { + pcont = pickup_float(pcont, s->pcount+i); + } + + int vertexp[s->vertex_count]; + + float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ; + float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ; + + /* p separate vertex position and nomal position. */ + for (int i = 0; i < s->polylist_count; i++) { + vertexp[i] = s->pcount[2*i]; + normal_table[i] = s->normal_float->u.array[(int)s->pcount[2*i+1]]; + } + + for (int i=0; vertexp[i];i++) { + if (s->vcount[i] == 4) { + for (int j=0; j > s->vcount[i]; j++) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + vertex_table[i+3] = s->vertex_float->u.array[vertexp[i+1]]; + i += 2; + } + } + if (s->vcount[i]==3) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + } + } + for (int i=0; vertex_table; i++) { + printf("normal_table= %f\n", normal_table[i]); + printf("vertex_table= %f\n", vertex_table[i]); + } + + /* got out of polylist */ + s->polylist = 0; + in_polylist = 0; + + } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); @@ -315,33 +481,25 @@ int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); - src->array = (float*)malloc(sizeof(float) * src->count); + src->u.array = (float*)malloc(sizeof(float) * src->count); char *cont =(char*)xmlNodeGetContent(cur); //const char *id = get_property("id", cur); //int count = atoi(get_property("count", cur)); + /* store float inpoint list */ for (int i = 0; cont != NULL; i++) { - - //cont = pickup_float(cont, src->array+1); - // ここ+1じゃなくて、+iじゃない? - cont = pickup_float(cont, src->array+i); + cont = pickup_float(cont, src->u.array+i); } - src->next = NULL; addSource(list, src); printf("id:%s count:%d cont:%s\n", id, count, cont); - if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { - char *p = (char*)xmlNodeGetContent(cur); - printf("p:%s", p); - } - } - + for (cur=cur->children; cur; cur=cur->next){ - xml_walk(self, cur, list); + xml_walk(self, cur, s, list); } } @@ -363,38 +521,21 @@ doc = xmlParseFile(xmlColladafile); cur = xmlDocGetRootElement(doc); - /*エラー処理……だけど何書けばいいのか謎。とりあえず-1返してみる*/ if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ return ; - }; + } /* node analyze */ + struct collada_state s; + s.polylist=0; + for(cur=cur->children; cur; cur=cur->next){ LIST list; init_list(&list); - xml_walk(this, cur, &list); - /* if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){ - cur_images = cur; - continue; - } - if(xmlStrcmp(cur->name,(xmlChar*)"library_effects") != 0){ - cur_effects = cur; - continue; - } - if(xmlStrcmp(cur->name,(xmlChar*)"library_geometries") != 0){ - cur_geometries = cur; - continue; - } - if(xmlStrcmp(cur->name,(xmlChar*)"library_visual_scenes")!=0){ - cur_visual_scenes = cur; - continue; - }*/ - - //tmp = new SceneGraph(manager, cur); - //registSceneGraph(tmp); - } + xml_walk(this, cur,&s, &list); + } xmlFreeDoc(doc); }
--- a/TaskManager/Fifo/FifoDmaManager.cc Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/Fifo/FifoDmaManager.cc Tue Dec 20 18:10:08 2011 +0900 @@ -4,13 +4,23 @@ #include "FifoDmaManager.h" #include "Scheduler.h" #include "TaskManagerImpl.h" +#include "rdtsc.h" void * FifoDmaManager::dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask) { if (size == 0) return buf; + + //unsigned long long wait = 0; + //(this->*start_dmawait_profile)(); + if (s) buf = s->manager->allocate(size); memcpy(buf, (void*)addr, size); + + //(this->*end_dmawait_profile)(&wait); + //global_load_time += wait; + //dma_load_time += wait; + return buf; } @@ -25,7 +35,16 @@ FifoDmaManager::dma_store(void *buf, memaddr addr, uint32 size, uint32 mask) { if (size == 0) return buf; + + //unsigned long long wait = 0; + //(this->*start_dmawait_profile)(); + memcpy((void*)addr, buf, size); + + //(this->*end_dmawait_profile)(&wait); + //global_store_time += wait; + //dma_store_time += wait; + return buf; } @@ -41,6 +60,9 @@ void * FifoDmaManager::dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask) { + //unsigned long long wait = 0; + //(this->*start_dmawait_profile)(); + int list_size = list->length; long bound; @@ -52,6 +74,11 @@ memcpy((void*)bound, (void*)elm->addr, elm->size); bound += elm->size; } + + //(this->*end_dmawait_profile)(&wait); + //global_load_time += wait; + //dma_loadList_time += wait; + return buff; } @@ -66,6 +93,9 @@ void FifoDmaManager::dma_storeList(ListDataPtr list, void *buff, uint32 mask) { + //unsigned long long wait = 0; + //(this->*start_dmawait_profile)(); + int list_size = list->length; memaddr bound; @@ -76,6 +106,78 @@ memcpy((void*)elm->addr, (void*)bound, elm->size); bound += elm->size; } + + //(this->*end_dmawait_profile)(&wait); + //global_store_time += wait; + //dma_storeList_time += wait; +} + +void +FifoDmaManager::start_profile() +{ + global_busy_time = 0; + global_load_time = 0; + global_store_time = 0; + dma_load_time = 0; + dma_store_time = 0; + dma_loadList_time = 0; + dma_storeList_time = 0; + + start_dmawait_profile = &FifoDmaManager::do_start_dmawait_profile; + end_dmawait_profile = &FifoDmaManager::do_end_dmawait_profile; + + stop_time = rdtsc(); +} + +void +FifoDmaManager::stop_profile() +{ + start_time = rdtsc(); + global_busy_time = stop_time - start_time; + + start_dmawait_profile = &FifoDmaManager::null_start_dmawait_profile; + end_dmawait_profile = &FifoDmaManager::null_end_dmawait_profile; +} + +void +FifoDmaManager::do_start_dmawait_profile() +{ + start_time = rdtsc(); + global_busy_time += stop_time - start_time; +} + +void +FifoDmaManager::do_end_dmawait_profile(unsigned long long *counter) +{ + stop_time = rdtsc(); + *counter += stop_time - start_time; +} + +void FifoDmaManager::null_start_dmawait_profile() {} +void FifoDmaManager::null_end_dmawait_profile(unsigned long long *counter) {} + +void +FifoDmaManager::show_dma_wait(Scheduler *s, int cpu) +{ + unsigned long long all_time = global_busy_time + global_load_time + global_store_time; + + double busy = ((double)global_busy_time)/((double)all_time)*100.0; + double load = ((double)global_load_time)/((double)all_time)*100.0; + double store = ((double)global_store_time)/((double)all_time)*100.0; + + + s->printf("cpu%d:\n busy_time = %.3g%%" + " load_time = %.3g%%, " + " store_time = %.3g%% " + ,cpu, busy, load, store); + + global_busy_time = 0; + global_load_time = 0; + global_store_time = 0; + dma_load_time = 0; + dma_store_time = 0; + dma_loadList_time = 0; + dma_storeList_time = 0; } uint32 @@ -102,15 +204,4 @@ } } -void -FifoDmaManager::start_profile() -{ - -} - -void -FifoDmaManager::stop_profile() -{ - -} /* end */
--- a/TaskManager/Fifo/FifoDmaManager.h Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/Fifo/FifoDmaManager.h Tue Dec 20 18:10:08 2011 +0900 @@ -3,6 +3,7 @@ #include "base.h" #include "DmaManager.h" + #ifdef __CERIUM_PARALLEL__ #include "SynchronizedMailManager.h" #else @@ -34,12 +35,24 @@ delete mail_queue2; } + /* variables */ +protected: + unsigned long long start_time, stop_time; + unsigned long long global_busy_time, global_load_time, global_store_time; + unsigned long long dma_load_time, dma_store_time, dma_loadList_time, dma_storeList_time; + /* functions */ +public: virtual void *dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask); void *dma_store(void *buf, memaddr addr, uint32 size, uint32 mask); void dma_wait(uint32 mask) ; void *get_writebuf(Scheduler *s, memaddr addr, uint32 size) ; + void (FifoDmaManager::*start_dmawait_profile)(); + void (FifoDmaManager::*end_dmawait_profile)(unsigned long long *counter); + void start_profile(); + void stop_profile(); + void show_dma_wait(Scheduler *s, int cpu); void mail_write(memaddr data) { mail_queue1->send(data); } void mail_write_queue(memaddr data) { mail_queue1->send(data); } @@ -51,13 +64,19 @@ memaddr mail_read_from_host() { return mail_queue1->recv(); } int has_mail_from_host() { return mail_queue1->count(); } - void *dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask); + virtual void *dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask); void dma_storeList(ListDataPtr, void *buff, uint32 mask); void *get_writebuf(Scheduler *s, ListDataPtr, uint32 size) ; uint32 get_tag(); void bound(ListData *); +private: + void do_start_dmawait_profile(); + void do_end_dmawait_profile(unsigned long long *counter); + void null_start_dmawait_profile(); + void null_end_dmawait_profile(unsigned long long *counter); + }; #endif
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Tue Dec 20 18:10:08 2011 +0900 @@ -298,6 +298,21 @@ s->mail_write_from_host(alloc_info[1]); } +void FifoTaskManagerImpl::show_profile() { + for (int id = 0; id < machineNum; id++) { + HTaskPtr t = schedTaskManager->create_task(ShowTime, 0, 0, 0, 0); + t->set_cpu((CPU_TYPE) (id + 2)); + t->spawn(); + } +} + +void FifoTaskManagerImpl::start_profile() { + for (int id = 0; id < machineNum; id++) { + HTaskPtr t = schedTaskManager->create_task(StartProfile, 0, 0, 0, 0); + t->set_cpu((CPU_TYPE) (id + 2)); + t->spawn(); + } +} void FifoTaskManagerImpl::print_arch()
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Tue Dec 20 18:10:08 2011 +0900 @@ -27,8 +27,8 @@ void poll(); // called from CellTaskManagerImpl void poll1(); // single CPU run called from CellTaskManagerImpl void run(); - void show_profile() {}; - void start_profile() {}; + void show_profile(); + void start_profile(); void polling();
--- a/TaskManager/Makefile.parallel Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/Makefile.parallel Tue Dec 20 18:10:08 2011 +0900 @@ -30,4 +30,4 @@ paralleldistclean: parallelclean rm -f $(TARGET) -parallelclean: \ No newline at end of file +parallelclean:
--- a/TaskManager/kernel/ppe/CpuThreads.cc Tue Dec 20 01:34:59 2011 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.cc Tue Dec 20 18:10:08 2011 +0900 @@ -5,9 +5,10 @@ #include "SysFunc.h" #include "SchedNop.h" #include "SpeTaskManagerImpl.h" +#include "CellScheduler.h" -//SchedExternTask(ShowTime); -//SchedExternTask(StartProfile); +SchedExternTask(ShowTime); +SchedExternTask(StartProfile); CpuThreads::CpuThreads(int num, int useRefDma, int start_id) : cpu_num(num), id_offset(start_id) { @@ -57,8 +58,8 @@ manager->set_scheduler(c_scheduler); - //SchedRegister(ShowTime); - //SchedRegister(StartProfile); + SchedRegister(ShowTime); + SchedRegister(StartProfile); argt->wait->sem_v(); //準備完了したスレッドができるたびに+1していく
--- a/example/Miller_Rabin/Makefile.def Tue Dec 20 01:34:59 2011 +0900 +++ b/example/Miller_Rabin/Makefile.def Tue Dec 20 18:10:08 2011 +0900 @@ -8,8 +8,8 @@ CERIUM = ../../../Cerium CC = g++ -CFLAGS = -O9 -Wall -#CFLAGS = -g -O0 -Wall +#CFLAGS = -O9 -Wall +CFLAGS = -g -O0 -Wall #CFLAGS = -pg -Wall INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..