mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.75k stars 407 forks source link

Exhaustive light sampler + area light + GPU render = fatal error #403

Open pbrt4bounty opened 8 months ago

pbrt4bounty commented 8 months ago

I obtain a FATAL CUDA error when I use 'Exhaustive' LightSampler with a rectangle area light and render the scene on the GPU. This don't happen with other light types.. Latest binaries from the master branch of the repository.

pbrt version 4 (built Nov 22 2023 at 19:33:35)
Copyright (c)1998-2021 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
The source code to pbrt (but *not* the book contents) is covered by the Apache 2.0 License.
See the file LICENSE.txt for the conditions of the license.
[ tid 19708 @     1.324s E:\REPOS\pbrt4blender\src\pbrt\wavefront\integrator.cpp:353 ] Starting to submit work for sample 16
[ tid 19708 @     1.334s E:\REPOS\pbrt4blender\src\pbrt\gpu\util.cpp:151 ] FATAL CUDA error: an illegal memory access was encountered
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00014C2000008F50 - `Q
(unknown                                 )      0x00007FFBC0E32560 - BaseThreadInitThunk
(unknown                                 )      0x00007FFBC1E6AA50 - RtlUserThreadStart
Wavefront rendering failed at sample 16. Debug with "--debugstart 16"

Can ayone confirm this issue, please? This are the scene that cause this error: exhaustive_error.zip

pbrt4bounty commented 8 months ago

Maybe the problem is here, in the Sample method: https://github.com/mmp/pbrt-v4/blob/master/src/pbrt/lightsamplers.cpp#L268

Float pInfinite = Float(infiniteLights.size()) /
                      Float(infiniteLights.size() + (!lightBounds.empty() ? 1 : 0));

infiniteLigths.size() value can be 0.0 and later this value is used in some division operations..

if (u < pInfinite) {
        u /= pInfinite;
        int index = std::min<int>(u * infiniteLights.size(), infiniteLights.size() - 1);
        Float pdf = pInfinite * 1.f / infiniteLights.size();
        return SampledLight{infiniteLights[index], pdf};
    } else {...

I try to add this... if (pInfinite == 0.0f) return {}; ..and seems that solve the issue, but unsure if this are the 'right' solution. @mmp what do you think?