Skip to content

Commit 9685122

Browse files
committed
Test that createBuffer/createTexture only allows exposed usages
For any buffer/texture usages known by the CTS, check that the browser only accepts it if it also exposes it. Currently the buffer test passes in all browsers - there haven't been any new usages in a long time. But next time we add a usage, this makes sure that when they start accepting the usage, they also start exposing it. The texture test fails in Safari because it's missing validation of unknown texture usages (this is also caught by another new test that tests an invalid usage). Passes in Chrome/Firefox. Unrelated cleanup: filter out redundant cases in createBuffer usage tests.
1 parent ded8b77 commit 9685122

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ g.test('usage')
6161
u
6262
.combine('usage1', [0, ...kBufferUsages, kInvalidUsage])
6363
.combine('usage2', [0, ...kBufferUsages, kInvalidUsage])
64+
.filter(p => p.usage1 <= p.usage2)
6465
.beginSubcases()
6566
.combine('mappedAtCreation', [false, true])
6667
)
@@ -83,6 +84,32 @@ g.test('usage')
8384
);
8485
});
8586

87+
g.test('new_usages')
88+
.desc(`Valid sages not present in GPUBufferUsage shouldn't be accepted by createBuffer().`)
89+
.params(u =>
90+
u //
91+
.beginSubcases()
92+
.combine('usage', kBufferUsages)
93+
)
94+
.fn(t => {
95+
const { usage } = t.params;
96+
97+
let exposedUsages = 0;
98+
for (const v of Object.values(GPUBufferUsage)) {
99+
exposedUsages |= v;
100+
}
101+
102+
const success = (usage & exposedUsages) === usage;
103+
104+
t.expectGPUError(
105+
'validation',
106+
() => {
107+
t.createBufferTracked({ size: 16, usage });
108+
},
109+
!success
110+
);
111+
});
112+
86113
const BufferUsage = GPUConst.BufferUsage;
87114

88115
g.test('createBuffer_invalid_and_oom')

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,35 @@ g.test('depthOrArrayLayers_and_mipLevelCount_for_transient_attachments')
10981098
}, !success);
10991099
});
11001100

1101+
g.test('new_usages')
1102+
.desc(`Valid sages not present in GPUTextureUsage shouldn't be accepted by createTexture().`)
1103+
.params(u =>
1104+
u
1105+
.combine('usage', [
1106+
...kTextureUsages,
1107+
GPUConst.TextureUsage.RENDER_ATTACHMENT | GPUConst.TextureUsage.TRANSIENT_ATTACHMENT,
1108+
])
1109+
.filter(p => isValidTextureUsageCombination(p.usage))
1110+
)
1111+
.fn(t => {
1112+
const { usage } = t.params;
1113+
1114+
let exposedUsages = 0;
1115+
for (const v of Object.values(GPUTextureUsage)) {
1116+
exposedUsages |= v;
1117+
}
1118+
1119+
const success = (usage & exposedUsages) === usage;
1120+
1121+
t.expectGPUError(
1122+
'validation',
1123+
() => {
1124+
t.createTextureTracked({ format: 'rgba8unorm', size: [1, 1], usage });
1125+
},
1126+
!success
1127+
);
1128+
});
1129+
11011130
g.test('viewFormats')
11021131
.desc(
11031132
`Test creating a texture with viewFormats list for all {texture format}x{view format}. Only compatible view formats should be valid.`

0 commit comments

Comments
 (0)