comparison TaskManager/Test/simple_render/spe/CreatePolygonPack.cpp @ 109:5c194c71eca8

Cerium cvs version
author gongo@gendarme.local
date Wed, 12 Nov 2008 17:39:33 +0900
parents c9efdb17e8d2
children 58fd16298954
comparison
equal deleted inserted replaced
108:6f3b3dd3c095 109:5c194c71eca8
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <spu_intrinsics.h> 2 #include <stdlib.h>
3 #include <malloc.h>
3 #include "CreatePolygonPack.h" 4 #include "CreatePolygonPack.h"
4 #include "polygon_pack.h" 5 #include "polygon_pack.h"
5 #include "scene_graph_pack.h" 6 #include "scene_graph_pack.h"
6 #include "sys.h"
7 7
8 8
9 void 9 void
10 CreatePolygonPack::read(void) 10 CreatePolygonPack::read(void)
11 { 11 {
12 printf("CreatePolgonPack\n"); 12 SchedTask::read();
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));
34 } 13 }
35 14
36 int 15 int
37 CreatePolygonPack::run(void *rbuf, void *wbuf) 16 CreatePolygonPack::run(void *rbuf, void *wbuf)
38 { 17 {
39 SceneGraphPack *sgp = (SceneGraphPack*)rbuf; 18 SceneGraphPack *sgp = (SceneGraphPack*)rbuf;
40 PolygonPack *pp = (PolygonPack*)wbuf; 19 PolygonPack *pp = (PolygonPack*)wbuf;
41 20
42 float xyz1[4],xyz2[4],xyz3[4]; 21 float xyz1[4],xyz2[4],xyz3[4];
43 22
44 for (int i = 0; i < sgp->info.size; i++) { 23 for (int i = 0; i < sgp->info.size; i++) {
45 SceneGraphNodePtr node = &sgp->node[i]; 24 SceneGraphNodePtr node = &sgp->node[i];
46 25
47 int n,nt,pt; 26 int n,nt,pt;
48 for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { 27 for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) {
49 xyz1[0] = node->vertex[n]; 28 xyz1[0] = node->vertex[n];
50 xyz1[1] = node->vertex[n+1]; 29 xyz1[1] = node->vertex[n+1];
51 xyz1[2] = node->vertex[n+2]*-1; 30 xyz1[2] = node->vertex[n+2]*-1;
52 xyz1[3] = 1; 31 xyz1[3] = 1;
53 xyz2[0] = node->vertex[n+3]; 32 xyz2[0] = node->vertex[n+3];
54 xyz2[1] = node->vertex[n+3+1]; 33 xyz2[1] = node->vertex[n+3+1];
55 xyz2[2] = node->vertex[n+3+2]*-1; 34 xyz2[2] = node->vertex[n+3+2]*-1;
56 xyz2[3] = 1; 35 xyz2[3] = 1;
57 xyz3[0] = node->vertex[n+6]; 36 xyz3[0] = node->vertex[n+6];
58 xyz3[1] = node->vertex[n+6+1]; 37 xyz3[1] = node->vertex[n+6+1];
59 xyz3[2] = node->vertex[n+6+2]*-1; 38 xyz3[2] = node->vertex[n+6+2]*-1;
60 xyz3[3] = 1; 39 xyz3[3] = 1;
61 40
62 rotate(xyz1, node->translation); 41 rotate(xyz1, node->translation);
63 rotate(xyz2, node->translation); 42 rotate(xyz2, node->translation);
64 rotate(xyz3, node->translation); 43 rotate(xyz3, node->translation);
65 44
66 pp->tri[pt].ver1.x = xyz1[0]; 45 pp->tri[pt].ver1.x = xyz1[0];
67 pp->tri[pt].ver1.y = xyz1[1]; 46 pp->tri[pt].ver1.y = xyz1[1];
68 pp->tri[pt].ver1.z = xyz1[2]; 47 pp->tri[pt].ver1.z = xyz1[2];
69 pp->tri[pt].ver1.tex_x = node->texture[nt]; 48 pp->tri[pt].ver1.tex_x = node->texture[nt];
70 pp->tri[pt].ver1.tex_y = node->texture[nt+1]; 49 pp->tri[pt].ver1.tex_y = node->texture[nt+1];
71 50
72 pp->tri[pt].ver2.x = xyz2[0]; 51 pp->tri[pt].ver2.x = xyz2[0];
73 pp->tri[pt].ver2.y = xyz2[1]; 52 pp->tri[pt].ver2.y = xyz2[1];
74 pp->tri[pt].ver2.z = xyz2[2]; 53 pp->tri[pt].ver2.z = xyz2[2];
75 pp->tri[pt].ver2.tex_x = node->texture[nt+2]; 54 pp->tri[pt].ver2.tex_x = node->texture[nt+2];
76 pp->tri[pt].ver2.tex_y = node->texture[nt+2+1]; 55 pp->tri[pt].ver2.tex_y = node->texture[nt+2+1];
77 56
78 pp->tri[pt].ver3.x = xyz3[0]; 57 pp->tri[pt].ver3.x = xyz3[0];
79 pp->tri[pt].ver3.y = xyz3[1]; 58 pp->tri[pt].ver3.y = xyz3[1];
80 pp->tri[pt].ver3.z = xyz3[2]; 59 pp->tri[pt].ver3.z = xyz3[2];
81 pp->tri[pt].ver3.tex_x = node->texture[nt+4]; 60 pp->tri[pt].ver3.tex_x = node->texture[nt+4];
82 pp->tri[pt].ver3.tex_y = node->texture[nt+4+1]; 61 pp->tri[pt].ver3.tex_y = node->texture[nt+4+1];
83 62
84 pp->tri[pt].tex_width = node->tex_width; 63 pp->tri[pt].tex_width = node->tex_width;
85 pp->tri[pt].tex_height = node->tex_height; 64 pp->tri[pt].tex_height = node->tex_height;
86 } 65 }
87 pp->info.size = pt; 66 pp->info.size = pt;
88 pp->ssl = sgp->ssl; 67 pp->ssl = sgp->ssl;
89 } 68 }
90 69
91 return sizeof(PolygonPack); 70 return sizeof(PolygonPack);
92 } 71 }
93 72
73 void
74 CreatePolygonPack::write(void)
75 {
76 SchedTask::write();
77
78 free(readbuf);
79 free(writebuf);
80 }
94 81
95 void 82 void
96 CreatePolygonPack::rotate(float *xyz, float *matrix) 83 CreatePolygonPack::rotate(float *xyz, float *matrix)
97 { 84 {
98 #if 1 85 float abc[4];
99 float abc[4];
100 86
101 abc[0] = xyz[0]; 87 abc[0] = xyz[0];
102 abc[1] = xyz[1]; 88 abc[1] = xyz[1];
103 abc[2] = xyz[2]; 89 abc[2] = xyz[2];
104 abc[3] = xyz[3]; 90 abc[3] = xyz[3];
105 91
106 // SIMD 使えるよね 92 // SIMD 使えるよね
107 for (int i=0; i<4; i++) 93 for (int i=0; i<4; i++)
108 { 94 {
109 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; 95 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4]
110 } 96 + abc[2]*matrix[i+8] + abc[3]*matrix[i+12];
111 #else 97 }
112 vector float *abc = (vector float *)xyz;
113 float tmp[4];
114
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
145 } 98 }
146 99
147 SchedTask* 100 SchedTask*
148 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task, 101 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task,
149 void *rbuff, void *wbuff, DmaManager *dma) 102 void *rbuff, void *wbuff, DmaManager *dma)
150 { 103 {
151 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma); 104 rbuff = memalign(16, sizeof(SceneGraphPack));
105 wbuff = memalign(16, sizeof(PolygonPack));
106
107 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma);
152 } 108 }