载入中...
搜索中...
未找到
FrameArena.cpp
浏览该文件的文档.
2
3#include <chrono>
4#include <cstdlib>
5#include <cstring>
6#include <functional>
7#include <thread>
8#include <vector>
9
10#include "common/Profile.h"
12#include "thread/JobSystem.h"
13
14// FrameGraphJobs lives beside the former FrameArena TU so CMake source lists
15// stay stable; the arena implementation now lives in VKBuilder.
16namespace eve::graphics::vulkan {
17
18vkb::PassRecordExecutor jobSystemPassExecutor(eve::thread::JobSystem *jobs) {
19 return [jobs](const std::vector<uint32_t> &layerPasses, const std::function<void(uint32_t)> &recordOne) {
20 if (!jobs || layerPasses.size() <= 1) {
21 for (uint32_t order : layerPasses) recordOne(order);
22 return;
23 }
24 auto *group = jobs->createFrameTaskGroup();
25 for (uint32_t order : layerPasses)
26 group->fork([recordOne, order] {
27 EV_PROFILE_MODULE("graphics", "DeferredGraph.RecordPass");
28 recordOne(order);
29 });
30 // Join without help-execution: TaskGroup::wait() help-executes on the
31 // waiting thread, and that path races with the arena lifecycle in
32 // beginFrame/endFrame (a help-run job's completion can observe
33 // outstandingFrame == 0 and reset the per-frame arena while workers
34 // are still finishing other jobs). Polling the group's pending count
35 // keeps workers as the sole executors; every forked job still drains.
36 // (Follow-up: fix the JobSystem help-execution race upstream so this
37 // can return to a blocking join.)
38 while (group->getPendingCount() > 0) std::this_thread::sleep_for(std::chrono::microseconds(50));
39 // Arena-owned group; never deleted.
40 };
41}
42
45 enum class Mode { Adaptive, Serial, Parallel };
46 static const Mode mode = [] {
47 const char *request = std::getenv("EVENGINE_FRAMEGRAPH_RECORDING");
48 if (request && std::strcmp(request, "serial") == 0) return Mode::Serial;
49 if (request && std::strcmp(request, "parallel") == 0) return Mode::Parallel;
50 return Mode::Adaptive;
51 }();
52 if (!jobs || mode == Mode::Serial || (mode == Mode::Adaptive && !state.isParallelWorthwhile())) {
53 EV_PROFILE_MODULE("graphics", "DeferredGraph.SerialRecord");
54 const auto begin = std::chrono::steady_clock::now();
55 graph.record();
56 state.serialCost = std::chrono::steady_clock::now() - begin;
57 state.parallelFrames = 0;
58 } else {
59 graph.record(jobSystemPassExecutor(jobs));
60 ++state.parallelFrames;
61 }
62}
63
64} // namespace eve::graphics::vulkan
const GltfImportRequest & request
std::vector< std::int32_t > order
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:173
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
Definition Profile.h:158
size_t begin
AbilityActivationGroup group
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, FrameGraphRecordingState &state)
Record a vkb::FrameGraph with the engine JobSystem as the parallel recording executor,...
Render-thread-owned recording cost history; reset when graph topology changes. @ownership Stored by G...