SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond


Published on

Location: Conference Hall K, Singapore EXPO
Date: Thursday, November 29, 2012
Time: 11:00 AM - 11:50 PM
Presenter: Mark Kilgard (Principal Software Engineer, NVIDIA, Austin, Texas)

Abstract: Attend this session to get the most out of OpenGL on NVIDIA Quadro and GeForce GPUs. Learn about the new features in OpenGL 4.3, particularly Compute Shaders. Other topics include bindless graphics; Linux improvements; and how to best use the modern OpenGL graphics pipeline. Learn how your application can benefit from NVIDIA's leadership driving OpenGL as a cross-platform, open industry standard.

Topic Areas: Computer Graphics; Development Tools & Libraries; Visualization; Image and Video Processing

Level: Intermediate

Published in: Technology
1 Comment
  • poor quality.....need more updated.......
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • One way to view the OpenGL offerings from NVIDIA is as a tool to enable awesome visual applications to be developed through a comprehensive stack of software solutions. We offer: Cg: A shading language and effects system to develop rendering effects and techniques, and deploy them on various platforms and APIs, including OpenGL. Scenix: OpenGL based professional scene graph used in many markets today. Automotive styling, visualization, simulation, broadcast graphics, and more. Applications can quickly add features such as stereo, SDI, 30-bit color, scene distribution and interactive ray tracing Optix: Is an interactive ray-tracing engine built on top of CUDA and OpenGL. Hybrid rendering, mixing of traditional graphics rendering and ray tracing, are also enabled. OptiX integrates with SceniX. With Optix, you accelerate an existing renderer, or build a new one yourself. Complex: Maintains interactivity for large scenes as they exceed the limits of a single GPU, allowing massive data sets to be explored, using multiple GPUs in a system. The CompleX engine can be adopted by any product using OpenGL, and can be enabled immediately by an application using SceniX Parallel Nsight is an advanced debugger and analyzer fully integrated with Visual Studio. It enables you to better see what is going on with your OpenGL, CUDA, Direct3D, DirectCompute or OpenCL application.
  • OpenGL is the only Cross Platform 3D API. Every major Operating System provides a version or flavor of OpenGL. Windows, Mac OS, iOS, Linux and Android.
  • After Mark’s deep-dive, I’ll pull you back up into the higher level view of where OpenGL fits in as the 3D graphics API.
  • OpenGL is a desktop API, as you’ve seen by now. OpenGL ES is the sister API for mobile and embedded devices. By keeping both APIs closely aligned, content can flow from there up into OpenGL enabled platforms and back down to OpenGL ES enabled platforms. WebGL was announced last year. It provides JavaScript bindings to OpenGL ES and provides plug-in less 3D graphics in a web browser. WebGL gives you access to the GPU in the system inside of a browser. Beta implementations of WebGL are already available from Mozilla, Google and Opera. For NVIDIA this means we will support and enhance OpenGL and WebGL on GeForce and OpenGL ES and WebGL on Tegra for the mobile market.
  • Internal format query 2 allows an application to find out actual supported limits for most texture parameters. Examples: Query if a particular internal format is actually supported, if a texture is renderable, or can be used to texture from in a vertex/tess/geom/fragment/compute shader, etc. Support is indicated as either fully supported, not support, or there are caveats. If there is a caveat, a debug output message will be generated (if enabled). Provides the ability to directly copy pixels between textures and renderbuffers without requiring the use of an intermediate buffer object or rendering using a framebuffer object. Immutable storage for all types of textures besides multisample and buffer textures was introduced by ARB_texture_storage. For completeness, this extension introduces immutable storage for multisampled textures.
  • Allows applications to invalidate all or some of the contents of textures, buffers, and framebuffers to permit implementations to perform optimizations that avoid any extra work needed to keep resources up to date. For example, one might invalidate the contents of a multisample framebuffer after a downsample operation since the individual samples may not be used again. Provides the ability to fill the contents of a buffer object's data store with a constant value, like C's memset() function. The only way to do this previously was to copy from a fully initialized scratch buffer via glBufferSubData(). Provides the ability to have multiple generic vertex attribute arrays to share a single data store, splitting the vertex attribute array state. In this model, there is a collection of "buffer binding" state that include strides (for interleaved arrays). There is also a collection of "vertex attribute" state, that includes the format of the attribute and the location of the data relative to one of the bindings. When switching between two sets of interleaved arrays with the same format but different buffer objects, it's only necessary to change a single piece of binding state.
  • Provide generic APIs allowing applications to enumerate active variables and interface blocks, which will be used as the sole enumeration API for ARB_shader_storage_buffer_object. Provides some new enumeration rules to avoid enumerating every array element/member in arrays of structures for ARB_shader_storage_buffer_object. Consolidates and obsoletes existing APIs such as GetActiveUniforms, GetActiveAttrib. Provides new support for enumerating inputs and outputs of separate shader objects. Provides missing enumeration support for fragment shader outputs.
  • For applications using the "robustness" APIs, specifies additional constraints on buffer object accesses. When accessing outside the bounds of a buffer object, the extension promises that crashes should not occur and that reads/writes access nothing other than the contents of the buffer object being accessed. Adds a new layout qualifier allowing shaders to specify an explicit locations for default uniforms. This allows applications to set their values without first having to call GetUniformLocation(). Removes the restriction forbidding multi-dimensional arrays in GLSL. As arrays are first-class objects in GLSL, a declaration like "float f[4][3]" is considered to be an array of four objects, each of which is an array of three floats. Useful for shared variables in compute shaders, which arrange threads into multi-dimensional groups and may naturally want to access shared values for a specific thread.
  • Adaptive Scalable Texture Compression (ASTC) is a new texture compression technology that offers unprecendented flexibility, while producing better or comparable results than existing texture compressions at all bit rates. It includes support for 2D and 3D textures, with low and high dynamic range, at bitrates from below 1 bit/pixel up to 8 bits/pixel in fine steps. The goal of this extension is to support the 2D, LDR-only profile of the ASTC texture compression specification. Provides a new texture parameter allowing textures with an sRGB internal format to be decoded as though it had a non-sRGB format with the same texel values.
  • NVIDIA FXAA technology harnesses the power of the GPU’s CUDA Cores to reduce visible aliasing. FXAA is a pixel shader-based image filter that is applied along with other post processing steps like motion blur and bloom. For game engines making use of deferred shading, FXAA provides a performance and memory advantage over deferred shading with multi-sample anti-aliasing (MSAA). FXAA targets edge aliasing and also aliasing on single-pixel and sub-pixel sized features, which tend to flicker as they move from frame to frame. FXAA reduces the visual contrast of these features so that they are less jarring to the eye. Note that FXAA cannot completely solve the sub-pixel aliasing problem, but it does substantially reduce it. The overall effect is smoother visual quality. FXAA reduces but does not completely eliminate shader aliasing. FXAA’s chief advantage over traditional MSAA is higher performance. In many cases, FXAA can be applied at a cost of 1ms per frame or less, resulting in frame rates that are often 2x higher than 4xMSAA with comparable image quality.
  • Finally, Siggraph is where we introduce 3D Vision Pro as well. Again, come to the booth for more information. Now on to OpenGL!
  • Before Kepler, in order to make a texture available for the GPU to reference it had to be assigned a “slot” in a fixed-size binding table. The number of slots in that table ultimately limits how many unique textures a shader can read from at run time. On Kepler, no such additional setup is necessary - shader can reference textures in memory directly and there is no need to go through the binding tables anymore. This effectively eliminates any limits on the number of unique textures it can use to render a scene.
  • Bindless textures reduce CPU work and provide more efficient access for the GPU
  • In advanced rendering apps such as raytracing it is impossible to know in advance which textures a given ray may hit – thus it is impossible to pre-“bind” them. Bindless model solves this problem by allowing shader reference textures directly
  • SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond

    1. 1. OpenGL 4.3 and Beyond Mark Kilgard
    2. 2. Talk DetailsLocation: Conference Hall K, Singapore EXPODate: Thursday, November 29, 2012Time: 11:00 AM - 11:50 PMMark Kilgard (Principal Software Engineer, NVIDIA, Austin, Texas)Abstract: Attend this session to get the most out of OpenGL on NVIDIA Quadro andGeForce GPUs. Learn about the new features in OpenGL 4.3, particularly ComputeShaders. Other topics include bindless graphics; Linux improvements; and how to bestuse the modern OpenGL graphics pipeline. Learn how your application can benefit fromNVIDIAs leadership driving OpenGL as a cross-platform, open industry standard.Topic Areas: Computer Graphics; Development Tools & Libraries; Visualization; Imageand Video ProcessingLevel: Intermediate
    3. 3. Mark Kilgard Principal System Software Engineer OpenGL driver and API evolution Cg (“C for graphics”) shading language GPU-accelerated path rendering OpenGL Utility Toolkit (GLUT) implementer Author of OpenGL for the X Window System Co-author of Cg Tutorial Worked on OpenGL for 20+ years
    4. 4. Outline State of OpenGL & OpenGL’s importance to NVIDIA Compute Shaders explored Other stuff in OpenGL 4.3 Further NVIDIA OpenGL Work How to exploit OpenGL’s modern graphics pipeline
    5. 5. State of OpenGL &OpenGL’s importance to NVIDIA
    6. 6. OpenGL Standard is 20 Years and Strong
    7. 7. Think back to Computing in 1992Programming Languages ANSI C (C 89) was just 3 years old C++ still implemented as a front-end to C OpenGL in 1992 provided FORTRAN and Pascal bindingsOne year before NCSA Mosaic web browser first written Now WebGL standard in almost every browserWindows version Windows 3.1 ships! NT 3.1 still a year awayEntertainment Great video game graphics? Mortal Kombat? Top grossing movie (Aladdin) was animated Back when animated movies were still hand-drawn
    8. 8. 20 Years Ago: Enter OpenGL
    9. 9. 20 Years in Print
    10. 10. Then and Now 2012 OpenGL 4.3: Real-time Global IlluminationOpenGL 1.0: Per-vertex lighting 1992 [Crassin]
    11. 11. Big News 4.3 OpenGL 4.3 announced at SIGGRAPH Los Angeles August 6, 2012 Moments later… NVIDIA beta OpenGL 4.3 driver on the web Now fully WHQL’ed production driver with OpenGL 4.3 now shipping OpenGL 4.3 brings substantial new features Compute Shaders! OpenGL Shading Language (GLSL) updates (multi-dimensional arrays, etc.) New texture functionality (stencil texturing, more queries)MarqueeFeature New buffer functionality (clear buffers, invalidate buffers, etc.) More Direct3D-isms (texture views, parity with DirectX compute shaders)
    12. 12. NVIDIA’s OpenGL Leverage GeForce Programmable Graphics (GLSL, Cg) Debugging with Tegra Parallel Nsight Quadro OptiX
    13. 13. Single 3D API for Every Platform Windows OS X Linux Android Solaris FreeBSD
    14. 14. OpenGL 3D Graphics API • cross-platform • most functional • peak performance • open standard • inter-operable • well specified & documented • 20 years of compatibility
    15. 15. OpenGL Spawns Closely Related Standards Congratulations: WebGL officially approved, February 2012 “The web is now 3D enabled”
    16. 16. Accelerating OpenGL Innovation 2004 2005 2006 2007 2008 2009 2010 2011 2012 DirectX 10.0 DirectX 10.1 DirectX 11 DirectX 9.0c OpenGL 3.1 OpenGL 3.3 +OpenGL 2.0 OpenGL 2.1 OpenGL 3.0 OpenGL 3.2 OpenGL 4.0 OpenGL 4.3 Now with OpenGL 4.1 compute • OpenGL has fast innovation + standardization shaders! - Pace is 7 new spec versions in four years - Actual implementations following specifications closely OpenGL 4.2 • OpenGL 4.3 is a superset of DirectX 11 functionality - While retaining backwards compatibility
    17. 17. OpenGL Today – DirectX 11 Superset Buffer and Event Interop First-class graphics + compute solution OpenGL 4.3 = graphics + compute shaders NVIDIA still has existing inter-op with CUDA / OpenCL Shaders can be saved to and loaded from binary blobs Ability to query a binary shader, and save it for reuse later Flow of content between desktop and mobile Brings ES 2.0 and 3.0 API and capabilities to desktop WebGL bridging desktop and mobile Cross platform Mac, Windows, Linux, Android, Solaris, FreeBSD Result of being an open standard
    18. 18. Increasing Functional Scope of OpenGL First-class Compute Shaders 4.3 Tessellation Features 4.0 Geometry Shaders 3.X Vertex and Fragment Shaders 2.X Fixed Function 1.XArguably, OpenGL 4.3is a 5.0 worthy feature-set!
    19. 19. Classic OpenGL State Machine From 1991-2007 * vertex & fragment processing got programmable 2001 & 2003 [source: GL 1.0 specification, 1992]
    20. 20. Complicated from inception
    21. 21. OpenGL 3.0 Conceptual Processing Flow (2008) uniform/ primitive topology, parameters transformed Legend vertex data Geometric primitive buffer objects Vertex Vertex assembly & vertices assembly primitive processing batch transformed processing programmable pixels operations type, vertex fragments vertex data attributes point, line, and polygon fixed-function filtered texels geometry operations Transform texture fragments buffer data vertex transform feedback fetches buffer objects feedback pixels in framebuffer object textures buffer objects stenciling, depth testing, primitive batch type, vertex blending, accumulation vertex indices, texture vertex attributes texture fetches buffer buffer data, objects Texture Fragment Raster unmap Framebuffer mapping fragment processing operations buffer texture Command Buffer fetches parser store pixel map buffer, pack get buffer buffer data objects image and bitmap texture fragments pixel image pixel image or unpack Pixel specification texture image buffer specification objects packing pixels to pack image OpenGL 3.0 rectangles, bitmaps Image Pixel Pixel primitive unpacking unpacked processing pixels processing copy pixels, copy texture image
    22. 22. Control point Patch Patch tessellation Patch evaluation (2010) assembly & processing transformed transformed generation transformed processing control points processing transformed patch patch, bivariatetessellation patch control patch domain points patch topology, evaluated patch vertextexture Legendfetches primitive topology, patch data transformed Geometric primitive Vertex Vertex vertex data programmable vertices assembly & operations assembly primitive processing pixels batch transformed processing fragments type, vertex fixed-function attributes point, line, operations filtered texels vertex data geometry and polygon buffer data vertex Transform texture fragments compute buffer transform feedback fetches objects feedback pixels in framebuffer object textures buffer primitive batch type, objects stenciling, depth testing, vertex vertex indices, texture blending, accumulation vertex attributes texture fetches buffer buffer data, objects Texture Fragment Raster unmap Framebuffer mapping fragment processing operations buffer pixel texture Command Buffer pack fetches parser store buffer map buffer, get buffer objects texture image and bitmap data pixel fragments image pixel image or unpack Pixel specification texture image packing specification buffer objects pixels to pack image OpenGL 4.0 rectangles, Image Pixel Pixel bitmaps primitive copy pixels, unpacking unpacked processing pixels processing copy texture image
    23. 23. Control point Patch Patch tessellation Patch evaluation (2012) assembly & processing transformed transformed generation transformed processing control points processing transformed patch patch, bivariatetessellation patch control patch domain points patch topology, evaluated patch vertextexture Legendfetches primitive topology, patch data transformed Geometric primitive Vertex Vertex vertex data programmable vertices assembly & operations assembly primitive processing pixels batch transformed processing fragments type, vertex fixed-function attributes point, line, operations filtered texels vertex data geometry and polygon buffer data vertex Transform texture fragments compute buffer transform feedback fetches objects feedback pixels in framebuffer object textures buffer primitive batch type, objects stenciling, depth testing, vertex vertex indices, texture blending, accumulation vertex attributes texture fetches buffer buffer data, objects Texture Fragment Raster unmap Framebuffer mapping fragment processing operations Command buffer Buffer texture fetches parser store pixel pack map buffer, get buffer buffer objects texture image and bitmap data Compute pixel fragments image pixel image or unpack Pixel processing specification texture image buffer packing specification objects pixels to pack image OpenGL 4.3 rectangles, Image Pixel Pixel bitmaps primitive copy pixels, unpacking unpacked processing pixels processing copy texture image
    24. 24. OpenGL 4.3 Processing Pipelines From Application From Application Vertex Puller Dispatch Indirect Dispatch Element Array Buffer b Buffer b Draw Indirect Buffer b Vertex Shader Image Load / Store t/b Compute Shader Tessellation Control Vertex Buffer Object b Shader Atomic Counter b Tessellation Primitive Generator Shader Storage b Tessellation Evaluation Shader Texture Fetch t/b Geometry Shader Uniform Block b Transform Feedback Transform Feedback Buffer b Legend Rasterization From Application Fixed Function Stage Fragment Shader Pixel Assembly Pixel Unpack Buffer b Programmable Stage b – Buffer Binding Raster Operations Pixel Operations Texture Image t t – Texture Binding Framebuffer Pixel Pack Pixel Pack Buffer b Arrows indicate data flow
    25. 25. OpenGL 4.3Compute Shadersexplored
    26. 26. Why Compute Shaders? particle physics Execute algorithmically general-purpose GLSL shaders Read and write uniforms and images Grid-oriented Single Program, Multiple Data (SPMD) fluid execution model with communication via shared variables behavior Process graphics data in context of the graphics pipeline Easier than interoperating with a compute API when processing ‘close to the pixel’ crowd Avoids involved “inter-op” APIs to connect OpenGL simulation objects to CUDA or OpenCL Complementary to OpenGL Gives full access to OpenGL objects (multisample buffers, ray etc.) tracing Same GLSL language used for graphic shaders Not a full heterogonous (CPU/GPU) programming framework using full ANSI C In contrast to CUDA C/C++, global Standard part of all OpenGL 4.3 implementations illumination Matches DirectX 11 functionality
    27. 27. Compute Shader Particle System Demo written by Mike Bailey @ Oregon State University also author of
    28. 28. OpenGL 4.3 Compute Shaders Single Program, Multiple Data (SPMD) Execution Model Mental model: “scores of threads jump into same function at once” Hierarchical thread structure Threads in Groups in Dispatches invocation work group dispatch (thread)
    29. 29. Single Program, Multiple Data Example Standard C Code, running single-threadedvoid SAXPY_CPU(int n, float alpha, float x[256], float y[256]){ if (n > 256) n = 256; for (int i = 0; i < n; i++) // loop over each element explicitly y[i] = alpha*x[i] + y[i];}#version 430layout(local_size_x=256) in; // spawn groups of 256 threads!buffer xBuffer { float x[]; }; buffer yBuffer { float y[]; };uniform float alpha;void main(){ int i = int(gl_GlobalInvocationID.x); if (i < x.length()) // derive size from buffer bound y[i] = alpha*x[i] + y[i];} OpenGL Compute Shader, running SPMD SAXPY = BLAS librarys single-precision alpha times x plus y
    30. 30. Examples of Single-threaded Execution vs. SPMD Programming Systems Single-threaded Single Program, Multiple Data C/C++ CUDA C/C++ FORTRAN DirectCompute Pascal OpenCL OpenGL Compute Shaders CPU-centric, GPU-centric,hard to make multi-threaded & parallel naturally expresses parallelism
    31. 31. Per-Thread Local Variables Each thread can read/write variables “private” to its execution Each thread gets its own unique storage for each local variable work group local Compute Shader source code thread #1 v i int i; float v; no access to locals i++; of other threads v = 2*v + i; thread #2 v i
    32. 32. Special Per-thread Variables Work group can have a 1D, 2D or 3D “shape” Specified via Compute Shader input declarations Compute Shader syntax examples 1D, 256 threads: layout(local_size_x=256) in; 2D, 8x10 thread shape: layout(local_size_x=8,local_size_y=10) in; 3D, 4x4x4 thread shape: layout(local_size_x=4,local_size_y=4,local_size_z=4) in; Every thread in work group has its own invocation # Accessed through built-in variable gl_LocalInvocationID=(4,1,0) in uvec3 gl_LocalInvocationID; Think of every thread having a “who am I?” variable Using these variables, threads are expected to Index arrays Determine their flow control Compute thread-dependent computations 6x3 work group
    33. 33. Per-Work Group Shared Variables Any thread in a work group can read/write shared variables Typical idiom is to index by each thread’s invocation # Compute Shader a[0][0] a[0][1] a[0][2] a[0][3] source code shared float a[3][4]; a[1][0] a[1][1] a[1][2] a[1][3] unsigned int x = gl_LocalInvocationID.x a[2][0] a[2][1] a[2][2] a[2][3] unsigned int y = gl_LocalInvocationID.y no access to shared variables of a different work group a[y][x] = 2*ndx; a[y][x^1] += a[y][x]; a[0][0] a[0][1] a[0][2] a[0][3] memoryBarrierShared(); a[y][x^2] += a[y][x]; a[1][0] a[1][1] a[1][2] a[1][3] use shared memory barriers a[2][0] a[2][1] a[2][2] a[2][3] to synchronize access to shared variables
    34. 34. work groupsReading and WritingGlobal ResourcesIn addition to local andshared variables…Compute Shaders can alsoaccess global resources Read-only Textures Uniform buffer objects red Read-write green blue color Texture images x vertex 0 Uniform buffers y z position atomic Shader storage buffers red counters green Atomic counters image blue color Bindless buffers (within texture) x vertex 1 y Take care updating textures z z position shared read-write buffer object resources global OpenGL resources
    35. 35. Simple Compute Shader Let’s just copy from one 2D texture image to another… Pseudo-code: for each pixel in source image  pixels could be copied copy pixel to destination image fully in parallel How would we write this as a compute shader...
    36. 36. Simple Compute Shader Let’s just copy from one 2D texture image to another… #version 430 // use OpenGL 4.3’s GLSL with Compute Shaders #define TILE_WIDTH 16 #define TILE_HEIGHT 16 const ivec2 tileSize = ivec2(TILE_WIDTH,TILE_HEIGHT); layout(binding=0,rgba8) uniform image2D input_image; layout(binding=1,rgba8) uniform image2D output_image; layout(local_size_x=TILE_WIDTH,local_size_y=TILE_HEIGHT) in; void main() { const ivec2 tile_xy = ivec2(gl_WorkGroupID); const ivec2 thread_xy = ivec2(gl_LocalInvocationID); const ivec2 pixel_xy = tile_xy*tileSize + thread_xy; vec4 pixel = imageLoad(input_image, pixel_xy); imageStore(output_image, pixel_xy, pixel); }
    37. 37. Compiles into NV_compute_program5 Assembly!!NVcp5.0 # NV_compute_program5 assemblyGROUP_SIZE 16 16; # work group is 16x16 so 256 threadsPARAM c[2] = { program.local[0..1] }; # internal constantsTEMP R0, R1; # temporariesIMAGE images[] = { image[0..7] }; # input & output imagesMAD.S R1.xy,invocation.groupid,{16,16,0,0}.x,invocation.localid;MOV.S R0.x, c[0];LOADIM.U32 R0.x, R1, images[R0.x], 2D; # load from input imageMOV.S R1.z, c[1].x;UP4UB.F R0, R0.x; # unpack RGBA pixel into float4 vectorSTOREIM.F images[R1.z], R0, R1, 2D; # store to output imageEND
    38. 38. What is NV_compute_program5? NVIDIA has always provided assembly-level interfaces to GPU programmability in OpenGL NV_gpu_program5 is Shader Model 5.0 assembly And NV_gpu_program4 was for Shader Model 4.0 NV_tessellation_program5 is programmable tessellation extension NV_compute_program5 is further extension for Compute Shaders Advantages of assembly extensions Faster load-time for shaders Easier target for dynamic shader generation Allows other languages/tools, such as Cg, to target the underlying hardware Provides concrete underlying execution model You don’t have to guess if your GLSL compiles well or not
    39. 39. Launching a Compute Shader First write your compute shader Request GLSL 4.30 in your source code: #version 430 The text of our “copy” kernel is an example Second compile your compute shader Same compilation process as standard GLSL graphics shaders… glCreateShader/glShaderSource with Compute Shader token GLuint compute_shader = glCreateShader(GL_COMPUTE_SHADER); glCreateProgram/glAttachShader/glLinkProgram (compute and graphics shaders cannot mix in the same program) Bind to your program object glUseProgram(compute_shader); dispatches a Dispatch a grid of work groups 4x4x3 grid glDispatchCompute(4, 4, 3); of work groups
    40. 40. Launching the Copy Compute ShaderSetup for copying from source to destination texture Create an input (source) texture object glTextureStorage2DEXT(input_texobj, GL_TEXTURE_2D, 1, GL_RGBA8, width, height); OpenGL 4.2 or glTextureSubImage2DEXT(input_texobj, GL_TEXTURE_2D, ARB_texture- /*level*/0, /*x,y*/0,0, width, height, _storage plus GL_RGBA, GL_UNSIGNED_BYTE, image); EXT_direct_state_access Create an empty output (destination) texture object glTextureStorage2DEXT(output_texobj, GL_TEXTURE_2D, 1, GL_RGBA8, width, height); Bind level zero of both textures to texture images 0 and 1 GLboolean is_not_layered = GL_FALSE; glBindImageTexture(/*image*/0, input_texobj, /*level*/0, OpenGL 4.2 or is_not_layered, /*layer*/0, GL_READ_ONLY, GL_RGBA8); ARB_shader- glBindImageTexture( /*image*/1, output_texobj, /*level*/0, _image- is_not_layered, /*layer*/0, GL_READ_WRITE, GL_RGBA8); _load_store Use the copy compute shader glUseProgram(compute_shader);Dispatch sufficient work group instances of the copy compute shaderglDispatchCompute((width + 15) / 16, (height + 15) / 16), 1); OpenGL 4.3
    41. 41. Copy Compute Shader Execution Input (source) image Output (destination) image
    42. 42. Copy Compute Shader Tiling gl_WorkGroupID=[x,y] [0,4] [1,4] [2,4] [3,4] [4,4] [0,4] [1,4] [2,4] [3,4] [4,4] [0,3] [0,3] [1,3] [1,3] [2,3] [2,3] [3,3] [3,3] [4,3] [4,3] [0,3] [0,3] [1,3] [1,3] [2,3] [2,3] [3,3] [3,3] [4,3] [4,3] [0,2] [0,2] [1,2] [1,2] [2,2] [2,2] [3,2] [3,2] [4,2] [4,2] [0,2] [0,2] [1,2] [1,2] [2,2] [2,2] [3,2] [3,2] [4,2] [4,2] [0,1] [0,1] [1,1] [1,1] [2,1] [2,1] [3,1] [3,1] [4,1] [4,1] [0,1] [0,1] [1,1] [1,1] [2,1] [2,1] [3,1] [3,1] [4,1] [4,1] [0,0] [0,0] [1,0] [1,0] [2,0] [2,0] [3,0] [3,0] [4,0] [4,0] [0,0] [0,0] [1,0] [1,0] [2,0] [2,0] [3,0] [3,0] [4,0] [4,0] Input (source) image 76x76 Output (destination) image 76x76
    43. 43. Next Example: General Convolution Discrete convolution: common image processing operation Building block for blurs, sharpening, edge detection, etc. Example: 5x5 convolution (N=5) of source (input) image s Generates destination (output) image d, given NxN matrix of weights w
    44. 44. Input Image
    45. 45. Output Image after 5x5 Gaussian Blur Gaussian sigma=2.0
    46. 46. Implementing a General Convolution Basic algorithm Tile-oriented: generate MxM pixel tiles So operating on a (M+2n)x(M+2n) region of the image For 5x5 convolution, n=2 Phase 1: Read all the pixels for a region from input image Phase 2: Perform weighted sum of pixels in [-n,n]x[-n,n] region around each output pixel Phase 3: Output the result pixel to output image
    47. 47. General Convolution: Preliminaries#version 430 // use OpenGL 4.3’s GLSL with Compute Shaders// Various kernel-wide constantsconst int tileWidth = 16, tileHeight = 16;const int filterWidth = 5, filterHeight = 5;const ivec2 tileSize = ivec2(tileWidth,tileHeight);const ivec2 filterOffset = ivec2(filterWidth/2,filterHeight/2);const ivec2 neighborhoodSize = tileSize + 2*filterOffset;// Declare the input and output images.layout(binding=0,rgba8) uniform image2D input_image;layout(binding=1,rgba8) uniform image2D output_image;uniform vec4 weight[filterHeight][filterWidth];uniform ivec4 imageBounds; // Bounds of the input image for pixel coordinate clamping.void retirePhase() { memoryBarrierShared(); barrier(); }ivec2 clampLocation(ivec2 xy) { // Clamp the image pixel location to the image boundary. return clamp(xy, imageBounds.xy,;}
    48. 48. General Convolution: Phase 1layout(local_size_x=TILE_WIDTH,local_size_y=TILE_HEIGHT) in;shared vec4 pixel[NEIGHBORHOOD_HEIGHT][NEIGHBORHOOD_WIDTH];void main() { const ivec2 tile_xy = ivec2(gl_WorkGroupID); const ivec2 thread_xy = ivec2(gl_LocalInvocationID); const ivec2 pixel_xy = tile_xy*tileSize + thread_xy; const uint x = thread_xy.x; const uint y = thread_xy.y; // Phase 1: Read the images neighborhood into shared pixel arrays. for (int j=0; j<neighborhoodSize.y; j += tileHeight) { for (int i=0; i<neighborhoodSize.x; i += tileWidth) { if (x+i < neighborhoodSize.x && y+j < neighborhoodSize.y) { const ivec2 read_at = clampLocation(pixel_xy+ivec2(i,j)-filterOffset); pixel[y+j][x+i] = imageLoad(input_image, read_at); } } } retirePhase();
    49. 49. General Convolution: Phases 2 & 3 // Phase 2: Compute general convolution. vec4 result = vec4(0); for (int j=0; j<filterHeight; j++) { for (int i=0; i<filterWidth; i++) { result += pixel[y+j][x+i] * weight[j][i]; } } // Phase 3: Store result to output image. imageStore(output_image, pixel_xy, result);}
    50. 50. Separable Convolution Many important convolutions expressible in “separable” form More efficient to evaluate Allows two step process: 1) blur rows, then 2) blur columns Two sets of weights: column vector weights c and row vector weights r weight is product of separable row & column weights Practical example for demonstrating Compute Shader shared variables…
    51. 51. Example Separable Convolutions Original Original Original
    52. 52. Example Separable ConvolutionsGaussian filter, sigma=2.25 Sobel filter, horizontal Sobel filter, vertical
    53. 53. GLSL Separable Filter Implementation<< assume preliminaries from earlier general convolution example>>layout(local_size_x=TILE_WIDTH,local_size_y=NEIGHBORHOOD_HEIGHT) in;shared vec4 pixel[NEIGHBORHOOD_HEIGHT][NEIGHBORHOOD_WIDTH]; // values read from input imageshared vec4 row[NEIGHBORHOOD_HEIGHT][TILE_WIDTH]; // weighted row sumsvoid main() // separable convolution{ const ivec2 tile_xy = ivec2(gl_WorkGroupID); const ivec2 thread_xy = ivec2(gl_LocalInvocationID); const ivec2 pixel_xy = tile_xy*tileSize + (thread_xy-ivec2(0,filterOffset.y)); const uint x = thread_xy.x; const uint y = thread_xy.y; // Phase 1: Read the images neighborhood into shared pixel arrays. for (int i=0; i<NEIGHBORHOOD_WIDTH; i += TILE_WIDTH) { if (x+i < NEIGHBORHOOD_WIDTH) { const ivec2 read_at = clampLocation(pixel_xy+ivec2(i-filterOffset.x,0)); pixel[y][x+i] = imageLoad(input_image, read_at); } } retirePhase();
    54. 54. GLSL Separable Filter Implementation // Phase 2: Weighted sum the rows horizontally. row[y][x] = vec4(0); for (int i=0; i<filterWidth; i++) { row[y][x] += pixel[y][x+i] * rowWeight[i]; } retirePhase(); // Phase 3: Weighted sum the row sums vertically and write result to output image. // Does this thread correspond to a tile pixel? // Recall: There are more threads in the Y direction than tileHeight. if (y < tileHeight) { vec4 result = vec4(0); for (int i=0; i<filterHeight; i++) { result += row[y+i][x] * columnWeight[i]; } // Phase 4: Store result to output image. const ivec2 pixel_xy = tile_xy*tileSize + thread_xy; imageStore(output_image, pixel_xy, result); }}
    55. 55. Compute Shader Median Filter Simple idea “For each pixel, replace it with the median-valued pixel in its NxN neighborhood” Non-linear, good for image enhancement through noise reduction Expensive: naively, requires lots sorting to find median Very expensive when the neighborhood is large Reasonably efficient with Compute Shaders
    56. 56. Median Filter Example Noisy appearance in candy Original
    57. 57. Median Filter Example Noisy lost in blur But text is blurry too Gaussian 5x5 blur
    58. 58. Median Filter Example Noise suppressed Text still sharp Median filter 5x5
    59. 59. Large Median Filters for Impressionistic Effect Original 7x7 Estimated Median Filter
    60. 60. Other stuff in OpenGL 4.3
    61. 61. OpenGL Evolves ModularlyEach core revision is specified as a set of extensions 4.3 Example: ARB_compute_shader Puts together all the functionality for compute shaders ARB_compute_shader Describe in its own text file ARB_ES3_compatibility May have dependencies on other extensions many more … Dependencies are stated explicitlyA core OpenGL revision (such as OpenGL 4.3) “bundles” a set ofagreed extensions—and mandates their mutual support Note: implementations can also “unbundle” ARB extensions for hardware unable to support the latest core revisionSo easiest to describe OpenGL 4.3 based on its bundledextensions…
    62. 62. OpenGL 4.3 debugging support ARB_debug_output OpenGL can present debug information back to developer ARB_debug_output2 Easier enabling of debug output ARB_debug_group Hierarchical grouping of debug tagging ARB_debug_label Label OpenGL objects for debugging
    63. 63. OpenGL 4.3 new texture functionality ARB_texture_view Provide different ways to interpret texture data without duplicating the texture Match DX11 functionality ARB_internalformat_query2 Find out actual supported limits for most texture parameters ARB_copy_image Direct copy of pixels between textures and render buffers ARB_texture_buffer_range Create texture buffer object corresponding to a sub-range of a buffer’s data store ARB_stencil_texturing Read stencil bits of a packed depth-stencil texture ARB_texture_storage_multisample Immutable storage objects for multisampled textures
    64. 64. OpenGL 4.3 new buffer functionalityARB_shader_storage_buffer_object Enables shader stages to read & write to very large buffers NVIDIA hardware allows every shader stage to read & write structs, arrays, scalars, etc.ARB_invalidate_subdata Invalidate all or some of the contents of textures and buffersARB_clear_buffer_object Clear a buffer object with a constant valueARB_vertex_attrib_binding Separate vertex attribute state from the data stores of each arrayARB_robust_buffer_access_behavior Shader read/write to an object only allowed to data owned by the application Applies to out of bounds accesses
    65. 65. OpenGL 4.3 new pipeline functionalityARB_compute_shader Introduces new shader stage Enables advanced processing algorithms that harness the parallelism of GPUsARB_multi_draw_indirect Draw many GPU generated objects with one callARB_program_interface_query Generic API to enumerate active variables and interface blocks for each stage Enumerate active variables in interfaces between separable program objectsARB_ES3_compatibility features not previously present in OpenGL Brings EAC and ETC2 texture compression formatsARB_framebuffer_no_attachments Render to an arbitrary sized framebuffer without actual populated pixels
    66. 66. GLSL 4.3 new functionality ARB_arrays_of_arrays Allows multi-dimensional arrays in GLSL. float f[4][3]; ARB_shader_image_size Query size of an image in a shader ARB_explicit_uniform_location Set location of a default-block uniform in the shader ARB_texture_query_levels Query number of mipmap levels accessible through a sampler uniform ARB_fragment_layer_viewport gl_Layer and gl_ViewportIndex now available to fragment shader
    67. 67. New KHR and ARB extensions Not part of core but important and standardized at same time as OpenGL 4.3… KHR_texture_compression_astc_ldr Adaptive Scalable Texture Compression (ASTC) 1-4 component, low bit rate < 1 bit/pixel – 8 bit/pixel ARB_robustness_isolation If application causes GPU reset, no other application will be affected For WebGL and other un-trusted 3D content sources
    68. 68. Getting at OpenGL 4.3 Easiest approach… Use OpenGL Extension Wrangler (GLEW) Release 1.9.0 already has OpenGL 4.3 support
    69. 69. Further NVIDIA OpenGL Work
    70. 70. Further NVIDIA OpenGL Work Linux enhancements Path Rendering for Resolution-independent 2D graphics Bindless Graphics Commitment to API Compatibility
    71. 71. OpenGL-relatedLinux Improvements  Support for X Resize, Rotate, and Reflect Extension  Also known as RandR  Version 1.2 and 1.3  OpenGL enables, by default, “Sync to Vertical Blank”  Locks your glXSwapBuffers to the monitor refresh rates  Matches Windows default now  Previously disabled by default
    72. 72. OpenGL-relatedLinux Improvements Expose additional full-scene antialiasing (FSAA) modes 16x multisample FSAA on all GeForce GPUs 2x2 supersampling of 4x multisampling Ultra high-quality FSAA modes for Quadro GPUs 32x multisample FSAA – 2x2 supersampling of 8x multisampling 64x multisample FSAA – 4x4 supersampling of 4x multisampling Coverage sample FSAA on GeForce 8 series and better 4 color/depth samples + 12 depth samples
    73. 73. Multisampling FSAA Patterns aliased 2x multisampling 4x multisampling 8x multisampling 1 sample/pixel 2 samples/pixel 4 samples/pixel 8 samples/pixel 64 bits/pixel 128 bits/pixel 256 bits/pixel 512 bits/pixel Assume: 32-bit RGBA + 24-bit Z + 8-bit Stencil = 64 bits/sample
    74. 74. Supersampling FSAA Patterns 2x2 supersampling 2x2 supersampling 4x4 supersampling of 4x multisampling of 8x multisampling of 16x multisampling 16 samples/pixel 32 samples/pixel 64 samples/pixel 1024 bits/pixel 2048 bits/pixel 4096 bits/pixel Quadro GPUs Assume: 32-bit RGBA + 24-bit Z + 8-bit Stencil = 64 bits/sample
    75. 75. Image Quality EvolvedNVIDIA Fast Approximated Anti-Alias (FXAA) Supported on Windows for several driver releases… Now enabled for Linux in 304.xx drivers
    76. 76. NVIDIA X Server Settings for LinuxControl Panel
    77. 77. GLX Protocol Network transparent OpenGL Run OpenGL app on one machine, display the X and 3D on a different machine 3D app X server GLX OpenGL Server GLX Client OpenGL network connection
    78. 78. OpenGL-relatedLinux Improvements Official GLX Protocol support for OpenGL extensions ARB_half_float_pixel EXT_point_parameters ARB_transpose_matrix EXT_stencil_two_side EXT_blend_equation_separate EXT_depth_bounds_test NV_copy_image EXT_framebuffer_blit NV_depth_buffer_float EXT_framebuffer_multisample NV_half_float EXT_packed_depth_stencil NV_occlusion_query NV_point_sprite NV_register_combiners2 NV_texture_barrier
    79. 79. OpenGL-relatedLinux Improvements Tentative GLX Protocol support for OpenGL extensionsARB_map_buffer_range EXT_vertex_attrib_64bitARB_shader_subroutine NV_conditional_renderARB_stencil_two_side NV_framebuffer_multisample_coverageEXT_transform_feedback2 NV_texture_barrier NV_transform_feedback2
    80. 80. Synchronizing X11-based OpenGL Streams New extension GL_EXT_x11_sync_object Bridges the X Synchronization Extension with OpenGL 3.2 “sync” objects (ARB_sync) Introduces new OpenGL command GLintptr sync_handle; GLsync glImportSyncEXT (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags); external_sync_type must be GL_SYNC_X11_FENCE_EXT flags must be zero
    81. 81. Other Linux Updates GL_CLAMP behaves in conformant way now Long-standing work-around for original Quake 3 Enabled 10-bit per component X desktop support GeForce 8 and better GPUs Support for 3D Vision Pro stereo now
    82. 82. What is 3D Vision Pro? For Professionals All of 3D Vision support, plus • Radio frequency (RF) glasses, Bidirectional • Query compass, accelerometer, battery • Many RF channels – no collision • Up to ~120 feet • No line of sight needed to emitter • NVAPI to control
    83. 83. NV_path_renderingAn NVIDIA OpenGL extension GPU-accelerates resolution- independent 2D graphics Very fast! Supports PostScript-style renderingCome to my afternoon paperpresentation to learn more “GPU-Accelerated Path Rendering” Garnet 217 Tomorrow, Friday, November 30 14:15 - 16:00
    84. 84. Teaser Scene: 2D and 3D mix!
    85. 85. NVIDIA’s Vision of Bindless Graphics Problem: Binding to different objects (textures, buffers) takes a lot of validation time in driver And applications are limited to a small palette of bound buffers and textures Approach of OpenGL, but also Direct3D Solution: Exposes GPU virtual addresses Let shaders and vertex puller access buffer and texture memory by its virtual address! Kepler GPUs support bindless texture
    86. 86. Prior to Bindless Graphics Traditional OpenGL GPU memory reads are “indirected” through bindings Limited number of texture units and vertex array attributes glBindTexture—for texture images and buffers glBindBuffer—for vertex arrays
    87. 87. Buffer-centric Evolution Data moves onto GPU, away from CPU Apps on CPUs just too slow at moving data otherwise Array Element Buffer glBegin, glDrawElements, etc. Object (VeBO) Texture Buffer Vertex Array Buffer Object Object (TexBO) Vertex Puller (VaBO) texel data Transform Feedback Buffer (XBO) Vertex Shading Pixel Unpack vertex data Buffer (PuBO) Texturing Geometry Shading Parameter Buffer glDrawPixels, glTexImage2D, etc. Object (PaBO) Pixel Pixel Pack Buffer Fragment Pipeline (PpBO) Uniform Buffer Shading glReadPixels, pixel data Object (UBO) etc. parameter data Framebuffer
    88. 88. Kepler – Bindless Textures Enormous increase in the number of unique textures available to shaders at run-time More different materials and richer texture detail in a scene texture #0 texture #0 Shader code texture #1 texture #1 Shader code texture #2 texture #2 … texture #127 texture #127 … Pre-Kepler texture binding model Kepler bindless textures over 1 million unique textures
    89. 89. Kepler – Bindless Textures Pre-Kepler texture binding model Kepler bindless textures CPU CPU Load texture A Load textures A, B, C Load texture B Draw() Load texture C Bind texture A to slot I GPU Bind texture B to slot J Read from texture A Draw() Read from texture B Read from texture C GPU Read from texture at slot I Read from texture at slot J CPU Bind texture C to slot K Bindless model reduces CPU Draw() overhead and improves GPU access GPU efficiency Read from texture at slot K
    90. 90. Bindless Textures Apropos for ray-tracing and advanced rendering where textures cannot be “bound” in advance Shader code
    91. 91. Bindless performance benefit Numbers obtained with a directed test
    92. 92. More Information on Bindless Texture Kepler has new NV_bindless_texture extension Texture companion to NV_vertex_buffer_unified_memory for bindless vertex arrays NV_shader_buffer_load for bindless shader buffer reads NV_shader_buffer_store (also NEW) for bindless shader buffer writes API specifications are publically available
    93. 93. NVIDIA’s Position on OpenGL Deprecation:Core vs. Compatibility Profiles OpenGL 3.1 introduced notion of Best advice for real developers “core” profile Simply use the “compatibility” Idea was remove stuff from core to profile make OpenGL “good-er” Easiest course of action Requesting the core profile requires Well-intentioned perhaps but… special context creation gymnastics Throws API backward Avoids the frustration of “they decided compatibility out the window to remove what??” Lots of useful functionality got Allows you to use existing OpenGL libraries and code as-is removed that is in fast hardware Examples: Polygon mode, line width, GL_QUADS No, your program won’t go faster for using the “core” profile Lots of easy-to-use, effective API It may go slower because of extra “is got labeled deprecated this allowed to work?” checks Immediate mode Display lists Nothing changes with OpenGL 4.3 NVIDIA still committed to compatibility without compromise
    94. 94. Questions?
    95. 95. Other OpenGL-relatedNVIDIA Sessions at SIGGRAPH Asia Scaling OpenGL Applications Across Multiple GPUs Thursday, 29 November 15:00 - 15:45, Conference Hall K (here) Shalini Venkataraman / Senior Applied Engineer, NVIDIA Developing an Optimized Maya Plugin Using CUDA and OpenGL Friday, 30 November 11:00 - 11:45, Conference Hall K Wil Braithwaite / Senior Applied Engineer, NVIDIA OpenGL ES Performance Tools and Optimization for Tegra Mobile Devices Friday, 30 November 13:00 - 13:45, Conference Hall K Xueqing Yang / Developer Technology Engineer, NVIDIA GPU-accelerated Path Rendering Friday, 30 November 14:15 – 16:00, Peridot 206 Third paper in “Points and Vectors” technical papers session Mark Kilgard / Principal Software Engineer, NVIDIA