mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
593 stars 43 forks source link

Any suggestion on when to use drjit::eval()? #77

Closed andyyankai closed 2 years ago

andyyankai commented 2 years ago

I am writing a PT using drjit, however. It seems I have to call drjit::eval() VERY often to ensure it can give me the correct result. like this:

BSDFArra bsdf_array = its.shape->bsdf();
drjit::eval(bsdf_array);
...
drjit::eval(its)
bsdf_val2 = bsdf_array->eval(its, wo_local, active_direct);
...
auto rs = throughput * emitter_val * bsdf_val2 * weight1;
drjit::eval(rs);
result[active_direct] +=  rs; // this will have correct result
// result[active_direct] += throughput * emitter_val * bsdf_val2 * weight1; // this will have incorrect result!!

Is there anything I might forget causing such issue? I think it is quite not normal to use such a lot eval to ensure the correct result compared to enoki... Thanks!

Speierers commented 2 years ago

Hi @andyyankai ,

This shouldn't be necessary. And infact, a forced evaluation should never change the result of some computation. It only tells the JIT compiler should to organize the kernel, which can be used for instance to define the "boundaries" of a megakernel in a renderer.

Could you share a tiny reproducer that behaves differently when using or not dr::eval()?

andyyankai commented 2 years ago

I will update later, but thanks for the help! This only happens when the program becomes more complex... and I just find out I didn't use DRJIT_STRUCT for my ray class, not sure this can be a potential problem. So I guess mitsuba3 doesn't face such a problem during development? Thanks!

Speierers commented 2 years ago

No, if you look through the Mitsuba 3 codebase, there are only a few places where we manually call dr::eval() to breakdown the computation in smaller kernels (intentionally).

Let me close this issue for now. If you manage to reproduce this with a smaller code example please post it here I will take a look.