# HG changeset patch # User Shinji KONO # Date 1260453355 -32400 # Node ID be44ada665e98919c8a6ef557976cfec655ce094 # Parent 9c8dd6026022e5ad26aa3a3524e610cb6a647829# Parent fc0227b5cb5ac2652af7f85adcda291a8a78e83c merge diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/Makefile.def --- a/Renderer/Engine/Makefile.def Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/Makefile.def Thu Dec 10 22:55:55 2009 +0900 @@ -5,7 +5,8 @@ ABIBIT = 32 ABI = -m$(ABIBIT) CC = g++ -CFLAGS = -g -Wall $(ABI) # -O9 -DDEBUG +OPT = -g +CFLAGS = -g -Wall $(ABI) $(OPT) # -O9 -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. # LIBS = -L$(CERIUM)/TaskManager -m$(ABIBIT) diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/SgChange.cc --- a/Renderer/Engine/SgChange.cc Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/SgChange.cc Thu Dec 10 22:55:55 2009 +0900 @@ -12,8 +12,10 @@ #include "Pad.h" #include "Application.h" #include "lindaapi.h" +#include "global_alloc.h" -static void post2runLoop(SchedTask *s,void *viewer,void *s1); +static void post2runLoop(SchedTask *s, void *viewer, void *s1); +static void post2runDraw(SchedTask *s, void *viewer, void *s1); /* measure for FPS (Frame Per Second) */ int start_time; @@ -29,10 +31,6 @@ int spackList_length; int spackList_length_align; -/** - * - */ - SgChange::SgChange(int b, int w, int h, int _num) { bpp = b; @@ -84,7 +82,7 @@ void SgChange::run_init(TaskManager *manager, Application *app) -{ +{ this->manager = manager; start_time = get_ticks(); @@ -94,23 +92,78 @@ // ココ! sgroot_A = new SceneGraphRoot(this->width, this->height); sgroot_A->tmanager = manager; - sgroot_B = new SceneGraphRoot(this->width, this->height); - sgroot_B->tmanager = manager; + //sgroot_B = new SceneGraphRoot(this->width, this->height); + //sgroot_B->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_only_sg(this, this->width, this->height); + + mainloop->mainLoop(); +} - mainloop->mainLoop(); +HTaskPtr +SgChange::initLoop() +{ + HTaskPtr task_next; + HTaskPtr task_tex; + + sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); + sgpack->init(); + ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); + + spackList_length = (this->height + split_screen_h - 1) / split_screen_h; + spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); + + spackList_length_align = (spackList_length + 3)&(~3); + + spackList_ptr = + (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); + + for (int i = 0; i < spackList_length; i++) { + spackList_ptr[i] = &spackList[i]; + } + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].init(i*split_screen_h); + } + + task_next = manager->create_task(Dummy); + + for (int i = 0; i < spe_num; i++) { + task_tex = manager->create_task(LoadTexture); + task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + task_next->wait_for(task_tex); + task_tex->spawn(); + } + + return task_next; } void SgChange::mainLoop() { - HTaskPtr task_next = manager->create_task(Dummy); + HTaskPtr task_next = initLoop(); task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL) task_next->spawn(); } + + static void post2runLoop(SchedTask *s, void *viewer_, void *arg) { @@ -141,15 +194,180 @@ return; } + clean_pixels(); + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].reinit(i*split_screen_h); + } + + //exchange_sgroot(); + sgroot_A->updateControllerState(); sgroot_A->allExecute(width, height); - exchange_sgroot(); + light_xyz_stock = sgroot_A->getLightVector(); //printf("Sgroot = %x\n", sgroot_A); + + //task_next->set_post(&post2runLoop, (void *)this, 0); + //task_next->spawn(); + + rendering(task_next); +} - task_next->set_post(&post2runLoop, (void *)this, 0); +void +SgChange::rendering(HTaskPtr task_next) +{ + common_rendering(task_next); + + task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) task_next->spawn(); } +void +SgChange::common_rendering(HTaskPtr task_next) +{ + HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); + + //task_create_pp->set_param(0, (memaddr)sgroot_B->getDrawSceneGraph()); + task_create_pp->set_param(0, (memaddr)sgroot_A->getDrawSceneGraph()); + task_create_pp->set_param(1, (memaddr)ppack); + + task_next->wait_for(task_create_pp); + + int range_base = spe_num; + int range = (spackList_length + range_base - 1) / range_base; + + for (int i = 0; i < range_base; i++) { + int index_start = range*i; + int index_end = (index_start + range >= spackList_length) + ? spackList_length : index_start + range; + + HTaskPtr task_create_sp = manager->create_task(CreateSpan); + + task_create_sp->set_param(0,index_start); + + task_create_sp->set_param(1,index_start*split_screen_h + 1); + task_create_sp->set_param(2,index_end*split_screen_h); + + task_create_sp->add_inData(ppack, sizeof(PolygonPack)); + task_create_sp->add_inData(spackList_ptr, + sizeof(SpanPack*)*spackList_length_align); + task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); + + task_next->wait_for(task_create_sp); + task_create_sp->wait_for(task_create_pp); + + task_create_sp->set_cpu(SPE_ANY); + task_create_sp->spawn(); + } + + task_create_pp->spawn(); +} + +static void +post2runDraw(SchedTask *s, void *viewer_, void *arg) +{ + SgChange *viewer = (SgChange *)viewer_; + HTaskPtr task_next = viewer->manager->create_task(Dummy); + viewer->run_draw(task_next); +} + +void +SgChange::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする +{ + common_draw(task_next); + + task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); + + frames++; +} + +void +SgChange::common_draw(HTaskPtr task_next) +{ + HTaskPtr task_draw; + + //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]; + int startx = 1; + int endx = split_screen_w; + + int starty = spack->info.y_top - split_screen_h + 1; + //int endy = spack->info.y_top; + int rangey = (starty + split_screen_h - 1 > this->height) + ? this->height - starty + 1 : split_screen_h; + + while (startx < this->width) { + if (spack->info.size > 0) { + // Draw SpanPack + task_draw = manager->create_task(DrawSpan); + + task_draw->set_param(0, + (memaddr)&pixels[(startx-1) + this->width*(starty-1)]); + task_draw->set_param(1,this->width); + task_draw->set_param(2,startx); + task_draw->set_param(3,endx); + task_draw->set_param(4,rangey); + + task_draw->add_inData(spack, sizeof(SpanPack)); + + for (int i = 0; i < rangey; i++) { + task_draw->add_outData( + &pixels[(startx-1) + this->width*(starty-1 + i) ], + (endx-startx+1)*sizeof(int)); + } + } else { + // 7.7.3 SL1 Data Cache Range Set to Zero コマンド + // を使って、DMAでclearするべき... ということは、 + // それもSPEでやる方が良い? + memset(&pixels[(startx-1)+this->width*(starty-1)], + 0, (this->width)*sizeof(int)*rangey); + break; + } + + 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; + endx += split_screen_w; + + if (endx > this->width) { + endx = this->width; + } + } + } +} void SgChange::run_finish(void) @@ -159,7 +377,7 @@ } delete sgroot_A; - delete sgroot_B; + //delete sgroot_B; quit(); } diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/SgChange.h --- a/Renderer/Engine/SgChange.h Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/SgChange.h Thu Dec 10 22:55:55 2009 +0900 @@ -38,10 +38,14 @@ int spe_num; + float light_xyz[4] __attribute__((aligned(16))); + float *light_xyz_stock; + int rgb_size[3]; Uint32 video_flags; Uint32 *pixels; + virtual void video_init(TaskManager *manager) = 0; void init(); int get_ticks(); @@ -54,7 +58,11 @@ virtual void run_init(TaskManager *manager, Application *app); virtual void run_loop(HTaskPtr task_next); virtual void run_finish(); + virtual void run_draw(HTaskPtr task_next); virtual void exchange_sgroot(); + virtual void rendering(HTaskPtr task_next); + virtual void common_draw(HTaskPtr task_next); + virtual void common_rendering(HTaskPtr task_next); void mainLoop(); void createFromXMLfile(const char *file) diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/SgMain.cc --- a/Renderer/Engine/SgMain.cc Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/SgMain.cc Thu Dec 10 22:55:55 2009 +0900 @@ -1,5 +1,7 @@ #include "TaskManager.h" #include "SgChange.h" +#include "sgchangeSDL.h" +#include "sgchangeFB.h" #include "Application.h" /* prototype */ @@ -14,6 +16,7 @@ int width = 640; int height = 480; int spenum = 1; + video_type vtype = VTYPE_SDL; for(int i = 1; argv[i]; ++i) { @@ -29,10 +32,32 @@ if (strcmp(argv[i], "-cpu") == 0) { spenum = atoi(argv[++i]); } + if (strcmp(argv[i], "-video") == 0) { + if (strcmp(argv[i+1], "sdl") == 0) { + vtype = VTYPE_SDL; + } else if (strcmp(argv[i+1], "fb") == 0) { + vtype = VTYPE_FB; + } + i++; + } } + /* SgChange *screen = new SgChange(bpp, width, height, spenum); screen->run_init(manager, application()); + */ + + SgChange *screen; + if (vtype == VTYPE_SDL) { + screen = new SgChangeSDL(manager, bpp, width, height, spenum); + } else if (vtype == VTYPE_FB) { + screen = new SgChangeFB(manager, bpp, width, height, spenum); + }else{ + screen = new SgChangeSDL(manager, bpp, width, height, spenum); + } + + screen->video_init(manager); + screen->run_init(manager, application()); return 0; } diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/sgchangeFB.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/sgchangeFB.cc Thu Dec 10 22:55:55 2009 +0900 @@ -0,0 +1,29 @@ +#include "sgchangeFB.h" +#include "Func.h" +#include "fb.h" + +//extern void post2runLoop(void *); + +void +SgChangeFB::video_init(TaskManager *manager) +{ + Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; + + if (SDL_Init(sdl_flag) < 0) { + fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); + exit(1); + } + + pixels = (Uint32*)get_fbdev_addr(); + + if (pixels == 0) { + pixels = (new Uint32[width*height*32/8]); + } +} + +void +SgChangeFB::clean_pixels() +{ + //bzero(pixels, sizeof(int)*width*height); + //memset(pixels, 0xFF, sizeof(int)*width*height); +} diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/sgchangeFB.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/sgchangeFB.h Thu Dec 10 22:55:55 2009 +0900 @@ -0,0 +1,16 @@ +#ifndef INCLUDED_SGCHANGE_FB +#define INCLUDED_SGCHANGE_FB + +#include "SgChange.h" + +class SgChangeFB : public SgChange { +public: +SgChangeFB(TaskManager *manager, int bpp, int width, int height, int spenum) + :SgChange(bpp, width, height, spenum) {} + + /* override function */ + void video_init(TaskManager *manager); + void clean_pixels(void); +}; + +#endif diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/sgchangeSDL.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/sgchangeSDL.cc Thu Dec 10 22:55:55 2009 +0900 @@ -0,0 +1,60 @@ +#include "sgchangeSDL.h" +#include "Func.h" +#include "TaskManager.h" + +extern void post2runLoop(void *); + +extern + +void +SgChangeSDL::video_init(TaskManager *manager) +{ + Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; + Uint32 *p; + + if (SDL_Init(sdl_flag) < 0) { + fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); + exit(1); + } + + screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); + if (screen == NULL) { + fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); + SDL_Quit(); + exit(1); + } + + p = (Uint32*)manager->allocate(screen->pitch*height); + bitmap = SDL_CreateRGBSurfaceFrom((void *)p, + screen->w, screen->h, + screen->format->BitsPerPixel, + screen->pitch, + redMask, greenMask, blueMask, alphaMask); + + pixels = p; +} + +void +SgChangeSDL::clean_pixels() +{ + //bzero(pixels, sizeof(int)*width*height); + SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); +} + +void +SgChangeSDL::run_loop(HTaskPtr task_next) +{ + SDL_BlitSurface(bitmap, NULL, screen, NULL); + SDL_UpdateRect(screen, 0, 0, 0, 0); + + SgChange::run_loop(task_next); +} + +void +SgChangeSDL::run_finish() +{ + free(bitmap->pixels); + SDL_FreeSurface(bitmap); + + SgChange::run_finish(); +} diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/sgchangeSDL.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/sgchangeSDL.h Thu Dec 10 22:55:55 2009 +0900 @@ -0,0 +1,21 @@ +#ifndef INCLUDED_SGCHANGE_SDL +#define INCLUDED_SGCHANGE_SDL + +#include "SgChange.h" + +class SgChangeSDL : public SgChange { +public: +SgChangeSDL(TaskManager* manager, int bpp, int width, int height, int spenum) + :SgChange(bpp, width, height, spenum) {} + + SDL_Surface *screen; + SDL_Surface *bitmap; + + /* override function */ + void video_init(TaskManager *manager); + void clean_pixels(); + void run_loop(HTaskPtr task_next); + void run_finish(); +}; + +#endif diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/spe/Makefile --- a/Renderer/Engine/spe/Makefile Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/spe/Makefile Thu Dec 10 22:55:55 2009 +0900 @@ -10,7 +10,7 @@ OBJS = $(SRCS:.cc=.o) CC = spu-g++ -CFLAGS = -O9 -Wall -g -fno-exceptions -fno-rtti #-DDEBUG +CFLAGS = -Wall -g -fno-exceptions -fno-rtti #-DDEBUG INCLUDE = -I$(TOP)/include/TaskManager -I. -I.. LIBS = -L$(TOP)/TaskManager -lspemanager @@ -22,7 +22,7 @@ all: $(TARGET) $(TARGET): $(OBJS) - $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + $(CC) $(OPT) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) clean: rm -f $(TARGET) $(OBJS) diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Engine/viewer.cc --- a/Renderer/Engine/viewer.cc Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Engine/viewer.cc Thu Dec 10 22:55:55 2009 +0900 @@ -105,7 +105,7 @@ sgroot = new SceneGraphRoot(this->width, this->height); sgroot->tmanager = manager; - + int size = 4; light_xyz[0] = 0.0f; diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Test/Makefile.cell --- a/Renderer/Test/Makefile.cell Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Test/Makefile.cell Thu Dec 10 22:55:55 2009 +0900 @@ -20,7 +20,7 @@ run: $(TARGET) sudo ./$(TARGET) -width 576 -height 384 -bpp 32 run-hd: $(TARGET) - sudo /usr/bin/ps3-video-mode -v 133 + sudo ps3-video-mode -v 133 sudo ./$(TARGET) -video fb -width 1920 -height 1080 -bpp 32 diff -r 9c8dd6026022 -r be44ada665e9 Renderer/Test/SgRootChange.cc --- a/Renderer/Test/SgRootChange.cc Mon Dec 07 12:39:34 2009 +0900 +++ b/Renderer/Test/SgRootChange.cc Thu Dec 10 22:55:55 2009 +0900 @@ -4,8 +4,18 @@ #include "MainLoop.h" #include "SgRootChange.h" +static void +ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) +{ + printf("test\n"); +} - +static void +ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + printf("collision\n"); +} // prototype MainLoopPtr @@ -18,18 +28,10 @@ SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h) { SceneGraphPtr ball; - SceneGraphPtr cube; - SceneGraphRoot *sg_buff_A = sgroot->sgroot_A; - SceneGraphRoot *sg_buff_B = sgroot->sgroot_B; - - sg_buff_A->createFromXMLfile(sgroot->manager, "xml_file/Ball.xml"); - sg_buff_B->createFromXMLfile(sgroot->manager, "xml_file/cube.xml"); - - ball = sgroot->sgroot_A->createSceneGraph("Ball"); - cube = sgroot->sgroot_B->createSceneGraph("Cube"); - - sgroot->sgroot_A->setSceneData(ball); - sgroot->sgroot_B->setSceneData(cube); + sgroot->createFromXMLfile("xml_file/Ball.xml"); + ball = sgroot->createSceneGraph("Ball"); + ball->set_move_collision(ball_move, ball_collision); + sgroot->setSceneData(ball); return sgroot; } diff -r 9c8dd6026022 -r be44ada665e9 TaskManager/Makefile.def --- a/TaskManager/Makefile.def Mon Dec 07 12:39:34 2009 +0900 +++ b/TaskManager/Makefile.def Thu Dec 10 22:55:55 2009 +0900 @@ -32,7 +32,11 @@ SIMPLE_TASK=-DSIMPLE_TASK # SIMPLE_TASK= +<<<<<<< local # OPT = -O9 +======= +#OPT = -O9 +>>>>>>> other OPT = -g CC = g++