EGL_ANDROID_native_fence_sync.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. Name
  2. ANDROID_native_fence_sync
  3. Name Strings
  4. EGL_ANDROID_native_fence_sync
  5. Contributors
  6. Jamie Gennis
  7. Contact
  8. Jamie Gennis, Google Inc. (jgennis 'at' google.com)
  9. Status
  10. Complete
  11. Version
  12. Version 3, September 4, 2012
  13. Number
  14. EGL Extension #50
  15. Dependencies
  16. Requires EGL 1.1
  17. This extension is written against the wording of the EGL 1.2 Specification
  18. EGL_KHR_fence_sync is required.
  19. Overview
  20. This extension enables the creation of EGL fence sync objects that are
  21. associated with a native synchronization fence object that is referenced
  22. using a file descriptor. These EGL fence sync objects have nearly
  23. identical semantics to those defined by the KHR_fence_sync extension,
  24. except that they have an additional attribute storing the file descriptor
  25. referring to the native fence object.
  26. This extension assumes the existence of a native fence synchronization
  27. object that behaves similarly to an EGL fence sync object. These native
  28. objects must have a signal status like that of an EGLSyncKHR object that
  29. indicates whether the fence has ever been signaled. Once signaled the
  30. native object's signal status may not change again.
  31. New Types
  32. None.
  33. New Procedures and Functions
  34. EGLint eglDupNativeFenceFDANDROID(
  35. EGLDisplay dpy,
  36. EGLSyncKHR);
  37. New Tokens
  38. Accepted by the <type> parameter of eglCreateSyncKHR, and returned
  39. in <value> when eglGetSyncAttribKHR is called with <attribute>
  40. EGL_SYNC_TYPE_KHR:
  41. EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144
  42. Accepted by the <attrib_list> parameter of eglCreateSyncKHR:
  43. EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145
  44. Accepted by the <attrib_list> parameter of eglCreateSyncKHR, and returned
  45. by eglDupNativeFenceFDANDROID in the event of an error:
  46. EGL_NO_NATIVE_FENCE_FD_ANDROID -1
  47. Returned in <value> when eglGetSyncAttribKHR is called with <attribute>
  48. EGL_SYNC_CONDITION_KHR:
  49. EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146
  50. Changes to Chapter 3 of the EGL 1.2 Specification (EGL Functions and Errors)
  51. Add the following after the sixth paragraph of Section 3.8.1 (Sync
  52. Objects), added by KHR_fence_sync
  53. "If <type> is EGL_SYNC_NATIVE_FENCE_ANDROID, an EGL native fence sync
  54. object is created. In this case the EGL_SYNC_NATIVE_FENCE_FD_ANDROID
  55. attribute may optionally be specified. If this attribute is specified, it
  56. must be set to either a file descriptor that refers to a native fence
  57. object or to the value EGL_NO_NATIVE_FENCE_FD_ANDROID.
  58. The default values for the EGL native fence sync object attributes are as
  59. follows:
  60. Attribute Name Initial Attribute Value(s)
  61. --------------- --------------------------
  62. EGL_SYNC_TYPE_KHR EGL_SYNC_NATIVE_FENCE_ANDROID
  63. EGL_SYNC_STATUS_KHR EGL_UNSIGNALED_KHR
  64. EGL_SYNC_CONDITION_KHR EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR
  65. EGL_SYNC_NATIVE_FENCE_FD_ANDROID EGL_NO_NATIVE_FENCE_FD_ANDROID
  66. If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute is not
  67. EGL_NO_NATIVE_FENCE_FD_ANDROID then the EGL_SYNC_CONDITION_KHR attribute is
  68. set to EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID and the EGL_SYNC_STATUS_KHR
  69. attribute is set to reflect the signal status of the native fence object.
  70. Additionally, the EGL implementation assumes ownership of the file
  71. descriptor, so the caller must not use it after calling eglCreateSyncKHR."
  72. Modify Section 3.8.1 (Sync Objects), added by KHR_fence_sync, starting at
  73. the seventh paragraph
  74. "When a fence sync object is created or when an EGL native fence sync
  75. object is created with the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute set
  76. to EGL_NO_NATIVE_FENCE_FD_ANDROID, eglCreateSyncKHR also inserts a fence
  77. command into the command stream of the bound client API's current context
  78. (i.e., the context returned by eglGetCurrentContext), and associates it
  79. with the newly created sync object.
  80. After associating the fence command with an EGL native fence sync object,
  81. the next Flush() operation performed by the current client API causes a
  82. new native fence object to be created, and the
  83. EGL_SYNC_NATIVE_FENCE_ANDROID attribute of the EGL native fence object is
  84. set to a file descriptor that refers to the new native fence object. This
  85. new native fence object is signaled when the EGL native fence sync object
  86. is signaled.
  87. When the condition of the sync object is satisfied by the fence command,
  88. the sync is signaled by the associated client API context, causing any
  89. eglClientWaitSyncKHR commands (see below) blocking on <sync> to unblock.
  90. If the sync object is an EGL native fence sync object then the native
  91. fence object is also signaled when the condition is satisfied. The
  92. EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR condition is satisfied by completion
  93. of the fence command corresponding to the sync object and all preceding
  94. commands in the associated client API context's command stream. The sync
  95. object will not be signaled until all effects from these commands on the
  96. client API's internal and framebuffer state are fully realized. No other
  97. state is affected by execution of the fence command.
  98. The EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID condition is satisfied by the
  99. signaling of the native fence object referred to by the
  100. EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute. When this happens any
  101. eglClientWaitSyncKHR commands blocking on <sync> unblock."
  102. Modify the list of eglCreateSyncKHR errors in Section 3.8.1 (Sync Objects),
  103. added by KHR_fence_sync
  104. "Errors
  105. ------
  106. * If <dpy> is not the name of a valid, initialized EGLDisplay,
  107. EGL_NO_SYNC_KHR is returned and an EGL_BAD_DISPLAY error is
  108. generated.
  109. * If <type> is EGL_SYNC_FENCE_KHR and <attrib_list> is neither NULL nor
  110. empty (containing only EGL_NONE), EGL_NO_SYNC_KHR is returned and an
  111. EGL_BAD_ATTRIBUTE error is generated.
  112. * If <type> is EGL_SYNC_NATIVE_FENCE_ANDROID and <attrib_list> contains
  113. an attribute other than EGL_SYNC_NATIVE_FENCE_FD_ANDROID,
  114. EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE error is
  115. generated.
  116. * If <type> is not a supported type of sync object,
  117. EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE error is
  118. generated.
  119. * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and
  120. no context is current for the bound API (i.e., eglGetCurrentContext
  121. returns EGL_NO_CONTEXT), EGL_NO_SYNC_KHR is returned and an
  122. EGL_BAD_MATCH error is generated.
  123. * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and
  124. <dpy> does not match the EGLDisplay of the currently bound context for
  125. the currently bound client API (the EGLDisplay returned by
  126. eglGetCurrentDisplay()) then EGL_NO_SYNC_KHR is returned and an
  127. EGL_BAD_MATCH error is generated.
  128. * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and
  129. the currently bound client API does not support the client API
  130. extension indicating it can place fence commands, then EGL_NO_SYNC_KHR
  131. is returned and an EGL_BAD_MATCH error is generated."
  132. Modify table 3.cc in Section 3.8.1 (Sync Objects), added by KHR_fence_sync
  133. "
  134. Attribute Description Supported Sync Objects
  135. ----------------- ----------------------- ----------------------
  136. EGL_SYNC_TYPE_KHR Type of the sync object All
  137. EGL_SYNC_STATUS_KHR Status of the sync object All
  138. EGL_SYNC_CONDITION_KHR Signaling condition EGL_SYNC_FENCE_KHR and
  139. EGL_SYNC_NATIVE_FENCE_ANDROID only
  140. "
  141. Modify the second paragraph description of eglDestroySyncKHR in Section
  142. 3.8.1 (Sync Objects), added by KHR_fence_sync
  143. "If no errors are generated, EGL_TRUE is returned, and <sync> will no
  144. longer be the handle of a valid sync object. Additionally, if <sync> is an
  145. EGL native fence sync object and the EGL_SYNC_NATIVE_FENCE_FD_ANDROID
  146. attribute is not EGL_NO_NATIVE_FENCE_FD_ANDROID then that file descriptor
  147. is closed."
  148. Add the following after the last paragraph of Section 3.8.1 (Sync
  149. Objects), added by KHR_fence_sync
  150. The command
  151. EGLint eglDupNativeFenceFDANDROID(
  152. EGLDisplay dpy,
  153. EGLSyncKHR sync);
  154. duplicates the file descriptor stored in the
  155. EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute of an EGL native fence sync
  156. object and returns the new file descriptor.
  157. Errors
  158. ------
  159. * If <sync> is not a valid sync object for <dpy>,
  160. EGL_NO_NATIVE_FENCE_FD_ANDROID is returned and an EGL_BAD_PARAMETER
  161. error is generated.
  162. * If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute of <sync> is
  163. EGL_NO_NATIVE_FENCE_FD_ANDROID, EGL_NO_NATIVE_FENCE_FD_ANDROID is
  164. returned and an EGL_BAD_PARAMETER error is generated.
  165. * If <dpy> does not match the display passed to eglCreateSyncKHR
  166. when <sync> was created, the behaviour is undefined."
  167. Issues
  168. 1. Should EGLSyncKHR objects that wrap native fence objects use the
  169. EGL_SYNC_FENCE_KHR type?
  170. RESOLVED: A new sync object type will be added.
  171. We don't want to require all EGL fence sync objects to wrap native fence
  172. objects, so we need some way to tell the EGL implementation at sync object
  173. creation whether the sync object should support querying the native fence
  174. FD attribute. We could do this with either a new sync object type or with a
  175. boolean attribute. It might be nice to pick up future signaling conditions
  176. that might be added for fence sync objects, but there may be things that
  177. get added that don't make sense in the context of native fence objects.
  178. 2. Who is responsible for dup'ing the native fence file descriptors?
  179. RESOLVED: Whenever a file descriptor is passed into or returned from an
  180. EGL call in this extension, ownership of that file descriptor is
  181. transfered. The recipient of the file descriptor must close it when it is
  182. no longer needed, and the provider of the file descriptor must dup it
  183. before providing it if they require continued use of the native fence.
  184. 3. Can the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute be queried?
  185. RESOLVED: No.
  186. Returning the file descriptor owned by the EGL implementation would
  187. violate the file descriptor ownership rule described in issue #2. Having
  188. eglGetSyncAttribKHR return a different (dup'd) file descriptor each time
  189. it's called seems wrong, so a new function was added to explicitly dup the
  190. file descriptor.
  191. That said, the attribute is useful both as a way to pass an existing file
  192. descriptor to eglCreateSyncKHR and as a way to describe the subsequent
  193. behavior of EGL native fence sync objects, so it is left as an attribute
  194. for which the value cannot be queried.
  195. Revision History
  196. #3 (Jamie Gennis, September 4, 2012)
  197. - Reworded the extension to refer to "native fence" objects rather than
  198. "Android fence" objects.
  199. - Added a paragraph to the overview that describes assumptions about the
  200. native fence sync objects.
  201. #2 (Jamie Gennis, July 23, 2012)
  202. - Changed the file descriptor ownership transferring behavior.
  203. - Added the eglDupAndroidFenceFDANDROID function.
  204. - Removed EGL_SYNC_NATIVE_FENCE_FD_ANDROID from the table of gettable
  205. attributes.
  206. - Added language specifying that a native Android fence is created at the
  207. flush following the creation of an EGL Android fence sync object that is
  208. not passed an existing native fence.
  209. #1 (Jamie Gennis, May 29, 2012)
  210. - Initial draft.