summaryrefslogtreecommitdiffstats
path: root/docs/MESA_program_debug.spec
blob: 67115532c25fc1b69af963fa806453a5dd998086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
Name

    MESA_program_debug

Name Strings

    GL_MESA_program_debug

Contact

    Brian Paul (brian_e_paul 'at' yahoo.com)

Status

    XXX - Not complete yet!!!

Version

    Last Modified Date: July 20, 2003
    Author Revision: 1.0
    $Date: 2003/07/21 04:23:32 $ $Revision: 1.1 $

Number

    TBD

Dependencies

    OpenGL 1.4 is required
    The extension is written against the OpenGL 1.4 specification.
    ARB_vertex_program or ARB_fragment_program or NV_vertex_program
    or NV_fragment_program is required.

Overview

    The extension provides facilities for implementing debuggers for
    vertex and fragment programs.

    The concept is that vertex and fragment program debuggers will be
    implemented outside of the GL as a utility package.  This extension
    only provides the minimal hooks required to implement a debugger.

    There are facilities to do the following:
    1. Query the current values of input, output and temporary registers.
    2. Query the current program position during execution.
    3. Have the GL call a user-specified function prior to executing
       each vertex or fragment instruction.

    The main feature is the ProgramCallbackMESA function.  It allows the
    user to register a callback function with the GL.  The callback will
    be called prior to executing each vertex or fragment program instruction.
    The callback function can determine whether to return immediately (to
    continue program execution) or stop and process user commands.

    From within the callback, the user may issue glGet* commands to
    query current GL state.  The GetProgramRegisterfvMESA function allows
    all program register values to be queried (such as temporaries,
    input attributes, and result registers).

    There are flags for enabling/disabling the program callbacks.

    The current execution position (as an offset from the start of the
    program string) can be queried with
    GetIntegerv(GL_FRAGMENT_PROGRAM_POSITION_MESA, &pos) or
    GetIntegerv(GL_VERTEX_PROGRAM_POSITION_MESA, &pos).


IP Status

    None

Issues

    1. Is this the right model for a debugger?

       It seems prudent to minimize the scope of this extension and leave
       it up to the developer (or developer community) to write (a)
       debugger(s) that layer on top of this extension.

       If the debugger were fully implemented within the GL it's not
       clear how terminal and GUI-based interfaces would work, for
       example.

    2. There aren't any other extensions that register callbacks with
       the GL.  Isn't there another solution?

       If we want to be able to single-step through vertex/fragment
       programs I don't see another way to do it.

    3. How do we prevent the user from doing something crazy in the
       callback function, like trying to call glBegin?

       The rule is that the callback function can only issue glGet*()
       functions and no other GL commands.  It could be difficult to
       enforce this, however.  Therefore, calling any non-get GL
       command from within the callback will result in undefined
       results.    

    4. Is this extension amenable to hardware implementation?

       Unresolved, but we'd hope so.  Perhaps the GL implementation
       will have to fall back to a software path when debugging.


New Procedures and Functions (and datatypes)

    typedef void (*programcallbackMESA)(enum target, void *data)

    void ProgramCallbackMESA(enum target, programcallbackMESA callback,
                             void *data)

    void GetProgramRegisterfvMESA(enum target, sizei len,
                                  const ubyte *registerName, float *v)

New Tokens

    Accepted by the <cap> parameter of Enable, Disable, IsEnabled,
    GetBooleanv, GetDoublev, GetFloatv and GetIntegerv:

        FRAGMENT_PROGRAM_CALLBACK_MESA      0x????
        VERTEX_PROGRAM_CALLBACK_MESA        0x????

    Accepted by the <pname> parameter GetBooleanv, GetDoublev,
    GetFloatv and GetIntegerv:

        FRAGMENT_PROGRAM_POSITION_MESA      0x????
        VERTEX_PROGRAM_POSITION_MESA        0x????

    Accepted by the <pname> parameter of GetPointerv:

        FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA 0x????
        FRAGMENT_PROGRAM_CALLBACK_DATA_MESA 0x????
        VERTEX_PROGRAM_CALLBACK_FUNC_MESA   0x????
        VERTEX_PROGRAM_CALLBACK_DATA_MESA   0x????

Additions to Chapter 2 of the OpenGL 1.4 Specification (OpenGL Operation)

    None.

Additions to Chapter 3 of the OpenGL 1.4 Specification (Rasterization)

    None.

Additions to Chapter 4 of the OpenGL 1.4 Specification (Per-Fragment
Operations and the Frame Buffer)

    None.

