Mercurial > hg > Game > Cerium
changeset 70:178459e03f5c
*** empty log message ***
line wrap: on
line diff
--- a/TaskManager/Cell/CellBufferManager.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Cell/CellBufferManager.cc Mon Feb 18 01:13:00 2008 +0900 @@ -60,19 +60,23 @@ return q; } } +#endif void -CellBufferManager::clear_taskList(void) +CellBufferManager::clear_cellTaskList(void) { TaskListPtr p, p1; - machineTaskList[0]->length = 0; + for (int i = 0; i < machineNum; i++) { + machineTaskList[i]->length = 0; - p = machineTaskList[0]->next; - while (p) { - p1 = p; - p = p->next; - cellTaskListImpl->free(p1); + p = machineTaskList[i]->next; + while (p) { + p1 = p; + p = p->next; + cellTaskListImpl->free(p1); + } + + machineTaskList[i]->next = NULL; } } -#endif
--- a/TaskManager/Cell/CellTaskManagerImpl.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.cc Mon Feb 18 01:13:00 2008 +0900 @@ -23,6 +23,62 @@ speThreads->init(); } +TaskListPtr +CellTaskManagerImpl::set_task(void) +{ + // ここ...直すかな + TaskListPtr list; + TaskQueuePtr queue; + TaskQueuePtr d; + HTaskPtr htask; + TaskPtr task; + + queue = ((CellBufferManager*)bufferManager)->speActiveTaskQueue; + if (queue == NULL) { + //return NULL; + goto FINISH; + } + + ((CellBufferManager*)bufferManager)->clear_cellTaskList(); + + while (queue) { + //list = bufferManager->get_available_taskList(); + list = ((CellBufferManager*)bufferManager)->machineTaskList[0]; + htask = queue->task; + d = queue; + queue = queue->next; + + task = &list->tasks[list->length++]; + task->command = htask->command; + + // Fix me !!!!! + // ださいというか動かないだろこれ。 + // かっこいい class 判定がないものか。typeinfoだっけ? + // in,out にあるのが DmaBuffer 以外だったら通信させない決まりにしたい + if (htask->in_addr != 0) { + htask->in_addr->get_buffer(&task->in_addr); + } else { + task->in_addr = 0; + } + if (htask->in_addr != 0) { + htask->out_addr->get_buffer(&task->out_addr); + } else { + task->out_addr = 0; + } + task->in_size = htask->in_size; + task->self = htask; + + bufferManager->free_taskQueue(d); + } + + ((CellBufferManager*)bufferManager)->speActiveTaskQueue = NULL; + + speThreads->send_mail(0, (unsigned int *)(&((CellBufferManager*)bufferManager)->machineTaskList[0])); + +FINISH: + return TaskManagerImpl::set_task(); +} + /** * mail_list は ppe 側の mail なので、変更せず渡す。 * その前に spe からのメールをチェックする @@ -32,24 +88,35 @@ { int id; int data; - unsigned int send; - - for (id = 0; id < machineNum; id++) { - while (1) { - data = speThreads->get_mail(id); - if (data < 0) break; + MailQueuePtr list, d; + TaskListPtr next_list; + + list = TaskManagerImpl::mail_check(mail_list); - // 名前あとでちゃんと決めよう => MY_SPE_... とかじゃなくて - if (data == MY_SPE_STATUS_READY) { - __debug_ppe("[SPE %d] finish\n", id); - } else { - __debug_ppe("[PPE] recv from [SPE %d] : 0x%x\n", data, id); - bufferManager->check_task_finish((HTaskPtr)data); + do { + for (id = 0; id < machineNum; id++) { + while (1) { + data = speThreads->get_mail(id); + if (data < 0) break; + + // 名前あとでちゃんと決めよう => MY_SPE_... とかじゃなくて + if (data == MY_SPE_STATUS_READY) { + __debug_ppe("[SPE %d] finish\n", id); + } else { + __debug_ppe("[PPE] recv from [SPE %d] : 0x%x\n", id, data); + bufferManager->check_task_finish((HTaskPtr)data); + } } } + } while (!list && bufferManager->waitTaskQueue); + + if (list == NULL) { + next_list = set_task(); + d = mailManager->create((unsigned int)next_list); + list = MailManager::append_mailQueue(list, d); } - return TaskManagerImpl::mail_check(mail_list); + return list; }
--- a/TaskManager/Cell/spe/CellScheduler.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Cell/spe/CellScheduler.cc Mon Feb 18 01:13:00 2008 +0900 @@ -9,8 +9,9 @@ connector = new CellDmaManager; for (int i = 0; i < 2; i++) { - listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, - sizeof(TaskListPtr)); + //listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, + //sizeof(TaskListPtr)); + listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE); readBuf[i] = memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE); writeBuf[i] = memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE); }
--- a/TaskManager/Test/simple_render/Makefile Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Test/simple_render/Makefile Mon Feb 18 01:13:00 2008 +0900 @@ -8,7 +8,7 @@ TASK_OBJS = $(TASK_SRCS:.cpp=.o) CC = g++ -CFLAGS = -O9 -g -Wall# -DDEBUG +CFLAGS = -g -Wall# -DDEBUG INCLUDE = -I../../../include/TaskManager -I. EXTRA_CFLAGS = `sdl-config --cflags` `xml2-config --cflags`\ @@ -30,6 +30,12 @@ link: $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) +run: $(TARGET) + sudo ./$(TARGET) -width 576 -height 384 -bpp 32 + +debug: $(TARGET) + sudo ppu-gdb ./$(TARGET) + clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#*
--- a/TaskManager/Test/simple_render/main.cpp Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Test/simple_render/main.cpp Mon Feb 18 01:13:00 2008 +0900 @@ -44,17 +44,9 @@ task_zrow_init = manager->create_task(fd_zrow_init, 0, 0, 0, NULL); task_run = manager->create_task(fd_run, 0, 0, 0, NULL); - // obsolute API - //manager->set_task_depend(task_sdl_init, task_run); - //manager->set_task_depend(task_zrow_init, task_run); task_run->set_depend(task_sdl_init); task_run->set_depend(task_zrow_init); - // obsolute API - //manager->spawn_task(task_sdl_init); - //manager->spawn_task(task_zrow_init); - //manager->spawn_task(task_run); - task_sdl_init->spawn(); task_zrow_init->spawn(); task_run->spawn(); @@ -119,7 +111,7 @@ int main(int argc, char *argv[]) { - manager = new TaskManager(3); + manager = new TaskManager(1); manager->init(); task_initialize();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/spe/Makefile Mon Feb 18 01:13:00 2008 +0900 @@ -0,0 +1,23 @@ +TARGET = ../spe-main + +SRCS = $(wildcard *.cpp) +OBJS = $(SRCS:.cpp=.o) + +CC = spu-g++ +CFLAGS = -g -Wall# -DDEBUG +INCLUDE = -I../../../../include/TaskManager -I. -I.. +LIBS = -L../../.. -lspemanager + +.SUFFIXES: .cpp .o + +.cpp.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +clean: + rm -f $(TARGET) $(OBJS) + rm -f *~ \#*
--- a/TaskManager/Test/simple_render/spe/spe-main.cpp Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Test/simple_render/spe/spe-main.cpp Mon Feb 18 01:13:00 2008 +0900 @@ -1,20 +1,180 @@ #include <stdio.h> -#include <spu_mfcio.h> +#include <string.h> +#include <math.h> +#include "polygon_pack.h" +#include "scene_graph_pack.h" +#include "sys.h" int -main(unsigned int speid, - unsigned long long argc, unsigned long long argv) +//create_pp(SceneGraphPack *sgp, PolygonPack *pp) +create_pp(void *read, void *write) { - unsigned int mail; + SceneGraphPack *sgp = (SceneGraphPack*)read; + PolygonPack *pp = (PolygonPack*)write; + + float xyz1[4],xyz2[4],xyz3[4]; - printf("[SPE] Hello, Word! \n"); - - spu_writech(SPU_WrOutMbox, speid); + for (int i = 0; i < sgp->info.size; i++) { + SceneGraphNodePtr node = &sgp->node[i]; + + int n,nt,pt; + for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { + xyz1[0] = node->vertex[n]; + xyz1[1] = node->vertex[n+1]; + xyz1[2] = node->vertex[n+2]*-1; + xyz1[3] = 1; + xyz2[0] = node->vertex[n+3]; + xyz2[1] = node->vertex[n+3+1]; + xyz2[2] = node->vertex[n+3+2]*-1; + xyz2[3] = 1; + xyz3[0] = node->vertex[n+6]; + xyz3[1] = node->vertex[n+6+1]; + xyz3[2] = node->vertex[n+6+2]*-1; + xyz3[3] = 1; - while (1) { - mail = spu_readch(SPU_RdInMbox); - spu_writech(SPU_WrOutMbox, mail+1); + rotate(xyz1, node->translation); + rotate(xyz2, node->translation); + rotate(xyz3, node->translation); + + pp->tri[pt].x1 = xyz1[0]; + pp->tri[pt].y1 = xyz1[1]; + pp->tri[pt].z1 = xyz1[2]; + pp->tri[pt].tex_x1 = node->texture[nt]; + pp->tri[pt].tex_y1 = node->texture[nt+1]; + + pp->tri[pt].x2 = xyz2[0]; + pp->tri[pt].y2 = xyz2[1]; + pp->tri[pt].z2 = xyz2[2]; + pp->tri[pt].tex_x2 = node->texture[nt+2]; + pp->tri[pt].tex_y2 = node->texture[nt+2+1]; + + pp->tri[pt].x3 = xyz3[0]; + pp->tri[pt].y3 = xyz3[1]; + pp->tri[pt].z3 = xyz3[2]; + pp->tri[pt].tex_x3 = node->texture[nt+4]; + pp->tri[pt].tex_y3 = node->texture[nt+4+1]; + + } + pp->info.size = pt; } - return 0; + return sizeof(PolygonPack); +} + +void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] +{ + for(int t=0; t<16; t+=4) + { + for(int i=0; i<4; i++) + { + xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i] + xyz1[t+3]*xyz2[12+i]; + } + } +} + +void rotate(float *xyz, float *matrix) +{ + float abc[4]; + abc[0] = xyz[0]; + abc[1] = xyz[1]; + abc[2] = xyz[2]; + abc[3] = xyz[3]; + + for(int i=0; i<4; i++) + { + //xyz[i] = abc[0]*rot[i] + abc[1]*rot[i+4] + abc[2]*rot[i+8] + abc[3]*rot[i+12]; + xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; + } } + +void get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) +{ + float radx,rady,radz; + radx = rxyz[0]*3.14/180; + rady = rxyz[1]*3.14/180; + radz = rxyz[2]*3.14/180; + + float sinx = sin(radx); + float cosx = cos(radx); + float siny = sin(rady); + float cosy = cos(rady); + float sinz = sin(radz); + float cosz = cos(radz); + + matrix[0] = cosz*cosy+sinz*sinx*siny; + matrix[1] =sinz*cosx; + matrix[2] = -cosz*siny+sinz*sinx*cosy; + matrix[3] = 0; + matrix[4] = -sinz*cosy+cosz*sinx*siny; + matrix[5] = cosz*cosx; + matrix[6] = sinz*siny+cosz*sinx*cosy; + matrix[7] = 0; + matrix[8] = cosx*siny; + matrix[9] = -sinx; + matrix[10] = cosx*cosy; + matrix[11] = 0; + matrix[12] = txyz[0]; + matrix[13] = txyz[1]; + matrix[14] = txyz[2]; + matrix[15] = 1; + + float m[16]; + + for(int i=0; i<16; i++) + { + m[i] = matrix[i]; + } + + if(stack) + { + matrix4x4(matrix, m, stack); + } + +} + + +int +//update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp) +update_sgp(void *rbuf, void *wbuf) +{ + SceneGraphPack *sgp = (SceneGraphPack*)rbuf; + SceneGraphPack *_sgp = (SceneGraphPack*)wbuf; + + SceneGraphNodePtr node; + float y_angle; + + for (int i = 0; i < sgp->info.size; i++) { + //(*my_func[node->move])(node); + //(*my_func[node->interaction])(node, sgp); + + node = &sgp->node[i]; + + // 本当は、ここは上の my_func で行う + y_angle = node->angle[1]; + y_angle += 1.0f; + if (y_angle > 360.0f) y_angle = 0.0f; + node->angle[1] = y_angle; + //node->obj_pos[0] += 0.5f; + //node->obj_pos[1] += 0.5f; + //node->obj_pos[2] += 0.5f; + + if (node->pn != -1) { + get_matrix(node->translation, + node->angle, node->obj_pos, + sgp->node[node->pn].translation); + } else { + get_matrix(node->translation, + node->angle, node->obj_pos, + NULL); + } + } + + // まあこれは多分駄目なんだけど。 + // in/out と update は分ける必要ある? + // それはユーザ側で in/out になるように書かせるもの? + memcpy(_sgp, sgp, sizeof(SceneGraphPack)); + + return sizeof(SceneGraphPack); +} + +int (*func_list[16])(void*, void*) = {0, update_sgp, create_pp, 0};
--- a/TaskManager/Test/simple_render/viewer.cpp Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Test/simple_render/viewer.cpp Mon Feb 18 01:13:00 2008 +0900 @@ -32,12 +32,21 @@ exit( 1 ); } +#if DEBUG screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE); if (screen == NULL) { fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } +#else + //void *pixels; + void *_pixels = new Uint32[width*height]; + //posix_memalign(&pixels, width*heigh/8, DEFAULT_ALIGNMENT); + screen = SDL_CreateRGBSurfaceFrom(_pixels, width, height, 32, + width*4, redMask, greenMask, + blueMask, alphaMask); +#endif } @@ -205,23 +214,6 @@ } } - -struct run_arg_t { - int start_time; - int this_time; - int frames; - SDL_Surface *bitmap; - SDL_PixelFormat *pf; - Uint32 background; - Polygon *p; - //SceneGraphPack *sgp; - //PolygonPack *pp; - DmaManager *sgp_buff; - DmaManager *pp_buff; -}; - -struct run_arg_t *arg; - // run_arg_t に書くのがめんどいからって // global に書くのもどうか int start_time; @@ -233,8 +225,8 @@ Polygon *polygon; //SceneGraphPack *sgp; //PolygonPack *pp; -DmaBuffer *sgp_buff; -DmaBuffer *pp_buff; +DmaBuffer *sgp_buff __attribute__((aligned(DEFAULT_ALIGNMENT))); +DmaBuffer *pp_buff __attribute__((aligned(DEFAULT_ALIGNMENT))); void Viewer::run_init() @@ -254,9 +246,6 @@ polygon->set_data("cube.xml"); polygon->viewer = this; - //sgp = new SceneGraphPack; - //create_sgp(arg->p, arg->sgp); - // 通信用 buffer の allocate // これじゃないと通信用に使えない(ように処理を書かないと!) sgp_buff = manager->allocate(sizeof(SceneGraphPack)); @@ -282,7 +271,6 @@ fd = manager->open("ViewerRunLoop"); task = manager->create_task(fd, 0, 0, 0, NULL); - //manager->spawn_task(task); task->spawn(); } @@ -303,7 +291,6 @@ this_time = get_ticks(); fd_finish = manager->open("ViewerRunFinish"); task_finish = manager->create_task(fd_finish, 0, 0, 0, NULL); - //manager->spawn_task(task_finish); task_finish->spawn(); return; } @@ -314,7 +301,9 @@ graph_line(); fd_update_sgp = manager->open("UpdateSGP"); + //fd_update_sgp = 0; fd_create_pp = manager->open("CreatePP"); + //fd_create_pp = 1; fd = manager->open("ViewerRunDraw"); task_update_sgp = manager->create_task(fd_update_sgp, sizeof(SceneGraphPack), @@ -327,6 +316,11 @@ task->set_depend(task_update_sgp); task->set_depend(task_create_pp); + task_update_sgp->set_cpu(CPU_SPE); + task_create_pp->set_cpu(CPU_SPE); + + printf("fd = %d\n", fd); + task_update_sgp->spawn(); task_create_pp->spawn(); task->spawn(); @@ -370,8 +364,6 @@ delete sgp_buff; delete pp_buff; quit(); - - delete arg; } void
--- a/TaskManager/Test/simple_render/viewer.h Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/Test/simple_render/viewer.h Mon Feb 18 01:13:00 2008 +0900 @@ -19,6 +19,7 @@ class Viewer{ public: + ~Viewer(void) { run_finish();} int width; int height;
--- a/TaskManager/kernel/ppe/BufferManager.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/kernel/ppe/BufferManager.cc Mon Feb 18 01:13:00 2008 +0900 @@ -62,21 +62,13 @@ delete htaskImpl; } -/** - * waitTaskList って別で持つ必要あるのかな。 - * ここでいう wait ってのは依存のことで、 - * 依存される? task はすでにこの task を持っているわけだから。 - * わざわざ waitTaskList を持つ必要は無い。 - * けど、OS とかだと依存とかじゃない wait もあるんだよな。 - * 消す必要は無いか。 - */ void BufferManager::append_waitTask(HTaskPtr task) { - //TaskQueuePtr q; + TaskQueuePtr q; - //q = taskQueueImpl->create(task); - //waitTaskQueue = taskQueueImpl->append(waitTaskQueue, q); + q = taskQueueImpl->create(task); + waitTaskQueue = taskQueueImpl->append(waitTaskQueue, q); } void @@ -91,7 +83,7 @@ void BufferManager::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list) { - TaskQueuePtr p, d; + TaskQueuePtr p; HTaskPtr task; p = list; // wait task list @@ -100,13 +92,10 @@ task = p->task; task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend); if (task->wait_i == NULL) { - d = p; - p = p->next; append_activeTask(task); - //waitTaskQueue = remove_taskQueue(waitTaskQueue, d); - } else { - p = p->next; + waitTaskQueue = remove_taskQueue_eq_task(waitTaskQueue, task); } + p = p->next; } }
--- a/TaskManager/kernel/ppe/DmaBuffer.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/kernel/ppe/DmaBuffer.cc Mon Feb 18 01:13:00 2008 +0900 @@ -1,11 +1,16 @@ #include <stdio.h> #include <stdlib.h> +#include "types.h" #include "DmaBuffer.h" DmaBuffer::DmaBuffer(int size) { - buffer[0] = malloc(size); - buffer[1] = malloc(size); + //buffer[0] = malloc(size); + //buffer[1] = malloc(size); + + posix_memalign(&buffer[0], DEFAULT_ALIGNMENT, size); + posix_memalign(&buffer[1], DEFAULT_ALIGNMENT, size); + flag = 0; }
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Feb 17 23:07:52 2008 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Mon Feb 18 01:13:00 2008 +0900 @@ -145,6 +145,14 @@ list_mail = mailManager->create((unsigned int)list); in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail); + + // Fix me + // spe で仕事中のタスクがあったとしても + // ppe 側で active なリストが無くなれば、 + // たとえ spe の task を待つ wait なリストがあったとしても + // loop を抜けて終わってしまう。 + // ppe側のタスクだけじゃなく、spe 側も全て終わったっていう判定が必要だな。 + // この do-while の一つ外でいいかなー do { sentinel = mailManager->create(MY_SPE_COMMAND_EXIT); in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel);
--- a/include/TaskManager/CellBufferManager.h Sun Feb 17 23:07:52 2008 +0900 +++ b/include/TaskManager/CellBufferManager.h Mon Feb 18 01:13:00 2008 +0900 @@ -18,6 +18,7 @@ void init(void); void append_activeTask(HTaskPtr); + void clear_cellTaskList(void); #if 0 virtual TaskListPtr get_available_taskList(void);
--- a/include/TaskManager/CellTaskManagerImpl.h Sun Feb 17 23:07:52 2008 +0900 +++ b/include/TaskManager/CellTaskManagerImpl.h Mon Feb 18 01:13:00 2008 +0900 @@ -21,6 +21,7 @@ void init(void); void run(void); MailQueuePtr mail_check(MailQueuePtr mail_list); + TaskListPtr set_task(void); }; #endif
--- a/include/TaskManager/Scheduler.h Sun Feb 17 23:07:52 2008 +0900 +++ b/include/TaskManager/Scheduler.h Mon Feb 18 01:13:00 2008 +0900 @@ -20,7 +20,7 @@ virtual ~Scheduler(void) {} /* variables */ - TaskListPtr listBuf[2]; + TaskListPtr listBuf[2] __attribute__((aligned(16))); void *readBuf[2]; void *writeBuf[2]; int listBufFlg;
--- a/include/TaskManager/TaskManagerImpl.h Sun Feb 17 23:07:52 2008 +0900 +++ b/include/TaskManager/TaskManagerImpl.h Mon Feb 18 01:13:00 2008 +0900 @@ -34,7 +34,7 @@ HTaskPtr create_task(int cmd, int siz, DmaBuffer *in_addr, DmaBuffer *out_addr, void (*func)(void)); void set_task_depend(HTaskPtr master, HTaskPtr slave); - TaskListPtr set_task(void); + virtual TaskListPtr set_task(void); virtual void spawn_task(HTaskPtr); void set_task_cpu(HTaskPtr, CPU_TYPE);