Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SpiralGridScheduler.h
Go to the documentation of this file.
1#pragma once
2
5#include "Math/math.h"
6
7#include <Common/assertion.h>
8
9#include <algorithm>
10#include <cmath>
11
12namespace ph
13{
14
20{
21public:
23
25 std::size_t numWorkers,
26 const WorkUnit& totalWorkUnit,
27 const math::Vector2S& spiralTileSize);
28
30 std::size_t numWorkers,
31 const WorkUnit& totalWorkUnit,
32 const math::Vector2S& spiralTileSize,
33 const math::Vector2S& numGridCells);
34
35private:
36 SpiralScheduler m_spiralScheduler;
37 math::Vector2S m_numGridCells;
38 GridScheduler m_currentGrid;
39
40 void scheduleOne(WorkUnit* out_workUnit) override;
41};
42
43// In-header Implementations:
44
46
48
49 , m_spiralScheduler()
50 , m_numGridCells (0)
51 , m_currentGrid ()
52{}
53
55 const std::size_t numWorkers,
56 const WorkUnit& totalWorkUnit,
57 const math::Vector2S& spiralTileSize) :
58
60 numWorkers,
61 totalWorkUnit,
62 spiralTileSize,
63 math::Vector2S(static_cast<std::size_t>(
64 std::max(math::fast_sqrt(static_cast<float>(numWorkers)), 1.0f))))
65{}
66
68 const std::size_t numWorkers,
69 const WorkUnit& totalWorkUnit,
70 const math::Vector2S& spiralTileSize,
71 const math::Vector2S& numGridCells) :
72
73 WorkScheduler(numWorkers, totalWorkUnit),
74
75 m_spiralScheduler(numWorkers, totalWorkUnit, spiralTileSize),
76 m_numGridCells (numGridCells),
77 m_currentGrid ()
78{}
79
80inline void SpiralGridScheduler::scheduleOne(WorkUnit* const out_workUnit)
81{
82 PH_ASSERT(out_workUnit);
83
84 if(!m_currentGrid.schedule(out_workUnit))
85 {
86 WorkUnit parentWorkUnit;
87 if(m_spiralScheduler.schedule(&parentWorkUnit))
88 {
89 m_currentGrid = GridScheduler(
90 m_numGridCells.product(),
91 parentWorkUnit,
92 m_numGridCells);
93
94 m_currentGrid.schedule(out_workUnit);
95 PH_ASSERT_GT(out_workUnit->getVolume(), 0);
96 }
97 else
98 {
99 *out_workUnit = WorkUnit();
100 }
101 }
102}
103
104}// end namespace ph
Definition GridScheduler.h:20
Definition SpiralGridScheduler.h:20
SpiralGridScheduler()
Definition SpiralGridScheduler.h:45
Definition SpiralScheduler.h:21
A manager that distributes a fixed amount of work to workers.
Definition WorkScheduler.h:21
bool schedule(WorkUnit *out_workUnit)
Get some amount of work.
Definition WorkScheduler.h:85
Represents some amount of work.
Definition WorkUnit.h:17
std::size_t getVolume() const
Definition WorkUnit.h:82
T product() const
Definition TArithmeticArrayBase.ipp:358
Miscellaneous math utilities.
float fast_sqrt(const float x)
Computes sqrt(x) in a fast but approximative way.
Definition math.h:436
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96