Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PlateScheduler.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
5
6#include <Common/assertion.h>
7
8#include <algorithm>
9
10namespace ph
11{
12
18{
19public:
21 PlateScheduler(std::size_t numWorkers, const WorkUnit& totalWorkUnit);
22
23private:
24 std::size_t m_numScheduled;
25
26 void scheduleOne(WorkUnit* out_workUnit) override;
27};
28
29// In-header Implementations:
30
33 , m_numScheduled(0)
34{}
35
36inline PlateScheduler::PlateScheduler(const std::size_t numWorkers, const WorkUnit& totalWorkUnit) :
37 WorkScheduler(numWorkers, totalWorkUnit),
38 m_numScheduled(0)
39{}
40
41inline void PlateScheduler::scheduleOne(WorkUnit* const out_workUnit)
42{
43 PH_ASSERT(out_workUnit);
44
45 if(m_numScheduled < m_numWorkers)
46 {
47 const auto depthRange = math::ith_evenly_divided_range(
48 m_numScheduled, m_totalWorkUnit.getDepth(), m_numWorkers);
49 *out_workUnit = WorkUnit(m_totalWorkUnit.getRegion(), depthRange.second - depthRange.first);
50
51 ++m_numScheduled;
52 }
53 else
54 {
55 *out_workUnit = WorkUnit();
56 }
57}
58
59}// end namespace ph
Definition PlateScheduler.h:18
PlateScheduler()
Definition PlateScheduler.h:31
A manager that distributes a fixed amount of work to workers.
Definition WorkScheduler.h:21
WorkUnit m_totalWorkUnit
Definition WorkScheduler.h:55
std::size_t m_numWorkers
Definition WorkScheduler.h:54
Represents some amount of work.
Definition WorkUnit.h:17
Region getRegion() const
Definition WorkUnit.h:72
std::size_t getDepth() const
Definition WorkUnit.h:77
Miscellaneous math utilities.
std::pair< std::size_t, std::size_t > ith_evenly_divided_range(const std::size_t rangeIndex, const std::size_t totalSize, const std::size_t numDivisions)
Gets the i-th evenly divided range.
Definition math.h:379
The root for all renderer implementations.
Definition EEngineProject.h:6