Skip to content

Allow GPUTexture where GPUTextureView is used #4407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/webgpu/api/validation/createBindGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,10 @@ g.test('texture,resource_state')
.combine('state', kResourceStates)
.combine('entry', sampledAndStorageBindingEntries(true, kTestFormat))
.combine('visibilityMask', [kAllShaderStages, GPUConst.ShaderStage.COMPUTE] as const)
.combine('bindTextureResource', [false, true] as const)
)
.fn(t => {
const { state, entry, visibilityMask } = t.params;
const { state, entry, visibilityMask, bindTextureResource } = t.params;
const info = texBindingTypeInfo(entry);

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

let textureView: GPUTextureView;
t.expectValidationError(() => {
textureView = texture.createView();
}, state === 'invalid');
let resource: GPUTexture | GPUTextureView;
if (bindTextureResource) {
resource = texture;
} else {
t.expectValidationError(() => {
resource = texture.createView();
}, state === 'invalid');
}

t.expectValidationError(() => {
t.device.createBindGroup({
layout: bgl,
entries: [
{
binding: 0,
resource: textureView,
},
],
entries: [{ binding: 0, resource }],
});
}, state === 'invalid');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ class F extends AllFeaturesMaxLimitsGPUTest {

getColorAttachment(
texture: GPUTexture,
textureViewDescriptor?: GPUTextureViewDescriptor
options: {
textureViewDescriptor?: GPUTextureViewDescriptor;
bindTextureResource?: boolean;
} = {}
): GPURenderPassColorAttachment {
const view = texture.createView(textureViewDescriptor);
const { textureViewDescriptor, bindTextureResource = false } = options;
const view = bindTextureResource ? texture : texture.createView(textureViewDescriptor);

return {
view,
Expand All @@ -74,9 +78,13 @@ class F extends AllFeaturesMaxLimitsGPUTest {

getDepthStencilAttachment(
texture: GPUTexture,
textureViewDescriptor?: GPUTextureViewDescriptor
options: {
textureViewDescriptor?: GPUTextureViewDescriptor;
bindTextureResource?: boolean;
} = {}
): GPURenderPassDepthStencilAttachment {
const view = texture.createView(textureViewDescriptor);
const { textureViewDescriptor, bindTextureResource = false } = options;
const view = bindTextureResource ? texture : texture.createView(textureViewDescriptor);

return {
view,
Expand Down Expand Up @@ -105,6 +113,7 @@ const kArrayLayerCount = 10;

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

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

const viewDescriptor: GPUTextureViewDescriptor = {
const textureViewDescriptor: GPUTextureViewDescriptor = {
baseMipLevel: mipLevel,
mipLevelCount: 1,
baseArrayLayer: 0,
arrayLayerCount: 1,
};

const colorAttachment = t.getColorAttachment(texture, viewDescriptor);
const colorAttachment = t.getColorAttachment(texture, { textureViewDescriptor });
colorAttachment.depthSlice = depthSlice;

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

const viewDescriptor: GPUTextureViewDescriptor = {
const textureViewDescriptor: GPUTextureViewDescriptor = {
baseMipLevel: 0,
mipLevelCount: 1,
baseArrayLayer: 0,
Expand All @@ -452,9 +462,9 @@ g.test('color_attachments,depthSlice,overlaps,diff_miplevel')
const colorAttachments = [];
for (let i = 0; i < mipLevelCount; i++) {
if (!sameMipLevel) {
viewDescriptor.baseMipLevel = i;
textureViewDescriptor.baseMipLevel = i;
}
const colorAttachment = t.getColorAttachment(texture, viewDescriptor);
const colorAttachment = t.getColorAttachment(texture, { textureViewDescriptor });
colorAttachment.depthSlice = 0;
colorAttachments.push(colorAttachment);
}
Expand Down Expand Up @@ -605,7 +615,7 @@ g.test('attachments,layer_count')
};

const descriptor: GPURenderPassDescriptor = {
colorAttachments: [t.getColorAttachment(colorTexture, textureViewDescriptor)],
colorAttachments: [t.getColorAttachment(colorTexture, { textureViewDescriptor })],
};

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

const descriptor: GPURenderPassDescriptor = {
colorAttachments: [],
depthStencilAttachment: t.getDepthStencilAttachment(
depthStencilTexture,
textureViewDescriptor
),
depthStencilAttachment: t.getDepthStencilAttachment(depthStencilTexture, {
textureViewDescriptor,
}),
};

t.tryRenderPass(_success, descriptor);
Expand Down Expand Up @@ -682,7 +691,7 @@ g.test('attachments,mip_level_count')
};

const descriptor: GPURenderPassDescriptor = {
colorAttachments: [t.getColorAttachment(colorTexture, textureViewDescriptor)],
colorAttachments: [t.getColorAttachment(colorTexture, { textureViewDescriptor })],
};

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

const descriptor: GPURenderPassDescriptor = {
colorAttachments: [],
depthStencilAttachment: t.getDepthStencilAttachment(
depthStencilTexture,
textureViewDescriptor
),
depthStencilAttachment: t.getDepthStencilAttachment(depthStencilTexture, {
textureViewDescriptor,
}),
};

t.tryRenderPass(_success, descriptor);
Expand Down
6 changes: 5 additions & 1 deletion src/webgpu/api/validation/render_pass/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ Test various validation behaviors when a resolveTarget is provided.
`
)
.paramsSimple([
// control case should be valid
// control cases should be valid
{ _valid: true },
{ bindTextureResource: true, _valid: true },
// a single sampled resolve source should cause a validation error.
{ colorAttachmentSamples: 1, _valid: false },
// a multisampled resolve target should cause a validation error.
Expand Down Expand Up @@ -78,6 +79,7 @@ Test various validation behaviors when a resolveTarget is provided.
] as const)
.fn(t => {
const {
bindTextureResource = false,
colorAttachmentFormat = 'rgba8unorm',
resolveTargetFormat = 'rgba8unorm',
otherAttachmentFormat = 'rgba8unorm',
Expand Down Expand Up @@ -139,6 +141,8 @@ Test various validation behaviors when a resolveTarget is provided.
storeOp: 'discard',
resolveTarget: resolveTargetInvalid
? vtu.getErrorTextureView(t)
: bindTextureResource
? resolveTarget
: resolveTarget.createView({
dimension: resolveTargetViewArrayLayerCount === 1 ? '2d' : '2d-array',
mipLevelCount: resolveTargetViewMipCount,
Expand Down
Loading