Skip to content

Commit 53669c4

Browse files
committed
Refactor api/operations/storage_texture/*
Also renamed isTextureFormatPossiblyStorageWritable to isTextureFormatPossiblyStorageReadWritable as the old name was wrong. That affected textureDimensions.spec.ts
1 parent 46e9a89 commit 53669c4

File tree

6 files changed

+55
-35
lines changed

6 files changed

+55
-35
lines changed

src/webgpu/api/operation/sampling/anisotropy.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ things. If there are no guarantees we can issue warnings instead of failures. Id
1212

1313
import { makeTestGroup } from '../../../../common/framework/test_group.js';
1414
import { assert } from '../../../../common/util/util.js';
15-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
15+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
1616
import { checkElementsEqual } from '../../../util/check_contents.js';
1717
import { TexelView } from '../../../util/texture/texel_view.js';
1818
import { PerPixelComparison } from '../../../util/texture/texture_ok.js';
@@ -33,7 +33,7 @@ const checkerColors = [
3333
];
3434

3535
// renders texture a slanted plane placed in a specific way
36-
class SamplerAnisotropicFilteringSlantedPlaneTest extends GPUTest {
36+
class SamplerAnisotropicFilteringSlantedPlaneTest extends AllFeaturesMaxLimitsGPUTest {
3737
copyRenderTargetToBuffer(rt: GPUTexture): GPUBuffer {
3838
const byteLength = kRTSize * kBytesPerRow;
3939
const buffer = this.createBufferTracked({

src/webgpu/api/operation/storage_texture/read_only.spec.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { Float16Array } from '../../../../external/petamoriken/float16/float16.j
1212
import { kTextureDimensions } from '../../../capability_info.js';
1313
import {
1414
ColorTextureFormat,
15-
kColorTextureFormats,
16-
kTextureFormatInfo,
15+
getBlockInfoForColorTextureFormat,
16+
getTextureFormatType,
17+
kPossibleStorageTextureFormats,
1718
} from '../../../format_info.js';
1819
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
1920
import { kValidShaderStages, TValidShaderStage } from '../../../util/shader.js';
@@ -51,8 +52,7 @@ class F extends AllFeaturesMaxLimitsGPUTest {
5152
storageTexture: GPUTexture,
5253
format: ColorTextureFormat
5354
): ArrayBuffer {
54-
const bytesPerBlock = kTextureFormatInfo[format].color.bytes;
55-
assert(bytesPerBlock !== undefined);
55+
const { bytesPerBlock } = getBlockInfoForColorTextureFormat(format);
5656

5757
const width = storageTexture.width;
5858
const height = storageTexture.height;
@@ -175,14 +175,16 @@ class F extends AllFeaturesMaxLimitsGPUTest {
175175
}
176176

177177
getTypedArrayBufferForOutputBufferData(arrayBuffer: ArrayBuffer, format: ColorTextureFormat) {
178-
switch (kTextureFormatInfo[format].color.type) {
178+
switch (getTextureFormatType(format)) {
179179
case 'uint':
180180
return new Uint32Array(arrayBuffer);
181181
case 'sint':
182182
return new Int32Array(arrayBuffer);
183183
case 'float':
184184
case 'unfilterable-float':
185185
return new Float32Array(arrayBuffer);
186+
default:
187+
unreachable();
186188
}
187189
}
188190

@@ -220,7 +222,7 @@ class F extends AllFeaturesMaxLimitsGPUTest {
220222
}
221223

222224
getOutputBufferWGSLType(format: ColorTextureFormat) {
223-
switch (kTextureFormatInfo[format].color.type) {
225+
switch (getTextureFormatType(format)) {
224226
case 'uint':
225227
return 'vec4u';
226228
case 'sint':
@@ -542,25 +544,16 @@ g.test('basic')
542544
)
543545
.params(u =>
544546
u
545-
.combine('format', kColorTextureFormats)
546-
.filter(
547-
p => p.format === 'bgra8unorm' || kTextureFormatInfo[p.format].color?.storage === true
548-
)
547+
.combine('format', kPossibleStorageTextureFormats)
549548
.combine('shaderStage', kValidShaderStages)
550549
.combine('dimension', kTextureDimensions)
551550
.combine('depthOrArrayLayers', [1, 2] as const)
552551
.unless(p => p.dimension === '1d' && p.depthOrArrayLayers > 1)
553552
)
554-
.beforeAllSubcases(t => {
555-
if (t.params.format === 'bgra8unorm') {
556-
t.selectDeviceOrSkipTestCase('bgra8unorm-storage');
557-
}
558-
if (t.isCompatibility) {
559-
t.skipIfTextureFormatNotUsableAsStorageTextureDeprecated(t.params.format);
560-
}
561-
})
562553
.fn(t => {
563554
const { format, shaderStage, dimension, depthOrArrayLayers } = t.params;
555+
t.skipIfTextureFormatNotSupported(format);
556+
t.skipIfTextureFormatNotUsableAsStorageTexture(format);
564557

565558
if (t.isCompatibility) {
566559
if (shaderStage === 'fragment') {
@@ -598,7 +591,7 @@ g.test('basic')
598591

599592
t.doTransform(storageTexture, shaderStage, format, outputBuffer);
600593

601-
switch (kTextureFormatInfo[format].color.type) {
594+
switch (getTextureFormatType(format)) {
602595
case 'uint':
603596
t.expectGPUBufferValuesEqual(outputBuffer, new Uint32Array(expectedData));
604597
break;

src/webgpu/api/operation/storage_texture/read_write.spec.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ TODO:
88
import { makeTestGroup } from '../../../../common/framework/test_group.js';
99
import { assert, unreachable } from '../../../../common/util/util.js';
1010
import { kTextureDimensions } from '../../../capability_info.js';
11-
import { kColorTextureFormats, kTextureFormatInfo } from '../../../format_info.js';
11+
import {
12+
getBlockInfoForColorTextureFormat,
13+
getBlockInfoForTextureFormat,
14+
kPossibleStorageTextureFormats,
15+
} from '../../../format_info.js';
1216
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
1317
import { align } from '../../../util/math.js';
1418

@@ -19,7 +23,7 @@ type ShaderStageForReadWriteStorageTexture =
1923
class F extends AllFeaturesMaxLimitsGPUTest {
2024
getInitialData(storageTexture: GPUTexture): ArrayBuffer {
2125
const format = storageTexture.format;
22-
const bytesPerBlock = kTextureFormatInfo[format].bytesPerBlock;
26+
const { bytesPerBlock } = getBlockInfoForTextureFormat(format);
2327
assert(bytesPerBlock !== undefined);
2428

2529
const width = storageTexture.width;
@@ -68,7 +72,7 @@ class F extends AllFeaturesMaxLimitsGPUTest {
6872
initialData: ArrayBuffer
6973
): ArrayBuffer {
7074
const format = storageTexture.format;
71-
const bytesPerBlock = kTextureFormatInfo[format].bytesPerBlock;
75+
const { bytesPerBlock } = getBlockInfoForTextureFormat(format);
7276
assert(bytesPerBlock !== undefined);
7377

7478
const width = storageTexture.width;
@@ -308,18 +312,16 @@ g.test('basic')
308312
)
309313
.params(u =>
310314
u
311-
.combine('format', kColorTextureFormats)
312-
.filter(p => kTextureFormatInfo[p.format].color?.readWriteStorage === true)
315+
.combine('format', kPossibleStorageTextureFormats)
313316
.combine('shaderStage', kShaderStagesForReadWriteStorageTexture)
314317
.combine('textureDimension', kTextureDimensions)
315318
.combine('depthOrArrayLayers', [1, 2] as const)
316319
.unless(p => p.textureDimension === '1d' && p.depthOrArrayLayers > 1)
317320
)
318-
.beforeAllSubcases(t => {
319-
t.skipIfTextureFormatNotUsableAsStorageTextureDeprecated(t.params.format);
320-
})
321321
.fn(t => {
322322
const { format, shaderStage, textureDimension, depthOrArrayLayers } = t.params;
323+
t.skipIfTextureFormatNotSupported(format);
324+
t.skipIfTextureFormatNotUsableAsReadWriteStorageTexture(format);
323325

324326
if (t.isCompatibility) {
325327
if (shaderStage === 'fragment') {
@@ -343,7 +345,7 @@ g.test('basic')
343345
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST | GPUTextureUsage.STORAGE_BINDING,
344346
});
345347

346-
const bytesPerBlock = kTextureFormatInfo[format].bytesPerBlock;
348+
const { bytesPerBlock } = getBlockInfoForColorTextureFormat(format);
347349
const initialData = t.getInitialData(storageTexture);
348350
t.queue.writeTexture(
349351
{ texture: storageTexture },

src/webgpu/format_info.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -2065,10 +2065,10 @@ export function isTextureFormatPossiblyStorageReadable(format: GPUTextureFormat)
20652065
}
20662066

20672067
/**
2068-
* Returns true if a texture can possibly be used as a writable storage texture.
2068+
* Returns true if a texture can possibly be used as a read-write storage texture.
20692069
* The texture may require certain features to be enabled.
20702070
*/
2071-
export function isTextureFormatPossiblyStorageWritable(format: GPUTextureFormat) {
2071+
export function isTextureFormatPossiblyStorageReadWritable(format: GPUTextureFormat) {
20722072
return !!kTextureFormatInfo[format].color?.readWriteStorage;
20732073
}
20742074

@@ -2129,6 +2129,16 @@ export function isTextureFormatUsableAsStorageFormat(
21292129
return !!(info.color?.storage || info.depth?.storage || info.stencil?.storage);
21302130
}
21312131

2132+
export function isTextureFormatUsableAsReadWriteStorageTexture(
2133+
device: GPUDevice,
2134+
format: GPUTextureFormat
2135+
): boolean {
2136+
return (
2137+
isTextureFormatUsableAsStorageFormat(device, format) &&
2138+
!!kTextureFormatInfo[format].color?.readWriteStorage
2139+
);
2140+
}
2141+
21322142
export function isRegularTextureFormat(format: GPUTextureFormat) {
21332143
return format in kRegularTextureFormatInfo;
21342144
}

src/webgpu/gpu_test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
is32Float,
4141
isSintOrUintFormat,
4242
isTextureFormatResolvable,
43+
isTextureFormatUsableAsReadWriteStorageTexture,
4344
} from './format_info.js';
4445
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
4546
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
@@ -655,6 +656,18 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
655656
}
656657
}
657658

