changeset 1415:774ea7a71b0f draft

try to fix bound in ReferencedDmaManager
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 19 Feb 2012 15:45:36 +0900
parents 94ac6d8e73aa
children 88d1b95e5f8d
files Renderer/Engine/task/CreateSpan.cc TaskManager/Fifo/ReferencedDmaManager.cc TaskManager/Fifo/ReferencedDmaManager.h
diffstat 3 files changed, 24 insertions(+), 196 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/task/CreateSpan.cc	Sun Feb 19 10:38:05 2012 +0900
+++ b/Renderer/Engine/task/CreateSpan.cc	Sun Feb 19 15:45:36 2012 +0900
@@ -5,7 +5,6 @@
 #include "Tapestry.h"
 #include "Func.h"
 
-
 // DMA channel
 static const int SPAN_PACK_LOAD    =  5;
 static const int SPAN_PACK_STORE   =  6;
@@ -13,13 +12,11 @@
 static const int TILE_ALLOCATE     =  8;
 static const int TILE_LOAD         =  9;
 static const int TILE_STORE        = 10;
-
 static SpanPackPtr spack = NULL;
 // static SpanPackPtr send_spack = NULL;
 static int prev_index = 0;
 
-
-SchedDefineTask(CreateSpan);
+SchedDefineTask1(CreateSpan,createSpan);
 
 static float
 calc(float f1, float f2,int i, float base)
@@ -40,7 +37,6 @@
 	    VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax,
             NormalPackPtr *normal1, NormalPackPtr *normal2, NormalPackPtr *normal3)
 {
-
     /**
      *  y座標から、vMax, vMid, vMin, を求める
      *
@@ -57,8 +53,6 @@
      *      vMin
      *
      */
-
-
     if (triPack->ver1.y <= triPack->ver2.y) {
 	if (triPack->ver2.y <= triPack->ver3.y) {
 	    *vMin = &triPack->ver1;
@@ -88,11 +82,9 @@
 	    *vMax = &triPack->ver1;
 	}
     }
-
     *normal1 = &triPack->normal1;
     *normal2 = &triPack->normal2;
     *normal3 = &triPack->normal3;
-
 }
 
 static void
@@ -102,10 +94,9 @@
     //int d, d1;
     float d;
     int d1;
-    
+
     d  = vMax->y - vMin->y;
     d1 = (int)(vMid->y - vMin->y);
-
     v->tex_x  = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x);
     v->tex_y  = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y);
     v->x      = calc(vMax->x - vMin->x, d, d1, vMin->x);
@@ -113,7 +104,6 @@
     v->z      = calc(vMax->z - vMin->z, d, d1, vMin->z);
     // test
     v->diffuse = calc(vMax->diffuse - vMin->diffuse, d, d1, vMin->diffuse);
