Does NZSL support recursion?
Is it possible to define recursive functions in NZSL?
I normally use macro expansion to define recursive functions in shading languages, but I wish they had built-in support for recursion.
Hi.
NZSL does not prevent recursion but it is explicitly disallowed on both GLSL and SPIR-V ("The static function call graph for an entry point must not contain cycles.").
There's not much I can do about this unfortunately.
@SirLynix You can implement recursion in the same way that I described here, but then the depth of recursion would need to be known at compile-time.
Indeed, it would be possible using this. However how should this be exposed? And since every recursive code can be turned into a loop, what would be the main advantage here?