Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vulkan WaW hazard & memory barrier

Vulkan spec states:

Write-after-read hazards can be solved with just an execution dependency, but read-after-write and write-after-write hazards need appropriate memory dependencies to be included between them.

I thought that WaW can be solved with only execution barrier as well. Why do we need a memory barrier to solve WaW hazard if we're not going to read data?

like image 365
YaaZ Avatar asked Jul 06 '19 10:07

YaaZ


1 Answers

Execution dependencies ensure the ordering of operations. Memory dependencies ensure the visibility of memory operations. These aren't the same thing.

In order for a write-after-write to work correctly, the second write has to happen after the first write, but also you have to make sure that the first write is visible to the operation doing the second write. Otherwise, it's possible for the second write to be overwritten by the first, even if the second write happened after the first.

If you want a more hardware-based explanation, consider what happens if the first write uses one cache, and the second write uses a separate cache from the first (GPUs have a lot of caches). Execution dependencies don't affect caches. So the second write's cache may write its data before the first write's cache does, which means that the first write will eventually overwrite the second.

Memory dependencies force data out of caches, thus ensuring that when the second write takes place, there isn't a write sitting around in a cache somewhere.

like image 99
Nicol Bolas Avatar answered Sep 20 '22 12:09

Nicol Bolas