1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2019-20 Mandelbulber Team     §R-==%w["'~5]m%=L.=~5N
5  *                                        ,=mm=§M ]=4 yJKA"/-Nsaj  "Bw,==,,
6  * This file is part of Mandelbulber.    §R.r= jw",M  Km .mM  FW ",§=ß., ,TN
7  *                                     ,4R =%["w[N=7]J '"5=],""]]M,w,-; T=]M
8  * Mandelbulber is free software:     §R.ß~-Q/M=,=5"v"]=Qf,'§"M= =,M.§ Rz]M"Kw
9  * you can redistribute it and/or     §w "xDY.J ' -"m=====WeC=\ ""%""y=%"]"" §
10  * modify it under the terms of the    "§M=M =D=4"N #"%==A%p M§ M6  R' #"=~.4M
11  * GNU General Public License as        §W =, ][T"]C  §  § '§ e===~ U  !§[Z ]N
12  * published by the                    4M",,Jm=,"=e~  §  §  j]]""N  BmM"py=ßM
13  * Free Software Foundation,          ]§ T,M=& 'YmMMpM9MMM%=w=,,=MT]M m§;'§,
14  * either version 3 of the License,    TWw [.j"5=~N[=§%=%W,T ]R,"=="Y[LFT ]N
15  * or (at your option)                   TW=,-#"%=;[  =Q:["V""  ],,M.m == ]N
16  * any later version.                      J§"mr"] ,=,," =="""J]= M"M"]==ß"
17  *                                          §= "=C=4 §"eM "=B:m|4"]#F,§~
18  * Mandelbulber is distributed in            "9w=,,]w em%wJ '"~" ,=,,ß"
19  * the hope that it will be useful,                 . "K=  ,=RMMMßM"""
20  * but WITHOUT ANY WARRANTY;                            .'''
21  * without even the implied warranty
22  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * See the GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with Mandelbulber. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ###########################################################################
29  *
30  * Authors: Krzysztof Marczak (buddhi1980@gmail.com)
31  *
32  * thread for one of GPUs in multi-gpu rendering
33  */
34 
35 #ifndef MANDELBULBER2_SRC_OPENCL_WORKER_THREAD_H_
36 #define MANDELBULBER2_SRC_OPENCL_WORKER_THREAD_H_
37 
38 #ifdef USE_OPENCL
39 
40 #include <memory>
41 
42 #include <QObject>
43 
44 #include "algebra.hpp"
45 #include "error_message.hpp"
46 #include "include_header_wrapper.hpp"
47 #include "opencl_input_output_buffer.h"
48 
49 class cOpenCLWorkerOutputQueue;
50 class cOpenClScheduler;
51 class cOpenClEngine;
52 
53 class cOpenClWorkerThread : public QObject
54 {
55 	Q_OBJECT
56 
57 public:
58 	cOpenClWorkerThread(
59 		cOpenClEngine *engine, const std::shared_ptr<cOpenClScheduler> scheduler, int deviceIndex);
60 	~cOpenClWorkerThread() override;
61 
setImageHeight(quint64 imageHeight)62 	void setImageHeight(quint64 imageHeight) { this->imageHeight = imageHeight; }
setImageWidth(quint64 imageWidth)63 	void setImageWidth(quint64 imageWidth) { this->imageWidth = imageWidth; }
setOptimalStepX(quint64 optimalStepX)64 	void setOptimalStepX(quint64 optimalStepX) { this->optimalStepX = optimalStepX; }
setOptimalStepY(quint64 optimalStepY)65 	void setOptimalStepY(quint64 optimalStepY) { this->optimalStepY = optimalStepY; }
setClKernel(const std::shared_ptr<cl::Kernel> & clKernel)66 	void setClKernel(const std::shared_ptr<cl::Kernel> &clKernel) { this->clKernel = clKernel; }
setClQueue(const std::shared_ptr<cl::CommandQueue> & clQueue)67 	void setClQueue(const std::shared_ptr<cl::CommandQueue> &clQueue) { this->clQueue = clQueue; }
setAntiAliasingDepth(int antiAliasingDepth)68 	void setAntiAliasingDepth(int antiAliasingDepth) { this->antiAliasingDepth = antiAliasingDepth; }
setFullEngineFlag(bool fullEngine)69 	void setFullEngineFlag(bool fullEngine) { this->isFullEngine = fullEngine; }
setInputAndOutputBuffers(const QList<sClInputOutputBuffer> & inputAndOutputBuffers)70 	void setInputAndOutputBuffers(const QList<sClInputOutputBuffer> &inputAndOutputBuffers)
71 	{
72 		this->inputAndOutputBuffers = inputAndOutputBuffers;
73 	}
setOutputBuffers(const QList<sClInputOutputBuffer> & outputBuffers)74 	void setOutputBuffers(const QList<sClInputOutputBuffer> &outputBuffers)
75 	{
76 		this->outputBuffers = outputBuffers;
77 	}
setOutputQueue(const std::shared_ptr<cOpenCLWorkerOutputQueue> & outputQueue)78 	void setOutputQueue(const std::shared_ptr<cOpenCLWorkerOutputQueue> &outputQueue)
79 	{
80 		this->outputQueue = outputQueue;
81 	}
setMaxMonteCarloSamples(int maxMonteCarloSamples)82 	void setMaxMonteCarloSamples(int maxMonteCarloSamples)
83 	{
84 		this->maxMonteCarloSamples = maxMonteCarloSamples;
85 	}
setStopRequest(bool * stopRequest)86 	void setStopRequest(bool *stopRequest) { this->stopRequest = stopRequest; }
setReservedGpuTime(double reservedGpuTime)87 	void setReservedGpuTime(double reservedGpuTime) { this->reservedGpuTime = reservedGpuTime; }
wasFishedWithSuccess()88 	bool wasFishedWithSuccess() { return finishedWithSuccess; }
89 
90 private:
91 	bool ProcessClQueue(quint64 jobX, quint64 jobY, quint64 pixelsLeftX, quint64 pixelsLeftY);
92 	static bool checkErr(cl_int err, QString functionName);
93 	bool AddAntiAliasingParameters(int actualDepth, int repeatIndex);
94 
95 	std::shared_ptr<cl::Kernel> clKernel;
96 	std::shared_ptr<cl::CommandQueue> clQueue;
97 
98 	std::shared_ptr<cOpenCLWorkerOutputQueue> outputQueue;
99 	std::shared_ptr<cOpenClScheduler> scheduler;
100 	QList<sClInputOutputBuffer> outputBuffers;
101 	QList<sClInputOutputBuffer> inputAndOutputBuffers;
102 	bool *stopRequest;
103 
104 	const int outputIndex = 0;
105 
106 	cOpenClEngine *engine;
107 
108 	quint64 optimalStepX;
109 	quint64 optimalStepY;
110 	quint64 imageWidth;
111 	quint64 imageHeight;
112 	double reservedGpuTime;
113 	int maxMonteCarloSamples;
114 	bool finishedWithSuccess;
115 	int antiAliasingDepth;
116 	int isFullEngine;
117 
118 	const int deviceIndex;
119 
120 public slots:
121 	void ProcessRenderingLoop();
122 
123 signals:
124 	void showErrorMessage(QString, cErrorMessage::enumMessageType, QWidget *);
125 	void finished();
126 };
127 
128 #endif // USE_OPENCL
129 
130 #endif /* MANDELBULBER2_SRC_OPENCL_WORKER_THREAD_H_ */
131