I know this technically isn't supported (and as far as I can tell it's undefined behavior) but is it really a fatally horrible thing to sample from a texture which is also being written to?
I ask because I need to read from a depth texture which I also need to write to, if I can't do this it means I will have to copy the depth texture and if it isn't that big of a deal I don't see the harm in simply copying it?
Thanks for any help!
Yes, it's fatal and triggers undefined behaviour. Just make a copy and read from the copy.
The explanation is simple. Since fragments are processed in parallel in a unspecified order, you might be reading from already written texels or original value texels, and there is no way of knowing what you are reading. Making a copy and reading from it ensures that you will read the correct values.