Skip to content

Commit d28a5ac

Browse files
committed
Refactor api/operation/render_pipeline for texture formats
Issue gpuweb#4181 Issue gpuweb#4178
1 parent 5e33111 commit d28a5ac

8 files changed

+62
-47
lines changed

src/webgpu/api/operation/render_pipeline/culling_tests.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Test all culling combinations of GPUFrontFace and GPUCullMode show the correct o
55
`;
66

77
import { makeTestGroup } from '../../../../common/framework/test_group.js';
8-
import { kTextureFormatInfo, SizedTextureFormat } from '../../../format_info.js';
9-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
8+
import { isStencilTextureFormat, SizedTextureFormat } from '../../../format_info.js';
9+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
1010

1111
function faceIsCulled(face: 'cw' | 'ccw', frontFace: GPUFrontFace, cullMode: GPUCullMode): boolean {
1212
return cullMode !== 'none' && (frontFace === face) === (cullMode === 'front');
@@ -24,7 +24,7 @@ function faceColor(face: 'cw' | 'ccw', frontFace: GPUFrontFace, cullMode: GPUCul
2424
}
2525
}
2626

27-
class CullingTest extends TextureTestMixin(GPUTest) {
27+
class CullingTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
2828
checkCornerPixels(
2929
texture: GPUTexture,
3030
expectedTopLeftColor: Uint8Array,
@@ -146,7 +146,7 @@ g.test('culling')
146146
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
147147
});
148148

149-
const haveStencil = depthStencilFormat && kTextureFormatInfo[depthStencilFormat].stencil;
149+
const haveStencil = depthStencilFormat && isStencilTextureFormat(depthStencilFormat);
150150
let depthTexture: GPUTexture | undefined = undefined;
151151
let depthStencilAttachment: GPURenderPassDepthStencilAttachment | undefined = undefined;
152152
let depthStencil: GPUDepthStencilState | undefined = undefined;

src/webgpu/api/operation/render_pipeline/overrides.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Testing render pipeline using overridable constants in vertex stage and fragment
33
`;
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
77
import { PerTexelComponent } from '../../../util/texture/texel_data.js';
88

