Skip to content

Commit

Permalink
Compat: fix float16(32)-renderable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrekshao committed Jan 17, 2025
1 parent 7cdd7c8 commit 824ea20
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/webgpu/api/operation/render_pass/storeOp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ g.test('render_pass_store_op,color_attachment_only')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.colorFormat);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.colorFormat);
})
.fn(t => {
const colorAttachment = t.createTextureTracked({
Expand Down
6 changes: 5 additions & 1 deletion src/webgpu/api/operation/render_pipeline/overrides.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ g.test('basic')
);
});

const kPrecisionTestFormat = 'rgba32float';
g.test('precision')
.desc(`Test that the float number precision is preserved for constants`)
.params(u =>
Expand All @@ -190,8 +191,11 @@ g.test('precision')
},
])
)
.beforeAllSubcases(t => {
t.skipIfFloatTextureFormatNotColorRenderable(kPrecisionTestFormat);
})
.fn(async t => {
const format = 'rgba32float';
const format = kPrecisionTestFormat;
await t.ExpectShaderOutputWithConstants(
t.params.isAsync,
format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ g.test('color,attachments')
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
Expand Down
15 changes: 13 additions & 2 deletions src/webgpu/api/operation/rendering/color_target_state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function computeBlendOperation(
}
}

const kBlendingGPUBlendComponentFormat = 'rgba16float';
g.test('blending,GPUBlendComponent')
.desc(
`Test all combinations of parameters for GPUBlendComponent.
Expand Down Expand Up @@ -202,15 +203,21 @@ g.test('blending,GPUBlendComponent')
})
)
.beforeAllSubcases(t => {
const requiredFeatures = t.getFloatTextureFormatColorRenderableFeatures(
kBlendingGPUBlendComponentFormat
);
if (
IsDualSourceBlendingFactor(t.params.srcFactor) ||
IsDualSourceBlendingFactor(t.params.dstFactor)
) {
t.selectDeviceOrSkipTestCase('dual-source-blending');
requiredFeatures.push('dual-source-blending');
}
if (requiredFeatures.length > 0) {
t.selectDeviceOrSkipTestCase(requiredFeatures);
}
})
.fn(t => {
const textureFormat: GPUTextureFormat = 'rgba16float';
const textureFormat: GPUTextureFormat = kBlendingGPUBlendComponentFormat;
const srcColor = t.params.srcColor;
const srcColor1 = t.params.srcColor1;
const dstColor = t.params.dstColor;
Expand Down Expand Up @@ -393,6 +400,7 @@ g.test('blending,formats')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
})
.fn(t => {
const { format } = t.params;
Expand Down Expand Up @@ -797,6 +805,9 @@ g.test('blending,clamping')
.combine('srcValue', [0.4, 0.6, 0.8, 1.0])
.combine('dstValue', [0.2, 0.4])
)
.beforeAllSubcases(t => {
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
})
.fn(t => {
const { format, srcValue, dstValue } = t.params;

Expand Down
6 changes: 5 additions & 1 deletion src/webgpu/api/operation/resource_init/texture_zero.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ g.test('uninitialized_texture_is_zero')
.params(kTestParams)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.selectDeviceOrSkipTestCase(kTextureFormatInfo[t.params.format].feature);
const requiredFeatures = [
...t.getFloatTextureFormatColorRenderableFeatures(t.params.format),
...(kTextureFormatInfo[t.params.format].feature ?? []),
] as GPUFeatureName[];
t.selectDeviceOrSkipTestCase(requiredFeatures);
})
.fn(t => {
const usage = getRequiredTextureUsage(
Expand Down
5 changes: 5 additions & 0 deletions src/webgpu/api/operation/sampling/filter_mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ g.test('magFilter,nearest')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
}
Expand Down Expand Up @@ -604,6 +605,7 @@ g.test('magFilter,linear')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
}
Expand Down Expand Up @@ -739,6 +741,7 @@ g.test('minFilter,nearest')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
}
Expand Down Expand Up @@ -872,6 +875,7 @@ g.test('minFilter,linear')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
}
Expand Down Expand Up @@ -968,6 +972,7 @@ g.test('mipmapFilter')
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupported(t.params.format);
t.skipIfFloatTextureFormatNotColorRenderable(t.params.format);
if (kTextureFormatInfo[t.params.format].color.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
}
Expand Down
4 changes: 4 additions & 0 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,10 @@ export function canUseAsRenderTarget(format: GPUTextureFormat) {
return kTextureFormatInfo[format].colorRender || isDepthOrStencilTextureFormat(format);
}

export function is16Float(format: GPUTextureFormat) {
return format === 'r16float' || format === 'rg16float' || format === 'rgba16float';
}

export function is32Float(format: GPUTextureFormat) {
return format === 'r32float' || format === 'rg32float' || format === 'rgba32float';
}
Expand Down
26 changes: 26 additions & 0 deletions src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
isCompressedTextureFormat,
ColorTextureFormat,
isTextureFormatUsableAsStorageFormat,
is32Float,
is16Float,
} from './format_info.js';
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
Expand Down Expand Up @@ -279,6 +281,30 @@ export class GPUTestSubcaseBatchState extends SubcaseBatchState {
}
}

getFloatTextureFormatColorRenderableFeatures(...formats: (GPUTextureFormat | undefined)[]) {
const requiredFeatures: GPUFeatureName[] = [];
if (this.isCompatibility) {
for (const format of formats) {
if (format === undefined) continue;
if (is32Float(format)) {
requiredFeatures.push('float32-renderable' as GPUFeatureName);
} else if (is16Float(format)) {
requiredFeatures.push('float16-renderable' as GPUFeatureName);
}
}
}
return requiredFeatures;
}

/** Skips test if format is float16 or float32 and not color renderable based on device feature availability. */
skipIfFloatTextureFormatNotColorRenderable(...formats: (GPUTextureFormat | undefined)[]) {
if (this.isCompatibility) {
this.selectDeviceOrSkipTestCase({
requiredFeatures: this.getFloatTextureFormatColorRenderableFeatures(...formats),
});
}
}

skipIfCopyTextureToTextureNotSupportedForFormat(...formats: (GPUTextureFormat | undefined)[]) {
if (this.isCompatibility) {
for (const format of formats) {
Expand Down
6 changes: 3 additions & 3 deletions src/webgpu/web_platform/canvas/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ g.test('format')
format,
});
const configuration = ctx.getConfiguration();
t.expect(configuration!.format === format);
t.expect(configuration.format === format);
} else {
t.shouldThrow('TypeError', () => {
ctx.configure({
Expand Down Expand Up @@ -224,7 +224,7 @@ g.test('usage')
});

const configuration = ctx.getConfiguration();
t.expect(configuration!.usage === usage);
t.expect(configuration.usage === usage);

const currentTexture = ctx.getCurrentTexture();
t.expect(currentTexture instanceof GPUTexture);
Expand Down Expand Up @@ -343,7 +343,7 @@ g.test('alpha_mode')
});

const configuration = ctx.getConfiguration();
t.expect(configuration!.alphaMode === alphaMode);
t.expect(configuration.alphaMode === alphaMode);

const currentTexture = ctx.getCurrentTexture();
t.expect(currentTexture instanceof GPUTexture);
Expand Down

0 comments on commit 824ea20

Please sign in to comment.