ShaderLang icon indicating copy to clipboard operation
ShaderLang copied to clipboard

Does NZSL support recursion?

Open jarble opened this issue 2 years ago • 3 comments

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.

jarble avatar Dec 02 '23 22:12 jarble

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 avatar Dec 03 '23 13:12 SirLynix

@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.

jarble avatar Dec 04 '23 18:12 jarble

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?

SirLynix avatar Dec 04 '23 19:12 SirLynix