Skip to content

Commit

Permalink
tweak maxMipLevelCount signature, move standardizeExtent3D inside
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Feb 19, 2021
1 parent 28d70df commit f1d958a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/webgpu/api/validation/createTexture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { poptions, params } from '../../../common/framework/params_builder.js';
import { makeTestGroup } from '../../../common/framework/test_group.js';
import { kAllTextureFormats, kAllTextureFormatInfo } from '../../capability_info.js';
import { maxMipLevelCount } from '../../util/texture/base.js';
import { standardizeExtent3D } from '../../util/unions.js';

import { ValidationTest } from './validation_test.js';

Expand Down Expand Up @@ -192,10 +191,7 @@ g.test('mipLevelCount,bound_check')
usage: GPUTextureUsage.SAMPLED,
};

const mipLevelCount = maxMipLevelCount(
standardizeExtent3D(descriptor.size),
descriptor.dimension
);
const mipLevelCount = maxMipLevelCount(descriptor);
descriptor.mipLevelCount = mipLevelCount;
t.device.createTexture(descriptor);

Expand Down
21 changes: 14 additions & 7 deletions src/webgpu/util/texture/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export function maxMipLevelCount(
size: GPUExtent3DDict,
dimension: GPUTextureDimension | undefined
): number {
let maxMippedDimension = size.width;
if (dimension !== '1d') maxMippedDimension = Math.max(maxMippedDimension, size.height);
if (dimension === '3d') maxMippedDimension = Math.max(maxMippedDimension, size.depth);
import { standardizeExtent3D } from '../../util/unions.js';

export function maxMipLevelCount({
size,
dimension = '2d',
}: {
readonly size: GPUExtent3D;
readonly dimension?: GPUTextureDimension;
}): number {
const sizeDict = standardizeExtent3D(size);

let maxMippedDimension = sizeDict.width;
if (dimension !== '1d') maxMippedDimension = Math.max(maxMippedDimension, sizeDict.height);
if (dimension === '3d') maxMippedDimension = Math.max(maxMippedDimension, sizeDict.depth);
return Math.floor(Math.log2(maxMippedDimension)) + 1;
}

0 comments on commit f1d958a

Please sign in to comment.