Shader doesn't write the fragment color in the second pass

Ha ok I forgot to declare the struct of my SSBO in the second shader so this is why it doesn’t compile.

Ok for the problem why it’s always display the color of the first sprite I’ve found why, it’s a bug in the mesa driver, the driver update the window content each time a pixel is drawn, but several pixel can be drawn at the same time at each window’s positions, so I’ve to modify the driver source code to make a list of each pixels to drawn, withdrawn a pixel of the list each time a pixel is drawn and update the window’s content one the list is empty.

I’ve to check where to put this on the driver source code and recompile it!
But it’s not easy, there are a lot of files.

I think I’ve fixed the bug, but I’m not sure, I have still to recompile the driver to test.

Mesa 3D loads the shader byte code to the video RAM from the first instruction to the last, but I think once the first instruction is copied (the boot), it initialize the increment register to go to the next instruction address, or, I think the GPU doesn’t wait that next instructions are copied, before going to the second instruction address. So I loaded the instructions from the last to the first, so all instructions are guarantee to be copied, until the boot is copied and so the shader byte code starts to execute once everything is copied.
(but I’m not sure, I don’t know how my GPU works and MESA use buffer rings, I don’t know what it is, maybe it makes already this work, so I tried to guess how to hardware works)

Or maybe there is an ASM instruction to initialize a register to start the shader program, but, I didn’t found one in the MESA source code.
But if this trick doesn’t works, I stop using shader because they doesn’t work with mesa3D. :confused:

Ok I can’t find out why that doesn’t works. I think I’ll have to make my own driver to understand why that doesn’t work.
I’ve send a bug report to mesa 3D but a guy said that it was not their bug.

Ok it’s seems I need to copy the per pixel linked list here otherwise it doesn’t work, I don’t know why :

const std::string fragmentShader2 =
               R"(
               #version 140
               #extension GL_ARB_shader_atomic_counters : require
               #extension GL_ARB_shading_language_420pack : require
               #extension GL_ARB_shader_image_load_store : require
               #extension GL_ARB_shader_storage_buffer_object : require
               #define MAX_FRAGMENTS 75
               struct NodeType {
                  vec4 color;
                  float depth;
                  uint next;
               };
               layout(binding = 0, r32ui) uniform uimage2D headPointers;
               layout(binding = 0, std430) buffer linkedLists {
                   NodeType nodes[];
               };
               void main() {
                  NodeType frags[MAX_FRAGMENTS];
                  NodeType frags2[MAX_FRAGMENTS];
                  int count = 0;
                  uint n = imageLoad(headPointers, ivec2(gl_FragCoord.xy)).r;
                  while( n != uint(0xffffffff) && count < MAX_FRAGMENTS) {
                       frags[count] = nodes[n];
                       frags2[count] = nodes[n];
                       n = frags[count].next;
                       count++;
                  }
                 for (int i = 0; i < count-1; i++) {
                    for (int j = i+1; j < count; j++) {
                        if (frags2[i].depth > frags2[j].depth) {
                            NodeType tmp = frags2[i];
                            frags2[i] = frags2[j];
                            frags2[j] = tmp;
                        }
                    }
                  }
                  vec4 dstcolor = vec4(0, 0, 0, 0);
                  for (int i = 0; i < count; i++) {
                    vec4 srccolor = frags2[i].color;
                    dstcolor = vec4(srccolor.rgb * srccolor.a + dstcolor.rgb * (1 - srccolor.a), srccolor.a + dstcolor.a * (1 - srccolor.a));
                  }
                  gl_FragColor = dstcolor;

But I’ve another problem now, there is no transparency…, it’s like if the color.a value is always equal to 1.

It’s ok it works, but I don’t understand why, I’ve just draw the vertexarray instead of a fullscreen quad.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.