diff --git a/src/webgpu/api/validation/encoding/cmds/copyTextureToTexture.spec.ts b/src/webgpu/api/validation/encoding/cmds/copyTextureToTexture.spec.ts index 3bbba48d52..e1e64d492e 100644 --- a/src/webgpu/api/validation/encoding/cmds/copyTextureToTexture.spec.ts +++ b/src/webgpu/api/validation/encoding/cmds/copyTextureToTexture.spec.ts @@ -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 { @@ -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, }); @@ -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' ); }); diff --git a/src/webgpu/util/math.ts b/src/webgpu/util/math.ts index 6c4236809b..429330d4af 100644 --- a/src/webgpu/util/math.ts +++ b/src/webgpu/util/math.ts @@ -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); +}