PDA

View Full Version : Many Textures with Shader Question



registerme
12-01-2011, 03:18 PM
We want to do some filtering on an input frame utilizing the shader's processing power. The frame is partitioned equally into 16x8 partitions. Each partition will have different parameters to do the filtering. On the edge of the partition, we need to repeat the edge pixels as if the edge pixel is extended out of edge. The outputs of each partition are put back together as the output frame. The easiest way is to pass individual partition as a texture with its parameters to the shader. But there are several problems:

1. Passing 16x8 textures to process one frame seems to be less efficient
2. Each partition's data need to be re-arranged so that it can be passed as texture. Because the texture data has to be continuous without line stride/span, we can not give the texture without the data outside of the partition in the input frame.
3. When each partition is processed, we need to put it back into the target frame.

Another way is, of course, just pass in the whole frame as one texture and process the partition logic inside the shader. That will require passing in the set of parameters for each partition to the shader, and the edge repeat logic can not be automatically done as if it were individual textures.

Is there a better way to do this?

BionicBytes
12-01-2011, 03:59 PM
You may be able to pass each segment as a layer of a texture array. Perhaps pass the uniform data in as a uniform array so that each slice of the array has a corresponding array entry in the uniform array. Alternitevly the uniform data could be put into uniform buffer object or texture buffer object if there are size limitations with uniform arrays.

registerme
12-01-2011, 05:34 PM
Sorry I don't quite understand what is "a layer of texture array". If an array of texture can be passed in, does that mean I can pass 16x8=128 textures to the shader?

And what is the alternative way of using using uniform data? Are you talking about each partition's data or the parameters for each partition I was talking about? For the latter, each partition has limited number of parameters, say 16, which I can pass in as a uniform array, I suppose.

I am using OpenGL ES so I am not sure if any of these are supported.

BionicBytes
12-02-2011, 02:05 AM
Sorry I don't quite understand what is "a layer of texture array". If an array of texture can be passed in, does that mean I can pass 16x8=128 textures to the shader?
You have heard of 3DTextures? A texture array is an extension to OpenGL 2.1 and core in OpenGL 3.0. It's very similar conceptually to a 3D texture in that it's a series of textures presented to OpenGL as a single texture object. You access the image you need via the 3rd texture coordinate.

Each partition's data need to be re-arranged so that it can be passed as textureWell you can pass that in as a texture, or that and the parameters for each partition could be bundled up into a uniform buffer object or texture buffer object.
Read up on those and see if they could be used for your needs.

I am using OpenGL ES so I am not sure if any of these are supported.Perhaps you could have mentioned that at the start?
You'll have to check if ARB_TEXTURE_ARRAY or ARB_TEXTURE_BUFFER_OBJECT or ARB_UNIFORM_BUFFER_OBJECT (or EXT_ variants) are available on ES. Which version BTW?

registerme
12-02-2011, 02:30 PM
It's OpenGL ES 2.0 and the shading language is glsl, GPU is Mali-400MP.

I can probably loose the number of partitions to just 8, but a practical problem is still how I pass it in from the input frame which has a bigger dimension than the partition. Here the input frame is just an array of pixel values. If the input frame is a texture, can I get a sub-region of it so that I can create the partition texture?

If I pass the whole frame in as one texture, and do the partition logic inside the shader, I will have to do the edge repeat on each partition edge. For example, the shader code needs to access pixels out of the partition boundary and if it is outside the boundary, the pixel will be the same value as the edge pixel. This is automatically done if I pass each partition in as a texture with the texture wrap setup correctly.

I guess texture array, uniform buffer object and texture buffer object are not available on my platform. From the OpenGL ES 2.0 book, I did not find any information about it.