@zephyr3d/scene 0.9.6 → 0.9.7

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.
Files changed (203) hide show
  1. package/dist/animation/joint_dynamics/controller.js +92 -32
  2. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  3. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  4. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  5. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  6. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  7. package/dist/animation/joint_dynamics/solver.js +71 -27
  8. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  9. package/dist/animation/joint_dynamics_modifier.js +21 -20
  10. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  11. package/dist/animation/skeleton.js +7 -10
  12. package/dist/animation/skeleton.js.map +1 -1
  13. package/dist/app/engine.js +134 -140
  14. package/dist/app/engine.js.map +1 -1
  15. package/dist/app/scriptregistry.js +47 -16
  16. package/dist/app/scriptregistry.js.map +1 -1
  17. package/dist/asset/assetmanager.js +3 -1
  18. package/dist/asset/assetmanager.js.map +1 -1
  19. package/dist/asset/model.js +346 -7
  20. package/dist/asset/model.js.map +1 -1
  21. package/dist/avatar/wardrobe.js +20 -16
  22. package/dist/avatar/wardrobe.js.map +1 -1
  23. package/dist/camera/camera.js +416 -210
  24. package/dist/camera/camera.js.map +1 -1
  25. package/dist/index.d.ts +1349 -621
  26. package/dist/index.js +6 -11
  27. package/dist/index.js.map +1 -1
  28. package/dist/material/blinn.js +1 -1
  29. package/dist/material/blinn.js.map +1 -1
  30. package/dist/material/lambert.js +1 -1
  31. package/dist/material/lambert.js.map +1 -1
  32. package/dist/material/material.js +23 -1
  33. package/dist/material/material.js.map +1 -1
  34. package/dist/material/meshmaterial.js +178 -23
  35. package/dist/material/meshmaterial.js.map +1 -1
  36. package/dist/material/mixins/albedocolor.js +4 -4
  37. package/dist/material/mixins/albedocolor.js.map +1 -1
  38. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  39. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  41. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  43. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
  45. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  47. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  48. package/dist/material/mixins/lit.js +1 -1
  49. package/dist/material/mixins/lit.js.map +1 -1
  50. package/dist/material/mixins/pbr/common.js +276 -65
  51. package/dist/material/mixins/pbr/common.js.map +1 -1
  52. package/dist/material/mixins/texture.js +3 -3
  53. package/dist/material/mixins/texture.js.map +1 -1
  54. package/dist/material/mixins/vertexcolor.js +2 -2
  55. package/dist/material/mixins/vertexcolor.js.map +1 -1
  56. package/dist/material/mtoon.js +574 -0
  57. package/dist/material/mtoon.js.map +1 -0
  58. package/dist/material/pbrblueprint.js +499 -336
  59. package/dist/material/pbrblueprint.js.map +1 -1
  60. package/dist/material/pbrmr.js +118 -100
  61. package/dist/material/pbrmr.js.map +1 -1
  62. package/dist/material/pbrsg.js +1 -1
  63. package/dist/material/pbrsg.js.map +1 -1
  64. package/dist/material/shader/helper.js +324 -294
  65. package/dist/material/shader/helper.js.map +1 -1
  66. package/dist/material/subsurfaceprofile.js +812 -0
  67. package/dist/material/subsurfaceprofile.js.map +1 -0
  68. package/dist/material/unlit.js +1 -1
  69. package/dist/material/unlit.js.map +1 -1
  70. package/dist/posteffect/compositor.js +46 -11
  71. package/dist/posteffect/compositor.js.map +1 -1
  72. package/dist/posteffect/ssr.js +422 -96
  73. package/dist/posteffect/ssr.js.map +1 -1
  74. package/dist/posteffect/sss.js +1053 -0
  75. package/dist/posteffect/sss.js.map +1 -0
  76. package/dist/posteffect/taa.js +61 -60
  77. package/dist/posteffect/taa.js.map +1 -1
  78. package/dist/render/abuffer_oit.js +63 -12
  79. package/dist/render/abuffer_oit.js.map +1 -1
  80. package/dist/render/cluster_light.js +6 -5
  81. package/dist/render/cluster_light.js.map +1 -1
  82. package/dist/render/drawable.js +1 -5
  83. package/dist/render/drawable.js.map +1 -1
  84. package/dist/render/drawable_mixin.js +2 -1
  85. package/dist/render/drawable_mixin.js.map +1 -1
  86. package/dist/render/fbm_wavegenerator.js +2 -1
  87. package/dist/render/fbm_wavegenerator.js.map +1 -1
  88. package/dist/render/gerstner_wavegenerator.js +2 -1
  89. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  90. package/dist/render/globalbindgroup_allocator.js +2 -1
  91. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  92. package/dist/render/lightpass.js +110 -23
  93. package/dist/render/lightpass.js.map +1 -1
  94. package/dist/render/render_queue.js +51 -8
  95. package/dist/render/render_queue.js.map +1 -1
  96. package/dist/render/renderer.js +80 -66
  97. package/dist/render/renderer.js.map +1 -1
  98. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  99. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  100. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  101. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  102. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  103. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  104. package/dist/render/rendergraph/history_resources.js +3 -1
  105. package/dist/render/rendergraph/history_resources.js.map +1 -1
  106. package/dist/render/rendergraph/types.js.map +1 -1
  107. package/dist/render/renderpass.js +10 -4
  108. package/dist/render/renderpass.js.map +1 -1
  109. package/dist/render/sky.js +31 -1
  110. package/dist/render/sky.js.map +1 -1
  111. package/dist/render/weightedblended_oit.js +23 -5
  112. package/dist/render/weightedblended_oit.js.map +1 -1
  113. package/dist/scene/basesprite.js +4 -2
  114. package/dist/scene/basesprite.js.map +1 -1
  115. package/dist/scene/batchgroup.js +3 -1
  116. package/dist/scene/batchgroup.js.map +1 -1
  117. package/dist/scene/environment.js +11 -1
  118. package/dist/scene/environment.js.map +1 -1
  119. package/dist/scene/light.js +21 -3
  120. package/dist/scene/light.js.map +1 -1
  121. package/dist/scene/mesh.js +29 -14
  122. package/dist/scene/mesh.js.map +1 -1
  123. package/dist/scene/meshdrawable.js +6 -0
  124. package/dist/scene/meshdrawable.js.map +1 -1
  125. package/dist/scene/msdftext.js +5 -2
  126. package/dist/scene/msdftext.js.map +1 -1
  127. package/dist/scene/msdftextsprite.js +5 -3
  128. package/dist/scene/msdftextsprite.js.map +1 -1
  129. package/dist/scene/particlesys.js +3 -1
  130. package/dist/scene/particlesys.js.map +1 -1
  131. package/dist/scene/scene.js +6 -5
  132. package/dist/scene/scene.js.map +1 -1
  133. package/dist/scene/terrain-cm/grass.js +4 -2
  134. package/dist/scene/terrain-cm/grass.js.map +1 -1
  135. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  136. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  137. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  138. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  139. package/dist/scene/water.js +4 -2
  140. package/dist/scene/water.js.map +1 -1
  141. package/dist/shaders/shadow.js +26 -393
  142. package/dist/shaders/shadow.js.map +1 -1
  143. package/dist/shadow/esm.js +112 -12
  144. package/dist/shadow/esm.js.map +1 -1
  145. package/dist/shadow/pcf_opt.js +2 -2
  146. package/dist/shadow/pcf_opt.js.map +1 -1
  147. package/dist/shadow/pcf_pd.js +19 -10
  148. package/dist/shadow/pcf_pd.js.map +1 -1
  149. package/dist/shadow/shader.js +58 -7
  150. package/dist/shadow/shader.js.map +1 -1
  151. package/dist/shadow/shadow_impl.js +6 -0
  152. package/dist/shadow/shadow_impl.js.map +1 -1
  153. package/dist/shadow/shadow_region.js +229 -0
  154. package/dist/shadow/shadow_region.js.map +1 -0
  155. package/dist/shadow/shadowmapper.js +67 -59
  156. package/dist/shadow/shadowmapper.js.map +1 -1
  157. package/dist/shadow/vsm.js +45 -19
  158. package/dist/shadow/vsm.js.map +1 -1
  159. package/dist/utility/blueprint/common/constants.js +8 -8
  160. package/dist/utility/blueprint/common/constants.js.map +1 -1
  161. package/dist/utility/blueprint/material/pbr.js +31 -4
  162. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  163. package/dist/utility/blueprint/material/texture.js +1 -17
  164. package/dist/utility/blueprint/material/texture.js.map +1 -1
  165. package/dist/utility/serialization/manager.js +327 -359
  166. package/dist/utility/serialization/manager.js.map +1 -1
  167. package/dist/utility/serialization/scene/animation.js +5 -2
  168. package/dist/utility/serialization/scene/animation.js.map +1 -1
  169. package/dist/utility/serialization/scene/batch.js +4 -1
  170. package/dist/utility/serialization/scene/batch.js.map +1 -1
  171. package/dist/utility/serialization/scene/camera.js +249 -54
  172. package/dist/utility/serialization/scene/camera.js.map +1 -1
  173. package/dist/utility/serialization/scene/common.js +37 -1
  174. package/dist/utility/serialization/scene/common.js.map +1 -1
  175. package/dist/utility/serialization/scene/light.js +42 -3
  176. package/dist/utility/serialization/scene/light.js.map +1 -1
  177. package/dist/utility/serialization/scene/material.js +1112 -646
  178. package/dist/utility/serialization/scene/material.js.map +1 -1
  179. package/dist/utility/serialization/scene/mesh.js +7 -4
  180. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  181. package/dist/utility/serialization/scene/node.js +31 -12
  182. package/dist/utility/serialization/scene/node.js.map +1 -1
  183. package/dist/utility/serialization/scene/particle.js +4 -1
  184. package/dist/utility/serialization/scene/particle.js.map +1 -1
  185. package/dist/utility/serialization/scene/primitive.js +3 -1
  186. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  187. package/dist/utility/serialization/scene/scene.js +18 -0
  188. package/dist/utility/serialization/scene/scene.js.map +1 -1
  189. package/dist/utility/serialization/scene/sprite.js +6 -3
  190. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  191. package/dist/utility/serialization/scene/terrain.js +5 -2
  192. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  193. package/dist/utility/serialization/scene/text.js +3 -1
  194. package/dist/utility/serialization/scene/text.js.map +1 -1
  195. package/dist/utility/serialization/scene/water.js +4 -1
  196. package/dist/utility/serialization/scene/water.js.map +1 -1
  197. package/dist/utility/textures/ltcdata.js +6 -0
  198. package/dist/utility/textures/ltcdata.js.map +1 -0
  199. package/dist/utility/textures/ltclut.js +61 -0
  200. package/dist/utility/textures/ltclut.js.map +1 -0
  201. package/dist/values.js +9 -1
  202. package/dist/values.js.map +1 -1
  203. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"history_resource_manager.js","sources":["../../../src/render/rendergraph/history_resource_manager.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\r\nimport type { RenderGraph } from './rendergraph';\r\nimport type { RenderGraphExecutor } from './executor';\r\nimport type { RGHandle, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\n\r\ninterface HistoryResource<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n textures: [TTexture | null, TTexture | null];\r\n ownsTexture: [boolean, boolean];\r\n currentIndex: number;\r\n valid: boolean;\r\n}\r\n\r\ninterface PendingHistoryCommit<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n texture: TTexture;\r\n ownsTexture: boolean;\r\n}\r\n\r\n/**\r\n * Manages cross-frame history resources that can be imported into a render graph.\r\n *\r\n * History resources are textures that persist across frames for temporal effects\r\n * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be\r\n * imported into a {@link RenderGraph}, and current-frame textures are committed\r\n * only after graph execution succeeds.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const historyMgr = new HistoryResourceManager(allocator);\r\n * historyMgr.beginFrame();\r\n * const prev = historyMgr.importPrevious(graph, 'taaColor');\r\n * // declare builder.read(prev) if non-null\r\n * historyMgr.bindImportedTextures(executor);\r\n * // after successful execution:\r\n * historyMgr.commitFrame();\r\n * ```\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport class HistoryResourceManager<TTexture = Texture2D> {\r\n private _resources: Map<string, HistoryResource<TTexture>> = new Map();\r\n private _allocator: RGTextureAllocator<TTexture>;\r\n private _pendingImports: Map<RGHandle, TTexture> = new Map();\r\n private _pendingCommits: Map<string, PendingHistoryCommit<TTexture>> = new Map();\r\n private _readScopeStack: Array<Map<string, TTexture>> = [];\r\n\r\n /**\r\n * Create a new history resource manager.\r\n *\r\n * @param allocator - Texture allocator for creating history textures.\r\n */\r\n constructor(allocator: RGTextureAllocator<TTexture>) {\r\n this._allocator = allocator;\r\n }\r\n\r\n /**\r\n * Get the previous-frame texture resolved by the current render graph pass.\r\n *\r\n * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or\r\n * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with\r\n * {@link HistoryResourceManager.beginReadScope} before this method is called.\r\n *\r\n * @param name - Name of the history resource.\r\n * @returns The graph-resolved previous-frame texture.\r\n * @throws If no read scope is active for the resource.\r\n */\r\n getPrevious(name: string): TTexture {\r\n const scoped = this._getScopedRead(name);\r\n if (scoped) {\r\n return scoped;\r\n }\r\n throw new Error(\r\n `History resource '${name}' is not available in the current render graph read scope. ` +\r\n `Import it and declare a pass read before accessing it.`\r\n );\r\n }\r\n\r\n /**\r\n * Check whether a valid history resource exists and matches the descriptor.\r\n *\r\n * @param name - Name of the history resource.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns True if the resource exists, is valid, and matches.\r\n */\r\n isCompatible(name: string, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n const resource = this._resources.get(name);\r\n return !!resource?.valid && this._matches(resource, desc, size);\r\n }\r\n\r\n /**\r\n * Start collecting graph imports and deferred commits for a new frame.\r\n */\r\n beginFrame(): void {\r\n this.discardFrame();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture for a history resource into the graph.\r\n *\r\n * Returns null when the resource has no valid previous frame.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @returns Imported graph handle, or null when no valid previous texture exists.\r\n */\r\n importPrevious(graph: RenderGraph, name: string): RGHandle | null {\r\n const resource = this._resources.get(name);\r\n const texture = resource?.valid ? resource.textures[resource.currentIndex] : null;\r\n if (!texture) {\r\n return null;\r\n }\r\n const handle = graph.importTexture(`history:${name}:previous`);\r\n this._pendingImports.set(handle, texture);\r\n return handle;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture only when it matches the expected shape.\r\n *\r\n * This is the preferred API for effects that can declare their history reads\r\n * while building the graph: incompatible history is treated as absent, so the\r\n * pass does not declare stale reads after resize or format changes.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns Imported graph handle, or null when no compatible history exists.\r\n */\r\n importPreviousIfCompatible(\r\n graph: RenderGraph,\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize\r\n ): RGHandle | null {\r\n return this.isCompatible(name, desc, size) ? this.importPrevious(graph, name) : null;\r\n }\r\n\r\n /**\r\n * Bind all history imports created for this frame to the executor.\r\n *\r\n * @param executor - Render graph executor for the current frame.\r\n */\r\n bindImportedTextures(executor: Pick<RenderGraphExecutor<TTexture>, 'setImportedTexture'>): void {\r\n for (const [handle, texture] of this._pendingImports) {\r\n executor.setImportedTexture(handle, texture);\r\n }\r\n }\r\n\r\n /**\r\n * Make resolved history textures available to code executing inside a pass.\r\n *\r\n * @param bindings - History name to resolved texture bindings.\r\n */\r\n beginReadScope(bindings: Array<{ name: string; texture: TTexture }>): void {\r\n const scope = new Map<string, TTexture>();\r\n for (const binding of bindings) {\r\n scope.set(binding.name, binding.texture);\r\n }\r\n this._readScopeStack.push(scope);\r\n }\r\n\r\n /**\r\n * End the most recent history read scope.\r\n */\r\n endReadScope(): void {\r\n this._readScopeStack.pop();\r\n }\r\n\r\n /**\r\n * Queue a current-frame texture to become the next previous-frame history.\r\n *\r\n * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the\r\n * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.\r\n *\r\n * @param name - History resource name.\r\n * @param desc - Texture descriptor.\r\n * @param size - Resolved texture size.\r\n * @param texture - Texture produced by the current frame.\r\n * @param ownsTexture - Whether this manager should release the texture later.\r\n */\r\n queueCommit(\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize,\r\n texture: TTexture,\r\n ownsTexture = true\r\n ): void {\r\n const existing = this._pendingCommits.get(name);\r\n if (existing?.ownsTexture) {\r\n this._allocator.release(existing.texture);\r\n }\r\n this._pendingCommits.set(name, {\r\n desc: { ...desc },\r\n size: { ...size },\r\n texture,\r\n ownsTexture\r\n });\r\n }\r\n\r\n /**\r\n * Commit all current-frame history writes.\r\n */\r\n commitFrame(): void {\r\n for (const [name, pending] of this._pendingCommits) {\r\n let resource = this._resources.get(name);\r\n if (resource && !this._matches(resource, pending.desc, pending.size)) {\r\n this._releaseResource(resource);\r\n this._resources.delete(name);\r\n resource = undefined;\r\n }\r\n if (!resource) {\r\n resource = {\r\n desc: { ...pending.desc },\r\n size: { ...pending.size },\r\n textures: [null, null],\r\n ownsTexture: [false, false],\r\n currentIndex: 0,\r\n valid: false\r\n };\r\n this._resources.set(name, resource);\r\n }\r\n\r\n const writeIndex = resource.valid ? 1 - resource.currentIndex : resource.currentIndex;\r\n this._releaseSlot(resource, writeIndex);\r\n resource.textures[writeIndex] = pending.texture;\r\n resource.ownsTexture[writeIndex] = pending.ownsTexture;\r\n resource.desc = { ...pending.desc };\r\n resource.size = { ...pending.size };\r\n resource.currentIndex = writeIndex;\r\n resource.valid = true;\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Discard all uncommitted frame history writes.\r\n */\r\n discardFrame(): void {\r\n for (const pending of this._pendingCommits.values()) {\r\n if (pending.ownsTexture) {\r\n this._allocator.release(pending.texture);\r\n }\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Release all history resources and clear the manager.\r\n *\r\n * Call this when disposing the render context or when history is no longer needed.\r\n */\r\n dispose(): void {\r\n this.discardFrame();\r\n for (const resource of this._resources.values()) {\r\n this._releaseResource(resource);\r\n }\r\n this._resources.clear();\r\n }\r\n\r\n /** @internal */\r\n private _getScopedRead(name: string): TTexture | null {\r\n for (let i = this._readScopeStack.length - 1; i >= 0; i--) {\r\n const texture = this._readScopeStack[i].get(name);\r\n if (texture) {\r\n return texture;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n private _matches(resource: HistoryResource<TTexture>, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n return (\r\n resource.desc.format === desc.format &&\r\n (resource.desc.mipLevels ?? 1) === (desc.mipLevels ?? 1) &&\r\n resource.size.width === size.width &&\r\n resource.size.height === size.height\r\n );\r\n }\r\n\r\n /** @internal */\r\n private _releaseResource(resource: HistoryResource<TTexture>): void {\r\n this._releaseSlot(resource, 0);\r\n this._releaseSlot(resource, 1);\r\n resource.valid = false;\r\n }\r\n\r\n /** @internal */\r\n private _releaseSlot(resource: HistoryResource<TTexture>, index: number): void {\r\n const texture = resource.textures[index];\r\n if (!texture) {\r\n return;\r\n }\r\n const otherIndex = 1 - index;\r\n if (resource.ownsTexture[index] && resource.textures[otherIndex] !== texture) {\r\n this._allocator.release(texture);\r\n }\r\n resource.textures[index] = null;\r\n resource.ownsTexture[index] = false;\r\n }\r\n}\r\n"],"names":["HistoryResourceManager","_resources","Map","_allocator","_pendingImports","_pendingCommits","_readScopeStack","allocator","getPrevious","name","scoped","_getScopedRead","Error","isCompatible","desc","size","resource","get","valid","_matches","beginFrame","discardFrame","clear","length","importPrevious","graph","texture","textures","currentIndex","handle","importTexture","set","importPreviousIfCompatible","bindImportedTextures","executor","setImportedTexture","beginReadScope","bindings","scope","binding","push","endReadScope","pop","queueCommit","ownsTexture","existing","release","commitFrame","pending","_releaseResource","delete","undefined","writeIndex","_releaseSlot","values","dispose","i","format","mipLevels","width","height","index","otherIndex"],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;AAqBC,IACM,MAAMA,sBAAAA,CAAAA;AACHC,IAAAA,UAAAA,GAAqD,IAAIC,GAAM,EAAA;IAC/DC,UAAyC;AACzCC,IAAAA,eAAAA,GAA2C,IAAIF,GAAM,EAAA;AACrDG,IAAAA,eAAAA,GAA+D,IAAIH,GAAM,EAAA;AACzEI,IAAAA,eAAAA,GAAgD,EAAE;AAE1D;;;;MAKA,WAAA,CAAYC,SAAuC,CAAE;QACnD,IAAI,CAACJ,UAAU,GAAGI,SAAAA;AACpB;AAEA;;;;;;;;;;MAWAC,WAAAA,CAAYC,IAAY,EAAY;AAClC,QAAA,MAAMC,MAAS,GAAA,IAAI,CAACC,cAAc,CAACF,IAAAA,CAAAA;AACnC,QAAA,IAAIC,MAAQ,EAAA;YACV,OAAOA,MAAAA;AACT;QACA,MAAM,IAAIE,KACR,CAAA,CAAC,kBAAkB,EAAEH,IAAK,CAAA,2DAA2D,CAAC,GACpF,CAAC,sDAAsD,CAAC,CAAA;AAE9D;AAEA;;;;;;;AAOC,MACDI,aAAaJ,IAAY,EAAEK,IAAmB,EAAEC,IAAoB,EAAW;AAC7E,QAAA,MAAMC,WAAW,IAAI,CAACf,UAAU,CAACgB,GAAG,CAACR,IAAAA,CAAAA;QACrC,OAAO,CAAC,CAACO,QAAUE,EAAAA,KAAAA,IAAS,IAAI,CAACC,QAAQ,CAACH,QAAAA,EAAUF,IAAMC,EAAAA,IAA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KAAK3C,KAAK2C,MAAM,IACpC,CAACzC,SAASF,IAAI,CAAC4C,SAAS,IAAI,CAAA,OAAQ5C,IAAK4C,CAAAA,SAAS,IAAI,CAAA,CAAA,IACtD1C,QAASD,CAAAA,IAAI,CAAC4C,KAAK,KAAK5C,IAAK4C,CAAAA,KAAK,IAClC3C,QAASD,CAAAA,IAAI,CAAC6C,MAAM,KAAK7C,KAAK6C,MAAM;AAExC;AAEA,qBACQX,gBAAiBjC,CAAAA,QAAmC,EAAQ;QAClE,IAAI,CAACqC,YAAY,CAACrC,QAAU,EAAA,CAAA,CAAA;QAC5B,IAAI,CAACqC,YAAY,CAACrC,QAAU,EAAA,CAAA,CAAA;AAC5BA,QAAAA,QAAAA,CAASE,KAAK,GAAG,KAAA;AACnB;AAEA,qBACA,YAAQmC,CAAarC,QAAmC,EAAE6C,KAAa,EAAQ;AAC7E,QAAA,MAAMnC,OAAUV,GAAAA,QAAAA,CAASW,QAAQ,CAACkC,KAAM,CAAA;AACxC,QAAA,IAAI,CAACnC,OAAS,EAAA;AACZ,YAAA;AACF;AACA,QAAA,MAAMoC,aAAa,CAAID,GAAAA,KAAAA;QACvB,IAAI7C,QAAAA,CAAS4B,WAAW,CAACiB,KAAM,CAAA,IAAI7C,SAASW,QAAQ,CAACmC,UAAW,CAAA,KAAKpC,OAAS,EAAA;AAC5E,YAAA,IAAI,CAACvB,UAAU,CAAC2C,OAAO,CAACpB,OAAAA,CAAAA;AAC1B;QACAV,QAASW,CAAAA,QAAQ,CAACkC,KAAAA,CAAM,GAAG,IAAA;QAC3B7C,QAAS4B,CAAAA,WAAW,CAACiB,KAAAA,CAAM,GAAG,KAAA;AAChC;AACF;;;;"}
