1bf215546Sopenharmony_ciName 2bf215546Sopenharmony_ci 3bf215546Sopenharmony_ci MESA_trace 4bf215546Sopenharmony_ci 5bf215546Sopenharmony_ciName Strings 6bf215546Sopenharmony_ci 7bf215546Sopenharmony_ci GL_MESA_trace 8bf215546Sopenharmony_ci 9bf215546Sopenharmony_ciContact 10bf215546Sopenharmony_ci 11bf215546Sopenharmony_ci Bernd Kreimeier, Loki Entertainment, bk 'at' lokigames.com 12bf215546Sopenharmony_ci Brian Paul, VA Linux Systems, Inc., brianp 'at' valinux.com 13bf215546Sopenharmony_ci 14bf215546Sopenharmony_ciStatus 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_ci Obsolete. 17bf215546Sopenharmony_ci 18bf215546Sopenharmony_ciVersion 19bf215546Sopenharmony_ci 20bf215546Sopenharmony_ci 21bf215546Sopenharmony_ciNumber 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci none yet 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ciDependencies 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci OpenGL 1.2 is required. 28bf215546Sopenharmony_ci The extension is written against the OpenGL 1.2 Specification 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ciOverview 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci Provides the application with means to enable and disable logging 33bf215546Sopenharmony_ci of GL calls including parameters as readable text. The verbosity 34bf215546Sopenharmony_ci of the generated log can be controlled. The resulting logs are 35bf215546Sopenharmony_ci valid (but possibly incomplete) C code and can be compiled and 36bf215546Sopenharmony_ci linked for standalone test programs. The set of calls and the 37bf215546Sopenharmony_ci amount of static data that is logged can be controlled at runtime. 38bf215546Sopenharmony_ci The application can add comments and enable or disable tracing of GL 39bf215546Sopenharmony_ci operations at any time. The data flow from the application to GL 40bf215546Sopenharmony_ci and back is unaffected except for timing. 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci Application-side implementation of these features raises namespace 43bf215546Sopenharmony_ci and linkage issues. In the driver dispatch table a simple 44bf215546Sopenharmony_ci "chain of responsibility" pattern (aka "composable piepline") 45bf215546Sopenharmony_ci can be added. 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ciIP Status 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci The extension spec is in the public domain. The current implementation 50bf215546Sopenharmony_ci in Mesa is covered by Mesa's XFree86-style copyright by the authors above. 51bf215546Sopenharmony_ci This extension is partially inspired by the Quake2 QGL wrapper. 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ciIssues 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci (1) Is this Extension obsolete because it can 57bf215546Sopenharmony_ci be implemented as a wrapper DLL? 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci RESOLVED: No. While certain operating systems (Win32) provide linkers 60bf215546Sopenharmony_ci that facilitate this kind of solution, other operating systems 61bf215546Sopenharmony_ci (Linux) do not support hierarchical linking, so a wrapper solution 62bf215546Sopenharmony_ci would result in symbol collisions. 63bf215546Sopenharmony_ci Further, IHV's might have builtin support for tracing GL execution 64bf215546Sopenharmony_ci that enjoys privileged access, or that they do not wish to separate 65bf215546Sopenharmony_ci the tracing code from their driver code base. 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci (2) Should the Trace API explicitely support the notion of "frames? 68bf215546Sopenharmony_ci This would require hooking into glXSwapBuffers calls as well. 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci RESOLVED: No. The application can use NewTraceMESA/EndTraceMESA 71bf215546Sopenharmony_ci and TraceComment along with external parsing tools to split the 72bf215546Sopenharmony_ci trace into frames, in whatever way considered adequate. 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci (2a) Should GLX calls be traced? 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci PBuffers and other render-to-texture solutions demonstrate that 77bf215546Sopenharmony_ci context level commands beyond SwapBuffers might have to be 78bf215546Sopenharmony_ci traced. The GL DLL exports the entry points, so this would not 79bf215546Sopenharmony_ci be out of the question. 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci (3) Should the specification mandate the actual output format? 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci RESOLVED: No. It is sufficient to guarantee that all data and commands 84bf215546Sopenharmony_ci will be traced as requested by Enable/DisableTraceMESA, in the order 85bf215546Sopenharmony_ci encountered. Whether the resulting trace is available as a readable 86bf215546Sopenharmony_ci text file, binary metafile, compilable source code, much less which 87bf215546Sopenharmony_ci indentation and formatting has been used, is up to the implementation. 88bf215546Sopenharmony_ci For the same reason this specification does not enforce or prohibit 89bf215546Sopenharmony_ci additional information added to the trace (statistics, profiling/timing, 90bf215546Sopenharmony_ci warnings on possible error conditions). 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci (4) Should the comment strings associated with names and pointer (ranges) 93bf215546Sopenharmony_ci be considered persistent state? 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci RESOLVED: No. The implementation is not forced to use this information 96bf215546Sopenharmony_ci on subsequent occurences of name/pointer, and is free to consider it 97bf215546Sopenharmony_ci transient state. 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci (5) Should comment commands be prohibited between Begin/End? 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci RESOLVED: Yes, with the exception of TraceCommentMESA. TraceCommentMESA 102bf215546Sopenharmony_ci is transient, the other commands might cause storage of persistent 103bf215546Sopenharmony_ci data in the context. There is no need to have the ability mark names 104bf215546Sopenharmony_ci or pointers between Begin and End. 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ciNew Procedures and Functions 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci void NewTraceMESA( bitfield mask, const ubyte * traceName ) 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci void EndTraceMESA( void ) 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ci void EnableTraceMESA( bitfield mask ) 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci void DisableTraceMESA( bitfield mask ) 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci void TraceAssertAttribMESA( bitfield attribMask ) 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci void TraceCommentMESA( const ubyte* comment ) 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci void TraceTextureMESA( uint name, const ubyte* comment ) 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci void TraceListMESA( uint name, const ubyte* comment ) 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci void TracePointerMESA( void* pointer, const ubyte* comment ) 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci void TracePointerRangeMESA( const void* first, 128bf215546Sopenharmony_ci const void* last, 129bf215546Sopenharmony_ci const ubyte* comment ) 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ciNew Tokens 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci Accepted by the <mask> parameter of EnableTrace and DisableTrace: 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci TRACE_ALL_BITS_MESA 0xFFFF 136bf215546Sopenharmony_ci TRACE_OPERATIONS_BIT_MESA 0x0001 137bf215546Sopenharmony_ci TRACE_PRIMITIVES_BIT_MESA 0x0002 138bf215546Sopenharmony_ci TRACE_ARRAYS_BIT_MESA 0x0004 139bf215546Sopenharmony_ci TRACE_TEXTURES_BIT_MESA 0x0008 140bf215546Sopenharmony_ci TRACE_PIXELS_BIT_MESA 0x0010 141bf215546Sopenharmony_ci TRACE_ERRORS_BIT_MESA 0x0020 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci Accepted by the <pname> parameter of GetIntegerv, GetBooleanv, 144bf215546Sopenharmony_ci GetFloatv, and GetDoublev: 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci TRACE_MASK_MESA 0x8755 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci Accepted by the <pname> parameter to GetString: 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci TRACE_NAME_MESA 0x8756 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ciAdditions to Chapter 2 of the OpenGL 1.2.1 Specification (OpenGL Operation) 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci None. 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ciAdditions to Chapter 3 of the OpenGL 1.2.1 Specification (OpenGL Operation) 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci None. 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ciAdditions to Chapter 4 of the OpenGL 1.2.1 Specification (OpenGL Operation) 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci None. 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ciAdditions to Chapter 5 of the OpenGL 1.2.1 Specification (Special Functions) 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci Add a new section: 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci 5.7 Tracing 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci The tracing facility is used to record the execution of a GL program 172bf215546Sopenharmony_ci to a human-readable log. The log appears as a sequence of GL commands 173bf215546Sopenharmony_ci using C syntax. The primary intention of tracing is to aid in program 174bf215546Sopenharmony_ci debugging. 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci A trace is started with the command 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci void NewTraceMESA( bitfield mask, const GLubyte * traceName ) 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci <mask> may be any value accepted by PushAttrib and specifies a set of 181bf215546Sopenharmony_ci attribute groups. The state values included in those attribute groups 182bf215546Sopenharmony_ci is written to the trace as a sequence of GL commands. 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_ci <traceName> specifies a name or label for the trace. It is expected 185bf215546Sopenharmony_ci that <traceName> will be interpreted as a filename in most implementations. 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci A trace is ended by calling the command 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci void EndTraceMESA( void ) 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci It is illegal to call NewTraceMESA or EndTraceMESA between Begin and End. 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci The commands 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci void EnableTraceMESA( bitfield mask ) 196bf215546Sopenharmony_ci void DisableTraceMESA( bitfield mask ) 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci enable or disable tracing of different classes of GL commands. 199bf215546Sopenharmony_ci <mask> may be the union of any of TRACE_OPERATIONS_BIT_MESA, 200bf215546Sopenharmony_ci TRACE_PRIMITIVES_BIT_MESA, TRACE_ARRAYS_BIT_MESA, TRACE_TEXTURES_BIT_MESA, 201bf215546Sopenharmony_ci and TRACE_PIXELS_BIT_MESA. The special token TRACE_ALL_BITS_MESA 202bf215546Sopenharmony_ci indicates all classes of commands are to be logged. 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci TRACE_OPERATIONS_BIT_MESA controls logging of all commands outside of 205bf215546Sopenharmony_ci Begin/End, including Begin/End. 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci TRACE_PRIMITIVES_BIT_MESA controls logging of all commands inside of 208bf215546Sopenharmony_ci Begin/End, including Begin/End. 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci TRACE_ARRAYS_BIT_MESA controls logging of VertexPointer, NormalPointer, 211bf215546Sopenharmony_ci ColorPointer, IndexPointer, TexCoordPointer and EdgeFlagPointer commands. 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci TRACE_TEXTURES_BIT_MESA controls logging of texture data dereferenced by 214bf215546Sopenharmony_ci TexImage1D, TexImage2D, TexImage3D, TexSubImage1D, TexSubImage2D, and 215bf215546Sopenharmony_ci TexSubImage3D commands. 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci TRACE_PIXELS_BIT_MESA controls logging of image data dereferenced by 218bf215546Sopenharmony_ci Bitmap and DrawPixels commands. 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci TRACE_ERRORS_BIT_MESA controls logging of all errors. If this bit is 221bf215546Sopenharmony_ci set, GetError will be executed whereever applicable, and the result will 222bf215546Sopenharmony_ci be added to the trace as a comment. The error returns are cached and 223bf215546Sopenharmony_ci returned to the application on its GetError calls. If the user does not 224bf215546Sopenharmony_ci wish the additional GetError calls to be performed, this bit should not 225bf215546Sopenharmony_ci be set. 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci The command 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci void TraceCommentMESA( const ubyte* comment ) 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci immediately adds the <comment> string to the trace output, surrounded 232bf215546Sopenharmony_ci by C-style comment delimiters. 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci The commands 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci void TraceTextureMESA( uint name, const ubyte* comment ) 237bf215546Sopenharmony_ci void TraceListMESA( uint name, const ubyte* comment ) 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci associates <comment> with the texture object or display list specified 240bf215546Sopenharmony_ci by <name>. Logged commands which reference the named texture object or 241bf215546Sopenharmony_ci display list will be annotated with <comment>. If IsTexture(name) or 242bf215546Sopenharmony_ci IsList(name) fail (respectively) the command is quietly ignored. 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci The commands 245bf215546Sopenharmony_ci 246bf215546Sopenharmony_ci void TracePointerMESA( void* pointer, const ubyte* comment ) 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_ci void TracePointerRangeMESA( const void* first, 249bf215546Sopenharmony_ci const void* last, 250bf215546Sopenharmony_ci const ubyte* comment ) 251bf215546Sopenharmony_ci 252bf215546Sopenharmony_ci associate <comment> with the address specified by <pointer> or with 253bf215546Sopenharmony_ci a range of addresses specified by <first> through <last>. 254bf215546Sopenharmony_ci Any logged commands which reference <pointer> or an address between 255bf215546Sopenharmony_ci <first> and <last> will be annotated with <comment>. 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci The command 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci void TraceAssertAttribMESA( bitfield attribMask ) 260bf215546Sopenharmony_ci 261bf215546Sopenharmony_ci will add GL state queries and assertion statements to the log to 262bf215546Sopenharmony_ci confirm that the current state at the time TraceAssertAttrib is 263bf215546Sopenharmony_ci executed matches the current state when the trace log is executed 264bf215546Sopenharmony_ci in the future. 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci <attribMask> is any value accepted by PushAttrib and specifies 267bf215546Sopenharmony_ci the groups of state variables which are to be asserted. 268bf215546Sopenharmony_ci 269bf215546Sopenharmony_ci The commands NewTraceMESA, EndTraceMESA, EnableTraceMESA, DisableTraceMESA, 270bf215546Sopenharmony_ci TraceAssertAttribMESA, TraceCommentMESA, TraceTextureMESA, TraceListMESA, 271bf215546Sopenharmony_ci TracePointerMESA and TracePointerRangeMESA are not compiled into display lists. 272bf215546Sopenharmony_ci 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci Examples: 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci The command NewTraceMESA(DEPTH_BUFFER_BIT, "log") will query the state 277bf215546Sopenharmony_ci variables DEPTH_TEST, DEPTH_FUNC, DEPTH_WRITEMASK, and DEPTH_CLEAR_VALUE 278bf215546Sopenharmony_ci to get the values <test>, <func>, <mask>, and <clear> respectively. 279bf215546Sopenharmony_ci Statements equivalent to the following will then be logged: 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_ci glEnable(GL_DEPTH_TEST); (if <test> is true) 282bf215546Sopenharmony_ci glDisable(GL_DEPTH_TEST); (if <test> is false) 283bf215546Sopenharmony_ci glDepthFunc(<func>); 284bf215546Sopenharmony_ci glDepthMask(<mask>); 285bf215546Sopenharmony_ci glClearDepth(<clear>); 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ci 288bf215546Sopenharmony_ci The command TraceAssertAttribMESA(DEPTH_BUFFER_BIT) will query the state 289bf215546Sopenharmony_ci variables DEPTH_TEST, DEPTH_FUNC, DEPTH_WRITEMASK, and DEPTH_CLEAR_VALUE 290bf215546Sopenharmony_ci to get the values <test>, <func>, <mask>, and <clear> respectively. 291bf215546Sopenharmony_ci The resulting trace might then look will like this: 292bf215546Sopenharmony_ci 293bf215546Sopenharmony_ci { 294bf215546Sopenharmony_ci GLboolean b; 295bf215546Sopenharmony_ci GLint i; 296bf215546Sopenharmony_ci GLfloat f; 297bf215546Sopenharmony_ci b = glIsEnabled(GL_DEPTH_TEST); 298bf215546Sopenharmony_ci assert(b == <test>); 299bf215546Sopenharmony_ci glGetIntegerv(GL_DEPTH_FUNC, &i); 300bf215546Sopenharmony_ci assert(i == <func>); 301bf215546Sopenharmony_ci glGetIntegerv(GL_DEPTH_MASK, &i); 302bf215546Sopenharmony_ci assert(i == <mask>); 303bf215546Sopenharmony_ci glGetFloatv(GL_DEPTH_CLEAR_VALUE, &f); 304bf215546Sopenharmony_ci assert(f == <clear>); 305bf215546Sopenharmony_ci } 306bf215546Sopenharmony_ci 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ciAdditions to Chapter 6 of the OpenGL 1.2.1 Specification 309bf215546Sopenharmony_ci (State and State Requests) 310bf215546Sopenharmony_ci 311bf215546Sopenharmony_ci Querying TRACE_MASK_MESA with GetIntegerv, GetFloatv, GetBooleanv or 312bf215546Sopenharmony_ci GetDoublev returns the current command class trace mask. 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci Querying TRACE_NAME_MESA with GetString returns the current trace name. 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_ciAdditions to Appendix A of the OpenGL 1.2.1 Specification (Invariance) 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci The MESA_trace extension can be used in a way that does not affect data 320bf215546Sopenharmony_ci flow from application to OpenGL, as well as data flow from OpenGL to 321bf215546Sopenharmony_ci application, except for timing, possible print I/O. TRACE_ERRORS_BIT_MESA 322bf215546Sopenharmony_ci will add additional GetError queries. Setting a trace mask with NewTraceMESA 323bf215546Sopenharmony_ci as well as use of TraceAssertAttribMESA might cause additional state queries. 324bf215546Sopenharmony_ci With the possible exception of performance, OpenGL rendering should not be 325bf215546Sopenharmony_ci affected at all by a properly chosen logging operation. 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ciAdditions to the AGL/GLX/WGL Specifications 328bf215546Sopenharmony_ci 329bf215546Sopenharmony_ci None. 330bf215546Sopenharmony_ci 331bf215546Sopenharmony_ciGLX Protocol 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_ci None. The logging operation is carried out client-side, by exporting 334bf215546Sopenharmony_ci entry points to the wrapper functions that execute the logging operation. 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ciErrors 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci INVALID_OPERATION is generated if any trace command except TraceCommentMESA 339bf215546Sopenharmony_ci is called between Begin and End. 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ciNew State 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci The current trace name and current command class mask are stored 344bf215546Sopenharmony_ci per-context. 345bf215546Sopenharmony_ci 346bf215546Sopenharmony_ciNew Implementation Dependent State 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_ci None. 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ciRevision History 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_ci * Revision 0.1 - Initial draft from template (bk000415) 353bf215546Sopenharmony_ci * Revision 0.2 - Draft (bk000906) 354bf215546Sopenharmony_ci * Revision 0.3 - Draft (bk000913) 355bf215546Sopenharmony_ci * Revision 0.4 - Reworked text, fixed typos (bp000914) 356bf215546Sopenharmony_ci * Revision 0.5 - Assigned final GLenum values (bp001103) 357bf215546Sopenharmony_ci * Revision 0.6 - TRACE_ERRORS_BIT_MESA (bk000916) 358bf215546Sopenharmony_ci * Revision 0.7 - Added MESA postfix (bk010126) 359bf215546Sopenharmony_ci 360