`vkCommandPool` 可以从主线程分配并移动到其他线程吗? [英] Can `vkCommandPool` be allocated from the main thread and the moved to other threads?

查看:22
本文介绍了`vkCommandPool` 可以从主线程分配并移动到其他线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从主线程分配vkCommandPool,然后将它们移动到一个新线程中,在那里独占使用?

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

伪代码:

// 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

在我发现的所有示例和演示文稿中,command_pool 是在线程中创建的,而不是在主线程中创建,但是我在 规范.

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.

推荐答案

vulkan 中没有任何内容与特定线程绑定.

Nothing in vulkan is bound to a specific thread.

只要您遵守外部同步要求,您就可以从任何线程自由调用任何 vulkan 函数.

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).

在其他 API 中,当一个对象绑定到一个线程时,它被非常清楚地记录下来.

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

在这种情况下,一次只有 1 个线程可以访问 command_pool,但是对同一命令池的连续命令可以来自不同的线程.

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.

这篇关于`vkCommandPool` 可以从主线程分配并移动到其他线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