I am in the process of updating my shadow mapping routines and came across an issue with my point lights. Basically I'm supplying a ByteAddressBuffer to my pixel shader that contains a list of light sources (actually it's an index table into a separate light data buffer) that are close enough to affect each mesh instance being rendered.
Having a for-loop iterate over this list works well when using a comparison sampler to query shadow maps, however it yields divergent gradient compilation errors when used with mip mapped shadow maps. I get why this happens and have been thinking about alternative ways around it.
I had an idea to expand the light table to account for every light source, even those not affecting certain meshes (which seems wasteful but I suppose there won't be that many light sources at once anyway). In this way I could loop over all point lights for every pixel, and then do a dynamic branch based on whether the current light index is referenced by the currently drawn instance. However, I then got to thinking, how are hardware instances really drawn? Is each instance drawn by a different thread group or could I end up with multiple instances in the same group? If that can happen I don't see any way to guarantee non-divergent gradients within pixel blocks. Is there any, or should I rethink this problem from the ground up?
Thankful for any advice.