Exemplo n.º 1
0
jobs::Future<std::any> SchedulerCPU::OnSetupNode(const FrameContextEx& context, const Pipeline& pipeline, lemon::ListDigraph::Node node, std::any) {
	GraphicsTask* task = pipeline.GetTaskFunctionMap()[node];
	if (task != nullptr) {
		SetupNode(*task, context);
	}
	co_return std::any{};
}
Exemplo n.º 2
0
jobs::Future<std::any> SchedulerCPU::OnExecuteNode(const FrameContextEx& context, const Pipeline& pipeline, lemon::ListDigraph::Node node, std::any forwarded) {
	GraphicsTask* task = pipeline.GetTaskFunctionMap()[node];
	if (task != nullptr) {
		// See if we inherited anything.
		std::optional<ProducedCommands> heritage;
		if (forwarded.has_value()) {
			ProducedCommands& commands = *std::any_cast<std::shared_ptr<ProducedCommands>&>(forwarded); // Throws if wrong.
			heritage = std::move(commands);
		}

		// Execute task.
		ProducedCommands commands = ExecuteNode(*task, heritage, context);

		// Enqueue heritage.
		if (heritage) {
			assert(heritage->list);
			co_await context.schedulerGpu->Enqueue(std::move(heritage->list), std::move(heritage->vheap));
			heritage.reset();
		}

		// Determine if next node can inherit.
		const auto& taskGraph = pipeline.GetTaskGraph();
		bool canNextInherit = false;
		if (lemon::countOutArcs(taskGraph, node) == 1) {
			lemon::ListDigraph::OutArcIt theOnlyOutArc(taskGraph, node);
			lemon::ListDigraph::Node theOnlyNextNode = taskGraph.target(theOnlyOutArc);
			canNextInherit = lemon::countInArcs(taskGraph, theOnlyNextNode) == 1;
		}

		// Pass on command lists to next node if possible.
		if (canNextInherit) {
			std::any ret(std::make_shared<ProducedCommands>(std::move(commands)));
			co_return ret;
		}
		else {
			// Enqueue commands.
			if (commands.list) {
				co_await context.schedulerGpu->Enqueue(std::move(commands.list), std::move(commands.vheap));
			}
		}
	}

	co_return std::any{};
}