Compute Library
 21.02
GCKernel Class Referencefinal

GCKernel class. More...

#include <GCKernelLibrary.h>

Public Member Functions

 GCKernel ()
 Default Constructor. More...
 
 GCKernel (const GCKernel &)=default
 Default Copy Constructor. More...
 
 GCKernel (GCKernel &&)=default
 Default Move Constructor. More...
 
GCKerneloperator= (const GCKernel &)=default
 Default copy assignment operator. More...
 
GCKerneloperator= (GCKernel &&)=default
 Default move assignment operator. More...
 
 GCKernel (std::string name, GLuint program)
 Constructor. More...
 
 ~GCKernel ()
 Destructor. More...
 
std::string name () const
 Returns kernel name. More...
 
GLuint get_program () const
 Get program id. More...
 
void use ()
 Use current program. More...
 
void unuse ()
 Unuse current program. More...
 
template<class T >
void set_argument (unsigned int idx, T value)
 Set argument value at index of shader params. More...
 
void clear_arguments ()
 Clear shader arguments. More...
 
void set_shader_params_binding_point (unsigned int binding)
 Set shader params binding point. More...
 
void update_shader_params ()
 Update shader params. More...
 
void cleanup ()
 Clean up program and ubo. More...
 

Detailed Description

GCKernel class.

Definition at line 87 of file GCKernelLibrary.h.

Constructor & Destructor Documentation

◆ GCKernel() [1/4]

GCKernel ( )

Default Constructor.

Definition at line 130 of file GCKernelLibrary.cpp.

131  : _name(), _program(), _shader_arguments(), _shader_params_ubo_name(), _shader_params_binding_point(), _shader_params_index(), _shader_params_size()
132 {
133 }

◆ GCKernel() [2/4]

GCKernel ( const GCKernel )
default

Default Copy Constructor.

◆ GCKernel() [3/4]

GCKernel ( GCKernel &&  )
default

Default Move Constructor.

◆ GCKernel() [4/4]

GCKernel ( std::string  name,
GLuint  program 
)

Constructor.

Parameters
[in]nameKernel name.
[in]programBuilt program.

Definition at line 140 of file GCKernelLibrary.cpp.

References ARM_COMPUTE_ERROR_ON_MSG_VAR, ARM_COMPUTE_GL_CHECK, glGenBuffers(), glGetActiveUniformBlockiv(), and glGetUniformBlockIndex().

141  : _name(std::move(name)),
142  _program(program),
143  _shader_arguments(),
144  _shader_params_ubo_name(0),
145  _shader_params_binding_point(0),
146  _shader_params_index(0),
147  _shader_params_size(0)
148 {
149  _shader_arguments.clear();
150 
151  ARM_COMPUTE_GL_CHECK(glGenBuffers(1, &_shader_params_ubo_name));
152 
153  _shader_params_index = ARM_COMPUTE_GL_CHECK(glGetUniformBlockIndex(_program, _shader_params_name));
154  ARM_COMPUTE_ERROR_ON_MSG_VAR(_shader_params_index == GL_INVALID_INDEX, "Failed to get index of %s", _shader_params_name);
155  ARM_COMPUTE_GL_CHECK(glGetActiveUniformBlockiv(_program, _shader_params_index, GL_UNIFORM_BLOCK_DATA_SIZE, &_shader_params_size));
156  ARM_COMPUTE_ERROR_ON_MSG_VAR(_shader_params_size == 0, "Failed to get size of %s", _shader_params_name);
157 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
std::string name() const
Returns kernel name.
#define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg,...)
Definition: Error.h:457
GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
Definition: OpenGLES.cpp:711
void GL_APIENTRY glGenBuffers(GLsizei n, GLuint *buffers)
Definition: OpenGLES.cpp:568
void GL_APIENTRY glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params)
Definition: OpenGLES.cpp:685

◆ ~GCKernel()

~GCKernel ( )

Destructor.

Definition at line 136 of file GCKernelLibrary.cpp.

137 {
138 }

Member Function Documentation

◆ cleanup()

void cleanup ( )

Clean up program and ubo.

Definition at line 159 of file GCKernelLibrary.cpp.

References ARM_COMPUTE_GL_CHECK, glBindBuffer(), glDeleteBuffers(), glDeleteProgram(), and glUseProgram().

