Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / deqp / functional / gles3 / es3fTextureStateQuery.js
blobab1f4d6bb9b24091c8e284b3f40ec57202aa9d48
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  */
21 'use strict';
22 goog.provide('functional.gles3.es3fTextureStateQuery');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('framework.delibs.debase.deRandom');
25 goog.require('functional.gles3.es3fApiCase');
26 goog.require('modules.shared.glsStateQuery');
28 goog.scope(function() {
29 var es3fTextureStateQuery = functional.gles3.es3fTextureStateQuery;
30 var tcuTestCase = framework.common.tcuTestCase;
31 var glsStateQuery = modules.shared.glsStateQuery;
32 var es3fApiCase = functional.gles3.es3fApiCase;
33 var deRandom = framework.delibs.debase.deRandom;
35 var setParentClass = function(child, parent) {
36     child.prototype = Object.create(parent.prototype);
37     child.prototype.constructor = child;
40 /**
41  * @constructor
42  * @extends {es3fApiCase.ApiCase}
43  * @param {string} name
44  * @param {string} description
45  * @param {number} textureTarget
46  */
47 es3fTextureStateQuery.TextureCase = function(name, description, textureTarget) {
48     es3fApiCase.ApiCase.call(this, name, description, gl);
49     /** @type {WebGLTexture} */ this.m_texture;
50     this.m_textureTarget = textureTarget;
53 setParentClass(es3fTextureStateQuery.TextureCase, es3fApiCase.ApiCase);
55 es3fTextureStateQuery.TextureCase.prototype.testTexture = function() {
56     throw new Error('Virtual function. Please override.');
59 es3fTextureStateQuery.TextureCase.prototype.test = function() {
60     this.m_texture = gl.createTexture();
61     gl.bindTexture(this.m_textureTarget, this.m_texture);
63     this.testTexture();
65     gl.bindTexture(this.m_textureTarget, null);
66     gl.deleteTexture(this.m_texture);
69 /**
70  * @constructor
71  * @extends {es3fTextureStateQuery.TextureCase}
72  * @param {string} name
73  * @param {string} description
74  * @param {number} textureTarget
75  */
76 es3fTextureStateQuery.IsTextureCase = function(name, description, textureTarget) {
77     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
80 setParentClass(es3fTextureStateQuery.IsTextureCase, es3fTextureStateQuery.TextureCase);
82 es3fTextureStateQuery.IsTextureCase.prototype.testTexture = function() {
83     this.check(glsStateQuery.compare(gl.isTexture(this.m_texture), true), 'gl.isTexture() should have returned true');
86 /**
87  * @constructor
88  * @extends {es3fTextureStateQuery.TextureCase}
89  * @param {string} name
90  * @param {string} description
91  * @param {number} textureTarget
92  * @param {number} valueName
93  * @param {number} initialValue
94  * @param {Array<number>} valueRange
95  */
96 es3fTextureStateQuery.TextureParamCase = function(name, description, textureTarget, valueName, initialValue, valueRange) {
97     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
98     this.m_valueName = valueName;
99     this.m_initialValue = initialValue;
100     this.m_valueRange = valueRange;
103 setParentClass(es3fTextureStateQuery.TextureParamCase, es3fTextureStateQuery.TextureCase);
105 es3fTextureStateQuery.TextureParamCase.prototype.testTexture = function() {
106     this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_valueName, this.m_initialValue));
108     for (var ndx = 0; ndx < this.m_valueRange.length; ++ndx) {
109         gl.texParameteri(this.m_textureTarget, this.m_valueName, this.m_valueRange[ndx]);
111         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_valueName, this.m_valueRange[ndx]));
112     }
114     //check unit conversions with float
116     for (var ndx = 0; ndx < this.m_valueRange.length; ++ndx) {
117         gl.texParameterf(this.m_textureTarget, this.m_valueName, this.m_valueRange[ndx]);
119         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_valueName, this.m_valueRange[ndx]));
120     }
124  * @constructor
125  * @extends {es3fTextureStateQuery.TextureCase}
126  * @param {string} name
127  * @param {string} description
128  * @param {number} textureTarget
129  * @param {number} lodTarget
130  * @param {number} initialValue
131  */
132 es3fTextureStateQuery.TextureLODCase = function(name, description, textureTarget, lodTarget, initialValue) {
133     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
134     this.m_lodTarget = lodTarget;
135     this.m_initialValue = initialValue;
138 setParentClass(es3fTextureStateQuery.TextureLODCase, es3fTextureStateQuery.TextureCase);
140 es3fTextureStateQuery.TextureLODCase.prototype.testTexture = function() {
141     var rnd = new deRandom.Random(0xabcdef);
143     this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_lodTarget, this.m_initialValue));
145     var numIterations = 60;
146     for (var ndx = 0; ndx < numIterations; ++ndx) {
147         var ref = rnd.getFloat(-64000, 64000);
149         gl.texParameterf(this.m_textureTarget, this.m_lodTarget, ref);
151         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_lodTarget, ref));
152     }
154     // check unit conversions with int
156     for (var ndx = 0; ndx < numIterations; ++ndx) {
157         var ref = rnd.getInt(-64000, 64000);
159         gl.texParameteri(this.m_textureTarget, this.m_lodTarget, ref);
161         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_lodTarget, ref));
162     }
166  * @constructor
167  * @extends {es3fTextureStateQuery.TextureCase}
168  * @param {string} name
169  * @param {string} description
170  * @param {number} textureTarget
171  * @param {number} levelTarget
172  * @param {number} initialValue
173  */
174 es3fTextureStateQuery.TextureLevelCase = function(name, description, textureTarget, levelTarget, initialValue) {
175     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
176     this.m_levelTarget = levelTarget;
177     this.m_initialValue = initialValue;
180 setParentClass(es3fTextureStateQuery.TextureLevelCase, es3fTextureStateQuery.TextureCase);
182 es3fTextureStateQuery.TextureLevelCase.prototype.testTexture = function() {
183     var rnd = new deRandom.Random(0xabcdef);
185     this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_levelTarget, this.m_initialValue));
187     var numIterations = 60;
188     for (var ndx = 0; ndx < numIterations; ++ndx) {
189         var ref = rnd.getInt(0, 64000);
191         gl.texParameteri(this.m_textureTarget, this.m_levelTarget, ref);
193         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_levelTarget, ref));
194     }
196     // check unit conversions with float
197     var nonSignificantOffsets = [-0.45, -0.25, 0, 0.45]; // offsets O so that for any integers z in Z, o in O roundToClosestInt(z+o)==z
199     for (var ndx = 0; ndx < numIterations; ++ndx) {
200         var ref = rnd.getInt(0, 64000);
202         for (var i = 0; i < nonSignificantOffsets.length; i++) {
203             gl.texParameterf(this.m_textureTarget, this.m_levelTarget, ref + nonSignificantOffsets[i]);
204             this.check(glsStateQuery.verifyTexture(this.m_textureTarget, this.m_levelTarget, ref));
205         }
206     }
210  * @constructor
211  * @extends {es3fTextureStateQuery.TextureCase}
212  * @param {string} name
213  * @param {string} description
214  * @param {number} textureTarget
215  */
216 es3fTextureStateQuery.TextureImmutableLevelsCase = function(name, description, textureTarget) {
217     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
220 setParentClass(es3fTextureStateQuery.TextureImmutableLevelsCase, es3fTextureStateQuery.TextureCase);
222 es3fTextureStateQuery.TextureImmutableLevelsCase.prototype.testTexture = function() {
223     this.check(glsStateQuery.verifyTexture(this.m_textureTarget, gl.TEXTURE_IMMUTABLE_LEVELS, 0));
224     for (var level = 1; level <= 8; ++level) {
225         var textureID = gl.createTexture();
226         gl.bindTexture(this.m_textureTarget, textureID);
228         if (this.m_textureTarget == gl.TEXTURE_2D_ARRAY || this.m_textureTarget == gl.TEXTURE_3D)
229             gl.texStorage3D(this.m_textureTarget, level, gl.RGB8, 256, 256, 256);
230         else
231             gl.texStorage2D(this.m_textureTarget, level, gl.RGB8, 256, 256);
233         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, gl.TEXTURE_IMMUTABLE_LEVELS, level));
234         gl.deleteTexture(textureID);
235     }
239  * @constructor
240  * @extends {es3fTextureStateQuery.TextureCase}
241  * @param {string} name
242  * @param {string} description
243  * @param {number} textureTarget
244  */
245 es3fTextureStateQuery.TextureImmutableFormatCase = function(name, description, textureTarget) {
246     es3fTextureStateQuery.TextureCase.call(this, name, description, textureTarget);
249 setParentClass(es3fTextureStateQuery.TextureImmutableFormatCase, es3fTextureStateQuery.TextureCase);
251 es3fTextureStateQuery.TextureImmutableFormatCase.prototype.testTexture = function() {
252     this.check(glsStateQuery.verifyTexture(this.m_textureTarget, gl.TEXTURE_IMMUTABLE_LEVELS, 0));
253     var testSingleFormat = function(format) {
254         var textureID = gl.createTexture();
255         gl.bindTexture(this.m_textureTarget, textureID);
257         if (this.m_textureTarget == gl.TEXTURE_2D_ARRAY || this.m_textureTarget == gl.TEXTURE_3D)
258             gl.texStorage3D(this.m_textureTarget, 1, format, 32, 32, 32);
259         else
260             gl.texStorage2D(this.m_textureTarget, 1, format, 32, 32);
262         this.check(glsStateQuery.verifyTexture(this.m_textureTarget, gl.TEXTURE_IMMUTABLE_FORMAT, 1));
263         gl.deleteTexture(textureID);
264     };
266     var formats = [
267         gl.RGBA32I, gl.RGBA32UI, gl.RGBA16I, gl.RGBA16UI, gl.RGBA8, gl.RGBA8I,
268         gl.RGBA8UI, gl.SRGB8_ALPHA8, gl.RGB10_A2, gl.RGB10_A2UI, gl.RGBA4,
269         gl.RGB5_A1, gl.RGB8, gl.RGB565, gl.RG32I, gl.RG32UI, gl.RG16I, gl.RG16UI,
270         gl.RG8, gl.RG8I, gl.RG8UI, gl.R32I, gl.R32UI, gl.R16I, gl.R16UI, gl.R8,
271         gl.R8I, gl.R8UI,
273         gl.RGBA32F, gl.RGBA16F, gl.RGBA8_SNORM, gl.RGB32F,
274         gl.RGB32I, gl.RGB32UI, gl.RGB16F, gl.RGB16I, gl.RGB16UI, gl.RGB8_SNORM,
275         gl.RGB8I, gl.RGB8UI, gl.SRGB8, gl.R11F_G11F_B10F, gl.RGB9_E5, gl.RG32F,
276         gl.RG16F, gl.RG8_SNORM, gl.R32F, gl.R16F, gl.R8_SNORM
277     ];
279     var non3dFormats = [
280         gl.DEPTH_COMPONENT32F, gl.DEPTH_COMPONENT24, gl.DEPTH_COMPONENT16,
281         gl.DEPTH32F_STENCIL8, gl.DEPTH24_STENCIL8
282     ];
284     for (var formatNdx = 0; formatNdx < formats.length; ++formatNdx)
285         testSingleFormat.bind(this, formats[formatNdx]);
287     if (this.m_textureTarget != gl.TEXTURE_3D)
288         for (var formatNdx = 0; formatNdx < non3dFormats.length; ++formatNdx)
289             testSingleFormat.bind(this, non3dFormats[formatNdx]);
293 * @constructor
294 * @extends {tcuTestCase.DeqpTest}
296 es3fTextureStateQuery.TextureStateQuery = function() {
297     tcuTestCase.DeqpTest.call(this, 'texture', 'Texture State Query tests');
300 es3fTextureStateQuery.TextureStateQuery.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
301 es3fTextureStateQuery.TextureStateQuery.prototype.constructor = es3fTextureStateQuery.TextureStateQuery;
303 es3fTextureStateQuery.TextureStateQuery.prototype.init = function() {
304     var textureTargets = [
305         ['texture_2d', gl.TEXTURE_2D],
306         ['texture_3d', gl.TEXTURE_3D],
307         ['texture_2d_array', gl.TEXTURE_2D_ARRAY],
308         ['texture_cube_map', gl.TEXTURE_CUBE_MAP]
309     ];
311     var state = this;
312     var wrapValues = [gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED_REPEAT];
313     var magValues = [gl.NEAREST, gl.LINEAR];
314     var minValues = [gl.NEAREST, gl.LINEAR, gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST_MIPMAP_LINEAR, gl.LINEAR_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_LINEAR];
315     var modes = [gl.COMPARE_REF_TO_TEXTURE, gl.NONE];
316     var compareFuncs = [gl.LEQUAL, gl.GEQUAL, gl.LESS, gl.GREATER, gl.EQUAL, gl.NOTEQUAL, gl.ALWAYS, gl.NEVER];
317     textureTargets.forEach(function(elem) {
318         var name = elem[0];
319         var target = elem[1];
320         state.addChild(new es3fTextureStateQuery.IsTextureCase(name + '_is_texture', 'IsTexture', target));
321         state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_wrap_s' , 'TEXTURE_WRAP_S',
322             target, gl.TEXTURE_WRAP_S, gl.REPEAT, wrapValues));
323         if (target == gl.TEXTURE_2D ||
324             target == gl.TEXTURE_3D ||
325             target == gl.TEXTURE_CUBE_MAP)
326             state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_wrap_t' , 'TEXTURE_WRAP_T',
327                 target, gl.TEXTURE_WRAP_T, gl.REPEAT, wrapValues));
329         if (target == gl.TEXTURE_3D)
330             state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_wrap_r' , 'TEXTURE_WRAP_R',
331                 target, gl.TEXTURE_WRAP_R, gl.REPEAT, wrapValues));
333         state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_mag_filter' , 'TEXTURE_MAG_FILTER',
334             target, gl.TEXTURE_MAG_FILTER, gl.LINEAR, magValues));
335         state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_min_filter' , 'TEXTURE_MIN_FILTER',
336             target, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR, minValues));
337         state.addChild(new es3fTextureStateQuery.TextureLODCase(name + '_texture_min_lod' , 'TEXTURE_MIN_LOD', target, gl.TEXTURE_MIN_LOD, -1000));
338         state.addChild(new es3fTextureStateQuery.TextureLODCase(name + '_texture_max_lod' , 'TEXTURE_MAX_LOD', target, gl.TEXTURE_MAX_LOD, 1000));
339         state.addChild(new es3fTextureStateQuery.TextureLevelCase(name + '_texture_base_level' , 'TEXTURE_BASE_LEVEL', target, gl.TEXTURE_BASE_LEVEL, 0));
340         state.addChild(new es3fTextureStateQuery.TextureLevelCase(name + '_texture_max_level' , 'TEXTURE_MAX_LEVEL', target, gl.TEXTURE_MAX_LEVEL, 1000));
342         state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_compare_mode' , 'TEXTURE_COMPARE_MODE',
343             target, gl.TEXTURE_COMPARE_MODE, gl.NONE, modes));
344         state.addChild(new es3fTextureStateQuery.TextureParamCase(name + '_texture_compare_func' , 'TEXTURE_COMPARE_FUNC',
345             target, gl.TEXTURE_COMPARE_FUNC, gl.LEQUAL, compareFuncs));
347         state.addChild(new es3fTextureStateQuery.TextureImmutableLevelsCase(name + '_texture_immutable_levels', 'TEXTURE_IMMUTABLE_LEVELS', target));
348         state.addChild(new es3fTextureStateQuery.TextureImmutableFormatCase(name + '_texture_immutable_format', 'TEXTURE_IMMUTABLE_FORMAT', target));
349     });
353 * Run test
354 * @param {WebGL2RenderingContext} context
356 es3fTextureStateQuery.run = function(context) {
357     gl = context;
358     //Set up Test Root parameters
359     var state = tcuTestCase.runner;
360     state.setRoot(new es3fTextureStateQuery.TextureStateQuery());
362     //Set up name and description of this test series.
363     setCurrentTestName(state.testCases.fullName());
364     description(state.testCases.getDescription());
366     try {
367         //Run test cases
368         tcuTestCase.runTestCases();
369     }
370     catch (err) {
371         testFailedOptions('Failed to es3fTextureStateQuery.run tests', false);
372         tcuTestCase.runner.terminate();
373     }