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

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