102f4aeb0Sopenharmony_ciName 202f4aeb0Sopenharmony_ci 302f4aeb0Sopenharmony_ci ARM_implicit_external_sync 402f4aeb0Sopenharmony_ci 502f4aeb0Sopenharmony_ciName Strings 602f4aeb0Sopenharmony_ci 702f4aeb0Sopenharmony_ci EGL_ARM_implicit_external_sync 802f4aeb0Sopenharmony_ci 902f4aeb0Sopenharmony_ciContributors 1002f4aeb0Sopenharmony_ci 1102f4aeb0Sopenharmony_ci David Garbett 1202f4aeb0Sopenharmony_ci Ray Smith 1302f4aeb0Sopenharmony_ci 1402f4aeb0Sopenharmony_ciContacts 1502f4aeb0Sopenharmony_ci 1602f4aeb0Sopenharmony_ci David Garbett, ARM Ltd. (david 'dot' garbett 'at' arm 'dot' com) 1702f4aeb0Sopenharmony_ci 1802f4aeb0Sopenharmony_ciStatus 1902f4aeb0Sopenharmony_ci 2002f4aeb0Sopenharmony_ci Draft 2102f4aeb0Sopenharmony_ci 2202f4aeb0Sopenharmony_ciVersion 2302f4aeb0Sopenharmony_ci 2402f4aeb0Sopenharmony_ci Version 1, September 8, 2014 2502f4aeb0Sopenharmony_ci 2602f4aeb0Sopenharmony_ciNumber 2702f4aeb0Sopenharmony_ci 2802f4aeb0Sopenharmony_ci EGL Extension #103 2902f4aeb0Sopenharmony_ci 3002f4aeb0Sopenharmony_ciDependencies 3102f4aeb0Sopenharmony_ci 3202f4aeb0Sopenharmony_ci Requires EGL 1.1. 3302f4aeb0Sopenharmony_ci 3402f4aeb0Sopenharmony_ci This extension is written against the wording of the EGL 1.2 Specification. 3502f4aeb0Sopenharmony_ci 3602f4aeb0Sopenharmony_ci EGL_KHR_fence_sync is required. 3702f4aeb0Sopenharmony_ci 3802f4aeb0Sopenharmony_ciOverview 3902f4aeb0Sopenharmony_ci 4002f4aeb0Sopenharmony_ci This extension extends the "fence sync objects" defined in 4102f4aeb0Sopenharmony_ci EGL_KHR_fence_sync. It allows the condition that triggers the associated 4202f4aeb0Sopenharmony_ci fence command in the client API command stream to be explicitly specified on 4302f4aeb0Sopenharmony_ci fence object creation. It introduces a new condition that can be used to 4402f4aeb0Sopenharmony_ci ensure ordering between operations on buffers that may be accessed 4502f4aeb0Sopenharmony_ci externally to the client API, when those operations use an implicit 4602f4aeb0Sopenharmony_ci synchronization mechanism. Such a fence object will be signaled when all 4702f4aeb0Sopenharmony_ci prior commands affecting such buffers are guaranteed to be executed before 4802f4aeb0Sopenharmony_ci such external commands. 4902f4aeb0Sopenharmony_ci 5002f4aeb0Sopenharmony_ci Applications have limited control over when a native buffer is read or 5102f4aeb0Sopenharmony_ci written by the GPU when imported as an EGLImageKHR or via 5202f4aeb0Sopenharmony_ci eglCreatePixmapSurface, which is controlled by the EGL and client API 5302f4aeb0Sopenharmony_ci implementations. While eglWaitClient or a client call such as glFinish 5402f4aeb0Sopenharmony_ci could be called, this forces all rendering to complete, which can result in 5502f4aeb0Sopenharmony_ci CPU/GPU serialization. Note this isn't an issue for window surfaces, where 5602f4aeb0Sopenharmony_ci eglSwapBuffers ensures the rendering occurs in the correct order for the 5702f4aeb0Sopenharmony_ci platform. 5802f4aeb0Sopenharmony_ci 5902f4aeb0Sopenharmony_ci Some platforms have an implicit synchronization mechanism associated with 6002f4aeb0Sopenharmony_ci native resources, such as buffers. This means that accesses to the buffer 6102f4aeb0Sopenharmony_ci have an implicit ordering imposed on them, without involvement from the 6202f4aeb0Sopenharmony_ci application. However, this requires that an application that has imported 6302f4aeb0Sopenharmony_ci an affected buffer into EGL has a mechanism to flush any drawing operations 6402f4aeb0Sopenharmony_ci in flight such that they are waiting on the synchronization mechanism. 6502f4aeb0Sopenharmony_ci Otherwise the application cannot guarantee that subsequent operations (such 6602f4aeb0Sopenharmony_ci as displaying a rendered buffer) will occur after the commands performed by 6702f4aeb0Sopenharmony_ci the client API (such as rendering the buffer). 6802f4aeb0Sopenharmony_ci 6902f4aeb0Sopenharmony_ci The mechanism to wait for the synchronization mechanism should not require 7002f4aeb0Sopenharmony_ci the application to wait for all rendering to complete, so that it can 7102f4aeb0Sopenharmony_ci continue preparing further commands asynchronously to the queued commands. 7202f4aeb0Sopenharmony_ci This extension provides this functionality using the new condition type for 7302f4aeb0Sopenharmony_ci fence sync objects, so the application only waits for the external 7402f4aeb0Sopenharmony_ci synchronization. 7502f4aeb0Sopenharmony_ci 7602f4aeb0Sopenharmony_ciNew Types 7702f4aeb0Sopenharmony_ci 7802f4aeb0Sopenharmony_ci None 7902f4aeb0Sopenharmony_ci 8002f4aeb0Sopenharmony_ciNew Procedures and Functions 8102f4aeb0Sopenharmony_ci 8202f4aeb0Sopenharmony_ci None 8302f4aeb0Sopenharmony_ci 8402f4aeb0Sopenharmony_ciNew Tokens 8502f4aeb0Sopenharmony_ci 8602f4aeb0Sopenharmony_ci Accepted as a value of the EGL_SYNC_CONDITION_KHR attribute passed in the 8702f4aeb0Sopenharmony_ci <attrib_list> list to eglCreateSyncKHR when <type> is EGL_FENCE_SYNC_KHR, 8802f4aeb0Sopenharmony_ci and can populate <*value> when eglGetSyncAttribKHR is called with 8902f4aeb0Sopenharmony_ci <attribute> set to EGL_SYNC_CONDITION_KHR: 9002f4aeb0Sopenharmony_ci 9102f4aeb0Sopenharmony_ci EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM 0x328A 9202f4aeb0Sopenharmony_ci 9302f4aeb0Sopenharmony_ciChanges to Chapter 3 of the EGL 1.2 Specification (EGL Functions and Errors) 9402f4aeb0Sopenharmony_ci 9502f4aeb0Sopenharmony_ci Add the following after the fifth paragraph of Section 3.8.1 (Sync Objects), 9602f4aeb0Sopenharmony_ci added by KHR_fence_sync: 9702f4aeb0Sopenharmony_ci 9802f4aeb0Sopenharmony_ci "Typically client APIs are considered to execute commands in a linear queue, 9902f4aeb0Sopenharmony_ci where a prior command is executed and completes before a later command is 10002f4aeb0Sopenharmony_ci started. By default fence sync objects adhere to this model - a fence is 10102f4aeb0Sopenharmony_ci signaled once prior commands have completed. However on some platforms a 10202f4aeb0Sopenharmony_ci command in a client API may transition through multiple states before it 10302f4aeb0Sopenharmony_ci completes, which may impact other components of the system. Therefore the 10402f4aeb0Sopenharmony_ci condition that all prior commands must meet before the fence is triggered is 10502f4aeb0Sopenharmony_ci configurable." 10602f4aeb0Sopenharmony_ci 10702f4aeb0Sopenharmony_ci Replace the sixth paragraph of Section 3.8.1 (Sync Objects), added by 10802f4aeb0Sopenharmony_ci KHR_fence_sync: 10902f4aeb0Sopenharmony_ci 11002f4aeb0Sopenharmony_ci "If, <type> is EGL_SYNC_FENCE_KHR, a fence sync object is created. In this 11102f4aeb0Sopenharmony_ci case <attrib_list> can be NULL or empty, or can specify the 11202f4aeb0Sopenharmony_ci EGL_SYNC_CONDITION_KHR attribute. Attributes of the fence sync object have 11302f4aeb0Sopenharmony_ci the following default values:" 11402f4aeb0Sopenharmony_ci 11502f4aeb0Sopenharmony_ci Replace the eighth paragraph of Section 3.8.1 (Sync Objects), added by 11602f4aeb0Sopenharmony_ci KHR_fence_sync: 11702f4aeb0Sopenharmony_ci 11802f4aeb0Sopenharmony_ci "When the condition of the sync object is satisfied by the fence command, 11902f4aeb0Sopenharmony_ci the sync is signaled by the associated client API context, causing any 12002f4aeb0Sopenharmony_ci eglClientWaitSyncKHR commands (see below) blocking on <sync> to unblock. The 12102f4aeb0Sopenharmony_ci condition is specified by the EGL_SYNC_CONDITION_KHR attribute passed to 12202f4aeb0Sopenharmony_ci eglCreateSyncKHR. 12302f4aeb0Sopenharmony_ci 12402f4aeb0Sopenharmony_ci If the condition is specified as EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR, the 12502f4aeb0Sopenharmony_ci fence sync object is satisfied by completion of the fence command 12602f4aeb0Sopenharmony_ci corresponding to the sync object, and all preceding commands in the 12702f4aeb0Sopenharmony_ci associated client API context's command stream. The sync object will not be 12802f4aeb0Sopenharmony_ci signaled until all effects from these commands on the client API's internal 12902f4aeb0Sopenharmony_ci and framebuffer state are fully realized. No other state is affected by 13002f4aeb0Sopenharmony_ci execution of the fence command. 13102f4aeb0Sopenharmony_ci 13202f4aeb0Sopenharmony_ci If the condition is specified as 13302f4aeb0Sopenharmony_ci EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM, the fence sync object is 13402f4aeb0Sopenharmony_ci satisfied by the completion of the fence command corresponding to the sync 13502f4aeb0Sopenharmony_ci object, and the <submission> of all preceding commands in the associated 13602f4aeb0Sopenharmony_ci client API context's command stream. <Submission> defines the point in time 13702f4aeb0Sopenharmony_ci when a command has been queued on any implicit synchronization mechanisms 13802f4aeb0Sopenharmony_ci present on the platform which apply to any of the resources used by the 13902f4aeb0Sopenharmony_ci command. This enforces an ordering, as defined by the synchronization 14002f4aeb0Sopenharmony_ci mechanism, between the command and any other operations that also respect 14102f4aeb0Sopenharmony_ci the synchronization mechanism(s)." 14202f4aeb0Sopenharmony_ci 14302f4aeb0Sopenharmony_ci Replace the second entry in the list of eglCreateSyncKHR errors in Section 14402f4aeb0Sopenharmony_ci 3.8.1 (Sync Objects), added by KHR_fence_sync: 14502f4aeb0Sopenharmony_ci 14602f4aeb0Sopenharmony_ci " * If <type> is EGL_SYNC_FENCE_KHR and <attrib_list> contains an attribute 14702f4aeb0Sopenharmony_ci other than EGL_SYNC_CONDITION_KHR, EGL_NO_SYNC_KHR is returned and an 14802f4aeb0Sopenharmony_ci EGL_BAD_ATTRIBUTE error is generated. 14902f4aeb0Sopenharmony_ci * If <type> is EGL_SYNC_FENCE_KHR and the value specified for 15002f4aeb0Sopenharmony_ci EGL_SYNC_CONDITION_KHR is not EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR or 15102f4aeb0Sopenharmony_ci EGL_SYNC_PRIOR_COMMANDS_SUBMITTED_ARM, EGL_NO_SYNC_KHR is returned and 15202f4aeb0Sopenharmony_ci an EGL_BAD_ATTRIBUTE error is generated." 15302f4aeb0Sopenharmony_ci 15402f4aeb0Sopenharmony_ciIssues 15502f4aeb0Sopenharmony_ci 15602f4aeb0Sopenharmony_ci 1. Could glFlush guarantee commands are submitted, making this extension 15702f4aeb0Sopenharmony_ci unnecessary? 15802f4aeb0Sopenharmony_ci 15902f4aeb0Sopenharmony_ci RESOLVED: The Open GL ES 3.1 specification defines glFlush() as causing "all 16002f4aeb0Sopenharmony_ci previously issued GL commands to complete in finite time". There is no 16102f4aeb0Sopenharmony_ci requirement for the execution of commands to reach any specific point before 16202f4aeb0Sopenharmony_ci it returns - a valid implementation of glFlush() could spawn a new thread 16302f4aeb0Sopenharmony_ci that sleeps for a minute before submitting the pending commands. While an 16402f4aeb0Sopenharmony_ci implementation could decide to ensure all commands are submitted within 16502f4aeb0Sopenharmony_ci glFlush(), it could not be assumed to be the case across all 16602f4aeb0Sopenharmony_ci implementations. 16702f4aeb0Sopenharmony_ci 16802f4aeb0Sopenharmony_ci In addition, there may be scenarios when submitting commands within 16902f4aeb0Sopenharmony_ci glFlush() is harmful. Waiting for command submission may have a performance 17002f4aeb0Sopenharmony_ci impact on some implementations that perform processing of commands 17102f4aeb0Sopenharmony_ci asynchronously. In addition such a change may restrict what is possible in 17202f4aeb0Sopenharmony_ci the future. For example if user events were introduced into OpenGL ES they 17302f4aeb0Sopenharmony_ci have the potential of introducing deadlocks if submission in glFlush() is 17402f4aeb0Sopenharmony_ci guaranteed. 17502f4aeb0Sopenharmony_ci 17602f4aeb0Sopenharmony_ci 2. Should a new entry point be defined that flushes commands synchronously, 17702f4aeb0Sopenharmony_ci instead of the new fence type as defined by this extension? 17802f4aeb0Sopenharmony_ci 17902f4aeb0Sopenharmony_ci RESOLVED: While a synchronous "flush and submit" entrypoint would meet the 18002f4aeb0Sopenharmony_ci requirements for this extension, there may be a small benefit in enabling 18102f4aeb0Sopenharmony_ci the application to continue processing between flushing and waiting for 18202f4aeb0Sopenharmony_ci submission. In addition, the semantics of the existing EGL_KHR_fence_sync 18302f4aeb0Sopenharmony_ci extension closely match what is required for this extension, so defining 18402f4aeb0Sopenharmony_ci the new functionality in terms of fences may enable simpler implementations. 18502f4aeb0Sopenharmony_ci 18602f4aeb0Sopenharmony_ci 3. Should OpenGL ES 3 glFenceSync be extended in preference to 18702f4aeb0Sopenharmony_ci eglCreateSyncKHR? 18802f4aeb0Sopenharmony_ci 18902f4aeb0Sopenharmony_ci RESOLVED: Some platforms are yet to move to a OpenGL ES 3 implementation, or 19002f4aeb0Sopenharmony_ci may be unwilling to expose OpenGL ES 3 entrypoints to applications. As 19102f4aeb0Sopenharmony_ci EGL_KHR_fence_sync is older than OpenGL ES 3, and is comparatively a small 19202f4aeb0Sopenharmony_ci change, it has a better chance of adoption in a platform. 19302f4aeb0Sopenharmony_ci 19402f4aeb0Sopenharmony_ci In addition this extension is based on the idea that there are 19502f4aeb0Sopenharmony_ci platform-specific ways to interact with the client API command stream. As 19602f4aeb0Sopenharmony_ci this is platform-specific, and does not fit with the existing model 19702f4aeb0Sopenharmony_ci typically used by client APIs (such as Open GL ES) it is better placed in 19802f4aeb0Sopenharmony_ci EGL. 19902f4aeb0Sopenharmony_ci 20002f4aeb0Sopenharmony_ci Finally extending EGL has the advantage that the extension applies to all 20102f4aeb0Sopenharmony_ci client APIs. 20202f4aeb0Sopenharmony_ci 20302f4aeb0Sopenharmony_ci 4. Should a new <type> parameter be defined, instead of extending the 20402f4aeb0Sopenharmony_ci EGL_FENCE_SYNC_KHR fence sync objects defined by EGL_KHR_fence_sync? 20502f4aeb0Sopenharmony_ci 20602f4aeb0Sopenharmony_ci RESOLVED: Whether the new functionality is defined as an extension to the 20702f4aeb0Sopenharmony_ci existing fence sync objects, or whether they are defined as a new type of 20802f4aeb0Sopenharmony_ci sync object, we must acknowledge that the model of a client API processing 20902f4aeb0Sopenharmony_ci commands serially (with prior commands completing before later commands are 21002f4aeb0Sopenharmony_ci executed) is too simplistic for some platforms. 21102f4aeb0Sopenharmony_ci 21202f4aeb0Sopenharmony_ci Extending the existing fence sync objects allows us to use the existing 21302f4aeb0Sopenharmony_ci concept of conditions that trigger the fences. It also allows the maximum 21402f4aeb0Sopenharmony_ci amount of reuse of existing functionality, potentially simplifying the 21502f4aeb0Sopenharmony_ci implementation and the use of the extension by applications. 21602f4aeb0Sopenharmony_ci 21702f4aeb0Sopenharmony_ciRevision History 21802f4aeb0Sopenharmony_ci#1 (David Garbett, September 8, 2014) 21902f4aeb0Sopenharmony_ci - Initial draft. 220