Not very clear about the "Host Synchronization" parts in spec

Hi, I’m writing a wrapper of Vulkan which do some validation checks on runtime, and I got a little confused of the “Host Synchronization” parts in spec, for example when I capsule the function vkDestroyInstance, the doc says:

  • Host access to instance must be externally synchronized
  • Host access to all VkPhysicalDevice objects enumerated from instance must be externally synchronized
  1. For the first rule, does that mean this function will “mutate” the state of instance, so when this function get called, no other thread should do anything with instance?
  2. If so, if a function’s doc didn’t talk about the synchronized rules, then this function can be called in multiple thread, as long as no synchronized function is calling?
  3. If so, then the synchronized part illustrates whether a parameter is mutated or not, but where’s the second rule comes? There’s no parameter of VkPhysicalDevice in vkDestroyInstance.

P.S. about question 3, or does that mean "when calling vkDestroyInstance", all VkPhysicalDevice created by instance should also not be used in other threads?

P.P.S. Are there any layers which can detect synchronized issue? It seems that “VK_LAYER_KHRONOS_validation” won’t.

From the specification:

Vulkan is intended to provide scalable performance when used on multiple host threads. All commands support being called concurrently from multiple threads, but certain parameters, or components of parameters are defined to be externally synchronized. This means that the caller must guarantee that no more than one thread is using such a parameter at a given time.

That is just a re-wording of the literal text you quoted. Everything in the valid usage boxes pertain to "when calling <insert function here>".

1 Like
  1. Yes. Command with externsync is a writer. No other thread may read or write instance at the same time.
  2. If the command is not externsync, then it is a reader. Multiple threads can read the same thing at the same time without disturbing each other.
  3. vkDestroyInstance implicitly destroys (i.e. “kinda writes”) all its VkPhysicalDevices. There’s no dedicated vkDestroyPhysicalDevice command. So there must be nothing reading any of the VkPhysicalDevice at the time they are destroyed.

VK_LAYER_KHRONOS_validation checks this, but might miss some coverage. Instance might be a special case, because the validation needs instance to work. Additionally threading issues may not always be triggered, as sometimes they simply miss the memory hazard by the way they are timed.

PS: Yea seems to be checked: Vulkan-ValidationLayers/thread_safety.cpp at a131fcaebf147ffc15377320a97f2fb4d9234191 · KhronosGroup/Vulkan-ValidationLayers · GitHub

PPS: Of course what externsync means is authoritatively written in teh spec: Vulkan® 1.0.208 - A Specification

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.