1
+ {"version":3,"file":"history_resource_manager.js","sources":["../../../src/render/rendergraph/history_resource_manager.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\r\nimport type { RenderGraph } from './rendergraph';\r\nimport type { RenderGraphExecutor } from './executor';\r\nimport type { RGHandle, RGExecuteContext, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\n\r\ninterface HistoryResource<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n textures: [TTexture | null, TTexture | null];\r\n ownsTexture: [boolean, boolean];\r\n currentIndex: number;\r\n valid: boolean;\r\n}\r\n\r\ninterface PendingHistoryCommit<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n texture: TTexture;\r\n ownsTexture: boolean;\r\n}\r\n\r\n/**\r\n * Manages cross-frame history resources that can be imported into a render graph.\r\n *\r\n * History resources are textures that persist across frames for temporal effects\r\n * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be\r\n * imported into a {@link RenderGraph}, and current-frame textures are committed\r\n * only after graph execution succeeds.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const historyMgr = new HistoryResourceManager(allocator);\r\n * historyMgr.beginFrame();\r\n * const prev = historyMgr.importPrevious(graph, 'taaColor');\r\n * // declare builder.read(prev) if non-null\r\n * historyMgr.bindImportedTextures(executor);\r\n * // after successful execution:\r\n * historyMgr.commitFrame();\r\n * ```\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport class HistoryResourceManager<TTexture = Texture2D> {\r\n private _resources: Map<string, HistoryResource<TTexture>> = new Map();\r\n private _allocator: RGTextureAllocator<TTexture>;\r\n private _pendingImports: Map<RGHandle, TTexture> = new Map();\r\n private _pendingCommits: Map<string, PendingHistoryCommit<TTexture>> = new Map();\r\n private _readScopeStack: Array<Map<string, TTexture>> = [];\r\n private _frameActive = false;\r\n\r\n /**\r\n * Create a new history resource manager.\r\n *\r\n * @param allocator - Texture allocator for creating history textures.\r\n */\r\n constructor(allocator: RGTextureAllocator<TTexture>) {\r\n this._allocator = allocator;\r\n }\r\n\r\n /**\r\n * Get the previous-frame texture resolved by the current render graph pass.\r\n *\r\n * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or\r\n * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with\r\n * {@link HistoryResourceManager.beginReadScope} before this method is called.\r\n *\r\n * @param name - Name of the history resource.\r\n * @returns The graph-resolved previous-frame texture.\r\n * @throws If no read scope is active for the resource.\r\n */\r\n getPrevious(name: string): TTexture {\r\n const scoped = this._getScopedRead(name);\r\n if (scoped) {\r\n return scoped;\r\n }\r\n throw new Error(\r\n `History resource '${name}' is not available in the current render graph read scope. ` +\r\n `Import it and declare a pass read before accessing it.`\r\n );\r\n }\r\n\r\n /**\r\n * Try to get a previous-frame texture from the current render graph read scope.\r\n *\r\n * Returns null when the resource was not imported for the current pass.\r\n *\r\n * @param name - Name of the history resource.\r\n * @returns The scoped previous-frame texture, or null.\r\n */\r\n tryGetPrevious(name: string): TTexture | null {\r\n return this._getScopedRead(name);\r\n }\r\n\r\n /**\r\n * Whether this manager is currently collecting imports/commits for a graph frame.\r\n */\r\n get frameActive(): boolean {\r\n return this._frameActive;\r\n }\r\n\r\n /**\r\n * Check whether a valid history resource exists and matches the descriptor.\r\n *\r\n * @param name - Name of the history resource.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns True if the resource exists, is valid, and matches.\r\n */\r\n isCompatible(name: string, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n const resource = this._resources.get(name);\r\n return !!resource?.valid && this._matches(resource, desc, size);\r\n }\r\n\r\n /**\r\n * Start collecting graph imports and deferred commits for a new frame.\r\n */\r\n beginFrame(): void {\r\n this.discardFrame();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n this._frameActive = true;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture for a history resource into the graph.\r\n *\r\n * Returns null when the resource has no valid previous frame.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @returns Imported graph handle, or null when no valid previous texture exists.\r\n */\r\n importPrevious(graph: RenderGraph, name: string): RGHandle | null {\r\n const resource = this._resources.get(name);\r\n const texture = resource?.valid ? resource.textures[resource.currentIndex] : null;\r\n if (!texture) {\r\n return null;\r\n }\r\n const handle = graph.importTexture(`history:${name}:previous`);\r\n this._pendingImports.set(handle, texture);\r\n return handle;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture only when it matches the expected shape.\r\n *\r\n * This is the preferred API for effects that can declare their history reads\r\n * while building the graph: incompatible history is treated as absent, so the\r\n * pass does not declare stale reads after resize or format changes.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns Imported graph handle, or null when no compatible history exists.\r\n */\r\n importPreviousIfCompatible(\r\n graph: RenderGraph,\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize\r\n ): RGHandle | null {\r\n return this.isCompatible(name, desc, size) ? this.importPrevious(graph, name) : null;\r\n }\r\n\r\n /**\r\n * Bind all history imports created for this frame to the executor.\r\n *\r\n * @param executor - Render graph executor for the current frame.\r\n */\r\n bindImportedTextures(executor: Pick<RenderGraphExecutor<TTexture>, 'setImportedTexture'>): void {\r\n for (const [handle, texture] of this._pendingImports) {\r\n executor.setImportedTexture(handle, texture);\r\n }\r\n }\r\n\r\n /**\r\n * Make resolved history textures available to code executing inside a pass.\r\n *\r\n * @param bindings - History name to resolved texture bindings.\r\n */\r\n beginReadScope(bindings: Array<{ name: string; texture: TTexture }>): void {\r\n const scope = new Map<string, TTexture>();\r\n for (const binding of bindings) {\r\n scope.set(binding.name, binding.texture);\r\n }\r\n this._readScopeStack.push(scope);\r\n }\r\n\r\n /**\r\n * End the most recent history read scope.\r\n */\r\n endReadScope(): void {\r\n this._readScopeStack.pop();\r\n }\r\n\r\n /**\r\n * Queue a current-frame texture to become the next previous-frame history.\r\n *\r\n * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the\r\n * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.\r\n *\r\n * @param name - History resource name.\r\n * @param desc - Texture descriptor.\r\n * @param size - Resolved texture size.\r\n * @param texture - Texture produced by the current frame.\r\n * @param ownsTexture - Whether this manager should release the texture later.\r\n */\r\n queueCommit(\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize,\r\n texture: TTexture,\r\n ownsTexture = true\r\n ): void {\r\n const existing = this._pendingCommits.get(name);\r\n if (existing?.ownsTexture) {\r\n this._allocator.release(existing.texture);\r\n }\r\n this._pendingCommits.set(name, {\r\n desc: { ...desc },\r\n size: { ...size },\r\n texture,\r\n ownsTexture\r\n });\r\n }\r\n\r\n /**\r\n * Queue a graph-produced texture as a current-frame history write.\r\n *\r\n * The allocator must retain the texture before the graph executor releases its\r\n * transient reference. Use this from inside the pass that declares access to\r\n * the handle being committed.\r\n *\r\n * @param name - History resource name.\r\n * @param desc - Texture descriptor.\r\n * @param size - Resolved texture size.\r\n * @param ctx - Current render graph execute context.\r\n * @param handle - Graph texture handle to commit.\r\n * @returns The retained texture.\r\n */\r\n queueCommitFromGraph(\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize,\r\n ctx: Pick<RGExecuteContext, 'getTexture'>,\r\n handle: RGHandle\r\n ): TTexture {\r\n const texture = ctx.getTexture<TTexture>(handle);\r\n this.queueRetainedCommit(name, desc, size, texture);\r\n return texture;\r\n }\r\n\r\n /**\r\n * Queue a texture after retaining it through the allocator.\r\n *\r\n * Use this for textures produced by the graph allocator. The manager owns the\r\n * retained reference and releases it when the history slot is overwritten,\r\n * discarded, or disposed.\r\n *\r\n * @param name - History resource name.\r\n * @param desc - Texture descriptor.\r\n * @param size - Resolved texture size.\r\n * @param texture - Texture to retain and commit.\r\n */\r\n queueRetainedCommit(name: string, desc: RGTextureDesc, size: RGResolvedSize, texture: TTexture): void {\r\n if (!this._allocator.retain) {\r\n throw new Error(\r\n `HistoryResourceManager: cannot retain history resource '${name}'. ` +\r\n `The allocator does not support retained graph texture handoff.`\r\n );\r\n }\r\n this._allocator.retain(texture);\r\n this.queueCommit(name, desc, size, texture, true);\r\n }\r\n\r\n /**\r\n * Commit all current-frame history writes.\r\n */\r\n commitFrame(): void {\r\n for (const [name, pending] of this._pendingCommits) {\r\n let resource = this._resources.get(name);\r\n if (resource && !this._matches(resource, pending.desc, pending.size)) {\r\n this._releaseResource(resource);\r\n this._resources.delete(name);\r\n resource = undefined;\r\n }\r\n if (!resource) {\r\n resource = {\r\n desc: { ...pending.desc },\r\n size: { ...pending.size },\r\n textures: [null, null],\r\n ownsTexture: [false, false],\r\n currentIndex: 0,\r\n valid: false\r\n };\r\n this._resources.set(name, resource);\r\n }\r\n\r\n const writeIndex = resource.valid ? 1 - resource.currentIndex : resource.currentIndex;\r\n this._releaseSlot(resource, writeIndex);\r\n resource.textures[writeIndex] = pending.texture;\r\n resource.ownsTexture[writeIndex] = pending.ownsTexture;\r\n resource.desc = { ...pending.desc };\r\n resource.size = { ...pending.size };\r\n resource.currentIndex = writeIndex;\r\n resource.valid = true;\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n this._frameActive = false;\r\n }\r\n\r\n /**\r\n * Discard all uncommitted frame history writes.\r\n */\r\n discardFrame(): void {\r\n for (const pending of this._pendingCommits.values()) {\r\n if (pending.ownsTexture) {\r\n this._allocator.release(pending.texture);\r\n }\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n this._frameActive = false;\r\n }\r\n\r\n /**\r\n * Release all history resources and clear the manager.\r\n *\r\n * Call this when disposing the render context or when history is no longer needed.\r\n */\r\n dispose(): void {\r\n this.discardFrame();\r\n for (const resource of this._resources.values()) {\r\n this._releaseResource(resource);\r\n }\r\n this._resources.clear();\r\n }\r\n\r\n /** @internal */\r\n private _getScopedRead(name: string): TTexture | null {\r\n for (let i = this._readScopeStack.length - 1; i >= 0; i--) {\r\n const texture = this._readScopeStack[i].get(name);\r\n if (texture) {\r\n return texture;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n private _matches(resource: HistoryResource<TTexture>, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n return (\r\n resource.desc.format === desc.format &&\r\n (resource.desc.mipLevels ?? 1) === (desc.mipLevels ?? 1) &&\r\n resource.size.width === size.width &&\r\n resource.size.height === size.height\r\n );\r\n }\r\n\r\n /** @internal */\r\n private _releaseResource(resource: HistoryResource<TTexture>): void {\r\n this._releaseSlot(resource, 0);\r\n this._releaseSlot(resource, 1);\r\n resource.valid = false;\r\n }\r\n\r\n /** @internal */\r\n private _releaseSlot(resource: HistoryResource<TTexture>, index: number): void {\r\n const texture = resource.textures[index];\r\n if (!texture) {\r\n return;\r\n }\r\n const otherIndex = 1 - index;\r\n if (resource.ownsTexture[index] && resource.textures[otherIndex] !== texture) {\r\n this._allocator.release(texture);\r\n }\r\n resource.textures[index] = null;\r\n resource.ownsTexture[index] = false;\r\n }\r\n}\r\n"],"names":["HistoryResourceManager","_resources","Map","_allocator","_pendingImports","_pendingCommits","_readScopeStack","_frameActive","allocator","getPrevious","name","scoped","_getScopedRead","Error","tryGetPrevious","frameActive","isCompatible","desc","size","resource","get","valid","_matches","beginFrame","discardFrame","clear","length","importPrevious","graph","texture","textures","currentIndex","handle","importTexture","set","importPreviousIfCompatible","bindImportedTextures","executor","setImportedTexture","beginReadScope","bindings","scope","binding","push","endReadScope","pop","queueCommit","ownsTexture","existing","release","queueCommitFromGraph","ctx","getTexture","queueRetainedCommit","retain","commitFrame","pending","_releaseResource","delete","undefined","writeIndex","_releaseSlot","values","dispose","i","format","mipLevels","width","height","index","otherIndex"],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;AAqBC,IACM,MAAMA,sBAAAA,CAAAA;AACHC,IAAAA,UAAAA,GAAqD,IAAIC,GAAM,EAAA;IAC/DC,UAAyC;AACzCC,IAAAA,eAAAA,GAA2C,IAAIF,GAAM,EAAA;AACrDG,IAAAA,eAAAA,GAA+D,IAAIH,GAAM,EAAA;AACzEI,IAAAA,eAAAA,GAA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AAAA;QACvB,IAAIlD,QAAAA,CAAS4B,WAAW,CAACsB,KAAM,CAAA,IAAIlD,SAASW,QAAQ,CAACwC,UAAW,CAAA,KAAKzC,OAAS,EAAA;AAC5E,YAAA,IAAI,CAAC1B,UAAU,CAAC8C,OAAO,CAACpB,OAAAA,CAAAA;AAC1B;QACAV,QAASW,CAAAA,QAAQ,CAACuC,KAAAA,CAAM,GAAG,IAAA;QAC3BlD,QAAS4B,CAAAA,WAAW,CAACsB,KAAAA,CAAM,GAAG,KAAA;AAChC;AACF;;;;"}
@@ -3,7 +3,9 @@
3
3
  * @public
4
4
  */ const RGHistoryResources = {
5
5
  TAA_COLOR: 'taaColor',
6
- TAA_MOTION_VECTOR: 'taaMotionVector'
6
+ TAA_MOTION_VECTOR: 'taaMotionVector',
7
+ SSR_REFLECT: 'ssrReflect',
8
+ SSR_MOTION_VECTOR: 'ssrMotionVector'
7
9
  };
8
10
 
9
11
  export { RGHistoryResources };
@@ -1 +1 @@
1
- {"version":3,"file":"history_resources.js","sources":["../../../src/render/rendergraph/history_resources.ts"],"sourcesContent":["/**\r\n * Resource names for render graph history resources.\r\n * @public\r\n */\r\nexport const RGHistoryResources = {\r\n TAA_COLOR: 'taaColor',\r\n TAA_MOTION_VECTOR: 'taaMotionVector'\r\n} as const;\r\n"],"names":["RGHistoryResources","TAA_COLOR","TAA_MOTION_VECTOR"],"mappings":"AAAA;;;UAIaA,kBAAqB,GAAA;IAChCC,SAAW,EAAA,UAAA;IACXC,iBAAmB,EAAA;AACrB;;;;"}
1
+ {"version":3,"file":"history_resources.js","sources":["../../../src/render/rendergraph/history_resources.ts"],"sourcesContent":["/**\r\n * Resource names for render graph history resources.\r\n * @public\r\n */\r\nexport const RGHistoryResources = {\r\n TAA_COLOR: 'taaColor',\r\n TAA_MOTION_VECTOR: 'taaMotionVector',\r\n SSR_REFLECT: 'ssrReflect',\r\n SSR_MOTION_VECTOR: 'ssrMotionVector'\r\n} as const;\r\n"],"names":["RGHistoryResources","TAA_COLOR","TAA_MOTION_VECTOR","SSR_REFLECT","SSR_MOTION_VECTOR"],"mappings":"AAAA;;;UAIaA,kBAAqB,GAAA;IAChCC,SAAW,EAAA,UAAA;IACXC,iBAAmB,EAAA,iBAAA;IACnBC,WAAa,EAAA,YAAA;IACbC,iBAAmB,EAAA;AACrB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../src/render/rendergraph/types.ts"],"sourcesContent":["import type { TextureFormat } from '@zephyr3d/device';\r\n\r\n// ─── Resource Descriptors ───────────────────────────────────────────────\r\n\r\n/**\r\n * Sizing mode for render graph textures.\r\n *\r\n * - 'absolute': fixed pixel dimensions\r\n * - 'backbuffer-relative': scaled relative to the backbuffer size\r\n *\r\n * @public\r\n */\r\nexport type RGSizeMode = 'absolute' | 'backbuffer-relative';\r\n\r\n/**\r\n * Descriptor for a transient texture resource within the render graph.\r\n *\r\n * Transient textures are allocated and released automatically by the graph compiler.\r\n *\r\n * @public\r\n */\r\nexport interface RGTextureDesc {\r\n /** Debug label for this resource. */\r\n label?: string;\r\n /** Texture format (e.g. 'rgba8unorm', 'r32f', 'rgba16f'). */\r\n format: TextureFormat;\r\n /** Sizing mode. Default 'backbuffer-relative'. */\r\n sizeMode?: RGSizeMode;\r\n /** Width in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n width?: number;\r\n /** Height in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n height?: number;\r\n /** Number of mip levels. Default 1. */\r\n mipLevels?: number;\r\n}\r\n\r\n// ─── Handles ────────────────────────────────────────────────────────────\r\n\r\n/**\r\n * Opaque handle referencing a resource within the render graph.\r\n *\r\n * Handles are obtained from {@link RGPassBuilder.createTexture}, {@link RGPassBuilder.createFramebuffer},\r\n * {@link RenderGraph.importTexture}, or {@link RGPassBuilder.write}. They are lightweight identifiers\r\n * used to declare dependencies between passes.\r\n *\r\n * @public\r\n */\r\nexport class RGHandle {\r\n /** @internal */\r\n readonly _id: number;\r\n /** @internal */\r\n readonly _name: string;\r\n\r\n /** @internal */\r\n constructor(id: number, name: string) {\r\n this._id = id;\r\n this._name = name;\r\n }\r\n\r\n /** Debug-friendly name of the referenced resource. */\r\n get name(): string {\r\n return this._name;\r\n }\r\n}\r\n\r\n// ─── Internal Resource Tracking ─────────────────────────────────────────\r\n\r\n/** @public */\r\nexport type RGResourceKind = 'transient' | 'imported' | 'token' | 'framebuffer';\r\n\r\n/**\r\n * Internal bookkeeping for a resource within the render graph.\r\n * @public\r\n */\r\nexport class RGResource {\r\n readonly id: number;\r\n readonly name: string;\r\n readonly kind: RGResourceKind;\r\n readonly desc: RGTextureDesc | RGFramebufferDesc | null;\r\n /** Resource ID of the physical backing resource used by imported versions. */\r\n readonly physicalId: number;\r\n /** The pass that creates / writes this resource (null for imported until written). */\r\n producer: RGPass | null = null;\r\n /** Passes that read this resource. */\r\n readonly consumers: RGPass[] = [];\r\n\r\n constructor(\r\n id: number,\r\n name: string,\r\n kind: RGResourceKind,\r\n desc: RGTextureDesc | RGFramebufferDesc | null,\r\n physicalId = id\r\n ) {\r\n this.id = id;\r\n this.name = name;\r\n this.kind = kind;\r\n this.desc = desc;\r\n this.physicalId = physicalId;\r\n }\r\n}\r\n\r\n// ─── Internal Pass Tracking ─────────────────────────────────────────────\r\n\r\n// ─── Execution Context ──────────────────────────────────────────────\r\n\r\n/**\r\n * Context passed to pass execute callbacks during graph execution.\r\n *\r\n * Provides access to resolved GPU resources by their handles.\r\n *\r\n * @public\r\n */\r\nexport interface RGExecuteContext {\r\n /**\r\n * Resolve a handle to the actual GPU texture object.\r\n *\r\n * For transient resources, this returns the texture allocated by the executor.\r\n * For imported resources, this returns the texture registered via\r\n * {@link RenderGraphExecutor.setImportedTexture}. The handle must be declared\r\n * by the current pass with {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param handle - Handle of the resource to resolve.\r\n * @returns The resolved texture object (type depends on the allocator).\r\n */\r\n getTexture<TTexture = unknown>(handle: RGHandle): TTexture;\r\n\r\n /**\r\n * Resolve a framebuffer handle to the actual backend framebuffer object.\r\n *\r\n * The handle must be declared by the current pass with {@link RGPassBuilder.read}\r\n * or created by the same pass with {@link RGPassBuilder.createFramebuffer}.\r\n *\r\n * @param handle - Handle returned from {@link RGPassBuilder.createFramebuffer}.\r\n * @returns The resolved framebuffer object (type depends on the allocator).\r\n */\r\n getFramebuffer<TFramebuffer = unknown>(handle: RGHandle): TFramebuffer;\r\n\r\n /**\r\n * Create a temporary framebuffer managed by the graph executor.\r\n *\r\n * The framebuffer is released automatically when graph execution finishes or\r\n * aborts. Attachments may be actual backend resources or texture formats,\r\n * depending on the allocator implementation. If an attachment is an\r\n * {@link RGHandle}, the current pass must declare it with\r\n * {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object (type depends on the allocator).\r\n */\r\n createFramebuffer<TFramebuffer = unknown>(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Register a cleanup callback to run when graph execution finishes or aborts.\r\n *\r\n * Callbacks run in reverse registration order. Use this for temporary objects\r\n * created inside pass execution that are not graph resources, such as pooled\r\n * framebuffers wrapping graph-managed textures. If pass execution throws, the\r\n * executor still runs cleanup callbacks and preserves the original pass error\r\n * ahead of cleanup errors.\r\n *\r\n * @param callback - Cleanup function to invoke after execution.\r\n */\r\n deferCleanup(callback: () => void): void;\r\n}\r\n\r\n/**\r\n * Execute callback signature.\r\n *\r\n * The callback receives a context for resolving handles to GPU resources,\r\n * plus the user data returned from the setup function.\r\n *\r\n * @public\r\n */\r\nexport type RGExecuteFn<T = void> = (ctx: RGExecuteContext, data: T) => void;\r\n\r\n/**\r\n * Ordered execution step inside a render graph pass.\r\n *\r\n * Subpasses share the parent pass's resource declarations, lifetime, culling,\r\n * and access validation. They are intended to make multi-step pass bodies\r\n * explicit without splitting graph-level resource dependencies.\r\n *\r\n * @public\r\n */\r\nexport class RGSubpass<T = unknown> {\r\n readonly name: string;\r\n readonly executeFn: RGExecuteFn<T>;\r\n\r\n constructor(name: string, executeFn: RGExecuteFn<T>) {\r\n this.name = name;\r\n this.executeFn = executeFn;\r\n }\r\n}\r\n\r\n/**\r\n * Internal bookkeeping for a pass within the render graph.\r\n * @public\r\n */\r\nexport class RGPass<T = unknown> {\r\n readonly index: number;\r\n readonly name: string;\r\n /** Resources this pass reads (dependencies). */\r\n readonly reads: RGResource[] = [];\r\n /** Resources this pass creates or writes. */\r\n readonly writes: RGResource[] = [];\r\n /** Passes that must complete before this pass due to non-resource hazards. */\r\n readonly dependencies: RGPass[] = [];\r\n /** Whether this pass has side effects and must not be culled. */\r\n hasSideEffect = false;\r\n /** User data returned from the setup function. */\r\n data: T | null = null;\r\n /** Execute callback. */\r\n executeFn: RGExecuteFn<T> | null = null;\r\n /** Ordered subpasses for passes with multiple logical execution steps. */\r\n readonly subpasses: RGSubpass<T>[] = [];\r\n /** Set during compilation: true if this pass is needed. */\r\n alive = true;\r\n\r\n constructor(index: number, name: string) {\r\n this.index = index;\r\n this.name = name;\r\n }\r\n}\r\n\r\n// ─── Pass Builder ───────────────────────────────────────────────────────\r\n\r\n/**\r\n * Builder interface used within the setup callback of {@link RenderGraph.addPass}\r\n * to declare a pass's resource requirements.\r\n *\r\n * @public\r\n */\r\nexport interface RGPassBuilder {\r\n /**\r\n * Declare a read dependency on an existing resource.\r\n *\r\n * The resource must have been created by a prior pass or imported into the graph.\r\n *\r\n * @param handle - Handle of the resource to read.\r\n */\r\n read(handle: RGHandle): void;\r\n\r\n /**\r\n * Declare that this pass writes a new version of an existing resource.\r\n *\r\n * The returned handle represents the post-write version. Use it for subsequent\r\n * reads and as the graph output passed to {@link RenderGraph.compile}. Passing\r\n * an older version of the same resource to `compile()` is rejected because it\r\n * usually means the caller ignored the handle returned by `write()`. If the pass\r\n * needs the previous contents, call {@link RGPassBuilder.read} on the input handle explicitly\r\n * before writing.\r\n *\r\n * @param handle - Handle of the resource to write to.\r\n * @returns A handle referencing the newly written version.\r\n */\r\n write(handle: RGHandle): RGHandle;\r\n\r\n /**\r\n * Create a new transient texture resource that this pass will produce.\r\n *\r\n * @param desc - Texture descriptor.\r\n * @returns A handle referencing the newly created resource.\r\n */\r\n createTexture(desc: RGTextureDesc): RGHandle;\r\n\r\n /**\r\n * Create a logical dependency token produced by this pass.\r\n *\r\n * Tokens do not resolve to GPU resources and are not allocated by the executor.\r\n * They are useful for ordering passes whose dependencies are side effects rather\r\n * than texture reads/writes.\r\n *\r\n * @param name - Debug label for this token.\r\n * @returns A handle referencing the newly created token.\r\n */\r\n createToken(name?: string): RGHandle;\r\n\r\n /**\r\n * Create a graph-managed framebuffer view.\r\n *\r\n * The graph compiler infers dependencies from any attachment handles in the\r\n * descriptor. The executor creates and releases the framebuffer automatically.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns A handle referencing the framebuffer view.\r\n */\r\n createFramebuffer(desc: RGFramebufferDesc): RGHandle;\r\n\r\n /**\r\n * Mark this pass as having side effects.\r\n *\r\n * Side-effect passes are never culled by the graph compiler, regardless of\r\n * whether their outputs are consumed. Use this for GPU readback, picking,\r\n * debug overlays, etc.\r\n */\r\n sideEffect(): void;\r\n\r\n /**\r\n * Add an ordered logical subpass to this pass.\r\n *\r\n * Subpasses execute in registration order and share the parent pass's declared\r\n * reads, writes, framebuffer views, and user data. A pass may use either\r\n * subpasses or {@link RGPassBuilder.setExecute}, but not both.\r\n *\r\n * @param name - Debug label for the subpass.\r\n * @param fn - Callback invoked when this subpass executes.\r\n */\r\n addSubpass<D>(name: string, fn: RGExecuteFn<D>): void;\r\n\r\n /**\r\n * Set the execution callback for this pass.\r\n *\r\n * A pass may use either this method or {@link RGPassBuilder.addSubpass}, but not both.\r\n *\r\n * @param fn - Callback invoked during graph execution.\r\n */\r\n setExecute<D>(fn: RGExecuteFn<D>): void;\r\n}\r\n\r\n// ─── Compiled Graph ─────────────────────────────────────────────────────\r\n\r\n/**\r\n * Lifetime information for a resource within the compiled graph.\r\n *\r\n * @public\r\n */\r\nexport interface RGResourceLifetime {\r\n /** The resource. */\r\n readonly resource: RGResource;\r\n /** Index of the first pass that uses (produces or reads) this resource. */\r\n readonly firstUse: number;\r\n /** Index of the last pass that uses this resource. */\r\n readonly lastUse: number;\r\n}\r\n\r\n/**\r\n * Result of compiling a render graph.\r\n *\r\n * Contains the ordered list of passes to execute and lifetime information\r\n * for automatic resource management.\r\n *\r\n * @public\r\n */\r\nexport interface CompiledRenderGraph {\r\n /** Topologically sorted passes (only non-culled passes). */\r\n readonly orderedPasses: ReadonlyArray<RGPass>;\r\n /** Resource lifetime information keyed by resource ID. */\r\n readonly lifetimes: ReadonlyMap<number, RGResourceLifetime>;\r\n}\r\n\r\n// ─── Texture Allocator ──────────────────────────────────────────────\r\n\r\n/**\r\n * Resolved dimensions for a texture allocation.\r\n * @public\r\n */\r\nexport interface RGResolvedSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * Descriptor for a framebuffer view managed by the graph or created temporarily during pass execution.\r\n *\r\n * This is intentionally backend-agnostic: graph-managed descriptors may use\r\n * {@link RGHandle} attachments, and executor-created descriptors use resolved\r\n * resources or texture formats understood by the allocator.\r\n *\r\n * @public\r\n */\r\nexport interface RGFramebufferDesc {\r\n /** Debug label for this framebuffer. */\r\n label?: string;\r\n /** Framebuffer width. Required when attachments are formats. */\r\n width?: number;\r\n /** Framebuffer height. Required when attachments are formats. */\r\n height?: number;\r\n /** Color attachments or formats. */\r\n colorAttachments: unknown | unknown[] | null;\r\n /** Depth/stencil attachment or format. */\r\n depthAttachment?: unknown | null;\r\n /** Whether color attachments created from formats should support mipmapping. */\r\n mipmapping?: boolean;\r\n /** Framebuffer sample count. */\r\n sampleCount?: number;\r\n /** Whether to ignore depth/stencil during MSAA resolve. */\r\n ignoreDepthStencil?: boolean;\r\n /** Attachment mip level. */\r\n attachmentMipLevel?: number;\r\n /** Attachment cubemap face. */\r\n attachmentCubeface?: number;\r\n /** Attachment array layer. */\r\n attachmentLayer?: number;\r\n}\r\n\r\n/**\r\n * Interface for allocating and releasing transient textures.\r\n *\r\n * Implement this to bridge the render graph with your GPU device's resource pool.\r\n * The executor calls `allocate()` before a resource's first use and\r\n * `release()` after its last use.\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport interface RGTextureAllocator<TTexture = unknown, TFramebuffer = unknown> {\r\n /**\r\n * Allocate a transient texture matching the given descriptor and resolved size.\r\n *\r\n * @param desc - The texture descriptor from the pass builder.\r\n * @param size - The resolved pixel dimensions.\r\n * @returns The allocated texture object.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): TTexture;\r\n\r\n /**\r\n * Release a previously allocated transient texture back to the pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: TTexture): void;\r\n\r\n /**\r\n * Allocate a temporary framebuffer matching the given descriptor.\r\n *\r\n * Implementations should not auto-release this framebuffer; the graph executor\r\n * calls {@link RGTextureAllocator.releaseFramebuffer} when execution completes or aborts.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object.\r\n */\r\n allocateFramebuffer?(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Release a previously allocated temporary framebuffer.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer?(framebuffer: TFramebuffer): void;\r\n}\r\n"],"names":["RGHandle","id","name","_id","_name","RGResource","kind","desc","producer","consumers","physicalId","RGSubpass","executeFn","RGPass","index","reads","writes","dependencies","hasSideEffect","data","subpasses","alive"],"mappings":"AAoCA;AAEA;;;;;;;;AAQC,IACM,MAAMA,QAAAA,CAAAA;qBAEX,GAAqB;qBAErB,KAAuB;AAEvB,qBACA,WAAA,CAAYC,EAAU,EAAEC,IAAY,CAAE;QACpC,IAAI,CAACC,GAAG,GAAGF,EAAAA;QACX,IAAI,CAACG,KAAK,GAAGF,IAAAA;AACf;2DAGA,IAAIA,IAAe,GAAA;QACjB,OAAO,IAAI,CAACE,KAAK;AACnB;AACF;AAOA;;;AAGC,IACM,MAAMC,UAAAA,CAAAA;IACFJ,EAAW;IACXC,IAAa;IACbI,IAAqB;IACrBC,IAA+C;mFAExD,UAA4B;2FAE5BC,WAA0B,IAAK;AAC/B,2CACSC,SAAsB,GAAA,EAAE;IAEjC,WACER,CAAAA,EAAU,EACVC,IAAY,EACZI,IAAoB,EACpBC,IAA8C,EAC9CG,UAAaT,GAAAA,EAAE,CACf;QACA,IAAI,CAACA,EAAE,GAAGA,EAAAA;QACV,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACI,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACG,UAAU,GAAGA,UAAAA;AACpB;AACF;AA4EA;;;;;;;;AAQC,IACM,MAAMC,SAAAA,CAAAA;IACFT,IAAa;IACbU,SAA0B;IAEnC,WAAYV,CAAAA,IAAY,EAAEU,SAAyB,CAAE;QACnD,IAAI,CAACV,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACU,SAAS,GAAGA,SAAAA;AACnB;AACF;AAEA;;;AAGC,IACM,MAAMC,MAAAA,CAAAA;IACFC,KAAc;IACdZ,IAAa;AACtB,qDACSa,KAAsB,GAAA,EAAE;AACjC,kDACSC,MAAuB,GAAA,EAAE;AAClC,mFACSC,YAAyB,GAAA,EAAE;sEAEpCC,gBAAgB,KAAM;uDAEtBC,OAAiB,IAAK;6BAEtBP,YAAmC,IAAK;AACxC,+EACSQ,SAA4B,GAAA,EAAE;gEAEvCC,QAAQ,IAAK;IAEb,WAAYP,CAAAA,KAAa,EAAEZ,IAAY,CAAE;QACvC,IAAI,CAACY,KAAK,GAAGA,KAAAA;QACb,IAAI,CAACZ,IAAI,GAAGA,IAAAA;AACd;AACF;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/render/rendergraph/types.ts"],"sourcesContent":["import type { TextureFormat } from '@zephyr3d/device';\r\n\r\n// ─── Resource Descriptors ───────────────────────────────────────────────\r\n\r\n/**\r\n * Sizing mode for render graph textures.\r\n *\r\n * - 'absolute': fixed pixel dimensions\r\n * - 'backbuffer-relative': scaled relative to the backbuffer size\r\n *\r\n * @public\r\n */\r\nexport type RGSizeMode = 'absolute' | 'backbuffer-relative';\r\n\r\n/**\r\n * Descriptor for a transient texture resource within the render graph.\r\n *\r\n * Transient textures are allocated and released automatically by the graph compiler.\r\n *\r\n * @public\r\n */\r\nexport interface RGTextureDesc {\r\n /** Debug label for this resource. */\r\n label?: string;\r\n /** Texture format (e.g. 'rgba8unorm', 'r32f', 'rgba16f'). */\r\n format: TextureFormat;\r\n /** Sizing mode. Default 'backbuffer-relative'. */\r\n sizeMode?: RGSizeMode;\r\n /** Width in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n width?: number;\r\n /** Height in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n height?: number;\r\n /** Number of mip levels. Default 1. */\r\n mipLevels?: number;\r\n}\r\n\r\n// ─── Handles ────────────────────────────────────────────────────────────\r\n\r\n/**\r\n * Opaque handle referencing a resource within the render graph.\r\n *\r\n * Handles are obtained from {@link RGPassBuilder.createTexture}, {@link RGPassBuilder.createFramebuffer},\r\n * {@link RenderGraph.importTexture}, or {@link RGPassBuilder.write}. They are lightweight identifiers\r\n * used to declare dependencies between passes.\r\n *\r\n * @public\r\n */\r\nexport class RGHandle {\r\n /** @internal */\r\n readonly _id: number;\r\n /** @internal */\r\n readonly _name: string;\r\n\r\n /** @internal */\r\n constructor(id: number, name: string) {\r\n this._id = id;\r\n this._name = name;\r\n }\r\n\r\n /** Debug-friendly name of the referenced resource. */\r\n get name(): string {\r\n return this._name;\r\n }\r\n}\r\n\r\n// ─── Internal Resource Tracking ─────────────────────────────────────────\r\n\r\n/** @public */\r\nexport type RGResourceKind = 'transient' | 'imported' | 'token' | 'framebuffer';\r\n\r\n/**\r\n * Internal bookkeeping for a resource within the render graph.\r\n * @public\r\n */\r\nexport class RGResource {\r\n readonly id: number;\r\n readonly name: string;\r\n readonly kind: RGResourceKind;\r\n readonly desc: RGTextureDesc | RGFramebufferDesc | null;\r\n /** Resource ID of the physical backing resource used by imported versions. */\r\n readonly physicalId: number;\r\n /** The pass that creates / writes this resource (null for imported until written). */\r\n producer: RGPass | null = null;\r\n /** Passes that read this resource. */\r\n readonly consumers: RGPass[] = [];\r\n\r\n constructor(\r\n id: number,\r\n name: string,\r\n kind: RGResourceKind,\r\n desc: RGTextureDesc | RGFramebufferDesc | null,\r\n physicalId = id\r\n ) {\r\n this.id = id;\r\n this.name = name;\r\n this.kind = kind;\r\n this.desc = desc;\r\n this.physicalId = physicalId;\r\n }\r\n}\r\n\r\n// ─── Internal Pass Tracking ─────────────────────────────────────────────\r\n\r\n// ─── Execution Context ──────────────────────────────────────────────\r\n\r\n/**\r\n * Context passed to pass execute callbacks during graph execution.\r\n *\r\n * Provides access to resolved GPU resources by their handles.\r\n *\r\n * @public\r\n */\r\nexport interface RGExecuteContext {\r\n /**\r\n * Resolve a handle to the actual GPU texture object.\r\n *\r\n * For transient resources, this returns the texture allocated by the executor.\r\n * For imported resources, this returns the texture registered via\r\n * {@link RenderGraphExecutor.setImportedTexture}. The handle must be declared\r\n * by the current pass with {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param handle - Handle of the resource to resolve.\r\n * @returns The resolved texture object (type depends on the allocator).\r\n */\r\n getTexture<TTexture = unknown>(handle: RGHandle): TTexture;\r\n\r\n /**\r\n * Resolve a framebuffer handle to the actual backend framebuffer object.\r\n *\r\n * The handle must be declared by the current pass with {@link RGPassBuilder.read}\r\n * or created by the same pass with {@link RGPassBuilder.createFramebuffer}.\r\n *\r\n * @param handle - Handle returned from {@link RGPassBuilder.createFramebuffer}.\r\n * @returns The resolved framebuffer object (type depends on the allocator).\r\n */\r\n getFramebuffer<TFramebuffer = unknown>(handle: RGHandle): TFramebuffer;\r\n\r\n /**\r\n * Create a temporary framebuffer managed by the graph executor.\r\n *\r\n * The framebuffer is released automatically when graph execution finishes or\r\n * aborts. Attachments may be actual backend resources or texture formats,\r\n * depending on the allocator implementation. If an attachment is an\r\n * {@link RGHandle}, the current pass must declare it with\r\n * {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object (type depends on the allocator).\r\n */\r\n createFramebuffer<TFramebuffer = unknown>(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Register a cleanup callback to run when graph execution finishes or aborts.\r\n *\r\n * Callbacks run in reverse registration order. Use this for temporary objects\r\n * created inside pass execution that are not graph resources, such as pooled\r\n * framebuffers wrapping graph-managed textures. If pass execution throws, the\r\n * executor still runs cleanup callbacks and preserves the original pass error\r\n * ahead of cleanup errors.\r\n *\r\n * @param callback - Cleanup function to invoke after execution.\r\n */\r\n deferCleanup(callback: () => void): void;\r\n}\r\n\r\n/**\r\n * Execute callback signature.\r\n *\r\n * The callback receives a context for resolving handles to GPU resources,\r\n * plus the user data returned from the setup function.\r\n *\r\n * @public\r\n */\r\nexport type RGExecuteFn<T = void> = (ctx: RGExecuteContext, data: T) => void;\r\n\r\n/**\r\n * Ordered execution step inside a render graph pass.\r\n *\r\n * Subpasses share the parent pass's resource declarations, lifetime, culling,\r\n * and access validation. They are intended to make multi-step pass bodies\r\n * explicit without splitting graph-level resource dependencies.\r\n *\r\n * @public\r\n */\r\nexport class RGSubpass<T = unknown> {\r\n readonly name: string;\r\n readonly executeFn: RGExecuteFn<T>;\r\n\r\n constructor(name: string, executeFn: RGExecuteFn<T>) {\r\n this.name = name;\r\n this.executeFn = executeFn;\r\n }\r\n}\r\n\r\n/**\r\n * Internal bookkeeping for a pass within the render graph.\r\n * @public\r\n */\r\nexport class RGPass<T = unknown> {\r\n readonly index: number;\r\n readonly name: string;\r\n /** Resources this pass reads (dependencies). */\r\n readonly reads: RGResource[] = [];\r\n /** Resources this pass creates or writes. */\r\n readonly writes: RGResource[] = [];\r\n /** Passes that must complete before this pass due to non-resource hazards. */\r\n readonly dependencies: RGPass[] = [];\r\n /** Whether this pass has side effects and must not be culled. */\r\n hasSideEffect = false;\r\n /** User data returned from the setup function. */\r\n data: T | null = null;\r\n /** Execute callback. */\r\n executeFn: RGExecuteFn<T> | null = null;\r\n /** Ordered subpasses for passes with multiple logical execution steps. */\r\n readonly subpasses: RGSubpass<T>[] = [];\r\n /** Set during compilation: true if this pass is needed. */\r\n alive = true;\r\n\r\n constructor(index: number, name: string) {\r\n this.index = index;\r\n this.name = name;\r\n }\r\n}\r\n\r\n// ─── Pass Builder ───────────────────────────────────────────────────────\r\n\r\n/**\r\n * Builder interface used within the setup callback of {@link RenderGraph.addPass}\r\n * to declare a pass's resource requirements.\r\n *\r\n * @public\r\n */\r\nexport interface RGPassBuilder {\r\n /**\r\n * Declare a read dependency on an existing resource.\r\n *\r\n * The resource must have been created by a prior pass or imported into the graph.\r\n *\r\n * @param handle - Handle of the resource to read.\r\n */\r\n read(handle: RGHandle): void;\r\n\r\n /**\r\n * Declare that this pass writes a new version of an existing resource.\r\n *\r\n * The returned handle represents the post-write version. Use it for subsequent\r\n * reads and as the graph output passed to {@link RenderGraph.compile}. Passing\r\n * an older version of the same resource to `compile()` is rejected because it\r\n * usually means the caller ignored the handle returned by `write()`. If the pass\r\n * needs the previous contents, call {@link RGPassBuilder.read} on the input handle explicitly\r\n * before writing.\r\n *\r\n * @param handle - Handle of the resource to write to.\r\n * @returns A handle referencing the newly written version.\r\n */\r\n write(handle: RGHandle): RGHandle;\r\n\r\n /**\r\n * Create a new transient texture resource that this pass will produce.\r\n *\r\n * @param desc - Texture descriptor.\r\n * @returns A handle referencing the newly created resource.\r\n */\r\n createTexture(desc: RGTextureDesc): RGHandle;\r\n\r\n /**\r\n * Create a logical dependency token produced by this pass.\r\n *\r\n * Tokens do not resolve to GPU resources and are not allocated by the executor.\r\n * They are useful for ordering passes whose dependencies are side effects rather\r\n * than texture reads/writes.\r\n *\r\n * @param name - Debug label for this token.\r\n * @returns A handle referencing the newly created token.\r\n */\r\n createToken(name?: string): RGHandle;\r\n\r\n /**\r\n * Create a graph-managed framebuffer view.\r\n *\r\n * The graph compiler infers dependencies from any attachment handles in the\r\n * descriptor. The executor creates and releases the framebuffer automatically.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns A handle referencing the framebuffer view.\r\n */\r\n createFramebuffer(desc: RGFramebufferDesc): RGHandle;\r\n\r\n /**\r\n * Mark this pass as having side effects.\r\n *\r\n * Side-effect passes are never culled by the graph compiler, regardless of\r\n * whether their outputs are consumed. Use this for GPU readback, picking,\r\n * debug overlays, etc.\r\n */\r\n sideEffect(): void;\r\n\r\n /**\r\n * Add an ordered logical subpass to this pass.\r\n *\r\n * Subpasses execute in registration order and share the parent pass's declared\r\n * reads, writes, framebuffer views, and user data. A pass may use either\r\n * subpasses or {@link RGPassBuilder.setExecute}, but not both.\r\n *\r\n * @param name - Debug label for the subpass.\r\n * @param fn - Callback invoked when this subpass executes.\r\n */\r\n addSubpass<D>(name: string, fn: RGExecuteFn<D>): void;\r\n\r\n /**\r\n * Set the execution callback for this pass.\r\n *\r\n * A pass may use either this method or {@link RGPassBuilder.addSubpass}, but not both.\r\n *\r\n * @param fn - Callback invoked during graph execution.\r\n */\r\n setExecute<D>(fn: RGExecuteFn<D>): void;\r\n}\r\n\r\n// ─── Compiled Graph ─────────────────────────────────────────────────────\r\n\r\n/**\r\n * Lifetime information for a resource within the compiled graph.\r\n *\r\n * @public\r\n */\r\nexport interface RGResourceLifetime {\r\n /** The resource. */\r\n readonly resource: RGResource;\r\n /** Index of the first pass that uses (produces or reads) this resource. */\r\n readonly firstUse: number;\r\n /** Index of the last pass that uses this resource. */\r\n readonly lastUse: number;\r\n}\r\n\r\n/**\r\n * Result of compiling a render graph.\r\n *\r\n * Contains the ordered list of passes to execute and lifetime information\r\n * for automatic resource management.\r\n *\r\n * @public\r\n */\r\nexport interface CompiledRenderGraph {\r\n /** Topologically sorted passes (only non-culled passes). */\r\n readonly orderedPasses: ReadonlyArray<RGPass>;\r\n /** Resource lifetime information keyed by resource ID. */\r\n readonly lifetimes: ReadonlyMap<number, RGResourceLifetime>;\r\n}\r\n\r\n// ─── Texture Allocator ──────────────────────────────────────────────\r\n\r\n/**\r\n * Resolved dimensions for a texture allocation.\r\n * @public\r\n */\r\nexport interface RGResolvedSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * Descriptor for a framebuffer view managed by the graph or created temporarily during pass execution.\r\n *\r\n * This is intentionally backend-agnostic: graph-managed descriptors may use\r\n * {@link RGHandle} attachments, and executor-created descriptors use resolved\r\n * resources or texture formats understood by the allocator.\r\n *\r\n * @public\r\n */\r\nexport interface RGFramebufferDesc {\r\n /** Debug label for this framebuffer. */\r\n label?: string;\r\n /** Framebuffer width. Required when attachments are formats. */\r\n width?: number;\r\n /** Framebuffer height. Required when attachments are formats. */\r\n height?: number;\r\n /** Color attachments or formats. */\r\n colorAttachments: unknown | unknown[] | null;\r\n /** Depth/stencil attachment or format. */\r\n depthAttachment?: unknown | null;\r\n /** Whether color attachments created from formats should support mipmapping. */\r\n mipmapping?: boolean;\r\n /** Framebuffer sample count. */\r\n sampleCount?: number;\r\n /** Whether to ignore depth/stencil during MSAA resolve. */\r\n ignoreDepthStencil?: boolean;\r\n /** Attachment mip level. */\r\n attachmentMipLevel?: number;\r\n /** Attachment cubemap face. */\r\n attachmentCubeface?: number;\r\n /** Attachment array layer. */\r\n attachmentLayer?: number;\r\n}\r\n\r\n/**\r\n * Interface for allocating and releasing transient textures.\r\n *\r\n * Implement this to bridge the render graph with your GPU device's resource pool.\r\n * The executor calls `allocate()` before a resource's first use and\r\n * `release()` after its last use.\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport interface RGTextureAllocator<TTexture = unknown, TFramebuffer = unknown> {\r\n /**\r\n * Allocate a transient texture matching the given descriptor and resolved size.\r\n *\r\n * @param desc - The texture descriptor from the pass builder.\r\n * @param size - The resolved pixel dimensions.\r\n * @returns The allocated texture object.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): TTexture;\r\n\r\n /**\r\n * Release a previously allocated transient texture back to the pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: TTexture): void;\r\n\r\n /**\r\n * Retain a texture allocated by this allocator so it can outlive the graph pass\r\n * that produced it.\r\n *\r\n * This is used when a graph-produced transient texture must be handed off to\r\n * an external owner, such as a cross-frame history resource. Executors still\r\n * release the graph's own reference at the resource's last use; the external\r\n * owner must later call {@link RGTextureAllocator.release} for the retained\r\n * reference.\r\n *\r\n * Allocators that cannot retain transient textures should leave this undefined.\r\n */\r\n retain?(texture: TTexture): void;\r\n\r\n /**\r\n * Allocate a temporary framebuffer matching the given descriptor.\r\n *\r\n * Implementations should not auto-release this framebuffer; the graph executor\r\n * calls {@link RGTextureAllocator.releaseFramebuffer} when execution completes or aborts.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object.\r\n */\r\n allocateFramebuffer?(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Release a previously allocated temporary framebuffer.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer?(framebuffer: TFramebuffer): void;\r\n}\r\n"],"names":["RGHandle","id","name","_id","_name","RGResource","kind","desc","producer","consumers","physicalId","RGSubpass","executeFn","RGPass","index","reads","writes","dependencies","hasSideEffect","data","subpasses","alive"],"mappings":"AAoCA;AAEA;;;;;;;;AAQC,IACM,MAAMA,QAAAA,CAAAA;qBAEX,GAAqB;qBAErB,KAAuB;AAEvB,qBACA,WAAA,CAAYC,EAAU,EAAEC,IAAY,CAAE;QACpC,IAAI,CAACC,GAAG,GAAGF,EAAAA;QACX,IAAI,CAACG,KAAK,GAAGF,IAAAA;AACf;2DAGA,IAAIA,IAAe,GAAA;QACjB,OAAO,IAAI,CAACE,KAAK;AACnB;AACF;AAOA;;;AAGC,IACM,MAAMC,UAAAA,CAAAA;IACFJ,EAAW;IACXC,IAAa;IACbI,IAAqB;IACrBC,IAA+C;mFAExD,UAA4B;2FAE5BC,WAA0B,IAAK;AAC/B,2CACSC,SAAsB,GAAA,EAAE;IAEjC,WACER,CAAAA,EAAU,EACVC,IAAY,EACZI,IAAoB,EACpBC,IAA8C,EAC9CG,UAAaT,GAAAA,EAAE,CACf;QACA,IAAI,CAACA,EAAE,GAAGA,EAAAA;QACV,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACI,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACG,UAAU,GAAGA,UAAAA;AACpB;AACF;AA4EA;;;;;;;;AAQC,IACM,MAAMC,SAAAA,CAAAA;IACFT,IAAa;IACbU,SAA0B;IAEnC,WAAYV,CAAAA,IAAY,EAAEU,SAAyB,CAAE;QACnD,IAAI,CAACV,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACU,SAAS,GAAGA,SAAAA;AACnB;AACF;AAEA;;;AAGC,IACM,MAAMC,MAAAA,CAAAA;IACFC,KAAc;IACdZ,IAAa;AACtB,qDACSa,KAAsB,GAAA,EAAE;AACjC,kDACSC,MAAuB,GAAA,EAAE;AAClC,mFACSC,YAAyB,GAAA,EAAE;sEAEpCC,gBAAgB,KAAM;uDAEtBC,OAAiB,IAAK;6BAEtBP,YAAmC,IAAK;AACxC,+EACSQ,SAA4B,GAAA,EAAE;gEAEvCC,QAAQ,IAAK;IAEb,WAAYP,CAAAA,KAAa,EAAEZ,IAAY,CAAE;QACvC,IAAI,CAACY,KAAK,GAAGA,KAAAA;QACb,IAAI,CAACZ,IAAI,GAAGA,IAAAA;AACd;AACF;;;;"}
@@ -2,7 +2,7 @@ import { Disposable, Vector4 } from '@zephyr3d/base';
2
2
  import { CullVisitor } from './cull_visitor.js';
