annotate TaskManager/Test/simple_render/spe/CreatePolygonPack.cpp @ 87:265fb700dd4c

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