@@ -39,14 +39,6 @@ export function instancingCompareFn (l: InstancedBuffer, r: InstancedBuffer): nu
3939 return ( ls . hash - rs . hash ) || ( ls . shaderId - rs . shaderId ) ;
4040}
4141
42- // Combines a running hash `seed` with `value` into a single 32-bit integer.
43- // Mirrors the native `ccstd::hash_combine` formula so merge keys can be plain
44- // numbers instead of formatted strings, avoiding per-merge string allocation.
45- function hashCombine ( seed : number , value : number ) : number {
46- // eslint-disable-next-line no-bitwise
47- return ( seed ^ ( value + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ) ) ) | 0 ;
48- }
49-
5042export interface IInstancedItem {
5143 count : number ;
5244 capacity : number ;
@@ -74,7 +66,7 @@ export class InstancedBuffer {
7466 public sortRender : IRenderPass ;
7567 private declare _passPool : RecyclePool < IRenderPass > ;
7668 private declare _device : Device ;
77- private readonly _instanceMap = new Map < number , IInstancedItem [ ] > ( ) ;
69+ private readonly _instanceMap = new Map < string , IInstancedItem [ ] > ( ) ;
7870 constructor ( pass : Pass ) {
7971 this . _device = pass . device ;
8072 this . pass = pass ;
@@ -118,13 +110,9 @@ export class InstancedBuffer {
118110 this . sortRender . shaderId = shader . typedID ;
119111 this . sortRender . passIdx = passIdx ;
120112
121- let key = hashCombine ( 2 , sourceIA . indexBuffer ?. objectID ?? 0 ) ;
122- key = hashCombine ( key , lightingMap . objectID ) ;
123- key = hashCombine ( key , useReflectionProbeType ) ;
124- key = hashCombine ( key , reflectionProbeCubemap . objectID ) ;
125- key = hashCombine ( key , reflectionProbePlanarMap . objectID ) ;
126- key = hashCombine ( key , ENABLE_PROBE_BLEND ? reflectionProbeBlendCubemap ! . objectID : 0 ) ;
127- key = hashCombine ( key , stride ) ;
113+ const key = `${ sourceIA . indexBuffer ?. objectID ?? 0 } /${ lightingMap . objectID } /${ useReflectionProbeType } /`
114+ + `${ reflectionProbeCubemap . objectID } /${ reflectionProbePlanarMap . objectID } /`
115+ + `${ ENABLE_PROBE_BLEND ? reflectionProbeBlendCubemap ! . objectID : 0 } /${ stride } ` ;
128116 const mappedInstances = this . _instanceMap . get ( key ) ;
129117 if ( mappedInstances ) {
130118 for ( let i = 0 ; i < mappedInstances . length ; ++ i ) {
@@ -167,7 +155,7 @@ export class InstancedBuffer {
167155 }
168156
169157 private _createInstance (
170- key : number ,
158+ key : string ,
171159 sourceIA : InputAssembler ,
172160 instancedAttributes : Attribute [ ] ,
173161 instanceData : Uint8Array ,
0 commit comments