Skip to content

Commit 85e2cc0

Browse files
authored
Create data transmitting class for fgviewer (#8332)
* 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 * Address the comment
1 parent bef849b commit 85e2cc0

File tree

5 files changed

+151
-29
lines changed

5 files changed

+151
-29
lines changed

libs/fgviewer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ endif()
1515
set(PUBLIC_HDRS
1616
include/fgviewer/DebugServer.h
1717
include/fgviewer/JsonWriter.h
18+
include/fgviewer/FrameGraphInfo.h
1819
)
1920

2021
set(SRCS
2122
src/ApiHandler.cpp
2223
src/ApiHandler.h
2324
src/DebugServer.cpp
25+
src/FrameGraphInfo.cpp
2426
)
2527

2628
# ==================================================================================================

libs/fgviewer/include/fgviewer/DebugServer.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef FGVIEWER_DEBUGSERVER_H
1818
#define FGVIEWER_DEBUGSERVER_H
1919

20+
#include <fgviewer/FrameGraphInfo.h>
21+
2022
#include <utils/CString.h>
2123
#include <utils/Mutex.h>
2224

@@ -27,17 +29,9 @@ class CivetServer;
2729

2830
namespace filament::fgviewer {
2931

30-
using FrameGraphInfoKey = uint32_t;
32+
using ViewHandle = uint32_t;
3133

32-
struct FrameGraphPassInfo {
33-
utils::CString pass_name;
34-
// TODO: Add struct detail properties
35-
};
3634

37-
struct FrameGraphInfo {
38-
utils::CString view_name;
39-
std::vector<FrameGraphPassInfo> passes;
40-
};
4135

4236
/**
4337
* Server-side frame graph debugger.
@@ -50,30 +44,31 @@ class DebugServer {
5044
static std::string_view const kSuccessHeader;
5145
static std::string_view const kErrorHeader;
5246

53-
DebugServer(int port);
47+
explicit DebugServer(int port);
5448
~DebugServer();
5549

5650
/**
5751
* Notifies the debugger that a new view has been added.
5852
*/
59-
void addView(const utils::CString& name, FrameGraphInfo info);
53+
ViewHandle createView(utils::CString name);
6054

6155
/**
6256
* Notifies the debugger that the given view has been deleted.
6357
*/
64-
void removeView(const utils::CString& name);
58+
void destroyView(ViewHandle h);
6559

6660
/**
6761
* Updates the information for a given view.
6862
*/
69-
void updateView(const utils::CString& name, FrameGraphInfo info);
63+
void update(ViewHandle h, FrameGraphInfo info);
7064

7165
bool isReady() const { return mServer; }
7266

7367
private:
7468
CivetServer* mServer;
7569

76-
std::unordered_map<FrameGraphInfoKey, FrameGraphInfo> mViews;
70+
std::unordered_map<ViewHandle, FrameGraphInfo> mViews;
71+
uint32_t mViewCounter = 0;
7772
mutable utils::Mutex mViewsMutex;
7873

7974
class FileRequestHandler* mFileHandler = nullptr;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FGVIEWER_FRAMEGRAPHINFO_H
18+
#define FGVIEWER_FRAMEGRAPHINFO_H
19+
20+
#include <utils/CString.h>
21+
22+
#include <cstdint>
23+
#include <vector>
24+
#include <unordered_map>
25+
26+
namespace filament::fgviewer {
27+
using ResourceId = uint32_t;
28+
29+
class FrameGraphInfo {
30+
public:
31+
explicit FrameGraphInfo(utils::CString viewName);
32+
33+
~FrameGraphInfo();
34+
35+
FrameGraphInfo(FrameGraphInfo &&rhs) noexcept;
36+
37+
FrameGraphInfo(FrameGraphInfo const &) = delete;
38+
39+
struct Pass {
40+
Pass(utils::CString name, std::vector<ResourceId> reads,
41+
std::vector<ResourceId> writes);
42+
43+
utils::CString name;
44+
std::vector<ResourceId> reads;
45+
std::vector<ResourceId> writes;
46+
};
47+
48+
struct Resource {
49+
struct Property {
50+
utils::CString name;
51+
utils::CString value;
52+
};
53+
54+
Resource(ResourceId id, utils::CString name,
55+
std::vector<Property> properties);
56+
57+
ResourceId id;
58+
utils::CString name;
59+
// We use a vector of Property here to store the resource properties,
60+
// so different kinds of resources could choose different types of
61+
// properties to record.
62+
// ex.
63+
// Texture2D --> { {"name","XXX"}, {"sizeX", "1024"}, {"sizeY", "768"} }
64+
// Buffer1D --> { {"name", "XXX"}, {"size", "512"} }
65+
std::vector<Property> properties;
66+
};
67+
68+
void setResources(std::unordered_map<ResourceId, Resource> resources);
69+
70+
// The incoming passes should be sorted by the execution order.
71+
void setPasses(std::vector<Pass> sortedPasses);
72+
73+
private:
74+
utils::CString viewName;
75+
// The order of the passes in the vector indicates the execution
76+
// order of the passes.
77+
std::vector<Pass> passes;
78+
std::unordered_map<ResourceId, Resource> resources;
79+
};
80+
} // namespace filament::fgviewer
81+
82+
#endif //FGVIEWER_FRAMEGRAPHINFO_H

libs/fgviewer/src/DebugServer.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <fgviewer/DebugServer.h>
18+
#include <fgviewer/FrameGraphInfo.h>
1819

1920
#include "ApiHandler.h"
2021

@@ -31,12 +32,6 @@ namespace filament::fgviewer {
3132

3233
namespace {
3334
std::string const BASE_URL = "libs/fgviewer/web";
34-
35-
FrameGraphInfoKey getKeybyString(const utils::CString &input,
36-
uint32_t seed) {
37-
return utils::hash::murmurSlow(reinterpret_cast<uint8_t const*>(
38-
input.c_str()), input.size(), 0);
39-
}
4035
} // anonymous
4136

4237
using namespace utils;
@@ -49,6 +44,7 @@ std::string_view const DebugServer::kErrorHeader =
4944
"HTTP/1.1 404 Not Found\r\nContent-Type: %s\r\n"
5045
"Connection: close\r\n\r\n";
5146

47+
5248
class FileRequestHandler : public CivetHandler {
5349
public:
5450
FileRequestHandler(DebugServer* server) : mServer(server) {}
@@ -110,22 +106,23 @@ DebugServer::~DebugServer() {
110106
delete mServer;
111107
}
112108

113-
void DebugServer::addView(const utils::CString &name, FrameGraphInfo info) {
109+
ViewHandle DebugServer::createView(utils::CString name) {
114110
std::unique_lock<utils::Mutex> lock(mViewsMutex);
115-
const FrameGraphInfoKey key = getKeybyString(name, 0);
116-
mViews.insert({key, info});
111+
ViewHandle handle = mViewCounter++;
112+
mViews.emplace(handle, FrameGraphInfo(std::move(name)));
113+
114+
return handle;
117115
}
118116

119-
void DebugServer::removeView(const utils::CString& name) {
117+
void DebugServer::destroyView(ViewHandle h) {
120118
std::unique_lock<utils::Mutex> lock(mViewsMutex);
121-
const FrameGraphInfoKey key = getKeybyString(name, 0);
122-
mViews.erase(key);
119+
mViews.erase(h);
123120
}
124121

125-
void DebugServer::updateView(const utils::CString& name, FrameGraphInfo info) {
122+
void DebugServer::update(ViewHandle h, FrameGraphInfo info) {
126123
std::unique_lock<utils::Mutex> lock(mViewsMutex);
127-
const FrameGraphInfoKey key = getKeybyString(name, 0);
128-
mViews[key] = info;
124+
mViews.erase(h);
125+
mViews.emplace(h, std::move(info));
129126
}
130127

131128
} // namespace filament::fgviewer

libs/fgviewer/src/FrameGraphInfo.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <fgviewer/FrameGraphInfo.h>
18+
19+
namespace filament::fgviewer {
20+
21+
FrameGraphInfo::FrameGraphInfo(utils::CString viewName):
22+
viewName(std::move(viewName)), passes({}), resources({}) {}
23+
24+
FrameGraphInfo::~FrameGraphInfo() = default;
25+
26+
FrameGraphInfo::FrameGraphInfo(FrameGraphInfo&& rhs) noexcept = default;
27+
28+
FrameGraphInfo::Pass::Pass(utils::CString name, std::vector<ResourceId> reads,
29+
std::vector<ResourceId> writes): name(std::move(name)),
30+
reads(std::move(reads)),
31+
writes(std::move(writes)) {}
32+
33+
FrameGraphInfo::Resource::Resource(ResourceId id, utils::CString name,
34+
std::vector<Property> properties): id(id),
35+
name(std::move(name)), properties(std::move(properties)) {}
36+
37+
void FrameGraphInfo::setResources(
38+
std::unordered_map<ResourceId, Resource> resources) {
39+
this->resources = std::move(resources);
40+
}
41+
42+
void FrameGraphInfo::setPasses(std::vector<Pass> sortedPasses) {
43+
passes = std::move(sortedPasses);
44+
}
45+
46+
} // namespace filament::fgviewer

0 commit comments

Comments
 (0)