Skip to content

Commit ca8eb21

Browse files
zjm-metameta-codesync[bot]
authored andcommitted
fix(core): determine isGPUDepth from session mode instead of texture existence
Summary: The depth occlusion system determined isGPUDepth by checking whether an ExternalTexture (nativeTexture) existed. This caused the preprocessing shader and material shader to disagree on which depth formula to use, because ExternalTexture availability can differ between render contexts. - Derive isGPUDepth from session.depthUsage === 'gpu-optimized' so both the preprocessing and material shaders always use the same formula - Extract shared isGPUDepth getter and getDepthTextureArray helper to eliminate duplicated texture selection logic - Remove minMaxEntityCount reset from cleanup() since entities persist across XR sessions and don't re-qualify on session re-entry. This fixed the bug of MinMax occluded objects being hidden after reentering the session Reviewed By: cabanier Differential Revision: D102858221 fbshipit-source-id: e5c6265972f724fc8e32437936bd48606626b3fa
1 parent f823f9c commit ca8eb21

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

packages/core/src/depth/depth-sensing-system.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ export class DepthSensingSystem extends createSystem(
326326
this.gpuDepthData = [];
327327
this.preprocessingPass?.dispose();
328328
this.preprocessingPass = undefined;
329-
this.minMaxEntityCount = 0;
330329
}
331330

332331
private updateEnabledFeatures(xrSession: XRSession | null): void {
@@ -365,21 +364,28 @@ export class DepthSensingSystem extends createSystem(
365364
* Renders a fullscreen pass per eye that computes min/max/avg depth in a 4×4
366365
* neighborhood, outputting to per-view 2D render targets.
367366
*/
367+
private get isGPUDepth(): boolean {
368+
const session = this.xrManager.getSession();
369+
return session?.depthUsage === 'gpu-optimized';
370+
}
371+
372+
private getDepthTextureArray(): Texture | undefined {
373+
return this.isGPUDepth
374+
? this.depthTextures?.getNativeTexture()
375+
: this.depthTextures?.getDataArrayTexture();
376+
}
377+
368378
private runMinMaxPreprocessing(): void {
369379
if (this.minMaxEntityCount === 0) {
370380
return;
371381
}
372382

373-
const nativeTexture = this.depthTextures?.getNativeTexture();
374-
const dataArrayTexture = this.depthTextures?.getDataArrayTexture();
375-
const isGPUDepth = nativeTexture !== undefined;
376-
const depthTextureArray = isGPUDepth
377-
? (nativeTexture as Texture)
378-
: (dataArrayTexture as Texture);
383+
const depthTextureArray = this.getDepthTextureArray();
379384
if (!depthTextureArray) {
380385
return;
381386
}
382387

388+
const isGPUDepth = this.isGPUDepth;
383389
const depthNear =
384390
(this.gpuDepthData[0] as unknown as { depthNear: number } | undefined)
385391
?.depthNear ?? 0;
@@ -481,19 +487,16 @@ export class DepthSensingSystem extends createSystem(
481487
* VIEW_ID to select the correct stereo layer.
482488
*/
483489
private updateOcclusionUniforms(): void {
484-
const nativeTexture = this.depthTextures?.getNativeTexture();
485-
const dataArrayTexture = this.depthTextures?.getDataArrayTexture();
486-
const isGPUDepth = nativeTexture !== undefined;
487-
const depthNear =
488-
(this.gpuDepthData[0] as unknown as { depthNear: number } | undefined)
489-
?.depthNear ?? 0;
490-
491-
// Select the texture array: ExternalTexture for GPU, DataArrayTexture for CPU
492-
const depthTextureArray = isGPUDepth ? nativeTexture : dataArrayTexture;
490+
const depthTextureArray = this.getDepthTextureArray();
493491
if (!depthTextureArray) {
494492
return;
495493
}
496494

495+
const isGPUDepth = this.isGPUDepth;
496+
const depthNear =
497+
(this.gpuDepthData[0] as unknown as { depthNear: number } | undefined)
498+
?.depthNear ?? 0;
499+
497500
this.renderer.getDrawingBufferSize(this.viewportSize);
498501

499502
for (const [entity, entityUniforms] of this.entityShaderMap) {

0 commit comments

Comments
 (0)