annotate TaskManager/Test/simple_render/spe/CreatePolygonPack.cpp @ 85:9b96b190cb73

*** empty log message ***
author gongo
date Wed, 27 Feb 2008 04:25:04 +0900
parents 9b0b11bf4085
children 265fb700dd4c
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
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
57 pp->tri[pt].x1 = xyz1[0];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
58 pp->tri[pt].y1 = xyz1[1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
59 pp->tri[pt].z1 = xyz1[2];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
60 pp->tri[pt].tex_x1 = node->texture[nt];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
61 pp->tri[pt].tex_y1 = node->texture[nt+1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
62
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
63 pp->tri[pt].x2 = xyz2[0];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
64 pp->tri[pt].y2 = xyz2[1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
65 pp->tri[pt].z2 = xyz2[2];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
66 pp->tri[pt].tex_x2 = node->texture[nt+2];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
67 pp->tri[pt].tex_y2 = node->texture[nt+2+1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
68
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
69 pp->tri[pt].x3 = xyz3[0];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
70 pp->tri[pt].y3 = xyz3[1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
71 pp->tri[pt].z3 = xyz3[2];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
72 pp->tri[pt].tex_x3 = node->texture[nt+4];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
73 pp->tri[pt].tex_y3 = node->texture[nt+4+1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
74
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
75 }
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
76 pp->info.size = pt;
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
77 }
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
78
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
79 return sizeof(PolygonPack);
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
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
83 void
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
84 CreatePolygonPack::rotate(float *xyz, float *matrix)
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
85 {
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
86 #if 0
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
87 float abc[4];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
88
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
89 abc[0] = xyz[0];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
90 abc[1] = xyz[1];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
91 abc[2] = xyz[2];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
92 abc[3] = xyz[3];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
93
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
94 // SIMD 使えるよね
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
95 for (int i=0; i<4; i++)
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
96 {
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
97 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
98 }
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
99 #else
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
100 vector float *abc = (vector float *)xyz;
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
101 float tmp[4];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
102
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
103 vector float matrixT0 = (vector float){matrix[0], matrix[4], matrix[8], matrix[12]};
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
104 vector float matrixT1 = (vector float){matrix[1], matrix[5], matrix[9], matrix[13]};
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
105 vector float matrixT2 = (vector float){matrix[2], matrix[6], matrix[10], matrix[14]};
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
106 vector float matrixT3 = (vector float){matrix[3], matrix[7], matrix[11], matrix[15]};
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
107
85
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
108 #if 1
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
109 vector float *v_tmp = (vector float *)tmp;
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
110
83
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
111 *v_tmp = spu_mul(*abc, matrixT0);
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
112 xyz[0] = tmp[0] + tmp[1] + tmp[2] + tmp[3];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
113 *v_tmp = spu_mul(*abc, matrixT1);
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
114 xyz[1] = tmp[0] + tmp[1] + tmp[2] + tmp[3];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
115 *v_tmp = spu_mul(*abc, matrixT2);
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
116 xyz[2] = tmp[0] + tmp[1] + tmp[2] + tmp[3];
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
117 *v_tmp = spu_mul(*abc, matrixT3);
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
118 xyz[3] = tmp[0] + tmp[1] + tmp[2] + tmp[3];
85
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
119 #else
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
120 vector float v_tmp;
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
121
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
122 v_tmp = spu_mul(*abc, matrixT0);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
123 xyz[0] = sum_across_float4(v_tmp);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
124 v_tmp = spu_mul(*abc, matrixT1);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
125 xyz[1] = sum_across_float4(v_tmp);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
126 v_tmp = spu_mul(*abc, matrixT2);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
127 xyz[2] = sum_across_float4(v_tmp);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
128 v_tmp = spu_mul(*abc, matrixT3);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
129 xyz[3] = sum_across_float4(v_tmp);
9b96b190cb73 *** empty log message ***
gongo
parents: 83
diff changeset
130 #endif
83
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
131 #endif
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
132
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
133 }
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
134
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
135 SchedTask*
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
136 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task,
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
137 void *rbuff, void *wbuff, DmaManager *dma)
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
138 {
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
139 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma);
9b0b11bf4085 *** empty log message ***
gongo
parents:
diff changeset
140 }