@zephyr3d/scene 0.9.22 → 0.9.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/joint_dynamics/collision.js +1 -7
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +2 -17
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +2 -20
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +1 -3
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +14 -60
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +3 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/app/app.js +23 -0
- package/dist/app/app.js.map +1 -1
- package/dist/app/scriptregistry.js +16 -53
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -0
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +22 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +3 -1
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/blitter.js +3 -3
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/camera/camera.js +398 -45
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/perspectivecamera.js +69 -2
- package/dist/camera/perspectivecamera.js.map +1 -1
- package/dist/index.d.ts +9113 -8740
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +3 -3
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +8 -5
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +17 -10
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +1 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +21 -6
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +33 -11
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/brdf.js +44 -12
- package/dist/material/mixins/pbr/brdf.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +149 -14
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mtoon.js +7 -4
- package/dist/material/mtoon.js.map +1 -1
- package/dist/material/pbrblueprint.js +5 -1
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +1 -1
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +512 -334
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/skin.js +2 -2
- package/dist/material/skin.js.map +1 -1
- package/dist/material/terrain-cm.js +5 -5
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/material/water.js +6 -4
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/bloom.js +54 -4
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +41 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/posteffect.js +35 -0
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +7 -6
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/skinsss.js +3 -3
- package/dist/posteffect/skinsss.js.map +1 -1
- package/dist/posteffect/ssgi.js +988 -436
- package/dist/posteffect/ssgi.js.map +1 -1
- package/dist/posteffect/ssr.js +83 -45
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +18 -15
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +5 -4
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/posteffect/tonemap.js +15 -3
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/render/abuffer_oit.js +2 -2
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +22 -16
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable_mixin.js +8 -5
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +10 -5
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/envlight.js +298 -5
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/gpu_picking.js +7 -5
- package/dist/render/gpu_picking.js.map +1 -1
- package/dist/render/hzb.js +28 -19
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +18 -4
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +37 -4
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +8 -3
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +20 -48
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +18 -58
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +89 -115
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +1003 -715
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +1 -1
- package/dist/render/rendergraph/frame_graph_context.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +14 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -0
- package/dist/render/rendergraph/history_resource_manager.js +74 -140
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +7 -5
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/render_context.js +19 -0
- package/dist/render/rendergraph/render_context.js.map +1 -0
- package/dist/render/rendergraph/render_pipeline.js +315 -0
- package/dist/render/rendergraph/render_pipeline.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +158 -141
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/scene_render_context.js +267 -0
- package/dist/render/rendergraph/scene_render_context.js.map +1 -0
- package/dist/render/rendergraph/texture_affinity_cache.js +19 -0
- package/dist/render/rendergraph/texture_affinity_cache.js.map +1 -0
- package/dist/render/rendergraph/types.js +19 -31
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +3 -3
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadow_mask_pass.js +7 -6
- package/dist/render/shadow_mask_pass.js.map +1 -1
- package/dist/render/sky.js +257 -95
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +4 -3
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +2 -0
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +10 -0
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +61 -2
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +178 -10
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/meshdrawable.js +89 -2
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +2 -0
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +2 -0
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +2 -0
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +34 -1
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +2 -1
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +2 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +2 -0
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/atmosphere.js +5 -4
- package/dist/shaders/atmosphere.js.map +1 -1
- package/dist/shaders/fog.js +10 -3
- package/dist/shaders/fog.js.map +1 -1
- package/dist/shaders/shadow.js +149 -40
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssgi_reprojection.js +118 -0
- package/dist/shaders/ssgi_reprojection.js.map +1 -0
- package/dist/shaders/ssr.js +322 -154
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shadow/esm.js +10 -7
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +12 -12
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +12 -12
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +16 -11
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadow_impl.js +29 -3
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +5 -2
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +13 -13
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +7 -7
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/physical.js +74 -0
- package/dist/utility/physical.js.map +1 -0
- package/dist/utility/rendermipmap.js +2 -2
- package/dist/utility/rendermipmap.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +3 -1
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +3 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +598 -2
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +180 -9
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +43 -3
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +3 -1
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +3 -1
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +3 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +2 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +70 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +3 -1
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +3 -1
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -0
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +3 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/values.js +59 -65
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sources":["../../src/render/renderer.ts"],"sourcesContent":["import { CopyBlitter } from '../blitter';\r\nimport type { DrawContext } from './drawable';\r\nimport type { Scene } from '../scene';\r\nimport type { Camera } from '../camera';\r\nimport { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { getDevice } from '../app/api';\r\nimport { executeForwardPlusGraph } from './rendergraph/forward_plus_builder';\r\n\r\n/**\r\n * Forward render scheme\r\n * @internal\r\n */\r\nexport class SceneRenderer {\r\n /**\r\n * Renders a scene by given camera\r\n * @param scene - The scene to render\r\n * @param camera - The camera that will be used to render the scene\r\n */\r\n static renderScene(scene: Scene, camera: Camera): void {\r\n const device = getDevice();\r\n const halfFloatColorBuffer = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer;\r\n const colorFormat = camera.HDR && halfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n const depthFormat = device.getDeviceCaps().framebufferCaps.supportDepth32floatStencil8\r\n ? 'd32fs8'\r\n : 'd24s8';\r\n const globalBindGroupAllocator = GlobalBindGroupAllocator.get();\r\n scene.frameUpdate();\r\n scene.frameUpdatePerCamera(camera);\r\n if (camera && !device.isContextLost()) {\r\n const defaultViewport = (!camera.TAA || device.type === 'webgl') && !camera.viewport && !camera.scissor;\r\n const renderX = camera.viewport ? device.screenXToDevice(camera.viewport[0]) : 0;\r\n const renderY = camera.viewport ? device.screenYToDevice(camera.viewport[1]) : 0;\r\n const renderWidth = camera.viewport\r\n ? device.screenXToDevice(camera.viewport[2])\r\n : device.getDrawingBufferWidth();\r\n const renderHeight = camera.viewport\r\n ? device.screenYToDevice(camera.viewport[3])\r\n : device.getDrawingBufferHeight();\r\n if (renderWidth > 0 && renderHeight > 0) {\r\n const tmpFramebuffer = defaultViewport\r\n ? null\r\n : device.pool.fetchTemporalFramebuffer(false, renderWidth, renderHeight, colorFormat, depthFormat);\r\n const originFramebuffer = device.getFramebuffer();\r\n if (tmpFramebuffer) {\r\n device.pushDeviceStates();\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n device.clearFrameBuffer(camera.clearColor, camera.clearDepth, camera.clearStencil);\r\n const SSR = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const SSS = camera.SSS;\r\n const ctx: DrawContext = {\r\n device,\r\n scene,\r\n renderWidth,\r\n renderHeight,\r\n oit: null,\r\n motionVectors:\r\n device.type !== 'webgl' && (camera.TAA || camera.motionBlur || (SSR && camera.ssrTemporal)),\r\n HiZ: camera.HiZ && device.type !== 'webgl',\r\n HiZTexture: null,\r\n // WebGL1 has no 2D array textures; degrade gracefully to the legacy\r\n // per-light additive shadow path (mirrors the HiZ gating above).\r\n screenSpaceShadowMask: camera.screenSpaceShadowMask && device.type !== 'webgl',\r\n globalBindGroupAllocator,\r\n camera,\r\n compositor: camera.compositor,\r\n queue: 0,\r\n lightBlending: false,\r\n renderPass: null,\r\n renderPassHash: null,\r\n flip: false,\r\n depthFormat,\r\n colorFormat,\r\n drawEnvLight: false,\r\n env: null,\r\n sunLight: null,\r\n primaryDirectionalLight: null,\r\n primaryTransmissionLight: null,\r\n materialFlags: 0,\r\n SSR,\r\n SSS,\r\n SSRCalcThickness: SSR && camera.ssrCalcThickness,\r\n // SSR roughness/normal MRT textures are render graph resources\r\n // created by the LightPass; resolved into these fields at execution.\r\n SSRRoughnessTexture: null,\r\n SSRNormalTexture: null,\r\n SSSProfileTexture: null,\r\n SSSParamTexture: null,\r\n SSSDiffuseTexture: null,\r\n SSSTransmissionTexture: null,\r\n SkinSSSTexture: null,\r\n ssrSDFBoxBuffer: null,\r\n ssrSDFBoxCount: 0,\r\n finalFramebuffer: device.getFramebuffer(),\r\n intermediateFramebuffer: null\r\n };\r\n this._renderScene(ctx);\r\n if (tmpFramebuffer) {\r\n device.popDeviceStates();\r\n const oversizedViewport =\r\n renderX < 0 ||\r\n renderY < 0 ||\r\n renderX + renderWidth > device.getDrawingBufferWidth() ||\r\n renderY + renderHeight > device.getDrawingBufferHeight();\r\n const blitter = new CopyBlitter();\r\n if (oversizedViewport) {\r\n blitter.destRect = [renderX, renderY, renderWidth, renderHeight];\r\n } else {\r\n blitter.viewport = camera.viewport ? camera.viewport.slice() : null;\r\n }\r\n blitter.scissor = camera.scissor ? camera.scissor.slice() : null;\r\n blitter.srgbOut = !originFramebuffer;\r\n blitter.blit(\r\n tmpFramebuffer.getColorAttachments()[0],\r\n originFramebuffer ?? null,\r\n fetchSampler('clamp_nearest_nomip')\r\n );\r\n device.pool.releaseFrameBuffer(tmpFramebuffer);\r\n }\r\n } else {\r\n camera.getPickResultResolveFunc()?.(null);\r\n return;\r\n }\r\n }\r\n GlobalBindGroupAllocator.release(globalBindGroupAllocator);\r\n }\r\n\r\n /** @internal */\r\n protected static _renderScene(ctx: DrawContext): void {\r\n executeForwardPlusGraph(ctx);\r\n }\r\n}\r\n"],"names":["SceneRenderer","renderScene","scene","camera","device","getDevice","halfFloatColorBuffer","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","colorFormat","HDR","depthFormat","framebufferCaps","supportDepth32floatStencil8","globalBindGroupAllocator","GlobalBindGroupAllocator","get","frameUpdate","frameUpdatePerCamera","isContextLost","defaultViewport","TAA","type","viewport","scissor","renderX","screenXToDevice","renderY","screenYToDevice","renderWidth","getDrawingBufferWidth","renderHeight","getDrawingBufferHeight","tmpFramebuffer","pool","fetchTemporalFramebuffer","originFramebuffer","getFramebuffer","pushDeviceStates","setFramebuffer","clearFrameBuffer","clearColor","clearDepth","clearStencil","SSR","env","light","envLight","hasRadiance","SSS","ctx","oit","motionVectors","motionBlur","ssrTemporal","HiZ","HiZTexture","screenSpaceShadowMask","compositor","queue","lightBlending","renderPass","renderPassHash","flip","drawEnvLight","sunLight","primaryDirectionalLight","primaryTransmissionLight","materialFlags","SSRCalcThickness","ssrCalcThickness","SSRRoughnessTexture","SSRNormalTexture","SSSProfileTexture","SSSParamTexture","SSSDiffuseTexture","SSSTransmissionTexture","SkinSSSTexture","ssrSDFBoxBuffer","ssrSDFBoxCount","finalFramebuffer","intermediateFramebuffer","_renderScene","popDeviceStates","oversizedViewport","blitter","CopyBlitter","destRect","slice","srgbOut","blit","getColorAttachments","fetchSampler","releaseFrameBuffer","getPickResultResolveFunc","release","executeForwardPlusGraph"],"mappings":";;;;;;;;;AASA;;;AAGC,IACM,MAAMA,aAAAA,CAAAA;AACX;;;;AAIC,MACD,OAAOC,WAAAA,CAAYC,KAAY,EAAEC,MAAc,EAAQ;AACrD,QAAA,MAAMC,MAASC,GA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
1
|
+
{"version":3,"file":"renderer.js","sources":["../../src/render/renderer.ts"],"sourcesContent":["import { CopyBlitter } from '../blitter';\r\nimport type { DrawContext } from './drawable';\r\nimport type { Scene } from '../scene';\r\nimport type { Camera } from '../camera';\r\nimport { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { getDevice } from '../app/api';\r\nimport { executeForwardPlusGraph } from './rendergraph/forward_plus_builder';\r\n\r\n/**\r\n * Forward render scheme\r\n * @internal\r\n */\r\nexport class SceneRenderer {\r\n /**\r\n * Renders a scene by given camera\r\n * @param scene - The scene to render\r\n * @param camera - The camera that will be used to render the scene\r\n */\r\n static renderScene(scene: Scene, camera: Camera): void {\r\n const device = getDevice();\r\n const halfFloatColorBuffer = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer;\r\n const colorFormat = camera.HDR && halfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n const depthFormat = device.getDeviceCaps().framebufferCaps.supportDepth32floatStencil8\r\n ? 'd32fs8'\r\n : 'd24s8';\r\n const globalBindGroupAllocator = GlobalBindGroupAllocator.get();\r\n scene.frameUpdate();\r\n scene.frameUpdatePerCamera(camera);\r\n if (camera && !device.isContextLost()) {\r\n const defaultViewport = (!camera.TAA || device.type === 'webgl') && !camera.viewport && !camera.scissor;\r\n const renderX = camera.viewport ? device.screenXToDevice(camera.viewport[0]) : 0;\r\n const renderY = camera.viewport ? device.screenYToDevice(camera.viewport[1]) : 0;\r\n const renderWidth = camera.viewport\r\n ? device.screenXToDevice(camera.viewport[2])\r\n : device.getDrawingBufferWidth();\r\n const renderHeight = camera.viewport\r\n ? device.screenYToDevice(camera.viewport[3])\r\n : device.getDrawingBufferHeight();\r\n if (renderWidth > 0 && renderHeight > 0) {\r\n const tmpFramebuffer = defaultViewport\r\n ? null\r\n : device.pool.fetchTemporalFramebuffer(false, renderWidth, renderHeight, colorFormat, depthFormat);\r\n const originFramebuffer = device.getFramebuffer();\r\n if (tmpFramebuffer) {\r\n device.pushDeviceStates();\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n device.clearFrameBuffer(camera.clearColor, camera.clearDepth, camera.clearStencil);\r\n const SSR = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const SSGI =\r\n camera.SSGI &&\r\n camera.HDR &&\r\n camera.ssgiIntensity > 0 &&\r\n scene.env.light.type === 'ibl' &&\r\n !!scene.env.light.envLight?.hasRadiance() &&\r\n !!scene.env.light.envLight?.hasIrradiance();\r\n const SSS = camera.SSS;\r\n const ctx: DrawContext = {\r\n device,\r\n scene,\r\n renderWidth,\r\n renderHeight,\r\n oit: null,\r\n motionVectors:\r\n device.type !== 'webgl' && (camera.TAA || camera.motionBlur || (SSR && camera.ssrTemporal)),\r\n HiZ: camera.HiZ && device.type !== 'webgl',\r\n HiZTexture: null,\r\n // WebGL1 has no 2D array textures; degrade gracefully to the legacy\r\n // per-light additive shadow path (mirrors the HiZ gating above).\r\n screenSpaceShadowMask: camera.screenSpaceShadowMask && device.type !== 'webgl',\r\n globalBindGroupAllocator,\r\n camera,\r\n compositor: camera.compositor,\r\n queue: 0,\r\n lightBlending: false,\r\n renderPass: null,\r\n renderPassHash: null,\r\n shaderVariantHash: null,\r\n flip: false,\r\n depthFormat,\r\n colorFormat,\r\n drawEnvLight: false,\r\n env: null,\r\n sunLight: null,\r\n primaryDirectionalLight: null,\r\n primaryTransmissionLight: null,\r\n materialFlags: 0,\r\n SSR,\r\n SSGI,\r\n SSGIIrradianceHistoryTexture: null,\r\n SSGISurfaceHistoryTexture: null,\r\n SSS,\r\n SSRCalcThickness: SSR && camera.ssrCalcThickness,\r\n // Surface roughness/normal MRT textures are render graph resources\r\n // created by the LightPass; resolved into these fields at execution.\r\n SceneRoughnessTexture: null,\r\n SceneNormalTexture: null,\r\n SSSProfileTexture: null,\r\n SSSParamTexture: null,\r\n SSSDiffuseTexture: null,\r\n SSSTransmissionTexture: null,\r\n SkinSSSTexture: null,\r\n ssrSDFBoxBuffer: null,\r\n ssrSDFBoxCount: 0,\r\n finalFramebuffer: device.getFramebuffer(),\r\n intermediateFramebuffer: null\r\n };\r\n this._renderScene(ctx);\r\n if (tmpFramebuffer) {\r\n device.popDeviceStates();\r\n const oversizedViewport =\r\n renderX < 0 ||\r\n renderY < 0 ||\r\n renderX + renderWidth > device.getDrawingBufferWidth() ||\r\n renderY + renderHeight > device.getDrawingBufferHeight();\r\n const blitter = new CopyBlitter();\r\n if (oversizedViewport) {\r\n blitter.destRect = [renderX, renderY, renderWidth, renderHeight];\r\n } else {\r\n blitter.viewport = camera.viewport ? camera.viewport.slice() : null;\r\n }\r\n blitter.scissor = camera.scissor ? camera.scissor.slice() : null;\r\n blitter.srgbOut = !originFramebuffer;\r\n blitter.blit(\r\n tmpFramebuffer.getColorAttachments()[0],\r\n originFramebuffer ?? null,\r\n fetchSampler('clamp_nearest_nomip')\r\n );\r\n device.pool.releaseFrameBuffer(tmpFramebuffer);\r\n }\r\n } else {\r\n camera.getPickResultResolveFunc()?.(null);\r\n return;\r\n }\r\n }\r\n GlobalBindGroupAllocator.release(globalBindGroupAllocator);\r\n }\r\n\r\n /** @internal */\r\n protected static _renderScene(ctx: DrawContext): void {\r\n executeForwardPlusGraph(ctx);\r\n }\r\n}\r\n"],"names":["SceneRenderer","renderScene","scene","camera","device","getDevice","halfFloatColorBuffer","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","colorFormat","HDR","depthFormat","framebufferCaps","supportDepth32floatStencil8","globalBindGroupAllocator","GlobalBindGroupAllocator","get","frameUpdate","frameUpdatePerCamera","isContextLost","defaultViewport","TAA","type","viewport","scissor","renderX","screenXToDevice","renderY","screenYToDevice","renderWidth","getDrawingBufferWidth","renderHeight","getDrawingBufferHeight","tmpFramebuffer","pool","fetchTemporalFramebuffer","originFramebuffer","getFramebuffer","pushDeviceStates","setFramebuffer","clearFrameBuffer","clearColor","clearDepth","clearStencil","SSR","env","light","envLight","hasRadiance","SSGI","ssgiIntensity","hasIrradiance","SSS","ctx","oit","motionVectors","motionBlur","ssrTemporal","HiZ","HiZTexture","screenSpaceShadowMask","compositor","queue","lightBlending","renderPass","renderPassHash","shaderVariantHash","flip","drawEnvLight","sunLight","primaryDirectionalLight","primaryTransmissionLight","materialFlags","SSGIIrradianceHistoryTexture","SSGISurfaceHistoryTexture","SSRCalcThickness","ssrCalcThickness","SceneRoughnessTexture","SceneNormalTexture","SSSProfileTexture","SSSParamTexture","SSSDiffuseTexture","SSSTransmissionTexture","SkinSSSTexture","ssrSDFBoxBuffer","ssrSDFBoxCount","finalFramebuffer","intermediateFramebuffer","_renderScene","popDeviceStates","oversizedViewport","blitter","CopyBlitter","destRect","slice","srgbOut","blit","getColorAttachments","fetchSampler","releaseFrameBuffer","getPickResultResolveFunc","release","executeForwardPlusGraph"],"mappings":";;;;;;;;;AASA;;;AAGC,IACM,MAAMA,aAAAA,CAAAA;AACX;;;;AAIC,MACD,OAAOC,WAAAA,CAAYC,KAAY,EAAEC,MAAc,EAAQ;AACrD,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;AACf,QAAA,MAAMC,uBAAuBF,MAAOG,CAAAA,aAAa,EAAGC,CAAAA,WAAW,CAACC,2BAA2B;AAC3F,QAAA,MAAMC,WAAcP,GAAAA,MAAAA,CAAOQ,GAAG,IAAIL,uBAAuB,SAAY,GAAA,YAAA;QACrE,MAAMM,WAAAA,GAAcR,OAAOG,aAAa,EAAA,CAAGM,eAAe,CAACC,2BAA2B,GAClF,QACA,GAAA,OAAA;QACJ,MAAMC,wBAAAA,GAA2BC,yBAAyBC,GAAG,EAAA;AAC7Df,QAAAA,KAAAA,CAAMgB,WAAW,EAAA;AACjBhB,QAAAA,KAAAA,CAAMiB,oBAAoB,CAAChB,MAAAA,CAAAA;AAC3B,QAAA,IAAIA,MAAU,IAAA,CAACC,MAAOgB,CAAAA,aAAa,EAAI,EAAA;AACrC,YAAA,MAAMC,kBAAkB,CAAC,CAAClB,MAAO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
*
|
|
4
|
-
* Producer passes register their output handles under these names so that
|
|
5
|
-
* consumers (e.g. post effects) can declare reads without hard-coupling to
|
|
6
|
-
* the pass that produced them.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/ const FrameResources = {
|
|
1
|
+
/** Well-known frame resource names shared through {@link RGBlackboard}. @public */ const FrameResources = {
|
|
10
2
|
SceneColor: 'sceneColor',
|
|
11
3
|
SceneColorCopy: 'sceneColorCopy',
|
|
4
|
+
/**
|
|
5
|
+
* Opaque scene color with sky but before height fog is composited.
|
|
6
|
+
*
|
|
7
|
+
* Screen-space passes read this as the outgoing radiance of a traced hit. Fog
|
|
8
|
+
* along the camera-to-hit ray is unrelated to the shading-point-to-hit path
|
|
9
|
+
* those passes integrate, and sampling it would both tint hits with the fog
|
|
10
|
+
* color and feed back into the next frame. Only published when fog is present
|
|
11
|
+
* and a consumer needs it.
|
|
12
|
+
*/ SceneColorNoFog: 'sceneColorNoFog',
|
|
12
13
|
LinearDepth: 'linearDepth',
|
|
13
14
|
SceneDepthAttachment: 'sceneDepthAttachment',
|
|
14
15
|
MotionVector: 'motionVector',
|
|
15
16
|
HiZ: 'hiZ',
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
SceneRoughness: 'sceneRoughness',
|
|
18
|
+
SceneNormal: 'sceneNormal',
|
|
18
19
|
SSSProfile: 'sssProfile',
|
|
19
20
|
SSSParam: 'sssParam',
|
|
20
21
|
SSSDiffuse: 'sssDiffuse',
|
|
21
22
|
SSSTransmission: 'sssTransmission',
|
|
22
23
|
SkinSSS: 'skinSSS',
|
|
23
|
-
ShadowMask: 'shadowMask'
|
|
24
|
+
ShadowMask: 'shadowMask',
|
|
25
|
+
/** Final presented color. The last registration becomes the graph sink. */ PresentedColor: 'presentedColor'
|
|
24
26
|
};
|
|
25
|
-
/**
|
|
26
|
-
* Named registry of render graph resource handles for the current frame.
|
|
27
|
-
*
|
|
28
|
-
* The blackboard decouples resource producers from consumers: passes that
|
|
29
|
-
* create shared resources register the returned handles by name, and later
|
|
30
|
-
* passes look them up to declare read dependencies. This replaces passing
|
|
31
|
-
* textures through mutable `DrawContext` fields.
|
|
32
|
-
*
|
|
33
|
-
* A blackboard instance is valid for a single graph build; create a new one
|
|
34
|
-
* (or clear it) every frame together with the graph.
|
|
35
|
-
*
|
|
36
|
-
* @public
|
|
37
|
-
*/ class RGBlackboard {
|
|
27
|
+
/** Per-frame registry of named render graph resources. @public */ class RGBlackboard {
|
|
38
28
|
/** @internal */ _handles = new Map();
|
|
39
|
-
/**
|
|
40
|
-
* Register a resource handle under a name, replacing any previous entry.
|
|
41
|
-
* @param name - Resource name, typically one of {@link FrameResources}.
|
|
42
|
-
* @param handle - The handle to register.
|
|
43
|
-
*/ set(name, handle) {
|
|
29
|
+
/** Register or replace a resource handle. */ set(name, handle) {
|
|
44
30
|
this._handles.set(name, handle);
|
|
45
31
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Look up a resource handle by name.
|
|
48
|
-
* @param name - Resource name, typically one of {@link FrameResources}.
|
|
49
|
-
* @returns The registered handle, or null if not present this frame.
|
|
50
|
-
*/ get(name) {
|
|
32
|
+
/** Return a resource handle, or null when absent. */ get(name) {
|
|
51
33
|
return this._handles.get(name) ?? null;
|
|
52
34
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Check whether a resource is registered.
|
|
55
|
-
* @param name - Resource name.
|
|
56
|
-
* @returns true if a handle is registered under the name.
|
|
57
|
-
*/ has(name) {
|
|
35
|
+
/** Check whether a resource is registered. */ has(name) {
|
|
58
36
|
return this._handles.has(name);
|
|
59
37
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Look up a resource handle that must exist.
|
|
62
|
-
* @param name - Resource name.
|
|
63
|
-
* @returns The registered handle.
|
|
64
|
-
*/ expect(name) {
|
|
38
|
+
/** Return a required resource handle. */ expect(name) {
|
|
65
39
|
const handle = this._handles.get(name);
|
|
66
40
|
if (!handle) {
|
|
67
41
|
throw new Error(`RGBlackboard: required frame resource "${name}" was not registered`);
|
|
68
42
|
}
|
|
69
43
|
return handle;
|
|
70
44
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Remove all registered handles.
|
|
73
|
-
*/ clear() {
|
|
45
|
+
/** Remove all registered handles. */ clear() {
|
|
74
46
|
this._handles.clear();
|
|
75
47
|
}
|
|
76
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blackboard.js","sources":["../../../src/render/rendergraph/blackboard.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport type { RGHandle } from './types';\r\n\r\n
|
|
1
|
+
{"version":3,"file":"blackboard.js","sources":["../../../src/render/rendergraph/blackboard.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport type { RGHandle, RGTextureHandle } from './types';\r\n\r\n/** Typed key used to publish a frame resource. @public */\r\nexport type FrameResourceKey<THandle extends RGHandle = RGHandle> = string & {\r\n readonly __frameResourceHandle: THandle;\r\n};\r\n\r\ntype FrameResourceMap = {\r\n readonly SceneColor: FrameResourceKey<RGTextureHandle>;\r\n readonly SceneColorCopy: FrameResourceKey<RGTextureHandle>;\r\n readonly SceneColorNoFog: FrameResourceKey<RGTextureHandle>;\r\n readonly LinearDepth: FrameResourceKey<RGTextureHandle>;\r\n readonly SceneDepthAttachment: FrameResourceKey<RGTextureHandle>;\r\n readonly MotionVector: FrameResourceKey<RGTextureHandle>;\r\n readonly HiZ: FrameResourceKey<RGTextureHandle>;\r\n readonly SceneRoughness: FrameResourceKey<RGTextureHandle>;\r\n readonly SceneNormal: FrameResourceKey<RGTextureHandle>;\r\n readonly SSSProfile: FrameResourceKey<RGTextureHandle>;\r\n readonly SSSParam: FrameResourceKey<RGTextureHandle>;\r\n readonly SSSDiffuse: FrameResourceKey<RGTextureHandle>;\r\n readonly SSSTransmission: FrameResourceKey<RGTextureHandle>;\r\n readonly SkinSSS: FrameResourceKey<RGTextureHandle>;\r\n readonly ShadowMask: FrameResourceKey<RGTextureHandle>;\r\n readonly PresentedColor: FrameResourceKey<RGTextureHandle>;\r\n};\r\n\r\n/** Well-known frame resource names shared through {@link RGBlackboard}. @public */\r\nexport const FrameResources = {\r\n SceneColor: 'sceneColor',\r\n SceneColorCopy: 'sceneColorCopy',\r\n /**\r\n * Opaque scene color with sky but before height fog is composited.\r\n *\r\n * Screen-space passes read this as the outgoing radiance of a traced hit. Fog\r\n * along the camera-to-hit ray is unrelated to the shading-point-to-hit path\r\n * those passes integrate, and sampling it would both tint hits with the fog\r\n * color and feed back into the next frame. Only published when fog is present\r\n * and a consumer needs it.\r\n */\r\n SceneColorNoFog: 'sceneColorNoFog',\r\n LinearDepth: 'linearDepth',\r\n SceneDepthAttachment: 'sceneDepthAttachment',\r\n MotionVector: 'motionVector',\r\n HiZ: 'hiZ',\r\n SceneRoughness: 'sceneRoughness',\r\n SceneNormal: 'sceneNormal',\r\n SSSProfile: 'sssProfile',\r\n SSSParam: 'sssParam',\r\n SSSDiffuse: 'sssDiffuse',\r\n SSSTransmission: 'sssTransmission',\r\n SkinSSS: 'skinSSS',\r\n ShadowMask: 'shadowMask',\r\n /** Final presented color. The last registration becomes the graph sink. */\r\n PresentedColor: 'presentedColor'\r\n} as unknown as FrameResourceMap;\r\n\r\n/** Per-frame registry of named render graph resources. @public */\r\nexport class RGBlackboard {\r\n /** @internal */\r\n private _handles: Map<string, RGHandle> = new Map();\r\n /** Register or replace a resource handle. */\r\n set<THandle extends RGHandle>(name: FrameResourceKey<THandle>, handle: THandle): void {\r\n this._handles.set(name, handle);\r\n }\r\n /** Return a resource handle, or null when absent. */\r\n get<THandle extends RGHandle = RGHandle>(name: FrameResourceKey<THandle>): Nullable<THandle> {\r\n return (this._handles.get(name) as THandle | undefined) ?? null;\r\n }\r\n /** Check whether a resource is registered. */\r\n has(name: FrameResourceKey): boolean {\r\n return this._handles.has(name);\r\n }\r\n /** Return a required resource handle. */\r\n expect<THandle extends RGHandle = RGHandle>(name: FrameResourceKey<THandle>): THandle {\r\n const handle = this._handles.get(name);\r\n if (!handle) {\r\n throw new Error(`RGBlackboard: required frame resource \"${name}\" was not registered`);\r\n }\r\n return handle as THandle;\r\n }\r\n /** Remove all registered handles. */\r\n clear(): void {\r\n this._handles.clear();\r\n }\r\n}\r\n"],"names":["FrameResources","SceneColor","SceneColorCopy","SceneColorNoFog","LinearDepth","SceneDepthAttachment","MotionVector","HiZ","SceneRoughness","SceneNormal","SSSProfile","SSSParam","SSSDiffuse","SSSTransmission","SkinSSS","ShadowMask","PresentedColor","RGBlackboard","_handles","Map","set","name","handle","get","has","expect","Error","clear"],"mappings":"AA2BA,oFACO,MAAMA,cAAiB,GAAA;IAC5BC,UAAY,EAAA,YAAA;IACZC,cAAgB,EAAA,gBAAA;AAChB;;;;;;;;AAQC,MACDC,eAAiB,EAAA,iBAAA;IACjBC,WAAa,EAAA,aAAA;IACbC,oBAAsB,EAAA,sBAAA;IACtBC,YAAc,EAAA,cAAA;IACdC,GAAK,EAAA,KAAA;IACLC,cAAgB,EAAA,gBAAA;IAChBC,WAAa,EAAA,aAAA;IACbC,UAAY,EAAA,YAAA;IACZC,QAAU,EAAA,UAAA;IACVC,UAAY,EAAA,YAAA;IACZC,eAAiB,EAAA,iBAAA;IACjBC,OAAS,EAAA,SAAA;IACTC,UAAY,EAAA,YAAA;AACZ,gFACAC,cAAgB,EAAA;AAClB;AAEA,mEACO,MAAMC,YAAAA,CAAAA;AACX,qBACQC,QAAkC,GAAA,IAAIC,GAAM,EAAA;AACpD,kDACAC,GAAAA,CAA8BC,IAA+B,EAAEC,MAAe,EAAQ;AACpF,QAAA,IAAI,CAACJ,QAAQ,CAACE,GAAG,CAACC,IAAMC,EAAAA,MAAAA,CAAAA;AAC1B;0DAEAC,GAAyCF,CAAAA,IAA+B,EAAqB;AAC3F,QAAA,OAAO,IAAK,CAACH,QAAQ,CAACK,GAAG,CAACF,IAAiC,CAAA,IAAA,IAAA;AAC7D;mDAEAG,GAAIH,CAAAA,IAAsB,EAAW;AACnC,QAAA,OAAO,IAAI,CAACH,QAAQ,CAACM,GAAG,CAACH,IAAAA,CAAAA;AAC3B;8CAEAI,MAA4CJ,CAAAA,IAA+B,EAAW;AACpF,QAAA,MAAMC,SAAS,IAAI,CAACJ,QAAQ,CAACK,GAAG,CAACF,IAAAA,CAAAA;AACjC,QAAA,IAAI,CAACC,MAAQ,EAAA;AACX,YAAA,MAAM,IAAII,KAAM,CAAA,CAAC,uCAAuC,EAAEL,IAAAA,CAAK,oBAAoB,CAAC,CAAA;AACtF;QACA,OAAOC,MAAAA;AACT;AACA,0CACAK,KAAc,GAAA;QACZ,IAAI,CAACT,QAAQ,CAACS,KAAK,EAAA;AACrB;AACF;;;;"}
|
|
@@ -1,75 +1,39 @@
|
|
|
1
1
|
import { getDevice } from '../../app/api.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Bridges the render graph's {@link RGTextureAllocator} interface to the
|
|
5
|
-
* engine's device resource pool (`device.pool`).
|
|
6
|
-
*
|
|
7
|
-
* Transient textures are fetched from the pool on `allocate()` and
|
|
8
|
-
* returned to the pool on `release()`, enabling automatic reuse
|
|
9
|
-
* across frames without manual lifecycle management.
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* ```ts
|
|
13
|
-
* const allocator = new DevicePoolAllocator();
|
|
14
|
-
* const executor = new RenderGraphExecutor(allocator, width, height);
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/ class DevicePoolAllocator {
|
|
3
|
+
/** Render graph allocator backed by the device resource pool. @public */ class DevicePoolAllocator {
|
|
19
4
|
_device;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new instance of the DevicePoolAllocator.
|
|
22
|
-
* @param device - Optional device instance to use for resource allocation. If not provided, the global device will be used.
|
|
23
|
-
*/ constructor(device){
|
|
5
|
+
/** Create an allocator using the given device or the global device. */ constructor(device){
|
|
24
6
|
this._device = device ?? null;
|
|
25
7
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Allocate a transient texture from the device pool.
|
|
28
|
-
*
|
|
29
|
-
* @param desc - Texture descriptor from the render graph pass.
|
|
30
|
-
* @param size - Resolved pixel dimensions.
|
|
31
|
-
* @returns A pooled Texture2D instance.
|
|
32
|
-
*/ allocate(desc, size) {
|
|
8
|
+
/** Allocate a transient texture from the device pool. */ allocate(desc, size, preferred) {
|
|
33
9
|
const device = this._device ?? getDevice();
|
|
34
|
-
const
|
|
10
|
+
const requestedMips = desc.mipLevels ?? 1;
|
|
11
|
+
// The pool allocates either one mip or a full chain.
|
|
12
|
+
if (requestedMips > 1) {
|
|
13
|
+
const maxMips = Math.max(1, Math.floor(Math.log2(Math.max(1, size.width, size.height))) + 1);
|
|
14
|
+
if (requestedMips > maxMips) {
|
|
15
|
+
throw new Error(`DevicePoolAllocator: texture "${desc.label ?? '<unnamed>'}" requested ${requestedMips} ` + `mip levels, but a ${size.width}x${size.height} texture supports at most ${maxMips}.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const mipmapping = requestedMips > 1;
|
|
35
19
|
const arrayLayers = desc.arrayLayers;
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
// not interchangeable when bound to a tex2DArray sampler. Array textures are
|
|
39
|
-
// fetched as Texture2DArray. The render graph's TTexture channel is nominally
|
|
40
|
-
// Texture2D (see forward_plus_builder's executor annotation); TS types are
|
|
41
|
-
// erased at runtime, every pool op below accepts BaseTexture, so the cast is
|
|
42
|
-
// safe. Passes resolve the real type via getTexture<Texture2DArray>().
|
|
43
|
-
// Individual layers are targeted through RGFramebufferDesc.attachmentLayer.
|
|
44
|
-
const texture = arrayLayers !== undefined ? device.pool.fetchTemporalTexture2DArray(false, desc.format, size.width, size.height, arrayLayers, mipmapping) : device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping);
|
|
20
|
+
// Any defined arrayLayers value requests Texture2DArray, including 1.
|
|
21
|
+
const texture = arrayLayers !== undefined ? device.pool.fetchTemporalTexture2DArray(false, desc.format, size.width, size.height, arrayLayers, mipmapping, preferred) : device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping, preferred);
|
|
45
22
|
if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {
|
|
46
23
|
device.pool.releaseTexture(texture);
|
|
47
24
|
throw new Error(`DevicePoolAllocator: texture "${desc.label ?? '<unnamed>'}" requested ${desc.mipLevels} ` + `mip levels, but only ${texture.mipLevelCount} were allocated.`);
|
|
48
25
|
}
|
|
49
26
|
return texture;
|
|
50
27
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Release a transient texture back to the device pool.
|
|
53
|
-
*
|
|
54
|
-
* @param texture - The texture to release.
|
|
55
|
-
*/ release(texture) {
|
|
28
|
+
/** Release a transient texture to the pool. */ release(texture) {
|
|
56
29
|
const device = this._device ?? getDevice();
|
|
57
30
|
device.pool.releaseTexture(texture);
|
|
58
31
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Retain a pooled texture so it can be owned outside the graph lifetime.
|
|
61
|
-
*
|
|
62
|
-
* @param texture - The texture to retain.
|
|
63
|
-
*/ retain(texture) {
|
|
32
|
+
/** Retain a pooled texture beyond graph execution. */ retain(texture) {
|
|
64
33
|
const device = this._device ?? getDevice();
|
|
65
34
|
device.pool.retainTexture(texture);
|
|
66
35
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Allocate a temporary framebuffer from the device pool.
|
|
69
|
-
*
|
|
70
|
-
* @param desc - Framebuffer descriptor from the render graph pass.
|
|
71
|
-
* @returns A pooled FrameBuffer instance.
|
|
72
|
-
*/ allocateFramebuffer(desc) {
|
|
36
|
+
/** Allocate a temporary framebuffer from the pool. */ allocateFramebuffer(desc) {
|
|
73
37
|
const device = this._device ?? getDevice();
|
|
74
38
|
const colors = Array.isArray(desc.colorAttachments) ? desc.colorAttachments : desc.colorAttachments ? [
|
|
75
39
|
desc.colorAttachments
|
|
@@ -77,11 +41,7 @@ import { getDevice } from '../../app/api.js';
|
|
|
77
41
|
const depthAttachment = desc.depthAttachment ?? null;
|
|
78
42
|
return device.pool.fetchTemporalFramebuffer(false, desc.width ?? 0, desc.height ?? 0, colors, depthAttachment, desc.mipmapping ?? false, desc.sampleCount ?? 1, desc.ignoreDepthStencil ?? true, desc.attachmentMipLevel ?? 0, desc.attachmentCubeface ?? 0, desc.attachmentLayer ?? 0);
|
|
79
43
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Release a temporary framebuffer back to the device pool.
|
|
82
|
-
*
|
|
83
|
-
* @param framebuffer - The framebuffer to release.
|
|
84
|
-
*/ releaseFramebuffer(framebuffer) {
|
|
44
|
+
/** Release a temporary framebuffer to the pool. */ releaseFramebuffer(framebuffer) {
|
|
85
45
|
const device = this._device ?? getDevice();
|
|
86
46
|
device.pool.releaseFrameBuffer(framebuffer);
|
|
87
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, TextureFormat, AbstractDevice } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\nimport type { Nullable } from '@zephyr3d/base';\r\n\r\n
|
|
1
|
+
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, Texture2DArray, TextureFormat, AbstractDevice } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\nimport type { Nullable } from '@zephyr3d/base';\r\n\r\n/** Render graph allocator backed by the device resource pool. @public */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D, FrameBuffer> {\r\n private _device: Nullable<AbstractDevice>;\r\n /** Create an allocator using the given device or the global device. */\r\n constructor(device?: AbstractDevice) {\r\n this._device = device ?? null;\r\n }\r\n /** Allocate a transient texture from the device pool. */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize, preferred?: Texture2D): Texture2D {\r\n const device = this._device ?? getDevice();\r\n const requestedMips = desc.mipLevels ?? 1;\r\n // The pool allocates either one mip or a full chain.\r\n if (requestedMips > 1) {\r\n const maxMips = Math.max(1, Math.floor(Math.log2(Math.max(1, size.width, size.height))) + 1);\r\n if (requestedMips > maxMips) {\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${requestedMips} ` +\r\n `mip levels, but a ${size.width}x${size.height} texture supports at most ${maxMips}.`\r\n );\r\n }\r\n }\r\n const mipmapping = requestedMips > 1;\r\n const arrayLayers = desc.arrayLayers;\r\n // Any defined arrayLayers value requests Texture2DArray, including 1.\r\n const texture =\r\n arrayLayers !== undefined\r\n ? (device.pool.fetchTemporalTexture2DArray(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n arrayLayers,\r\n mipmapping,\r\n preferred as unknown as Texture2DArray\r\n ) as unknown as Texture2D)\r\n : device.pool.fetchTemporalTexture2D(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n mipmapping,\r\n preferred\r\n );\r\n if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {\r\n device.pool.releaseTexture(texture);\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${desc.mipLevels} ` +\r\n `mip levels, but only ${texture.mipLevelCount} were allocated.`\r\n );\r\n }\r\n return texture;\r\n }\r\n\r\n /** Release a transient texture to the pool. */\r\n release(texture: Texture2D): void {\r\n const device = this._device ?? getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n\r\n /** Retain a pooled texture beyond graph execution. */\r\n retain(texture: Texture2D): void {\r\n const device = this._device ?? getDevice();\r\n device.pool.retainTexture(texture);\r\n }\r\n\r\n /** Allocate a temporary framebuffer from the pool. */\r\n allocateFramebuffer(desc: RGFramebufferDesc): FrameBuffer {\r\n const device = this._device ?? getDevice();\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? (desc.colorAttachments as Array<Texture2D | TextureFormat>)\r\n : desc.colorAttachments\r\n ? [desc.colorAttachments as Texture2D | TextureFormat]\r\n : [];\r\n const depthAttachment = (desc.depthAttachment ?? null) as Texture2D | TextureFormat | null;\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n desc.width ?? 0,\r\n desc.height ?? 0,\r\n colors,\r\n depthAttachment,\r\n desc.mipmapping ?? false,\r\n desc.sampleCount ?? 1,\r\n desc.ignoreDepthStencil ?? true,\r\n desc.attachmentMipLevel ?? 0,\r\n desc.attachmentCubeface ?? 0,\r\n desc.attachmentLayer ?? 0\r\n );\r\n }\r\n\r\n /** Release a temporary framebuffer to the pool. */\r\n releaseFramebuffer(framebuffer: FrameBuffer): void {\r\n const device = this._device ?? getDevice();\r\n device.pool.releaseFrameBuffer(framebuffer);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","_device","device","allocate","desc","size","preferred","getDevice","requestedMips","mipLevels","maxMips","Math","max","floor","log2","width","height","Error","label","mipmapping","arrayLayers","texture","undefined","pool","fetchTemporalTexture2DArray","format","fetchTemporalTexture2D","mipLevelCount","releaseTexture","release","retain","retainTexture","allocateFramebuffer","colors","Array","isArray","colorAttachments","depthAttachment","fetchTemporalFramebuffer","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","releaseFramebuffer","framebuffer","releaseFrameBuffer"],"mappings":";;AAKA,0EACO,MAAMA,mBAAAA,CAAAA;IACHC,OAAkC;4EAE1C,WAAYC,CAAAA,MAAuB,CAAE;QACnC,IAAI,CAACD,OAAO,GAAGC,MAAU,IAAA,IAAA;AAC3B;AACA,8DACAC,QAASC,CAAAA,IAAmB,EAAEC,IAAoB,EAAEC,SAAqB,EAAa;AACpF,QAAA,MAAMJ,MAAS,GAAA,IAAI,CAACD,OAAO,IAAIM,SAAAA,EAAAA;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