存储动画顶点数据的最佳方式 [英] Best way to store animated vertex data

查看:40
本文介绍了存储动画顶点数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,有几种方法可以将顶点数据存储和传输到 GPU.

From what I understand there are several methods for storing and transferring vertex data to the GPU.

  • 使用临时暂存缓冲区并将其每帧复制到独立的 GPU 内存
  • 使用共享缓冲区(这很慢?)并且每帧更新共享缓冲区
  • 永久存储每个网格的暂存缓冲区,而不是每帧重新创建它并将其复制到 GPU

哪种方法最适合存储快速变化的动画网格数据?

Which method is best for storing animating mesh data which changes rapidly?

推荐答案

这取决于硬件和它宣传的内存类型.请注意,以下所有内容都要求您使用 vkGetBufferMemoryRequirements 来检查内存类型是否可以支持您需要的用法.

It depends on the hardware and the memory types it advertises. Note that all of the following requires you to use vkGetBufferMemoryRequirements to check to see if the memory type can support the usages you need.

如果硬件通告的内存类型 DEVICE_LOCALHOST_VISIBLE,那么您应该使用而不是 分期.现在,您仍然需要对此进行双缓冲,因为您无法写入 GPU 正在读取的数据,并且除非 GPU 延迟超过一帧,否则您不想与 GPU 同步.这也是你应该衡量的东西;您的 GPU 需求可能需要三重缓冲区,因此请灵活设计您的系统.

If hardware advertises a memory type that is both DEVICE_LOCAL and HOST_VISIBLE, then you should use that instead of staging. Now, you still need to double-buffer this, since you cannot write to data that the GPU is reading from, and you don't want to synchronize with the GPU unless the GPU is over a frame late. This is something you should also measure; your GPU needs may require a triple buffer, so design your system to be flexible.

请注意,某些硬件具有两种不同的 DEVICE_LOCAL 堆,但其中只有一种具有 HOST_VISIBLE 内存类型.所以要注意那些情况.

Note that some hardware has two different heaps that are DEVICE_LOCAL, but only one of them will have HOST_VISIBLE memory types for them. So pay attention to those cases.

如果没有这样的内存类型(或者如果内存类型不支持您需要的缓冲区使用),那么您需要对此进行分析.两种选择是:

If there is no such memory type (or if the memory type doesn't support the buffer usages you need), then you need to profile this. The two alternatives are:

  • 暂存(通过专用传输队列,如果可用)到 DEVICE_LOCAL 内存类型,数据最终会在其中使用.
  • 直接使用非DEVICE_LOCAL 内存类型.
  • Staging (via a dedicated transfer queue, where available) to a DEVICE_LOCAL memory type, where the data eventually gets used.
  • Directly using a non-DEVICE_LOCAL memory type.

请注意,这两个都需要缓冲,因为您希望尽可能避免同步.暂存传输队列也需要信号量,因为您需要确保图形队列在传输队列完成之前不会尝试使用内存.这也意味着您需要处理第 11.7 章:如何在队列之间共享资源.

Note that both of these require buffering, since you want to avoid synchronization as much as possible. Staging through a transfer queue will also require a semaphore, since you need to make sure that the graphics queue doesn't try to use the memory until the transfer queue is done with it. It also means you need to deal with chapter 11.7: how to share resources between queues.

不过,就我个人而言,我会尽量避免 CPU 动画顶点数据.支持 Vulkan 的 GPU 完全能够自己制作任何动画.十多年来,GPU 一直在进行骨骼加权蒙皮(甚至基于双四元数).甚至顶点调色板动画也是 GPU 可以做到的;总结各种不同的顶点以得出最终答案.因此,具有大量 CPU 生成顶点数据的场景应该相对较少.

Personally though, I would try to avoid CPU animated vertex data whenever possible. Vulkan-capable GPUs are perfectly capable of doing any animating themselves. GPUs have been doing bone weighted skinning (even dual-quaternion-based) for over a decade now. Even vertex palette animation is something the GPU can do; summing up the various different vertices to reach the final answer. So scenes with lots of CPU-generated vertex data should be relatively rare.

这篇关于存储动画顶点数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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