diff --git a/src/pbrt/cmd/pbrt.cpp b/src/pbrt/cmd/pbrt.cpp index 845c5429e0e5efe64503587f68d0f65daf0251a3..5ab8a373961c2b81fb6e09d77a5fffcb80996c56 100644 --- a/src/pbrt/cmd/pbrt.cpp +++ b/src/pbrt/cmd/pbrt.cpp @@ -167,8 +167,9 @@ int main(int argc, char *argv[]) { onError) || ParseArg(&iter, args.end(), "format", &format, onError) || ParseArg(&iter, args.end(), "log-level", &logLevel, onError) || + ParseArg(&iter, args.end(), "log-utilization", &options.logUtilization, + onError) || ParseArg(&iter, args.end(), "log-file", &options.logFile, onError) || - ParseArg(&iter, args.end(), "log-utilization", &options.logUtilization, onError) || ParseArg(&iter, args.end(), "mse-reference-image", &options.mseReferenceImage, onError) || ParseArg(&iter, args.end(), "mse-reference-out", &options.mseReferenceOutput, diff --git a/src/pbrt/cpu/aggregates.cpp b/src/pbrt/cpu/aggregates.cpp index ae97853980beb4f190c9cb9cd19f39293ac89227..1efa11e753c0c257fa76849e90e6feb3676e9888 100644 --- a/src/pbrt/cpu/aggregates.cpp +++ b/src/pbrt/cpu/aggregates.cpp @@ -153,9 +153,11 @@ BVHAggregate::BVHAggregate(std::vector prims, int maxPrimsInNode, // Declare _Allocator_s used for BVH construction pstd::pmr::monotonic_buffer_resource resource; Allocator alloc(&resource); - std::vector> threadBufferResources; + std::vector> + threadBufferResources; ThreadLocal threadAllocators([&threadBufferResources]() { - threadBufferResources.push_back(std::make_unique()); + threadBufferResources.push_back( + std::make_unique()); auto ptr = threadBufferResources.back().get(); return Allocator(ptr); }); diff --git a/src/pbrt/cpu/integrators.cpp b/src/pbrt/cpu/integrators.cpp index bcdf2852cab268fa6345c9d0d5ad43507ef58220..743cdd0f53e0584a6ffeb48670d5753c2aad870e 100644 --- a/src/pbrt/cpu/integrators.cpp +++ b/src/pbrt/cpu/integrators.cpp @@ -94,7 +94,8 @@ void ImageTileIntegrator::Render() { }); // Declare common variables for rendering image in tiles - ThreadLocal scratchBuffers([]() { return ScratchBuffer(65536); } ); + ThreadLocal scratchBuffers([]() { return ScratchBuffer(65536); }); + ThreadLocal samplers([this]() { return samplerPrototype.Clone(); }); Bounds2i pixelBounds = camera.GetFilm().PixelBounds(); @@ -2539,7 +2540,8 @@ void MLTIntegrator::Render() { int nBootstrapSamples = nBootstrap * (maxDepth + 1); std::vector bootstrapWeights(nBootstrapSamples, 0); // Allocate scratch buffers for MLT samples - ThreadLocal threadScratchBuffers([]() { return ScratchBuffer(65536); }); + ThreadLocal threadScratchBuffers( + []() { return ScratchBuffer(65536); }); // Generate bootstrap samples in parallel ProgressReporter progress(nBootstrap, "Generating bootstrap paths", Options->quiet); @@ -2795,9 +2797,8 @@ void SPPMIntegrator::Render() { }); // Allocate samplers for SPPM rendering - ThreadLocal threadSamplers([this]() { - return samplerPrototype.Clone(Allocator()); - }); + ThreadLocal threadSamplers( + [this]() { return samplerPrototype.Clone(Allocator()); }); pstd::vector *digitPermutations( ComputeRadicalInversePermutations(digitPermutationsSeed)); @@ -3013,7 +3014,8 @@ void SPPMIntegrator::Render() { // Trace photons and accumulate contributions // Create per-thread scratch buffers for photon shooting - ThreadLocal photonShootScratchBuffers([]() { return ScratchBuffer(65536); }); + ThreadLocal photonShootScratchBuffers( + []() { return ScratchBuffer(65536); }); ParallelFor(0, photonsPerIteration, [&](int64_t start, int64_t end) { // Follow photon paths for photon index range _start_ - _end_ @@ -3141,9 +3143,7 @@ void SPPMIntegrator::Render() { } }); // Reset _threadScratchBuffers_ after tracing photons - threadScratchBuffers.ForAll([](ScratchBuffer &buffer) { - buffer.Reset(); - }); + threadScratchBuffers.ForAll([](ScratchBuffer &buffer) { buffer.Reset(); }); progress.Update(); photonPaths += photonsPerIteration; diff --git a/src/pbrt/cpu/render.cpp b/src/pbrt/cpu/render.cpp index fbb9edddb1a092aca6d557ed683c191b09125e07..778a3b57b2e541040a31602efd97fbb1e7acd7a0 100644 --- a/src/pbrt/cpu/render.cpp +++ b/src/pbrt/cpu/render.cpp @@ -88,8 +88,8 @@ void RenderCPU(ParsedScene &parsedScene) { parsedScene.CreateMaterials(textures, threadAllocators, &namedMaterials, &materials); LOG_VERBOSE("Finished materials"); - Primitive accel = parsedScene.CreateAggregate(textures, shapeIndexToAreaLights, - media, namedMaterials, materials); + Primitive accel = parsedScene.CreateAggregate(textures, shapeIndexToAreaLights, media, + namedMaterials, materials); // Integrator const RGBColorSpace *integratorColorSpace = parsedScene.film.parameters.ColorSpace(); diff --git a/src/pbrt/options.cpp b/src/pbrt/options.cpp index 3a7d2683573e1391dabba28c888fe4de625849a5..c05f7f891ed5b0367eeed8ce21cb954c5434560b 100644 --- a/src/pbrt/options.cpp +++ b/src/pbrt/options.cpp @@ -27,18 +27,19 @@ std::string ToString(const RenderingCoordinateSystem &r) { std::string PBRTOptions::ToString() const { return StringPrintf( - "[ PBRTOptions seed: %s quiet: %s disablePixelJitter: %s disableWavelengthJitter: %s " - "forceDiffuse: %s useGPU: %s wavefront: %s renderingSpace: %s nThreads: %s " - "logLevel: %s logFile: %s logUtilization: %s writePartialImages: %s recordPixelStatistics: %s " - "printStatistics: %s pixelSamples: %s gpuDevice: %s quickRender: %s upgrade: %s " - "imageFile: %s mseReferenceImage: %s mseReferenceOutput: %s debugStart: %s " - "displayServer: %s cropWindow: %s pixelBounds: %s pixelMaterial: %s " - "displacementEdgeScale: %f ]", + "[ PBRTOptions seed: %s quiet: %s disablePixelJitter: %s " + "disableWavelengthJitter: %s forceDiffuse: %s useGPU: %s wavefront: %s " + "renderingSpace: %s nThreads: %s logLevel: %s logFile: %s logUtilization: %s " + "writePartialImages: %s recordPixelStatistics: %s printStatistics: %s " + "pixelSamples: %s gpuDevice: %s quickRender: %s upgrade: %s imageFile: %s " + "mseReferenceImage: %s mseReferenceOutput: %s debugStart: %s displayServer: %s " + "cropWindow: %s pixelBounds: %s pixelMaterial: %s displacementEdgeScale: %f ]", seed, quiet, disablePixelJitter, disableWavelengthJitter, forceDiffuse, useGPU, - wavefront, renderingSpace, nThreads, logLevel, logFile, logUtilization, writePartialImages, - recordPixelStatistics, printStatistics, pixelSamples, gpuDevice, quickRender, - upgrade, imageFile, mseReferenceImage, mseReferenceOutput, debugStart, - displayServer, cropWindow, pixelBounds, pixelMaterial, displacementEdgeScale); + wavefront, renderingSpace, nThreads, logLevel, logFile, logUtilization, + writePartialImages, recordPixelStatistics, printStatistics, pixelSamples, + gpuDevice, quickRender, upgrade, imageFile, mseReferenceImage, mseReferenceOutput, + debugStart, displayServer, cropWindow, pixelBounds, pixelMaterial, + displacementEdgeScale); } } // namespace pbrt diff --git a/src/pbrt/parsedscene.cpp b/src/pbrt/parsedscene.cpp index 3735384b10dd696cb2afde694350562e7adf1dbd..b5fb4ef7a19bd97e62bf3e6b624c8350d6375831 100644 --- a/src/pbrt/parsedscene.cpp +++ b/src/pbrt/parsedscene.cpp @@ -808,9 +808,8 @@ void ParsedScene::CreateMaterials( std::map normalMapCache; std::mutex mutex; ParallelFor(0, normalMapFilenameVector.size(), [&](int64_t index) { - std::string filename = normalMapFilenameVector[index]; Allocator alloc = threadAllocators.Get(); - + std::string filename = normalMapFilenameVector[index]; ImageAndMetadata immeta = Image::Read(filename, Allocator(), ColorEncoding::Linear); Image &image = immeta.image; @@ -829,9 +828,10 @@ void ParsedScene::CreateMaterials( // Named materials for (const auto &nm : namedMaterials) { - Allocator alloc = threadAllocators.Get(); const std::string &name = nm.first; const SceneEntity &mtl = nm.second; + Allocator alloc = threadAllocators.Get(); + if (namedMaterialsOut->find(name) != namedMaterialsOut->end()) { ErrorExitDeferred(&mtl.loc, "%s: trying to redefine named material.", name); continue; @@ -950,8 +950,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal &threadAllocato std::mutex mutex; ParallelFor(0, parallelFloatTextures.size(), [&](int64_t i) { - const auto &tex = floatTextures[parallelFloatTextures[i]]; Allocator alloc = threadAllocators.Get(); + const auto &tex = floatTextures[parallelFloatTextures[i]]; pbrt::Transform renderFromTexture = tex.second.renderFromObject.startTransform; // Pass nullptr for the textures, since they shouldn't be accessed @@ -964,8 +964,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal &threadAllocato }); ParallelFor(0, parallelSpectrumTextures.size(), [&](int64_t i) { - const auto &tex = spectrumTextures[parallelSpectrumTextures[i]]; Allocator alloc = threadAllocators.Get(); + const auto &tex = spectrumTextures[parallelSpectrumTextures[i]]; pbrt::Transform renderFromTexture = tex.second.renderFromObject.startTransform; // nullptr for the textures, as above. @@ -990,8 +990,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal &threadAllocato LOG_VERBOSE("Loading serial textures"); // And do the rest serially for (size_t index : serialFloatTextures) { - const auto &tex = floatTextures[index]; Allocator alloc = threadAllocators.Get(); + const auto &tex = floatTextures[index]; pbrt::Transform renderFromTexture = tex.second.renderFromObject.startTransform; TextureParameterDictionary texDict(&tex.second.parameters, &textures); @@ -1000,8 +1000,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal &threadAllocato textures.floatTextures[tex.first] = t; } for (size_t index : serialSpectrumTextures) { - const auto &tex = spectrumTextures[index]; Allocator alloc = threadAllocators.Get(); + const auto &tex = spectrumTextures[index]; if (tex.second.renderFromObject.IsAnimated()) Warning(&tex.second.loc, "Animated world to texture transform not supported. " diff --git a/src/pbrt/pbrt.cpp b/src/pbrt/pbrt.cpp index f2be1b837b65267f426fa81d7276cc662944b277..be4d30631bddf43e24a33d83ba7a6f04cb47ec1e 100644 --- a/src/pbrt/pbrt.cpp +++ b/src/pbrt/pbrt.cpp @@ -61,11 +61,11 @@ void InitPBRT(const PBRTOptions &opt) { CUDA_CHECK(cudaMemcpyToSymbol(OptionsGPU, Options, sizeof(OptionsGPU))); - // Leak so things aren't freed - pstd::pmr::monotonic_buffer_resource *bufferResource = new - pstd::pmr::monotonic_buffer_resource(1024*1024, &CUDATrackedMemoryResource::singleton); + // Leak this so memory it allocates isn't freed + pstd::pmr::monotonic_buffer_resource *bufferResource = + new pstd::pmr::monotonic_buffer_resource( + 1024 * 1024, &CUDATrackedMemoryResource::singleton); Allocator alloc(bufferResource); - ColorEncoding::Init(alloc); Spectra::Init(alloc); RGBToSpectrumTable::Init(alloc); diff --git a/src/pbrt/samplers.cpp b/src/pbrt/samplers.cpp index 73562a9e7c0ba70fd2caa1c46d780a3fb8939a00..07f3120db714d28694bf24b111807f52996f5dd0 100644 --- a/src/pbrt/samplers.cpp +++ b/src/pbrt/samplers.cpp @@ -52,9 +52,7 @@ HaltonSampler::HaltonSampler(int samplesPerPixel, Point2i fullRes, } Sampler HaltonSampler::Clone(Allocator alloc) { - HaltonSampler *s = (HaltonSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } std::string HaltonSampler::ToString() const { @@ -95,9 +93,7 @@ HaltonSampler *HaltonSampler::Create(const ParameterDictionary ¶meters, } Sampler SobolSampler::Clone(Allocator alloc) { - SobolSampler *s = (SobolSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } std::string PaddedSobolSampler::ToString() const { @@ -107,9 +103,7 @@ std::string PaddedSobolSampler::ToString() const { } Sampler PaddedSobolSampler::Clone(Allocator alloc) { - PaddedSobolSampler *s = (PaddedSobolSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } PaddedSobolSampler *PaddedSobolSampler::Create(const ParameterDictionary ¶meters, @@ -140,9 +134,7 @@ PaddedSobolSampler *PaddedSobolSampler::Create(const ParameterDictionary ¶me // ZSobolSampler Method Definitions Sampler ZSobolSampler::Clone(Allocator alloc) { - ZSobolSampler *s = (ZSobolSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } std::string ZSobolSampler::ToString() const { @@ -227,9 +219,7 @@ PMJ02BNSampler *PMJ02BNSampler::Create(const ParameterDictionary ¶meters, } Sampler PMJ02BNSampler::Clone(Allocator alloc) { - PMJ02BNSampler *s = (PMJ02BNSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } std::string PMJ02BNSampler::ToString() const { @@ -245,9 +235,7 @@ std::string IndependentSampler::ToString() const { } Sampler IndependentSampler::Clone(Allocator alloc) { - IndependentSampler *s = (IndependentSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } IndependentSampler *IndependentSampler::Create(const ParameterDictionary ¶meters, @@ -304,9 +292,7 @@ std::string StratifiedSampler::ToString() const { } Sampler StratifiedSampler::Clone(Allocator alloc) { - StratifiedSampler *s = (StratifiedSampler *)alloc.allocate_object(); - alloc.construct(s, *this); - return s; + return alloc.new_object(*this); } StratifiedSampler *StratifiedSampler::Create(const ParameterDictionary ¶meters, @@ -348,7 +334,7 @@ Point2f MLTSampler::GetPixel2D() { } Sampler MLTSampler::Clone(Allocator alloc) { - LOG_FATAL("MLTSampler::Clone() mplemented"); + LOG_FATAL("MLTSampler::Clone() is not implemented"); return {}; } diff --git a/src/pbrt/textures.cpp b/src/pbrt/textures.cpp index 6c8266d286d1ab0d782644ca65d20923f34bda04..84c20eff1dcdcd7ffde17a96f76636e19046b423 100644 --- a/src/pbrt/textures.cpp +++ b/src/pbrt/textures.cpp @@ -1292,8 +1292,10 @@ GPUSpectrumImageTexture *GPUSpectrumImageTexture::Create( texDesc.maxAnisotropy = Clamp(maxAniso, 1, 16); texDesc.maxMipmapLevelClamp = nMIPMapLevels - 1; texDesc.minMipmapLevelClamp = 0; - texDesc.mipmapFilterMode = (filter == "trilinear" || filter == "ewa" || filter == "EWA") ? - cudaFilterModeLinear : cudaFilterModePoint; + texDesc.mipmapFilterMode = + (filter == "trilinear" || filter == "ewa" || filter == "EWA") + ? cudaFilterModeLinear + : cudaFilterModePoint; texDesc.borderColor[0] = texDesc.borderColor[1] = texDesc.borderColor[2] = texDesc.borderColor[3] = 0.f; texDesc.sRGB = 1; @@ -1415,8 +1417,10 @@ GPUFloatImageTexture *GPUFloatImageTexture::Create( texDesc.maxAnisotropy = Clamp(maxAniso, 1, 16); texDesc.maxMipmapLevelClamp = nMIPMapLevels - 1; texDesc.minMipmapLevelClamp = 0; - texDesc.mipmapFilterMode = (filter == "trilinear" || filter == "ewa" || filter == "EWA") ? - cudaFilterModeLinear : cudaFilterModePoint; + texDesc.mipmapFilterMode = + (filter == "trilinear" || filter == "ewa" || filter == "EWA") + ? cudaFilterModeLinear + : cudaFilterModePoint; texDesc.borderColor[0] = texDesc.borderColor[1] = texDesc.borderColor[2] = texDesc.borderColor[3] = 0.f; texDesc.sRGB = 1; diff --git a/src/pbrt/util/buffercache.h b/src/pbrt/util/buffercache.h index 4b9b88f47606a016b3849295fb6855ff46c4997f..07456168608a374cca4ab684054c33d881cdfbc1 100644 --- a/src/pbrt/util/buffercache.h +++ b/src/pbrt/util/buffercache.h @@ -33,40 +33,36 @@ class BufferCache { ++nBufferCacheLookups; // Return pointer to data if _buf_ contents is already in the cache Buffer lookupBuffer(buf.data(), buf.size()); - int shardIndex = uint32_t(lookupBuffer.hash) >> (32 - logShards); - CHECK(shardIndex >= 0 && shardIndex < nShards); - + DCHECK(shardIndex >= 0 && shardIndex < nShards); mutex[shardIndex].lock_shared(); - if (auto iter = cache[shardIndex].find(lookupBuffer); iter != cache[shardIndex].end()) { - DCHECK(std::memcmp(buf.data(), iter->ptr, buf.size() * sizeof(T)) == 0); + if (auto iter = cache[shardIndex].find(lookupBuffer); + iter != cache[shardIndex].end()) { const T *ptr = iter->ptr; mutex[shardIndex].unlock_shared(); - + DCHECK(std::memcmp(buf.data(), iter->ptr, buf.size() * sizeof(T)) == 0); ++nBufferCacheHits; redundantBufferBytes += buf.size() * sizeof(T); return ptr; } - mutex[shardIndex].unlock_shared(); - // Add _buf_ contents to cache and return pointer to cached copy + mutex[shardIndex].unlock_shared(); T *ptr = alloc.allocate_object(buf.size()); std::copy(buf.begin(), buf.end(), ptr); bytesUsed += buf.size() * sizeof(T); - mutex[shardIndex].lock(); - if (auto iter = cache[shardIndex].find(lookupBuffer); iter != cache[shardIndex].end()) { - // Someone else got it in there in the meantime... - alloc.deallocate_object(ptr, buf.size()); - - const T *ptr = iter->ptr; + // Handle the case of another thread adding the buffer first + if (auto iter = cache[shardIndex].find(lookupBuffer); + iter != cache[shardIndex].end()) { + const T *cachePtr = iter->ptr; mutex[shardIndex].unlock(); - + alloc.deallocate_object(ptr, buf.size()); ++nBufferCacheHits; redundantBufferBytes += buf.size() * sizeof(T); - return ptr; + return cachePtr; } + cache[shardIndex].insert(Buffer(ptr, buf.size())); mutex[shardIndex].unlock(); return ptr; @@ -88,8 +84,7 @@ class BufferCache { } const T *ptr = nullptr; - size_t size = 0; - size_t hash; + size_t size = 0, hash; }; // BufferCache::BufferHasher Definition diff --git a/src/pbrt/util/containers.h b/src/pbrt/util/containers.h index 368e879eac133a1d1b3631710fdc06503570d29a..1b80ef515fac29a6e6a4f26dff0dbd9527378225 100644 --- a/src/pbrt/util/containers.h +++ b/src/pbrt/util/containers.h @@ -838,14 +838,13 @@ class SampledGrid { Vector3f d = pSamples - (Point3f)pi; // Return trilinearly interpolated voxel values - auto d00 = - Lerp(d.x, Lookup(pi), Lookup(pi + Vector3i(1, 0, 0))); - auto d10 = Lerp(d.x, Lookup(pi + Vector3i(0, 1, 0)), - Lookup(pi + Vector3i(1, 1, 0))); - auto d01 = Lerp(d.x, Lookup(pi + Vector3i(0, 0, 1)), - Lookup(pi + Vector3i(1, 0, 1))); - auto d11 = Lerp(d.x, Lookup(pi + Vector3i(0, 1, 1)), - Lookup(pi + Vector3i(1, 1, 1))); + auto d00 = Lerp(d.x, Lookup(pi), Lookup(pi + Vector3i(1, 0, 0))); + auto d10 = + Lerp(d.x, Lookup(pi + Vector3i(0, 1, 0)), Lookup(pi + Vector3i(1, 1, 0))); + auto d01 = + Lerp(d.x, Lookup(pi + Vector3i(0, 0, 1)), Lookup(pi + Vector3i(1, 0, 1))); + auto d11 = + Lerp(d.x, Lookup(pi + Vector3i(0, 1, 1)), Lookup(pi + Vector3i(1, 1, 1))); return Lerp(d.z, Lerp(d.y, d00, d10), Lerp(d.y, d01, d11)); } diff --git a/src/pbrt/util/image.cpp b/src/pbrt/util/image.cpp index 0f6b297cb1ce168421ec14fdd388238ec4b32c4f..26797c06a3c189eee0dfa75dec17ae8ea6691fcd 100644 --- a/src/pbrt/util/image.cpp +++ b/src/pbrt/util/image.cpp @@ -197,7 +197,8 @@ pstd::vector Image::GeneratePyramid(Image image, WrapMode2D wrapMode, } bool Image::HasAnyInfinitePixels() const { - if (format == PixelFormat::U256) return false; + if (format == PixelFormat::U256) + return false; for (int y = 0; y < resolution.y; ++y) for (int x = 0; x < resolution.x; ++x) @@ -208,7 +209,8 @@ bool Image::HasAnyInfinitePixels() const { } bool Image::HasAnyNaNPixels() const { - if (format == PixelFormat::U256) return false; + if (format == PixelFormat::U256) + return false; for (int y = 0; y < resolution.y; ++y) for (int x = 0; x < resolution.x; ++x) @@ -1339,7 +1341,10 @@ Image Image::SelectChannels(const ImageChannelDesc &desc, Allocator alloc) const dst[i] = src[desc.offset[i]]; } break; + default: + LOG_FATAL("Unhandled PixelFormat"); } + return image; } diff --git a/src/pbrt/util/log.h b/src/pbrt/util/log.h index 000ec4b010f8cb8ac9e1280028394cd2aa5942e8..0cde178d54a389d6fe3c003dbe4e9ae2b62b1eda 100644 --- a/src/pbrt/util/log.h +++ b/src/pbrt/util/log.h @@ -18,9 +18,8 @@ enum class LogLevel { Verbose, Error, Fatal, Invalid }; std::string ToString(LogLevel level); LogLevel LogLevelFromString(const std::string &s); -void InitLogging(LogLevel level, std::string logFile, bool logUtilization, - bool useGPU); void ShutdownLogging(); +void InitLogging(LogLevel level, std::string logFile, bool logUtilization, bool useGPU); #ifdef PBRT_BUILD_GPU_RENDERER diff --git a/src/pbrt/util/mesh.h b/src/pbrt/util/mesh.h index 07e6cea492ec490a2c477ec85dd0623e369760b5..db72e8f3fbcf54ae9b75366688b6dd5d44ccf761 100644 --- a/src/pbrt/util/mesh.h +++ b/src/pbrt/util/mesh.h @@ -27,8 +27,7 @@ class TriangleMesh { TriangleMesh(const Transform &renderFromObject, bool reverseOrientation, std::vector vertexIndices, std::vector p, std::vector S, std::vector N, - std::vector uv, std::vector faceIndices, - Allocator alloc); + std::vector uv, std::vector faceIndices, Allocator alloc); std::string ToString() const; diff --git a/src/pbrt/util/parallel.h b/src/pbrt/util/parallel.h index 8a752da05a76131e94cdd6cb6b5fe31c9cbd869b..8d0dd092f55c008d211b0a1d3c2b949e3d36b312 100644 --- a/src/pbrt/util/parallel.h +++ b/src/pbrt/util/parallel.h @@ -23,13 +23,12 @@ namespace pbrt { +// ThreadLocal Definition template class ThreadLocal { -public: - ThreadLocal() - : hashTable(maxThreads), create([]() { return T(); }) {} - ThreadLocal(std::function &&c) - : hashTable(maxThreads), create(c) {} + public: + ThreadLocal() : hashTable(maxThreads), create([]() { return T(); }) {} + ThreadLocal(std::function &&c) : hashTable(maxThreads), create(c) {} T &Get() { std::thread::id tid = std::this_thread::get_id(); @@ -86,7 +85,7 @@ public: mutex.unlock(); } -private: + private: struct Entry { std::thread::id tid; T value; diff --git a/src/pbrt/wavefront/integrator.cpp b/src/pbrt/wavefront/integrator.cpp index f329a46a12328ddff57ca919c8621cb2921bf78f..c4d39d8dc98e8de55966f5d53d0f419dcfdc27b8 100644 --- a/src/pbrt/wavefront/integrator.cpp +++ b/src/pbrt/wavefront/integrator.cpp @@ -75,12 +75,12 @@ static void updateMaterialNeeds( (*haveUniversalEvalMaterial)[m.Tag()] = true; } -WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *memoryResource, - ParsedScene &scene) +WavefrontPathIntegrator::WavefrontPathIntegrator( + pstd::pmr::memory_resource *memoryResource, ParsedScene &scene) : memoryResource(memoryResource) { ThreadLocal threadAllocators([memoryResource]() { pstd::pmr::monotonic_buffer_resource *resource = - new pstd::pmr::monotonic_buffer_resource(1024*1024, memoryResource); + new pstd::pmr::monotonic_buffer_resource(1024 * 1024, memoryResource); return Allocator(resource); }); @@ -149,6 +149,7 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem LOG_VERBOSE("Starting to create lights"); pstd::vector allLights; + infiniteLights = alloc.new_object>(alloc); for (const auto &light : scene.lights) { Medium outsideMedium = findMedium(light.medium, &light.loc); @@ -171,11 +172,10 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem std::map *> shapeIndexToAreaLights; std::set namedMaterialsThatAreInterfaces; - for (auto iter = scene.namedMaterials.begin(); - iter != scene.namedMaterials.end(); ++iter) { + for (auto iter = scene.namedMaterials.begin(); iter != scene.namedMaterials.end(); + ++iter) { std::string materialName = iter->second.parameters.GetOneString("type", ""); - if (materialName == "interface" || materialName == "none" || - materialName.empty()) + if (materialName == "interface" || materialName == "none" || materialName.empty()) namedMaterialsThatAreInterfaces.insert(iter->first); } @@ -263,14 +263,14 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem CUDATrackedMemoryResource *mr = dynamic_cast(memoryResource); CHECK(mr); - aggregate = new OptiXAggregate(scene, mr, textures, shapeIndexToAreaLights, - media, namedMaterials, materials); + aggregate = new OptiXAggregate(scene, mr, textures, shapeIndexToAreaLights, media, + namedMaterials, materials); #else LOG_FATAL("Options->useGPU was set without PBRT_BUILD_GPU_RENDERER enabled"); #endif } else - aggregate = new CPUAggregate(scene, textures, shapeIndexToAreaLights, - media, namedMaterials, materials); + aggregate = new CPUAggregate(scene, textures, shapeIndexToAreaLights, media, + namedMaterials, materials); // Preprocess the light sources for (Light light : allLights) @@ -310,8 +310,8 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem if (!Options->mseReferenceOutput.empty()) Warning("The wavefront integrator does not support --mse-reference-out."); - /////////////////////////////////////////////////////////////////////////// - // Allocate storage for all of the queues/buffers... + /////////////////////////////////////////////////////////////////////////// + // Allocate storage for all of the queues/buffers... #ifdef PBRT_BUILD_GPU_RENDERER CUDATrackedMemoryResource *mr = diff --git a/src/pbrt/wavefront/integrator.h b/src/pbrt/wavefront/integrator.h index ff4b63dee670f77425fae2e65343e6f998cb63e5..59710164a9a1c6d8424ba63b0be5a4033d501960 100644 --- a/src/pbrt/wavefront/integrator.h +++ b/src/pbrt/wavefront/integrator.h @@ -118,7 +118,6 @@ class WavefrontPathIntegrator { } // WavefrontPathIntegrator Member Variables - pstd::pmr::memory_resource *memoryResource; bool initializeVisibleSurface; bool haveSubsurface; bool haveMedia; @@ -136,6 +135,8 @@ class WavefrontPathIntegrator { }; Stats *stats; + pstd::pmr::memory_resource *memoryResource; + Filter filter; Film film; Sampler sampler;