Skip to content

Commit 7d143a9

Browse files
Allow GPUTexture where GPUTextureView is used (#4407)
* Allow GPUTexture where GPUTextureView is used * Fix nit * Update webgpu types
1 parent a691430 commit 7d143a9

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
lines changed

package-lock.json

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/w3c-image-capture": "^1.0.10",
5151
"@typescript-eslint/eslint-plugin": "^6.9.1",
5252
"@typescript-eslint/parser": "^6.9.1",
53-
"@webgpu/types": "^0.1.63",
53+
"@webgpu/types": "^0.1.64",
5454
"ansi-colors": "4.1.3",
5555
"babel-plugin-add-header-comment": "^1.0.3",
5656
"babel-plugin-const-enum": "^1.2.0",

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,10 @@ g.test('texture,resource_state')
610610
.combine('state', kResourceStates)
611611
.combine('entry', sampledAndStorageBindingEntries(true, kTestFormat))
612612
.combine('visibilityMask', [kAllShaderStages, GPUConst.ShaderStage.COMPUTE] as const)
613+
.combine('bindTextureResource', [false, true] as const)
613614
)
614615
.fn(t => {
615-
const { state, entry, visibilityMask } = t.params;
616+
const { state, entry, visibilityMask, bindTextureResource } = t.params;
616617
const info = texBindingTypeInfo(entry);
617618

618619
const visibility = info.validStages & visibilityMask;
@@ -640,20 +641,19 @@ g.test('texture,resource_state')
640641
sampleCount: entry.texture?.multisampled ? 4 : 1,
641642
});
642643

643-
let textureView: GPUTextureView;
644-
t.expectValidationError(() => {
645-
textureView = texture.createView();
646-
}, state === 'invalid');
644+
let resource: GPUTexture | GPUTextureView;
645+
if (bindTextureResource) {
646+
resource = texture;
647+
} else {
648+
t.expectValidationError(() => {
649+
resource = texture.createView();
650+
}, state === 'invalid');
651+
}
647652

