<div dir="ltr">Ah I see what you mean now, thank you for taking the time to explain, I'll make that change :)<div><br></div><div>Thanks,</div><div>Pam</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 24, 2017 at 11:30 PM, Nicolai Hähnle <span dir="ltr"><<a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Plamena,<br>
<br>
On <a href="tel:24.04.2017%2023" value="+12404201723" target="_blank">24.04.2017 23</a>:04, Manolova, Plamena wrote:<br>
[snip]<span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
        +       static const char *fs_text =<br>
        +               "#version 430\n"<br>
        +               "#extension GL_ARB_fragment_shader_interlo<wbr>ck:<br>
        require\n"<br>
        +               "layout(sample_interlock_orde<wbr>red) in;\n"<br>
<br>
<br>
    Since the shader writes to per-pixel data, it needs to be<br>
    pixel_interlock_ordered. Otherwise, there might be a race between<br>
    shader invocations that affect the same pixel but disjoint sets of<br>
    samples (i.e. along the seams between triangles).<br>
<br>
<br>
Actually this test cares only about the data written to image3D<br>
img_output  which stores data on a per-sample basis (with the z<br>
coordinate being the sample number), so we actually want<br>
sample_interlock_ordered.<br>
</blockquote>
<br></span>
The last plane/slice of img_output contains the per-pixel average over all samples.<br>
<br>
So I'm concerned about the following scenario of two invocations operating on different samples of the same pixel and interleaving as follows:<br>
<br>
Invocation 1                       Invocation 2<br>
------------                       ------------<br>
Write current-sample data<br>
Read and average all samples<br>
                                   Write current-sample data<br>
                                   Read and average all samples<br>
                                   Write per-pixel data<br>
