Mercurial > hg > Game > Cerium
diff TaskManager/Test/test_render/spe/DrawSpan.cpp @ 193:1ff24ca2f016 draft
fix
author | gongo@localhost.localdomain |
---|---|
date | Tue, 13 Jan 2009 19:06:13 +0900 |
parents | 6694da357750 |
children | b56fb6ac2fc4 |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/spe/DrawSpan.cpp Tue Jan 13 10:41:05 2009 +0900 +++ b/TaskManager/Test/test_render/spe/DrawSpan.cpp Tue Jan 13 19:06:13 2009 +0900 @@ -9,11 +9,18 @@ #define SPAN_PACK_LOAD 0 #define TEX_LOAD 1 +#define FB_STORE 2 SchedDefineTask(DrawSpan); +DrawSpan::~DrawSpan(void) +{ + smanager->dma_wait(FB_STORE); + free((void*)((int)linebuf*doneWrite)); +} + /** - * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する + * 鴻cTEXTURE_SPLIT_PIXEL^2 蚊 * * +---+---+---+---+---+---+ * | 0 | 1 | 2 | 3 | 4 | 5 | @@ -29,13 +36,13 @@ * | | | | | |35 | * +---+---+---+---+---+---+ * - * 一辺を TEXTURE_SPLIT とする - * 各ブロックの数字がブロックIDとなる。 + * 筝莨冴 TEXTURE_SPLIT + * 医ID */ /** - * テクスチャの座標から、 - * テクスチャのどのブロックかを求める + * 鴻c綺ф + * 鴻c羆 * * @param[in] tx X coordinates of texture * @param[in] tx Y coordinates of texture @@ -54,13 +61,13 @@ } /** - * block ID と、テクスチャの TOP address から - * (tx,ty) で使われるテクスチャの Tile addres を求める + * block ID 鴻c TOP address + * (tx,ty) т戎鴻c Tile addres 羆 * * @param[in] tx X coordinates of texture * @param[in] tx Y coordinates of texture * @param[in] tw Width of texture - * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address + * @param[in] tex_addr_top (tx,ty) т戎鴻caddress * @return block ID */ uint32* @@ -70,19 +77,52 @@ return tex_addr_top + block*TEXTURE_BLOCK_SIZE; } -void -DrawSpan::linebuf_init(int *buf, int x, int rgb) +/** + * FrameBuffer 吾莨若 rgb + * + * @param width Width of Buffer + * @param height Height of Buffer + * @param rgb Initial value of RGB at Buffer + * @return Buffer + */ +int* +DrawSpan::linebuf_init(int width, int height, int rgb) { - for (int i = 0; i < x; i++) { + int *buf = (int*)smanager->allocate(sizeof(int)*width*height); + + for (int i = 0; i < width*height; i++) { buf[i] = rgb; } + + return buf; } /** - * Span が使う Texture Tile があるか + * Z-Buffer * - * @retval != NULL 存在する - * @retval NULL 存在しない + * @param width Width of Z-Buffer + * @param height Height of Z-Buffer + * @return Z-Buffer + */ +float* +DrawSpan::zRow_init(int width, int height) +{ + float *buf = (float*)smanager->allocate(sizeof(float)*width*height); + float def = 65535.0f; + + for (int i = 0; i < width*height; i++) { + buf[i] = def; + } + + return buf; +} + + +/** + * Span 篏帥 Texture Tile + * + * @retval != NULL 絖 + * @retval NULL 絖 */ TilePtr DrawSpan::isAvailableTile(uint32 *addr) @@ -95,22 +135,18 @@ { TilePtr tile; - if (!isAvailableTile(addr)) { - tile = tileList->nextTile(); - /** - * FIFO なので、もし前のが残っていれば削除 - */ - hash->remove(tile->texture_addr); - - tile->texture_addr = addr; - - hash->put(tile->texture_addr, tile); - - smanager->dma_load(tile->pixel, (uint32)addr, - sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD); - - //smanager->dma_wait(TEX_LOAD); - } + tile = tileList->nextTile(); + /** + * FIFO с罧c医 + */ + hash->remove(tile->texture_addr); + + tile->texture_addr = addr; + + hash->put(tile->texture_addr, tile); + + smanager->dma_load(tile->pixel, (uint32)addr, + sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD); } void @@ -118,16 +154,16 @@ { uint32 start = (uint32)addr; uint32 end = (uint32)max_addr; - uint32 length = end-start; - uint32 diff = sizeof(uint32)*TEXTURE_BLOCK_SIZE; - uint32 max_tile = 16; - - for (uint32 i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) { + int length = (int)end-start; + int diff = sizeof(int)*TEXTURE_BLOCK_SIZE; + int max_tile = 16; + + for (int i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) { set_rgb((uint32*)(start + i)); } } -Uint32 +uint32 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) { TilePtr tile; @@ -137,93 +173,99 @@ } /** - * DrawSpan の再起動 (DrawSpanRenew 生成) + * DrawSpan 莎桁 (DrawSpanRenew ) * - * @param[in] spack 現在処理している SpanPack - * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で - * どこまで進んでいるか + * @param[in] spack 憜 SpanPack + * @param[in] cur_span_x span->length_x != 1 Span + * 障ч蚊с */ void DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) { + DrawSpanArgPtr args = + (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); - int rangey = smanager->get_param(2); + + // 違紊ф篏ф検 + args->display = smanager->get_param(0); + args->screen_width = smanager->get_param(1); + args->rangex_start = smanager->get_param(2); + args->rangex_end = smanager->get_param(3); + args->rangey = smanager->get_param(4); + renew_task->add_param((int)args); /** - * 共通の outData, param はそのまま渡す - */ - for (int i = 0; i < rangey; i++) { - renew_task->add_outData(smanager->get_outputAddr(i), - smanager->get_outputSize(i)); - } - - // rangex_start, rangex_end, rangey - renew_task->add_param(smanager->get_param(0)); - renew_task->add_param(smanager->get_param(1)); - renew_task->add_param(smanager->get_param(2)); - - /** - * SpanPack は続きから開始するので、 - * 現在の状態をコピーしておく。 - * spack は rbuf から取得してる可能性があり - * rbuf はシステムが自動的に free() するため - * アドレスだけ渡すのはNG + * SpanPack 膓紮с + * 憜倶潟若 + * spack rbuf 緇醇с + * rbuf 激鴻 free() + * ≪鴻羝<NG */ SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); memcpy(curr, spack, sizeof(SpanPack)); renew_task->add_param((int)curr); renew_task->add_param(cur_span_x); - fprintf(stderr, "[%p] start %u\n", - curr, spu_readch(SPU_RdDec)); + // linebuf zRow 綣膓 + renew_task->add_param((int)linebuf); + renew_task->add_param((int)zRow); + + //fprintf(stderr, "[%p] start %u\n", curr, spu_readch(SPU_RdDec)); /** - * 再起動したタスクを待つ + * 莎桁帥鴻緇 */ smanager->wait_task(renew_task); - // next_spack は free() するので wait する + // next_spack free() wait smanager->dma_wait(SPAN_PACK_LOAD); } +void +DrawSpan::writebuffer(unsigned int display, int buf_width, int height, + int screen_width) +{ + for (int i = 0; i < height; i++) { + smanager->dma_store(&linebuf[i*buf_width], + display + (sizeof(int)*screen_width*i), + sizeof(int)*buf_width, FB_STORE); + } + + doneWrite = 1; +} + int DrawSpan::run(void *rbuf, void *wbuf) { + SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); + SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + SpanPackPtr free_spack = next_spack; // next_spack free() + Span *span; + + uint32 display = smanager->get_param(0); + int screen_width = smanager->get_param(1); + int rangex_start = smanager->get_param(2); + int rangex_end = smanager->get_param(3); + + // 帥鴻綵 x 膀 + int rangex = rangex_end - rangex_start + 1; + + // y 膀 + int rangey = smanager->get_param(4); + hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); - int rangex_start = smanager->get_param(0); - int rangex_end = smanager->get_param(1); - - // このタスクが担当する x の範囲 - int rangex = rangex_end - rangex_start + 1; - - // y の範囲 (render_y + rangey - 1) - int rangey = smanager->get_param(2); - - float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey); + zRow = zRow_init(rangex, rangey); + linebuf = linebuf_init(rangex, rangey, 0xffffffff); - for (int i = 0; i < rangex*rangey; i++) { - zRow[i] = 65535.0f; - } - - int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); - - for (int i = 0; i < rangey; i++) { - linebuf[i] = (int*)smanager->get_output(i); - linebuf_init(linebuf[i], rangex, 0xffffffff); - } - - SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); - SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - SpanPackPtr free_spack = next_spack; // next_spack の free() 用 - Span *span; + doneWrite = 0; do { /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う + * SpanPack->next 絖翫 + * 憜 SpanPack + * 罨< SpanPack DMA 荵∫茵 */ if (spack->next != NULL) { smanager->dma_load(next_spack, (uint32)spack->next, @@ -235,22 +277,22 @@ for (int t = 0; t < spack->info.size; t++) { span = &spack->span[t]; - Uint32 rgb = 0x00ff00; + uint32 rgb = 0x0000ff00; float tex1 = span->tex_x1; float tex2 = span->tex_x2; float tey1 = span->tex_y1; float tey2 = span->tex_y2; /** - * Span が持つ 1 pixel 毎の - * テクスチャの座標 + * Span 1 pixel 罸 + * 鴻c綺ф */ int tex_xpos; int tex_ypos; /** - * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と - * そのブロックのアドレス(MainMemory) + * (tex_xpos, tex_ypos) (筝喝)с綺ф + * ≪(MainMemory) */ int tex_localx; int tex_localy; @@ -262,7 +304,7 @@ float z = span->start_z; float zpos = span->end_z; - // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + // 綺ф [0 .. split_screen_w-1] ャ x,y -1 int localx = getLocalX(x-1); int localy = getLocalY(y-1); @@ -274,30 +316,21 @@ tex_xpos = (int)((span->tex_width-1) * tex1); tex_ypos = (int)((span->tex_height-1) * tey1); - if (zpos < zRow[localx + (rangex * localy)]) { + if (zpos < zRow[localx + (rangex*localy)]) { tex_addr = getTile(tex_xpos, tex_ypos, span->tex_width, span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - /** - * Tile が無い場合、一旦タスクはここで中断し、 - * Tile をロードするタスクを走らせた後に再起動する - */ if (!isAvailableTile(tex_addr)) { - spack->info.start = t; set_rgb(tex_addr); - //set_rgbs(tex_addr, - //getTile(span->tex_width-1, tex_ypos, - //span->tex_width, span->tex_addr)); - //reboot(spack, 0); - //goto FINISH; + smanager->dma_wait(TEX_LOAD); } rgb = get_rgb(tex_localx, tex_localy, tex_addr); - zRow[localx + (rangex * localy)] = zpos; - linebuf[localy][localx] = rgb; + zRow[localx + (rangex*localy)] = zpos; + linebuf[localx + (rangex*localy)] = rgb; } } else { int js = (x < rangex_start) ? rangex_start - x : 0; @@ -324,20 +357,29 @@ tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + /** + * Tile <翫筝帥鴻т賢 + * Tile 若帥鴻莎違緇莎桁 + */ if (!isAvailableTile(tex_addr)) { spack->info.start = t; - //set_rgb(tex_addr); +#if 1 set_rgbs(tex_addr, getTile(span->tex_width-1, tex_ypos, span->tex_width, span->tex_addr)); + //smanager->dma_wait(TEX_LOAD); reboot(spack, j); goto FINISH; +#else + set_rgb(tex_addr); + smanager->dma_wait(TEX_LOAD); +#endif } rgb = get_rgb(tex_localx, tex_localy, tex_addr); zRow[localx + (rangex*localy)] = tex_z; - linebuf[localy][localx] = rgb; + linebuf[localx + (rangex*localy)] = rgb; } } } @@ -350,11 +392,19 @@ next_spack = tmp_spack; } while (spack); + writebuffer(display, rangex, rangey, screen_width); + + // linebuf writebuffer() dma_store wait + // DrawSpan::~DrawSpan() free + //free(linebuf); + free(zRow); FINISH: + /** + * goto FINISH; reboot + * linebuf, zRow free() + */ free(free_spack); - free(linebuf); - free(zRow); return 0; }