Skip to content

Commit 46e9a89

Browse files
committed
Refactor api/operation/sampling
Issue #4181 Issue #4178
1 parent ffdf222 commit 46e9a89

File tree

3 files changed

+50
-72
lines changed

3 files changed

+50
-72
lines changed

src/webgpu/api/operation/sampling/filter_mode.spec.ts

+35-70
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
export const description = `
22
Tests the behavior of different filtering modes in minFilter/magFilter/mipmapFilter.
3+
4+
Note: It's possible these tests duplicated tests under shader/execution/expression/call/builtin/textureXXX.
5+
Further, these tests only test encodable/filterable/renderable color formats. Depth, sint, uint,
6+
and compressed formats are not tested.
37
`;
48

59
import { makeTestGroup } from '../../../../common/framework/test_group.js';
610
import { kAddressModes, kMipmapFilterModes } from '../../../capability_info.js';
711
import {
812
EncodableTextureFormat,
9-
kRenderableColorTextureFormats,
10-
kTextureFormatInfo,
13+
getTextureFormatType,
14+
kPossiblyRenderableColorTextureFormats,
1115
} from '../../../format_info.js';
12-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
16+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
1317
import { getTextureCopyLayout } from '../../../util/texture/layout.js';
1418
import { TexelView } from '../../../util/texture/texel_view.js';
1519

@@ -22,7 +26,18 @@ const kCheckerTextureData = [
2226
{ R: 1.0, G: 1.0, B: 1.0, A: 1.0 },
2327
];
2428

