1

I have a matrix (for example 100x100 dimantion): I need to do calculation with each element (matrix[i,j]*tt/8+5 for example)

I have huge matrix and I want to implement the algorithm using OpenGL shaders. I want to use shader like:

uniform float val;
uniform float tt;

void main()
{
    gl_Position.x = val*tt/8+5
}

How I can implement the program? How I can get matrix after calculation(I do not want to show any windows\pictures?

7
  • 3
    This sounds like a job for a compute shader (rather than a vertex/fragment one). Compute shaders work much the same way, but they don't go through the graphics pipe. – Borgleader Aug 19 '16 at 18:20
  • 2
    I'm thinking you might be looking for CUDA or OpenCL or some such thing. – Fred Larson Aug 19 '16 at 18:22
  • I looked for OpenCL (cross-platform and cross-vendors solution), but I should have runtime in this case. It will be one more dependency. I prefer to use OpenGL directly. Because my application already has the dependency. – Mike Smirnov Aug 19 '16 at 18:31
  • Borgleader, Do you know how to get data after shaders processing in OpenGL? – Mike Smirnov Aug 19 '16 at 18:35
  • 3
    100x100 is not a "huge matrix". It would barely qualify as "big". You'd kill your performance just on having to transfer the data to the GPU and back. – Nicol Bolas Aug 19 '16 at 19:24
4

It is possible if you create a fake window frame buffer.

See my sample program where I abused the fragment Shader as a compute Shader because compute shaders are quite new. This program does some Gaussian Filtering calculations of the matrix and returns it to the CPU. (It actually does not matter what it does).

Here are few things to note:

  • the transporting of files between CPU/GPU is slow
  • other people already pointed out that your matrix is NOT huge. I consider it as very very small (it even fits in the RAM).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.