PDA

View Full Version : Can shader programs return values?



boehmi
01-13-2011, 04:58 AM
Hello,

i want to perform some matrix multiplications on the GPU with no relation to graphics rendering.
I know i can pass data to the shader with glBindBuffer and glBufferData and manipulate it there... but is it somehow possible to get data back to my program?

I thought of calling a function like "glGetBufferData" after running the shaderprogram... but i couldn't find something like this.

Is there a way to do this?

Thank you for your effort

V-man
01-13-2011, 06:21 AM
tranform feedback

or use another lib like opencl or cuda.

Dark Photon
01-13-2011, 04:46 PM
In addition to those, can render to a float texture or renderbuffer and read that back.

Are your matrices of large size? Are they sparse or dense?

It'd be worth thinking carefully about the multiply technique you use to minimize memory bandwidth. Often these kind of algs can use shared memory on the GPU to great advantage. To do so you'll need to use OpenCL or CUDA. And there's already matrix multiply code in these (CUDA at least) that you can just pick up and use.

I'd start here:

* http://www.google.com/search?q=matrix+multiply+%28cuda|opencl%29&ie=utf-8&oe=utf-8
* http://www.google.com/search?q=matrix+multiply+site%3Agpgpu.org&ie=utf-8&oe=utf-8

boehmi
01-14-2011, 05:26 AM
Hi there,

i should have said that i'm using WebGL and so there is no CUDA or something, just OpenGL2 ;)
i just want to shift some matrix multiplications from javascript to the shaders

Alfonse Reinheart
01-14-2011, 10:05 AM
just OpenGL2

There's no OpenGL 2 there either. There is OpenGL ES 2.0, but that's different from OpenGL 2.0.


i just want to shift some matrix multiplications from javascript to the shaders

Unless you are doing lots of matrix multiplications (like, tens of thousands per frame), you don't want to do this.

boehmi
01-18-2011, 08:48 AM
Yes i think the overhead for few matrix multiplications is too big...

But another use case would be to change an objects vertex model (for example with displacement mapping + height maps) and return the transformed object vertex buffer to the program