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