Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
StripeScheduler.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
5#include "Math/constant.h"
6
7#include <Common/assertion.h>
8
9#include <algorithm>
10
11namespace ph
12{
13
19{
20public:
22
24 std::size_t numWorkers,
25 const WorkUnit& totalWorkUnit);
26
28 std::size_t numWorkers,
29 const WorkUnit& totalWorkUnit,
30 std::size_t slicedAxis);
31
32private:
33 std::size_t m_slicedAxis;
34 std::size_t m_numScheduled;
35 std::size_t m_sideLength;
36
37 void scheduleOne(WorkUnit* out_workUnit) override;
38};
39
40// In-header Implementations:
41
43
45
46 , m_slicedAxis (math::constant::X_AXIS)
47 , m_numScheduled(0)
48 , m_sideLength (0)
49{}
50
52 const std::size_t numWorkers,
53 const WorkUnit& totalWorkUnit)
54
56 numWorkers,
57 totalWorkUnit,
58 math::constant::Y_AXIS)// default to slice Y as it is likely more cache friendly
59{}
60
62 const std::size_t numWorkers,
63 const WorkUnit& totalWorkUnit,
64 const std::size_t slicedAxis)
65
66 : WorkScheduler(numWorkers, totalWorkUnit)
67
68 , m_slicedAxis (slicedAxis)
69 , m_numScheduled(0)
70 , m_sideLength (static_cast<std::size_t>(m_totalWorkUnit.getRegion().getExtents()[slicedAxis]))
71{}
72
73inline void StripeScheduler::scheduleOne(WorkUnit* const out_workUnit)
74{
75 PH_ASSERT(out_workUnit);
76
77 if(m_numScheduled < m_numWorkers)
78 {
79 const auto sideRange = math::ith_evenly_divided_range(m_numScheduled, m_sideLength, m_numWorkers);
80
81 Region stripRegion = m_totalWorkUnit.getRegion();
82 auto [minVertex, maxVertex] = stripRegion.getVertices();
83 minVertex[m_slicedAxis] += static_cast<int64>(sideRange.first);
84 maxVertex[m_slicedAxis] -= static_cast<int64>(m_sideLength - sideRange.second);
85 stripRegion.setVertices({minVertex, maxVertex});
86
87 *out_workUnit = WorkUnit(stripRegion, m_totalWorkUnit.getDepth());
88
89 ++m_numScheduled;
90 }
91 else
92 {
93 *out_workUnit = WorkUnit();
94 }
95}
96
97}// end namespace ph
Definition StripeScheduler.h:19
StripeScheduler()
Definition StripeScheduler.h:42
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
std::pair< TVector2< T >, TVector2< T > > getVertices() const
Definition TAABB2D.ipp:132
TAABB2D & setVertices(std::pair< TVector2< T >, TVector2< T > > minMaxVertices)
Definition TAABB2D.ipp:111
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
Definition TAABB2D.h:96