Skip to content

Commit c2bd4be

Browse files
authored
Add offset test to webgl-compressed-texture-astc (#3750)
* Add offset test to webgl-compressed-texture-astc * Add source length override to ASTC sub image upload
1 parent 62d401e commit c2bd4be

File tree

1 file changed

+71
-15
lines changed

1 file changed

+71
-15
lines changed

sdk/tests/conformance/extensions/webgl-compressed-texture-astc.html

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,20 +2163,6 @@
21632163
}
21642164

21652165
function uploadSubData(target) {
2166-
function checkResult(target, expectations, dim) {
2167-
switch (target) {
2168-
case gl.TEXTURE_2D:
2169-
wtu.glErrorShouldBe(gl, expectations[0], "uploading compressed 2D texture data via compressedTexSubImage" + dim);
2170-
break;
2171-
case gl.TEXTURE_2D_ARRAY:
2172-
wtu.glErrorShouldBe(gl, expectations[1], "uploading compressed 2D array texture data via compressedTexSubImage" + dim);
2173-
break;
2174-
case gl.TEXTURE_3D:
2175-
wtu.glErrorShouldBe(gl, expectations[2], "uploading compressed 3D texture data via compressedTexSubImage" + dim);
2176-
break;
2177-
}
2178-
}
2179-
21802166
gl.compressedTexSubImage2D(target, 0, 0, 0, width, height, format, data);
21812167
checkResult(target, [gl.NO_ERROR, gl.INVALID_ENUM, gl.INVALID_ENUM ], "2D");
21822168

@@ -2186,6 +2172,38 @@
21862172
}
21872173
}
21882174

2175+
function uploadSubDataOffset(target) {
2176+
const blockSize = getBlockDimensions(format);
2177+
if ((width % blockSize.width) || (height % blockSize.height)) {
2178+
// Skip test for unaligned blocks
2179+
return;
2180+
}
2181+
2182+
const x = blockSize.width;
2183+
const y = blockSize.height;
2184+
const blitWidth = width - x;
2185+
const blitHeight = height - y;
2186+
2187+
// Offset the update by one horizontal and one vertical rows.
2188+
// ASTC block size is always 16 bytes (128 bits)
2189+
const offset = (width / blockSize.width + height / blockSize.height - 1) * 16;
2190+
2191+
gl.compressedTexSubImage2D(target, 0, x, y, blitWidth, blitHeight, format, data, offset);
2192+
checkResult(target, [gl.NO_ERROR, gl.INVALID_ENUM, gl.INVALID_ENUM ], "2D", true);
2193+
2194+
const srcLengthOverride = data.length - offset;
2195+
gl.compressedTexSubImage2D(target, 0, x, y, blitWidth, blitHeight, format, data, 0, srcLengthOverride);
2196+
checkResult(target, [gl.NO_ERROR, gl.INVALID_ENUM, gl.INVALID_ENUM ], "2D", true);
2197+
2198+
if (useES3) {
2199+
gl.compressedTexSubImage3D(target, 0, x, y, 0, blitWidth, blitHeight, 1, format, data, offset);
2200+
checkResult(target, [gl.INVALID_ENUM, gl.NO_ERROR, gl.NO_ERROR], "3D", true);
2201+
2202+
gl.compressedTexSubImage3D(target, 0, x, y, 0, blitWidth, blitHeight, 1, format, data, 0, srcLengthOverride);
2203+
checkResult(target, [gl.INVALID_ENUM, gl.NO_ERROR, gl.NO_ERROR], "3D", true);
2204+
}
2205+
}
2206+
21892207
function setupFilledTexture(target) {
21902208
var tex = gl.createTexture();
21912209
gl.bindTexture(target, tex);
@@ -2277,6 +2295,12 @@
22772295
checkSampling(gl.TEXTURE_2D)
22782296
gl.deleteTexture(tex);
22792297

2298+
// Upload with offsets
2299+
tex = setupEmptyTexture(gl.TEXTURE_2D, false);
2300+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating empty compressed texture via compressedTexImage2D");
2301+
uploadSubDataOffset(gl.TEXTURE_2D);
2302+
gl.deleteTexture(tex);
2303+
22802304
// mutable filled
22812305
tex = setupFilledTexture(gl.TEXTURE_2D);
22822306
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating filled compressed texture via compressedTexImage2D");
@@ -2304,6 +2328,12 @@
23042328
checkSampling(gl.TEXTURE_2D_ARRAY)
23052329
gl.deleteTexture(tex);
23062330

2331+
// Upload with offsets
2332+
tex = setupEmptyTexture(gl.TEXTURE_2D_ARRAY, false);
2333+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating empty compressed texture array via compressedTexImage3D");
2334+
uploadSubDataOffset(gl.TEXTURE_2D_ARRAY);
2335+
gl.deleteTexture(tex);
2336+
23072337
// mutable filled
23082338
tex = setupFilledTexture(gl.TEXTURE_2D_ARRAY);
23092339
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating filled compressed texture array via compressedTexImage3D");
@@ -2338,6 +2368,17 @@
23382368
}
23392369
gl.deleteTexture(tex);
23402370

2371+
// Upload with offsets
2372+
tex = setupEmptyTexture(gl.TEXTURE_3D, false);
2373+
if (hasHdr) {
2374+
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating empty compressed sliced 3D texture via compressedTexImage3D");
2375+
checkErrorColor();
2376+
uploadSubDataOffset(gl.TEXTURE_3D);
2377+
} else {
2378+
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "allocating empty compressed sliced 3D texture via compressedTexImage3D");
2379+
}
2380+
gl.deleteTexture(tex);
2381+
23412382
// mutable filled
23422383
tex = setupFilledTexture(gl.TEXTURE_3D);
23432384
if (hasHdr) {
@@ -2420,6 +2461,21 @@
24202461
}
24212462
}
24222463

2464+
function checkResult(target, expectations, dim, offsets = false) {
2465+
const offsetStr = offsets ? " with x/y offsets" : "";
2466+
switch (target) {
2467+
case gl.TEXTURE_2D:
2468+
wtu.glErrorShouldBe(gl, expectations[0], "uploading compressed 2D texture data via compressedTexSubImage" + dim + offsetStr);
2469+
break;
2470+
case gl.TEXTURE_2D_ARRAY:
2471+
wtu.glErrorShouldBe(gl, expectations[1], "uploading compressed 2D array texture data via compressedTexSubImage" + dim + offsetStr);
2472+
break;
2473+
case gl.TEXTURE_3D:
2474+
wtu.glErrorShouldBe(gl, expectations[2], "uploading compressed 3D texture data via compressedTexSubImage" + dim + offsetStr);
2475+
break;
2476+
}
2477+
}
2478+
24232479
// Builds several tests from two arrays
24242480
// data gives each Uint8Array encoded data to use
24252481
// formats the associate format to decode the data
@@ -2484,7 +2540,7 @@
24842540
return {
24852541
width: parseInt(match[1], 10),
24862542
height: parseInt(match[2], 10)
2487-
};
2543+
};
24882544
}
24892545
}
24902546
testFailed('Could not find block dimensions for format ' + ctu.formatToString(ext, format));

0 commit comments

Comments
 (0)