Skip to content

Commit 5170f8a

Browse files
authored
Test createTexture() with invalid usages or combinations of usages (#4636)
* Test createTexture() with invalid usages or combinations of usages Per spec, TRANSIENT_ATTACHMENT cannot be used in any combination of usages other than RENDER_ATTACHMENT | TRANSIENT_ATTACHMENT. * address comments
1 parent 0d85e34 commit 5170f8a

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/webgpu/api/validation/buffer/create.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
kAllBufferUsageBits,
99
kBufferSizeAlignment,
1010
kBufferUsages,
11+
kSomeBogusBufferUsage,
1112
} from '../../../capability_info.js';
1213
import { GPUConst } from '../../../constants.js';
1314
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
@@ -54,14 +55,12 @@ g.test('limit')
5455
t.expectGPUError('validation', () => t.createBufferTracked({ size, usage }), !isValid);
5556
});
5657

57-
const kInvalidUsage = 0x8000;
58-
assert((kInvalidUsage & kAllBufferUsageBits) === 0);
5958
g.test('usage')
6059
.desc('Test combinations of zero to two usage flags are validated to be valid.')
6160
.params(u =>
6261
u
63-
.combine('usage1', [0, ...kBufferUsages, kInvalidUsage])
64-
.combine('usage2', [0, ...kBufferUsages, kInvalidUsage])
62+
.combine('usage1', [0, ...kBufferUsages, kSomeBogusBufferUsage])
63+
.combine('usage2', [0, ...kBufferUsages, kSomeBogusBufferUsage])
6564
.beginSubcases()
6665
.combine('mappedAtCreation', [false, true])
6766
)

src/webgpu/api/validation/createTexture.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
kTextureUsages,
99
isValidTextureUsageCombination,
1010
kValidCombinationsOfOneOrTwoTextureUsages,
11+
kAllTextureUsages,
12+
kSomeBogusTextureUsage,
1113
} from '../../capability_info.js';
1214
import { GPUConst } from '../../constants.js';
1315
import {
@@ -1098,6 +1100,38 @@ g.test('depthOrArrayLayers_and_mipLevelCount_for_transient_attachments')
10981100
}, !success);
10991101
});
11001102

1103+
g.test('usage')
1104+
.desc('Test combinations of zero to two usage flags are validated to be valid.')
1105+
.params(u =>
1106+
u
1107+
.combine('usage1', [0, ...kTextureUsages, kSomeBogusTextureUsage])
1108+
.combine('usage2', [0, ...kTextureUsages, kSomeBogusTextureUsage])
1109+
.filter(p => p.usage1 <= p.usage2)
1110+
)
1111+
.fn(t => {
1112+
const { usage1, usage2 } = t.params;
1113+
const usage = usage1 | usage2;
1114+
1115+
// MAINTENANCE_TODO(#4509): Remove this after all implementations have TRANSIENT_ATTACHMENT.
1116+
if ((usage & GPUConst.TextureUsage.TRANSIENT_ATTACHMENT) !== 0) {
1117+
t.skipIfTransientAttachmentNotSupported();
1118+
}
1119+
1120+
const isValid =
1121+
usage !== 0 &&
1122+
(usage & ~kAllTextureUsages) === 0 &&
1123+
((usage & GPUTextureUsage.TRANSIENT_ATTACHMENT) === 0 ||
1124+
usage === (GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TRANSIENT_ATTACHMENT));
1125+
1126+
t.expectGPUError(
1127+
'validation',
1128+
() => {
1129+
t.createTextureTracked({ format: 'rgba8unorm', size: [1, 1], usage });
1130+
},
1131+
!isValid
1132+
);
1133+
});
1134+
11011135
g.test('viewFormats')
11021136
.desc(
11031137
`Test creating a texture with viewFormats list for all {texture format}x{view format}. Only compatible view formats should be valid.`

src/webgpu/capability_info.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export const kAllBufferUsageBits = kBufferUsages.reduce(
7777
0
7878
);
7979

80+
/** An arbitrary invalid buffer usage bit. */
81+
export const kSomeBogusBufferUsage: GPUBufferUsageFlags = 0x4000_0000;
82+
assert((kSomeBogusBufferUsage & kAllBufferUsageBits) === 0);
83+
8084
// Errors
8185

8286
/** Per-GPUErrorFilter info. */
@@ -225,7 +229,7 @@ const kTextureUsageInfo: {
225229
/** List of all GPUTextureUsage values. */
226230
export const kTextureUsages = numericKeysOf(kTextureUsageInfo);
227231
/** Bitmask of all known texture usages. */
228-
const kAllTextureUsages = kTextureUsages.reduce((acc, usage) => acc | usage, 0);
232+
export const kAllTextureUsages = kTextureUsages.reduce((acc, usage) => acc | usage, 0);
229233

230234
/** An arbitrary invalid texture usage bit. */
231235
export const kSomeBogusTextureUsage: GPUTextureUsageFlags = 0x4000_0000;

0 commit comments

Comments
 (0)