{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/140","repository_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples","labels_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/140/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/140/comments","events_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/140/events","html_url":"https://github.com/Microsoft/DirectX-Graphics-Samples/issues/140","id":149083619,"number":140,"title":"GroupMemoryBarrier? GroupMemoryBarrierWithGroupSync?","user":{"login":"pengliu916","id":5034673,"avatar_url":"https://avatars.githubusercontent.com/u/5034673?v=3","gravatar_id":"","url":"https://api.github.com/users/pengliu916","html_url":"https://github.com/pengliu916","followers_url":"https://api.github.com/users/pengliu916/followers","following_url":"https://api.github.com/users/pengliu916/following{/other_user}","gists_url":"https://api.github.com/users/pengliu916/gists{/gist_id}","starred_url":"https://api.github.com/users/pengliu916/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pengliu916/subscriptions","organizations_url":"https://api.github.com/users/pengliu916/orgs","repos_url":"https://api.github.com/users/pengliu916/repos","events_url":"https://api.github.com/users/pengliu916/events{/privacy}","received_events_url":"https://api.github.com/users/pengliu916/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-04-18T08:41:55Z","updated_at":"2016-04-22T20:16:43Z","closed_at":"2016-04-18T22:41:49Z","body":"I have seen miniEngine use XXXMemoryBarrierWithGroupSync exclusively across all its cs where there need a 'sync'. But after looking through several of them I found most of them just need memory barrier, so it may be benificial (conceptually) to use XXXMemoryBarrier instead of XXXMemoryBarrierWithGroupSync.  Or are there some reasons to stick with the GroupSync version which I missed? Or am I misunderstand XXXMemoryBarrierWithGroupSync?\r\n\r\nThanks\r\nPeng"},"comment":{"url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/comments/213575193","html_url":"https://github.com/Microsoft/DirectX-Graphics-Samples/issues/140#issuecomment-213575193","issue_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/140","id":213575193,"user":{"login":"nikitablack","id":6390092,"avatar_url":"https://avatars.githubusercontent.com/u/6390092?v=3","gravatar_id":"","url":"https://api.github.com/users/nikitablack","html_url":"https://github.com/nikitablack","followers_url":"https://api.github.com/users/nikitablack/followers","following_url":"https://api.github.com/users/nikitablack/following{/other_user}","gists_url":"https://api.github.com/users/nikitablack/gists{/gist_id}","starred_url":"https://api.github.com/users/nikitablack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikitablack/subscriptions","organizations_url":"https://api.github.com/users/nikitablack/orgs","repos_url":"https://api.github.com/users/nikitablack/repos","events_url":"https://api.github.com/users/nikitablack/events{/privacy}","received_events_url":"https://api.github.com/users/nikitablack/received_events","type":"User","site_admin":false},"created_at":"2016-04-22T20:16:42Z","updated_at":"2016-04-22T20:16:42Z","body":"Sorry for asking in a closed issue but that's exactly the problem I'm trying to understand for a couple of weeks. I tried to compare gpu memory barriers with c++11 memory fences with different memory ordering (relaxed, seq_consistency, acquire/release) but I can't see the similarities. @stanard, after your great explanation memory barriers start to make some sense to me thought not absolutely clear. Can you please explain it one more with an example. Let's take this pseudocode:\r\n```\r\nshaderResource.store(42); // #1\r\nGroupMemoryBarrier(); // #2\r\nint i = shaderResource.load(); //#3\r\n```\r\nAm I correctly understanding that if `thread1` and `thread2` (a hypothetical group made of 2 threads) are from different waves than this flow is possible?\r\n\r\n1. `thread1` writes to the resource (`#1`). Since `thread2` is from another wave it doesn't go with `thread1` in a lockstep and it doing nothing for now (I mean it's possible to do nothing).\r\n2. `thread1` reaches barrier (`#2`). No more threads in a group accessed memory untill this moment - only `thread1`. That means that this barrier can be passed for this thread. `thread2` still doing nothing.\r\n3. `thread1` reads from the memory (`#3`). Now, at the same time, `thread2` starts to write (`#1`). Ans it's a classical race condition.\r\n\r\nIs my understanding correct?"}}