How to manipulate the gl_array_buffer?

Hi everyone,

I have question. May be it is weird for u guys. But I really need help here.

I have a program running in CPU. I want change it to run in GPU using open glsl. I want to send a bunch of data in array into the GPU using VBO. But I dun want to mix up the array. Means that I need to be able to differentiate the array. So, I send the array into the buffer using different ID. Something like this:


for(p=0;p<noOfpacket;p++){

		for(q=0;q<2048;q++){
			gpu_payload[q] = packet_payload[p][q];
		}
		glGenBuffersARB(1, &vboID[p]);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboID[p]);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(gpu_payload), gpu_payload, GL_STATIC_READ_ARB);

	}

After that, I want to create a shader that can parallel process those array. So, I create a function inside the shader.


void pattern_search(GLubyte *payload)

However, I have a problem here that how I manipulate those array that I had sent into the VBO just now? I send into the gl_array_buffer with different ID. But how to pass them into the function inside the shader? I am stuck here to write my shader source code. OpenGL Pro please help =.=

That’s really not how it works. You don’t just create a buffer object and have the shader read from it however it wants. Well, you can, but not by binding it to GL_ARRAY_BUFFER.

Buffer objects used as array buffers provide vertex attributes for your vertex shader.

Also, “GL_STATIC_READ” is the wrong hint to give to OpenGL. You want GL_STATIC_DRAW (meaning that you from C/C++ will write to the buffer, but not read from it).

Actually I am not going to draw it out as these data are not using for rendering display. For example, I have this kind of arrays:

array[N][2048] = { ‘a’,‘b’,‘c’,‘d’,…,‘z’}//total 2048 bytes

N = number of array

I sent the array into the vbo. I want to process each N array by using shader program. But not a rendering function inside. I just want to do some string matching since the data inside the array are simply string of characters only. Because shader program are able to process each vertex in parallel right?

So, the problems is I not really understand how the vbo locate and store the array. How I point to the address of these array?
By using the method of vbo, the array are stored in vertex?

Refer to the image I added, I have illustrate what I am doing and plan to do.

Because shader program are able to process each vertex in parallel right?

But you’re not sending vertices, are you? You’re sending string.

GLSL and OpenGL are not a general-purpose programming APIs; they are rendering APIs. If you’re interested in just using the GPU to do some arbitrary work, use OpenCL.

Is it possible to use OpenGL to do what you want? Yes. You could use put your buffer object in a buffer texture and get at it that way. But OpenCL will make doing this sort of thing much more natural.

Though honestly, the overhead of uploading the strings and downloading the results is going to make this slower than just doing string matching on the CPU. Generally, to make GPGPU worthwhile, you have to be doing something pretty substantial on the GPU.

I am sending the bytes in ascii format. So, all the value should be from 0 - 255. I know the overhead of uploading.
But somehow, I have no choice. I am forced to do this. :frowning:

I able to send the bytes into the buffer and map it out again. It is tested already even though it is slow. The problem I am having now is I not sure how to manipulate the vertex array. One way that I found is the shader since it can process each vertex in parallel.

Anyway, thanks for your reply…

But somehow, I have no choice. I am forced to do this.

I’m curious. How are you being forced to do GPU-based string comparisons?

In any case, if you want to do GPGPU through OpenGL, you have to make your processing look like rendering. It also therefore must live within the restrictions of the rendering pipeline.

The vertex shader can takes uniform values, textures, and 16 vec4 per-vertex attributes for each execution. It can output some number of per-vertex output values; with transform feedback, it can output these directly to a buffer object.

Your string array is too big to be a vertex attribute. That’s why I suggested that it should be a buffer texture. I don’t know what you would use for your actual vertex attributes, but it could be dummy data. Or an index into the buffer texture. Or whatever your needs are; you haven’t really explained exactly what algorithm you’re trying to implement.

[quote=Alfonse Reinheart]

In any case, if you want to do GPGPU through OpenGL, you have to make your processing look like rendering. It also therefore must live within the restrictions of the rendering pipeline.

The vertex shader can takes uniform values, textures, and 16 vec4 per-vertex attributes for each execution. It can output some number of per-vertex output values; with transform feedback, it can output these directly to a buffer object.

Your string array is too big to be a vertex attribute. That’s why I suggested that it should be a buffer texture. I don’t know what you would use for your actual vertex attributes, but it could be dummy data. Or an index into the buffer texture. Or whatever your needs are; you haven’t really explained exactly what algorithm you’re trying to implement.

I just use a simple string pattern matching. Just consist of if–else and loop to find the pattern.

Eg: payload[N][2048]—> N = number of packets; 2048 –> 2048 bytes of each packets.

Since vertex shader process each vertex in parallel, how I sent these array into each vertex so that I can use it to process all the vertex in parallel. So, if pattern is found, I will change all the value of that vertex to ‘0’. Then, I read it out again. Everytime I read a consequences of 2048 times of ‘0’, it means that packets has a pattern found. That is it.

By the way, u mention the my array is too big to store in the vertex attribute. So,any other way?buffer texture?

How about I create one-dimensional texture objects to store those array? Eg: If I have 100 packets, I create 100 texture objects. Then, use shader to process every texture object in parallel. will this work?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.