Esempio n. 1
0
void PathNativeRenderThread::RenderThreadImpl(PathNativeRenderThread *renderThread) {
	cerr << "[PathNativeRenderThread::" << renderThread->threadIndex << "] Rendering thread started" << endl;

	try {
		RayBuffer *rayBuffer = renderThread->rayBuffer;
		PathIntegrator *pathIntegrator = renderThread->pathIntegrator;
		NativeThreadIntersectionDevice *intersectionDevice = renderThread->intersectionDevice;

		while (!boost::this_thread::interruption_requested()) {
			rayBuffer->Reset();
			pathIntegrator->FillRayBuffer(rayBuffer);
			intersectionDevice->Intersect(rayBuffer);
			pathIntegrator->AdvancePaths(rayBuffer);
		}

		cerr << "[PathNativeRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	} catch (boost::thread_interrupted) {
		cerr << "[PathNativeRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	}
#if !defined(LUXRAYS_DISABLE_OPENCL)
	catch (cl::Error err) {
		cerr << "[PathNativeRenderThread::" << renderThread->threadIndex << "] Rendering thread ERROR: " << err.what() << "(" << err.err() << ")" << endl;
	}
#endif
}
Esempio n. 2
0
void PathDeviceRenderThread::RenderThreadImpl(PathDeviceRenderThread *renderThread) {
	cerr << "[PathDeviceRenderThread::" << renderThread->threadIndex << "] Rendering thread started" << endl;

	std::deque<RayBuffer *> todoBuffers;
	for(size_t i = 0; i < PATH_DEVICE_RENDER_BUFFER_COUNT; i++)
		todoBuffers.push_back(renderThread->rayBuffers[i]);

	try {
		while (!boost::this_thread::interruption_requested()) {
			// Produce buffers to trace
			while (todoBuffers.size() > 0) {
				RayBuffer *rayBuffer = todoBuffers.front();
				todoBuffers.pop_front();

				rayBuffer->Reset();
				renderThread->pathIntegrators[rayBuffer->GetUserData()]->FillRayBuffer(rayBuffer);
				renderThread->intersectionDevice->PushRayBuffer(rayBuffer);
			}

			RayBuffer *rayBuffer = renderThread->intersectionDevice->PopRayBuffer();
			renderThread->pathIntegrators[rayBuffer->GetUserData()]->AdvancePaths(rayBuffer);
			todoBuffers.push_back(rayBuffer);
		}

		cerr << "[PathDeviceRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	} catch (boost::thread_interrupted) {
		cerr << "[PathDeviceRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	}
#if !defined(LUXRAYS_DISABLE_OPENCL)
	catch (cl::Error err) {
		cerr << "[PathDeviceRenderThread::" << renderThread->threadIndex << "] Rendering thread ERROR: " << err.what() << "(" << err.err() << ")" << endl;
	}
#endif
}
Esempio n. 3
0
void NativeRenderThread::RenderThreadImpl(NativeRenderThread *renderThread) {
	cerr << "[NativeRenderThread::" << renderThread->threadIndex << "] Rendering thread started" << endl;

	try {
		RayBuffer *rayBuffer = renderThread->rayBuffer;
		PathIntegrator *pathIntegrator = renderThread->pathIntegrator;
		NativeIntersectionDevice *intersectionDevice = renderThread->intersectionDevice;

		while (!boost::this_thread::interruption_requested()) {
			rayBuffer->Reset();
			pathIntegrator->FillRayBuffer(rayBuffer);
			intersectionDevice->TraceRays(rayBuffer);
			pathIntegrator->AdvancePaths(rayBuffer);
		}

		cerr << "[NativeRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	} catch (boost::thread_interrupted) {
		cerr << "[NativeRenderThread::" << renderThread->threadIndex << "] Rendering thread halted" << endl;
	} catch (cl::Error err) {
		cerr << "[NativeRenderThread::" << renderThread->threadIndex << "] RenderingERROR: " << err.what() << "(" << err.err() << ")" << endl;
	}
}
void HybridRenderThread::RenderFunc() {
	//SLG_LOG("[HybridRenderThread::" << threadIndex << "] Rendering thread started");
	boost::this_thread::disable_interruption di;

	Film *film = threadFilm;
	const u_int filmWidth = film->GetWidth();
	const u_int filmHeight = film->GetHeight();
	pixelCount = filmWidth * filmHeight;

	RandomGenerator *rndGen = new RandomGenerator(threadIndex + renderEngine->seedBase);

	const u_int incrementStep = 4096;
	vector<HybridRenderState *> states(incrementStep);

	try {
		// Initialize the first states
		for (u_int i = 0; i < states.size(); ++i)
			states[i] = AllocRenderState(rndGen);

		u_int generateIndex = 0;
		u_int collectIndex = 0;
		while (!boost::this_thread::interruption_requested()) {
			// Generate new rays up to the point to have 3 pending buffers
			while (pendingRayBuffers < 3) {
				states[generateIndex]->GenerateRays(this);

				generateIndex = (generateIndex + 1) % states.size();
				if (generateIndex == collectIndex) {
					//SLG_LOG("[HybridRenderThread::" << threadIndex << "] Increasing states size by " << incrementStep);
					//SLG_LOG("[HybridRenderThread::" << threadIndex << "] State size: " << states.size());

					// Insert a set of new states and continue
					states.insert(states.begin() + generateIndex, incrementStep, NULL);
					for (u_int i = generateIndex; i < generateIndex + incrementStep; ++i)
						states[i] = AllocRenderState(rndGen);
					collectIndex += incrementStep;
				}
			}

			//SLG_LOG("[HybridRenderThread::" << threadIndex << "] State size: " << states.size());
			//SLG_LOG("[HybridRenderThread::" << threadIndex << "] generateIndex: " << generateIndex);
			//SLG_LOG("[HybridRenderThread::" << threadIndex << "] collectIndex: " << collectIndex);
			//SLG_LOG("[HybridRenderThread::" << threadIndex << "] pendingRayBuffers: " << pendingRayBuffers);

			// Collect rays up to the point to have only 1 pending buffer
			while (pendingRayBuffers > 1) {
				samplesCount += states[collectIndex]->CollectResults(this);

				const u_int newCollectIndex = (collectIndex + 1) % states.size();
				// A safety-check, it should never happen
				if (newCollectIndex == generateIndex)
					break;
				collectIndex = newCollectIndex;
			}
		}

		//SLG_LOG("[HybridRenderThread::" << threadIndex << "] Rendering thread halted");
	} catch (boost::thread_interrupted) {
		SLG_LOG("[HybridRenderThread::" << threadIndex << "] Rendering thread halted");
	}
#ifndef LUXRAYS_DISABLE_OPENCL
	catch (cl::Error err) {
		SLG_LOG("[HybridRenderThread::" << threadIndex << "] Rendering thread ERROR: " << err.what() <<
				"(" << luxrays::utils::oclErrorString(err.err()) << ")");
	}
#endif

	// Clean current ray buffers
	if (currentRayBufferToSend) {
		currentRayBufferToSend->Reset();
		freeRayBuffers.push_back(currentRayBufferToSend);
		currentRayBufferToSend = NULL;
	}
	if (currentReiceivedRayBuffer) {
		currentReiceivedRayBuffer->Reset();
		freeRayBuffers.push_back(currentReiceivedRayBuffer);
		currentReiceivedRayBuffer = NULL;
	}

	// Free all states
	for (u_int i = 0; i < states.size(); ++i)
		delete states[i];
	delete rndGen;

	// Remove all pending ray buffers
	while (pendingRayBuffers > 0) {
		RayBuffer *rayBuffer = device->PopRayBuffer();
		--(pendingRayBuffers);
		rayBuffer->Reset();
		freeRayBuffers.push_back(rayBuffer);
	}
}