Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/spe/DrawSpan.cpp @ 362:a64a6c34868f
vacuum -sg 15
author | e065746@localhost.localdomain |
---|---|
date | Fri, 17 Jul 2009 23:02:07 +0900 |
parents | 953811245b63 |
children | f88744ee9350 |
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 */ |
184 | 103 uint32* |
104 DrawSpan::getTile(int tx, int ty, int tw, uint32 *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); |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
107 return tex_addr_top + block*TEXTURE_BLOCK_SIZE; |
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 | |
169 DrawSpan::isAvailableTile(uint32 *addr) | |
170 { | |
171 return hash->get(addr); | |
172 } | |
173 | |
354 | 174 TilePtr |
210 | 175 DrawSpan::set_rgb(uint32 *addr, int tag) |
184 | 176 { |
177 TilePtr tile; | |
178 | |
193 | 179 tile = tileList->nextTile(); |
357
953811245b63
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
180 uint32 *old_addr = tile->texture_addr; |
354 | 181 smanager->dma_load(tile->pixel, (uint32)addr, |
182 sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); | |
193 | 183 /** |
184 * FIFO なので、もし前のが残っていれば削除 | |
185 */ | |
356 | 186 |
354 | 187 hash->remove(old_addr); |
352 | 188 |
193 | 189 tile->texture_addr = addr; |
352 | 190 |
243 | 191 hash->put(tile->texture_addr, tile); |
354 | 192 |
193 return tile; | |
184 | 194 } |
195 | |
193 | 196 uint32 |
354 | 197 DrawSpan::get_rgb(int tx, int ty, TilePtr tile) |
184 | 198 { |
354 | 199 |
168 | 200 return tile->pixel[(TEXTURE_SPLIT_PIXEL)*ty+tx]; |
109 | 201 } |
202 | |
184 | 203 /** |
193 | 204 * DrawSpan の再起動 (DrawSpanRenew 生成) |
184 | 205 * |
193 | 206 * @param[in] spack 現在処理している SpanPack |
207 * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で | |
208 * どこまで進んでいるか | |
184 | 209 */ |
210 void | |
211 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) | |
212 { | |
193 | 213 DrawSpanArgPtr args = |
352 | 214 (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); |
184 | 215 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
|
216 |
193 | 217 // 数が多いので構造体で渡す |
218 args->display = smanager->get_param(0); | |
219 args->screen_width = smanager->get_param(1); | |
220 args->rangex_start = smanager->get_param(2); | |
221 args->rangex_end = smanager->get_param(3); | |
222 args->rangey = smanager->get_param(4); | |
223 renew_task->add_param((int)args); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
224 |
184 | 225 /** |
193 | 226 * SpanPack は続きから開始するので、 |
227 * 現在の状態をコピーしておく。 | |
228 * spack は rbuf から取得してる可能性があり | |
229 * rbuf はシステムが自動的に free() するため | |
230 * アドレスだけ渡すのはNG | |
352 | 231 */ |
184 | 232 SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); |
233 memcpy(curr, spack, sizeof(SpanPack)); | |
234 renew_task->add_param((int)curr); | |
235 renew_task->add_param(cur_span_x); | |
236 | |
193 | 237 // linebuf と zRow も引き継がせる |
238 renew_task->add_param((int)linebuf); | |
239 renew_task->add_param((int)zRow); | |
240 | |
184 | 241 /** |
193 | 242 * 再起動したタスクを待つ |
352 | 243 */ |
184 | 244 smanager->wait_task(renew_task); |
245 | |
193 | 246 // next_spack は free() するので wait する |
184 | 247 smanager->dma_wait(SPAN_PACK_LOAD); |
248 } | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
249 |
193 | 250 void |
251 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
352 | 252 int screen_width) |
193 | 253 { |
254 for (int i = 0; i < height; i++) { | |
352 | 255 smanager->dma_store(&linebuf[i*buf_width], |
256 display + (sizeof(int)*screen_width*i), | |
257 sizeof(int)*buf_width, FB_STORE); | |
193 | 258 } |
259 | |
260 doneWrite = 1; | |
261 } | |
262 | |
205 | 263 /** |
210 | 264 * zRow と Linebuf を更新する |
265 * | |
266 * @param zpos 更新する pixel のZ座標 | |
267 * @param rangex このタスクが処理する描画領域の x の長さ | |
268 * @param x pixel の、描画領域内での x 座標 | |
269 * @param y 〃 の、y 座標 | |
270 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
271 * @param tex_y 〃 の y 座標 | |
272 * @param tex_addr テクスチャのアドレス(MainMemory) | |
273 */ | |
274 void | |
275 DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, | |
354 | 276 int tex_x, int tex_y, TilePtr tile) |
210 | 277 { |
354 | 278 int rgb = get_rgb(tex_x, tex_y, tile); |
352 | 279 |
210 | 280 zRow[x + (rangex*y)] = zpos; |
281 linebuf[x + (rangex*y)] = rgb; | |
282 } | |
283 | |
284 /** | |
205 | 285 * 長さが 1 の Span の描画 (要するに 1 pixel) |
286 * | |
287 * @param span Span | |
288 * @param startx 描画開始範囲 | |
289 * @param endx 描画終了範囲 | |
290 */ | |
210 | 291 int |
292 DrawSpan::drawDot1(SpanPtr span, int startx, int endx, int wait_tag) | |
205 | 293 { |
294 int rangex = endx - startx + 1; | |
295 | |
296 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
297 int tex_xpos, tex_ypos; | |
298 | |
299 // span の始点に対応する Texture の座標 (tex1, tey1) | |
300 float tex = span->tex_x1; | |
301 float tey = span->tex_y1; | |
302 | |
303 // span の始点に対応する z 座標 | |
304 float zpos = span->start_z; | |
305 | |
306 /* Tile 内での座標 */ | |
307 int localx = getLocalX(span->x-1); | |
308 int localy = getLocalY(span->y-1); | |
309 | |
310 /** | |
311 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
312 * そのブロックのアドレス(MainMemory) | |
313 */ | |
314 int tex_localx; | |
315 int tex_localy; | |
316 uint32 *tex_addr; | |
317 | |
318 if (span->x < startx || endx < span->x) { | |
352 | 319 return -1; |
205 | 320 } |
321 | |
322 tex_xpos = (int)((span->tex_width-1) * tex); | |
323 tex_ypos = (int)((span->tex_height-1) * tey); | |
324 | |
325 if (zpos < zRow[localx + (rangex*localy)]) { | |
352 | 326 tex_addr = getTile(tex_xpos, tex_ypos, |
327 span->tex_width, span->tex_addr); | |
328 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
329 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
205 | 330 |
354 | 331 TilePtr tile; |
332 if (!(tile = isAvailableTile(tex_addr))) { | |
333 tile = set_rgb(tex_addr, wait_tag); | |
352 | 334 smanager->dma_wait(wait_tag); |
335 //return startx; | |
336 } | |
205 | 337 |
352 | 338 updateBuffer(zpos, rangex, localx, localy, |
356 | 339 tex_localx, tex_localy, tile); |
205 | 340 } |
210 | 341 |
342 return -1; | |
205 | 343 } |
344 | |
210 | 345 |
233 | 346 /** |
347 * 長さが 1 より大きい Span の描画 | |
348 * | |
349 * 本来の目的として、この関数(drawLine1) では | |
350 * : 既に SPE 上に Tile のある pixel だけ描画 | |
351 * : それ以外は、ここで予め DMA load しておき、 | |
352 * : drawLine2 で一気に描画する | |
353 * ってものだったんだけど、どうも上手く行かなかったので | |
354 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
355 * (rendering といっても、rendering buffer に書き込むだけで | |
356 * まだ main memory (frame buffer) に dma store してるわけではない) | |
352 | 357 * |
233 | 358 * @param span Span |
359 * @param startx 描画開始範囲 | |
360 * @param endx 描画終了範囲 | |
361 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
362 */ | |
210 | 363 int |
364 DrawSpan::drawLine1(SpanPtr span, int startx, int endx, int wait_tag) | |
205 | 365 { |
366 int x = span->x; | |
367 int rangex = endx - startx + 1; | |
368 int x_len = span->length_x; | |
369 | |
370 int js = (x < startx) ? startx - x : 0; | |
371 int je = (x + x_len > endx) ? endx - x : x_len; | |
372 | |
373 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
374 int tex_xpos, tex_ypos; | |
375 | |
376 // span の始点に対応する座標 (tex1, tey1) | |
377 float tex1 = span->tex_x1; | |
378 float tey1 = span->tex_y1; | |
379 | |
380 // span の終点に対応する座標 (tex2, tey2) | |
381 float tex2 = span->tex_x2; | |
382 float tey2 = span->tex_y2; | |
383 | |
384 // span の始点、終点に対応する z 座標 | |
385 float zpos1 = span->start_z; | |
386 float zpos2 = span->end_z; | |
387 | |
388 // Tile 内での座標 | |
389 int localx, localy = getLocalY(span->y-1); | |
390 | |
210 | 391 int ret = je+1; |
392 | |
393 //for (int j = js; j <= je; j++) { | |
394 for (int j = je; j >= js; j--) { | |
352 | 395 float tex_x, tex_y, tex_z; |
210 | 396 |
352 | 397 localx = getLocalX(x-1+j); |
210 | 398 |
352 | 399 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); |
210 | 400 |
352 | 401 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
402 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
403 if (tex_x > 1) tex_x = 1; | |
404 if (tex_x < 0) tex_x = 0; | |
405 if (tex_y > 1) tex_y = 1; | |
406 if (tex_y < 0) tex_y = 0; | |
407 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
408 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
409 | |
410 if (tex_z < zRow[localx + (rangex*localy)]) { | |
411 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
412 // そのブロックのアドレス(MainMemory) | |
413 uint32 *tex_addr; | |
414 int tex_localx; | |
415 int tex_localy; | |
210 | 416 |
352 | 417 tex_addr = getTile(tex_xpos, tex_ypos, |
418 span->tex_width, span->tex_addr); | |
419 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
420 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
210 | 421 |
354 | 422 TilePtr tile; |
356 | 423 if (!(tile = isAvailableTile(tex_addr))) { |
354 | 424 tile = set_rgb(tex_addr, wait_tag); |
425 smanager->dma_wait(wait_tag); | |
356 | 426 } |
210 | 427 |
428 | |
352 | 429 updateBuffer(tex_z, rangex, localx, localy, |
356 | 430 tex_localx, tex_localy, tile); |
352 | 431 } |
210 | 432 } |
433 | |
434 return ret; | |
435 } | |
436 | |
109 | 437 int |
438 DrawSpan::run(void *rbuf, void *wbuf) | |
439 { | |
321 | 440 __debug_spe("DrawSpan\n"); |
193 | 441 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
442 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
443 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
109 | 444 Span *span; |
445 | |
210 | 446 Span nop_span; |
447 nop_span.length_x = 1; | |
448 | |
449 int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { | |
352 | 450 &DrawSpan::drawDot1, &DrawSpan::drawLine1 |
210 | 451 }; |
452 | |
193 | 453 uint32 display = smanager->get_param(0); |
454 int screen_width = smanager->get_param(1); | |
455 int rangex_start = smanager->get_param(2); | |
352 | 456 int rangex_end = smanager->get_param(3); |
457 | |
193 | 458 // このタスクが担当する x の範囲 |
459 int rangex = rangex_end - rangex_start + 1; | |
460 | |
461 // y の範囲 | |
462 int rangey = smanager->get_param(4); | |
203 | 463 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
464 hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); |
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
465 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
109 | 466 |
193 | 467 zRow = zRow_init(rangex, rangey); |
213
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
468 //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); |
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
469 linebuf = linebuf_init(rangex, rangey, 0); |
184 | 470 |
193 | 471 doneWrite = 0; |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
472 |
210 | 473 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; |
474 int tl_tag_flg1 = 0; | |
475 int tl_tag_flg2 = 1; | |
352 | 476 |
109 | 477 do { |
352 | 478 /** |
479 * SpanPack->next が存在する場合、 | |
480 * 現在の SpanPack を処理してる間に | |
481 * 次の SpanPack の DMA 転送を行う | |
482 */ | |
483 if (spack->next != NULL) { | |
484 smanager->dma_load(next_spack, (uint32)spack->next, | |
485 sizeof(SpanPack), SPAN_PACK_LOAD); | |
486 } else { | |
487 next_spack = NULL; | |
488 } | |
109 | 489 |
352 | 490 SpanPtr resume_span = &nop_span; |
491 int resume_span_x = 0; | |
109 | 492 |
352 | 493 for (int t = 0; t < spack->info.size; t++) { |
494 SpanPtr next_span; | |
495 int next_span_x; | |
147 | 496 |
352 | 497 span = &spack->span[t]; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
498 |
352 | 499 /** |
500 * span の長さによって、drawLine か drawDot を選択している | |
501 */ | |
502 next_span_x | |
503 = (this->*drawFunc1[(span->length_x != 1)])( | |
504 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
505 next_span = span; | |
109 | 506 |
352 | 507 resume_span = next_span; |
508 resume_span_x = next_span_x; | |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
147
diff
changeset
|
509 |
352 | 510 //smanager->dma_wait(tl_tag[tl_tag_flg1]); |
511 | |
512 tl_tag_flg1 ^= 1; | |
513 tl_tag_flg2 ^= 1; | |
514 } | |
109 | 515 |
352 | 516 // 現在 drawLine2、drawDot2 は機能してないので |
517 //(this->*drawFunc2[(resume_span->length_x != 1)])( | |
518 //resume_span, rangex_start, rangex_end, resume_span_x, | |
519 //tl_tag[tl_tag_flg1]); | |
147 | 520 |
352 | 521 smanager->dma_wait(SPAN_PACK_LOAD); |
109 | 522 |
352 | 523 SpanPackPtr tmp_spack = spack; |
524 spack = next_spack; | |
525 next_spack = tmp_spack; | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
526 } while (spack); |
109 | 527 |
193 | 528 writebuffer(display, rangex, rangey, screen_width); |
529 | |
530 // linebuf は、writebuffer() の dma_store を wait する | |
531 // DrawSpan::~DrawSpan() 内で free する。 | |
532 //free(linebuf); | |
533 free(zRow); | |
184 | 534 |
210 | 535 //FINISH: |
193 | 536 /** |
537 * goto FINISH; の時は reboot なので | |
538 * linebuf, zRow は free() しない | |
539 */ | |
210 | 540 |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
180
diff
changeset
|
541 free(free_spack); |
109 | 542 return 0; |
543 } |