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