1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 goog.provide('functional.gles3.es3fBufferCopyTests');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('framework.delibs.debase.deMath');
25 goog.require('framework.delibs.debase.deRandom');
26 goog.require('framework.delibs.debase.deString');
27 goog.require('modules.shared.glsBufferTestUtil');
29 goog.scope(function() {
31 var es3fBufferCopyTests = functional.gles3.es3fBufferCopyTests;
32 var glsBufferTestUtil = modules.shared.glsBufferTestUtil;
33 var tcuTestCase = framework.common.tcuTestCase;
34 var deMath = framework.delibs.debase.deMath;
35 var deString = framework.delibs.debase.deString;
36 var deRandom = framework.delibs.debase.deRandom;
38 /** @type {WebGL2RenderingContext} */ var gl;
42 * @extends {glsBufferTestUtil.BufferCase}
43 * @param {string} name
44 * @param {string} desc
45 * @param {number} srcTarget
46 * @param {number} srcSize
47 * @param {number} srcHint
48 * @param {number} dstTarget
49 * @param {number} dstSize
50 * @param {number} dstHint
51 * @param {number} copySrcOffset
52 * @param {number} copyDstOffset
53 * @param {number} copySize
54 * @param {glsBufferTestUtil.VerifyType} verifyType
56 es3fBufferCopyTests.BasicBufferCopyCase = function(name, desc, srcTarget, srcSize, srcHint, dstTarget, dstSize, dstHint, copySrcOffset, copyDstOffset, copySize, verifyType) {
57 glsBufferTestUtil.BufferCase.call(this, name, desc);
59 this.m_srcTarget = srcTarget;
60 this.m_srcSize = srcSize;
61 this.m_srcHint = srcHint;
62 this.m_dstTarget = dstTarget;
63 this.m_dstSize = dstSize;
64 this.m_dstHint = dstHint;
65 this.m_copySrcOffset = copySrcOffset;
66 this.m_copyDstOffset = copyDstOffset;
67 this.m_copySize = copySize;
68 this.m_verifyType = verifyType;
70 assertMsgOptions(deMath.deInBounds32(this.m_copySrcOffset, 0, this.m_srcSize) && deMath.deInRange32(this.m_copySrcOffset + this.m_copySize, this.m_copySrcOffset, this.m_srcSize), 'Copy parameters are out of buffer\'s range', false, true);
71 assertMsgOptions(deMath.deInBounds32(this.m_copyDstOffset, 0, this.m_dstSize) && deMath.deInRange32(this.m_copyDstOffset + this.m_copySize, this.m_copyDstOffset, this.m_dstSize), 'Copy parameters are out of buffer\'s range', false, true);
74 es3fBufferCopyTests.BasicBufferCopyCase.prototype = Object.create(glsBufferTestUtil.BufferCase.prototype);
75 es3fBufferCopyTests.BasicBufferCopyCase.prototype.constructor = es3fBufferCopyTests.BasicBufferCopyCase;
78 * @return {tcuTestCase.IterateResult}
80 es3fBufferCopyTests.BasicBufferCopyCase.prototype.iterate = function() {
81 /** @type {glsBufferTestUtil.BufferVerifier} */ var verifier = new glsBufferTestUtil.BufferVerifier(this.m_verifyType);
82 var srcRef = new glsBufferTestUtil.ReferenceBuffer();
83 var dstRef = new glsBufferTestUtil.ReferenceBuffer();
86 var srcSeed = deMath.binaryOp(deString.deStringHash(this.fullName()), 0xabcd, deMath.BinaryOp.XOR);
87 var dstSeed = deMath.binaryOp(deString.deStringHash(this.fullName()), 0xef01, deMath.BinaryOp.XOR);
90 srcRef.setSize(this.m_srcSize);
91 glsBufferTestUtil.fillWithRandomBytes(srcRef.getPtr(), this.m_srcSize, srcSeed);
93 dstRef.setSize(this.m_dstSize);
94 glsBufferTestUtil.fillWithRandomBytes(dstRef.getPtr(), this.m_dstSize, dstSeed);
96 // Create source buffer and fill with data.
97 srcBuf = this.genBuffer();
98 gl.bindBuffer(this.m_srcTarget, srcBuf);
99 gl.bufferData(this.m_srcTarget, srcRef.getPtr(), this.m_srcHint);
101 // Create destination buffer and fill with data.
102 dstBuf = this.genBuffer();
103 gl.bindBuffer(this.m_dstTarget, dstBuf);
104 gl.bufferData(this.m_dstTarget, dstRef.getPtr(), this.m_dstHint);
106 // Verify both buffers before executing copy.
107 isOk = verifier.verify(srcBuf, srcRef.getPtr(), 0, this.m_srcSize, this.m_srcTarget) && isOk;
108 isOk = verifier.verify(dstBuf, dstRef.getPtr(), 0, this.m_dstSize, this.m_dstTarget) && isOk;
111 dstRef.getPtr().set(srcRef.getPtr().subarray(this.m_copySrcOffset, this.m_copySrcOffset + this.m_copySize), this.m_copyDstOffset);
113 gl.bindBuffer(this.m_srcTarget, srcBuf);
114 gl.bindBuffer(this.m_dstTarget, dstBuf);
115 gl.copyBufferSubData(this.m_srcTarget, this.m_dstTarget, this.m_copySrcOffset, this.m_copyDstOffset, this.m_copySize);
117 // Verify both buffers after copy.
118 isOk = verifier.verify(srcBuf, srcRef.getPtr(), 0, this.m_srcSize, this.m_srcTarget) && isOk;
119 isOk = verifier.verify(dstBuf, dstRef.getPtr(), 0, this.m_dstSize, this.m_dstTarget) && isOk;
124 testFailed('Buffer verification failed');
126 return tcuTestCase.IterateResult.STOP;
129 // Case B: same buffer, take range as parameter
133 * @extends {glsBufferTestUtil.BufferCase}
134 * @param {string} name
135 * @param {string} desc
136 * @param {number} srcTarget
137 * @param {number} dstTarget
138 * @param {number} hint
139 * @param {glsBufferTestUtil.VerifyType} verifyType
141 es3fBufferCopyTests.SingleBufferCopyCase = function(name, desc, srcTarget, dstTarget, hint, verifyType) {
142 glsBufferTestUtil.BufferCase.call(this, name, desc);
143 this.m_srcTarget = srcTarget;
144 this.m_dstTarget = dstTarget;
146 this.m_verifyType = verifyType;
149 es3fBufferCopyTests.SingleBufferCopyCase.prototype = Object.create(glsBufferTestUtil.BufferCase.prototype);
150 es3fBufferCopyTests.SingleBufferCopyCase.prototype.constructor = es3fBufferCopyTests.SingleBufferCopyCase;
153 * @return {tcuTestCase.IterateResult}
155 es3fBufferCopyTests.SingleBufferCopyCase.prototype.iterate = function() {
157 /** @type {glsBufferTestUtil.BufferVerifier} */ var verifier = new glsBufferTestUtil.BufferVerifier(this.m_verifyType);
158 var ref = new glsBufferTestUtil.ReferenceBuffer();
159 var baseSeed = deString.deStringHash(this.fullName());
165 var buf = this.genBuffer();
166 gl.bindBuffer(this.m_srcTarget, buf);
168 /** @type {Array<{srcOffset: number, dstOffset: number, copySize: number}>} */
170 srcOffset: 57, dstOffset: 701, copySize: 101 // Non-adjecent, from low to high.
172 srcOffset: 640, dstOffset: 101, copySize: 101 // Non-adjecent, from high to low.
174 srcOffset: 0, dstOffset: 500, copySize: 500 // Lower half to upper half.
176 srcOffset: 500, dstOffset: 0, copySize: 500 // Upper half to lower half.
179 for (var ndx = 0; ndx < copyRanges.length && isOk; ndx++) {
180 var srcOffset = copyRanges[ndx].srcOffset;
181 var dstOffset = copyRanges[ndx].dstOffset;
182 var copySize = copyRanges[ndx].copySize;
184 glsBufferTestUtil.fillWithRandomBytes(ref.getPtr(), size, deMath.binaryOp(baseSeed, deMath.deMathHash(ndx), deMath.BinaryOp.XOR));
187 gl.bindBuffer(this.m_srcTarget, buf);
188 gl.bufferData(this.m_srcTarget, ref.getPtr(), this.m_hint);
191 ref.getPtr().set(ref.getPtr().subarray(srcOffset, srcOffset + copySize), dstOffset);
193 gl.bindBuffer(this.m_dstTarget, buf);
194 gl.copyBufferSubData(this.m_srcTarget, this.m_dstTarget, srcOffset, dstOffset, copySize);
196 // Verify buffer after copy.
197 isOk = verifier.verify(buf, ref.getPtr(), 0, size, this.m_dstTarget) && isOk;
203 testFailed('Buffer verification failed');
205 return tcuTestCase.IterateResult.STOP;
210 * @extends {tcuTestCase.DeqpTest}
212 es3fBufferCopyTests.BufferCopyTests = function() {
213 tcuTestCase.DeqpTest.call(this, 'copy', 'Buffer copy tests');
214 this.makeExecutable();
217 es3fBufferCopyTests.BufferCopyTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
218 es3fBufferCopyTests.BufferCopyTests.prototype.constructor = es3fBufferCopyTests.BufferCopyTests;
220 es3fBufferCopyTests.BufferCopyTests.prototype.init = function() {
221 /** @type {glsBufferTestUtil.VerifyType} */ var verify;
223 var bufferTargets = [
226 gl.COPY_WRITE_BUFFER,
227 gl.ELEMENT_ARRAY_BUFFER,
228 gl.PIXEL_PACK_BUFFER,
229 gl.PIXEL_UNPACK_BUFFER,
230 gl.TRANSFORM_FEEDBACK_BUFFER,
236 var basicGroup = new tcuTestCase.DeqpTest('basic', 'Basic buffer copy cases');
237 this.addChild(basicGroup);
239 for (var srcTargetNdx = 0; srcTargetNdx < bufferTargets.length; srcTargetNdx++) {
240 for (var dstTargetNdx = 0; dstTargetNdx < bufferTargets.length; dstTargetNdx++) {
241 if (srcTargetNdx == dstTargetNdx)
244 // In WebGL 2, a copy between an ELEMENT_ARRAY_BUFFER and other data buffer
245 // (not COPY_WRITE_BUFFER nor COPY_READ_BUFFER nor ELEMENT_ARRAY_BUFFER)
246 // cannot be made, so let's skip those cases.
247 if (bufferTargets[srcTargetNdx] == gl.ELEMENT_ARRAY_BUFFER ||
248 bufferTargets[dstTargetNdx] == gl.ELEMENT_ARRAY_BUFFER)
251 var srcTarget = bufferTargets[srcTargetNdx];
252 var dstTarget = bufferTargets[dstTargetNdx];
254 var hint = gl.STATIC_DRAW;
255 verify = glsBufferTestUtil.VerifyType.AS_VERTEX_ARRAY;
256 var name = glsBufferTestUtil.getBufferTargetName(srcTarget) + '_' + glsBufferTestUtil.getBufferTargetName(dstTarget);
258 basicGroup.addChild(new es3fBufferCopyTests.BasicBufferCopyCase(name, '', srcTarget, size, hint, dstTarget, size, hint, 0, 0, size, verify));
264 var subrangeGroup = new tcuTestCase.DeqpTest('subrange', 'Buffer subrange copy tests');
265 this.addChild(subrangeGroup);
268 * @type {Array<{name: string, srcSize: number, dstSize: number, srcOffset: number, dstOffset: number, copySize: number}>}
271 name: 'middle', srcSize: 1000, dstSize: 1000, srcOffset: 250, dstOffset: 250, copySize: 500
273 name: 'small_to_large', srcSize: 100, dstSize: 1000, srcOffset: 0, dstOffset: 409, copySize: 100
275 name: 'large_to_small', srcSize: 1000, dstSize: 100, srcOffset: 409, dstOffset: 0, copySize: 100
277 name: 'low_to_high_1', srcSize: 1000, dstSize: 1000, srcOffset: 0, dstOffset: 500, copySize: 500
279 name: 'low_to_high_2', srcSize: 997, dstSize: 1027, srcOffset: 0, dstOffset: 701, copySize: 111
281 name: 'high_to_low_1', srcSize: 1000, dstSize: 1000, srcOffset: 500, dstOffset: 0, copySize: 500
283 name: 'high_to_low_2', srcSize: 1027, dstSize: 997, srcOffset: 701, dstOffset: 17, copySize: 111
286 for (var ndx = 0; ndx < cases.length; ndx++) {
287 var srcTarget = gl.COPY_READ_BUFFER;
288 var dstTarget = gl.COPY_WRITE_BUFFER;
289 var hint = gl.STATIC_DRAW;
290 verify = glsBufferTestUtil.VerifyType.AS_VERTEX_ARRAY;
292 subrangeGroup.addChild(
293 new es3fBufferCopyTests.BasicBufferCopyCase(
295 srcTarget, cases[ndx].srcSize, hint,
296 dstTarget, cases[ndx].dstSize, hint,
297 cases[ndx].srcOffset, cases[ndx].dstOffset, cases[ndx].copySize,
305 var singleBufGroup = new tcuTestCase.DeqpTest('single_buffer', 'Copies within single buffer');
306 this.addChild(singleBufGroup);
308 for (var srcTargetNdx = 0; srcTargetNdx < bufferTargets.length; srcTargetNdx++) {
309 for (var dstTargetNdx = 0; dstTargetNdx < bufferTargets.length; dstTargetNdx++) {
310 if (srcTargetNdx == dstTargetNdx)
313 // In WebGL 2, we can't rebind an ELEMENT_ARRAY_BUFFER or TRANSFORM_FEEDBACK_BUFFER as a
314 // different type of buffer, so we skip those cases.
315 if (bufferTargets[srcTargetNdx] == gl.ELEMENT_ARRAY_BUFFER || bufferTargets[srcTargetNdx] == gl.TRANSFORM_FEEDBACK_BUFFER ||
316 bufferTargets[dstTargetNdx] == gl.ELEMENT_ARRAY_BUFFER || bufferTargets[dstTargetNdx] == gl.TRANSFORM_FEEDBACK_BUFFER)
319 var srcTarget = bufferTargets[srcTargetNdx];
320 var dstTarget = bufferTargets[dstTargetNdx];
321 var hint = gl.STATIC_DRAW;
322 verify = glsBufferTestUtil.VerifyType.AS_VERTEX_ARRAY;
323 var name = glsBufferTestUtil.getBufferTargetName(srcTarget) + '_' + glsBufferTestUtil.getBufferTargetName(dstTarget);
325 singleBufGroup.addChild(new es3fBufferCopyTests.SingleBufferCopyCase(name, '', srcTarget, dstTarget, hint, verify));
331 * Create and execute the test cases
332 * @param {WebGL2RenderingContext} context
334 es3fBufferCopyTests.run = function(context) {
336 //Set up Test Root parameters
337 var state = tcuTestCase.runner;
339 state.setRoot(new es3fBufferCopyTests.BufferCopyTests());
341 //Set up name and description of this test series.
342 setCurrentTestName(state.testCases.fullName());
343 description(state.testCases.getDescription());
347 tcuTestCase.runTestCases();
350 testFailedOptions('Failed to run tests', false);
351 tcuTestCase.runner.terminate();