OpenGL parallelism and shaders

Hello, I need to write a shader where, for a specific pixel, as a fragment comes in I will sort a struct stored in memory based on the value of depth. For the sake of argument, let’s assume I have an array of 10 entries per pixel of the struct containing {float depth; vec4 color}. As a new fragment comes in for a pixel I will use an insertion sort so I only keep the 10 front-most fragments and discard the rest. If OpenGL were sequential, this is a rather trivial operation: just program a proper insertion sort. However, my worry is that the same pixel may be processed in 2 different fragments simultaneously, so my insertion sort would fail because multiple threads would be accessing the same array. This leads me to 2 questions I’m hoping somebody has the insight to help out: 1) Can I be assured that, despite OpenGL’s parallelism, no two fragments for the same pixel will ever be processed simultaneously? In other words, can I be sure that if I’m working on a pixel, then parallelism means that on another thread OpenGL will not be working on the same pixel? 2) If the answer to (1) above is no – that is, there are no guarantees – is there a way that would allow me do this in a safe way? Thanks.

Published by CelleSports Mill

CelleSports is a Game development, News outlet, and Social Cell community. Build your cells or teams for any game and start communicating efficiently. Join us in building the number one eSport and gaming community in the World. Join Cell eSports

Leave a comment