changeset 1129:a8bffdb5d2e3 draft

bus error
author yutaka@localhost.localdomain
date Sun, 13 Feb 2011 07:20:55 +0900
parents 293b36802714
children 5addc6c1d5c4
files Renderer/Engine/Camera.cc Renderer/Engine/ChangeLog Renderer/Engine/Makefile.def Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h Renderer/Engine/polygon.cc Renderer/Engine/polygon.h Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc Renderer/Engine/texture.h Renderer/Engine/viewer.cc Renderer/Test/Makefile.def TaskManager/Makefile.def
diffstat 12 files changed, 88 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/Camera.cc	Sun Feb 13 07:20:55 2011 +0900
@@ -114,6 +114,9 @@
  */
 Camera::Camera(float w, float h, SceneGraphRoot *sgroot_)
 {
+
+  printf("camera \n");
+
     name = (char*)"Camera";
     sgroot = sgroot_;
 
@@ -146,16 +149,13 @@
     
     this->set_move_collision(camera_move, camera_collision, (void *)sgroot);
 
-#if SPE_CREATE_POLYGON
-
-#endif
-
     for(int i = 0; i < 16; i++) {
       real_matrix[i] = 0;
       if (i % 5 == 0) {
         real_matrix[i] = 1;
       }
-    }
+      }
+    
 
     update(w,h); // to make matrix[]
 }
--- a/Renderer/Engine/ChangeLog	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/ChangeLog	Sun Feb 13 07:20:55 2011 +0900
@@ -1,3 +1,10 @@
+2011-2-14 Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
+
+	CreatePolygonFromScenenGraph を SPEで動くようにTask化。もうできるのはわかっているけど
+	今はバスエラーです。polygon.h が持っている matrix, real_matrix, texture_info にアラインメント
+	合わせないとダメです。いろいろ書きなおさないとアラインメントかけれない?どーも簡単にはいかない。
+	継承関係あたりちょっと見直しが必要。
+
 2010-8-6  Shinji Kono  <kono@ie.u-ryukyu.ac.jp>
 
 	Renderer Engine の task の下に user task を置くのは反則だろ?
--- a/Renderer/Engine/Makefile.def	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/Makefile.def	Sun Feb 13 07:20:55 2011 +0900
@@ -5,7 +5,7 @@
 ABIBIT = 64 
 ABI = -m$(ABIBIT)
 CC      = g++
-OPT	=  -g #-O9 
+OPT	=  -O9 
 CFLAGS  = -Wall $(ABI) $(OPT)  #  -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I.