-
 }
 
 /**
@@ -153,18 +143,13 @@
     int diff = TEXTURE_SPLIT_PIXEL;
 
     for (int s = 1; s < scale; s <<= 1) {
-
         // makeTapestry の作り方をみると、こんな感じでindexだせるはず。眠いんでこれで勘弁(ry
 	index += (align(tw, diff) / diff) * (align(th, diff) / diff) * TEXTURE_BLOCK_SIZE;
 	diff <<= 1;
-
     }
-
-
     return addr_top + index;
 }
 
-
 /**
  * span の width,height と texture の width,height を比べて
  * span を描画する際に使う texture の比率を求める
@@ -197,32 +182,27 @@
 	base = height;
 	tex_base = tex_height;
     }
-
     if (tex_base > base) {
 	int t_scale = tex_base/base;
 	while (t_scale >>= 1) {
 	    scale <<= 1;
 	}
     }
-
     return (scale > scale_max) ? scale_max : scale;
     //return scale_max;
 }
 
-
 static void
 span_calc(SpanPackPtr spack, VertexPackPtr vMid, VertexPackPtr vMid10, VertexPackPtr vMin, 
      NormalPackPtr normal1, NormalPackPtr normal2, NormalPackPtr normal3,
      TriangleTexInfoPtr tex_info, int length_y, float tex_y_len, float div_y, int y, int i)
 {
-
     float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2;
     float tmp_xpos,tmp_end,tmp_zpos;
     float tmp_diffuse_l,tmp_diffuse_r;
     float start_z, end_z;
     float start_tex_x, end_tex_x, start_tex_y, end_tex_y;
     float diffuse_l, diffuse_r;
-
     int x,length;
 
     tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x);
@@ -232,23 +212,19 @@
     // test
     tmp_diffuse_l = calc(vMid10->diffuse - vMin->diffuse, div_y, i, vMin->diffuse);
     tmp_diffuse_r = calc(vMid->diffuse  - vMin->diffuse, div_y, i, vMin->diffuse);
-    
     length = (tmp_xpos > tmp_end)
         ? (int)tmp_xpos - (int)tmp_end : (int)tmp_end - (int)tmp_xpos;
     if (length == 0) {
         return;
     }
-
     tmp_tex1 =((i/(div_y)) * vMid10->tex_x) +
         ( ((div_y - i)/(div_y)) * vMin->tex_x);
     tmp_tex2 =( (i/(div_y)) * vMid->tex_x) +
         ( ((div_y - i)/(div_y)) * vMin->tex_x);
-    
     tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) +
         ( ((div_y - i)/(div_y)) * vMin->tex_y);
     tmp_tey2 =( (i/(div_y)) * vMid->tex_y) +
         ( ((div_y - i)/(div_y)) * vMin->tex_y);
-    
     if (tmp_xpos > tmp_end) {
         x = (int)tmp_end;
         length = (int)(tmp_xpos)-(int)(tmp_end)+1;
@@ -274,13 +250,10 @@
         diffuse_l = tmp_diffuse_l;
         diffuse_r = tmp_diffuse_r;
     }
-    
     // ここいる? load してその後必ず、wait してるように見える。
     // この wait に対応しているloadはないはずだ・・・きっと。
     //smanager->dma_wait(SPAN_PACK_LOAD);
-    
     Span *span = &spack->span[spack->info.size++];
-    
     span->x          = x;
     span->y          = y;
     span->length_x   = length;
@@ -293,21 +266,16 @@
     // test
     span->diffuse_l  = diffuse_l;
     span->diffuse_r  = diffuse_r;
-    
     /*
      * ここで頂点分法線ベクトルがあったんだけど、
      *  一つだけ取り出して、spanに一つの法線ベクトルを持たしている
      */
-    
     span->normal_x    = normal1->x;
     span->normal_y    = normal1->y;
     span->normal_z    = normal1->z;
-    
     float tex_x_len = span->tex_x2 - span->tex_x1;
-    
     span->tex_width = tex_info->width;
     span->tex_height = tex_info->height;
-
     /**
      * tex_x_len, tex_y_len を掛ける理由は
      * Changelog の 2008-12-16 を参照
@@ -317,14 +285,12 @@
                          (int)(span->tex_height*tex_y_len),
                          tex_info->scale_max);
     //scale = tex_info->scale_max;
-    
     uint32 *tapestry = getTapestry(tex_info->width,
                                    tex_info->height, scale,
                                    tex_info->addr);
     span->tex_addr   = tapestry;
     span->tex_width  = tex_info->width/scale;
     span->tex_height = tex_info->height/scale;
-    
 }
 
 /**
@@ -345,7 +311,6 @@
  * @param[in] tex_y_len 分割する前の Triangle に貼られている Texture の
  *                      長さの割合 (0 ... 1)
  */
