Skip to content

Commit 0d85e34

Browse files
authored
Test createView and resolveTarget with TRANSIENT_ATTACHMENT (#4635)
This restriction is missing from the spec, but textures with TRANSIENT_ATTACHMENT must not be used as resolve targets. This must apply regardless of any usage subsetting in createView(). For simplicity (to better avoid bugs in validation elsewhere), it's proposed that createView() simply cannot subset a TRANSIENT_ATTACHMENT texture. This test implements that proposal.
1 parent 1a90098 commit 0d85e34

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { kUnitCaseParamsBuilder } from '../../../common/framework/params_builder
55
import { makeTestGroup } from '../../../common/framework/test_group.js';
66
import { unreachable } from '../../../common/util/util.js';
77
import {
8+
isValidTextureUsageCombination,
89
kTextureAspects,
910
kTextureDimensions,
1011
kTextureUsages,
@@ -356,7 +357,7 @@ g.test('texture_view_usage')
356357
);
357358
})
358359
.beginSubcases()
359-
.combine('textureViewUsage', [0, ...kTextureUsages])
360+
.combine('textureViewUsage', kTextureUsages)
360361
.unless(({ textureUsage, textureViewUsage }) => {
361362
// TRANSIENT_ATTACHMENT is only valid when combined with RENDER_ATTACHMENT.
362363
return (
@@ -391,9 +392,50 @@ g.test('texture_view_usage')
391392
}, !success);
392393
});
393394

395+
g.test('texture_view_usage_of_multiple_usages')
396+
.desc(
397+
`For a single format (rgba8unorm), check that createView:
398+
- allows 0 usages
399+
- disallows subsetting usages of TRANSIENT_ATTACHMENT textures
400+
`
401+
)
402+
.params(u =>
403+
u
404+
.combine('usage1', kTextureUsages)
405+
.combine('usage2', kTextureUsages)
406+
.filter(p => p.usage1 <= p.usage2)
407+
.filter(p => isValidTextureUsageCombination(p.usage1 | p.usage2))
408+
.beginSubcases()
409+
.expand('viewUsage', p => new Set([0, p.usage1, p.usage2, p.usage1 | p.usage2]))
410+
)
411+
.fn(t => {
412+
const { usage1, usage2, viewUsage } = t.params;
413+
const usage = usage1 | usage2;
414+
415+
// MAINTENANCE_TODO(#4509): Remove this after all implementations have TRANSIENT_ATTACHMENT.
416+
if ((usage & GPUConst.TextureUsage.TRANSIENT_ATTACHMENT) !== 0) {
417+
t.skipIfTransientAttachmentNotSupported();
418+
}
419+
420+
let isValid = true;
421+
if (usage & GPUTextureUsage.TRANSIENT_ATTACHMENT) {
422+
isValid &&= viewUsage === usage;
423+
}
424+
425+
const texture = t.createTextureTracked({ format: 'rgba8unorm', size: [1, 1], usage });
426+
t.expectGPUError(
427+
'validation',
428+
() => {
429+
texture.createView({ usage: viewUsage });
430+
},
431+
!isValid
432+
);
433+
});
434+
394435
g.test('texture_view_usage_with_view_format')
395436
.desc(
396-
`Test that the texture view usage must be supported by the view's format. Checks for every view format possible, and every usage supported by the texture's format`
437+
`Test that the texture view usage must be supported by the view's format. Checks for every view
438+
format possible, and every usage supported by the texture's format`
397439
)
398440
.params(u =>
399441
u

src/webgpu/api/validation/render_pass/resolve.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Test various validation behaviors when a resolveTarget is provided.
2020
- resolve source is not multisampled.
2121
- resolve target is not single sampled.
2222
- resolve target missing RENDER_ATTACHMENT usage.
23+
- resolve target has TRANSIENT_ATTACHMENT usage.
2324
- resolve target must have exactly one subresource:
2425
- base mip level {0, >0}, mip level count {1, >1}.
2526
- base array layer {0, >0}, array layer count {1, >1}.
@@ -35,12 +36,20 @@ Test various validation behaviors when a resolveTarget is provided.
3536
// control cases should be valid
3637
{ _valid: true },
3738
{ bindTextureResource: true, _valid: true },
39+
{ resolveTargetUsage: GPUConst.TextureUsage.RENDER_ATTACHMENT, _valid: true },
3840
// a single sampled resolve source should cause a validation error.
3941
{ colorAttachmentSamples: 1, _valid: false },
4042
// a multisampled resolve target should cause a validation error.
4143
{ resolveTargetSamples: 4, _valid: false },
4244
// resolveTargetUsage without RENDER_ATTACHMENT usage should cause a validation error.
4345
{ resolveTargetUsage: GPUConst.TextureUsage.COPY_SRC, _valid: false },
46+
// resolveTargetUsage with TRANSIENT_ATTACHMENT | RENDER_ATTACHMENT usage should cause a
47+
// validation error.
48+
{
49+
resolveTargetUsage:
50+
GPUConst.TextureUsage.RENDER_ATTACHMENT | GPUConst.TextureUsage.TRANSIENT_ATTACHMENT,
51+
_valid: false,
52+
},
4453
// non-zero resolve target base mip level should be valid.
4554
{
4655
resolveTargetViewBaseMipLevel: 1,
@@ -98,6 +107,11 @@ Test various validation behaviors when a resolveTarget is provided.
98107
_valid,
99108
} = t.params;
100109

110+
// MAINTENANCE_TODO(#4509): Remove this after all implementations have TRANSIENT_ATTACHMENT.
111+
if ((resolveTargetUsage & GPUConst.TextureUsage.TRANSIENT_ATTACHMENT) !== 0) {
112+
t.skipIfTransientAttachmentNotSupported();
113+
}
114+
101115
// Run the test in a nested loop such that the configured color attachment with resolve target
102116
// is tested while occupying each individual colorAttachment slot.
103117
for (let resolveSlot = 0; resolveSlot < kNumColorAttachments; resolveSlot++) {

0 commit comments

Comments
 (0)