-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathpathcputhread.cpp
More file actions
146 lines (116 loc) · 5.45 KB
/
Copy pathpathcputhread.cpp
File metadata and controls
146 lines (116 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/***************************************************************************
* Copyright 1998-2020 by authors (see AUTHORS.txt) *
* *
* This file is part of LuxCoreRender. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
#include "luxrays/utils/thread.h"
#include "slg/engines/pathcpu/pathcpu.h"
#include "slg/volumes/volume.h"
#include "slg/utils/varianceclamping.h"
#include "slg/samplers/metropolis.h"
using namespace std;
using namespace luxrays;
using namespace slg;
//------------------------------------------------------------------------------
// PathCPU RenderThread
//------------------------------------------------------------------------------
PathCPURenderThread::PathCPURenderThread(PathCPURenderEngine *engine,
const u_int index, IntersectionDevice *device) :
CPUNoTileRenderThread(engine, index, device) {
}
void PathCPURenderThread::RenderFunc() {
#if defined (_MSC_VER) || defined (__INTEL_COMPILER)
// Embree recommends settings these flags in each thread to improve performance
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
#endif
//SLG_LOG("[PathCPURenderEngine::" << threadIndex << "] Rendering thread started");
//--------------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------------
// This is really used only by Windows for 64+ threads support
SetThreadGroupAffinity(threadIndex);
PathCPURenderEngine *engine = (PathCPURenderEngine *)renderEngine;
const PathTracer &pathTracer = engine->pathTracer;
// (engine->seedBase + 1) seed is used for sharedRndGen
RandomGenerator *rndGen = new RandomGenerator(engine->seedBase + 1 + threadIndex);
// Setup the sampler(s)
Sampler *eyeSampler = nullptr;
Sampler *lightSampler = nullptr;
eyeSampler = engine->renderConfig->AllocSampler(rndGen, engine->film,
nullptr, engine->samplerSharedData, Properties());
eyeSampler->SetThreadIndex(threadIndex);
eyeSampler->RequestSamples(PIXEL_NORMALIZED_ONLY, pathTracer.eyeSampleSize);
if (pathTracer.hybridBackForwardEnable) {
// Light path sampler is always Metropolis
Properties props;
props <<
Property("sampler.type")("METROPOLIS") <<
// Disable image plane meaning for samples 0 and 1
Property("sampler.imagesamples.enable")(false) <<
Property("sampler.metropolis.addonlycaustics")(true);
lightSampler = Sampler::FromProperties(props, rndGen, engine->film, engine->lightSampleSplatter,
engine->lightSamplerSharedData);
lightSampler->SetThreadIndex(threadIndex);
lightSampler->RequestSamples(SCREEN_NORMALIZED_ONLY, pathTracer.lightSampleSize);
}
// Setup variance clamping
VarianceClamping varianceClamping(pathTracer.sqrtVarianceClampMaxValue);
// Setup PathTracer thread state
PathTracerThreadState pathTracerThreadState(device,
eyeSampler, lightSampler,
engine->renderConfig->scene, engine->film,
&varianceClamping);
//--------------------------------------------------------------------------
// Trace paths
//--------------------------------------------------------------------------
for (u_int steps = 0; !boost::this_thread::interruption_requested(); ++steps) {
// Check if we are in pause mode
if (engine->pauseMode) {
// Check every 100ms if I have to continue the rendering
while (!boost::this_thread::interruption_requested() && engine->pauseMode)
boost::this_thread::sleep(boost::posix_time::millisec(100));
if (boost::this_thread::interruption_requested())
break;
}
pathTracer.RenderSample(pathTracerThreadState);
#ifdef WIN32
// Work around Windows bad scheduling
renderThread->yield();
#endif
// Check halt conditions
if (engine->film->GetConvergence() == 1.f)
break;
if (engine->photonGICache) {
try {
const u_int spp = engine->film->GetTotalEyeSampleCount() / engine->film->GetPixelCount();
engine->photonGICache->Update(threadIndex, spp);
} catch (boost::thread_interrupted &ti) {
// I have been interrupted, I must stop
break;
}
}
}
delete eyeSampler;
delete lightSampler;
delete rndGen;
threadDone = true;
// This is done to stop threads pending on barrier wait
// inside engine->photonGICache->Update(). This can happen when an
// halt condition is satisfied.
if (engine->photonGICache)
engine->photonGICache->FinishUpdate(threadIndex);
//SLG_LOG("[PathCPURenderEngine::" << threadIndex << "] Rendering thread halted");
}