+ All Categories
Home > Software > OpenGL (ES) debugging

OpenGL (ES) debugging

Date post: 13-Jul-2015
Category:
Upload: leszek-godlewski
View: 233 times
Download: 0 times
Share this document with a friend
36
Leszek Godlewski Programmer, Nordic Games OpenGL (ES) debugging
Transcript
Page 1: OpenGL (ES) debugging

L e sz e k G o d l e w sk i

P r o g r a m m e r , N o r d i c G a m e s

OpenGL (ES) debugging

Page 2: OpenGL (ES) debugging

Nordic Games GmbH

● Started in 2011 as a sister company to Nordic Games Publishing (We Sing)

● Base IP acquired from JoWooD and DreamCatcher (SpellForce, The Guild, Aquanox, Painkiller)

● Initially focusing on smaller, niche games

● Acquired THQ IPs in 2013 (Darksiders, Titan Quest, Red Faction, MX vs. ATV)

● Now shifting towards being a production company with internal devs

● Since fall 2013: internal studio in Munich, Germany (Grimlore Games)

Page 3: OpenGL (ES) debugging

Who is this guy?

Leszek GodlewskiProgrammer, Nordic Games (early 2014 – now)

– Linux port of Darksiders

Freelance Programmer (Sep 2013 – early 2014)

– Linux port of Painkiller Hell & Damnation

– Linux port of Deadfall Adventures

Generalist Programmer, The Farm 51 (Mar 2010 – Aug 2013)

– Painkiller Hell & Damnation, Deadfall Adventures

Page 4: OpenGL (ES) debugging

Demo code available

is.gd/GDCE14Linux

Page 5: OpenGL (ES) debugging

Agenda

Overview of available IHV toolsDebug callback

– Setup and implementation

– Verbosity control

– Noise filtering

API call tracing and replaying– Using apitrace

– Annotating the call trace

Resource leak checking

Page 6: OpenGL (ES) debugging

NVIDIA Nsight

Page 7: OpenGL (ES) debugging

NVIDIA Nsight (cont.)

Supports CUDA, OpenGL and Direct3DPlugin for Visual Studio and EclipseVery good feature set

– Including debugging shaders just like CPU code! See [PLASTIC13]

– Operation on one machine is slow, it's suggested to have two (sic!)

Hardware limitations– Recent NVIDIA GPUs only

Software limitations– Windows only (Visual Studio edition)

– Windows or Linux (Eclipse edition)

– OpenGL 4.2 or newer

Page 8: OpenGL (ES) debugging

AMD CodeXL

Page 9: OpenGL (ES) debugging

AMD CodeXL (cont.)

Supports OpenCL, OpenGL and advanced AMD CPU features

Stand-alone applicaiton + plugin for Visual StudioReasonable feature set

– Includes functionality of gDEBugger

– No shader debugging (although OpenCL kernels can be debugged)

Hardware limitations– Some functionality limited to AMD GPUs

Page 10: OpenGL (ES) debugging

AMD GPU PerfStudio

Page 11: OpenGL (ES) debugging

AMD GPU PerfStudio (cont.)

Supports OpenGL and Direct3DCross-platform client, Windows stand-alone server/GUIReasonable feature set

– Shader debugging only for Direct3D

Hardware limitations– Some functionality limited to AMD GPUs

Software limitations– OpenGL 4.2 or newer

Page 12: OpenGL (ES) debugging

Intel Graphics Performance Analyzer

Page 13: OpenGL (ES) debugging

Intel Graphics Performance Analyzer (cont.)

Supports OpenGL ES and Direct3DWindows/Android client, Windows/Linux stand-alone

server/GUIReasonable feature set

– No shader debugging

Hardware limitations– Only Intel GPUs

Software limitations– Windows or Android only

– OpenGL ES only (Android)

Page 14: OpenGL (ES) debugging

Agenda

Overview of available IHV toolsDebug callback

– Setup and implementation

– Verbosity control

– Noise filtering

API call tracing and replaying– Using apitrace

– Annotating the call trace

Resource leak checking

Page 15: OpenGL (ES) debugging

Ye Olde Way

Call glGetError() after each OpenGL callGet 1 of 8 (sic!) error codesLook the call up in the manualSee what this particular error means in this particular

contextCheck which of the parameters was wrong

– Usually by attaching a regular debugger and replaying the scenario

…This sucks!

Page 16: OpenGL (ES) debugging

Ye Olde Way

Call glGetError() after each OpenGL callGet 1 of 8 (sic!) error codesLook the call up in the manualSee what this particular error means in this particular

contextCheck which of the parameters was wrong

– Usually by attaching a regular debugger and replaying the scenario

…This sucks! used to suck ☺

Page 17: OpenGL (ES) debugging

Debug callback

Never call glGetError() again!Much more detailed information

– Including Performance tips from the driver

– Good to check what different drivers say

May not work without a debug OpenGL context– GLX_CONTEXT_DEBUG_BIT_ARB

– WGL_CONTEXT_DEBUG_BIT_ARB

Page 18: OpenGL (ES) debugging

Debug callback (cont.)

Provided by either of (ABI-compatible):GL_KHR_debug orGL_ARB_debug_output

