tor-browser

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

es3fTextureWrapTests.js (19939B)


      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.es3fTextureWrapTests');
     23 goog.require('framework.common.tcuCompressedTexture');
     24 goog.require('framework.common.tcuPixelFormat');
     25 goog.require('framework.common.tcuSurface');
     26 goog.require('framework.common.tcuTestCase');
     27 goog.require('framework.common.tcuTexLookupVerifier');
     28 goog.require('framework.common.tcuTexture');
     29 goog.require('framework.common.tcuTextureUtil');
     30 goog.require('framework.delibs.debase.deMath');
     31 goog.require('framework.delibs.debase.deRandom');
     32 goog.require('framework.delibs.debase.deString');
     33 goog.require('framework.opengl.gluShaderUtil');
     34 goog.require('framework.opengl.gluTexture');
     35 goog.require('framework.opengl.gluTextureUtil');
     36 goog.require('modules.shared.glsTextureTestUtil');
     37 
     38 goog.scope(function() {
     39    /** @type {?WebGL2RenderingContext} */ var gl;
     40 
     41    var es3fTextureWrapTests = functional.gles3.es3fTextureWrapTests;
     42    var tcuTestCase = framework.common.tcuTestCase;
     43    var gluTexture = framework.opengl.gluTexture;
     44    var gluTextureUtil = framework.opengl.gluTextureUtil;
     45    var gluShaderUtil = framework.opengl.gluShaderUtil;
     46    var glsTextureTestUtil = modules.shared.glsTextureTestUtil;
     47    var tcuCompressedTexture = framework.common.tcuCompressedTexture;
     48    var deRandom = framework.delibs.debase.deRandom;
     49    var deMath = framework.delibs.debase.deMath;
     50    var tcuPixelFormat = framework.common.tcuPixelFormat;
     51    var tcuSurface = framework.common.tcuSurface;
     52    var tcuTexLookupVerifier = framework.common.tcuTexLookupVerifier;
     53    var tcuTexture = framework.common.tcuTexture;
     54    var tcuTextureUtil = framework.common.tcuTextureUtil;
     55    var deString = framework.delibs.debase.deString;
     56 
     57    /**
     58     * @enum {number}
     59     */
     60    var Viewport = {
     61        WIDTH: 256,
     62        HEIGHT: 256
     63    };
     64 
     65    /**
     66     * @constructor
     67     * @param {Array<number>=} bl
     68     * @param {Array<number>=} tr
     69     */
     70    es3fTextureWrapTests.Case = function(bl, tr) {
     71        /** @type {?Array<number>} */ this.bottomLeft = bl || null;
     72        /** @type {?Array<number>} */ this.topRight = tr || null;
     73    };
     74 
     75    /**
     76     * @constructor
     77     * @extends {tcuTestCase.DeqpTest}
     78     * @param {string} name
     79     * @param {string} description
     80     * @param {?tcuCompressedTexture.Format} compressedFormat
     81     * @param {number} wrapS
     82     * @param {number} wrapT
     83     * @param {number} minFilter
     84     * @param {number} magFilter
     85     * @param {number} width
     86     * @param {number} height
     87     */
     88    es3fTextureWrapTests.TextureWrapCase = function(name, description, compressedFormat, wrapS, wrapT, minFilter, magFilter, width, height) {
     89        tcuTestCase.DeqpTest.call(this, name, description);
     90        /** @type {number} */ this.m_format = gl.NONE;
     91        /** @type {number} */ this.m_dataType = gl.NONE;
     92        /** @type {?tcuCompressedTexture.Format} */ this.m_compressedFormat = compressedFormat;
     93        /** @type {number} */ this.m_wrapS = wrapS;
     94        /** @type {number} */ this.m_wrapT = wrapT;
     95        /** @type {number} */ this.m_minFilter = minFilter;
     96        /** @type {number} */ this.m_magFilter = magFilter;
     97        /** @type {number} */ this.m_width = width;
     98        /** @type {number} */ this.m_height = height;
     99        /** @type {Array<es3fTextureWrapTests.Case>} */ this.m_cases = [];
    100        /** @type {number} */ this.m_caseNdx = 0;
    101        /** @type {gluTexture.Texture2D} */ this.m_texture = null;
    102        /** @type {glsTextureTestUtil.TextureRenderer} */
    103        this.m_renderer = new glsTextureTestUtil.TextureRenderer(gluShaderUtil.getGLSLVersionString(gluShaderUtil.GLSLVersion.V300_ES), gluShaderUtil.precision.PRECISION_MEDIUMP);
    104    };
    105 
    106    es3fTextureWrapTests.TextureWrapCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
    107 
    108    /** Copy the constructor */
    109    es3fTextureWrapTests.TextureWrapCase.prototype.constructor = es3fTextureWrapTests.TextureWrapCase;
    110 
    111    /**
    112     * @param {string} name
    113     * @param {string} description
    114     * @param {number} format
    115     * @param {number} dataType
    116     * @param {number} wrapS
    117     * @param {number} wrapT
    118     * @param {number} minFilter
    119     * @param {number} magFilter
    120     * @param {number} width
    121     * @param {number} height
    122     * @return {es3fTextureWrapTests.TextureWrapCase}
    123     */
    124    es3fTextureWrapTests.textureWrapCaseFromFormat = function(name, description, format, dataType, wrapS, wrapT, minFilter, magFilter, width, height) {
    125        var texWrapCase = new es3fTextureWrapTests.TextureWrapCase(name, description, null, wrapS, wrapT, minFilter, magFilter, width, height);
    126        texWrapCase.m_format = gl.RGBA;
    127        texWrapCase.m_dataType = gl.UNSIGNED_BYTE;
    128        return texWrapCase;
    129    };
    130 
    131    /**
    132     */
    133    es3fTextureWrapTests.TextureWrapCase.prototype.init = function() {
    134        if (this.m_compressedFormat !== null) {
    135            // Generate compressed texture.
    136 
    137            assertMsgOptions(this.m_format == gl.NONE && this.m_dataType == gl.NONE, 'init/compressedFormat', false, true);
    138            if (tcuCompressedTexture.isEtcFormat(this.m_compressedFormat)) {
    139                // Create ETC texture. Any content is valid.
    140 
    141                /** @type {tcuCompressedTexture.CompressedTexture}*/
    142                var compressedTexture = new tcuCompressedTexture.CompressedTexture(this.m_compressedFormat, this.m_width, this.m_height);
    143                /** @type {number} */ var dataSize = compressedTexture.getDataSize();
    144                /** @type {goog.NumberArray} */ var data = compressedTexture.getData();
    145                /** @type {deRandom.Random} */ var rnd = new deRandom.Random(deString.deStringHash(this.name));
    146 
    147                for (var i = 0; i < dataSize; i++)
    148                    data[i] = rnd.getFloat() & 0xff;
    149 
    150                this.m_texture = gluTexture.texture2DFromCompressedTexture(gl, 1, [compressedTexture]);
    151            } else
    152                throw new Error('Only ETC2 and EAC are supported.');
    153        } else{
    154            this.m_texture = gluTexture.texture2DFromFormat(gl, this.m_format, this.m_dataType, this.m_width, this.m_height);
    155 
    156            // Fill level 0.
    157            this.m_texture.getRefTexture().allocLevel(0);
    158            tcuTextureUtil.fillWithComponentGradients(this.m_texture.getRefTexture().getLevel(0), [-0.5, -0.5, -0.5, 2.0], [1.0, 1.0, 1.0, 0.0]);
    159 
    160            this.m_texture.upload();
    161        }
    162 
    163        // Sub-cases.
    164 
    165        this.m_cases.push(new es3fTextureWrapTests.Case([-1.5, -3.0], [1.5, 2.5]));
    166        this.m_cases.push(new es3fTextureWrapTests.Case([-0.5, 0.75], [0.25, 1.25]));
    167        assertMsgOptions(this.m_caseNdx == 0, 'm_caseNdx != 0', false, true);
    168    };
    169 
    170    /**
    171     * @return {tcuTestCase.IterateResult}
    172     */
    173    es3fTextureWrapTests.TextureWrapCase.prototype.iterate = function() {
    174        /** @type {glsTextureTestUtil.RandomViewport} */ var viewport = new glsTextureTestUtil.RandomViewport(gl.canvas, Viewport.WIDTH, Viewport.HEIGHT, deString.deStringHash(this.name) + this.m_caseNdx);
    175        /** @type {tcuSurface.Surface} */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    176        /** @type {tcuSurface.Surface} */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    177        /** @type {glsTextureTestUtil.ReferenceParams} */ var refParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_2D);
    178        /** @type {tcuTexture.TextureFormat} */ var texFormat = this.m_texture.getRefTexture().getFormat();
    179        /** @type {Array<number>} */ var texCoord;
    180        /** @type {tcuTextureUtil.TextureFormatInfo} */ var texFormatInfo = tcuTextureUtil.getTextureFormatInfo(texFormat);
    181        /** @type {boolean} */ var useDefaultColorScaleAndBias = true;
    182 
    183        // Bind to unit 0.
    184        gl.activeTexture(gl.TEXTURE0);
    185        gl.bindTexture(gl.TEXTURE_2D, this.m_texture.getGLTexture());
    186 
    187        // Setup filtering and wrap modes.
    188        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.m_wrapS);
    189        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.m_wrapT);
    190        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.m_minFilter);
    191        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.m_magFilter);
    192 
    193        // Parameters for reference images.
    194        refParams.sampler = gluTextureUtil.mapGLSamplerWrapST(this.m_wrapS, this.m_wrapT, this.m_minFilter, this.m_magFilter);
    195        refParams.lodMode = glsTextureTestUtil.lodMode.EXACT;
    196        refParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    197        refParams.colorScale = useDefaultColorScaleAndBias ? texFormatInfo.lookupScale : [1.0, 1.0, 1.0, 1.0];
    198        refParams.colorBias = useDefaultColorScaleAndBias ? texFormatInfo.lookupBias : [0, 0, 0, 0];
    199 
    200        gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
    201        texCoord = glsTextureTestUtil.computeQuadTexCoord2D(this.m_cases[this.m_caseNdx].bottomLeft, this.m_cases[this.m_caseNdx].topRight);
    202        this.m_renderer.renderQuad(0, texCoord, refParams);
    203 
    204        // gluPixelTransfer.readPixels(viewport.x, viewport.y, renderedFrame.getAccess());
    205        /** @type {number} */ var pixelSize = renderedFrame.getAccess().getFormat().getPixelSize();
    206        /** @type {number} */ var param = deMath.deIsPowerOfTwo32(pixelSize) ? Math.min(pixelSize, 8) : 1;
    207 
    208        gl.pixelStorei(gl.PACK_ALIGNMENT, param);
    209        /** @type {gluTextureUtil.TransferFormat} */ var format = gluTextureUtil.getTransferFormat(renderedFrame.getAccess().getFormat());
    210 
    211        renderedFrame.readViewport(gl, viewport);
    212 
    213        // const tcu::ScopedLogSection section (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
    214        /** @type {boolean} */ var isNearestOnly = this.m_minFilter == gl.NEAREST && this.m_magFilter == gl.NEAREST;
    215        /** @type {boolean} */ var isSRGB = texFormat.order == tcuTexture.ChannelOrder.sRGB || texFormat.order == tcuTexture.ChannelOrder.sRGBA;
    216        /** @type {tcuPixelFormat.PixelFormat} */ var pixelFormat = new tcuPixelFormat.PixelFormat(8, 8, 8, 8);
    217        /** @type {Array<number>} */ var colorBits = deMath.max(deMath.subtract(glsTextureTestUtil.getBitsVec(pixelFormat), (isNearestOnly && !isSRGB ? [1, 1, 1, 1] : [2, 2, 2, 2])), [0, 0, 0, 0]);
    218        /** @type {tcuTexLookupVerifier.LodPrecision} */ var lodPrecision = new tcuTexLookupVerifier.LodPrecision(18, 5);
    219        /** @type {tcuTexLookupVerifier.LookupPrecision} */
    220        var lookupPrecision = new tcuTexLookupVerifier.LookupPrecision(
    221            [20, 20, 0],
    222            [5, 5, 0],
    223            deMath.divide(tcuTexLookupVerifier.computeFixedPointThreshold(colorBits), refParams.colorScale),
    224            glsTextureTestUtil.getCompareMask(pixelFormat)
    225        );
    226 
    227        // log << TestLog::Message << "Note: lookup coordinates: bottom-left " << m_cases[m_caseNdx].bottomLeft << ", top-right " << m_cases[m_caseNdx].topRight << TestLog::EndMessage;
    228 
    229        /** @type {boolean} */ var isOk = glsTextureTestUtil.verifyTexture2DResult(renderedFrame.getAccess(), this.m_texture.getRefTexture(), texCoord, refParams, lookupPrecision, lodPrecision, pixelFormat);
    230 
    231        if (!isOk)
    232            testFailedOptions('Case ' + this.m_caseNdx + ': verifyTexture2DResult is false', false);
    233        else
    234            testPassedOptions('Case ' + this.m_caseNdx + ': OK', true);
    235 
    236        this.m_caseNdx++;
    237 
    238        return this.m_caseNdx < this.m_cases.length ? tcuTestCase.IterateResult.CONTINUE : tcuTestCase.IterateResult.STOP;
    239    };
    240 
    241    /**
    242     * Initialize test
    243     */
    244    es3fTextureWrapTests.init = function() {
    245        var testGroup = tcuTestCase.runner.testCases;
    246        /** @type {string} */ var name;
    247        /**
    248         * @constructor
    249         * @struct
    250         * @param {string} name
    251         * @param {number} mode
    252         */
    253        var WrapMode = function(name, mode) {
    254            /** @type {string} */ this.name = name;
    255            /** @type {number} */ this.mode = mode;
    256        };
    257 
    258        /** @type {Array<WrapMode>} */ var wrapModes = [
    259            new WrapMode('clamp', gl.CLAMP_TO_EDGE),
    260            new WrapMode('repeat', gl.REPEAT),
    261            new WrapMode('mirror', gl.MIRRORED_REPEAT)
    262        ];
    263 
    264        /**
    265         * @constructor
    266         * @struct
    267         * @param {string} name
    268         * @param {number} mode
    269         */
    270        var FilteringMode = function(name, mode) {
    271            /** @type {string} */ this.name = name;
    272            /** @type {number} */ this.mode = mode;
    273        };
    274 
    275        /** @type {Array<FilteringMode>} */ var filteringModes = [
    276            new FilteringMode('nearest', gl.NEAREST),
    277            new FilteringMode('linear', gl.LINEAR)
    278        ];
    279 
    280        /* Begin RGBA8 Cases */
    281        /**
    282         * @constructor
    283         * @struct
    284         * @param {string} name
    285         * @param {number} width
    286         * @param {number} height
    287         */
    288        var Rgba8Size = function(name, width, height) {
    289            /** @type {string} */ this.name = name;
    290            /** @type {number} */ this.width = width;
    291            /** @type {number} */ this.height = height;
    292        };
    293 
    294        /** @type {Array<Rgba8Size>} */ var rgba8Sizes = [
    295            new Rgba8Size('pot', 64, 128),
    296            new Rgba8Size('npot', 63, 112)
    297        ];
    298 
    299        for (var size = 0; size < rgba8Sizes.length; size++) {
    300            /** @type {tcuTestCase.DeqpTest} */ var rgba8Group = tcuTestCase.newTest('rgba8', '');
    301            testGroup.addChild(rgba8Group);
    302            for (var wrapS = 0; wrapS < wrapModes.length; wrapS++) {
    303                for (var wrapT = 0; wrapT < wrapModes.length; wrapT++) {
    304                    for (var filter = 0; filter < filteringModes.length; filter++) {
    305                        name = [
    306                            wrapModes[wrapS].name,
    307                            wrapModes[wrapT].name,
    308                            filteringModes[filter].name,
    309                            rgba8Sizes[size].name
    310                        ].join('_');
    311 
    312                        rgba8Group.addChild(es3fTextureWrapTests.textureWrapCaseFromFormat(
    313                            name, '',
    314                            gl.RGBA, gl.UNSIGNED_BYTE,
    315                            wrapModes[wrapS].mode,
    316                            wrapModes[wrapT].mode,
    317                            filteringModes[filter].mode, filteringModes[filter].mode,
    318                            rgba8Sizes[size].width, rgba8Sizes[size].height
    319                        ));
    320                    }
    321                }
    322            }
    323        }
    324        /* End RGBA8 Cases */
    325 
    326        /* Begin ETC-2 (and EAC) cases */
    327        /**
    328         * @constructor
    329         * @struct
    330         * @param {string} name
    331         * @param {tcuCompressedTexture.Format} format
    332         */
    333        var Etc2Format = function(name, format) {
    334            /** @type {string} */ this.name = name;
    335            /** @type {tcuCompressedTexture.Format} */ this.format = format;
    336        };
    337 
    338        var etc2Formats = [
    339            new Etc2Format('eac_r11', tcuCompressedTexture.Format.EAC_R11),
    340            new Etc2Format('eac_signed_r11', tcuCompressedTexture.Format.EAC_SIGNED_R11),
    341            new Etc2Format('eac_rg11', tcuCompressedTexture.Format.EAC_RG11),
    342            new Etc2Format('eac_signed_rg11', tcuCompressedTexture.Format.EAC_SIGNED_RG11),
    343            new Etc2Format('etc2_rgb8', tcuCompressedTexture.Format.ETC2_RGB8),
    344            new Etc2Format('etc2_srgb8', tcuCompressedTexture.Format.ETC2_SRGB8),
    345            new Etc2Format('etc2_rgb8_punchthrough_alpha1', tcuCompressedTexture.Format.ETC2_RGB8_PUNCHTHROUGH_ALPHA1),
    346            new Etc2Format('etc2_srgb8_punchthrough_alpha1', tcuCompressedTexture.Format.ETC2_SRGB8_PUNCHTHROUGH_ALPHA1),
    347            new Etc2Format('etc2_eac_rgba8', tcuCompressedTexture.Format.ETC2_EAC_RGBA8),
    348            new Etc2Format('etc2_eac_srgb8_alpha8', tcuCompressedTexture.Format.ETC2_EAC_SRGB8_ALPHA8)
    349        ];
    350        if (!gluTextureUtil.enableCompressedTextureETC()) {
    351            debug('Skipping ETC2/EAC texture format tests: no support for WEBGL_compressed_texture_etc');
    352            etc2Formats = [];
    353        }
    354 
    355        /**
    356         * @constructor
    357         * @struct
    358         * @param {string} name
    359         * @param {number} width
    360         * @param {number} height
    361         */
    362        var Etc2Size = function(name, width, height) {
    363            /** @type {string} */ this.name = name;
    364            /** @type {number} */ this.width = width;
    365            /** @type {number} */ this.height = height;
    366        };
    367 
    368        /** @type {Array<Etc2Size>} */ var etc2Sizes = [
    369            new Etc2Size('pot', 64, 128),
    370            new Etc2Size('npot', 123, 107)
    371        ];
    372 
    373        for (var formatNdx = 0; formatNdx < etc2Formats.length; formatNdx++) {
    374            for (var size = 0; size < etc2Sizes.length; size++) {
    375                /** @type {tcuTestCase.DeqpTest} */ var formatGroup = tcuTestCase.newTest(etc2Formats[formatNdx].name, '');
    376                testGroup.addChild(formatGroup);
    377                for (var wrapS = 0; wrapS < wrapModes.length; wrapS++) {
    378                    for (var wrapT = 0; wrapT < wrapModes.length; wrapT++) {
    379                        for (var filter = 0; filter < filteringModes.length; filter++) {
    380                            name = [
    381                                wrapModes[wrapS].name,
    382                                wrapModes[wrapT].name,
    383                                filteringModes[filter].name,
    384                                etc2Sizes[size].name
    385                            ].join('_');
    386 
    387                            formatGroup.addChild(new es3fTextureWrapTests.TextureWrapCase(
    388                                name, '',
    389                                etc2Formats[formatNdx].format,
    390                                wrapModes[wrapS].mode,
    391                                wrapModes[wrapT].mode,
    392                                filteringModes[filter].mode, filteringModes[filter].mode,
    393                                etc2Sizes[size].width, etc2Sizes[size].height
    394                            ));
    395                        }
    396                    }
    397                }
    398            }
    399        }
    400    };
    401 
    402    /**
    403     * Run test
    404     * @param {WebGL2RenderingContext} context
    405     */
    406    es3fTextureWrapTests.run = function(context, range) {
    407        gl = context;
    408        //Set up Test Root parameters
    409        var testName = 'texture_wrap';
    410        var testDescription = 'Texture Wrap Tests';
    411        var state = tcuTestCase.runner;
    412 
    413        state.testName = testName;
    414        state.setRoot(tcuTestCase.newTest(testName, testDescription, null));
    415 
    416        //Set up name and description of this test series.
    417        setCurrentTestName(testName);
    418        description(testDescription);
    419 
    420        try {
    421            //Create test cases
    422            es3fTextureWrapTests.init();
    423            if (range)
    424                state.setRange(range);
    425            //Run test cases
    426            tcuTestCase.runTestCases();
    427        }
    428        catch (err) {
    429            testFailedOptions('Failed to es3fTextureWrapTests.run tests', false);
    430            state.terminate();
    431        }
    432    };
    433 
    434 });