简体   繁体   English

vulkan中的异步渲染model

[英]Asynchronous rendering model in vulkan

Recently I'm reading https://github.com/ARM-software/vulkan_best_practice_for_mobile_developers/blob/master/samples/vulkan_basics.md , and it said:最近我正在阅读https://github.com/ARM-software/vulkan_best_practice_for_mobile_developers/blob/master/samples/vulkan_basics.md ,它说:

OpenGL ES uses a synchronous rendering model, which means that an API call must behave as if all earlier API calls have already been processed. OpenGL ES 使用同步渲染 model,这意味着 API 调用必须表现得好像所有先前的 ZDB974238714CA81DEFZ 调用都已处理一样。 In reality no modern GPU works this way, rendering workloads are processed asynchronously and the synchronous model is an elaborate illusion maintained by the device driver.实际上,没有现代 GPU 以这种方式工作,渲染工作负载是异步处理的,同步 model 是由设备驱动程序维护的精心设计的错觉。 To maintain this illusion the driver must track which resources are read or written by each rendering operation in the queue, ensure that workloads run in a legal order to avoid rendering corruption, and ensure that API calls which need a data resource block and wait until that resource is safely available.为了保持这种错觉,驱动程序必须跟踪队列中的每个渲染操作读取或写入哪些资源,确保工作负载以合法顺序运行以避免渲染损坏,并确保需要数据资源块的 API 调用并等待直到资源是安全可用的。

Vulkan uses an asynchronous rendering model, reflecting how the modern GPUs work. Vulkan 使用异步渲染 model,反映了现代 GPU 的工作方式。 Applications queue rendering commands into a queue, use explicit scheduling dependencies to control workload execution order, and use explicit synchronization primitives to align dependent CPU and GPU processing.应用程序将渲染命令排入队列,使用显式调度依赖关系来控制工作负载执行顺序,并使用显式同步原语来对齐依赖 CPU 和 GPU 处理。

The impact of these changes is to significantly reduce the CPU overhead of the graphics drivers, at the expense of requiring the application to handle dependency management and synchronization.这些更改的影响是显着降低了图形驱动程序的 CPU 开销,但代价是要求应用程序处理依赖关系管理和同步。

Could someone help explain why asynchronous rendering model could reduce CPU overhead?有人可以帮助解释为什么异步渲染 model 可以减少 CPU 开销吗? Since in Vulkan you still have to track state yourself.由于在 Vulkan 中,您仍然需要自己跟踪 state。

Could someone help explain why asynchronous rendering model could reduce CPU overhead?有人可以帮助解释为什么异步渲染 model 可以减少 CPU 开销吗?

First of all, let's get back to the original statement you are referring to, emphasis mine:首先,让我们回到您所指的原始陈述,强调我的:

The impact of these changes is to significantly reduce the CPU overhead of the graphics drivers , [...]这些更改的影响是显着降低图形驱动程序的 CPU 开销,[...]

So the claim here is that the driver itself will need to consume less CPU, and it is easy to see as it can more directly forward your requests "as-is".所以这里的说法是驱动程序本身将需要消耗更少的 CPU,并且很容易看出它可以更直接地“按原样”转发您的请求。

However, one overall goal of a low-level rendering API like Vulkan is also a potentially reduced CPU overhead in general, not only in the driver.然而,像 Vulkan 这样的低级渲染 API 的一个总体目标也是总体上可能降低 CPU 开销,不仅在驱动程序中。

Consider the following example: You have a draw call which renders to a texture.考虑以下示例:您有一个渲染到纹理的绘制调用。 And then you have another draw call which samples from this texture.然后你有另一个从这个纹理中采样的绘图调用。

To get the implicit synchronization right, the driver has to track the usage of this texture, both as render target and as source for texture sampling operations.为了获得正确的隐式同步,驱动程序必须跟踪这个纹理的使用,作为渲染目标和纹理采样操作的源。

It doesn't know in advance if the next draw call will need any resources which are still to be written to in previous draw calls.它事先不知道下一个绘图调用是否需要任何仍要在先前的绘图调用中写入的资源。 It has to always track every possible such conflicts, no matter if they can occur in your application or not.它必须始终跟踪所有可能的此类冲突,无论它们是否会在您的应用程序中发生。 And it also must be extremely conservative in its decisions.它的决定也必须非常保守。 It might be possible that you have a texture bound for a framebuffer for a draw call, but you may know that with the actual uniform values you set for this shaders the texture is not modified.您可能有一个用于绘制调用的帧缓冲区的纹理绑定,但您可能知道使用您为此着色器设置的实际统一值,纹理不会被修改。 But the GPU driver can't know that.但是 GPU 驱动程序无法知道这一点。 If it can't rule - out with absolute certainty - that a resource is modified, it has to assume it is.如果它不能排除 - 绝对确定 - 资源被修改,它必须假设它是。

However, your application will more like know such details.但是,您的应用程序会更喜欢知道这些细节。 If you have several render passes, and the second pass will depend on the texture rendered to in the first, you can (and must) add proper synchronization primitives - but the GPU driver doesn't need to care why there is any synchronization necessary at all, and it doesn't need track any resource usage to find out - it can just do as it is told.如果您有多个渲染通道,并且第二个通道将取决于第一个渲染到的纹理,您可以(并且必须)添加适当的同步基元 - 但是 GPU 驱动程序不需要关心为什么在全部,并且它不需要跟踪任何资源使用来找出 - 它可以按照它的指示去做。 And your application also doesn't need to track it's own resource usage in many cases.在许多情况下,您的应用程序也不需要跟踪它自己的资源使用情况。 It is just inherent from the usage as you coded it that a synchronization might be required at some point.在您对其进行编码时,使用它只是固有的,在某些时候可能需要同步。 There might be still cases where you need to track your own resource usage to find out though, especially if you write some intermediate layer like some more high-level graphics library where you know less and less of the structure of the rendering - then you are getting into a position similar to what a GL driver has to do (unless you want to forward all the burden of synchronization on the users of your library, like Vulkan does).在某些情况下,您可能仍然需要跟踪自己的资源使用情况以找出答案,特别是如果您编写一些中间层,例如一些更高级的图形库,而您对渲染结构的了解越来越少 - 那么您就是进入 position 类似于 GL 驱动程序必须执行的操作(除非您想像 Vulkan 那样将所有同步负担转嫁给库的用户)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM