Skip to content

Commit bcb00f9

Browse files
author
aardgoose
committed
rework cache key
1 parent 4c13bbd commit bcb00f9

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/renderers/common/ClippingContext.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { Vector4 } from '../../math/Vector4.js';
44

55
const _plane = /*@__PURE__*/ new Plane();
66

7-
let _clippingContextVersion = 0;
8-
97
class ClippingContext {
108

119
constructor( parentContext = null ) {
1210

13-
this.version = ++ _clippingContextVersion;
11+
this.version = 0;
1412

1513
this.clipIntersection = null;
14+
this.cacheKey = '';
1615

1716

1817
if ( parentContext === null ) {
@@ -36,7 +35,7 @@ class ClippingContext {
3635

3736
}
3837

39-
this.parentVersion = 0;
38+
this.parentVersion = null;
4039

4140
}
4241

@@ -131,7 +130,12 @@ class ClippingContext {
131130

132131
this.projectPlanes( srcClippingPlanes, dstClippingPlanes, offset );
133132

134-
if ( update ) this.version = _clippingContextVersion ++;
133+
if ( update ) {
134+
135+
this.version ++;
136+
this.cacheKey = `${ this.intersectionPlanes.length }:${ this.unionPlanes.length }`;
137+
138+
}
135139

136140
}
137141

src/renderers/common/RenderObject.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class RenderObject {
6262
this.vertexBuffers = null;
6363

6464
this.clippingContext = clippingContext;
65-
this.clippingContextVersion = clippingContext !== null ? clippingContext.version : 0;
65+
this.clippingContextCacheKey = clippingContext !== null ? clippingContext.cacheKey : '';
6666

6767
this.initialNodesCacheKey = this.getDynamicCacheKey();
6868
this.initialCacheKey = this.getCacheKey();
@@ -92,9 +92,9 @@ export default class RenderObject {
9292

9393
get clippingNeedsUpdate() {
9494

95-
if ( this.clippingContext === null || this.clippingContext.version === this.clippingContextVersion ) return false;
95+
if ( this.clippingContext === null || this.clippingContext.cacheKey === this.clippingContextCacheKey ) return false;
9696

97-
this.clippingContextVersion = this.clippingContext.version;
97+
this.clippingContextCacheKey = this.clippingContext.cacheKey;
9898

9999
return true;
100100

@@ -214,7 +214,7 @@ export default class RenderObject {
214214

215215
}
216216

217-
cacheKey += this.clippingContextVersion + ',';
217+
cacheKey += this.clippingContextCacheKey + ',';
218218

219219
if ( object.skeleton ) {
220220

src/renderers/webgpu/WebGPUBackend.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ class WebGPUBackend extends Backend {
10261026
data.sampleCount !== sampleCount || data.colorSpace !== colorSpace ||
10271027
data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat ||
10281028
data.primitiveTopology !== primitiveTopology ||
1029-
data.clippingContextVersion !== renderObject.clippingContextVersion
1029+
data.clippingContextCacheKey !== renderObject.clippingContextCacheKey
10301030
) {
10311031

10321032
data.material = material; data.materialVersion = material.version;
@@ -1044,7 +1044,7 @@ class WebGPUBackend extends Backend {
10441044
data.colorFormat = colorFormat;
10451045
data.depthStencilFormat = depthStencilFormat;
10461046
data.primitiveTopology = primitiveTopology;
1047-
data.clippingContextVersion = renderObject.clippingContextVersion;
1047+
data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
10481048

10491049
needsUpdate = true;
10501050

@@ -1074,7 +1074,7 @@ class WebGPUBackend extends Backend {
10741074
utils.getSampleCountRenderContext( renderContext ),
10751075
utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
10761076
utils.getPrimitiveTopology( object, material ),
1077-
renderObject.clippingContextVersion
1077+
renderObject.clippingContextCacheKey
10781078
].join();
10791079

10801080
}

0 commit comments

Comments
 (0)