Revision: 22299
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22299
Author:   jaguarandi
Date:     2009-08-07 15:49:15 +0200 (Fri, 07 Aug 2009)

Log Message:
-----------
*BLI_memarena support for any power of two alignment
*some simd stuff on bvh

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/blenlib/BLI_memarena.h
    branches/soc-2009-jaguarandi/source/blender/blenlib/intern/BLI_memarena.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
    
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp

Modified: branches/soc-2009-jaguarandi/source/blender/blenlib/BLI_memarena.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/blenlib/BLI_memarena.h  
2009-08-07 13:19:17 UTC (rev 22298)
+++ branches/soc-2009-jaguarandi/source/blender/blenlib/BLI_memarena.h  
2009-08-07 13:49:15 UTC (rev 22299)
@@ -57,6 +57,8 @@
 void                           BLI_memarena_use_malloc (struct MemArena *ma);
 void                           BLI_memarena_use_calloc (struct MemArena *ma);
 
+void                           BLI_memarena_use_align(struct MemArena *ma, int 
align);
+
 void*                          BLI_memarena_alloc      (struct MemArena *ma, 
int size);
 
 #ifdef __cplusplus

Modified: 
branches/soc-2009-jaguarandi/source/blender/blenlib/intern/BLI_memarena.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/blenlib/intern/BLI_memarena.c   
2009-08-07 13:19:17 UTC (rev 22298)
+++ branches/soc-2009-jaguarandi/source/blender/blenlib/intern/BLI_memarena.c   
2009-08-07 13:49:15 UTC (rev 22299)
@@ -45,6 +45,7 @@
        int bufsize, cursize;
        
        int use_calloc; 
+       int align;
        
        LinkNode *bufs;
 };
@@ -52,6 +53,7 @@
 MemArena *BLI_memarena_new(int bufsize) {
        MemArena *ma= MEM_callocN(sizeof(*ma), "memarena");
        ma->bufsize= bufsize;
+       ma->align = 8;
        
        return ma;
 }
@@ -64,6 +66,11 @@
        ma->use_calloc= 0;
 }
 
+void BLI_memarena_use_align(struct MemArena *ma, int align) {
+       /* align should be a power of two */
+       ma->align = align;
+}
+
 void BLI_memarena_free(MemArena *ma) {
        BLI_linklist_free(ma->bufs, (void(*)(void*)) MEM_freeN);
        MEM_freeN(ma);
@@ -77,16 +84,28 @@
 
                /* ensure proper alignment by rounding
                 * size up to multiple of 8 */  
-       size= PADUP(size, 8);
+       size= PADUP(size, ma->align);
        
        if (size>ma->cursize) {
-               ma->cursize= (size>ma->bufsize)?size:ma->bufsize;
+               unsigned char *tmp;
+               
+               if(size > ma->bufsize - (ma->align - 1))
+               {
+                       ma->cursize = PADUP(size+1, ma->align);
+               }
+               else ma->cursize = ma->bufsize;
+
                if(ma->use_calloc)
                        ma->curbuf= MEM_callocN(ma->cursize, "memarena calloc");
                else
                        ma->curbuf= MEM_mallocN(ma->cursize, "memarena malloc");
                
                BLI_linklist_prepend(&ma->bufs, ma->curbuf);
+
+               /* align alloc'ed memory (needed if align > 8) */
+               tmp = (unsigned char*)PADUP( (intptr_t) ma->curbuf, ma->align);
+               ma->cursize -= (tmp - ma->curbuf);
+               ma->curbuf = tmp;               
        }
        
        ptr= ma->curbuf;

Modified: 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h    
2009-08-07 13:19:17 UTC (rev 22298)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h    
2009-08-07 13:49:15 UTC (rev 22299)
@@ -196,18 +196,18 @@
                        const float *bb2 = stack[stack_pos+2]->bb;
                        const float *bb3 = stack[stack_pos+3]->bb;
                        
-                       const __m128 x0y0x1y1 = _mm_shuffle_ps( 
_mm_loadu_ps(bb0), _mm_loadu_ps(bb1), _MM_SHUFFLE(1,0,1,0) );
-                       const __m128 x2y2x3y3 = _mm_shuffle_ps( 
_mm_loadu_ps(bb2), _mm_loadu_ps(bb3), _MM_SHUFFLE(1,0,1,0) );
+                       const __m128 x0y0x1y1 = _mm_shuffle_ps( 
_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1,0,1,0) );
+                       const __m128 x2y2x3y3 = _mm_shuffle_ps( 
_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1,0,1,0) );
                        t_bb[0] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, 
