Skip to content

Commit

Permalink
Bugfix for getTextureCopyLayout introduced in #1068 (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Mar 18, 2022
1 parent e2df105 commit 25d05d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/webgpu/util/texture/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export function physicalMipSize(

/**
* Compute the "virtual size" of a mip level of a texture (not accounting for texel block rounding).
*
* MAINTENANCE_TODO: Change input/output to Required<GPUExtent3DDict> for consistency.
*/
export function virtualMipSize(
dimension: GPUTextureDimension,
Expand Down
13 changes: 10 additions & 3 deletions src/webgpu/util/texture/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { align } from '../math.js';
import { reifyExtent3D } from '../unions.js';

import { virtualMipSize } from './base.js';
import { physicalMipSize, virtualMipSize } from './base.js';

/** The minimum `bytesPerRow` alignment, per spec. */
export const kBytesPerRowAlignment = 256;
Expand Down Expand Up @@ -50,17 +50,24 @@ export interface TextureCopyLayout extends TextureSubCopyLayout {
* of size `baseSize` with the provided `format` and `dimension`.
*
* Computes default values for `bytesPerRow` and `rowsPerImage` if not specified.
*
* MAINTENANCE_TODO: Change input/output to Required<GPUExtent3DDict> for consistency.
*/
export function getTextureCopyLayout(
format: SizedTextureFormat,
dimension: GPUTextureDimension,
baseSize: readonly [number, number, number],
{ mipLevel, bytesPerRow, rowsPerImage }: LayoutOptions = kDefaultLayoutOptions
): TextureCopyLayout {
const mipSize = virtualMipSize(dimension, baseSize, mipLevel);
const mipSize = physicalMipSize(
{ width: baseSize[0], height: baseSize[1], depthOrArrayLayers: baseSize[2] },
format,
dimension,
mipLevel
);

const layout = getTextureSubCopyLayout(format, mipSize, { bytesPerRow, rowsPerImage });
return { ...layout, mipSize };
return { ...layout, mipSize: [mipSize.width, mipSize.height, mipSize.depthOrArrayLayers] };
}

/**
Expand Down

0 comments on commit 25d05d4

Please sign in to comment.