160 {
161  ARM_COMPUTE_GL_CHECK(glDeleteBuffers(1, &_shader_params_ubo_name));
162  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
165 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint *buffers)
Definition: OpenGLES.cpp:529
void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer)
Definition: OpenGLES.cpp:490
void GL_APIENTRY glDeleteProgram(GLuint program)
Definition: OpenGLES.cpp:360
void GL_APIENTRY glUseProgram(GLuint program)
Definition: OpenGLES.cpp:477

◆ clear_arguments()

void clear_arguments ( )
inline

Clear shader arguments.

Definition at line 154 of file GCKernelLibrary.h.

Referenced by GCKernelLibrary::create_kernel().

155  {
156  _shader_arguments.clear();
157  }

◆ get_program()

GLuint get_program ( ) const
inline

Get program id.

Returns
program id.

Definition at line 121 of file GCKernelLibrary.h.

Referenced by arm_compute::enqueue().

122  {
123  return _program;
124  }

◆ name()

std::string name ( ) const
inline

Returns kernel name.

Returns
Kernel's name.

Definition at line 113 of file GCKernelLibrary.h.

114  {
115  return _name;
116  }

◆ operator=() [1/2]

GCKernel& operator= ( const GCKernel )
default

Default copy assignment operator.

◆ operator=() [2/2]

GCKernel& operator= ( GCKernel &&  )
default

Default move assignment operator.

◆ set_argument()

void set_argument ( unsigned int  idx,
value 
)
inline

Set argument value at index of shader params.

Parameters
[in]idxIndex in shader params.
[in]valueArgument value to be set.

Definition at line 141 of file GCKernelLibrary.h.

Referenced by IGCKernel::kernel().

142  {
143  if(idx >= _shader_arguments.size())
144  {
145  _shader_arguments.resize(idx + 1, 0);
146  }
147 
148  unsigned int *p = reinterpret_cast<unsigned int *>(&value);
149  _shader_arguments[idx] = *p;
150  }

◆ set_shader_params_binding_point()

void set_shader_params_binding_point ( unsigned int  binding)
inline

Set shader params binding point.

Parameters
[in]bindingShader params binding point.

Definition at line 162 of file GCKernelLibrary.h.

Referenced by GCKernelLibrary::create_kernel().

163  {
164  _shader_params_binding_point = binding;
165  }

◆ unuse()

void unuse ( )

Unuse current program.

Returns
program id.

Definition at line 172 of file GCKernelLibrary.cpp.

References ARM_COMPUTE_GL_CHECK, and glUseProgram().

173 {
175 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
void GL_APIENTRY glUseProgram(GLuint program)
Definition: OpenGLES.cpp:477

◆ update_shader_params()

void update_shader_params ( )

Update shader params.

Definition at line 177 of file GCKernelLibrary.cpp.

References ARM_COMPUTE_ERROR_ON_MSG_VAR, ARM_COMPUTE_GL_CHECK, glBindBuffer(), glBindBufferBase(), glBufferData(), and glUniformBlockBinding().

178 {
179  ARM_COMPUTE_ERROR_ON_MSG_VAR((_shader_params_size != (int)(_shader_arguments.size() * sizeof(_shader_arguments[0]))), "Arguments size (%zu) is not equal to shader params block size (%d)",
180  _shader_arguments.size() * sizeof(_shader_arguments[0]), _shader_params_size);
181 
182  ARM_COMPUTE_GL_CHECK(glUniformBlockBinding(_program, _shader_params_index, _shader_params_binding_point));
183  ARM_COMPUTE_GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER, _shader_params_binding_point, _shader_params_ubo_name));
184  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, _shader_params_ubo_name));
185  ARM_COMPUTE_GL_CHECK(glBufferData(GL_UNIFORM_BUFFER, _shader_params_size, _shader_arguments.data(), GL_DYNAMIC_DRAW));
186  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
187 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
#define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg,...)
Definition: Error.h:457
void GL_APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
Definition: OpenGLES.cpp:698
void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer)
Definition: OpenGLES.cpp:490
void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
Definition: OpenGLES.cpp:503
void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
Definition: OpenGLES.cpp:516

◆ use()

void use ( )

Use current program.

Returns
program id.

Definition at line 167 of file GCKernelLibrary.cpp.

References ARM_COMPUTE_GL_CHECK, and glUseProgram().

Referenced by GCKernelLibrary::create_kernel().

168 {
170 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
void GL_APIENTRY glUseProgram(GLuint program)
Definition: OpenGLES.cpp:477

The documentation for this class was generated from the following files: