Esempio n. 1
0
void bvh_done<SVBVHTree>(SVBVHTree *obj)
{
	rtbuild_done(obj->builder, &obj->rayobj.control);
	
	//TODO find a away to exactly calculate the needed memory
	MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
					   BLI_memarena_use_malloc(arena1);

	MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
					   BLI_memarena_use_malloc(arena2);
					   BLI_memarena_use_align(arena2, 16);

	//Build and optimize the tree
	if(0)
	{
		VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
		if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
		{
			BLI_memarena_free(arena1);
			BLI_memarena_free(arena2);
			return;
		}
		
		reorganize(root);
		remove_useless(root, &root);
		bvh_refit(root);
	
		pushup(root);
		pushdown(root);
		pushup_simd<VBVHNode,4>(root);
	
		obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
	}
	else
	{
		//Finds the optimal packing of this tree using a given cost model
		//TODO this uses quite a lot of memory, find ways to reduce memory usage during building
		OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);			
		if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
		{
			BLI_memarena_free(arena1);
			BLI_memarena_free(arena2);
			return;
		}

		VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root);
		obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root);
	}

	
	//Free data
	BLI_memarena_free(arena1);
	
	obj->node_arena = arena2;
	obj->cost = 1.0;
	
	
	rtbuild_free( obj->builder );
	obj->builder = NULL;
}
Esempio n. 2
0
void bvh_done<QBVHTree>(QBVHTree *obj)
{
	rtbuild_done(obj->builder, &obj->rayobj.control);
	
	//TODO find a away to exactly calculate the needed memory
	MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena");
	BLI_memarena_use_malloc(arena1);

	MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena 2");
	BLI_memarena_use_malloc(arena2);
	BLI_memarena_use_align(arena2, 16);

	//Build and optimize the tree
	//TODO do this in 1 pass (half memory usage during building)
	VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);

	if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
		BLI_memarena_free(arena1);
		BLI_memarena_free(arena2);
		return;
	}
	
	if (root) {
		pushup_simd<VBVHNode, 4>(root);
		obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
	}
	else
		obj->root = NULL;
	
	//Free data
	BLI_memarena_free(arena1);
	
	obj->node_arena = arena2;
	obj->cost = 1.0;

	rtbuild_free(obj->builder);
	obj->builder = NULL;
}