Vulkan extension doubt about SPV_KHR_shader_ballot

Hi guys. I have a AMD Radeon R9 2000 GPU. I use SPV_KHR_shader_ballot extension like this:

  1. create device with “VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME” extension
  2. add “#extension GL_ARB_shader_ballot : require” in compute shader.
  3. compile GLSL shader to SPIRV.
    everything is OK. This also fits with my understanding that if you need an extension, you need to turn on support for that extension.

But I did the following experiment:

  1. create device with default extension, setting enabledExtensionCount = 0 and ppEnabledExtensionNames = nullptr in VkDeviceCreateInfo.
  2. add “#extension GL_ARB_shader_ballot : require” in my compute shader.
  3. compile GLSL shader to SPIRV.

program is OK! this makes me a little confused.
So I have a question: if the device doesn’t support an extension, but enable this extension is SPIRV code, the driver will cover this problem when creating a shader module with vkCreateShaderModule?

Vulkan is not a safe API; you should never assume “it didn’t error out” means that what you did was fine. Implementations will almost never check things like whether you’re trying to use an extension you didn’t enable. That’s what validation layers are for.

Enable VK_LAYER_KHRONOS_validation, there is [VUID-VkShaderModuleCreateInfo-pCode-01091] Validation Error. But I don’t understand that result is right.

That sounds like the error you should get. What is difficult to understand about it?

I mean that I get VUID-VkShaderModuleCreateInfo-pCode-01091 error, but the result is right. How to explain this?

It’s what I said before: “Vulkan is not a safe API”. “My code seems to work right” is insufficient information to know if it is actually valid in accord with Vulkan’s rules. There’s nothing to explain: invalid code yields undefined behavior, and undefined behavior may appear to “work”.

This is precisely why validation layers exist and precisely why you should always develop using them.

Undefined behavior is undefined. Anything is allowed to happen in such a case.