New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stochastic Progressive Photon Mapping (SPPM) #86

Open
wahn opened this Issue Jan 18, 2019 · 8 comments

Comments

Projects
None yet
1 participant
@wahn
Copy link
Owner

wahn commented Jan 18, 2019

Look at chapter 16.2 of the Physically Based Rendering book for the theoretical background on this topic and a simple test scene for caustics. Let's use that scene to see caustic from light passing through the glass becoming increasingly sharper.

@wahn wahn added the enhancement label Jan 18, 2019

@wahn wahn self-assigned this Jan 18, 2019

@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Jan 18, 2019

Here the results rendered by the C++ version (using 10 iterations):

> grep sppm f16-9a.pbrt
Integrator "sppm" "integer numiterations" [10] "float radius" .025

f16-9a

@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Jan 18, 2019

Here the results rendered by the C++ version (using 100 iterations):

> grep sppm f16-9b.pbrt
Integrator "sppm" "integer numiterations" [100] "float radius" .075

f16-9b

@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Jan 18, 2019

Here the results rendered by the C++ version (using 10.000 iterations):

> grep sppm f16-9c.pbrt
Integrator "sppm" "integer numiterations" [10000] "float radius" .075

f16-9c

wahn added a commit that referenced this issue Jan 28, 2019

@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Feb 1, 2019

There are two options (after commit 5f108ce):

  1. Proceed with render_sppm(...)
  2. Invest some time in profiling

Some arguments for option 2:

The C++ (release) version takes about 11 seconds to render (multi-threaded):

> time ~/builds/pbrt/release/pbrt f16-9a.pbrt
pbrt version 3 (built Dec  4 2018 at 10:10:06) [Detected 8 cores]
...
73.535u 2.423s 0:10.54 720.5%	0+0k 13536+5816io 36pf+0w

The single-threaded (release) version still needs only about 1m5s to render:

> time ~/builds/pbrt/release/pbrt --nthreads 1 f16-9a.pbrt
pbrt version 3 (built Dec  4 2018 at 10:10:06) [Detected 8 cores]
...
63.870u 0.716s 1:04.95 99.4%	0+0k 0+5824io 0pf+0w

I added some progress bars to the current (single-threaded) Rust executable because the current code runs far too long:

> ~/git/github/rs_pbrt/target/release/examples/rs_pbrt -i f16-9a.pbrt
pbrt version 0.5.0 [Detected 8 cores]
...
Generate SPPM visible points ...
9 / 63 [=========================>------------------------------------------------------------------------------------------------------------------------------------------------------------] 14.29 % 0.04/s 22m 
...

That's the estimate after running the program for about 4 minutes. I did previous runs where it finished that phase but it took over 15 minutes and those stages are repeated many times. So, yes, maybe it's time to investigate via the perf profiler.

Here a link from a previous discussion about Profilers and how to interprete results on recursive functions ...

@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Feb 1, 2019

After about 15 minutes:

35 / 63 [===========================================================================================================================================>----------------------------------------------------------------------------------------------------------------] 55.56 % 0.04/s 12m 
> procs pbrt ; date
 PID   User           | State TTY   CPU   MEM VSZ      RSS      TCP UDP Read  Write | CPU Time Start            | Command                                                                                                                                                                 
                      |             [%]   [%] [bytes]  [bytes]          [B/s] [B/s] |                           |                                                                                                                                                                         
 4965  jan            | R     pts/8 29.0  0.0 18.809M  2.777M   []  []  0     0     | 00:00:00 2019/02/01 10:28 | procs pbrt                                                                                                                                                              
 30775 jan            | R     pts/7 102.7 0.6 328.332M 311.633M []  []  0     0     | 00:15:02 2019/02/01 10:13 | /usr/people/jan/git/github/rs_pbrt/target/release/examples/rs_pbrt -i f16-9a.pbrt                                                                                       
Fri  1 Feb 10:28:30 GMT 2019
@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Feb 1, 2019

I'm using perf on another machine (where it is installed already).

Tell cargo that we’re going to need debugging symbols:

$ pwd
/home/jan/git/self_hosted/Rust/pbrt
$ export RUSTFLAGS='-g'
$ make clobber
$ make

We need to change something (as root) before we can run perf as user:

$ pwd
/home/jan/Graphics/Rendering/PBRT/pbrt-v3-scenes/caustic-glass
$ perf record --call-graph=lbr ~/git/self_hosted/Rust/pbrt/target/release/examples/rs_pbrt -i f16-9a.pbrt
perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 13 (Permission denied)
perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)
Error:
You may not have permission to collect stats.

Consider tweaking /proc/sys/kernel/perf_event_paranoid,
which controls use of the performance events system by
unprivileged users (without CAP_SYS_ADMIN).

The current value is 3:

  -1: Allow use of (almost) all events by all users
      Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
      Disallow raw tracepoint access by users without CAP_SYS_ADMIN
>= 1: Disallow CPU event access by users without CAP_SYS_ADMIN
>= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN

To make this setting permanent, edit /etc/sysctl.conf too, e.g.:

        kernel.perf_event_paranoid = -1

As root:

# cat /proc/sys/kernel/perf_event_paranoid
3
# echo "-1" > /proc/sys/kernel/perf_event_paranoid
# cat /proc/sys/kernel/perf_event_paranoid
-1
@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Feb 1, 2019

After approx. one minute:

$ perf record --call-graph=lbr ~/git/self_hosted/Rust/pbrt/target/release/examples/rs_pbrt -i f16-9a.pbrt
$ perf report
+   99.31%     0.00%  rs_pbrt  rs_pbrt             [.] pbrt::core::api::pbrt_cleanup                                                                                                                                                                                                     ◆
+   99.18%     0.11%  rs_pbrt  rs_pbrt             [.] pbrt::integrators::sppm::render_sppm                                                                                                                                                                                              ▒
+   97.84%     0.03%  rs_pbrt  rs_pbrt             [.] <pbrt::samplers::halton::HaltonSampler as core::clone::Clone>::clone                                                                                                                                                              ▒
-   97.71%    97.42%  rs_pbrt  rs_pbrt             [.] <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter                                                                                                                                                                   ▒
     97.41% pbrt::core::api::pbrt_cleanup                                                                                                                                                                                                                                                ▒
      - pbrt::integrators::sppm::render_sppm                                                                                                                                                                                                                                             ▒
         - 97.41% <pbrt::samplers::halton::HaltonSampler as core::clone::Clone>::clone                                                                                                                                                                                                   ▒
              <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
@wahn

This comment has been minimized.

Copy link
Owner

wahn commented Feb 1, 2019

Let's see what happens if we implement the HaltonSampler::set_sample_number() method:

impl GlobalSampler for HaltonSampler {                                                                                                      
    fn set_sample_number(&mut self, sample_num: i64) -> bool {                                                                              
        // TODO                                                                                                                             
        false                                                                                                                               
    }                                                                                                                                       
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment