admin管理员组

文章数量:1391991

I have a compute shader in Vulkan, where I launch N threads with eight sub-threads each. Each subgroup of 8 threads share an eight element 'location' array. Each of the sub-threads calculate a number from 1 to 8 where there can be duplicates.The sub threads do no need to be ordered.

A sub-thread only needs to do work if it has calculated a number which is not a duplicate. So, each thread must read the location array to see if its number has already been processed. If its number is not in the array then it writes its number to the array and does work. Another thread comes along with the same number, reads the array, and sees that its number has been processed, and so does nothing.

I need the 'location' array to be shared and thread safe.

I tried to use subgroups to do this but it is not clear how the subgroup threads share writable data. Can I use broadcast? If so any ideas how? I've tried atomics and memory barriers without success.

本文标签: multithreadingComputer shader data sharing among threads Stack Overflow