最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

multithreading - Computer shader data sharing among threads, - Stack Overflow

matteradmin10PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far