Reapply "optimize scene edge visibility toggle"

This reverts commit bcc5f55424.
This commit is contained in:
danielzhong 2025-09-17 21:25:09 -04:00
parent bcc5f55424
commit 5a00918005
4 changed files with 23 additions and 17 deletions

View File

@ -456,13 +456,16 @@ function FrameState(context, creditDisplay, jobScheduler) {
this.pickedMetadataInfo = undefined;
/**
* The owning Scene for this frame. Set each frame by Scene before updating primitives.
* Added so internal pipeline stages can reliably access the scene without depending
* on context.scene (which may not exist) or external closures.
* @type {Scene|undefined}
* Internal toggle indicating that at least one primitive for this frame requested
* edge visibility rendering (EXT_mesh_primitive_edge_visibility). This allows
* lazy allocation/activation of the edge MRT without storing a Scene reference
* on the frame state (avoids passing entire Scene through internal APIs).
* Set by model pipeline stages when they encounter edge visibility data.
* Consumed by Scene to flip its _enableEdgeVisibility flag.
* @type {boolean}
* @private
*/
this.scene = undefined;
this.edgeVisibilityRequested = false;
}
/**

View File

@ -51,12 +51,8 @@ EdgeVisibilityPipelineStage.process = function (
return;
}
// Fallback auto-enable: If edge visibility is being processed but the scene flag
// is still false (e.g., custom model loading path bypassed earlier auto-enable), turn it on.
const scene = frameState?.scene || frameState?.context?.scene;
if (defined(scene) && scene._enableEdgeVisibility === false) {
scene._enableEdgeVisibility = true;
}
// Fallback request: mark that edge visibility is needed this frame.
frameState.edgeVisibilityRequested = true;
const shaderBuilder = renderResources.shaderBuilder;

View File

@ -329,10 +329,8 @@ ModelRuntimePrimitive.prototype.configurePipeline = function (frameState) {
}
if (hasEdgeVisibility) {
const scene = frameState.scene;
if (scene && scene._enableEdgeVisibility === false) {
scene._enableEdgeVisibility = true;
}
// Indicate to Scene (after primitive updates) that the edge MRT should be enabled.
frameState.edgeVisibilityRequested = true;
pipelineStages.push(EdgeVisibilityPipelineStage);
pipelineStages.push(EdgeDetectionPipelineStage);
}

View File

@ -3687,12 +3687,21 @@ function updateShadowMaps(scene) {
function updateAndRenderPrimitives(scene) {
const frameState = scene._frameState;
// Ensure the frame state's scene reference is current each frame before primitives update
frameState.scene = scene;
// Reset per-frame edge visibility request flag before primitives update
frameState.edgeVisibilityRequested = false;
scene._groundPrimitives.update(frameState);
scene._primitives.update(frameState);
// If any primitive requested edge visibility this frame, flip the scene flag lazily.
if (
frameState.edgeVisibilityRequested &&
scene._enableEdgeVisibility === false
) {
scene._enableEdgeVisibility = true;
}
updateDebugFrustumPlanes(scene);
updateShadowMaps(scene);