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

Lionel Landwerlin lionel.g.landwerlin at intel.com
Wed Dec 7 15:25:00 UTC 2016


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.

>
>> +         if (ctx->IntelConservativeRasterization == state)
>> +            return;
>> +         FLUSH_VERTICES(ctx, _NEW_POLYGON);
> Why _NEW_POLYGON? Why not, e.g., _NEW_MULTISAMPLE. Or something else convenient?

Right, I didn't have a good sense what would fit better, polygon seemed 
to fit better because the specification doesn't apply to lines & points.
Will change.

>
>> +         ctx->IntelConservativeRasterization = state;
>> +         break;
>>         case GL_COLOR_LOGIC_OP:
>>            if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
>>               goto invalid_enum_error;
>> @@ -1631,6 +1639,10 @@ _mesa_IsEnabled( GLenum cap )
>>            CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
>>            return ctx->Color.BlendCoherent;
>>
>> +      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
>> +         CHECK_EXTENSION(INTEL_conservative_rasterization);
>> +         return ctx->IntelConservativeRasterization;
>> +
>>         default:
>>            goto invalid_enum_error;
>>      }
>> diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
>> index f2d3a5b..6756f7c 100644
>> --- a/src/mesa/main/extensions_table.h
>> +++ b/src/mesa/main/extensions_table.h
>> @@ -290,6 +290,7 @@ EXT(IBM_texture_mirrored_repeat             , dummy_true
>>
>>   EXT(INGR_blend_func_separate                , EXT_blend_func_separate                , GLL,  x ,  x ,  x , 1999)
>>
>> +EXT(INTEL_conservative_rasterization        , INTEL_conservative_rasterization       ,  x ,  42,  x ,  32, 2013)
> I guess the only reason the spec requires GL 4.2 is that it depends on
> early_fragment_tests. My recommendation would be to downgrade this to
> GLC. Also, there's no mention of requiring ES 3.2 - presumably ES 3.1
> + OES_sample_variables should be sufficient, no? (So just drop it to
> 31 for ES.)

Sure, will change.
Thanks for the feedback.

>
>>   EXT(INTEL_performance_query                 , INTEL_performance_query                , GLL, GLC,  x , ES2, 2013)
>>
>>   EXT(KHR_blend_equation_advanced             , KHR_blend_equation_advanced            , GLL, GLC,  x , ES2, 2014)
>> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
>> index dfa9a78..e91a8ac 100644
>> --- a/src/mesa/main/mtypes.h
>> +++ b/src/mesa/main/mtypes.h
>> @@ -2175,6 +2175,7 @@ struct gl_shader_info
>>      bool uses_gl_fragcoord;
>>      bool redeclares_gl_fragcoord;
>>      bool PostDepthCoverage;
>> +   bool InnerCoverage;
>>      bool ARB_fragment_coord_conventions_enable;
>>
>>      /**
>> @@ -3935,6 +3936,7 @@ struct gl_extensions
>>      GLboolean ATI_fragment_shader;
>>      GLboolean ATI_separate_stencil;
>>      GLboolean GREMEDY_string_marker;
>> +   GLboolean INTEL_conservative_rasterization;
>>      GLboolean INTEL_performance_query;
>>      GLboolean KHR_blend_equation_advanced;
>>      GLboolean KHR_blend_equation_advanced_coherent;
>> @@ -4618,6 +4620,7 @@ struct gl_context
>>      GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
>>
>>      GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
>> +   GLboolean IntelConservativeRasterization; /**< GL_INTEL_CONSERVATIVE_RASTERIZATION */
>>
>>      /**
>>       * \name Hooks for module contexts.
>> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
>> index 33e4334..d8f2e79 100644
>> --- a/src/mesa/main/shaderapi.c
>> +++ b/src/mesa/main/shaderapi.c
>> @@ -2194,6 +2194,7 @@ _mesa_copy_linked_program_data(const struct gl_shader_program *src,
>>      case MESA_SHADER_FRAGMENT: {
>>         dst->info.fs.depth_layout = src->FragDepthLayout;
>>         dst->info.fs.early_fragment_tests = dst_sh->info.EarlyFragmentTests;
>> +      dst->info.fs.inner_coverage = dst_sh->info.InnerCoverage;
>>         dst->info.fs.post_depth_coverage = dst_sh->info.PostDepthCoverage;
>>         break;
>>      }
>> --
>> 2.10.2
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev




More information about the mesa-dev mailing list