summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/deqp/functional/gles3/es3fIndexedStateQueryTests.js
blob: a18f6708b24250f0378cd80690954eb976cf299d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/*-------------------------------------------------------------------------
 * drawElements Quality Program OpenGL ES Utilities
 * ------------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

'use strict';
goog.provide('functional.gles3.es3fIndexedStateQueryTests');
goog.require('framework.common.tcuTestCase');
goog.require('functional.gles3.es3fApiCase');

goog.scope(function() {
	var es3fIndexedStateQueryTests = functional.gles3.es3fIndexedStateQueryTests;
    var tcuTestCase = framework.common.tcuTestCase;
    var es3fApiCase = functional.gles3.es3fApiCase;

	/**
	 * @constructor
	 * @extends {es3fApiCase.ApiCase}
	 * @param {string} name
	 * @param {string} description
	 */
	es3fIndexedStateQueryTests.TransformFeedbackCase = function(name, description) {
		es3fApiCase.ApiCase.call(this, name, description, gl);
	};

	es3fIndexedStateQueryTests.TransformFeedbackCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
	es3fIndexedStateQueryTests.TransformFeedbackCase.prototype.constructor = es3fIndexedStateQueryTests.TransformFeedbackCase;

	es3fIndexedStateQueryTests.TransformFeedbackCase.prototype.testTransformFeedback = function() {
		throw new Error('This method should be overriden.');
	};

	es3fIndexedStateQueryTests.TransformFeedbackCase.prototype.test = function() {
		/** @type {string} */ var transformFeedbackTestVertSource = '' +
			'#version 300 es\n' +
			'out highp vec4 anotherOutput;\n' +
			'void main (void)\n' +
			'{\n' +
			'	gl_Position = vec4(0.0);\n' +
			'	anotherOutput = vec4(0.0);\n' +
			'}\n';
		/** @type {string} */ var transformFeedbackTestFragSource = '' +
			'#version 300 es\n' +
			'layout(location = 0) out mediump vec4 fragColor;' +
			'void main (void)\n' +
			'{\n' +
			'	fragColor = vec4(0.0);\n' +
			'}\n';

		/** @type {WebGLShader} */ var shaderVert = gl.createShader(gl.VERTEX_SHADER);
		/** @type {WebGLShader} */ var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER);

		gl.shaderSource(shaderVert, transformFeedbackTestVertSource);
		gl.shaderSource(shaderFrag, transformFeedbackTestFragSource);

		gl.compileShader(shaderVert);
		gl.compileShader(shaderFrag);

		/** @type {WebGLProgram} */ var shaderProg = gl.createProgram();
		gl.attachShader(shaderProg, shaderVert);
		gl.attachShader(shaderProg, shaderFrag);

		/** @type {Array<string>} */ var transformFeedbackOutputs = ['gl_Position', 'anotherOutput'];

		gl.transformFeedbackVaryings(shaderProg, transformFeedbackOutputs, gl.INTERLEAVED_ATTRIBS);
		gl.linkProgram(shaderProg);

		/** @type {WebGLTransformFeedback} */ var transformFeedbackId = gl.createTransformFeedback();
		gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, transformFeedbackId);

		this.testTransformFeedback();

		// cleanup

		gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);

		gl.deleteTransformFeedback(transformFeedbackId);
		gl.deleteShader(shaderVert);
		gl.deleteShader(shaderFrag);
		gl.deleteProgram(shaderProg);
	};

	/**
	 * @constructor
	 * @extends {es3fIndexedStateQueryTests.TransformFeedbackCase}
	 * @param {string} name
	 * @param {string} description
	 */
	es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase = function(name, description) {
		es3fIndexedStateQueryTests.TransformFeedbackCase.call(this, name, description);
	};

	es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase.prototype = Object.create(es3fIndexedStateQueryTests.TransformFeedbackCase.prototype);
	es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase.prototype.constructor = es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase;

	es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase.prototype.testTransformFeedback = function() {
		/** @type {number} */ var feedbackPositionIndex = 0;
		/** @type {number} */ var feedbackOutputIndex = 1;
		/** @type {Array<number>} */ var feedbackIndex = [feedbackPositionIndex, feedbackOutputIndex];

		// bind buffers

		/** @type {Array<WebGLBuffer>} */ var feedbackBuffers = [];
		for (var ndx = 0; ndx < 2; ndx++)
			feedbackBuffers[ndx] = gl.createBuffer();

		for (var ndx = 0; ndx < feedbackBuffers.length; ndx++) {
			gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackBuffers[ndx]);
			gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, new Float32Array(16), gl.DYNAMIC_READ);
			gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackIndex[ndx], feedbackBuffers[ndx]);
		}

		// test TRANSFORM_FEEDBACK_BUFFER_BINDING
		for (var ndx = 0; ndx < feedbackBuffers.length; ndx++) {
			var boundBuffer = /** @type {WebGLBuffer} */ (gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, ndx));
			this.check(boundBuffer === feedbackBuffers[ndx], 'buffers do not match');
		}

		// cleanup
		for (var ndx = 0; ndx < feedbackBuffers.length; ndx++)
			gl.deleteBuffer(feedbackBuffers[ndx]);
	};

	/**
	 * @constructor
	 * @extends {es3fIndexedStateQueryTests.TransformFeedbackCase}
	 * @param {string} name
	 * @param {string} description
	 */
	es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase = function(name, description) {
		es3fIndexedStateQueryTests.TransformFeedbackCase.call(this, name, description);
	};

	es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase.prototype = Object.create(es3fIndexedStateQueryTests.TransformFeedbackCase.prototype);
	es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase.prototype.constructor = es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase;

	es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase.prototype.testTransformFeedback = function() {
		/** @type {number} */ var feedbackPositionIndex = 0;
		/** @type {number} */ var feedbackOutputIndex = 1;

		/** @type {number} */ var rangeBufferOffset = 4;
		/** @type {number} */ var rangeBufferSize = 8;

		// bind buffers

		/** @type {Array<WebGLBuffer>} */ var feedbackBuffers = [];
		for (var ndx = 0; ndx < 2; ndx++)
			feedbackBuffers[ndx] = gl.createBuffer();

		gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackBuffers[0]);
		gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, new Float32Array(16), gl.DYNAMIC_READ);
		gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackPositionIndex, feedbackBuffers[0]);

		gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackBuffers[1]);
		gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, new Float32Array(16), gl.DYNAMIC_READ);
		gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, feedbackOutputIndex, feedbackBuffers[1], rangeBufferOffset, rangeBufferSize);

		/** @type {Array<{index: number, pname: number, value: number}>} */ var requirements = [
			{index: feedbackPositionIndex, pname: gl.TRANSFORM_FEEDBACK_BUFFER_START, value: 0},
			{index: feedbackPositionIndex, pname: gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, value: 0},
			{index: feedbackOutputIndex, pname: gl.TRANSFORM_FEEDBACK_BUFFER_START, value: rangeBufferOffset},
			{index: feedbackOutputIndex, pname: gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, value: rangeBufferSize}
		];

		for (var ndx = 0; ndx < requirements.length; ndx++) {
			var state = /** @type {number} */ (gl.getIndexedParameter(requirements[ndx].pname, requirements[ndx].index));
			this.check(state === requirements[ndx].value, 'got ' + state + '; expected ' + requirements[ndx].value);
		}

		// cleanup
		for (var ndx = 0; ndx < feedbackBuffers.length; ndx++)
			gl.deleteBuffer(feedbackBuffers[ndx]);
	};

	/**
	 * @constructor
	 * @extends {es3fApiCase.ApiCase}
	 * @param {string} name
	 * @param {string} description
	 */
	es3fIndexedStateQueryTests.UniformBufferCase = function(name, description) {
		es3fApiCase.ApiCase.call(this, name, description, gl);
		/** @type {?WebGLProgram} */ this.m_program = null;
	};

	es3fIndexedStateQueryTests.UniformBufferCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
	es3fIndexedStateQueryTests.UniformBufferCase.prototype.constructor = es3fIndexedStateQueryTests.UniformBufferCase;

	es3fIndexedStateQueryTests.UniformBufferCase.prototype.testUniformBuffers = function() {
		throw new Error('This method should be overriden.');
	};

	es3fIndexedStateQueryTests.UniformBufferCase.prototype.test = function() {

		/** @type {string} */ var testVertSource = '' +
			'#version 300 es\n' +
			'uniform highp vec4 input1;\n' +
			'uniform highp vec4 input2;\n' +
			'void main (void)\n' +
			'{\n' +
			'	gl_Position = input1 + input2;\n' +
			'}\n';
		/** @type {string} */ var testFragSource = '' +
			'#version 300 es\n' +
			'layout(location = 0) out mediump vec4 fragColor;' +
			'void main (void)\n' +
			'{\n' +
			'	fragColor = vec4(0.0);\n' +
			'}\n';

		/** @type {WebGLShader} */ var shaderVert = gl.createShader(gl.VERTEX_SHADER);
		/** @type {WebGLShader} */ var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER);

		gl.shaderSource(shaderVert, testVertSource);
		gl.shaderSource(shaderFrag, testFragSource);

		gl.compileShader(shaderVert);
		gl.compileShader(shaderFrag);

		this.m_program = gl.createProgram();
		gl.attachShader(this.m_program, shaderVert);
		gl.attachShader(this.m_program, shaderFrag);
		gl.linkProgram(this.m_program);
		gl.useProgram(this.m_program);

		this.testUniformBuffers();

		gl.useProgram(null);
		gl.deleteShader(shaderVert);
		gl.deleteShader(shaderFrag);
		gl.deleteProgram(this.m_program);
	};

	/**
	* @constructor
	* @extends {es3fIndexedStateQueryTests.UniformBufferCase}
	* @param {string} name
	* @param {string} description
	*/
	es3fIndexedStateQueryTests.UniformBufferBindingCase = function(name, description) {
		es3fIndexedStateQueryTests.UniformBufferCase.call(this, name, description);
		/** @type {?WebGLProgram} */ this.m_program = null;
	};

	es3fIndexedStateQueryTests.UniformBufferBindingCase.prototype = Object.create(es3fIndexedStateQueryTests.UniformBufferCase.prototype);
	es3fIndexedStateQueryTests.UniformBufferBindingCase.prototype.constructor = es3fIndexedStateQueryTests.UniformBufferBindingCase;

	es3fIndexedStateQueryTests.UniformBufferBindingCase.prototype.testUniformBuffers = function() {
		/** @type {Array<string>} */ var uniformNames = ['input1', 'input2'];

		/** @type {Array<number>} */ var uniformIndices = gl.getUniformIndices(this.m_program, uniformNames);

		/** @type {Array<WebGLBuffer>} */ var buffers = [];
		for (var ndx = 0; ndx < 2; ndx++)
			buffers[ndx] = gl.createBuffer();

		for (var ndx = 0; ndx < buffers.length; ++ndx) {
			gl.bindBuffer(gl.UNIFORM_BUFFER, buffers[ndx]);
			gl.bufferData(gl.UNIFORM_BUFFER, new Float32Array(32), gl.DYNAMIC_DRAW);
			gl.bindBufferBase(gl.UNIFORM_BUFFER, uniformIndices[ndx], buffers[ndx]);
		}

		/** @type {Array<WebGLBuffer>} */ var boundBuffer = [];
		for (var ndx = 0; ndx < buffers.length; ndx++) {
			boundBuffer[ndx] = /** @type {WebGLBuffer} */ (gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, uniformIndices[ndx]));
			this.check(boundBuffer[ndx] === buffers[ndx], 'buffers do not match');
		}

		for (var ndx = 0; ndx < buffers.length; ndx++)
			gl.deleteBuffer(buffers[ndx]);
	};

	/**
	* @constructor
	* @extends {es3fIndexedStateQueryTests.UniformBufferCase}
	* @param {string} name
	* @param {string} description
	*/
	es3fIndexedStateQueryTests.UniformBufferBufferCase = function(name, description) {
		es3fIndexedStateQueryTests.UniformBufferCase.call(this, name, description);
		/** @type {?WebGLProgram} */ this.m_program = null;
	};

	es3fIndexedStateQueryTests.UniformBufferBufferCase.prototype = Object.create(es3fIndexedStateQueryTests.UniformBufferCase.prototype);
	es3fIndexedStateQueryTests.UniformBufferBufferCase.prototype.constructor = es3fIndexedStateQueryTests.UniformBufferBufferCase;

	es3fIndexedStateQueryTests.UniformBufferBufferCase.prototype.testUniformBuffers = function() {
		/** @type {Array<string>} */ var uniformNames = ['input1', 'input2'];

		/** @type {Array<number>} */ var uniformIndices = gl.getUniformIndices(this.m_program, uniformNames);

		/** @type {number} */ var alignment = this.getAlignment();
		if (alignment === -1) // cannot continue without this
			return;

		bufferedLogToConsole('Alignment is ' + alignment);

		/** @type {number} */ var rangeBufferOffset = alignment;
		/** @type {number} */ var rangeBufferSize = alignment * 2;
		/** @type {number} */ var rangeBufferTotalSize = rangeBufferOffset + rangeBufferSize + 8; // + 8 has no special meaning, just to make it != with the size of the range

		/** @type {Array<WebGLBuffer>} */ var buffers = [];
		for (var ndx = 0; ndx < 2; ndx++)
			buffers[ndx] = gl.createBuffer();

		gl.bindBuffer(gl.UNIFORM_BUFFER, buffers[0]);
		gl.bufferData(gl.UNIFORM_BUFFER, new Float32Array(32), gl.DYNAMIC_DRAW);
		gl.bindBufferBase(gl.UNIFORM_BUFFER, uniformIndices[0], buffers[0]);

		gl.bindBuffer(gl.UNIFORM_BUFFER, buffers[1]);
		gl.bufferData(gl.UNIFORM_BUFFER, new Float32Array(32), gl.DYNAMIC_DRAW);
		gl.bindBufferRange(gl.UNIFORM_BUFFER, uniformIndices[1], buffers[1], rangeBufferOffset, rangeBufferSize);

		// test UNIFORM_BUFFER_START and UNIFORM_BUFFER_SIZE

		/** @type {Array<{index: number, pname: number, value: number}>} */ var requirements = [
			{index: uniformIndices[0], pname: gl.UNIFORM_BUFFER_START, value: 0},
			{index: uniformIndices[0], pname: gl.UNIFORM_BUFFER_SIZE, value: 0},
			{index: uniformIndices[1], pname: gl.UNIFORM_BUFFER_START, value: rangeBufferOffset},
			{index: uniformIndices[1], pname: gl.UNIFORM_BUFFER_SIZE, value: rangeBufferSize}
		];

		for (var ndx = 0; ndx < requirements.length; ndx++) {
			var state = /** @type {number} */ (gl.getIndexedParameter(requirements[ndx].pname, requirements[ndx].index));

			this.check(state === requirements[ndx].value, 'got ' + state + '; expected ' + requirements[ndx].value);
		}

		for (var ndx = 0; ndx < buffers.length; ndx++)
			gl.deleteBuffer(buffers[ndx]);

	};

	/**
	 * @return {number}
	 */
	es3fIndexedStateQueryTests.UniformBufferBufferCase.prototype.getAlignment = function() {
		var state = /** @type {number} */ (gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT));

		if (state <= 256)
			return state;

		bufferedLogToConsole('ERROR: UNIFORM_BUFFER_OFFSET_ALIGNMENT has a maximum value of 256.');
		testFailedOptions('invalid UNIFORM_BUFFER_OFFSET_ALIGNMENT value', false);

		return -1;
	};

    /**
    * @constructor
    * @extends {tcuTestCase.DeqpTest}
    */
    es3fIndexedStateQueryTests.IndexedStateQueryTests = function() {
        tcuTestCase.DeqpTest.call(this, 'indexed', 'Indexed Integer Values');
    };

    es3fIndexedStateQueryTests.IndexedStateQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
    es3fIndexedStateQueryTests.IndexedStateQueryTests.prototype.constructor = es3fIndexedStateQueryTests.IndexedStateQueryTests;

    es3fIndexedStateQueryTests.IndexedStateQueryTests.prototype.init = function() {
		// transform feedback
		this.addChild(new es3fIndexedStateQueryTests.TransformFeedbackBufferBindingCase('transform_feedback_buffer_binding', 'TRANSFORM_FEEDBACK_BUFFER_BINDING'));
		this.addChild(new es3fIndexedStateQueryTests.TransformFeedbackBufferBufferCase('transform_feedback_buffer_start_size', 'TRANSFORM_FEEDBACK_BUFFER_START and TRANSFORM_FEEDBACK_BUFFER_SIZE'));

		// uniform buffers
		this.addChild(new es3fIndexedStateQueryTests.UniformBufferBindingCase('uniform_buffer_binding', 'UNIFORM_BUFFER_BINDING'));
		this.addChild(new es3fIndexedStateQueryTests.UniformBufferBufferCase('uniform_buffer_start_size', 'UNIFORM_BUFFER_START and UNIFORM_BUFFER_SIZE'));
    };

    /**
    * Run test
    * @param {WebGL2RenderingContext} context
    */
    es3fIndexedStateQueryTests.run = function(context) {
    	gl = context;
    	//Set up Test Root parameters
    	var state = tcuTestCase.runner;
    	state.setRoot(new es3fIndexedStateQueryTests.IndexedStateQueryTests());

    	//Set up name and description of this test series.
    	setCurrentTestName(state.testCases.fullName());
    	description(state.testCases.getDescription());

    	try {
    		//Run test cases
    		tcuTestCase.runTestCases();
    	}
    	catch (err) {
    		testFailedOptions('Failed to es3fIndexedStateQueryTests.run tests', false);
    		tcuTestCase.runner.terminate();
    	}
    };

});