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