Skip to content

Commit 3944321

Browse files
authored
Check results in copyTex{Sub}Image tests. (#3804)
After performing copyTex{Sub}Image, verify the color channels of the destination texture to ensure the copy was performed correctly. Strengthens the following tests: conformance/extensions/ext-color-buffer-half-float.html conformance2/extensions/ext-color-buffer-float.html conformance2/extensions/ext-color-buffer-half-float.html conformance2/textures/misc/copy-texture-image.html Associated with Chromium bug crbug.com/576651388.
1 parent 3a65272 commit 3944321

4 files changed

Lines changed: 248 additions & 4 deletions

File tree

‎sdk/tests/conformance2/extensions/ext-color-buffer-float.html‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@
313313
testPassed("Internal format query succeeded");
314314
}
315315

316+
const copyTestFullColor = [0.125, 0.25, 0.5, 0.75];
317+
const copyTestSubColor = [0.875, 0.625, 0.375, 0.25];
318+
316319
function runCopyTexImageTest(enabled)
317320
{
318321
var width = 16;
@@ -383,6 +386,7 @@
383386
data: new Float32Array(width * height * 3)
384387
}
385388
];
389+
var copyVerifyProgram = wtu.setupSimpleTextureProgram(gl);
386390
cases.forEach(function(testcase) {
387391
debug("");
388392
debug("Testing CopyTexImage2D for internalformat: " + testcase.destInternalformat);
@@ -400,13 +404,30 @@
400404
var fbo = gl.createFramebuffer();
401405
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
402406
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texSrc, level);
403-
var texDest = gl.createTexture();
404-
gl.bindTexture(gl.TEXTURE_2D, texDest);
407+
var texDest = allocateTexture();
405408
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup framebuffer with texture should succeed.");
406409
if (enabled) {
407410
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
411+
gl.clearColor(copyTestFullColor[0], copyTestFullColor[1], copyTestFullColor[2], copyTestFullColor[3]);
412+
gl.clear(gl.COLOR_BUFFER_BIT);
408413
gl.copyTexImage2D(gl.TEXTURE_2D, level, destInternalformat, 0, 0, width, height, 0);
409414
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "CopyTexImage2D should succeed.");
415+
gl.clearColor(copyTestSubColor[0], copyTestSubColor[1], copyTestSubColor[2], copyTestSubColor[3]);
416+
gl.clear(gl.COLOR_BUFFER_BIT);
417+
gl.copyTexSubImage2D(gl.TEXTURE_2D, level, 0, 0, 0, 0, width / 2, height / 2);
418+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "CopyTexSubImage2D should succeed.");
419+
420+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
421+
gl.useProgram(copyVerifyProgram);
422+
wtu.clearAndDrawUnitQuad(gl);
423+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Drawing copied texture should succeed.");
424+
425+
const expectedSub = wtu.expectedSampledCopyColor(gl, destInternalformat, copyTestSubColor);
426+
const expectedFull = wtu.expectedSampledCopyColor(gl, destInternalformat, copyTestFullColor);
427+
wtu.checkCanvasRect(gl, Math.floor(gl.canvas.width / 4), Math.floor(gl.canvas.height / 4), 1, 1,
428+
expectedSub, "Sub-image copy region should match expected color", 2);
429+
wtu.checkCanvasRect(gl, Math.floor(gl.canvas.width * 3 / 4), Math.floor(gl.canvas.height * 3 / 4), 1, 1,
430+
expectedFull, "Full-image copy region should match expected color", 2);
410431
} else {
411432
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
412433
gl.copyTexImage2D(gl.TEXTURE_2D, level, destInternalformat, 0, 0, width, height, 0);

‎sdk/tests/conformance2/textures/misc/copy-texture-image.html‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,42 @@
133133

134134
var texture = gl.createTexture();
135135
gl.bindTexture(gl.TEXTURE_2D, texture);
136+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
137+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
138+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
139+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
140+
141+
wtu.setupUnitQuad(gl, 0, 1);
142+
const floatCopyVerifyProgram = wtu.setupSimpleTextureProgram(gl, 0, 1);
143+
const intCopyVerifyFS = `#version 300 es
144+
precision highp float;
145+
precision highp int;
146+
precision highp isampler2D;
147+
uniform isampler2D tex;
148+
in vec2 texCoord;
149+
out ivec4 out_color;
150+
void main() {
151+
out_color = texture(tex, texCoord);
152+
}`;
153+
const intCopyVerifyProgram = wtu.setupSimpleTextureProgramESSL300(gl, 0, 1, intCopyVerifyFS);
154+
const uintCopyVerifyFS = `#version 300 es
155+
precision highp float;
156+
precision highp int;
157+
precision highp usampler2D;
158+
uniform usampler2D tex;
159+
in vec2 texCoord;
160+
out uvec4 out_color;
161+
void main() {
162+
out_color = texture(tex, texCoord);
163+
}`;
164+
const uintCopyVerifyProgram = wtu.setupSimpleTextureProgramESSL300(gl, 0, 1, uintCopyVerifyFS);
165+
166+
const copyTestFullColor = [0.125, 0.25, 0.5, 0.75];
167+
const copyTestSubColor = [0.875, 0.625, 0.375, 0.25];
168+
const fullIntColor = new Int32Array([17, -42, 103, -120]);
169+
const subIntColor = new Int32Array([-85, 64, -19, 91]);
170+
const fullUintColor = new Uint32Array([31, 79, 151, 223]);
171+
const subUintColor = new Uint32Array([211, 139, 67, 19]);
136172

137173
function testFormat(internalformat, srcTexFormatsTypes, fboAttachmentType, expected, msg) {
138174
var fbo = gl.createFramebuffer();
@@ -143,10 +179,74 @@
143179
gl.framebufferTexture2D(gl.FRAMEBUFFER, fboAttachmentType, gl.TEXTURE_2D, srcTexture, 0);
144180
checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
145181

182+
if (expected == gl.NO_ERROR) {
183+
if (srcTexFormatsTypes.type == gl.INT) {
184+
gl.clearBufferiv(gl.COLOR, 0, fullIntColor);
185+
} else if (srcTexFormatsTypes.type == gl.UNSIGNED_INT) {
186+
gl.clearBufferuiv(gl.COLOR, 0, fullUintColor);
187+
} else {
188+
gl.clearColor(copyTestFullColor[0], copyTestFullColor[1], copyTestFullColor[2], copyTestFullColor[3]);
189+
gl.clear(gl.COLOR_BUFFER_BIT);
190+
}
191+
}
192+
146193
gl.bindTexture(gl.TEXTURE_2D, texture);
147194
gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl[internalformat], 0, 0, 64, 64, 0);
148195
wtu.glErrorShouldBe(gl, expected, msg + srcTexFormatsTypes.internalformat + '=>' + internalformat);
149196

197+
if (expected == gl.NO_ERROR) {
198+
if (srcTexFormatsTypes.type == gl.INT) {
199+
gl.clearBufferiv(gl.COLOR, 0, subIntColor);
200+
} else if (srcTexFormatsTypes.type == gl.UNSIGNED_INT) {
201+
gl.clearBufferuiv(gl.COLOR, 0, subUintColor);
202+
} else {
203+
gl.clearColor(copyTestSubColor[0], copyTestSubColor[1], copyTestSubColor[2], copyTestSubColor[3]);
204+
gl.clear(gl.COLOR_BUFFER_BIT);
205+
}
206+
gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 32, 32);
207+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "copyTexSubImage2D should succeed for " + srcTexFormatsTypes.internalformat + '=>' + internalformat);
208+
209+
const destFormatEnum = gl[internalformat];
210+
if (srcTexFormatsTypes.type == gl.INT || srcTexFormatsTypes.type == gl.UNSIGNED_INT) {
211+
const isInt = (srcTexFormatsTypes.type == gl.INT);
212+
const verifyFbo = gl.createFramebuffer();
213+
const verifyRbo = gl.createRenderbuffer();
214+
gl.bindFramebuffer(gl.FRAMEBUFFER, verifyFbo);
215+
gl.bindRenderbuffer(gl.RENDERBUFFER, verifyRbo);
216+
gl.renderbufferStorage(gl.RENDERBUFFER, isInt ? gl.RGBA32I : gl.RGBA32UI, gl.canvas.width, gl.canvas.height);
217+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, verifyRbo);
218+
checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
219+
gl.useProgram(isInt ? intCopyVerifyProgram : uintCopyVerifyProgram);
220+
wtu.drawUnitQuad(gl);
221+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Drawing integer copied texture should succeed.");
222+
223+
const readBufSub = isInt ? new Int32Array(4) : new Uint32Array(4);
224+
const readBufFull = isInt ? new Int32Array(4) : new Uint32Array(4);
225+
const expectedSub = wtu.expectedSampledIntColor(gl, destFormatEnum, isInt ? subIntColor : subUintColor);
226+
const expectedFull = wtu.expectedSampledIntColor(gl, destFormatEnum, isInt ? fullIntColor : fullUintColor);
227+
wtu.checkCanvasRect(gl, 16, 16, 1, 1, expectedSub,
228+
"Sub-image copy region should match for " + internalformat, 0,
229+
readBufSub, isInt ? gl.INT : gl.UNSIGNED_INT, gl.RGBA_INTEGER);
230+
wtu.checkCanvasRect(gl, 48, 48, 1, 1, expectedFull,
231+
"Full-image copy region should match for " + internalformat, 0,
232+
readBufFull, isInt ? gl.INT : gl.UNSIGNED_INT, gl.RGBA_INTEGER);
233+
gl.deleteRenderbuffer(verifyRbo);
234+
gl.deleteFramebuffer(verifyFbo);
235+
} else {
236+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
237+
gl.useProgram(floatCopyVerifyProgram);
238+
wtu.clearAndDrawUnitQuad(gl);
239+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Drawing copied texture should succeed.");
240+
241+
const expectedSub = wtu.expectedSampledCopyColor(gl, destFormatEnum, copyTestSubColor);
242+
const expectedFull = wtu.expectedSampledCopyColor(gl, destFormatEnum, copyTestFullColor);
243+
wtu.checkCanvasRect(gl, 16, 16, 1, 1, expectedSub,
244+
"Sub-image copy region should match for " + internalformat, 2);
245+
wtu.checkCanvasRect(gl, 48, 48, 1, 1, expectedFull,
246+
"Full-image copy region should match for " + internalformat, 2);
247+
}
248+
}
249+
150250
gl.deleteTexture(srcTexture);
151251
gl.deleteFramebuffer(fbo);
152252
}

