15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci NV_timeline_semaphore 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_NV_timeline_semaphore 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContributors 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Carsten Rohde, NVIDIA 125bd8deadSopenharmony_ci James Jones, NVIDIA 135bd8deadSopenharmony_ci 145bd8deadSopenharmony_ciContact 155bd8deadSopenharmony_ci 165bd8deadSopenharmony_ci Carsten Rohde, NVIDIA Corporation (crohde 'at' nvidia.com) 175bd8deadSopenharmony_ci 185bd8deadSopenharmony_ciStatus 195bd8deadSopenharmony_ci 205bd8deadSopenharmony_ci Complete 215bd8deadSopenharmony_ci 225bd8deadSopenharmony_ciVersion 235bd8deadSopenharmony_ci 245bd8deadSopenharmony_ci Last Modified Date: Jul 10, 2020 255bd8deadSopenharmony_ci Revision: 1 265bd8deadSopenharmony_ci 275bd8deadSopenharmony_ciNumber 285bd8deadSopenharmony_ci 295bd8deadSopenharmony_ci 551 305bd8deadSopenharmony_ci OpenGL ES Extension #330 315bd8deadSopenharmony_ci 325bd8deadSopenharmony_ciDependencies 335bd8deadSopenharmony_ci 345bd8deadSopenharmony_ci Written against the OpenGL 4.6 and OpenGL ES 3.2 specifications. 355bd8deadSopenharmony_ci 365bd8deadSopenharmony_ci GL_NV_timeline_semaphore requires GL_EXT_semaphore or a version of 375bd8deadSopenharmony_ci OpenGL or OpenGL ES that incorporates it. 385bd8deadSopenharmony_ci 395bd8deadSopenharmony_ciOverview 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ci The Vulkan API introduces the concept of timeline semaphores. 425bd8deadSopenharmony_ci This extension brings those concepts to the OpenGL API by adding 435bd8deadSopenharmony_ci a semaphore type to the semaphore object. In OpenGL, timeline semaphore 445bd8deadSopenharmony_ci signal and wait operations are similar to the corresponding operations on 455bd8deadSopenharmony_ci imported Direct3D 12 fences defined in EXT_external_objects_win32. 465bd8deadSopenharmony_ci 475bd8deadSopenharmony_ciNew Procedures and Functions 485bd8deadSopenharmony_ci 495bd8deadSopenharmony_ci void CreateSemaphoresNV(sizei n, uint *semaphores); 505bd8deadSopenharmony_ci 515bd8deadSopenharmony_ci void SemaphoreParameterivNV(uint semaphore, 525bd8deadSopenharmony_ci enum pname, 535bd8deadSopenharmony_ci const GLint *params); 545bd8deadSopenharmony_ci 555bd8deadSopenharmony_ci void GetSemaphoreParameterivNV(uint semaphore, 565bd8deadSopenharmony_ci enum pname, 575bd8deadSopenharmony_ci int *params); 585bd8deadSopenharmony_ci 595bd8deadSopenharmony_ciNew Tokens 605bd8deadSopenharmony_ci 615bd8deadSopenharmony_ci Accepted by the <pname> parameter of SemaphoreParameterivNV 625bd8deadSopenharmony_ci and GetSemaphoreParameterivNV: 635bd8deadSopenharmony_ci 645bd8deadSopenharmony_ci SEMAPHORE_TYPE_NV 0x95B3 655bd8deadSopenharmony_ci 665bd8deadSopenharmony_ci Accepted by the <param> parameter of SemaphoreParameterivNV and 675bd8deadSopenharmony_ci GetSemaphoreParameterivNV when <pname> parameter is SEMAPHORE_TYPE_NV: 685bd8deadSopenharmony_ci 695bd8deadSopenharmony_ci SEMAPHORE_TYPE_BINARY_NV 0x95B4 705bd8deadSopenharmony_ci SEMAPHORE_TYPE_TIMELINE_NV 0x95B5 715bd8deadSopenharmony_ci 725bd8deadSopenharmony_ci Accepted by the <pname> parameter of SemaphoreParameterui64vNV 735bd8deadSopenharmony_ci and GetSemaphoreParameterui64vNV: 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ci TIMELINE_SEMAPHORE_VALUE_NV 0x9595 765bd8deadSopenharmony_ci 775bd8deadSopenharmony_ci Accepted by the <pname> parameter to GetIntegerv, GetFloatv, GetDoublev, 785bd8deadSopenharmony_ci GetInteger64v, and GetBooleanv: 795bd8deadSopenharmony_ci 805bd8deadSopenharmony_ci MAX_TIMELINE_SEMAPHORE_VALUE_DIFFERENCE_NV 0x95B6 815bd8deadSopenharmony_ci 825bd8deadSopenharmony_ci 835bd8deadSopenharmony_ciAdditions to Chapter 4 of the OpenGL 4.6 Specification (Event Model) 845bd8deadSopenharmony_ci 855bd8deadSopenharmony_ci Add the following to section 4.2 Semaphore Objects after paragraph 865bd8deadSopenharmony_ci which describes command GenSemaphoresEXT: 875bd8deadSopenharmony_ci 885bd8deadSopenharmony_ci The command 895bd8deadSopenharmony_ci 905bd8deadSopenharmony_ci void CreateSemaphoresNV(sizei n, 915bd8deadSopenharmony_ci uint *semaphores); 925bd8deadSopenharmony_ci 935bd8deadSopenharmony_ci returns <n> previously unused semaphore names in <semaphores>. 945bd8deadSopenharmony_ci The semaphores named contain default state, but initially have no 955bd8deadSopenharmony_ci external semaphores associated with them. 965bd8deadSopenharmony_ci 975bd8deadSopenharmony_ci Replace section 4.2.2 Semaphore Parameters with the following: 985bd8deadSopenharmony_ci 995bd8deadSopenharmony_ci Semaphore parameters control the type of the semaphore and how 1005bd8deadSopenharmony_ci semaphore wait and signal operations behave. 1015bd8deadSopenharmony_ci Table 4.3 defines which parameters are available for a semaphore 1025bd8deadSopenharmony_ci based on the external handle type from which it was imported. 1035bd8deadSopenharmony_ci Semaphore parameters are set using the commands 1045bd8deadSopenharmony_ci 1055bd8deadSopenharmony_ci void SemaphoreParameterivNV(uint semaphore, 1065bd8deadSopenharmony_ci enum pname, 1075bd8deadSopenharmony_ci const int *params); 1085bd8deadSopenharmony_ci 1095bd8deadSopenharmony_ci and 1105bd8deadSopenharmony_ci 1115bd8deadSopenharmony_ci void SemaphoreParameterui64vEXT(uint semaphore, 1125bd8deadSopenharmony_ci enum pname, 1135bd8deadSopenharmony_ci const uint64 *params); 1145bd8deadSopenharmony_ci 1155bd8deadSopenharmony_ci <semaphore> is the name of the semaphore object on which the 1165bd8deadSopenharmony_ci parameter <pname> will be set to the value(s) in <pname>. 1175bd8deadSopenharmony_ci 1185bd8deadSopenharmony_ci Table 4.3: Semaphore parameters 1195bd8deadSopenharmony_ci 1205bd8deadSopenharmony_ci | Name | Handle Types | Legal Values | 1215bd8deadSopenharmony_ci +-----------------------------+-----------------------------+--------------------------------------+ 1225bd8deadSopenharmony_ci | SEMAPHORE_TYPE_NV | any handle type | SEMAPHORE_TYPE_BINARY_NV (default) | 1235bd8deadSopenharmony_ci | | | SEMAPHORE_TYPE_TIMELINE_NV | 1245bd8deadSopenharmony_ci +-----------------------------+-----------------------------+--------------------------------------+ 1255bd8deadSopenharmony_ci | TIMELINE_SEMAPHORE_VALUE_NV | any handle type | any value | 1265bd8deadSopenharmony_ci +-----------------------------+-----------------------------+--------------------------------------+ 1275bd8deadSopenharmony_ci 1285bd8deadSopenharmony_ci The default type of a semaphore is SEMAPHORE_TYPE_BINARY_NV. Only when the semaphore is imported 1295bd8deadSopenharmony_ci from a D3D fence, the semaphore type defaults to SEMAPHORE_TYPE_TIMELINE_NV. 1305bd8deadSopenharmony_ci 1315bd8deadSopenharmony_ci Parameters of a semaphore object may be queried with the commands 1325bd8deadSopenharmony_ci 1335bd8deadSopenharmony_ci void GetSemaphoreParameteriEXT(uint semaphore, 1345bd8deadSopenharmony_ci enum pname, 1355bd8deadSopenharmony_ci uint64 *params); 1365bd8deadSopenharmony_ci 1375bd8deadSopenharmony_ci and 1385bd8deadSopenharmony_ci 1395bd8deadSopenharmony_ci void GetSemaphoreParameterui64EXT(uint semaphore, 1405bd8deadSopenharmony_ci enum pname, 1415bd8deadSopenharmony_ci uint64 *params); 1425bd8deadSopenharmony_ci 1435bd8deadSopenharmony_ci <semaphore> is the semaphore object from with the parameter <pname> 1445bd8deadSopenharmony_ci is queried. The value(s) of the parameter are returned in <params>. 1455bd8deadSopenharmony_ci <pname> may be any value in table 4.3. 1465bd8deadSopenharmony_ci 1475bd8deadSopenharmony_ci Add the following after the first paragraph of section 4.2.3 "Waiting 1485bd8deadSopenharmony_ci for Semaphores" 1495bd8deadSopenharmony_ci 1505bd8deadSopenharmony_ci If <semaphore> is of the type SEMAPHORE_TYPE_TIMELINE_NV, it will 1515bd8deadSopenharmony_ci reach the signaled state when its value is greater than or equal 1525bd8deadSopenharmony_ci to the value specified by its TIMELINE_SEMAPHORE_VALUE_NV parameter. 1535bd8deadSopenharmony_ci 1545bd8deadSopenharmony_ci Add the following at the end of section 4.2.3 "Waiting for Semaphores": 1555bd8deadSopenharmony_ci 1565bd8deadSopenharmony_ci When using binary semaphores, for every wait on a semaphore there must 1575bd8deadSopenharmony_ci be a prior signal of that semaphore that will not be consumed by a 1585bd8deadSopenharmony_ci different wait on the semaphore. 1595bd8deadSopenharmony_ci When using timeline semaphores, wait-before-signal behavior is 1605bd8deadSopenharmony_ci well-defined and applications can wait for semaphore before the 1615bd8deadSopenharmony_ci corresponding semaphore signal operation is flushed. 1625bd8deadSopenharmony_ci 1635bd8deadSopenharmony_ci MAX_TIMELINE_SEMAPHORE_VALUE_DIFFERENCE_NV indicates the maximum 1645bd8deadSopenharmony_ci difference allowed by the implementation between the current value 1655bd8deadSopenharmony_ci of a timeline semaphore and any pending wait operations 1665bd8deadSopenharmony_ci 1675bd8deadSopenharmony_ci Add the following after the first paragraph of section 4.2.4 "Signaling 1685bd8deadSopenharmony_ci Semaphores" 1695bd8deadSopenharmony_ci 1705bd8deadSopenharmony_ci If <semaphore> is of the type SEMAPHORE_TYPE_TIMELINE_NV, its value 1715bd8deadSopenharmony_ci will be set to the value specified by its TIMELINE_SEMAPHORE_VALUE_NV 1725bd8deadSopenharmony_ci parameter when the signal operation completes. 1735bd8deadSopenharmony_ci 1745bd8deadSopenharmony_ci Add the following at the end of section 4.2.4 "Signaling for Semaphores": 1755bd8deadSopenharmony_ci 1765bd8deadSopenharmony_ci MAX_TIMELINE_SEMAPHORE_VALUE_DIFFERENCE_NV indicates the maximum 1775bd8deadSopenharmony_ci difference allowed by the implementation between the current value 1785bd8deadSopenharmony_ci of a timeline semaphore and any pending signal operations. 1795bd8deadSopenharmony_ci 1805bd8deadSopenharmony_ci 1815bd8deadSopenharmony_ciExample 1825bd8deadSopenharmony_ci 1835bd8deadSopenharmony_ci GLuint semapohre; 1845bd8deadSopenharmony_ci glCreateSemaphoresNV(1, &semaphore); 1855bd8deadSopenharmony_ci GLenum semaphoreType = GL_SEMAPHORE_TYPE_TIMELINE_NV; 1865bd8deadSopenharmony_ci glSemaphoreParameterivNV(semaphore, GL_SEMAPHORE_TYPE_NV, (GLint*)&semaphoreType); 1875bd8deadSopenharmony_ci glImportSemaphoreFdEXT(semaphore, GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd); // or win32 equivalent 1885bd8deadSopenharmony_ci 1895bd8deadSopenharmony_ci GLuint64 semaphoreValue = 0; 1905bd8deadSopenharmony_ci 1915bd8deadSopenharmony_ci while (...) { 1925bd8deadSopenharmony_ci glSemaphoreParameterui64vEXT(semaphore, GL_TIMELINE_SEMAPHORE_VALUE_NV, &semaphoreValue); 1935bd8deadSopenharmony_ci glWaitSemaphoreEXT(semaphore, ...); 1945bd8deadSopenharmony_ci 1955bd8deadSopenharmony_ci ... 1965bd8deadSopenharmony_ci 1975bd8deadSopenharmony_ci semaphoreValue ++; 1985bd8deadSopenharmony_ci glSemaphoreParameterui64vEXT(semaphore, GL_TIMELINE_SEMAPHORE_VALUE_NV, &semaphoreValue); 1995bd8deadSopenharmony_ci glSignalSemaphoreEXT(semaphore, ...); 2005bd8deadSopenharmony_ci } 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci glDeleteSemaphoresEXT(1, &semaphore); 2035bd8deadSopenharmony_ci 2045bd8deadSopenharmony_ci 2055bd8deadSopenharmony_ciIssues 2065bd8deadSopenharmony_ci 2075bd8deadSopenharmony_ci (1) Should we add client functions to signal and wait for the semaphore on 2085bd8deadSopenharmony_ci the CPU? 2095bd8deadSopenharmony_ci 2105bd8deadSopenharmony_ci RESOLVED: No. We already declined to add external Vulkan fence interop 2115bd8deadSopenharmony_ci with GL on the basis that you can just do that with Vulkan 2125bd8deadSopenharmony_ci if you need it. 2135bd8deadSopenharmony_ci 2145bd8deadSopenharmony_ci (2) Should GetIntegerv and GetBooleanv be allowed to query 2155bd8deadSopenharmony_ci MAX_TIMELINE_SEMAPHORE_VALUE_DIFFERENCE_NV? 2165bd8deadSopenharmony_ci 2175bd8deadSopenharmony_ci RESOLVED: Yes. Although it's dangerous to use them they don't throw an 2185bd8deadSopenharmony_ci error but you are advised to use GetInteger64v. 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ciRevision History 2215bd8deadSopenharmony_ci 2225bd8deadSopenharmony_ci Revision 1, 2020-07-10 (Carsten Rohde) 2235bd8deadSopenharmony_ci - Initial draft. 224