Mercurial > hg > Members > kono > Cerium
changeset 352:3f5289873643
add global_alloc.h
author | admin@mb22-no-macbook-2.local |
---|---|
date | Mon, 13 Jul 2009 19:25:10 +0900 |
parents | 852d7ba57be2 |
children | f0c89b2b1105 |
files | TaskManager/Test/test_render/global_alloc.h TaskManager/Test/test_render/spe/DrawSpan.cpp TaskManager/Test/test_render/spe/DrawSpanRenew.cpp TaskManager/Test/test_render/spe/Load_Texture.cpp TaskManager/Test/test_render/spe/Set_Texture.cpp TaskManager/Test/test_render/spe/TileHash.cpp TaskManager/Test/test_render/spe/TileHash.h TaskManager/Test/test_render/spe/texture.h TaskManager/Test/test_render/task/DrawSpan.cpp TaskManager/Test/test_render/task/DrawSpanRenew.cpp TaskManager/Test/test_render/task/Load_Texture.cpp TaskManager/Test/test_render/task/Set_Texture.cpp TaskManager/Test/test_render/task/TileHash.h TaskManager/Test/test_render/task/texture.h |
diffstat | 14 files changed, 591 insertions(+), 566 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/global_alloc.h Mon Jul 13 19:25:10 2009 +0900 @@ -0,0 +1,11 @@ +/*! + global_alloc 用の ID + + */ +enum global_allocate_id { + + TEXTURE_ID, + GLOBAL_TEXTURE_HASH, + GLOBAL_TILE_LIST, + +};
--- a/TaskManager/Test/test_render/spe/DrawSpan.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/DrawSpan.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -9,6 +9,7 @@ #include "texture.h" #include "viewer_types.h" #include "Func.h" +#include "global_alloc.h" SchedDefineTask(DrawSpan); @@ -120,7 +121,7 @@ int *buf = (int*)smanager->allocate(sizeof(int)*width*height); for (int i = 0; i < width*height; i++) { - buf[i] = rgb; + buf[i] = rgb; } return buf; @@ -141,16 +142,16 @@ #if 0 for (int i = 0; i < width*height; i++) { - buf[i] = def; + buf[i] = def; } -#else +#else vector float init = spu_splats(0.0f); vector float defi = spu_splats(def); for (int i = 0; i < width*height; i += 4) { - vector float *out = (vector float *)&buf[i]; + vector float *out = (vector float *)&buf[i]; - *out = spu_add(init, defi); + *out = spu_add(init, defi); } #endif @@ -175,25 +176,29 @@ { TilePtr tile; +#if 0 if (isAvailableTile(addr)) { - return; + return; } +#endif 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, tag); + sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); } +#if 0 + /** - * + * */ void DrawSpan::set_rgbs(uint32 *cur_addr, uint32 *max_addr, int wait_tag) @@ -211,16 +216,19 @@ startp = cmp*maxp + !cmp*curp; #else if (length < 0) { - length = -length; - startp = maxp; + length = -length; + startp = maxp; } #endif for (int i = 0; i <= length; i += diff) { - set_rgb((uint32*)(startp + i), wait_tag); + if (!isAvailableTile((uint32*)(startp + i)) { + set_rgb((uint32*)(startp + i), wait_tag); } } +#endif + uint32 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) { @@ -241,7 +249,7 @@ DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) { DrawSpanArgPtr args = - (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); + (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); // 数が多いので構造体で渡す @@ -258,7 +266,7 @@ * spack は rbuf から取得してる可能性があり * rbuf はシステムが自動的に free() するため * アドレスだけ渡すのはNG - */ + */ SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); memcpy(curr, spack, sizeof(SpanPack)); renew_task->add_param((int)curr); @@ -270,7 +278,7 @@ /** * 再起動したタスクを待つ - */ + */ smanager->wait_task(renew_task); // next_spack は free() するので wait する @@ -279,12 +287,12 @@ void DrawSpan::writebuffer(unsigned int display, int buf_width, int height, - int screen_width) + 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); + smanager->dma_store(&linebuf[i*buf_width], + display + (sizeof(int)*screen_width*i), + sizeof(int)*buf_width, FB_STORE); } doneWrite = 1; @@ -303,10 +311,10 @@ */ void DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, - int tex_x, int tex_y, uint32 *tex_addr) + int tex_x, int tex_y, uint32 *tex_addr) { int rgb = get_rgb(tex_x, tex_y, tex_addr); - + zRow[x + (rangex*y)] = zpos; linebuf[x + (rangex*y)] = rgb; } @@ -346,26 +354,26 @@ uint32 *tex_addr; if (span->x < startx || endx < span->x) { - return -1; + return -1; } tex_xpos = (int)((span->tex_width-1) * tex); tex_ypos = (int)((span->tex_height-1) * tey); 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; + 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; - if (!isAvailableTile(tex_addr)) { - set_rgb(tex_addr, wait_tag); - smanager->dma_wait(wait_tag); - //return startx; - } + if (!isAvailableTile(tex_addr)) { + set_rgb(tex_addr, wait_tag); + smanager->dma_wait(wait_tag); + //return startx; + } - updateBuffer(zpos, rangex, localx, localy, - tex_localx, tex_localy, tex_addr); + updateBuffer(zpos, rangex, localx, localy, + tex_localx, tex_localy, tex_addr); } return -1; @@ -388,7 +396,7 @@ * 今は drawLine1 で load -> wait -> rendering を全部やってます * (rendering といっても、rendering buffer に書き込むだけで * まだ main memory (frame buffer) に dma store してるわけではない) - * + * * @param span Span * @param startx 描画開始範囲 * @param endx 描画終了範囲 @@ -426,57 +434,57 @@ //for (int j = js; j <= je; j++) { for (int j = je; j >= js; j--) { - float tex_x, tex_y, tex_z; + float tex_x, tex_y, tex_z; - localx = getLocalX(x-1+j); + localx = getLocalX(x-1+j); - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < zRow[localx + (rangex*localy)]) { - // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と - // そのブロックのアドレス(MainMemory) - uint32 *tex_addr; - int tex_localx; - int tex_localy; + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と + // そのブロックのアドレス(MainMemory) + uint32 *tex_addr; + int tex_localx; + int tex_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; + 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; - if (!isAvailableTile(tex_addr)) { + if (!isAvailableTile(tex_addr)) { #if 0 - // span が必要とするであろう tile を予想紙 - // set_rgbs で複数同時に load しようとしている図 - // まあ上手くいかなかったんだけど。。 - tex_x = tex1*(x_len-1-js)/(x_len-1) + tex2*js/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); + // span が必要とするであろう tile を予想紙 + // set_rgbs で複数同時に load しようとしている図 + // まあ上手くいかなかったんだけど。。 + tex_x = tex1*(x_len-1-js)/(x_len-1) + tex2*js/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); - uint32 *max_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + uint32 *max_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); - set_rgbs(tex_addr, max_addr, wait_tag); - return js; + set_rgbs(tex_addr, max_addr, wait_tag); + return js; #else - set_rgb(tex_addr, wait_tag); - smanager->dma_wait(wait_tag); + set_rgb(tex_addr, wait_tag); + smanager->dma_wait(wait_tag); #endif - } + } - updateBuffer(tex_z, rangex, localx, localy, - tex_localx, tex_localy, tex_addr); - } + updateBuffer(tex_z, rangex, localx, localy, + tex_localx, tex_localy, tex_addr); + } } return ret; @@ -532,29 +540,29 @@ smanager->dma_wait(wait_tag); for (int j = js; j <= je; j++) { - localx = getLocalX(x-1+j); + localx = getLocalX(x-1+j); - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); - if (tex_z < 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; + if (tex_z < 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; - updateBuffer(tex_z, rangex, localx, localy, - tex_localx, tex_localy, tex_addr); - } - } + updateBuffer(tex_z, rangex, localx, localy, + tex_localx, tex_localy, tex_addr); + } + } } int @@ -570,18 +578,18 @@ nop_span.length_x = 1; int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { - &DrawSpan::drawDot1, &DrawSpan::drawLine1 + &DrawSpan::drawDot1, &DrawSpan::drawLine1 }; void (DrawSpan::*drawFunc2[2])(SpanPtr, int, int, int, int) = { - &DrawSpan::drawDot2, &DrawSpan::drawLine2 + &DrawSpan::drawDot2, &DrawSpan::drawLine2 }; 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); - + int rangex_end = smanager->get_param(3); + // このタスクが担当する x の範囲 int rangex = rangex_end - rangex_start + 1; @@ -600,60 +608,60 @@ int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; int tl_tag_flg1 = 0; int tl_tag_flg2 = 1; - + do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } - SpanPtr resume_span = &nop_span; - int resume_span_x = 0; + SpanPtr resume_span = &nop_span; + int resume_span_x = 0; - for (int t = 0; t < spack->info.size; t++) { - SpanPtr next_span; - int next_span_x; + for (int t = 0; t < spack->info.size; t++) { + SpanPtr next_span; + int next_span_x; - span = &spack->span[t]; + span = &spack->span[t]; - /** - * span の長さによって、drawLine か drawDot を選択している - */ - next_span_x - = (this->*drawFunc1[(span->length_x != 1)])( - span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); - next_span = span; + /** + * span の長さによって、drawLine か drawDot を選択している + */ + next_span_x + = (this->*drawFunc1[(span->length_x != 1)])( + span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); + next_span = span; - (this->*drawFunc2[(resume_span->length_x != 1)])( - resume_span, rangex_start, rangex_end, resume_span_x, - tl_tag[tl_tag_flg2]); + (this->*drawFunc2[(resume_span->length_x != 1)])( + resume_span, rangex_start, rangex_end, resume_span_x, + tl_tag[tl_tag_flg2]); + + resume_span = next_span; + resume_span_x = next_span_x; - resume_span = next_span; - resume_span_x = next_span_x; - - //smanager->dma_wait(tl_tag[tl_tag_flg1]); + //smanager->dma_wait(tl_tag[tl_tag_flg1]); + + tl_tag_flg1 ^= 1; + tl_tag_flg2 ^= 1; + } - tl_tag_flg1 ^= 1; - tl_tag_flg2 ^= 1; - } - - // 現在 drawLine2、drawDot2 は機能してないので - //(this->*drawFunc2[(resume_span->length_x != 1)])( - //resume_span, rangex_start, rangex_end, resume_span_x, - //tl_tag[tl_tag_flg1]); + // 現在 drawLine2、drawDot2 は機能してないので + //(this->*drawFunc2[(resume_span->length_x != 1)])( + //resume_span, rangex_start, rangex_end, resume_span_x, + //tl_tag[tl_tag_flg1]); - smanager->dma_wait(SPAN_PACK_LOAD); + smanager->dma_wait(SPAN_PACK_LOAD); - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; } while (spack); writebuffer(display, rangex, rangey, screen_width);
--- a/TaskManager/Test/test_render/spe/DrawSpanRenew.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/DrawSpanRenew.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -10,6 +10,7 @@ #include "texture.h" #include "viewer_types.h" #include "Func.h" +#include "global_alloc.h" #define SPAN_PACK_LOAD 0 #define TEX_LOAD 1 @@ -37,7 +38,7 @@ /** * 再起動したタスクを待つ - */ + */ smanager->wait_task(renew_task); // next_spack は free() するので wait する @@ -68,7 +69,7 @@ hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); - + linebuf = (int*)smanager->get_param(3); zRow = (float*)smanager->get_param(4); @@ -82,137 +83,137 @@ smanager->dma_wait(TEX_LOAD); do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } - for (int t = spack->info.start; t < spack->info.size; t++) { - span = &spack->span[t]; + for (int t = spack->info.start; t < spack->info.size; t++) { + span = &spack->span[t]; - uint32 rgb = 0x00ff0000; - float tex1 = span->tex_x1; - float tex2 = span->tex_x2; - float tey1 = span->tex_y1; - float tey2 = span->tex_y2; + uint32 rgb = 0x00ff0000; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; - /** - * Span が持つ 1 pixel 毎の - * テクスチャの座標 - */ - int tex_xpos; - int tex_ypos; + /** + * Span が持つ 1 pixel 毎の + * テクスチャの座標 + */ + int tex_xpos; + int tex_ypos; - /** - * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と - * そのブロックのアドレス(MainMemory) - */ - int tex_localx; - int tex_localy; - uint32 *tex_addr; + /** + * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + uint32 *tex_addr; - int x = span->x; - int y = span->y; - int x_len = span->length_x; - float z = span->start_z; - float zpos = span->end_z; + int x = span->x; + int y = span->y; + int x_len = span->length_x; + float z = span->start_z; + float zpos = span->end_z; + + // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + int localx = getLocalX(x-1); + int localy = getLocalY(y-1); - // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 - int localx = getLocalX(x-1); - int localy = getLocalY(y-1); + if (x_len == 1) { + if (x < rangex_start || rangex_end < x) { + continue; + } - if (x_len == 1) { - if (x < rangex_start || rangex_end < x) { - continue; - } + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); - tex_xpos = (int)((span->tex_width-1) * tex1); - tex_ypos = (int)((span->tex_height-1) * tey1); + 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; - 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; + if (!isAvailableTile(tex_addr)) { + set_rgb(tex_addr, 0); + smanager->dma_wait(0); + } - if (!isAvailableTile(tex_addr)) { - set_rgb(tex_addr, 0); - smanager->dma_wait(0); - } - - rgb = get_rgb(tex_localx, tex_localy, tex_addr); + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex*localy)] = zpos; + linebuf[localx + (rangex*localy)] = rgb; + } + } else { + int js = (x < rangex_start) ? rangex_start - x : 0; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; + float tex_x, tex_y, tex_z; - zRow[localx + (rangex*localy)] = zpos; - linebuf[localx + (rangex*localy)] = rgb; - } - } else { - int js = (x < rangex_start) ? rangex_start - x : 0; - int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; - float tex_x, tex_y, tex_z; - - /** - * 一回比較すれば、以後再起動するまでは - * js_cont は使わないから 0 にしてるわけだけど、 - * 最初の一回のためだけにこれはめんどくさいのー。 - */ - js = (js < js_cont) ? js_cont : js; - js_cont = 0; + /** + * 一回比較すれば、以後再起動するまでは + * js_cont は使わないから 0 にしてるわけだけど、 + * 最初の一回のためだけにこれはめんどくさいのー。 + */ + js = (js < js_cont) ? js_cont : js; + js_cont = 0; + + for (int j = js; j <= je; j++) { + localx = getLocalX(x-1+j); - for (int j = js; j <= je; j++) { - localx = getLocalX(x-1+j); + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); - tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < 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; + if (tex_z < 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; - if (!isAvailableTile(tex_addr)) { - spack->info.start = t; + if (!isAvailableTile(tex_addr)) { + spack->info.start = t; #if 0 - set_rgbs(tex_addr, - getTile(span->tex_width-1, tex_ypos, - span->tex_width, span->tex_addr)); - reboot(spack, j); - goto FINISH; + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, j); + goto FINISH; #else - set_rgb(tex_addr, TEX_LOAD); - smanager->dma_wait(TEX_LOAD); + set_rgb(tex_addr, TEX_LOAD); + smanager->dma_wait(TEX_LOAD); #endif - } - - rgb = get_rgb(tex_localx, tex_localy, tex_addr); - - zRow[localx + (rangex*localy)] = tex_z; - linebuf[localx + (rangex*localy)] = rgb; - } - } - } - } + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); - smanager->dma_wait(SPAN_PACK_LOAD); + zRow[localx + (rangex*localy)] = tex_z; + linebuf[localx + (rangex*localy)] = rgb; + } + } + } + } - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; } while (spack); writebuffer(display, rangex, rangey, screen_width);
--- a/TaskManager/Test/test_render/spe/Load_Texture.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/Load_Texture.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -7,6 +7,7 @@ #include "texture.h" #include "TileHash.h" #include "Func.h" +#include "global_alloc.h" SchedDefineTask(LoadTexture); @@ -14,8 +15,8 @@ * 「Load」といいながら、結局 DrawSpan で使う * Hash の準備だけなので、名前変えないとなー */ -int -LoadTexture::run(void *rbuf , void *wbuf) +int +LoadTexture::run(void *rbuf , void *wbuf) { __debug_spe("LoadTexture\n"); /** @@ -23,11 +24,11 @@ * コンストラクタ呼ぶために placement new してます。 */ void *hash_tmp - = smanager->global_alloc(GLOBAL_TEXTURE_HASH, sizeof(TileHash)); + = smanager->global_alloc(GLOBAL_TEXTURE_HASH, sizeof(TileHash)); new(hash_tmp) TileHash; void *tileList_tmp - = smanager->global_alloc(GLOBAL_TILE_LIST, sizeof(TileList)); + = smanager->global_alloc(GLOBAL_TILE_LIST, sizeof(TileList)); new(tileList_tmp) TileList; return 0;
--- a/TaskManager/Test/test_render/spe/Set_Texture.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/Set_Texture.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -1,34 +1,34 @@ // #define DEBUG #include "error.h" - #include <string.h> #include "Set_Texture.h" #include "texture.h" +#include "global_alloc.h" SchedDefineTask(SetTexture); //texture をglobal 領域にコピーするタスク -int +int SetTexture::run(void *rbuf, void *wbuf) { __debug_spe("SetTexture\n"); void *src[4]; - + src[0] = get_input(rbuf, 0); src[1] = get_input(rbuf, 1); src[2] = get_input(rbuf, 2); src[3] = get_input(rbuf, 3); - + if (global_get(TEXTURE_ID)) { - return 0; + return 0; } else { - //タスクが共有できる領域確保 - void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); + //タスクが共有できる領域確保 + void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); - memcpy(data, src[0], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); + memcpy(data, src[0], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); } return 0;
--- a/TaskManager/Test/test_render/spe/TileHash.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/TileHash.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -15,9 +15,9 @@ int key; for (int i = 0; i < 8; i ++) { - key = data & 0xf; - value += key * PRIME[n++]; - data >>= 4; + key = data & 0xf; + value += key * PRIME[n++]; + data >>= 4; } return value % hashSize; @@ -25,8 +25,8 @@ TileHash::TileHash(void) { - hashSize = 263; - tableSize = sizeof(TilePtr)*hashSize; + //hashSize = 263; + //tableSize = sizeof(TilePtr)*hashSize; table = (TilePtr*)malloc(tableSize); clear(); @@ -38,12 +38,12 @@ int hashval = hash((uint32)key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; + int index = (hashval + i*i)%hashSize; - if (table[index] == 0) { // 空の table に入れる - table[index] = data; - return index; - } + if (table[index] == 0) { // 空の table に入れる + table[index] = data; + return index; + } } return -1; @@ -55,12 +55,12 @@ int hashval = hash((uint32)key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->texture_addr == key) { - return table[index]; - } + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->texture_addr == key) { + return table[index]; + } } return NULL; @@ -72,12 +72,12 @@ int hashval = hash((uint32)key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->texture_addr == key) { - table[index] = NULL; - } + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->texture_addr == key) { + table[index] = NULL; + } } }
--- a/TaskManager/Test/test_render/spe/TileHash.h Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/TileHash.h Mon Jul 13 19:25:10 2009 +0900 @@ -11,8 +11,6 @@ private: TilePtr *table; - int hashSize; - int tableSize; public: void clear(void); @@ -26,5 +24,7 @@ #endif -const int GLOBAL_TEXTURE_HASH = 0; -const int GLOBAL_TILE_LIST = 1; +const int hashSize = 263; +const int tableSize = sizeof(TilePtr)*hashSize; + +
--- a/TaskManager/Test/test_render/spe/texture.h Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/spe/texture.h Mon Jul 13 19:25:10 2009 +0900 @@ -1,3 +1,2 @@ #define MAX_LOAD_SIZE 16384 -#define TEXTURE_ID 0 #define TEXTURE2_ID 13
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -6,6 +6,7 @@ #include "viewer_types.h" #include "Func.h" #include "sys.h" +#include "global_alloc.h" SchedDefineTask(DrawSpan); @@ -92,7 +93,7 @@ int *buf = (int*)smanager->allocate(sizeof(int)*width*height); for (int i = 0; i < width*height; i++) { - buf[i] = rgb; + buf[i] = rgb; } return buf; @@ -112,7 +113,7 @@ float def = 65535.0f; for (int i = 0; i < width*height; i++) { - buf[i] = def; + buf[i] = def; } return buf; @@ -136,25 +137,28 @@ { TilePtr tile; +#if 0 if (isAvailableTile(addr)) { - return; + return; } +#endif 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, tag); + sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); } +#if 0 /** - * + * */ void DrawSpan::set_rgbs(uint32 *cur_addr, uint32 *max_addr, int wait_tag) @@ -172,15 +176,16 @@ startp = cmp*maxp + !cmp*curp; #else if (length < 0) { - length = -length; - startp = maxp; + length = -length; + startp = maxp; } #endif for (int i = 0; i <= length; i += diff) { - set_rgb((uint32*)(startp + i), wait_tag); + set_rgb((uint32*)(startp + i), wait_tag); } } +#endif uint32 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) @@ -202,7 +207,7 @@ DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) { DrawSpanArgPtr args = - (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); + (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); // 数が多いので構造体で渡す @@ -219,7 +224,7 @@ * spack は rbuf から取得してる可能性があり * rbuf はシステムが自動的に free() するため * アドレスだけ渡すのはNG - */ + */ SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); memcpy(curr, spack, sizeof(SpanPack)); renew_task->add_param((int)curr); @@ -231,7 +236,7 @@ /** * 再起動したタスクを待つ - */ + */ smanager->wait_task(renew_task); // next_spack は free() するので wait する @@ -240,12 +245,12 @@ void DrawSpan::writebuffer(unsigned int display, int buf_width, int height, - int screen_width) + 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); + smanager->dma_store(&linebuf[i*buf_width], + display + (sizeof(int)*screen_width*i), + sizeof(int)*buf_width, FB_STORE); } doneWrite = 1; @@ -263,7 +268,7 @@ * @param tex_addr テクスチャのアドレス(MainMemory) */ void -DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, +DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, float normal_x, float normal_y, float normal_z, uint32 *tex_addr) { @@ -320,26 +325,26 @@ uint32 *tex_addr; if (span->x < startx || endx < span->x) { - return -1; + return -1; } tex_xpos = (int)((span->tex_width-1) * tex); tex_ypos = (int)((span->tex_height-1) * tey); 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; + 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; - if (!isAvailableTile(tex_addr)) { - set_rgb(tex_addr, wait_tag); - smanager->dma_wait(wait_tag); - //return startx; - } + if (!isAvailableTile(tex_addr)) { + set_rgb(tex_addr, wait_tag); + smanager->dma_wait(wait_tag); + //return startx; + } - updateBuffer(zpos, rangex, localx, localy, - tex_localx, tex_localy, + updateBuffer(zpos, rangex, localx, localy, + tex_localx, tex_localy, normal_x,normal_y,normal_z,tex_addr); } @@ -363,7 +368,7 @@ * 今は drawLine1 で load -> wait -> rendering を全部やってます * (rendering といっても、rendering buffer に書き込むだけで * まだ main memory (frame buffer) に dma store してるわけではない) - * + * * @param span Span * @param startx 描画開始範囲 * @param endx 描画終了範囲 @@ -406,58 +411,58 @@ //for (int j = js; j <= je; j++) { for (int j = je; j >= js; j--) { - float tex_x, tex_y, tex_z; + float tex_x, tex_y, tex_z; - localx = getLocalX(x-1+j); + localx = getLocalX(x-1+j); - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < zRow[localx + (rangex*localy)]) { - // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と - // そのブロックのアドレス(MainMemory) - uint32 *tex_addr; - int tex_localx; - int tex_localy; + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と + // そのブロックのアドレス(MainMemory) + uint32 *tex_addr; + int tex_localx; + int tex_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; + 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; - if (!isAvailableTile(tex_addr)) { + if (!isAvailableTile(tex_addr)) { #if 0 - // span が必要とするであろう tile を予想紙 - // set_rgbs で複数同時に load しようとしている図 - // まあ上手くいかなかったんだけど。。 - tex_x = tex1*(x_len-1-js)/(x_len-1) + tex2*js/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); + // span が必要とするであろう tile を予想紙 + // set_rgbs で複数同時に load しようとしている図 + // まあ上手くいかなかったんだけど。。 + tex_x = tex1*(x_len-1-js)/(x_len-1) + tex2*js/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); - uint32 *max_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + uint32 *max_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); - set_rgbs(tex_addr, max_addr, wait_tag); - return js; + set_rgbs(tex_addr, max_addr, wait_tag); + return js; #else - set_rgb(tex_addr, wait_tag); - smanager->dma_wait(wait_tag); + set_rgb(tex_addr, wait_tag); + smanager->dma_wait(wait_tag); #endif - } + } - updateBuffer(tex_z, rangex, localx, localy, - tex_localx, tex_localy, + updateBuffer(tex_z, rangex, localx, localy, + tex_localx, tex_localy, normal_x, normal_y, normal_z,tex_addr); - } + } } return ret; @@ -518,30 +523,30 @@ smanager->dma_wait(wait_tag); for (int j = js; j <= je; j++) { - localx = getLocalX(x-1+j); + localx = getLocalX(x-1+j); - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); - if (tex_z < 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; + if (tex_z < 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; - updateBuffer(tex_z, rangex, localx, localy, - tex_localx, tex_localy, + updateBuffer(tex_z, rangex, localx, localy, + tex_localx, tex_localy, normal_x, normal_y, normal_z,tex_addr); - } - } + } + } } @@ -571,7 +576,7 @@ rgb[0] = rgb[0]*inner_product*flag; rgb[1] = rgb[1]*inner_product*flag; rgb[2] = rgb[2]*inner_product*flag; - + //計算した rgb を light_rgb にまとめる。 light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); @@ -591,18 +596,18 @@ nop_span.length_x = 1; int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { - &DrawSpan::drawDot1, &DrawSpan::drawLine1 + &DrawSpan::drawDot1, &DrawSpan::drawLine1 }; void (DrawSpan::*drawFunc2[2])(SpanPtr, int, int, int, int) = { - &DrawSpan::drawDot2, &DrawSpan::drawLine2 + &DrawSpan::drawDot2, &DrawSpan::drawLine2 }; 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); - + int rangex_end = smanager->get_param(3); + // このタスクが担当する x の範囲 int rangex = rangex_end - rangex_start + 1; @@ -621,60 +626,60 @@ int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; int tl_tag_flg1 = 0; int tl_tag_flg2 = 1; - + do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } - SpanPtr resume_span = &nop_span; - int resume_span_x = 0; + SpanPtr resume_span = &nop_span; + int resume_span_x = 0; - for (int t = 0; t < spack->info.size; t++) { - SpanPtr next_span; - int next_span_x; + for (int t = 0; t < spack->info.size; t++) { + SpanPtr next_span; + int next_span_x; - span = &spack->span[t]; + span = &spack->span[t]; - /** - * span の長さによって、drawLine か drawDot を選択している - */ - next_span_x - = (this->*drawFunc1[(span->length_x != 1)])( - span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); - next_span = span; + /** + * span の長さによって、drawLine か drawDot を選択している + */ + next_span_x + = (this->*drawFunc1[(span->length_x != 1)])( + span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); + next_span = span; - (this->*drawFunc2[(resume_span->length_x != 1)])( - resume_span, rangex_start, rangex_end, resume_span_x, - tl_tag[tl_tag_flg2]); + (this->*drawFunc2[(resume_span->length_x != 1)])( + resume_span, rangex_start, rangex_end, resume_span_x, + tl_tag[tl_tag_flg2]); + + resume_span = next_span; + resume_span_x = next_span_x; - resume_span = next_span; - resume_span_x = next_span_x; - - //smanager->dma_wait(tl_tag[tl_tag_flg1]); + //smanager->dma_wait(tl_tag[tl_tag_flg1]); + + tl_tag_flg1 ^= 1; + tl_tag_flg2 ^= 1; + } - tl_tag_flg1 ^= 1; - tl_tag_flg2 ^= 1; - } - - // 現在 drawLine2、drawDot2 は機能してないので - //(this->*drawFunc2[(resume_span->length_x != 1)])( - //resume_span, rangex_start, rangex_end, resume_span_x, - //tl_tag[tl_tag_flg1]); + // 現在 drawLine2、drawDot2 は機能してないので + //(this->*drawFunc2[(resume_span->length_x != 1)])( + //resume_span, rangex_start, rangex_end, resume_span_x, + //tl_tag[tl_tag_flg1]); - smanager->dma_wait(SPAN_PACK_LOAD); + smanager->dma_wait(SPAN_PACK_LOAD); - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; } while (spack); writebuffer(display, rangex, rangey, screen_width);
--- a/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -6,6 +6,7 @@ #include "texture.h" #include "viewer_types.h" #include "Func.h" +#include "global_alloc.h" #define SPAN_PACK_LOAD 0 #define TEX_LOAD 1 @@ -33,7 +34,7 @@ /** * 再起動したタスクを待つ - */ + */ smanager->wait_task(renew_task); // next_spack は free() するので wait する @@ -63,7 +64,7 @@ hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); - + linebuf = (int*)smanager->get_param(3); zRow = (float*)smanager->get_param(4); @@ -77,137 +78,137 @@ smanager->dma_wait(TEX_LOAD); do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } - for (int t = spack->info.start; t < spack->info.size; t++) { - span = &spack->span[t]; + for (int t = spack->info.start; t < spack->info.size; t++) { + span = &spack->span[t]; - uint32 rgb = 0x00ff0000; - float tex1 = span->tex_x1; - float tex2 = span->tex_x2; - float tey1 = span->tex_y1; - float tey2 = span->tex_y2; + uint32 rgb = 0x00ff0000; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; - /** - * Span が持つ 1 pixel 毎の - * テクスチャの座標 - */ - int tex_xpos; - int tex_ypos; + /** + * Span が持つ 1 pixel 毎の + * テクスチャの座標 + */ + int tex_xpos; + int tex_ypos; - /** - * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と - * そのブロックのアドレス(MainMemory) - */ - int tex_localx; - int tex_localy; - uint32 *tex_addr; + /** + * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + uint32 *tex_addr; - int x = span->x; - int y = span->y; - int x_len = span->length_x; - float z = span->start_z; - float zpos = span->end_z; + int x = span->x; + int y = span->y; + int x_len = span->length_x; + float z = span->start_z; + float zpos = span->end_z; + + // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + int localx = getLocalX(x-1); + int localy = getLocalY(y-1); - // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 - int localx = getLocalX(x-1); - int localy = getLocalY(y-1); + if (x_len == 1) { + if (x < rangex_start || rangex_end < x) { + continue; + } - if (x_len == 1) { - if (x < rangex_start || rangex_end < x) { - continue; - } + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); - tex_xpos = (int)((span->tex_width-1) * tex1); - tex_ypos = (int)((span->tex_height-1) * tey1); + 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; - 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; + if (!isAvailableTile(tex_addr)) { + set_rgb(tex_addr, 0); + smanager->dma_wait(0); + } - if (!isAvailableTile(tex_addr)) { - set_rgb(tex_addr, 0); - smanager->dma_wait(0); - } - - rgb = get_rgb(tex_localx, tex_localy, tex_addr); + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex*localy)] = zpos; + linebuf[localx + (rangex*localy)] = rgb; + } + } else { + int js = (x < rangex_start) ? rangex_start - x : 0; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; + float tex_x, tex_y, tex_z; - zRow[localx + (rangex*localy)] = zpos; - linebuf[localx + (rangex*localy)] = rgb; - } - } else { - int js = (x < rangex_start) ? rangex_start - x : 0; - int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; - float tex_x, tex_y, tex_z; - - /** - * 一回比較すれば、以後再起動するまでは - * js_cont は使わないから 0 にしてるわけだけど、 - * 最初の一回のためだけにこれはめんどくさいのー。 - */ - js = (js < js_cont) ? js_cont : js; - js_cont = 0; + /** + * 一回比較すれば、以後再起動するまでは + * js_cont は使わないから 0 にしてるわけだけど、 + * 最初の一回のためだけにこれはめんどくさいのー。 + */ + js = (js < js_cont) ? js_cont : js; + js_cont = 0; + + for (int j = js; j <= je; j++) { + localx = getLocalX(x-1+j); - for (int j = js; j <= je; j++) { - localx = getLocalX(x-1+j); + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); - tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < 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; + if (tex_z < 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; - if (!isAvailableTile(tex_addr)) { - spack->info.start = t; + if (!isAvailableTile(tex_addr)) { + spack->info.start = t; #if 0 - set_rgbs(tex_addr, - getTile(span->tex_width-1, tex_ypos, - span->tex_width, span->tex_addr)); - reboot(spack, j); - goto FINISH; + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, j); + goto FINISH; #else - set_rgb(tex_addr, TEX_LOAD); - smanager->dma_wait(TEX_LOAD); + set_rgb(tex_addr, TEX_LOAD); + smanager->dma_wait(TEX_LOAD); #endif - } - - rgb = get_rgb(tex_localx, tex_localy, tex_addr); - - zRow[localx + (rangex*localy)] = tex_z; - linebuf[localx + (rangex*localy)] = rgb; - } - } - } - } + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); - smanager->dma_wait(SPAN_PACK_LOAD); + zRow[localx + (rangex*localy)] = tex_z; + linebuf[localx + (rangex*localy)] = rgb; + } + } + } + } - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; } while (spack); writebuffer(display, rangex, rangey, screen_width);
--- a/TaskManager/Test/test_render/task/Load_Texture.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/task/Load_Texture.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -4,6 +4,7 @@ #include "texture.h" #include "TileHash.h" #include "Func.h" +#include "global_alloc.h" SchedDefineTask(LoadTexture); @@ -11,19 +12,19 @@ * 「Load」といいながら、結局 DrawSpan で使う * Hash の準備だけなので、名前変えないとなー */ -int -LoadTexture::run(void *rbuf , void *wbuf) +int +LoadTexture::run(void *rbuf , void *wbuf) { /** * 現在 global_alloc() では new をサポートしてないので * コンストラクタ呼ぶために placement new してます。 */ void *hash_tmp - = smanager->global_alloc(GLOBAL_TEXTURE_HASH, sizeof(TileHash)); + = smanager->global_alloc(GLOBAL_TEXTURE_HASH, sizeof(TileHash)); new(hash_tmp) TileHash; void *tileList_tmp - = smanager->global_alloc(GLOBAL_TILE_LIST, sizeof(TileList)); + = smanager->global_alloc(GLOBAL_TILE_LIST, sizeof(TileList)); new(tileList_tmp) TileList; return 0;
--- a/TaskManager/Test/test_render/task/Set_Texture.cpp Fri Jul 10 18:20:26 2009 +0900 +++ b/TaskManager/Test/test_render/task/Set_Texture.cpp Mon Jul 13 19:25:10 2009 +0900 @@ -1,30 +1,31 @@ #include <string.h> #include "Set_Texture.h" #include "texture.h" +#include "global_alloc.h" SchedDefineTask(SetTexture); //texture をglobal 領域にコピーするタスク -int +int SetTexture::run(void *rbuf, void *wbuf) { void *src[4]; - + src[0] = get_input(rbuf, 0); src[1] = get_input(rbuf, 1); src[2] = get_input(rbuf, 2); src[3] = get_input(rbuf, 3); - + if (global_get(TEXTURE_ID)) { - return 0; + return 0; } else { - //タスクが共有できる領域確保 - void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); + //タスクが共有できる領域確保 + void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); - memcpy(data, src[0], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); + memcpy(data, src[0], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); } return 0;