Skip to content

Commit 4ebea89

Browse files
authored
Refactor maxColorAttachmentBytesPerSample.spec.ts (#4284)
Issue #4181
1 parent 5265eae commit 4ebea89

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/webgpu/api/validation/capability_checks/limits/maxColorAttachmentBytesPerSample.spec.ts

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert } from '../../../../../common/util/util.js';
22
import { kTextureSampleCounts } from '../../../../capability_info.js';
3-
import { kTextureFormatInfo } from '../../../../format_info.js';
3+
import { getColorRenderAlignment, getColorRenderByteCost } from '../../../../format_info.js';
44
import { align } from '../../../../util/math.js';
55

66
import {
@@ -10,30 +10,26 @@ import {
1010
makeLimitTestGroup,
1111
} from './limit_utils.js';
1212

13-
const kFormatsToUseBySize: GPUTextureFormat[] = [
13+
const kFormatsToUseBySize = [
1414
'rgba32uint',
1515
'rgba16uint',
1616
'rgba8unorm',
1717
'rg8unorm',
1818
'r8unorm',
19-
];
19+
] as const;
2020

21-
const kInterleaveFormats: GPUTextureFormat[] = [
22-
'rgba16uint',
23-
'rg16uint',
24-
'rgba8unorm',
25-
'rg8unorm',
26-
'r8unorm',
27-
];
21+
const kInterleaveFormats = ['rgba16uint', 'rg16uint', 'rgba8unorm', 'rg8unorm', 'r8unorm'] as const;
22+
23+
const kFormatsUsedInTest = [...kFormatsToUseBySize, ...kInterleaveFormats] as const;
24+
type FormatUsedInTest = (typeof kFormatsUsedInTest)[number];
2825

29-
function getAttachments(interleaveFormat: GPUTextureFormat, testValue: number) {
26+
function getAttachments(interleaveFormat: FormatUsedInTest, testValue: number) {
3027
let bytesPerSample = 0;
3128
const targets: GPUColorTargetState[] = [];
3229

33-
const addTexture = (format: GPUTextureFormat) => {
34-
const info = kTextureFormatInfo[format];
30+
const addTexture = (format: FormatUsedInTest) => {
3531
const newBytesPerSample =
36-
align(bytesPerSample, info.colorRender!.alignment) + info.colorRender!.byteCost;
32+
align(bytesPerSample, getColorRenderAlignment(format)) + getColorRenderByteCost(format);
3733
if (newBytesPerSample > testValue) {
3834
return false;
3935
}
@@ -70,12 +66,13 @@ function getDescription(
7066
let offset = 0;
7167
return targets
7268
.map(({ format }) => {
73-
const info = kTextureFormatInfo[format];
74-
offset = align(offset, info.colorRender!.alignment);
75-
const s = `// ${format.padEnd(11)} (offset: ${offset.toString().padStart(2)}, align: ${
76-
info.colorRender!.alignment
77-
}, size: ${info.colorRender!.byteCost})`;
78-
offset += info.colorRender!.byteCost;
69+
const alignment = getColorRenderAlignment(format as FormatUsedInTest);
70+
const byteCost = getColorRenderByteCost(format as FormatUsedInTest);
71+
offset = align(offset, alignment);
72+
const s = `// ${format.padEnd(11)} (offset: ${offset
73+
.toString()
74+
.padStart(2)}, align: ${alignment}, size: ${byteCost})`;
75+
offset += byteCost;
7976
return s;
8077
})
8178
.join('\n ');
@@ -86,7 +83,7 @@ function getDescription(
8683
function getPipelineDescriptor(
8784
device: GPUDevice,
8885
actualLimit: number,
89-
interleaveFormat: GPUTextureFormat,
86+
interleaveFormat: FormatUsedInTest,
9087
sampleCount: number,
9188
testValue: number
9289
): { pipelineDescriptor: GPURenderPipelineDescriptor; code: string } | undefined {

src/webgpu/format_info.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,21 @@ export function getColorRenderByteCost(format: PossibleColorRenderTextureFormat)
18991899
return byteCost;
19001900
}
19011901

1902+
/**
1903+
* Returns the "alignment" of rendering to a color texture format.
1904+
* MAINTENANCE_TODO: remove `rg11b10ufloat' from here and add its data to table
1905+
* once CTS is refactored. See issue #4181
1906+
*/
1907+
export function getColorRenderAlignment(format: PossibleColorRenderTextureFormat) {
1908+
const alignment =
1909+
format === 'rg11b10ufloat' ? 1 : kTextureFormatInfo[format].colorRender?.alignment;
1910+
// MAINTENANCE_TODO: remove this assert. The issue is typescript thinks
1911+
// PossibleColorRenderTextureFormat contains all texture formats and not just
1912+
// a filtered list.
1913+
assert(alignment !== undefined);
1914+
return alignment;
1915+
}
1916+
19021917
/**
19031918
* Gets the baseFormat for a texture format.
19041919
*/

0 commit comments

Comments
 (0)