Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor api/operation/render_pipeline for texture formats #4204

Merged
merged 1 commit into from
Feb 25, 2025
Merged
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 @@ -5,8 +5,8 @@ Test all culling combinations of GPUFrontFace and GPUCullMode show the correct o
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kTextureFormatInfo, SizedTextureFormat } from '../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { isStencilTextureFormat, SizedTextureFormat } from '../../../format_info.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';

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

class CullingTest extends TextureTestMixin(GPUTest) {
class CullingTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
checkCornerPixels(
texture: GPUTexture,
expectedTopLeftColor: Uint8Array,
Expand Down Expand Up @@ -146,7 +146,7 @@ g.test('culling')
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
});

const haveStencil = depthStencilFormat && kTextureFormatInfo[depthStencilFormat].stencil;
const haveStencil = depthStencilFormat && isStencilTextureFormat(depthStencilFormat);
let depthTexture: GPUTexture | undefined = undefined;
let depthStencilAttachment: GPURenderPassDepthStencilAttachment | undefined = undefined;
let depthStencil: GPUDepthStencilState | undefined = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/render_pipeline/overrides.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Testing render pipeline using overridable constants in vertex stage and fragment
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { GPUTest } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
import { PerTexelComponent } from '../../../util/texture/texel_data.js';

class F extends GPUTest {
class F extends AllFeaturesMaxLimitsGPUTest {
async ExpectShaderOutputWithConstants(
isAsync: boolean,
format: GPUTextureFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { range } from '../../../../common/util/util.js';
import {
computeBytesPerSampleFromFormats,
kRenderableColorTextureFormats,
kTextureFormatInfo,
getColorRenderByteCost,
getTextureFormatType,
isSintOrUintFormat,
kPossibleColorRenderableTextureFormats,
} from '../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { getFragmentShaderCodeWithOutput, getPlainTypeInfo } from '../../../util/shader.js';
import { kTexelRepresentationInfo } from '../../../util/texture/texel_data.js';

Expand All @@ -25,7 +27,7 @@ const kVertexShader = `
}
`;

export const g = makeTestGroup(TextureTestMixin(GPUTest));
export const g = makeTestGroup(TextureTestMixin(AllFeaturesMaxLimitsGPUTest));

// Values to write into each attachment
// We make values different for each attachment index and each channel
Expand All @@ -50,33 +52,30 @@ g.test('color,attachments')
.desc(`Test that pipeline with sparse color attachments write values correctly.`)
.params(u =>
u
.combine('format', kRenderableColorTextureFormats)
.combine('format', kPossibleColorRenderableTextureFormats)
.beginSubcases()
.combine('attachmentCount', [2, 3, 4])
.expand('emptyAttachmentId', p => range(p.attachmentCount, i => i))
)
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
const { format, attachmentCount, emptyAttachmentId } = t.params;

t.skipIfTextureFormatNotSupported(format);
t.skipIfTextureFormatNotUsableAsRenderAttachment(format);

const componentCount = kTexelRepresentationInfo[format].componentOrder.length;
const info = kTextureFormatInfo[format];

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

const writeValues =
info.color.type === 'sint' || info.color.type === 'uint'
? attachmentsIntWriteValues
: attachmentsFloatWriteValues;
const writeValues = isSintOrUintFormat(format)
? attachmentsIntWriteValues
: attachmentsFloatWriteValues;

const renderTargets = range(attachmentCount, () =>
t.createTextureTracked({
Expand Down Expand Up @@ -106,7 +105,7 @@ g.test('color,attachments')
writeValues[i].B,
writeValues[i].A,
],
plainType: getPlainTypeInfo(info.color.type),
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
componentCount,
}
)
Expand Down Expand Up @@ -152,19 +151,15 @@ g.test('color,component_count')
)
.params(u =>
u
.combine('format', kRenderableColorTextureFormats)
.combine('format', kPossibleColorRenderableTextureFormats)
.beginSubcases()
.combine('componentCount', [1, 2, 3, 4])
.filter(x => x.componentCount >= kTexelRepresentationInfo[x.format].componentOrder.length)
)
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
const { format, componentCount } = t.params;
const info = kTextureFormatInfo[format];
t.skipIfTextureFormatNotSupported(format);
t.skipIfTextureFormatNotUsableAsRenderAttachment(format);

// expected RGBA values
// extra channels are discarded
Expand All @@ -189,7 +184,7 @@ g.test('color,component_count')
code: getFragmentShaderCodeWithOutput([
{
values,
plainType: getPlainTypeInfo(info.color.type),
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
componentCount,
},
]),
Expand Down Expand Up @@ -364,10 +359,6 @@ The attachment has a load value of [1, 0, 0, 1]
] as const)
.filter(x => x.output.length >= kTexelRepresentationInfo[x.format].componentOrder.length)
)
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
const {
format,
Expand All @@ -378,8 +369,10 @@ The attachment has a load value of [1, 0, 0, 1]
alphaSrcFactor,
alphaDstFactor,
} = t.params;
t.skipIfTextureFormatNotSupported(format);
t.skipIfTextureFormatNotBlendable(format);