25-
class FilterModeTest extends TextureTestMixin(GPUTest) {
29+
/**
30+
* These formats are possibly renderable and possibly filterable.
31+
* One more both may required certain features to be enabled.
32+
*/
33+
const kPossiblyRenderablePossiblyFilterableColorTextureFormats =
34+
kPossiblyRenderableColorTextureFormats.filter(
35+
format =>
36+
getTextureFormatType(format) === 'float' ||
37+
getTextureFormatType(format) === 'unfilterable-float'
38+
);
39+
40+
class FilterModeTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
2641
runFilterRenderPipeline(
2742
sampler: GPUSampler,
2843
module: GPUShaderModule,
@@ -468,25 +483,15 @@ g.test('magFilter,nearest')
468483
)
469484
.params(u =>
470485
u
471-
.combine('format', kRenderableColorTextureFormats)
472-
.filter(t => {
473-
return (
474-
kTextureFormatInfo[t.format].color.type === 'float' ||
475-
kTextureFormatInfo[t.format].color.type === 'unfilterable-float'
476-
);
477-
})
486+
.combine('format', kPossiblyRenderablePossiblyFilterableColorTextureFormats)
478487
.beginSubcases()
479488
.combine('addressModeU', kAddressModes)
480489
.combine('addressModeV', kAddressModes)
481490
)
482-
.beforeAllSubcases(t => {
483-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
484-
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
485-
t.selectDeviceOrSkipTestCase('float32-filterable');
486-
}
487-
})
488491
.fn(t => {
489492
const { format, addressModeU, addressModeV } = t.params;
493+
t.skipIfTextureFormatNotSupported(format);
494+
t.skipIfTextureFormatNotFilterable(format);
490495
const sampler = t.device.createSampler({
491496
addressModeU,
492497
addressModeV,
@@ -591,25 +596,15 @@ g.test('magFilter,linear')
591596
)
592597
.params(u =>
593598
u
594-
.combine('format', kRenderableColorTextureFormats)
595-
.filter(t => {
596-
return (
597-
kTextureFormatInfo[t.format].color.type === 'float' ||
598-
kTextureFormatInfo[t.format].color.type === 'unfilterable-float'
599-
);
600-
})
599+
.combine('format', kPossiblyRenderablePossiblyFilterableColorTextureFormats)
601600
.beginSubcases()
602601
.combine('addressModeU', kAddressModes)
603602
.combine('addressModeV', kAddressModes)
604603
)
605-
.beforeAllSubcases(t => {
606-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
607-
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
608-
t.selectDeviceOrSkipTestCase('float32-filterable');
609-
}
610-
})
611604
.fn(t => {
612605
const { format, addressModeU, addressModeV } = t.params;
606+
t.skipIfTextureFormatNotSupported(format);
607+
t.skipIfTextureFormatNotFilterable(format);
613608
const sampler = t.device.createSampler({
614609
addressModeU,
615610
addressModeV,
@@ -726,25 +721,15 @@ g.test('minFilter,nearest')
726721
)
727722
.params(u =>
728723
u
729-
.combine('format', kRenderableColorTextureFormats)
730-
.filter(t => {
731-
return (
732-
kTextureFormatInfo[t.format].color.type === 'float' ||
733-
kTextureFormatInfo[t.format].color.type === 'unfilterable-float'
734-
);
735-
})
724+
.combine('format', kPossiblyRenderablePossiblyFilterableColorTextureFormats)
736725
.beginSubcases()
737726
.combine('addressModeU', kAddressModes)
738727
.combine('addressModeV', kAddressModes)
739728
)
740-
.beforeAllSubcases(t => {
741-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
742-
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
743-
t.selectDeviceOrSkipTestCase('float32-filterable');
744-
}
745-
})
746729
.fn(t => {
747730
const { format, addressModeU, addressModeV } = t.params;
731+
t.skipIfTextureFormatNotSupported(format);
732+
t.skipIfTextureFormatNotFilterable(format);
748733
const sampler = t.device.createSampler({
749734
addressModeU,
750735
addressModeV,
@@ -859,25 +844,15 @@ g.test('minFilter,linear')
859844
)
860845
.params(u =>
861846
u
862-
.combine('format', kRenderableColorTextureFormats)
863-
.filter(t => {
864-
return (
865-
kTextureFormatInfo[t.format].color.type === 'float' ||
866-
kTextureFormatInfo[t.format].color.type === 'unfilterable-float'
867-
);
868-
})
847+
.combine('format', kPossiblyRenderablePossiblyFilterableColorTextureFormats)
869848
.beginSubcases()
870849
.combine('addressModeU', kAddressModes)
871850
.combine('addressModeV', kAddressModes)
872851
)
873-
.beforeAllSubcases(t => {
874-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
875-
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
876-
t.selectDeviceOrSkipTestCase('float32-filterable');
877-
}
878-
})
879852
.fn(t => {
880853
const { format, addressModeU, addressModeV } = t.params;
854+
t.skipIfTextureFormatNotSupported(format);
855+
t.skipIfTextureFormatNotFilterable(format);
881856
const sampler = t.device.createSampler({
882857
addressModeU,
883858
addressModeV,
@@ -956,24 +931,14 @@ g.test('mipmapFilter')
956931
)
957932
.params(u =>
958933
u
959-
.combine('format', kRenderableColorTextureFormats)
960-
.filter(t => {
961-
return (
962-
kTextureFormatInfo[t.format].color.type === 'float' ||
963-
kTextureFormatInfo[t.format].color.type === 'unfilterable-float'
964-
);
965-
})
934+
.combine('format', kPossiblyRenderablePossiblyFilterableColorTextureFormats)
966935
.beginSubcases()
967936
.combine('filterMode', kMipmapFilterModes)
968937
)
969-
.beforeAllSubcases(t => {
970-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
971-
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
972-
t.selectDeviceOrSkipTestCase('float32-filterable');
973-
}
974-
})
975938
.fn(t => {
976939
const { format, filterMode } = t.params;
940+
t.skipIfTextureFormatNotSupported(format);
941+
t.skipIfTextureFormatNotFilterable(format);
977942
// Takes a 8x8/4x4 mipmapped texture and renders it on multiple quads with different UVs such
978943
// that each instanced quad from left to right emulates moving the quad further and further from
979944
// the camera. Each quad is then rendered to a single pixel in a 1-dimensional texture. Since
@@ -1126,7 +1091,7 @@ g.test('mipmapFilter')
11261091
}
11271092
if (changes !== 1) {
11281093
return Error(
1129-
`Nearest filtering on mipmaps should change exacly once but found (${changes}):\n` +
1094+
`Nearest filtering on mipmaps should change exactly once but found (${changes}):\n` +
11301095
view.toString(
11311096
{ x: 0, y: 0, z: 0 },
11321097
{ width: kRenderSize, height: 1, depthOrArrayLayers: 1 }

src/webgpu/api/operation/sampling/lod_clamp.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ TODO:
77
`;
88

99
import { makeTestGroup } from '../../../../common/framework/test_group.js';
10-
import { GPUTest } from '../../../gpu_test.js';
10+
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
1111

12-
export const g = makeTestGroup(GPUTest);
12+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

src/webgpu/gpu_test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,19 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
685685
}
686686
}
687687

688+
skipIfTextureFormatNotFilterable(...formats: (GPUTextureFormat | undefined)[]) {
689+
for (const format of formats) {
690+
if (format === undefined) continue;
691+
this.skipIf(isSintOrUintFormat(format), 'sint/uint formats are not filterable');
692+
if (is32Float(format)) {
693+
this.skipIf(
694+
!this.device.features.has('float32-filterable'),
695+
`texture format '${format}' is not filterable`
696+
);
697+
}
698+
}
699+
}
700+
688701
skipIfTextureFormatDoesNotSupportUsage(
689702
usage: GPUTextureUsageFlags,
690703
...formats: (GPUTextureFormat | undefined)[]

0 commit comments

Comments
 (0)