Fragment Shader Ordering with OpenGL 4.2

This Windows OpenGL 4.2 Sample was written by John Hartwig - Software Engineer at Intel Corporation.

Introduction

Fragment Shader Ordering is a graphics extension that Intel has implemented for OpenGL 4.2 to be used with 4th Generation Intel® Core™ processors with Iris™, Iris™ Pro and Intel® HD graphics. Fragment Shader Ordering guarantees ordered access to texture and buffer objects when performing random access read and write operations from a fragment shader. This sample demonstrates how to use Fragment Shader Ordering to perform programmable blending in a pixel shader without using fixed function blending.

Fragment Shader Ordering

Fragment Shader Ordering provides a mechanism for controlling access to memory in the fragment shader. When invoked, all reads and writes to the specified resources from a given pixel location will be performed in submit order. It achieves this by blocking execution until invocations from all previous primitives that map to the same xy window coordinate and same sample have finished execution.

The extension requires the use of shader image load store to perform random access read/writes. To use fragment shader ordering within your fragment shader, call the function beginFragmentShaderOrderingINTEL(). Ordering will be guaranteed for the remainder of the fragment shader invocation. It should be noted that reads and writes to a memory location from outside fragment locations do not have guaranteed ordering. Usual multithreading performance rules apply and for optimal performance it’s best to put off blocking the shader execution until the last possible moment and to minimize use.

GLSL Code Sample:

	layout(rgba8) uniform image2D image; 

         int PSMainRGBE( ) 
	        { 
	        ….shader initialization 

             if(FragmentShaderOrdering.r == 0) 
	            { 
	                ….Calculate color with no ordering performed 
	            } else { 
	                beginFragmentShaderOrderingINTEL(); 
	                baseColor = imageLoad(image, coords); 
	                ….Calculate color. Order is guaranteed 
	                imageStore(image, coords, color); 
	            } 
	            ….no ordering guarantees as branch might not be taken 
	        } 

Sample Implementation

This sample first renders all opaque geometry. A second pass binds the render target to an image2d object and uses Fragment Shader Ordering to perform programmable blending of all transparent geometry. A final pass renders this image as a full screen sprite.

Unlike the corresponding DirectX implementation which uses a 32bit unit buffer to store a packed RGBE surface, this sample uses the more common floating point RGBA8 format as OpenGL’s shader image load store doesn’t have the same format restrictions Unordered Access Views do.

Number keys 1-3 allow easy toggling through fixed camera angles.

For Additional References

Initial DirectX sample and article:

https://software.intel.com/en-us/blogs/2013/03/27/programmable-blend-with-pixel-shader-ordering

Fragment Shader Ordering extension in OpenGL spec:

https://www.opengl.org/registry/specs/INTEL/fragment_shader_ordering.txt

Shader Image Load Store extension in OpenGL spec:

https://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt

 
06-02-2014
06-02-2014
Graphics Tech Samples
 
 
https://software.intel.com/sites/default/files/managed/2c/6b/FragShaderOrdering.png
Fragment Shader Ordering guarantees ordered access to texture and buffer objects when performing random access read and write operations from a fragment shader.
Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.