Skip to content

Commit

Permalink
Improve sampler-based profiling coverage.
Browse files Browse the repository at this point in the history
Specifically, for BDPT (and by extension, MLT), and in where the samplers
spend their time.
  • Loading branch information
mmp committed Nov 19, 2016
1 parent 6a590d5 commit e574111
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/film.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class FilmTile {
}
void AddSample(const Point2f &pFilm, Spectrum L,
Float sampleWeight = 1.) {
ProfilePhase _(Prof::AddFilmSample);
if (L.y() > maxSampleLuminance)
L *= maxSampleLuminance / L.y();
// Compute sample's raster bounds
Expand Down
6 changes: 6 additions & 0 deletions src/core/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "sampler.h"
#include "sampling.h"
#include "camera.h"
#include "stats.h"

// Sampler Method Definitions
Sampler::~Sampler() {}
Expand Down Expand Up @@ -113,6 +114,7 @@ bool PixelSampler::SetSampleNumber(int64_t sampleNum) {
}

Float PixelSampler::Get1D() {
ProfilePhase _(Prof::GetSample);
CHECK_LT(currentPixelSampleIndex, samplesPerPixel);
if (current1DDimension < samples1D.size())
return samples1D[current1DDimension++][currentPixelSampleIndex];
Expand All @@ -121,6 +123,7 @@ Float PixelSampler::Get1D() {
}

Point2f PixelSampler::Get2D() {
ProfilePhase _(Prof::GetSample);
CHECK_LT(currentPixelSampleIndex, samplesPerPixel);
if (current2DDimension < samples2D.size())
return samples2D[current2DDimension++][currentPixelSampleIndex];
Expand All @@ -129,6 +132,7 @@ Point2f PixelSampler::Get2D() {
}

void GlobalSampler::StartPixel(const Point2i &p) {
ProfilePhase _(Prof::StartPixel);
Sampler::StartPixel(p);
dimension = 0;
intervalSampleIndex = GetIndexForSample(0);
Expand Down Expand Up @@ -172,12 +176,14 @@ bool GlobalSampler::SetSampleNumber(int64_t sampleNum) {
}

Float GlobalSampler::Get1D() {
ProfilePhase _(Prof::GetSample);
if (dimension >= arrayStartDim && dimension < arrayEndDim)
dimension = arrayEndDim;
return SampleDimension(intervalSampleIndex, dimension++);
}

Point2f GlobalSampler::Get2D() {
ProfilePhase _(Prof::GetSample);
if (dimension + 1 >= arrayStartDim && dimension < arrayEndDim)
dimension = arrayEndDim;
Point2f p(SampleDimension(intervalSampleIndex, dimension),
Expand Down
8 changes: 8 additions & 0 deletions src/core/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ enum class Prof {
SPPMGridConstruction,
SPPMPhotonPass,
SPPMStatsUpdate,
BDPTGenerateSubpath,
BDPTConnectSubpaths,
LightDistribLookup,
LightDistribLookupL2,
LightDistribCreation,
Expand All @@ -168,7 +170,9 @@ enum class Prof {
GenerateCameraRay,
MergeFilmTile,
SplatFilm,
AddFilmSample,
StartPixel,
GetSample,
TexFiltTrilerp,
TexFiltEWA,
NumProfCategories
Expand All @@ -191,6 +195,8 @@ static const char *ProfNames[] = {
"SPPM grid construction",
"SPPM photon pass",
"SPPM photon statistics update",
"BDPT subpath generation",
"BDPT subpath connections",
"SpatialLightDistribution lookup",
"SpatialLightDistribution global lookup",
"SpatialLightDistribution creation",
Expand All @@ -214,7 +220,9 @@ static const char *ProfNames[] = {
"Camera::GenerateRay[Differential]()",
"Film::MergeTile()",
"Film::AddSplat()",
"Film::AddSample()",
"Sampler::StartPixelSample()",
"Sampler::GetSample[12]D()",
"MIPMap::Lookup() (trilinear)",
"MIPMap::Lookup() (EWA)",
};
Expand Down
3 changes: 3 additions & 0 deletions src/integrators/bdpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int GenerateCameraSubpath(const Scene &scene, Sampler &sampler,
const Camera &camera, const Point2f &pFilm,
Vertex *path) {
if (maxDepth == 0) return 0;
ProfilePhase _(Prof::BDPTGenerateSubpath);
// Sample initial ray for camera subpath
CameraSample cameraSample;
cameraSample.pFilm = pFilm;
Expand All @@ -95,6 +96,7 @@ int GenerateLightSubpath(
const std::unordered_map<const Light *, size_t> &lightToIndex,
Vertex *path) {
if (maxDepth == 0) return 0;
ProfilePhase _(Prof::BDPTGenerateSubpath);
// Sample initial ray for light subpath
Float lightPdf;
int lightNum = lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf);
Expand Down Expand Up @@ -440,6 +442,7 @@ Spectrum ConnectBDPT(
const std::unordered_map<const Light *, size_t> &lightToIndex,
const Camera &camera, Sampler &sampler, Point2f *pRaster,
Float *misWeightPtr) {
ProfilePhase _(Prof::BDPTConnectSubpaths);
Spectrum L(0.f);
// Ignore invalid connections related to infinite area lights
if (t > 1 && s != 0 && cameraVertices[t - 1].type == VertexType::Light)
Expand Down
1 change: 1 addition & 0 deletions src/integrators/mlt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static const int nSampleStreams = 3;

// MLTSampler Method Definitions
Float MLTSampler::Get1D() {
ProfilePhase _(Prof::GetSample);
int index = GetNextIndex();
EnsureReady(index);
return X[index].value;
Expand Down
2 changes: 2 additions & 0 deletions src/samplers/maxmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
// samplers/maxmin.cpp*
#include "samplers/maxmin.h"
#include "paramset.h"
#include "stats.h"

// MaxMinDistSampler Method Definitions
void MaxMinDistSampler::StartPixel(const Point2i &p) {
ProfilePhase _(Prof::StartPixel);
Float invSPP = (Float)1 / samplesPerPixel;
for (int i = 0; i < samplesPerPixel; ++i)
samples2D[0][i] = Point2f(i * invSPP, SampleGeneratorMatrix(CPixel, i));
Expand Down
4 changes: 4 additions & 0 deletions src/samplers/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@
#include "samplers/random.h"
#include "paramset.h"
#include "sampling.h"
#include "stats.h"

RandomSampler::RandomSampler(int ns, int seed) : Sampler(ns), rng(seed) {}

Float RandomSampler::Get1D() {
ProfilePhase _(Prof::GetSample);
CHECK_LT(currentPixelSampleIndex, samplesPerPixel);
return rng.UniformFloat();
}

Point2f RandomSampler::Get2D() {
ProfilePhase _(Prof::GetSample);
CHECK_LT(currentPixelSampleIndex, samplesPerPixel);
return {rng.UniformFloat(), rng.UniformFloat()};
}
Expand All @@ -55,6 +58,7 @@ std::unique_ptr<Sampler> RandomSampler::Clone(int seed) {
}

void RandomSampler::StartPixel(const Point2i &p) {
ProfilePhase _(Prof::StartPixel);
for (size_t i = 0; i < sampleArray1D.size(); ++i)
for (size_t j = 0; j < sampleArray1D[i].size(); ++j)
sampleArray1D[i][j] = rng.UniformFloat();
Expand Down
2 changes: 2 additions & 0 deletions src/samplers/stratified.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
#include "samplers/stratified.h"
#include "paramset.h"
#include "sampling.h"
#include "stats.h"

// StratifiedSampler Method Definitions
void StratifiedSampler::StartPixel(const Point2i &p) {
ProfilePhase _(Prof::StartPixel);
// Generate single stratified samples for the pixel
for (size_t i = 0; i < samples1D.size(); ++i) {
StratifiedSample1D(&samples1D[i][0], xPixelSamples * yPixelSamples, rng,
Expand Down
2 changes: 2 additions & 0 deletions src/samplers/zerotwosequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "samplers/zerotwosequence.h"
#include "lowdiscrepancy.h"
#include "paramset.h"
#include "stats.h"

// ZeroTwoSequenceSampler Method Definitions
ZeroTwoSequenceSampler::ZeroTwoSequenceSampler(int64_t samplesPerPixel,
Expand All @@ -48,6 +49,7 @@ ZeroTwoSequenceSampler::ZeroTwoSequenceSampler(int64_t samplesPerPixel,
}

void ZeroTwoSequenceSampler::StartPixel(const Point2i &p) {
ProfilePhase _(Prof::StartPixel);
// Generate 1D and 2D pixel sample components using $(0,2)$-sequence
for (size_t i = 0; i < samples1D.size(); ++i)
VanDerCorput(1, samplesPerPixel, &samples1D[i][0], rng);
Expand Down

0 comments on commit e574111

Please sign in to comment.