Skip to content

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
vonture committed Sep 25, 2024
1 parent 88d0634 commit 7a0291c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 61 deletions.
35 changes: 16 additions & 19 deletions src/webgpu/api/operation/texture_view/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ const kTextureViewWriteMethods = [
] as const;
type TextureViewWriteMethod = (typeof kTextureViewWriteMethods)[number];

const kTextureViewUsageMethods = [
'inherit',
'minimal',
] as const;
const kTextureViewUsageMethods = ['inherit', 'minimal'] as const;
type TextureViewUsageMethod = (typeof kTextureViewUsageMethods)[number];

// Src color values to read from a shader array.
Expand Down Expand Up @@ -278,18 +275,19 @@ function writeTextureAndGetExpectedTexelView(
}

function getTextureViewUsage(
viewUsageMethod : TextureViewUsageMethod,
minimalUsageForTest : GPUTextureUsageFlags) {
switch (viewUsageMethod) {
case 'inherit':
return 0;
viewUsageMethod: TextureViewUsageMethod,
minimalUsageForTest: GPUTextureUsageFlags
) {
switch (viewUsageMethod) {
case 'inherit':
return 0;

case 'minimal':
return minimalUsageForTest;
case 'minimal':
return minimalUsageForTest;

default:
unreachable();
}
default:
unreachable();
}
}

g.test('format')
Expand Down Expand Up @@ -358,10 +356,9 @@ TODO: Test rgb10a2uint when TexelRepresentation.numericRange is made per-compone
const { format, method, sampleCount, viewUsageMethod } = t.params;

const textureUsageForMethod = method.includes('storage')
? GPUTextureUsage.STORAGE_BINDING
: GPUTextureUsage.RENDER_ATTACHMENT;
const usage =
GPUTextureUsage.COPY_SRC | textureUsageForMethod;
? GPUTextureUsage.STORAGE_BINDING
: GPUTextureUsage.RENDER_ATTACHMENT;
const usage = GPUTextureUsage.COPY_SRC | textureUsageForMethod;

const texture = t.createTextureTracked({
format,
Expand All @@ -371,7 +368,7 @@ TODO: Test rgb10a2uint when TexelRepresentation.numericRange is made per-compone
});

const view = texture.createView({
usage : getTextureViewUsage(viewUsageMethod, textureUsageForMethod),
usage: getTextureViewUsage(viewUsageMethod, textureUsageForMethod),
});
const expectedTexelView = writeTextureAndGetExpectedTexelView(
t,
Expand Down
18 changes: 9 additions & 9 deletions src/webgpu/api/validation/createView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ g.test('texture_view_usage')
if (textureUsage & GPUTextureUsage.STORAGE_BINDING) {
t.skipIfTextureFormatNotUsableAsStorageTexture(format);
}
if ((textureUsage & GPUTextureUsage.RENDER_ATTACHMENT) && info.color && !info.colorRender) {
if (textureUsage & GPUTextureUsage.RENDER_ATTACHMENT && info.color && !info.colorRender) {
t.skip(`Texture with ${format} is not usable as a render attachment`);
}
})
Expand All @@ -374,9 +374,9 @@ g.test('texture_view_usage')
const size = [info.blockWidth, info.blockHeight, 1];
const dimension = '2d';
const mipLevelCount = 1;
const usage = textureUsage0 | textureUsage0;
const usage = textureUsage0 | textureUsage1;

const textureDescriptor : GPUTextureDescriptor = {
const textureDescriptor: GPUTextureDescriptor = {
size,
mipLevelCount,
dimension,
Expand All @@ -391,11 +391,11 @@ g.test('texture_view_usage')
const textureViewUsage = textureViewUsage0 | textureViewUsage1;

// Texture view usage must be a subset of texture usage
if ((~usage & textureViewUsage) != 0) success = false;
if ((~usage & textureViewUsage) !== 0) success = false;

t.expectValidationError(() => {
texture.createView({
usage : textureViewUsage,
});
}, !success);
t.expectValidationError(() => {
texture.createView({
usage: textureViewUsage,
});
}, !success);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ Texture Usages Validation Tests on All Kinds of WebGPU Subresource Usage Scopes.

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { unreachable } from '../../../../../common/util/util.js';
import { kTextureUsages } from '../../../../capability_info.js';
import { ValidationTest } from '../../validation_test.js';
import {
TextureBindingType,
kTextureBindingTypes,
IsReadOnlyTextureBindingType,
} from '../texture/in_render_common.spec.js';
import {
kTextureUsages,
} from '../../../../capability_info.js';

class F extends ValidationTest {
createBindGroupLayoutForTest(
Expand Down Expand Up @@ -583,10 +581,7 @@ g.test('subresources,texture_view_usages')
)
.params(u =>
u
.combine('usage', [
'color-attachment',
...kTextureBindingTypes,
] as const)
.combine('usage', ['color-attachment', ...kTextureBindingTypes] as const)
.combine('viewUsage', [0, ...kTextureUsages])
)
.fn(t => {
Expand All @@ -606,17 +601,17 @@ g.test('subresources,texture_view_usages')
}),
});


let validViewUsage = 0;
switch (usage) {
case 'color-attachment': {
const encoder = t.device.createCommandEncoder();
const renderPassEncoder = encoder.beginRenderPass({
colorAttachments: [{ view: texture.createView({usage:viewUsage}), loadOp: 'load', storeOp: 'store' }],
colorAttachments: [
{ view: texture.createView({ usage: viewUsage }), loadOp: 'load', storeOp: 'store' },
],
});
renderPassEncoder.end();

const success = (viewUsage == 0) || (viewUsage & GPUTextureUsage.RENDER_ATTACHMENT);
const success = viewUsage === 0 || viewUsage & GPUTextureUsage.RENDER_ATTACHMENT;

t.expectValidationError(() => {
encoder.finish();
Expand All @@ -626,29 +621,30 @@ g.test('subresources,texture_view_usages')
case 'sampled-texture':
case 'readonly-storage-texture':
case 'writeonly-storage-texture':
case 'readwrite-storage-texture': {
let success = true;
if (viewUsage != 0) {
if (usage == 'sampled-texture') {
if ((viewUsage & GPUTextureUsage.TEXTURE_BINDING) == 0) success = false;
} else {
if ((viewUsage & GPUTextureUsage.STORAGE_BINDING) == 0) success = false;
case 'readwrite-storage-texture':
{
let success = true;
if (viewUsage !== 0) {
if (usage === 'sampled-texture') {
if ((viewUsage & GPUTextureUsage.TEXTURE_BINDING) === 0) success = false;
} else {
if ((viewUsage & GPUTextureUsage.STORAGE_BINDING) === 0) success = false;
}
}
}

t.expectValidationError(() => {
const bindGroup = t.createBindGroupForTest(
texture.createView({
dimension: '2d-array',
usage:viewUsage
}),
usage,
'unfilterable-float'
);
}, !success);
}
break;
default:
unreachable();
t.expectValidationError(() => {
t.createBindGroupForTest(
texture.createView({
dimension: '2d-array',
usage: viewUsage,
}),
usage,
'unfilterable-float'
);
}, !success);
}
break;
default:
unreachable();
}
});

0 comments on commit 7a0291c

Please sign in to comment.