--- a/Renderer/Engine/SceneGraph.cc	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Sun Feb 13 07:20:55 2011 +0900
@@ -120,6 +120,7 @@
  */
 SceneGraph::SceneGraph()
 {
+
     init();
     finalize = &SceneGraph::finalize_copy;
 
@@ -133,6 +134,7 @@
 {
 
     init();
+
     memcpy(this, orig, sizeof(SceneGraph));
 
     // コピーしない
--- a/Renderer/Engine/SceneGraph.h	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/SceneGraph.h	Sun Feb 13 07:20:55 2011 +0900
@@ -18,7 +18,7 @@
 
 class SceneGraph : public Polygon {
 public:
-    SceneGraph(void);
+    SceneGraph();
     SceneGraph(TaskManager *manager, xmlNodePtr surface);
     SceneGraph(SceneGraphPtr orig);
     ~SceneGraph(void);
--- a/Renderer/Engine/polygon.cc	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/polygon.cc	Sun Feb 13 07:20:55 2011 +0900
@@ -23,6 +23,7 @@
 void
 Polygon::position_init(void)
 {
+
     xyz[0] = 0;
     xyz[1] = 0;
     xyz[2] = 0;
@@ -40,11 +41,6 @@
     scale[2] = 1;
 
 
-    for (int i = 0; i < 16; i++) {
-        matrix[i] = 0;
-	real_matrix[i] = 0;
-    }
-
 }
 
 void Polygon::pickup_coordinate(char *cont)
--- a/Renderer/Engine/polygon.h	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/polygon.h	Sun Feb 13 07:20:55 2011 +0900
@@ -6,6 +6,7 @@
 #include "polygon_pack.h"
 #include "SpanPack.h"
 #include "texture.h"
+#include "TaskManager.h"
 
 class Polygon {
 public:
@@ -15,10 +16,14 @@
 
     //float *data;    //"vertex" and "normal" and "texture"
 
-    float matrix[16] __attribute__((aligned(16)));;
-    float real_matrix[16] __attribute__((aligned(16)));;
-    texture_list texture_info __attribute__((aligned(16)));;
+    //float *matrix;
+    //float *real_matrix;
+    //texture_list *texture_info;
 
+    float matrix[16] ;
+    float real_matrix[16] ;
+    texture_list texture_info;
+      
     PolygonPackPtr pp;
     int pp_num;
 
--- a/Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc	Sun Feb 13 07:20:55 2011 +0900
@@ -8,8 +8,7 @@
 #include "polygon_pack.h"
 #include "texture.h"
 
-SchedDefineTask1(CreatePolygonFromSceneGraph, createPolygonFromSceneGraph);
-
+SchedDefineTask(CreatePolygonFromSceneGraph);
 
 /**
  *  ベクトルに行列を乗算する
@@ -31,22 +30,9 @@
     }
 }
 
-static void
-ApplyNormalMatrix(float *v, float *m)
-{
-    float t[4];
-
-    t[0] = v[0];
-    t[1] = v[1];
-    t[2] = v[2];
-
-    for (int i = 0; i < 3; i++) {
-        v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8];
-    }
-}
 
 static int 
-createPolygonFromSceneGraph(SchedTask *smanager, void *rbuf, void *wbuf)
+run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
     float xyz1[4], xyz2[4], xyz3[4];
     float normal1[4],normal2[4],normal3[4];
@@ -56,10 +42,17 @@
     float *matrix             = (float*)smanager->get_input(rbuf, 1);
     float *real_matrix        = (float*)smanager->get_input(rbuf, 2);
     texture_list *tritexinfo  = (texture_list*)smanager->get_input(rbuf, 3);
+    
+    PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0);
 
 
     PolygonPackPtr out_pp = (PolygonPackPtr)smanager->get_output(wbuf, 0);
     out_pp->info.size = in_pp->info.size;
+    out_pp->next = next;
+
+    if (in_pp->info.size == 0) {
+      printf("in_pp->info.size = 0\n");
+    }
 
     for (int i = 0; i < in_pp->info.size; i++) {
 
@@ -67,17 +60,17 @@
       
       xyz1[0] = tri.ver1.x;
       xyz1[1] = tri.ver1.y;
-      xyz1[2] = tri.ver1.z;
+      xyz1[2] = tri.ver1.z * -1.0f;
       xyz1[3] = 1.0f;
       
       xyz2[0] = tri.ver2.x;
       xyz2[1] = tri.ver2.y;
-      xyz2[2] = tri.ver2.z;
+      xyz2[2] = tri.ver2.z * -1.0f;
       xyz2[3] = 1.0f;
       
       xyz3[0] = tri.ver3.x;
       xyz3[1] = tri.ver3.y;
-      xyz3[2] = tri.ver3.z;
+      xyz3[2] = tri.ver3.z * -1.0f;
       xyz3[3] = 1.0f;
       
       // matrix = 回転行列*透視変換行列
@@ -92,25 +85,25 @@
       xyz3[0] /= xyz3[2];
       xyz3[1] /= xyz3[2];
    
-      TrianglePack triangle = out_pp->tri[i];
+      TrianglePackPtr triangle = &out_pp->tri[i];
 
-      triangle.ver1.x = xyz1[0];
-      triangle.ver1.y = xyz1[1];
-      triangle.ver1.z = xyz1[2];
-      triangle.ver1.tex_x = tri.ver1.tex_x;
-      triangle.ver1.tex_y = tri.ver1.tex_y;
+      triangle->ver1.x = xyz1[0];
+      triangle->ver1.y = xyz1[1];
+      triangle->ver1.z = xyz1[2];
+      triangle->ver1.tex_x = tri.ver1.tex_x;
+      triangle->ver1.tex_y = tri.ver1.tex_y;
       
-      triangle.ver2.x = xyz2[0];
-      triangle.ver2.y = xyz2[1];
-      triangle.ver2.z = xyz2[2];
-      triangle.ver2.tex_x = tri.ver2.tex_x;
-      triangle.ver2.tex_y = tri.ver2.tex_y;
+      triangle->ver2.x = xyz2[0];
+      triangle->ver2.y = xyz2[1];
+      triangle->ver2.z = xyz2[2];
+      triangle->ver2.tex_x = tri.ver2.tex_x;
+      triangle->ver2.tex_y = tri.ver2.tex_y;
       
-      triangle.ver3.x = xyz3[0];
-      triangle.ver3.y = xyz3[1];
-      triangle.ver3.z = xyz3[2];
-      triangle.ver3.tex_x = tri.ver3.tex_x;
-      triangle.ver3.tex_y = tri.ver3.tex_y;
+      triangle->ver3.x = xyz3[0];
+      triangle->ver3.y = xyz3[1];
+      triangle->ver3.z = xyz3[2];
+      triangle->ver3.tex_x = tri.ver3.tex_x;
+      triangle->ver3.tex_y = tri.ver3.tex_y;
       
       normal1[0] = tri.normal1.x;
       normal1[1] = tri.normal1.y;
@@ -130,9 +123,9 @@
       //normal3[3] = 1.0f;
       normal3[3] = 0.0f;
       
-      ApplyNormalMatrix(normal1,real_matrix);
-      ApplyNormalMatrix(normal2,real_matrix);
-      ApplyNormalMatrix(normal3,real_matrix);
+      ApplyMatrix(normal1,real_matrix);
+      ApplyMatrix(normal2,real_matrix);
+      ApplyMatrix(normal3,real_matrix);
       
       normal1[0] /= normal1[2];
       normal1[1] /= normal1[2];
@@ -143,22 +136,22 @@
       normal3[0] /= normal3[2];
       normal3[1] /= normal3[2];
       
-      triangle.normal1.x = normal1[0];
-      triangle.normal1.y = normal1[1];
-      triangle.normal1.z = normal1[2];
+      triangle->normal1.x = normal1[0];
+      triangle->normal1.y = normal1[1];
+      triangle->normal1.z = normal1[2];
       
-      triangle.normal2.x = normal2[0];
-      triangle.normal2.y = normal2[1];
-      triangle.normal2.z = normal2[2];
+      triangle->normal2.x = normal2[0];
+      triangle->normal2.y = normal2[1];
+      triangle->normal2.z = normal2[2];
       
-      triangle.normal3.x = normal3[0];
-      triangle.normal3.y = normal3[1];
-      triangle.normal3.z = normal3[2];
+      triangle->normal3.x = normal3[0];
+      triangle->normal3.y = normal3[1];
+      triangle->normal3.z = normal3[2];
       
-      triangle.tex_info.addr   = tritexinfo->pixels;
-      triangle.tex_info.width  = tritexinfo->t_w;
-      triangle.tex_info.height = tritexinfo->t_h;
-      triangle.tex_info.scale_max = tritexinfo->scale_max;
+      triangle->tex_info.addr   = tritexinfo->pixels;
+      triangle->tex_info.width  = tritexinfo->t_w;
+      triangle->tex_info.height = tritexinfo->t_h;
+      triangle->tex_info.scale_max = tritexinfo->scale_max;
     }
 
     return 0;
--- a/Renderer/Engine/texture.h	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/texture.h	Sun Feb 13 07:20:55 2011 +0900
@@ -33,7 +33,7 @@
     void *gl_tex;
     int texture_id;
 
-} texture_list, *texture_list_ptr ; // 20 + pad(12) = 32
+} texture_list, *texture_list_ptr; // 20 + pad(12) = 32
 
 #endif
 
--- a/Renderer/Engine/viewer.cc	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Engine/viewer.cc	Sun Feb 13 07:20:55 2011 +0900
@@ -101,6 +101,7 @@
     light_xyz_stock = (float *)manager->allocate(size);
     light_xyz = (float *)manager->allocate(size);
 
+	
     for (int i = 0; i < light_size ; i++) {
       light_xyz[i] = 0.0f;
     }
@@ -360,8 +361,8 @@
 }
 
 void 
-Viewer::rendering(HTaskPtr task_next)
-{
+Viewer::rendering(HTaskPtr task_next) {
+
     common_rendering(task_next, sgroot);
     
     // Barrier 同期
@@ -455,10 +456,23 @@
 
       for (int i = 0; i < t->pp_num; i++) {
 	HTaskPtr create_pp = manager->create_task(CreatePolygonFromSceneGraph);
+
 	create_pp->add_inData(&t->pp[i], sizeof(PolygonPack));
 	create_pp->add_inData(t->matrix, sizeof(float)*16);
 	create_pp->add_inData(t->real_matrix, sizeof(float)*16);
 	create_pp->add_inData(&t->texture_info, sizeof(texture_list));
+
+	if ( (unsigned long)t->matrix & 0xf) {
+	  printf("marix not aligned\n");
+	}
+
+	if ((unsigned long)t->real_matrix & 0xf) {
+	  printf("real_matrix not aligned\n");
+	}
+
+	if ((unsigned long)&t->texture_info & 0xf) {
+	  printf("texture_info not aligned\n");
+	}
 	
 	create_pp->add_outData(out_pp, sizeof(PolygonPack));
 
--- a/Renderer/Test/Makefile.def	Mon Feb 14 02:24:28 2011 +0900
+++ b/Renderer/Test/Makefile.def	Sun Feb 13 07:20:55 2011 +0900
@@ -4,7 +4,7 @@
 ABIBIT = 64
 ABI =  -m$(ABIBIT)
 CC      = g++
-CFLAGS  = -g -Wall $(ABI) # -O9   # -O -DDEBUG
+CFLAGS  = -g -Wall $(ABI) -O9   # -O -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I$(CERIUM)/Renderer/Engine -I. -I$(CERIUM)/include/Cerium
 LIBS = -L$(CERIUM)/TaskManager -L$(CERIUM)/Renderer/Engine $(ABI)
--- a/TaskManager/Makefile.def	Mon Feb 14 02:24:28 2011 +0900
+++ b/TaskManager/Makefile.def	Sun Feb 13 07:20:55 2011 +0900
@@ -29,7 +29,7 @@
 
 ABIBIT = 64
 
-OPT = -g  -DMAIL_QUEUE
+OPT = -O9  -DMAIL_QUEUE
 # -DEARLY_TOUCH
 # -g -DTASK_LIST_MAIL -O9