Looking through Sascha Willem's C++ Vulkan Demos hosted on GitHub, I noticed that some Functions returned the Datatype VkBool32
.
I was curious to why Khronos didn't use a normal bool when I noticed the Line
typedef uint32_t VkBool32;
in vulkan.h. The uint32_t is defined as
typedef unsigned int uint32_t;
in stdint.h.
My Question is, why does it make Sense to throw away 3 Bytes if a standard Bool would do the Job with just one Byte? My little Recherche showed that there is next to no performance Difference (see Which is faster : if (bool) or if(int)?), and Khronos themselfes said that they wanted to minimize compatibility issues (in this case old C not having a primitive boolean Type) in Order to Focus on modern Code.
(See Trevett's Quote taken from here)
a ground-up redesign, we’re not backwards compatible
Try printing sizeof(bool)
on your system. Common answers are 4 or 1, and the value is by no means universal. You can get different answers depending on the compiler flags you are using.
Vulkan needs to work the same way on all systems, and it needs to work correctly no matter what compiler flags you are using to compile your program. If Vulkan was compiled with sizeof(bool) == 1
but you compile with sizeof(bool) == 4
, the interface will be incorrect. I have personally witnessed this particular error happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With