SSBO access

Hi, this may be a rather specific question, but I need to access some structure on my fragment shader and write fragment information to it and then be able to read from that same structure on a second shader pass that will do raycasting on that fragment structure. This structure must be the size of 1280720AVGDEPTHCOMPLEXITY times 3 floats for position, 3 floats for normal, 1 integer for material index, 1 integer for previous node index (I think this is all). The AVGDEPTHCOMPLEXITY might be a fixed value. This structure will essentially have nodes linked to one another composing up to 1280*720 linked lists. Is SSBO the structure I am looking for? (I believe I won’t need to write or read from the CPU)

You can’t count on an SSBO being large enough, even if AVGDEPTHCOMPLEXITY is only one. The minimum required value of GL_MAX_SHADER_STORAGE_BLOCK_SIZE is 224 = 16 MiB, while you require 12807208*4 = ~28 MiB multiplied by AVGDEPTHCOMPLEXITY.

Using writeable (“image”) textures may be preferable. E.g. 3 * 3D (or 2D-array) textures (2GL_RGB32F plus 1GL_RG32UI), each of size 1280720AVGDEPTHCOMPLEXITY. AFAICT, any 4.2 implementation is required to support that combination (constrained only by memory availability). Also, image textures only require 4.2, SSBOs require 4.3.

[QUOTE=GClements;1255996]You can’t count on an SSBO being large enough, even if AVGDEPTHCOMPLEXITY is only one. The minimum required value of GL_MAX_SHADER_STORAGE_BLOCK_SIZE is 224 = 16 MiB, while you require 12807208*4 = ~28 MiB multiplied by AVGDEPTHCOMPLEXITY.

Using writeable (“image”) textures may be preferable. E.g. 3 * 3D (or 2D-array) textures (2GL_RGB32F plus 1GL_RG32UI), each of size 1280720AVGDEPTHCOMPLEXITY. AFAICT, any 4.2 implementation is required to support that combination (constrained only by memory availability). Also, image textures only require 4.2, SSBOs require 4.3.[/QUOTE]

I would prefer a 1D array since I am doing several interleaved linked lists, a 3D array would be allocating a fixed size for the linked lists if it was 1280x720xAVGDEPTHCOMPLEXITY. I need array[1280720AVGDEPTHCOMPLEXITY] instead of 3Darray[1280][720][AVGDEPTHCOMPLEXITY]. I am working with 4.3 and not looking for backward compatibility. Also, I may need atomic operations since GPU kernels are going to look at this shared memory structure at the same time.

As for the data I need per linked node: 3 floats for position, 3 floats for normal, minimum of 4 bits for material ID, 1 float for depth and 1 uint for pointer. Maybe I can encode depth and material ID together, say 24-bit depth and 8-bit uint.

Also, according to this guy, SSBOs have the highest minimum MAX SIZE value, 16MB, while Buffer Textures only have 64KB. And I’ve heard most high-end GPUs have the SSBO size limited only by VRAM. I have 2GB VRAM on each card, but I will need one of them to build those structures only, the other one to raycast those structures, which means they will probably be replicated on each of the GPU’s VRAM, right?

Can I set up the SSBO, then render a scene using 1 shader program, discarding all fragments, then render a quad with a second shader program using that SSBO to fetch some data?

Another question, but maybe I should make a new topic since this one might be more advanced and interesting to answer: Is it possible to make a fragment shader output a list of vertices to go through a second shader’s rasterization phase?