载入中...
搜索中...
未找到
FrameGraphJobs.h
浏览该文件的文档.
1#pragma once
2
3#include "thread/JobSystem.h"
4#include "vkbuilder/framegraph.hpp"
5
6#include <chrono>
7#include <cstdint>
8#include <functional>
9#include <thread>
10#include <vector>
11
12namespace eve::graphics::vulkan {
13
25inline vkb::PassRecordExecutor jobSystemPassExecutor(eve::thread::JobSystem *jobs) {
26 return [jobs](const std::vector<uint32_t> &layerPasses,
27 const std::function<void(uint32_t)> &recordOne) {
28 if (!jobs || layerPasses.size() <= 1) {
29 for (uint32_t order : layerPasses) recordOne(order);
30 return;
31 }
32 auto *group = jobs->createFrameTaskGroup();
33 for (uint32_t order : layerPasses)
34 group->fork([recordOne, order] { recordOne(order); });
35 // Join without help-execution: TaskGroup::wait() help-executes on the
36 // waiting thread, and that path races with the arena lifecycle in
37 // beginFrame/endFrame (a help-run job's completion can observe
38 // outstandingFrame == 0 and reset the per-frame arena while workers
39 // are still finishing other jobs). Polling the group's pending count
40 // keeps workers as the sole executors; every forked job still drains.
41 // (Follow-up: fix the JobSystem help-execution race upstream so this
42 // can return to a blocking join.)
43 while (group->getPendingCount() > 0)
44 std::this_thread::sleep_for(std::chrono::microseconds(50));
45 // Arena-owned group; never deleted.
46 };
47}
48
67inline void recordFrameGraphWithJobSystem(vkb::FrameGraph &graph, eve::thread::JobSystem *jobs) {
68 graph.record(jobSystemPassExecutor(jobs));
69}
70
71} // namespace eve::graphics::vulkan
const FusedGroup & group
const Graph & graph
Abstract job scheduler: dependencies, parallel_for, task_group, arena.
Definition JobSystem.h:153
virtual TaskGroup * createFrameTaskGroup()=0
Create a fork/join task group whose children are frame-scoped.
virtual Job * fork(JobFunc body)=0
Spawn a scheduled child job and add it to this group.
void recordFrameGraphWithJobSystem(vkb::FrameGraph &graph, eve::thread::JobSystem *jobs)
Record a vkb::FrameGraph with the engine JobSystem as the parallel recording executor.
vkb::PassRecordExecutor jobSystemPassExecutor(eve::thread::JobSystem *jobs)
Build a vkb::PassRecordExecutor backed by the engine JobSystem.