Vulkan 描述符绑定 [英] Vulkan descriptor binding

查看:42
本文介绍了Vulkan 描述符绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 vulkan 应用程序中,当所有网格都使用相同的纹理时,我曾经绘制这样的网格

In my vulkan application i used to draw meshes like this when all the meshes used the same texture

Updatedescriptorsets(texture)

Command buffer record
{
 For each mesh
        Bind transformubo
        Draw mesh
}

但现在我希望每个网格都有独特的纹理,所以我尝试了这个

But now I want each mesh to have a unique texture so i tried this

Command buffer record
{
 For each mesh
        Bind transformubo
        Updatedescriptorsets (textures[meshindex])
        Draw mesh
}

但是它给出了一个错误,说明描述符集被破坏或更新.我查看了 vulkan 文档,发现我无法在命令缓冲区记录期间更新描述符集.那么如何让每个网格都有独特的纹理呢?

But it gives an error saying descriptorset is destroyed or updated. I looked in vulkan documentation and found out that I can't update descriptorset during command buffer records. So how can I have a unique texture to each mesh?

推荐答案

vkUpdateDescriptorSets 未与任何内容同步.因此,您不能在使用中更新描述符集.您必须确保使用相关描述符集的所有渲染操作都已完成,并且未将任何命令放置在使用相关描述符集的命令缓冲区中.

vkUpdateDescriptorSets is not synchonrized with anything. Therefore, you cannot update a descriptor set while it is in use. You must ensure that all rendering operations that use the descriptor set in question have finished, and that no commands have been placed in command buffers that use the set in question.

它基本上就像一个全局变量;你不能让人们在没有某种同步的情况下从多个线程访问全局变量.而且 Vulkan 不会同步对描述符集的访问.

It's basically like a global variable; you can't have people accessing a global variable from numerous threads without some kind of synchronization. And Vulkan doesn't synchronize access to descriptor sets.

有几种方法可以解决这个问题.您可以为每个对象提供其自己的描述符集.这通常是通过使频繁变化的描述符集数据具有比不太频繁变化的数据更高的索引来实现的.这样,您就不会更改每个对象的每个描述符,而只会更改每个对象的描述符.

There are several ways to deal with this. You can give each object its own descriptor set. This is usually done by having the frequently changing descriptor set data be of a higher index than the less frequently changing data. That way, you're not changing every descriptor for each object, only the ones that change on a per-object basis.

您可以使用推送常量数据来索引大表/数组纹理.所以描述符集将有一个数组纹理或一个纹理数组(如果你有纹理数组的动态索引).推送常量将提供一个索引,着色器使用该索引从数组纹理/纹理数组中获取该特定对象的纹理.这使得频繁更改相当便宜,并且相同的索引也可以用于为每个对象提供自己的变换矩阵(通过获取矩阵数组).

You can use push constant data to index into large tables/array textures. So the descriptor set would have an array texture or an array of textures (if you have dynamic indexing for arrays of textures). A push constant would provide an index, which is used by the shader to fetch that particular object's texture from the array texture/array of textures. This makes frequent changes fairly cheap, and the same index can also be used to give each object its own transformation matrices (by fetching into an array of matrices).

如果您有可用的扩展 VK_KHR_push_descriptor,那么您可以将描述符的更改直接集成到命令缓冲区中.这比推送常量机制好多少当然取决于实现.

If you have the extension VK_KHR_push_descriptor available, then you can integrate changes to descriptors directly into the command buffer. How much better this is than the push constant mechanism is of course implementation-dependent.

这篇关于Vulkan 描述符绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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