Two Dimensional Shader Storage Buffer Objects? (2DSSBO)

Hi there everyone,

I’m fairly new to OpenGLES3.1 and I’m attempting to utilise compute shaders in attempt to parallelise a conventionally serial algorithm.
I was wondering if anyone could offer any advice on the subject of SSBOs and potentially two dimensional SSBOs.

I would like my shader to take two input buffers of structs :

struct Vector2f
{
float x;
float y;
};

struct Node
{
Vector2f id;
float f;
float h;
float g;
};

layout(std140, binding = 0) buffer destBuffer
{
nodes Node;
} outBuffer;

The first buffer would consist of a few select nodes which correspond to a node in the second buffer.

I would like to take this initial node (first buffer), find its corresponding node (second buffer) and then find its adjacent nodes in the second buffer.

Once the adjacent nodes have been found I would then like to fill up a 3rd SSBO with these adjacent nodes.

[ATTACH=CONFIG]1082[/ATTACH]

That’s about it for now;

My first question would be is this at all possible?
If yes would it be possible with 2D SSBOs?
If yes how do I go about creating two dimensional SSBOs?
If not possible with 2D SSBOs what are my other options? (A 1D SSBO with an Array of Arrays perhaps?)

I hope I have explained this in enough detail, any comments would be greatly appreciated :slight_smile:

Thanks in advance.

What do you mean by a “2D SSBO”? Your buffer definition uses an unbounded array of data, which means the length is determined by the length of the buffer object you bind to it. You can’t have two dimensions which both have an unbounded length.

But if you can use SSBOs, you can use arrays of arrays. So long as you can specify the size of all but the first dimension, you can have as many dimensions as you like.

The dimension must be of course a constant expression.

I would like my shader to take two input buffers of structs :

Is there some reason you couldn’t copy/paste that text, rather than uploading a screenshot?

Thanks for your response,

I tried to keep my sample as generic as possible, so I didn’t define values, I only really posted that image to show the struct definition, I apologise for the confusion.

The reason I say 2D SSBO is because I’m trying to find out if such a thing is common or even possible, I’m very new to OpenGLES3.1 and SSBOs so I’m not sure what the best practice or approach is to achieving something similar to a Two Dimensional SSBO.

My ‘2DSSBO’ would have completely defined values depending on the complexity of my algorithm.

8 * 8 for example; giving a total of 64 nodes, working as a makeshift lookup table?
while my input buffer could have anywhere between 1 to 64 nodes. (Although this is unlikely to be the case)
further, my output buffer would be similar to that of the input buffer.

I’ve removed the image and posted quoted text instead, sincerest apologies.

I’ll attempt a method using an array of arrays like you’ve suggested thank you very much!

EDIT : My buffer definition is for my output buffer that would contain an amount of nodes proportional to the number of input nodes received.

Again I apologise if my post seems a bit flimsy I am very new to compute shaders >.<

Any sources that you could recommend would also be welcomed!

If you’re asking if an SSBO can have an 8x8 array in it, then as I stated, that would be an array of arrays. So yes, assuming you have access to that functionality.

Thank you! yes, I’ll proceed along this path :slight_smile:

Hi again,

I attempted to define a multidimensional array as follows :

and I am recieving the error ‘multidimensional arrays are not allowed’

layout(std140, binding = 0) buffer destBuffer
{
nodes Node;
}
outBuffer;

Could anyone offer any assistance ?

Additionally if there are any other locations that I could ask similar questions or read information that would help solve this issues I’d greatly appreciate suggestions.

Thanks in advance.

When I linked you to information about arrays of arrays, you would fine this sentence: “If an array can be specified without a size (such as in buffer variables), only the first array index can be unsized.” Your definition uses two unsized arrays.

Reading links is a good idea.

I have read the entire page you linked, the code snippet I posted doesn’t contain all forms of combinations I have tried.

Is the sarcasm really necessary?

I keep getting a really negative vibe from you, no offence, I’m just looking for some simple assistance.

layout(std140, binding = 0) buffer destBuffer
{
Node nodes[8];
}
outBuffer;

uniform int size;

layout(std140, binding = 0) buffer destBuffer
{
Node nodes[size];
}
outBuffer;

uniform int size;

layout(std140, binding = 0) buffer destBuffer
{
Node nodes[size];
}
outBuffer;

uniform int size;

layout(std140, binding = 0) buffer destBuffer
{
Node nodes[size][size];
}
outBuffer;

All give the same error

Maybe I am not understanding some of the terminology in the link you have posted but that is why I have come back and asked for more assistance.

I apologize if your message wasn’t sarcastic or intentionally hateful but I find it hard to look at it any other way.

Furthermore I’m making my way through several pages of documentation and searching other sources for information on the subject, I’m not some lazy guy looking to make some generic program I’m working on my thesis.

I tried to not take offence from your other two comments but I feel like the assumption that I didn’t thoroughly read the sources you linked was crossing the line :\

I sincerely apologize for wasting your time. I was just looking to be pointed in the right direction, I hesitated posting my initial question as I thought it may be a stupid one. Turns out it was.

I have read the entire page you linked, the code snippet I posted doesn’t contain all forms of combinations I have tried.

How can someone possibly know what you’ve tried… if you don’t actually post what you’ve tried?

We’re not telepathic. We have to assume that what is presented to us is what you’ve actually tried, not “some” of what you’ve tried. The linked page is very clear that [][] cannot work, it is syntactically invalid GLSL code. As this was the only case you posted, the most reasonable explanation for you to post it was that you did not know that it was syntactically invalid. Since the page made it clear that it is syntactically invalid, it stands to reason that you did not read or understand the page.

In any case, if your implementation supports arrays of arrays, then the Nodes [][8] version is the only variation (that you posted) which must work. The [size][] version cannot work (it’s even explicitly shown on the page as a failure example), but the other two size versions may or may not work, depending on what size is.

So I’ll focus on [][8].

If that failed, this suggests that your implementation doesn’t support arrays of arrays at all. SSBOs and arrays of arrays are both GL 4.3 features, so most implementations that support one ought to support the other. If you’re getting this, then here are the potential reasons for that:

  1. If your implementation does not advertise GL 4.3 or better, then you must be using SSBOs as an extension. That would require that you’re enabling the extension via #extension syntax. Thus, in order to use arrays of arrays, you must also use #extension syntax to enable it. You’d get this error if you’re enabling SSBOs but not arrays of arrays.

  2. If your implementation does not advertise GL 4.3 or better, then you must be using SSBOs and arrays of arrays as an extension. If your shader requests both, but you’re only using #extension ... enable rather than #extension ... require, then it is possible that your implementation doesn’t actually support arrays of arrays as an extension. Since you’re only using “enable”, the compilation will succeed, but emit a warning. Since your code relies on arrays of arrays, you should “require” it.

  3. If your implementation does advertise GL 4.3 or better, then your shader must use #version 430 or better to get SSBO and arrays of arrays support.

  4. If none of those apply, then it’s a driver bug.

Again I’m sincerely sorry, for being so aggressive and for not giving you this piece of information.

I’m working in OpenGLES3.1

#version 310 es

Which from your response likely doesn’t support Arrays of Arrays.

I’ll look into this myself.

Again I’m sorry, I didn’t take the vagueness of my own comment into consideration.

Actually, ES 3.1 does support arrays of arrays. So this is very much a driver bug.

Oh… that’s anti climactic

So I guess my only option is to use a 1D array and manually index as if it was 2D?

Node [8][8] becomes Node[64]

Writing to Node [2][4] becomes Node [2*8+4] / Node [20]