Skip to content

Commit

Permalink
Update validation tests for 3D textures with BC compression
Browse files Browse the repository at this point in the history
Partially fixes gpuweb#3761

Please let me know if I missed or overlooked anything. Your guidance would be appreciated. Thank you!
  • Loading branch information
mehmetoguzderin committed Jun 1, 2024
1 parent 5c23d90 commit a344bb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/webgpu/api/validation/createTexture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ 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. Note that compressed formats are not valid for 1D dimension type with only partial support for 3D dimension type and depth/stencil formats are not valid for 1D/3D dimension types.`
)
.params(u =>
u //
Expand Down Expand Up @@ -220,7 +220,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 +458,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 @@ -476,8 +475,10 @@ g.test('texture_size,default_value_and_smallest_size,compressed_format')
})
)
.beforeAllSubcases(t => {
const { format } = t.params;
const { dimension, format } = t.params;
const info = kTextureFormatInfo[format];
// Skip if the dimension is 3D and format is not compatible
t.skipIf(dimension === '3d' && !info.texture3D, `${format} is not compatible with 3D texture`);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(t => {
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

0 comments on commit a344bb5

Please sign in to comment.