Skip to content

Commit

Permalink
val/copyT2T,format_compat: Don't assume compressed is always 4x4 (gpu…
Browse files Browse the repository at this point in the history
…web#1134)

The ASTC texture compression format has a lot of different block sizes
so using 16x16 for the test might not work. Instead use the LCM of the
block size.

(and add GCD and LCD util functions)
  • Loading branch information
Kangz committed Apr 5, 2022
1 parent 23afd04 commit 3032cf0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Expand Up @@ -13,7 +13,7 @@ import {
kTextureDimensions,
} from '../../../../capability_info.js';
import { kResourceStates } from '../../../../gpu_test.js';
import { align } from '../../../../util/math.js';
import { align, lcm } from '../../../../util/math.js';
import { ValidationTest } from '../../validation_test.js';

class F extends ValidationTest {
Expand Down Expand Up @@ -356,16 +356,20 @@ Test the formats of textures in copyTextureToTexture must be copy-compatible.
const dstFormatInfo = kTextureFormatInfo[dstFormat];
await t.selectDeviceOrSkipTestCase([srcFormatInfo.feature, dstFormatInfo.feature]);

const kTextureSize = { width: 16, height: 16, depthOrArrayLayers: 1 };
const textureSize = {
width: lcm(srcFormatInfo.blockWidth, dstFormatInfo.blockWidth),
height: lcm(srcFormatInfo.blockHeight, dstFormatInfo.blockHeight),
depthOrArrayLayers: 1,
};

const srcTexture = t.device.createTexture({
size: kTextureSize,
size: textureSize,
format: srcFormat,
usage: GPUTextureUsage.COPY_SRC,
});

const dstTexture = t.device.createTexture({
size: kTextureSize,
size: textureSize,
format: dstFormat,
usage: GPUTextureUsage.COPY_DST,
});
Expand All @@ -378,7 +382,7 @@ Test the formats of textures in copyTextureToTexture must be copy-compatible.
t.TestCopyTextureToTexture(
{ texture: srcTexture },
{ texture: dstTexture },
kTextureSize,
textureSize,
isSuccess ? 'Success' : 'FinishError'
);
});
Expand Down
19 changes: 19 additions & 0 deletions src/webgpu/util/math.ts
Expand Up @@ -349,3 +349,22 @@ export function isPowerOfTwo(n: number): boolean {
}
return n !== 0 && (n & (n - 1)) === 0;
}

/** @returns the Greatest Common Divisor (GCD) of the inputs */
export function gcd(a: number, b: number): number {
assert(Number.isInteger(a) && a > 0);
assert(Number.isInteger(b) && b > 0);

while (b !== 0) {
const bTemp = b;
b = a % b;
a = bTemp;
}

return a;
}

/** @returns the Least Common Multiplier (LCM) of the inputs */
export function lcm(a: number, b: number): number {
return (a * b) / gcd(a, b);
}

0 comments on commit 3032cf0

Please sign in to comment.