2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL2 specific sync object behaviors
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
22 description("This test checks WebGL2 specific sync object behaviors");
25 debug("Canvas.getContext");
27 var wtu
= WebGLTestUtils
;
28 var gl
= wtu
.create3DContext("canvas", null, 2);
30 var pixel
= new Uint8Array(4);
33 testFailed("context does not exist");
36 testPassed("context exists");
39 shouldBe("gl.TIMEOUT_IGNORED", "-1");
40 shouldBe("gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL", "0x9247");
41 var max
= gl
.getParameter(gl
.MAX_CLIENT_WAIT_TIMEOUT_WEBGL
);
42 debug("Querying gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL");
43 shouldBe("gl.getError()", "gl.NO_ERROR");
44 debug("gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL returns " + max
+ "ns");
46 testFailed("gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL < 0");
47 } else if (max
> 1000 * 1000 * 1000) {
48 // This is not demanded by the WebGL2 spec, but anything larger than 1000ms
49 // is bad idea and no implementation should allow it.
50 testFailed("gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL should not exceed 1000ms");
52 testPassed("gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL returns a valid value");
54 sync
= gl
.fenceSync(gl
.SYNC_GPU_COMMANDS_COMPLETE
, 0);
55 shouldBeNonNull("sync");
56 shouldBe("gl.getError()", "gl.NO_ERROR");
57 gl
.clientWaitSync(sync
, 0, max
);
58 shouldBe("gl.getError()", "gl.NO_ERROR");
59 gl
.clientWaitSync(sync
, 0, max
+ 1);
60 shouldBe("gl.getError()", "gl.INVALID_OPERATION");
62 requestAnimationFrame(runGetSyncParameterTest
);
65 var numRetries
= 20000;
68 function syncWithGLServer() {
69 gl
.readPixels(0, 0, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, pixel
);
72 function runGetSyncParameterTest() {
74 debug("Verifying sync object isn't signaled too early");
75 sync
= gl
.fenceSync(gl
.SYNC_GPU_COMMANDS_COMPLETE
, 0);
76 // Verify as best as possible that the implementation doesn't allow a sync
77 // object to become signaled until returning control to the event loop, by
78 // spin-looping for some time.
79 var iter
= numRetries
;
82 if (gl
.getSyncParameter(sync
, gl
.SYNC_STATUS
) == gl
.SIGNALED
) {
83 testFailed("Sync object was signaled too early");
88 testPassed("Sync object wasn't signaled too early");
89 iteration
= numRetries
;
90 requestAnimationFrame(finishSyncParameterTest
);
94 function finishSyncParameterTest() {
95 if (--iteration
== 0) {
96 testFailed("Sync object wasn't signaled in a reasonable timeframe (" + numRetries
+ " iterations)");
100 var res
= gl
.getSyncParameter(sync
, gl
.SYNC_STATUS
);
101 if (res
== gl
.SIGNALED
) {
102 testPassed("Sync object was signaled");
103 requestAnimationFrame(runClientWaitSyncTest
);
108 requestAnimationFrame(finishSyncParameterTest
);
111 function runClientWaitSyncTest() {
113 debug("Verifying clientWaitSync doesn't complete too early");
115 sync
= gl
.fenceSync(gl
.SYNC_GPU_COMMANDS_COMPLETE
, 0);
116 // Verify as best as possible that the implementation doesn't allow
117 // clientWaitSync to return CONDITION_SATISFIED or ALREADY_SIGNALED until
118 // returning control to the event loop, by spin-looping for some time.
119 var iter
= numRetries
;
122 var res
= gl
.clientWaitSync(sync
, 0, 0);
123 if (res
== gl
.CONDITION_SATISFIED
|| res
== gl
.ALREADY_SIGNALED
) {
124 testFailed("clientWaitSync completed successfully too early");
129 testPassed("clientWaitSync didn't complete successfully too early");
130 iteration
= numRetries
;
131 requestAnimationFrame(finishClientWaitSyncTest
);
134 function finishClientWaitSyncTest() {
135 if (--iteration
== 0) {
136 testFailed("clientWaitSync didn't complete in a reasonable timeframe (" + numRetries
+ " iterations)");
140 var res
= gl
.clientWaitSync(sync
, 0, 0);
141 if (res
== gl
.CONDITION_SATISFIED
|| res
== gl
.ALREADY_SIGNALED
) {
142 testPassed("clientWaitSync completed successfully");
143 // This is the last test right now.
149 requestAnimationFrame(finishClientWaitSyncTest
);
153 var successfullyParsed
= true;