1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include "bionic_fg/session.hpp"
#include "logging.hpp"
#include "shaders_registry.hpp"
#include <chrono>
#include <sstream>
namespace bionic_fg {
namespace {
std::uint64_t nowMs() {
using namespace std::chrono;
return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
}
std::size_t countValidShaders() {
std::size_t valid = 0;
for (const auto& shader : embedded::kShaderRegistry) {
if (embedded::IsValidSpirv(shader)) {
++valid;
}
}
return valid;
}
} // namespace
Session::Session(Config config)
: config_(config)
, embeddedShaderCount_(EmbeddedShaderCount())
, validShaderCount_(ValidEmbeddedShaderCount())
, createdAtMs_(nowMs()) {
config_.sanitize();
readyForHostIntegration_ = embeddedShaderCount_ > 0 && embeddedShaderCount_ == validShaderCount_;
BFG_LOGI(
"Session bootstrap: %zushaders/%zu valid, multiplier=%u flowScale=%.2f model=%u ready=%s",
validShaderCount_,
embeddedShaderCount_,
config_.multiplier,
config_.flowScale,
config_.model,
readyForHostIntegration_ ? "true" : "false"
);
}
void Session::updateConfig(Config config) {
config_ = config;
config_.sanitize();
}
std::string Session::describe() const {
std::ostringstream out;
out
<< "BionicFGSession{"
<< "width=" << config_.width
<< ", height=" << config_.height
<< ", multiplier=" << config_.multiplier
<< ", flowScale=" << config_.flowScale
<< ", model=" << config_.model
<< ", shaders=" << validShaderCount_ << "/" << embeddedShaderCount_
<< ", readyForHostIntegration=" << (readyForHostIntegration_ ? "true" : "false")
<< ", createdAtMs=" << createdAtMs_
<< '}';
return out.str();
}
std::size_t Session::EmbeddedShaderCount() {
return embedded::kShaderRegistry.size();
}
std::size_t Session::ValidEmbeddedShaderCount() {
static const std::size_t valid = countValidShaders();
return valid;
}
std::string Session::DescribeEmbeddedBundle() {
std::ostringstream out;
out
<< "BionicFGEmbeddedBundle{"
<< "shaderCount=" << EmbeddedShaderCount()
<< ", validShaderCount=" << ValidEmbeddedShaderCount();
if (!embedded::kShaderRegistry.empty()) {
const auto& first = embedded::kShaderRegistry.front();
const auto& last = embedded::kShaderRegistry.back();
out
<< ", first=\"" << first.name << "\""
<< ", last=\"" << last.name << "\"";
}
out << '}';
return out.str();
}
} // namespace bionic_fg
|