Blender  V2.93
COM_OpenCLDevice.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 class OpenCLDevice;
20 
21 #pragma once
22 
23 #include "COM_Device.h"
25 #include "COM_WorkScheduler.h"
26 #include "clew.h"
27 
28 namespace blender::compositor {
29 
34 class OpenCLDevice : public Device {
35  private:
39  cl_context m_context;
40 
44  cl_device_id m_device;
45 
49  cl_program m_program;
50 
54  cl_command_queue m_queue;
55 
59  cl_int m_vendorID;
60 
61  public:
69  OpenCLDevice(cl_context context, cl_device_id device, cl_program program, cl_int vendorId);
70 
71  OpenCLDevice(OpenCLDevice &&other) noexcept;
72 
73  ~OpenCLDevice();
74 
79  void execute(WorkPackage *work) override;
80 
85  static const cl_image_format *determineImageFormat(MemoryBuffer *memoryBuffer);
86 
87  cl_context getContext()
88  {
89  return this->m_context;
90  }
91 
92  cl_command_queue getQueue()
93  {
94  return this->m_queue;
95  }
96 
97  cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
98  int parameterIndex,
99  int offsetIndex,
100  std::list<cl_mem> *cleanup,
101  MemoryBuffer **inputMemoryBuffers,
102  SocketReader *reader);
103  cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
104  int parameterIndex,
105  int offsetIndex,
106  std::list<cl_mem> *cleanup,
107  MemoryBuffer **inputMemoryBuffers,
108  ReadBufferOperation *reader);
110  int offsetIndex,
111  MemoryBuffer *memoryBuffers);
113  int parameterIndex,
114  cl_mem clOutputMemoryBuffer);
115  void COM_clAttachSizeToKernelParameter(cl_kernel kernel,
116  int offsetIndex,
117  NodeOperation *operation);
118  void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer);
119  void COM_clEnqueueRange(cl_kernel kernel,
120  MemoryBuffer *outputMemoryBuffer,
121  int offsetIndex,
122  NodeOperation *operation);
123  cl_kernel COM_clCreateKernel(const char *kernelname, std::list<cl_kernel> *clKernelsToCleanUp);
124 };
125 
126 } // namespace blender::compositor
Abstract class for device implementations to be used by the Compositor. devices are queried,...
Definition: COM_Device.h:30
a MemoryBuffer contains access to the data of a chunk
NodeOperation contains calculation logic.
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
contains data about work that can be scheduled