Skip to content

Commit 793f2b4

Browse files
authored
[Depends on #8332] Integrate fgviewer to the engine side (#8344)
* Introduce FrameGraphInfo class * Move the assignment into pimpl * Make ctors explicit * Add ctors to fg info structs * Revert the macro change to align with existing * Address the comments * Remove pimpl and move func def to .cc * Fix * Convert the FrameGraph to FrameGraphInfo * Initialize and update debug server on engine side * Fix compile error * Address the comments * Update * Use camelCase * Use camelCase * Update
1 parent 9a2ca8d commit 793f2b4

File tree

8 files changed

+133
-2
lines changed

8 files changed

+133
-2
lines changed

filament/src/details/Engine.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,25 @@ int FEngine::loop() {
749749
}
750750
#endif
751751

752+
#if FILAMENT_ENABLE_FGVIEWER
753+
#ifdef __ANDROID__
754+
const char* fgviewerPortString = "8085";
755+
#else
756+
const char* fgviewerPortString = getenv("FILAMENT_FGVIEWER_PORT");
757+
#endif
758+
if (fgviewerPortString != nullptr) {
759+
const int fgviewerPort = atoi(fgviewerPortString);
760+
debug.fgviewerServer = new fgviewer::DebugServer(fgviewerPort);
761+
762+
// Sometimes the server can fail to spin up (e.g. if the above port is already in use).
763+
// When this occurs, carry onward, developers can look at civetweb.txt for details.
764+
if (!debug.fgviewerServer->isReady()) {
765+
delete debug.fgviewerServer;
766+
debug.fgviewerServer = nullptr;
767+
}
768+
}
769+
#endif
770+
752771
while (true) {
753772
if (!execute()) {
754773
break;

filament/src/details/Engine.h

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ using MaterialKey = uint32_t;
8888
} // namespace filament::matdbg
8989
#endif
9090

91+
#if FILAMENT_ENABLE_FGVIEWER
92+
#include <fgviewer/DebugServer.h>
93+
#else
94+
namespace filament::fgviewer {
95+
class DebugServer;
96+
} // namespace filament::fgviewer
97+
#endif
98+
9199
namespace filament {
92100

93101
class Renderer;
@@ -673,6 +681,7 @@ class FEngine : public Engine {
673681
bool combine_multiview_images = false;
674682
} stereo;
675683
matdbg::DebugServer* server = nullptr;
684+
fgviewer::DebugServer* fgviewerServer = nullptr;
676685
} debug;
677686

678687
struct {

filament/src/details/Renderer.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,13 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) {
14401440

14411441
fg.compile();
14421442

1443+
#if FILAMENT_ENABLE_FGVIEWER
1444+
fgviewer::DebugServer* fgviewerServer = engine.debug.fgviewerServer;
1445+
if (UTILS_LIKELY(fgviewerServer)) {
1446+
fgviewerServer->update(view.getViewHandle(), fg.getFrameGraphInfo(view.getName()));
1447+
}
1448+
#endif
1449+
14431450
//fg.export_graphviz(slog.d, view.getName());
14441451

14451452
fg.execute(driver);

filament/src/details/View.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ FView::FView(FEngine& engine)
109109
}
110110
#endif
111111

112+
#if FILAMENT_ENABLE_FGVIEWER
113+
fgviewer::DebugServer* fgviewerServer = engine.debug.fgviewerServer;
114+
if (UTILS_LIKELY(fgviewerServer)) {
115+
mFrameGraphViewerViewHandle =
116+
fgviewerServer->createView(utils::CString(getName()));
117+
}
118+
#endif
119+
112120
// allocate UBOs
113121
mLightUbh = driver.createBufferObject(CONFIG_MAX_LIGHT_COUNT * sizeof(LightsUib),
114122
BufferObjectBinding::UNIFORM, BufferUsage::DYNAMIC);
@@ -153,6 +161,13 @@ void FView::terminate(FEngine& engine) {
153161
engine.getDebugRegistry().unregisterDataSource("d.view.frame_info");
154162
}
155163
#endif
164+
165+
#if FILAMENT_ENABLE_FGVIEWER
166+
fgviewer::DebugServer* fgviewerServer = engine.debug.fgviewerServer;
167+
if (UTILS_LIKELY(fgviewerServer)) {
168+
fgviewerServer->destroyView(mFrameGraphViewerViewHandle);
169+
}
170+
#endif
156171
}
157172

158173
void FView::setViewport(filament::Viewport const& viewport) noexcept {

filament/src/details/View.h

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
#include <utils/Range.h>
6161
#include <utils/Slice.h>
6262

63+
#if FILAMENT_ENABLE_FGVIEWER
64+
#include <fgviewer/DebugServer.h>
65+
#else
66+
namespace filament::fgviewer {
67+
using ViewHandle = uint32_t;
68+
}
69+
#endif
70+
6371
#include <math/scalar.h>
6472
#include <math/mat4.h>
6573

@@ -467,6 +475,10 @@ class FView : public View {
467475
return mUniforms;
468476
}
469477

478+
fgviewer::ViewHandle getViewHandle() const noexcept {
479+
return mFrameGraphViewerViewHandle;
480+
}
481+
470482
private:
471483
struct FPickingQuery : public PickingQuery {
472484
private:
@@ -600,6 +612,8 @@ class FView : public View {
600612
{ 0, 0, 0, 1 },
601613
}};
602614

615+
fgviewer::ViewHandle mFrameGraphViewerViewHandle;
616+
603617
#ifndef NDEBUG
604618
struct DebugState {
605619
std::unique_ptr<std::array<DebugRegistry::FrameHistory, 5*60>> debugFrameHistory{};

filament/src/fg/FrameGraph.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,61 @@ void FrameGraph::export_graphviz(utils::io::ostream& out, char const* name) {
479479
mGraph.export_graphviz(out, name);
480480
}
481481

482+
fgviewer::FrameGraphInfo FrameGraph::getFrameGraphInfo(const char *viewName) const {
483+
#if FILAMENT_ENABLE_FGVIEWER
484+
fgviewer::FrameGraphInfo info{utils::CString(viewName)};
485+
std::vector<fgviewer::FrameGraphInfo::Pass> passes;
486+
487+
auto first = mPassNodes.begin();
488+
const auto activePassNodesEnd = mActivePassNodesEnd;
489+
while (first != activePassNodesEnd) {
490+
PassNode *const pass = *first;
491+
first++;
492+
493+
assert_invariant(!pass->isCulled());
494+
std::vector<fgviewer::ResourceId> reads;
495+
auto const &readEdges = mGraph.getIncomingEdges(pass);
496+
for (auto const &edge: readEdges) {
497+
// all incoming edges should be valid by construction
498+
assert_invariant(mGraph.isEdgeValid(edge));
499+
reads.push_back(edge->from);
500+
}
501+
502+
std::vector<fgviewer::ResourceId> writes;
503+
auto const &writeEdges = mGraph.getOutgoingEdges(pass);
504+
for (auto const &edge: writeEdges) {
505+
// It is possible that the node we're writing to has been culled.
506+
// In this case we'd like to ignore the edge.
507+
if (!mGraph.isEdgeValid(edge)) {
508+
continue;
509+
}
510+
writes.push_back(edge->to);
511+
}
512+
passes.emplace_back(utils::CString(pass->getName()),
513+
std::move(reads), std::move(writes));
514+
}
515+
516+
std::unordered_map<fgviewer::ResourceId, fgviewer::FrameGraphInfo::Resource> resources;
517+
for (const auto &resource: mResourceNodes) {
518+
std::vector<fgviewer::FrameGraphInfo::Resource::Property> resourceProps;
519+
// TODO: Fill in resource properties
520+
fgviewer::ResourceId id = resource->getId();
521+
resources.emplace(id, fgviewer::FrameGraphInfo::Resource(
522+
id, utils::CString(resource->getName()),
523+
std::move(resourceProps))
524+
);
525+
}
526+
527+
info.setResources(std::move(resources));
528+
info.setPasses(std::move(passes));
529+
530+
return info;
531+
#else
532+
return fgviewer::FrameGraphInfo();
533+
#endif
534+
}
535+
536+
482537
// ------------------------------------------------------------------------------------------------
483538

484539
/*

filament/src/fg/FrameGraph.h

+14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636

3737
#include <functional>
3838

39+
#if FILAMENT_ENABLE_FGVIEWER
40+
#include <fgviewer/FrameGraphInfo.h>
41+
#else
42+
namespace filament::fgviewer {
43+
class FrameGraphInfo{};
44+
} // namespace filament::fgviewer
45+
#endif
46+
3947
namespace filament {
4048

4149
class ResourceAllocatorInterface;
@@ -434,6 +442,12 @@ class FrameGraph {
434442
//! export a graphviz view of the graph
435443
void export_graphviz(utils::io::ostream& out, const char* name = nullptr);
436444

445+
/**
446+
* Export a fgviewer::FrameGraphInfo for current graph.
447+
* Note that this function should be called after FrameGraph::compile().
448+
*/
449+
fgviewer::FrameGraphInfo getFrameGraphInfo(const char *viewName) const;
450+
437451
private:
438452
friend class FrameGraphResources;
439453
friend class PassNode;

libs/fgviewer/include/fgviewer/DebugServer.h

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace filament::fgviewer {
3131

3232
using ViewHandle = uint32_t;
3333

34-
35-
3634
/**
3735
* Server-side frame graph debugger.
3836
*

0 commit comments

Comments
 (0)