Mercurial > hg > Game > Cerium
changeset 54:90523ccc4dff
*** empty log message ***
author | gongo |
---|---|
date | Sat, 16 Feb 2008 14:38:36 +0900 |
parents | 0c8ae614d421 |
children | 9a9c7bef1988 |
files | TaskManager/Test/simple_render/viewer.cpp TaskManager/kernel/ppe/BufferManager.cc TaskManager/kernel/ppe/DmaBuffer.cc TaskManager/kernel/ppe/HTaskInfo.cc TaskManager/kernel/ppe/TaskManager.cc TaskManager/kernel/ppe/TaskManagerImpl.cc include/TaskManager/BufferManager.h include/TaskManager/DmaBuffer.h include/TaskManager/HTaskInfo.h include/TaskManager/TaskManager.h include/TaskManager/TaskManagerImpl.h include/TaskManager/TaskQueueInfo.h include/TaskManager/task.h |
diffstat | 13 files changed, 204 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/simple_render/viewer.cpp Fri Feb 15 20:58:50 2008 +0900 +++ b/TaskManager/Test/simple_render/viewer.cpp Sat Feb 16 14:38:36 2008 +0900 @@ -209,37 +209,69 @@ SDL_PixelFormat *pf; Uint32 background; Polygon *p; - SceneGraphPack *sgp; - PolygonPack *pp; + //SceneGraphPack *sgp; + //PolygonPack *pp; + DmaManager *sgp_buff; + DmaManager *pp_buff; }; struct run_arg_t *arg; +// run_arg_t に書くのがめんどいからって +// global に書くのもどうか +int start_time; +int this_time; +int frames; +SDL_Surface *bitmap; +SDL_PixelFormat *pixelFormat; +Uint32 background; +Polygon *polygon; +//SceneGraphPack *sgp; +//PolygonPack *pp; +DmaBuffer *sgp_buff; +DmaBuffer *pp_buff; + void Viewer::run_init() { - arg = new run_arg_t; HTaskPtr task; int fd; - arg->start_time = get_ticks(); - arg->this_time = 0; - arg->frames = 0; + SceneGraphPack *sgp; + + start_time = get_ticks(); + this_time = 0; + frames = 0; + + pixelFormat = screen->format; + background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); + polygon = new Polygon; + polygon->set_data("cube.xml"); + polygon->viewer = this; + + //sgp = new SceneGraphPack; + //create_sgp(arg->p, arg->sgp); - arg->pf = screen->format; - arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); - arg->p = new Polygon; - arg->p->set_data("cube.xml"); - arg->p->viewer = this; - arg->sgp = new SceneGraphPack; - create_sgp(arg->p, arg->sgp); - arg->pp = new PolygonPack; + // 通信用 buffer の allocate + // これじゃないと通信用に使えない(ように処理を書かないと!) + sgp_buff = manager->allocate(sizeof(SceneGraphPack)); + + sgp_buff->get_buffer(&sgp); + create_sgp(polygon, sgp); + sgp_buff->swap_buffer(); + + sgp_buff->get_buffer(&sgp); + create_sgp(polygon, sgp); + sgp_buff->swap_buffer(); + + //pp = new PolygonPack; + pp_buff = manager->allocate(sizeof(PolygonPack)); pixels = new Uint32[width*height]; graph_line(); - arg->bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, + bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, width*4, redMask, greenMask, blueMask, alphaMask); @@ -262,7 +294,7 @@ int fd; if (quit_check()) { - arg->this_time = get_ticks(); + 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); @@ -279,14 +311,10 @@ fd = manager->open("ViewerRunDraw"); task_update_sgp = manager->create_task(fd_update_sgp, sizeof(SceneGraphPack), - (unsigned int)arg->sgp, - (unsigned int)arg->sgp, - NULL); + sgp_buff, sgp_buff, NULL); task_create_pp = manager->create_task(fd_create_pp, sizeof(SceneGraphPack), - (unsigned int)arg->sgp, - (unsigned int)arg->pp, - NULL); + sgp_buff, pp_buff, NULL); task = manager->create_task(fd, 0, 0, 0, NULL); manager->set_task_depend(task_update_sgp, task); @@ -295,6 +323,8 @@ manager->spawn_task(task_update_sgp); manager->spawn_task(task_create_pp); manager->spawn_task(task); + + sgp_buff->swap_buffer(); } void @@ -303,12 +333,15 @@ HTaskPtr task; int fd; - arg->p->draw(arg->pp); // test draw of PolygonPack - - SDL_BlitSurface(arg->bitmap, NULL, screen, NULL); + PolygonPack *pp; + + pp_buff->get_buffer(&pp); + + polygon->draw(pp); // test draw of PolygonPack + SDL_BlitSurface(bitmap, NULL, screen, NULL); SDL_UpdateRect(screen, 0, 0, 0, 0); - arg->frames++; + frames++; fd = manager->open("ViewerRunLoop"); task = manager->create_task(fd, 0, 0, 0, NULL); @@ -318,16 +351,16 @@ void Viewer::run_finish(void) { - if (arg->this_time != arg->start_time) { - cout<< (((float)arg->frames)/(arg->this_time-arg->start_time))*1000.0 << " FPS\n"; + if (this_time != start_time) { + cout<< (((float)frames)/(this_time-start_time))*1000.0 << " FPS\n"; } - SDL_FreeSurface(arg->bitmap); + SDL_FreeSurface(bitmap); delete [] pixels; - arg->p->delete_data(); - delete arg->p; - delete arg->sgp; - delete arg->pp; + polygon->delete_data(); + delete polygon; + delete sgp_buff; + delete pp_buff; quit(); delete arg;
--- a/TaskManager/kernel/ppe/BufferManager.cc Fri Feb 15 20:58:50 2008 +0900 +++ b/TaskManager/kernel/ppe/BufferManager.cc Sat Feb 16 14:38:36 2008 +0900 @@ -32,9 +32,9 @@ } HTaskPtr -BufferManager::create_task(int cmd, int siz, uint64 in_addr, uint64 out_addr) +BufferManager::create_task(int cmd, int siz, DmaBuffer *in, DmaBuffer *out) { - return htaskImpl->create(cmd, siz, in_addr, out_addr); + return htaskImpl->create(cmd, siz, in, out); } void
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/DmaBuffer.cc Sat Feb 16 14:38:36 2008 +0900 @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include "DmaBuffer.h" + +DmaBuffer::DmaBuffer(int size) +// :(buffer[0])(buf1), (buffer[1])(buf2), flag(0) {}; +{ + buffer[0] = malloc(size); + buffer[1] = malloc(size); + flag = 0; +} + +DmaBuffer::~DmaBuffer(void) +{ + free(buffer[0]); + free(buffer[1]); +} + +void +DmaBuffer::swap_buffer(void) +{ + flag ^= 1; +} + +void +DmaBuffer::get_buffer(void *_dst) +{ + void **dst = (void**)_dst; + *dst = buffer[flag]; +}
--- a/TaskManager/kernel/ppe/HTaskInfo.cc Fri Feb 15 20:58:50 2008 +0900 +++ b/TaskManager/kernel/ppe/HTaskInfo.cc Sat Feb 16 14:38:36 2008 +0900 @@ -44,9 +44,7 @@ } HTaskPtr -HTaskInfo::create(int cmd, int size, - unsigned long long in_addr, - unsigned long long out_addr) +HTaskInfo::create(int cmd, int size, DmaBuffer *in_addr, DmaBuffer *out_addr) { HTaskPtr q;
--- a/TaskManager/kernel/ppe/TaskManager.cc Fri Feb 15 20:58:50 2008 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.cc Sat Feb 16 14:38:36 2008 +0900 @@ -52,10 +52,10 @@ */ HTaskPtr -TaskManager::create_task(int cmd, int size, unsigned long long in_addr, - unsigned long long out_addr, void (*func)(void)) +TaskManager::create_task(int cmd, int size, DmaBuffer *in, + DmaBuffer *out, void (*func)(void)) { - return m_impl->create_task(cmd, size, in_addr, out_addr, func); + return m_impl->create_task(cmd, size, in, out, func); } void @@ -115,3 +115,12 @@ { return symtb->get_address(fd); } + +/** + * 型名指定するには template だけど... + */ +DmaBuffer* +TaskManager::allocate(int size) +{ + return m_impl->allocate(size); +}
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Fri Feb 15 20:58:50 2008 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Sat Feb 16 14:38:36 2008 +0900 @@ -29,10 +29,8 @@ } HTaskPtr -TaskManagerImpl::create_task(int cmd, int size, - unsigned long long in_addr, - unsigned long long out_addr, - void (*func)(void)) +TaskManagerImpl::create_task(int cmd, int size, DmaBuffer *in_addr, + DmaBuffer *out_addr, void (*func)(void)) { HTaskPtr new_task; @@ -98,8 +96,23 @@ task = &list->tasks[list->length++]; task->command = htask->command; - task->in_addr = htask->in_addr; - task->out_addr = htask->out_addr; + + // Fix me !!!!! + // ださい + // かっこいい class 判定がないものか。typeinfoだっけ? + // in,out にあるのが DmaBuffer 以外だったら通信させない決まりにしたい + if (htask->in_addr != 0) { + //task->in_addr = (uint32)(htask->in_addr->get_buffer()); + htask->in_addr->get_buffer(&task->in_addr); + } else { + task->in_addr = 0; + } + if (htask->in_addr != 0) { + //task->out_addr = (uint32)(htask->out_addr->get_buffer()); + htask->out_addr->get_buffer(&task->out_addr); + } else { + task->out_addr = 0; + } task->in_size = htask->in_size; task->self = htask; @@ -174,3 +187,12 @@ return ret; } + +/** + * 型名指定するには template だけど... + */ +DmaBuffer* +TaskManagerImpl::allocate(int size) +{ + return new DmaBuffer(size); +}
--- a/include/TaskManager/BufferManager.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/BufferManager.h Sat Feb 16 14:38:36 2008 +0900 @@ -17,10 +17,14 @@ # include "TaskQueueInfo.h" #endif -#ifndef INCLUDED_HTask_INFO +#ifndef INCLUDED_HTASK_INFO # include "HTaskInfo.h" #endif +#ifndef INCLUDED_DMA_BUFFER +# include "DmaBuffer.h" +#endif + class BufferManager { public: /* constructor */ @@ -41,7 +45,7 @@ void init(void); TaskQueuePtr create_taskQueue(HTaskPtr); - HTaskPtr create_task(int cmd, int siz, uint64 in, uint64 out); + HTaskPtr create_task(int cmd, int siz, DmaBuffer *in, DmaBuffer *out); void free_taskQueue(TaskQueuePtr); void free_task(HTaskPtr);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/DmaBuffer.h Sat Feb 16 14:38:36 2008 +0900 @@ -0,0 +1,20 @@ +#ifndef INCLUDED_DMA_BUFFER +#define INCLUDED_DMA_BUFFER + +class DmaBuffer { +public: + /* constructor */ + DmaBuffer(int size = 4); + ~DmaBuffer(void); + + /* variables */ + void *buffer[2]; + int flag; // variable that select buffer[0 or 1] + + /* functions */ + void swap_buffer(void); + //void* get_buffer(void); + void get_buffer(void*); +}; + +#endif
--- a/include/TaskManager/HTaskInfo.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/HTaskInfo.h Sat Feb 16 14:38:36 2008 +0900 @@ -1,14 +1,31 @@ #ifndef INCLUDED_HTASK_INFO #define INCLUDED_HTASK_INFO +#ifndef INCLUDED_TYPES +# include "types.h" +#endif + #ifndef INCLUDED_TASK # include "task.h" #endif -#ifndef INCLUDED_TYPES -# include "types.h" +#ifndef INCLUDED_DMA_BUFFER +# include "DmaBuffer.h" #endif +struct htask { + int command; + int in_size; + //unsigned int in_addr; + //unsigned int out_addr; + DmaBuffer *in_addr; + DmaBuffer *out_addr; + TaskQueuePtr wait_me; // List of task waiting for me + TaskQueuePtr wait_i; // List of task for which I am waiting + void (*post_func)(void); + struct htask *next; +}; + class HTaskInfo { public: /* constructor */ @@ -17,7 +34,7 @@ /* functions */ int init(int num); - HTaskPtr create(int cmd, int size, uint64 in_addr, uint64 out_addr); + HTaskPtr create(int cmd,int size,DmaBuffer *in_addr, DmaBuffer *out_addr); void free(HTaskPtr q); private:
--- a/include/TaskManager/TaskManager.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/TaskManager.h Sat Feb 16 14:38:36 2008 +0900 @@ -21,8 +21,8 @@ /* functions */ void init(void); void finish(void); - HTaskPtr create_task(int cmd, int siz, unsigned long long in_addr, - unsigned long long out_addr, void (*func)(void)); + HTaskPtr create_task(int cmd, int siz, DmaBuffer *in_addr, + DmaBuffer *out_addr, void (*func)(void)); void set_task_depend(HTaskPtr master, HTaskPtr slave); void spawn_task(HTaskPtr); void run(void); @@ -32,6 +32,8 @@ void set_symbol(const char *sym, void *addr); int open(const char *sym); static void* get_address(int fd); + + DmaBuffer* allocate(int size); private: int machineNum;
--- a/include/TaskManager/TaskManagerImpl.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/TaskManagerImpl.h Sat Feb 16 14:38:36 2008 +0900 @@ -1,10 +1,6 @@ #ifndef INCLUDED_TASK_MANAGER_IMPL #define INCLUDED_TASK_MANAGER_IMPL -#ifndef INCLUDED_BUFFER_MANAGER -# include "BufferManager.h" -#endif - #ifndef INCLUDED_MAIL_MANAGER # include "MailManager.h" #endif @@ -13,6 +9,10 @@ # include "MainScheduler.h" #endif +#ifndef INCLUDED_BUFFER_MANAGER +# include "BufferManager.h" +#endif + class TaskManagerImpl { public: /* constructor */ @@ -31,12 +31,14 @@ void run(void); MailQueuePtr mail_check(MailQueuePtr mail_list); - HTaskPtr create_task(int cmd, int siz, - unsigned long long in_addr, - unsigned long long out_addr, - void (*func)(void)); + 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 void spawn_task(HTaskPtr); + + // Fixme + // アライメントとか、インスタンス用の new 使える奴とか、etc... + DmaBuffer* allocate(int size); }; #endif
--- a/include/TaskManager/TaskQueueInfo.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/TaskQueueInfo.h Sat Feb 16 14:38:36 2008 +0900 @@ -9,6 +9,11 @@ # include "HTaskInfo.h" #endif +typedef struct task_queue { + HTaskPtr task; + TaskQueuePtr next; +} TaskQueue, *TaskQueuePtr; + class TaskQueueInfo { public: /* constructor */
--- a/include/TaskManager/task.h Fri Feb 15 20:58:50 2008 +0900 +++ b/include/TaskManager/task.h Sat Feb 16 14:38:36 2008 +0900 @@ -14,22 +14,6 @@ HTaskPtr self; } Task, *TaskPtr; -struct htask { - int command; - int in_size; - unsigned int in_addr; - unsigned int out_addr; - TaskQueuePtr wait_me; // List of task waiting for me - TaskQueuePtr wait_i; // List of task for which I am waiting - void (*post_func)(void); - struct htask *next; -}; - -struct task_queue { - HTaskPtr task; - TaskQueuePtr next; -}; - typedef struct task_list { int length; struct task_list *next;