Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Vulkan's VkBool32 implemented as an unsigned int?

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

like image 972
Jan Hohenheim Avatar asked Feb 18 '16 16:02

Jan Hohenheim


1 Answers

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.

like image 112
Dietrich Epp Avatar answered Nov 08 '22 13:11

Dietrich Epp