<commit_before>// ======================================================================== //
// Copyright 2009-2014 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "scene.h"

#if !defined(__MIC__)
#include "bvh4/bvh4_builder_toplevel.h" // FIXME: remove
#include "bvh4/bvh4.h"
#include "bvh8/bvh8.h"
#include "bvh4hair/bvh4hair.h"
#include "bvh4mb/bvh4mb.h"
#else
#include "xeonphi/bvh4i/bvh4i.h"
#include "xeonphi/bvh4mb/bvh4mb.h"
#include "xeonphi/bvh4hair/bvh4hair.h"
#endif

namespace embree
{
  Scene::Scene (RTCSceneFlags sflags, RTCAlgorithmFlags aflags)
    : flags(sflags), aflags(aflags), numMappedBuffers(0), is_build(false), needTriangles(false), needVertices(false),
      numTriangleMeshes(0), numTriangleMeshes2(0), numTriangles(0), numTriangles2(0), numBezierCurves(0), numBezierCurves2(0), numUserGeometries1(0), 
      numIntersectionFilters4(0), numIntersectionFilters8(0), numIntersectionFilters16(0)
  {
    if (g_scene_flags != -1)
      flags = (RTCSceneFlags) g_scene_flags;

    geometries.reserve(128);

#if defined(__MIC__)
    accels.add( BVH4mb::BVH4mbTriangle1ObjectSplitBinnedSAH(this) );
    accels.add( BVH4i::BVH4iVirtualGeometryBinnedSAH(this) );
    accels.add( BVH4Hair::BVH4HairBinnedSAH(this) );

    if (g_verbose >= 1)
      {
	std::cout << "scene flags: static " << isStatic() << " compact = " << isCompact() << " high quality = " << isHighQuality() << " robust = " << isRobust() << std::endl;
      }
  
    if (g_tri_accel == "default" || g_tri_accel == "bvh4i")   
      {
	if (g_tri_builder == "default") 
	  {
	    if (isStatic())
	      {
		if (g_verbose >= 1) std::cout << "STATIC BUILDER MODE" << std::endl;
		if ( isCompact() )
		  accels.add(BVH4i::BVH4iTriangle1MemoryConservativeBinnedSAH(this));		    
		else if ( isHighQuality() )
		  accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
		else
		  accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
	      }
	    else
	      {
		if (g_verbose >= 1) std::cout << "DYNAMIC BUILDER MODE" << std::endl;
		accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton(this));
	      }
	  }
	else
	  {
	    if (g_tri_builder == "sah" || g_tri_builder == "bvh4i" || g_tri_builder == "bvh4i.sah") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
	    }
	    else if (g_tri_builder == "fast" || g_tri_builder == "morton") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton(this));
	    }
	    else if (g_tri_builder == "fast_enhanced" || g_tri_builder == "morton.enhanced") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitEnhancedMorton(this));
	    }
	    else if (g_tri_builder == "high_quality" || g_tri_builder == "presplits") {
	      accels.add(BVH4i::BVH4iTriangle1PreSplitsBinnedSAH(this));
	    }
	    else if (g_tri_builder == "compact" ||
		     g_tri_builder == "memory_conservative") {
	      accels.add(BVH4i::BVH4iTriangle1MemoryConservativeBinnedSAH(this));
	    }
	    else if (g_tri_builder == "morton64") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton64Bit(this));
	    }

	    else throw std::runtime_error("unknown builder "+g_tri_builder+" for BVH4i<Triangle1>");
	  }
      }
    else throw std::runtime_error("unknown accel "+g_tri_accel);


#else
    createTriangleAccel();
    accels.add(BVH4MB::BVH4MBTriangle1v(this));
    accels.add(BVH4::BVH4UserGeometry(this));
    createHairAccel();
#endif
  }