3
3
  import { RenderQueue } from './render_queue.js';
4
4
  import { RenderBundleWrapper } from './renderbundle_wrapper.js';
5
- import { MaterialVaryingFlags } from '../values.js';
5
+ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
6
6
  import { getDevice } from '../app/api.js';
7
7
 
8
8
  /**
@@ -90,11 +90,14 @@ import { getDevice } from '../app/api.js';
90
90
  }
91
91
  renderQueue.end(cullCamera);
92
92
  ctx.sunLight = renderQueue.sunLight;
93
+ ctx.primaryDirectionalLight = renderQueue.primaryDirectionalLight;
94
+ ctx.primaryTransmissionLight = renderQueue.primaryTransmissionLight;
93
95
  return renderQueue;
94
96
  }
95
97
  /** @internal */ internalDrawItemList(ctx, items, renderQueue, renderBundle, reverseWinding, hash) {
96
98
  let recording = false;
97
- if (renderBundle && ctx.camera.commandBufferReuse) {
99
+ const disableRenderBundles = this.shouldDisableRenderBundles(ctx);
100
+ if (renderBundle && ctx.camera.commandBufferReuse && !disableRenderBundles) {
98
101
  const bundle = renderBundle.getRenderBundle(hash);
99
102
  if (bundle) {
100
103
  ctx.device.executeRenderBundle(bundle);
@@ -112,15 +115,18 @@ import { getDevice } from '../app/api.js';
112
115
  if (recording) {
113
116
  RenderBundleWrapper.addDrawable(item.drawable, item.drawable.getMaterial()?.coreMaterial, item.drawable.getPrimitive(), renderBundle, hash);
114
117
  }
115
- item.drawable.draw(ctx, renderQueue, recording ? undefined : hash);
118
+ item.drawable.draw(ctx, renderQueue, recording || disableRenderBundles ? undefined : hash);
116
119
  if (reverse) {
117
120
  ctx.device.reverseVertexWindingOrder(!ctx.device.isWindingOrderReversed());
118
121
  }
119
122
  }
120
- if (renderBundle && ctx.camera.commandBufferReuse) {
123
+ if (renderBundle && ctx.camera.commandBufferReuse && !disableRenderBundles) {
121
124
  renderBundle.endRenderBundle(hash);
122
125
  }
123
126
  }
127
+ shouldDisableRenderBundles(ctx) {
128
+ return ctx.renderPass?.type === RENDER_PASS_TYPE_LIGHT && (!!ctx.SSS || !!ctx.currentShadowLight || !!ctx.lightBlending) || false;
129
+ }
124
130
  /** @internal */ drawItemList(itemList, ctx, reverseWinding) {
125
131
  ctx.instanceData = null;
126
132
  const windingHash = reverseWinding ? '1' : '0';
@@ -1 +1 @@
1
- {"version":3,"file":"renderpass.js","sources":["../../src/render/renderpass.ts"],"sourcesContent":["import type { Immutable, Nullable } from '@zephyr3d/base';\r\nimport { Disposable, Vector4 } from '@zephyr3d/base';\r\nimport { CullVisitor } from './cull_visitor';\r\nimport type { RenderItemListInfo, RenderQueueItem } from './render_queue';\r\nimport { RenderQueue } from './render_queue';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { DrawContext } from './drawable';\r\nimport { RenderBundleWrapper } from './renderbundle_wrapper';\r\nimport { MaterialVaryingFlags } from '../values';\r\nimport type { BindGroup } from '@zephyr3d/device';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Base class for any kind of render passes\r\n * @public\r\n */\r\nexport abstract class RenderPass extends Disposable {\r\n /** @internal */\r\n protected _type: number;\r\n /** @internal */\r\n protected _globalBindGroups: Record<string, BindGroup>;\r\n /** @internal */\r\n protected _clearColor: Nullable<Vector4>;\r\n /** @internal */\r\n protected _clearDepth: Nullable<number>;\r\n /** @internal */\r\n protected _clearStencil: Nullable<number>;\r\n /**\r\n * Creates an instanceof RenderPass\r\n * @param type - Render pass type\r\n */\r\n constructor(type: number) {\r\n super();\r\n this._type = type;\r\n this._clearColor = new Vector4(0, 0, 0, 1);\r\n this._clearDepth = 1;\r\n this._clearStencil = 0;\r\n this._globalBindGroups = {};\r\n }\r\n /** Color value that is used to clear the frame buffer */\r\n get clearColor(): Nullable<Immutable<Vector4>> {\r\n return this._clearColor;\r\n }\r\n set clearColor(color: Nullable<Immutable<Vector4>>) {\r\n this._clearColor = color;\r\n }\r\n /** Depth value that is used to clear the frame buffer */\r\n get clearDepth() {\r\n return this._clearDepth;\r\n }\r\n set clearDepth(depth) {\r\n this._clearDepth = depth;\r\n }\r\n /** Stencil value that is used to clear the frame buffer */\r\n get clearStencil() {\r\n return this._clearStencil;\r\n }\r\n set clearStencil(stencil) {\r\n this._clearStencil = stencil;\r\n }\r\n /**\r\n * The render pass type\r\n */\r\n get type() {\r\n return this._type;\r\n }\r\n /** @internal */\r\n isAutoFlip(ctx: DrawContext) {\r\n return !!(ctx.device.getFramebuffer() && ctx.device.type === 'webgpu');\r\n }\r\n /**\r\n * Renders a scene\r\n * @param ctx - Drawing context\r\n */\r\n render(\r\n ctx: DrawContext,\r\n renderCamera?: Nullable<Camera>,\r\n cullCamera?: Nullable<Camera>,\r\n renderQueue?: RenderQueue\r\n ) {\r\n ctx.renderPass = this;\r\n this.drawScene(ctx, renderCamera ?? ctx.camera, cullCamera ?? renderCamera ?? ctx.camera, renderQueue);\r\n }\r\n /** @internal */\r\n getGlobalBindGroupHash(ctx: DrawContext, camera: Camera) {\r\n return `${this.constructor.name}:${this._getGlobalBindGroupHash(ctx, camera)}`;\r\n }\r\n /** @internal */\r\n protected abstract _getGlobalBindGroupHash(ctx: DrawContext, camera: Camera): string;\r\n /** @internal */\r\n protected abstract renderItems(ctx: DrawContext, renderCamera: Camera, renderQueue: RenderQueue): void;\r\n /** @internal */\r\n protected drawScene(ctx: DrawContext, renderCamera: Camera, cullCamera: Camera, renderQueue?: RenderQueue) {\r\n const device = ctx.device;\r\n this.clearFramebuffer();\r\n const rq = renderQueue ?? this.cullScene(ctx, cullCamera);\r\n if (rq) {\r\n const windingReversed = device.isWindingOrderReversed();\r\n device.reverseVertexWindingOrder(this.isAutoFlip(ctx) ? !windingReversed : windingReversed);\r\n this.renderItems(ctx, renderCamera, rq);\r\n device.reverseVertexWindingOrder(windingReversed);\r\n if (rq !== renderQueue) {\r\n rq.dispose();\r\n }\r\n }\r\n }\r\n /**\r\n * Culls a scene by a given camera\r\n * @param ctx - The draw context\r\n * @param cullCamera - The camera that will be used to cull the scene\r\n * @returns The cull result\r\n */\r\n cullScene(ctx: DrawContext, cullCamera: Camera) {\r\n const renderQueue = new RenderQueue(this);\r\n const cullVisitor = new CullVisitor(this, cullCamera, renderQueue);\r\n if (ctx.scene.octree) {\r\n ctx.scene.octree.getRootNode().traverse(cullVisitor);\r\n } else {\r\n ctx.scene.rootNode.traverse(cullVisitor);\r\n }\r\n renderQueue.end(cullCamera);\r\n ctx.sunLight = renderQueue.sunLight;\r\n return renderQueue;\r\n }\r\n /** @internal */\r\n private internalDrawItemList(\r\n ctx: DrawContext,\r\n items: RenderQueueItem[],\r\n renderQueue: Nullable<RenderQueue>,\r\n renderBundle: Nullable<RenderBundleWrapper>,\r\n reverseWinding: boolean,\r\n hash: string\r\n ) {\r\n let recording = false;\r\n if (renderBundle && ctx.camera.commandBufferReuse) {\r\n const bundle = renderBundle.getRenderBundle(hash);\r\n if (bundle) {\r\n ctx.device.executeRenderBundle(bundle);\r\n return;\r\n }\r\n recording = true;\r\n renderBundle.beginRenderBundle();\r\n }\r\n for (const item of items) {\r\n ctx.instanceData = item.instanceData;\r\n const reverse = reverseWinding !== item.drawable.getNode().worldMatrixDet < 0;\r\n if (reverse) {\r\n ctx.device.reverseVertexWindingOrder(!ctx.device.isWindingOrderReversed());\r\n }\r\n if (recording) {\r\n RenderBundleWrapper.addDrawable(\r\n item.drawable,\r\n item.drawable.getMaterial()?.coreMaterial!,\r\n item.drawable.getPrimitive()!,\r\n renderBundle!,\r\n hash\r\n );\r\n }\r\n item.drawable.draw(ctx, renderQueue, recording ? undefined : hash);\r\n if (reverse) {\r\n ctx.device.reverseVertexWindingOrder(!ctx.device.isWindingOrderReversed());\r\n }\r\n }\r\n if (renderBundle && ctx.camera.commandBufferReuse) {\r\n renderBundle.endRenderBundle(hash);\r\n }\r\n }\r\n /** @internal */\r\n protected drawItemList(itemList: RenderItemListInfo, ctx: DrawContext, reverseWinding: boolean) {\r\n ctx.instanceData = null;\r\n const windingHash = reverseWinding ? '1' : '0';\r\n const bindGroupHash = ctx.device.getBindGroup(0)[0].getGPUId();\r\n const framebufferHash = ctx.device.getFramebuffer()?.getHash() ?? '';\r\n const ctxHash = `${ctx.sceneColorTexture?.uid ?? 0}-${ctx.linearDepthTexture?.uid ?? 0}`;\r\n const hash = `${windingHash}-${bindGroupHash}-${framebufferHash}-${ctxHash}-${ctx.renderPassHash}`;\r\n if (itemList) {\r\n if (itemList.itemList.length > 0) {\r\n ctx.materialFlags &= ~(\r\n MaterialVaryingFlags.SKIN_ANIMATION |\r\n MaterialVaryingFlags.INSTANCING |\r\n MaterialVaryingFlags.MORPH_ANIMATION\r\n );\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.itemList,\r\n itemList.renderQueue,\r\n itemList.renderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.skinItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_ANIMATION;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.MORPH_ANIMATION | MaterialVaryingFlags.INSTANCING);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.skinItemList,\r\n itemList.renderQueue,\r\n itemList.skinRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.morphItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.MORPH_ANIMATION;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.INSTANCING);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.morphItemList,\r\n itemList.renderQueue,\r\n itemList.morphRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.skinAndMorphItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.MORPH_ANIMATION;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.INSTANCING;\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.skinAndMorphItemList,\r\n itemList.renderQueue,\r\n itemList.skinAndMorphRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.instanceItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.INSTANCING;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.MORPH_ANIMATION);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.instanceItemList,\r\n itemList.renderQueue,\r\n itemList.instanceRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n }\r\n }\r\n /**\r\n * Disposes the render pass\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._globalBindGroups = {};\r\n }\r\n /** @internal */\r\n private clearFramebuffer() {\r\n if (this._clearColor || this._clearDepth || this._clearStencil) {\r\n getDevice().clearFrameBuffer(this._clearColor, this._clearDepth, this._clearStencil);\r\n }\r\n }\r\n}\r\n"],"names":["RenderPass","Disposable","type","_type","_clearColor","Vector4","_clearDepth","_clearStencil","_globalBindGroups","clearColor","color","clearDepth","depth","clearStencil","stencil","isAutoFlip","ctx","device","getFramebuffer","render","renderCamera","cullCamera","renderQueue","renderPass","drawScene","camera","getGlobalBindGroupHash","name","_getGlobalBindGroupHash","clearFramebuffer","rq","cullScene","windingReversed","isWindingOrderReversed","reverseVertexWindingOrder","renderItems","dispose","RenderQueue","cullVisitor","CullVisitor","scene","octree","getRootNode","traverse","rootNode","end","sunLight","internalDrawItemList","items","renderBundle","reverseWinding","hash","recording","commandBufferReuse","bundle","getRenderBundle","executeRenderBundle","beginRenderBundle","item","instanceData","reverse","drawable","getNode","worldMatrixDet","RenderBundleWrapper","addDrawable","getMaterial","coreMaterial","getPrimitive","draw","undefined","endRenderBundle","itemList","windingHash","bindGroupHash","getBindGroup","getGPUId","framebufferHash","getHash","ctxHash","sceneColorTexture","uid","linearDepthTexture","renderPassHash","length","materialFlags","MaterialVaryingFlags","SKIN_ANIMATION","INSTANCING","MORPH_ANIMATION","materialList","forEach","mat","apply","skinItemList","skinRenderBundle","morphItemList","morphRenderBundle","skinAndMorphItemList","skinAndMorphRenderBundle","instanceItemList","instanceRenderBundle","onDispose","getDevice","clearFrameBuffer"],"mappings":";;;;;;;AAYA;;;IAIO,MAAeA,UAAmBC,SAAAA,UAAAA,CAAAA;qBAEvC,KAAwB;qBAExB,iBAAuD;qBAEvD,WAAyC;qBAEzC,WAAwC;qBAExC,aAA0C;AAC1C;;;MAIA,WAAA,CAAYC,IAAY,CAAE;QACxB,KAAK,EAAA;QACL,IAAI,CAACC,KAAK,GAAGD,IAAAA;AACb,QAAA,IAAI,CAACE,WAAW,GAAG,IAAIC,OAAQ,CAAA,CAAA,EAAG,GAAG,CAAG,EAAA,CAAA,CAAA;QACxC,IAAI,CAACC,WAAW,GAAG,CAAA;QACnB,IAAI,CAACC,aAAa,GAAG,CAAA;QACrB,IAAI,CAACC,iBAAiB,GAAG,EAAC;AAC5B;+DAEA,IAAIC,UAA2C,GAAA;QAC7C,OAAO,IAAI,CAACL,WAAW;AACzB;IACA,IAAIK,UAAAA,CAAWC,KAAmC,EAAE;QAClD,IAAI,CAACN,WAAW,GAAGM,KAAAA;AACrB;8DAEA,IAAIC,UAAa,GAAA;QACf,OAAO,IAAI,CAACL,WAAW;AACzB;IACA,IAAIK,UAAAA,CAAWC,KAAK,EAAE;QACpB,IAAI,CAACN,WAAW,GAAGM,KAAAA;AACrB;gEAEA,IAAIC,YAAe,GAAA;QACjB,OAAO,IAAI,CAACN,aAAa;AAC3B;IACA,IAAIM,YAAAA,CAAaC,OAAO,EAAE;QACxB,IAAI,CAACP,aAAa,GAAGO,OAAAA;AACvB;AACA;;AAEC,MACD,IAAIZ,IAAO,GAAA;QACT,OAAO,IAAI,CAACC,KAAK;AACnB;qBAEAY,UAAWC,CAAAA,G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,IAAI,CAAC+B,oBAAoB,CACvB/B,GAAAA,EACAwD,SAAS0B,oBAAoB,EAC7B1B,QAASlD,CAAAA,WAAW,EACpBkD,QAAAA,CAAS2B,wBAAwB,IAAI,MACrCjD,cACAC,EAAAA,IAAAA,CAAAA;AAEJ;AACA,YAAA,IAAIqB,QAAS4B,CAAAA,gBAAgB,CAAChB,MAAM,GAAG,CAAG,EAAA;gBACxCpE,GAAIqE,CAAAA,aAAa,IAAIC,oBAAAA,CAAqBE,UAAU;gBACpDxE,GAAIqE,CAAAA,aAAa,IAAI,EAAEC,qBAAqBC,cAAc,GAAGD,oBAAqBG,CAAAA,eAAe,CAAD;gBAChGjB,QAASkB,CAAAA,YAAY,CAACC,OAAO,CAAC,CAACC,GAAQA,GAAAA,GAAAA,CAAIC,KAAK,CAAC7E,GAAAA,CAAAA,CAAAA;AACjD,gBAAA,IAAI,CAAC+B,oBAAoB,CACvB/B,GAAAA,EACAwD,SAAS4B,gBAAgB,EACzB5B,QAASlD,CAAAA,WAAW,EACpBkD,QAAAA,CAAS6B,oBAAoB,IAAI,MACjCnD,cACAC,EAAAA,IAAAA,CAAAA;AAEJ;AACF;AACF;AACA;;AAEC,MACD,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACmD,SAAAA,EAAAA;QACN,IAAI,CAAC9F,iBAAiB,GAAG,EAAC;AAC5B;qBAEA,gBAA2B,GAAA;QACzB,IAAI,IAAI,CAACJ,WAAW,IAAI,IAAI,CAACE,WAAW,IAAI,IAAI,CAACC,aAAa,EAAE;AAC9DgG,YAAAA,SAAAA,EAAAA,CAAYC,gBAAgB,CAAC,IAAI,CAACpG,WAAW,EAAE,IAAI,CAACE,WAAW,EAAE,IAAI,CAACC,aAAa,CAAA;AACrF;AACF;AACF;;;;"}
1
+ {"version":3,"file":"renderpass.js","sources":["../../src/render/renderpass.ts"],"sourcesContent":["import type { Immutable, Nullable } from '@zephyr3d/base';\r\nimport { Disposable, Vector4 } from '@zephyr3d/base';\r\nimport { CullVisitor } from './cull_visitor';\r\nimport type { RenderItemListInfo, RenderQueueItem } from './render_queue';\r\nimport { RenderQueue } from './render_queue';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { DrawContext } from './drawable';\r\nimport { RenderBundleWrapper } from './renderbundle_wrapper';\r\nimport { MaterialVaryingFlags, RENDER_PASS_TYPE_LIGHT } from '../values';\r\nimport type { BindGroup } from '@zephyr3d/device';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Base class for any kind of render passes\r\n * @public\r\n */\r\nexport abstract class RenderPass extends Disposable {\r\n /** @internal */\r\n protected _type: number;\r\n /** @internal */\r\n protected _globalBindGroups: Record<string, BindGroup>;\r\n /** @internal */\r\n protected _clearColor: Nullable<Vector4>;\r\n /** @internal */\r\n protected _clearDepth: Nullable<number>;\r\n /** @internal */\r\n protected _clearStencil: Nullable<number>;\r\n /**\r\n * Creates an instanceof RenderPass\r\n * @param type - Render pass type\r\n */\r\n constructor(type: number) {\r\n super();\r\n this._type = type;\r\n this._clearColor = new Vector4(0, 0, 0, 1);\r\n this._clearDepth = 1;\r\n this._clearStencil = 0;\r\n this._globalBindGroups = {};\r\n }\r\n /** Color value that is used to clear the frame buffer */\r\n get clearColor(): Nullable<Immutable<Vector4>> {\r\n return this._clearColor;\r\n }\r\n set clearColor(color: Nullable<Immutable<Vector4>>) {\r\n this._clearColor = color;\r\n }\r\n /** Depth value that is used to clear the frame buffer */\r\n get clearDepth() {\r\n return this._clearDepth;\r\n }\r\n set clearDepth(depth) {\r\n this._clearDepth = depth;\r\n }\r\n /** Stencil value that is used to clear the frame buffer */\r\n get clearStencil() {\r\n return this._clearStencil;\r\n }\r\n set clearStencil(stencil) {\r\n this._clearStencil = stencil;\r\n }\r\n /**\r\n * The render pass type\r\n */\r\n get type() {\r\n return this._type;\r\n }\r\n /** @internal */\r\n isAutoFlip(ctx: DrawContext) {\r\n return !!(ctx.device.getFramebuffer() && ctx.device.type === 'webgpu');\r\n }\r\n /**\r\n * Renders a scene\r\n * @param ctx - Drawing context\r\n */\r\n render(\r\n ctx: DrawContext,\r\n renderCamera?: Nullable<Camera>,\r\n cullCamera?: Nullable<Camera>,\r\n renderQueue?: RenderQueue\r\n ) {\r\n ctx.renderPass = this;\r\n this.drawScene(ctx, renderCamera ?? ctx.camera, cullCamera ?? renderCamera ?? ctx.camera, renderQueue);\r\n }\r\n /** @internal */\r\n getGlobalBindGroupHash(ctx: DrawContext, camera: Camera) {\r\n return `${this.constructor.name}:${this._getGlobalBindGroupHash(ctx, camera)}`;\r\n }\r\n /** @internal */\r\n protected abstract _getGlobalBindGroupHash(ctx: DrawContext, camera: Camera): string;\r\n /** @internal */\r\n protected abstract renderItems(ctx: DrawContext, renderCamera: Camera, renderQueue: RenderQueue): void;\r\n /** @internal */\r\n protected drawScene(ctx: DrawContext, renderCamera: Camera, cullCamera: Camera, renderQueue?: RenderQueue) {\r\n const device = ctx.device;\r\n this.clearFramebuffer();\r\n const rq = renderQueue ?? this.cullScene(ctx, cullCamera);\r\n if (rq) {\r\n const windingReversed = device.isWindingOrderReversed();\r\n device.reverseVertexWindingOrder(this.isAutoFlip(ctx) ? !windingReversed : windingReversed);\r\n this.renderItems(ctx, renderCamera, rq);\r\n device.reverseVertexWindingOrder(windingReversed);\r\n if (rq !== renderQueue) {\r\n rq.dispose();\r\n }\r\n }\r\n }\r\n /**\r\n * Culls a scene by a given camera\r\n * @param ctx - The draw context\r\n * @param cullCamera - The camera that will be used to cull the scene\r\n * @returns The cull result\r\n */\r\n cullScene(ctx: DrawContext, cullCamera: Camera) {\r\n const renderQueue = new RenderQueue(this);\r\n const cullVisitor = new CullVisitor(this, cullCamera, renderQueue);\r\n if (ctx.scene.octree) {\r\n ctx.scene.octree.getRootNode().traverse(cullVisitor);\r\n } else {\r\n ctx.scene.rootNode.traverse(cullVisitor);\r\n }\r\n renderQueue.end(cullCamera);\r\n ctx.sunLight = renderQueue.sunLight;\r\n ctx.primaryDirectionalLight = renderQueue.primaryDirectionalLight;\r\n ctx.primaryTransmissionLight = renderQueue.primaryTransmissionLight;\r\n return renderQueue;\r\n }\r\n /** @internal */\r\n private internalDrawItemList(\r\n ctx: DrawContext,\r\n items: RenderQueueItem[],\r\n renderQueue: Nullable<RenderQueue>,\r\n renderBundle: Nullable<RenderBundleWrapper>,\r\n reverseWinding: boolean,\r\n hash: string\r\n ) {\r\n let recording = false;\r\n const disableRenderBundles = this.shouldDisableRenderBundles(ctx);\r\n if (renderBundle && ctx.camera.commandBufferReuse && !disableRenderBundles) {\r\n const bundle = renderBundle.getRenderBundle(hash);\r\n if (bundle) {\r\n ctx.device.executeRenderBundle(bundle);\r\n return;\r\n }\r\n recording = true;\r\n renderBundle.beginRenderBundle();\r\n }\r\n for (const item of items) {\r\n ctx.instanceData = item.instanceData;\r\n const reverse = reverseWinding !== item.drawable.getNode().worldMatrixDet < 0;\r\n if (reverse) {\r\n ctx.device.reverseVertexWindingOrder(!ctx.device.isWindingOrderReversed());\r\n }\r\n if (recording) {\r\n RenderBundleWrapper.addDrawable(\r\n item.drawable,\r\n item.drawable.getMaterial()?.coreMaterial!,\r\n item.drawable.getPrimitive()!,\r\n renderBundle!,\r\n hash\r\n );\r\n }\r\n item.drawable.draw(ctx, renderQueue, recording || disableRenderBundles ? undefined : hash);\r\n if (reverse) {\r\n ctx.device.reverseVertexWindingOrder(!ctx.device.isWindingOrderReversed());\r\n }\r\n }\r\n if (renderBundle && ctx.camera.commandBufferReuse && !disableRenderBundles) {\r\n renderBundle.endRenderBundle(hash);\r\n }\r\n }\r\n private shouldDisableRenderBundles(ctx: DrawContext) {\r\n return (\r\n (ctx.renderPass?.type === RENDER_PASS_TYPE_LIGHT &&\r\n (!!ctx.SSS || !!ctx.currentShadowLight || !!ctx.lightBlending)) ||\r\n false\r\n );\r\n }\r\n /** @internal */\r\n protected drawItemList(itemList: RenderItemListInfo, ctx: DrawContext, reverseWinding: boolean) {\r\n ctx.instanceData = null;\r\n const windingHash = reverseWinding ? '1' : '0';\r\n const bindGroupHash = ctx.device.getBindGroup(0)[0].getGPUId();\r\n const framebufferHash = ctx.device.getFramebuffer()?.getHash() ?? '';\r\n const ctxHash = `${ctx.sceneColorTexture?.uid ?? 0}-${ctx.linearDepthTexture?.uid ?? 0}`;\r\n const hash = `${windingHash}-${bindGroupHash}-${framebufferHash}-${ctxHash}-${ctx.renderPassHash}`;\r\n if (itemList) {\r\n if (itemList.itemList.length > 0) {\r\n ctx.materialFlags &= ~(\r\n MaterialVaryingFlags.SKIN_ANIMATION |\r\n MaterialVaryingFlags.INSTANCING |\r\n MaterialVaryingFlags.MORPH_ANIMATION\r\n );\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.itemList,\r\n itemList.renderQueue,\r\n itemList.renderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.skinItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_ANIMATION;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.MORPH_ANIMATION | MaterialVaryingFlags.INSTANCING);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.skinItemList,\r\n itemList.renderQueue,\r\n itemList.skinRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.morphItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.MORPH_ANIMATION;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.INSTANCING);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.morphItemList,\r\n itemList.renderQueue,\r\n itemList.morphRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.skinAndMorphItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.MORPH_ANIMATION;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.INSTANCING;\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.skinAndMorphItemList,\r\n itemList.renderQueue,\r\n itemList.skinAndMorphRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n if (itemList.instanceItemList.length > 0) {\r\n ctx.materialFlags |= MaterialVaryingFlags.INSTANCING;\r\n ctx.materialFlags &= ~(MaterialVaryingFlags.SKIN_ANIMATION | MaterialVaryingFlags.MORPH_ANIMATION);\r\n itemList.materialList.forEach((mat) => mat.apply(ctx));\r\n this.internalDrawItemList(\r\n ctx,\r\n itemList.instanceItemList,\r\n itemList.renderQueue,\r\n itemList.instanceRenderBundle ?? null,\r\n reverseWinding,\r\n hash\r\n );\r\n }\r\n }\r\n }\r\n /**\r\n * Disposes the render pass\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._globalBindGroups = {};\r\n }\r\n /** @internal */\r\n private clearFramebuffer() {\r\n if (this._clearColor || this._clearDepth || this._clearStencil) {\r\n getDevice().clearFrameBuffer(this._clearColor, this._clearDepth, this._clearStencil);\r\n }\r\n }\r\n}\r\n"],"names":["RenderPass","Disposable","type","_type","_clearColor","Vector4","_clearDepth","_clearStencil","_globalBindGroups","clearColor","color","clearDepth","depth","clearStencil","stencil","isAutoFlip","ctx","device","getFramebuffer","render","renderCamera","cullCamera","renderQueue","renderPass","drawScene","camera","getGlobalBindGroupHash","name","_getGlobalBindGroupHash","clearFramebuffer","rq","cullScene","windingReversed","isWindingOrderReversed","reverseVertexWindingOrder","renderItems","dispose","RenderQueue","cullVisitor","CullVisitor","scene","octree","getRootNode","traverse","rootNode","end","sunLight","primaryDirectionalLight","primaryTransmissionLight","internalDrawItemList","items","renderBundle","reverseWinding","hash","recording","disableRenderBundles","shouldDisableRenderBundles","commandBufferReuse","bundle","getRenderBundle","executeRenderBundle","beginRenderBundle","item","instanceData","reverse","drawable","getNode","worldMatrixDet","RenderBundleWrapper","addDrawable","getMaterial","coreMaterial","getPrimitive","draw","undefined","endRenderBundle","RENDER_PASS_TYPE_LIGHT","SSS","currentShadowLight","lightBlending","itemList","windingHash","bindGroupHash","getBindGroup","getGPUId","framebufferHash","getHash","ctxHash","sceneColorTexture","uid","linearDepthTexture","renderPassHash","length","materialFlags","MaterialVaryingFlags","SKIN_ANIMATION","INSTANCING","MORPH_ANIMATION","materialList","forEach","mat","apply","skinItemList","skinRenderBundle","morphItemList","morphRenderBundle","skinAndMorphItemList","skinAndMorphRenderBundle","instanceItemList","instanceRenderBundle","onDispose","getDevice","clearFrameBuffer"],"mappings":";;;;;;;AAYA;;;IAIO,MAAeA,UAAmBC,SAAAA,UAAAA,CAAAA;qBAEvC,KAAwB;qBAExB,iBAAuD;qBAEvD,WAAyC;qBAEzC,WAAwC;qBAExC,aAA0C;AAC1C;;;MAIA,WAAA,CAAYC,IAAY,CAAE;QACxB,KAAK,EAAA;QACL,IAAI,CAACC,KAAK,GAAGD,IAAAA;AACb,QAAA,IAAI,CAACE,WAAW,GAAG,IAAIC,OAAQ,CAAA,CAAA,EAAG,GAAG,CAAG,EAAA,CAAA,CAAA;QACxC,IAAI,CAACC,WAAW,GAAG,CAAA;QACnB,IAAI,CAACC,aAAa,GAAG,CAAA;QACrB,IAAI,CAACC,iBAAiB,GAAG,EAAC;AAC5B;+DAEA,IAAIC,UAA2C,GAAA;QAC7C,OAAO,IAAI,CAACL,WAAW;AACzB;IACA,IAAIK,UAAAA,CAAWC,KAAmC,EAAE;QAClD,IAAI,CAACN,WAAW,GAAGM,KAAAA;AACrB;8DAEA,IAAIC,UAAa,GAAA;QACf,OAAO,IAAI,CAACL,WAAW;AACzB;IACA,IAAIK,UAAAA,CAAWC,KAAK,EAAE;QACpB,IAAI,CAACN,WAAW,GAAGM,KAAAA;AACrB;gEAEA,IAAIC,YAAe,GAAA;QACjB,OAAO,IAAI,CAACN,aAAa;AAC3B;IACA,IAAIM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AAS4B,gBAAgB,EACzB5B,QAAS1D,CAAAA,WAAW,EACpB0D,QAAAA,CAAS6B,oBAAoB,IAAI,MACjCzD,cACAC,EAAAA,IAAAA,CAAAA;AAEJ;AACF;AACF;AACA;;AAEC,MACD,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACyD,SAAAA,EAAAA;QACN,IAAI,CAACtG,iBAAiB,GAAG,EAAC;AAC5B;qBAEA,gBAA2B,GAAA;QACzB,IAAI,IAAI,CAACJ,WAAW,IAAI,IAAI,CAACE,WAAW,IAAI,IAAI,CAACC,aAAa,EAAE;AAC9DwG,YAAAA,SAAAA,EAAAA,CAAYC,gBAAgB,CAAC,IAAI,CAAC5G,WAAW,EAAE,IAAI,CAACE,WAAW,EAAE,IAAI,CAACC,aAAa,CAAA;AACrF;AACF;AACF;;;;"}
@@ -693,13 +693,43 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
693
693
  device.pool.releaseFrameBuffer(fogFramebuffer);
694
694
  }
695
695
  }
696
+ /** @internal */ _beginSingleColorPass(withDepth) {
697
+ const device = getDevice();
698
+ const currentFramebuffer = device.getFramebuffer();
699
+ const colorBuffer = currentFramebuffer?.getColorAttachments()[0] ?? null;
700
+ const depthBuffer = withDepth ? currentFramebuffer?.getDepthAttachment() ?? null : null;
701
+ if (!currentFramebuffer || currentFramebuffer.getColorAttachments().length <= 1 || !colorBuffer) {
702
+ return null;
703
+ }
704
+ const framebuffer = device.pool.fetchTemporalFramebuffer(false, 0, 0, colorBuffer, depthBuffer, false);
705
+ const vp = device.getViewport();
706
+ const scissor = device.getScissor();
707
+ device.pushDeviceStates();
708
+ device.setFramebuffer(framebuffer);
709
+ device.setViewport(vp);
710
+ device.setScissor(scissor);
711
+ return framebuffer;
712
+ }
713
+ /** @internal */ _endSingleColorPass(framebuffer) {
714
+ if (!framebuffer) {
715
+ return;
716
+ }
717
+ const device = getDevice();
718
+ device.popDeviceStates();
719
+ device.pool.releaseFrameBuffer(framebuffer);
720
+ }
696
721
  /** @internal */ renderSky(ctx) {
697
722
  let skyCamera = ctx.camera;
698
723
  if (!skyCamera.isPerspective()) {
699
724
  skyCamera = SkyRenderer._skyCamera;
700
725
  ctx.camera.worldMatrix.decompose(null, skyCamera.rotation, null);
701
726
  }
702
- this._renderSky(skyCamera, true);
727
+ const framebuffer = this._beginSingleColorPass(true);
728
+ try {
729
+ this._renderSky(skyCamera, true);
730
+ } finally{
731
+ this._endSingleColorPass(framebuffer);
732
+ }
703
733
  }
704
734
  /** Disposes resources of this SkyRenderer */ onDispose() {
705
735
  super.onDispose();