[Mesa-dev] [PATCH 1/2] mesa: add support for GL_INTEL_conservative_rasterization

Ilia Mirkin imirkin at alum.mit.edu
Wed Dec 7 17:20:40 UTC 2016


On Wed, Dec 7, 2016 at 12:04 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Wed, Dec 7, 2016 at 10:31 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
>> On Wed, Dec 7, 2016 at 10:25 AM, Lionel Landwerlin
>> <lionel.g.landwerlin at intel.com> wrote:
>>> On 07/12/16 14:55, Ilia Mirkin wrote:
>>>>
>>>> On Thu, Dec 1, 2016 at 10:56 AM, Lionel Landwerlin
>>>> <lionel.g.landwerlin at intel.com> wrote:
>>>>>
>>>>> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
>>>>> ---
>>>>>   src/compiler/glsl/ast.h                  |  5 ++++
>>>>>   src/compiler/glsl/ast_to_hir.cpp         |  5 ++++
>>>>>   src/compiler/glsl/ast_type.cpp           | 16 +++++++++++-
>>>>>   src/compiler/glsl/glsl_parser.yy         | 34
>>>>> ++++++++++++++++++++++----
>>>>>   src/compiler/glsl/glsl_parser_extras.cpp |  4 +++
>>>>>   src/compiler/glsl/glsl_parser_extras.h   |  4 +++
>>>>>   src/compiler/glsl/linker.cpp             |  3 +++
>>>>>   src/compiler/shader_info.h               |  6 +++++
>>>>>   src/mesa/main/api_validate.c             | 42
>>>>> ++++++++++++++++++++++++++++++++
>>>>>   src/mesa/main/enable.c                   | 12 +++++++++
>>>>>   src/mesa/main/extensions_table.h         |  1 +
>>>>>   src/mesa/main/mtypes.h                   |  3 +++
>>>>>   src/mesa/main/shaderapi.c                |  1 +
>>>>>   13 files changed, 130 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
>>>>> index df3a744..0e32c36 100644
>>>>> --- a/src/compiler/glsl/ast.h
>>>>> +++ b/src/compiler/glsl/ast.h
>>>>> @@ -610,6 +610,11 @@ struct ast_type_qualifier {
>>>>>             * Flag set if GL_ARB_post_depth_coverage layout qualifier is
>>>>> used.
>>>>>             */
>>>>>            unsigned post_depth_coverage:1;
>>>>> +         /**
>>>>> +          * Flag set if GL_INTEL_conservartive_rasterization layout
>>>>> qualifier
>>>>> +          * is used.
>>>>> +          */
>>>>> +         unsigned inner_coverage:1;
>>>>>         }
>>>>>         /** \brief Set of flags, accessed by name. */
>>>>>         q;
>>>>> diff --git a/src/compiler/glsl/ast_to_hir.cpp
>>>>> b/src/compiler/glsl/ast_to_hir.cpp
>>>>> index 2434ce5..1e14d27 100644
>>>>> --- a/src/compiler/glsl/ast_to_hir.cpp
>>>>> +++ b/src/compiler/glsl/ast_to_hir.cpp
>>>>> @@ -3633,6 +3633,11 @@ apply_layout_qualifier_to_variable(const struct
>>>>> ast_type_qualifier *qual,
>>>>>                          "valid in fragment shader input layout
>>>>> declaration.");
>>>>>      }
>>>>>
>>>>> +   if (qual->flags.q.inner_coverage) {
>>>>> +      _mesa_glsl_error(loc, state, "inner_coverage layout qualifier only
>>>>> "
>>>>> +                       "valid in fragment shader input layout
>>>>> declaration.");
>>>>> +   }
>>>>> +
>>>>>      if (qual->flags.q.post_depth_coverage) {
>>>>>         _mesa_glsl_error(loc, state, "post_depth_coverage layout
>>>>> qualifier only "
>>>>>                          "valid in fragment shader input layout
>>>>> declaration.");
>>>>> diff --git a/src/compiler/glsl/ast_type.cpp
>>>>> b/src/compiler/glsl/ast_type.cpp
>>>>> index aa1ae7e..d68e6e2 100644
>>>>> --- a/src/compiler/glsl/ast_type.cpp
>>>>> +++ b/src/compiler/glsl/ast_type.cpp
>>>>> @@ -579,6 +579,7 @@ ast_type_qualifier::validate_in_qualifier(YYLTYPE
>>>>> *loc,
>>>>>         break;
>>>>>      case MESA_SHADER_FRAGMENT:
>>>>>         valid_in_mask.flags.q.early_fragment_tests = 1;
>>>>> +      valid_in_mask.flags.q.inner_coverage = 1;
>>>>>         valid_in_mask.flags.q.post_depth_coverage = 1;
>>>>>         break;
>>>>>      case MESA_SHADER_COMPUTE:
>>>>> @@ -634,11 +635,23 @@ ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
>>>>> *loc,
>>>>>         state->in_qualifier->flags.q.early_fragment_tests = false;
>>>>>      }
>>>>>
>>>>> +   if (state->in_qualifier->flags.q.inner_coverage) {
>>>>> +      state->fs_inner_coverage = true;
>>>>> +      state->in_qualifier->flags.q.inner_coverage = false;
>>>>> +   }
>>>>> +
>>>>>      if (state->in_qualifier->flags.q.post_depth_coverage) {
>>>>>         state->fs_post_depth_coverage = true;
>>>>>         state->in_qualifier->flags.q.post_depth_coverage = false;
>>>>>      }
>>>>>
>>>>> +   if (state->fs_inner_coverage && state->fs_post_depth_coverage) {
>>>>> +      _mesa_glsl_error(loc, state,
>>>>> +                       "inner_coverage & post_depth_coverage layout
>>>>> qualifiers "
>>>>> +                       "are mutally exclusives");
>>>>> +      r = false;
>>>>> +   }
>>>>> +
>>>>>      /* We allow the creation of multiple cs_input_layout nodes.
>>>>> Coherence among
>>>>>       * all existing nodes is checked later, when the AST node is
>>>>> transformed
>>>>>       * into HIR.
>>>>> @@ -707,7 +720,7 @@ ast_type_qualifier::validate_flags(YYLTYPE *loc,
>>>>>                       "%s '%s':"
>>>>>                       "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
>>>>>                       "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
>>>>> -                    "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
>>>>> +                    "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
>>>>>                       message, name,
>>>>>                       bad.flags.q.invariant ? " invariant" : "",
>>>>>                       bad.flags.q.precise ? " precise" : "",
>>>>> @@ -768,6 +781,7 @@ ast_type_qualifier::validate_flags(YYLTYPE *loc,
>>>>>                       bad.flags.q.vertices ? " vertices" : "",
>>>>>                       bad.flags.q.subroutine ? " subroutine" : "",
>>>>>                       bad.flags.q.subroutine_def ? " subroutine_def" :
>>>>> "",
>>>>> +                    bad.flags.q.inner_coverage ? " inner_coverage" : "",
>>>>>                       bad.flags.q.post_depth_coverage ? "
>>>>> post_depth_coverage" : "");
>>>>>      return false;
>>>>>   }
>>>>> diff --git a/src/compiler/glsl/glsl_parser.yy
>>>>> b/src/compiler/glsl/glsl_parser.yy
>>>>> index 09b7e79..e3893d5 100644
>>>>> --- a/src/compiler/glsl/glsl_parser.yy
>>>>> +++ b/src/compiler/glsl/glsl_parser.yy
>>>>> @@ -1372,9 +1372,10 @@ layout_qualifier_id:
>>>>>                  }
>>>>>               }
>>>>>            }
>>>>> +      }
>>>>>
>>>>> -         if (!$$.flags.i &&
>>>>> -             match_layout_qualifier($1, "early_fragment_tests", state)
>>>>> == 0) {
>>>>> +      if (!$$.flags.i) {
>>>>> +         if (match_layout_qualifier($1, "early_fragment_tests", state)
>>>>> == 0) {
>>>>>               /* From section 4.4.1.3 of the GLSL 4.50 specification
>>>>>                * (Fragment Shader Inputs):
>>>>>                *
>>>>> @@ -1393,15 +1394,32 @@ layout_qualifier_id:
>>>>>               $$.flags.q.early_fragment_tests = 1;
>>>>>            }
>>>>>
>>>>> -         if (!$$.flags.i &&
>>>>> -             match_layout_qualifier($1, "post_depth_coverage", state) ==
>>>>> 0) {
>>>>> +         if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
>>>>> +            if (state->stage != MESA_SHADER_FRAGMENT) {
>>>>> +               _mesa_glsl_error(& @1, state,
>>>>> +                                "inner_coverage layout qualifier only "
>>>>> +                                "valid in fragment shaders");
>>>>> +            }
>>>>> +
>>>>> +           if (state->INTEL_conservative_rasterization_enable) {
>>>>> +              $$.flags.q.inner_coverage = 1;
>>>>> +           } else {
>>>>> +              _mesa_glsl_error(& @1, state,
>>>>> +                                "inner_coverage layout qualifier
>>>>> present, "
>>>>> +                                "but the
>>>>> INTEL_conservative_rasterization extension "
>>>>> +                                "is not enabled.");
>>>>> +            }
>>>>> +         }
>>>>> +
>>>>> +         if (match_layout_qualifier($1, "post_depth_coverage", state) ==
>>>>> 0) {
>>>>>               if (state->stage != MESA_SHADER_FRAGMENT) {
>>>>>                  _mesa_glsl_error(& @1, state,
>>>>>                                   "post_depth_coverage layout qualifier
>>>>> only "
>>>>>                                   "valid in fragment shaders");
>>>>>               }
>>>>>
>>>>> -            if (state->ARB_post_depth_coverage_enable) {
>>>>> +            if (state->ARB_post_depth_coverage_enable ||
>>>>> +               state->INTEL_conservative_rasterization_enable) {
>>>>>                  $$.flags.q.post_depth_coverage = 1;
>>>>>               } else {
>>>>>                  _mesa_glsl_error(& @1, state,
>>>>> @@ -1410,6 +1428,12 @@ layout_qualifier_id:
>>>>>                                   "is not enabled.");
>>>>>               }
>>>>>            }
>>>>> +
>>>>> +         if ($$.flags.q.post_depth_coverage &&
>>>>> $$.flags.q.inner_coverage) {
>>>>> +            _mesa_glsl_error(& @1, state,
>>>>> +                             "post_depth_coverage & inner_coverage
>>>>> layout qualifiers "
>>>>> +                             "are mutually exclusive");
>>>>> +         }
>>>>>         }
>>>>>
>>>>>         /* Layout qualifiers for tessellation evaluation shaders. */
>>>>> diff --git a/src/compiler/glsl/glsl_parser_extras.cpp
>>>>> b/src/compiler/glsl/glsl_parser_extras.cpp
>>>>> index d1fc98d..14b7153 100644
>>>>> --- a/src/compiler/glsl/glsl_parser_extras.cpp
>>>>> +++ b/src/compiler/glsl/glsl_parser_extras.cpp
>>>>> @@ -293,6 +293,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct
>>>>> gl_context *_ctx,
>>>>>      this->in_qualifier = new(this) ast_type_qualifier();
>>>>>      this->out_qualifier = new(this) ast_type_qualifier();
>>>>>      this->fs_early_fragment_tests = false;
>>>>> +   this->fs_inner_coverage = false;
>>>>>      this->fs_post_depth_coverage = false;
>>>>>      this->fs_blend_support = 0;
>>>>>      memset(this->atomic_counter_offsets, 0,
>>>>> @@ -687,6 +688,7 @@ static const _mesa_glsl_extension
>>>>> _mesa_glsl_supported_extensions[] = {
>>>>>      EXT(EXT_texture_array),
>>>>>      EXT_AEP(EXT_texture_buffer),
>>>>>      EXT_AEP(EXT_texture_cube_map_array),
>>>>> +   EXT(INTEL_conservative_rasterization),
>>>>>      EXT(MESA_shader_integer_functions),
>>>>>      EXT(NV_image_formats),
>>>>>   };
>>>>> @@ -1692,6 +1694,7 @@ set_shader_inout_layout(struct gl_shader *shader,
>>>>>         assert(!state->fs_pixel_center_integer);
>>>>>         assert(!state->fs_origin_upper_left);
>>>>>         assert(!state->fs_early_fragment_tests);
>>>>> +      assert(!state->fs_inner_coverage);
>>>>>         assert(!state->fs_post_depth_coverage);
>>>>>      }
>>>>>
>>>>> @@ -1813,6 +1816,7 @@ set_shader_inout_layout(struct gl_shader *shader,
>>>>>         shader->info.ARB_fragment_coord_conventions_enable =
>>>>>            state->ARB_fragment_coord_conventions_enable;
>>>>>         shader->info.EarlyFragmentTests = state->fs_early_fragment_tests;
>>>>> +      shader->info.InnerCoverage = state->fs_inner_coverage;
>>>>>         shader->info.PostDepthCoverage = state->fs_post_depth_coverage;
>>>>>         shader->info.BlendSupport = state->fs_blend_support;
>>>>>         break;
>>>>> diff --git a/src/compiler/glsl/glsl_parser_extras.h
>>>>> b/src/compiler/glsl/glsl_parser_extras.h
>>>>> index 4277d43..d6fc377 100644
>>>>> --- a/src/compiler/glsl/glsl_parser_extras.h
>>>>> +++ b/src/compiler/glsl/glsl_parser_extras.h
>>>>> @@ -761,6 +761,8 @@ struct _mesa_glsl_parse_state {
>>>>>      bool EXT_texture_buffer_warn;
>>>>>      bool EXT_texture_cube_map_array_enable;
>>>>>      bool EXT_texture_cube_map_array_warn;
>>>>> +   bool INTEL_conservative_rasterization_enable;
>>>>> +   bool INTEL_conservative_rasterization_warn;
>>>>>      bool MESA_shader_framebuffer_fetch_enable;
>>>>>      bool MESA_shader_framebuffer_fetch_warn;
>>>>>      bool MESA_shader_framebuffer_fetch_non_coherent_enable;
>>>>> @@ -788,6 +790,8 @@ struct _mesa_glsl_parse_state {
>>>>>
>>>>>      bool fs_early_fragment_tests;
>>>>>
>>>>> +   bool fs_inner_coverage;
>>>>> +
>>>>>      bool fs_post_depth_coverage;
>>>>>
>>>>>      unsigned fs_blend_support;
>>>>> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
>>>>> index 39c5e07..f43ee97 100644
>>>>> --- a/src/compiler/glsl/linker.cpp
>>>>> +++ b/src/compiler/glsl/linker.cpp
>>>>> @@ -1888,6 +1888,9 @@ link_fs_inout_layout_qualifiers(struct
>>>>> gl_shader_program *prog,
>>>>>         linked_shader->info.EarlyFragmentTests |=
>>>>>            shader->info.EarlyFragmentTests;
>>>>>
>>>>> +      linked_shader->info.InnerCoverage |=
>>>>> +         shader->info.InnerCoverage;
>>>>> +
>>>>>         linked_shader->info.PostDepthCoverage |=
>>>>>            shader->info.PostDepthCoverage;
>>>>>
>>>>> diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
>>>>> index b2830e0..768f053 100644
>>>>> --- a/src/compiler/shader_info.h
>>>>> +++ b/src/compiler/shader_info.h
>>>>> @@ -116,6 +116,12 @@ typedef struct shader_info {
>>>>>             * ARB_shader_image_load_store.
>>>>>             */
>>>>>            bool early_fragment_tests;
>>>>> +
>>>>> +         /**
>>>>> +          * Defined by INTEL_conservative_rasterization.
>>>>> +          */
>>>>> +         bool inner_coverage;
>>>>> +
>>>>>            bool post_depth_coverage;
>>>>>
>>>>>            /** gl_FragDepth layout for ARB_conservative_depth. */
>>>>> diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
>>>>> index d3b4cab..95a9676 100644
>>>>> --- a/src/mesa/main/api_validate.c
>>>>> +++ b/src/mesa/main/api_validate.c
>>>>> @@ -555,6 +555,48 @@ _mesa_valid_prim_mode(struct gl_context *ctx, GLenum
>>>>> mode, const char *name)
>>>>>         }
>>>>>      }
>>>>>
>>>>> +   /* From GL_INTEL_conservative_rasterization spec:
>>>>> +    *
>>>>> +    * The conservative rasterization option applies only to polygons
>>>>> with
>>>>> +    * PolygonMode state set to FILL. Draw requests for polygons with
>>>>> different
>>>>> +    * PolygonMode setting or for other primitive types (points/lines)
>>>>> generate
>>>>> +    * INVALID_OPERATION error.
>>>>> +    */
>>>>> +   if (ctx->IntelConservativeRasterization) {
>>>>> +      GLboolean pass = GL_TRUE;
>>>>> +
>>>>> +      switch (mode) {
>>>>> +      case GL_POINTS:
>>>>> +      case GL_LINES:
>>>>> +      case GL_LINE_LOOP:
>>>>> +      case GL_LINE_STRIP:
>>>>> +      case GL_LINES_ADJACENCY:
>>>>> +      case GL_LINE_STRIP_ADJACENCY:
>>>>> +         pass = GL_FALSE;
>>>>> +         break;
>>>>> +      case GL_TRIANGLES:
>>>>> +      case GL_TRIANGLE_STRIP:
>>>>> +      case GL_TRIANGLE_FAN:
>>>>> +      case GL_QUADS:
>>>>> +      case GL_QUAD_STRIP:
>>>>> +      case GL_POLYGON:
>>>>> +      case GL_TRIANGLES_ADJACENCY:
>>>>> +      case GL_TRIANGLE_STRIP_ADJACENCY:
>>>>> +         if (ctx->Polygon.FrontMode != GL_FILL ||
>>>>> +             ctx->Polygon.BackMode != GL_FILL)
>>>>> +            pass = GL_FALSE;
>>>>> +         break;
>>>>> +      default:
>>>>> +         pass = GL_FALSE;
>>>>> +      }
>>>>> +      if (!pass) {
>>>>> +         _mesa_error(ctx, GL_INVALID_OPERATION,
>>>>> +                     "mode=%s invalid with
>>>>> GL_INTEL_conservative_rasterization",
>>>>> +                     _mesa_lookup_prim_by_nr(mode));
>>>>> +         return GL_FALSE;
>>>>> +      }
>>>>> +   }
>>>>> +
>>>>>      return GL_TRUE;
>>>>>   }
>>>>>
>>>>> diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
>>>>> index d1ab81e..c9f10ab 100644
>>>>> --- a/src/mesa/main/enable.c
>>>>> +++ b/src/mesa/main/enable.c
>>>>> @@ -439,6 +439,14 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap,
>>>>> GLboolean state)
>>>>>            FLUSH_VERTICES(ctx, _NEW_COLOR);
>>>>>            ctx->Color.IndexLogicOpEnabled = state;
>>>>>            break;
>>>>> +      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
>>>>> +         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
>>>>> +            goto invalid_enum_error;
>>>>
>>>> Did you test this on GLES? I don't think it'll work like you think.
>>>> (Hint - API_OPENGLES == ES 1.0)
>>>
>>>
>>> Oops indeed. Thanks for pointing that out, I'll decline the piglit tests for
>>> GLES.
>
> Actually it occurs to me that this will also pass for compat contexts.
> Maybe you should just do
>
> if (!_mesa_has_INTEL_conservative_reasterization(ctx))
>   goto invalid_enum_error;
>
> which will cover all the various cases.

... and also I think you need to add something to
src/mesa/main/get_hash_params.py - you're supposed to be able to use
glGet* with the IsEnabled stuff. (I don't have a spec quote handy, but
e.g. look at the GL_BLEND_ADVANCED_COHERENT_KHR handling.)

  -ilia


More information about the mesa-dev mailing list