Tim Diekmann
Tim Diekmann

Reputation: 8466

Can `vkCommandPool` be allocated from the main thread and the moved to other threads?

Is it possible, to allocate vkCommandPool from the main thread and then move them into a new thread, where it is used exclusively?

Pseudo code:

// Pool for creating secondary buffers
threaded_command_pool = new CommandPool();

// Thread for filling secondary buffers
// threaded_command_poolzd is used only here
thread_handle = new Thread(move(command_pool))

thread_handle.join()

// Pool for merging secondary buffers
command_pool = new CommandPool() 
primary_command_buffer = command_pool.create_buffer()

// fill primary_command_buffer with secondary buffers from thread

In all examples and presentation I have found, the command_pool is created in the thread, not in the main thread, but I couldn't find this requirement in the specs.

Upvotes: 2

Views: 568

Answers (1)

ratchet freak
ratchet freak

Reputation: 48196

Nothing in vulkan is bound to a specific thread.

You are free to call any vulkan function from any thread as long as you obey the externally synchronized requirements.

If two commands operate on the same object and at least one of the commands declares the object to be externally synchronized, then the caller must guarantee not only that the commands do not execute simultaneously, but also that the two commands are separated by an appropriate memory barrier (if needed).

In other APIs when an object is bound to a thread it is very clearly documented.

In this case only 1 thread at a time can access a command_pool however successive commands to the same command pool can be from different threads.

Upvotes: 8

Related Questions