Page 19: OpenGL (ES) debugging

Debug callback (cont.)

void callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam);

Filter by source, type,

severity or individual messages

Page 20: OpenGL (ES) debugging

Debug callback (cont.)

Verbosity can be controlled– glDebugMessageControl[ARB]()

– [OPENGL01][OPENGL02]

Turn to 11 for valuable perf information:– Which memory type a buffer is backed by

– Memory wasted by unused mip levels

– More!

– glDebugMessageControl(GL_DONT_CARE,GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);

Page 21: OpenGL (ES) debugging

Agenda

Overview of available IHV toolsDebug callback

– Setup and implementation

– Verbosity control

– Noise filtering

API call tracing and replaying– Using apitrace

– Annotating the call trace

Resource leak checking

Page 22: OpenGL (ES) debugging

API call tracing

Record a trace of the run of the applicationReplay and review the trace

– Look up OpenGL state at a particular call

– Inspect state variables, resources and objects:

● Textures● Shaders● Buffers● …

apitrace or VOGL

Page 23: OpenGL (ES) debugging

Well, this is not helpful...

Page 24: OpenGL (ES) debugging

Much better!

Page 25: OpenGL (ES) debugging

Annotating the call stream

Page 26: OpenGL (ES) debugging

Annotating the call stream (cont.)

All aforementioned extensions supported by apitrace even if not by driver

Recommended: GL_KHR_debug– Best vendor coverage

● GL_KHR_debug is slightly less common● GL_ARB_debug_output has no debug groups or object labels

– Emulation wrapper for Mac OS X [PIPELINE13]

Page 27: OpenGL (ES) debugging

Annotating the call stream (cont.)

Call grouping– glPushDebugGroup()/glPopDebugGroup() (KHR_debug)

One-off messages– glDebugMessageInsert() (KHR_debug/ARB_debug_output)

– glStringMarkerGREMEDY() (GREMEDY_string_marker)

Page 28: OpenGL (ES) debugging

Object labelling

Buffer, shader, program, vertex array, query, program pipeline, transform feedback, sampler, texture, render buffer, frame buffer, display list

– glObjectLabel(), glGetObjectLabel()

Sync objects– glObjectPtrLabel(), glGetObjectPtrLabel()

Page 29: OpenGL (ES) debugging

Annotation caveats

Multi-threaded/multi-context OpenGL application may break debug group hierarchy

glDebugMessageInsert() calls the debug callback, polluting error streams

– Workaround: drop if source == GL_DEBUG_SOURCE_APPLICATION

Page 30: OpenGL (ES) debugging

Agenda

Overview of available IHV toolsDebug callback

– Setup and implementation

– Verbosity control

– Noise filtering

API call tracing and replaying– Using apitrace

– Annotating the call trace

Resource leak checking

Page 31: OpenGL (ES) debugging

Resource leak checking

When created correctly (glGen*()), object names are integers, consecutive & recycled

– Not necessarily!

– Desktop GL names may be user-supplied

– GLES may be not recycled

Stupid idea: iterate over names [1; ∞)?

Page 32: OpenGL (ES) debugging

Resource leak checking (cont.)

Courtesy of Eric Lengyel & Fabian Giesenstatic void check_for_leaks(){

GLuint max_id = 10000; // better idea would be to keep track of assigned names.

GLuint id;

// if brute force doesn't work, you're not applying it hard enough

for ( id = 1 ; id <= max_id ; id++ ) {

#define CHECK( type ) if ( glIs##type( id ) ) \ fprintf( stderr, "GLX: leaked " #type " handle 0x%x\n", (unsigned int) id )

CHECK( Texture );

CHECK( Buffer );

CHECK( Framebuffer );

CHECK( Renderbuffer );

CHECK( VertexArray );

CHECK( Shader );

CHECK( Program );

CHECK( ProgramPipeline );

#undef CHECK

}

}

Page 33: OpenGL (ES) debugging

Takeaway

IHV tools are cool, but complex & have their limits– Valuable, so pick what works best for your HW+SW combo

Debug callbacks work everywhereDebug callbacks will show you exactly what the problem

is (most of the time)API call tracing works everywhere across-the-boardAnnotating the trace helps you find your wayResource leak checks? glIs*()!

Page 34: OpenGL (ES) debugging

@ l g o d l e w s k i @ n o r d i c g a m e s . a tt @ T h e I n e Q u a t i o n

K w w w . i n e q u a t i o n . o r g

Questions?

Page 35: OpenGL (ES) debugging

F u r t h e r N o r d i c G a m e s i n f o r m a t i o n :K w w w . n o r d i c g a m e s . a t

D e v e l o p m e n t i n f o r m a t i o n :K w w w . g r i m l o r e g a m e s . c o m

Thank you!

Page 36: OpenGL (ES) debugging

References

PLASTIC13 – Staniszewski, M., Szymczyk, M. ”Nsight” [link] OPENGL01 – “ARB_debug_output” [link] OPENGL02 – “KHR_debug” [link] PIPELINE13 – Menzer, R. ”(Simulating) KHR_debug on MacOS X” [link]


Recommended