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