9-
class F extends GPUTest {
9+
class F extends AllFeaturesMaxLimitsGPUTest {
1010
async ExpectShaderOutputWithConstants(
1111
isAsync: boolean,
1212
format: GPUTextureFormat,

src/webgpu/api/operation/render_pipeline/pipeline_output_targets.spec.ts

+24-31
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { range } from '../../../../common/util/util.js';
77
import {
88
computeBytesPerSampleFromFormats,
9-
kRenderableColorTextureFormats,
10-
kTextureFormatInfo,
9+
getColorRenderByteCost,
10+
getTextureFormatType,
11+
isSintOrUintFormat,
12+
kPossibleColorRenderableTextureFormats,
1113
} from '../../../format_info.js';
12-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
14+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
1315
import { getFragmentShaderCodeWithOutput, getPlainTypeInfo } from '../../../util/shader.js';
1416
import { kTexelRepresentationInfo } from '../../../util/texture/texel_data.js';
1517

@@ -25,7 +27,7 @@ const kVertexShader = `
2527
}
2628
`;
2729

28-
export const g = makeTestGroup(TextureTestMixin(GPUTest));
30+
export const g = makeTestGroup(TextureTestMixin(AllFeaturesMaxLimitsGPUTest));
2931

3032
// Values to write into each attachment
3133
// We make values different for each attachment index and each channel
@@ -50,33 +52,30 @@ g.test('color,attachments')
5052
.desc(`Test that pipeline with sparse color attachments write values correctly.`)
5153
.params(u =>
5254
u
53-
.combine('format', kRenderableColorTextureFormats)
55+
.combine('format', kPossibleColorRenderableTextureFormats)
5456
.beginSubcases()
5557
.combine('attachmentCount', [2, 3, 4])
5658
.expand('emptyAttachmentId', p => range(p.attachmentCount, i => i))
5759
)
58-
.beforeAllSubcases(t => {
59-
const info = kTextureFormatInfo[t.params.format];
60-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
61-
t.selectDeviceOrSkipTestCase(info.feature);
62-
})
6360
.fn(t => {
6461
const { format, attachmentCount, emptyAttachmentId } = t.params;
62+
63+
t.skipIfTextureFormatNotSupported(format);
64+
t.skipIfTextureFormatNotUsableAsRenderAttachment(format);
65+
6566
const componentCount = kTexelRepresentationInfo[format].componentOrder.length;
66-
const info = kTextureFormatInfo[format];
6767

6868
// We only need to test formats that have a valid color attachment bytes per sample.
69-
const pixelByteCost = kTextureFormatInfo[format].colorRender?.byteCost;
69+
const pixelByteCost = getColorRenderByteCost(format);
7070
t.skipIf(
7171
pixelByteCost === undefined ||
7272
computeBytesPerSampleFromFormats(range(attachmentCount, () => format)) >
7373
t.device.limits.maxColorAttachmentBytesPerSample
7474
);
7575

76-
const writeValues =
77-
info.color.type === 'sint' || info.color.type === 'uint'
78-
? attachmentsIntWriteValues
79-
: attachmentsFloatWriteValues;
76+
const writeValues = isSintOrUintFormat(format)
77+
? attachmentsIntWriteValues
78+
: attachmentsFloatWriteValues;
8079

8180
const renderTargets = range(attachmentCount, () =>
8281
t.createTextureTracked({
@@ -106,7 +105,7 @@ g.test('color,attachments')
106105
writeValues[i].B,
107106
writeValues[i].A,
108107
],
109-
plainType: getPlainTypeInfo(info.color.type),
108+
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
110109
componentCount,
111110
}
112111
)
@@ -152,19 +151,15 @@ g.test('color,component_count')
152151
)
153152
.params(u =>
154153
u
155-
.combine('format', kRenderableColorTextureFormats)
154+
.combine('format', kPossibleColorRenderableTextureFormats)
156155
.beginSubcases()
157156
.combine('componentCount', [1, 2, 3, 4])
158157
.filter(x => x.componentCount >= kTexelRepresentationInfo[x.format].componentOrder.length)
159158
)
160-
.beforeAllSubcases(t => {
161-
const info = kTextureFormatInfo[t.params.format];
162-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
163-
t.selectDeviceOrSkipTestCase(info.feature);
164-
})
165159
.fn(t => {
166160
const { format, componentCount } = t.params;
167-
const info = kTextureFormatInfo[format];
161+
t.skipIfTextureFormatNotSupported(format);
162+
t.skipIfTextureFormatNotUsableAsRenderAttachment(format);
168163

169164
// expected RGBA values
170165
// extra channels are discarded
@@ -189,7 +184,7 @@ g.test('color,component_count')
189184
code: getFragmentShaderCodeWithOutput([
190185
{
191186
values,
192-
plainType: getPlainTypeInfo(info.color.type),
187+
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
193188
componentCount,
194189
},
195190
]),
@@ -364,10 +359,6 @@ The attachment has a load value of [1, 0, 0, 1]
364359
] as const)
365360
.filter(x => x.output.length >= kTexelRepresentationInfo[x.format].componentOrder.length)
366361
)
367-
.beforeAllSubcases(t => {
368-
const info = kTextureFormatInfo[t.params.format];
369-
t.selectDeviceOrSkipTestCase(info.feature);
370-
})
371362
.fn(t => {
372363
const {
373364
format,
@@ -378,8 +369,10 @@ The attachment has a load value of [1, 0, 0, 1]
378369
alphaSrcFactor,
379370
alphaDstFactor,
380371
} = t.params;
372+
t.skipIfTextureFormatNotSupported(format);
373+
t.skipIfTextureFormatNotBlendable(format);
374+
381375
const componentCount = output.length;
382-
const info = kTextureFormatInfo[format];
383376

384377
const renderTarget = t.createTextureTracked({
385378
format,
@@ -400,7 +393,7 @@ The attachment has a load value of [1, 0, 0, 1]
400393
code: getFragmentShaderCodeWithOutput([
401394
{
402395
values: output,
403-
plainType: getPlainTypeInfo(info.color.type),
396+
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
404397
componentCount,
405398
},
406399
]),

src/webgpu/api/operation/render_pipeline/primitive_topology.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Test locations are framebuffer coordinates:
5656
`;
5757

5858
import { makeTestGroup } from '../../../../common/framework/test_group.js';
59-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
59+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
6060
import { PerPixelComparison } from '../../../util/texture/texture_ok.js';
6161

6262
const kRTSize: number = 56;
@@ -279,7 +279,7 @@ function generateVertexBuffer(vertexLocations: Point2D[]): Float32Array {
279279
}
280280

281281
const kDefaultDrawCount = 6;
282-
class PrimitiveTopologyTest extends TextureTestMixin(GPUTest) {
282+
class PrimitiveTopologyTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
283283
makeAttachmentTexture(): GPUTexture {
284284
return this.createTextureTracked({
285285
format: kColorFormat,

src/webgpu/api/operation/render_pipeline/sample_mask.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Details could be found at: https://github.com/gpuweb/cts/issues/2201
1919

2020
import { makeTestGroup } from '../../../../common/framework/test_group.js';
2121
import { assert, range } from '../../../../common/util/util.js';
22-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
22+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
2323
import { checkElementsPassPredicate, checkElementsEqual } from '../../../util/check_contents.js';
2424
import { Type } from '../../../util/conversion.js';
2525
import { TexelView } from '../../../util/texture/texel_view.js';
@@ -263,7 +263,7 @@ struct FragmentOutput2 {
263263
}
264264
`;
265265

266-
class F extends TextureTestMixin(GPUTest) {
266+
class F extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
267267
private sampleTexture: GPUTexture | undefined;
268268
private sampler: GPUSampler | undefined;
269269

src/webgpu/api/operation/render_pipeline/vertex_only_render_pipeline.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Test vertex-only render pipeline.
33
`;
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
77

8-
class F extends GPUTest {}
8+
class F extends AllFeaturesMaxLimitsGPUTest {}
99

1010
export const g = makeTestGroup(F);
1111

src/webgpu/format_info.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1565,28 +1565,29 @@ export const kStencilTextureFormats = kDepthStencilFormats.filter(
15651565
// Texture formats that may possibly be used as a storage texture.
15661566
// Some may require certain features to be enabled.
15671567
export const kPossibleStorageTextureFormats = [
1568-
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].color?.storage),
1568+
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].color?.storage),
15691569
'bgra8unorm',
15701570
] as const;
15711571

15721572
// Texture formats that may possibly be multisampled.
15731573
// Some may require certain features to be enabled.
15741574
export const kPossibleMultisampledTextureFormats = [
1575-
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
1575+
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
1576+
...kDepthStencilFormats.filter(f => kTextureFormatInfo[f].multisample),
15761577
'rg11b10ufloat',
15771578
] as const;
15781579

15791580
// Texture formats that may possibly be color renderable.
15801581
// Some may require certain features to be enabled.
15811582
export const kPossibleColorRenderableTextureFormats = [
1582-
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].colorRender),
1583+
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].colorRender),
15831584
'rg11b10ufloat',
15841585
] as const;
15851586
export type PossibleColorRenderTextureFormat =
15861587
(typeof kPossibleColorRenderableTextureFormats)[number];
15871588

15881589
// Texture formats that have a different base format. This is effectively all -srgb formats.
1589-
export const kDifferentBaseFormatTextureFormats = kAllTextureFormats.filter(
1590+
export const kDifferentBaseFormatTextureFormats = kColorTextureFormats.filter(
15901591
f => kTextureFormatInfo[f].baseFormat && kTextureFormatInfo[f].baseFormat !== f
15911592
);
15921593

@@ -1933,6 +1934,14 @@ export function isTextureFormatUsableAsRenderAttachment(
19331934
return kTextureFormatInfo[format].colorRender || isDepthOrStencilTextureFormat(format);
19341935
}
19351936

1937+
/**
1938+
* Returns the texture's type (float, unsigned-float, sint, uint, depth)
1939+
*/
1940+
export function getTextureFormatType(format: GPUTextureFormat) {
1941+
const info = kTextureFormatInfo[format];
1942+
return info.color?.type ?? info.depth?.type ?? info.stencil?.type;
1943+
}
1944+
19361945
/**
19371946
* Returns if a texture can be used as a "colorAttachment".
19381947
*/

src/webgpu/gpu_test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
isTextureFormatUsableAsStorageFormat,
3838
isTextureFormatUsableAsRenderAttachment,
3939
isTextureFormatMultisampled,
40+
is32Float,
4041
} from './format_info.js';
4142
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
4243
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
@@ -669,6 +670,18 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
669670
}
670671
}
671672

673+
skipIfTextureFormatNotBlendable(...formats: (GPUTextureFormat | undefined)[]) {
674+
for (const format of formats) {
675+
if (format === undefined) continue;
676+
if (is32Float(format)) {
677+
this.skipIf(
678+
!this.device.features.has('float32-blendable'),
679+
`texture format '${format}' is not blendable`
680+
);
681+
}
682+
}
683+
}
684+
672685
skipIfTextureFormatDoesNotSupportUsage(
673686
usage: GPUTextureUsageFlags,
674687
...formats: (GPUTextureFormat | undefined)[]

0 commit comments

Comments
 (0)