43 this->m_device = device;
46 this->m_queue =
nullptr;
47 this->m_vendorID = vendorId;
50 this->m_queue = clCreateCommandQueue(this->m_context, this->m_device, 0, &
error);
54 : m_context(other.m_context),
55 m_device(other.m_device),
56 m_program(other.m_program),
57 m_queue(other.m_queue),
58 m_vendorID(other.m_vendorID)
60 other.m_queue =
nullptr;
66 clReleaseCommandQueue(this->m_queue);
72 const unsigned int chunkNumber = work_package->
chunk_number;
79 this, &work_package->
rect, chunkNumber, inputBuffers, outputBuffer);
88 std::list<cl_mem> *cleanup,
122 std::list<cl_mem> *cleanup,
132 cl_mem clBuffer = clCreateImage2D(this->m_context,
133 CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
141 if (
error != CL_SUCCESS) {
142 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
144 if (
error == CL_SUCCESS) {
145 cleanup->push_back(clBuffer);
148 error = clSetKernelArg(kernel, parameterIndex,
sizeof(cl_mem), &clBuffer);
149 if (
error != CL_SUCCESS) {
150 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
161 if (offsetIndex != -1) {
164 cl_int2 offset = {{rect.
xmin, rect.
ymin}};
166 error = clSetKernelArg(kernel, offsetIndex,
sizeof(cl_int2), &offset);
167 if (
error != CL_SUCCESS) {
168 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
177 if (offsetIndex != -1) {
179 cl_int2 offset = {{(cl_int)operation->
getWidth(), (cl_int)operation->
getHeight()}};
181 error = clSetKernelArg(kernel, offsetIndex,
sizeof(cl_int2), &offset);
182 if (
error != CL_SUCCESS) {
183 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
190 cl_mem clOutputMemoryBuffer)
193 error = clSetKernelArg(kernel, parameterIndex,
sizeof(cl_mem), &clOutputMemoryBuffer);
194 if (
error != CL_SUCCESS) {
195 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
202 const size_t size[] = {
203 (size_t)outputMemoryBuffer->
getWidth(),
207 error = clEnqueueNDRangeKernel(
208 this->m_queue, kernel, 2,
nullptr,
size,
nullptr, 0,
nullptr,
nullptr);
209 if (
error != CL_SUCCESS) {
210 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
224 int localSize = 1024;
228 if (this->m_vendorID ==
NVIDIA) {
232 bool breaked =
false;
233 for (offsety = 0; offsety <
height && (!breaked); offsety += localSize) {
234 offset.s[1] = offsety;
235 if (offsety + localSize <
height) {
242 for (offsetx = 0; offsetx <
width && (!breaked); offsetx += localSize) {
243 if (offsetx + localSize <
width) {
249 offset.s[0] = offsetx;
251 error = clSetKernelArg(kernel, offsetIndex,
sizeof(cl_int2), &offset);
252 if (
error != CL_SUCCESS) {
253 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
255 error = clEnqueueNDRangeKernel(
256 this->m_queue, kernel, 2,
nullptr,
size,
nullptr, 0,
nullptr,
nullptr);
257 if (
error != CL_SUCCESS) {
258 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
260 clFlush(this->m_queue);
269 std::list<cl_kernel> *clKernelsToCleanUp)
272 cl_kernel kernel = clCreateKernel(this->m_program, kernelname, &
error);
273 if (
error != CL_SUCCESS) {
274 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
277 if (clKernelsToCleanUp) {
278 clKernelsToCleanUp->push_back(kernel);
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Class ExecutionGroup is a group of Operations that are executed as one. This grouping is used to comb...
MemoryBuffer * allocateOutputBuffer(rcti &rect)
allocate the outputbuffer of a chunk
MemoryBuffer ** getInputBuffersOpenCL(int chunkNumber)
get all inputbuffers needed to calculate an chunk
NodeOperation * getOutputOperation() const
get the output operation of this ExecutionGroup
void finalizeChunkExecution(int chunkNumber, MemoryBuffer **memoryBuffers)
after a chunk is executed the needed resources can be freed or unlocked.
a MemoryBuffer contains access to the data of a chunk
const rcti & get_rect() const
get the rect of this MemoryBuffer
const int getHeight() const
get the height of this MemoryBuffer
uint8_t get_num_channels()
const int getWidth() const
get the width of this MemoryBuffer
NodeOperation contains calculation logic.
unsigned int getHeight() const
unsigned int getWidth() const
virtual void executeOpenCLRegion(OpenCLDevice *, rcti *, unsigned int, MemoryBuffer **, MemoryBuffer *)
when a chunk is executed by an OpenCLDevice, this method is called
device representing an GPU OpenCL device. an instance of this class represents a single cl_device
static const cl_image_format * determineImageFormat(MemoryBuffer *memoryBuffer)
determine an image format
void COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel kernel, int offsetIndex, MemoryBuffer *memoryBuffers)
cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, std::list< cl_mem > *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader *reader)
void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer)
void COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer)
void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation *operation)
cl_kernel COM_clCreateKernel(const char *kernelname, std::list< cl_kernel > *clKernelsToCleanUp)
OpenCLDevice(cl_context context, cl_device_id device, cl_program program, cl_int vendorId)
constructor with opencl device
void execute(WorkPackage *work) override
execute a WorkPackage
MemoryBuffer * getInputMemoryBuffer(MemoryBuffer **memoryBuffers) override
static void error(const char *str)
const cl_image_format IMAGE_FORMAT_COLOR
const cl_image_format IMAGE_FORMAT_VECTOR
const cl_image_format IMAGE_FORMAT_VALUE
contains data about work that can be scheduled
unsigned int chunk_number
number of the chunk to be executed
ExecutionGroup * execution_group
executionGroup with the operations-setup to be evaluated