Skip to content

Commit

Permalink
Slightly improve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
phisiart committed Nov 26, 2017
1 parent a1f3ea5 commit e5c159d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
55 changes: 44 additions & 11 deletions src/runtime/opengl/opengl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,25 @@ class OpenGLWorkspace final : public DeviceAPI {
void* AllocWorkspace(TVMContext ctx, size_t size) final;
void FreeWorkspace(TVMContext ctx, void* data) final;

/*!
* \brief Create an OpenGL program that uses the given fragment shader.
* \param fragment_shader The fragment shader **source**.
* \return The OpenGL program.
*/
std::unique_ptr<Program> CreateProgram(const char* fragment_shader_src);

// get the global workspace
/*!
* \brief Get the global OpenGL workspace.
* \return The global OpenGL workspace.
*/
static const std::shared_ptr<OpenGLWorkspace>& Global();

/*!
* \brief Use an OpenGL program to render to a texture.
* \param program The OpenGL program. Created by CreateProgram().
* \param inputs All input textures.
* \param output The output texture.
*/
void Render(
const Program& program,
const std::vector<std::pair<std::string, Texture*>>& inputs,
Expand All @@ -76,8 +90,20 @@ class OpenGLWorkspace final : public DeviceAPI {

GLuint NumTextureUnits();

/*!
* \brief Create and compile a shader from a source string.
* \param shader_kind The kind of shader.
* Could be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
* \param shader_src The source string of the shader.
* \return The compiled shader ID.
*/
GLuint CreateShader(GLenum shader_kind, const char* shader_src);

/*!
* \brief Create an OpenGL program that uses the given fragment shader.
* \param fragment_shader The **compiled** fragment shader.
* \return The OpenGL program.
*/
std::unique_ptr<Program> CreateProgram(GLuint fragment_shader);
};

Expand All @@ -90,10 +116,6 @@ class OpenGLWorkspace final : public DeviceAPI {
*/
class Program {
public:
Program() : program_(kInvalidProgram) {}

explicit Program(GLuint program) : program_(program) {}

// Move constructor.
Program(Program&& other) noexcept : program_(other.program_) {
other.program_ = kInvalidProgram;
Expand All @@ -107,22 +129,26 @@ class Program {
private:
friend class OpenGLWorkspace;

// Only OpenGLWorkspace can create a Program.
// We enforce this to make sure OpenGL is initialized.
explicit Program(GLuint program) : program_(program) {}

// The internal OpenGL program ID.
GLuint program() { return program_; }

static constexpr GLuint kInvalidProgram = static_cast<GLuint>(-1);

GLuint program_;
static const GLuint kInvalidProgram = static_cast<GLuint>(-1);
};

/*!
* An OpenGL texture represents a chunk of GPU memory.
* \brief An OpenGL texture represents a chunk of GPU memory.
* This is the way we represent tensors.
* We always use 2D textures.
*/
class Texture {
public:
explicit Texture(size_t nbytes);

~Texture();

// Move constructor.
Texture(Texture&& other) noexcept
: texture_(other.texture_), width_(other.width_), height_(other.height_) {
other.texture_ = kInvalidTexture;
Expand All @@ -131,6 +157,8 @@ class Texture {
Texture(const Texture& other) = delete;
Texture& operator=(const Texture& other) = delete;

~Texture();

GLsizei width() const { return width_; }

GLsizei height() const { return height_; }
Expand All @@ -142,6 +170,11 @@ class Texture {
private:
friend class OpenGLWorkspace;

// Only OpenGLWorkspace can create a Texture.
// We enforce this to make sure OpenGL is initialized.
explicit Texture(size_t nbytes);

// The internal texture ID.
GLuint texture() const { return texture_; }

static constexpr GLuint kInvalidTexture = static_cast<GLuint>(-1);
Expand Down
17 changes: 0 additions & 17 deletions src/runtime/opengl/opengl_device_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,6 @@ const char* OpenGLWorkspace::vertex_shader_text_ = "#version 330 core\n"
" gl_Position = vec4(point, 0.0, 1.0);\n"
"}\n";

/*!
* \brief Create a program that uses the given vertex and fragment shader.
* \param fragment_shader The fragment shader **source**.
* \return The program ID.
*/
std::unique_ptr<Program> OpenGLWorkspace::CreateProgram(
const char* fragment_shader_src) {
// Create and compile the shaders.
Expand All @@ -343,13 +338,6 @@ std::unique_ptr<Program> OpenGLWorkspace::CreateProgram(
return program;
}

/*!
* \brief Create and compile a shader from a source string.
* \param shader_kind The kind of shader.
* Could be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
* \param shader_src The source string of the shader.
* \return The compiled shader ID.
*/
GLuint OpenGLWorkspace::CreateShader(GLenum shader_kind,
const char* shader_src) {
// Create the shader.
Expand All @@ -376,11 +364,6 @@ GLuint OpenGLWorkspace::CreateShader(GLenum shader_kind,
return shader;
}

/*!
* \brief Create a program that uses the given vertex and fragment shaders.
* \param fragment_shader The **compiled** fragment shader.
* \return The program ID.
*/
std::unique_ptr<Program> OpenGLWorkspace::CreateProgram(
GLuint fragment_shader) {
// Create the program and link the shaders.
Expand Down

0 comments on commit e5c159d

Please sign in to comment.