Skip to content

Commit 38dd024

Browse files
committed
Test multisampled textures
1 parent a5dd68c commit 38dd024

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

src/webgpu/api/operation/texture_view/texture_component_swizzle.spec.ts

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
getBlockInfoForTextureFormat,
1616
isStencilTextureFormat,
1717
isDepthStencilTextureFormat,
18+
isTextureFormatPossiblyMultisampled,
19+
isTextureFormatUsableAsRenderAttachment,
1820
} from '../../../format_info.js';
1921
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
2022
import {
@@ -56,10 +58,27 @@ function altResultForSwizzle(component: GPUComponentSwizzle): number {
5658
}
5759
}
5860

59-
type TextureInput = 'texture_2d<f32>' | 'texture_2d<u32>' | 'texture_2d<i32>' | 'texture_depth_2d';
61+
type TextureInput =
62+
| 'texture_2d<f32>'
63+
| 'texture_2d<u32>'
64+
| 'texture_2d<i32>'
65+
| 'texture_depth_2d'
66+
| 'texture_multisampled_2d<f32>'
67+
| 'texture_multisampled_2d<u32>'
68+
| 'texture_multisampled_2d<i32>'
69+
| 'texture_depth_multisampled_2d';
6070

6171
function isSingleChannelInput(input: TextureInput) {
62-
return input === 'texture_depth_2d';
72+
return input === 'texture_depth_2d' || input === 'texture_depth_multisampled_2d';
73+
}
74+
75+
function isMultisampledInput(input: TextureInput) {
76+
return (
77+
input === 'texture_multisampled_2d<f32>' ||
78+
input === 'texture_multisampled_2d<u32>' ||
79+
input === 'texture_multisampled_2d<i32>' ||
80+
input === 'texture_depth_multisampled_2d'
81+
);
6382
}
6483

6584
// This returns a validMask vec4u for if a channel is valid (1) or not-valid (0)
@@ -298,6 +317,29 @@ g.test('read_swizzle')
298317
) {
299318
yield `texture_depth_2d`;
300319
}
320+
if (t.func === 'textureLoad' && isTextureFormatPossiblyMultisampled(t.format)) {
321+
const { componentType } = getTextureFormatTypeInfo(t.format, t.aspect);
322+
switch (componentType) {
323+
case 'f32':
324+
yield `texture_multisampled_2d<f32>`;
325+
break;
326+
case 'u32':
327+
yield `texture_multisampled_2d<u32>`;
328+
break;
329+
case 'i32':
330+
yield `texture_multisampled_2d<i32>`;
331+
break;
332+
default:
333+
unreachable();
334+
}
335+
if (
336+
isDepthTextureFormat(t.format) &&
337+
canBuiltinTakeTextureDepth(t.func) &&
338+
t.aspect === 'depth-only'
339+
) {
340+
yield `texture_depth_multisampled_2d`;
341+
}
342+
}
301343
})
302344
.expand('channel', function* (t) {
303345
if (t.func === 'textureGather' && !isSingleChannelInput(t.input)) {
@@ -333,6 +375,9 @@ g.test('read_swizzle')
333375
if (func === 'textureLoad') {
334376
t.skipIfTextureLoadNotSupportedForTextureType(input);
335377
}
378+
if (isMultisampledInput(input)) {
379+
t.skipIfTextureFormatNotMultisampled(format);
380+
}
336381
const otherSwizzleSpec = getSwizzleSpecByOffsetFromSwizzleSpec(
337382
swizzleSpec,
338383
otherSwizzleIndexOffset
@@ -362,7 +407,13 @@ g.test('read_swizzle')
362407
const descriptor: GPUTextureDescriptor = {
363408
format,
364409
size,
365-
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
410+
usage:
411+
GPUTextureUsage.COPY_DST |
412+
GPUTextureUsage.TEXTURE_BINDING |
413+
(isTextureFormatUsableAsRenderAttachment(t.device, format)
414+
? GPUTextureUsage.RENDER_ATTACHMENT
415+
: 0),
416+
sampleCount: isMultisampledInput(input) ? 4 : 1,
366417
};
367418
const { texels: srcTexelViews, texture } =
368419
await createTextureWithRandomDataAndGetTexelsForEachAspect(t, descriptor);
@@ -419,7 +470,11 @@ ${sampledColors.map((c, i) => `${i % 2}, ${(i / 2) | 0}, ${JSON.stringify(c)}`).
419470
}
420471
: expRGBAColor;
421472
const expTexelView = TexelView.fromTexelsAsColors(expFormat, _coords => expColor);
422-
const textureView = texture.createView({ swizzle, aspect });
473+
const textureView = texture.createView({
474+
swizzle,
475+
aspect,
476+
usage: GPUTextureUsage.TEXTURE_BINDING,
477+
});
423478

424479
// BA in a 2x2 texel area this is
425480
// RG the order of gather.
@@ -533,6 +588,8 @@ ${testData
533588
? isBuiltinComparison(func)
534589
? 'depth'
535590
: 'unfilterable-float'
591+
: srcSampleType === 'float' && isMultisampledInput(input)
592+
? 'unfilterable-float'
536593
: srcSampleType;
537594
const samplerType = isBuiltinComparison(func) ? 'comparison' : 'non-filtering';
538595

@@ -550,6 +607,7 @@ ${testData
550607
visibility: GPUShaderStage.COMPUTE | GPUShaderStage.FRAGMENT | GPUShaderStage.VERTEX,
551608
texture: {
552609
sampleType,
610+
multisampled: isMultisampledInput(input),
553611
},
554612
},
555613
{
@@ -581,6 +639,7 @@ ${testData
581639
visibility: GPUShaderStage.COMPUTE | GPUShaderStage.FRAGMENT | GPUShaderStage.VERTEX,
582640
texture: {
583641
sampleType,
642+
multisampled: isMultisampledInput(input),
584643
},
585644
},
586645
],

0 commit comments

Comments
 (0)