Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1379f26

Browse files
authored
Adds ETC2 and ASTC types to enable testing when relevant. (gpuweb#805)
- Modifies texture sizes to be functions of the block sizes to generalize the tests.
1 parent 6a232fd commit 1379f26

File tree

6 files changed

+118
-65
lines changed

6 files changed

+118
-65
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@types/offscreencanvas": "^2019.6.2",
4141
"@types/serve-index": "^1.9.1",
4242
"@typescript-eslint/parser": "^4.22.0",
43-
"@webgpu/types": "^0.1.6",
43+
"@webgpu/types": "^0.1.7",
4444
"ansi-colors": "4.1.1",
4545
"babel-plugin-add-header-comment": "^1.0.3",
4646
"babel-plugin-const-enum": "^1.0.1",

src/webgpu/api/operation/command_buffer/copyTextureToTexture.spec.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -665,51 +665,42 @@ g.test('color_textures,compressed,non_array')
665665
u
666666
.combine('format', kCompressedTextureFormats)
667667
.beginSubcases()
668-
.combine('textureSize', [
669-
// The heights and widths are all power of 2
670-
{
671-
srcTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
672-
dstTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
673-
},
674-
// The virtual width of the source texture at mipmap level 2 (15) is not a multiple of 4
675-
{
676-
srcTextureSize: { width: 60, height: 32, depthOrArrayLayers: 1 },
677-
dstTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
678-
},
668+
.combine('textureSizeInBlocks', [
669+
// The heights and widths in blocks are all power of 2
670+
{ src: { width: 16, height: 8 }, dst: { width: 16, height: 8 } },
671+
// The virtual width of the source texture at mipmap level 2 (15) is not a multiple of 4 blocks
672+
{ src: { width: 15, height: 8 }, dst: { width: 16, height: 8 } },
679673
// The virtual width of the destination texture at mipmap level 2 (15) is not a multiple
680-
// of 4
681-
{
682-
srcTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
683-
dstTextureSize: { width: 60, height: 32, depthOrArrayLayers: 1 },
684-
},
685-
// The virtual height of the source texture at mipmap level 2 (13) is not a multiple of 4
686-
{
687-
srcTextureSize: { width: 64, height: 52, depthOrArrayLayers: 1 },
688-
dstTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
689-
},
674+
// of 4 blocks
675+
{ src: { width: 16, height: 8 }, dst: { width: 15, height: 8 } },
676+
// The virtual height of the source texture at mipmap level 2 (13) is not a multiple of 4 blocks
677+
{ src: { width: 16, height: 13 }, dst: { width: 16, height: 8 } },
690678
// The virtual height of the destination texture at mipmap level 2 (13) is not a
691-
// multiple of 4
692-
{
693-
srcTextureSize: { width: 64, height: 32, depthOrArrayLayers: 1 },
694-
dstTextureSize: { width: 64, height: 52, depthOrArrayLayers: 1 },
695-
},
696-
// None of the widths or heights are power of 2
697-
{
698-
srcTextureSize: { width: 60, height: 52, depthOrArrayLayers: 1 },
699-
dstTextureSize: { width: 60, height: 52, depthOrArrayLayers: 1 },
700-
},
679+
// multiple of 4 blocks
680+
{ src: { width: 16, height: 8 }, dst: { width: 16, height: 13 } },
681+
// None of the widths or heights in blocks are power of 2
682+
{ src: { width: 15, height: 13 }, dst: { width: 15, height: 13 } },
701683
])
702684
.combine('copyBoxOffsets', kCopyBoxOffsetsForWholeDepth)
703685
.combine('srcCopyLevel', [0, 2])
704686
.combine('dstCopyLevel', [0, 2])
705687
)
706688
.fn(async t => {
707-
const { textureSize, format, copyBoxOffsets, srcCopyLevel, dstCopyLevel } = t.params;
689+
const { textureSizeInBlocks, format, copyBoxOffsets, srcCopyLevel, dstCopyLevel } = t.params;
708690
await t.selectDeviceOrSkipTestCase(kTextureFormatInfo[format].feature);
691+
const { blockWidth, blockHeight } = kTextureFormatInfo[format];
709692

710693
t.DoCopyTextureToTextureTest(
711-
textureSize.srcTextureSize,
712-
textureSize.dstTextureSize,
694+
{
695+
width: textureSizeInBlocks.src.width * blockWidth,
696+
height: textureSizeInBlocks.src.height * blockHeight,
697+
depthOrArrayLayers: 1,
698+
},
699+
{
700+
width: textureSizeInBlocks.dst.width * blockWidth,
701+
height: textureSizeInBlocks.dst.height * blockHeight,
702+
depthOrArrayLayers: 1,
703+
},
713704
format,
714705
copyBoxOffsets,
715706
srcCopyLevel,
@@ -769,30 +760,32 @@ g.test('color_textures,compressed,array')
769760
u
770761
.combine('format', kCompressedTextureFormats)
771762
.beginSubcases()
772-
.combine('textureSize', [
773-
// The heights and widths are all power of 2
774-
{
775-
srcTextureSize: { width: 8, height: 8, depthOrArrayLayers: 5 },
776-
dstTextureSize: { width: 8, height: 8, depthOrArrayLayers: 5 },
777-
},
778-
// None of the widths or heights are power of 2
779-
{
780-
srcTextureSize: { width: 60, height: 52, depthOrArrayLayers: 5 },
781-
dstTextureSize: { width: 60, height: 52, depthOrArrayLayers: 5 },
782-
},
763+
.combine('textureSizeInBlocks', [
764+
// The heights and widths in blocks are all power of 2
765+
{ src: { width: 2, height: 2 }, dst: { width: 2, height: 2 } },
766+
// None of the widths or heights in blocks are power of 2
767+
{ src: { width: 15, height: 13 }, dst: { width: 15, height: 13 } },
783768
])
784-
785769
.combine('copyBoxOffsets', kCopyBoxOffsetsFor2DArrayTextures)
786770
.combine('srcCopyLevel', [0, 2])
787771
.combine('dstCopyLevel', [0, 2])
788772
)
789773
.fn(async t => {
790-
const { textureSize, format, copyBoxOffsets, srcCopyLevel, dstCopyLevel } = t.params;
774+
const { textureSizeInBlocks, format, copyBoxOffsets, srcCopyLevel, dstCopyLevel } = t.params;
791775
await t.selectDeviceOrSkipTestCase(kTextureFormatInfo[format].feature);
776+
const { blockWidth, blockHeight } = kTextureFormatInfo[format];
792777

793778
t.DoCopyTextureToTextureTest(
794-
textureSize.srcTextureSize,
795-
textureSize.dstTextureSize,
779+
{
780+
width: textureSizeInBlocks.src.width * blockWidth,
781+
height: textureSizeInBlocks.src.height * blockHeight,
782+
depthOrArrayLayers: 5,
783+
},
784+
{
785+
width: textureSizeInBlocks.dst.width * blockWidth,
786+
height: textureSizeInBlocks.dst.height * blockHeight,
787+
depthOrArrayLayers: 5,
788+
},
796789
format,
797790
copyBoxOffsets,
798791
srcCopyLevel,

src/webgpu/api/validation/createTexture.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,6 @@ g.test('texture_size,2d_texture,compressed_format')
506506
const info = kTextureFormatInfo[format];
507507
await t.selectDeviceOrSkipTestCase(info.feature);
508508

509-
assert(
510-
DefaultLimits.maxTextureDimension2D % info.blockWidth === 0 &&
511-
DefaultLimits.maxTextureDimension2D % info.blockHeight === 0
512-
);
513-
514509
const descriptor: GPUTextureDescriptor = {
515510
size,
516511
dimension,

src/webgpu/api/validation/encoding/cmds/copyTextureToTexture.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,13 @@ g.test('copy_ranges_with_compressed_texture_formats')
586586
.fn(async t => {
587587
const { format, copyBoxOffsets, srcCopyLevel, dstCopyLevel } = t.params;
588588
await t.selectDeviceOrSkipTestCase(kTextureFormatInfo[format].feature);
589+
const { blockWidth, blockHeight } = kTextureFormatInfo[format];
589590

590-
const kTextureSize = { width: 60, height: 48, depthOrArrayLayers: 3 };
591+
const kTextureSize = {
592+
width: 15 * blockWidth,
593+
height: 12 * blockHeight,
594+
depthOrArrayLayers: 3,
595+
};
591596
const kMipLevelCount = 4;
592597

593598
const srcTexture = t.device.createTexture({

src/webgpu/capability_info.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ const kUnsizedDepthStencilFormatInfo = /* prettier-ignore */ makeTable(kTexFmtIn
125125
'depth24unorm-stencil8': [ , , , true, true, , , , 'depth', , , , 'depth24unorm-stencil8'],
126126
'depth32float-stencil8': [ , , , true, true, , , , 'depth', , , , 'depth32float-stencil8'],
127127
} as const);
128-
const kCompressedTextureFormatInfo = /* prettier-ignore */ makeTable(kTexFmtInfoHeader,
128+
129+
// Separated compressed formats by type
130+
const kBCTextureFormatInfo = /* prettier-ignore */ makeTable(kTexFmtInfoHeader,
129131
[ false, false, true, false, false, false, true, true, , , 4, 4, ] as const, {
132+
// Block Compression (BC) formats
130133
'bc1-rgba-unorm': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-bc'],
131134
'bc1-rgba-unorm-srgb': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-bc'],
132135
'bc2-rgba-unorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-bc'],
@@ -142,11 +145,58 @@ const kCompressedTextureFormatInfo = /* prettier-ignore */ makeTable(kTexFmtInfo
142145
'bc7-rgba-unorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-bc'],
143146
'bc7-rgba-unorm-srgb': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-bc'],
144147
} as const);
148+
const kETC2TextureFormatInfo = /* prettier-ignore */ makeTable(kTexFmtInfoHeader,
149+
[ false, false, true, false, false, false, true, true, , , 4, 4, ] as const, {
150+
// Ericsson Compression (ETC2) formats
151+
'etc2-rgb8unorm': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
152+
'etc2-rgb8unorm-srgb': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
153+
'etc2-rgb8a1unorm': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
154+
'etc2-rgb8a1unorm-srgb': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
155+
'etc2-rgba8unorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-etc2'],
156+
'etc2-rgba8unorm-srgb': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-etc2'],
157+
'eac-r11unorm': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
158+
'eac-r11snorm': [ , , , , , , , , 'float', 8, 4, 4, 'texture-compression-etc2'],
159+
'eac-rg11unorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-etc2'],
160+
'eac-rg11snorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-etc2'],
161+
} as const);
162+
const kASTCTextureFormatInfo = /* prettier-ignore */ makeTable(kTexFmtInfoHeader,
163+
[ false, false, true, false, false, false, true, true, , , , , ] as const, {
164+
// Adaptable Scalable Compression (ASTC) formats
165+
'astc-4x4-unorm': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-astc'],
166+
'astc-4x4-unorm-srgb': [ , , , , , , , , 'float', 16, 4, 4, 'texture-compression-astc'],
167+
'astc-5x4-unorm': [ , , , , , , , , 'float', 16, 5, 4, 'texture-compression-astc'],
168+
'astc-5x4-unorm-srgb': [ , , , , , , , , 'float', 16, 5, 4, 'texture-compression-astc'],
169+
'astc-5x5-unorm': [ , , , , , , , , 'float', 16, 5, 5, 'texture-compression-astc'],
170+
'astc-5x5-unorm-srgb': [ , , , , , , , , 'float', 16, 5, 5, 'texture-compression-astc'],
171+
'astc-6x5-unorm': [ , , , , , , , , 'float', 16, 6, 5, 'texture-compression-astc'],
172+
'astc-6x5-unorm-srgb': [ , , , , , , , , 'float', 16, 6, 5, 'texture-compression-astc'],
173+
'astc-6x6-unorm': [ , , , , , , , , 'float', 16, 6, 6, 'texture-compression-astc'],
174+
'astc-6x6-unorm-srgb': [ , , , , , , , , 'float', 16, 6, 6, 'texture-compression-astc'],
175+
'astc-8x5-unorm': [ , , , , , , , , 'float', 16, 8, 5, 'texture-compression-astc'],
176+
'astc-8x5-unorm-srgb': [ , , , , , , , , 'float', 16, 8, 5, 'texture-compression-astc'],
177+
'astc-8x6-unorm': [ , , , , , , , , 'float', 16, 8, 6, 'texture-compression-astc'],
178+
'astc-8x6-unorm-srgb': [ , , , , , , , , 'float', 16, 8, 6, 'texture-compression-astc'],
179+
'astc-8x8-unorm': [ , , , , , , , , 'float', 16, 8, 8, 'texture-compression-astc'],
180+
'astc-8x8-unorm-srgb': [ , , , , , , , , 'float', 16, 8, 8, 'texture-compression-astc'],
181+
'astc-10x5-unorm': [ , , , , , , , , 'float', 16, 10, 5, 'texture-compression-astc'],
182+
'astc-10x5-unorm-srgb': [ , , , , , , , , 'float', 16, 10, 5, 'texture-compression-astc'],
183+
'astc-10x6-unorm': [ , , , , , , , , 'float', 16, 10, 6, 'texture-compression-astc'],
184+
'astc-10x6-unorm-srgb': [ , , , , , , , , 'float', 16, 10, 6, 'texture-compression-astc'],
185+
'astc-10x8-unorm': [ , , , , , , , , 'float', 16, 10, 8, 'texture-compression-astc'],
186+
'astc-10x8-unorm-srgb': [ , , , , , , , , 'float', 16, 10, 8, 'texture-compression-astc'],
187+
'astc-10x10-unorm': [ , , , , , , , , 'float', 16, 10, 10, 'texture-compression-astc'],
188+
'astc-10x10-unorm-srgb': [ , , , , , , , , 'float', 16, 10, 10, 'texture-compression-astc'],
189+
'astc-12x10-unorm': [ , , , , , , , , 'float', 16, 12, 10, 'texture-compression-astc'],
190+
'astc-12x10-unorm-srgb': [ , , , , , , , , 'float', 16, 12, 10, 'texture-compression-astc'],
191+
'astc-12x12-unorm': [ , , , , , , , , 'float', 16, 12, 12, 'texture-compression-astc'],
192+
'astc-12x12-unorm-srgb': [ , , , , , , , , 'float', 16, 12, 12, 'texture-compression-astc'],
193+
} as const);
145194

146195
// Definitions for use locally. To access the table entries, use `kTextureFormatInfo`.
147196

148197
// TODO: Consider generating the exports below programmatically by filtering the big list, instead
149198
// of using these local constants? Requires some type magic though.
199+
/* prettier-ignore */ const kCompressedTextureFormatInfo = { ...kBCTextureFormatInfo, ...kETC2TextureFormatInfo, ...kASTCTextureFormatInfo } as const;
150200
/* prettier-ignore */ const kColorTextureFormatInfo = { ...kRegularTextureFormatInfo, ...kCompressedTextureFormatInfo } as const;
151201
/* prettier-ignore */ const kEncodableTextureFormatInfo = { ...kRegularTextureFormatInfo, ...kSizedDepthStencilFormatInfo } as const;
152202
/* prettier-ignore */ const kSizedTextureFormatInfo = { ...kRegularTextureFormatInfo, ...kSizedDepthStencilFormatInfo, ...kCompressedTextureFormatInfo } as const;

src/webgpu/examples.spec.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,29 @@ Tests that a BC format passes validation iff the feature is enabled.`
249249
);
250250
});
251251

252-
g.test('gpu,with_texture_compression,etc')
252+
g.test('gpu,with_texture_compression,etc2')
253253
.desc(
254254
`Example of a test using a device descriptor.
255-
256-
TODO: Test that an ETC format passes validation iff the feature is enabled.`
255+
Tests that an ETC2 format passes validation iff the feature is enabled.`
257256
)
258-
.params(u => u.combine('textureCompressionETC', [false, true]))
257+
.params(u => u.combine('textureCompressionETC2', [false, true]))
259258
.fn(async t => {
260-
const { textureCompressionETC } = t.params;
259+
const { textureCompressionETC2 } = t.params;
261260

262-
if (textureCompressionETC) {
263-
await t.selectDeviceOrSkipTestCase('texture-compression-etc' as GPUFeatureName);
261+
if (textureCompressionETC2) {
262+
await t.selectDeviceOrSkipTestCase('texture-compression-etc2' as GPUFeatureName);
264263
}
265264

266-
// TODO: Should actually test createTexture with an ETC format here.
265+
const shouldError = !textureCompressionETC2;
266+
t.expectGPUError(
267+
'validation',
268+
() => {
269+
t.device.createTexture({
270+
format: 'etc2-rgb8unorm',
271+
size: [4, 4, 1],
272+
usage: GPUTextureUsage.TEXTURE_BINDING,
273+
});
274+
},
275+
shouldError
276+
);
267277
});

0 commit comments

Comments
 (0)