1848b8605SmrgName
2848b8605Smrg
3848b8605Smrg     MESA_trace
4848b8605Smrg
5848b8605SmrgName Strings
6848b8605Smrg
7848b8605Smrg     GL_MESA_trace
8848b8605Smrg
9848b8605SmrgContact
10848b8605Smrg    
11848b8605Smrg    Bernd Kreimeier, Loki Entertainment, bk 'at' lokigames.com
12848b8605Smrg    Brian Paul, VA Linux Systems, Inc., brianp 'at' valinux.com
13848b8605Smrg
14848b8605SmrgStatus
15848b8605Smrg
16848b8605Smrg    Obsolete.
17848b8605Smrg
18848b8605SmrgVersion
19848b8605Smrg
20848b8605Smrg
21848b8605SmrgNumber
22848b8605Smrg
23848b8605Smrg    none yet
24848b8605Smrg
25848b8605SmrgDependencies
26848b8605Smrg
27848b8605Smrg    OpenGL 1.2 is required.
28848b8605Smrg    The extension is written against the OpenGL 1.2 Specification
29848b8605Smrg
30848b8605SmrgOverview
31848b8605Smrg
32848b8605Smrg    Provides the application with means to enable and disable logging
33848b8605Smrg    of GL calls including parameters as readable text. The verbosity
34848b8605Smrg    of the generated log can be controlled. The resulting logs are
35848b8605Smrg    valid (but possibly incomplete) C code and can be compiled and 
36848b8605Smrg    linked for standalone test programs. The set of calls and the 
37848b8605Smrg    amount of static data that is logged can be controlled at runtime. 
38848b8605Smrg    The application can add comments and enable or disable tracing of GL 
39848b8605Smrg    operations at any time. The data flow from the application to GL
40848b8605Smrg    and back is unaffected except for timing.
41848b8605Smrg
42848b8605Smrg    Application-side implementation of these features raises namespace
43848b8605Smrg    and linkage issues. In the driver dispatch table a simple
44848b8605Smrg    "chain of responsibility" pattern (aka "composable piepline")
45848b8605Smrg    can be added.
46848b8605Smrg
47848b8605SmrgIP Status
48848b8605Smrg
49848b8605Smrg    The extension spec is in the public domain.  The current implementation
50848b8605Smrg    in Mesa is covered by Mesa's XFree86-style copyright by the authors above.
51848b8605Smrg    This extension is partially inspired by the Quake2 QGL wrapper.
52848b8605Smrg
53848b8605SmrgIssues
54848b8605Smrg
55848b8605Smrg 
56848b8605Smrg    (1) Is this Extension obsolete because it can
57848b8605Smrg    be implemented as a wrapper DLL?
58848b8605Smrg
59848b8605Smrg      RESOLVED: No. While certain operating systems (Win32) provide linkers 
60848b8605Smrg      that facilitate this kind of solution, other operating systems
61848b8605Smrg      (Linux) do not support hierarchical linking, so a wrapper solution
62848b8605Smrg      would result in symbol collisions.
63848b8605Smrg      Further, IHV's might have builtin support for tracing GL execution 
64848b8605Smrg      that enjoys privileged access, or that they do not wish to separate
65848b8605Smrg      the tracing code from their driver code base.
66848b8605Smrg
67848b8605Smrg    (2) Should the Trace API explicitely support the notion of "frames? 
68848b8605Smrg    This would require hooking into glXSwapBuffers calls as well.
69848b8605Smrg
70848b8605Smrg      RESOLVED: No. The application can use NewTraceMESA/EndTraceMESA
71848b8605Smrg      and TraceComment along with external parsing tools to split the 
72848b8605Smrg      trace into frames, in whatever way considered adequate.
73848b8605Smrg
74848b8605Smrg    (2a) Should GLX calls be traced?
75848b8605Smrg
76848b8605Smrg      PBuffers and other render-to-texture solutions demonstrate that
77848b8605Smrg      context level commands beyond SwapBuffers might have to be
78848b8605Smrg      traced. The GL DLL exports the entry points, so this would not
79848b8605Smrg      be out of the question. 
80848b8605Smrg
81848b8605Smrg    (3) Should the specification mandate the actual output format?
82848b8605Smrg
83848b8605Smrg      RESOLVED: No. It is sufficient to guarantee that all data and commands 
84848b8605Smrg      will be traced as requested by Enable/DisableTraceMESA, in the order
85848b8605Smrg      encountered. Whether the resulting trace is available as a readable 
86848b8605Smrg      text file, binary metafile, compilable source code, much less which 
87848b8605Smrg      indentation and formatting has been used, is up to the implementation. 
88848b8605Smrg      For the same reason this specification does not enforce or prohibit
89848b8605Smrg      additional information added to the trace (statistics, profiling/timing, 
90848b8605Smrg      warnings on possible error conditions).
91848b8605Smrg
92848b8605Smrg    (4) Should the comment strings associated with names and pointer (ranges) 
93848b8605Smrg    be considered persistent state?
94848b8605Smrg
95848b8605Smrg      RESOLVED: No. The implementation is not forced to use this information 
96848b8605Smrg      on subsequent occurences of name/pointer, and is free to consider it 
97848b8605Smrg      transient state.
98848b8605Smrg 
99848b8605Smrg    (5) Should comment commands be prohibited between Begin/End?
100848b8605Smrg
101848b8605Smrg      RESOLVED: Yes, with the exception of TraceCommentMESA. TraceCommentMESA 
102848b8605Smrg      is transient, the other commands might cause storage of persistent
103848b8605Smrg      data in the context. There is no need to have the ability mark names 
104848b8605Smrg      or pointers between Begin and End.
105848b8605Smrg
106848b8605Smrg
107848b8605SmrgNew Procedures and Functions
108848b8605Smrg 
109848b8605Smrg    void NewTraceMESA( bitfield mask, const ubyte * traceName )
110848b8605Smrg
111848b8605Smrg    void EndTraceMESA( void )
112848b8605Smrg
113848b8605Smrg    void EnableTraceMESA( bitfield mask )
114848b8605Smrg
115848b8605Smrg    void DisableTraceMESA( bitfield mask )
116848b8605Smrg
117848b8605Smrg    void TraceAssertAttribMESA( bitfield attribMask )
118848b8605Smrg
119848b8605Smrg    void TraceCommentMESA( const ubyte* comment )
120848b8605Smrg
121848b8605Smrg    void TraceTextureMESA( uint name, const ubyte* comment )
122848b8605Smrg
123848b8605Smrg    void TraceListMESA( uint name, const ubyte* comment )
124848b8605Smrg
125848b8605Smrg    void TracePointerMESA( void* pointer, const ubyte* comment )
126848b8605Smrg
127848b8605Smrg    void TracePointerRangeMESA( const void* first, 
128848b8605Smrg                                const void* last, 
129848b8605Smrg                                const ubyte* comment ) 
130848b8605Smrg
131848b8605SmrgNew Tokens
132848b8605Smrg 
133848b8605Smrg    Accepted by the <mask> parameter of EnableTrace and DisableTrace:
134848b8605Smrg
135848b8605Smrg       TRACE_ALL_BITS_MESA           0xFFFF
136848b8605Smrg       TRACE_OPERATIONS_BIT_MESA     0x0001
137848b8605Smrg       TRACE_PRIMITIVES_BIT_MESA     0x0002
138848b8605Smrg       TRACE_ARRAYS_BIT_MESA         0x0004
139848b8605Smrg       TRACE_TEXTURES_BIT_MESA       0x0008
140848b8605Smrg       TRACE_PIXELS_BIT_MESA         0x0010
141848b8605Smrg       TRACE_ERRORS_BIT_MESA         0x0020
142848b8605Smrg
143848b8605Smrg    Accepted by the <pname> parameter of GetIntegerv, GetBooleanv,
144848b8605Smrg    GetFloatv, and GetDoublev:
145848b8605Smrg
146848b8605Smrg       TRACE_MASK_MESA               0x8755
147848b8605Smrg
148848b8605Smrg    Accepted by the <pname> parameter to GetString:
149848b8605Smrg
150848b8605Smrg       TRACE_NAME_MESA               0x8756
151848b8605Smrg
152848b8605Smrg
153848b8605SmrgAdditions to Chapter 2 of the OpenGL 1.2.1 Specification (OpenGL Operation)
154848b8605Smrg
155848b8605Smrg    None.
156848b8605Smrg
157848b8605SmrgAdditions to Chapter 3 of the OpenGL 1.2.1 Specification (OpenGL Operation)
158848b8605Smrg
159848b8605Smrg    None.
160848b8605Smrg
161848b8605SmrgAdditions to Chapter 4 of the OpenGL 1.2.1 Specification (OpenGL Operation)
162848b8605Smrg
163848b8605Smrg    None.
164848b8605Smrg
165848b8605SmrgAdditions to Chapter 5 of the OpenGL 1.2.1 Specification (Special Functions)
166848b8605Smrg
167848b8605Smrg    Add a new section:
168848b8605Smrg
169848b8605Smrg    5.7 Tracing
170848b8605Smrg
171848b8605Smrg    The tracing facility is used to record the execution of a GL program
172848b8605Smrg    to a human-readable log.  The log appears as a sequence of GL commands
173848b8605Smrg    using C syntax.  The primary intention of tracing is to aid in program
174848b8605Smrg    debugging.
175848b8605Smrg
176848b8605Smrg    A trace is started with the command
177848b8605Smrg
178848b8605Smrg      void NewTraceMESA( bitfield mask, const GLubyte * traceName )
179848b8605Smrg
180848b8605Smrg    <mask> may be any value accepted by PushAttrib and specifies a set of
181848b8605Smrg    attribute groups.  The state values included in those attribute groups
182848b8605Smrg    is written to the trace as a sequence of GL commands.
183848b8605Smrg
184848b8605Smrg    <traceName> specifies a name or label for the trace.  It is expected
185848b8605Smrg    that <traceName> will be interpreted as a filename in most implementations.
186848b8605Smrg
187848b8605Smrg    A trace is ended by calling the command
188848b8605Smrg
189848b8605Smrg      void EndTraceMESA( void )
190848b8605Smrg
191848b8605Smrg    It is illegal to call NewTraceMESA or EndTraceMESA between Begin and End. 
192848b8605Smrg
193848b8605Smrg    The commands
194848b8605Smrg
195848b8605Smrg      void EnableTraceMESA( bitfield mask )
196848b8605Smrg      void DisableTraceMESA( bitfield mask )
197848b8605Smrg
198848b8605Smrg    enable or disable tracing of different classes of GL commands.
199848b8605Smrg    <mask> may be the union of any of TRACE_OPERATIONS_BIT_MESA,
200848b8605Smrg    TRACE_PRIMITIVES_BIT_MESA, TRACE_ARRAYS_BIT_MESA, TRACE_TEXTURES_BIT_MESA,
201848b8605Smrg    and TRACE_PIXELS_BIT_MESA.  The special token TRACE_ALL_BITS_MESA
202848b8605Smrg    indicates all classes of commands are to be logged.
203848b8605Smrg
204848b8605Smrg    TRACE_OPERATIONS_BIT_MESA controls logging of all commands outside of
205848b8605Smrg    Begin/End, including Begin/End.
206848b8605Smrg  
207848b8605Smrg    TRACE_PRIMITIVES_BIT_MESA controls logging of all commands inside of
208848b8605Smrg    Begin/End, including Begin/End.
209848b8605Smrg 
210848b8605Smrg    TRACE_ARRAYS_BIT_MESA controls logging of VertexPointer, NormalPointer,
211848b8605Smrg    ColorPointer, IndexPointer, TexCoordPointer and EdgeFlagPointer commands.
212848b8605Smrg
213848b8605Smrg    TRACE_TEXTURES_BIT_MESA controls logging of texture data dereferenced by
214848b8605Smrg    TexImage1D, TexImage2D, TexImage3D, TexSubImage1D, TexSubImage2D, and
215848b8605Smrg    TexSubImage3D commands.
216848b8605Smrg
217848b8605Smrg    TRACE_PIXELS_BIT_MESA controls logging of image data dereferenced by
218848b8605Smrg    Bitmap and DrawPixels commands.
219848b8605Smrg
220848b8605Smrg    TRACE_ERRORS_BIT_MESA controls logging of all errors. If this bit is 
221848b8605Smrg    set, GetError will be executed whereever applicable, and the result will 
222848b8605Smrg    be added to the trace as a comment. The error returns are cached and 
223848b8605Smrg    returned to the application on its GetError calls. If the user does not 
224848b8605Smrg    wish the additional GetError calls to be performed, this bit should not
225848b8605Smrg    be set.
226848b8605Smrg    
227848b8605Smrg    The command
228848b8605Smrg
229848b8605Smrg      void TraceCommentMESA( const ubyte* comment )
230848b8605Smrg
231848b8605Smrg    immediately adds the <comment> string to the trace output, surrounded
232848b8605Smrg    by C-style comment delimiters.
233848b8605Smrg
234848b8605Smrg    The commands
235848b8605Smrg
236848b8605Smrg      void TraceTextureMESA( uint name, const ubyte* comment )
237848b8605Smrg      void TraceListMESA( uint name, const ubyte* comment )
238848b8605Smrg
239848b8605Smrg    associates <comment> with the texture object or display list specified
240848b8605Smrg    by <name>.  Logged commands which reference the named texture object or
241848b8605Smrg    display list will be annotated with <comment>.  If IsTexture(name) or
242848b8605Smrg    IsList(name) fail (respectively) the command is quietly ignored.
243848b8605Smrg
244848b8605Smrg    The commands
245848b8605Smrg
246848b8605Smrg      void TracePointerMESA( void* pointer, const ubyte* comment )
247848b8605Smrg
248848b8605Smrg      void TracePointerRangeMESA( const void* first, 
249848b8605Smrg                                  const void* last,
250848b8605Smrg                                  const ubyte* comment ) 
251848b8605Smrg
252848b8605Smrg    associate <comment> with the address specified by <pointer> or with
253848b8605Smrg    a range of addresses specified by <first> through <last>.
254848b8605Smrg    Any logged commands which reference <pointer> or an address between
255848b8605Smrg    <first> and <last> will be annotated with <comment>.
256848b8605Smrg
257848b8605Smrg    The command
258848b8605Smrg
259848b8605Smrg      void TraceAssertAttribMESA( bitfield attribMask )
260848b8605Smrg
261848b8605Smrg    will add GL state queries and assertion statements to the log to
262848b8605Smrg    confirm that the current state at the time TraceAssertAttrib is
263848b8605Smrg    executed matches the current state when the trace log is executed
264848b8605Smrg    in the future.
265848b8605Smrg
266848b8605Smrg    <attribMask> is any value accepted by PushAttrib and specifies
267848b8605Smrg    the groups of state variables which are to be asserted.
268848b8605Smrg
269848b8605Smrg    The commands NewTraceMESA, EndTraceMESA, EnableTraceMESA, DisableTraceMESA,
270848b8605Smrg    TraceAssertAttribMESA, TraceCommentMESA, TraceTextureMESA, TraceListMESA, 
271848b8605Smrg    TracePointerMESA and TracePointerRangeMESA are not compiled into display lists.
272848b8605Smrg
273848b8605Smrg
274848b8605Smrg    Examples:
275848b8605Smrg
276848b8605Smrg    The command NewTraceMESA(DEPTH_BUFFER_BIT, "log") will query the state
277848b8605Smrg    variables DEPTH_TEST, DEPTH_FUNC, DEPTH_WRITEMASK, and DEPTH_CLEAR_VALUE
278848b8605Smrg    to get the values <test>, <func>, <mask>, and <clear> respectively.
279848b8605Smrg    Statements equivalent to the following will then be logged:
280848b8605Smrg
281848b8605Smrg       glEnable(GL_DEPTH_TEST);   (if <test> is true)
282848b8605Smrg       glDisable(GL_DEPTH_TEST);  (if <test> is false)
283848b8605Smrg       glDepthFunc(<func>); 
284848b8605Smrg       glDepthMask(<mask>);
285848b8605Smrg       glClearDepth(<clear>);
286848b8605Smrg   
287848b8605Smrg
288848b8605Smrg    The command TraceAssertAttribMESA(DEPTH_BUFFER_BIT) will query the state
289848b8605Smrg    variables DEPTH_TEST, DEPTH_FUNC, DEPTH_WRITEMASK, and DEPTH_CLEAR_VALUE
290848b8605Smrg    to get the values <test>, <func>, <mask>, and <clear> respectively.
291848b8605Smrg    The resulting trace might then look will like this:
292848b8605Smrg
293848b8605Smrg    {
294848b8605Smrg      GLboolean b;
295848b8605Smrg      GLint i;
296848b8605Smrg      GLfloat f;
297848b8605Smrg      b = glIsEnabled(GL_DEPTH_TEST);
298848b8605Smrg      assert(b == <test>);
299848b8605Smrg      glGetIntegerv(GL_DEPTH_FUNC, &i);
300848b8605Smrg      assert(i == <func>);
301848b8605Smrg      glGetIntegerv(GL_DEPTH_MASK, &i);
302848b8605Smrg      assert(i == <mask>);
303848b8605Smrg      glGetFloatv(GL_DEPTH_CLEAR_VALUE, &f);
304848b8605Smrg      assert(f == <clear>);
305848b8605Smrg    }
306848b8605Smrg
307848b8605Smrg
308848b8605SmrgAdditions to Chapter 6 of the OpenGL 1.2.1 Specification 
309848b8605Smrg    (State and State Requests)
310848b8605Smrg
311848b8605Smrg    Querying TRACE_MASK_MESA with GetIntegerv, GetFloatv, GetBooleanv or
312848b8605Smrg    GetDoublev returns the current command class trace mask.
313848b8605Smrg
314848b8605Smrg    Querying TRACE_NAME_MESA with GetString returns the current trace name.
315848b8605Smrg
316848b8605Smrg
317848b8605SmrgAdditions to Appendix A of the OpenGL 1.2.1 Specification (Invariance)
318848b8605Smrg
319848b8605Smrg    The MESA_trace extension can be used in a way that does not affect data 
320848b8605Smrg    flow from application to OpenGL, as well as data flow from OpenGL to 
321848b8605Smrg    application, except for timing, possible print I/O. TRACE_ERRORS_BIT_MESA
322848b8605Smrg    will add additional GetError queries. Setting a trace mask with NewTraceMESA
323848b8605Smrg    as well as use of TraceAssertAttribMESA might cause additional state queries.
324848b8605Smrg    With the possible exception of performance, OpenGL rendering should not be
325848b8605Smrg    affected at all by a properly chosen logging operation.
326848b8605Smrg
327848b8605SmrgAdditions to the AGL/GLX/WGL Specifications
328848b8605Smrg
329848b8605Smrg    None.
330848b8605Smrg
331848b8605SmrgGLX Protocol
332848b8605Smrg
333848b8605Smrg    None. The logging operation is carried out client-side, by exporting
334848b8605Smrg    entry points to the wrapper functions that execute the logging operation.
335848b8605Smrg
336848b8605SmrgErrors
337848b8605Smrg
338848b8605Smrg    INVALID_OPERATION is generated if any trace command except TraceCommentMESA
339848b8605Smrg    is called between Begin and End.
340848b8605Smrg
341848b8605SmrgNew State
342848b8605Smrg
343848b8605Smrg    The current trace name and current command class mask are stored
344848b8605Smrg    per-context.
345848b8605Smrg
346848b8605SmrgNew Implementation Dependent State
347848b8605Smrg
348848b8605Smrg    None.
349848b8605Smrg
350848b8605SmrgRevision History
351848b8605Smrg
352848b8605Smrg  * Revision 0.1 - Initial draft from template (bk000415)
353848b8605Smrg  * Revision 0.2 - Draft (bk000906)
354848b8605Smrg  * Revision 0.3 - Draft (bk000913)
355848b8605Smrg  * Revision 0.4 - Reworked text, fixed typos (bp000914)
356848b8605Smrg  * Revision 0.5 - Assigned final GLenum values (bp001103)
357848b8605Smrg  * Revision 0.6 - TRACE_ERRORS_BIT_MESA (bk000916)
358848b8605Smrg  * Revision 0.7 - Added MESA postfix (bk010126)
359848b8605Smrg
360