summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/transform_feedback/same-buffer-two-binding-points.html
blob: 86e7a5d4026574ee2823853d0288c8be010cf04d (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
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Transform Feedback Conformance Tests - one buffer bound to two binding points</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">#version 300 es

in vec4 in_data;
out vec4 out_add;
out vec4 out_mul;
void main(void) {
    out_add = in_data + vec4(2.0, 3.0, 4.0, 5.0);
    out_mul = in_data * vec4(2.0, 3.0, 4.0, 5.0);
}
</script>
<script>
"use strict";
description();

debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext(null, null, 2);
var program = null;

if (!gl) {
    testFailed("WebGL context does not exist");
} else {
    testPassed("WebGL context exists");
    runTwoOutFeedbackTest();
}

function doDrawWithTransformFeedback(expectedError, msg) {
    gl.beginTransformFeedback(gl.POINTS);
    wtu.glErrorShouldBe(gl, expectedError, msg);
    gl.drawArrays(gl.POINTS, 0, 3);
    gl.endTransformFeedback();
    gl.getError();
}

function runTwoOutFeedbackTest() {
    debug("");
    debug("Test binding the same buffer to two transform feedback binding points. Buffer should be untouched and an error should be generated.")

    // Build the input and output buffers
    var in_data = [
        1.0, 2.0, 3.0, 4.0,
        2.0, 4.0, 8.0, 16.0,
        0.75, 0.5, 0.25, 0.0
    ];

    var in_buffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, in_buffer);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(in_data), gl.STATIC_DRAW);

    // Create the transform feedback shader
    program = wtu.setupTransformFeedbackProgram(gl, ["vshader", wtu.simpleColorFragmentShaderESSL300],
        ["out_add", "out_mul"], gl.SEPARATE_ATTRIBS,
        ["in_data"]);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "linking transform feedback shader should not set an error");
    shouldBeNonNull("program");

    // Draw the the transform feedback buffers
    var tf = gl.createTransformFeedback();

    gl.enableVertexAttribArray(0);
    gl.bindBuffer(gl.ARRAY_BUFFER, in_buffer);
    gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 16, 0);

    var out_buffer = gl.createBuffer();
    var out_buffer2 = gl.createBuffer();
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);

    // Test binding the same buffer to two transform feedback binding points with bindBufferBase.
    debug("");
    gl.enable(gl.RASTERIZER_DISCARD);
    gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length * 2, gl.STATIC_DRAW);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, out_buffer);

    doDrawWithTransformFeedback(gl.INVALID_OPERATION, "same buffer bound to two transform feedback binding points with bindBufferBase");

    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, null);
    gl.disable(gl.RASTERIZER_DISCARD);

    // Check buffer contents.
    var expectedZeroes = [];
    for (var i = 0; i < in_data.length * 2; ++i)
    {
        expectedZeroes.push(0.0);
    }
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
    debug("buffer should be untouched - filled with zeroes");
    wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expectedZeroes);

    // Test binding the same buffer to two transform feedback binding points with bindBufferRange. The ranges overlap just slightly.
    debug("");
    gl.enable(gl.RASTERIZER_DISCARD);
    gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length * 2, gl.STATIC_DRAW);
    gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer, 0, in_data.length * 4);
    gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, 1, out_buffer, (in_data.length - 1) * 4, in_data.length * 4);

    doDrawWithTransformFeedback(gl.INVALID_OPERATION, "same buffer bound to two transform feedback binding points with bindBufferRange, overlapping ranges");

    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, null);
    gl.disable(gl.RASTERIZER_DISCARD);

    // Check buffer contents.
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
    debug("buffer should be untouched - filled with zeroes");
    wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expectedZeroes);

    // Test non-overlapping ranges.
    debug("");
    gl.enable(gl.RASTERIZER_DISCARD);
    gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length * 2, gl.STATIC_DRAW);
    gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer, 0, in_data.length * 4);
    gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, 1, out_buffer, in_data.length * 4, in_data.length * 4);

    doDrawWithTransformFeedback(gl.INVALID_OPERATION, "same buffer bound to two transform feedback binding points with bindBufferRange, non-overlapping ranges");

    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, null);
    gl.disable(gl.RASTERIZER_DISCARD);

    // Check buffer contents.
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
    debug("buffer should be untouched - filled with zeroes");
    wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expectedZeroes);

    // Test binding the same buffer to a binding point that doesn't have a corresponding output in the vertex shader.
    debug("");
    gl.enable(gl.RASTERIZER_DISCARD);
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer2);
    gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length * 2, gl.STATIC_DRAW);
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
    gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length * 2, gl.STATIC_DRAW);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, out_buffer2);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 2, out_buffer);  // No corresponding output.

    doDrawWithTransformFeedback(gl.INVALID_OPERATION, "same buffer bound to two transform feedback binding points with bindBufferBase, but one of the binding points doesn't have a corresponding shader output");

    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, null);
    gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 2, null);
    gl.disable(gl.RASTERIZER_DISCARD);

    // Check buffer contents.
    debug("buffers should be untouched - filled with zeroes");
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
    wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expectedZeroes);
    gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer2);
    wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expectedZeroes);

    finishTest();
}
</script>

</body>
</html>