使用金属有效渲染滚动图像

发布于 2025-02-07 17:56:40 字数 569 浏览 2 评论 0原文

我想使用金属有效地呈现特定类型的时变图像 - 即连续垂直滚动的图像。也就是说,每个帧与以前的帧完全相同,除了向下移动一行。底部排从屏幕上滚动并丢弃。顶行是从一些Swift数组输入的新数据。我的应用程序使用实时音频数据来渲染频谱图 - 但是,这种“渲染滚动图像”是具有广泛适用性的通用需求。

实现此目的的蛮力方法是将数据存储在数组中,并将整个图像数组读取到每个帧的渲染屏幕中 - 忽略了99.9%的数据已经在视频存储器缓冲区中,而只需需要访问方式不同。

在过去,当开发人员可以直接访问Display的VRAM视频内存时,可以通过简单地将VRAM的行 - 访问指针递增为每个帧(并在Top Row的新数据中编写)来实现此效果。如今,OS的摘要屏幕的缓冲存储器 - 但希望金属提供了一种巧妙的方法,可以切割此抽象以允许这种低级数据转移。

这样的问题“使用金属着色器移动图像”(在这里)很有帮助,但让我想知道正确的方法是什么。有人可以请我指向正确的方向吗?

I would like to use Metal to efficiently render a particular type of time-varying image - namely an image which continuously scrolls vertically. That is, each frame is exactly the same as the previous frame except shifted down by one row. The bottom row scrolls off the screen and is discarded. The top row is new data inputted from some Swift array. My application uses real-time audio data to render a spectrogram - but this "rendering a scrolling image" is a general-purpose need with broad applicability.

The brute-force way to implement this is to store the data in an array and read the entire image array into the rendering screen for each frame - ignoring the fact that 99.9% of the data is already in the video memory buffer and simply needs to be accessed differently.

In the old days, when developers had direct access to the display's VRAM video memory, one could achieve this effect by simply incrementing the VRAM's row-access pointer by one for each frame (and writing in the top row's new data). Today, OS's abstract the screen's buffer memory - but hopefully Metal provided a clever way of cutting through this abstraction to allow this low-level data shifting.

The SO question "Moving an Image using Metal Shader" (here) is helpful, but leaves me wondering what's the right approach. Can someone please point me in the right direction to implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文