EXT_window_rectangles extends OpenGL with a new per-fragment test called the "window rectangles test" for use with FBOs that provides 8 or more inclusive or exclusive rectangles for rasterized fragments. Applications of this functionality include web browsers and virtual reality.
2. What is EXT_window_rectangles?
âą Provides new per-fragment pipeline stage:
window rectangles tests
â Provide an array of window-space rectangles
âą Maintained as GL context state
â Rasterized fragments must be inclusive or exclusive
to the set of active window rectangles
â Limited to framebuffer objects (FBOs), not windows
â Fast because discards prior to shading & pixel
operations
âą Specified as multi-vendor OpenGL extension
4. NEW Window Rectangles Test in
Per-fragment Operations
Window
Rectangles
Test
NEW
stage
5. Rationale for
EXT_window_rectangles
âą Often rendering is obscured by opaque regions
in window space
â Wasteful to render to obscured regions
â Discarding such rendering = easy performance
âą Common applications
â Web page background often
obscured by overlapping
âą Complication: modern web pages
use lots of rounded rectangle sections
â Windowed rendering in UI
â Virtual reality limited views
6. Rationale for FBO-only Behavior
âą Window rectangles test hardware is used to aide
conventional window clip enforcement for
windows
â Called âpixel ownership testâ in OpenGL specification
â Details of pixel ownership depend on underlying
window systemâs clipping
âą But FBO rendering is unclipped by window
system
â So window rectangles test functionality can be re-
tasked for FBO rendering under application control
âą Reasonable because modern OpenGL rendering
is FBO-focused
7. All Rendering Subject to Window
Rectangles Test
âą Affects
â point/line/polygon rasterizaton
â framebuffer clears (glClear, etc.)
â framebuffer blits (glBlitFramebuffer, etc.)
â image rectangles (glDrawPixels, glCopyPixels,
glDrawTextureNV)
â bitmaps (glBitmap)
âą Means regions excluded or not inclusive simply
have no effort spent on shading or pixel
operations
â Excellent at avoiding wasted rasterization, shading,
and pixel update bandwidth & effort
8. Straightforward API
âą glWindowRectanglesEXT(GLenum mode, GLsizei count,
const GLint rects[]);
â mode can be either GL_INCLUSIVE_EXT or
GL_EXCLUSIVE_EXT
â count can be from 0 to maximum number of supported window
rectangles
âą Must be at least 8
â Rectangles allowed to overlap and/or disjoint
âą Each rectangle is (x,y,width,height)
âą width & height must be non-negative
âą Initial state
â GL_EXCLUSIVE_NV with zero rectangles
â Excluding rendering from zero rectangles means nothing is
discarded by window rectangles test
9. API Queries
âą State can be queried
â GL_WINDOW_RECTANGLE_MODE_EXT
âą Use glGetIntegerv to query mode
â Either inclusive or exclusive
â GL_WINDOW_RECTANGLE_EXT
âą Use indexed glGetIntegeri_v to query (x,y,width,height) of a
window rectangle by index
â GL_NUM_WINDOW_RECTANGLES_EXT
âą Use glGetIntegerv to get number of active window rectangles
âą Implementation-dependent limit query
â GL_MAX_WINDOW_RECTANGLES_EXT
âą Number of window rectangles supported, at least 8
10. Window Rectangles Test
Pseudo-Code
âą Given a fragment at window-space position (x,y)
âą And winrect state structure with EXT_window_rectangles state
âą Determine if this fragment should be discarded or not
const bool inclusive = (winrects.mode == GL_INCLUSIVE_EXT);
bool in_some_rect = false;
// For each window rectangle...
for (int r = 0; r < winrects.count; r++) {
const WinRect &rect = winrects.rect[r];
const int box_x0 = rect.x;
const int box_y0 = rect.y;
const int box_x1 = int(rect.x + rect.width);
const int box_y1 = int(rect.y + rect.height);
// Is this fragment [i,j] within this rectangle r?
if ((x >= box_x0) && (y >= box_y0) && (x < box_x1) && (y < box_y1)) {
in_some_rect = true;
}
}
if (inclusive ^ in_some_rect) {
// INCLUSIVE: Fragment not in any inclusive rectangle; discard.
// EXCLUSIVE: Fragment in one or more exclusive rectangles; discard.
discard;
} else {
// INCLUSIVE: Fragment included in at least one rectangle; accept.
// EXCLUSIVE: Fragment not within any exclusive rectangles; accept.
}
11. Rasterization Performance Benefits
âą Being able to throwing away useless work quickly is
always a boon to performance
âą Software rasterization details
â Scan-line rasterizers can quick âskip overâ window rectangles
along scan-lines
â Happens before expensive shading & pixel operations
â MMX friendly
âą Hardware rasterization details
â Today, GPUs can enforce rectangular windows
âą Details vary but rectangular region discard commonly supported
âą Example: OpenVG exposes at least 32 window rectangles
â Very fast discard since done in rasterizer and requires no reads
to video memory (e.g. stencil buffer reads)
â EXT_window_rectangles allows this same hardware to be re-
tasked for application use
12. Skia Support
âą Skia has patches to support this
functionality
â Implemented by Chris Dalton
âą For acceleration of Googleâs Chrome
browser
â <div> sections in web pages provide
exploitable knowledge of opaque layered
occlusion
â Rounded rectangles can be approximated by
two overlapped rectangles
14. Example Scene
âą Scenario: draw the green background to be overlapped
by 5 irregular regions
Waste of rendering
to rasterize green
into regions to be
subsequently
overdrawn
15. Window Rectangles to the Rescue
âą Naively, just want to draw a big rectangles
âą Use all 8 window rectangles to restrict rendering
â Using exclusive mode, GL_EXCLUSIVE_NV
16. Window Rectangles to the Rescue
âą Checkerboard regions show discarded rendering that
gets excluded by GL_EXCLUSIVE_NV window
rectangles test
17. Visualization
âą Rounded rectangles & non-pixel aligned rectangles still
need additional discarding
Shader discarded
regions shown in
gray checkerboard
Window rectangles
test regions shown
in orange/yellow
hash
18. Usage of Window Rectangles Test
âą Shows rectangle drawn in 8 inclusive and 8 exclusive
situations
â Notice how window rectangles allowed to overlap
19. Real-world Web Pages that Benefit
89% improvement @ 4x 46% improvement @ 4x 59% improvement @ 4x
21. Restricted to a Non-rectangular
View
âą Limit rasterization to approximately circular
region cheaply with window rectangles test
22. Restricted to a Non-rectangular
View
âą Visualizing the 8 inclusive rectangles
23. Alternatively Exclusive
âą Visualizing the 8 inclusive rectangles
â Overlap of two sets of window rectangles means exclusive &
inclusive scenes have overlap of pixels
25. Specification, Driver, & Library
Status
âą Specification public
â https://www.opengl.org/registry/specs/EXT/window_rectangles.txt
â Identical API for OpenGL 4.5, ES 2.0, and ES 3.2
âą Patches in progress for Googleâs Skia library
â 2D graphics library used by Chrome browser
âą NVIDIA OpenGL drivers
â Fermi, Kepler, Maxwell, and Pascal
â So GeForce 4xx and up
â In drivers mid-2016
âą Mesa3D
â Considered by Brian Paul
26. Thanks
âą Brian Paul, VMware
âą Brian Salomon, Google
âą Chris Dalton, Google
âą Jeff Bolz, NVIDIA
âą Mark Callow, Khronos
âą Walt Steiner, NVIDIA