mitsuba-renderer/drjit

Create and query multiple textures in parallel

WeiPhil opened this issue · 2 comments

Hi,
I'm not sure if I'm approaching this problem from the right angle but I am trying to create an array of N textures in python (cuda_rgb variant) that I could later query in parallel for a set of pairs (2d_coord, tex_id), i.e. each 2d coordinate needs to query their associated texture tex_id independently.
However, when using textures = dr.zeros(mi.Texture2f, 100) it returns None (a bug?), and dr.repeat(mi.Texture2f(shape=512,512],channels=3),100) fails with an error. Is there a different way of going about my specific problem with drjit/mitsuba?

In the end I would expect something like

tex_to_eval = dr.gather(mi.Texture2f, textures, tex_ids )
tex_to_eval.eval(coords_to_eval)

to be possible but I don't seem to find a way of achieving this going that way.

Best,
Philippe

The Texture2f type only wrap a buffer with fancy lookup routines and can't be stacked in dynamic arrays. I suppose what you are looking for ressembles vectorized virtual function call, e.g. evaluating a different BSDF for a wide array of BSDF ids. For this we have BSDFPtr that represents a dynamic array of BSDF pointers, and on top of that the BSDF type and its virtual methods are registered in Dr.Jit so that it knows how to dispatch a call on an array of pointers.

Back to the Texture2f type, we don't have a corresponding Texture2fPtr type. Fortunately, we recently added dr.switch() in Dr.Jit. You can provide it an array of functions, a dynamic array of indices and other arguments (same width of the array of indices) and it will dispatch the call on the different functions. In your case you should be able to create one function per texture and dispatch the texture evaluations using dr.switch().

For more information on the syntax, take a look at the documentation.

Something like BSDFPtr for texture is indeed what I was looking for but I didn't know of the new addition of dr.switch, this is exactly what I was looking for!
Thank you Sebastien :)