-
 static void
 half_triangle(SchedTask *smanager, SpanPackPtr *spackList,
 			  int charge_y_top, int charge_y_end,
@@ -359,9 +324,7 @@
 #endif
 			  int length_y, float tex_y_len)
 {
-
     int y;
-
 #if 1
     // これじゃないと
     // テクスチャの貼りに微妙に隙間が。謎だ
@@ -374,16 +337,10 @@
     float div_y = start_y - end_y;
     int k = 0;
     int l = 1;
-
 #ifdef USE_SEGMENT
-
-
 #else
-
     SpanPackPtr tmp_spack;
-
 #endif
-
     /**
      * 三角形ポリゴンをx軸に水平に二つに分けようとして
      * ある一辺がすでに水平だった場合、つまり
@@ -403,6 +360,7 @@
      * half_triangle 呼ぶ前にこれを判断できれば良いかもしれない。
      * てかこんなんでいいのかよ。。。
      */
+
 #if 1
     if ((int)div_y == 0) {
 	return;
@@ -412,16 +370,13 @@
 	return;
     }
 #endif
-
     if (div_y < 0) {
 	div_y = -div_y;
 	k = 1;
 	l = -1;
     }
-
     for (int i = k; i < (int)div_y+1; i++) {
 	y = (int)vMin->y + i*l;
-
 	/**
 	 * 担当 y 範囲内
 	 * 必要なデータは先読みできるはず
@@ -429,56 +384,37 @@
 	if (charge_y_top <= y && y <= charge_y_end) {
 	    // 1..8 を index0, 9..16 を index1 にするために y を -1
 	    int index = (y-1) / split_screen_h;
-
 	    /**
 	     * 違う SpanPack を扱う場合、
 	     * 現在の SpanPack をメインメモリに送り、
 	     * 新しい SpanPack を取ってくる
 	     */
-
 	    if (index != prev_index) {
-
 #ifdef USE_SEGMENT
-
-
                 smanager->wait_segment(span_put_ms);
-
                 span_put_ms = span_get_ms;
                 smanager->put_segment(span_put_ms);
-
                 span_get_ms = smanager->get_segment((memaddr)spackList[index], span_ml);
                 smanager->wait_segment(span_get_ms);
-
                 prev_index = index;
                 spack = (SpanPackPtr)span_get_ms->data;
-
-
 #elif defined(USE_ITERATOR)
-                
                 ms = it->get_ms();
                 spack = (SpanPackPtr)ms->data;
                 prev_index = index;
-
 #else
-
 		tmp_spack = spack;
 		spack = send_spack;
 		send_spack = tmp_spack;
-
 		smanager->dma_wait(SPAN_PACK_STORE);
 		smanager->dma_store(send_spack, (memaddr)spackList[prev_index],
 				    sizeof(SpanPack), SPAN_PACK_STORE);
-
 		smanager->dma_load(spack, (memaddr)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
-
 		prev_index = index;
 		smanager->dma_wait(SPAN_PACK_LOAD);
-
 #endif
-
 	    }
-
 	    /**
 	     * 書き込む SpanPack が満杯だったら
 	     * メインメモリで allocate した領域 (next) を持ってきて
@@ -493,67 +429,44 @@
              * mainMem 追い出すには、ちょっと苦労するかも? 
              * mainMem するかどうかは予想できはする。 
 	     */
-
 	    if (spack->info.size >= MAX_SIZE_SPAN) {
 		SpanPackPtr next;
-	
 		smanager->mainMem_alloc(0, sizeof(SpanPack));
 		smanager->mainMem_wait();
 		next = (SpanPackPtr)smanager->mainMem_get(0);
-		
 		spack->next = next;
-
-
 #ifdef USE_SEGMENT
-
                 smanager->wait_segment(span_put_ms);
-
                 span_put_ms = span_get_ms;
                 smanager->put_segment(span_put_ms);
-
                 spackList[index] = next;
                 span_get_ms = smanager->get_segment((memaddr)spackList[index],span_ml);
                 smanager->wait_segment(span_get_ms);
-
                 spack = (SpanPackPtr)span_get_ms->data;
 		spack->init((index+1)*split_screen_h);
-
-
 #elif defined(USE_ITERATOR)
-
                 /*
                   next は AddrList に直さないといけない
                   AddrList next_list = make_list(next);
                   とかいうAPIか、overwrite_list の中でもいいかもね。
                  */
-
                 overwrite_list(next_ist);
                 ms = it->get_ms();
                 spack = (SpanPackPtr)ms->data;
                 prev_index = index;
-                
 #else
-
-
 		tmp_spack = spack;
 		spack = send_spack;
 		send_spack = tmp_spack;
-
 		smanager->dma_wait(SPAN_PACK_STORE);
 		smanager->dma_store(send_spack, (memaddr)spackList[index],
 				    sizeof(SpanPack), SPAN_PACK_STORE);
-
-
 		spackList[index] = next;
-		
-
 		smanager->dma_load(spack, (memaddr)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
 		smanager->dma_wait(SPAN_PACK_LOAD);
 		spack->init((index+1)*split_screen_h);
-
 #endif
-
 	    }
 	} else {
 	    /**
@@ -561,58 +474,37 @@
 	     */
 	    continue;
 	}
-
-
         span_calc(spack, vMid, vMid10, vMin, 
                   normal1, normal2,  normal3,
                   tex_info, length_y, tex_y_len, div_y, y, i);
-
     }
-
-
 }
 
-
-
-
 static int
-run(SchedTask *smanager, void *rbuf, void *wbuf)
+createSpan(SchedTask *smanager, void *rbuf, void *wbuf)
 {
     /*
-
       get_segmentを使うと、input buffer からの入力は要らなくなる
       Task化するなら、get_segment は取り去る。
       途中でloadが入ってるのは DMA転送のサイズの限界と、SPEのLSの容量の少なさにある
       必要なときに、必要な分だけ load するのは、自動的にやってほしいから、get_segment も
       いづれは、Task の内部で処理されるものになるのかな。
       そうすると、Task の input , output のデータの大きさはスケーラブルになるのか。
-
     */
-
     PolygonPack *pp = (PolygonPack*)smanager->get_input(rbuf, 0);
-
-
 #ifdef USE_SEGMENT
-
     // global に取ってみた。いづれはひとつにまとめて、サイズを可変にするのかね。
     MemList *pp_ml = (MemList*)smanager->global_get(GLOBAL_POLYGONPACK_LIST);
     MemList *span_ml = (MemList*)smanager->global_get(GLOBAL_SPANPACK_LIST);
-
     MemorySegmentPtr pp_ms = NULL; //Tileみたいに typedef したほうがいいのか。でもPolygonPackはすでに使われてるし。
-
     MemorySegmentPtr span_put_ms = NULL; 
     MemorySegmentPtr span_get_ms = NULL; 
-
 #else
-
     PolygonPack *next_pp = 
 	(PolygonPack*)smanager->allocate(sizeof(PolygonPack));
-
     PolygonPack *free_pp = next_pp;
     PolygonPack *tmp_pp;
-
 #endif
-
     TrianglePackPtr triPack;
     VertexPackPtr vMin, vMid, vMax;
     VertexPackPtr vMid10
@@ -621,79 +513,47 @@
     SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(rbuf, 1);
 
     prev_index = (long)smanager->get_param(0);
-
-
 #ifdef USE_SEGMENT
-
     /*rbuf2 はspackList[prev_index]と一緒なんだけど、この書き方は微妙ね*/
     span_get_ms = smanager->get_segment((memaddr)spackList[prev_index], span_ml);
     smanager->wait_segment(span_get_ms);
     spack = (SpanPackPtr)span_get_ms->data;
-
 #else
-
     spack = (SpanPackPtr)smanager->get_input(rbuf, 2);
     send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
-
     // spack と send_spack は swap しながら DMA を繰り返すので
     // 自分で allocate した send_spack を覚えてないといけない
     SpanPackPtr free_spack = send_spack;
-
-
 #endif
 
     // ここで AddrList は作れるかな。 
     int charge_y_top = (long)smanager->get_param(1);
     int charge_y_end = (long)smanager->get_param(2);
-
     do {
 	if (pp->next != NULL) {
-
-
 #ifdef USE_SEGMENT
-
             /* 
                Segmentの数は2つにしてその領域のアドレスが交互に返される
             */
- 
             pp_ms = smanager->get_segment((memaddr)pp->next, pp_ml);
-
 #elif defined(USE_ITERATOR)
-            
-            
-
 #else
-
 	    smanager->dma_load(next_pp, (memaddr)pp->next,
 			       sizeof(PolygonPack), POLYGON_PACK_LOAD);
 #endif
-
 	} else {
-
-
 #ifdef USE_SEGMENT
-
             pp_ms = NULL;
-
 #elif defined(USE_ITERATOR)
-
-
 #else
 	    next_pp = NULL;
-
 #endif
-
-
 	}
-
 	for (int i = 0; i < pp->info.size; i++) {
 	    triPack = &pp->tri[i];
-
 	    TriangleTexInfoPtr tri_tex_info = &triPack->tex_info;
-
 	    make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3);
 	    make_vMid10(vMid10, vMin, vMid, vMax);
-
 	    /**
 	     * ポリゴンを、x軸に水平に分割して二つの三角形を作り、
 	     * それぞれから Span を求める
@@ -714,99 +574,64 @@
 	     * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という
 	     * 二つの Triangle に分けている
 	     */
-
 #ifdef USE_SEGMENT
-
 	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMin, vMid, vMid10,
                           normal1,normal2,normal3,
                           span_get_ms, span_put_ms, 
                           span_ml,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
-
 	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMax, vMid, vMid10,
                           normal1,normal2,normal3,
                           span_get_ms, span_put_ms, 
                           span_ml,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
-
 #else
-
 	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMin, vMid, vMid10,
                           normal1,normal2,normal3,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
-
 	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
 			  tri_tex_info, vMax, vMid, vMid10,
                           normal1,normal2,normal3,
 			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
-
-
 #endif
-
 	}
-
 #ifdef USE_SEGMENT
-
-
         // うーん
-
         if (pp_ms != NULL) {
             smanager->wait_segment(pp_ms);
             pp = (PolygonPackPtr)pp_ms->data;
         } else {
             pp = NULL;
         }
-
 #elif defined(USE_ITERATOR)
-        
 #else
-
 	smanager->dma_wait(POLYGON_PACK_LOAD);	
-
 	tmp_pp = pp;
 	pp = next_pp;
 	next_pp = tmp_pp;
-
-
 #endif
-
-
     } while (pp);
-
-
 #ifdef USE_SEGMENT
-      
       smanager->wait_segment(span_put_ms);
       span_put_ms = span_get_ms;
       smanager->put_segment(span_put_ms);
       smanager->wait_segment(span_put_ms);
-
 #else
-
     smanager->dma_wait(SPAN_PACK_STORE);
     smanager->dma_store(spack, (memaddr)spackList[prev_index],
                         sizeof(SpanPack), SPAN_PACK_STORE);
     smanager->dma_wait(SPAN_PACK_STORE);
-
 #endif
-
 #ifdef USE_SEGMENT
-
     // Global でSegmentとったので、いつか解放しないといかないなぁ。
-
 #elif defined(USE_ITERATOR)
-
 #else
-
     free(free_pp);
     free(free_spack);
-
 #endif
-
     free(vMid10);
-
     return 0;
 }
