62 if (state_ != 1)
return;
63 if (device_.timerDisjoint()) {
66 for (Frame& f : frames_) f.inflight =
false;
68 for (
u32 i = 0; i < kFrames; ++i) {
69 Frame& f = frames_[i];
70 if (!f.inflight || !poll(f))
continue;
73 if (frameNo_[i] <= lastNo_)
continue;
74 lastNo_ = frameNo_[i];
77 for (
const Slot& slot : f.slots) {
78 lastTotal_ += slot.ms;
80 for (
Entry& e : last_) {
81 if (e.name == slot.name) { e.ms += slot.ms; merged =
true;
break; }
83 if (!merged) last_.push_back({slot.name, slot.ms});
91 const u32 next = (cur_ + 1) % kFrames;
92 if (frames_[next].inflight && counter_ - frameNo_[next] < kGiveUpFrames) {
97 if (frames_[next].inflight) ++framesDropped_;
99 frames_[cur_].slots.clear();
100 frames_[cur_].inflight =
false;
101 frameNo_[cur_] = counter_;
112 if (state_ != 1 || !timing_ || arming_ || !open_)
return;
113 const std::string label = pass_ +
"/" + name;
115 Frame& f = frames_[cur_];
116 if (f.slots.size() >= kMaxPasses)
return;
117 const u32 query = queryFor(cur_,
static_cast<u32>(f.slots.size()));
118 if (query == 0)
return;
120 slot.name = names_.insert(label).first->c_str();
122 f.slots.push_back(slot);
123 device_.beginTimerQuery(query);
128 if (state_ != 1 || !timing_)
return;
131 Frame& f = frames_[cur_];
132 if (f.slots.size() >= kMaxPasses)
return;
133 const u32 query = queryFor(cur_,
static_cast<u32>(f.slots.size()));
134 if (query == 0)
return;
136 slot.name = names_.insert(name).first->c_str();
138 f.slots.push_back(slot);
139 if (arming_) device_.armPassTimer(query);
140 else device_.beginTimerQuery(query);
292 const std::vector<bool>& live = live_;
296 for (
auto& res : resources_) res.lastRead = -1;
297 for (
usize i = 0; i < passes_.size(); ++i) {
298 if (!live[i])
continue;
300 if (read < resources_.size()) resources_[read].lastRead =
static_cast<i32>(i);
302 for (
ResourceId dep : passes_[i].dependencies) {
303 if (dep < resources_.size()) resources_[dep].lastRead =
static_cast<i32>(i);
309 std::vector<i32>& lastWriter = last_writer_;
310 lastWriter.assign(resources_.size(), -1);
311 for (
usize i = 0; i < passes_.size(); ++i) {
312 if (live[i] && passes_[i].write < resources_.size()) lastWriter[passes_[i].write] =
static_cast<i32>(i);
316 std::vector<ResourceId> inFlight;
317 std::vector<TextureHandle> inFlightTextures;
319 if (
id >= resources_.size())
return false;
320 const Resource&
resource = resources_[id];
325 return std::find(inFlight.begin(), inFlight.end(),
id) != inFlight.end() ||
327 std::find(inFlightTextures.begin(), inFlightTextures.end(), tex) != inFlightTextures.end());
330 for (
usize i = 0; i < passes_.size(); ++i) {
331 if (!live[i])
continue;
333 Resource& target = resources_[pass.
write];
335 if (target.kind == Kind::ImportedTexture) {
336 ES_LOG_ERROR(
"RenderGraph: pass '{}' writes an imported texture", pass.
name);
341 if (target.kind == Kind::Transient) {
343 target.pooled = acquire(target);
344 if (target.pooled ==
kNoTarget)
continue;
345 target.texture = pool_.textureOf(target.pooled);
347 fbo = pool_.framebufferOf(target.pooled);
355 std::any_of(pass.
reads.begin(), pass.
reads.end(), touchesPending) ||
357 device_.graphicsWaitOnAsyncComputeJob(pending);
361 if (timer_) timer_->begin(pass.
name);
365 device_.endRenderPass();
366 inputScratch_.clear();
370 ctx.width = target.width;
371 ctx.height = target.height;
372 ctx.inputs = &inputScratch_;
373 ctx.output = target.texture;
374 const bool scoped = pass.
asyncCompute && !timer_ && device_.asyncComputeEnabled() &&
375 device_.supportsAsyncCompute() && device_.beginAsyncComputeJob(pass.
computePriority);
378 pending = device_.endAsyncComputeJob();
380 inFlight = pass.
reads;
382 inFlight.push_back(pass.
write);
383 inFlightTextures.clear();
389 if (timer_) timer_->end();
390 for (
auto& res : resources_) {
391 if (res.kind == Kind::Transient && res.lastRead ==
static_cast<i32>(i)) release(res);
411 device_.beginRenderPass(rp);
415 device_.setViewport(0, 0, target.width, target.height);
418 inputScratch_.clear();
419 for (
u32 unit = 0; unit < pass.
reads.size(); ++unit) {
422 device_.bindTexture(unit, tex);
423 inputScratch_.push_back(tex);
428 ctx.width = target.width;
429 ctx.height = target.height;
430 ctx.inputs = &inputScratch_;
434 if (timer_) timer_->end();
438 for (
auto& res : resources_) {
439 if (res.kind == Kind::Transient && res.lastRead ==
static_cast<i32>(i)) release(res);
442 device_.graphicsWaitOnAsyncComputeJob(pending);