gpt4 book ai didi

opengl - UBO/SSBO 与 Vulkan 的着色器内存绑定(bind)有何不同?

转载 作者:行者123 更新时间:2023-12-03 22:31:23 25 4
gpt4 key购买 nike

article on Imagination's website ,我已阅读以下段落:

For example, there are no glUniform*() equivalent entry points in Vulkan; instead, writing to GPU memory is the only way to pass data to shaders.

When you call glUniform*(), the OpenGL ES driver typically needs to allocate a driver managed buffer and copy data to it, the management of which incurs CPU overhead. In Vulkan, you simply map the memory address and write to that memory location directly.


那和使用统一缓冲区有什么区别吗?它们也被明确分配并且可以携带任意数据。由于统一缓冲区的大小非常有限,也许 Shader Storage Buffers是一个更好的比喻。

最佳答案

据我了解,这不是 glUniform*()具体:glUniform*()只是本文作者用来说明 Vulkan 在主机与 GPU 之间通信方面的工作方式的一个示例。

When you call glUniform*(), the OpenGL ES driver typically needs to allocate a driver managed buffer and copy data to it, the management of which incurs CPU overhead.



在这种情况下,当用户调用 glUniform*()对于一些数据,该数据首先被复制到 OpenGL 实现所拥有的缓冲区中。这个缓冲区可能是固定的,然后驱动程序可以使用它通过 DMA 将数据传输到设备。这是两个步骤:
  • 将用户数据复制到驱动缓冲区;
  • 通过 DMA 将缓冲区内容传输到 GPU。

  • In Vulkan, you simply map the memory address and write to that memory location directly.



    在这种情况下,没有用户数据的中间副本。您要求 Vulkan 将一个区域映射到您直接写入的主机的虚拟地址空间。数据通过 DMA 以对用户完全透明的方式到达设备。

    从性能的角度来看,好处是显而易见的:零拷贝。这也意味着 Vulkan 实现可以更简单,因为它不需要管理中间缓冲区。

    由于规范尚未发布,这是一个虚构的示例,说明它的外观:
    // Assume Lights is some kind of handle to your buffer/data
    float4* lights = vkMap(Lights);

    for (int i = 0; i < light_count; ++i) {
    // Goes directly to the device
    lights[i] = make_light(/* stuff */);
    }

    vkUnmap(lights);

    关于opengl - UBO/SSBO 与 Vulkan 的着色器内存绑定(bind)有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28835100/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com