#if !defined(__MIC__)

  void Scene::createTriangleAccel()
  {
    if (g_tri_accel == "default") 
    {
      if (isStatic()) {
        int mode =  2*(int)isCompact() + 1*(int)isRobust(); 
        switch (mode) {
        case /*0b00*/ 0: 
#if defined (__TARGET_AVX__)
          if (has_feature(AVX)) 
	  {
            if (isHighQuality()) accels.add(BVH8::BVH8Triangle8SpatialSplit(this)); 
            else                 accels.add(BVH8::BVH8Triangle8ObjectSplit(this)); 
          }
          else 
#endif
          {<commit_msg>enabling bvh8 only on AVX2 machines<commit_after>// ======================================================================== //
// Copyright 2009-2014 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "scene.h"

#if !defined(__MIC__)
#include "bvh4/bvh4_builder_toplevel.h" // FIXME: remove
#include "bvh4/bvh4.h"
#include "bvh8/bvh8.h"
#include "bvh4hair/bvh4hair.h"
#include "bvh4mb/bvh4mb.h"
#else
#include "xeonphi/bvh4i/bvh4i.h"
#include "xeonphi/bvh4mb/bvh4mb.h"
#include "xeonphi/bvh4hair/bvh4hair.h"
#endif

namespace embree
{
  Scene::Scene (RTCSceneFlags sflags, RTCAlgorithmFlags aflags)
    : flags(sflags), aflags(aflags), numMappedBuffers(0), is_build(false), needTriangles(false), needVertices(false),
      numTriangleMeshes(0), numTriangleMeshes2(0), numTriangles(0), numTriangles2(0), numBezierCurves(0), numBezierCurves2(0), numUserGeometries1(0), 
      numIntersectionFilters4(0), numIntersectionFilters8(0), numIntersectionFilters16(0)
  {
    if (g_scene_flags != -1)
      flags = (RTCSceneFlags) g_scene_flags;

    geometries.reserve(128);

#if defined(__MIC__)
    accels.add( BVH4mb::BVH4mbTriangle1ObjectSplitBinnedSAH(this) );
    accels.add( BVH4i::BVH4iVirtualGeometryBinnedSAH(this) );
    accels.add( BVH4Hair::BVH4HairBinnedSAH(this) );

    if (g_verbose >= 1)
      {
	std::cout << "scene flags: static " << isStatic() << " compact = " << isCompact() << " high quality = " << isHighQuality() << " robust = " << isRobust() << std::endl;
      }
  
    if (g_tri_accel == "default" || g_tri_accel == "bvh4i")   
      {
	if (g_tri_builder == "default") 
	  {
	    if (isStatic())
	      {
		if (g_verbose >= 1) std::cout << "STATIC BUILDER MODE" << std::endl;
		if ( isCompact() )
		  accels.add(BVH4i::BVH4iTriangle1MemoryConservativeBinnedSAH(this));		    
		else if ( isHighQuality() )
		  accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
		else
		  accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
	      }
	    else
	      {
		if (g_verbose >= 1) std::cout << "DYNAMIC BUILDER MODE" << std::endl;
		accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton(this));
	      }
	  }
	else
	  {
	    if (g_tri_builder == "sah" || g_tri_builder == "bvh4i" || g_tri_builder == "bvh4i.sah") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitBinnedSAH(this));
	    }
	    else if (g_tri_builder == "fast" || g_tri_builder == "morton") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton(this));
	    }
	    else if (g_tri_builder == "fast_enhanced" || g_tri_builder == "morton.enhanced") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitEnhancedMorton(this));
	    }
	    else if (g_tri_builder == "high_quality" || g_tri_builder == "presplits") {
	      accels.add(BVH4i::BVH4iTriangle1PreSplitsBinnedSAH(this));
	    }
	    else if (g_tri_builder == "compact" ||
		     g_tri_builder == "memory_conservative") {
	      accels.add(BVH4i::BVH4iTriangle1MemoryConservativeBinnedSAH(this));
	    }
	    else if (g_tri_builder == "morton64") {
	      accels.add(BVH4i::BVH4iTriangle1ObjectSplitMorton64Bit(this));
	    }

	    else throw std::runtime_error("unknown builder "+g_tri_builder+" for BVH4i<Triangle1>");
	  }
      }
    else throw std::runtime_error("unknown accel "+g_tri_accel);


#else
    createTriangleAccel();
    accels.add(BVH4MB::BVH4MBTriangle1v(this));
    accels.add(BVH4::BVH4UserGeometry(this));
    createHairAccel();
#endif
  }

#if !defined(__MIC__)

  void Scene::createTriangleAccel()
  {
    if (g_tri_accel == "default") 
    {
      if (isStatic()) {
        int mode =  2*(int)isCompact() + 1*(int)isRobust(); 
        switch (mode) {
        case /*0b00*/ 0: 
#if defined (__TARGET_AVX__)
          if (has_feature(AVX2)) // on AVX machines BVH8 gives lower performance, only enable on AVX2!
	  {
            if (isHighQuality()) accels.add(BVH8::BVH8Triangle8SpatialSplit(this)); 
            else                 accels.add(BVH8::BVH8Triangle8ObjectSplit(this)); 
          }
          else 
#endif
          {
{'fraction_non_alphanumeric': 0.15773690523790485, 'fraction_numerical': 0.023890443822471012, 'mean_word_length': 2.6158294181423924, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1517685', 'n_tokens_mistral': 3658, 'n_tokens_neox': 3316, 'n_words': 592}