@@ -1214,3 +1214,56 @@ g.test('viewFormats')
12141214 } ) ;
12151215 } , ! compatible ) ;
12161216 } ) ;
1217+
1218+ g . test ( 'transient_viewFormats' )
1219+ . desc ( `Test that viewFormats is not allowed with TRANSIENT_ATTACHMENT textures.` )
1220+ . params ( u =>
1221+ u
1222+ // Just test rgba8unorm formats as this check doesn't care about what the format is.
1223+ . combineWithParams ( [
1224+ { format : 'rgba8unorm' , _otherFormat : 'rgba8unorm-srgb' } ,
1225+ { format : 'rgba8unorm-srgb' , _otherFormat : 'rgba8unorm' } ,
1226+ ] as const )
1227+ . beginSubcases ( )
1228+ . expandWithParams ( ( { format, _otherFormat } ) => [
1229+ // Control cases
1230+ { useTransient : true , viewFormat : undefined } ,
1231+ { useTransient : false , viewFormat : format } ,
1232+ { useTransient : false , viewFormat : _otherFormat } ,
1233+ // Invalid cases
1234+ { useTransient : true , viewFormat : format } ,
1235+ { useTransient : true , viewFormat : _otherFormat } ,
1236+ ] )
1237+ )
1238+ . fn ( t => {
1239+ const { format, viewFormat, useTransient } = t . params ;
1240+ if ( viewFormat && ! textureFormatsAreViewCompatible ( t . device . features , format , viewFormat ) ) {
1241+ t . skip ( `"${ format } " and "${ viewFormat } " are not view-compatible` ) ;
1242+ }
1243+
1244+ const { blockWidth, blockHeight } = getBlockInfoForTextureFormat ( format ) ;
1245+
1246+ const invalid = useTransient && viewFormat !== undefined ;
1247+ let tex : GPUTexture ;
1248+ t . expectValidationError ( ( ) => {
1249+ tex = t . createTextureTracked ( {
1250+ format,
1251+ size : [ blockWidth , blockHeight ] ,
1252+ usage :
1253+ GPUConst . TextureUsage . RENDER_ATTACHMENT |
1254+ ( useTransient ? GPUConst . TextureUsage . TRANSIENT_ATTACHMENT : 0 ) ,
1255+ // Doesn't matter what formats we request, TRANSIENT_ATTACHMENT doesn't allow it.
1256+ // So we use [format] since that's otherwise ALWAYS valid regardless of format.
1257+ viewFormats : viewFormat ? [ viewFormat ] : undefined ,
1258+ } ) ;
1259+ } , invalid ) ;
1260+
1261+ if ( invalid ) {
1262+ // When we reach here the texture should be invalid, so creating a view should be invalid.
1263+ // But try it anyway just to see what happens - if the browser had a bug above, this could
1264+ // issue a bad command to the backend API.
1265+ t . expectValidationError ( ( ) => {
1266+ tex . createView ( { format : viewFormat } ) ;
1267+ } , true ) ;
1268+ }
1269+ } ) ;
0 commit comments