Additions to Chapter 5 of the OpenGL 1.4 Specification (Special Functions)

    XXX Document ProgramCallbackMESA here

    Add to the list of functions which cannot be included in display
    lists:  ProgramCallbackMESA.


Additions to Chapter 6 of the OpenGL 1.4 Specification (State and
State Requests)

    XXX document GetProgramRegisterfvMESA here



Additions to Appendix A of the OpenGL 1.4 Specification (Invariance)

    None.

Additions to the AGL/GLX/WGL Specifications

    None.

GLX Protocol

    XXX TBD

Dependencies on NV_vertex_program and NV_fragment_program

    If NV_vertex_program and/or NV_fragment_program are supported,
    vertex and/or fragment programs defined by those extensions may
    be debugged as well.  Register queries will use the syntax used
    by those extensions (i.e. "v[X]" to query vertex attributes,
    "o[X]" for vertex outputs, etc.)

Errors

    INVALID_OPERATION is generated if ProgramCallbackMESA is called
    between Begin and End.

    INVALID_ENUM is generated by ProgramCallbackMESA if <target> is not
    a supported vertex or fragment program type.

    Note: INVALID_OPERAION IS NOT generated by GetProgramRegisterfvMESA,
    GetBooleanv, GetDoublev, GetFloatv, or GetIntegerv if called between
    Begin and End.
    These functions may be called from the user-provided callback function
    which is called between Begin/End.

    INVALID_ENUM is generated by ProgramCallbackMESA,
    GetProgramRegisterfvMESA if <target> is not a program target supported
    by ARB_vertex_program, ARB_fragment_program (or NV_vertex_program or
    NV_fragment_program).

    INVALID_VALUE is generated by GetProgramRegisterfvMESA if <registerName>
    is not a recognized program register.

    INVALID_OPERATION is generated by GetProgramRegisterfvMESA when a
    register query is attempted for a program target that's not currently
    being executed.


New State

    XXX finish

(table 6.N, p. ###)
                                                            Initial
    Get Value                            Type Get Command   Value    Description  Sec.  Attribute
    ---------                            ---- -----------   -----    -----------  ----  ---------
    FRAGMENT_PROGRAM_CALLBACK_MESA        B   IsEnabled     FALSE    XXX          XXX   enable
    VERTEX_PROGRAM_CALLBACK_MESA          B   IsEnabled     FALSE    XXX          XXX   enable
    FRAGMENT_PROGRAM_POSITION_MESA        Z+  GetIntegerv   -1       XXX          XXX   -
    VERTEX_PROGRAM_POSITION_MESA          Z+  GetIntegerv   -1       XXX          XXX   -
    FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA   P   GetPointerv   NULL     XXX          XXX   -
    VERTEX_PROGRAM_CALLBACK_FUNC_MESA     P   GetPointerv   NULL     XXX          XXX   -
    FRAGMENT_PROGRAM_CALLBACK_DATA_MESA   P   GetPointerv   NULL     XXX          XXX   -
    VERTEX_PROGRAM_CALLBACK_DATA_MESA     P   GetPointerv   NULL     XXX          XXX   -

    XXX more?

New Implementation Dependent State

    None.

Revision History

    8 July 2003
        Initial draft. (Brian Paul)
    11 July 2003
        Second draft. (Brian Paul)
    20 July 2003
        Third draft.  Lots of fundamental changes. (Brian Paul)

Example Usage

/* This is called by the GL when the vertex program is executing.
 * We can only make glGet* calls from within this function!
 */
void DebugCallback(GLenum target, GLvoid *data)
{
   GLint pos;
   GLuint i;

   /* Get PC and current instruction string */
   glGetIntegerv(GL_VERTEX_PROGRAM_POSITION_ARB, &pos);

   printf("Current position: %d\n", pos);

   printf("Current temporary registers:\n");
   for (i = 0; i < 4; i++) {
      GLfloat v[4];
      char s[10];
      sprintf(s, "R%d", i);
      glGetProgramRegisterfvMESA(GL_VERTEX_PROGRAM_ARB, strlen(s), s, v);
      printf("R%d = %g, %g, %g, %g\n", i, v[0], v[1], v[2], v[3]);
   }
}


   /*
    * elsewhere...
    */

   /* Register our debugger callback function */
   glProgramCallbackMESA(GL_VERTEX_PROGRAM_ARB, DebugCallback, NULL);
   glEnable(GL_VERTEX_PROGRAM_CALLBACK_MESA);

   /* define/bind a vertex program */

   glEnable(GL_VERTEX_PROGRAM);

   /* render something */
   glBegin(GL_POINTS);
   glVertex2f(0, 0);
   glEnd();