zeux / volk

Meta loader for Vulkan API
MIT License
1.35k stars 118 forks source link

Should I be calling `volkFinalize()`? #156

Closed gruelingpine185 closed 11 months ago

gruelingpine185 commented 11 months ago

This is interesting... you expose several functions such as volkInitialize() and volkLoadInstance() and a few other functions. The ones I explicitly mentioned have a place on the README where a brief usage example utilizes them. Usually libraries and APIs would expose functions like init_xyz() or create_xyz(), and they will have their own termination functions like deinit_xyz() and destroy_xyz(). The README has no mention such, but upon looking into the volk header file I found volkFinalize() - which thanks to the comment above it - allows me to draw the conclusion that this is the termination function of volkInitialize().

It's exposed in the header file, so I'd assume it is for users of Volk to call (and volk.c doesn't seem to call it), but sometimes this isn't always the case. The tests that reside in test/ don't call the volkFinalize() and neither do the projects that I found that use Volk. My question is: Should I be calling volkFinalize()? and when?

It would be appreciated if the comments on each function can reflect its usage. Say, the comment can add:

/**
 * <original comment here>
 * 
 * if initializing volk fails, volk will internally do teardown operations,
 * but if it is successful, then the caller needs to call `volkFinalize()`
 * when the renderer is being deconstructed (or something like that).
*/
VkResult volkInitialize(void);

You know?

zeux commented 11 months ago

You don't have to call volkFinalize as the only "resource" here is the DLL loaded into the process space and it will be unloaded upon process exit. But if you want to do an early teardown for some reason, it's provided. I'll add it to readme.

gruelingpine185 commented 11 months ago

Awesome. Thanks so much