Skip to content

Commit b28d4ee

Browse files
kdashgkenrussell
authored andcommitted
Test for A8-on-R8 swizzle being applied to the wrong tex unit. (#2778)
Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1503813
1 parent 5ddec66 commit b28d4ee

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

sdk/tests/conformance/textures/misc/texture-active-bind.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
5050
texCoord = texCoord0;
5151
}
5252
</script>
53+
<script id="trivial-vs" type="text/plain">
54+
void main()
55+
{
56+
gl_Position = vec4(0,0,0,1);
57+
}
58+
</script>
59+
<script id="tex-point-fs" type="text/plain">
60+
precision mediump float;
61+
uniform sampler2D uSampler;
62+
void main()
63+
{
64+
gl_FragColor = texture2D(uSampler, vec2(0));
65+
}
66+
</script>
5367
<script>
5468
"use strict";
5569
var gl;
@@ -128,6 +142,51 @@
128142
var y = Math.floor(ii / 2);
129143
wtu.checkCanvasRect(gl, x, y, 1, 1, colors[ii]);
130144
}
145+
146+
debug("");
147+
debug("Swizzle applied to correct ActiveTexture index");
148+
149+
{
150+
const prog = wtu.setupProgram(
151+
gl,
152+
["trivial-vs", "tex-point-fs"]);
153+
prog.uSampler = gl.getUniformLocation(prog, "uSampler");
154+
gl.useProgram(prog);
155+
gl.viewport(0, 0, 1, 1);
156+
gl.activeTexture(gl.TEXTURE0);
157+
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
158+
159+
const tex0_rgba8 = gl.createTexture();
160+
gl.bindTexture(gl.TEXTURE_2D, tex0_rgba8);
161+
const tex0_rgba8_data = new Uint8Array([10, 20, 30, 40]);
162+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, tex0_rgba8_data);
163+
164+
const tex2_a8 = gl.createTexture();
165+
gl.bindTexture(gl.TEXTURE_2D, tex2_a8);
166+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 1, 1, 0, gl.ALPHA, gl.UNSIGNED_BYTE, null);
167+
168+
window.control = new Uint8Array(4);
169+
window.after_swizzle_applied = new Uint8Array(4);
170+
171+
gl.bindTexture(gl.TEXTURE_2D, tex0_rgba8);
172+
gl.drawArrays(gl.POINTS, 0, 1);
173+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, window.control);
174+
shouldBeString("window.control", tex0_rgba8_data.toString());
175+
176+
gl.activeTexture(gl.TEXTURE2);
177+
gl.bindTexture(gl.TEXTURE_2D, tex2_a8);
178+
gl.uniform1i(prog.uSampler, 2);
179+
gl.activeTexture(gl.TEXTURE0);
180+
gl.drawArrays(gl.POINTS, 0, 1);
181+
// Firefox would apply the A8-on-R8 swizzle to whatever tex-unit was active.
182+
183+
gl.uniform1i(prog.uSampler, 0);
184+
gl.drawArrays(gl.POINTS, 0, 1);
185+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, window.after_swizzle_applied);
186+
shouldBeString("window.after_swizzle_applied", tex0_rgba8_data.toString());
187+
// Firefox would then get 0,0,0,10 here, as the [ZERO,ZERO,ZERO,RED] swizzle was applied to our
188+
// 10,20,30,40 texture.
189+
}
131190
}
132191

133192
init();

sdk/tests/js/js-test-pre.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ function evalAndLog(_a)
373373
return _av;
374374
}
375375

376+
function shouldBeString(evalable, expected) {
377+
const val = eval(evalable);
378+
const text = evalable + " should be " + expected + ".";
379+
if (val == expected) {
380+
testPassed(text);
381+
} else {
382+
testFailed(text + " (was " + val + ")");
383+
}
384+
}
385+
376386
function shouldBe(_a, _b, quiet)
377387
{
378388
if (typeof _a != "string" || typeof _b != "string")

0 commit comments

Comments
 (0)