Write per-pixel data<br>
<br>
Invocation 1 will produce the final per-pixel data, but won't take into account the per-sample data written by Invocation 2. This particular issue is fixed by using any of the pixel_interlock_* modes.<br>
<br>
Thanks,<br>
Nicolai<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
<br>
        +               "layout(rgba32f, binding = 0) uniform image3D<br>
        img_output;\n"<br>
        +               "layout(location = 1) uniform int sample_rate;\n"<br>
        +               "smooth in vec4 col_vary;\n"<br>
        +               "out vec4 col_out;\n"<br>
        +               "void main()\n"<br>
        +               "{\n"<br>
        +               "       vec4 result = vec4(0.0, 0.0, 0.0, 1.0);\n"<br>
        +               "       ivec3 current_sample_coord =<br>
        ivec3(gl_FragCoord.x, gl_FragCoord.y, gl_SampleID);\n"<br>
        +               "       ivec3 result_coord =<br>
        ivec3(gl_FragCoord.x, gl_FragCoord.y, sample_rate);\n"<br>
        +               "       int i;\n"<br>
        +               "       beginInvocationInterlockARB()<wbr>;\n"<br>
        +               "       vec4 current_sample_color =<br>
        imageLoad(img_output, current_sample_coord);\n"<br>
        +               "       result.rgb += col_vary.a * col_vary.rgb<br>
        + (1 - col_vary.a) * current_sample_color.rgb;\n"<br>
        +               "       imageStore(img_output,<br>
        current_sample_coord, result);\n"<br>
        +               "\n"<br>
        +               "       for (i = 0; i < sample_rate; i++) {\n"<br>
        +               "               if (i != gl_SampleID) {\n"<br>
        +               "                       ivec3 sample_coord =<br>
        ivec3(gl_FragCoord.x, gl_FragCoord.y, i);\n"<br>
        +               "                       vec4 sample_color =<br>
        imageLoad(img_output, sample_coord);\n"<br>
        +               "                       result.rgb +=<br>
        sample_color.rgb;\n"<br>
        +               "               }\n"<br>
        +               "       }\n"<br>
        +               "       result.rgb /= sample_rate;\n"<br>
        +               "       imageStore(img_output, result_coord,<br>
        result);\n"<br>
        +               "       endInvocationInterlockARB();\<wbr>n"<br>
        +               "       col_out = result;\n"<br>
        +               "}\n";<br>
        +<br>
        +       GLuint prog;<br>
        +<br>
        +       prog = piglit_build_simple_program(vs<wbr>_text, fs_text);<br>
        +       glUseProgram(prog);<br>
        +<br>
        +       glBindAttribLocation(prog, 0, "pos_in");<br>
        +       glBindAttribLocation(prog, 1, "col_in");<br>
        +<br>
        +       glLinkProgram(prog);<br>
        +<br>
        +       if (!piglit_check_gl_error(GL_NO_<wbr>ERROR)) {<br>
        +               piglit_report_result(PIGLIT_F<wbr>AIL);<br>
        +       }<br>
        +<br>
        +       return prog;<br>
        +}<br>
        +<br>
        +static GLuint<br>
        +make_texture_buffer(void)<br>
        +{<br>
        +       GLuint tex;<br>
        +<br>
        +       glGenTextures(1, &tex);<br>
        +       glBindTexture(GL_TEXTURE_2D_M<wbr>ULTISAMPLE, tex);<br>
        +       glTexImage2DMultisample(GL_TE<wbr>XTURE_2D_MULTISAMPLE, 2,<br>
        +               GL_RGBA32F, piglit_width, piglit_height, false);<br>
        +       glBindTexture(GL_TEXTURE_2D_M<wbr>ULTISAMPLE, tex);<br>
        +<br>
        +       return tex;<br>
        +}<br>
        +<br>
        +static GLuint<br>
        +make_texture_blend(void)<br>
        +{<br>
        +       GLuint tex;<br>
        +<br>
        +       glGenTextures(1, &tex);<br>
        +       glActiveTexture(GL_TEXTURE0);<br>
        +       glBindTexture(GL_TEXTURE_3D, tex);<br>
        +       glTexParameteri(GL_TEXTURE_<wbr>3D, GL_TEXTURE_WRAP_S,<br>
        GL_CLAMP_TO_EDGE);<br>
        +       glTexParameteri(GL_TEXTURE_<wbr>3D, GL_TEXTURE_WRAP_T,<br>
        GL_CLAMP_TO_EDGE);<br>
        +       glTexParameteri(GL_TEXTURE_<wbr>3D, GL_TEXTURE_MAG_FILTER,<br>
        GL_LINEAR);<br>
        +       glTexParameteri(GL_TEXTURE_<wbr>3D, GL_TEXTURE_MIN_FILTER,<br>
        GL_LINEAR);<br>
        +       glBindImageTexture(0, tex, 0, GL_TRUE, 0, GL_READ_WRITE,<br>
        GL_RGBA32F);<br>
        +<br>
        +       return tex;<br>
        +}<br>
        +<br>
        +static GLuint<br>
        +make_vao(void)<br>
        +{<br>
        +       static const float pos_col[18][6] = {<br>
        +               { -1.0, -1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               {  0.0, -1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               {  0.0,  1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               {  0.0,  1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               { -1.0,  1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               { -1.0, -1.0, 0.0, 1.0, 0.0, 0.25 },<br>
        +               { -1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               {  1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               {  1.0,  1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               {  1.0,  1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               { -1.0,  1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               { -1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },<br>
        +               { -1.0, -1.0, 0.0, 0.0, 1.0, 0.25 },<br>
        +               {  1.0, -1.0, 0.0, 0.0, 1.0, 0.25 },<br>
        +               {  1.0,  1.0, 0.0, 0.0, 1.0, 0.25 },<br>
        +               {  1.0,  1.0, 0.0, 0.0, 1.0, 0.25 },<br>
        +               { -1.0,  1.0, 0.0, 0.0, 1.0, 0.25 },<br>
        +               { -1.0, -1.0, 0.0, 0.0, 1.0, 0.25 }<br>
        +       };<br>
        +<br>
        +       const int stride = sizeof(pos_col[0]);<br>
        +       GLuint vbo, vao;<br>
        +<br>
        +       glGenVertexArrays(1, &vao);<br>
        +       glBindVertexArray(vao);<br>
        +<br>
        +       glGenBuffers(1, &vbo);<br>
        +       glBindBuffer(GL_ARRAY_BUFFER, vbo);<br>
        +       glBufferData(GL_ARRAY_BUFFER, sizeof(pos_col), pos_col,<br>
        GL_STATIC_DRAW);<br>
        +<br>
        +       glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride,<br>
        (void *) 0);<br>
        +       glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, stride,<br>
        +               (void *)(sizeof(float) * 2));<br>
        +<br>
        +       glEnableVertexAttribArray(0);<br>
        +       glEnableVertexAttribArray(1);<br>
        +<br>
        +       if (!piglit_check_gl_error(GL_NO_<wbr>ERROR)) {<br>
        +               piglit_report_result(PIGLIT_F<wbr>AIL);<br>
        +       }<br>
        +<br>
        +       return vao;<br>
        +}<br>
        +<br>
        +void<br>
        +piglit_init(int argc, char **argv)<br>
        +{<br>
        +<br>
         piglit_require_extension("GL_<wbr>ARB_fragment_shader_interlock"<wbr>);<br>
        +<br>
        +       glEnable(GL_MULTISAMPLE);<br>
        +       glDisable(GL_CULL_FACE);<br>
        +       glClearColor(0.0, 0.0, 0.0, 1.0);<br>
        +<br>
        +       prog = make_shader_program();<br>
        +       vao = make_vao();<br>
        +       tex_frame = make_texture_buffer();<br>
        +       fbo = make_fbo();<br>
        +       tex_blend = make_texture_blend();<br>
        +}<br>
        +<br>
        +enum piglit_result<br>
        +piglit_display(void)<br>
        +{<br>
        +       int samples[4] = { 2, 4, 8, 16 };<br>
        +       bool pass = true;<br>
        +       uint i, j, k, l;<br>
        +       uint result1[4] = { 47, 35, 63, 255 };<br>
        +       uint result2[4] = { 47, 0, 63, 255 };<br>
        +<br>
        +       glViewport(0, 0, piglit_width, piglit_height);<br>
        +<br>
        +       for (i = 0; i < 4; i++) {<br>
        +               GLfloat *tex_data = calloc(piglit_width *<br>
        piglit_height *<br>
        +                       (samples[i] + 1) * 4, sizeof(GLfloat));<br>
        +<br>
        +               glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F,<br>
        piglit_width, piglit_height,<br>
        +                       samples[i] + 1, 0, GL_RGBA, GL_FLOAT,<br>
        tex_data);<br>
<br>
<br>
    Iterations should be skipped when the given number of samples is not<br>
    supported.<br>
<br>
<br>
        +<br>
        +               glBindFramebuffer(GL_DRAW_FRA<wbr>MEBUFFER, fbo);<br>
        +               glBindTexture(GL_TEXTURE_2D_M<wbr>ULTISAMPLE, tex_frame);<br>
        +<br>
         glTexImage2DMultisample(GL_TE<wbr>XTURE_2D_MULTISAMPLE, samples[i],<br>
        +                       GL_RGBA8, piglit_width, piglit_height,<br>
        false);<br>
        +               glUniform1i(1, samples[i]);<br>
        +<br>
        +               glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |<br>
        +                       GL_STENCIL_BUFFER_BIT);<br>
        +<br>
        +               glUseProgram(prog);<br>
        +               glDrawArrays(GL_TRIANGLES, 0, 18);<br>
        +<br>
        +               glBindFramebuffer(GL_DRAW_FRA<wbr>MEBUFFER, 0);<br>
        +               glBindFramebuffer(GL_READ_FRA<wbr>MEBUFFER, fbo);<br>
        +               glDrawBuffer(GL_BACK);<br>
        +               glBlitFramebuffer(0, 0, piglit_width,<br>
        piglit_height, 0, 0, piglit_width,<br>
        +                       piglit_height, GL_COLOR_BUFFER_BIT,<br>
        GL_NEAREST);<br>
<br>
<br>
    Maybe add piglit_check_gl_error?<br>
<br>
    Cheers,<br>
    Nicolai<br>
<br>
<br>
<br>
        +               piglit_present_results();<br>
        +<br>
        +               glGetTexImage(GL_TEXTURE_3D, 0, GL_RGBA,<br>
        GL_FLOAT, tex_data);<br>
        +               for (j = 0; j < samples[i] + 1; j++) {<br>
        +                       for (k = 0; k < piglit_height; k++) {<br>
        +                               for (l = 0; l < piglit_width; l++) {<br>
        +                                       uint m = ((piglit_width<br>
        * piglit_height * j) +<br>
        +                                               (k *<br>
        piglit_width) + l) * 4;<br>
        +                                       uint r =<br>
        fabs(tex_data[m]) * 255;<br>
        +                                       uint g = fabs(tex_data[m<br>
        + 1]) * 255;<br>
        +                                       uint b = fabs(tex_data[m<br>
        + 2]) * 255;<br>
        +                                       uint a = fabs(tex_data[m<br>
        + 3]) * 255;<br>
        +<br>
        +                                       if ((l < piglit_width /<br>
        2) && (r != result1[0] ||<br>
        +                                                 g !=<br>
        result1[1] || b != result1[2] || a != result1[3])) {<br>
        +                                               printf("observed<br>
        %u %u %u     %u %u %u %u\n", j, k, l, r,<br>
        +                                                       g, b, a);<br>
        +                                               printf("expected<br>
        %u %u %u     %u %u %u %u\n", j, k, l,<br>
        +                                               result1[0],<br>
        result1[1], result1[2], result1[3]);<br>
        +                                               pass = false;<br>
        +                                               break;<br>
        +                                       }<br>
        +<br>
        +                                       if ((l > piglit_width /<br>
        2) && (r != result2[0] ||<br>
        +                                                 g !=<br>
        result2[1] || b != result2[2] || a != result2[3])) {<br>
        +                                               printf("observed<br>
        %u %u %u     %u %u %u %u\n", j, k, l, r,<br>
        +                                                       g, b, a);<br>
        +                                               printf("expected<br>
        %u %u %u     %u %u %u %u\n", j, k, l,<br>
        +<br>
         result1[0], result1[1], result1[2], result1[3]);<br>
        +                                               pass = false;<br>
        +                                               break;<br>
        +                                       }<br>
        +                               }<br>
        +                               if (!pass)<br>
        +                                       break;<br>
        +                       }<br>
        +                       if (!pass)<br>
        +                               break;<br>
        +               }<br>
        +<br>
        +               free(tex_data);<br>
        +               pass = piglit_check_gl_error(GL_NO_ER<wbr>ROR) && pass;<br>
        +               if (!pass)<br>
        +                       break;<br>
        +       }<br>
        +<br>
        +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
        +}<br>
<br>
<br>
<br>
    --<br>
    Lerne, wie die Welt wirklich ist,<br>
    Aber vergiss niemals, wie sie sein sollte.<br>
<br>
<br>
</blockquote>
<br>
<br>
-- <br>
Lerne, wie die Welt wirklich ist,<br>
Aber vergiss niemals, wie sie sein sollte.<br>
</div></div></blockquote></div><br></div>