00001 /*************************************************************************** 00002 * Copyright (C) 1998-2009 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRender. * 00005 * * 00006 * Lux Renderer 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 * Lux Renderer 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 * This project is based on PBRT ; see http://www.pbrt.org * 00020 * Lux Renderer website : http://www.luxrender.net * 00021 ***************************************************************************/ 00022 00023 #ifndef _LUXRAYS_VIRTUALDEVICE_H 00024 #define _LUXRAYS_VIRTUALDEVICE_H 00025 00026 #include <boost/thread/mutex.hpp> 00027 00028 #include "luxrays/luxrays.h" 00029 #include "luxrays/core/intersectiondevice.h" 00030 00031 namespace luxrays { 00032 00033 //------------------------------------------------------------------------------ 00034 // Virtual Many to One hardware device 00035 //------------------------------------------------------------------------------ 00036 00037 class VirtualM2OHardwareIntersectionDevice { 00038 public: 00039 VirtualM2OHardwareIntersectionDevice(const size_t count, HardwareIntersectionDevice *device); 00040 ~VirtualM2OHardwareIntersectionDevice(); 00041 00042 IntersectionDevice *GetVirtualDevice(size_t index); 00043 00044 static size_t RayBufferSize; 00045 00046 private: 00047 class VirtualM2ODevHInstance : public IntersectionDevice { 00048 public: 00049 VirtualM2ODevHInstance(VirtualM2OHardwareIntersectionDevice *device, const size_t index); 00050 ~VirtualM2ODevHInstance(); 00051 00052 RayBuffer *NewRayBuffer(); 00053 void PushRayBuffer(RayBuffer *rayBuffer); 00054 RayBuffer *PopRayBuffer(); 00055 size_t GetQueueSize() { return virtualDevice->rayBufferQueue.GetSizeToDo(); } 00056 00057 void PushRayBufferDone(RayBuffer *rayBuffer); 00058 00059 double GetLoad() const { return virtualDevice->realDevice->GetLoad(); } 00060 00061 protected: 00062 void SetDataSet(const DataSet *newDataSet); 00063 void Start(); 00064 void Interrupt(); 00065 void Stop(); 00066 00067 private: 00068 size_t instanceIndex; 00069 VirtualM2OHardwareIntersectionDevice *virtualDevice; 00070 00071 size_t pendingRayBuffers; 00072 }; 00073 00074 size_t virtualDeviceCount; 00075 HardwareIntersectionDevice *realDevice; 00076 RayBufferQueueM2O rayBufferQueue; 00077 00078 boost::mutex virtualDeviceMutex; 00079 VirtualM2ODevHInstance **virtualDeviceInstances; 00080 }; 00081 00082 //------------------------------------------------------------------------------ 00083 // Virtual Many to Many hardware device 00084 //------------------------------------------------------------------------------ 00085 00086 class VirtualM2MHardwareIntersectionDevice { 00087 public: 00088 VirtualM2MHardwareIntersectionDevice(const size_t count, const std::vector<HardwareIntersectionDevice *> &devices); 00089 ~VirtualM2MHardwareIntersectionDevice(); 00090 00091 IntersectionDevice *GetVirtualDevice(size_t index); 00092 00093 static size_t RayBufferSize; 00094 00095 private: 00096 class VirtualM2MDevHInstance : public IntersectionDevice { 00097 public: 00098 VirtualM2MDevHInstance(VirtualM2MHardwareIntersectionDevice *device, const size_t index); 00099 ~VirtualM2MDevHInstance(); 00100 00101 RayBuffer *NewRayBuffer(); 00102 void PushRayBuffer(RayBuffer *rayBuffer); 00103 RayBuffer *PopRayBuffer(); 00104 size_t GetQueueSize() { return virtualDevice->rayBufferQueue.GetSizeToDo(); } 00105 00106 void PushRayBufferDone(RayBuffer *rayBuffer); 00107 00108 double GetLoad() const { return 1.0; } 00109 00110 protected: 00111 void SetDataSet(const DataSet *newDataSet); 00112 void Start(); 00113 void Interrupt(); 00114 void Stop(); 00115 00116 private: 00117 size_t instanceIndex; 00118 VirtualM2MHardwareIntersectionDevice *virtualDevice; 00119 00120 size_t pendingRayBuffers; 00121 }; 00122 00123 size_t virtualDeviceCount; 00124 std::vector<HardwareIntersectionDevice *> realDevices; 00125 RayBufferQueueM2M rayBufferQueue; 00126 00127 boost::mutex virtualDeviceMutex; 00128 VirtualM2MDevHInstance **virtualDeviceInstances; 00129 }; 00130 00131 } 00132 00133 #endif /* _LUXRAYS_VIRTUALDEVICE_H */
1.6.3