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