Vulkan-ValidationLayers icon indicating copy to clipboard operation
Vulkan-ValidationLayers copied to clipboard

Use of `VkApplicationInfo::apiVersion` to limit available enums/structs in (physical) device calls

Open MarijnS95 opened this issue 2 months ago • 7 comments

Describe the situation in which you encountered the missing validation

I'm not exactly confident from reading https://docs.vulkan.org/spec/latest/chapters/initialization.html#VkApplicationInfo that apiVersion here describes/limits the "API" that we can use. From reading https://docs.vulkan.org/spec/latest/chapters/fundamentals.html#fundamentals-validusage-enums it doesn't seem to constrain what I can pass to vkCreateDevice() for example:

  • If the enumerant is used in a function that has a VkPhysicalDevice object as its first parameter and either:

But if we move on to https://docs.vulkan.org/spec/latest/chapters/initialization.html#_extending_physical_device_core_functionality, it says:

New core physical-device-level functionality can be used when both VkPhysicalDeviceProperties::apiVersion and VkApplicationInfo::apiVersion are greater than or equal to the version of Vulkan that added the new functionality.

Emphasis mine. If that's true, validation is probably expected here?

In my example I find a Vulkan 1.4 physical device while only setting VkApplicationInfo::apiVersion to 1.2, and expected a validation layer error for using/passing structures to vkCreateDevice() that are only defined in 1.3 onwards, such as passing VkPhysicalDeviceVulkan13Features (my application shouldn't be allowed to assume that anything from a core version >1.2 even exists?).

Valid Usage IDs requested Please include the valid usage IDs for the checks you are requesting: ? Additional Context

Perhaps this is alson an upstream Vulkan-Docs issue, as the last quote should probably make its way into the earlier two if this is true.

Prior art

  • https://github.com/KhronosGroup/Vulkan-Docs/issues/1097 point 4.
  • https://github.com/KhronosGroup/Vulkan-Docs/issues/1539
  • https://github.com/KhronosGroup/Vulkan-Docs/issues/1569
  • https://github.com/KhronosGroup/Vulkan-Docs/issues/2077 point 6. (there is a reply that says "yea I missed that this is bounded by the api version - will fix." but not sure it materialized)
  • https://github.com/KhronosGroup/Vulkan-Docs/issues/2384

MarijnS95 avatar Oct 23 '25 18:10 MarijnS95

@MarijnS95 to make sure we both are on the same page, you basically want a validation layer error message when trying to use something like VkPhysicalDeviceVulkan13Features when VkApplicationInfo::apiVersion is set to 1.2, regardless of the driver version support or the loader (instance) version?

spencer-lunarg avatar Oct 23 '25 19:10 spencer-lunarg

@spencer-lunarg if that is in accordance with the rest of the spec [^1], then yes that's what I expect. I wouldn't say "regardless of", it should probably be a MIN(VkApplicationInfo::apiVersion, VkPhysicalDeviceProperties::apiVersion (driver version)) assuming there's already validation that says VkApplicationInfo::apiVersion <= loader (instance) version too. Together with amending it to the docs :)

[^1]: https://docs.vulkan.org/spec/latest/chapters/initialization.html#_extending_physical_device_core_functionality mentions it, https://docs.vulkan.org/spec/latest/chapters/fundamentals.html#fundamentals-validusage-enums implicitly disagrees by probably-accidental omission

MarijnS95 avatar Oct 23 '25 19:10 MarijnS95

This entire corner of the spec is honestly a constant back and forth what we are suppose to validate or not validate and due to not wanting to get it wrong (again), going to raise an internal spec issue and confirm this before spending time on code generation to fix it

spencer-lunarg avatar Oct 23 '25 20:10 spencer-lunarg

Thanks for that; yeah I should have checked with the spec first before coming here and ultimately requesting the final step which is validation. There were many duplicates open at Vulkan-Docs already however.

This was mostly to show someone "look what you're doing is invalid AFAIK", but then there was no Validation error and I had to dig through this ambiguous spec to figure out whether or not my mental model was wrong 🙂

MarijnS95 avatar Oct 23 '25 20:10 MarijnS95

I also always like examples, mainly because I will need to write a test later, and knowing what to write a test on is helpful

spencer-lunarg avatar Oct 23 '25 20:10 spencer-lunarg

for future tracking https://gitlab.khronos.org/vulkan/vulkan/-/issues/4497

spencer-lunarg avatar Oct 23 '25 21:10 spencer-lunarg

@spencer-lunarg sure, I pieced together a sample test right away. Couldn't run it, some linker error against slang_createGlobalSession2 and I have yet to validate what's stuck on my system.

https://github.com/MarijnS95/Vulkan-ValidationLayers/compare/application-api-version-affects-all-calls

MarijnS95 avatar Oct 23 '25 22:10 MarijnS95