Skip to content

Commit 68676e3

Browse files
authored
Refactor isTextureFormatUsableAsStorageFormatInCreateShaderModule (#4419)
The function had an incomplete list. I still think the function is better than checking for array membership in each test that needs it. It's a single place that can encapsulate what to do to do check. It's a single place to hide the type casting. It's also a single place to fix if someone wants to change the internals for how this info is stored. It's a central place to make device dependent changes if that ever comes up.
1 parent eba794d commit 68676e3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/webgpu/format_info.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,11 +2534,9 @@ export function isTextureFormatUsableAsStorageFormatInCreateShaderModule(
25342534
device: GPUDevice,
25352535
format: GPUTextureFormat
25362536
): boolean {
2537-
if (format === 'bgra8unorm') {
2538-
return true;
2539-
}
2540-
const info = kTextureFormatInfo[format];
2541-
return !!(info.color?.storage || info.depth?.storage || info.stencil?.storage);
2537+
return kPossibleStorageTextureFormats.includes(
2538+
format as (typeof kPossibleStorageTextureFormats)[number]
2539+
);
25422540
}
25432541

25442542
function isTextureFormatUsableAsReadWriteStorageTexture(

src/webgpu/shader/validation/types/textures.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Validation tests for various texture types in shaders.
55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import {
77
getTextureFormatType,
8+
isTextureFormatUsableAsStorageFormatInCreateShaderModule,
89
kAllTextureFormats,
910
kPossibleStorageTextureFormats,
1011
} from '../../../format_info.js';
@@ -108,7 +109,10 @@ Besides, the shader compilation should always pass regardless of whether the for
108109
)
109110
.fn(t => {
110111
const { format, access, comma } = t.params;
111-
const isFormatValid = (kPossibleStorageTextureFormats as string[]).includes(format);
112+
const isFormatValid = isTextureFormatUsableAsStorageFormatInCreateShaderModule(
113+
t.device,
114+
format
115+
);
112116
const isAccessValid = kAccessModes.includes(access);
113117
const wgsl = `@group(0) @binding(0) var tex: texture_storage_2d<${format}, ${access}${comma}>;`;
114118
t.expectCompileResult(isFormatValid && isAccessValid, wgsl);

0 commit comments

Comments
 (0)