As part of our PowerVR SDK v3.3 development, we chose to refine navigation in PVRTraceGUI – our OpenGL ES analysis utility. This work consisted of many minor tweaks to simplify the interface. It also included a bigger change – a brand new search engine. One of the most important features of the new, streamlined Find dialog is its powerful regular expression search engine.

PVRTrace_find

In this blog post, I’ll detail a few tricks I’ve picked so far (despite being a regular expression novice) to significantly speed up my OpenGL ES debugging process.

What are regular expressions?

For those unfamiliar, regular expressions (a.k.a. RegEx) allow explicit definition of search patterns. They’re extremely useful when you want to search for something more specific than a single keyword. Before going any further, it’s worth mentioning that PVRTraceGUI actually supports Extended RegEx. This basically means there are some additional metacharacters to make life easier (this section of the Wikipedia RegEx article explains the differences).

Complex regular expressions can look a little daunting. Appendix A of the PVRTrace User Manual includes a table of all supported metacharacters. For convenience, I’ve included a cheat sheet below. If you can, I’d recommend also trying an online RegEx prototyping tool while reading this (e.g. www.rubular.com) to help you wrap your head around the basics.

MetacharacterDescription
.Matches any single character.
[ ]A bracket expression. Matches a single character that is contained within the brackets.
[^ ]Matches a single character that is not contained within the brackets.
^Matches the starting position within the string.
$Matches the ending position of the string or the position just before a string-ending newline.
( )Defines a marked subexpression.
nMatches what the nth marked subexpression matched, where n is a digit from 1 to 9
*Matches the preceding element zero or more times.
{m,n}Matches the preceding element at least m and not more than n times. For example, a{3,5} matches only “aaa”, “aaaa”, and “aaaaa”.
?Matches the preceding element zero or one time. For example, ab?c matches only “ac” or “abc”.
+Matches the preceding element one or more times. For example, ab+c matches “abc”, “abbc”, “abbbc”, and so on, but not “ac”.
|The choice (also known as alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc|def matches “abc” or “def”.
bMatches a word boundary.

Do the Find dialog’s options affect the search?

PVRTrace_find2

Regular expression searches can be used at the same time as the dialog’s other options.

  • “Look in” – Search in the Current Frame, the Whole Trace or a Frame Range. In multi-threaded applications, you can also choose which rendering thread should be searched
  • “Match case” – By default, the search is case-insensitive. Enabling this flag forces all pattern matches to be case-sensitive

How can I use regular expressions?

A very simple use I’ve found is to isolate all occurrences of a specific GL name with a family of calls. For example, the pattern below will find the creation, linking & binding of a particular shader program (135311933).

Program.*b135311933b

TheChase_findA

This pattern uses the ‘.’ metacharacter to capture any character type (a-z, A-Z, 0-9 etc.). The ‘*’ indicates that any number of the previous character should be captured (zero or more). Together, ‘.*’ tells the RegEx engine that we don’t care what characters are between the two search terms. The ‘b’ word boundary metacharacters ensure we match the word exactly and ignore cases where the word is a sub-string of a larger word (e.g. ignore 135311933456). When the expression is executed, PVRTraceGUI’s Search widget will list all matches in call order, grouped by the frame number they occurred in.

TheChase_findA_results

From this expression, we can go further and expand the search to include other GL calls that take the program name as an argument.

(Program|ActiveAttrib|ActiveUniform|AttachedShaders
|AttribLocation|GetUniform).*b135311933b

TheChase_findB_results

In this search, the ‘(‘ and ‘)’ brackets are used to define a sub expression. ‘|’ metacharacters indicate an OR operation. It’s possible to include multiple sub-expressions, so we can easily expand this search to include several GL names:

(Program|ActiveAttrib|ActiveUniform|AttachedShaders
|AttribLocation|GetUniform).*b(135311933|40810583|50050715)b

TheChase_findC_results

Any more suggestions?

As the search is performed on all textual data captured in the GL and EGL call stream, we can search for any call and/or parameter name. For example, the pattern below finds all compressed ETC2 texture data uploads where the resolution is 512×512, regardless of format (i.e. COMPRESSED_RGB8_ETC2, COMPRESSED_SRGB8_ETC2, COMPRESSED_SRGB8_ALPHA8_ETC2_EAC etc.).

glCompressedTex.*Image.*GL_COMPRESSED_.*ETC2.*b512b, b512b,

This is great! Where can I learn more?

There are countless wikis, blog posts and documents out there that explain clever uses of RegEx patterns to find needles in haystacks. The online tool I mentioned earlier is really useful (www.rubular.com). The best thing to do though is capture a PVRT, load it into PVRTraceGUI and start experimenting!

About the author: Joe Davis

Profile photo of Joe Davis

Joe Davis leads the PowerVR Graphics developer support team. He and his team support a wide variety of graphics developers including those writing games, middleware, UIs, navigation systems, operating systems and web browsers. Joe regularly attends and presents at developer conferences to help graphics developers get the most out of PowerVR GPUs. You can follow him on Twitter @joedavisdev.

View all posts by Joe Davis