载入中...
搜索中...
未找到
FrameGraphJobs.cpp
浏览该文件的文档.
2
3#include "thread/JobSystem.h"
4
5#include <chrono>
6#include <functional>
7#include <thread>
8#include <vector>
9
10namespace eve::graphics::vulkan {
11
12vkb::PassRecordExecutor jobSystemPassExecutor(eve::thread::JobSystem *jobs) {
13 return [jobs](const std::vector<uint32_t> &layerPasses,
14 const std::function<void(uint32_t)> &recordOne) {
15 if (!jobs || layerPasses.size() <= 1) {
16 for (uint32_t order : layerPasses) recordOne(order);
17 return;
18 }
19 auto *group = jobs->createFrameTaskGroup();
20 for (uint32_t order : layerPasses)
21 group->fork([recordOne, order] { recordOne(order); });
22 // Join without help-execution: TaskGroup::wait() help-executes on the
23 // waiting thread, and that path races with the arena lifecycle in
24 // beginFrame/endFrame (a help-run job's completion can observe
25 // outstandingFrame == 0 and reset the per-frame arena while workers
26 // are still finishing other jobs). Polling the group's pending count
27 // keeps workers as the sole executors; every forked job still drains.
28 // (Follow-up: fix the JobSystem help-execution race upstream so this
29 // can return to a blocking join.)
30 while (group->getPendingCount() > 0)
31 std::this_thread::sleep_for(std::chrono::microseconds(50));
32 // Arena-owned group; never deleted.
33 };
34}
35
37 graph.record(jobSystemPassExecutor(jobs));
38}
39
40} // namespace eve::graphics::vulkan
building::EdgeCurveGroup group
std::vector< std::int32_t > order
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:59
Abstract job scheduler: dependencies, parallel_for, task_group, arena.
Definition JobSystem.h:157
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.
vkb::PassRecordExecutor jobSystemPassExecutor(eve::thread::JobSystem *jobs)
Build a vkb::PassRecordExecutor backed by the engine JobSystem.
void recordFrameGraphWithJobSystem(vkb::FrameGraph &graph, eve::thread::JobSystem *jobs)
Record a vkb::FrameGraph with the engine JobSystem as the parallel recording executor.