Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up deprecated .copyDst/.renderable/.renderTarget* from kTextureFormatInfo #3412

Merged
merged 8 commits into from
Mar 11, 2024
2 changes: 1 addition & 1 deletion src/webgpu/api/operation/command_buffer/image_copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ works for every format with 2d and 2d-array textures.
};
let textureHeight = 4 * info.blockHeight;
let rowsPerImage = rowsPerImageEqualsCopyHeight ? copyHeight : copyHeight + 1;
const bytesPerRow = align(copyWidth * info.bytesPerBlock, 256);
const bytesPerRow = align(copyWidth * info.color.bytes, 256);

if (dimension === '1d') {
copySize.height = 1;
Expand Down
10 changes: 6 additions & 4 deletions src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ depth ranges as well.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { assert } from '../../../../common/util/util.js';
import { kDepthStencilFormats, kTextureFormatInfo } from '../../../format_info.js';
import { GPUTest } from '../../../gpu_test.js';
import {
Expand Down Expand Up @@ -52,6 +53,7 @@ have unexpected values then get drawn to the color buffer, which is later checke
.fn(async t => {
const { format, unclippedDepth, writeDepth, multisampled } = t.params;
const info = kTextureFormatInfo[format];
assert(!!info.depth);

/** Number of depth values to test for both vertex output and frag_depth output. */
const kNumDepthValues = 8;
Expand Down Expand Up @@ -222,16 +224,16 @@ have unexpected values then get drawn to the color buffer, which is later checke
: undefined;

const dsActual =
!multisampled && info.bytesPerBlock
!multisampled && info.depth.bytes
? t.device.createBuffer({
size: kNumTestPoints * info.bytesPerBlock,
size: kNumTestPoints * info.depth.bytes,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
})
: undefined;
const dsExpected =
!multisampled && info.bytesPerBlock
!multisampled && info.depth.bytes
? t.device.createBuffer({
size: kNumTestPoints * info.bytesPerBlock,
size: kNumTestPoints * info.depth.bytes,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
})
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ const initializedStateAsStencil = {
[InitializedState.Canary]: 42,
};

function allAspectsCopyDst(info: (typeof kTextureFormatInfo)[UncompressedTextureFormat]) {
return (
(!info.color || info.color.copyDst) &&
(!info.depth || info.depth.copyDst) &&
(!info.stencil || info.stencil.copyDst)
);
}

export function getRequiredTextureUsage(
format: UncompressedTextureFormat,
sampleCount: number,
Expand Down Expand Up @@ -159,10 +167,11 @@ export function getRequiredTextureUsage(
usage |= GPUConst.TextureUsage.RENDER_ATTACHMENT;
}

if (!kTextureFormatInfo[format].copyDst) {
const info = kTextureFormatInfo[format];
if (!allAspectsCopyDst(info)) {
// Copies are not possible. We need OutputAttachment to initialize
// canary data.
assert(kTextureFormatInfo[format].renderable);
if (info.color) assert(!!info.colorRender, 'not implemented for non-renderable color');
usage |= GPUConst.TextureUsage.RENDER_ATTACHMENT;
}

Expand Down Expand Up @@ -388,10 +397,11 @@ export class TextureZeroInitTest extends GPUTest {
state: InitializedState,
subresourceRange: SubresourceRange
): void {
if (this.p.sampleCount > 1 || !kTextureFormatInfo[this.p.format].copyDst) {
const info = kTextureFormatInfo[this.p.format];
if (this.p.sampleCount > 1 || !allAspectsCopyDst(info)) {
// Copies to multisampled textures not yet specified.
// Use a storeOp for now.
assert(kTextureFormatInfo[this.p.format].renderable);
if (info.color) assert(!!info.colorRender, 'not implemented for non-renderable color');
this.initializeWithStoreOp(state, texture, subresourceRange);
} else {
this.initializeWithCopy(texture, state, subresourceRange);
Expand Down Expand Up @@ -517,20 +527,15 @@ export const kTestParams = kUnitCaseParamsBuilder
const info = kTextureFormatInfo[format];

return (
((usage & GPUConst.TextureUsage.RENDER_ATTACHMENT) !== 0 && !info.renderable) ||
((usage & GPUConst.TextureUsage.RENDER_ATTACHMENT) !== 0 &&
info.color &&
!info.colorRender) ||
((usage & GPUConst.TextureUsage.STORAGE_BINDING) !== 0 && !info.color?.storage) ||
(sampleCount > 1 && !info.multisample)
);
})
.combine('nonPowerOfTwo', [false, true])
.combine('canaryOnCreation', [false, true])
.filter(({ canaryOnCreation, format }) => {
// We can only initialize the texture if it's encodable or renderable.
const canInitialize = format in kTextureFormatInfo || kTextureFormatInfo[format].renderable;

// Filter out cases where we want canary values but can't initialize.
return !canaryOnCreation || canInitialize;
});
.combine('canaryOnCreation', [false, true]);

type TextureZeroParams = ParamTypeOf<typeof kTestParams>;

Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/api/operation/storage_texture/read_only.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class F extends GPUTest {
storageTexture: GPUTexture,
format: ColorTextureFormat
): ArrayBuffer {
const bytesPerBlock = kTextureFormatInfo[format].bytesPerBlock;
const bytesPerBlock = kTextureFormatInfo[format].color.bytes;
assert(bytesPerBlock !== undefined);

const width = storageTexture.width;
Expand Down
19 changes: 8 additions & 11 deletions src/webgpu/api/validation/createTexture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ g.test('sampleCount,various_sampleCount_with_all_formats')
usage,
};

const success = sampleCount === 1 || (sampleCount === 4 && info.multisample && info.renderable);
const success = sampleCount === 1 || (sampleCount === 4 && info.multisample);

t.expectValidationError(() => {
t.device.createTexture(descriptor);
Expand Down Expand Up @@ -1066,16 +1066,13 @@ g.test('texture_usage')
// Note that we unconditionally test copy usages for all formats. We don't check copySrc/copyDst in kTextureFormatInfo in capability_info.js
// if (!info.copySrc && (usage & GPUTextureUsage.COPY_SRC) !== 0) success = false;
// if (!info.copyDst && (usage & GPUTextureUsage.COPY_DST) !== 0) success = false;
if (
(usage & GPUTextureUsage.STORAGE_BINDING) !== 0 &&
!isTextureFormatUsableAsStorageFormat(format, t.isCompatibility)
)
success = false;
if (
(!info.renderable || (appliedDimension !== '2d' && appliedDimension !== '3d')) &&
(usage & GPUTextureUsage.RENDER_ATTACHMENT) !== 0
)
success = false;
if (usage & GPUTextureUsage.STORAGE_BINDING) {
if (!isTextureFormatUsableAsStorageFormat(format, t.isCompatibility)) success = false;
}
if (usage & GPUTextureUsage.RENDER_ATTACHMENT) {
if (appliedDimension === '1d') success = false;
if (info.color && !info.colorRender) success = false;
}

t.expectValidationError(() => {
t.device.createTexture(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Test that the copy size must be aligned to the texture's format's block size.
const texture = t.createAlignedTexture(format, size, origin, dimension);

const bytesPerRow = align(
Math.max(1, Math.ceil(size.width / info.blockWidth)) * info.bytesPerBlock,
Math.max(1, Math.ceil(size.width / info.blockWidth)) * info.color.bytes,
256
);
const rowsPerImage = Math.ceil(size.height / info.blockHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ g.test('compressed')
.fn(t => {
const { format } = t.params;

const { blockWidth, blockHeight, bytesPerBlock } = kTextureFormatInfo[format];
const info = kTextureFormatInfo[format];

const textureSize = [info.blockWidth, info.blockHeight, 1];
const texture = t.device.createTexture({
size: [blockWidth, blockHeight, 1],
size: textureSize,
format,
usage: GPUTextureUsage.COPY_SRC,
});
t.trackForCleanup(texture);

const bytesPerRow = align(bytesPerBlock, 256);
const bytesPerRow = align(info.color.bytes, 256);

const buffer = t.device.createBuffer({
size: bytesPerRow,
Expand All @@ -37,7 +38,7 @@ g.test('compressed')
t.trackForCleanup(buffer);

const encoder = t.device.createCommandEncoder();
encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, [blockWidth, blockHeight, 1]);
encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, textureSize);
t.expectGPUError('validation', () => {
encoder.finish();
});
Expand Down
Loading
Loading