GPUFence

struct in UnityEngine.Rendering

切换到手册

描述

用于管理异步计算队列和图形队列上的任务之间的同步。

并不是所有平台都支持 GPU 栅栏。请参阅 SystemInfo.supportsGPUFence

一个 GPUFence 表示 GPU 处理过程中的一个点,位于某个特定计算着色器分发或绘制调用完成之后。可用于实现异步计算队列或图形队列上运行的任务之间的同步,方法是让一个或多个队列等待,直到通过给定栅栏。在使用异步计算时,这一点非常重要,因为提高 GPU 性能的关键在于确定哪些任务可在图形队列和异步计算队列上同时运行。

对于两个 GPU 任务分别写入和读取同一资源的情况,不需要使用 GPUFence 进行同步。Unity 会自动处理这些资源依赖关系。

应通过 Graphics.CreateGPUFenceCommandBuffer.CreateGPUFence 创建 GPUFence。尝试使用尚未通过这些函数之一创建的 GPUFence 会导致异常。

使用 GPUFence 有可能产生循环依赖,执行时会使 GPU 死锁。Unity 会在 Editor 中检测这类循环依赖,如果存在,会在调用 Graphics.CreateGPUFenceGraphics.WaitOnGPUFenceGraphics.ExecuteCommandBufferGraphics.ExecuteCommandBufferAsyncScriptableRenderContext.ExecuteCommandBufferScriptableRenderContext.ExecuteCommandBufferAsync 后引发异常。

另请参阅:SystemInfo.supportsGPUFenceGraphics.CreateGPUFenceGraphics.WaitOnGPUFenceCommandBuffer.CreateGPUFenceCommandBuffer.WaitOnGPUFenceGraphics.ExecuteCommandBufferGraphics.ExecuteCommandBufferAsyncScriptableRenderContext.ExecuteCommandBufferScriptableRenderContext.ExecuteCommandBufferAsync

变量

passed是否已通过 GPUFence?允许 CPU 确定 GPU 是否已通过其处理过程中由 GPUFence 表示的点。