How to read vertex array in vertex shader?

Started by
5 comments, last by SagoO 13 years, 1 month ago
Hi,

I have a program which will send thousands of array with size 2048 bytes each array. I uses VBO here.


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

for(q=0;q<2048;q++){
gpu_payload[q] = packet_payload

[q];
}
glGenBuffersARB(1, &vboID

);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboID

);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(gpu_payload), gpu_payload, GL_STATIC_DRAW_ARB);

}



After I send the data into the buffer, I want to process each of the array by using vertex shader. How to manipulate the vertex array in lower level?
Is it the vertex shader able to process each buffer object in parallel? That is what I want to reach.

Help please =.=
Advertisement
Not sure what your trying to do here so i am gonna give as a general answer as i can
The vertex shader can't process all the buffer objects in paralell, but it does process each vertex in parallel (spread across the available shader units on your graphics card), also you can't directly manipulate the buffers, just whatever output you decide to render.
You can however use the transform feedback mode that will pass a vertex buffer trough the vertex and geometry shader and return it to another buffer.
Also using separate vertex buffers like that seems like a waste, try to pack several packets into one buffer, you should be able to fit at least 30 in each.
If there is anything specific you want to know then please give a more detailed description of what you want to do.

Not sure what your trying to do here so i am gonna give as a general answer as i can
The vertex shader can't process all the buffer objects in paralell, but it does process each vertex in parallel (spread across the available shader units on your graphics card), also you can't directly manipulate the buffers, just whatever output you decide to render.
You can however use the transform feedback mode that will pass a vertex buffer trough the vertex and geometry shader and return it to another buffer.
Also using separate vertex buffers like that seems like a waste, try to pack several packets into one buffer, you should be able to fit at least 30 in each.
If there is anything specific you want to know then please give a more detailed description of what you want to do.




Thanks for you reply. Okay..I explain more detail about my project. I am doing the simple deep packet inspection on the payload of the packet by using CPU and GPU. I will getting all the packets in one time.Then, send the packets into the buffer. I already have the algorithm to do the pattern matching in CPU using if--else statement and looping only. What I am doing was just a simple string matching. So, I store all the packets into 2-dimensional array. Eg: payload[N][2048]---> N = number of packets; 2048 --> 2048 bytes of each packets.

Since you say 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.

actually in that case i think it might be better to put all the packets in a 2048xN texture instead as it would allow you to access every packet in the fragment shader, then all you just render a line or a quad matching the output you like (you take it's coordinates and use it on the texture in one or more axis) and finally use glReadPixels to get the data.

actually in that case i think it might be better to put all the packets in a 2048xN texture instead as it would allow you to access every packet in the fragment shader, then all you just render a line or a quad matching the output you like (you take it's coordinates and use it on the texture in one or more axis) and finally use glReadPixels to get the data.



[font="Arial"]Do you means texture buffer? I dun wan to render any display. [size=2]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?[/font]


[font="Arial"]Do you means texture buffer? I dun wan to render any display. 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?[/font]


no just a plain old texture, you can use an FBO to render to, that way you don't have to have any output.
A 1 dimensional array could work but it's far easier to just cram it into a 2048x2048 texture, that way you have packets in one dimension and the data in one, what works best depends on exactly your algorithm, but that is something you have to find out for yourself.

Another thing to try could be either Cuda or openCL as they are more adept to this kind of work.

no just a plain old texture, you can use an FBO to render to, that way you don't have to have any output.
A 1 dimensional array could work but it's far easier to just cram it into a 2048x2048 texture, that way you have packets in one dimension and the data in one, what works best depends on exactly your algorithm, but that is something you have to find out for yourself.

Another thing to try could be either Cuda or openCL as they are more adept to this kind of work.


Ya.I know about Cuda and openCL. I would like to try them if my budget is allowed. =.=

However, my only choice is to use openGL.

Back to topic-->

In short, I create a 2048x2048 textures. I initialize all the textures values = 1. After that, I pass the data into the texture accordingly. Send the texture into buffer.Those with value = 1 definitely is not my data so that I can recognize it.

I process the texture line by line in parallel. Those line with pattern found I change the value to 0. After that, I map out the whole texture to CPU and read it again. Then, I would know which data has pattern matched.

So that is the program flow I expect. However, I not sure what kind of function and concept should be used.

May be I try to use texture buffer object?However, how I manipulate the value of texture that had sent into the buffer object in shader program?

Eg:

I have this texture --> texture[2048]2048] = {...};

In CPU, I jz use if else and loop to search for pattern. After I send tis into the buffer, how I program the shader ? How I use the texture value again since I have to compare the value of the texture.

Eg:

for(int i = 0;i<2048;i++){
for(int j=0;j<2048;j++){

if( texture[j] = 12)
//do sth;
}
}

How i perform this task in the shader program since I cannot use texture[j] anymore. I really get mad with this....

This topic is closed to new replies.

Advertisement