Mercurial > hg > Members > kono > Cerium
changeset 395:8c5fa57128cb
chain on SPE
author | game@localhost.localdomain |
---|---|
date | Thu, 17 Sep 2009 16:55:18 +0900 |
parents | e08d0aa94367 |
children | d1f1e27d0a12 |
files | TaskManager/Test/test_render/Func.h TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/chain.cpp TaskManager/Test/test_render/spe/ChainCal.cpp TaskManager/Test/test_render/spe/ChainCal.h TaskManager/Test/test_render/spe/ChainInit.cpp TaskManager/Test/test_render/spe/ChainInit.h TaskManager/Test/test_render/spe/spe-main.cpp TaskManager/include/types.h TaskManager/kernel/schedule/SchedTask.cc TaskManager/kernel/schedule/SchedTask.h TaskManager/kernel/schedule/Scheduler.cc example/MemList/main.cc example/get_segment/spe/Hello.cc |
diffstat | 14 files changed, 249 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Func.h Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/Test/test_render/Func.h Thu Sep 17 16:55:18 2009 +0900 @@ -21,5 +21,11 @@ TASK_SET_TEXTURE, TASK_DUMMY, + CHAINCAL_TASK, + CHAININIT_TASK, + RUN_FINISH, + SHOW_TIME, }; + +#define DATA_ID 0
--- a/TaskManager/Test/test_render/SceneGraph.h Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.h Thu Sep 17 16:55:18 2009 +0900 @@ -24,6 +24,8 @@ float stack_angle[3]; int id; + void* propertyptr; + // xml ファイルから生成した時のオブジェクトリスト SceneGraphPtr next; SceneGraphPtr prev;
--- a/TaskManager/Test/test_render/chain.cpp Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/Test/test_render/chain.cpp Thu Sep 17 16:55:18 2009 +0900 @@ -1,27 +1,34 @@ #include <iostream> #include <math.h> #include "SceneGraphRoot.h" +#include "SceneGraph.h" #include "SGList.h" +#include "TaskManager.h" +#include "Func.h" #define FALSE 0 #define TRUE !FALSE #define CHAIN_LEN 50 -static double m = 100.0; -static double k = 7000.0; -static double g = 9.8; -static double dt = 0.003; static double chain_width = 10; -static double safe = 0.995; typedef struct { double x, y, next_x, next_y; double vx, vy, next_vx, next_vy; + double angle[3]; int can_move; + SceneGraphPtr parent; + int id; + //int parent; } CHAIN_VARS; +/* SceneGraph の property */ +CHAIN_VARS* property; + CHAIN_VARS cv[CHAIN_LEN]; +void createSceneGraphFromProperty(CHAIN_VARS* p) ; + void init_chain_vars(CHAIN_VARS *cv) { cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; @@ -30,10 +37,13 @@ } void -set_vector(CHAIN_VARS *cv, SceneGraphPtr sg) { - sg->xyz[0] = (float)cv->next_x; - sg->xyz[1] = (float)cv->next_y; +set_vector(CHAIN_VARS *p, SceneGraphPtr sg) { + sg->xyz[0] = p->next_x; + sg->xyz[1] = p->next_y; sg->xyz[2] = 0.0f; + sg->angle[0] = p->angle[0]; + sg->angle[1] = p->angle[1]; + sg->angle[2] = p->angle[2]; } @@ -43,20 +53,20 @@ Pad *pad = sgroot->getController(); if (pad->circle.isHold()) { - cv[CHAIN_LEN-1].can_move = FALSE; + property[CHAIN_LEN-1].can_move = FALSE; if (pad->left.isHold()) { - cv[CHAIN_LEN-1].x += -5.0; + property[CHAIN_LEN-1].x += -5.0; } else if (pad->right.isHold()) { - cv[CHAIN_LEN-1].x += 5.0; + property[CHAIN_LEN-1].x += 5.0; } if (pad->up.isHold()) { - cv[CHAIN_LEN-1].y += -5.0; + property[CHAIN_LEN-1].y += -5.0; } else if (pad->down.isHold()) { - cv[CHAIN_LEN-1].y += 5.0; + property[CHAIN_LEN-1].y += 5.0; } } else { - cv[CHAIN_LEN-1].can_move = TRUE; + property[CHAIN_LEN-1].can_move = TRUE; } } @@ -64,56 +74,17 @@ chain_move(SceneGraphPtr sg, int w, int h) { int id = sg->id; + CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr; if(id == 0) { - for(int cnt = 0; cnt < 600; cnt++) { - for(int i = 0; i < CHAIN_LEN; i++) { - if(cv[i].can_move) { - double dx = cv[i-1].x - cv[i].x; - double dy = cv[i-1].y - cv[i].y; - double l = sqrt(dx * dx + dy * dy); - double a = k * (l - chain_width) / m; - double ax = a * dx / l; - double ay = a * dy / l; - if(i < CHAIN_LEN - 1) { - dx = cv[i+1].x - cv[i].x; - dy = cv[i+1].y - cv[i].y; - l = sqrt(dx * dx + dy * dy); - a = k * (l - chain_width) / m; - ax += a * dx / l; - ay += a * dy / l; - } - ay += g; - cv[i].vx *= safe; - cv[i].vy *= safe; - cv[i].next_vx = cv[i].vx + ax * dt; - cv[i].next_vy = cv[i].vy + ay * dt; - cv[i].next_x = cv[i].x + cv[i].vx * dt; - cv[i].next_y = cv[i].y + cv[i].vy * dt; - } else { - cv[i].next_x = cv[i].x; - cv[i].next_y = cv[i].y; - } - } - for(int i = 0; i < CHAIN_LEN; i++) { - cv[i].vx = cv[i].next_vx; - cv[i].vy = cv[i].next_vy; - cv[i].x = cv[i].next_x; - cv[i].y = cv[i].next_y; - } - } - // cout << id << ", " << sg->xyz[1] << endl; + HTaskPtr chain_cal; + chain_cal = manager->create_task(CHAINCAL_TASK); + chain_cal->add_inData(&property[CHAIN_LEN-1], sizeof(CHAIN_VARS)); + chain_cal->add_param(id); + chain_cal->add_outData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_cal->spawn(); + createSceneGraphFromProperty(p); } - set_vector(&cv[id], sg); - int p, n; - p = n = id; - if(p != 0) { - p--; - } - if(n != CHAIN_LEN - 1) { - n++; - } - sg->angle[2-(id%2)*2] - = 90 + atan((cv[p].next_y - cv[n].next_y) / (cv[p].next_x - cv[n].next_x)) * 180 / M_PI; + } void @@ -122,34 +93,62 @@ } +void +createSceneGraphFromProperty(CHAIN_VARS* p) +{ + SceneGraphPtr chain_copy; + chain_copy = sgroot->createSceneGraph(CHAIN); + chain_copy->propertyptr = (void*)p; + set_vector(p, chain_copy); + p->parent->addChild(chain_copy); +} + void chain_init(int w, int h) { SceneGraphPtr root_chain, chain; CHAIN_VARS rcv; + HTaskPtr chain_init; + sgroot->createFromXMLfile("xml_file/chain.xml"); + /* SPE に送る property の配列の領域確保 */ + property = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); + root_chain = sgroot->createSceneGraph(CHAIN); root_chain->set_move_collision(chain_move_ope, chain_collision); init_chain_vars(&rcv); rcv.next_x = w / 2; rcv.next_y = 0.0; + rcv.angle[0] = 0; + rcv.angle[1] = 0; + rcv.angle[2] = 0; + set_vector(&rcv, root_chain); for(int i = 0; i < CHAIN_LEN; i++) { chain = sgroot->createSceneGraph(CHAIN); - chain->id = i; - init_chain_vars(&cv[i]); - cv[i].x = 0; - cv[i].y = chain_width * i; - set_vector(&cv[i], chain); - chain->angle[1] = -90 * (i % 2); + property[i].id = i; + init_chain_vars(&property[i]); + property[i].x = 0; + property[i].y = chain_width * i; + set_vector(&property[i], chain); + property->angle[1] = -90 * (i % 2); chain->set_move_collision(chain_move, chain_collision); root_chain->addChild(chain); + property[i].parent = root_chain; } cv[0].can_move = FALSE; + // property を SPU の共有領域へコピーする + chain_init = manager->create_task(CHAININIT_TASK); + chain_init->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_init->add_param(CHAIN_LEN); + chain_init->set_cpu(SPE_0); + + sgroot->setSceneData(root_chain); } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/ChainCal.cpp Thu Sep 17 16:55:18 2009 +0900 @@ -0,0 +1,93 @@ +#include <stdio.h> +#include <string.h> +#include "ChainCal.h" +#include "Func.h" +#include "types.h" +#include <math.h> + + +/* これは必須 */ +SchedDefineTask(ChainCal); + +#define CHAIN_LEN 50 + +static double m = 100.0; +static double k = 7000.0; +static double g = 9.8; +static double dt = 0.003; +static double chain_width = 10; +static double safe = 0.995; + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + double angle[3]; + int can_move; + uint32 parent; + int id; + //int parent; +} CHAIN_VARS; + +int +ChainCal::run(void *rbuf, void *wbuf) +{ + CHAIN_VARS* property = (CHAIN_VARS*)global_get(DATA_ID); + //&property[CHAIN_LEN-1] = (CHAIN_VARS*)get_input(rbuf, 0); + CHAIN_VARS* pro = (CHAIN_VARS*)get_input(rbuf, 0); + int id = get_param(0); + memcpy(&property[CHAIN_LEN-1], pro, sizeof(CHAIN_VARS)); + + CHAIN_VARS* o_property = (CHAIN_VARS*)get_output(wbuf, 0); + + for(int cnt = 0; cnt < 600; cnt++) { + for(int i = 0; i < CHAIN_LEN; i++) { + if(property[i].can_move) { + double dx = property[i-1].x - property[i].x; + double dy = property[i-1].y - property[i].y; + double l = sqrt(dx * dx + dy * dy); + double a = k * (l - chain_width) / m; + double ax = a * dx / l; + double ay = a * dy / l; + if(i < CHAIN_LEN - 1) { + dx = property[i+1].x - property[i].x; + dy = property[i+1].y - property[i].y; + l = sqrt(dx * dx + dy * dy); + a = k * (l - chain_width) / m; + ax += a * dx / l; + ay += a * dy / l; + } + ay += g; + property[i].vx *= safe; + property[i].vy *= safe; + property[i].next_vx = property[i].vx + ax * dt; + property[i].next_vy = property[i].vy + ay * dt; + property[i].next_x = property[i].x + property[i].vx * dt; + property[i].next_y = property[i].y + property[i].vy * dt; + } else { + property[i].next_x = property[i].x; + property[i].next_y = property[i].y; + } + } + for(int i = 0; i < CHAIN_LEN; i++) { + property[i].vx = property[i].next_vx; + property[i].vy = property[i].next_vy; + property[i].x = property[i].next_x; + property[i].y = property[i].next_y; + } + } + + int p, n; + p = n = id; + if(p != 0) { + p--; + } + if(n != CHAIN_LEN - 1) { + n++; + } + property->angle[2-(id%2)*2] + = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI; + + o_property = property; + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/ChainCal.h Thu Sep 17 16:55:18 2009 +0900 @@ -0,0 +1,16 @@ +#ifndef INCLUDED_TASK_CHAIN_CAL +#define INCLUDED_TASK_CHAIN_CAL + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + +class ChainCal : public SchedTask { +public: + SchedConstructor(ChainCal); + + //int run(SchedTask *smanager, void *r, void *w); + int run(void *r, void *w); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/ChainInit.cpp Thu Sep 17 16:55:18 2009 +0900 @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <string.h> +#include "ChainInit.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(ChainInit); + +/* + spe の global 領域に MemList を生成する + */ + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + int can_move; + uint32 parent; +} CHAIN_VARS; + +CHAIN_VARS* property; + +int +ChainInit::run(void *rbuf, void *wbuf) +{ + CHAIN_VARS* idata = (CHAIN_VARS*)get_input(rbuf, 0); + uint32 chain_len = get_param(0); + + // property は spe 上で allocate している(global) + property = (CHAIN_VARS*)global_alloc(DATA_ID, sizeof(CHAIN_VARS)*chain_len); + memcpy(property, idata, sizeof(CHAIN_VARS)*chain_len); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/ChainInit.h Thu Sep 17 16:55:18 2009 +0900 @@ -0,0 +1,16 @@ +#ifndef INCLUDED_TASK_CHAIN_INIT +#define INCLUDED_TASK_CHAIN_INIT + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +class ChainInit : public SchedTask { +public: + SchedConstructor(ChainInit); + + int run(void *r, void *w); +}; + +#endif
--- a/TaskManager/Test/test_render/spe/spe-main.cpp Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/Test/test_render/spe/spe-main.cpp Thu Sep 17 16:55:18 2009 +0900 @@ -7,6 +7,9 @@ SchedExternTask(DrawSpanRenew); SchedExternTask(DrawBack); +SchedExternTask(ChainCal); +SchedExternTask(ChainInit); + SchedExternTask(CreateSpan); //SchedExternTask(CreatePolygon); @@ -18,6 +21,9 @@ SchedRegisterTask(TASK_INIT_TEXTURE, LoadTexture); SchedRegisterTask(TASK_SET_TEXTURE, SetTexture); SchedRegisterTask(TASK_DRAW_SPAN, DrawSpan); + + SchedRegisterTask(CHAINCAL_TASK, ChainCal); + SchedRegisterTask(CHAININIT_TASK, ChainInit); #if 0 SchedRegisterTask(TASK_DRAW_SPAN2, DrawSpanRenew); #endif
--- a/TaskManager/include/types.h Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/include/types.h Thu Sep 17 16:55:18 2009 +0900 @@ -6,6 +6,7 @@ typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; + #ifdef SPU typedef uint64_t memaddr; #else @@ -16,6 +17,9 @@ #endif #endif + + + #define SPE_ALIGNMENT 16 #define SPE_ALIGNMENT_FULL 128 #define SPE_ALIGN __attribute__((aligned(SPE_ALIGNMENT)))
--- a/TaskManager/kernel/schedule/SchedTask.cc Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Thu Sep 17 16:55:18 2009 +0900 @@ -572,7 +572,6 @@ __scheduler->show_dma_wait(); } - MemorySegment * SchedTask::get_segment(memaddr addr, MemList *m) { return __scheduler->get_segment(addr,m); }
--- a/TaskManager/kernel/schedule/SchedTask.h Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Thu Sep 17 16:55:18 2009 +0900 @@ -23,7 +23,7 @@ // Task を実行するスケジューラ自身 Scheduler *__scheduler; - + // 現在スケジューラが実行している TaskList と、このタスクに対応する Task TaskListPtr __list; TaskPtr __task;
--- a/TaskManager/kernel/schedule/Scheduler.cc Wed Sep 16 22:33:40 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Thu Sep 17 16:55:18 2009 +0900 @@ -362,6 +362,7 @@ char* data = (char*)next+head_size; next->data = (void*)data; next->size = size; + next->address = (memaddr)next; mlist->addLast(next); } @@ -375,7 +376,6 @@ @param [addr] Main Memory のアドレス @param [m] Mem List @return allocate した領域のポインタ - memory directory にあるべきだが... */
--- a/example/MemList/main.cc Wed Sep 16 22:33:40 2009 +0900 +++ b/example/MemList/main.cc Thu Sep 17 16:55:18 2009 +0900 @@ -16,6 +16,7 @@ -cpu Number of SPE (default 1) \n \ -count Number of task is print \"Hello, World!!\""; + void test1(MemList* active, MemList* freelist, uint32 size, uint32 count) { @@ -32,6 +33,7 @@ printf("test1\n"); } + int TMmain(int argc, char *argv[]) {
--- a/example/get_segment/spe/Hello.cc Wed Sep 16 22:33:40 2009 +0900 +++ b/example/get_segment/spe/Hello.cc Thu Sep 17 16:55:18 2009 +0900 @@ -24,10 +24,10 @@ } #endif - void *next = 0; + memaddr *next = 0; #if 1 smanager->mainMem_wait(); - next = (void *)smanager->mainMem_get(0); + next = (memaddr*)smanager->mainMem_get(0); smanager->dma_wait(PP_STORE); smanager->dma_store(ptr, (uint32)next,