void RenderingConfig::SaveFilm() { const vector<string> filmNames = cfg.GetStringVector("screen.file", ""); if (filmNames.size() == 0) return; boost::unique_lock<boost::mutex> lock(filmMutex); StopAllRenderThreadsLockless(); if (filmNames.size() == 1) film->SaveFilm(filmNames[0]); else if (filmNames.size() > 1) film->SaveFilm("merged.flm"); StartAllRenderThreadsLockless(); }
void RenderingConfig::ReInit(const bool reallocBuffers, const unsigned int w, unsigned int h) { boost::unique_lock<boost::mutex> lock(cfgMutex); bool wasRunning = renderThreadsStarted; // First stop all devices if (wasRunning) StopAllRenderThreadsLockless(); // Check if I have to reallocate buffers if (reallocBuffers) film->Init(w, h); else film->Reset(); scene->camera->Update(film->GetWidth(), film->GetHeight()); // Restart all devices if (wasRunning) StartAllRenderThreadsLockless(); }
void RenderingConfig::SetMotionBlur(const bool v) { boost::unique_lock<boost::mutex> lock(cfgMutex); bool wasRunning = renderThreadsStarted; // First stop all devices if (wasRunning) StopAllRenderThreadsLockless(); film->Reset(); PerspectiveCamera *camera = scene->camera; camera->motionBlur = v; if (camera->motionBlur) { camera->mbOrig = camera->orig; camera->mbTarget = camera->target; camera->mbUp = camera->up; } camera->Update(film->GetWidth(), film->GetHeight()); // Restart all devices if (wasRunning) StartAllRenderThreadsLockless(); }
void RenderingConfig::SetRenderingEngineType(const RenderEngineType type) { boost::unique_lock<boost::mutex> lock(cfgMutex); // Check the current rendering engine type is different if (renderEngine->GetEngineType() != type) { bool wasRunning = renderThreadsStarted; // First stop all devices if (wasRunning) StopAllRenderThreadsLockless(); delete renderEngine; switch (type) { case PATH: renderEngine = new PathRenderEngine(scene, film, &filmMutex, intersectionAllDevices, false, cfg); break; case SPPM: renderEngine = new SPPMRenderEngine(scene, film, &filmMutex, intersectionAllDevices, cfg); break; case DIRECTLIGHT: renderEngine = new PathRenderEngine(scene, film, &filmMutex, intersectionAllDevices, true, cfg); break; #if !defined(LUXRAYS_DISABLE_OPENCL) case PATHGPU: renderEngine = new PathGPURenderEngine(scene, film, &filmMutex, intersectionGPUDevices, cfg); break; case PATHGPU2: renderEngine = new PathGPU2RenderEngine(scene, film, &filmMutex, intersectionGPUDevices, cfg); break; #endif default: assert (false); } film->Reset(); // Restart all devices if (wasRunning) StartAllRenderThreadsLockless(); } }
void RenderingConfig::Init() { boost::unique_lock<boost::mutex> lock(cfgMutex); const bool lowLatency = (cfg.GetInt("opencl.latency.mode", 1) != 0); const string sceneFileName = cfg.GetString("scene.file", "scenes/luxball/luxball.scn"); const unsigned int w = cfg.GetInt("image.width", 640); const unsigned int h = cfg.GetInt("image.height", 480); const unsigned int nativeThreadCount = cfg.GetInt("opencl.nativethread.count", 2); const bool useCPUs = (cfg.GetInt("opencl.cpu.use", 0) != 0); const bool useGPUs = (cfg.GetInt("opencl.gpu.use", 1) != 0); const unsigned int forceGPUWorkSize = cfg.GetInt("opencl.gpu.workgroup.size", 64); const unsigned int oclPlatformIndex = cfg.GetInt("opencl.platform.index", 0); const string oclIntersectionDeviceConfig = cfg.GetString("opencl.devices.select", ""); const int oclPixelDeviceConfig = cfg.GetInt("opencl.pixeldevice.select", -1); const unsigned int oclDeviceThreads = cfg.GetInt("opencl.renderthread.count", 0); luxrays::RAY_EPSILON = cfg.GetFloat("scene.epsilon", luxrays::RAY_EPSILON); periodiceSaveTime = cfg.GetFloat("batch.periodicsave", 0.f); lastPeriodicSave = WallClockTime(); periodicSaveEnabled = (periodiceSaveTime > 0.f); screenRefreshInterval = cfg.GetInt("screen.refresh.interval", lowLatency ? 100 : 2000); captionBuffer[0] = '\0'; // Create LuxRays context ctx = new Context(DebugHandler, oclPlatformIndex); // Create the Film std::vector<DeviceDescription *> descs = ctx->GetAvailableDeviceDescriptions(); if (oclPixelDeviceConfig == -1) { DeviceDescription::Filter(DEVICE_TYPE_NATIVE_THREAD, descs); film = new LuxRaysFilm(ctx, w, h, descs[0]); } else { DeviceDescription::Filter(DEVICE_TYPE_OPENCL, descs); film = new LuxRaysFilm(ctx, w, h, descs[oclPixelDeviceConfig]); } const int filterType = cfg.GetInt("film.filter.type", 1); if (filterType == 0) film->SetFilterType(FILTER_NONE); else film->SetFilterType(FILTER_GAUSSIAN); const int toneMapType = cfg.GetInt("film.tonemap.type", 0); if (toneMapType == 0) { LinearToneMapParams params; params.scale = cfg.GetFloat("film.tonemap.linear.scale", params.scale); film->SetToneMapParams(params); } else { Reinhard02ToneMapParams params; params.preScale = cfg.GetFloat("film.tonemap.reinhard02.prescale", params.preScale); params.postScale = cfg.GetFloat("film.tonemap.reinhard02.postscale", params.postScale); params.burn = cfg.GetFloat("film.tonemap.reinhard02.burn", params.burn); film->SetToneMapParams(params); } const float gamma = cfg.GetFloat("film.gamma", 2.2f); if (gamma != 2.2f) film->InitGammaTable(gamma); // Load film files const vector<string> filmNames = cfg.GetStringVector("film.file", ""); if (filmNames.size() > 0) { for (size_t i = 0; i < filmNames.size(); ++i) film->AddFilm(filmNames[i]); } // Create the Scene const int accelType = cfg.GetInt("accelerator.type", -1); scene = new SLGScene(ctx, sceneFileName, film, accelType); // For compatibility with old scenes scene->camera->fieldOfView = cfg.GetFloat("scene.fieldofview", scene->camera->fieldOfView); scene->camera->Update(film->GetWidth(), film->GetHeight()); // Start OpenCL devices SetUpOpenCLDevices(useCPUs, useGPUs, forceGPUWorkSize, oclDeviceThreads, oclIntersectionDeviceConfig); // Start Native threads SetUpNativeDevices(nativeThreadCount); const size_t deviceCount = intersectionCPUDevices.size() + intersectionGPUDevices.size(); if (deviceCount <= 0) throw runtime_error("Unable to find any appropiate IntersectionDevice"); intersectionCPUGPUDevices.resize(deviceCount); if (intersectionGPUDevices.size() > 0) copy(intersectionGPUDevices.begin(), intersectionGPUDevices.end(), intersectionCPUGPUDevices.begin()); if (intersectionCPUDevices.size() > 0) copy(intersectionCPUDevices.begin(), intersectionCPUDevices.end(), intersectionCPUGPUDevices.begin() + intersectionGPUDevices.size()); #if !defined(LUXRAYS_DISABLE_OPENCL) // Check if I have to disable image storage const bool frocedDisableImageStorage = (accelType == 2); for (size_t i = 0; i < intersectionGPUDevices.size(); ++i) ((OpenCLIntersectionDevice *)intersectionGPUDevices[i])->SetQBVHDisableImageStorage(frocedDisableImageStorage); #endif // Set the Luxrays SataSet ctx->SetDataSet(scene->dataSet); intersectionAllDevices = ctx->GetIntersectionDevices(); // Check the kind of render engine to start const int renderEngineType = cfg.GetInt("renderengine.type", 0); // Create and start the render engine switch (renderEngineType) { case 0: renderEngine = new PathRenderEngine(scene, film, &filmMutex, intersectionAllDevices, false, cfg); break; case 1: renderEngine = new SPPMRenderEngine(scene, film, &filmMutex, intersectionAllDevices, cfg); break; case 2: renderEngine = new PathRenderEngine(scene, film, &filmMutex, intersectionAllDevices, true, cfg); break; #if !defined(LUXRAYS_DISABLE_OPENCL) case 3: renderEngine = new PathGPURenderEngine(scene, film, &filmMutex, intersectionGPUDevices, cfg); break; #endif default: assert (false); } film->StartSampleTime(); StartAllRenderThreadsLockless(); }
void RenderingConfig::StartAllRenderThreads() { boost::unique_lock<boost::mutex> lock(cfgMutex); StartAllRenderThreadsLockless(); }