_MM_SHUFFLE(2,0,2,0) );
                        t_bb[1] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, 
_MM_SHUFFLE(3,1,3,1) );
 
-                       const __m128 z0X0z1X1 = _mm_shuffle_ps( 
_mm_loadu_ps(bb0+2), _mm_loadu_ps(bb1+2), _MM_SHUFFLE(1,0,1,0) );
-                       const __m128 z2X2z3X3 = _mm_shuffle_ps( 
_mm_loadu_ps(bb2+2), _mm_loadu_ps(bb3+2), _MM_SHUFFLE(1,0,1,0) );
+                       const __m128 z0X0z1X1 = _mm_shuffle_ps( 
_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3,1,3,1) );
+                       const __m128 z2X2z3X3 = _mm_shuffle_ps( 
_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3,1,3,1) );
                        t_bb[2] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, 
_MM_SHUFFLE(2,0,2,0) );
                        t_bb[3] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, 
_MM_SHUFFLE(3,1,3,1) );
 
-                       const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps( 
_mm_loadu_ps(bb0+4), _mm_loadu_ps(bb1+4), _MM_SHUFFLE(1,0,1,0) );
-                       const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps( 
_mm_loadu_ps(bb2+4), _mm_loadu_ps(bb3+4), _MM_SHUFFLE(1,0,1,0) );
+                       const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps( 
_mm_load_ps(bb0+4), _mm_load_ps(bb1+4), _MM_SHUFFLE(1,0,1,0) );
+                       const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps( 
_mm_load_ps(bb2+4), _mm_load_ps(bb3+4), _MM_SHUFFLE(1,0,1,0) );
                        t_bb[4] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, 
_MM_SHUFFLE(2,0,2,0) );
                        t_bb[5] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, 
_MM_SHUFFLE(3,1,3,1) );
 /*                     

Modified: 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
===================================================================
--- 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
       2009-08-07 13:19:17 UTC (rev 22298)
+++ 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
       2009-08-07 13:49:15 UTC (rev 22299)
@@ -56,14 +56,14 @@
 
 struct BVHNode
 {
-       BVHNode *child;
-       BVHNode *sibling;
-
 #ifdef DYNAMIC_ALLOC_BB
        float *bb;
 #else
        float   bb[6];
 #endif
+
+       BVHNode *child;
+       BVHNode *sibling;
 };
 
 struct BVHTree
@@ -114,6 +114,12 @@
 static BVHNode *bvh_new_node(BVHTree *tree)
 {
        BVHNode *node = (BVHNode*)BLI_memarena_alloc(tree->node_arena, 
sizeof(BVHNode));
+       
+       if( (((intptr_t)node) & (0x0f)) != 0 )
+       {
+               puts("WRONG!");
+               printf("%08x\n", (intptr_t)node);
+       }
        node->sibling = NULL;
        node->child   = NULL;
 
@@ -317,6 +323,7 @@
 
        obj->node_arena = BLI_memarena_new(needed_nodes);
        BLI_memarena_use_malloc(obj->node_arena);
+       BLI_memarena_use_align(obj->node_arena, 16);
 
        
        obj->root = bvh_rearrange<BVHTree,BVHNode,RTBuilder>( obj, obj->builder 
);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to