Closed Honeybunch closed 4 years ago
Looks like some checks failed. I will work on that :)
Code has changed a bit since I first opened the review. Glad I managed to fix the builds in CI. Though I'm not so happy about requiring vulkan.h to be included before optick.h. I don't like adding an include order dependency to anything but I can't think of a better way to be able to get access to the Vulkan function pointers. I would forward declare them but I don't think I can forward declare functions with unknown types (VkResult for example). Hopefully this is still okay.
Hi Arsen, thanks for the pull request.
Though I'm not so happy about requiring vulkan.h to be included before optick.h. I don't like adding an include order dependency to anything but I can't think of a better way to be able to get access to the Vulkan function pointers. I would forward declare them but I don't think I can forward declare functions with unknown types (VkResult for example).
You should be able to replace VkResult with int32_t in forward declarations. Including vulkan.h from optick.h is a really bad idea as it will have a noticeable impact on the compilation time for big projects. I can see that you've already tried this approach in https://github.com/bombomby/optick/pull/109/commits/ef25e91739a6d0731f840b7204dd2feb863ae707. What was the problem with this approach?
Thanks for the feedback! My preliminary efforts to forward declare the function pointers were thwarted by not being able to replace certain enums with compatible types. Turns out you can forward declare enums in C++ with enum VkResult;
or if you want you can supply a specific size/backing type with enum VkResult : int32_t;
TIL!
I'm much happier with this PR with that resolved :)
Well it looks like enum VkResult;
only works on MSVC and enum VkResult : int32_t
will only work if the later declaration of VkResult
ALSO uses the same explicit backing type. What a pain. The current solution works but does mean that including optick.h before vulkan.h will cause a problem
The only way to avoid this would be to avoid trying to forward declare the enums and instead require users to cast their function pointers to the "forward declared" versions
So, with forward declared enums off the table as an option. What would be your preferred solution to this?
So, with forward declared enums off the table as an option. What would be your preferred solution to this?
I would go for option 2 for now: Replacing enums with int types and requiring users to manually cast function pointers. optick.h is usually included in many headers, so keeping it small and with minimum dependencies is the key.
After posting this issue: https://github.com/bombomby/optick/issues/108 I figured I'd dig in and at least see what would be needed to support vulkan meta-loaders. This is the solution I've whipped up so far. I've tested this in a personal engine and it seems to work great.