void Worker::ProcessIterations(PPM* engine) { u_int64_t photonPerIteration = engine->photonsFirstIteration; uint iterationCount; resetRayBuffer(); UpdateBBox(); LookupSetHitPoints(hitPointsStaticInfo_iterationCopy, hitPoints_iterationCopy); uint iter = 0; double previousIterTime = WallClockTime(); fprintf(stdout, "iteration, photons_iter, photons_total, photons_sec, total_time, radius, device\n"); while (iter < config->max_iters) { ++iter; double start = WallClockTime(); iterationCount = engine->IncIteration(); if (engine->GetIterationNumber() > MAX_ITERATIONS) { break; } photonPerIteration = engine->photonsFirstIteration; #if defined USE_SPPMPA || defined USE_SPPM BuildHitPoints(iterationCount); UpdateBBox(); #endif #if defined USE_SPPM || defined USE_PPM if (iterationCount == 1) InitRadius(iterationCount); #else InitRadius(iterationCount); #endif updateDeviceHitPoints(); ReHash(currentPhotonRadius2);//argument ignored in non-PA updateDeviceLookupAcc(); photonPerIteration = AdvancePhotonPath(photonPerIteration); getDeviceHitpoints(); #if defined USE_PPM AccumulateFluxPPM(iterationCount, photonPerIteration); #endif #if defined USE_SPPM AccumulateFluxSPPM(iterationCount, photonPerIteration); #endif #if defined USE_SPPMPA AccumulateFluxSPPMPA(iterationCount, photonPerIteration); #endif #if defined USE_PPMPA AccumulateFluxPPMPA(iterationCount, photonPerIteration); #endif UpdateSampleFrameBuffer(photonPerIteration); /** * iteration lock required in PhotonTracedTotal */ engine->incPhotonTracedTotal(photonPerIteration); //PushHitPoints(); profiler->additeratingTime(WallClockTime() - start); profiler->addIteration(1); if (profiler->iterationCount % 100 == 0) profiler->printStats(deviceID); // if (iterationCount % 50 == 0) // engine->SaveImpl(to_string<uint> (iterationCount, std::dec) + engine->fileName); #if defined USE_SPPM || defined USE_PPM const float radius = hitPoints_iterationCopy[0].accumPhotonRadius2; #else const float radius = currentPhotonRadius2; #endif const double time = WallClockTime(); const double totalTime = time - engine->startTime; const double iterTime = time - previousIterTime; // const float itsec = engine->GetIterationNumber() / totalTime; const uint photonTotal = engine->getPhotonTracedTotal(); const float photonSec = photonTotal / (totalTime * 1000.f); fprintf(stdout, "%d, %lu, %u, %f, %f, %f, %f, %d\n", iterationCount, photonPerIteration, photonTotal, photonSec, iterTime, totalTime, radius, getDeviceID()); previousIterTime = time; } }
void Worker::BuildHitPoints(uint iteration) { const unsigned int width = engine->width; const unsigned int height = engine->height; const unsigned int superSampling = engine->superSampling; const unsigned int hitPointTotal = engine->hitPointTotal; EyePath* todoEyePaths = new EyePath[hitPointTotal]; #ifndef USE_SPPM memset(HPsIterationRadianceFlux, 0, sizeof(HitPointRadianceFlux) * engine->hitPointTotal); #endif unsigned int hitPointsIndex = 0; const float invSuperSampling = 1.f / superSampling; for (unsigned int y = 0; y < height; ++y) { //for all hitpoints for (unsigned int x = 0; x < width; ++x) { for (unsigned int sy = 0; sy < superSampling; ++sy) { for (unsigned int sx = 0; sx < superSampling; ++sx) { EyePath *eyePath = &todoEyePaths[hitPointsIndex]; eyePath->scrX = x + (sx + getFloatRNG(seedBuffer[hitPointsIndex])) * invSuperSampling - 0.5f; eyePath->scrY = y + (sy + getFloatRNG(seedBuffer[hitPointsIndex])) * invSuperSampling - 0.5f; float u0 = getFloatRNG(seedBuffer[hitPointsIndex]); float u1 = getFloatRNG(seedBuffer[hitPointsIndex]); float u2 = getFloatRNG(seedBuffer[hitPointsIndex]); ss->GenerateRay(eyePath->scrX, eyePath->scrY, width, height, &eyePath->ray, u0, u1, u2, &ss->camera); eyePath->depth = 0; eyePath->throughput = Spectrum(1.f, 1.f, 1.f); eyePath->done = false; eyePath->splat = false; eyePath->sampleIndex = hitPointsIndex; hitPointsIndex++; } } } } uint todoEyePathCount = hitPointTotal; uint chunk_counter = 0; uint* eyePathIndexes = new uint[getRaybufferSize()]; resetRayBuffer(); while (todoEyePathCount > 0) { //transversing in chunks uint start = (chunk_counter / getRaybufferSize()) * getRaybufferSize(); uint end; if (hitPointTotal - start < getRaybufferSize()) end = hitPointTotal; else end = start + getRaybufferSize(); for (uint i = start; i < end; i++) { EyePath *eyePath = &todoEyePaths[i]; // Check if we reached the max path depth if (!eyePath->done && eyePath->depth > MAX_EYE_PATH_DEPTH) { // Add an hit point HitPointPositionInfo* hp = GetHitPointInfo(eyePath->sampleIndex); hp->type = CONSTANT_COLOR; hp->scrX = eyePath->scrX; hp->scrY = eyePath->scrY; hp->throughput = Spectrum(); eyePath->done = true; } else if (!eyePath->done) { eyePath->depth++; uint p = RaybufferAddRay(eyePath->ray); eyePathIndexes[p] = i; } if (eyePath->done && !eyePath->splat) { --todoEyePathCount; chunk_counter++; eyePath->splat = true; } } if (getRayBufferRayCount() > 0) { IntersectRayBuffer(); AdvanceEyePaths(&todoEyePaths[0], eyePathIndexes); resetRayBuffer(); } } delete[] todoEyePaths; delete[] eyePathIndexes; }
void Worker::BuildHitPoints(uint /*iteration*/) { const unsigned int width = engine->width; const unsigned int height = engine->height; const unsigned int superSampling = engine->superSampling; const unsigned int hitPointTotal = engine->hitPointTotal; //Seed* EyePathsSeeds = new Seed[hitPointTotal]; EyePath* todoEyePaths = new EyePath[hitPointTotal]; memset(hitPointsStaticInfo_iterationCopy, 0, sizeof(HitPointStaticInfo) * engine->hitPointTotal); #ifndef USE_SPPM memset(hitPoints_iterationCopy, 0, sizeof(HitPoint) * engine->hitPointTotal); #endif unsigned int hitPointsIndex = 0; // Generate eye rays //std::cerr << "Building eye paths rays with " << superSampling << "x" // << superSampling << " super-sampling:" << std::endl; //std::cerr << " 0/" << height << std::endl; // double lastPrintTime = WallClockTime(); const float invSuperSampling = 1.f / superSampling; for (unsigned int y = 0; y < height; ++y) { // if (WallClockTime() - lastPrintTime > 2.0) { // std::cerr << " " << y << "/" << height << std::endl; // lastPrintTime = WallClockTime(); // } //for all hitpoints for (unsigned int x = 0; x < width; ++x) { for (unsigned int sy = 0; sy < superSampling; ++sy) { for (unsigned int sx = 0; sx < superSampling; ++sx) { EyePath *eyePath = &todoEyePaths[hitPointsIndex]; //EyePathsSeeds[hitPointsIndex] = mwc(hitPointsIndex + deviceID); eyePath->scrX = x + (sx + getFloatRNG(seedBuffer[hitPointsIndex])) * invSuperSampling - 0.5f; eyePath->scrY = y + (sy + getFloatRNG(seedBuffer[hitPointsIndex])) * invSuperSampling - 0.5f; float u0 = getFloatRNG(seedBuffer[hitPointsIndex]); float u1 = getFloatRNG(seedBuffer[hitPointsIndex]); float u2 = getFloatRNG(seedBuffer[hitPointsIndex]); // scene->camera->GenerateRay(eyePath->scrX, // eyePath->scrY, width, height, &eyePath->ray, // u0, u1, u2); ss->GenerateRay(eyePath->scrX, eyePath->scrY, width, height, &eyePath->ray, u0, u1, u2, &ss->camera); eyePath->depth = 0; eyePath->throughput = Spectrum(1.f, 1.f, 1.f); eyePath->done = false; eyePath->splat = false; eyePath->sampleIndex = hitPointsIndex; hitPointsIndex++; } } } } // Iterate through all eye paths //std::cerr << "Building eye paths hit points: " << std::endl; // lastPrintTime = WallClockTime(); // Note: (todoEyePaths.size() > 0) is extremly slow to execute uint todoEyePathCount = hitPointTotal; uint chunk_counter = 0; //std::cerr << " " << todoEyePathCount / 1000 << "k eye paths left" // << std::endl; uint* eyePathIndexes = new uint[getRaybufferSize()]; while (todoEyePathCount > 0) { // if (WallClockTime() - lastPrintTime > 2.0) { // std::cerr << " " << todoEyePathCount / 1000 << "k eye paths left" << std::endl; // lastPrintTime = WallClockTime(); // } //std::vector<EyePath *>::iterator todoEyePathsIterator = // todoEyePaths.begin() + roundPointer; //transversing in chunks uint start = (chunk_counter / getRaybufferSize()) * getRaybufferSize(); uint end; if (hitPointTotal - start < getRaybufferSize()) end = hitPointTotal; else end = start + getRaybufferSize(); for (uint i = start; i < end; i++) { EyePath *eyePath = &todoEyePaths[i]; // Check if we reached the max path depth if (!eyePath->done && eyePath->depth > MAX_EYE_PATH_DEPTH) { // Add an hit point //HitPointInfo &hp = *(engine->GetHitPointInfo( // eyePath->pixelIndex)); HitPointStaticInfo &hp = hitPointsStaticInfo_iterationCopy[eyePath->sampleIndex]; hp.type = CONSTANT_COLOR; hp.scrX = eyePath->scrX; hp.scrY = eyePath->scrY; hp.throughput = Spectrum(); //ihp.accumPhotonCount = 0; //ihp.accumReflectedFlux = Spectrum(); //ihp.photonCount = 0; //hp.reflectedFlux = Spectrum(); eyePath->done = true; } else if (!eyePath->done) { eyePath->depth++; uint p = RaybufferAddRay(eyePath->ray); eyePathIndexes[p] = i; } if (eyePath->done && !eyePath->splat) { --todoEyePathCount; chunk_counter++; eyePath->splat = true; } //if (rayBuffer->IsFull()) // break; } if (getRayBufferRayCount() > 0) { IntersectRayBuffer(); //printf("%d\n",rayBuffer->GetRayCount()); AdvanceEyePaths(&todoEyePaths[0], eyePathIndexes); resetRayBuffer(); } } delete[] todoEyePaths; delete[] eyePathIndexes; }
void Worker::ProcessIterations(PPM* engine) { u_int64_t photonPerIteration = engine->photonsFirstIteration; uint iterationCount; resetRayBuffer(); UpdateBBox(); while (!boost::this_thread::interruption_requested()) { double start = WallClockTime(); if (engine->GetIterationNumber() > config->max_iters) { break; } iterationCount = engine->IncIteration(); photonPerIteration = engine->photonsFirstIteration; // #if defined USE_SPPMPA || defined USE_SPPM BuildHitPoints(iterationCount); UpdateBBox(); // #endif // #if defined USE_SPPM || defined USE_PPM // if (iterationCount == 1) // InitRadius(iterationCount); // #else InitRadius(iterationCount); // #endif updateDeviceHitPoints(); #ifndef REBUILD_HASH if (iterationCount == 1) #endif ReHash(currentPhotonRadius2);//argument ignored in non-PA #ifndef REBUILD_HASH if (iterationCount == 1) #endif updateDeviceLookupAcc(); photonPerIteration = AdvancePhotonPath(photonPerIteration); // #if defined USE_PPM // getDeviceHitpoints(); // AccumulateFluxPPM(iterationCount, photonPerIteration); // #endif // #if defined USE_SPPM // AccumulateFluxSPPM(iterationCount, photonPerIteration); // #endif // #if defined USE_SPPMPA AccumulateFluxSPPMPA(iterationCount, photonPerIteration); // #endif // #if defined USE_PPMPA // AccumulateFluxPPMPA(iterationCount, photonPerIteration); // getDeviceHitpoints(); // #endif UpdateSampleFrameBuffer(photonPerIteration); /** * iteration lock required in PhotonTracedTotal */ engine->incPhotonTracedTotal(photonPerIteration); profiler->additeratingTime(WallClockTime() - start); profiler->addIteration(1); //if (profiler->iterationCount % 20 == 0) // profiler->printStats(deviceID); //if (iterationCount % 100 == 0) // engine->SaveImpl(to_string<uint> (iterationCount, std::dec) + engine->fileName); printf("iteration %d finished\n", iterationCount); } //profiler->printStats(deviceID); }