‎sdk/tests/js/tests/ext-color-buffer-half-float.js‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ function runInternalFormatQueryTest()
273273
testPassed("Internal format query succeeded");
274274
}
275275

276+
const copyTestFullColor = [0.125, 0.25, 0.5, 0.75];
277+
const copyTestSubColor = [0.875, 0.625, 0.375, 0.25];
278+
276279
function runCopyTexImageTest(enabled)
277280
{
278281
var width = 16;
@@ -313,6 +316,7 @@ function runCopyTexImageTest(enabled)
313316
{ valid: true, renderable: false, format: "LUMINANCE_ALPHA", destFormat: "LUMINANCE_ALPHA", },
314317
];
315318
}
319+
var copyVerifyProgram = wtu.setupSimpleTextureProgram(gl);
316320
cases.forEach(function(testcase) {
317321
debug("");
318322
debug(`Testing CopyTexImage2D for format: ${testcase.format}, internalformat: ${testcase.internalformat}, destformat: ${testcase.destFormat}`);
@@ -330,16 +334,35 @@ function runCopyTexImageTest(enabled)
330334
var fbo = gl.createFramebuffer();
331335
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
332336
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texSrc, level);
333-
var texDest = gl.createTexture();
334-
gl.bindTexture(gl.TEXTURE_2D, texDest);
337+
var texDest = allocateTexture();
335338
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup framebuffer with texture should succeed.");
336339
if (enabled && testcase.renderable) {
337340
if (!wtu.isWebGL2(gl) && format == gl.RGB && gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
338341
testPassed("RGB framebuffer attachment not supported. This is allowed.")
339342
} else {
340343
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
344+
gl.clearColor(copyTestFullColor[0], copyTestFullColor[1], copyTestFullColor[2], copyTestFullColor[3]);
345+
gl.clear(gl.COLOR_BUFFER_BIT);
341346
gl.copyTexImage2D(gl.TEXTURE_2D, level, destFormat, 0, 0, width, height, 0);
342347
wtu.glErrorShouldBe(gl, testcase.valid ? gl.NO_ERROR : [gl.INVALID_ENUM, gl.INVALID_OPERATION], "CopyTexImage2D");
348+
if (testcase.valid) {
349+
gl.clearColor(copyTestSubColor[0], copyTestSubColor[1], copyTestSubColor[2], copyTestSubColor[3]);
350+
gl.clear(gl.COLOR_BUFFER_BIT);
351+
gl.copyTexSubImage2D(gl.TEXTURE_2D, level, 0, 0, 0, 0, width / 2, height / 2);
352+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "CopyTexSubImage2D should succeed.");
353+
354+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
355+
gl.useProgram(copyVerifyProgram);
356+
wtu.clearAndDrawUnitQuad(gl);
357+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Drawing copied texture should succeed.");
358+
359+
const expectedSub = wtu.expectedSampledCopyColor(gl, destFormat, copyTestSubColor);
360+
const expectedFull = wtu.expectedSampledCopyColor(gl, destFormat, copyTestFullColor);
361+
wtu.checkCanvasRect(gl, Math.floor(gl.canvas.width / 4), Math.floor(gl.canvas.height / 4), 1, 1,
362+
expectedSub, "Sub-image copy region should match expected color", 2);
363+
wtu.checkCanvasRect(gl, Math.floor(gl.canvas.width * 3 / 4), Math.floor(gl.canvas.height * 3 / 4), 1, 1,
364+
expectedFull, "Full-image copy region should match expected color", 2);
365+
}
343366
}
344367
} else {
345368
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT");

‎sdk/tests/js/webgl-test-utils.js‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,104 @@ var colorAsSampledWithInternalFormat = function(color, internalFormat) {
35433543
return color;
35443544
}
35453545

3546+
/**
3547+
* Returns the expected 8-bit RGBA color when sampling a texture of internal
3548+
* format |destFormat| populated by copying from a framebuffer cleared to the
3549+
* floating-point [0, 1] RGBA color |src|, and drawing it to an 8-bit RGBA
3550+
* framebuffer.
3551+
* @param {!WebGLRenderingContext} gl The WebGLRenderingContext to use.
3552+
* @param {GLenum} destFormat The destination texture internalFormat.
3553+
* @param {!Array.<number>} src 4-element array of [0, 1] RGBA values.
3554+
* @return {!Array.<number>} 4-element array of [0, 255] RGBA values.
3555+
*/
3556+
var expectedSampledCopyColor = function(gl, destFormat, src) {
3557+
const GL = globalThis.WebGL2RenderingContext || gl;
3558+
const toByte = v => Math.round(Math.min(Math.max(v, 0.0), 1.0) * 255.0);
3559+
const r = toByte(src[0]);
3560+
const g = toByte(src[1]);
3561+
const b = toByte(src[2]);
3562+
const a = toByte(src[3]);
3563+
switch (destFormat) {
3564+
case GL.R8:
3565+
case GL.R16F:
3566+
case GL.R32F:
3567+
return [r, 0, 0, 255];
3568+
case GL.RG8:
3569+
case GL.RG16F:
3570+
case GL.RG32F:
3571+
return [r, g, 0, 255];
3572+
case GL.RGB:
3573+
case GL.RGB8:
3574+
case GL.SRGB8:
3575+
case GL.RGB16F:
3576+
case GL.RGB32F:
3577+
case GL.R11F_G11F_B10F:
3578+
return [r, g, b, 255];
3579+
case GL.RGBA:
3580+
case GL.RGBA8:
3581+
case GL.SRGB8_ALPHA8:
3582+
case GL.RGBA16F:
3583+
case GL.RGBA32F:
3584+
return [r, g, b, a];
3585+
case GL.LUMINANCE:
3586+
return [r, r, r, 255];
3587+
case GL.ALPHA:
3588+
return [0, 0, 0, a];
3589+
case GL.LUMINANCE_ALPHA:
3590+
return [r, r, r, a];
3591+
default:
3592+
testFailed("Unexpected destFormat: " + glEnumToString(gl, destFormat));
3593+
return [0, 0, 0, 0];
3594+
}
3595+
};
3596+
3597+
/**
3598+
* Returns the expected 4-element integer/unsigned-integer RGBA color when
3599+
* sampling a texture of integer internal format |destFormat| populated from
3600+
* a framebuffer cleared to |src|.
3601+
* @param {!WebGL2RenderingContext} gl The WebGL2RenderingContext to use.
3602+
* @param {GLenum} destFormat The destination texture internalFormat.
3603+
* @param {!Array.<number>|!Int32Array|!Uint32Array} src 4-element RGBA values.
3604+
* @return {!Array.<number>} 4-element array of expected sampled RGBA values.
3605+
*/
3606+
var expectedSampledIntColor = function(gl, destFormat, src) {
3607+
const GL = globalThis.WebGL2RenderingContext || gl;
3608+
switch (destFormat) {
3609+
case GL.R8I:
3610+
case GL.R8UI:
3611+
case GL.R16I:
3612+
case GL.R16UI:
3613+
case GL.R32I:
3614+
case GL.R32UI:
3615+
return [src[0], 0, 0, 1];
3616+
case GL.RG8I:
3617+
case GL.RG8UI:
3618+
case GL.RG16I:
3619+
case GL.RG16UI:
3620+
case GL.RG32I:
3621+
case GL.RG32UI:
3622+
return [src[0], src[1], 0, 1];
3623+
case GL.RGB8I:
3624+
case GL.RGB8UI:
3625+
case GL.RGB16I:
3626+
case GL.RGB16UI:
3627+
case GL.RGB32I:
3628+
case GL.RGB32UI:
3629+
return [src[0], src[1], src[2], 1];
3630+
case GL.RGBA8I:
3631+
case GL.RGBA8UI:
3632+
case GL.RGBA16I:
3633+
case GL.RGBA16UI:
3634+
case GL.RGBA32I:
3635+
case GL.RGBA32UI:
3636+
case GL.RGB10_A2UI:
3637+
return [src[0], src[1], src[2], src[3]];
3638+
default:
3639+
testFailed("Unexpected integer destFormat: " + glEnumToString(gl, destFormat));
3640+
return [0, 0, 0, 0];
3641+
}
3642+
};
3643+
35463644
function comparePixels(cmp, ref, tolerance, diff) {
35473645
if (cmp.length != ref.length) {
35483646
testFailed("invalid pixel size.");
@@ -3769,6 +3867,8 @@ var API = {
37693867
// color converter API
37703868
namedColorInColorSpace: namedColorInColorSpace,
37713869
colorAsSampledWithInternalFormat: colorAsSampledWithInternalFormat,
3870+
expectedSampledCopyColor: expectedSampledCopyColor,
3871+
expectedSampledIntColor: expectedSampledIntColor,
37723872

37733873
// sRGB converter api
37743874
sRGBToLinear: sRGBToLinear,

0 commit comments

Comments
 (0)