@zephyr3d/scene 0.9.0 → 0.9.2
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/dist/animation/animationset.js +135 -133
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/cloth/gpu_cloth_system.js +9 -1
- package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
- package/dist/animation/fixed_geometry_cache_track.js +5 -1
- package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
- package/dist/animation/geometry_cache_utils.js +20 -4
- package/dist/animation/geometry_cache_utils.js.map +1 -1
- package/dist/animation/ik/ik_angle_constraint.js +2 -6
- package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
- package/dist/animation/ik/two_bone_ik_solver.js +2 -6
- package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
- package/dist/animation/joint_dynamics/collision.js +60 -12
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +20 -4
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +151 -103
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +21 -11
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +15 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/animation/pca_geometry_cache_track.js +5 -1
- package/dist/animation/pca_geometry_cache_track.js.map +1 -1
- package/dist/animation/skeleton.js +2 -2
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/skeleton_modifier.js +2 -6
- package/dist/animation/skeleton_modifier.js.map +1 -1
- package/dist/animation/spring/spring_system.js +87 -114
- package/dist/animation/spring/spring_system.js.map +1 -1
- package/dist/app/app.js.map +1 -1
- package/dist/app/engine.js +1 -1
- package/dist/app/engine.js.map +1 -1
- package/dist/app/screen.js +4 -4
- package/dist/app/screen.js.map +1 -1
- package/dist/app/scriptingsystem.js +24 -1
- package/dist/app/scriptingsystem.js.map +1 -1
- package/dist/app/scriptregistry.js +165 -144
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -2
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +3 -3
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/camera.js +185 -185
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +794 -261
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/material.js +290 -288
- package/dist/material/material.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -26
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/pbrmr.js +1 -11
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/sprite.js +6 -6
- package/dist/material/sprite.js.map +1 -1
- package/dist/material/terrain-cm.js +2 -2
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/posteffect/taa.js +31 -39
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/drawable.js +5 -1
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +29 -3
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +283 -33
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +338 -108
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +236 -156
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +10 -0
- package/dist/render/rendergraph/history_resources.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +162 -35
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/types.js +36 -16
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/rendertarget.js +5 -1
- package/dist/render/rendertarget.js.map +1 -1
- package/dist/render/screenrendertarget.js +5 -1
- package/dist/render/screenrendertarget.js.map +1 -1
- package/dist/render/sky.js +4 -4
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/basesprite.js +2 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/graph_node.js +1 -1
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +4 -20
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/particlesys.js +1 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene_node.js +2 -2
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/script_attachment.js +15 -3
- package/dist/scene/script_attachment.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +3 -3
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shapes/box.js +1 -1
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/capsule.js +0 -3
- package/dist/shapes/capsule.js.map +1 -1
- package/dist/shapes/cylinder.js +0 -3
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +0 -3
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/tetrahedron.js +3 -9
- package/dist/shapes/tetrahedron.js.map +1 -1
- package/dist/shapes/torus.js +4 -7
- package/dist/shapes/torus.js.map +1 -1
- package/dist/utility/blueprint/material/inputs.js +3 -3
- package/dist/utility/blueprint/material/inputs.js.map +1 -1
- package/dist/utility/blueprint/material/ir.js +493 -493
- package/dist/utility/blueprint/material/ir.js.map +1 -1
- package/dist/utility/serialization/manager.js +34 -3
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +45 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +53 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +10 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +30 -0
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +63 -0
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +11 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/misc.js +2 -0
- package/dist/utility/serialization/scene/misc.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +19 -0
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +22 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +33 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +39 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/script.js +2 -0
- package/dist/utility/serialization/scene/script.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +9 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +21 -0
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js +5 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawable.js","sources":["../../src/render/drawable.ts"],"sourcesContent":["import type { DRef, Nullable, TypedArray, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n ColorState,\r\n FaceMode,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n Texture2D,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { Primitive, RenderPass } from '.';\r\nimport type { DrawableInstanceInfo, InstanceData, RenderQueue, RenderQueueRef } from './render_queue';\r\nimport type { ShadowMapParams } from '../shadow';\r\nimport type { Environment } from '../scene/environment';\r\nimport type { DirectionalLight, PunctualLight, Scene, SceneNode } from '../scene';\r\nimport type { Compositor } from '../posteffect';\r\nimport type { ClusteredLight } from './cluster_light';\r\nimport type { MeshMaterial } from '../material';\r\nimport type { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport type { OIT } from './oit';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Picking result target container.\r\n *\r\n * Use to override/annotate which scene node (and optional label) a drawable should report\r\n * when GPU picking or raycast returns a hit.\r\n *\r\n * @public\r\n */\r\nexport type PickTarget = { node: SceneNode; label?: string };\r\n\r\nexport class RenderContext {\r\n public device: AbstractDevice;\r\n public renderWidth: number;\r\n public renderHeight: number;\r\n constructor(_camera: Camera, w: number, h: number) {\r\n this.device = getDevice();\r\n this.renderWidth = w;\r\n this.renderHeight = h;\r\n }\r\n}\r\n/**\r\n * Context object passed to draw calls and render helpers.\r\n *\r\n * It aggregates all per-frame, per-pass, and per-draw state derived from the engine and renderer,\r\n * including device handles, textures, passes, flags, and post-processing links.\r\n *\r\n * Notes:\r\n * - Not all textures/fields are present for every pass; check for undefined when optional.\r\n * - Values like `HiZ`, `TAA`, `SSR` signal features the renderer has activated for the current pass.\r\n *\r\n * @public\r\n */\r\nexport interface DrawContext {\r\n /** Render device used for issuing GPU commands. */\r\n readonly device: AbstractDevice;\r\n /** Framebuffer width for rendering (in pixels). */\r\n readonly renderWidth: number;\r\n /** Framebuffer height for rendering (in pixels). */\r\n readonly renderHeight: number;\r\n /** Allocator for global (frame/pass) bind groups and descriptor resources. */\r\n readonly globalBindGroupAllocator: GlobalBindGroupAllocator;\r\n /** The camera associated with the current drawing task (may differ from primaryCamera). */\r\n readonly camera: Camera;\r\n /** Order-Independent Transparency interface for transparent passes. */\r\n oit: Nullable<OIT>;\r\n /** Whether motion vectors are being written this pass (used by TAA/MotionBlur). */\r\n readonly motionVectors: boolean;\r\n /** Motion vector texture target when motion vectors are active. */\r\n motionVectorTexture?: Nullable<Texture2D>;\r\n /** Whether hierarchical depth (Hi-Z) is enabled for the current pass. */\r\n readonly HiZ: boolean;\r\n /** Hi-Z (hierarchical Z) depth texture, when generated. */\r\n HiZTexture: Nullable<Texture2D>;\r\n /** The scene currently being drawn. */\r\n readonly scene: Scene;\r\n /** The render pass to which this drawing task belongs. */\r\n renderPass: Nullable<RenderPass>;\r\n /** Stable hash for the current pass/draw state, for render bundle or pipeline cache. */\r\n renderPassHash: Nullable<string>;\r\n /** Whether the output orientation is flipped vertically (e.g., due to framebuffer conventions). */\r\n flip: boolean;\r\n /** Whether this is the base lighting pass that draws environment lighting. */\r\n drawEnvLight: boolean;\r\n /** Scene environment (sky, IBL, exposure, etc.) used for shading. */\r\n env: Nullable<Environment>;\r\n /** Current sub-queue index within the render queue (e.g., opaque, transparent). */\r\n queue: number;\r\n /** Whether the current lighting pass is blending light accumulations. */\r\n lightBlending: boolean;\r\n /** Scene (non-linear) depth texture bound for sampling. */\r\n depthTexture?: Texture2D;\r\n /** Linearized depth texture bound for sampling. */\r\n linearDepthTexture?: Texture2D;\r\n /** Scene color texture bound for sampling (previous pass or resolved color). */\r\n sceneColorTexture?: Texture2D;\r\n /** Default depth buffer format for targets created in this pass. */\r\n readonly depthFormat: TextureFormat;\r\n /** Default color buffer format for targets created in this pass. */\r\n readonly colorFormat: TextureFormat;\r\n /** Instance data buffer/metadata for the current drawing task (instanced rendering). */\r\n instanceData?: Nullable<InstanceData>;\r\n /** Compositor used to apply post-processing effects at the end of the frame/pass. */\r\n compositor?: Nullable<Compositor>;\r\n /** @internal Map of punctual lights to their shadow map parameters for this pass. */\r\n shadowMapInfo?: Nullable<Map<PunctualLight, ShadowMapParams>>;\r\n /** @internal The punctual light currently rendering shadows (shadow pass). */\r\n currentShadowLight?: Nullable<PunctualLight>;\r\n /** Sun/directional light reference for passes that need it. */\r\n sunLight?: Nullable<DirectionalLight>;\r\n /** Clustered light index/structure for lighting in forward+, clustered shading, etc. */\r\n clusteredLight?: ClusteredLight;\r\n /** Material varying bit flags that influence shader selection. */\r\n materialFlags: number;\r\n /** Force cull mode override for special passes (optional). */\r\n forceCullMode?: Nullable<FaceMode>;\r\n /** Force color mask state override for special passes (optional). */\r\n forceColorState?: Nullable<ColorState>;\r\n /** Screen-space reflections are active this frame/pass. */\r\n readonly SSR: boolean;\r\n /** Whether SSR thickness should be computed dynamically in this pass. */\r\n SSRCalcThickness: boolean;\r\n /** SSR roughness input texture. */\r\n SSRRoughnessTexture: Texture2D;\r\n /** SSR normal input texture (usually view-space or world-space normals). */\r\n SSRNormalTexture: Texture2D;\r\n /** Final framebuffer target where the last stage renders. */\r\n finalFramebuffer: Nullable<FrameBuffer>;\r\n /** Intermediate framebuffer used by the compositor or multi-pass pipelines. */\r\n intermediateFramebuffer: Nullable<FrameBuffer>;\r\n}\r\n\r\n/**\r\n * Morph Data\r\n * @public\r\n */\r\nexport type MorphData = {\r\n width: number;\r\n height: number;\r\n data: Float32Array<ArrayBuffer>;\r\n texture?: DRef<Texture2D>;\r\n};\r\n\r\n/**\r\n * Morph information\r\n * @public\r\n */\r\nexport type MorphInfo = { data: TypedArray; buffer?: DRef<GPUDataBuffer>; names: Record<string, number> };\r\n\r\n/**\r\n * Base interface for a drawable (renderable) object.\r\n *\r\n * A drawable encapsulates geometry, material, and GPU-resident data required to be rendered.\r\n * Implementations integrate with render queues, batching, and instancing.\r\n *\r\n * @public\r\n */\r\nexport interface Drawable {\r\n /** Gets the display name of the drawable object (for debugging/UI). */\r\n getName(): string;\r\n /** Unique, stable identifier for the drawable, used in caches and picking. */\r\n getDrawableId(): number;\r\n /** Returns the owning scene node (transform and hierarchy). */\r\n getNode(): SceneNode;\r\n /**\r\n * Returns the pick target override to be reported when this object is picked.\r\n *\r\n * If not set, a default target derived from the node/material may be used.\r\n */\r\n getPickTarget(): PickTarget;\r\n /** Returns the texture containing bone matrices for skinned meshes. */\r\n getBoneMatrices(): Nullable<Texture2D>;\r\n /** Returns the unique color used for GPU picking (object ID in color). */\r\n getObjectColor(): Vector4;\r\n /** Returns the morph target data texture (if morphing is used). */\r\n getMorphData(): Nullable<MorphData>;\r\n /** Returns the morph information buffer (weights, ranges, etc.). */\r\n getMorphInfo(): Nullable<MorphInfo>;\r\n /**\r\n * Computes the distance used for sorting (e.g., transparent draw order).\r\n *\r\n * @param camera - Camera from which to compute distance (usually camera -\\> object).\r\n */\r\n getSortDistance(camera: Camera): number;\r\n /** Returns the type/category of render queue this object belongs to. */\r\n getQueueType(): number;\r\n /** Whether the object requires access to the scene color buffer. */\r\n needSceneColor(): boolean;\r\n /** Whether the object requires access to the scene depth (linear or non-linear). */\r\n needSceneDepth(): boolean;\r\n /** True if shading is unlit (does not depend on scene lighting). */\r\n isUnlit(): boolean;\r\n /** Returns the bound material driving shading for this drawable. */\r\n getMaterial(): Nullable<MeshMaterial>;\r\n /** Returns the geometry primitive to be drawn. */\r\n getPrimitive(): Nullable<Primitive>;\r\n /**\r\n * Pushes a reference to the current render queue for cleanup or back-references.\r\n *\r\n * Useful for batching or deferred state application.\r\n */\r\n pushRenderQueueRef(ref: RenderQueueRef): void;\r\n /**\r\n * Applies transform-related uniforms to the active bind group or pipeline.\r\n *\r\n * @param renderQueue - The current render queue issuing this draw.\r\n */\r\n applyTransformUniforms(renderQueue: RenderQueue): void;\r\n /**\r\n * Issues draw commands for this object.\r\n *\r\n * @param ctx - Full draw context for the current pass.\r\n * @param renderQueue - The current render queue issuing this draw.\r\n * @param hash - Optional hash key for render bundle or pipeline caching.\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string): void;\r\n /**\r\n * Updates internal state or GPU resources for this drawable, if needed.\r\n */\r\n updateState(): void;\r\n /**\r\n * Returns true if the object supports instanced rendering.\r\n *\r\n * When true, the object should also implement the {@link BatchDrawable} methods.\r\n */\r\n isBatchable(): this is BatchDrawable;\r\n /** Releases all GPU resources and detaches from the renderer. */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * Interface for drawables that support hardware instancing.\r\n *\r\n * Instanced drawables supply instance-specific uniforms, offsets, and strides\r\n * to allow a single draw call to render many instances efficiently.\r\n *\r\n * @public\r\n */\r\nexport interface BatchDrawable extends Drawable {\r\n /**\r\n * Returns a stable instance ID string for use with the given render pass.\r\n *\r\n * Used to group compatible instances into batches within a pass.\r\n *\r\n * @param renderPass - The render pass to which current drawing task belongs.\r\n * @internal\r\n */\r\n getInstanceId(renderPass: RenderPass): string;\r\n /**\r\n * Returns a tightly-packed float array of instance uniforms for GPU upload.\r\n *\r\n * The returned memory should be compatible with ArrayBuffer views used by the renderer.\r\n *\r\n * @internal\r\n */\r\n getInstanceUniforms(): Float32Array<ArrayBuffer>;\r\n /**\r\n * Applies instance stride and starting offset to the active bind group.\r\n *\r\n * This informs the shader how to index into the instance buffer for this batch.\r\n *\r\n * @param renderQueue - Render queue associated with the bind group or pipeline.\r\n * @param stride - Per-instance stride in bytes or floats (renderer-defined).\r\n * @param offset - Starting instance offset within the instance buffer.\r\n * @internal\r\n */\r\n applyInstanceOffsetAndStride(renderQueue: RenderQueue, stride: number, offset: number): void;\r\n /**\r\n * Applies material uniforms for a single instance group.\r\n *\r\n * @param instanceInfo - Instance data information for this batch.\r\n * @internal\r\n */\r\n applyMaterialUniforms(instanceInfo: DrawableInstanceInfo): void;\r\n /**\r\n * Applies material uniforms across all grouped instance informations belonging to this material.\r\n *\r\n * Useful when batching merges multiple instance groups sharing the same material.\r\n *\r\n * @internal\r\n */\r\n applyMaterialUniformsAll(): void;\r\n}\r\n"],"names":["RenderContext","device","renderWidth","renderHeight","_camera","w","h","getDevice"],"mappings":";;AAiCO,MAAMA,aAAAA,CAAAA;IACJC,MAAuB;IACvBC,WAAoB;IACpBC,YAAqB;AAC5B,IAAA,WAAA,CAAYC,OAAe,EAAEC,CAAS,EAAEC,CAAS,CAAE;QACjD,IAAI,CAACL,MAAM,GAAGM,SAAAA,EAAAA;QACd,IAAI,CAACL,WAAW,GAAGG,CAAAA;QACnB,IAAI,CAACF,YAAY,GAAGG,CAAAA;AACtB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"drawable.js","sources":["../../src/render/drawable.ts"],"sourcesContent":["import type { DRef, Nullable, TypedArray, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n ColorState,\r\n FaceMode,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n Texture2D,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { Primitive, RenderPass } from '.';\r\nimport type { DrawableInstanceInfo, InstanceData, RenderQueue, RenderQueueRef } from './render_queue';\r\nimport type { ShadowMapParams } from '../shadow';\r\nimport type { Environment } from '../scene/environment';\r\nimport type { DirectionalLight, PunctualLight, Scene, SceneNode } from '../scene';\r\nimport type { Compositor } from '../posteffect';\r\nimport type { ClusteredLight } from './cluster_light';\r\nimport type { MeshMaterial } from '../material';\r\nimport type { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport type { OIT } from './oit';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Picking result target container.\r\n *\r\n * Use to override/annotate which scene node (and optional label) a drawable should report\r\n * when GPU picking or raycast returns a hit.\r\n *\r\n * @public\r\n */\r\nexport type PickTarget = { node: SceneNode; label?: string };\r\n\r\n/**\r\n * Minimal render context carrying target size and device information.\r\n *\r\n * @public\r\n */\r\nexport class RenderContext {\r\n public device: AbstractDevice;\r\n public renderWidth: number;\r\n public renderHeight: number;\r\n constructor(_camera: Camera, w: number, h: number) {\r\n this.device = getDevice();\r\n this.renderWidth = w;\r\n this.renderHeight = h;\r\n }\r\n}\r\n/**\r\n * Context object passed to draw calls and render helpers.\r\n *\r\n * It aggregates all per-frame, per-pass, and per-draw state derived from the engine and renderer,\r\n * including device handles, textures, passes, flags, and post-processing links.\r\n *\r\n * Notes:\r\n * - Not all textures/fields are present for every pass; check for undefined when optional.\r\n * - Values like `HiZ`, `TAA`, `SSR` signal features the renderer has activated for the current pass.\r\n *\r\n * @public\r\n */\r\nexport interface DrawContext {\r\n /** Render device used for issuing GPU commands. */\r\n readonly device: AbstractDevice;\r\n /** Framebuffer width for rendering (in pixels). */\r\n readonly renderWidth: number;\r\n /** Framebuffer height for rendering (in pixels). */\r\n readonly renderHeight: number;\r\n /** Allocator for global (frame/pass) bind groups and descriptor resources. */\r\n readonly globalBindGroupAllocator: GlobalBindGroupAllocator;\r\n /** The camera associated with the current drawing task (may differ from primaryCamera). */\r\n readonly camera: Camera;\r\n /** Order-Independent Transparency interface for transparent passes. */\r\n oit: Nullable<OIT>;\r\n /** Whether motion vectors are being written this pass (used by TAA/MotionBlur). */\r\n readonly motionVectors: boolean;\r\n /** Motion vector texture target when motion vectors are active. */\r\n motionVectorTexture?: Nullable<Texture2D>;\r\n /** Whether hierarchical depth (Hi-Z) is enabled for the current pass. */\r\n readonly HiZ: boolean;\r\n /** Hi-Z (hierarchical Z) depth texture, when generated. */\r\n HiZTexture: Nullable<Texture2D>;\r\n /** The scene currently being drawn. */\r\n readonly scene: Scene;\r\n /** The render pass to which this drawing task belongs. */\r\n renderPass: Nullable<RenderPass>;\r\n /** Stable hash for the current pass/draw state, for render bundle or pipeline cache. */\r\n renderPassHash: Nullable<string>;\r\n /** Whether the output orientation is flipped vertically (e.g., due to framebuffer conventions). */\r\n flip: boolean;\r\n /** Whether this is the base lighting pass that draws environment lighting. */\r\n drawEnvLight: boolean;\r\n /** Scene environment (sky, IBL, exposure, etc.) used for shading. */\r\n env: Nullable<Environment>;\r\n /** Current sub-queue index within the render queue (e.g., opaque, transparent). */\r\n queue: number;\r\n /** Whether the current lighting pass is blending light accumulations. */\r\n lightBlending: boolean;\r\n /** Scene (non-linear) depth texture bound for sampling. */\r\n depthTexture?: Texture2D;\r\n /** Linearized depth texture bound for sampling. */\r\n linearDepthTexture?: Texture2D;\r\n /** Scene color texture bound for sampling (previous pass or resolved color). */\r\n sceneColorTexture?: Texture2D;\r\n /** Default depth buffer format for targets created in this pass. */\r\n readonly depthFormat: TextureFormat;\r\n /** Default color buffer format for targets created in this pass. */\r\n readonly colorFormat: TextureFormat;\r\n /** Instance data buffer/metadata for the current drawing task (instanced rendering). */\r\n instanceData?: Nullable<InstanceData>;\r\n /** Compositor used to apply post-processing effects at the end of the frame/pass. */\r\n compositor?: Nullable<Compositor>;\r\n /** @internal Map of punctual lights to their shadow map parameters for this pass. */\r\n shadowMapInfo?: Nullable<Map<PunctualLight, ShadowMapParams>>;\r\n /** @internal The punctual light currently rendering shadows (shadow pass). */\r\n currentShadowLight?: Nullable<PunctualLight>;\r\n /** Sun/directional light reference for passes that need it. */\r\n sunLight?: Nullable<DirectionalLight>;\r\n /** Clustered light index/structure for lighting in forward+, clustered shading, etc. */\r\n clusteredLight?: ClusteredLight;\r\n /** Material varying bit flags that influence shader selection. */\r\n materialFlags: number;\r\n /** Force cull mode override for special passes (optional). */\r\n forceCullMode?: Nullable<FaceMode>;\r\n /** Force color mask state override for special passes (optional). */\r\n forceColorState?: Nullable<ColorState>;\r\n /** Screen-space reflections are active this frame/pass. */\r\n readonly SSR: boolean;\r\n /** Whether SSR thickness should be computed dynamically in this pass. */\r\n SSRCalcThickness: boolean;\r\n /** SSR roughness input texture. */\r\n SSRRoughnessTexture: Texture2D;\r\n /** SSR normal input texture (usually view-space or world-space normals). */\r\n SSRNormalTexture: Texture2D;\r\n /** Final framebuffer target where the last stage renders. */\r\n finalFramebuffer: Nullable<FrameBuffer>;\r\n /** Intermediate framebuffer used by the compositor or multi-pass pipelines. */\r\n intermediateFramebuffer: Nullable<FrameBuffer>;\r\n}\r\n\r\n/**\r\n * Morph Data\r\n * @public\r\n */\r\nexport type MorphData = {\r\n width: number;\r\n height: number;\r\n data: Float32Array<ArrayBuffer>;\r\n texture?: DRef<Texture2D>;\r\n};\r\n\r\n/**\r\n * Morph information\r\n * @public\r\n */\r\nexport type MorphInfo = { data: TypedArray; buffer?: DRef<GPUDataBuffer>; names: Record<string, number> };\r\n\r\n/**\r\n * Base interface for a drawable (renderable) object.\r\n *\r\n * A drawable encapsulates geometry, material, and GPU-resident data required to be rendered.\r\n * Implementations integrate with render queues, batching, and instancing.\r\n *\r\n * @public\r\n */\r\nexport interface Drawable {\r\n /** Gets the display name of the drawable object (for debugging/UI). */\r\n getName(): string;\r\n /** Unique, stable identifier for the drawable, used in caches and picking. */\r\n getDrawableId(): number;\r\n /** Returns the owning scene node (transform and hierarchy). */\r\n getNode(): SceneNode;\r\n /**\r\n * Returns the pick target override to be reported when this object is picked.\r\n *\r\n * If not set, a default target derived from the node/material may be used.\r\n */\r\n getPickTarget(): PickTarget;\r\n /** Returns the texture containing bone matrices for skinned meshes. */\r\n getBoneMatrices(): Nullable<Texture2D>;\r\n /** Returns the unique color used for GPU picking (object ID in color). */\r\n getObjectColor(): Vector4;\r\n /** Returns the morph target data texture (if morphing is used). */\r\n getMorphData(): Nullable<MorphData>;\r\n /** Returns the morph information buffer (weights, ranges, etc.). */\r\n getMorphInfo(): Nullable<MorphInfo>;\r\n /**\r\n * Computes the distance used for sorting (e.g., transparent draw order).\r\n *\r\n * @param camera - Camera from which to compute distance (usually camera -\\> object).\r\n */\r\n getSortDistance(camera: Camera): number;\r\n /** Returns the type/category of render queue this object belongs to. */\r\n getQueueType(): number;\r\n /** Whether the object requires access to the scene color buffer. */\r\n needSceneColor(): boolean;\r\n /** Whether the object requires access to the scene depth (linear or non-linear). */\r\n needSceneDepth(): boolean;\r\n /** True if shading is unlit (does not depend on scene lighting). */\r\n isUnlit(): boolean;\r\n /** Returns the bound material driving shading for this drawable. */\r\n getMaterial(): Nullable<MeshMaterial>;\r\n /** Returns the geometry primitive to be drawn. */\r\n getPrimitive(): Nullable<Primitive>;\r\n /**\r\n * Pushes a reference to the current render queue for cleanup or back-references.\r\n *\r\n * Useful for batching or deferred state application.\r\n */\r\n pushRenderQueueRef(ref: RenderQueueRef): void;\r\n /**\r\n * Applies transform-related uniforms to the active bind group or pipeline.\r\n *\r\n * @param renderQueue - The current render queue issuing this draw.\r\n */\r\n applyTransformUniforms(renderQueue: RenderQueue): void;\r\n /**\r\n * Issues draw commands for this object.\r\n *\r\n * @param ctx - Full draw context for the current pass.\r\n * @param renderQueue - The current render queue issuing this draw.\r\n * @param hash - Optional hash key for render bundle or pipeline caching.\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string): void;\r\n /**\r\n * Updates internal state or GPU resources for this drawable, if needed.\r\n */\r\n updateState(): void;\r\n /**\r\n * Returns true if the object supports instanced rendering.\r\n *\r\n * When true, the object should also implement the {@link BatchDrawable} methods.\r\n */\r\n isBatchable(): this is BatchDrawable;\r\n /** Releases all GPU resources and detaches from the renderer. */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * Interface for drawables that support hardware instancing.\r\n *\r\n * Instanced drawables supply instance-specific uniforms, offsets, and strides\r\n * to allow a single draw call to render many instances efficiently.\r\n *\r\n * @public\r\n */\r\nexport interface BatchDrawable extends Drawable {\r\n /**\r\n * Returns a stable instance ID string for use with the given render pass.\r\n *\r\n * Used to group compatible instances into batches within a pass.\r\n *\r\n * @param renderPass - The render pass to which current drawing task belongs.\r\n * @internal\r\n */\r\n getInstanceId(renderPass: RenderPass): string;\r\n /**\r\n * Returns a tightly-packed float array of instance uniforms for GPU upload.\r\n *\r\n * The returned memory should be compatible with ArrayBuffer views used by the renderer.\r\n *\r\n * @internal\r\n */\r\n getInstanceUniforms(): Float32Array<ArrayBuffer>;\r\n /**\r\n * Applies instance stride and starting offset to the active bind group.\r\n *\r\n * This informs the shader how to index into the instance buffer for this batch.\r\n *\r\n * @param renderQueue - Render queue associated with the bind group or pipeline.\r\n * @param stride - Per-instance stride in bytes or floats (renderer-defined).\r\n * @param offset - Starting instance offset within the instance buffer.\r\n * @internal\r\n */\r\n applyInstanceOffsetAndStride(renderQueue: RenderQueue, stride: number, offset: number): void;\r\n /**\r\n * Applies material uniforms for a single instance group.\r\n *\r\n * @param instanceInfo - Instance data information for this batch.\r\n * @internal\r\n */\r\n applyMaterialUniforms(instanceInfo: DrawableInstanceInfo): void;\r\n /**\r\n * Applies material uniforms across all grouped instance informations belonging to this material.\r\n *\r\n * Useful when batching merges multiple instance groups sharing the same material.\r\n *\r\n * @internal\r\n */\r\n applyMaterialUniformsAll(): void;\r\n}\r\n"],"names":["RenderContext","device","renderWidth","renderHeight","_camera","w","h","getDevice"],"mappings":";;AAiCA;;;;AAIC,IACM,MAAMA,aAAAA,CAAAA;IACJC,MAAuB;IACvBC,WAAoB;IACpBC,YAAqB;AAC5B,IAAA,WAAA,CAAYC,OAAe,EAAEC,CAAS,EAAEC,CAAS,CAAE;QACjD,IAAI,CAACL,MAAM,GAAGM,SAAAA,EAAAA;QACd,IAAI,CAACL,WAAW,GAAGG,CAAAA;QACnB,IAAI,CAACF,YAAY,GAAGG,CAAAA;AACtB;AACF;;;;"}
|
|
@@ -4,8 +4,8 @@ import { getDevice } from '../../app/api.js';
|
|
|
4
4
|
* Bridges the render graph's {@link RGTextureAllocator} interface to the
|
|
5
5
|
* engine's device resource pool (`device.pool`).
|
|
6
6
|
*
|
|
7
|
-
* Transient textures are fetched from the pool on
|
|
8
|
-
* returned to the pool on
|
|
7
|
+
* Transient textures are fetched from the pool on `allocate()` and
|
|
8
|
+
* returned to the pool on `release()`, enabling automatic reuse
|
|
9
9
|
* across frames without manual lifecycle management.
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
@@ -25,7 +25,12 @@ import { getDevice } from '../../app/api.js';
|
|
|
25
25
|
*/ allocate(desc, size) {
|
|
26
26
|
const device = getDevice();
|
|
27
27
|
const mipmapping = (desc.mipLevels ?? 1) > 1;
|
|
28
|
-
|
|
28
|
+
const texture = device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping);
|
|
29
|
+
if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {
|
|
30
|
+
device.pool.releaseTexture(texture);
|
|
31
|
+
throw new Error(`DevicePoolAllocator: texture "${desc.label ?? '<unnamed>'}" requested ${desc.mipLevels} ` + `mip levels, but only ${texture.mipLevelCount} were allocated.`);
|
|
32
|
+
}
|
|
33
|
+
return texture;
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* Release a transient texture back to the device pool.
|
|
@@ -35,6 +40,27 @@ import { getDevice } from '../../app/api.js';
|
|
|
35
40
|
const device = getDevice();
|
|
36
41
|
device.pool.releaseTexture(texture);
|
|
37
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Allocate a temporary framebuffer from the device pool.
|
|
45
|
+
*
|
|
46
|
+
* @param desc - Framebuffer descriptor from the render graph pass.
|
|
47
|
+
* @returns A pooled FrameBuffer instance.
|
|
48
|
+
*/ allocateFramebuffer(desc) {
|
|
49
|
+
const device = getDevice();
|
|
50
|
+
const colors = Array.isArray(desc.colorAttachments) ? desc.colorAttachments : desc.colorAttachments ? [
|
|
51
|
+
desc.colorAttachments
|
|
52
|
+
] : [];
|
|
53
|
+
const depthAttachment = desc.depthAttachment ?? null;
|
|
54
|
+
return device.pool.fetchTemporalFramebuffer(false, desc.width ?? 0, desc.height ?? 0, colors, depthAttachment, desc.mipmapping ?? false, desc.sampleCount ?? 1, desc.ignoreDepthStencil ?? true, desc.attachmentMipLevel ?? 0, desc.attachmentCubeface ?? 0, desc.attachmentLayer ?? 0);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Release a temporary framebuffer back to the device pool.
|
|
58
|
+
*
|
|
59
|
+
* @param framebuffer - The framebuffer to release.
|
|
60
|
+
*/ releaseFramebuffer(framebuffer) {
|
|
61
|
+
const device = getDevice();
|
|
62
|
+
device.pool.releaseFrameBuffer(framebuffer);
|
|
63
|
+
}
|
|
38
64
|
}
|
|
39
65
|
|
|
40
66
|
export { DevicePoolAllocator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\r\nimport type { RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on
|
|
1
|
+
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, TextureFormat } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on `allocate()` and\r\n * returned to the pool on `release()`, enabling automatic reuse\r\n * across frames without manual lifecycle management.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const allocator = new DevicePoolAllocator();\r\n * const executor = new RenderGraphExecutor(allocator, width, height);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D, FrameBuffer> {\r\n /**\r\n * Allocate a transient texture from the device pool.\r\n *\r\n * @param desc - Texture descriptor from the render graph pass.\r\n * @param size - Resolved pixel dimensions.\r\n * @returns A pooled Texture2D instance.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): Texture2D {\r\n const device = getDevice();\r\n const mipmapping = (desc.mipLevels ?? 1) > 1;\r\n const texture = device.pool.fetchTemporalTexture2D(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n mipmapping\r\n );\r\n if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {\r\n device.pool.releaseTexture(texture);\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${desc.mipLevels} ` +\r\n `mip levels, but only ${texture.mipLevelCount} were allocated.`\r\n );\r\n }\r\n return texture;\r\n }\r\n\r\n /**\r\n * Release a transient texture back to the device pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n\r\n /**\r\n * Allocate a temporary framebuffer from the device pool.\r\n *\r\n * @param desc - Framebuffer descriptor from the render graph pass.\r\n * @returns A pooled FrameBuffer instance.\r\n */\r\n allocateFramebuffer(desc: RGFramebufferDesc): FrameBuffer {\r\n const device = getDevice();\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? (desc.colorAttachments as Array<Texture2D | TextureFormat>)\r\n : desc.colorAttachments\r\n ? [desc.colorAttachments as Texture2D | TextureFormat]\r\n : [];\r\n const depthAttachment = (desc.depthAttachment ?? null) as Texture2D | TextureFormat | null;\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n desc.width ?? 0,\r\n desc.height ?? 0,\r\n colors,\r\n depthAttachment,\r\n desc.mipmapping ?? false,\r\n desc.sampleCount ?? 1,\r\n desc.ignoreDepthStencil ?? true,\r\n desc.attachmentMipLevel ?? 0,\r\n desc.attachmentCubeface ?? 0,\r\n desc.attachmentLayer ?? 0\r\n );\r\n }\r\n\r\n /**\r\n * Release a temporary framebuffer back to the device pool.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer(framebuffer: FrameBuffer): void {\r\n const device = getDevice();\r\n device.pool.releaseFrameBuffer(framebuffer);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","allocate","desc","size","device","getDevice","mipmapping","mipLevels","texture","pool","fetchTemporalTexture2D","format","width","height","mipLevelCount","releaseTexture","Error","label","release","allocateFramebuffer","colors","Array","isArray","colorAttachments","depthAttachment","fetchTemporalFramebuffer","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","releaseFramebuffer","framebuffer","releaseFrameBuffer"],"mappings":";;AAIA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;AACX;;;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,MAAMC,eAAAA,GAAmBtB,IAAKsB,CAAAA,eAAe,IAAI,IAAA;AACjD,QAAA,OAAOpB,OAAOK,IAAI,CAACgB,wBAAwB,CACzC,OACAvB,IAAKU,CAAAA,KAAK,IAAI,CAAA,EACdV,KAAKW,MAAM,IAAI,GACfO,MACAI,EAAAA,eAAAA,EACAtB,KAAKI,UAAU,IAAI,KACnBJ,EAAAA,IAAAA,CAAKwB,WAAW,IAAI,CAAA,EACpBxB,IAAKyB,CAAAA,kBAAkB,IAAI,IAC3BzB,EAAAA,IAAAA,CAAK0B,kBAAkB,IAAI,GAC3B1B,IAAK2B,CAAAA,kBAAkB,IAAI,CAC3B3B,EAAAA,IAAAA,CAAK4B,eAAe,IAAI,CAAA,CAAA;AAE5B;AAEA;;;;MAKAC,kBAAAA,CAAmBC,WAAwB,EAAQ;AACjD,QAAA,MAAM5B,MAASC,GAAAA,SAAAA,EAAAA;QACfD,MAAOK,CAAAA,IAAI,CAACwB,kBAAkB,CAACD,WAAAA,CAAAA;AACjC;AACF;;;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RGHandle } from './types.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Executes a compiled render graph with automatic resource lifecycle management.
|
|
3
5
|
*
|
|
@@ -19,6 +21,10 @@
|
|
|
19
21
|
/** @internal */ _backbufferHeight;
|
|
20
22
|
/** @internal */ _importedTextures = new Map();
|
|
21
23
|
/** @internal */ _allocatedTextures = new Map();
|
|
24
|
+
/** @internal */ _allocatedFramebuffers = new Map();
|
|
25
|
+
/** @internal */ _importedTextureAliases = new Map();
|
|
26
|
+
/** @internal */ _resolvedImportedTextures = new Map();
|
|
27
|
+
/** @internal */ _cleanupCallbacks = [];
|
|
22
28
|
constructor(allocator, backbufferWidth, backbufferHeight){
|
|
23
29
|
this._allocator = allocator;
|
|
24
30
|
this._backbufferWidth = backbufferWidth;
|
|
@@ -48,9 +54,13 @@
|
|
|
48
54
|
*
|
|
49
55
|
* @param compiled - The compiled graph from {@link RenderGraph.compile}.
|
|
50
56
|
*/ execute(compiled) {
|
|
57
|
+
this._cleanupCallbacks.length = 0;
|
|
58
|
+
this._resolveImportedTextureAliases(compiled);
|
|
51
59
|
// Build per-pass allocation and release schedules
|
|
52
|
-
const allocateAt = new Map(); // passIndex -> resourceIds to allocate
|
|
53
|
-
const releaseAt = new Map(); // passIndex -> resourceIds to release
|
|
60
|
+
const allocateAt = new Map(); // passIndex -> transient texture resourceIds to allocate
|
|
61
|
+
const releaseAt = new Map(); // passIndex -> transient texture resourceIds to release
|
|
62
|
+
const allocateFramebufferAt = new Map(); // passIndex -> framebuffer resourceIds to allocate
|
|
63
|
+
const releaseFramebufferAt = new Map(); // passIndex -> framebuffer resourceIds to release
|
|
54
64
|
for (const [resId, lifetime] of compiled.lifetimes){
|
|
55
65
|
if (lifetime.resource.kind === 'transient') {
|
|
56
66
|
if (!allocateAt.has(lifetime.firstUse)) {
|
|
@@ -61,39 +71,125 @@
|
|
|
61
71
|
releaseAt.set(lifetime.lastUse, []);
|
|
62
72
|
}
|
|
63
73
|
releaseAt.get(lifetime.lastUse).push(resId);
|
|
74
|
+
} else if (lifetime.resource.kind === 'framebuffer') {
|
|
75
|
+
if (!allocateFramebufferAt.has(lifetime.firstUse)) {
|
|
76
|
+
allocateFramebufferAt.set(lifetime.firstUse, []);
|
|
77
|
+
}
|
|
78
|
+
allocateFramebufferAt.get(lifetime.firstUse).push(resId);
|
|
79
|
+
if (!releaseFramebufferAt.has(lifetime.lastUse)) {
|
|
80
|
+
releaseFramebufferAt.set(lifetime.lastUse, []);
|
|
81
|
+
}
|
|
82
|
+
releaseFramebufferAt.get(lifetime.lastUse).push(resId);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
let completed = false;
|
|
86
|
+
let executionError = null;
|
|
87
|
+
try {
|
|
88
|
+
for(let i = 0; i < compiled.orderedPasses.length; i++){
|
|
89
|
+
const pass = compiled.orderedPasses[i];
|
|
90
|
+
// Allocate resources that start at this pass
|
|
91
|
+
const toAllocate = allocateAt.get(i);
|
|
92
|
+
if (toAllocate) {
|
|
93
|
+
for (const resId of toAllocate){
|
|
94
|
+
const lifetime = compiled.lifetimes.get(resId);
|
|
95
|
+
const desc = lifetime.resource.desc;
|
|
96
|
+
const size = this._resolveSize(desc);
|
|
97
|
+
const texture = this._allocator.allocate(desc, size);
|
|
98
|
+
this._allocatedTextures.set(resId, texture);
|
|
99
|
+
}
|
|
78
100
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
// Allocate framebuffer views after their texture attachments are available.
|
|
102
|
+
const framebuffersToAllocate = allocateFramebufferAt.get(i);
|
|
103
|
+
if (framebuffersToAllocate) {
|
|
104
|
+
for (const resId of framebuffersToAllocate){
|
|
105
|
+
const lifetime = compiled.lifetimes.get(resId);
|
|
106
|
+
const desc = lifetime.resource.desc;
|
|
107
|
+
const framebuffer = this._createFramebuffer(this._resolveFramebufferDesc(desc), false);
|
|
108
|
+
this._allocatedFramebuffers.set(resId, framebuffer);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Execute the pass with exception safety for resource cleanup.
|
|
112
|
+
// Release errors must not hide the original pass execution error.
|
|
113
|
+
let passError = null;
|
|
114
|
+
try {
|
|
115
|
+
if (pass.subpasses.length > 0) {
|
|
116
|
+
const accessScope = this._createAccessScope(pass);
|
|
117
|
+
const ctx = this._createContext(accessScope);
|
|
118
|
+
for (const subpass of pass.subpasses){
|
|
119
|
+
try {
|
|
120
|
+
subpass.executeFn(ctx, pass.data);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
throw this._wrapSubpassError(pass.name, subpass.name, e);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else if (pass.executeFn) {
|
|
126
|
+
const accessScope = this._createAccessScope(pass);
|
|
127
|
+
const ctx = this._createContext(accessScope);
|
|
128
|
+
pass.executeFn(ctx, pass.data);
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
passError = e;
|
|
132
|
+
}
|
|
133
|
+
let releaseError = null;
|
|
134
|
+
const framebuffersToRelease = releaseFramebufferAt.get(i);
|
|
135
|
+
if (framebuffersToRelease) {
|
|
136
|
+
for (const resId of framebuffersToRelease){
|
|
137
|
+
const framebuffer = this._allocatedFramebuffers.get(resId);
|
|
138
|
+
if (framebuffer !== undefined) {
|
|
139
|
+
try {
|
|
140
|
+
this._releaseFramebuffer(framebuffer);
|
|
141
|
+
this._allocatedFramebuffers.delete(resId);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
releaseError ??= e;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
84
147
|
}
|
|
85
|
-
} finally{
|
|
86
148
|
// Release resources that end at this pass (always runs even if pass throws)
|
|
87
149
|
const toRelease = releaseAt.get(i);
|
|
88
150
|
if (toRelease) {
|
|
89
151
|
for (const resId of toRelease){
|
|
90
152
|
const texture = this._allocatedTextures.get(resId);
|
|
91
153
|
if (texture !== undefined) {
|
|
92
|
-
|
|
93
|
-
|
|
154
|
+
try {
|
|
155
|
+
this._allocator.release(texture);
|
|
156
|
+
this._allocatedTextures.delete(resId);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
releaseError ??= e;
|
|
159
|
+
}
|
|
94
160
|
}
|
|
95
161
|
}
|
|
96
162
|
}
|
|
163
|
+
if (passError) {
|
|
164
|
+
throw passError;
|
|
165
|
+
}
|
|
166
|
+
if (releaseError) {
|
|
167
|
+
throw releaseError;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
completed = true;
|
|
171
|
+
} catch (e) {
|
|
172
|
+
executionError = e;
|
|
173
|
+
} finally{
|
|
174
|
+
let cleanupError = null;
|
|
175
|
+
try {
|
|
176
|
+
this._runCleanupCallbacks();
|
|
177
|
+
} catch (e) {
|
|
178
|
+
cleanupError = e;
|
|
179
|
+
} finally{
|
|
180
|
+
if (!completed) {
|
|
181
|
+
try {
|
|
182
|
+
this.reset();
|
|
183
|
+
} catch (e) {
|
|
184
|
+
cleanupError ??= e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (executionError) {
|
|
189
|
+
throw executionError;
|
|
190
|
+
}
|
|
191
|
+
if (cleanupError) {
|
|
192
|
+
throw cleanupError;
|
|
97
193
|
}
|
|
98
194
|
}
|
|
99
195
|
}
|
|
@@ -101,12 +197,19 @@
|
|
|
101
197
|
* Clear imported texture registrations and any leftover allocated textures.
|
|
102
198
|
* Call this after execution or when resetting for a new frame.
|
|
103
199
|
*/ reset() {
|
|
200
|
+
this._runCleanupCallbacks();
|
|
104
201
|
// Release any textures that weren't released (shouldn't happen in normal flow)
|
|
202
|
+
for (const framebuffer of this._allocatedFramebuffers.values()){
|
|
203
|
+
this._releaseFramebuffer(framebuffer);
|
|
204
|
+
}
|
|
205
|
+
this._allocatedFramebuffers.clear();
|
|
105
206
|
for (const texture of this._allocatedTextures.values()){
|
|
106
207
|
this._allocator.release(texture);
|
|
107
208
|
}
|
|
108
209
|
this._allocatedTextures.clear();
|
|
109
210
|
this._importedTextures.clear();
|
|
211
|
+
this._importedTextureAliases.clear();
|
|
212
|
+
this._resolvedImportedTextures.clear();
|
|
110
213
|
}
|
|
111
214
|
// ─── Private ────────────────────────────────────────────────────────
|
|
112
215
|
/** @internal */ _resolveSize(desc) {
|
|
@@ -125,21 +228,168 @@
|
|
|
125
228
|
height: Math.max(1, Math.floor(this._backbufferHeight * scaleY))
|
|
126
229
|
};
|
|
127
230
|
}
|
|
128
|
-
/** @internal */
|
|
231
|
+
/** @internal */ _resolveImportedTextureAliases(compiled) {
|
|
232
|
+
this._importedTextureAliases.clear();
|
|
233
|
+
this._resolvedImportedTextures.clear();
|
|
234
|
+
const physicalToTexture = new Map();
|
|
235
|
+
for (const lifetime of compiled.lifetimes.values()){
|
|
236
|
+
const resource = lifetime.resource;
|
|
237
|
+
if (resource.kind !== 'imported') {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const texture = this._importedTextures.get(resource.id) ?? this._importedTextures.get(resource.physicalId);
|
|
241
|
+
if (texture !== undefined) {
|
|
242
|
+
physicalToTexture.set(resource.physicalId, texture);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
for (const lifetime of compiled.lifetimes.values()){
|
|
246
|
+
const resource = lifetime.resource;
|
|
247
|
+
if (resource.kind !== 'imported') {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
this._importedTextureAliases.set(resource.id, resource.physicalId);
|
|
251
|
+
const texture = physicalToTexture.get(resource.physicalId);
|
|
252
|
+
if (texture !== undefined) {
|
|
253
|
+
this._resolvedImportedTextures.set(resource.id, texture);
|
|
254
|
+
this._resolvedImportedTextures.set(resource.physicalId, texture);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** @internal */ _runCleanupCallbacks() {
|
|
259
|
+
let error = null;
|
|
260
|
+
while(this._cleanupCallbacks.length > 0){
|
|
261
|
+
const callback = this._cleanupCallbacks.pop();
|
|
262
|
+
try {
|
|
263
|
+
callback();
|
|
264
|
+
} catch (e) {
|
|
265
|
+
error ??= e;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (error) {
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/** @internal */ _createFramebuffer(desc, autoCleanup = true) {
|
|
273
|
+
if (!this._allocator.allocateFramebuffer || !this._allocator.releaseFramebuffer) {
|
|
274
|
+
throw new Error('RenderGraphExecutor: framebuffer allocation is not supported by this allocator.');
|
|
275
|
+
}
|
|
276
|
+
const framebuffer = this._allocator.allocateFramebuffer(desc);
|
|
277
|
+
if (autoCleanup) {
|
|
278
|
+
this._cleanupCallbacks.push(()=>{
|
|
279
|
+
this._allocator.releaseFramebuffer(framebuffer);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return framebuffer;
|
|
283
|
+
}
|
|
284
|
+
/** @internal */ _releaseFramebuffer(framebuffer) {
|
|
285
|
+
if (!this._allocator.releaseFramebuffer) {
|
|
286
|
+
throw new Error('RenderGraphExecutor: framebuffer release is not supported by this allocator.');
|
|
287
|
+
}
|
|
288
|
+
this._allocator.releaseFramebuffer(framebuffer);
|
|
289
|
+
}
|
|
290
|
+
/** @internal */ _resolveFramebufferDesc(desc, accessScope) {
|
|
291
|
+
const resolveAttachment = (attachment)=>{
|
|
292
|
+
if (attachment instanceof RGHandle) {
|
|
293
|
+
if (accessScope) {
|
|
294
|
+
this._assertDeclaredAccess(accessScope, attachment, 'texture');
|
|
295
|
+
}
|
|
296
|
+
return this._resolveResource(attachment);
|
|
297
|
+
}
|
|
298
|
+
return attachment;
|
|
299
|
+
};
|
|
300
|
+
const colors = Array.isArray(desc.colorAttachments) ? desc.colorAttachments.map(resolveAttachment) : desc.colorAttachments ? resolveAttachment(desc.colorAttachments) : null;
|
|
301
|
+
return {
|
|
302
|
+
...desc,
|
|
303
|
+
colorAttachments: colors,
|
|
304
|
+
depthAttachment: resolveAttachment(desc.depthAttachment)
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** @internal */ _resolveResource(handle) {
|
|
308
|
+
const imported = this._importedTextures.get(handle._id);
|
|
309
|
+
if (imported !== undefined) {
|
|
310
|
+
return imported;
|
|
311
|
+
}
|
|
312
|
+
const resolvedImported = this._resolvedImportedTextures.get(handle._id);
|
|
313
|
+
if (resolvedImported !== undefined) {
|
|
314
|
+
return resolvedImported;
|
|
315
|
+
}
|
|
316
|
+
const importedAlias = this._importedTextureAliases.get(handle._id);
|
|
317
|
+
if (importedAlias !== undefined) {
|
|
318
|
+
const aliased = this._importedTextures.get(importedAlias) ?? this._resolvedImportedTextures.get(importedAlias);
|
|
319
|
+
if (aliased !== undefined) {
|
|
320
|
+
return aliased;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const allocated = this._allocatedTextures.get(handle._id);
|
|
324
|
+
if (allocated !== undefined) {
|
|
325
|
+
return allocated;
|
|
326
|
+
}
|
|
327
|
+
throw new Error(`RenderGraphExecutor: cannot resolve resource "${handle.name}" (id=${handle._id}). ` + `It may not have been allocated yet or was already released.`);
|
|
328
|
+
}
|
|
329
|
+
/** @internal */ _createAccessScope(pass) {
|
|
330
|
+
const accessibleIds = new Set();
|
|
331
|
+
const textureIds = new Set();
|
|
332
|
+
const framebufferIds = new Set();
|
|
333
|
+
for (const resource of pass.reads){
|
|
334
|
+
accessibleIds.add(resource.id);
|
|
335
|
+
if (resource.kind === 'transient' || resource.kind === 'imported') {
|
|
336
|
+
textureIds.add(resource.id);
|
|
337
|
+
} else if (resource.kind === 'framebuffer') {
|
|
338
|
+
framebufferIds.add(resource.id);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const resource of pass.writes){
|
|
342
|
+
accessibleIds.add(resource.id);
|
|
343
|
+
if (resource.kind === 'transient' || resource.kind === 'imported') {
|
|
344
|
+
textureIds.add(resource.id);
|
|
345
|
+
} else if (resource.kind === 'framebuffer') {
|
|
346
|
+
framebufferIds.add(resource.id);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
passName: pass.name,
|
|
351
|
+
accessibleIds,
|
|
352
|
+
textureIds,
|
|
353
|
+
framebufferIds
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/** @internal */ _assertDeclaredAccess(accessScope, handle, access) {
|
|
357
|
+
if (!accessScope.accessibleIds.has(handle._id)) {
|
|
358
|
+
throw new Error(`RenderGraphExecutor: pass "${accessScope.passName}" tried to access ${access} "${handle.name}" ` + `without declaring a read/write dependency.`);
|
|
359
|
+
}
|
|
360
|
+
if (access === 'texture' && !accessScope.textureIds.has(handle._id)) {
|
|
361
|
+
throw new Error(`RenderGraphExecutor: pass "${accessScope.passName}" tried to access "${handle.name}" as a texture, ` + `but it is not a texture resource.`);
|
|
362
|
+
}
|
|
363
|
+
if (access === 'framebuffer' && !accessScope.framebufferIds.has(handle._id)) {
|
|
364
|
+
throw new Error(`RenderGraphExecutor: pass "${accessScope.passName}" tried to access "${handle.name}" as a framebuffer, ` + `but it is not a framebuffer resource.`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/** @internal */ _wrapSubpassError(passName, subpassName, error) {
|
|
368
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
369
|
+
const wrapped = new Error(`RenderGraphExecutor: pass "${passName}" subpass "${subpassName}" failed: ${message}`);
|
|
370
|
+
wrapped.cause = error;
|
|
371
|
+
return wrapped;
|
|
372
|
+
}
|
|
373
|
+
/** @internal */ _createContext(accessScope) {
|
|
129
374
|
const self = this;
|
|
130
375
|
return {
|
|
131
376
|
getTexture (handle) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return allocated;
|
|
377
|
+
self._assertDeclaredAccess(accessScope, handle, 'texture');
|
|
378
|
+
return self._resolveResource(handle);
|
|
379
|
+
},
|
|
380
|
+
getFramebuffer (handle) {
|
|
381
|
+
self._assertDeclaredAccess(accessScope, handle, 'framebuffer');
|
|
382
|
+
const framebuffer = self._allocatedFramebuffers.get(handle._id);
|
|
383
|
+
if (framebuffer !== undefined) {
|
|
384
|
+
return framebuffer;
|
|
141
385
|
}
|
|
142
|
-
throw new Error(`RenderGraphExecutor: cannot resolve
|
|
386
|
+
throw new Error(`RenderGraphExecutor: cannot resolve framebuffer "${handle.name}" (id=${handle._id}). ` + `It may not have been allocated yet or was already released.`);
|
|
387
|
+
},
|
|
388
|
+
createFramebuffer (desc) {
|
|
389
|
+
return self._createFramebuffer(self._resolveFramebufferDesc(desc, accessScope));
|
|
390
|
+
},
|
|
391
|
+
deferCleanup (callback) {
|
|
392
|
+
self._cleanupCallbacks.push(callback);
|
|
143
393
|
}
|
|
144
394
|
};
|
|
145
395
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sources":["../../../src/render/rendergraph/executor.ts"],"sourcesContent":["import type {\r\n CompiledRenderGraph,\r\n RGTextureAllocator,\r\n RGTextureDesc,\r\n RGResolvedSize,\r\n RGExecuteContext,\r\n RGExecuteFn\r\n} from './types';\r\nimport type { RGHandle } from './types';\r\n\r\n/**\r\n * Executes a compiled render graph with automatic resource lifecycle management.\r\n *\r\n * The executor allocates transient textures before their first use and releases\r\n * them after their last use, using the provided {@link RGTextureAllocator}.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const executor = new RenderGraphExecutor(myAllocator, backbufferWidth, backbufferHeight);\r\n * executor.setImportedTexture(backbufferHandle, actualBackbufferTexture);\r\n * executor.execute(compiledGraph);\r\n * ```\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport class RenderGraphExecutor<TTexture = unknown> {\r\n /** @internal */\r\n private _allocator: RGTextureAllocator<TTexture>;\r\n /** @internal */\r\n private _backbufferWidth: number;\r\n /** @internal */\r\n private _backbufferHeight: number;\r\n /** @internal */\r\n private _importedTextures: Map<number, TTexture> = new Map();\r\n /** @internal */\r\n private _allocatedTextures: Map<number, TTexture> = new Map();\r\n\r\n constructor(allocator: RGTextureAllocator<TTexture>, backbufferWidth: number, backbufferHeight: number) {\r\n this._allocator = allocator;\r\n this._backbufferWidth = backbufferWidth;\r\n this._backbufferHeight = backbufferHeight;\r\n }\r\n\r\n /**\r\n * Update the backbuffer dimensions used for 'backbuffer-relative' sizing.\r\n */\r\n setBackbufferSize(width: number, height: number): void {\r\n this._backbufferWidth = width;\r\n this._backbufferHeight = height;\r\n }\r\n\r\n /**\r\n * Register an imported (external) texture so it can be resolved during execution.\r\n *\r\n * @param handle - The handle returned from {@link RenderGraph.importTexture}.\r\n * @param texture - The actual GPU texture object.\r\n */\r\n setImportedTexture(handle: RGHandle, texture: TTexture): void {\r\n this._importedTextures.set(handle._id, texture);\r\n }\r\n\r\n /**\r\n * Execute the compiled graph with full resource lifecycle management.\r\n *\r\n * For each pass in topological order:\r\n * 1. Allocate any transient resources whose lifetime begins at this pass\r\n * 2. Invoke the pass's execute callback with a context that resolves handles\r\n * 3. Release any transient resources whose lifetime ends at this pass\r\n *\r\n * @param compiled - The compiled graph from {@link RenderGraph.compile}.\r\n */\r\n execute(compiled: CompiledRenderGraph): void {\r\n // Build per-pass allocation and release schedules\r\n const allocateAt = new Map<number, number[]>(); // passIndex -> resourceIds to allocate\r\n const releaseAt = new Map<number, number[]>(); // passIndex -> resourceIds to release\r\n\r\n for (const [resId, lifetime] of compiled.lifetimes) {\r\n if (lifetime.resource.kind === 'transient') {\r\n if (!allocateAt.has(lifetime.firstUse)) {\r\n allocateAt.set(lifetime.firstUse, []);\r\n }\r\n allocateAt.get(lifetime.firstUse)!.push(resId);\r\n\r\n if (!releaseAt.has(lifetime.lastUse)) {\r\n releaseAt.set(lifetime.lastUse, []);\r\n }\r\n releaseAt.get(lifetime.lastUse)!.push(resId);\r\n }\r\n }\r\n\r\n const ctx = this._createContext();\r\n\r\n for (let i = 0; i < compiled.orderedPasses.length; i++) {\r\n const pass = compiled.orderedPasses[i];\r\n\r\n // Allocate resources that start at this pass\r\n const toAllocate = allocateAt.get(i);\r\n if (toAllocate) {\r\n for (const resId of toAllocate) {\r\n const lifetime = compiled.lifetimes.get(resId)!;\r\n const desc = lifetime.resource.desc!;\r\n const size = this._resolveSize(desc);\r\n const texture = this._allocator.allocate(desc, size);\r\n this._allocatedTextures.set(resId, texture);\r\n }\r\n }\r\n\r\n // Execute the pass with exception safety for resource cleanup\r\n try {\r\n if (pass.executeFn) {\r\n (pass.executeFn as RGExecuteFn<unknown>)(ctx, pass.data);\r\n }\r\n } finally {\r\n // Release resources that end at this pass (always runs even if pass throws)\r\n const toRelease = releaseAt.get(i);\r\n if (toRelease) {\r\n for (const resId of toRelease) {\r\n const texture = this._allocatedTextures.get(resId);\r\n if (texture !== undefined) {\r\n this._allocator.release(texture);\r\n this._allocatedTextures.delete(resId);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear imported texture registrations and any leftover allocated textures.\r\n * Call this after execution or when resetting for a new frame.\r\n */\r\n reset(): void {\r\n // Release any textures that weren't released (shouldn't happen in normal flow)\r\n for (const texture of this._allocatedTextures.values()) {\r\n this._allocator.release(texture);\r\n }\r\n this._allocatedTextures.clear();\r\n this._importedTextures.clear();\r\n }\r\n\r\n // ─── Private ────────────────────────────────────────────────────────\r\n\r\n /** @internal */\r\n private _resolveSize(desc: RGTextureDesc): RGResolvedSize {\r\n const mode = desc.sizeMode ?? 'backbuffer-relative';\r\n if (mode === 'absolute') {\r\n return {\r\n width: desc.width ?? 1,\r\n height: desc.height ?? 1\r\n };\r\n }\r\n // backbuffer-relative: width/height are scale factors (default 1.0)\r\n const scaleX = desc.width ?? 1.0;\r\n const scaleY = desc.height ?? 1.0;\r\n return {\r\n width: Math.max(1, Math.floor(this._backbufferWidth * scaleX)),\r\n height: Math.max(1, Math.floor(this._backbufferHeight * scaleY))\r\n };\r\n }\r\n\r\n /** @internal */\r\n private _createContext(): RGExecuteContext {\r\n const self = this;\r\n return {\r\n getTexture<T>(handle: RGHandle): T {\r\n // Check imported first\r\n const imported = self._importedTextures.get(handle._id);\r\n if (imported !== undefined) {\r\n return imported as unknown as T;\r\n }\r\n // Check allocated transient\r\n const allocated = self._allocatedTextures.get(handle._id);\r\n if (allocated !== undefined) {\r\n return allocated as unknown as T;\r\n }\r\n throw new Error(\r\n `RenderGraphExecutor: cannot resolve resource \"${handle.name}\" (id=${handle._id}). ` +\r\n `It may not have been allocated yet or was already released.`\r\n );\r\n }\r\n };\r\n }\r\n}\r\n"],"names":["RenderGraphExecutor","_importedTextures","Map","_allocatedTextures","allocator","backbufferWidth","backbufferHeight","_allocator","_backbufferWidth","_backbufferHeight","setBackbufferSize","width","height","setImportedTexture","handle","texture","set","_id","execute","compiled","allocateAt","releaseAt","resId","lifetime","lifetimes","resource","kind","has","firstUse","get","push","lastUse","ctx","_createContext","i","orderedPasses","length","pass","toAllocate","desc","size","_resolveSize","allocate","executeFn","data","toRelease","undefined","release","delete","reset","values","clear","mode","sizeMode","scaleX","scaleY","Math","max","floor","self","getTexture","imported","allocated","Error","name"],"mappings":"AAUA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;qBAEX,UAAiD;qBAEjD,gBAAiC;qBAEjC,iBAAkC;AAClC,qBACQC,iBAA2C,GAAA,IAAIC,GAAM,EAAA;AAC7D,qBACQC,kBAA4C,GAAA,IAAID,GAAM,EAAA;AAE9D,IAAA,WAAA,CAAYE,SAAuC,EAAEC,eAAuB,EAAEC,gBAAwB,CAAE;QACtG,IAAI,CAACC,UAAU,GAAGH,SAAAA;QAClB,IAAI,CAACI,gBAAgB,GAAGH,eAAAA;QACxB,IAAI,CAACI,iBAAiB,GAAGH,gBAAAA;AAC3B;AAEA;;AAEC,MACDI,iBAAkBC,CAAAA,KAAa,EAAEC,MAAc,EAAQ;QACrD,IAAI,CAACJ,gBAAgB,GAAGG,KAAAA;QACxB,IAAI,CAACF,iBAAiB,GAAGG,MAAAA;AAC3B;AAEA;;;;;AAKC,MACDC,kBAAmBC,CAAAA,MAAgB,EAAEC,OAAiB,EAAQ;AAC5D,QAAA,IAAI,CAACd,iBAAiB,CAACe,GAAG,CAACF,MAAAA,CAAOG,GAAG,EAAEF,OAAAA,CAAAA;AACzC;AAEA;;;;;;;;;MAUAG,OAAAA,CAAQC,QAA6B,EAAQ;;QAE3C,MAAMC,UAAAA,GAAa,IAAIlB,GAAAA,EAAAA,CAAAA;QACvB,MAAMmB,SAAAA,GAAY,IAAInB,GAAAA,EAAAA,CAAAA;AAEtB,QAAA,KAAK,MAAM,CAACoB,KAAAA,EAAOC,S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SAAA;AACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"executor.js","sources":["../../../src/render/rendergraph/executor.ts"],"sourcesContent":["import type {\r\n CompiledRenderGraph,\r\n RGTextureAllocator,\r\n RGTextureDesc,\r\n RGFramebufferDesc,\r\n RGResolvedSize,\r\n RGExecuteContext,\r\n RGExecuteFn,\r\n RGPass\r\n} from './types';\r\nimport { RGHandle } from './types';\r\n\r\ninterface RGPassAccessScope {\r\n passName: string;\r\n accessibleIds: Set<number>;\r\n textureIds: Set<number>;\r\n framebufferIds: Set<number>;\r\n}\r\n\r\n/**\r\n * Executes a compiled render graph with automatic resource lifecycle management.\r\n *\r\n * The executor allocates transient textures before their first use and releases\r\n * them after their last use, using the provided {@link RGTextureAllocator}.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const executor = new RenderGraphExecutor(myAllocator, backbufferWidth, backbufferHeight);\r\n * executor.setImportedTexture(backbufferHandle, actualBackbufferTexture);\r\n * executor.execute(compiledGraph);\r\n * ```\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport class RenderGraphExecutor<TTexture = unknown, TFramebuffer = unknown> {\r\n /** @internal */\r\n private _allocator: RGTextureAllocator<TTexture, TFramebuffer>;\r\n /** @internal */\r\n private _backbufferWidth: number;\r\n /** @internal */\r\n private _backbufferHeight: number;\r\n /** @internal */\r\n private _importedTextures: Map<number, TTexture> = new Map();\r\n /** @internal */\r\n private _allocatedTextures: Map<number, TTexture> = new Map();\r\n /** @internal */\r\n private _allocatedFramebuffers: Map<number, TFramebuffer> = new Map();\r\n /** @internal */\r\n private _importedTextureAliases: Map<number, number> = new Map();\r\n /** @internal */\r\n private _resolvedImportedTextures: Map<number, TTexture> = new Map();\r\n /** @internal */\r\n private _cleanupCallbacks: Array<() => void> = [];\r\n\r\n constructor(\r\n allocator: RGTextureAllocator<TTexture, TFramebuffer>,\r\n backbufferWidth: number,\r\n backbufferHeight: number\r\n ) {\r\n this._allocator = allocator;\r\n this._backbufferWidth = backbufferWidth;\r\n this._backbufferHeight = backbufferHeight;\r\n }\r\n\r\n /**\r\n * Update the backbuffer dimensions used for 'backbuffer-relative' sizing.\r\n */\r\n setBackbufferSize(width: number, height: number): void {\r\n this._backbufferWidth = width;\r\n this._backbufferHeight = height;\r\n }\r\n\r\n /**\r\n * Register an imported (external) texture so it can be resolved during execution.\r\n *\r\n * @param handle - The handle returned from {@link RenderGraph.importTexture}.\r\n * @param texture - The actual GPU texture object.\r\n */\r\n setImportedTexture(handle: RGHandle, texture: TTexture): void {\r\n this._importedTextures.set(handle._id, texture);\r\n }\r\n\r\n /**\r\n * Execute the compiled graph with full resource lifecycle management.\r\n *\r\n * For each pass in topological order:\r\n * 1. Allocate any transient resources whose lifetime begins at this pass\r\n * 2. Invoke the pass's execute callback with a context that resolves handles\r\n * 3. Release any transient resources whose lifetime ends at this pass\r\n *\r\n * @param compiled - The compiled graph from {@link RenderGraph.compile}.\r\n */\r\n execute(compiled: CompiledRenderGraph): void {\r\n this._cleanupCallbacks.length = 0;\r\n this._resolveImportedTextureAliases(compiled);\r\n\r\n // Build per-pass allocation and release schedules\r\n const allocateAt = new Map<number, number[]>(); // passIndex -> transient texture resourceIds to allocate\r\n const releaseAt = new Map<number, number[]>(); // passIndex -> transient texture resourceIds to release\r\n const allocateFramebufferAt = new Map<number, number[]>(); // passIndex -> framebuffer resourceIds to allocate\r\n const releaseFramebufferAt = new Map<number, number[]>(); // passIndex -> framebuffer resourceIds to release\r\n\r\n for (const [resId, lifetime] of compiled.lifetimes) {\r\n if (lifetime.resource.kind === 'transient') {\r\n if (!allocateAt.has(lifetime.firstUse)) {\r\n allocateAt.set(lifetime.firstUse, []);\r\n }\r\n allocateAt.get(lifetime.firstUse)!.push(resId);\r\n\r\n if (!releaseAt.has(lifetime.lastUse)) {\r\n releaseAt.set(lifetime.lastUse, []);\r\n }\r\n releaseAt.get(lifetime.lastUse)!.push(resId);\r\n } else if (lifetime.resource.kind === 'framebuffer') {\r\n if (!allocateFramebufferAt.has(lifetime.firstUse)) {\r\n allocateFramebufferAt.set(lifetime.firstUse, []);\r\n }\r\n allocateFramebufferAt.get(lifetime.firstUse)!.push(resId);\r\n\r\n if (!releaseFramebufferAt.has(lifetime.lastUse)) {\r\n releaseFramebufferAt.set(lifetime.lastUse, []);\r\n }\r\n releaseFramebufferAt.get(lifetime.lastUse)!.push(resId);\r\n }\r\n }\r\n\r\n let completed = false;\r\n let executionError: unknown = null;\r\n try {\r\n for (let i = 0; i < compiled.orderedPasses.length; i++) {\r\n const pass = compiled.orderedPasses[i];\r\n\r\n // Allocate resources that start at this pass\r\n const toAllocate = allocateAt.get(i);\r\n if (toAllocate) {\r\n for (const resId of toAllocate) {\r\n const lifetime = compiled.lifetimes.get(resId)!;\r\n const desc = lifetime.resource.desc as RGTextureDesc;\r\n const size = this._resolveSize(desc);\r\n const texture = this._allocator.allocate(desc, size);\r\n this._allocatedTextures.set(resId, texture);\r\n }\r\n }\r\n\r\n // Allocate framebuffer views after their texture attachments are available.\r\n const framebuffersToAllocate = allocateFramebufferAt.get(i);\r\n if (framebuffersToAllocate) {\r\n for (const resId of framebuffersToAllocate) {\r\n const lifetime = compiled.lifetimes.get(resId)!;\r\n const desc = lifetime.resource.desc as RGFramebufferDesc;\r\n const framebuffer = this._createFramebuffer(this._resolveFramebufferDesc(desc), false);\r\n this._allocatedFramebuffers.set(resId, framebuffer);\r\n }\r\n }\r\n\r\n // Execute the pass with exception safety for resource cleanup.\r\n // Release errors must not hide the original pass execution error.\r\n let passError: unknown = null;\r\n try {\r\n if (pass.subpasses.length > 0) {\r\n const accessScope = this._createAccessScope(pass);\r\n const ctx = this._createContext(accessScope);\r\n for (const subpass of pass.subpasses) {\r\n try {\r\n (subpass.executeFn as RGExecuteFn<unknown>)(ctx, pass.data);\r\n } catch (e) {\r\n throw this._wrapSubpassError(pass.name, subpass.name, e);\r\n }\r\n }\r\n } else if (pass.executeFn) {\r\n const accessScope = this._createAccessScope(pass);\r\n const ctx = this._createContext(accessScope);\r\n (pass.executeFn as RGExecuteFn<unknown>)(ctx, pass.data);\r\n }\r\n } catch (e) {\r\n passError = e;\r\n }\r\n\r\n let releaseError: unknown = null;\r\n const framebuffersToRelease = releaseFramebufferAt.get(i);\r\n if (framebuffersToRelease) {\r\n for (const resId of framebuffersToRelease) {\r\n const framebuffer = this._allocatedFramebuffers.get(resId);\r\n if (framebuffer !== undefined) {\r\n try {\r\n this._releaseFramebuffer(framebuffer);\r\n this._allocatedFramebuffers.delete(resId);\r\n } catch (e) {\r\n releaseError ??= e;\r\n }\r\n }\r\n }\r\n }\r\n // Release resources that end at this pass (always runs even if pass throws)\r\n const toRelease = releaseAt.get(i);\r\n if (toRelease) {\r\n for (const resId of toRelease) {\r\n const texture = this._allocatedTextures.get(resId);\r\n if (texture !== undefined) {\r\n try {\r\n this._allocator.release(texture);\r\n this._allocatedTextures.delete(resId);\r\n } catch (e) {\r\n releaseError ??= e;\r\n }\r\n }\r\n }\r\n }\r\n if (passError) {\r\n throw passError;\r\n }\r\n if (releaseError) {\r\n throw releaseError;\r\n }\r\n }\r\n completed = true;\r\n } catch (e) {\r\n executionError = e;\r\n } finally {\r\n let cleanupError: unknown = null;\r\n try {\r\n this._runCleanupCallbacks();\r\n } catch (e) {\r\n cleanupError = e;\r\n } finally {\r\n if (!completed) {\r\n try {\r\n this.reset();\r\n } catch (e) {\r\n cleanupError ??= e;\r\n }\r\n }\r\n }\r\n if (executionError) {\r\n throw executionError;\r\n }\r\n if (cleanupError) {\r\n throw cleanupError;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear imported texture registrations and any leftover allocated textures.\r\n * Call this after execution or when resetting for a new frame.\r\n */\r\n reset(): void {\r\n this._runCleanupCallbacks();\r\n // Release any textures that weren't released (shouldn't happen in normal flow)\r\n for (const framebuffer of this._allocatedFramebuffers.values()) {\r\n this._releaseFramebuffer(framebuffer);\r\n }\r\n this._allocatedFramebuffers.clear();\r\n for (const texture of this._allocatedTextures.values()) {\r\n this._allocator.release(texture);\r\n }\r\n this._allocatedTextures.clear();\r\n this._importedTextures.clear();\r\n this._importedTextureAliases.clear();\r\n this._resolvedImportedTextures.clear();\r\n }\r\n\r\n // ─── Private ────────────────────────────────────────────────────────\r\n\r\n /** @internal */\r\n private _resolveSize(desc: RGTextureDesc): RGResolvedSize {\r\n const mode = desc.sizeMode ?? 'backbuffer-relative';\r\n if (mode === 'absolute') {\r\n return {\r\n width: desc.width ?? 1,\r\n height: desc.height ?? 1\r\n };\r\n }\r\n // backbuffer-relative: width/height are scale factors (default 1.0)\r\n const scaleX = desc.width ?? 1.0;\r\n const scaleY = desc.height ?? 1.0;\r\n return {\r\n width: Math.max(1, Math.floor(this._backbufferWidth * scaleX)),\r\n height: Math.max(1, Math.floor(this._backbufferHeight * scaleY))\r\n };\r\n }\r\n\r\n /** @internal */\r\n private _resolveImportedTextureAliases(compiled: CompiledRenderGraph): void {\r\n this._importedTextureAliases.clear();\r\n this._resolvedImportedTextures.clear();\r\n const physicalToTexture = new Map<number, TTexture>();\r\n for (const lifetime of compiled.lifetimes.values()) {\r\n const resource = lifetime.resource;\r\n if (resource.kind !== 'imported') {\r\n continue;\r\n }\r\n const texture =\r\n this._importedTextures.get(resource.id) ?? this._importedTextures.get(resource.physicalId);\r\n if (texture !== undefined) {\r\n physicalToTexture.set(resource.physicalId, texture);\r\n }\r\n }\r\n for (const lifetime of compiled.lifetimes.values()) {\r\n const resource = lifetime.resource;\r\n if (resource.kind !== 'imported') {\r\n continue;\r\n }\r\n this._importedTextureAliases.set(resource.id, resource.physicalId);\r\n const texture = physicalToTexture.get(resource.physicalId);\r\n if (texture !== undefined) {\r\n this._resolvedImportedTextures.set(resource.id, texture);\r\n this._resolvedImportedTextures.set(resource.physicalId, texture);\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n private _runCleanupCallbacks(): void {\r\n let error: unknown = null;\r\n while (this._cleanupCallbacks.length > 0) {\r\n const callback = this._cleanupCallbacks.pop()!;\r\n try {\r\n callback();\r\n } catch (e) {\r\n error ??= e;\r\n }\r\n }\r\n if (error) {\r\n throw error;\r\n }\r\n }\r\n\r\n /** @internal */\r\n private _createFramebuffer(desc: RGFramebufferDesc, autoCleanup = true): TFramebuffer {\r\n if (!this._allocator.allocateFramebuffer || !this._allocator.releaseFramebuffer) {\r\n throw new Error('RenderGraphExecutor: framebuffer allocation is not supported by this allocator.');\r\n }\r\n const framebuffer = this._allocator.allocateFramebuffer(desc);\r\n if (autoCleanup) {\r\n this._cleanupCallbacks.push(() => {\r\n this._allocator.releaseFramebuffer!(framebuffer);\r\n });\r\n }\r\n return framebuffer;\r\n }\r\n\r\n /** @internal */\r\n private _releaseFramebuffer(framebuffer: TFramebuffer): void {\r\n if (!this._allocator.releaseFramebuffer) {\r\n throw new Error('RenderGraphExecutor: framebuffer release is not supported by this allocator.');\r\n }\r\n this._allocator.releaseFramebuffer(framebuffer);\r\n }\r\n\r\n /** @internal */\r\n private _resolveFramebufferDesc(\r\n desc: RGFramebufferDesc,\r\n accessScope?: RGPassAccessScope\r\n ): RGFramebufferDesc {\r\n const resolveAttachment = (attachment: unknown): unknown => {\r\n if (attachment instanceof RGHandle) {\r\n if (accessScope) {\r\n this._assertDeclaredAccess(accessScope, attachment, 'texture');\r\n }\r\n return this._resolveResource(attachment);\r\n }\r\n return attachment;\r\n };\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? desc.colorAttachments.map(resolveAttachment)\r\n : desc.colorAttachments\r\n ? resolveAttachment(desc.colorAttachments)\r\n : null;\r\n return {\r\n ...desc,\r\n colorAttachments: colors,\r\n depthAttachment: resolveAttachment(desc.depthAttachment)\r\n };\r\n }\r\n\r\n /** @internal */\r\n private _resolveResource(handle: RGHandle): TTexture {\r\n const imported = this._importedTextures.get(handle._id);\r\n if (imported !== undefined) {\r\n return imported;\r\n }\r\n const resolvedImported = this._resolvedImportedTextures.get(handle._id);\r\n if (resolvedImported !== undefined) {\r\n return resolvedImported;\r\n }\r\n const importedAlias = this._importedTextureAliases.get(handle._id);\r\n if (importedAlias !== undefined) {\r\n const aliased =\r\n this._importedTextures.get(importedAlias) ?? this._resolvedImportedTextures.get(importedAlias);\r\n if (aliased !== undefined) {\r\n return aliased;\r\n }\r\n }\r\n const allocated = this._allocatedTextures.get(handle._id);\r\n if (allocated !== undefined) {\r\n return allocated;\r\n }\r\n throw new Error(\r\n `RenderGraphExecutor: cannot resolve resource \"${handle.name}\" (id=${handle._id}). ` +\r\n `It may not have been allocated yet or was already released.`\r\n );\r\n }\r\n\r\n /** @internal */\r\n private _createAccessScope(pass: RGPass): RGPassAccessScope {\r\n const accessibleIds = new Set<number>();\r\n const textureIds = new Set<number>();\r\n const framebufferIds = new Set<number>();\r\n for (const resource of pass.reads) {\r\n accessibleIds.add(resource.id);\r\n if (resource.kind === 'transient' || resource.kind === 'imported') {\r\n textureIds.add(resource.id);\r\n } else if (resource.kind === 'framebuffer') {\r\n framebufferIds.add(resource.id);\r\n }\r\n }\r\n for (const resource of pass.writes) {\r\n accessibleIds.add(resource.id);\r\n if (resource.kind === 'transient' || resource.kind === 'imported') {\r\n textureIds.add(resource.id);\r\n } else if (resource.kind === 'framebuffer') {\r\n framebufferIds.add(resource.id);\r\n }\r\n }\r\n return {\r\n passName: pass.name,\r\n accessibleIds,\r\n textureIds,\r\n framebufferIds\r\n };\r\n }\r\n\r\n /** @internal */\r\n private _assertDeclaredAccess(\r\n accessScope: RGPassAccessScope,\r\n handle: RGHandle,\r\n access: 'texture' | 'framebuffer'\r\n ): void {\r\n if (!accessScope.accessibleIds.has(handle._id)) {\r\n throw new Error(\r\n `RenderGraphExecutor: pass \"${accessScope.passName}\" tried to access ${access} \"${handle.name}\" ` +\r\n `without declaring a read/write dependency.`\r\n );\r\n }\r\n if (access === 'texture' && !accessScope.textureIds.has(handle._id)) {\r\n throw new Error(\r\n `RenderGraphExecutor: pass \"${accessScope.passName}\" tried to access \"${handle.name}\" as a texture, ` +\r\n `but it is not a texture resource.`\r\n );\r\n }\r\n if (access === 'framebuffer' && !accessScope.framebufferIds.has(handle._id)) {\r\n throw new Error(\r\n `RenderGraphExecutor: pass \"${accessScope.passName}\" tried to access \"${handle.name}\" as a framebuffer, ` +\r\n `but it is not a framebuffer resource.`\r\n );\r\n }\r\n }\r\n\r\n /** @internal */\r\n private _wrapSubpassError(passName: string, subpassName: string, error: unknown): Error {\r\n const message = error instanceof Error ? error.message : String(error);\r\n const wrapped = new Error(\r\n `RenderGraphExecutor: pass \"${passName}\" subpass \"${subpassName}\" failed: ${message}`\r\n );\r\n (wrapped as Error & { cause?: unknown }).cause = error;\r\n return wrapped;\r\n }\r\n\r\n /** @internal */\r\n private _createContext(accessScope: RGPassAccessScope): RGExecuteContext {\r\n const self = this;\r\n return {\r\n getTexture<T>(handle: RGHandle): T {\r\n self._assertDeclaredAccess(accessScope, handle, 'texture');\r\n return self._resolveResource(handle) as unknown as T;\r\n },\r\n getFramebuffer<TFramebuffer = unknown>(handle: RGHandle): TFramebuffer {\r\n self._assertDeclaredAccess(accessScope, handle, 'framebuffer');\r\n const framebuffer = self._allocatedFramebuffers.get(handle._id);\r\n if (framebuffer !== undefined) {\r\n return framebuffer as unknown as TFramebuffer;\r\n }\r\n throw new Error(\r\n `RenderGraphExecutor: cannot resolve framebuffer \"${handle.name}\" (id=${handle._id}). ` +\r\n `It may not have been allocated yet or was already released.`\r\n );\r\n },\r\n createFramebuffer<TFramebuffer = unknown>(desc: RGFramebufferDesc): TFramebuffer {\r\n return self._createFramebuffer(\r\n self._resolveFramebufferDesc(desc, accessScope)\r\n ) as unknown as TFramebuffer;\r\n },\r\n deferCleanup(callback: () => void): void {\r\n self._cleanupCallbacks.push(callback);\r\n }\r\n };\r\n }\r\n}\r\n"],"names":["RenderGraphExecutor","_importedTextures","Map","_allocatedTextures","_allocatedFramebuffers","_importedTextureAliases","_resolvedImportedTextures","_cleanupCallbacks","allocator","backbufferWidth","backbufferHeight","_allocator","_backbufferWidth","_backbufferHeight","setBackbufferSize","width","height","setImportedTexture","handle","texture","set","_id","execute","compiled","length","_resolveImportedTextureAliases","allocateAt","releaseAt","allocateFramebufferAt","releaseFramebufferAt","resId","lifetime","lifetimes","resource","kind","has","firstUse","get","push","lastUse","completed","executionError","i","orderedPasses","pass","toAllocate","desc","size","_resolveSize","allocate","framebuffersToAllocate","framebuffer","_createFramebuffer","_resolveFramebufferDesc","passError","subpasses","accessScope","_createAccessScope","ctx","_createContext","subpass","executeFn","data","e","_wrapSubpassError","name","releaseError","framebuffersToRelease","undefined","_releaseFramebuffer","delete","toRelease","release","cleanupError","_runCleanupCallbacks","reset","values","clear","mode","sizeMode","scaleX","scaleY","Math","max","floor","physicalToTexture","id","physicalId","error","callback","pop","autoCleanup","allocateFramebuffer","releaseFramebuffer","Error","resolveAttachment","attachment","RGHandle","_assertDeclaredAccess","_resolveResource","colors","Array","isArray","colorAttachments","map","depthAttachment","imported","resolvedImported","importedAlias","aliased","allocated","accessibleIds","Set","textureIds","framebufferIds","reads","add","writes","passName","access","subpassName","message","String","wrapped","cause","self","getTexture","getFramebuffer","createFramebuffer","deferCleanup"],"mappings":";;AAmBA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;qBAEX,UAA+D;qBAE/D,gBAAiC;qBAEjC,iBAAkC;AAClC,qBACQC,iBAA2C,GAAA,IAAIC,GAAM,EAAA;AAC7D,qBACQC,kBAA4C,GAAA,IAAID,GAAM,EAAA;AAC9D,qBACQE,sBAAoD,GAAA,IAAIF,GAAM,EAAA;AACtE,qBACQG,uBAA+C,GAAA,IAAIH,GAAM,EAAA;AACjE,qBACQI,yBAAmD,GAAA,IAAIJ,GAAM,EAAA;AACrE,qBACQK,iBAAuC,GAAA,EAAE;AAEjD,IAAA,WAAA,CACEC,SAAqD,EACrDC,eAAuB,EACvBC,gBAAwB,CACxB;QACA,IAAI,CAACC,UAAU,GAAGH,SAAAA;QAClB,IAAI,CAACI,gBAAgB,GAAGH,eAAAA;QACxB,IAAI,CAAC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