@@ -7,13 +7,22 @@ import { assert, unreachable } from '../../../../../common/util/util.js';
7
7
import { kTextureAspects , kTextureDimensions } from '../../../../capability_info.js' ;
8
8
import { GPUConst } from '../../../../constants.js' ;
9
9
import {
10
- kTextureFormatInfo ,
11
10
kUncompressedTextureFormats ,
12
11
textureDimensionAndFormatCompatible ,
13
12
UncompressedTextureFormat ,
14
13
EncodableTextureFormat ,
14
+ isColorTextureFormat ,
15
+ isDepthTextureFormat ,
16
+ isStencilTextureFormat ,
17
+ isDepthOrStencilTextureFormat ,
18
+ isTextureFormatPossiblyUsableAsRenderAttachment ,
19
+ isTextureFormatPossiblyStorageReadable ,
20
+ isTextureFormatPossiblyMultisampled ,
21
+ canCopyAllAspectsOfTextureFormat ,
22
+ isTextureFormatColorRenderable ,
23
+ isTextureFormatPossiblyUsableAsColorRenderAttachment ,
15
24
} from '../../../../format_info.js' ;
16
- import { GPUTest , GPUTestSubcaseBatchState } from '../../../../gpu_test.js' ;
25
+ import { AllFeaturesMaxLimitsGPUTest , GPUTestSubcaseBatchState } from '../../../../gpu_test.js' ;
17
26
import { virtualMipSize } from '../../../../util/texture/base.js' ;
18
27
import { createTextureUploadBuffer } from '../../../../util/texture/layout.js' ;
19
28
import { BeginEndRange , SubresourceRange } from '../../../../util/texture/subresource.js' ;
@@ -115,14 +124,6 @@ const initializedStateAsStencil = {
115
124
[ InitializedState . Canary ] : 42 ,
116
125
} ;
117
126
118
- function allAspectsCopyDst ( info : ( typeof kTextureFormatInfo ) [ UncompressedTextureFormat ] ) {
119
- return (
120
- ( ! info . color || info . color . copyDst ) &&
121
- ( ! info . depth || info . depth . copyDst ) &&
122
- ( ! info . stencil || info . stencil . copyDst )
123
- ) ;
124
- }
125
-
126
127
export function getRequiredTextureUsage (
127
128
format : UncompressedTextureFormat ,
128
129
sampleCount : number ,
@@ -167,18 +168,22 @@ export function getRequiredTextureUsage(
167
168
usage |= GPUConst . TextureUsage . RENDER_ATTACHMENT ;
168
169
}
169
170
170
- const info = kTextureFormatInfo [ format ] ;
171
- if ( ! allAspectsCopyDst ( info ) ) {
171
+ if ( ! canCopyAllAspectsOfTextureFormat ( format ) ) {
172
172
// Copies are not possible. We need OutputAttachment to initialize
173
173
// canary data.
174
- if ( info . color ) assert ( ! ! info . colorRender , 'not implemented for non-renderable color' ) ;
174
+ if ( isColorTextureFormat ( format ) ) {
175
+ assert (
176
+ isTextureFormatPossiblyUsableAsColorRenderAttachment ( format ) ,
177
+ 'not implemented for non-renderable color'
178
+ ) ;
179
+ }
175
180
usage |= GPUConst . TextureUsage . RENDER_ATTACHMENT ;
176
181
}
177
182
178
183
return usage ;
179
184
}
180
185
181
- export class TextureZeroInitTest extends GPUTest {
186
+ export class TextureZeroInitTest extends AllFeaturesMaxLimitsGPUTest {
182
187
readonly stateToTexelComponents : { [ k in InitializedState ] : PerTexelComponent < number > } ;
183
188
184
189
private p : TextureZeroParams ;
@@ -302,7 +307,7 @@ export class TextureZeroInitTest extends GPUTest {
302
307
'all' ,
303
308
subresourceRange
304
309
) ) {
305
- if ( kTextureFormatInfo [ this . p . format ] . color ) {
310
+ if ( isColorTextureFormat ( this . p . format ) ) {
306
311
commandEncoder
307
312
. beginRenderPass ( {
308
313
colorAttachments : [
@@ -319,12 +324,12 @@ export class TextureZeroInitTest extends GPUTest {
319
324
const depthStencilAttachment : GPURenderPassDepthStencilAttachment = {
320
325
view : texture . createView ( viewDescriptor ) ,
321
326
} ;
322
- if ( kTextureFormatInfo [ this . p . format ] . depth ) {
327
+ if ( isDepthTextureFormat ( this . p . format ) ) {
323
328
depthStencilAttachment . depthClearValue = initializedStateAsDepth [ state ] ;
324
329
depthStencilAttachment . depthLoadOp = 'clear' ;
325
330
depthStencilAttachment . depthStoreOp = 'store' ;
326
331
}
327
- if ( kTextureFormatInfo [ this . p . format ] . stencil ) {
332
+ if ( isStencilTextureFormat ( this . p . format ) ) {
328
333
depthStencilAttachment . stencilClearValue = initializedStateAsStencil [ state ] ;
329
334
depthStencilAttachment . stencilLoadOp = 'clear' ;
330
335
depthStencilAttachment . stencilStoreOp = 'store' ;
@@ -347,7 +352,6 @@ export class TextureZeroInitTest extends GPUTest {
347
352
state : InitializedState ,
348
353
subresourceRange : SubresourceRange
349
354
) : void {
350
- assert ( this . p . format in kTextureFormatInfo ) ;
351
355
const format = this . p . format as EncodableTextureFormat ;
352
356
353
357
const firstSubresource = subresourceRange . each ( ) . next ( ) . value ;
@@ -394,11 +398,15 @@ export class TextureZeroInitTest extends GPUTest {
394
398
state : InitializedState ,
395
399
subresourceRange : SubresourceRange
396
400
) : void {
397
- const info = kTextureFormatInfo [ this . p . format ] ;
398
- if ( this . p . sampleCount > 1 || ! allAspectsCopyDst ( info ) ) {
401
+ if ( this . p . sampleCount > 1 || ! canCopyAllAspectsOfTextureFormat ( this . p . format ) ) {
399
402
// Copies to multisampled textures not yet specified.
400
403
// Use a storeOp for now.
401
- if ( info . color ) assert ( ! ! info . colorRender , 'not implemented for non-renderable color' ) ;
404
+ if ( isColorTextureFormat ( this . p . format ) ) {
405
+ assert (
406
+ isTextureFormatColorRenderable ( this . device , this . p . format ) ,
407
+ 'not implemented for non-renderable color'
408
+ ) ;
409
+ }
402
410
this . initializeWithStoreOp ( state , texture , subresourceRange ) ;
403
411
} else {
404
412
this . initializeWithCopy ( texture , state , subresourceRange ) ;
@@ -410,7 +418,7 @@ export class TextureZeroInitTest extends GPUTest {
410
418
commandEncoder . pushDebugGroup ( 'discardTexture' ) ;
411
419
412
420
for ( const desc of this . generateTextureViewDescriptorsForRendering ( 'all' , subresourceRange ) ) {
413
- if ( kTextureFormatInfo [ this . p . format ] . color ) {
421
+ if ( isColorTextureFormat ( this . p . format ) ) {
414
422
commandEncoder
415
423
. beginRenderPass ( {
416
424
colorAttachments : [
@@ -426,11 +434,11 @@ export class TextureZeroInitTest extends GPUTest {
426
434
const depthStencilAttachment : GPURenderPassDepthStencilAttachment = {
427
435
view : texture . createView ( desc ) ,
428
436
} ;
429
- if ( kTextureFormatInfo [ this . p . format ] . depth ) {
437
+ if ( isDepthTextureFormat ( this . p . format ) ) {
430
438
depthStencilAttachment . depthLoadOp = 'load' ;
431
439
depthStencilAttachment . depthStoreOp = 'discard' ;
432
440
}
433
- if ( kTextureFormatInfo [ this . p . format ] . stencil ) {
441
+ if ( isStencilTextureFormat ( this . p . format ) ) {
434
442
depthStencilAttachment . stencilLoadOp = 'load' ;
435
443
depthStencilAttachment . stencilStoreOp = 'discard' ;
436
444
}
@@ -446,6 +454,19 @@ export class TextureZeroInitTest extends GPUTest {
446
454
commandEncoder . popDebugGroup ( ) ;
447
455
this . queue . submit ( [ commandEncoder . finish ( ) ] ) ;
448
456
}
457
+
458
+ skipIfTextureFormatNotSupportedForTest ( params : TextureZeroParams ) {
459
+ const { format, sampleCount, uninitializeMethod, readMethod } = params ;
460
+ this . skipIfTextureFormatNotSupported ( format ) ;
461
+
462
+ const usage = getRequiredTextureUsage ( format , sampleCount , uninitializeMethod , readMethod ) ;
463
+
464
+ this . skipIfTextureFormatDoesNotSupportUsage ( usage , format ) ;
465
+
466
+ if ( sampleCount > 1 ) {
467
+ this . skipIfTextureFormatNotMultisampled ( format ) ;
468
+ }
469
+ }
449
470
}
450
471
451
472
export const kTestParams = kUnitCaseParamsBuilder
@@ -463,16 +484,18 @@ export const kTestParams = kUnitCaseParamsBuilder
463
484
. beginSubcases ( )
464
485
. combine ( 'aspect' , kTextureAspects )
465
486
. unless ( ( { readMethod, format, aspect } ) => {
466
- const info = kTextureFormatInfo [ format ] ;
487
+ const hasColor = isColorTextureFormat ( format ) ;
488
+ const hasDepth = isDepthTextureFormat ( format ) ;
489
+ const hasStencil = isStencilTextureFormat ( format ) ;
467
490
return (
468
- ( readMethod === ReadMethod . DepthTest && ( ! info . depth || aspect === 'stencil-only' ) ) ||
469
- ( readMethod === ReadMethod . StencilTest && ( ! info . stencil || aspect === 'depth-only' ) ) ||
470
- ( readMethod === ReadMethod . ColorBlending && ! info . color ) ||
491
+ ( readMethod === ReadMethod . DepthTest && ( ! hasDepth || aspect === 'stencil-only' ) ) ||
492
+ ( readMethod === ReadMethod . StencilTest && ( ! hasStencil || aspect === 'depth-only' ) ) ||
493
+ ( readMethod === ReadMethod . ColorBlending && ! hasColor ) ||
471
494
// [1]: Test with depth/stencil sampling
472
- ( readMethod === ReadMethod . Sample && ( ! ! info . depth || ! ! info . stencil ) ) ||
473
- ( aspect === 'depth-only' && ! info . depth ) ||
474
- ( aspect === 'stencil-only' && ! info . stencil ) ||
475
- ( aspect === 'all' && ! ! info . depth && ! ! info . stencil ) ||
495
+ ( readMethod === ReadMethod . Sample && ( hasDepth || hasStencil ) ) ||
496
+ ( aspect === 'depth-only' && ! hasDepth ) ||
497
+ ( aspect === 'stencil-only' && ! hasStencil ) ||
498
+ ( aspect === 'all' && ! ! hasDepth && ! ! hasStencil ) ||
476
499
// Cannot copy from a packed depth format.
477
500
// [2]: Test copying out of the stencil aspect.
478
501
( ( readMethod === ReadMethod . CopyToBuffer || readMethod === ReadMethod . CopyToTexture ) &&
@@ -493,12 +516,10 @@ export const kTestParams = kUnitCaseParamsBuilder
493
516
. unless ( ( { sampleCount, mipLevelCount } ) => sampleCount > 1 && mipLevelCount > 1 )
494
517
. combine ( 'uninitializeMethod' , kUninitializeMethods )
495
518
. unless ( ( { dimension, readMethod, uninitializeMethod, format, sampleCount } ) => {
496
- const formatInfo = kTextureFormatInfo [ format ] ;
497
519
return (
498
520
dimension !== '2d' &&
499
521
( sampleCount > 1 ||
500
- ! ! formatInfo . depth ||
501
- ! ! formatInfo . stencil ||
522
+ isDepthOrStencilTextureFormat ( format ) ||
502
523
readMethod === ReadMethod . DepthTest ||
503
524
readMethod === ReadMethod . StencilTest ||
504
525
readMethod === ReadMethod . ColorBlending ||
@@ -521,14 +542,13 @@ export const kTestParams = kUnitCaseParamsBuilder
521
542
. unless ( ( { sampleCount, layerCount } ) => sampleCount > 1 && layerCount > 1 )
522
543
. unless ( ( { format, sampleCount, uninitializeMethod, readMethod } ) => {
523
544
const usage = getRequiredTextureUsage ( format , sampleCount , uninitializeMethod , readMethod ) ;
524
- const info = kTextureFormatInfo [ format ] ;
525
545
526
546
return (
527
547
( ( usage & GPUConst . TextureUsage . RENDER_ATTACHMENT ) !== 0 &&
528
- info . color &&
529
- ! info . colorRender ) ||
530
- ( ( usage & GPUConst . TextureUsage . STORAGE_BINDING ) !== 0 && ! info . color ?. storage ) ||
531
- ( sampleCount > 1 && ! info . multisample )
548
+ ! isTextureFormatPossiblyUsableAsRenderAttachment ( format ) ) ||
549
+ ( ( usage & GPUConst . TextureUsage . STORAGE_BINDING ) !== 0 &&
550
+ ! isTextureFormatPossiblyStorageReadable ( format ) ) ||
551
+ ( sampleCount > 1 && ! isTextureFormatPossiblyMultisampled ( format ) )
532
552
) ;
533
553
} )
534
554
. combine ( 'nonPowerOfTwo' , [ false , true ] )
0 commit comments