Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
isDepthTextureFormat,
getBlockInfoForTextureFormat,
isStencilTextureFormat,
isDepthStencilTextureFormat,
isDepthAndStencilTextureFormat,
isTextureFormatPossiblyMultisampled,
isTextureFormatUsableAsRenderAttachment,
} from '../../../format_info.js';
Expand Down Expand Up @@ -312,7 +312,7 @@ g.test('read_swizzle')
};
const { texels: srcTexelViews, texture } =
await createTextureWithRandomDataAndGetTexelsForEachAspect(t, descriptor);
const aspectNdx = isDepthStencilTextureFormat(format) && aspect === 'stencil-only' ? 1 : 0;
const aspectNdx = isDepthAndStencilTextureFormat(format) && aspect === 'stencil-only' ? 1 : 0;
const srcTexelView = srcTexelViews[aspectNdx];

const samples = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
isTextureFormatColorRenderable,
isDepthTextureFormat,
isStencilTextureFormat,
isDepthAndStencilTextureFormat,
isDepthOrStencilTextureFormat,
isTextureFormatResolvable,
} from '../../../format_info.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
Expand Down Expand Up @@ -183,6 +185,40 @@ g.test('color_attachments,empty')
});
});

g.test('color_attachments,depth_stencil_format')
.desc(
`
Test that texture views of depth and/or stencil format are invalid as color attachments in render passes:
- One control (color) case and all error (depth-and/or-stencil) cases.
`
)
.params(u =>
u
.combine('format', ['rgba8unorm', ...kDepthStencilFormats] as const)
.beginSubcases()
.expand('aspect', p =>
isDepthAndStencilTextureFormat(p.format)
? (['all', 'depth-only', 'stencil-only'] as const)
: (['all'] as const)
)
)
.fn(t => {
const { format, aspect } = t.params;
t.skipIfTextureFormatNotSupported(format);

const texture = t.createTestTexture({ format });
const descriptor: GPURenderPassDescriptor = {
colorAttachments: [
t.getColorAttachment(texture, {
textureViewDescriptor: { aspect },
}),
],
};

const isValid = isTextureFormatColorRenderable(t.device.features, format);
t.tryRenderPass(isValid, descriptor);
});

g.test('color_attachments,limits,maxColorAttachments')
.desc(
`
Expand Down Expand Up @@ -541,31 +577,6 @@ g.test('attachments,same_size')
}
});

g.test('attachments,color_depth_mismatch')
.desc(`Test that attachments match whether they are used for color or depth stencil.`)
.fn(t => {
const colorTexture = t.createTestTexture({ format: 'rgba8unorm' });
const depthStencilTexture = t.createTestTexture({ format: 'depth24plus-stencil8' });

{
// Using depth-stencil for color
const descriptor: GPURenderPassDescriptor = {
colorAttachments: [t.getColorAttachment(depthStencilTexture)],
};

t.tryRenderPass(false, descriptor);
}
{
// Using color for depth-stencil
const descriptor: GPURenderPassDescriptor = {
colorAttachments: [],
depthStencilAttachment: t.getDepthStencilAttachment(colorTexture),
};

t.tryRenderPass(false, descriptor);
}
});

g.test('attachments,layer_count')
.desc(
`
Expand Down Expand Up @@ -1023,6 +1034,44 @@ g.test('resolveTarget,different_size')
}
});

g.test('depth_stencil_attachment,color_format')
.desc(
`
Test that texture views of color formats are invalid as depth stencil attachments in render passes:
- One control (depth) case and a selection of error (color) cases.
`
)
.params(u =>
u
.combine('format', [
'depth24plus-stencil8',
'r8uint',
'r8unorm',
'rgba16float',
'rgba8unorm',
] as const)
.beginSubcases()
.expand('aspect', p =>
isDepthAndStencilTextureFormat(p.format)
? (['all', 'depth-only', 'stencil-only'] as const)
: (['all'] as const)
)
)
.fn(t => {
const { format } = t.params;
t.skipIfTextureFormatNotSupported(format);
t.skipIfTextureFormatNotUsableAsRenderAttachment(format);

const texture = t.createTestTexture({ format });
const descriptor: GPURenderPassDescriptor = {
colorAttachments: [],
depthStencilAttachment: t.getDepthStencilAttachment(texture),
};

const isValid = isDepthOrStencilTextureFormat(format);
t.tryRenderPass(isValid, descriptor);
});

g.test('depth_stencil_attachment,sample_counts_mismatch')
.desc(
`
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ export function isStencilTextureFormat(format: GPUTextureFormat) {
return !!kTextureFormatInfo[format].stencil;
}

export function isDepthStencilTextureFormat(format: GPUTextureFormat) {
export function isDepthAndStencilTextureFormat(format: GPUTextureFormat) {
return isDepthTextureFormat(format) && isStencilTextureFormat(format);
}

Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/util/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert, unreachable } from '../../common/util/util.js';
import {
getBlockInfoForTextureFormat,
isDepthOrStencilTextureFormat,
isDepthStencilTextureFormat,
isDepthAndStencilTextureFormat,
isDepthTextureFormat,
isSintOrUintFormat,
isStencilTextureFormat,
Expand Down Expand Up @@ -752,7 +752,7 @@ export function createTextureFromTexelViews(
// Note: At the time of this writing there is no such thing as a depth-stencil TexelView
// so we couldn't have passed in data for "all" aspects. This seems like a code smell issue
// but it's a big change to fix.
const aspect = isDepthStencilTextureFormat(textureFormat)
const aspect = isDepthAndStencilTextureFormat(textureFormat)
? isSintOrUintFormat(viewsFormat)
? 'stencil-only'
: 'depth-only'
Expand Down
Loading