Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Using GPU as GPGPU with opengl es 2.0

  1. #1
    Newbie Newbie
    Join Date
    May 2017
    Posts
    3

    Using GPU as GPGPU with opengl es 2.0

    Hello,

    I'm a beginner in programming GPU with opengl es 2.0 and I'm trying to use my GPU to accelerate calculation. The purpose is to develop a program that takes for example a matrix of values, performs some calculation with these values and then returns back the results. I have written a program that takes a matrix and defines it as a texture (width,height) using "glTexture2D". Then, it applies this texture to a rectangle and finally draws the result in a window defined by "glViewPort(0,0, width, height)". When I read the results using "glReadPixels", I'm waiting to see the same values that I have injected the first time as texture. However, I get another result. When I have added "glDisable(GL_DITHER)", I have got better results but not what I want.

    For example, when I insert a matrix as an RGBA texture containing values like that:
    [51 51 51 255 51 51 51 255 .....]
    [51 51 51 255 51 51 51 255 .....]


    I get this result:
    [49 52 49 255 49 52 49 255 .....]
    [49 52 49 255 49 52 49 255 .....]

    It looks like it is making a sampling algorithm. So, I wonder if there is a way to fix this problem and get the good result.

    Here I give you the code of vertex shader and fragment shader:

    Vertex shader:

    Code glsl:
    precision highp float;
    attribute vec4 av4position;
    attribute vec2 av2texcoord;
    varying vec2 vv2texcoord;
     
    void main()
    {
        vv2texcoord = av2texcoord;
        gl_Position = av4position;
    }

    Fragment shader:

    Code glsl:
    precision highp float;
    varying vec2 vv2texcoord;
    uniform sampler2D texture;
     
    void main()
    {
        vec4 color = texture2D(texture,vv2texcoord);
        gl_FragColor =  color;
    }

    Thanks.
    Last edited by Dark Photon; 05-29-2017 at 06:44 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,522
    Quote Originally Posted by Lfahem View Post
    I'm a beginner in programming GPU with opengl es 2.0 and I'm trying to use my GPU to accelerate calculation.
    • OpenGL ES does not require the fragment shader to support high precision, only medium and low.
    • High precision has a relative error of 2-16.
    • Medium precision has a relative error of 2-10.
    • Textures aren't required to use 8 bits per component; 5:6:5, 5:5:5 and 4:4:4:4 are all acceptable (and fairly common on devices using OpenGL ES). There isn't even a way to request an 8:8:8 texture without using extensions. So values stored in textures may have a relative error of 2-4.


    In short, OpenGL ES isn't particularly suited for GPGPU computing.

  3. #3
    Newbie Newbie
    Join Date
    May 2017
    Posts
    3
    Thank you for your answer,

    Actually, what I did is that I inserted the matrix as texture in the format of GL_RGBA and the type GL_UNSIGNED_BYTE using "glTexture2D". Then I used the same format and type when reading data from framebuffer with "glReadPixels". So, what are you saying is there is no way to get exactly the same values that I have injected as texture?

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,171
    Quote Originally Posted by Lfahem View Post
    I'm a beginner in programming GPU with opengl es 2.0 and I'm trying to use my GPU to accelerate calculation.

    The purpose is to develop a program that takes for example a matrix of values, performs some calculation with these values and then returns back the results. ... read the results using "glReadPixels"
    Quote Originally Posted by GClements
    In short, OpenGL ES isn't particularly suited for GPGPU computing.
    To add more wood to that fire, you did say you wanted to accelerate calculation. Mobile GPUs run the fragment pipe a frame late. If you're VSynced to 60Hz, then it could be 16-32ms or more before you can get your result back. That's a long time compared to how long it'd take you to compute this on the CPU. Further, a readback is going to trigger a full pipeline flush on the GPU which is horribly inefficient on mobile and can generate rendering artifacts under some configurations.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    Quote Originally Posted by Lfahem View Post
    Thank you for your answer,

    Actually, what I did is that I inserted the matrix as texture in the format of GL_RGBA and the type GL_UNSIGNED_BYTE using "glTexture2D". Then I used the same format and type when reading data from framebuffer with "glReadPixels". So, what are you saying is there is no way to get exactly the same values that I have injected as texture?
    From the documentation:
    type may be used as a hint to specify how much precision is desired, but a GL implementation may choose to store the texture array at any internal resolution it chooses.
    Bottom-line - even though you specify GL_RGBA/GL_UNSIGNED_BYTE, your GL ES implementation is allowed to convert that down to a lower-precision type. You've chosen an inappropriate tool for the job you want to do; sorry.

  6. #6
    Newbie Newbie
    Join Date
    May 2017
    Posts
    3
    Thank you for your answers,

    I think I don't have a chance. In fact the GPU that I have supports only openGL es 2.0 et openVG 1.1. So, it is made only for graphics processing not for making general purpose calculations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •