"Pohjolainen, Topi" <[email protected]> writes:

> On Wed, Nov 25, 2015 at 06:11:53PM +0100, Neil Roberts wrote:
>> On SKL in the i965 driver there is some special handling of the fast
>> clear optimisation when GL_FRAMEBUFFER_SRGB is enabled because the
>> hardware can't cope with the fast clear buffer in that case and the
>> color buffer needs to be resolved. This test just tries varies
>> different clear colors and enabling at GL_FRAMEBUFFER_SRGB at
>> different points to make sure this resolving works correctly.
>> ---
>>  tests/all.py                                       |   1 +
>>  tests/spec/arb_framebuffer_srgb/CMakeLists.gl.txt  |   1 +
>>  tests/spec/arb_framebuffer_srgb/fast-clear-blend.c | 238 
>> +++++++++++++++++++++
>>  3 files changed, 240 insertions(+)
>>  create mode 100644 tests/spec/arb_framebuffer_srgb/fast-clear-blend.c
>> 
>> diff --git a/tests/all.py b/tests/all.py
>> index ab9f181..425f301 100644
>> --- a/tests/all.py
>> +++ b/tests/all.py
>> @@ -2052,6 +2052,7 @@ with profile.group_manager(
>>         'enable-fb-srgb',
>>         'single-sample'],
>>        'fbo-fast-clear')
>> +    g(['arb_framebuffer_srgb-fast-clear-blend'])
>>  
>>  with profile.group_manager(
>>          PiglitGLTest,
>> diff --git a/tests/spec/arb_framebuffer_srgb/CMakeLists.gl.txt 
>> b/tests/spec/arb_framebuffer_srgb/CMakeLists.gl.txt
>> index 04609b8..fc1eb57 100644
>> --- a/tests/spec/arb_framebuffer_srgb/CMakeLists.gl.txt
>> +++ b/tests/spec/arb_framebuffer_srgb/CMakeLists.gl.txt
>> @@ -12,4 +12,5 @@ piglit_add_executable (arb_framebuffer_srgb-pushpop 
>> pushpop.c)
>>  piglit_add_executable (arb_framebuffer_srgb-blit blit.c)
>>  piglit_add_executable (arb_framebuffer_srgb-clear clear.c)
>>  piglit_add_executable (arb_framebuffer_srgb-srgb_conformance 
>> srgb_conformance.c)
>> +piglit_add_executable (arb_framebuffer_srgb-fast-clear-blend 
>> fast-clear-blend.c)
>>  
>> diff --git a/tests/spec/arb_framebuffer_srgb/fast-clear-blend.c 
>> b/tests/spec/arb_framebuffer_srgb/fast-clear-blend.c
>> new file mode 100644
>> index 0000000..c8fe723
>> --- /dev/null
>> +++ b/tests/spec/arb_framebuffer_srgb/fast-clear-blend.c
>> @@ -0,0 +1,238 @@
>> +/*
>> + * Copyright © 2015 Intel Corporation
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a
>> + * copy of this software and associated documentation files (the 
>> "Software"),
>> + * to deal in the Software without restriction, including without limitation
>> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
>> + * and/or sell copies of the Software, and to permit persons to whom the
>> + * Software is furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice (including the next
>> + * paragraph) shall be included in all copies or substantial portions of the
>> + * Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
>> OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
>> OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
>> + * DEALINGS IN THE SOFTWARE.
>> + */
>> +
>> +/**
>> + * \file fast-clear-blend.c
>> + *
>> + * Enables GL_FRAMEBUFFER_SRGB, clears the buffer to a color and then
>> + * blends it with a rectangle in another color before verifying the
>> + * result. This is mainly to test fast clears on SKL in the i965
>> + * driver because in that case fast clears can't be used with
>> + * GL_FRAMEBUFFER_SRGB so it internally needs to resolve the color
>> + * buffer.
>> + */
>> +
>> +#include "piglit-util-gl.h"
>> +
>> +PIGLIT_GL_TEST_CONFIG_BEGIN
>> +
>> +    config.supports_gl_compat_version = 21;
>> +    config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
>> +
>> +PIGLIT_GL_TEST_CONFIG_END
>> +
>> +static const char
>> +vertex_source[] =
>> +    "attribute vec4 piglit_vertex;\n"
>> +    "\n"
>> +    "void\n"
>> +    "main()\n"
>> +    "{\n"
>> +    "        gl_Position = piglit_vertex;\n"
>> +    "}\n";
>> +
>> +static const char
>> +fragment_source[] =
>> +    "uniform vec4 color;\n"
>> +    "\n"
>> +    "void\n"
>> +    "main()\n"
>> +    "{\n"
>> +    "        gl_FragColor = color;\n"
>> +    "}\n";
>> +
>> +static GLuint prog;
>> +static GLuint fbo;
>> +static GLint color_location;
>> +
>> +static const float
>> +clear_colors[][4] = {
>> +    { 0.0f, 0.0f, 0.0f, 0.0f },
>> +    { 1.0f, 1.0f, 1.0f, 1.0f },
>> +    { 0.0f, 0.0f, 1.0f, 0.0f },
>> +    { 1.0f, 0.0f, 0.0f, 1.0f },
>> +
>> +    { 0.25f, 0.5f, 0.75f, 1.0f },
>> +    { 0.75f, 0.5f, 0.25f, 0.0f },
>> +    { 0.5f, 0.25f, 0.75f, 0.5f },
>> +};
>> +
>> +static bool
>> +probe_srgb_color(int x, int y, int w, int h,
>> +             const GLfloat *color)
>> +{
>> +    GLfloat srgb_color[4];
>> +    int i;
>> +
>> +    /* The value in the framebuffer is stored in SRGB space so we
>> +     * need to convert to that.
>> +     */
>> +    for (i = 0; i < 3; i++)
>> +            srgb_color[i] = piglit_linear_to_srgb(color[i]);
>> +    srgb_color[3] = color[3];
>> +
>> +    return piglit_probe_rect_rgba(x, y, w, h, srgb_color);
>> +}
>> +
>> +static bool
>> +test_color(bool srgb_before_clear,
>> +       const GLfloat *clear_color)
>> +{
>> +    static const GLfloat rect_color[] = {
>> +            0.0f, 0.75f, 1.0f, 0.5f
>> +    };
>> +    GLfloat expected_color[4];
>> +    GLfloat fb_color;
>> +    bool pass = true;
>> +    int i;
>> +
>> +    printf("Clear to %f,%f,%f,%f - SRGB enabled %s clear\n",
>> +           clear_color[0],
>> +           clear_color[1],
>> +           clear_color[2],
>> +           clear_color[3],
>> +           srgb_before_clear ? "before" : "after");
>> +
>> +    if (srgb_before_clear)
>> +            glEnable(GL_FRAMEBUFFER_SRGB);
>> +
>> +    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
>> +    glClearColor(clear_color[0],
>> +                 clear_color[1],
>> +                 clear_color[2],
>> +                 clear_color[3]);
>> +    glClear(GL_COLOR_BUFFER_BIT);
>> +
>> +    if (!srgb_before_clear)
>> +            glEnable(GL_FRAMEBUFFER_SRGB);
>> +
>> +    glUseProgram(prog);
>> +    glUniform4fv(color_location, 1, rect_color);
>> +
>> +    glEnable(GL_BLEND);
>> +    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
>> +
>> +    /* Blend a rectangle into the right-hand half of the framebuffer */
>> +    piglit_draw_rect(0.0f, -1.0f, 1.0f, 2.0f);
>> +
>> +    glDisable(GL_BLEND);
>> +    glDisable(GL_FRAMEBUFFER_SRGB);
>> +
>
> Below we check the pixel values in the left-hand side, this is to check that
> the blending (and hence the implied resolving of the buffer) in the
> right-hand side didn't alter the values in the left-hand side, right? If so,
> perhaps a small comment?

Yes that's right. Ok, yes, a comment sounds sensible.

>> +enum piglit_result
>> +piglit_display()
>> +{
>> +    bool pass = true;
>> +    int srgb_before_clear;
>> +    int i;
>> +
>> +    for (srgb_before_clear = 0;
>> +         srgb_before_clear < 2;
>> +         srgb_before_clear++) {
>> +            for (i = 0; i < ARRAY_SIZE(clear_colors); i++) {
>> +                    pass = test_color(srgb_before_clear,
>> +                                      clear_colors[i]) && pass;
>> +            }
>> +    }
>
> Iterating over false-true looks a little strange. Could we just open code
> the two cases? Or perhaps:
>
>         for (i = 0; i < ARRAY_SIZE(clear_colors); i++) {
>                 pass = test_color(false, clear_colors[i]) && pass;
>                 pass = test_color(true, clear_colors[i]) && pass;
>         }

Yes, that looks much better. I'll take your suggestion.

Thanks again.

- Neil
_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to