tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

es3fBufferCopyTests.js (15332B)


      1 /*-------------------------------------------------------------------------
      2 * drawElements Quality Program OpenGL ES Utilities
      3 * ------------------------------------------------
      4 *
      5 * Copyright 2014 The Android Open Source Project
      6 *
      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
     10 *
     11 *      http://www.apache.org/licenses/LICENSE-2.0
     12 *
     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.
     18 *
     19 */
     20 
     21 'use strict';
     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');
     28 
     29 goog.scope(function() {
     30 
     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;
     37 
     38    /** @type {WebGL2RenderingContext} */ var gl;
     39 
     40    /**
     41     * @constructor
     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
     55     */
     56    es3fBufferCopyTests.BasicBufferCopyCase = function(name, desc, srcTarget, srcSize, srcHint, dstTarget, dstSize, dstHint, copySrcOffset, copyDstOffset, copySize, verifyType) {
     57        glsBufferTestUtil.BufferCase.call(this, name, desc);
     58 
     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;
     69 
     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);
     72    };
     73 
     74    es3fBufferCopyTests.BasicBufferCopyCase.prototype = Object.create(glsBufferTestUtil.BufferCase.prototype);
     75    es3fBufferCopyTests.BasicBufferCopyCase.prototype.constructor = es3fBufferCopyTests.BasicBufferCopyCase;
     76 
     77    /**
     78     * @return {tcuTestCase.IterateResult}
     79     */
     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();
     84        var srcBuf = 0;
     85        var dstBuf = 0;
     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);
     88        var isOk = true;
     89 
     90        srcRef.setSize(this.m_srcSize);
     91        glsBufferTestUtil.fillWithRandomBytes(srcRef.getPtr(), this.m_srcSize, srcSeed);
     92 
     93        dstRef.setSize(this.m_dstSize);
     94        glsBufferTestUtil.fillWithRandomBytes(dstRef.getPtr(), this.m_dstSize, dstSeed);
     95 
     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);
    100 
    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);
    105 
    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;
    109 
    110        // Execute copy.
    111        dstRef.getPtr().set(srcRef.getPtr().subarray(this.m_copySrcOffset, this.m_copySrcOffset + this.m_copySize), this.m_copyDstOffset);
    112 
    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);
    116 
    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;
    120 
    121        if (isOk)
    122            testPassed('');
    123        else
    124            testFailed('Buffer verification failed');
    125 
    126        return tcuTestCase.IterateResult.STOP;
    127    };
    128 
    129    // Case B: same buffer, take range as parameter
    130 
    131    /**
    132     * @constructor
    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
    140     */
    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;
    145        this.m_hint = hint;
    146        this.m_verifyType = verifyType;
    147    };
    148 
    149    es3fBufferCopyTests.SingleBufferCopyCase.prototype = Object.create(glsBufferTestUtil.BufferCase.prototype);
    150    es3fBufferCopyTests.SingleBufferCopyCase.prototype.constructor = es3fBufferCopyTests.SingleBufferCopyCase;
    151 
    152    /**
    153     * @return {tcuTestCase.IterateResult}
    154     */
    155     es3fBufferCopyTests.SingleBufferCopyCase.prototype.iterate = function() {
    156        var size = 1000;
    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());
    160        var isOk = true;
    161 
    162        ref.setSize(size);
    163 
    164        // Create buffer.
    165        var buf = this.genBuffer();
    166        gl.bindBuffer(this.m_srcTarget, buf);
    167 
    168        /** @type {Array<{srcOffset: number, dstOffset: number, copySize: number}>} */
    169        var copyRanges = [{
    170                srcOffset: 57, dstOffset: 701, copySize: 101 // Non-adjecent, from low to high.
    171            },{
    172                srcOffset: 640, dstOffset: 101, copySize: 101 // Non-adjecent, from high to low.
    173            },{
    174                srcOffset: 0, dstOffset: 500, copySize: 500 // Lower half to upper half.
    175            },{
    176                srcOffset: 500, dstOffset: 0, copySize: 500 // Upper half to lower half.
    177        }];
    178 
    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;
    183 
    184            glsBufferTestUtil.fillWithRandomBytes(ref.getPtr(), size, deMath.binaryOp(baseSeed, deMath.deMathHash(ndx), deMath.BinaryOp.XOR));
    185 
    186            // Fill with data.
    187            gl.bindBuffer(this.m_srcTarget, buf);
    188            gl.bufferData(this.m_srcTarget, ref.getPtr(), this.m_hint);
    189 
    190            // Execute copy.
    191            ref.getPtr().set(ref.getPtr().subarray(srcOffset, srcOffset + copySize), dstOffset);
    192 
    193            gl.bindBuffer(this.m_dstTarget, buf);
    194            gl.copyBufferSubData(this.m_srcTarget, this.m_dstTarget, srcOffset, dstOffset, copySize);
    195 
    196            // Verify buffer after copy.
    197            isOk = verifier.verify(buf, ref.getPtr(), 0, size, this.m_dstTarget) && isOk;
    198        }
    199 
    200        if (isOk)
    201            testPassed('');
    202        else
    203            testFailed('Buffer verification failed');
    204 
    205        return tcuTestCase.IterateResult.STOP;
    206    };
    207 
    208    /**
    209     * @constructor
    210     * @extends {tcuTestCase.DeqpTest}
    211     */
    212    es3fBufferCopyTests.BufferCopyTests = function() {
    213        tcuTestCase.DeqpTest.call(this, 'copy', 'Buffer copy tests');
    214        this.makeExecutable();
    215    };
    216 
    217    es3fBufferCopyTests.BufferCopyTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
    218    es3fBufferCopyTests.BufferCopyTests.prototype.constructor = es3fBufferCopyTests.BufferCopyTests;
    219 
    220    es3fBufferCopyTests.BufferCopyTests.prototype.init = function() {
    221        /** @type {glsBufferTestUtil.VerifyType} */ var verify;
    222 
    223        var bufferTargets = [
    224            gl.ARRAY_BUFFER,
    225            gl.COPY_READ_BUFFER,
    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,
    231            gl.UNIFORM_BUFFER
    232        ];
    233 
    234        // .basic
    235 
    236        var basicGroup = new tcuTestCase.DeqpTest('basic', 'Basic buffer copy cases');
    237        this.addChild(basicGroup);
    238 
    239        for (var srcTargetNdx = 0; srcTargetNdx < bufferTargets.length; srcTargetNdx++) {
    240            for (var dstTargetNdx = 0; dstTargetNdx < bufferTargets.length; dstTargetNdx++) {
    241                if (srcTargetNdx == dstTargetNdx)
    242                    continue;
    243 
    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)
    249                    continue;
    250 
    251                var srcTarget = bufferTargets[srcTargetNdx];
    252                var dstTarget = bufferTargets[dstTargetNdx];
    253                var size = 1017;
    254                var hint = gl.STATIC_DRAW;
    255                verify = glsBufferTestUtil.VerifyType.AS_VERTEX_ARRAY;
    256                var name = glsBufferTestUtil.getBufferTargetName(srcTarget) + '_' + glsBufferTestUtil.getBufferTargetName(dstTarget);
    257 
    258                basicGroup.addChild(new es3fBufferCopyTests.BasicBufferCopyCase(name, '', srcTarget, size, hint, dstTarget, size, hint, 0, 0, size, verify));
    259            }
    260        }
    261 
    262        // .subrange
    263 
    264        var subrangeGroup = new tcuTestCase.DeqpTest('subrange', 'Buffer subrange copy tests');
    265        this.addChild(subrangeGroup);
    266 
    267        /**
    268         * @type {Array<{name: string, srcSize: number, dstSize: number, srcOffset: number, dstOffset: number, copySize: number}>}
    269         */
    270        var cases = [{
    271                name: 'middle', srcSize: 1000, dstSize: 1000, srcOffset: 250, dstOffset: 250, copySize: 500
    272            },{
    273                name: 'small_to_large', srcSize: 100, dstSize: 1000, srcOffset: 0, dstOffset: 409, copySize: 100
    274            },{
    275                name: 'large_to_small', srcSize: 1000, dstSize: 100, srcOffset: 409, dstOffset: 0, copySize: 100
    276            },{
    277                name: 'low_to_high_1', srcSize: 1000, dstSize: 1000, srcOffset: 0, dstOffset: 500, copySize: 500
    278            },{
    279                name: 'low_to_high_2', srcSize: 997, dstSize: 1027, srcOffset: 0, dstOffset: 701, copySize: 111
    280            },{
    281                name: 'high_to_low_1', srcSize: 1000, dstSize: 1000, srcOffset: 500, dstOffset: 0, copySize: 500
    282            },{
    283                name: 'high_to_low_2', srcSize: 1027, dstSize: 997, srcOffset: 701, dstOffset: 17, copySize: 111
    284        }];
    285 
    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;
    291 
    292            subrangeGroup.addChild(
    293                new es3fBufferCopyTests.BasicBufferCopyCase(
    294                    cases[ndx].name, '',
    295                    srcTarget, cases[ndx].srcSize, hint,
    296                    dstTarget, cases[ndx].dstSize, hint,
    297                    cases[ndx].srcOffset, cases[ndx].dstOffset, cases[ndx].copySize,
    298                    verify
    299                )
    300            );
    301        }
    302 
    303        // .single_buffer
    304 
    305        var singleBufGroup = new tcuTestCase.DeqpTest('single_buffer', 'Copies within single buffer');
    306        this.addChild(singleBufGroup);
    307 
    308        for (var srcTargetNdx = 0; srcTargetNdx < bufferTargets.length; srcTargetNdx++) {
    309            for (var dstTargetNdx = 0; dstTargetNdx < bufferTargets.length; dstTargetNdx++) {
    310                if (srcTargetNdx == dstTargetNdx)
    311                    continue;
    312 
    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)
    317                    continue;
    318 
    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);
    324 
    325                singleBufGroup.addChild(new es3fBufferCopyTests.SingleBufferCopyCase(name, '', srcTarget, dstTarget, hint, verify));
    326            }
    327        }
    328    };
    329 
    330    /**
    331     * Create and execute the test cases
    332     * @param {WebGL2RenderingContext} context
    333     */
    334     es3fBufferCopyTests.run = function(context) {
    335        gl = context;
    336        //Set up Test Root parameters
    337        var state = tcuTestCase.runner;
    338 
    339        state.setRoot(new es3fBufferCopyTests.BufferCopyTests());
    340 
    341        //Set up name and description of this test series.
    342        setCurrentTestName(state.testCases.fullName());
    343        description(state.testCases.getDescription());
    344 
    345        try {
    346            //Run test cases
    347            tcuTestCase.runTestCases();
    348        }
    349        catch (err) {
    350            testFailedOptions('Failed to run tests', false);
    351            tcuTestCase.runner.terminate();
    352        }
    353    };
    354 
    355 });