Aqoole_Hateenaの技術日記

vulkan+raytraceで色々描いてます

synchronizationとdependenciesについて

Synchronization

仕様書にはこのように書かれている。Vulkan® 1.2.202 - A Specification (with all registered Vulkan extensions)

Synchronization of access to resources is primarily the responsibility of the application in Vulkan. The order of execution of commands with respect to the host and other commands on the device has few implicit guarantees, and needs to be explicitly specified. Memory caches and other optimizations are also explicitly managed, requiring that the flow of data through the system is largely under application control.

Resourcesのアクセスの同期について、Vulkanではその責任のほとんどをアプリ実装者が担う。ホストメモリと他のデバイスコマンドについては、多少の暗黙の保証はあるが、大部分は明示的に定義される必要がある。

Whilst some implicit guarantees exist between commands, five explicit synchronization mechanisms are exposed by Vulkan:

とのことで、明示的な同期の仕方は5つある。

Fences
Fences can be used to communicate to the host that execution of some task on the device has completed.

Semaphores
Semaphores can be used to control resource access across multiple queues.

Events
Events provide a fine-grained synchronization primitive which can be signaled either within a command buffer or by the host, and can be waited upon within a command buffer or queried on the host.

Pipeline Barriers
Pipeline barriers also provide synchronization control within a command buffer, but at a single point, rather than with separate signal and wait operations.

Render Passes
Render passes provide a useful synchronization framework for most rendering tasks, built upon the concepts in this chapter. Many cases that would otherwise need an application to use other synchronization primitives can be expressed more efficiently as part of a render pass.

fencesはホストに通信するときに使用され、何かデバイス上のタスクが完了しているかどうかを通信するときに使用される。
semaphoresは複数のqueues間のresource accessをコントロールするときに使用する。
eventsはコマンドバッファー内またはホストによって通知され、コマンドバッファー内で待機したり、ホストで照会したりできる、きめ細かいプリミティブな同期を提供する。
pipeline barriersはevents同様にコマンドバッファー内の同期を提供するが、別個のシグナルや待機操作ではなく、シングルポイントで行われる。
render passは、他の同期と併せてフレームワークを構築できる、とのこと。
Vulkan Tutorialで用いる同期の方法は主にfencesとsemaphoresだと思っているが、Render passのレベルで効率的なフレームワークがつくれる、らしい。

実行とメモリ依存

Vulkan® 1.2.202 - A Specification (with all registered Vulkan extensions)
オペレーションとは、ホストやデバイス上などで実行される任意の量のworksである。
同期コマンドは、同時に実行されるオペレーションの実行の依存性とメモリの依存性を明に定義する。

実行の依存性とは、2つのオペレーションがあった場合に、先のオペレーションが完了してから別のオペレーションを開始させることを保証する。

メモリの依存性とは、availability operationsとvisibility operationsのことで、
availability operationsにより、特定のメモリ書き込みにより生成された値が、将来のアクセスのためにメモリドメインでavailableになる。
memory domain operationsにより、source domainで使用可能な書き込みがdestination側で使用可能になる。(host側で書き込んだものがdevice側で使用可能になる感じ)
visibility operationsにより、メモリドメインの値が特定のメモリアクセスから見れるようになる。