Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MESA_program_debug.spec 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. Name
  2. MESA_program_debug
  3. Name Strings
  4. GL_MESA_program_debug
  5. Contact
  6. Brian Paul (brian.paul 'at' tungstengraphics.com)
  7. Status
  8. XXX - Not complete yet!!!
  9. Version
  10. Last Modified Date: July 20, 2003
  11. Author Revision: 1.0
  12. $Date: 2004/03/25 01:42:41 $ $Revision: 1.4 $
  13. Number
  14. TBD
  15. Dependencies
  16. OpenGL 1.4 is required
  17. The extension is written against the OpenGL 1.4 specification.
  18. ARB_vertex_program or ARB_fragment_program or NV_vertex_program
  19. or NV_fragment_program is required.
  20. Overview
  21. The extension provides facilities for implementing debuggers for
  22. vertex and fragment programs.
  23. The concept is that vertex and fragment program debuggers will be
  24. implemented outside of the GL as a utility package. This extension
  25. only provides the minimal hooks required to implement a debugger.
  26. There are facilities to do the following:
  27. 1. Have the GL call a user-specified function prior to executing
  28. each vertex or fragment instruction.
  29. 2. Query the current program string's execution position.
  30. 3. Query the current values of intermediate program values.
  31. The main feature is the ProgramCallbackMESA function. It allows the
  32. user to register a callback function with the GL. The callback will
  33. be called prior to executing each vertex or fragment program instruction.
  34. From within the callback, the user may issue Get* commands to
  35. query current GL state. The GetProgramRegisterfvMESA function allows
  36. current program values to be queried (such as temporaries, input
  37. attributes, and result registers).
  38. There are flags for enabling/disabling the program callbacks.
  39. The current execution position (as an offset from the start of the
  40. program string) can be queried with
  41. GetIntegerv(GL_FRAGMENT_PROGRAM_POSITION_MESA, &pos) or
  42. GetIntegerv(GL_VERTEX_PROGRAM_POSITION_MESA, &pos).
  43. IP Status
  44. None
  45. Issues
  46. 1. Is this the right model for a debugger?
  47. It seems prudent to minimize the scope of this extension and leave
  48. it up to the developer (or developer community) to write debuggers
  49. that layer on top of this extension.
  50. If the debugger were fully implemented within the GL it's not
  51. clear how terminal and GUI-based interfaces would work, for
  52. example.
  53. 2. There aren't any other extensions that register callbacks with
  54. the GL. Isn't there another solution?
  55. If we want to be able to single-step through vertex/fragment
  56. programs I don't see another way to do it.
  57. 3. How do we prevent the user from doing something crazy in the
  58. callback function, like trying to call glBegin (leading to
  59. recursion)?
  60. The rule is that the callback function can only issue glGet*()
  61. functions and no other GL commands. It could be difficult to
  62. enforce this, however. Therefore, calling any non-get GL
  63. command from within the callback will result in undefined
  64. results.
  65. 4. Is this extension amenable to hardware implementation?
  66. Hopefully, but if not, the GL implementation will have to fall
  67. back to a software path when debugging. This may be acceptable
  68. for debugging.
  69. 5. What's the <data> parameter to ProgramCallbackMESA for?
  70. It's a common programming practice to associate a user-supplied
  71. value with callback functions.
  72. 6. Debuggers often allow one to modify intermediate program values,
  73. then continue. Does this extension support that?
  74. No.
  75. New Procedures and Functions (and datatypes)
  76. typedef void (*programcallbackMESA)(enum target, void *data)
  77. void ProgramCallbackMESA(enum target, programcallbackMESA callback,
  78. void *data)
  79. void GetProgramRegisterfvMESA(enum target, sizei len,
  80. const ubyte *registerName, float *v)
  81. New Tokens
  82. Accepted by the <cap> parameter of Enable, Disable, IsEnabled,
  83. GetBooleanv, GetDoublev, GetFloatv and GetIntegerv:
  84. FRAGMENT_PROGRAM_CALLBACK_MESA 0x8bb1
  85. VERTEX_PROGRAM_CALLBACK_MESA 0x8bb4
  86. Accepted by the <pname> parameter GetBooleanv, GetDoublev,
  87. GetFloatv and GetIntegerv:
  88. FRAGMENT_PROGRAM_POSITION_MESA 0x8bb0
  89. VERTEX_PROGRAM_POSITION_MESA 0x8bb4
  90. Accepted by the <pname> parameter of GetPointerv:
  91. FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA 0x8bb2
  92. FRAGMENT_PROGRAM_CALLBACK_DATA_MESA 0x8bb3
  93. VERTEX_PROGRAM_CALLBACK_FUNC_MESA 0x8bb6
  94. VERTEX_PROGRAM_CALLBACK_DATA_MESA 0x8bb7
  95. Additions to Chapter 2 of the OpenGL 1.4 Specification (OpenGL Operation)
  96. None.
  97. Additions to Chapter 3 of the OpenGL 1.4 Specification (Rasterization)
  98. None.
  99. Additions to Chapter 4 of the OpenGL 1.4 Specification (Per-Fragment
  100. Operations and the Frame Buffer)
  101. None.
  102. Additions to Chapter 5 of the OpenGL 1.4 Specification (Special Functions)
  103. In section 5.4 "Display Lists", page 202, add the following command
  104. to the list of those that are not compiled into display lists:
  105. ProgramCallbackMESA.
  106. Add a new section 5.7 "Callback Functions"
  107. The function
  108. void ProgramCallbackMESA(enum target, programcallbackMESA callback,
  109. void *data)
  110. registers a user-defined callback function with the GL. <target>
  111. may be FRAGMENT_PROGRAM_ARB or VERTEX_PROGRAM_ARB. The enabled
  112. callback functions registered with these targets will be called
  113. prior to executing each instruction in the current fragment or
  114. vertex program, respectively. The callbacks are enabled and
  115. disabled by calling Enable or Disable with <cap>
  116. FRAGMENT_PROGRAM_ARB or VERTEX_PROGRAM_ARB.
  117. The callback function's signature must match the typedef
  118. typedef void (*programcallbackMESA)(enum target, void *data)
  119. When the callback function is called, <target> will either be
  120. FRAGMENT_PROGRAM_ARB or VERTEX_PROGRAM_ARB to indicate which
  121. program is currently executing and <data> will be the value
  122. specified when ProgramCallbackMESA was called.
  123. From within the callback function, only the following GL commands
  124. may be called:
  125. GetBooleanv
  126. GetDoublev
  127. GetFloatv
  128. GetIntegerv
  129. GetProgramLocalParameter
  130. GetProgramEnvParameter
  131. GetProgramRegisterfvMESA
  132. GetProgramivARB
  133. GetProgramStringARB
  134. GetError
  135. Calling any other command from within the callback results in
  136. undefined behaviour.
  137. Additions to Chapter 6 of the OpenGL 1.4 Specification (State and
  138. State Requests)
  139. Add a new section 6.1.3 "Program Value Queries":
  140. The command
  141. void GetProgramRegisterfvMESA(enum target, sizei len,
  142. const ubyte *registerName,
  143. float *v)
  144. Is used to query the value of program variables and registers
  145. during program execution. GetProgramRegisterfvMESA may only be
  146. called from within a callback function registered with
  147. ProgramCallbackMESA.
  148. <registerName> and <len> specify the name a variable, input
  149. attribute, temporary, or result register in the program string.
  150. The current value of the named variable is returned as four
  151. values in <v>. If <name> doesn't exist in the program string,
  152. the error INVALID_OPERATION is generated.
  153. Additions to Appendix A of the OpenGL 1.4 Specification (Invariance)
  154. None.
  155. Additions to the AGL/GLX/WGL Specifications
  156. None.
  157. GLX Protocol
  158. XXX TBD
  159. Dependencies on NV_vertex_program and NV_fragment_program
  160. If NV_vertex_program and/or NV_fragment_program are supported,
  161. vertex and/or fragment programs defined by those extensions may
  162. be debugged as well. Register queries will use the syntax used
  163. by those extensions (i.e. "v[X]" to query vertex attributes,
  164. "o[X]" for vertex outputs, etc.)
  165. Errors
  166. INVALID_OPERATION is generated if ProgramCallbackMESA is called
  167. between Begin and End.
  168. INVALID_ENUM is generated by ProgramCallbackMESA if <target> is not
  169. a supported vertex or fragment program type.
  170. Note: INVALID_OPERAION IS NOT generated by GetProgramRegisterfvMESA,
  171. GetBooleanv, GetDoublev, GetFloatv, or GetIntegerv if called between
  172. Begin and End when a vertex or fragment program is currently executing.
  173. INVALID_ENUM is generated by ProgramCallbackMESA,
  174. GetProgramRegisterfvMESA if <target> is not a program target supported
  175. by ARB_vertex_program, ARB_fragment_program (or NV_vertex_program or
  176. NV_fragment_program).
  177. INVALID_VALUE is generated by GetProgramRegisterfvMESA if <registerName>
  178. does not name a known program register or variable.
  179. INVALID_OPERATION is generated by GetProgramRegisterfvMESA when a
  180. register query is attempted for a program target that's not currently
  181. being executed.
  182. New State
  183. XXX finish
  184. (table 6.N, p. ###)
  185. Initial
  186. Get Value Type Get Command Value Description Sec. Attribute
  187. --------- ---- ----------- ----- ----------- ---- ---------
  188. FRAGMENT_PROGRAM_CALLBACK_MESA B IsEnabled FALSE XXX XXX enable
  189. VERTEX_PROGRAM_CALLBACK_MESA B IsEnabled FALSE XXX XXX enable
  190. FRAGMENT_PROGRAM_POSITION_MESA Z+ GetIntegerv -1 XXX XXX -
  191. VERTEX_PROGRAM_POSITION_MESA Z+ GetIntegerv -1 XXX XXX -
  192. FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA P GetPointerv NULL XXX XXX -
  193. VERTEX_PROGRAM_CALLBACK_FUNC_MESA P GetPointerv NULL XXX XXX -
  194. FRAGMENT_PROGRAM_CALLBACK_DATA_MESA P GetPointerv NULL XXX XXX -
  195. VERTEX_PROGRAM_CALLBACK_DATA_MESA P GetPointerv NULL XXX XXX -
  196. XXX more?
  197. New Implementation Dependent State
  198. None.
  199. Revision History
  200. 8 July 2003
  201. Initial draft. (Brian Paul)
  202. 11 July 2003
  203. Second draft. (Brian Paul)
  204. 20 July 2003
  205. Third draft. Lots of fundamental changes. (Brian Paul)
  206. 23 July 2003
  207. Added chapter 5 and 6 spec language. (Brian Paul)
  208. Example Usage
  209. The following is a very simple example of how this extension may
  210. be used to print the values of R0, R1, R2 and R3 while executing
  211. vertex programs.
  212. /* This is called by the GL when the vertex program is executing.
  213. * We can only make glGet* calls from within this function!
  214. */
  215. void DebugCallback(GLenum target, GLvoid *data)
  216. {
  217. GLint pos;
  218. GLuint i;
  219. /* Get PC and current instruction string */
  220. glGetIntegerv(GL_VERTEX_PROGRAM_POSITION_ARB, &pos);
  221. printf("Current position: %d\n", pos);
  222. printf("Current temporary registers:\n");
  223. for (i = 0; i < 4; i++) {
  224. GLfloat v[4];
  225. char s[10];
  226. sprintf(s, "R%d", i);
  227. glGetProgramRegisterfvMESA(GL_VERTEX_PROGRAM_ARB, strlen(s), s, v);
  228. printf("R%d = %g, %g, %g, %g\n", i, v[0], v[1], v[2], v[3]);
  229. }
  230. }
  231. /*
  232. * elsewhere...
  233. */
  234. /* Register our debugger callback function */
  235. glProgramCallbackMESA(GL_VERTEX_PROGRAM_ARB, DebugCallback, NULL);
  236. glEnable(GL_VERTEX_PROGRAM_CALLBACK_MESA);
  237. /* define/bind a vertex program */
  238. glEnable(GL_VERTEX_PROGRAM);
  239. /* render something */
  240. glBegin(GL_POINTS);
  241. glVertex2f(0, 0);
  242. glEnd();