Image Qualifiers and Barriers

The techniques outlined above work well when compilers don’t perform overly aggressive optimizations on your shaders. However, under certain circumstances, the compiler might change the order or frequency of image loads or stores, and may eliminate them altogether if it believes they are redundant. For example, consider the simple example loop in Example 11.15.

Example 11.15. Basic Spin-Loop Waiting on Memory

#version 420 core// Image that we’ll read from in the looplayout (r32ui} uniform uimageBuffer my_image;void waitForImageToBeNonZero(){    uint val;    do     {        // (Re-)read from the image at a fixed location.        val = imageLoad(my_image, 0).x;        // Loop until the ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.