Mercurial > hg > Game > Cerium
comparison TaskManager/Test/simple_render/spe/CreatePolygonPack.cpp @ 102:62679f4cae18
tag:first_render_with_spe fix
author | gongo |
---|---|
date | Mon, 03 Mar 2008 17:15:28 +0900 (2008-03-03) |
parents | 504899860e66 |
children | 3e331f7576a1 |
comparison
equal
deleted
inserted
replaced
101:c31499d11926 | 102:62679f4cae18 |
---|---|
7 | 7 |
8 | 8 |
9 void | 9 void |
10 CreatePolygonPack::read(void) | 10 CreatePolygonPack::read(void) |
11 { | 11 { |
12 printf("CreatePolgonPack\n"); | 12 printf("CreatePolgonPack\n"); |
13 | 13 |
14 SchedTask::read(); | 14 SchedTask::read(); |
15 } | 15 } |
16 | 16 |
17 //create_pp(SceneGraphPack *sgp, PolygonPack *pp) | 17 //create_pp(SceneGraphPack *sgp, PolygonPack *pp) |
18 //create_pp(void *read, void *write) | 18 //create_pp(void *read, void *write) |
19 //CreatePolygonPack::run(SceneGraphPack *sgp, PolygonPack *pp) | 19 //CreatePolygonPack::run(SceneGraphPack *sgp, PolygonPack *pp) |
20 inline float | 20 inline float |
21 CreatePolygonPack::sum_across_float4(vector float v) | 21 CreatePolygonPack::sum_across_float4(vector float v) |
22 { | 22 { |
23 vector float c12, c2, c3, c4, c34; | 23 vector float c12, c2, c3, c4, c34; |
24 vector float result; | 24 vector float result; |
25 | 25 |
26 c2 = spu_rlqwbyte(v, 4); | 26 c2 = spu_rlqwbyte(v, 4); |
27 c3 = spu_rlqwbyte(v, 8); | 27 c3 = spu_rlqwbyte(v, 8); |
28 c4 = spu_rlqwbyte(v, 12); | 28 c4 = spu_rlqwbyte(v, 12); |
29 c12 = spu_add(v, c2); | 29 c12 = spu_add(v, c2); |
30 c34 = spu_add(c3, c4); | 30 c34 = spu_add(c3, c4); |
31 | 31 |
32 result = spu_add(c12, c34); | 32 result = spu_add(c12, c34); |
33 return (spu_extract(result, 0)); | 33 return (spu_extract(result, 0)); |
34 } | 34 } |
35 | 35 |
36 int | 36 int |
37 CreatePolygonPack::run(void *rbuf, void *wbuf) | 37 CreatePolygonPack::run(void *rbuf, void *wbuf) |
38 { | 38 { |
39 SceneGraphPack *sgp = (SceneGraphPack*)rbuf; | 39 SceneGraphPack *sgp = (SceneGraphPack*)rbuf; |
40 PolygonPack *pp = (PolygonPack*)wbuf; | 40 PolygonPack *pp = (PolygonPack*)wbuf; |
41 | 41 |
42 float xyz1[4],xyz2[4],xyz3[4]; | 42 float xyz1[4],xyz2[4],xyz3[4]; |
43 | 43 |
44 for (int i = 0; i < sgp->info.size; i++) { | 44 for (int i = 0; i < sgp->info.size; i++) { |
45 SceneGraphNodePtr node = &sgp->node[i]; | 45 SceneGraphNodePtr node = &sgp->node[i]; |
46 | 46 |
47 int n,nt,pt; | 47 int n,nt,pt; |
48 for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { | 48 for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { |
49 xyz1[0] = node->vertex[n]; | 49 xyz1[0] = node->vertex[n]; |
50 xyz1[1] = node->vertex[n+1]; | 50 xyz1[1] = node->vertex[n+1]; |
51 xyz1[2] = node->vertex[n+2]*-1; | 51 xyz1[2] = node->vertex[n+2]*-1; |
52 xyz1[3] = 1; | 52 xyz1[3] = 1; |
53 xyz2[0] = node->vertex[n+3]; | 53 xyz2[0] = node->vertex[n+3]; |
54 xyz2[1] = node->vertex[n+3+1]; | 54 xyz2[1] = node->vertex[n+3+1]; |
55 xyz2[2] = node->vertex[n+3+2]*-1; | 55 xyz2[2] = node->vertex[n+3+2]*-1; |
56 xyz2[3] = 1; | 56 xyz2[3] = 1; |
57 xyz3[0] = node->vertex[n+6]; | 57 xyz3[0] = node->vertex[n+6]; |
58 xyz3[1] = node->vertex[n+6+1]; | 58 xyz3[1] = node->vertex[n+6+1]; |
59 xyz3[2] = node->vertex[n+6+2]*-1; | 59 xyz3[2] = node->vertex[n+6+2]*-1; |
60 xyz3[3] = 1; | 60 xyz3[3] = 1; |
61 | 61 |
62 rotate(xyz1, node->translation); | 62 rotate(xyz1, node->translation); |
63 rotate(xyz2, node->translation); | 63 rotate(xyz2, node->translation); |
64 rotate(xyz3, node->translation); | 64 rotate(xyz3, node->translation); |
65 | 65 |
66 pp->tri[pt].ver1.x = xyz1[0]; | 66 pp->tri[pt].ver1.x = xyz1[0]; |
67 pp->tri[pt].ver1.y = xyz1[1]; | 67 pp->tri[pt].ver1.y = xyz1[1]; |
68 pp->tri[pt].ver1.z = xyz1[2]; | 68 pp->tri[pt].ver1.z = xyz1[2]; |
69 pp->tri[pt].ver1.tex_x = node->texture[nt]; | 69 pp->tri[pt].ver1.tex_x = node->texture[nt]; |
70 pp->tri[pt].ver1.tex_y = node->texture[nt+1]; | 70 pp->tri[pt].ver1.tex_y = node->texture[nt+1]; |
71 | 71 |
72 pp->tri[pt].ver2.x = xyz2[0]; | 72 pp->tri[pt].ver2.x = xyz2[0]; |
73 pp->tri[pt].ver2.y = xyz2[1]; | 73 pp->tri[pt].ver2.y = xyz2[1]; |
74 pp->tri[pt].ver2.z = xyz2[2]; | 74 pp->tri[pt].ver2.z = xyz2[2]; |
75 pp->tri[pt].ver2.tex_x = node->texture[nt+2]; | 75 pp->tri[pt].ver2.tex_x = node->texture[nt+2]; |
76 pp->tri[pt].ver2.tex_y = node->texture[nt+2+1]; | 76 pp->tri[pt].ver2.tex_y = node->texture[nt+2+1]; |
77 | 77 |
78 pp->tri[pt].ver3.x = xyz3[0]; | 78 pp->tri[pt].ver3.x = xyz3[0]; |
79 pp->tri[pt].ver3.y = xyz3[1]; | 79 pp->tri[pt].ver3.y = xyz3[1]; |
80 pp->tri[pt].ver3.z = xyz3[2]; | 80 pp->tri[pt].ver3.z = xyz3[2]; |
81 pp->tri[pt].ver3.tex_x = node->texture[nt+4]; | 81 pp->tri[pt].ver3.tex_x = node->texture[nt+4]; |
82 pp->tri[pt].ver3.tex_y = node->texture[nt+4+1]; | 82 pp->tri[pt].ver3.tex_y = node->texture[nt+4+1]; |
83 | 83 |
84 pp->tri[pt].tex_width = node->tex_width; | 84 pp->tri[pt].tex_width = node->tex_width; |
85 pp->tri[pt].tex_height = node->tex_height; | 85 pp->tri[pt].tex_height = node->tex_height; |
86 } | 86 } |
87 pp->info.size = pt; | 87 pp->info.size = pt; |
88 pp->ssl = sgp->ssl; | 88 pp->ssl = sgp->ssl; |
89 } | 89 } |
90 | 90 |
91 return sizeof(PolygonPack); | 91 return sizeof(PolygonPack); |
92 } | 92 } |
93 | |
94 | 93 |
95 void | 94 void |
96 CreatePolygonPack::rotate(float *xyz, float *matrix) | 95 CreatePolygonPack::rotate(float *xyz, float *matrix) |
97 { | 96 { |
98 #if 1 | 97 #if 1 |
99 float abc[4]; | 98 float abc[4]; |
100 | 99 |
101 abc[0] = xyz[0]; | 100 abc[0] = xyz[0]; |
102 abc[1] = xyz[1]; | 101 abc[1] = xyz[1]; |
103 abc[2] = xyz[2]; | 102 abc[2] = xyz[2]; |
104 abc[3] = xyz[3]; | 103 abc[3] = xyz[3]; |
105 | 104 |
106 // SIMD �Ȥ����� | 105 // SIMD �Ȥ����� |
107 for (int i=0; i<4; i++) | 106 for (int i=0; i<4; i++) |
108 { | 107 { |
109 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; | 108 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; |
110 } | 109 } |
111 #else | 110 #else |
112 vector float *abc = (vector float *)xyz; | 111 vector float *abc = (vector float *)xyz; |
113 float tmp[4]; | 112 float tmp[4]; |
114 | 113 |
115 vector float matrixT0 = (vector float){matrix[0], matrix[4], matrix[8], matrix[12]}; | 114 vector float matrixT0 = (vector float){matrix[0], matrix[4], matrix[8], matrix[12]}; |
116 vector float matrixT1 = (vector float){matrix[1], matrix[5], matrix[9], matrix[13]}; | 115 vector float matrixT1 = (vector float){matrix[1], matrix[5], matrix[9], matrix[13]}; |
117 vector float matrixT2 = (vector float){matrix[2], matrix[6], matrix[10], matrix[14]}; | 116 vector float matrixT2 = (vector float){matrix[2], matrix[6], matrix[10], matrix[14]}; |
118 vector float matrixT3 = (vector float){matrix[3], matrix[7], matrix[11], matrix[15]}; | 117 vector float matrixT3 = (vector float){matrix[3], matrix[7], matrix[11], matrix[15]}; |
119 | 118 |
120 #if 1 | 119 #if 1 |
121 vector float *v_tmp = (vector float *)tmp; | 120 vector float *v_tmp = (vector float *)tmp; |
122 | 121 |
123 *v_tmp = spu_mul(*abc, matrixT0); | 122 *v_tmp = spu_mul(*abc, matrixT0); |
124 xyz[0] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; | 123 xyz[0] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; |
125 *v_tmp = spu_mul(*abc, matrixT1); | 124 *v_tmp = spu_mul(*abc, matrixT1); |
126 xyz[1] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; | 125 xyz[1] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; |
127 *v_tmp = spu_mul(*abc, matrixT2); | 126 *v_tmp = spu_mul(*abc, matrixT2); |
128 xyz[2] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; | 127 xyz[2] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; |
129 *v_tmp = spu_mul(*abc, matrixT3); | 128 *v_tmp = spu_mul(*abc, matrixT3); |
130 xyz[3] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; | 129 xyz[3] = tmp[0] + tmp[1] + tmp[2] + tmp[3]; |
131 #else | 130 #else |
132 vector float v_tmp; | 131 vector float v_tmp; |
133 | 132 |
134 v_tmp = spu_mul(*abc, matrixT0); | 133 v_tmp = spu_mul(*abc, matrixT0); |
135 xyz[0] = sum_across_float4(v_tmp); | 134 xyz[0] = sum_across_float4(v_tmp); |
136 v_tmp = spu_mul(*abc, matrixT1); | 135 v_tmp = spu_mul(*abc, matrixT1); |
137 xyz[1] = sum_across_float4(v_tmp); | 136 xyz[1] = sum_across_float4(v_tmp); |
138 v_tmp = spu_mul(*abc, matrixT2); | 137 v_tmp = spu_mul(*abc, matrixT2); |
139 xyz[2] = sum_across_float4(v_tmp); | 138 xyz[2] = sum_across_float4(v_tmp); |
140 v_tmp = spu_mul(*abc, matrixT3); | 139 v_tmp = spu_mul(*abc, matrixT3); |
141 xyz[3] = sum_across_float4(v_tmp); | 140 xyz[3] = sum_across_float4(v_tmp); |
142 #endif | 141 #endif |
143 #endif | 142 #endif |
144 | 143 |
145 } | 144 } |
146 | 145 |
147 SchedTask* | 146 SchedTask* |
148 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task, | 147 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task, |
149 void *rbuff, void *wbuff, DmaManager *dma) | 148 void *rbuff, void *wbuff, DmaManager *dma) |
150 { | 149 { |
151 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma); | 150 //rbuff = memalign(16, sizeof(SceneGraphPack)); |
151 //wbuff = memalign(16, sizeof(PolygonPack)); | |
152 | |
153 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma); | |
152 } | 154 } |