@@ -43,13 +43,14 @@ import {
43
43
AttachmentType , LightInfo ,
44
44
QueueHint , ResourceResidency , SceneFlags , UpdateFrequency ,
45
45
} from './types' ;
46
- import { Vec4 , geometry , toRadian , cclegacy } from '../../core' ;
46
+ import { Vec4 , geometry , toRadian , cclegacy , RecyclePool } from '../../core' ;
47
47
import { RenderWindow } from '../../render-scene/core/render-window' ;
48
48
import { RasterPass , RenderData , RenderGraph } from './render-graph' ;
49
49
import { WebPipeline } from './web-pipeline' ;
50
50
import { DescriptorSetData , LayoutGraphData } from './layout-graph' ;
51
51
import { AABB } from '../../core/geometry' ;
52
52
import { getUBOTypeCount } from './utils' ;
53
+ import { init } from '.' ;
53
54
54
55
const _rangedDirLightBoundingBox = new AABB ( 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.5 ) ;
55
56
const _tmpBoundingBox = new AABB ( ) ;
@@ -860,37 +861,104 @@ export function getSubpassOrPassID (sceneId: number, rg: RenderGraph, lg: Layout
860
861
return layoutId ;
861
862
}
862
863
864
+ export class RenderPassMergeInfo {
865
+ constructor (
866
+ public combineHash : number = 0 ,
867
+ public needBeginRP : boolean = true ,
868
+ public needEndRP : boolean = true ,
869
+ ) { }
870
+ init (
871
+ combineHash : number ,
872
+ needBeginRP : boolean = true ,
873
+ needEndRP : boolean = true ,
874
+ ) : void {
875
+ this . combineHash = combineHash ;
876
+ this . needBeginRP = needBeginRP ;
877
+ this . needEndRP = needEndRP ;
878
+ }
879
+ }
880
+
881
+ const passOrders : RasterPass [ ] = [ ] ;
882
+ const rpCombineMap : Map < RasterPass , number > = new Map ( ) ;
883
+ export const rpMergeInfos : Map < RasterPass , RenderPassMergeInfo > = new Map ( ) ;
884
+ const rpMergeInfoPool = new RecyclePool < RenderPassMergeInfo > ( ( ) : RenderPassMergeInfo => new RenderPassMergeInfo ( ) , 16 ) ;
885
+ export function resetPassMGState ( ) : void {
886
+ rpMergeInfoPool . reset ( ) ;
887
+ rpMergeInfos . clear ( ) ;
888
+ rpCombineMap . clear ( ) ;
889
+ passOrders . length = 0 ;
890
+ }
891
+ export function processPassMG ( pass : RasterPass ) : void {
892
+ const currCHash = rpCombineMap . get ( pass ) ! ;
893
+ const currRPInfo = rpMergeInfoPool . add ( ) ;
894
+ if ( ! rpMergeInfos . has ( pass ) ) {
895
+ rpMergeInfos . set ( pass , currRPInfo ) ;
896
+ }
897
+ currRPInfo . init ( currCHash ) ;
898
+ const poLen = passOrders . length ;
899
+ if ( poLen !== 0 ) {
900
+ let isLoadOP = false ;
901
+ for ( const [ _ , raster ] of pass . rasterViews ) {
902
+ if ( raster . loadOp === LoadOp . LOAD ) {
903
+ isLoadOP = true ;
904
+ break ;
905
+ }
906
+ }
907
+ const prevPass = passOrders [ poLen - 1 ] ;
908
+ if ( isLoadOP && rpCombineMap . get ( prevPass ) === currCHash ) {
909
+ const prevInfo = rpMergeInfos . get ( prevPass ) ! ;
910
+ prevInfo . needEndRP = false ;
911
+ currRPInfo . needBeginRP = false ;
912
+ }
913
+ }
914
+ passOrders . push ( pass ) ;
915
+ }
916
+
863
917
export function genHashValue ( pass : RasterPass ) : void {
864
- let hashCode = '' ;
918
+ const hashCodeParts : string [ ] = [ ] ;
919
+ const combineHashParts : string [ ] = [ ] ;
865
920
for ( const [ name , raster ] of pass . rasterViews ) {
866
- hashCode += hashCombineKey ( name ) ;
867
- hashCode += hashCombineKey ( raster . slotName ) ;
868
- hashCode += hashCombineKey ( raster . accessType ) ;
869
- hashCode += hashCombineKey ( raster . attachmentType ) ;
870
- hashCode += hashCombineKey ( raster . loadOp ) ;
871
- hashCode += hashCombineKey ( raster . storeOp ) ;
872
- hashCode += hashCombineKey ( raster . clearFlags ) ;
873
- hashCode += hashCombineKey ( raster . clearColor . x ) ;
874
- hashCode += hashCombineKey ( raster . clearColor . y ) ;
875
- hashCode += hashCombineKey ( raster . clearColor . z ) ;
876
- hashCode += hashCombineKey ( raster . clearColor . w ) ;
877
- hashCode += hashCombineKey ( raster . slotID ) ;
878
- hashCode += hashCombineKey ( raster . shaderStageFlags ) ;
879
- }
880
- for ( const [ name , computes ] of pass . computeViews ) {
881
- hashCode += hashCombineKey ( name ) ;
882
- for ( const compute of computes ) {
883
- hashCode += hashCombineKey ( compute . name ) ;
884
- hashCode += hashCombineKey ( compute . accessType ) ;
885
- hashCode += hashCombineKey ( compute . clearFlags ) ;
886
- hashCode += hashCombineKey ( compute . clearValueType ) ;
887
- hashCode += hashCombineKey ( compute . clearValue . x ) ;
888
- hashCode += hashCombineKey ( compute . clearValue . y ) ;
889
- hashCode += hashCombineKey ( compute . clearValue . z ) ;
890
- hashCode += hashCombineKey ( compute . clearValue . w ) ;
891
- hashCode += hashCombineKey ( compute . shaderStageFlags ) ;
921
+ const commonParts = [
922
+ hashCombineKey ( name ) ,
923
+ hashCombineKey ( raster . slotName ) ,
924
+ hashCombineKey ( raster . accessType ) ,
925
+ hashCombineKey ( raster . attachmentType ) ,
926
+ hashCombineKey ( raster . storeOp ) ,
927
+ hashCombineKey ( raster . clearFlags ) ,
928
+ hashCombineKey ( raster . slotID ) ,
929
+ hashCombineKey ( raster . shaderStageFlags ) ,
930
+ ] ;
931
+
932
+ const extraParts = [
933
+ hashCombineKey ( raster . loadOp ) ,
934
+ hashCombineKey ( raster . clearColor . x ) ,
935
+ hashCombineKey ( raster . clearColor . y ) ,
936
+ hashCombineKey ( raster . clearColor . z ) ,
937
+ hashCombineKey ( raster . clearColor . w ) ,
938
+ ] ;
939
+
940
+ const fullHash = commonParts . concat ( extraParts ) . join ( '' ) ;
941
+ const combineHash = commonParts . join ( '' ) ;
942
+
943
+ hashCodeParts . push ( fullHash ) ;
944
+ combineHashParts . push ( combineHash ) ;
945
+ }
946
+
947
+ const subpassGraph = pass . subpassGraph ;
948
+ const subpasses = subpassGraph . _subpasses ;
949
+ for ( const subpass of subpasses ) {
950
+ const resolvePairs = subpass . resolvePairs ;
951
+ for ( const resolve of resolvePairs ) {
952
+ const commonParts = [
953
+ hashCombineKey ( resolve . source ) ,
954
+ hashCombineKey ( resolve . target ) ,
955
+ ] ;
956
+ const combineHash = commonParts . join ( '' ) ;
957
+ combineHashParts . push ( combineHash ) ;
892
958
}
893
959
}
894
- hashCode += hashCombineKey ( pass . showStatistics ? 1 : 0 ) ;
895
- pass . hashValue = hashCombineStr ( hashCode ) ;
960
+
961
+ pass . hashValue = hashCombineStr ( hashCodeParts . join ( '' ) ) ;
962
+ rpCombineMap . set ( pass , hashCombineStr ( combineHashParts . join ( '' ) ) ) ;
963
+ processPassMG ( pass ) ;
896
964
}
0 commit comments