Skip to content

Commit

Permalink
Refactor opreation/render_pass/* for texture_formats
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Feb 21, 2025
1 parent 145ca53 commit 9fa0b35
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
20 changes: 8 additions & 12 deletions src/webgpu/api/operation/render_pass/clear_value.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Tests for render pass clear values.
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { assert } from '../../../../common/util/util.js';
import {
kTextureFormatInfo,
kDepthStencilFormats,
depthStencilFormatAspectSize,
kStencilTextureFormats,
isDepthTextureFormat,
} from '../../../format_info.js';
import { GPUTest } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';

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

g.test('stored')
.desc(`Test render pass clear values are stored at the end of an empty pass.`)
Expand Down Expand Up @@ -48,20 +48,16 @@ g.test('stencil_clear_value')
)
.params(u =>
u
.combine('stencilFormat', kDepthStencilFormats)
.combine('stencilFormat', kStencilTextureFormats)
.combine('stencilClearValue', [0, 1, 0xff, 0x100 + 2, 0x10000 + 3])
.combine('applyStencilClearValueAsStencilReferenceValue', [true, false])
.filter(t => !!kTextureFormatInfo[t.stencilFormat].stencil)
)
.beforeAllSubcases(t => {
const { stencilFormat } = t.params;
const info = kTextureFormatInfo[stencilFormat];
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
const { stencilFormat, stencilClearValue, applyStencilClearValueAsStencilReferenceValue } =
t.params;

t.skipIfTextureFormatNotSupported(stencilFormat);

const kSize = [1, 1, 1] as const;
const colorFormat = 'rgba8unorm';
const stencilTexture = t.createTextureTracked({
Expand Down Expand Up @@ -141,7 +137,7 @@ g.test('stencil_clear_value')
stencilStoreOp: 'store',
stencilClearValue,
};
if (kTextureFormatInfo[stencilFormat].depth) {
if (isDepthTextureFormat(stencilFormat)) {
depthStencilAttachment.depthClearValue = 0;
depthStencilAttachment.depthLoadOp = 'clear';
depthStencilAttachment.depthStoreOp = 'store';
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/render_pass/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Tests a render pass with a resolveTarget resolves correctly for many combination
`;

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

const kSlotsToResolve = [
[0, 2],
Expand All @@ -25,7 +25,7 @@ const kSlotsToResolve = [
const kSize = 4;
const kFormat: GPUTextureFormat = 'rgba8unorm';

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

g.test('render_pass_resolve')
.params(u =>
Expand Down
27 changes: 13 additions & 14 deletions src/webgpu/api/operation/render_pass/storeOp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export const description = `API Operation Tests for RenderPass StoreOp.

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import {
kTextureFormatInfo,
kEncodableTextureFormats,
isDepthTextureFormat,
isStencilTextureFormat,
kPossibleColorRenderableTextureFormats,
kSizedDepthStencilFormats,
} from '../../../format_info.js';
import { GPUTest } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
import { PerTexelComponent } from '../../../util/texture/texel_data.js';

// Test with a zero and non-zero mip.
Expand All @@ -52,7 +53,7 @@ const kStoreOps: GPUStoreOp[] = ['discard', 'store'];
const kHeight = 2;
const kWidth = 2;

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

// Tests a render pass with both a color and depth stencil attachment to ensure store operations are
// set independently.
Expand Down Expand Up @@ -142,18 +143,16 @@ g.test('render_pass_store_op,color_attachment_with_depth_stencil_attachment')
g.test('render_pass_store_op,color_attachment_only')
.params(u =>
u
.combine('colorFormat', kEncodableTextureFormats)
// Filter out any non-renderable formats
.filter(({ colorFormat }) => !!kTextureFormatInfo[colorFormat].colorRender)
.combine('colorFormat', kPossibleColorRenderableTextureFormats)
.combine('storeOperation', kStoreOps)
.beginSubcases()
.combine('mipLevel', kMipLevel)
.combine('arrayLayer', kArrayLayers)
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupportedDeprecated(t.params.colorFormat);
})
.fn(t => {
t.skipIfTextureFormatNotSupported(t.params.colorFormat);
t.skipIfTextureFormatNotUsableAsRenderAttachment(t.params.colorFormat);

const colorAttachment = t.createTextureTracked({
format: t.params.colorFormat,
size: { width: kWidth, height: kHeight, depthOrArrayLayers: t.params.arrayLayer + 1 },
Expand Down Expand Up @@ -306,12 +305,12 @@ TODO: Also test unsized depth/stencil formats [1]
const depthStencilAttachment: GPURenderPassDepthStencilAttachment = {
view: depthStencilAttachmentView,
};
if (kTextureFormatInfo[t.params.depthStencilFormat].depth) {
if (isDepthTextureFormat(t.params.depthStencilFormat)) {
depthStencilAttachment.depthClearValue = 1.0;
depthStencilAttachment.depthLoadOp = 'clear';
depthStencilAttachment.depthStoreOp = t.params.storeOperation;
}
if (kTextureFormatInfo[t.params.depthStencilFormat].stencil) {
if (isStencilTextureFormat(t.params.depthStencilFormat)) {
depthStencilAttachment.stencilClearValue = 1;
depthStencilAttachment.stencilLoadOp = 'clear';
depthStencilAttachment.stencilStoreOp = t.params.storeOperation;
Expand All @@ -335,15 +334,15 @@ TODO: Also test unsized depth/stencil formats [1]
expectedStencilValue = { Stencil: 1 };
}

if (kTextureFormatInfo[t.params.depthStencilFormat].depth) {
if (isDepthTextureFormat(t.params.depthStencilFormat)) {
t.expectSingleColor(depthStencilTexture, t.params.depthStencilFormat, {
size: [kHeight, kWidth, 1],
slice: t.params.arrayLayer,
exp: expectedDepthValue,
layout: { mipLevel: t.params.mipLevel, aspect: 'depth-only' },
});
}
if (kTextureFormatInfo[t.params.depthStencilFormat].stencil) {
if (isStencilTextureFormat(t.params.depthStencilFormat)) {
t.expectSingleColor(depthStencilTexture, t.params.depthStencilFormat, {
size: [kHeight, kWidth, 1],
slice: t.params.arrayLayer,
Expand Down
6 changes: 3 additions & 3 deletions src/webgpu/api/operation/render_pass/storeop2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const description = `
renderPass store op test that drawn quad is either stored or cleared based on storeop
renderPass store op test that drawn quad is either stored or cleared based on storeOp
`;

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

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

g.test('storeOp_controls_whether_1x1_drawn_quad_is_stored')
.desc(
Expand Down
7 changes: 7 additions & 0 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,13 @@ export const kPossibleMultisampledTextureFormats = [
'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),
'rg11b10ufloat',
] as const;

// Texture formats that have a different base format. This is effectively all -srgb formats.
export const kDifferentBaseFormatTextureFormats = kAllTextureFormats.filter(
f => kTextureFormatInfo[f].baseFormat && kTextureFormatInfo[f].baseFormat !== f
Expand Down
13 changes: 12 additions & 1 deletion src/webgpu/shader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ export const kAddressSpaceInfo: Record<string, AddressSpaceInfo> = {
},
} as const;

/** List of texel formats and their shader representation */
/**
* List of texel formats and their shader representation
* MAINTENANCE_TODO: It's not clear what this table is used for but being static we should
* check that it's used correctly and not missing formats. For example the textureLoad tests
* were using this table and then manually adding in bgra8unorm but doing that at every
* test means that if a new format is added it will have to be added at every test.
* If this table is useful, say for a list of storage texture formats, it should probably
* be validated with the data in format_info.ts and visa versa so that adding a new format
* to one or the other asserts if it's missing in the other. Marking as deprecated for now
* to highlight where it's used.
*/
/** @deprecated */
export const TexelFormats = [
{ format: 'rgba8unorm', _shaderType: 'f32' },
{ format: 'rgba8snorm', _shaderType: 'f32' },
Expand Down

0 comments on commit 9fa0b35

Please sign in to comment.