Compute Shaders

Monday to Friday, a day, 7 am Beijing time on time updates -

The first sections of this chapter describe the graphics pipeline in OpenGL (first part of this chapter describes the OpenGL graphics pipeline). However, OpenGL also includes the compute shader stage (OpenGL Compute Shader stage comprising the same), which can almost be thought of as a separate pipeline that runs indepdendently of the other graphics-oriented stages (at this stage a separate operation, not related to other graphics rendering pipeline stage have any contact). Compute shaders are a way of getting at the computational power possessed by the graphics processor in the system (Compute shader object is to allow the programmer to get computing power graphics card). Unlike the graphics-centric vertex, tessellation, geometry, and fragment shaders, compute shaders could be considered as a special, single- stage pipeline all on their own (Unlike other shader, compute shader may be considered as a separate module). each compute shader operates on a single unit of work known as a work item (each number to each compute shader According to the unit as a work object); these items are, in turn, collected together into small groups called local workgroups (those who work objects are organized into groups, called Local Working Group). Collections of these workgroups can be sent into OpenGL's compute pipeline to be processed (a large number of such local working groups can be sent to OpenGL is compute shader processing stage for processing). the compute shader does not have any fixed inputs or outputs besides a handful of built-in variables to tell the shader which item it is working on (except for some of its work to tell shader than some built-in control variable objects, this shader no data any fixed input and output). All processing performed by a compute shader is explicitly written to memory by the shader itself, rather than being consumed by a subsequent pipeline stage (any data is written to the memory of its own shader display are completed, rather than other shader, the output data will be treated as input behind the rendering stage). a very basic compute shader is shown in Listing 3.13 (Listing3.13 show A basic compute shader)

#version 450 core
layout (local_size_x = 32, local_size_y = 32) in;
void main(void)
{
// Do nothing
}
Listing 3.13: Simple do-nothing compute shader

Compute shaders are otherwise just like any other shader stage in OpenGL (compute shaders like other shader the same). To compile one, you create a shader object with the type GL_COMPUTE_SHADER, attach yourGLSL source code to it with glShaderSource (), compile it with glCompileShader (), and then link it into a program with glAttachShader () and glLinkProgram () (you need to create shader, and then attach it to a shader source, then compile it, link to become GPU program). The result is a program object with a compiled compute shader in it that can be launched to do work for you (compiled after, can be used for a large-scale parallel computing)

The shader in Listing 3.13 tells OpenGL that the size of the local workgroup will be 32 by 32 work items, but then proceeds to the code (Listing3.13 in OpenGL do nothing to tell the size of the local working group is 32x32, but the shader consequently did not do). to create a compute shader that actually does something useful, you need to know a bit more about OpenGL-so we'll revisit this topic later in the book (and in order to create a compute shader to do something, you must first learn about OpenGL, so we will come back to this topic in the following pages)

Translations of this day to get here, see you tomorrow, bye ~

Get the latest plot first time, please pay attention to the Eastern Han Dynasty academy and the heart of the public graphic No.

Han College, waiting for you to play Oh

Guess you like

Origin blog.51cto.com/battlefire/2423323