--- a/TaskManager/Fifo/ReferencedDmaManager.cc	Sun Feb 19 10:38:05 2012 +0900
+++ b/TaskManager/Fifo/ReferencedDmaManager.cc	Sun Feb 19 15:45:36 2012 +0900
@@ -5,28 +5,13 @@
 void *
 ReferencedDmaManager::dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask)
 {
-	unsigned long long wait = 0;
-	(this->*start_dmawait_profile)();
-
-	(this->*end_dmawait_profile)(&wait);
-	global_load_time += wait;
-	dma_load_time += wait;
-
-	return (void*)addr;
+    return (void*)addr;
 }
 
 void *
 ReferencedDmaManager::dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask)
 {
-	unsigned long long wait = 0;
-	(this->*start_dmawait_profile)();
-
-	ListElementPtr elm = &list->element[0];
-
-	(this->*end_dmawait_profile)(&wait);
-	global_load_time += wait;
-	dma_loadList_time += wait;
-
+    ListElementPtr elm = &list->element[0];
     return (void*)elm->addr; 
 }
 
@@ -34,4 +19,21 @@
 ReferencedDmaManager::free_(void *buf) {
 }
 
+/**
+ *  DMA buffer offset in rbuf
+ *
+ *  faked offset for real address must be set to get correct address by
+ *    return (void*)((char*)readbuf + inListData.bound[index]);
+ *
+ */
+void
+ReferencedDmaManager::bound(ListData *list)
+{
+    ListElement *elm = list->element;
+    int *bound = list->bound;
+    memaddr readbuf = elm[0].addr;
+    for(int i=0;i<list->length;i++) {
+        bound[i] = elm[i].addr-readbuf;
+    }
+}
 
--- a/TaskManager/Fifo/ReferencedDmaManager.h	Sun Feb 19 10:38:05 2012 +0900
+++ b/TaskManager/Fifo/ReferencedDmaManager.h	Sun Feb 19 15:45:36 2012 +0900
@@ -10,6 +10,7 @@
     virtual void *dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask);
     virtual void *dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask);
     virtual void free_(void *buff);
+    virtual void bound(ListData *list);
 } ;
 
 #endif/* REFERENCED_DMA_MANAGER */