Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/spe/DrawSpan.cpp @ 387:5e2d30bfbf23
no compile error but not worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 06 Aug 2009 22:40:52 +0900 |
parents | b4b8345b5366 |
children | 016d45583994 |
rev | line source |
---|---|
322 | 1 // #define DEBUG |
321 | 2 #include "error.h" |
3 | |
109 | 4 #include <stdlib.h> |
5 #include <string.h> | |
200 | 6 #include <spu_intrinsics.h> |
109 | 7 #include "DrawSpan.h" |
8 #include "polygon_pack.h" | |
9 #include "texture.h" | |
10 #include "viewer_types.h" | |
184 | 11 #include "Func.h" |
352 | 12 #include "global_alloc.h" |
109 | 13 |
14 SchedDefineTask(DrawSpan); | |
15 | |
210 | 16 #define TEX_LOAD1 0 |
17 #define TEX_LOAD2 1 | |
18 #define SPAN_PACK_LOAD 2 | |
19 #define FB_STORE 3 | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
20 |
193 | 21 DrawSpan::~DrawSpan(void) |
22 { | |
23 smanager->dma_wait(FB_STORE); | |
24 free((void*)((int)linebuf*doneWrite)); | |
25 } | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
26 |
205 | 27 inline vector float |
28 spu_re_nrm(vector float a) | |
29 { | |
30 vector float unit = (vector float){1.0, 1.0, 1.0, 1.0}; | |
31 vector float approximation; | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
32 |
205 | 33 approximation = spu_re(a); |
34 return spu_madd(spu_nmsub(approximation, a, unit), | |
35 approximation, approximation); | |
36 } | |
37 | |
38 | |
39 vector signed int | |
40 getLocalPositionVec(vector signed int d, signed int offset) | |
41 { | |
42 return spu_and(d, spu_splats(offset-1)); | |
43 } | |
44 | |
45 vector signed int | |
46 getLocalXVec(vector signed int x) | |
47 { | |
48 return getLocalPositionVec(x, split_screen_w); | |
49 } | |
50 | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
51 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
52 /** |
193 | 53 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
54 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
55 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
56 * | 0 | 1 | 2 | 3 | 4 | 5 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
57 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
58 * | | | | | |11 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
59 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
60 * | | | | | |17 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
61 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
62 * | | | | | |23 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
63 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
64 * | | | | | |29 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
65 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
66 * | | | | | |35 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
67 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
68 * |
193 | 69 * 一辺を TEXTURE_SPLIT とする |
70 * 各ブロックの数字がブロックIDとなる。 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
71 */ |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
72 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
73 /** |
193 | 74 * テクスチャの座標から、 |
75 * テクスチャのどのブロックかを求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
76 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
77 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
78 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
79 * @param[in] twidth Width of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
80 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
81 */ |
184 | 82 int |
83 DrawSpan::getTexBlock(int tx, int ty, int twidth) | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
84 { |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
85 int blockX, blockY; |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
86 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
87 blockX = tx / TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
88 blockY = ty / TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
89 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
90 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
91 } |
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
92 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
93 /** |
193 | 94 * block ID と、テクスチャの TOP address から |
95 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
96 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
97 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
98 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
99 * @param[in] tw Width of texture |
193 | 100 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
101 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
102 */ |
380 | 103 memaddr |
104 DrawSpan::getTile(int tx, int ty, int tw, memaddr tex_addr_top) | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
105 { |
184 | 106 int block = getTexBlock(tx, ty, tw); |
380 | 107 return tex_addr_top + block*TEXTURE_BLOCK_SIZE * sizeof(uint32); |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
108 } |
120 | 109 |
193 | 110 /** |
111 * FrameBuffer に書き込む rgb の領域初期化 | |
112 * | |
113 * @param width Width of Buffer | |
114 * @param height Height of Buffer | |
115 * @param rgb Initial value of RGB at Buffer | |
116 * @return Buffer | |
117 */ | |
118 int* | |
119 DrawSpan::linebuf_init(int width, int height, int rgb) | |
109 | 120 { |
193 | 121 int *buf = (int*)smanager->allocate(sizeof(int)*width*height); |
122 | |
123 for (int i = 0; i < width*height; i++) { | |
352 | 124 buf[i] = rgb; |
109 | 125 } |
193 | 126 |
127 return buf; | |
109 | 128 } |
129 | |
184 | 130 /** |
193 | 131 * Z-Buffer の初期化 |
184 | 132 * |
193 | 133 * @param width Width of Z-Buffer |
134 * @param height Height of Z-Buffer | |
135 * @return Z-Buffer | |
136 */ | |
137 float* | |
138 DrawSpan::zRow_init(int width, int height) | |
109 | 139 { |
193 | 140 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); |
141 float def = 65535.0f; | |
142 | |
205 | 143 #if 0 |
193 | 144 for (int i = 0; i < width*height; i++) { |
352 | 145 buf[i] = def; |
193 | 146 } |
352 | 147 #else |
210 | 148 vector float init = spu_splats(0.0f); |
149 vector float defi = spu_splats(def); | |
200 | 150 |
151 for (int i = 0; i < width*height; i += 4) { | |
352 | 152 vector float *out = (vector float *)&buf[i]; |
200 | 153 |
352 | 154 *out = spu_add(init, defi); |
200 | 155 } |
156 #endif | |
193 | 157 |
158 return buf; | |
159 } | |
160 | |
161 | |
162 /** | |
163 * Span が使う Texture Tile があるか | |
164 * | |
165 * @retval != NULL 存在する | |
166 * @retval NULL 存在しない | |
184 | 167 */ |
168 TilePtr | |
380 | 169 DrawSpan::isAvailableTile(memaddr addr) |
184 | 170 { |
171 return hash->get(addr); | |
172 } | |
173 | |
354 | 174 TilePtr |
380 | 175 DrawSpan::set_rgb(memaddr addr, int tag) |
184 | 176 { |
177 TilePtr tile; | |
178 | |
371 | 179 #ifdef USE_MEMLIST |
180 tile = tileList->getLast(); | |
380 | 181 tileList->moveToFirst(tile); |
371 | 182 #else |
193 | 183 tile = tileList->nextTile(); |
371 | 184 #endif |
185 | |
380 | 186 memaddr old_addr = tile->address; |
187 smanager->dma_load(tile->data, addr, | |
354 | 188 sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); |
193 | 189 /** |
190 * FIFO なので、もし前のが残っていれば削除 | |
191 */ | |
356 | 192 |
354 | 193 hash->remove(old_addr); |
352 | 194 |
371 | 195 tile->address = addr; |
352 | 196 |
371 | 197 hash->put(tile->address, tile); |
354 | 198 |
199 return tile; | |
184 | 200 } |
201 | |
193 | 202 uint32 |
354 | 203 DrawSpan::get_rgb(int tx, int ty, TilePtr tile) |
184 | 204 { |
380 | 205 uint32 *data = (uint32 *)tile->data; |
206 return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; | |
109 | 207 } |
208 | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
209 #if 0 |
184 | 210 /** |
193 | 211 * DrawSpan の再起動 (DrawSpanRenew 生成) |
184 | 212 * |
193 | 213 * @param[in] spack 現在処理している SpanPack |
214 * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で | |
215 * どこまで進んでいるか | |
184 | 216 */ |
217 void | |
218 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) | |
219 { | |
193 | 220 DrawSpanArgPtr args = |
352 | 221 (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); |
184 | 222 TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
223 |
193 | 224 // 数が多いので構造体で渡す |
225 args->display = smanager->get_param(0); | |
226 args->screen_width = smanager->get_param(1); | |
227 args->rangex_start = smanager->get_param(2); | |
228 args->rangex_end = smanager->get_param(3); | |
229 args->rangey = smanager->get_param(4); | |
230 renew_task->add_param((int)args); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
231 |
184 | 232 /** |
193 | 233 * SpanPack は続きから開始するので、 |
234 * 現在の状態をコピーしておく。 | |
235 * spack は rbuf から取得してる可能性があり | |
236 * rbuf はシステムが自動的に free() するため | |
237 * アドレスだけ渡すのはNG | |
352 | 238 */ |
184 | 239 SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); |
240 memcpy(curr, spack, sizeof(SpanPack)); | |
241 renew_task->add_param((int)curr); | |
242 renew_task->add_param(cur_span_x); | |
243 | |
193 | 244 // linebuf と zRow も引き継がせる |
245 renew_task->add_param((int)linebuf); | |
246 renew_task->add_param((int)zRow); | |
247 | |
184 | 248 /** |
193 | 249 * 再起動したタスクを待つ |
352 | 250 */ |
184 | 251 smanager->wait_task(renew_task); |
252 | |
193 | 253 // next_spack は free() するので wait する |
184 | 254 smanager->dma_wait(SPAN_PACK_LOAD); |
255 } | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
256 |
193 | 257 void |
258 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
352 | 259 int screen_width) |
193 | 260 { |
261 for (int i = 0; i < height; i++) { | |
352 | 262 smanager->dma_store(&linebuf[i*buf_width], |
263 display + (sizeof(int)*screen_width*i), | |
264 sizeof(int)*buf_width, FB_STORE); | |
193 | 265 } |
266 | |
267 doneWrite = 1; | |
268 } | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
269 #endif |
193 | 270 |
205 | 271 /** |
210 | 272 * zRow と Linebuf を更新する |
273 * | |
274 * @param zpos 更新する pixel のZ座標 | |
275 * @param rangex このタスクが処理する描画領域の x の長さ | |
276 * @param x pixel の、描画領域内での x 座標 | |
277 * @param y 〃 の、y 座標 | |
278 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
279 * @param tex_y 〃 の y 座標 | |
280 * @param tex_addr テクスチャのアドレス(MainMemory) | |
281 */ | |
282 void | |
283 DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, | |
354 | 284 int tex_x, int tex_y, TilePtr tile) |
210 | 285 { |
354 | 286 int rgb = get_rgb(tex_x, tex_y, tile); |
352 | 287 |
210 | 288 zRow[x + (rangex*y)] = zpos; |
289 linebuf[x + (rangex*y)] = rgb; | |
290 } | |
291 | |
292 /** | |
205 | 293 * 長さが 1 の Span の描画 (要するに 1 pixel) |
294 * | |
295 * @param span Span | |
296 * @param startx 描画開始範囲 | |
297 * @param endx 描画終了範囲 | |
298 */ | |
210 | 299 int |
300 DrawSpan::drawDot1(SpanPtr span, int startx, int endx, int wait_tag) | |
205 | 301 { |
302 int rangex = endx - startx + 1; | |
303 | |
304 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
305 int tex_xpos, tex_ypos; | |
306 | |
307 // span の始点に対応する Texture の座標 (tex1, tey1) | |
308 float tex = span->tex_x1; | |
309 float tey = span->tex_y1; | |
310 | |
311 // span の始点に対応する z 座標 | |
312 float zpos = span->start_z; | |
313 | |
314 /* Tile 内での座標 */ | |
315 int localx = getLocalX(span->x-1); | |
316 int localy = getLocalY(span->y-1); | |
317 | |
318 /** | |
319 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
320 * そのブロックのアドレス(MainMemory) | |
321 */ | |
322 int tex_localx; | |
323 int tex_localy; | |
380 | 324 memaddr tex_addr; |
205 | 325 |
326 if (span->x < startx || endx < span->x) { | |
352 | 327 return -1; |
205 | 328 } |
329 | |
330 tex_xpos = (int)((span->tex_width-1) * tex); | |
331 tex_ypos = (int)((span->tex_height-1) * tey); | |
332 | |
333 if (zpos < zRow[localx + (rangex*localy)]) { | |
352 | 334 tex_addr = getTile(tex_xpos, tex_ypos, |
380 | 335 span->tex_width, (memaddr)span->tex_addr); |
352 | 336 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
337 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
205 | 338 |
354 | 339 TilePtr tile; |
340 if (!(tile = isAvailableTile(tex_addr))) { | |
341 tile = set_rgb(tex_addr, wait_tag); | |
352 | 342 smanager->dma_wait(wait_tag); |
343 //return startx; | |
344 } | |
371 | 345 #ifdef USE_MEMLIST |
346 else { | |
347 tileList->moveToFirst(tile); | |
348 } | |
349 #endif | |
205 | 350 |
352 | 351 updateBuffer(zpos, rangex, localx, localy, |
356 | 352 tex_localx, tex_localy, tile); |
205 | 353 } |
210 | 354 |
355 return -1; | |
205 | 356 } |
357 | |
210 | 358 |
233 | 359 /** |
360 * 長さが 1 より大きい Span の描画 | |
361 * | |
362 * 本来の目的として、この関数(drawLine1) では | |
363 * : 既に SPE 上に Tile のある pixel だけ描画 | |
364 * : それ以外は、ここで予め DMA load しておき、 | |
365 * : drawLine2 で一気に描画する | |
366 * ってものだったんだけど、どうも上手く行かなかったので | |
367 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
368 * (rendering といっても、rendering buffer に書き込むだけで | |
369 * まだ main memory (frame buffer) に dma store してるわけではない) | |
352 | 370 * |
233 | 371 * @param span Span |
372 * @param startx 描画開始範囲 | |
373 * @param endx 描画終了範囲 | |
374 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
375 */ | |
210 | 376 int |
377 DrawSpan::drawLine1(SpanPtr span, int startx, int endx, int wait_tag) | |
205 | 378 { |
379 int x = span->x; | |
380 int rangex = endx - startx + 1; | |
381 int x_len = span->length_x; | |
382 | |
383 int js = (x < startx) ? startx - x : 0; | |
384 int je = (x + x_len > endx) ? endx - x : x_len; | |
385 | |
386 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
387 int tex_xpos, tex_ypos; | |
388 | |
389 // span の始点に対応する座標 (tex1, tey1) | |
390 float tex1 = span->tex_x1; | |
391 float tey1 = span->tex_y1; | |
392 | |
393 // span の終点に対応する座標 (tex2, tey2) | |
394 float tex2 = span->tex_x2; | |
395 float tey2 = span->tex_y2; | |
396 | |
397 // span の始点、終点に対応する z 座標 | |
398 float zpos1 = span->start_z; | |
399 float zpos2 = span->end_z; | |
400 | |
401 // Tile 内での座標 | |
402 int localx, localy = getLocalY(span->y-1); | |
403 | |
210 | 404 int ret = je+1; |
405 | |
406 //for (int j = js; j <= je; j++) { | |
407 for (int j = je; j >= js; j--) { | |
352 | 408 float tex_x, tex_y, tex_z; |
210 | 409 |
352 | 410 localx = getLocalX(x-1+j); |
210 | 411 |
352 | 412 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); |
210 | 413 |
352 | 414 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
415 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
416 if (tex_x > 1) tex_x = 1; | |
417 if (tex_x < 0) tex_x = 0; | |
418 if (tex_y > 1) tex_y = 1; | |
419 if (tex_y < 0) tex_y = 0; | |
420 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
421 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
422 | |
423 if (tex_z < zRow[localx + (rangex*localy)]) { | |
424 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
425 // そのブロックのアドレス(MainMemory) | |
380 | 426 memaddr tex_addr; |
352 | 427 int tex_localx; |
428 int tex_localy; | |
210 | 429 |
352 | 430 tex_addr = getTile(tex_xpos, tex_ypos, |
380 | 431 span->tex_width, (memaddr)span->tex_addr); |
352 | 432 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
433 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
210 | 434 |
354 | 435 TilePtr tile; |
356 | 436 if (!(tile = isAvailableTile(tex_addr))) { |
354 | 437 tile = set_rgb(tex_addr, wait_tag); |
438 smanager->dma_wait(wait_tag); | |
356 | 439 } |
371 | 440 #ifdef USE_MEMLIST |
441 else { | |
442 tileList->moveToFirst(tile); | |
443 } | |
444 #endif | |
210 | 445 |
352 | 446 updateBuffer(tex_z, rangex, localx, localy, |
356 | 447 tex_localx, tex_localy, tile); |
352 | 448 } |
210 | 449 } |
450 | |
451 return ret; | |
452 } | |
453 | |
109 | 454 int |
455 DrawSpan::run(void *rbuf, void *wbuf) | |
456 { | |
321 | 457 __debug_spe("DrawSpan\n"); |
193 | 458 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
459 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
460 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
109 | 461 Span *span; |
462 | |
210 | 463 Span nop_span; |
464 nop_span.length_x = 1; | |
465 | |
466 int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { | |
352 | 467 &DrawSpan::drawDot1, &DrawSpan::drawLine1 |
210 | 468 }; |
469 | |
193 | 470 uint32 display = smanager->get_param(0); |
471 int screen_width = smanager->get_param(1); | |
472 int rangex_start = smanager->get_param(2); | |
352 | 473 int rangex_end = smanager->get_param(3); |
474 | |
193 | 475 // このタスクが担当する x の範囲 |
476 int rangex = rangex_end - rangex_start + 1; | |
477 | |
478 // y の範囲 | |
479 int rangey = smanager->get_param(4); | |
203 | 480 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
481 hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); |
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
482 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
109 | 483 |
193 | 484 zRow = zRow_init(rangex, rangey); |
213
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
485 //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); |
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
486 linebuf = linebuf_init(rangex, rangey, 0); |
184 | 487 |
193 | 488 doneWrite = 0; |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
489 |
210 | 490 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; |
491 int tl_tag_flg1 = 0; | |
492 int tl_tag_flg2 = 1; | |
352 | 493 |
109 | 494 do { |
352 | 495 /** |
496 * SpanPack->next が存在する場合、 | |
497 * 現在の SpanPack を処理してる間に | |
498 * 次の SpanPack の DMA 転送を行う | |
499 */ | |
500 if (spack->next != NULL) { | |
380 | 501 smanager->dma_load(next_spack, (memaddr)spack->next, |
352 | 502 sizeof(SpanPack), SPAN_PACK_LOAD); |
503 } else { | |
504 next_spack = NULL; | |
505 } | |
109 | 506 |
352 | 507 SpanPtr resume_span = &nop_span; |
508 int resume_span_x = 0; | |
109 | 509 |
352 | 510 for (int t = 0; t < spack->info.size; t++) { |
511 SpanPtr next_span; | |
512 int next_span_x; | |
147 | 513 |
352 | 514 span = &spack->span[t]; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
515 |
352 | 516 /** |
517 * span の長さによって、drawLine か drawDot を選択している | |
518 */ | |
519 next_span_x | |
520 = (this->*drawFunc1[(span->length_x != 1)])( | |
521 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
522 next_span = span; | |
109 | 523 |
352 | 524 resume_span = next_span; |
525 resume_span_x = next_span_x; | |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
147
diff
changeset
|
526 |
352 | 527 //smanager->dma_wait(tl_tag[tl_tag_flg1]); |
528 | |
529 tl_tag_flg1 ^= 1; | |
530 tl_tag_flg2 ^= 1; | |
531 } | |
109 | 532 |
352 | 533 // 現在 drawLine2、drawDot2 は機能してないので |
534 //(this->*drawFunc2[(resume_span->length_x != 1)])( | |
535 //resume_span, rangex_start, rangex_end, resume_span_x, | |
536 //tl_tag[tl_tag_flg1]); | |
147 | 537 |
352 | 538 smanager->dma_wait(SPAN_PACK_LOAD); |
109 | 539 |
352 | 540 SpanPackPtr tmp_spack = spack; |
541 spack = next_spack; | |
542 next_spack = tmp_spack; | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
543 } while (spack); |
109 | 544 |
193 | 545 writebuffer(display, rangex, rangey, screen_width); |
546 | |
547 // linebuf は、writebuffer() の dma_store を wait する | |
548 // DrawSpan::~DrawSpan() 内で free する。 | |
549 //free(linebuf); | |
550 free(zRow); | |
184 | 551 |
210 | 552 //FINISH: |
193 | 553 /** |
554 * goto FINISH; の時は reboot なので | |
555 * linebuf, zRow は free() しない | |
556 */ | |
210 | 557 |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
558 free(free_spack); |
109 | 559 return 0; |
560 } |