1 / 22

OpenGL ES 3.0 & 3.1 Shading Language

An Overview of the OpenGL Shading Language (GLSL). OpenGL ES 3.0 & 3.1 Shading Language. Presenters: Ron Fosner & Rudy Cazabón. Agenda. Difference between “classic” and “modern” OpenGL OpenGL Shading Language (GLSL) Review of syntax and semantics Views of the Processing Pipeline

asher
Download Presentation

OpenGL ES 3.0 & 3.1 Shading Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Overview of the OpenGL Shading Language (GLSL) OpenGL ES 3.0 & 3.1 Shading Language Presenters: Ron Fosner & Rudy Cazabón

  2. Agenda • Difference between “classic” and “modern” OpenGL • OpenGL Shading Language (GLSL) • Review of syntax and semantics • Views of the Processing Pipeline • Review of Shader Types Within Processing Pipeline

  3. Difference between “classic” and “modern” OpenGL “Classic” OpenGL defines fixed-function operations – e.g. transform and lighting – “Modern” OpenGL supersedes ALL stages of the graphics pipeline with programmable shaders From OGL ES 2.0 onwards ALL applications must use shaders for their graphics processing At minimum a vertex shader for T&L a fragment shader to paint to framebuffer

  4. GLSL – Variable Types • Strongly typed language; strict rules on type conversions

  5. Example: Manipulation of Vector and Matrix Fields vec3 → 3-element struct mat2, mat3, mat4→ 2x2, 3x3, 4x4 mat vec4 → 4-element struct

  6. Variables Declaration Syntax and Keywords • Every shader has its execution entry-point in main() • Keywords in/outdef’ns data that OpenGL passes into/out-of shaders from/to the pipeline • Keyword uniform does not change within the pipeline – it is updated by application #version 300 es in vec4 v_Position; in vec4 v_Color; out vec4 o_Color; uniform mat4 ModelViewProjectionMatrix; void main() { o_Color = v_Color; gl_Position = ModelViewProjectionMatrix * v_Position; } Into shader Out of shader

  7. 10,000ft Simplified Model GPU Data Flow Application Framebuffer fragments vertices vertices Rasterizer Fragment Processing Vertex Processing Vertex Shader Fragment Shader Minimum Required

  8. View of All Stages of the Processing Pipeline 1 Skip Draw Fragment Draw Processing Primitive Rasterization Pixel 3 4 5 Draw Pixel Processing Geometry Fragment 2 Vertex Processing No Write Vertex Tessellation Vertex Compute (OGLES 3.1) Primitive Processing Image Fragment Processing Stream Tessellation Control Tesselator Xform Feedback Processing Tessellation Evaluation No primitive generated No stream generated Rasterization discard Fail test discard

  9. OpenGL ES 3.0 and 3.1 Shading Language “Cookbook Approach” • Create Shader Programs • Create buffer objects • Load data into the buffers • “Connect” data locations with shadervariables • Make shader program current • Update shader uniforms (application/host-side data) • Set attribute inputs • Render

  10. OpenGL ES 3.0 and 3.1 Shading Language Applying the Shaders Create Program • Shaders need to be compiled • Linked to form an executable shader program • OpenGL provides the compiler and linker glCreateProgram() Create Shader glCreateShader() These steps are repeated for each shader program type Load Shader Source glShaderSource() Compile Shader glCompileShader() Attach shader to program glAttachShader() Compile ALL shaders THEN link them into one program Link shader program glLinkProgram() Use shader program glUseProgram()

  11. Vertex Shader • Basic uses of vertex shaders • Transformations – e.g. translate, rotate, scale • Lighting – e.g. per-vertex lighting, cartoon shading • Moving vertex positions – e.g. skinning, height fields • Its output must be a position in clip coordinates to the rasterizer

  12. Tessellation Shaders • Two (2) conjoined processing steps in a tessellation shader • Tessellation control shader (TCS) • Controls how much tessellation a particular control shape surface (patch) is to receive and defines a size • Tessellation evaluation shader (TES) • Consumes the results of the TCS and computes interpolated per-vertex data from them, e.g. positions, texture coords, and normals N.b. Only available in OpenGL ES 3.1 by way of hardware vendor EXTs

  13. Geometry Shaders • Geometry Shaders precede the primitive assembly and fragment/pixel shaders • Geometry shader invocations take a single Primitive as input and may output zero or more primitives. • Usages for geometry shaders • Layered rendering: taking one primitive and rendering it to multiple images without having to change bound rendertargets and so forth • Transform feedback: employed for doing computational tasks on the GPU • Instancing - Major win of geometry shaders • allows multiple invocations to operate over the same input primitive • Enables layered rendering easier to implement and possibly faster performing, as each layer's primitive(s) can be computed by a separate GS instance • N.b. Only available in OpenGL ES 3.1 by way of hardware vendor EXTs

  14. Fragment Shaders • Fragment shader is the pipeline stage after the primitive rasterizer • A fragment shader is executed for each “potential” pixel • fragments still need to pass several tests before making it to the framebuffer • Common outputs of fragment shaders • RGB colors, depth values, stencil values TESTs • Effects that can be done with fragment shaders • Per-fragment lighting • Bump Mapping • Use a “sampler” inside to enable environment (reflection) maps

  15. Compute ShadersCommon Usages

  16. Use-Case – Image Processing • Gaussian blurs with large kernels • Common in photo processing apps such as Photoshop • Expensive, particular for large neighborhoods • Compute Shaders ideal for such image processing operations • Fast shared memory and hundreds executing threads • No way to perform these in OpenGL ES prior at these processing rates • Results immediately available in OpenGL for display

  17. 20 total items to compute Compute ShadersWorkgroups – local, global • Work item fundamental unit of work inside a work-group; executes once per invocation • Workgroup collection of work-items launched simultaneously • Local workgroup – collection of workgroups that have topological computational neighbors • Global workgroup – full aggregate of (local) workgroups Computational neighbors 4 work-items 5 Work Groups

  18. Compute Topology #version 300 es // local input layout qualifier layout (local_size_x = 4) in; • The invocation space for compute shaders can be 1-D (previous slide), 2-D, or 3-D • The size and dimensionality of a workgroup is defined in compute shader source-code via input layout qualifier • Whenever an input layout qualifier is omitted it automatically defaults to one (1) #version 300 es // local input layout qualifier Layout (local_size_x = 4, local_size_y = 4) in; #version 300 es // local input layout qualifier Layout (local_size_x = 4, local_size_y = 4, Local_size_z = 4) in;

  19. Shared State Variables and Parallel Compute Model • Communication Achieved via GPU-Internal Shared Memory • Use of the “shared”keyword signals the driver to place the annotated data in special storage that is visible to all compute shader invocations within the same local workgroup • Parallelism Achieved via GPU-Internal HW Threading • Each thread can share data with other members of the workgroup via shared memory (variables) • Each thread can issue memory and control barriers to synchronise with other members of the workgroup • Data cannot be shared between workgroups, unless via images, buffer objects or atomic counters • Each thread can uniquely identify itself within a workgroup and globally with builtin variables. This is the only method for a thread to determine where to get its input and where to write its output Compute Thread 1 Shared Variables Workgroup 1 ...?... Compute Thread N Compute Thread 1 Shared Variables Workgroup M ...?... Compute Thread N

  20. Back up slides

  21. OpenGL ES 3.0 and 3.1 Shading10K-Foot View of the Processing Pipeline Primitive Assembly?

  22. Vertex Stage

More Related