Skip to content
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
@@ -1,6 +1,6 @@
import { assert } from '../../../../../common/util/util.js';
import { kTextureSampleCounts } from '../../../../capability_info.js';
import { kTextureFormatInfo } from '../../../../format_info.js';
import { getColorRenderAlignment, getColorRenderByteCost } from '../../../../format_info.js';
import { align } from '../../../../util/math.js';

import {
Expand All @@ -10,30 +10,26 @@ import {
makeLimitTestGroup,
} from './limit_utils.js';

const kFormatsToUseBySize: GPUTextureFormat[] = [
const kFormatsToUseBySize = [
'rgba32uint',
'rgba16uint',
'rgba8unorm',
'rg8unorm',
'r8unorm',
];
] as const;

const kInterleaveFormats: GPUTextureFormat[] = [
'rgba16uint',
'rg16uint',
'rgba8unorm',
'rg8unorm',
'r8unorm',
];
const kInterleaveFormats = ['rgba16uint', 'rg16uint', 'rgba8unorm', 'rg8unorm', 'r8unorm'] as const;

const kFormatsUsedInTest = [...kFormatsToUseBySize, ...kInterleaveFormats] as const;
type FormatUsedInTest = (typeof kFormatsUsedInTest)[number];

function getAttachments(interleaveFormat: GPUTextureFormat, testValue: number) {
function getAttachments(interleaveFormat: FormatUsedInTest, testValue: number) {
let bytesPerSample = 0;
const targets: GPUColorTargetState[] = [];

const addTexture = (format: GPUTextureFormat) => {
const info = kTextureFormatInfo[format];
const addTexture = (format: FormatUsedInTest) => {
const newBytesPerSample =
align(bytesPerSample, info.colorRender!.alignment) + info.colorRender!.byteCost;
align(bytesPerSample, getColorRenderAlignment(format)) + getColorRenderByteCost(format);
if (newBytesPerSample > testValue) {
return false;
}
Expand Down Expand Up @@ -70,12 +66,13 @@ function getDescription(
let offset = 0;
return targets
.map(({ format }) => {
const info = kTextureFormatInfo[format];
offset = align(offset, info.colorRender!.alignment);
const s = `// ${format.padEnd(11)} (offset: ${offset.toString().padStart(2)}, align: ${
info.colorRender!.alignment
}, size: ${info.colorRender!.byteCost})`;
offset += info.colorRender!.byteCost;
const alignment = getColorRenderAlignment(format as FormatUsedInTest);
const byteCost = getColorRenderByteCost(format as FormatUsedInTest);
offset = align(offset, alignment);
const s = `// ${format.padEnd(11)} (offset: ${offset
.toString()
.padStart(2)}, align: ${alignment}, size: ${byteCost})`;
offset += byteCost;
return s;
})
.join('\n ');
Expand All @@ -86,7 +83,7 @@ function getDescription(
function getPipelineDescriptor(
device: GPUDevice,
actualLimit: number,
interleaveFormat: GPUTextureFormat,
interleaveFormat: FormatUsedInTest,
sampleCount: number,
testValue: number
): { pipelineDescriptor: GPURenderPipelineDescriptor; code: string } | undefined {
Expand Down
15 changes: 15 additions & 0 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,21 @@ export function getColorRenderByteCost(format: PossibleColorRenderTextureFormat)
return byteCost;
}

/**
* Returns the "alignment" of rendering to a color texture format.
* MAINTENANCE_TODO: remove `rg11b10ufloat' from here and add its data to table
* once CTS is refactored. See issue #4181
*/
export function getColorRenderAlignment(format: PossibleColorRenderTextureFormat) {
const alignment =
format === 'rg11b10ufloat' ? 1 : kTextureFormatInfo[format].colorRender?.alignment;
// MAINTENANCE_TODO: remove this assert. The issue is typescript thinks
// PossibleColorRenderTextureFormat contains all texture formats and not just
// a filtered list.
assert(alignment !== undefined);
return alignment;
}

/**
* Gets the baseFormat for a texture format.
*/
Expand Down