A Hardware-Aware Debugger for the Opengl Shading Language
Total Page:16
File Type:pdf, Size:1020Kb
Graphics Hardware (2007) Timo Aila and Mark Segal (Editors) A Hardware-Aware Debugger for the OpenGL Shading Language Magnus Strengert, Thomas Klein, and Thomas Ertl Institute for Visualization and Interactive Systems Universität Stuttgart Abstract The enormous flexibility of the modern GPU rendering pipeline as well as the availability of high-level shader languages have led to an increased demand for sophisticated programming tools. As the application domain for GPU-based algorithms extends beyond traditional computer graphics, shader programs become more and more complex. The turn-around time for debugging, profiling, and optimizing GPU-based algorithms is now a critical factor in application development which is not addressed adequately by the tools available. In this paper we present a generic, minimal intrusive, and application-transparent solution for debugging OpenGL Shading Language programs, which for the first time fully supports GLSL 1.2 vertex and fragment shaders plus the recent geometry shader extension. By transparently instrumenting the shader program we retrieve information directly from the hardware pipeline and provide data for visual debugging and program analysis. Categories and Subject Descriptors (according to ACM CCS): I.3.4 [Computer Graphics]: Graphics Utilities – Soft- ware Support I.3.8 [Computer Graphics]: Methodology and Techniques – Languages D.2.5 [Software]: Software Engineering – Testing and Debugging 1. Introduction bugging and code analysis tools, did not keep up with the rapid advances of the hardware and software interface. As Graphics processing units have evolved into highly flex- a result, developers typically spend quite a large amount of ible, massively parallel computing architectures and have time locating and debugging programming errors. Thus, the reached a level of programmability roughly resembling their availability of effective debugging means is essential for fast CPU counterparts. Recent advances include full integer and efficient shader code development. arithmetics, unlimited program instruction count, and gen- uine dynamic flow control. Simultaneously, this progress in In comparison to a traditional debugger for sequential hardware technology was followed by the introduction of CPU programs, the special characteristics of graphics hard- suitable high level shading languages, i.e. HLSL, Cg, and ware pose additional challenges for a shader debugger. Most GLSL, nearly as powerful as traditional CPU programming important, there is no direct access to the hardware, i.e. there languages. In addition, they offer also advanced features, is no specific low-level debugging interface. Second, it has like vector and matrix data types, reflecting the underly- to deal with the intrinsic parallelism of the graphics hard- ing SIMD architecture of the GPU. The high computational ware that requires to deal with thousands or even millions of power of modern graphics processors combined with the threads running in parallel. ease of these high level programming languages allow for In general, current solutions for shader debugging can be more and more complex algorithms to be implemented on divided into two basic approaches: software emulation and the GPU as well as enabling a widening range of applica- shader code instrumentation. The former uses a software im- tions to benefit from the use of graphics hardware as a nu- plementation of the rendering pipeline in order to emulate merical co-processing unit. Accordingly, shaders tend to be- the execution of shader programs according to the specifica- come more and more complex. tion of the shading language. This allows for direct control However, the development environment, in particular de- of program execution and provides access to arbitrary data Copyright c 2007 by the Association for Computing Machinery, Inc. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or a fee. Re- quest permissions from Permissions Dept, ACM Inc., fax +1 (212) 869-0481 or e-mail [email protected]. GH 2007, San Diego, California, August 04 - 05, 2007 c 2007 ACM 978-1-59593-625-7/07/0008 $ 5.00 M. Strengert, T. Klein, & T. Ertl / A Hardware-Aware Debugger for GLSL content. The main drawback of this approach is that debug- be roughly divided into two distinct groups: graphics calls ging is not performed on the target hardware and results may and state debuggers, and dedicated shader debuggers. therefore not correspond to actual hardware values. In con- The first group includes Microsoft's Direct3D profiling trast, shader code instrumentation will provide true hardware and debugging tool PIX [Mic07] and a number of OpenGL values, but access to the data is complicated. Since there is state machine debuggers, namely spyGLass [Mag02], Bu- no direct access to the individual processing elements, the GLe [Mer04], GLIntercept [Tre04] and the commercial only possibility to get data back from the GPU is to read back gDEBugger [Gra04]. While all of these tools provide the the final result of a shader invocation, i.e. vertex attributes or ability of API call tracing and logging as well as breakpoint- pixel color. Accordingly, it is common practice in shader de- ing (PIX and gDEBugger further allow to display various velopment to use printf-style visual debugging by manually performance counters and other profiling information), only rewriting the (fragment) shader to return the value of interest the PIX tool provides the possibility of shader debugging. as its final output and to interpret the resulting images. How- However, for shader debugging PIX relies on the software ever, in the context of multi-pass algorithms involving off- emulation of the Direct3D reference rasterizer, i.e. no ac- screen render targets or if debugging full floating-point pre- tual hardware values are debugged. In case of OpenGL some cision data, the direct display of intermediate results is often of the above mentioned solutions provide Edit&Continue not sufficient and a fair amount of code changes to the host shader editing, but currently no tool that we know of fea- program is required to permit readback of rendering results tures a full-fledged shader debugger. to main memory. This is even worse for vertex and geometry processing units, as they do not output directly displayable On the other hand there are solutions that are specifi- content and debugging those shaders may require additional cally geared towards shader debugging. The Apple OpenGL changes in subsequent stages of the rendering pipeline. Fur- Shader Builder [App02] provides mechanisms to develop thermore, this manual Edit&Continue style of debugging is and debug ARB vertex and fragment shaders in a closed en- tedious and error prone. vironment. The first tool to automate fragment shader de- bugging in the context of the target application was Shade- An efficient shader debugging tool therefore must be able smith [PS03]. It introduced the so-called interactive deepen- to automatically instrument the shader code and host pro- ing method, a technique for automatically generating a se- gram in an application-transparent manner. In particular, it quence of truncated debug programs for singlestep execution has to work without explicit code changes, i.e. does not re- of ARB assembly fragment programs without flow control. quire modification and re-compilation of the host program. Using Shadesmith requires slight source code modifications In this paper we present a generic, minimal intrusive, of the host program. Furthermore, its frame level debugging and light-weight solution for debugging OpenGL Shading approach did not allow for debugging multi-pass algorithms. Language programs directly on the target hardware, that Another approach that allows the analysis of the com- operates completely application-transparent. It supports the plete rendering pipeline including vertex and fragment pro- ∗ full GLSL 1.2 specification for vertex and fragment shaders grams was proposed by Duca et al. [DNB 05]. Their system ∗ including the recently introduced extension for geometry is based on the Chromium [HHN 02] system to intercept shaders [NVI06]. Shader debugging is performed on a per and record the OpenGL command stream and stores data draw call level and allows singlestepping and the inspection from the pipeline in a relational database. This allows subse- of arbitrary variable content. quent queries for arbitrary elements of the captured OpenGL state using a specialized query language. Debugging high- level Cg shaders is facilitated by instrumenting shaders fol- 2. Related Work lowing an extented interactive deepening approach that al- Basic requirements for a versatile GPU debugger have been lows for handling dynamic flow control. Up to now, the pro- defined by Purcell [Pur05] and more recently by Owens et posed system is the most complete solution for the analy- ∗ al. [OLG 07]. They conclude that a practical tool for GPU sis of OpenGL programs. The availability of the complete debugging should provide essentially the same basic features OpenGL stream offers ample opportunities for debugging as a traditional debugger.