A method of operating a graphic processing unit,GPU, comprising: receiving, by the GPU from a shader compiler, a shader program comprising a preamble code block and a main shader code block, the preamble code block comprising threads which produce one or more results that are the same each time the threads are executed during execution of the shader program; executing, by the GPU, using a plurality of warps of execution of the shader program, multiple instances of the shader program, wherein executing each of the multiple instances of the shader program comprises: for a first warp, determining whether or not a first flag indicates that the execution of the preamble code block has started in any other warp; responsive to the first flag indicating that execution of the preamble code block has not started, setting the first flag to indicate that execution of the preamble code block has started; executing the preamble code block to produce the one or more results; and storing the one or more results of the preamble code block; responsive to the first flag indicating that execution of the preamble code block has started, not executing the preamble code block; for each warp, determining whether or not a second flag indicates that execution of the preamble code block is complete; responsive to the second flag indicating that execution of the preamble code block is not complete, waiting for the second flag to indicate that execution of the preamble code block is complete; and responsive to the second flag indicating that execution of the preamble code block is complete, executing, the main shader code block using the one or more results produced by executing the preamble code block. receiving, by the GPU from a shader compiler, a shader program comprising a preamble code block and a main shader code block, the preamble code block comprising threads which produce one or more results that are the same each time the threads are executed during execution of the shader program; executing, by the GPU, using a plurality of warps of execution of the shader program, multiple instances of the shader program, wherein executing each of the multiple instances of the shader program comprises: for a first warp, determining whether or not a first flag indicates that the execution of the preamble code block has started in any other warp; responsive to the first flag indicating that execution of the preamble code block has not started, setting the first flag to indicate that execution of the preamble code block has started; executing the preamble code block to produce the one or more results; for a first warp, determining whether or not a first flag indicates that the execution of the preamble code block has started in any other warp; responsive to the first flag indicating that execution of the preamble code block has not started, setting the first flag to indicate that execution of the preamble code block has started; executing the preamble code block to produce the one or more results; and storing the one or more results of the preamble code block; responsive to the first flag indicating that execution of the preamble code block has started, not executing the preamble code block; for each warp, determining whether or not a second flag indicates that execution of the preamble code block is complete; responsive to the second flag indicating that execution of the preamble code block is not complete, waiting for the second flag to indicate that execution of the preamble code block is complete; and responsive to the second flag indicating that execution of the preamble code block is complete, executing, the main shader code block using the one or more results produced by executing the preamble code block. responsive to the first flag indicating that execution of the preamble code block has started, not executing the preamble code block; for each warp, determining whether or not a second flag indicates that execution of the preamble code block is complete; responsive to the second flag indicating that execution of the preamble code block is not complete, waiting for the second flag to indicate that execution of the preamble code block is complete; and responsive to the second flag indicating that execution of the preamble code block is complete, executing, the main shader code block using the one or more results produced by executing the preamble code block.