First of all I have a struct which looks like the following:
struct structName
{
vec3 position;
float radius;
float type;
...some more information which are definitely needed! Not sure how many, but most probably less than 10
};
there are like 200 of these struct elements within my scene. When rendering the scene these objects are fixed. That mean, that they don't change during rendering the scene. They only change after rendering the scene. Right now I am using a SSBO to store the elements. Inside my vertex shader (of another geometry) I am reading out all 200 struct elements, iterate over them and make a calculation. This is slowing down my shader... I am trying to improve the speed of the shader. So I am looking for a better way to read the data.
Lets talk about the limitations:
- Within the shader I NEVER change any value of any element within the struct (read only).
- All vertices within my other geometry need all 200 of these struct elements.
- The iterated calculation result for each vertex is different (has something to do with the vertex position) So the calculation can not be outsourced.
- The 200 elements will not be rendered at all. They are only information which is needed for other geometry
- Each of the 200 struct elements will be changed after each render call (60 FPS => 60 times each of the elements have been changed).
- The new values of the elements are calculated within another shader program (shader2). So they are "read only" during the render call, and "read/write" during the calculation in shader2.
- The elements need some atomic operation functions during the calculation in shader2 (atomic add).
I think to store it as a SSBO slows down my shader, because shaders are able to read/write to SSBOs so the elements are lying down on some global memory which is slow. Maybe some other buffer type is the correct one... but which one? uniform buffer objects sounds good, because uniforms are const. So maybe when using it as uniform buffer a copy will be put to a local GPU memory so that each shader instruction can access these memory faster.
Which buffer type is needed to increase the FPS of my program under these circumstances?
An alternative may be to read the whole buffer within the vertex shader at once? (not sure if this is possible) The size is already known (200 * sizeof(structName)). For me it is also okay, if the data is stored in an float array each value next to each other.
Thanks a lot!
myStructData {vec3 positionS[200]; float radiusS[200]; /*etc*/} my;
$\endgroup$