多个网格上的 Vulkan 纹理渲染 [英] Vulkan texture rendering on multiple meshes

查看:28
本文介绍了多个网格上的 Vulkan 纹理渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个模型的多个网格上渲染不同的纹理,但我对这些过程没有太多线索.有人建议为每个网格创建自己的描述符集并调用 vkCmdBindDescriptorSets() 和 vkCmdDrawIndexed() 进行渲染,如下所示:

I am in the middle of rendering different textures on multiple meshes of a model, but I do not have much clues about the procedures. Someone suggested for each mesh, create its own descriptor sets and call vkCmdBindDescriptorSets() and vkCmdDrawIndexed() for rendering like this:

    // Pipeline with descriptor set layout that matches the shared descriptor sets
vkCmdBindPipeline(...pipelines.mesh...);
...
// Mesh A
vkCmdBindDescriptorSets(...&meshA.descriptorSet... );
vkCmdDrawIndexed(...);
// Mesh B
vkCmdBindDescriptorSets(...&meshB.descriptorSet... );
vkCmdDrawIndexed(...);

但是,上面的做法和chopper的sample和vulkan的sample有很大的不同,让我不知道从哪里开始改变.我非常感谢任何帮助指导我走向正确方向的帮助.

However, the above approach is quite different from the chopper sample and vulkan's samples that makes me have no idea where to start the change. I really appreciate any help to guide me to a correct direction.

干杯

推荐答案

您有一个概念对象,它由具有不同纹理需求的多个网格组成.处理这种情况的一般方法是:

You have a conceptual object which is made of multiple meshes which have different texturing needs. The general ways to deal with this are:

  1. 更改对象部分之间的描述符集.很痛苦,但它适用于所有支持 Vulkan 的硬件.

  1. Change descriptor sets between parts of the object. Painful, but it works on all Vulkan-capable hardware.

使用阵列纹理.每个单独的网格从阵列纹理中的特定层获取其数据.当然,这会限制您让每个子网格使用相同大小的纹理.但它适用于所有支持 Vulkan 的硬件(最多 128 个数组元素,最少).特定网格的阵列层可以作为推常​​数提供,也可以作为基础实例(如果可用)提供.

Employ array textures. Each individual mesh fetches its data from a particular layer in the array texture. Of course, this restricts you to having each sub-mesh use textures of the same size. But it works on all Vulkan-capable hardware (up to 128 array elements, minimum). The array layer for a particular mesh can be provided as a push-constant, or a base instance if that's available.

请注意,如果您设法能够通过基本实例来完成,那么您可以使用多绘制间接命令渲染整个对象.尽管尚不清楚简短的多次绘制间接是否比将简短的绘制命令序列放入命令缓冲区要快.

Note that if you manage to be able to do it by base instance, then you can render the entire object with a multi-draw indirect command. Though it's not clear that a short multi-draw indirect would be faster than just baking a short sequence of drawing commands into a command buffer.

使用采样器数组,正如 Sascha Willems 所建议的那样.据推测,子网格的数组索引是作为推常数或多次绘制的绘制索引提供的.问题是,无论数组索引是如何提供的,它都必须是一个动态统一的表达式.并且 Vulkan 实现不需要来允许您使用动态统一表达式索引采样器数组.基本要求只是一个常量表达式.

Employ sampler arrays, as Sascha Willems suggests. Presumably, the array index for the sub-mesh is provided as a push-constant or a multi-draw's draw index. The problem is that, regardless of how that array index is provided, it will have to be a dynamically uniform expression. And Vulkan implementations are not required to allow you to index a sampler array with a dynamically uniform expression. The base requirement is just a constant expression.

这将您限制为支持 shaderSampledImageArrayDynamicIndexing 功能的硬件.所以你必须提出要求,如果它不可用,那么你必须用#1 或#2 解决这个问题.或者只是不要在该硬件上运行.但最后一个意味着你不能在任何移动硬件上运行,因为 他们中的大多数人目前还不支持这个功能.

This limits you to hardware that supports the shaderSampledImageArrayDynamicIndexing feature. So you have to ask for that, and if it's not available, then you've got to work around that with #1 or #2. Or just don't run on that hardware. But the last one means that you can't run on any mobile hardware, since most of them don't support this feature as of yet.

请注意,我并不是说您不应该使用这种方法.我只是想让你知道有成本.有很多硬件无法做到这一点.所以你需要为此做好计划.

Note that I am not saying you shouldn't use this method. I just want you to be aware that there are costs. There's a lot of hardware out there that can't do this. So you need to plan for that.

这篇关于多个网格上的 Vulkan 纹理渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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