A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(graph): a pass can name a resource the graph must not bind
esengineb73e9faf86c2
diff --git a/src/esengine/renderer/graph/RenderGraph.cpp b/src/esengine/renderer/graph/RenderGraph.cppindex 83ac9efde..53fde7e1b 100644--- a/src/esengine/renderer/graph/RenderGraph.cpp+++ b/src/esengine/renderer/graph/RenderGraph.cpp@@ -124,6 +124,11 @@ void RenderGraph::cull(std::vector<bool>& live) const {for (ResourceId read : pass.reads) {if (read < resources_.size()) wanted[read] = true;}+ // A dependency is wanted on the same terms as a read: the pass that+ // produces it contributed to the image even though nothing binds it.+ for (ResourceId dep : pass.dependencies) {+ if (dep < resources_.size()) wanted[dep] = true;+ }}}@@ -158,6 +163,9 @@ void RenderGraph::execute() {for (ResourceId read : passes_[i].reads) {if (read < resources_.size()) resources_[read].lastRead = static_cast<i32>(i);}+ for (ResourceId dep : passes_[i].dependencies) {+ if (dep < resources_.size()) resources_[dep].lastRead = static_cast<i32>(i);+ }}for (usize i = 0; i < passes_.size(); ++i) {@@ -185,6 +193,7 @@ void RenderGraph::execute() {RenderPassDesc rp{};rp.target = fbo;rp.clearColor = pass.clear;+ rp.clearDepth = pass.clearDepth;if (pass.clear) {for (u32 c = 0; c < 4; ++c) rp.clearColorValue[c] = pass.clearColor[c];}diff --git a/src/esengine/renderer/graph/RenderGraph.hpp b/src/esengine/renderer/graph/RenderGraph.hppindex 27a700a0e..869ad0a63 100644--- a/src/esengine/renderer/graph/RenderGraph.hpp+++ b/src/esengine/renderer/graph/RenderGraph.hpp@@ -85,8 +85,21 @@ struct PassContext {struct PassDesc {std::string name;std::vector<ResourceId> reads;+ /**+ * @brief Resources the pass uses but the graph must not bind.+ *+ * @details A scene pass reaches the shadow atlas through the material each+ * draw carries, so it owes the graph ordering but must not spend a+ * unit — as a `read` it would claim unit 0 from under the batch.+ * Culling counts it either way: a producer nothing names is dropped.+ */+ std::vector<ResourceId> dependencies;ResourceId write = kNoResource;bool clear = false;+ /// Clears the depth attachment with the colour, for a target that has one.+ /// A geometry pass writes depth, so the frame before it is not what it+ /// should be tested against; a fullscreen pass has neither and ignores this.+ bool clearDepth = false;f32 clearColor[4] = {0.0f, 0.0f, 0.0f, 1.0f};/*** @brief The rect of its target this pass draws into. Zero width = all of it.diff --git a/tests/renderer/test_render_graph.cpp b/tests/renderer/test_render_graph.cppindex 761852302..782da3e30 100644--- a/tests/renderer/test_render_graph.cpp+++ b/tests/renderer/test_render_graph.cpp@@ -250,6 +250,54 @@ int main() {"and it survives a resize the fraction-sized targets do not");}+ // --- a resource named but not bound still orders the two passes ---+ //+ // The scene reaches the atlas through its materials, not a sampler the graph+ // wired: as a read it would claim a unit; as nothing, its producer is culled.+ {+ MockGfxDevice d;+ rg::RenderGraph graph(d);+ std::vector<std::string> ran;++ graph.begin(256, 128);+ const auto out = graph.importTarget(FramebufferHandle{9}, 256, 128);+ rg::TargetDesc atlas;+ atlas.width = 2048;+ atlas.height = 2048;+ atlas.depthStencil = true;+ const auto maps = graph.createTarget(atlas);+ graph.addPass(fullscreen("shadow-atlas", {}, maps, &ran));+ rg::PassDesc scene = fullscreen("scene", {}, out, &ran);+ scene.dependencies.push_back(maps);+ graph.addPass(std::move(scene));+ graph.execute();++ CHECK(ran.size() == 2 && ran[0] == "shadow-atlas" && ran[1] == "scene",+ "a pass reached only through a dependency survives culling, and runs first");+ CHECK(d.bindLog.empty(), "and costs no texture unit, because nothing declared a read");+ CHECK(graph.pooledTargetCount() == 1, "the atlas is a pooled target like any other");++ // Lifetime has to count it too: an atlas whose last reader is not counted+ // would either be recycled while the scene still samples it, or held to+ // the end of the frame and paid for twice on the next camera.+ graph.begin(256, 128);+ const auto out2 = graph.importTarget(FramebufferHandle{9}, 256, 128);+ const auto maps2 = graph.createTarget(atlas);+ graph.addPass(fullscreen("shadow-atlas", {}, maps2));+ rg::PassDesc scene2 = fullscreen("scene", {}, out2);+ scene2.dependencies.push_back(maps2);+ graph.addPass(std::move(scene2));+ const auto after = graph.createTarget(atlas);+ graph.addPass(fullscreen("second-camera-atlas", {}, after));+ rg::PassDesc scene3 = fullscreen("scene-2", {}, out2);+ scene3.dependencies.push_back(after);+ graph.addPass(std::move(scene3));+ graph.execute();++ CHECK(d.createFramebufferCalls == 1,+ "the atlas goes back after the pass that names it, so the next one reuses it");+ }+// --- the pool gives back what nothing asks for any more ---{MockGfxDevice d;