Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
RenderWork.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/assertion.h>
7
8#include <atomic>
9#include <cstddef>
10#include <limits>
11
12namespace ph
13{
14
16{
17public:
18 RenderWork();
19 RenderWork(const RenderWork& other);
20 virtual ~RenderWork();
21
22 void work();
23
25
26protected:
27 void setTotalWork(std::size_t totalWork);
28 void setWorkDone(std::size_t workDone);
29 void incrementWorkDone();
30 void setElapsedMs(std::size_t elapsedMs);
31
33
34private:
35 virtual void doWork() = 0;
36
37 std::atomic_uint32_t m_totalWork;
38 std::atomic_uint32_t m_workDone;
39 std::atomic_uint32_t m_elapsedMs;
40};
41
42// In-header Implementations:
43
45 m_totalWork(0),
46 m_workDone (0),
47 m_elapsedMs(0)
48{}
49
50inline RenderWork::RenderWork(const RenderWork& other) :
51 m_totalWork(other.m_totalWork.load(std::memory_order_relaxed)),
52 m_workDone (other.m_workDone.load(std::memory_order_relaxed)),
53 m_elapsedMs(other.m_elapsedMs.load(std::memory_order_relaxed))
54{}
55
56inline RenderWork::~RenderWork() = default;
57
58inline void RenderWork::setTotalWork(const std::size_t totalWork)
59{
60 PH_ASSERT_LE(totalWork, std::numeric_limits<std::uint32_t>::max());
61
62 m_totalWork.store(static_cast<std::uint32_t>(totalWork), std::memory_order_relaxed);
63}
64
65inline void RenderWork::setWorkDone(const std::size_t workDone)
66{
67 PH_ASSERT_LE(workDone, std::numeric_limits<std::uint32_t>::max());
68
69 m_workDone.store(static_cast<std::uint32_t>(workDone), std::memory_order_relaxed);
70}
71
73{
74 m_workDone.fetch_add(1, std::memory_order_relaxed);
75}
76
77inline void RenderWork::setElapsedMs(const std::size_t elapsedMs)
78{
79 PH_ASSERT_LE(elapsedMs, std::numeric_limits<std::uint32_t>::max());
80
81 m_elapsedMs.store(static_cast<std::uint32_t>(elapsedMs), std::memory_order_relaxed);
82}
83
85{
86 return RenderProgress(
87 m_totalWork.load(std::memory_order_relaxed),
88 m_workDone.load(std::memory_order_relaxed),
89 m_elapsedMs.load(std::memory_order_relaxed));
90}
91
93{
94 m_totalWork = rhs.m_totalWork.load(std::memory_order_relaxed);
95 m_workDone = rhs.m_workDone.load(std::memory_order_relaxed);
96 m_elapsedMs = rhs.m_elapsedMs.load(std::memory_order_relaxed);
97
98 return *this;
99}
100
101}// end namespace ph
Definition RenderProgress.h:12
Definition RenderWork.h:16
virtual ~RenderWork()
void incrementWorkDone()
Definition RenderWork.h:72
RenderWork()
Definition RenderWork.h:44
RenderProgress asyncGetProgress() const
Definition RenderWork.h:84
void work()
Definition RenderWork.cpp:8
void setWorkDone(std::size_t workDone)
Definition RenderWork.h:65
RenderWork & operator=(const RenderWork &rhs)
Definition RenderWork.h:92
void setElapsedMs(std::size_t elapsedMs)
Definition RenderWork.h:77
void setTotalWork(std::size_t totalWork)
Definition RenderWork.h:58
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96