@@ -369,10 +369,9 @@ class WebGPUBackend extends Backend {
369
369
renderTargetData . width !== renderTarget . width ||
370
370
renderTargetData . height !== renderTarget . height ||
371
371
renderTargetData . dimensions !== renderTarget . dimensions ||
372
- renderTargetData . activeMipmapLevel !== renderTarget . activeMipmapLevel ||
372
+ renderTargetData . activeMipmapLevel !== renderContext . activeMipmapLevel ||
373
373
renderTargetData . activeCubeFace !== renderContext . activeCubeFace ||
374
- renderTargetData . samples !== renderTarget . samples ||
375
- renderTargetData . loadOp !== colorAttachmentsConfig . loadOp
374
+ renderTargetData . samples !== renderTarget . samples
376
375
) {
377
376
378
377
descriptors = { } ;
@@ -384,23 +383,25 @@ class WebGPUBackend extends Backend {
384
383
const onDispose = ( ) => {
385
384
386
385
renderTarget . removeEventListener ( 'dispose' , onDispose ) ;
387
-
388
386
this . delete ( renderTarget ) ;
389
387
390
388
} ;
391
389
392
- renderTarget . addEventListener ( 'dispose' , onDispose ) ;
390
+ if ( renderTarget . hasEventListener ( 'dispose' , onDispose ) === false ) {
391
+
392
+ renderTarget . addEventListener ( 'dispose' , onDispose ) ;
393
+
394
+ }
393
395
394
396
}
395
397
396
398
const cacheKey = renderContext . getCacheKey ( ) ;
399
+ let descriptorBase = descriptors [ cacheKey ] ;
397
400
398
- let descriptor = descriptors [ cacheKey ] ;
399
-
400
- if ( descriptor === undefined ) {
401
+ if ( descriptorBase === undefined ) {
401
402
402
403
const textures = renderContext . textures ;
403
- const colorAttachments = [ ] ;
404
+ const textureViews = [ ] ;
404
405
405
406
let sliceIndex ;
406
407
@@ -448,53 +449,66 @@ class WebGPUBackend extends Backend {
448
449
449
450
}
450
451
451
- // only apply the user-defined clearValue to the first color attachment like in beginRender()
452
-
453
- let clearValue = { r : 0 , g : 0 , b : 0 , a : 1 } ;
454
-
455
- if ( i === 0 && colorAttachmentsConfig . clearValue ) {
456
-
457
- clearValue = colorAttachmentsConfig . clearValue ;
458
-
459
- }
460
-
461
- colorAttachments . push ( {
452
+ textureViews . push ( {
462
453
view,
463
- depthSlice : sliceIndex ,
464
454
resolveTarget,
465
- loadOp : colorAttachmentsConfig . loadOP || GPULoadOp . Load ,
466
- storeOp : colorAttachmentsConfig . storeOP || GPUStoreOp . Store ,
467
- clearValue : clearValue
455
+ depthSlice : sliceIndex
468
456
} ) ;
469
457
470
458
}
471
459
472
-
473
- descriptor = {
474
- colorAttachments,
475
- } ;
460
+ descriptorBase = { textureViews } ;
476
461
477
462
if ( renderContext . depth ) {
478
463
479
464
const depthTextureData = this . get ( renderContext . depthTexture ) ;
480
-
481
- const depthStencilAttachment = {
482
- view : depthTextureData . texture . createView ( )
483
- } ;
484
- descriptor . depthStencilAttachment = depthStencilAttachment ;
465
+ descriptorBase . depthStencilView = depthTextureData . texture . createView ( ) ;
485
466
486
467
}
487
468
488
- descriptors [ cacheKey ] = descriptor ;
469
+ descriptors [ cacheKey ] = descriptorBase ;
489
470
490
471
renderTargetData . width = renderTarget . width ;
491
472
renderTargetData . height = renderTarget . height ;
492
473
renderTargetData . samples = renderTarget . samples ;
493
474
renderTargetData . activeMipmapLevel = renderContext . activeMipmapLevel ;
494
475
renderTargetData . activeCubeFace = renderContext . activeCubeFace ;
495
476
renderTargetData . dimensions = renderTarget . dimensions ;
496
- renderTargetData . depthSlice = sliceIndex ;
497
- renderTargetData . loadOp = colorAttachments [ 0 ] . loadOp ;
477
+
478
+ }
479
+
480
+ const descriptor = {
481
+ colorAttachments : [ ]
482
+ } ;
483
+
484
+ // Apply dynamic properties to cached views
485
+ for ( let i = 0 ; i < descriptorBase . textureViews . length ; i ++ ) {
486
+
487
+ const viewInfo = descriptorBase . textureViews [ i ] ;
488
+
489
+ let clearValue = { r : 0 , g : 0 , b : 0 , a : 1 } ;
490
+ if ( i === 0 && colorAttachmentsConfig . clearValue ) {
491
+
492
+ clearValue = colorAttachmentsConfig . clearValue ;
493
+
494
+ }
495
+
496
+ descriptor . colorAttachments . push ( {
497
+ view : viewInfo . view ,
498
+ depthSlice : viewInfo . depthSlice ,
499
+ resolveTarget : viewInfo . resolveTarget ,
500
+ loadOp : colorAttachmentsConfig . loadOp || GPULoadOp . Load ,
501
+ storeOp : colorAttachmentsConfig . storeOp || GPUStoreOp . Store ,
502
+ clearValue : clearValue
503
+ } ) ;
504
+
505
+ }
506
+
507
+ if ( descriptorBase . depthStencilView ) {
508
+
509
+ descriptor . depthStencilAttachment = {
510
+ view : descriptorBase . depthStencilView
511
+ } ;
498
512
499
513
}
500
514
@@ -873,7 +887,6 @@ class WebGPUBackend extends Backend {
873
887
const renderer = this . renderer ;
874
888
875
889
let colorAttachments = [ ] ;
876
-
877
890
let depthStencilAttachment ;
878
891
let clearValue ;
879
892
@@ -917,29 +930,35 @@ class WebGPUBackend extends Backend {
917
930
supportsDepth = renderTargetContext . depth ;
918
931
supportsStencil = renderTargetContext . stencil ;
919
932
920
- if ( color ) {
933
+ const clearConfig = {
934
+ loadOp : color ? GPULoadOp . Clear : GPULoadOp . Load ,
935
+ clearValue : color ? clearValue : undefined
936
+ } ;
921
937
922
- const descriptor = this . _getRenderPassDescriptor ( renderTargetContext , { loadOp : GPULoadOp . Clear , clearValue } ) ;
938
+ if ( supportsDepth ) {
923
939
924
- colorAttachments = descriptor . colorAttachments ;
940
+ clearConfig . depthLoadOp = depth ? GPULoadOp . Clear : GPULoadOp . Load ;
941
+ clearConfig . depthClearValue = depth ? renderer . getClearDepth ( ) : undefined ;
942
+ clearConfig . depthStoreOp = GPUStoreOp . Store ;
925
943
926
944
}
927
945
928
- if ( supportsDepth || supportsStencil ) {
946
+ if ( supportsStencil ) {
929
947
930
- const depthTextureData = this . get ( renderTargetContext . depthTexture ) ;
931
-
932
- depthStencilAttachment = {
933
- view : depthTextureData . texture . createView ( )
934
- } ;
948
+ clearConfig . stencilLoadOp = stencil ? GPULoadOp . Clear : GPULoadOp . Load ;
949
+ clearConfig . stencilClearValue = stencil ? renderer . getClearStencil ( ) : undefined ;
950
+ clearConfig . stencilStoreOp = GPUStoreOp . Store ;
935
951
936
952
}
937
953
938
- }
954
+ const descriptor = this . _getRenderPassDescriptor ( renderTargetContext , clearConfig ) ;
939
955
940
- //
956
+ colorAttachments = descriptor . colorAttachments ;
957
+ depthStencilAttachment = descriptor . depthStencilAttachment ;
958
+
959
+ }
941
960
942
- if ( supportsDepth ) {
961
+ if ( supportsDepth && depthStencilAttachment && depthStencilAttachment . depthLoadOp === undefined ) {
943
962
944
963
if ( depth ) {
945
964
@@ -958,7 +977,7 @@ class WebGPUBackend extends Backend {
958
977
959
978
//
960
979
961
- if ( supportsStencil ) {
980
+ if ( supportsStencil && depthStencilAttachment && depthStencilAttachment . stencilLoadOp === undefined ) {
962
981
963
982
if ( stencil ) {
964
983
0 commit comments