Why is Vulkan VkBool32 implemented as an unsigned int?

Looking through the Sascha Willem C ++ Vulkan Demos hosted on GitHub , I noticed that some functions returned the VkBool32 data VkBool32 .

I was curious why Khronos did not use the usual bool when I noticed Line

typedef uint32_t VkBool32;

at vulkan.h. Uint32_t is defined as

typedef unsigned int uint32_t;

in stdint.h.

My question is: why does it make Sense throw 3 bytes if the standard Bool will do the job with only one byte? My little Recherche showed that there is no performance difference near (see Which is faster: if (bool) or if (int)? ), And Khronos themselfes said they wanted to minimize compatibility problems (in this case, old C, not having a primitive Boolean type) in the order of focus on modern code.

(See Trevett Quote from here )

grounding design, were not compatible with the reverse side

+6
source share
1 answer

Try printing sizeof(bool) on your system. The general answers are 4 or 1, and this value is by no means universal. You may receive different answers depending on the compiler flags you use.

Vulkan should work the same on all systems, and it should work correctly no matter what compiler flags you use to compile your program. If Vulkan was compiled using sizeof(bool) == 1 , but you are compiling it using sizeof(bool) == 4 , the interface will be incorrect. I personally witnessed this error.

+8
source

All Articles