@forgeax/engine-render 0.1.33 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1010 -124
- package/dist/assembly/backend-contract.d.ts +2 -0
- package/dist/assembly/backend-contract.d.ts.map +1 -1
- package/dist/assembly/barrel-distortion-inspection.d.ts +3 -0
- package/dist/assembly/barrel-distortion-inspection.d.ts.map +1 -0
- package/dist/assembly/canvas-draw-guard.d.ts +3 -0
- package/dist/assembly/canvas-draw-guard.d.ts.map +1 -0
- package/dist/assembly/cloud-shadow-entry.d.ts +4 -0
- package/dist/assembly/cloud-shadow-entry.d.ts.map +1 -0
- package/dist/assembly/dynamic-geometry-host.d.ts +4 -1
- package/dist/assembly/dynamic-geometry-host.d.ts.map +1 -1
- package/dist/assembly/dynamic-geometry-runtime.d.ts +1 -1
- package/dist/assembly/dynamic-geometry-runtime.d.ts.map +1 -1
- package/dist/assembly/factory.d.ts +1 -1
- package/dist/assembly/factory.d.ts.map +1 -1
- package/dist/assembly/host-contract.d.ts +3 -3
- package/dist/assembly/host-contract.d.ts.map +1 -1
- package/dist/assembly/material/assembly.d.ts.map +1 -1
- package/dist/assembly/material/pipeline-helpers.d.ts +5 -0
- package/dist/assembly/material/pipeline-helpers.d.ts.map +1 -1
- package/dist/assembly/material-shader-policy.d.ts +16 -2
- package/dist/assembly/material-shader-policy.d.ts.map +1 -1
- package/dist/assembly/material-shader-prewarm.d.ts.map +1 -1
- package/dist/assembly/recovery/device-loss-fanout.d.ts.map +1 -1
- package/dist/assembly/recovery/renderer-recover.d.ts +2 -0
- package/dist/assembly/recovery/renderer-recover.d.ts.map +1 -1
- package/dist/assembly/render-feature-post-processes.d.ts +6 -0
- package/dist/assembly/render-feature-post-processes.d.ts.map +1 -0
- package/dist/assembly/renderer-facade.d.ts.map +1 -1
- package/dist/assembly/renderer-feature-inspection.d.ts +1 -1
- package/dist/assembly/renderer-feature-inspection.d.ts.map +1 -1
- package/dist/assembly/renderer-frame-transaction.d.ts +12 -0
- package/dist/assembly/renderer-frame-transaction.d.ts.map +1 -1
- package/dist/assembly/renderer-inspection.d.ts +11 -0
- package/dist/assembly/renderer-inspection.d.ts.map +1 -1
- package/dist/assembly/webgpu-pbr-ready.d.ts +1 -0
- package/dist/assembly/webgpu-pbr-ready.d.ts.map +1 -1
- package/dist/assembly/webgpu-ready-per-pass.d.ts +39 -0
- package/dist/assembly/webgpu-ready-per-pass.d.ts.map +1 -0
- package/dist/assembly/webgpu-ready.d.ts +1 -1
- package/dist/assembly/webgpu-ready.d.ts.map +1 -1
- package/dist/assembly/webgpu-renderer-bootstrap.d.ts.map +1 -1
- package/dist/assembly/webgpu-renderer-observation-owner.d.ts +35 -0
- package/dist/assembly/webgpu-renderer-observation-owner.d.ts.map +1 -0
- package/dist/assembly/webgpu-renderer.d.ts +1 -1
- package/dist/assembly/webgpu-renderer.d.ts.map +1 -1
- package/dist/authoring.mjs +1 -1
- package/dist/barrel-distortion.d.ts +47 -0
- package/dist/barrel-distortion.d.ts.map +1 -0
- package/dist/{chunk-PA5DRJNI.mjs → chunk-ELJFJ2BU.mjs} +2 -2
- package/dist/chunk-ELJFJ2BU.mjs.map +1 -0
- package/dist/{chunk-ZDQWGQW7.mjs → chunk-HEB564WF.mjs} +4 -4
- package/dist/{chunk-ZDQWGQW7.mjs.map → chunk-HEB564WF.mjs.map} +1 -1
- package/dist/{chunk-VOZWDM3L.mjs → chunk-MKDIT2EM.mjs} +1307 -188
- package/dist/chunk-MKDIT2EM.mjs.map +1 -0
- package/dist/{chunk-LEAXOMYJ.mjs → chunk-OCDLEI6I.mjs} +3 -3
- package/dist/{chunk-LEAXOMYJ.mjs.map → chunk-OCDLEI6I.mjs.map} +1 -1
- package/dist/chunk-ODZWR6JQ.mjs +4927 -0
- package/dist/chunk-ODZWR6JQ.mjs.map +1 -0
- package/dist/{chunk-3RTCJTH4.mjs → chunk-SHFUFJ5N.mjs} +184 -13
- package/dist/chunk-SHFUFJ5N.mjs.map +1 -0
- package/dist/{chunk-OO3DRYK7.mjs → chunk-UI5SFODX.mjs} +176 -96
- package/dist/chunk-UI5SFODX.mjs.map +1 -0
- package/dist/{chunk-PLAXOOX5.mjs → chunk-UINHLCZA.mjs} +561 -79
- package/dist/chunk-UINHLCZA.mjs.map +1 -0
- package/dist/{chunk-NB2S7ZRX.mjs → chunk-WEX45HKH.mjs} +127 -386
- package/dist/chunk-WEX45HKH.mjs.map +1 -0
- package/dist/cloud/density.d.ts +55 -0
- package/dist/cloud/density.d.ts.map +1 -0
- package/dist/cloud/extract.d.ts +25 -0
- package/dist/cloud/extract.d.ts.map +1 -0
- package/dist/cloud/feature.d.ts +57 -0
- package/dist/cloud/feature.d.ts.map +1 -0
- package/dist/cloud/frame-context.d.ts +8 -0
- package/dist/cloud/frame-context.d.ts.map +1 -0
- package/dist/cloud/inspection.d.ts +59 -0
- package/dist/cloud/inspection.d.ts.map +1 -0
- package/dist/cloud/optics.d.ts +56 -0
- package/dist/cloud/optics.d.ts.map +1 -0
- package/dist/cloud/parameters.d.ts +73 -0
- package/dist/cloud/parameters.d.ts.map +1 -0
- package/dist/cloud/resources.d.ts +60 -0
- package/dist/cloud/resources.d.ts.map +1 -0
- package/dist/cloud/shadow.d.ts +42 -0
- package/dist/cloud/shadow.d.ts.map +1 -0
- package/dist/cloud/temporal.d.ts +74 -0
- package/dist/cloud/temporal.d.ts.map +1 -0
- package/dist/components/barrel-distortion.d.ts +13 -0
- package/dist/components/barrel-distortion.d.ts.map +1 -0
- package/dist/components/cloud-layer.d.ts +29 -0
- package/dist/components/cloud-layer.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/instances.d.ts +20 -6
- package/dist/components/instances.d.ts.map +1 -1
- package/dist/construct-renderer.d.ts +1 -1
- package/dist/construct-renderer.d.ts.map +1 -1
- package/dist/construct-renderer.mjs +6759 -2875
- package/dist/construct-renderer.mjs.map +1 -1
- package/dist/dynamic-geometry.d.ts +5 -1
- package/dist/dynamic-geometry.d.ts.map +1 -1
- package/dist/errors/cloud.d.ts +59 -0
- package/dist/errors/cloud.d.ts.map +1 -0
- package/dist/errors/render.d.ts +18 -4
- package/dist/errors/render.d.ts.map +1 -1
- package/dist/examples/single-layer-medium-surface.d.ts +47 -0
- package/dist/examples/single-layer-medium-surface.d.ts.map +1 -0
- package/dist/extract/camera.d.ts.map +1 -1
- package/dist/extract/contracts.d.ts +5 -1
- package/dist/extract/contracts.d.ts.map +1 -1
- package/dist/features/barrel-distortion.d.ts +29 -0
- package/dist/features/barrel-distortion.d.ts.map +1 -0
- package/dist/features/error-reporting.d.ts +6 -2
- package/dist/features/error-reporting.d.ts.map +1 -1
- package/dist/features/host.d.ts +10 -0
- package/dist/features/host.d.ts.map +1 -1
- package/dist/features/plan.d.ts +8 -0
- package/dist/features/plan.d.ts.map +1 -1
- package/dist/features/render-graph-contribution.d.ts +5 -0
- package/dist/features/render-graph-contribution.d.ts.map +1 -1
- package/dist/features/render-graph-raster.d.ts +1 -0
- package/dist/features/render-graph-raster.d.ts.map +1 -1
- package/dist/features/targets.d.ts +2 -0
- package/dist/features/targets.d.ts.map +1 -1
- package/dist/features/types.d.ts +44 -0
- package/dist/features/types.d.ts.map +1 -1
- package/dist/fullscreen-post-process-pass.d.ts +15 -7
- package/dist/fullscreen-post-process-pass.d.ts.map +1 -1
- package/dist/gpu-dirty-ranges.d.ts +11 -0
- package/dist/gpu-dirty-ranges.d.ts.map +1 -0
- package/dist/gpu-driven/batch-topology.d.ts +17 -0
- package/dist/gpu-driven/batch-topology.d.ts.map +1 -1
- package/dist/gpu-driven/material-artifacts.d.ts +6 -0
- package/dist/gpu-driven/material-artifacts.d.ts.map +1 -1
- package/dist/gpu-driven/prepared-draw.d.ts.map +1 -1
- package/dist/gpu-driven/production-raster-material.d.ts +178 -0
- package/dist/gpu-driven/production-raster-material.d.ts.map +1 -0
- package/dist/gpu-driven/production-raster.d.ts +47 -3
- package/dist/gpu-driven/production-raster.d.ts.map +1 -1
- package/dist/gpu-driven/resource-allocation.d.ts +31 -0
- package/dist/gpu-driven/resource-allocation.d.ts.map +1 -0
- package/dist/gpu-driven/shadow-ownership.d.ts +14 -0
- package/dist/gpu-driven/shadow-ownership.d.ts.map +1 -0
- package/dist/gpu-driven/view-gpu.d.ts +26 -2
- package/dist/gpu-driven/view-gpu.d.ts.map +1 -1
- package/dist/gpu-scene.d.ts +5 -0
- package/dist/gpu-scene.d.ts.map +1 -1
- package/dist/hdrp-buffers.d.ts +2 -2
- package/dist/hdrp-buffers.d.ts.map +1 -1
- package/dist/ibl/skylight-bind-group.d.ts +10 -1
- package/dist/ibl/skylight-bind-group.d.ts.map +1 -1
- package/dist/index.d.ts +27 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +258 -8
- package/dist/index.mjs.map +1 -1
- package/dist/inspection-types.d.ts +135 -1
- package/dist/inspection-types.d.ts.map +1 -1
- package/dist/instance-buffer-cache.d.ts +4 -4
- package/dist/instance-buffer-cache.d.ts.map +1 -1
- package/dist/instances.d.ts +48 -100
- package/dist/instances.d.ts.map +1 -1
- package/dist/internal.mjs +7 -7
- package/dist/pbr-pipeline.d.ts +19 -1
- package/dist/pbr-pipeline.d.ts.map +1 -1
- package/dist/pipeline/single-layer-medium-passes.d.ts +73 -0
- package/dist/pipeline/single-layer-medium-passes.d.ts.map +1 -0
- package/dist/pipeline/standard-forward-lane.d.ts.map +1 -1
- package/dist/pipeline/standard-output/graph.d.ts.map +1 -1
- package/dist/pipeline/standard-output/types.d.ts +4 -2
- package/dist/pipeline/standard-output/types.d.ts.map +1 -1
- package/dist/pipeline/standard-pipeline.d.ts.map +1 -1
- package/dist/pipeline/standard-post.d.ts.map +1 -1
- package/dist/pipeline-builder.d.ts +1 -1
- package/dist/pipeline-builder.d.ts.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/prepare/prepared-graphics-resolver.d.ts +2 -0
- package/dist/prepare/prepared-graphics-resolver.d.ts.map +1 -1
- package/dist/record/barrel-distortion-frame.d.ts +15 -0
- package/dist/record/barrel-distortion-frame.d.ts.map +1 -0
- package/dist/record/dynamic-geometry-consumption.d.ts +10 -2
- package/dist/record/dynamic-geometry-consumption.d.ts.map +1 -1
- package/dist/record/fold-buckets.d.ts +95 -0
- package/dist/record/fold-buckets.d.ts.map +1 -0
- package/dist/record/fold-instance-buffer.d.ts +6 -0
- package/dist/record/fold-instance-buffer.d.ts.map +1 -0
- package/dist/record/frame-lighting.d.ts +1 -0
- package/dist/record/frame-lighting.d.ts.map +1 -1
- package/dist/record/frame-snapshot.d.ts +37 -3
- package/dist/record/frame-snapshot.d.ts.map +1 -1
- package/dist/record/frame.d.ts +10 -61
- package/dist/record/frame.d.ts.map +1 -1
- package/dist/record/gpu-draw-receipts.d.ts +11 -0
- package/dist/record/gpu-draw-receipts.d.ts.map +1 -0
- package/dist/record/gpu-timing.d.ts +8 -0
- package/dist/record/gpu-timing.d.ts.map +1 -1
- package/dist/record/main-pass-geometry.d.ts +21 -5
- package/dist/record/main-pass-geometry.d.ts.map +1 -1
- package/dist/record/main-pass-material.d.ts +7 -1
- package/dist/record/main-pass-material.d.ts.map +1 -1
- package/dist/record/main-pass-sprite-draws.d.ts.map +1 -1
- package/dist/record/main-pass.d.ts +13 -2
- package/dist/record/main-pass.d.ts.map +1 -1
- package/dist/record/motion-blur-receipt.d.ts +11 -0
- package/dist/record/motion-blur-receipt.d.ts.map +1 -0
- package/dist/record/probe-blend-buffer.d.ts +16 -0
- package/dist/record/probe-blend-buffer.d.ts.map +1 -0
- package/dist/record/recovery-pipeline.d.ts.map +1 -1
- package/dist/record/render-context.d.ts +22 -3
- package/dist/record/render-context.d.ts.map +1 -1
- package/dist/record/shadow-pass.d.ts +2 -0
- package/dist/record/shadow-pass.d.ts.map +1 -1
- package/dist/record/skybox-post-pass.d.ts +1 -1
- package/dist/record/skybox-post-pass.d.ts.map +1 -1
- package/dist/record/typed-frame-graph.d.ts +22 -2
- package/dist/record/typed-frame-graph.d.ts.map +1 -1
- package/dist/record/view-ubo.d.ts +11 -3
- package/dist/record/view-ubo.d.ts.map +1 -1
- package/dist/record/volume-params.d.ts +9 -0
- package/dist/record/volume-params.d.ts.map +1 -0
- package/dist/recovery/render-system-candidate.d.ts +10 -0
- package/dist/recovery/render-system-candidate.d.ts.map +1 -1
- package/dist/reflection/record-owner.d.ts.map +1 -1
- package/dist/render-contract.d.ts +42 -4
- package/dist/render-contract.d.ts.map +1 -1
- package/dist/render-graph-primitives.d.ts.map +1 -1
- package/dist/render-pipeline.d.ts +103 -2
- package/dist/render-pipeline.d.ts.map +1 -1
- package/dist/render-system-extract-tail.d.ts +3 -2
- package/dist/render-system-extract-tail.d.ts.map +1 -1
- package/dist/render-system-extract.d.ts +16 -9
- package/dist/render-system-extract.d.ts.map +1 -1
- package/dist/render-system-presentation.d.ts +23 -0
- package/dist/render-system-presentation.d.ts.map +1 -0
- package/dist/render-system-producer-roots.d.ts +10 -0
- package/dist/render-system-producer-roots.d.ts.map +1 -0
- package/dist/render-system-residency.d.ts +12 -0
- package/dist/render-system-residency.d.ts.map +1 -0
- package/dist/render-system.d.ts +19 -14
- package/dist/render-system.d.ts.map +1 -1
- package/dist/scene/probe-blend.d.ts +27 -0
- package/dist/scene/probe-blend.d.ts.map +1 -1
- package/dist/scene/render-scene.d.ts +12 -5
- package/dist/scene/render-scene.d.ts.map +1 -1
- package/dist/ssao-buffers.d.ts +9 -0
- package/dist/ssao-buffers.d.ts.map +1 -1
- package/dist/surface/dynamic-input.d.ts +133 -0
- package/dist/surface/dynamic-input.d.ts.map +1 -0
- package/dist/surface/gpu-driven.d.ts +41 -0
- package/dist/surface/gpu-driven.d.ts.map +1 -0
- package/dist/surface/submission-observation.d.ts +136 -0
- package/dist/surface/submission-observation.d.ts.map +1 -0
- package/dist/systems/skin-palette-allocator.d.ts.map +1 -1
- package/dist/temporal/gpu.d.ts +13 -1
- package/dist/temporal/gpu.d.ts.map +1 -1
- package/dist/temporal/index.mjs +5 -5
- package/dist/temporal/inspection.d.ts.map +1 -1
- package/dist/temporal/standard-scene-data.d.ts.map +1 -1
- package/dist/temporal/target-coverage-attachment.d.ts.map +1 -1
- package/dist/transmission/single-layer-medium.d.ts +89 -0
- package/dist/transmission/single-layer-medium.d.ts.map +1 -0
- package/dist/typed-render-graph-primitives.d.ts +14 -2
- package/dist/typed-render-graph-primitives.d.ts.map +1 -1
- package/dist/volume/component.d.ts +9 -4
- package/dist/volume/component.d.ts.map +1 -1
- package/dist/volume/extract.d.ts +1 -1
- package/dist/volume/extract.d.ts.map +1 -1
- package/dist/volume/inspection.d.ts +2 -0
- package/dist/volume/inspection.d.ts.map +1 -1
- package/dist/volume/passes.d.ts +4 -1
- package/dist/volume/passes.d.ts.map +1 -1
- package/dist/volume/resources.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/__tests__/atmosphere-daylight.dawn.test.ts +72 -0
- package/src/__tests__/barrel-distortion-lkg.integration.test.ts +353 -0
- package/src/__tests__/barrel-distortion.dawn.test.ts +41 -0
- package/src/__tests__/barrel-distortion.unit.test.ts +364 -0
- package/src/__tests__/construct-renderer-identity.unit.test.ts +49 -0
- package/src/__tests__/detached-recovery-graph.unit.test.ts +277 -0
- package/src/__tests__/device-loss-fanout.unit.test.ts +36 -1
- package/src/__tests__/docs-gate-green.unit.test.ts +112 -1
- package/src/__tests__/factory-contract.integration.test.ts +295 -45
- package/src/__tests__/feature-depth-input.dawn.test.ts +129 -2
- package/src/__tests__/fullscreen-feature-plan.unit.test.ts +14 -3
- package/src/__tests__/gpu-dirty-ranges.unit.test.ts +22 -0
- package/src/__tests__/gpu-driven-baseline.characterization.test.ts +16 -3
- package/src/__tests__/gpu-driven-batch-topology-pbr.unit.test.ts +12 -0
- package/src/__tests__/gpu-driven-material-artifacts.unit.test.ts +143 -0
- package/src/__tests__/gpu-driven-pbr.dawn.test.ts +2 -2
- package/src/__tests__/gpu-driven-production.integration.test.ts +482 -3
- package/src/__tests__/gpu-driven-shadow-views.dawn.test.ts +6 -5
- package/src/__tests__/gpu-driven-view-gpu-evidence.ts +94 -6
- package/src/__tests__/gpu-driven-view-graph.integration.test.ts +18 -2
- package/src/__tests__/gpu-driven-view.browser.test.ts +5 -8
- package/src/__tests__/gpu-driven-view.dawn.test.ts +6 -2
- package/src/__tests__/gpu-driven-view.unit.test.ts +1 -1
- package/src/__tests__/gpu-pass-timing-lifecycle.integration.test.ts +1 -0
- package/src/__tests__/gpu-pass-timing.browser.test.ts +6 -4
- package/src/__tests__/gpu-pass-timing.rhi-null.unit.test.ts +1 -0
- package/src/__tests__/gpu-scene.unit.test.ts +119 -9
- package/src/__tests__/instance-allocation-failure.unit.test.ts +57 -0
- package/src/__tests__/instances-culling.integration.test.ts +10 -36
- package/src/__tests__/instances-store.unit.test.ts +97 -305
- package/src/__tests__/instances-world-ownership.integration.test.ts +62 -0
- package/src/__tests__/main-pass-material-medium-selection.unit.test.ts +146 -0
- package/src/__tests__/material-shader-prewarm.unit.test.ts +59 -0
- package/src/__tests__/material-snapshot-mutation.integration.test.ts +39 -1
- package/src/__tests__/morph-culling-reentry.dawn.test.ts +5 -5
- package/src/__tests__/morph-visual-evidence.integration.test.ts +8 -7
- package/src/__tests__/motion-blur-compute.dawn.test.ts +13 -7
- package/src/__tests__/motion-blur.pixel.integration.test.ts +2 -2
- package/src/__tests__/nineslice-handle-surface.unit.test.ts +4 -4
- package/src/__tests__/pbr-view-layout.unit.test.ts +9 -0
- package/src/__tests__/physical-clearcoat.integration.test.ts +58 -0
- package/src/__tests__/prepared-graphics-capability.unit.test.ts +66 -2
- package/src/__tests__/probe-bindings.unit.test.ts +582 -1
- package/src/__tests__/probe-scene-dirty.integration.test.ts +28 -1
- package/src/__tests__/receipt-observation-retirement.unit.test.ts +65 -0
- package/src/__tests__/recovery-candidate-prepare.contract.test.ts +69 -0
- package/src/__tests__/render-error-code-owner.test-d.ts +7 -0
- package/src/__tests__/render-feature-diagnostics.unit.test.ts +15 -2
- package/src/__tests__/render-feature-error-reporting.unit.test.ts +21 -1
- package/src/__tests__/render-feature-prepared-diagnostics.unit.test.ts +10 -1
- package/src/__tests__/render-feature-retry.unit.test.ts +12 -1
- package/src/__tests__/render-scene-mixed-updates.integration.test.ts +145 -19
- package/src/__tests__/render-scene-projection.unit.test.ts +36 -11
- package/src/__tests__/render-scene-temporal-retry.unit.test.ts +20 -20
- package/src/__tests__/render-target-probe-soak.perf.test.ts +2 -2
- package/src/__tests__/render-temporal-environment-consumer.browser.test.ts +3 -3
- package/src/__tests__/render-temporal-environment-consumer.dawn.test.ts +5 -2
- package/src/__tests__/renderer-factory-material-contract.unit.test.ts +41 -7
- package/src/__tests__/renderer-frame-generation-fence.integration.test.ts +16 -0
- package/src/__tests__/renderer-frame-transaction.integration.test.ts +26 -10
- package/src/__tests__/resource-allocation.unit.test.ts +123 -0
- package/src/__tests__/single-layer-medium-passes.unit.test.ts +275 -0
- package/src/__tests__/skin-motion-regression.unit.test.ts +70 -1
- package/src/__tests__/skin-palette-recycling.dawn.test.ts +97 -0
- package/src/__tests__/skinned-shadow-caster.test.ts +15 -0
- package/src/__tests__/ssr-carrier-public-contract.unit.test.ts +21 -0
- package/src/__tests__/ssr-gpu-dispatch.browser.test.ts +4 -4
- package/src/__tests__/ssr-gpu-dispatch.dawn.test.ts +2 -2
- package/src/__tests__/ssr-gpu-dispatch.ts +1 -1
- package/src/__tests__/ssr-receiver-coverage.dawn.test.ts +6 -2
- package/src/__tests__/standard-output-chain-contract.unit.test.ts +28 -0
- package/src/__tests__/standard-pbr-artifact-assembly.unit.test.ts +46 -1
- package/src/__tests__/standard-pipeline.integration.test.ts +182 -1
- package/src/__tests__/surface-dynamic-buffer-lifecycle.unit.test.ts +506 -0
- package/src/__tests__/surface-submission-observation.unit.test.ts +812 -0
- package/src/__tests__/temporal-history-lifecycle.unit.test.ts +32 -0
- package/src/__tests__/temporal-performance.integration.test.ts +3 -3
- package/src/__tests__/visibility-instances.integration.test.ts +7 -19
- package/src/__tests__/visibility-producer-matrix.integration.test.ts +9 -20
- package/src/__tests__/volume-optics-oracle.unit.test.ts +4 -2
- package/src/__tests__/volumetric-fog-budget-recovery.integration.test.ts +30 -20
- package/src/__tests__/volumetric-fog-errors.unit.test.ts +4 -3
- package/src/__tests__/volumetric-fog-multiple.unit.test.ts +55 -0
- package/src/__tests__/volumetric-fog-spot-frame-optics.integration.test.ts +1 -1
- package/src/__tests__/volumetric-fog-stage-readback.dawn.test.ts +113 -9
- package/src/__tests__/volumetric-fog-topology.unit.test.ts +5 -3
- package/src/assembly/backend-contract.ts +30 -0
- package/src/assembly/barrel-distortion-inspection.ts +22 -0
- package/src/assembly/canvas-draw-guard.ts +11 -0
- package/src/assembly/cloud-shadow-entry.ts +22 -0
- package/src/assembly/dynamic-geometry-host.ts +65 -37
- package/src/assembly/dynamic-geometry-runtime.ts +7 -1
- package/src/assembly/factory.ts +2 -30
- package/src/assembly/host-contract.ts +3 -3
- package/src/assembly/material/assembly.ts +25 -13
- package/src/assembly/material/pipeline-helpers.ts +53 -12
- package/src/assembly/material-shader-policy.ts +55 -0
- package/src/assembly/material-shader-prewarm.ts +21 -10
- package/src/assembly/recovery/device-loss-fanout.ts +13 -0
- package/src/assembly/recovery/renderer-recover.ts +41 -18
- package/src/assembly/render-feature-post-processes.ts +54 -0
- package/src/assembly/renderer-facade.ts +4 -1
- package/src/assembly/renderer-feature-inspection.ts +8 -2
- package/src/assembly/renderer-frame-transaction.ts +23 -0
- package/src/assembly/renderer-inspection.ts +28 -0
- package/src/assembly/skin-palette-owner.ts +1 -1
- package/src/assembly/temporal-post-process-prewarm.ts +3 -3
- package/src/assembly/webgpu-pbr-ready.ts +9 -1
- package/src/assembly/webgpu-ready-per-pass.ts +104 -0
- package/src/assembly/webgpu-ready.ts +115 -61
- package/src/assembly/webgpu-renderer-bootstrap.ts +0 -12
- package/src/assembly/webgpu-renderer-observation-owner.ts +222 -0
- package/src/assembly/webgpu-renderer.ts +214 -252
- package/src/assembly/webgpu-vertex-layouts.ts +1 -1
- package/src/barrel-distortion.ts +247 -0
- package/src/cloud/__tests__/cloud-density-parity.dawn.test.ts +173 -0
- package/src/cloud/__tests__/cloud-layer-framebuffer-y.dawn.test.ts +265 -0
- package/src/cloud/__tests__/cloud-layer.browser.test.ts +432 -0
- package/src/cloud/__tests__/cloud-layer.unit.test.ts +634 -0
- package/src/cloud/density.ts +600 -0
- package/src/cloud/extract.ts +110 -0
- package/src/cloud/feature.ts +1810 -0
- package/src/cloud/frame-context.ts +42 -0
- package/src/cloud/inspection.ts +130 -0
- package/src/cloud/optics.ts +285 -0
- package/src/cloud/parameters.ts +255 -0
- package/src/cloud/resources.ts +122 -0
- package/src/cloud/shadow.ts +167 -0
- package/src/cloud/temporal.ts +226 -0
- package/src/components/barrel-distortion.ts +46 -0
- package/src/components/cloud-layer.ts +47 -0
- package/src/components/index.ts +2 -0
- package/src/components/instances.ts +18 -45
- package/src/components/sprite-instances.ts +1 -1
- package/src/construct-renderer.ts +1 -1
- package/src/dynamic-geometry.ts +12 -1
- package/src/errors/cloud.ts +103 -0
- package/src/errors/render.ts +44 -7
- package/src/examples/single-layer-medium-surface.ts +59 -0
- package/src/extract/camera.ts +15 -1
- package/src/extract/contracts.ts +5 -0
- package/src/features/barrel-distortion.ts +172 -0
- package/src/features/error-reporting.ts +26 -6
- package/src/features/host.ts +115 -14
- package/src/features/plan.ts +8 -0
- package/src/features/render-graph-contribution.ts +9 -0
- package/src/features/render-graph-raster.ts +45 -3
- package/src/features/targets.ts +66 -0
- package/src/features/types.ts +47 -0
- package/src/fullscreen-post-process-pass.ts +41 -9
- package/src/gpu-dirty-ranges.ts +48 -0
- package/src/gpu-driven/batch-topology.ts +53 -0
- package/src/gpu-driven/material-artifacts.ts +33 -25
- package/src/gpu-driven/prepared-draw.ts +12 -4
- package/src/gpu-driven/production-raster-material.ts +1894 -0
- package/src/gpu-driven/production-raster.ts +825 -784
- package/src/gpu-driven/resource-allocation.ts +142 -0
- package/src/gpu-driven/shadow-ownership.ts +71 -0
- package/src/gpu-driven/view-gpu.ts +164 -10
- package/src/gpu-scene.ts +75 -84
- package/src/hdrp-buffers.ts +4 -3
- package/src/ibl/skylight-bind-group.ts +49 -7
- package/src/index.ts +196 -9
- package/src/inspection-types.ts +162 -0
- package/src/instance-buffer-cache.ts +4 -4
- package/src/instances.ts +149 -569
- package/src/pbr-pipeline.ts +219 -13
- package/src/pipeline/single-layer-medium-passes.ts +267 -0
- package/src/pipeline/standard-forward-lane.ts +313 -57
- package/src/pipeline/standard-output/graph.ts +8 -2
- package/src/pipeline/standard-output/types.ts +12 -1
- package/src/pipeline/standard-pipeline.ts +291 -18
- package/src/pipeline/standard-post.ts +90 -24
- package/src/pipeline-builder.ts +1 -1
- package/src/plugin.ts +4 -0
- package/src/points-lines/__tests__/points-lines.bench.ts +17 -8
- package/src/prepare/prepared-graphics-resolver.ts +2 -0
- package/src/record/__tests__/main-pass-geometry.unit.test.ts +30 -0
- package/src/record/__tests__/sprite-material-abi.unit.test.ts +1 -1
- package/src/record/__tests__/temporal-payload.unit.test.ts +1 -1
- package/src/record/__tests__/transparent-group2-selection.unit.test.ts +11 -0
- package/src/record/__tests__/typed-frame-graph-plan.unit.test.ts +1 -0
- package/src/record/__tests__/view-ubo-layout.unit.test.ts +4 -3
- package/src/record/barrel-distortion-frame.ts +110 -0
- package/src/record/dynamic-geometry-consumption.ts +39 -9
- package/src/record/fold-buckets.ts +852 -0
- package/src/record/fold-instance-buffer.ts +51 -0
- package/src/record/frame-lighting.ts +36 -2
- package/src/record/frame-snapshot.ts +39 -3
- package/src/record/frame.ts +217 -1084
- package/src/record/gpu-draw-receipts.ts +38 -0
- package/src/record/gpu-timing.ts +48 -5
- package/src/record/main-pass-geometry.ts +251 -82
- package/src/record/main-pass-material.ts +66 -4
- package/src/record/main-pass-sprite-draws.ts +7 -65
- package/src/record/main-pass.ts +156 -20
- package/src/record/motion-blur-receipt.ts +91 -0
- package/src/record/probe-blend-buffer.ts +180 -0
- package/src/record/recovery-pipeline.ts +35 -3
- package/src/record/render-context.ts +39 -3
- package/src/record/shadow-pass.ts +30 -1
- package/src/record/skybox-post-pass.ts +28 -4
- package/src/record/typed-frame-graph.ts +770 -134
- package/src/record/view-ubo.ts +26 -3
- package/src/record/volume-params.ts +225 -0
- package/src/recovery/render-system-candidate.ts +235 -42
- package/src/reflection/record-owner.ts +7 -3
- package/src/render-contract.ts +48 -4
- package/src/render-graph-primitives.ts +7 -1
- package/src/render-pipeline.ts +130 -0
- package/src/render-system-extract-tail.ts +57 -61
- package/src/render-system-extract.ts +74 -76
- package/src/render-system-presentation.ts +56 -0
- package/src/render-system-producer-roots.ts +96 -0
- package/src/render-system-residency.ts +159 -0
- package/src/render-system.ts +347 -363
- package/src/scene/probe-blend.ts +96 -4
- package/src/scene/render-scene.ts +349 -280
- package/src/ssao-buffers.ts +95 -2
- package/src/surface/__tests__/dynamic-input.unit.test.ts +374 -0
- package/src/surface/__tests__/gpu-driven.unit.test.ts +87 -0
- package/src/surface/dynamic-input.ts +658 -0
- package/src/surface/gpu-driven.ts +147 -0
- package/src/surface/submission-observation.ts +517 -0
- package/src/systems/skin-palette-allocator.ts +4 -1
- package/src/temporal/gpu.ts +101 -17
- package/src/temporal/inspection.ts +7 -1
- package/src/temporal/standard-scene-data.ts +5 -0
- package/src/temporal/target-coverage-attachment.ts +4 -0
- package/src/transmission/__tests__/single-layer-medium.unit.test.ts +149 -0
- package/src/transmission/__tests__/standard-transmission.dawn.test.ts +12 -11
- package/src/transmission/single-layer-medium.ts +322 -0
- package/src/typed-render-graph-primitives.ts +70 -2
- package/src/volume/component.ts +10 -9
- package/src/volume/extract.ts +11 -5
- package/src/volume/inspection.ts +3 -0
- package/src/volume/passes.ts +87 -4
- package/src/volume/resources.ts +2 -1
- package/dist/chunk-3RTCJTH4.mjs.map +0 -1
- package/dist/chunk-NB2S7ZRX.mjs.map +0 -1
- package/dist/chunk-NNQL7CB3.mjs +0 -1713
- package/dist/chunk-NNQL7CB3.mjs.map +0 -1
- package/dist/chunk-OO3DRYK7.mjs.map +0 -1
- package/dist/chunk-PA5DRJNI.mjs.map +0 -1
- package/dist/chunk-PLAXOOX5.mjs.map +0 -1
- package/dist/chunk-VOZWDM3L.mjs.map +0 -1
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import { HANDLE_NINESLICE_QUAD, resolveAssetHandle } from '@forgeax/engine-assets-runtime';
|
|
2
|
+
import type { World } from '@forgeax/engine-ecs';
|
|
3
|
+
import { deriveVertexCount } from '@forgeax/engine-geometry';
|
|
4
|
+
import { RhiError } from '@forgeax/engine-rhi';
|
|
5
|
+
import type { MaterialRenderState, MeshAsset } from '@forgeax/engine-types';
|
|
6
|
+
import { handleSlot, toShared } from '@forgeax/engine-types';
|
|
7
|
+
import type { MeshGpuHandles } from '../device/gpu-residency';
|
|
8
|
+
import { materialBindingKey } from '../gpu-driven/material-bindings';
|
|
9
|
+
import { GpuBuffer } from '../gpu-resource';
|
|
10
|
+
import { GPU_BUFFER_USAGE_COPY_DST, GPU_BUFFER_USAGE_VERTEX } from '../gpu-usage';
|
|
11
|
+
import { disposeTransientInstanceBuffers } from '../instance-buffer-cache';
|
|
12
|
+
import type { DispatchEntry, MaterialSnapshot, RenderableSnapshot } from '../render-system-extract';
|
|
13
|
+
import {
|
|
14
|
+
getTransparentSortConfig,
|
|
15
|
+
TRANSPARENT_SORT_MODE_LAYER_Y,
|
|
16
|
+
TRANSPARENT_SORT_MODE_LAYER_Z,
|
|
17
|
+
} from '../systems/transparent-sort-config';
|
|
18
|
+
import {
|
|
19
|
+
instanceCollectionCacheKey,
|
|
20
|
+
type RenderFrameState,
|
|
21
|
+
type ValidatedRenderable,
|
|
22
|
+
worldEntityKey,
|
|
23
|
+
} from './frame-snapshot';
|
|
24
|
+
import { variantSetFromDefines } from './helpers';
|
|
25
|
+
import {
|
|
26
|
+
buildFoldDispatchPlan,
|
|
27
|
+
cleanPerEntityCache,
|
|
28
|
+
ensureMeshSsboCapacity,
|
|
29
|
+
evaluateFoldBucketUniformCap,
|
|
30
|
+
type FoldBucket,
|
|
31
|
+
type FoldDispatchPlan,
|
|
32
|
+
foldDispatchBuckets,
|
|
33
|
+
incrementFoldedDrawsMetric,
|
|
34
|
+
} from './mesh-ssbo';
|
|
35
|
+
import type { PipelineState, RenderSystemInternals } from './render-context';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A frame-local material table. Repeated snapshot objects share one UBO slot;
|
|
39
|
+
* each renderable keeps only the slot index used by each authored material.
|
|
40
|
+
*/
|
|
41
|
+
export interface MaterialSlotPlan<T extends object> {
|
|
42
|
+
readonly slotIndices: readonly (readonly number[])[];
|
|
43
|
+
readonly slots: readonly T[];
|
|
44
|
+
/** Index of the first renderable that referenced each slot. */
|
|
45
|
+
readonly slotOwners: readonly number[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Intern identical material snapshots into one frame-local slot table.
|
|
50
|
+
* Snapshot identity is the extract layer's invalidation token, so this keeps
|
|
51
|
+
* the same correctness boundary while avoiding duplicate payload assembly and
|
|
52
|
+
* upload for repeated scene instances.
|
|
53
|
+
*/
|
|
54
|
+
export function buildMaterialSlotPlan<T extends object>(
|
|
55
|
+
materialGroups: readonly (readonly T[])[],
|
|
56
|
+
bindingClass?: (material: T, owner: number) => string,
|
|
57
|
+
): MaterialSlotPlan<T> {
|
|
58
|
+
const slotByMaterial = new Map<T, Map<string, number>>();
|
|
59
|
+
const slots: T[] = [];
|
|
60
|
+
const slotOwners: number[] = [];
|
|
61
|
+
const slotIndices = materialGroups.map((materials, ownerIndex) =>
|
|
62
|
+
materials.map((material) => {
|
|
63
|
+
const resourceClass = bindingClass?.(material, ownerIndex) ?? '';
|
|
64
|
+
let materialClasses = slotByMaterial.get(material);
|
|
65
|
+
if (materialClasses === undefined) {
|
|
66
|
+
materialClasses = new Map();
|
|
67
|
+
slotByMaterial.set(material, materialClasses);
|
|
68
|
+
}
|
|
69
|
+
const cached = materialClasses.get(resourceClass);
|
|
70
|
+
if (cached !== undefined) return cached;
|
|
71
|
+
const slot = slots.length;
|
|
72
|
+
slots.push(material);
|
|
73
|
+
slotOwners.push(ownerIndex);
|
|
74
|
+
materialClasses.set(resourceClass, slot);
|
|
75
|
+
return slot;
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
return { slotIndices, slots, slotOwners };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Return the largest complete renderable prefix supported by a shared
|
|
83
|
+
* mesh/material capacity. Mesh rows consume one slot per renderable; material
|
|
84
|
+
* rows use the deduplicated slot indices assigned in first-seen order.
|
|
85
|
+
*/
|
|
86
|
+
export function findRenderablePrefixForSlotCapacity(
|
|
87
|
+
materialSlotIndices: readonly (readonly number[])[],
|
|
88
|
+
slotCapacity: number,
|
|
89
|
+
): number {
|
|
90
|
+
const capacity = Math.max(0, Math.floor(slotCapacity));
|
|
91
|
+
const maxRenderableCount = Math.min(materialSlotIndices.length, capacity);
|
|
92
|
+
let renderableCount = 0;
|
|
93
|
+
while (renderableCount < maxRenderableCount) {
|
|
94
|
+
const slots = materialSlotIndices[renderableCount] ?? [];
|
|
95
|
+
if (slots.some((slot) => slot >= capacity)) break;
|
|
96
|
+
renderableCount += 1;
|
|
97
|
+
}
|
|
98
|
+
return renderableCount;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Count material slots reachable from a prefix of a first-seen slot plan. */
|
|
102
|
+
export function materialSlotCountForPrefix(
|
|
103
|
+
materialSlotIndices: readonly (readonly number[])[],
|
|
104
|
+
renderableCount: number,
|
|
105
|
+
): number {
|
|
106
|
+
let maxSlot = -1;
|
|
107
|
+
for (let index = 0; index < renderableCount; index += 1) {
|
|
108
|
+
for (const slot of materialSlotIndices[index] ?? []) maxSlot = Math.max(maxSlot, slot);
|
|
109
|
+
}
|
|
110
|
+
return maxSlot + 1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
type MeshSsboCapacityResult = ReturnType<typeof ensureMeshSsboCapacity>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Resolve the actual mesh-SSBO ceiling after the shared grow contract ran.
|
|
117
|
+
* A missing grow controller is the legacy/test surface with no renderer-owned
|
|
118
|
+
* ceiling; a failed grow explicitly exposes the pre-grow capacity and must
|
|
119
|
+
* constrain every row written by this frame, including retained shadow rows.
|
|
120
|
+
*/
|
|
121
|
+
function meshSsboSlotCapacityAfterEnsure(
|
|
122
|
+
internals: Pick<RenderSystemInternals, 'growMeshSsbo' | 'meshSsboState'>,
|
|
123
|
+
neededSlots: number,
|
|
124
|
+
result: MeshSsboCapacityResult,
|
|
125
|
+
): number {
|
|
126
|
+
if (internals.growMeshSsbo === undefined) return Number.POSITIVE_INFINITY;
|
|
127
|
+
if (!result.ok) return Math.max(0, result.degradedToSlotCount);
|
|
128
|
+
return internals.meshSsboState?.slotCount ?? neededSlots;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Keep a row sequence inside the capacity published by the mesh-SSBO owner.
|
|
133
|
+
* The caller has already reserved earlier rows (the primary view), so this
|
|
134
|
+
* helper only accepts the remaining slots for the retained shadow sequence.
|
|
135
|
+
*/
|
|
136
|
+
function limitRowsToMeshSsboCapacity<T>(rows: readonly T[], availableSlots: number): readonly T[] {
|
|
137
|
+
if (availableSlots === Number.POSITIVE_INFINITY) return rows;
|
|
138
|
+
return rows.slice(0, Math.max(0, Math.floor(availableSlots)));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* feat-20260704 M3/w18: validate renderable handles + collect the render plan,
|
|
143
|
+
* extracted verbatim from `recordFrame`. Empty `renderables` input or all-
|
|
144
|
+
* unregistered handles both yield an empty result (the Case E clear-pass-only
|
|
145
|
+
* path). Builds per-entry renderState / stencilReference overlays from the
|
|
146
|
+
* transparent-dispatch entries, resolves each MeshFilter.assetHandle through
|
|
147
|
+
* the AssetRegistry + GPU store (with the sprite 9-slice mesh swap), and fires
|
|
148
|
+
* structured `asset-not-registered` errors for handles that fail to resolve.
|
|
149
|
+
*
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
export function validateRenderables(
|
|
153
|
+
internals: RenderSystemInternals,
|
|
154
|
+
world: World,
|
|
155
|
+
// feat-20260709-editor-world-partition ENGINE-fix-round2 (defect 2): the full
|
|
156
|
+
// worlds[] list. Each renderable's mesh handle is a user-tier slot in its OWN
|
|
157
|
+
// world's sharedRefs; resolving against a foreign world either misses
|
|
158
|
+
// (asset-not-registered) or resolves the wrong slot payload. `world` (the
|
|
159
|
+
// resource-owner) is retained as the fallback for renderables whose worldId
|
|
160
|
+
// is out of range (defensive; extractFrames always stamps a valid index).
|
|
161
|
+
worlds: readonly World[],
|
|
162
|
+
pipelineState: PipelineState,
|
|
163
|
+
frameState: RenderFrameState,
|
|
164
|
+
renderables: readonly RenderableSnapshot[],
|
|
165
|
+
transparentDispatch: readonly DispatchEntry[],
|
|
166
|
+
excludedEntityKeys: ReadonlySet<number> = new Set<number>(),
|
|
167
|
+
worldKeys?: readonly number[],
|
|
168
|
+
): ValidatedRenderable[] {
|
|
169
|
+
// bug-20260527-renderstate-pipeline-dispatch-gap D-4:
|
|
170
|
+
// build a renderableIndex -> renderState map from dispatch entries
|
|
171
|
+
// so each ValidatedRenderable carries its per-material renderState
|
|
172
|
+
// override without an O(n^2) back-scan in the draw loop.
|
|
173
|
+
const renderStateByRenderableIdx = new Map<number, MaterialRenderState | undefined>();
|
|
174
|
+
// w10: also build a renderableIndex -> stencilReference map from
|
|
175
|
+
// dispatch entries for per-draw setStencilReference calls.
|
|
176
|
+
const stencilRefByRenderableIdx = new Map<number, number | undefined>();
|
|
177
|
+
const variantSetByRenderableIdx = new Map<number, string | undefined>();
|
|
178
|
+
// Keep these three independent maps because each overlay has its own
|
|
179
|
+
// consumer and the last dispatch entry remains authoritative. Populate
|
|
180
|
+
// them in one pass: the old code walked the same dispatch list three times
|
|
181
|
+
// and repeated the same renderableIndex branch / hash writes.
|
|
182
|
+
for (const de of transparentDispatch) {
|
|
183
|
+
const renderableIndex = de.renderableIndex;
|
|
184
|
+
if (renderableIndex === undefined) continue;
|
|
185
|
+
renderStateByRenderableIdx.set(renderableIndex, de.renderState);
|
|
186
|
+
stencilRefByRenderableIdx.set(renderableIndex, de.stencilReference);
|
|
187
|
+
variantSetByRenderableIdx.set(renderableIndex, variantSetFromDefines(de.defines));
|
|
188
|
+
}
|
|
189
|
+
const validated: ValidatedRenderable[] = [];
|
|
190
|
+
for (let rIdx = 0; rIdx < renderables.length; rIdx++) {
|
|
191
|
+
const r = renderables[rIdx];
|
|
192
|
+
if (r === undefined) continue;
|
|
193
|
+
if (excludedEntityKeys.has(worldEntityKey(worldKeys?.[r.worldId] ?? r.worldId, r.entityKey)))
|
|
194
|
+
continue;
|
|
195
|
+
// feat-20260709-editor-world-partition ENGINE-fix-round2 (defect 2): resolve
|
|
196
|
+
// this renderable's mesh against the world it was EXTRACTED from
|
|
197
|
+
// (worlds[r.worldId]) — NOT the single resource-owner `world`. Builtin mesh
|
|
198
|
+
// slots (< BUILTIN_BASE) resolve process-statically regardless of world, so
|
|
199
|
+
// the per-world pick only matters for user-tier handles, but selecting it
|
|
200
|
+
// unconditionally keeps a single code path. Falls back to the resource-owner
|
|
201
|
+
// world if worldId is out of range (defensive; extractFrames always stamps
|
|
202
|
+
// a valid index into worlds[]).
|
|
203
|
+
const renderableWorld = worlds[r.worldId] ?? world;
|
|
204
|
+
const assetRes = resolveAssetHandle<MeshAsset>(
|
|
205
|
+
renderableWorld,
|
|
206
|
+
toShared<'MeshAsset'>(r.assetHandle),
|
|
207
|
+
);
|
|
208
|
+
if (!assetRes.ok) {
|
|
209
|
+
internals.errorRegistry.fire(
|
|
210
|
+
new RhiError({
|
|
211
|
+
code: 'asset-not-registered',
|
|
212
|
+
expected: 'MeshFilter.assetHandle in AssetRegistry',
|
|
213
|
+
hint: 'use HANDLE_CUBE / HANDLE_TRIANGLE imports; custom mesh register path: feat-future-asset-system',
|
|
214
|
+
detail: { assetHandle: r.assetHandle },
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
// feat-20260601-device/gpu-residency-extraction M1 (D-1): builtin meshes
|
|
220
|
+
// (slots through HANDLE_NINESLICE_QUAD) keep the createRenderer step-3
|
|
221
|
+
// direct-upload + `pipelineState.meshes` path -- they are NOT routed
|
|
222
|
+
// through `ensureResident`. User-registered meshes pull through the store
|
|
223
|
+
// on first access (the register->upload push was severed in this M1);
|
|
224
|
+
// the POD fetched above (assetRes.value) is passed in, store holds no
|
|
225
|
+
// registry ref (D-2). A first-access miss builds the GPU buffers; later
|
|
226
|
+
// frames hit the O(1) cache.
|
|
227
|
+
const meshAssetHandle = toShared<'MeshAsset'>(r.assetHandle);
|
|
228
|
+
let meshHandles = internals.gpuStore.getMeshGpuHandles(meshAssetHandle, renderableWorld);
|
|
229
|
+
const lodMeshes = r.lods?.map((lod) => internals.assets.lookup<MeshAsset>(lod.mesh));
|
|
230
|
+
const resolvedLodMeshes =
|
|
231
|
+
lodMeshes?.every((lod): lod is MeshAsset => lod?.kind === 'mesh') === true
|
|
232
|
+
? lodMeshes
|
|
233
|
+
: undefined;
|
|
234
|
+
if (meshHandles === undefined && r.assetHandle > handleSlot(HANDLE_NINESLICE_QUAD)) {
|
|
235
|
+
const residentRes = internals.gpuStore.ensureResident(
|
|
236
|
+
meshAssetHandle,
|
|
237
|
+
assetRes.value,
|
|
238
|
+
renderableWorld,
|
|
239
|
+
resolvedLodMeshes,
|
|
240
|
+
);
|
|
241
|
+
if (residentRes.ok) {
|
|
242
|
+
meshHandles = residentRes.value;
|
|
243
|
+
} else if (residentRes.error instanceof RhiError) {
|
|
244
|
+
internals.errorRegistry.fire(residentRes.error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
meshHandles = meshHandles ?? pipelineState.meshes.get(r.assetHandle);
|
|
248
|
+
if (meshHandles === undefined) {
|
|
249
|
+
internals.errorRegistry.fire(
|
|
250
|
+
new RhiError({
|
|
251
|
+
code: 'asset-not-registered',
|
|
252
|
+
expected: 'GPU mesh buffers uploaded for assetHandle',
|
|
253
|
+
hint: 'await renderer.initialization before draw([world], { cameraOwner: 0, resourceOwner: 0 }); ensure AssetRegistry.configureGpuDevice ran so user meshes are uploaded',
|
|
254
|
+
detail: { assetHandle: r.assetHandle },
|
|
255
|
+
}),
|
|
256
|
+
);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
// feat-20260527-sprite-nineslice M2 / w11 (plan-strategy section D-2):
|
|
260
|
+
// sprite branch with non-zero `slicesAndMode` (post-w12 paramSnapshot
|
|
261
|
+
// entry name) overrides the user-supplied mesh handle (typically
|
|
262
|
+
// HANDLE_QUAD = 3) with the 16-vertex / 54-index HANDLE_NINESLICE_QUAD
|
|
263
|
+
// (id=5) topology so the vertex shader sees the 4x4 grid required for
|
|
264
|
+
// 9-region anchor mapping. Default slicesAndMode ([0, 0, 0, 0]) keeps
|
|
265
|
+
// the legacy HANDLE_QUAD path; a flip from zero to non-zero on the
|
|
266
|
+
// same entity routes here per-frame so AI users can toggle 9-slice
|
|
267
|
+
// on the fly without re-spawning the entity (charter F1 minimum
|
|
268
|
+
// surface). The HANDLE_NINESLICE_QUAD GPU buffers are seeded by
|
|
269
|
+
// createRenderer step-3.
|
|
270
|
+
//
|
|
271
|
+
// feat-20260625-refactor-sprite-as-transparent-mesh M3 / w13: judgement
|
|
272
|
+
// key migrated from `shadingModel === 'sprite'` to
|
|
273
|
+
// `materialShaderId === 'forgeax::sprite'` (plan-strategy D-10); slices
|
|
274
|
+
// sourced from `paramSnapshot.slicesAndMode` (post-w12 UBO-aligned
|
|
275
|
+
// overlay path).
|
|
276
|
+
//
|
|
277
|
+
// feat-20260624-sprite-lit-shading-model-pure-2d-lighting M1' / t7:
|
|
278
|
+
// sprite-lit shares the sprite paramSchema (5 fields, t4 mirror) so
|
|
279
|
+
// the 9-slices mesh swap applies identically.
|
|
280
|
+
let effectiveMeshHandles = meshHandles;
|
|
281
|
+
if (
|
|
282
|
+
r.material.materialShaderId === 'forgeax::sprite' ||
|
|
283
|
+
r.material.materialShaderId === 'forgeax::sprite-lit'
|
|
284
|
+
) {
|
|
285
|
+
const slicesArr = r.material.paramSnapshot?.slicesAndMode as readonly number[] | undefined;
|
|
286
|
+
if (
|
|
287
|
+
slicesArr !== undefined &&
|
|
288
|
+
slicesArr.length >= 4 &&
|
|
289
|
+
(slicesArr[0] !== 0 || slicesArr[1] !== 0 || slicesArr[2] !== 0 || slicesArr[3] !== 0)
|
|
290
|
+
) {
|
|
291
|
+
const nineSliceHandles = pipelineState.meshes.get(handleSlot(HANDLE_NINESLICE_QUAD));
|
|
292
|
+
if (nineSliceHandles !== undefined) {
|
|
293
|
+
effectiveMeshHandles = nineSliceHandles;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (r.morph !== undefined) {
|
|
298
|
+
const morphed = prepareMorphMesh(
|
|
299
|
+
internals,
|
|
300
|
+
frameState,
|
|
301
|
+
worldEntityKey(r.worldId, r.entityKey),
|
|
302
|
+
effectiveMeshHandles,
|
|
303
|
+
assetRes.value,
|
|
304
|
+
r.morph,
|
|
305
|
+
);
|
|
306
|
+
if (morphed !== undefined) effectiveMeshHandles = morphed;
|
|
307
|
+
}
|
|
308
|
+
validated.push({
|
|
309
|
+
source: r,
|
|
310
|
+
world: renderableWorld,
|
|
311
|
+
mesh: effectiveMeshHandles,
|
|
312
|
+
renderableIndex: rIdx,
|
|
313
|
+
renderState: renderStateByRenderableIdx.get(rIdx),
|
|
314
|
+
variantSet: variantSetByRenderableIdx.get(rIdx),
|
|
315
|
+
stencilReference: stencilRefByRenderableIdx.get(rIdx),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return validated;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Keep the primary record-stage name explicit at its call site while sharing
|
|
322
|
+
// the same owner implementation for the complete retained ShadowCaster view.
|
|
323
|
+
|
|
324
|
+
function prepareMorphMesh(
|
|
325
|
+
internals: RenderSystemInternals,
|
|
326
|
+
frameState: RenderFrameState,
|
|
327
|
+
cacheKey: number,
|
|
328
|
+
base: MeshGpuHandles,
|
|
329
|
+
mesh: MeshAsset,
|
|
330
|
+
morph: RenderableSnapshot['morph'],
|
|
331
|
+
): MeshGpuHandles | undefined {
|
|
332
|
+
if (morph === undefined || frameState.morphBuffers === undefined) return undefined;
|
|
333
|
+
const targets = mesh.morphTargets;
|
|
334
|
+
if (targets === undefined || targets.length !== morph.targetCount) return undefined;
|
|
335
|
+
const position = base.layoutProjection.attributes.find(
|
|
336
|
+
(attribute) => attribute.key === 'position',
|
|
337
|
+
);
|
|
338
|
+
if (
|
|
339
|
+
position === undefined ||
|
|
340
|
+
position.offset !== 0 ||
|
|
341
|
+
position.shaderLocation !== 0 ||
|
|
342
|
+
position.format !== 'float32x3' ||
|
|
343
|
+
position.byteLength !== 12
|
|
344
|
+
) {
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
const vertexCount = deriveVertexCount(mesh.vertices, base.layoutProjection);
|
|
348
|
+
if (vertexCount === undefined || vertexCount !== base.vertexCount || vertexCount <= 0) {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
const stride = base.layoutProjection.arrayStride / Float32Array.BYTES_PER_ELEMENT;
|
|
352
|
+
|
|
353
|
+
let active = false;
|
|
354
|
+
for (const weight of morph.weights) {
|
|
355
|
+
if (weight !== 0) {
|
|
356
|
+
active = true;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (!active) {
|
|
361
|
+
frameState.morphBuffers.get(cacheKey)?.buffer.destroy();
|
|
362
|
+
frameState.morphBuffers.delete(cacheKey);
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const vertices = new Float32Array(mesh.vertices);
|
|
367
|
+
for (let targetIndex = 0; targetIndex < targets.length; targetIndex += 1) {
|
|
368
|
+
const weight = morph.weights[targetIndex] ?? 0;
|
|
369
|
+
const positions = targets[targetIndex]?.position;
|
|
370
|
+
if (positions === undefined || positions.length !== base.vertexCount * 3) return undefined;
|
|
371
|
+
for (let vertex = 0; vertex < base.vertexCount; vertex += 1) {
|
|
372
|
+
const vertexBase = vertex * stride;
|
|
373
|
+
const positionBase = vertex * 3;
|
|
374
|
+
vertices[vertexBase] = (vertices[vertexBase] ?? 0) + (positions[positionBase] ?? 0) * weight;
|
|
375
|
+
vertices[vertexBase + 1] =
|
|
376
|
+
(vertices[vertexBase + 1] ?? 0) + (positions[positionBase + 1] ?? 0) * weight;
|
|
377
|
+
vertices[vertexBase + 2] =
|
|
378
|
+
(vertices[vertexBase + 2] ?? 0) + (positions[positionBase + 2] ?? 0) * weight;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let cached = frameState.morphBuffers.get(cacheKey);
|
|
383
|
+
if (cached === undefined || cached.byteLength !== vertices.byteLength) {
|
|
384
|
+
if (cached !== undefined && !cached.buffer.isDestroyed) {
|
|
385
|
+
const destroyed = cached.buffer.destroy();
|
|
386
|
+
if (!destroyed.ok) internals.errorRegistry.fire(destroyed.error);
|
|
387
|
+
}
|
|
388
|
+
const created = internals.device.createBuffer({
|
|
389
|
+
label: `morph-${cacheKey}-vbo`,
|
|
390
|
+
size: vertices.byteLength,
|
|
391
|
+
usage: GPU_BUFFER_USAGE_VERTEX | GPU_BUFFER_USAGE_COPY_DST,
|
|
392
|
+
mappedAtCreation: false,
|
|
393
|
+
});
|
|
394
|
+
if (!created.ok) {
|
|
395
|
+
internals.errorRegistry.fire(created.error);
|
|
396
|
+
frameState.morphBuffers.delete(cacheKey);
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
const buffer = new GpuBuffer(internals.device, created.value);
|
|
400
|
+
internals.deviceScope._adopt('buffer', buffer, (owned) => {
|
|
401
|
+
if (!owned.isDestroyed) owned.destroy();
|
|
402
|
+
});
|
|
403
|
+
cached = {
|
|
404
|
+
buffer,
|
|
405
|
+
byteLength: vertices.byteLength,
|
|
406
|
+
};
|
|
407
|
+
frameState.morphBuffers.set(cacheKey, cached);
|
|
408
|
+
}
|
|
409
|
+
const written = internals.device.queue.writeBuffer(cached.buffer.handle, 0, vertices);
|
|
410
|
+
if (!written.ok) {
|
|
411
|
+
internals.errorRegistry.fire(written.error);
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
return { ...base, vertexBuffer: cached.buffer };
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* feat-20260704 M3/w18: build the dispatch-ordered render plan, extracted
|
|
419
|
+
* verbatim from `recordFrame`. (1) M3/w26 dispatch-ordered reorder: reorder
|
|
420
|
+
* `validated` to follow the transparent-dispatch order (extract-order fallback
|
|
421
|
+
* for unmatched entries). (2) feat-20260608 mesh-SSBO capacity gate: size the
|
|
422
|
+
* mesh-SSBO + material-UBO pair to the larger of entity vs cumulative
|
|
423
|
+
* material-slot count, truncating on ceiling (graceful degradation). (3)
|
|
424
|
+
* feat-20260622 fold dispatch plan: build + apply the WebGL2 uniform-cap
|
|
425
|
+
* fallback + bump the folded-draws metric.
|
|
426
|
+
*
|
|
427
|
+
* @internal
|
|
428
|
+
*/
|
|
429
|
+
export function buildDispatchPlan(
|
|
430
|
+
internals: RenderSystemInternals,
|
|
431
|
+
validated: readonly ValidatedRenderable[],
|
|
432
|
+
transparentDispatch: readonly DispatchEntry[],
|
|
433
|
+
foldBuckets: readonly FoldBucket[],
|
|
434
|
+
shadowValidated: readonly ValidatedRenderable[] = [],
|
|
435
|
+
materialBindingClasses?: ReadonlyMap<string, string>,
|
|
436
|
+
): {
|
|
437
|
+
validatedOrdered: readonly ValidatedRenderable[];
|
|
438
|
+
shadowValidatedOrdered: readonly ValidatedRenderable[];
|
|
439
|
+
foldDispatchPlan: FoldDispatchPlan | null;
|
|
440
|
+
materialSlotIndices: readonly (readonly number[])[];
|
|
441
|
+
materialSlots: readonly MaterialSnapshot[];
|
|
442
|
+
materialSlotOwners: readonly ValidatedRenderable[];
|
|
443
|
+
materialSlotCount: number;
|
|
444
|
+
} {
|
|
445
|
+
// A production GPU-owned frame has no CPU validated rows by design. The
|
|
446
|
+
// dispatch list can still contain one entry per authored entity, but no
|
|
447
|
+
// CPU plan, material table, or fold bucket is consumed in that lane. Return
|
|
448
|
+
// the empty plan without walking that list so a steady 100k scene remains
|
|
449
|
+
// bounded by the persistent GPU batches rather than per-entity record work.
|
|
450
|
+
if (validated.length === 0 && shadowValidated.length === 0) {
|
|
451
|
+
const meshSsboCapResult = ensureMeshSsboCapacity(internals, shadowValidated.length);
|
|
452
|
+
const meshSsboSlotCapacity = meshSsboSlotCapacityAfterEnsure(
|
|
453
|
+
internals,
|
|
454
|
+
shadowValidated.length,
|
|
455
|
+
meshSsboCapResult,
|
|
456
|
+
);
|
|
457
|
+
return {
|
|
458
|
+
validatedOrdered: [],
|
|
459
|
+
shadowValidatedOrdered: limitRowsToMeshSsboCapacity(shadowValidated, meshSsboSlotCapacity),
|
|
460
|
+
foldDispatchPlan: null,
|
|
461
|
+
materialSlotIndices: [],
|
|
462
|
+
materialSlots: [],
|
|
463
|
+
materialSlotOwners: [],
|
|
464
|
+
materialSlotCount: 0,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
// M3 / w26: dispatch-ordered render. The dispatch list is pre-sorted
|
|
468
|
+
// by queue (ascending, stable) by the extract stage per plan-strategy D-3.
|
|
469
|
+
// Reorder validated renderables to follow the dispatch order, falling
|
|
470
|
+
// back to extract order for renderables with no matching dispatch entry.
|
|
471
|
+
let dispatchOrderMatchesValidated = transparentDispatch.length === validated.length;
|
|
472
|
+
if (dispatchOrderMatchesValidated) {
|
|
473
|
+
for (let i = 0; i < validated.length; i++) {
|
|
474
|
+
if (transparentDispatch[i]?.renderableIndex !== validated[i]?.renderableIndex) {
|
|
475
|
+
dispatchOrderMatchesValidated = false;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
let validatedOrdered: readonly ValidatedRenderable[] = dispatchOrderMatchesValidated
|
|
481
|
+
? validated
|
|
482
|
+
: [...validated];
|
|
483
|
+
if (transparentDispatch.length > 0 && !dispatchOrderMatchesValidated) {
|
|
484
|
+
const validatedByRenderableIdx = new Map<number, ValidatedRenderable>();
|
|
485
|
+
const seen = new Set<number>();
|
|
486
|
+
for (const v of validated) {
|
|
487
|
+
validatedByRenderableIdx.set(v.renderableIndex, v);
|
|
488
|
+
}
|
|
489
|
+
const ordered: ValidatedRenderable[] = [];
|
|
490
|
+
for (const de of transparentDispatch) {
|
|
491
|
+
if (de.renderableIndex === undefined) continue;
|
|
492
|
+
const v = validatedByRenderableIdx.get(de.renderableIndex);
|
|
493
|
+
if (v !== undefined && !seen.has(de.renderableIndex)) {
|
|
494
|
+
seen.add(de.renderableIndex);
|
|
495
|
+
ordered.push(v);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// Append renderables not in the dispatch list (e.g. default-material entities)
|
|
499
|
+
for (const v of validated) {
|
|
500
|
+
if (!seen.has(v.renderableIndex)) {
|
|
501
|
+
ordered.push(v);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
validatedOrdered = ordered;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Shadow-only/off-camera CPU residuals consume the same material UBO as
|
|
508
|
+
// visible draws. Their preparation must not depend on main-view visibility.
|
|
509
|
+
const materialRows = [...validatedOrdered, ...shadowValidated];
|
|
510
|
+
const materialGroups = materialRows.map((entry): readonly MaterialSnapshot[] => {
|
|
511
|
+
const shaderId = entry.source.material.materialShaderId;
|
|
512
|
+
if (shaderId === 'forgeax::sprite' || shaderId === 'forgeax::sprite-lit') {
|
|
513
|
+
return [entry.source.material];
|
|
514
|
+
}
|
|
515
|
+
return entry.source.materials.length > 0 ? entry.source.materials : [entry.source.material];
|
|
516
|
+
});
|
|
517
|
+
const materialSlotPlan = buildMaterialSlotPlan(materialGroups, (material, owner) => {
|
|
518
|
+
const row = materialRows[owner];
|
|
519
|
+
return row === undefined
|
|
520
|
+
? ''
|
|
521
|
+
: (materialBindingClasses?.get(
|
|
522
|
+
materialBindingKey(row.source, material.materialHandle ?? -1),
|
|
523
|
+
) ?? '');
|
|
524
|
+
});
|
|
525
|
+
let materialSlotIndices = materialSlotPlan.slotIndices;
|
|
526
|
+
let materialSlots = materialSlotPlan.slots;
|
|
527
|
+
let materialSlotOwners = materialSlotPlan.slotOwners.map((index) => {
|
|
528
|
+
const owner = materialRows[index];
|
|
529
|
+
if (owner === undefined) throw new Error('material slot has no validated owner');
|
|
530
|
+
return owner;
|
|
531
|
+
});
|
|
532
|
+
let materialSlotCount = materialSlots.length;
|
|
533
|
+
let materialRenderableCount = materialRows.length;
|
|
534
|
+
|
|
535
|
+
// feat-20260608-mesh-ssbo-dynamic-grow-l1-lift-1024-entity-cap M3 / T-M3-04:
|
|
536
|
+
// ensure the mesh-SSBO + material-UBO buffer pair is large enough to hold
|
|
537
|
+
// the render plan BEFORE the first per-entity writeBuffer.
|
|
538
|
+
// On `ok:false` the controller has already fired a structured RuntimeError
|
|
539
|
+
// (`mesh-ssbo-ceiling-reached` / `mesh-ssbo-capacity-exceeded`); we truncate
|
|
540
|
+
// the draw list to the largest complete entity prefix whose cumulative
|
|
541
|
+
// material slots fit `degradedToSlotCount` (graceful degradation per
|
|
542
|
+
// plan-strategy D-2): render the subset that fits, discard overflow, no
|
|
543
|
+
// black frame. The helper is idempotent across same-frame re-calls (AC-09)
|
|
544
|
+
// and short-circuits on length=0 / length<=slotCount (boundary table).
|
|
545
|
+
//
|
|
546
|
+
// bug-20260609: feat-20260608 M5 amend made the material UBO indexed by
|
|
547
|
+
// cumulative *material-slot* count (one slot per submesh material),
|
|
548
|
+
// which is >= entity count once an entity carries `materials.length>1`.
|
|
549
|
+
// The mesh + material buffer pair share `slotCount` (single allocator),
|
|
550
|
+
// so we size against the larger of the two requirements: entity count
|
|
551
|
+
// (mesh-SSBO consumer) vs cumulative material-slot count (material-UBO
|
|
552
|
+
// consumer). Sprite entities collapse to 1 slot in the material table,
|
|
553
|
+
// mirroring the same rule (sprite per-submesh OOS-1;
|
|
554
|
+
// post-w13 judgement key migrated to materialShaderId).
|
|
555
|
+
//
|
|
556
|
+
// feat-20260624 M1' / t7: sprite-lit treated identically to sprite
|
|
557
|
+
// for material-slot accounting (paramSchema mirror, t4).
|
|
558
|
+
const neededSlots = Math.max(validatedOrdered.length + shadowValidated.length, materialSlotCount);
|
|
559
|
+
const meshSsboCapResult = ensureMeshSsboCapacity(internals, neededSlots);
|
|
560
|
+
const meshSsboSlotCapacity = meshSsboSlotCapacityAfterEnsure(
|
|
561
|
+
internals,
|
|
562
|
+
neededSlots,
|
|
563
|
+
meshSsboCapResult,
|
|
564
|
+
);
|
|
565
|
+
if (!meshSsboCapResult.ok) {
|
|
566
|
+
// Graceful degradation: the controller reports slots, but this stage
|
|
567
|
+
// consumes entities. Find a complete prefix instead of slicing at the
|
|
568
|
+
// numeric slot count; a multi-material entity can consume several slots.
|
|
569
|
+
const degradedRenderableCount = findRenderablePrefixForSlotCapacity(
|
|
570
|
+
materialSlotIndices,
|
|
571
|
+
meshSsboCapResult.degradedToSlotCount,
|
|
572
|
+
);
|
|
573
|
+
materialRenderableCount = degradedRenderableCount;
|
|
574
|
+
materialSlotCount = materialSlotCountForPrefix(materialSlotIndices, degradedRenderableCount);
|
|
575
|
+
materialSlotIndices = materialSlotIndices.slice(0, degradedRenderableCount);
|
|
576
|
+
materialSlots = materialSlots.slice(0, materialSlotCount);
|
|
577
|
+
materialSlotOwners = materialSlotOwners.slice(0, materialSlotCount);
|
|
578
|
+
validatedOrdered = validatedOrdered.slice(0, degradedRenderableCount);
|
|
579
|
+
}
|
|
580
|
+
const shadowValidatedOrdered = limitRowsToMeshSsboCapacity(
|
|
581
|
+
shadowValidated,
|
|
582
|
+
Math.min(meshSsboSlotCapacity, materialRenderableCount) - validatedOrdered.length,
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
// feat-20260622-chunk-gpu-instancing-sprite-tilemap M1 / w4-record-swap
|
|
586
|
+
// (D-1): build the fold dispatch plan once `validatedOrdered` is final
|
|
587
|
+
// (post truncation by mesh-SSBO capacity gate). The plan re-keys each
|
|
588
|
+
// non-singleton bucket from `renderableIndex` to the validated-ordered
|
|
589
|
+
// index `i` consumed by the dispatch loops; the loops use it to skip
|
|
590
|
+
// non-head bucket members and emit one instanced drawIndexed per
|
|
591
|
+
// bucket head. Empty plan (no fold-eligible buckets) is a byte-
|
|
592
|
+
// identical no-op for the dispatch loops below (charter P3: silent
|
|
593
|
+
// pass-through, no error path).
|
|
594
|
+
let renderableToValidatedIdx: Map<number, number> | null = null;
|
|
595
|
+
let foldDispatchPlan: FoldDispatchPlan | null = null;
|
|
596
|
+
if (foldBuckets.length > 0) {
|
|
597
|
+
renderableToValidatedIdx = new Map<number, number>();
|
|
598
|
+
for (let i = 0; i < validatedOrdered.length; i++) {
|
|
599
|
+
const e = validatedOrdered[i];
|
|
600
|
+
if (e === undefined) continue;
|
|
601
|
+
renderableToValidatedIdx.set(e.renderableIndex, i);
|
|
602
|
+
}
|
|
603
|
+
foldDispatchPlan = buildFoldDispatchPlan(foldBuckets, renderableToValidatedIdx);
|
|
604
|
+
|
|
605
|
+
// feat-20260622 M2 / w11 (D-2 + D-9 + AC-05): WebGL2 uniform-fallback
|
|
606
|
+
// per-bucket instance-count cap. When caps.storageBuffer===false AND
|
|
607
|
+
// a fold bucket carries more than FOLD_UNIFORM_INSTANCE_CAP (128)
|
|
608
|
+
// instances, fire RhiError({code:'instancing-exceeds-uniform-cap'})
|
|
609
|
+
// AND remove the bucket from the dispatch plan so its members fall
|
|
610
|
+
// through to the per-entity drawIndexed exit (the same exit the
|
|
611
|
+
// mode-gate bypass uses — D-9 "shared fallback exit"). The frame
|
|
612
|
+
// stays visually correct (charter proposition 9 graceful
|
|
613
|
+
// degradation: no identity-collapse / black screen) while the cap
|
|
614
|
+
// event surfaces structurally for AI users (proposition 4 explicit
|
|
615
|
+
// failure on .code).
|
|
616
|
+
//
|
|
617
|
+
// Scope discrimination: tilemap-chunk-extract-system encodes
|
|
618
|
+
// Layer.value = (layerOrder<<20) | (chunkIndex & 0xfffff), so a
|
|
619
|
+
// bucket whose head entry carries non-zero low-20-bits is
|
|
620
|
+
// definitively a tilemap-chunk dispatch site. Plain sprite buckets
|
|
621
|
+
// use SPRITE_LAYER_VALUE = layerOrder<<20 (low-20 zero) by the
|
|
622
|
+
// documented convention (apps/hello/asi-world main.ts pattern).
|
|
623
|
+
// The chunkIndex===0 edge case maps to 'sprite' (the helper's
|
|
624
|
+
// default branch) — a one-bucket ambiguity per layerOrder that is
|
|
625
|
+
// acceptable for the AI-user affordance level (the error semantics
|
|
626
|
+
// — "this bucket exceeded the cap" — is the actionable signal;
|
|
627
|
+
// scope=sprite vs tilemap-chunk only refines the recovery hint).
|
|
628
|
+
if (foldDispatchPlan.headBuckets.size > 0 && !internals.device.caps.storageBuffer) {
|
|
629
|
+
const filteredHeads = new Map<number, FoldBucket>(foldDispatchPlan.headBuckets);
|
|
630
|
+
const filteredSkips = new Set<number>(foldDispatchPlan.skipIndices);
|
|
631
|
+
let filteredCount = foldDispatchPlan.foldedBucketCount;
|
|
632
|
+
for (const [headIdx, bucket] of foldDispatchPlan.headBuckets) {
|
|
633
|
+
const scope: 'sprite' | 'tilemap-chunk' =
|
|
634
|
+
(bucket.layer & 0xfffff) !== 0 ? 'tilemap-chunk' : 'sprite';
|
|
635
|
+
const decision = evaluateFoldBucketUniformCap(bucket, internals.device.caps, scope);
|
|
636
|
+
if (decision.fallback && decision.error !== undefined) {
|
|
637
|
+
internals.errorRegistry.fire(decision.error);
|
|
638
|
+
filteredHeads.delete(headIdx);
|
|
639
|
+
filteredCount -= 1;
|
|
640
|
+
for (let j = 1; j < bucket.entries.length; j++) {
|
|
641
|
+
const memberEntry = bucket.entries[j];
|
|
642
|
+
if (memberEntry === undefined) continue;
|
|
643
|
+
const memberValidatedIdx = renderableToValidatedIdx.get(memberEntry.renderableIndex);
|
|
644
|
+
if (memberValidatedIdx !== undefined) {
|
|
645
|
+
filteredSkips.delete(memberValidatedIdx);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (filteredCount !== foldDispatchPlan.foldedBucketCount) {
|
|
651
|
+
foldDispatchPlan = {
|
|
652
|
+
headBuckets: filteredHeads,
|
|
653
|
+
skipIndices: filteredSkips,
|
|
654
|
+
foldedBucketCount: filteredCount,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// feat-20260622-chunk-gpu-instancing-sprite-tilemap M3 / w13 (D-3 +
|
|
660
|
+
// AC-06): increment `render.instancing.foldedDraws` once per fold-
|
|
661
|
+
// eligible head bucket retained after the cap-fallback filter above.
|
|
662
|
+
// The metric tracks instanced drawIndexed call count for this frame
|
|
663
|
+
// — cap-overrun buckets routed through the per-entity fallback exit
|
|
664
|
+
// are removed from `foldDispatchPlan` and therefore not counted, by
|
|
665
|
+
// construction (M2 / w11 cap-fallback + plan-strategy D-3 semantics).
|
|
666
|
+
// Singleton buckets (mode-bypass under D-5, or non-foldable under
|
|
667
|
+
// mode 0) carry `bucketSize === 1` and never enter `headBuckets`, so
|
|
668
|
+
// the per-entity drawIndexed path correctly does not count.
|
|
669
|
+
// SSOT helper lives in this record owner — engine code never
|
|
670
|
+
// hardcodes the metric key string.
|
|
671
|
+
incrementFoldedDrawsMetric(foldDispatchPlan, internals.metrics);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return {
|
|
675
|
+
validatedOrdered,
|
|
676
|
+
shadowValidatedOrdered,
|
|
677
|
+
foldDispatchPlan,
|
|
678
|
+
materialSlotIndices,
|
|
679
|
+
materialSlots,
|
|
680
|
+
materialSlotOwners,
|
|
681
|
+
materialSlotCount,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* feat-20260704 M3/w18: per-frame cache clean-up (despawn eviction), extracted
|
|
687
|
+
* verbatim from `recordFrame`.
|
|
688
|
+
*
|
|
689
|
+
* feat-20260531-per-frame-bind-group-cache M4 / w14 (D-5): drop per-entity BG
|
|
690
|
+
* cache entries (materialBgPerEntity / instancesBgPerEntity) + instance buffers
|
|
691
|
+
* whose outer-Map entityKey (packed Entity u32) is absent from the current
|
|
692
|
+
* validated set, preventing unbounded growth after entity despawn. view + mesh
|
|
693
|
+
* caches are frame-shared (keyed by GPU resource handle objects, WeakMap chains
|
|
694
|
+
* naturally bounded) and are not touched. feat-20260619 M4 / F11: destroy the
|
|
695
|
+
* GPU instance buffer before Map.delete (D-6 symmetric release); failure fires
|
|
696
|
+
* errorRegistry + continues the sweep.
|
|
697
|
+
*
|
|
698
|
+
* @internal
|
|
699
|
+
*/
|
|
700
|
+
export function cleanPerFrameCaches(
|
|
701
|
+
internals: RenderSystemInternals,
|
|
702
|
+
frameState: RenderFrameState,
|
|
703
|
+
validated: readonly ValidatedRenderable[],
|
|
704
|
+
retainedEntityKeys: ReadonlySet<number> = new Set<number>(),
|
|
705
|
+
): void {
|
|
706
|
+
if (frameState.transientInstanceBuffers !== undefined) {
|
|
707
|
+
disposeTransientInstanceBuffers(frameState.transientInstanceBuffers, internals.errorRegistry);
|
|
708
|
+
}
|
|
709
|
+
// Build a Set<number> of worldEntityKey composites from the validated
|
|
710
|
+
// renderables. D-1a #4: validatedEntityKeys are worldEntityKey(worldId, entityKey)
|
|
711
|
+
// composites matching the write-side keys of #1-#3 — cross-world false eviction
|
|
712
|
+
// is prevented because worldEntityKey(0, k) !== worldEntityKey(1, k).
|
|
713
|
+
const validatedEntityKeys = new Set<number>(retainedEntityKeys);
|
|
714
|
+
const validatedInstanceKeys = new Set<number>(retainedEntityKeys);
|
|
715
|
+
for (const v of validated) {
|
|
716
|
+
const entityKey = worldEntityKey(v.source.worldId, v.source.entityKey);
|
|
717
|
+
validatedEntityKeys.add(entityKey);
|
|
718
|
+
validatedInstanceKeys.add(entityKey);
|
|
719
|
+
if (v.source.instances !== undefined) {
|
|
720
|
+
validatedInstanceKeys.add(instanceCollectionCacheKey(v.source.worldId, v.source.instances));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Clean per-entity material BG cache: drop outer-Map entries whose
|
|
725
|
+
// entityKey is absent from the current validated set. The shared and
|
|
726
|
+
// singleton material caches have no entityKey and are not touched here.
|
|
727
|
+
cleanPerEntityCache(frameState.materialBgPerEntity, validatedEntityKeys);
|
|
728
|
+
|
|
729
|
+
// Clean per-entity instances BG cache.
|
|
730
|
+
cleanPerEntityCache(frameState.instancesBgPerEntity, validatedEntityKeys);
|
|
731
|
+
|
|
732
|
+
// D-5 retrofit: instanceBuffers clean-up. The instanceBuffers Map is
|
|
733
|
+
// keyed by cacheKey (packed Entity u32, same as entityKey on
|
|
734
|
+
// RenderableSnapshot). Drop entries whose key is no longer in the
|
|
735
|
+
// validated set (OQ-3 / R-4). feat-20260619 M4 / F11: destroy the GPU
|
|
736
|
+
// buffer before Map.delete so despawned entities release their
|
|
737
|
+
// instance-buffer backing memory symmetrically (D-6).
|
|
738
|
+
//
|
|
739
|
+
// D-1a #1: instanceBuffers keys on the positive half (>= 0) are
|
|
740
|
+
// worldEntityKey composites matching the write side. Negative half
|
|
741
|
+
// fold-bucket keys (< 0) are NOT worldEntityKey; they are
|
|
742
|
+
// material-handle-based and cross-world collision is semantically
|
|
743
|
+
// correct (same material renders in same fold bucket).
|
|
744
|
+
for (const [key, entry] of frameState.instanceBuffers.entries()) {
|
|
745
|
+
if (!validatedInstanceKeys.has(key)) {
|
|
746
|
+
if (!entry.buffer.isDestroyed) {
|
|
747
|
+
const r = entry.buffer.destroy();
|
|
748
|
+
if (!r.ok) internals.errorRegistry.fire(r.error);
|
|
749
|
+
}
|
|
750
|
+
frameState.instanceBuffers.delete(key);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// Chunk keys are `${worldEntityKey}:${chunkStart}`. Keep the key opaque to
|
|
755
|
+
// the authoring API, but retain the numeric owner prefix for eviction.
|
|
756
|
+
if (frameState.instanceBufferChunks !== undefined) {
|
|
757
|
+
for (const [key, entry] of frameState.instanceBufferChunks.entries()) {
|
|
758
|
+
const separator = key.indexOf(':');
|
|
759
|
+
const ownerKey = separator < 0 ? Number.NaN : Number(key.slice(0, separator));
|
|
760
|
+
if (validatedInstanceKeys.has(ownerKey)) continue;
|
|
761
|
+
if (!entry.buffer.isDestroyed) {
|
|
762
|
+
const r = entry.buffer.destroy();
|
|
763
|
+
if (!r.ok) internals.errorRegistry.fire(r.error);
|
|
764
|
+
}
|
|
765
|
+
frameState.instanceBufferChunks.delete(key);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (frameState.morphBuffers !== undefined) {
|
|
770
|
+
for (const [key, entry] of frameState.morphBuffers.entries()) {
|
|
771
|
+
if (validatedEntityKeys.has(key)) continue;
|
|
772
|
+
if (!entry.buffer.isDestroyed) {
|
|
773
|
+
const result = entry.buffer.destroy();
|
|
774
|
+
if (!result.ok) internals.errorRegistry.fire(result.error);
|
|
775
|
+
}
|
|
776
|
+
frameState.morphBuffers.delete(key);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* feat-20260704 M3/w18: record-stage fold operator linear scan, extracted
|
|
783
|
+
* verbatim from `recordFrame`.
|
|
784
|
+
*
|
|
785
|
+
* feat-20260622-chunk-gpu-instancing-sprite-tilemap M1 / w4 + w5 (D-1, D-5):
|
|
786
|
+
* groups transparent-sort-ordered dispatch entries with equal (Layer.value,
|
|
787
|
+
* sortKey, materialHandle) into fold buckets. Mode-gate (D-5 extended): modes 0
|
|
788
|
+
* (LAYER_Z) and 1 (LAYER_Y) fold using the pos z/y lanes; modes 2/3 bypass per-entity
|
|
789
|
+
* (each entry a singleton bucket). Records `frameState.lastFoldBucketCount` =
|
|
790
|
+
* fold-eligible buckets (bucketSize > 1) for the AC-06 metric. Empty dispatch
|
|
791
|
+
* short-circuits (test fixtures pass null world).
|
|
792
|
+
*
|
|
793
|
+
* @internal
|
|
794
|
+
*/
|
|
795
|
+
export function computeFoldBuckets(
|
|
796
|
+
world: World,
|
|
797
|
+
frameState: RenderFrameState,
|
|
798
|
+
transparentDispatch: readonly DispatchEntry[],
|
|
799
|
+
renderables: readonly RenderableSnapshot[],
|
|
800
|
+
): readonly FoldBucket[] {
|
|
801
|
+
if (transparentDispatch.length === 0) {
|
|
802
|
+
frameState.lastFoldBucketCount = 0;
|
|
803
|
+
return [];
|
|
804
|
+
}
|
|
805
|
+
const transparentSortCfg = getTransparentSortConfig(world);
|
|
806
|
+
|
|
807
|
+
// Only layer-Z / layer-Y modes can produce non-singleton fold buckets.
|
|
808
|
+
// The other modes make one inert singleton per entry, which is discarded by
|
|
809
|
+
// buildFoldDispatchPlan. Returning the same empty plan here avoids allocating
|
|
810
|
+
// a transform matrix for every renderable when folding is disabled by mode.
|
|
811
|
+
if (
|
|
812
|
+
transparentSortCfg.mode !== TRANSPARENT_SORT_MODE_LAYER_Z &&
|
|
813
|
+
transparentSortCfg.mode !== TRANSPARENT_SORT_MODE_LAYER_Y
|
|
814
|
+
) {
|
|
815
|
+
frameState.lastFoldBucketCount = 0;
|
|
816
|
+
return [];
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// `transparentDispatch` is the legacy name for the complete sorted dispatch
|
|
820
|
+
// list. Opaque entries can never participate in the transparent-only fold
|
|
821
|
+
// plan, yet foldDispatchBuckets must preserve its general helper contract and
|
|
822
|
+
// therefore materializes an inert singleton (including a Float32Array(16))
|
|
823
|
+
// for each one. Filter only at this private production call site so the fold
|
|
824
|
+
// helper keeps its testable semantics while record avoids work whose result
|
|
825
|
+
// is provably discarded.
|
|
826
|
+
let transparentCount = 0;
|
|
827
|
+
for (const entry of transparentDispatch) {
|
|
828
|
+
if (renderables[entry.renderableIndex]?.material.transparent === true) {
|
|
829
|
+
transparentCount += 1;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (transparentCount === 0) {
|
|
833
|
+
frameState.lastFoldBucketCount = 0;
|
|
834
|
+
return [];
|
|
835
|
+
}
|
|
836
|
+
const foldCandidates =
|
|
837
|
+
transparentCount === transparentDispatch.length
|
|
838
|
+
? transparentDispatch
|
|
839
|
+
: transparentDispatch.filter(
|
|
840
|
+
(entry) => renderables[entry.renderableIndex]?.material.transparent === true,
|
|
841
|
+
);
|
|
842
|
+
const foldBuckets = foldDispatchBuckets(foldCandidates, transparentSortCfg.mode, renderables);
|
|
843
|
+
// Count only fold-eligible buckets (bucketSize > 1) so the metric
|
|
844
|
+
// surfaces fold actually reducing draws — singleton buckets under
|
|
845
|
+
// mode bypass do not change draw count, so they do not contribute.
|
|
846
|
+
let foldEligibleCount = 0;
|
|
847
|
+
for (const b of foldBuckets) {
|
|
848
|
+
if (b.bucketSize > 1) foldEligibleCount += 1;
|
|
849
|
+
}
|
|
850
|
+
frameState.lastFoldBucketCount = foldEligibleCount;
|
|
851
|
+
return foldBuckets;
|
|
852
|
+
}
|