const componentCount = output.length;
const info = kTextureFormatInfo[format];

const renderTarget = t.createTextureTracked({
format,
Expand All @@ -400,7 +393,7 @@ The attachment has a load value of [1, 0, 0, 1]
code: getFragmentShaderCodeWithOutput([
{
values: output,
plainType: getPlainTypeInfo(info.color.type),
plainType: getPlainTypeInfo(getTextureFormatType(format)!),
componentCount,
},
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Test locations are framebuffer coordinates:
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { PerPixelComparison } from '../../../util/texture/texture_ok.js';

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

const kDefaultDrawCount = 6;
class PrimitiveTopologyTest extends TextureTestMixin(GPUTest) {
class PrimitiveTopologyTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
makeAttachmentTexture(): GPUTexture {
return this.createTextureTracked({
format: kColorFormat,
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/render_pipeline/sample_mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Details could be found at: https://github.com/gpuweb/cts/issues/2201

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { assert, range } from '../../../../common/util/util.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { checkElementsPassPredicate, checkElementsEqual } from '../../../util/check_contents.js';
import { Type } from '../../../util/conversion.js';
import { TexelView } from '../../../util/texture/texel_view.js';
Expand Down Expand Up @@ -263,7 +263,7 @@ struct FragmentOutput2 {
}
`;

class F extends TextureTestMixin(GPUTest) {
class F extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
private sampleTexture: GPUTexture | undefined;
private sampler: GPUSampler | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Test vertex-only render pipeline.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { GPUTest } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';

class F extends GPUTest {}
class F extends AllFeaturesMaxLimitsGPUTest {}

export const g = makeTestGroup(F);

Expand Down
17 changes: 13 additions & 4 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1565,28 +1565,29 @@ export const kStencilTextureFormats = kDepthStencilFormats.filter(
// Texture formats that may possibly be used as a storage texture.
// Some may require certain features to be enabled.
export const kPossibleStorageTextureFormats = [
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].color?.storage),
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].color?.storage),
'bgra8unorm',
] as const;

// Texture formats that may possibly be multisampled.
// Some may require certain features to be enabled.
export const kPossibleMultisampledTextureFormats = [
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
...kDepthStencilFormats.filter(f => kTextureFormatInfo[f].multisample),
'rg11b10ufloat',
] as const;

// Texture formats that may possibly be color renderable.
// Some may require certain features to be enabled.
export const kPossibleColorRenderableTextureFormats = [
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].colorRender),
...kRegularTextureFormats.filter(f => kTextureFormatInfo[f].colorRender),
'rg11b10ufloat',
] as const;
export type PossibleColorRenderTextureFormat =
(typeof kPossibleColorRenderableTextureFormats)[number];

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

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

/**
* Returns the texture's type (float, unsigned-float, sint, uint, depth)
*/
export function getTextureFormatType(format: GPUTextureFormat) {
const info = kTextureFormatInfo[format];
return info.color?.type ?? info.depth?.type ?? info.stencil?.type;
}

/**
* Returns if a texture can be used as a "colorAttachment".
*/
Expand Down
13 changes: 13 additions & 0 deletions src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
isTextureFormatUsableAsStorageFormat,
isTextureFormatUsableAsRenderAttachment,
isTextureFormatMultisampled,
is32Float,
} 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 @@ -669,6 +670,18 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
}
}

skipIfTextureFormatNotBlendable(...formats: (GPUTextureFormat | undefined)[]) {
for (const format of formats) {
if (format === undefined) continue;
if (is32Float(format)) {
this.skipIf(
!this.device.features.has('float32-blendable'),
`texture format '${format}' is not blendable`
);
}
}
}

skipIfTextureFormatDoesNotSupportUsage(
usage: GPUTextureUsageFlags,
...formats: (GPUTextureFormat | undefined)[]
Expand Down