The attribute program will be used inside the anyhit program as well.
Calculations of attributes which are not sourced will be removed as dead code.
This is the same for RTX and pre-Turing GPUs.
“To my understanding, in “mega-kernel execution strategy”, attribute evaluation takes place for every successfully intersected triangle”
Only if OptiX is not able to optimize that automatically, which it did in the past, but not for all cases. That’s why I said it might not always do that
It always will now with the attribute program in the RTX execution strategy, which is the default now.
Having an anyhit program will generally run slower than not having one. This is especially true for RTX boards where the traversal and triangle intersection runs in hardware on the RT cores but anyhit programs will run on the streaming multiprocessor.
You’ll need the attributes latest in the closesthit program.
There are even more possibilities now. For scenes with only opaque materials (means no cutout opacity) there isn’t actually an anyhit program needed for either the radiance or the shadow ray in OptiX 6 anymore, because that introduced ray flags which are hardware accelerated on RTX GPUs and result in less execution divergence overall. The ray flags allow, for example, to terminate the ray on first hit, which is exactly what an anyhit program for the shadow ray of opaque materials does.
This is just one example how things can be sped up in OptiX 6 for special cases.
Please have a look a the GTC Presentation S9768 - New Features in OptiX 6.0 once it becomes available (30 days after the GTC 2019) on:
It shows the execution flow for these things.