Skip to content

Commit

Permalink
Fix readSinglePixelFrom2DTexture helper (#1088)
Browse files Browse the repository at this point in the history
Since it reads only one pixel, this should use the new
getTextureSubCopyLayout instead of getTextureCopyLayout.
  • Loading branch information
kainino0x authored Mar 18, 2022
1 parent 8245ea0 commit 6600201
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 3 additions & 7 deletions src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { align, roundDown } from './util/math.js';
import {
getTextureCopyLayout,
getTextureSubCopyLayout,
LayoutOptions as TextureLayoutOptions,
} from './util/texture/layout.js';
import { PerTexelComponent, kTexelRepresentationInfo } from './util/texture/texel_data.js';
Expand Down Expand Up @@ -596,12 +597,7 @@ export class GPUTest extends Fixture {
{ x, y }: { x: number; y: number },
{ slice = 0, layout }: { slice?: number; layout?: TextureLayoutOptions }
): GPUBuffer {
const { byteLength, bytesPerRow, rowsPerImage, mipSize } = getTextureCopyLayout(
format,
'2d',
[1, 1, 1],
layout
);
const { byteLength, bytesPerRow, rowsPerImage } = getTextureSubCopyLayout(format, [1, 1]);
const buffer = this.device.createBuffer({
size: byteLength,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
Expand All @@ -612,7 +608,7 @@ export class GPUTest extends Fixture {
commandEncoder.copyTextureToBuffer(
{ texture: src, mipLevel: layout?.mipLevel, origin: { x, y, z: slice } },
{ buffer, bytesPerRow, rowsPerImage },
mipSize
[1, 1]
);
this.queue.submit([commandEncoder.finish()]);

Expand Down
17 changes: 13 additions & 4 deletions src/webgpu/util/texture/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ export function physicalMipSize(
): Required<GPUExtent3DDict> {
switch (dimension) {
case '1d':
assert(level === 0 && baseSize.height === 1 && baseSize.depthOrArrayLayers === 1);
assert(level === 0, '1d textures cannot be mipmapped');
assert(baseSize.height === 1 && baseSize.depthOrArrayLayers === 1, '1d texture not Wx1x1');
return { width: baseSize.width, height: 1, depthOrArrayLayers: 1 };

case '2d': {
assert(Math.max(baseSize.width, baseSize.height) >> level > 0);
assert(
Math.max(baseSize.width, baseSize.height) >> level > 0,
() => `level (${level}) too large for base size (${baseSize.width}x${baseSize.height})`
);

const virtualWidthAtLevel = Math.max(baseSize.width >> level, 1);
const virtualHeightAtLevel = Math.max(baseSize.height >> level, 1);
Expand All @@ -67,9 +71,14 @@ export function physicalMipSize(
}

case '3d': {
assert(Math.max(baseSize.width, baseSize.height, baseSize.depthOrArrayLayers) >> level > 0);
assert(
kTextureFormatInfo[format].blockWidth === 1 && kTextureFormatInfo[format].blockHeight === 1
Math.max(baseSize.width, baseSize.height, baseSize.depthOrArrayLayers) >> level > 0,
() =>
`level (${level}) too large for base size (${baseSize.width}x${baseSize.height}x${baseSize.depthOrArrayLayers})`
);
assert(
kTextureFormatInfo[format].blockWidth === 1 && kTextureFormatInfo[format].blockHeight === 1,
'not implemented for 3d block formats'
);
return {
width: Math.max(baseSize.width >> level, 1),
Expand Down

0 comments on commit 6600201

Please sign in to comment.