Mercurial > hg > Game > Cerium
changeset 684:ecf7e09b1fe8 draft
adding Array Task.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Dec 2009 11:33:09 +0900 |
parents | 262f28511797 (current diff) 24054155368c (diff) |
children | 8edef3e62bf6 |
files | TaskManager/ChangeLog TaskManager/Makefile.def TaskManager/kernel/ppe/HTask.h TaskManager/kernel/ppe/Task.h TaskManager/kernel/sys_task/SysTasks.h example/Bulk/main.cc |
diffstat | 20 files changed, 293 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/RenderingTasks.h Sun Dec 06 11:33:09 2009 +0900 @@ -2,6 +2,9 @@ SDL_INIT, FINISH, + DataLoad, + DataUpdate, + Create_SGP, Update_SGP, CreatePolygon,
--- a/Renderer/Engine/SceneGraphRoot.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Dec 06 11:33:09 2009 +0900 @@ -25,7 +25,7 @@ sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); camera = new Camera(w, h, this); - light = new Light(w, h); + light = new SceneGraph; iterator = new SceneGraphIterator; controller = create_controller(); @@ -36,6 +36,14 @@ sgroot = this; + //int size = 4; + //light_vector = (float*)malloc(sizeof(float)*size); + + light->xyz[0] = 0; + light->xyz[1] = 0; + light->xyz[2] = 0; + + // TODO // 今はとりあえず camera を Root にしています // 今はそれすらもしてません @@ -405,6 +413,18 @@ list = list->next; } + get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); + + light_vector[0] = 0.0f; + light_vector[1] = 0.0f; + light_vector[2] = 0.0f; + light_vector[3] = 1.0f; + + ApplyMatrix(light_vector, light->matrix); + + light_vector[0] /= light_vector[2]; + light_vector[1] /= light_vector[2]; + if(sg_exec_tree != NULL) { return; } @@ -538,10 +558,18 @@ return camera; } -LightPtr + +SceneGraphPtr SceneGraphRoot::getLight() { return light; } + + +float* +SceneGraphRoot::getLightVector() +{ + return light_vector; +}
--- a/Renderer/Engine/SceneGraphRoot.h Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.h Sun Dec 06 11:33:09 2009 +0900 @@ -4,7 +4,6 @@ #include "SceneGraph.h" #include "SceneGraphArray.h" #include "Camera.h" -#include "Light.h" #include "SceneGraphIterator.h" #include <sys/types.h> @@ -53,13 +52,15 @@ Camera *camera; // 光源のオブジェクト - Light *light; + SceneGraphPtr light; + // 光源の疑似 xml file + float light_vector[4]; // SceneGraphIterator SceneGraphIteratorPtr iterator; - // fd of Linda taple space - int tid; + // fd of Linda taple space + int tid; /** * Functions @@ -77,7 +78,8 @@ SceneGraphIteratorPtr getIterator(); SceneGraphIteratorPtr getIterator(SceneGraphPtr list); CameraPtr getCamera(); - LightPtr getLight(); + SceneGraphPtr getLight(); + float* getLightVector(); /* Other System API */ void allExecute(int screen_w, int screen_h);
--- a/Renderer/Engine/global_alloc.h Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/global_alloc.h Sun Dec 06 11:33:09 2009 +0900 @@ -12,6 +12,8 @@ GLOBAL_TEXTURE_HASH, GLOBAL_TILE_LIST, KEY_STATUS, + LOAD_ID, + }; #endif
--- a/Renderer/Engine/spe/spe-main.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/spe/spe-main.cc Sun Dec 06 11:33:09 2009 +0900 @@ -1,6 +1,9 @@ #include "../Func.h" #include "SchedTask.h" +SchedExternTask(DataLoad); +SchedExternTask(DataUpdate); + SchedExternTask(LoadTexture); SchedExternTask(SetTexture); SchedExternTask(DrawSpan); @@ -22,6 +25,10 @@ void task_init(Scheduler *s) { + + SchedRegister( DataLoad); + SchedRegister( DataUpdate); + SchedRegister( LoadTexture); SchedRegister( SetTexture); SchedRegister( DrawSpan);
--- a/Renderer/Engine/sys.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/sys.cc Sun Dec 06 11:33:09 2009 +0900 @@ -241,3 +241,24 @@ xyz[1] += y; xyz[2] += z; } + +/** + * ベクトルに行列を乗算する + * @param[out] v vector (float[4]) + * @param[in] m matrix (float[16]) + */ +void +ApplyMatrix(float *v, float *m) +{ + float t[4]; + + t[0] = v[0]; + t[1] = v[1]; + t[2] = v[2]; + t[3] = v[3]; + + for (int i = 0; i < 4; i++) { + v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; + } +} +
--- a/Renderer/Engine/sys.h Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/sys.h Sun Dec 06 11:33:09 2009 +0900 @@ -20,5 +20,6 @@ void transposeMatrix(float *m0, float *m1); void unitMatrix(float *m); void transMatrix(float *m0, float *m1, float *v); +void ApplyMatrix(float *v1, float *v2); #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataLoad.cc Sun Dec 06 11:33:09 2009 +0900 @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> +#include "DataLoad.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(DataLoad); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + + int length = (int)s->get_param(0); + int load_id = (int)s->get_param(1); + + //printf("size %d",sizeof(float)*length); + + s->global_alloc(load_id, sizeof(float)*length); + + //MemList *ml = s->createMemList(length,length); + //s->global_set(load_id, (void *)ml); + + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataLoad.h Sun Dec 06 11:33:09 2009 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_LOAD +#define INCLUDED_TASK_LOAD + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataUpdate.cc Sun Dec 06 11:33:09 2009 +0900 @@ -0,0 +1,28 @@ +#include <stdio.h> +#include "DataUpdate.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(DataUpdate); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + + float *idata = (float*)s->get_input(rbuf, 0); + int load_id = (int)s->get_param(0); + float *global_data = (float*)s->global_get(load_id); + + global_data[0] = idata[0]; + global_data[1] = idata[1]; + global_data[2] = idata[2]; + global_data[3] = idata[3]; + +#if 0 + s->printf("spe %f ",idata[0]); + s->printf("spe %f ",idata[1]); + s->printf("spe %f\n",idata[2]); +#endif + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataUpdate.h Sun Dec 06 11:33:09 2009 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_DATAUPDATE +#define INCLUDED_TASK_DATAUPDATE + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- a/Renderer/Engine/task/task_init.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/task/task_init.cc Sun Dec 06 11:33:09 2009 +0900 @@ -1,6 +1,9 @@ #include "../Func.h" #include "Scheduler.h" +SchedExternTask(DataLoad); +SchedExternTask(DataUpdate); + SchedExternTask(Create_SGP); SchedExternTask(Update_SGP); SchedExternTask(CreatePolygonFromSceneGraph); @@ -34,6 +37,9 @@ void task_initialize() { + SchedRegister( DataLoad); + SchedRegister( DataUpdate); + SchedRegister( Create_SGP); SchedRegister( Update_SGP); SchedRegister(CreatePolygonFromSceneGraph); @@ -53,7 +59,7 @@ SchedRegister( UpdateKey); SchedRegister( InitKey); - SchedRegister( ShowTime); + //SchedRegister( ShowTime); SchedRegister( Switch); // usr
--- a/Renderer/Engine/viewer.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/viewer.cc Sun Dec 06 11:33:09 2009 +0900 @@ -12,6 +12,7 @@ #include "Pad.h" #include "Application.h" #include "lindaapi.h" +#include "global_alloc.h" static void post2runLoop(SchedTask *s,void *viewer,void *s1); static void post2runDraw(SchedTask *s,void *viewer,void *s1); @@ -49,6 +50,7 @@ width = w; height = h; spe_num = _num; + } int @@ -104,6 +106,22 @@ sgroot = new SceneGraphRoot(this->width, this->height); sgroot->tmanager = manager; + int size = 4; + + light_xyz[0] = 0.0f; + light_xyz[1] = 0.0f; + light_xyz[2] = 0.0f; + light_xyz[3] = 0.0f; + + HTaskPtr data_load; + for(int i = 0; i < spe_num; i++) { + data_load = manager->create_task(DataLoad); + data_load->set_param(0,(memaddr)size); + data_load->set_param(1,(memaddr)LOAD_ID); + data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + data_load->spawn(); + } + MainLoop *mainloop = app->init(this, this->width, this->height); mainloop->mainLoop(); @@ -361,10 +379,11 @@ for (int i = 1; i <= spackList_length; i++) { spackList[i-1].reinit(i*split_screen_h); } - + //run_move(task_next); sgroot->updateControllerState(); sgroot->allExecute(width, height); + light_xyz_stock = sgroot->getLightVector(); //sgroot->checkRemove(); // ここから下は Rendering という関数にする @@ -450,6 +469,8 @@ // SceneGraph(木構造) -> PolygonPack + + task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); task_create_pp->set_param(1,(memaddr)ppack); @@ -503,6 +524,36 @@ //task_next = manager->create_task(Dummy); //task_next->set_post(post2runLoop, (void*)this); + //Light info update + + HTaskPtr data_update; + HTaskPtr data_update_wait; + int size = 4; + + light_xyz[0] = light_xyz_stock[0]; + light_xyz[1] = light_xyz_stock[1]; + light_xyz[2] = light_xyz_stock[2]; + light_xyz[3] = light_xyz_stock[3]; + + data_update_wait = manager->create_task(DataUpdate); + data_update_wait->add_inData(light_xyz,sizeof(float)*size); + data_update_wait->set_param(0,size); + data_update_wait->set_param(1,LOAD_ID); + data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0)); + + + for (int i = 1; i < spe_num; i++) { + data_update = manager->create_task(DataUpdate); + data_update->add_inData(light_xyz,sizeof(float)*size); + data_update->set_param(0,size); + data_update->set_param(1,LOAD_ID); + data_update->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + data_update_wait->wait_for(data_update); + data_update->spawn(); + } + + data_update_wait->spawn(); + ppack->clear(); for (int i = 0; i < spackList_length; i++) { SpanPack *spack = &spackList[i]; @@ -544,6 +595,7 @@ task_draw->set_cpu(SPE_ANY); task_next->wait_for(task_draw); + task_draw->wait_for(data_update_wait); task_draw->spawn(); startx += split_screen_w; @@ -554,6 +606,7 @@ } } } + } /* end */
--- a/Renderer/Engine/viewer.h Sun Dec 06 10:23:19 2009 +0900 +++ b/Renderer/Engine/viewer.h Sun Dec 06 11:33:09 2009 +0900 @@ -36,6 +36,9 @@ int spe_num; int rgb_size[3]; + float light_xyz[4]; + float *light_xyz_stock; + Uint32 video_flags; Uint32 *pixels;
--- a/TaskManager/ChangeLog Sun Dec 06 10:23:19 2009 +0900 +++ b/TaskManager/ChangeLog Sun Dec 06 11:33:09 2009 +0900 @@ -15,6 +15,18 @@ ぐらい? get_segment 使うべきか。連続領域に使える get_segement があると 良いわけね。write とも言うが。 + sort で、memcpy しているのは変。read/write buffer をflipしてやると + 良い。両方とも握っているんだから問題ない。ただし、read/write buffer + の大きさは等しい必要がある。SchedTask->flip_read_write_buffer(); か? + sort ちゃんとは動いているんだよ。 + + word_count_test の稼働率が10%なのはひどい。word_count の方だと偏りが + あって、一部が50%になるが10%ぐらい。DMA待ちではなくて、メール待ちに + なっている。PPUネックになっているっぽい。 + + TaskArray は、SchedTask を拡張して処理する。next で、次のTaskを + 用意する感じか。inData/outData の処理も。 + 2009-12-5 Shinji KONO <kono@ie.u-ryukyu.ac.jp> なんかなぁ。一つの機能を付け加えようとすると、
--- a/TaskManager/Makefile.def Sun Dec 06 10:23:19 2009 +0900 +++ b/TaskManager/Makefile.def Sun Dec 06 11:33:09 2009 +0900 @@ -29,11 +29,11 @@ ABIBIT = 32 -# SIMPLE_TASK=-DSIMPLE_TASK -SIMPLE_TASK= +SIMPLE_TASK=-DSIMPLE_TASK +# SIMPLE_TASK= -OPT = -O9 -# OPT = -g +# OPT = -O9 +OPT = -g CC = g++ CFLAGS = $(SIMPLE_TASK) -Wall `sdl-config --cflags` -m$(ABIBIT) $(OPT)
--- a/TaskManager/kernel/ppe/HTask.h Sun Dec 06 10:23:19 2009 +0900 +++ b/TaskManager/kernel/ppe/HTask.h Sun Dec 06 11:33:09 2009 +0900 @@ -45,6 +45,9 @@ void wait_for(HTask *); void set_cpu(CPU_TYPE type); void set_post(PostFunction func, void *read, void *write); +#ifdef SIPMLE_TASK + Task *create_task_array(int size); +#endif }; typedef HTask* HTaskPtr;
--- a/TaskManager/kernel/ppe/Task.h Sun Dec 06 10:23:19 2009 +0900 +++ b/TaskManager/kernel/ppe/Task.h Sun Dec 06 11:33:09 2009 +0900 @@ -8,32 +8,71 @@ #define MAX_PARAMS 8 +#ifndef SIMPLE_TASK class Task : public SimpleTask { public: // variables BASE_NEW_DELETE(Task); -#ifndef SIMPLE_TASK int param_size; // 4 byte memaddr param[MAX_PARAMS]; // 4*MAX_PARAMS byte ListData inData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); ListData outData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); -#endif public: // functions int add_inData_t(memaddr addr, int size); // unsigned int ではなく 64bit int add_outData_t(memaddr addr, int size); // unsigned int ではなく 64bit int add_data(ListData &list, memaddr addr, int size); - int add_param0(memaddr param); // obsolete. do not use. - int set_param0(int index, memaddr param); + int add_param_t(memaddr param); // obsolete. do not use. + int set_param_t(int index, memaddr param); -#define add_param(param) add_param0((memaddr)(param)) -#define set_param(index,param) set_param0(index, (memaddr) (param)) +#define add_param(param) add_param_t((memaddr)(param)) +#define set_param(index,param) set_param_t(index, (memaddr) (param)) #define add_inData(addr, size) \ add_inData_t((memaddr)(addr), (size)); #define add_outData(addr, size) \ add_outData_t((memaddr)(addr), (size)); }; +#else +class Task { +public: // variables + + BASE_NEW_DELETE(Task); + + int size; + int param_size; + memaddr *param; + int inData_size; + ListEelemnt *inData; + int outData_size; + ListElement *outData; + +public: // functions + int add_inData_t(memaddr addr, int size); + int add_outData_t(memaddr addr, int size); + int set_inData_length(int length); + int set_inData_t(int index, memaddr addr, int size); + int set_outData_length(int length); + int set_outData_t(int index, memaddr addr, int size); + int add_data(ListData &list, memaddr addr, int size); + void set_param_length(int i); + int add_param_t(memaddr param); // obsolete. do not use. + int set_param_t(int index, memaddr param); + int size() { return size; } + +#define add_param(param) add_param_t((memaddr)(param)) +#define set_param(index,param) set_param_t(index, (memaddr) (param)) + +#define add_inData(addr, size) \ + add_inData_t((memaddr)(addr), (size)); +#define add_outData(addr, size) \ + add_outData_t((memaddr)(addr), (size)); +#define set_inData(index, addr, size) \ + set_inData_t(index, (memaddr)(addr), (size)); +#define set_outData(index, addr, size) \ + set_outData_t(index, (memaddr)(addr), (size)); +}; +#endif typedef Task* TaskPtr;
--- a/TaskManager/kernel/sys_task/SysTasks.h Sun Dec 06 10:23:19 2009 +0900 +++ b/TaskManager/kernel/sys_task/SysTasks.h Sun Dec 06 11:33:09 2009 +0900 @@ -1,5 +1,6 @@ StartTask, FinishTask, +TaskArray, ShowTime, StartProfile, #define Dummy StartTask
--- a/example/Bulk/main.cc Sun Dec 06 10:23:19 2009 +0900 +++ b/example/Bulk/main.cc Sun Dec 06 11:33:09 2009 +0900 @@ -7,8 +7,8 @@ extern void task_init(void); static int length = DATA_NUM; -static int task = 1; -static int count = 1; +static int task = 10; +static int count = 10; const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ -length Number of data (default DATA_NUM (Func.h))\n\ @@ -55,7 +55,6 @@ void twice_init(TaskManager *manager) { - TaskArray *twice; int *data = (int*)manager->allocate(sizeof(int)*length); @@ -69,38 +68,47 @@ * Create Task * create_task(Task ID); */ - twice = manager->create_bulk_task(count); + int size = count*(SizeOfParam(2) + SizeOfData(sizeof(int)*length) + + SizeOfData(sizeof(int)*length)); + HTask *twice_main = manager->create_task_array(size); + int pos = 0; for(int i = 0;i<count;i++) { - Task t = twice_main->create_stask(Twice); + Task t = twice_main->create_task(Twice,pos); int length2 = length/2; + // 以下の順序でデータを追加する必要がある。 + // length を先に指定すればsetは後からでも良い。 /** * Set 32bits parameter * add_param(32bit parameter); */ + t->set_param_length(2); t->set_param(0, (memaddr)length2); t->set_param(1, (memaddr)length2); /** * Set of Input Data * add_inData(address of input data, size of input data); */ - t->add_inData(data, sizeof(int)*length2); - t->add_inData(data+length2, sizeof(int)*length2); + t->set_inData_length(2); + t->set_inData(0,data, sizeof(int)*length2); + t->set_inData(1,data+length2, sizeof(int)*length2); /** - * Set of OutPut area + * Set of Output area * add_outData(address of output area, size of output area); */ - t->add_outData(data, sizeof(int)*length2); - t->add_outData(data+length2, sizeof(int)*length2); + t->set_outData_length(2); + t->set_outData(0,data, sizeof(int)*length2); + t->set_outData(1,data+length2, sizeof(int)*length2); + pos += t->size(); + + delete t; // Wao! } twice_main->set_cpu(SPE_ANY); - /* * set_post() で ppe task を渡せるようにしたい */ - twice->set_post(twice_result, (void*)data, 0); - + twice_main->set_post(twice_result, (void*)data, 0); // add Active Queue - twice->spawn_bulk(); + twice_main->spawn(); } int