From 6d43fe5a7d161554f7018749d7773fd52b758bfd Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sat, 25 Apr 2026 15:57:46 +0800 Subject: [PATCH] Wire URP render pass finish callback --- ...nderingPipeline_CloseoutPlan_2026-04-24.md | 35 ++++++++++--------- .../Rendering/Universal/ScriptableRenderer.cs | 27 +++++++++++++- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/docs/plan/URP_RenderingPipeline_CloseoutPlan_2026-04-24.md b/docs/plan/URP_RenderingPipeline_CloseoutPlan_2026-04-24.md index 55101dd8..ba6f6777 100644 --- a/docs/plan/URP_RenderingPipeline_CloseoutPlan_2026-04-24.md +++ b/docs/plan/URP_RenderingPipeline_CloseoutPlan_2026-04-24.md @@ -4,13 +4,13 @@ Date: 2026-04-24 ## Progress -Current plan completion: 11%. +Current plan completion: 12%. ```text -[##------------------] 11% +[##------------------] 12% ``` -Last updated: 2026-04-25 15:49. +Last updated: 2026-04-25 15:55. Progress definition: @@ -33,7 +33,7 @@ Phase completion snapshot: | Phase 1: Native Pipeline and CameraFramePlan Closeout | open | 10% | | Phase 2: RenderGraph Productionization | in progress | 12% | | Phase 3: Managed SRP Core Closeout | in progress | 15% | -| Phase 4: Managed Universal Renderer Closeout | in progress | 15% | +| Phase 4: Managed Universal Renderer Closeout | in progress | 16% | | Phase 5: Native Builtin Passes as URP Backend Pieces | open | 5% | | Phase 6: ShaderLibrary Foundation | in progress | 10% | | Phase 7: Shader Import, Dependencies, and Compile Pipeline | in progress | 16% | @@ -43,7 +43,7 @@ Phase completion snapshot: | Phase 11: RendererFeature Assetization and Editor Workflow | open | 0% | | Phase 12: Post-Processing and Final Color | open | 0% | | Phase 13: Editor and Tooling Rendering | open | 0% | -| Phase 14: Testing Strategy | in progress | 10% | +| Phase 14: Testing Strategy | in progress | 11% | | Phase 15: Migration Order | open | 5% | Current basis: @@ -92,16 +92,16 @@ Plan maintenance rules: ## Execution Status -Last updated: 2026-04-25 15:49. +Last updated: 2026-04-25 15:55. -Current plan completion: 11%. +Current plan completion: 12%. Current position: - Fresh audit restart remains active. Treat this section as the current source of truth; older build/smoke notes are only supporting evidence, not acceptance for the active workspace. -- Executor validation at 2026-04-25 15:49 caught the editor validation up after adding the managed `RenderGraph`/`ContextContainer` API shape and `ScriptableRenderPass.RecordRenderGraph(RenderGraph, ContextContainer)` dispatch shim: `shader_tests` passed, `XCEngine` rebuilt, `XCUIEditorApp` rebuilt, `xcengine_project_managed_assemblies` rebuilt, a 12s `XCUIEditor.exe` smoke passed against the rebuilt managed assemblies, a screenshot was visually reviewed, red-dominant ratio was measured, and `runtime.log`/`crash.log` were timestamp-filtered. Unrelated dirty `new_editor/` refactor files were temporarily isolated again so the URP batch was validated against the clean editor baseline. The previous 15:07, 15:25, and 15:31 runs remain valid historical evidence; the current accepted gate is the 15:47 run. +- Executor validation at 2026-04-25 15:55 caught the editor validation up after wiring `OnFinishCameraStackRendering(...)` into the managed renderer recording path: `shader_tests` passed, `XCEngine` rebuilt, `XCUIEditorApp` rebuilt, `xcengine_project_managed_assemblies` rebuilt, a 12s `XCUIEditor.exe` smoke passed against the rebuilt managed assemblies, a screenshot was visually reviewed, red-dominant ratio was measured, and `runtime.log`/`crash.log` were timestamp-filtered. Unrelated dirty `new_editor/` refactor files were temporarily isolated again so the URP batch was validated against the clean editor baseline. The previous 15:07, 15:25, 15:31, and 15:47 runs remain valid historical evidence; the current accepted gate is the 15:54 run. - Separate reviewer is currently unavailable; the executor is maintaining this plan directly from verified evidence. Do not touch unrelated `new_editor/` changes for this URP increment; commit/push only verified scoped batches. -- Current scoped executor diff is managed RenderGraph API parity only: `managed/CMakeLists.txt`, `managed/XCEngine.ScriptCore/Rendering/Core/ContextItem.cs`, `managed/XCEngine.ScriptCore/Rendering/Core/ContextContainer.cs`, `managed/XCEngine.ScriptCore/Rendering/Graph/RenderGraph.cs`, `managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderPass.cs`, `managed/GameScripts/ScriptableRenderContextApiSurfaceProbe.cs`, `managed/GameScripts/RenderPipelineApiProbe.cs`, and this plan. +- Current scoped executor diff is managed renderer lifecycle parity only: `managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderer.cs` and this plan. - `new_editor/` has separate executor changes and is intentionally not audited or modified by this reviewer pass. - Current package work is still a low-level ShaderLibrary/dependency-resolution restart only. Builtin runtime shader entry points must stay untouched until the dependency/compile parity work is accepted. - Current resolver/test progress: `ResolveBuiltinShaderPackageDependencyPath()` rejects `Packages/../...` traversal, dependency collection is recursive, missing package includes return an error string, backslash package includes are normalized, absolute includes are rejected, `AssetDatabase::ImportShaderAsset()` propagates dependency errors into the last error message, `BuildConcretePass()` expands package includes before `ShaderStageVariant::sourceCode` reaches runtime/compiler paths, and package resolution now prefers the engine source-root anchor before fallback anchors. The latest `shader_tests` run covers expanded stage source, D3D12 bytecode generation, current-directory shadow package-root rejection for existing package files, current-path fallback for package files absent from source-root, all current public package include files, AssetDatabase failed-import diagnostics, searched-anchor diagnostics, include-chain diagnostics, stale package dependency records forcing shader reimport, and an end-to-end valid package file edit producing a distinct valid shader artifact through `AssetDatabase::EnsureArtifact()` without hand-editing artifact DB rows. @@ -113,12 +113,12 @@ Current active blockers: - Commit/push gate: the user allowed verified batch commits/pushes on 2026-04-25; only commit scoped, tested URP files and keep unrelated `new_editor/` workspace changes out of these commits. - Runtime safety gate: do not migrate builtin runtime shader entry points, pass templates, depth/shadow/forward/final-color shaders, or ABI bindings until the low-risk resolver/test work is accepted first. - Unity API parity gate: public C#/native-facing rendering APIs must intentionally mirror Unity SRP/URP naming, lifecycle, and extension seams before they are accepted. Official Unity URP 17.0.4 docs show `ScriptableRendererFeature : ScriptableObject, IDisposable`, `Create()`/`AddRenderPasses(ScriptableRenderer, ref RenderingData)` as abstract entry points, `SetupRenderPasses(ScriptableRenderer, in RenderingData)`, `SetActive(bool)`, public `Dispose()` plus protected `Dispose(bool)`, and `OnCameraPreCull(...)`. The local `ScriptableRendererFeature` instead uses virtual `Create()`, by-value `AddRenderPasses(...)`, a writable `isActive` property, and an internal release pattern. Official `ScriptableRenderPass` exposes public settable `renderPassEvent`, `input`, `passName`, `profilingSampler`, `requiresIntermediateTexture`, `ConfigureInput(...)`, `OnCameraCleanup(...)`, and public virtual `RecordRenderGraph(RenderGraph, ContextContainer)`; the local pass instead uses an engine-specific protected `bool RecordRenderGraph(ScriptableRenderContext, RenderingData)`. `RenderPassEvent` is also not a cosmetic mismatch: the local enum omits Unity events such as `BeforeRendering`, GBuffer/deferred hooks, and `AfterRendering`, adds engine-specific `RenderOpaques`/`RenderSkybox`/`RenderTransparents`/final-output events, and uses local numeric ordering while `ScriptableRenderer.EnqueuePass()` sorts by `renderPassEvent`. Any deviation must be explicitly documented as an adapter, compatibility shim, or engine-specific extension; silent renames or incompatible semantics are blockers. -- Unity API compatibility progress: `ScriptableRendererFeature` now implements `IDisposable`, exposes read-only `isActive`, `SetActive(bool)`, `SetupRenderPasses(...)`, `OnCameraPreCull(...)`, protected `Dispose(bool)`, and a `ref RenderingData` `AddRenderPasses(...)` shim while preserving existing by-value overrides; `ScriptableRenderer` calls `SetupRenderPasses()` before `AddRenderPasses(ref ...)`; `ScriptableRenderPass` now exposes public settable `renderPassEvent`, `ScriptableRenderPassInput`, `input`, `ConfigureInput(...)`, `requiresIntermediateTexture`, `Execute(...)`, `OnCameraSetup(...)`, `OnCameraCleanup(...)`, `OnFinishCameraStackRendering(...)`, protected `profilingSampler`, comparison operators, and public `RecordRenderGraph(RenderGraph, ContextContainer)` dispatch; `RenderPassEvent` now carries Unity's 17.0 numeric ordering plus explicit XCEngine extension events for native scene phases and final output; managed `ContextItem`, `ContextContainer`, and `RenderGraph` compatibility types now exist. Remaining parity gaps are exact functional scope for command-buffer-style callbacks, `BeforeRendering` stage semantics, and the `RenderingData` class-vs-struct decision. +- Unity API compatibility progress: `ScriptableRendererFeature` now implements `IDisposable`, exposes read-only `isActive`, `SetActive(bool)`, `SetupRenderPasses(...)`, `OnCameraPreCull(...)`, protected `Dispose(bool)`, and a `ref RenderingData` `AddRenderPasses(...)` shim while preserving existing by-value overrides; `ScriptableRenderer` calls `SetupRenderPasses()` before `AddRenderPasses(ref ...)` and now invokes `OnFinishCameraStackRendering(...)` after successful renderer recording; `ScriptableRenderPass` exposes public settable `renderPassEvent`, `ScriptableRenderPassInput`, `input`, `ConfigureInput(...)`, `requiresIntermediateTexture`, `Execute(...)`, `OnCameraSetup(...)`, `OnCameraCleanup(...)`, `OnFinishCameraStackRendering(...)`, protected `profilingSampler`, comparison operators, and public `RecordRenderGraph(RenderGraph, ContextContainer)` dispatch; `RenderPassEvent` carries Unity's 17.0 numeric ordering plus explicit XCEngine extension events for native scene phases and final output; managed `ContextItem`, `ContextContainer`, and `RenderGraph` compatibility types exist. Remaining parity gaps are exact `CommandBuffer` functional scope, `BeforeRendering` stage semantics, and the `RenderingData` class-vs-struct decision. - ShaderLibrary contract gate: current package files are an incomplete starter surface and still expose old public ABI names such as `PerObjectConstants`, `MaterialConstants`, and `LightingConstants`. - Resolver safety gate: forward-slash package includes, backslash package includes, recursive package includes, missing package includes, absolute include rejection, `Packages/../...` traversal rejection, current-directory shadow package-root rejection, current-path fallback for source-root-missing unique package files, and searched-anchor diagnostics now have `shader_tests` evidence. Remaining resolver safety work is only ResourceManager-root fallback coverage if that fallback is expected to be supported outside editor/runtime bootstrapping. - Test coverage gate: `tests/Resources/Shader/test_shader_dependencies.cpp` now has executed evidence for dependency collection, package include expansion into stage source, D3D12 bytecode smoke for a temp/project-style authoring shader, current-directory shadow package-root rejection, current-path fallback resolution, all current public package include files, AssetDatabase missing-package-include failure diagnostics, actionable include diagnostics, stale package dependency records forcing reimport, and end-to-end valid package-edit artifact invalidation. Managed compile/reflection probes now cover the new URP pass input/lifecycle API, `RenderPassEvent` ordering, `ContextContainer`, `ContextItem`, `RenderGraph`, and public `RecordRenderGraph(RenderGraph, ContextContainer)`, but future runtime assertions are still needed for complete Unity API parity behavior. -- Validation gate: current code gate passed after the managed RenderGraph/ContextContainer parity shim: `shader_tests` rebuilt and passed, `XCEngine.lib` rebuilt, `XCUIEditorApp` rebuilt, `xcengine_project_managed_assemblies` rebuilt, and the 15:47 editor smoke passed on a clean `new_editor/` baseline. Continue to rerun the full gate after every subsequent code/test change. -- Editor smoke gate: the accepted 2026-04-25 15:47 run reached `[app] initialize end`, closed normally with exit code 0, wrote `[trace] trace session ended`, produced `build/new_editor/Debug/logs/smoke_scene_20260425_154759.png`, and had red-dominant ratio `0.000242` from normal scene content rather than full-screen failure. Visual review shows the Scene viewport, grid, volumetric clouds, lights, and scene objects without full red-screen regression. Corrected `runtime.log` and `crash.log` timestamp filters from 2026-04-25 15:47:59 found no crash/assert/fatal/error/failed/device-removed/RenderGraph/shader-failure entries and no crash-log entries. +- Validation gate: current code gate passed after the managed renderer finish-lifecycle shim: `shader_tests` rebuilt and passed, `XCEngine.lib` rebuilt, `XCUIEditorApp` rebuilt, `xcengine_project_managed_assemblies` rebuilt, and the 15:54 editor smoke passed on a clean `new_editor/` baseline. Continue to rerun the full gate after every subsequent code/test change. +- Editor smoke gate: the accepted 2026-04-25 15:54 run reached `[app] initialize end`, closed normally with exit code 0, wrote `[trace] trace session ended`, produced `build/new_editor/Debug/logs/smoke_scene_20260425_155440.png`, and had red-dominant ratio `0.000242` from normal scene content rather than full-screen failure. Visual review shows the Scene viewport, grid, volumetric clouds, lights, and scene objects without full red-screen regression. Corrected `runtime.log` and `crash.log` timestamp filters from 2026-04-25 15:54:40 found no crash/assert/fatal/error/failed/device-removed/RenderGraph/shader-failure entries and no crash-log entries. - Build-scope gate: the root `CMakeLists.txt` change that conditionally skips missing `editor/CMakeLists.txt` is accepted only as build-enablement because this workspace has no `editor/` directory and the verified targets rely on the current CMake configure path. It is not counted as rendering progress by itself. - Scope gate: `docs/plan/NewEditor_Win32WindowArchitectureRefactorPlan_2026-04-23.md` has a very large unrelated rewrite/deletion in the current non-`new_editor` diff. It is outside this URP closeout increment and must be separated or reverted before URP acceptance. @@ -146,15 +146,16 @@ Validation record: - Managed Unity API compatibility evidence (2026-04-25 15:09): `ScriptableRendererFeature` gained Unity-compatible `IDisposable`, `SetActive(bool)`, `SetupRenderPasses(...)`, `OnCameraPreCull(...)`, protected `Dispose(bool)`, and `AddRenderPasses(..., ref RenderingData)` shims; `ScriptableRenderer` now calls setup before pass injection; `ScriptableRenderPass.renderPassEvent` is public settable. Existing engine-specific paths remain intact. - Managed render-pass lifecycle evidence (2026-04-25 15:32): `ScriptableRenderPass` gained `ScriptableRenderPassInput`, `input`, `ConfigureInput(...)`, `requiresIntermediateTexture`, `Execute(...)`, `OnCameraSetup(...)`, `OnCameraCleanup(...)`, `OnFinishCameraStackRendering(...)`, protected `profilingSampler`, and comparison operators; `RenderPassEvent` now includes Unity 17.0 events and numeric ordering, with XCEngine `RenderOpaques`/`RenderSkybox`/`RenderTransparents`/final-output extension events placed between Unity events. Compile/reflection probes were updated to cover these public API seams. - Managed RenderGraph API evidence (2026-04-25 15:49): managed `ContextItem`, `ContextContainer`, and `XCEngine.Rendering.RenderGraphModule.RenderGraph` compatibility types were added; `ScriptableRenderPass` now exposes and dispatches public virtual `RecordRenderGraph(RenderGraph, ContextContainer)` when a pass overrides that Unity-style seam while preserving the existing protected `ScriptableRenderContext`/`RenderingData` path for current engine passes. Compile/reflection probes cover the new API surface. -- Test evidence (2026-04-25 15:49): `cmake --build build --config Debug --target shader_tests` emitted `build/tests/Debug/shader_tests.exe`, and `ctest --test-dir build -C Debug -R shader_tests --output-on-failure` passed. -- Build evidence (2026-04-25 15:49): `cmake --build build --config Debug --target XCEngine`, `cmake --build build --config Debug --target XCUIEditorApp`, and `cmake --build build --config Debug --target xcengine_project_managed_assemblies` all passed after isolating unrelated dirty `new_editor/` files. -- Runtime log evidence (2026-04-25 15:47): a 12s `XCUIEditor.exe` smoke stayed alive after managed assembly rebuild, closed normally with exit code 0, reached `[app] initialize end`, `[app] shutdown end`, and `[trace] trace session ended`; corrected timestamp-window filtering from 15:47:59 found no crash/assert/fatal/error/failed/device-removed/RenderGraph/shader-failure entries. -- Visual smoke evidence (2026-04-25 15:47): valid screenshot `build/new_editor/Debug/logs/smoke_scene_20260425_154759.png` was captured from the visible `XCUIEditor.exe` main window, shows the Scene viewport, grid, volumetric clouds, lights, and scene objects, and has red-dominant ratio `0.000242`. +- Managed finish-lifecycle evidence (2026-04-25 15:55): `ScriptableRenderer.RecordRenderer(...)` now calls `ScriptableRenderPass.OnFinishCameraStackRendering(...)` for the active pass queue after successful stage recording, using a renderer-owned finish command buffer. This gives the Unity-style finish callback an actual managed lifecycle hook without changing native render pass ABI. +- Test evidence (2026-04-25 15:55): `cmake --build build --config Debug --target shader_tests` emitted `build/tests/Debug/shader_tests.exe`, and `ctest --test-dir build -C Debug -R shader_tests --output-on-failure` passed. +- Build evidence (2026-04-25 15:55): `cmake --build build --config Debug --target XCEngine`, `cmake --build build --config Debug --target XCUIEditorApp`, and `cmake --build build --config Debug --target xcengine_project_managed_assemblies` all passed after isolating unrelated dirty `new_editor/` files. +- Runtime log evidence (2026-04-25 15:54): a 12s `XCUIEditor.exe` smoke stayed alive after managed assembly rebuild, closed normally with exit code 0, reached `[app] initialize end`, `[app] shutdown end`, and `[trace] trace session ended`; corrected timestamp-window filtering from 15:54:40 found no crash/assert/fatal/error/failed/device-removed/RenderGraph/shader-failure entries. +- Visual smoke evidence (2026-04-25 15:54): valid screenshot `build/new_editor/Debug/logs/smoke_scene_20260425_155440.png` was captured from the visible `XCUIEditor.exe` main window, shows the Scene viewport, grid, volumetric clouds, lights, and scene objects, and has red-dominant ratio `0.000242`. - Crash log evidence: no newer crash than the old 2026-04-25 02:45 `D3D12Buffer::SetData` stack was found, but the old crash remains the exact regression signature to guard against. Next actions (priority order): -1. Continue resolving the Unity SRP/URP API parity checklist: decide exact command-buffer callback semantics, `BeforeRendering` mapping, and `RenderingData` class-vs-struct compatibility. +1. Continue resolving the Unity SRP/URP API parity checklist: decide exact `CommandBuffer` functional scope, `BeforeRendering` mapping, and `RenderingData` class-vs-struct compatibility. 2. Decide whether ResourceManager-root package fallback is a supported deployment path; if yes, add explicit coverage without leaving async loader threads alive in `shader_tests`. 3. Keep builtin runtime shaders and ABI bindings unchanged until steps 1-2 are accepted. 4. Rerun the full gate after every code/test change: `XCEngine` build, `shader_tests` build/run, `XCUIEditorApp` build, 12s `XCUIEditor.exe` smoke, screenshot review, `runtime.log` timestamp check, and `crash.log` timestamp check. diff --git a/managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderer.cs b/managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderer.cs index cbe60a08..ee8acc30 100644 --- a/managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderer.cs +++ b/managed/XCEngine.RenderPipelines.Universal/Rendering/Universal/ScriptableRenderer.cs @@ -12,6 +12,8 @@ namespace XCEngine.Rendering.Universal new List(); private readonly RendererBlocks m_rendererBlocks = new RendererBlocks(); + private readonly CommandBuffer m_finishCameraStackCommandBuffer = + new CommandBuffer("ScriptableRenderer.FinishCameraStack"); private bool m_isBuildingPassQueue; private CameraFrameStage m_passQueueStage = CameraFrameStage.MainScene; @@ -164,7 +166,14 @@ namespace XCEngine.Rendering.Universal RenderingData renderingData = context.renderingData; BuildPassQueue(renderingData); - return RecordRendererStage(context); + bool recorded = + RecordRendererStage(context); + if (recorded) + { + FinishCameraStackRendering(); + } + + return recorded; } protected internal virtual bool SupportsStageRenderGraph( @@ -383,6 +392,22 @@ namespace XCEngine.Rendering.Universal } } + private void FinishCameraStackRendering() + { + for (int i = 0; i < m_activePassQueue.Count; ++i) + { + ScriptableRenderPass renderPass = + m_activePassQueue[i]; + if (renderPass == null) + { + continue; + } + + renderPass.OnFinishCameraStackRendering( + m_finishCameraStackCommandBuffer); + } + } + protected virtual void ReleaseRuntimeResources() { }