648653
t.expectValidationError(() => {
649654
t.device.createBindGroup({
650655
layout: bgl,
651-
entries: [
652-
{
653-
binding: 0,
654-
resource: textureView,
655-
},
656-
],
656+
entries: [{ binding: 0, resource }],
657657
});
658658
}, state === 'invalid');
659659
});

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ class F extends AllFeaturesMaxLimitsGPUTest {
6060

6161
getColorAttachment(
6262
texture: GPUTexture,
63-
textureViewDescriptor?: GPUTextureViewDescriptor
63+
options: {
64+
textureViewDescriptor?: GPUTextureViewDescriptor;
65+
bindTextureResource?: boolean;
66+
} = {}
6467
): GPURenderPassColorAttachment {
65-
const view = texture.createView(textureViewDescriptor);
68+
const { textureViewDescriptor, bindTextureResource = false } = options;
69+
const view = bindTextureResource ? texture : texture.createView(textureViewDescriptor);
6670

6771
return {
6872
view,
@@ -74,9 +78,13 @@ class F extends AllFeaturesMaxLimitsGPUTest {
7478

7579
getDepthStencilAttachment(
7680
texture: GPUTexture,
77-
textureViewDescriptor?: GPUTextureViewDescriptor
81+
options: {
82+
textureViewDescriptor?: GPUTextureViewDescriptor;
83+
bindTextureResource?: boolean;
84+
} = {}
7885
): GPURenderPassDepthStencilAttachment {
79-
const view = texture.createView(textureViewDescriptor);
86+
const { textureViewDescriptor, bindTextureResource = false } = options;
87+
const view = bindTextureResource ? texture : texture.createView(textureViewDescriptor);
8088

8189
return {
8290
view,
@@ -105,6 +113,7 @@ const kArrayLayerCount = 10;
105113

106114
g.test('attachments,one_color_attachment')
107115
.desc(`Test that a render pass works with only one color attachment.`)
116+
.paramsSubcasesOnly(u => u.combine('bindTextureResource', [false, true] as const))
108117
.fn(t => {
109118
const colorTexture = t.createTestTexture({ format: 'rgba8unorm' });
110119
const descriptor = {
@@ -116,6 +125,7 @@ g.test('attachments,one_color_attachment')
116125

117126
g.test('attachments,one_depth_stencil_attachment')
118127
.desc(`Test that a render pass works with only one depthStencil attachment.`)
128+
.paramsSubcasesOnly(u => u.combine('bindTextureResource', [false, true] as const))
119129
.fn(t => {
120130
const depthStencilTexture = t.createTestTexture({ format: 'depth24plus-stencil8' });
121131
const descriptor = {
@@ -350,14 +360,14 @@ g.test('color_attachments,depthSlice,bound_check')
350360
mipLevelCount: mipLevel + 1,
351361
});
352362

353-
const viewDescriptor: GPUTextureViewDescriptor = {
363+
const textureViewDescriptor: GPUTextureViewDescriptor = {
354364
baseMipLevel: mipLevel,
355365
mipLevelCount: 1,
356366
baseArrayLayer: 0,
357367
arrayLayerCount: 1,
358368
};
359369

360-
const colorAttachment = t.getColorAttachment(texture, viewDescriptor);
370+
const colorAttachment = t.getColorAttachment(texture, { textureViewDescriptor });
361371
colorAttachment.depthSlice = depthSlice;
362372

363373
const passDescriptor: GPURenderPassDescriptor = {
@@ -442,7 +452,7 @@ g.test('color_attachments,depthSlice,overlaps,diff_miplevel')
442452
};
443453
const texture = t.createTestTexture(texDescriptor);
444454

445-
const viewDescriptor: GPUTextureViewDescriptor = {
455+
const textureViewDescriptor: GPUTextureViewDescriptor = {
446456
baseMipLevel: 0,
447457
mipLevelCount: 1,
448458
baseArrayLayer: 0,
@@ -452,9 +462,9 @@ g.test('color_attachments,depthSlice,overlaps,diff_miplevel')
452462
const colorAttachments = [];
453463
for (let i = 0; i < mipLevelCount; i++) {
454464
if (!sameMipLevel) {
455-
viewDescriptor.baseMipLevel = i;
465+
textureViewDescriptor.baseMipLevel = i;
456466
}
457-
const colorAttachment = t.getColorAttachment(texture, viewDescriptor);
467+
const colorAttachment = t.getColorAttachment(texture, { textureViewDescriptor });
458468
colorAttachment.depthSlice = 0;
459469
colorAttachments.push(colorAttachment);
460470
}
@@ -605,7 +615,7 @@ g.test('attachments,layer_count')
605615
};
606616

607617
const descriptor: GPURenderPassDescriptor = {
608-
colorAttachments: [t.getColorAttachment(colorTexture, textureViewDescriptor)],
618+
colorAttachments: [t.getColorAttachment(colorTexture, { textureViewDescriptor })],
609619
};
610620

611621
t.tryRenderPass(_success, descriptor);
@@ -619,10 +629,9 @@ g.test('attachments,layer_count')
619629

620630
const descriptor: GPURenderPassDescriptor = {
621631
colorAttachments: [],
622-
depthStencilAttachment: t.getDepthStencilAttachment(
623-
depthStencilTexture,
624-
textureViewDescriptor
625-
),
632+
depthStencilAttachment: t.getDepthStencilAttachment(depthStencilTexture, {
633+
textureViewDescriptor,
634+
}),
626635
};
627636

628637
t.tryRenderPass(_success, descriptor);
@@ -682,7 +691,7 @@ g.test('attachments,mip_level_count')
682691
};
683692

684693
const descriptor: GPURenderPassDescriptor = {
685-
colorAttachments: [t.getColorAttachment(colorTexture, textureViewDescriptor)],
694+
colorAttachments: [t.getColorAttachment(colorTexture, { textureViewDescriptor })],
686695
};
687696

688697
t.tryRenderPass(_success, descriptor);
@@ -696,10 +705,9 @@ g.test('attachments,mip_level_count')
696705

697706
const descriptor: GPURenderPassDescriptor = {
698707
colorAttachments: [],
699-
depthStencilAttachment: t.getDepthStencilAttachment(
700-
depthStencilTexture,
701-
textureViewDescriptor
702-
),
708+
depthStencilAttachment: t.getDepthStencilAttachment(depthStencilTexture, {
709+
textureViewDescriptor,
710+
}),
703711
};
704712

705713
t.tryRenderPass(_success, descriptor);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ Test various validation behaviors when a resolveTarget is provided.
3232
`
3333
)
3434
.paramsSimple([
35-
// control case should be valid
35+
// control cases should be valid
3636
{ _valid: true },
37+
{ bindTextureResource: true, _valid: true },
3738
// a single sampled resolve source should cause a validation error.
3839
{ colorAttachmentSamples: 1, _valid: false },
3940
// a multisampled resolve target should cause a validation error.
@@ -78,6 +79,7 @@ Test various validation behaviors when a resolveTarget is provided.
7879
] as const)
7980
.fn(t => {
8081
const {
82+
bindTextureResource = false,
8183
colorAttachmentFormat = 'rgba8unorm',
8284
resolveTargetFormat = 'rgba8unorm',
8385
otherAttachmentFormat = 'rgba8unorm',
@@ -139,6 +141,8 @@ Test various validation behaviors when a resolveTarget is provided.
139141
storeOp: 'discard',
140142
resolveTarget: resolveTargetInvalid
141143
? vtu.getErrorTextureView(t)
144+
: bindTextureResource
145+
? resolveTarget
142146
: resolveTarget.createView({
143147
dimension: resolveTargetViewArrayLayerCount === 1 ? '2d' : '2d-array',
144148
mipLevelCount: resolveTargetViewMipCount,

0 commit comments

Comments
 (0)