EGL_ANDROID_blob_cache.txt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. Name
  2. ANDROID_blob_cache
  3. Name Strings
  4. EGL_ANDROID_blob_cache
  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, December 13, 2012
  13. Number
  14. EGL Extension #48
  15. Dependencies
  16. Requires EGL 1.0
  17. This extension is written against the wording of the EGL 1.4 Specification
  18. Overview
  19. Shader compilation and optimization has been a troublesome aspect of OpenGL
  20. programming for a long time. It can consume seconds of CPU cycles during
  21. application start-up. Additionally, state-based re-compiles done
  22. internally by the drivers add an unpredictable element to application
  23. performance tuning, often leading to occasional pauses in otherwise smooth
  24. animations.
  25. This extension provides a mechanism through which client API
  26. implementations may cache shader binaries after they are compiled. It may
  27. then retrieve those cached shaders during subsequent executions of the same
  28. program. The management of the cache is handled by the application (or
  29. middleware), allowing it to be tuned to a particular platform or
  30. environment.
  31. While the focus of this extension is on providing a persistent cache for
  32. shader binaries, it may also be useful for caching other data. This is
  33. perfectly acceptable, but the guarantees provided (or lack thereof) were
  34. designed around the shader use case.
  35. Note that although this extension is written as if the application
  36. implements the caching functionality, on the Android OS it is implemented
  37. as part of the Android EGL module. This extension is not exposed to
  38. applications on Android, but will be used automatically in every
  39. application that uses EGL if it is supported by the underlying
  40. device-specific EGL implementation.
  41. New Types
  42. /*
  43. * EGLsizeiANDROID is a signed integer type for representing the size of a
  44. * memory buffer.
  45. */
  46. #include <khrplatform.h>
  47. typedef khronos_ssize_t EGLsizeiANDROID;
  48. /*
  49. * EGLSetBlobFunc is a pointer to an application-provided function that a
  50. * client API implementation may use to insert a key/value pair into the
  51. * cache.
  52. */
  53. typedef void (*EGLSetBlobFuncANDROID) (const void* key,
  54. EGLsizeiANDROID keySize, const void* value, EGLsizeiANDROID valueSize)
  55. /*
  56. * EGLGetBlobFunc is a pointer to an application-provided function that a
  57. * client API implementation may use to retrieve a cached value from the
  58. * cache.
  59. */
  60. typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void* key,
  61. EGLsizeiANDROID keySize, void* value, EGLsizeiANDROID valueSize)
  62. New Procedures and Functions
  63. void eglSetBlobCacheFuncsANDROID(EGLDisplay dpy,
  64. EGLSetBlobFuncANDROID set,
  65. EGLGetBlobFuncANDROID get);
  66. New Tokens
  67. None.
  68. Changes to Chapter 3 of the EGL 1.4 Specification (EGL Functions and Errors)
  69. Add a new subsection after Section 3.8, page 50
  70. (Synchronization Primitives)
  71. "3.9 Persistent Caching
  72. In order to facilitate persistent caching of internal client API state that
  73. is slow to compute or collect, the application may specify callback
  74. function pointers through which the client APIs can request data be cached
  75. and retrieved. The command
  76. void eglSetBlobCacheFuncsANDROID(EGLDisplay dpy,
  77. EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
  78. sets the callback function pointers that client APIs associated with
  79. display <dpy> can use to interact with caching functionality provided by
  80. the application. <set> points to a function that inserts a new value into
  81. the cache and associates it with the given key. <get> points to a function
  82. that retrieves from the cache the value associated with a given key. The
  83. semantics of these callback functions are described in Section 3.9.1 (Cache
  84. Operations).
  85. Cache functions may only be specified once during the lifetime of an
  86. EGLDisplay. The <set> and <get> functions may be called at any time and
  87. from any thread from the time at which eglSetBlobCacheFuncsANDROID is
  88. called until the time that the last resource associated with <dpy> is
  89. deleted and <dpy> itself is terminated. Concurrent calls to these
  90. functions from different threads is also allowed.
  91. If eglSetBlobCacheFuncsANDROID generates an error then all client APIs must
  92. behave as though eglSetBlobCacheFuncsANDROID was not called for the display
  93. <dpy>. If <set> or <get> is NULL then an EGL_BAD_PARAMETER error is
  94. generated. If a successful eglSetBlobCacheFuncsANDROID call was already
  95. made for <dpy> and the display has not since been terminated then an
  96. EGL_BAD_PARAMETER error is generated.
  97. 3.9.1 Cache Operations
  98. To insert a new binary value into the cache and associate it with a given
  99. key, a client API implementation can call the application-provided callback
  100. function
  101. void (*set) (const void* key, EGLsizeiANDROID keySize,
  102. const void* value, EGLsizeiANDROID valueSize)
  103. <key> and <value> are pointers to the beginning of the key and value,
  104. respectively, that are to be inserted. <keySize> and <valueSize> specify
  105. the size in bytes of the data pointed to by <key> and <value>,
  106. respectively.
  107. No guarantees are made as to whether a given key/value pair is present in
  108. the cache after the set call. If a different value has been associated
  109. with the given key in the past then it is undefined which value, if any, is
  110. associated with the key after the set call. Note that while there are no
  111. guarantees, the cache implementation should attempt to cache the most
  112. recently set value for a given key.
  113. To retrieve the binary value associated with a given key from the cache, a
  114. client API implementation can call the application-provided callback
  115. function
  116. EGLsizeiANDROID (*get) (const void* key, EGLsizeiANDROID keySize,
  117. void* value, EGLsizeiANDROID valueSize)
  118. <key> is a pointer to the beginning of the key. <keySize> specifies the
  119. size in bytes of the binary key pointed to by <key>. If the cache contains
  120. a value associated with the given key then the size of that binary value in
  121. bytes is returned. Otherwise 0 is returned.
  122. If the cache contains a value for the given key and its size in bytes is
  123. less than or equal to <valueSize> then the value is written to the memory
  124. pointed to by <value>. Otherwise nothing is written to the memory pointed
  125. to by <value>.
  126. Issues
  127. 1. How should errors be handled in the callback functions?
  128. RESOLVED: No guarantees are made about the presence of values in the cache,
  129. so there should not be a need to return error information to the client API
  130. implementation. The cache implementation can simply drop a value if it
  131. encounters an error during the 'set' callback. Similarly, it can simply
  132. return 0 if it encouters an error in a 'get' callback.
  133. 2. When a client API driver gets updated, that may need to invalidate
  134. previously cached entries. How can the driver handle this situation?
  135. RESPONSE: There are a number of ways the driver can handle this situation.
  136. The recommended way is to include the driver version in all cache keys.
  137. That way each driver version will use a set of cache keys that are unique
  138. to that version, and conflicts should never occur. Updating the driver
  139. could then leave a number of values in the cache that will never be
  140. requested again. If needed, the cache implementation can handle those
  141. values in some way, but the driver does not need to take any special
  142. action.
  143. 3. How much data can be stored in the cache?
  144. RESPONSE: This is entirely dependent upon the cache implementation.
  145. Presumably it will be tuned to store enough data to be useful, but not
  146. enough to become problematic. :)
  147. Revision History
  148. #3 (Jon Leech, December 13, 2012)
  149. - Fix typo in New Functions section & assign extension #.
  150. #2 (Jamie Gennis, April 25, 2011)
  151. - Swapped the order of the size and pointer arguments to the get and set
  152. functions.
  153. #1 (Jamie Gennis, April 22, 2011)
  154. - Initial draft.