00001 /*************************************************************************** 00002 * Copyright (C) 1998-2010 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRays. * 00005 * * 00006 * LuxRays is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * LuxRays is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * LuxRays website: http://www.luxrender.net * 00020 ***************************************************************************/ 00021 00022 #include <cstdio> 00023 00024 #include "luxrays/core/intersectiondevice.h" 00025 #include "luxrays/core/context.h" 00026 00027 using namespace luxrays; 00028 00029 //------------------------------------------------------------------------------ 00030 // Native thread IntersectionDevice 00031 //------------------------------------------------------------------------------ 00032 00033 size_t NativeThreadIntersectionDevice::RayBufferSize = 512; 00034 00035 NativeThreadIntersectionDevice::NativeThreadIntersectionDevice(const Context *context, 00036 const unsigned int threadIndex, const unsigned int devIndex) : 00037 IntersectionDevice(context, DEVICE_TYPE_NATIVE_THREAD, devIndex) { 00038 char buf[64]; 00039 sprintf(buf, "NativeIntersectThread-%03d", (int)threadIndex); 00040 deviceName = std::string(buf); 00041 } 00042 00043 NativeThreadIntersectionDevice::~NativeThreadIntersectionDevice() { 00044 if (started) 00045 Stop(); 00046 } 00047 00048 void NativeThreadIntersectionDevice::SetDataSet(const DataSet *newDataSet) { 00049 IntersectionDevice::SetDataSet(newDataSet); 00050 } 00051 00052 void NativeThreadIntersectionDevice::Start() { 00053 IntersectionDevice::Start(); 00054 } 00055 00056 void NativeThreadIntersectionDevice::Interrupt() { 00057 assert (started); 00058 } 00059 00060 void NativeThreadIntersectionDevice::Stop() { 00061 IntersectionDevice::Stop(); 00062 00063 doneRayBufferQueue.Clear(); 00064 } 00065 00066 RayBuffer *NativeThreadIntersectionDevice::NewRayBuffer() { 00067 return new RayBuffer(RayBufferSize); 00068 } 00069 00070 void NativeThreadIntersectionDevice::PushRayBuffer(RayBuffer *rayBuffer) { 00071 Intersect(rayBuffer); 00072 00073 doneRayBufferQueue.Push(rayBuffer); 00074 } 00075 00076 void NativeThreadIntersectionDevice::Intersect(RayBuffer *rayBuffer) { 00077 assert (started); 00078 00079 const double t1 = WallClockTime(); 00080 00081 // Trace rays 00082 const Ray *rb = rayBuffer->GetRayBuffer(); 00083 RayHit *hb = rayBuffer->GetHitBuffer(); 00084 const size_t rayCount = rayBuffer->GetRayCount(); 00085 for (unsigned int i = 0; i < rayCount; ++i) { 00086 hb[i].SetMiss(); 00087 dataSet->Intersect(&rb[i], &hb[i]); 00088 } 00089 00090 const double t2 = WallClockTime(); 00091 00092 statsTotalRayCount += rayCount; 00093 statsDeviceTotalTime += t2 - t1; 00094 } 00095 00096 RayBuffer *NativeThreadIntersectionDevice::PopRayBuffer() { 00097 assert (started); 00098 00099 return doneRayBufferQueue.Pop(); 00100 }
1.6.3