Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api tests for 3D textures with BC compression #3799

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 8 additions & 4 deletions src/webgpu/api/validation/createTexture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ g.test('zero_size_and_usage')

g.test('dimension_type_and_format_compatibility')
.desc(
`Test every dimension type on every format. Note that compressed formats and depth/stencil formats are not valid for 1D/3D dimension types.`
`Test every dimension type on every format. Depth/stencil formats only support 2d;
compressed formats support either 2d or 2d+3d.`
)
.params(u =>
u //
Expand Down Expand Up @@ -220,7 +221,6 @@ g.test('mipLevelCount,bound_check')
({ format, size, dimension }) =>
format === 'bc1-rgba-unorm' &&
(dimension === '1d' ||
dimension === '3d' ||
size[0] % kTextureFormatInfo[format].blockWidth !== 0 ||
size[1] % kTextureFormatInfo[format].blockHeight !== 0)
)
Expand Down Expand Up @@ -459,8 +459,8 @@ g.test('texture_size,default_value_and_smallest_size,compressed_format')
)
.params(u =>
u
// Compressed formats are invalid for 1D and 3D.
.combine('dimension', [undefined, '2d'] as const)
// Compressed formats are invalid for 1D.
.combine('dimension', [undefined, '2d', '3d'] as const)
.combine('format', kCompressedTextureFormats)
.beginSubcases()
.expandWithParams(p => {
Expand All @@ -474,6 +474,10 @@ g.test('texture_size,default_value_and_smallest_size,compressed_format')
{ size: [blockWidth, blockHeight, 1], _success: true },
];
})
// Filter if the dimension is 3D and format is not compatible
.unless(
({ dimension, format }) => dimension === '3d' && !kTextureFormatInfo[format].texture3D
)
)
.beforeAllSubcases(t => {
const { format } = t.params;
Expand Down
17 changes: 11 additions & 6 deletions src/webgpu/format_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const kFormatUniversalDefaults = {
feature: undefined,
/** The base format for srgb formats. Specified on both srgb and equivalent non-srgb formats. */
baseFormat: undefined,
/** Whether the format can be used in textures with 3D dimension. */
texture3D: undefined,

/** @deprecated Use `.color.bytes`, `.depth.bytes`, or `.stencil.bytes`. */
bytesPerBlock: undefined,
Expand Down Expand Up @@ -68,7 +70,7 @@ function formatTableWithDefaults<Defaults extends {}, Table extends { readonly [

/** "plain color formats", plus rgb9e5ufloat. */
const kRegularTextureFormatInfo = formatTableWithDefaults({
defaults: { blockWidth: 1, blockHeight: 1 },
defaults: { blockWidth: 1, blockHeight: 1, texture3D: true },
table: {
// plain, 8 bits per component

Expand Down Expand Up @@ -577,7 +579,7 @@ const kRegularTextureFormatInfo = formatTableWithDefaults({
// because one aspect can be sized and one can be unsized. This should be cleaned up, but is kept
// this way during a migration phase.
const kSizedDepthStencilFormatInfo = formatTableWithDefaults({
defaults: { blockWidth: 1, blockHeight: 1, multisample: true },
defaults: { blockWidth: 1, blockHeight: 1, multisample: true, texture3D: false },
table: {
stencil8: {
stencil: {
Expand Down Expand Up @@ -615,7 +617,7 @@ const kSizedDepthStencilFormatInfo = formatTableWithDefaults({
},
} as const);
const kUnsizedDepthStencilFormatInfo = formatTableWithDefaults({
defaults: { blockWidth: 1, blockHeight: 1, multisample: true },
defaults: { blockWidth: 1, blockHeight: 1, multisample: true, texture3D: false },
table: {
depth24plus: {
depth: {
Expand Down Expand Up @@ -673,6 +675,7 @@ const kBCTextureFormatInfo = formatTableWithDefaults({
blockHeight: 4,
multisample: false,
feature: 'texture-compression-bc',
texture3D: true,
},
table: {
'bc1-rgba-unorm': {
Expand Down Expand Up @@ -852,6 +855,7 @@ const kETC2TextureFormatInfo = formatTableWithDefaults({
blockHeight: 4,
multisample: false,
feature: 'texture-compression-etc2',
texture3D: false,
},
table: {
'etc2-rgb8unorm': {
Expand Down Expand Up @@ -981,6 +985,7 @@ const kASTCTextureFormatInfo = formatTableWithDefaults({
defaults: {
multisample: false,
feature: 'texture-compression-astc',
texture3D: false,
},
table: {
'astc-4x4-unorm': {
Expand Down Expand Up @@ -1737,9 +1742,9 @@ export function textureDimensionAndFormatCompatible(
format: GPUTextureFormat
): boolean {
const info = kAllTextureFormatInfo[format];
return !(
(dimension === '1d' || dimension === '3d') &&
(info.blockWidth > 1 || info.depth || info.stencil)
return (
!(dimension === '1d' && (info.blockWidth > 1 || info.depth || info.stencil)) &&
!(dimension === '3d' && !info.texture3D)
);
}

Expand Down
Loading