659+
skipIfTextureFormatNotUsableAsReadWriteStorageTexture(
660+
...formats: (GPUTextureFormat | undefined)[]
661+
) {
662+
for (const format of formats) {
663+
if (!format) continue;
664+
665+
if (!isTextureFormatUsableAsReadWriteStorageTexture(this.device, format)) {
666+
this.skip(`Texture with ${format} is not usable as a storage texture`);
667+
}
668+
}
669+
}
670+
658671
skipIfTextureFormatNotUsableAsRenderAttachment(...formats: (GPUTextureFormat | undefined)[]) {
659672
for (const format of formats) {
660673
if (format && !isTextureFormatUsableAsRenderAttachment(this.device, format)) {

src/webgpu/shader/execution/expression/call/builtin/textureDimensions.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isDepthTextureFormat,
1414
isStencilTextureFormat,
1515
isTextureFormatPossiblyMultisampled,
16-
isTextureFormatPossiblyStorageWritable,
16+
isTextureFormatPossiblyStorageReadWritable,
1717
kAllTextureFormats,
1818
kDepthTextureFormats,
1919
kPossibleStorageTextureFormats,
@@ -463,8 +463,10 @@ Parameters:
463463
.combine('access', ['read', 'write', 'read_write'] as const)
464464
// vertex stage can not use writable storage.
465465
.unless(t => t.stage === 'vertex' && t.access !== 'read')
466-
// Only some formats support write
467-
.unless(t => !isTextureFormatPossiblyStorageWritable(t.format) && t.access === 'read_write')
466+
// Only some formats support read_write
467+
.unless(
468+
t => !isTextureFormatPossiblyStorageReadWritable(t.format) && t.access === 'read_write'
469+
)
468470
.expand('dimensions', u => viewDimensions(u).filter(dimensionsValidForStorage))
469471
.expand('textureMipCount', textureMipCount)
470472
.expand('baseMipLevel', baseMipLevel)

0 commit comments

Comments
 (0)