[Mesa-dev] [PATCH v4 1/4] mesa: add support for nvidia conservative rasterization extensions

Marek Olšák maraeo at gmail.com
Mon Apr 2 02:37:56 UTC 2018


On Wed, Mar 28, 2018 at 3:22 PM, Rhys Perry <pendingchaos02 at gmail.com>
wrote:

> Although the specs are written against compatibility GL 4.3 and allows core
> profile and GLES2+, it is exposed for GL 1.0+ and GLES1 and GLES2+.
> ---
>  src/mapi/glapi/gen/gl_API.xml           |  47 ++++++++++++
>  src/mapi/glapi/gen/gl_genexec.py        |   1 +
>  src/mesa/Makefile.sources               |   2 +
>  src/mesa/main/attrib.c                  |  60 ++++++++++++---
>  src/mesa/main/conservativeraster.c      | 128
> ++++++++++++++++++++++++++++++++
>  src/mesa/main/conservativeraster.h      |  48 ++++++++++++
>  src/mesa/main/context.c                 |  10 +++
>  src/mesa/main/dlist.c                   |  86 +++++++++++++++++++++
>  src/mesa/main/enable.c                  |  14 ++++
>  src/mesa/main/extensions_table.h        |   4 +
>  src/mesa/main/get.c                     |   3 +
>  src/mesa/main/get_hash_params.py        |  13 ++++
>  src/mesa/main/mtypes.h                  |  28 ++++++-
>  src/mesa/main/tests/dispatch_sanity.cpp |  27 +++++++
>  src/mesa/main/viewport.c                |  57 ++++++++++++++
>  src/mesa/main/viewport.h                |   6 ++
>  src/mesa/meson.build                    |   2 +
>  17 files changed, 525 insertions(+), 11 deletions(-)
>  create mode 100644 src/mesa/main/conservativeraster.c
>  create mode 100644 src/mesa/main/conservativeraster.h
>
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
> index 38c1921047..db312370b1 100644
> --- a/src/mapi/glapi/gen/gl_API.xml
> +++ b/src/mapi/glapi/gen/gl_API.xml
> @@ -12871,6 +12871,53 @@
>    <enum name="CONSERVATIVE_RASTERIZATION_INTEL" value="0x83FE"/>
>  </category>
>
> +<category name="GL_NV_conservative_raster" number="465">
> +    <enum name="CONSERVATIVE_RASTERIZATION_NV"       value="0x9346">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="SUBPIXEL_PRECISION_BIAS_X_BITS_NV"   value="0x9347">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="SUBPIXEL_PRECISION_BIAS_Y_BITS_NV"   value="0x9348">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV" value="0x9349">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <function name="SubpixelPrecisionBiasNV" es1="1.0" es2="2.0"
> no_error="true">
> +        <param name="xbits" type="GLuint"/>
> +        <param name="ybits" type="GLuint"/>
> +    </function>
> +</category>
> +
> +<category name="GL_NV_conservative_raster_dilate" number="480">
> +    <enum name="CONSERVATIVE_RASTER_DILATE_NV"
>  value="0x9379">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="CONSERVATIVE_RASTER_DILATE_RANGE_NV"
>  value="0x937A">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="CONSERVATIVE_RASTER_DILATE_GRANULARITY_NV"
> value="0x937B">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <function name="ConservativeRasterParameterfNV" es1="1.0" es2="2.0"
> no_error="true">
> +        <param name="pname" type="GLenum"/>
> +        <param name="param" type="GLfloat"/>
> +    </function>
> +</category>
> +
> +<category name="GL_NV_conservative_pre_snap_triangles" number="487">
> +    <enum name="CONSERVATIVE_RASTER_MODE_NV"       value="0x954D">
> +        <size name="Get" mode="get"/>
> +    </enum>
> +    <enum name="CONSERVATIVE_RASTER_MODE_POST_SNAP_NV"   value="0x954E"/>
> +    <enum name="CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV"
>  value="0x954F"/>
> +    <function name="ConservativeRasterParameteriNV" es1="1.0" es2="2.0"
> no_error="true">
> +        <param name="pname" type="GLenum"/>
> +        <param name="param" type="GLint"/>
> +    </function>
> +</category>
> +
>  <xi:include href="INTEL_performance_query.xml" xmlns:xi="
> http://www.w3.org/2001/XInclude"/>
>
>  <category name="GL_EXT_polygon_offset_clamp" number="460">
> diff --git a/src/mapi/glapi/gen/gl_genexec.py b/src/mapi/glapi/gen/gl_
> genexec.py
> index aaff9f230b..be8013b62b 100644
> --- a/src/mapi/glapi/gen/gl_genexec.py
> +++ b/src/mapi/glapi/gen/gl_genexec.py
> @@ -62,6 +62,7 @@ header = """/**
>  #include "main/colortab.h"
>  #include "main/compute.h"
>  #include "main/condrender.h"
> +#include "main/conservativeraster.h"
>  #include "main/context.h"
>  #include "main/convolve.h"
>  #include "main/copyimage.h"
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
> index 0446078136..43ec55f580 100644
> --- a/src/mesa/Makefile.sources
> +++ b/src/mesa/Makefile.sources
> @@ -49,6 +49,8 @@ MAIN_FILES = \
>         main/condrender.c \
>         main/condrender.h \
>         main/config.h \
> +       main/conservativeraster.c \
> +       main/conservativeraster.h \
>         main/context.c \
>         main/context.h \
>         main/convolve.c \
> diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
> index 9d3aa728a1..e785aa5549 100644
> --- a/src/mesa/main/attrib.c
> +++ b/src/mesa/main/attrib.c
> @@ -138,6 +138,9 @@ struct gl_enable_attrib
>
>     /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
>     GLboolean sRGBEnabled;
> +
> +   /* GL_NV_conservative_raster */
> +   GLboolean ConservativeRasterization;
>  };
>
>
> @@ -178,6 +181,13 @@ struct texture_state
>  };
>
>
> +struct viewport_state
> +{
> +   struct gl_viewport_attrib ViewportArray[MAX_VIEWPORTS];
> +   GLuint SubpixelPrecisionBias[2];
> +};
> +
> +
>  /** An unused GL_*_BIT value */
>  #define DUMMY_BIT 0x10000000
>
> @@ -394,6 +404,9 @@ _mesa_PushAttrib(GLbitfield mask)
>
>        /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
>        attr->sRGBEnabled = ctx->Color.sRGBEnabled;
> +
> +      /* GL_NV_conservative_raster */
> +      attr->ConservativeRasterization = ctx->ConservativeRasterization;
>     }
>
>     if (mask & GL_EVAL_BIT) {
> @@ -545,11 +558,23 @@ _mesa_PushAttrib(GLbitfield mask)
>     }
>
>     if (mask & GL_VIEWPORT_BIT) {
> -      if (!push_attrib(ctx, &head, GL_VIEWPORT_BIT,
> -                       sizeof(struct gl_viewport_attrib)
> -                       * ctx->Const.MaxViewports,
> -                       (void*)&ctx->ViewportArray))
> +      struct viewport_state *viewstate = CALLOC_STRUCT(viewport_state);
> +      if (!viewstate) {
> +         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_VIEWPORT_BIT)
> ");
> +         goto end;
> +      }
> +
> +      if (!save_attrib_data(&head, GL_VIEWPORT_BIT, viewstate)) {
> +         free(viewstate);
> +         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_VIEWPORT_BIT)
> ");
>           goto end;
> +      }
> +
> +      memcpy(&viewstate->ViewportArray, &ctx->ViewportArray,
> +             sizeof(struct gl_viewport_attrib)*ctx->Const.MaxViewports);
> +
> +      viewstate->SubpixelPrecisionBias[0] =
> ctx->SubpixelPrecisionBias[0];
> +      viewstate->SubpixelPrecisionBias[1] =
> ctx->SubpixelPrecisionBias[1];
>     }
>
>     /* GL_ARB_multisample */
> @@ -714,6 +739,13 @@ pop_enable_group(struct gl_context *ctx, const struct
> gl_enable_attrib *enable)
>     TEST_AND_UPDATE(ctx->Color.sRGBEnabled, enable->sRGBEnabled,
>                     GL_FRAMEBUFFER_SRGB);
>
> +   /* GL_NV_conservative_raster */
> +   if (ctx->Extensions.NV_conservative_raster) {
> +      TEST_AND_UPDATE(ctx->ConservativeRasterization,
> +                      enable->ConservativeRasterization,
> +                      GL_CONSERVATIVE_RASTERIZATION_NV);
> +   }
> +
>     /* texture unit enables */
>     for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
>        const GLbitfield enabled = enable->Texture[i];
> @@ -1127,7 +1159,8 @@ _mesa_PopAttrib(void)
>                                        ctx->DriverFlags.NewSampleAlphaToXEnable
> |
>                                        ctx->DriverFlags.NewSampleMask |
>                                        ctx->DriverFlags.NewScissorTest |
> -                                      ctx->DriverFlags.NewStencil;
> +                                      ctx->DriverFlags.NewStencil |
> +                                      ctx->DriverFlags.
> NewNvConservativeRasterization;
>              }
>              break;
>           case GL_EVAL_BIT:
> @@ -1419,13 +1452,20 @@ _mesa_PopAttrib(void)
>           case GL_VIEWPORT_BIT:
>              {
>                 unsigned i;
> -               const struct gl_viewport_attrib *vp;
> -               vp = (const struct gl_viewport_attrib *) attr->data;
> +               const struct viewport_state *viewstate;
> +               viewstate = (const struct viewport_state *) attr->data;
>
>                 for (i = 0; i < ctx->Const.MaxViewports; i++) {
> -                  _mesa_set_viewport(ctx, i, vp[i].X, vp[i].Y,
> vp[i].Width,
> -                                     vp[i].Height);
> -                  _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far);
> +                  const struct gl_viewport_attrib *vp =
> &viewstate->ViewportArray[i];
> +                  _mesa_set_viewport(ctx, i, vp->X, vp->Y, vp->Width,
> +                                     vp->Height);
> +                  _mesa_set_depth_range(ctx, i, vp->Near, vp->Far);
> +               }
> +
> +               if (ctx->Extensions.NV_conservative_raster) {
> +                  GLuint biasx = viewstate->SubpixelPrecisionBias[0];
> +                  GLuint biasy = viewstate->SubpixelPrecisionBias[1];
> +                  _mesa_SubpixelPrecisionBiasNV(biasx, biasy);
>                 }
>              }
>              break;
> diff --git a/src/mesa/main/conservativeraster.c b/src/mesa/main/
> conservativeraster.c
> new file mode 100644
> index 0000000000..8a7241d2a8
> --- /dev/null
> +++ b/src/mesa/main/conservativeraster.c
> @@ -0,0 +1,128 @@
> +/*
> + * Mesa 3-D graphics library
> + *
> + * Copyright (C) 2018 Rhys Perry
> + *
> + * 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 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 conservativeraster.c
> + * glConservativeRasterParameteriNV and glConservativeRasterParameterfNV
> functions
> + */
> +
> +#include "conservativeraster.h"
> +#include "context.h"
> +#include "enums.h"
> +
> +static void
> +conservative_raster_parameter(GLenum pname, GLdouble param,
> +                              bool no_error, const char *func)
>

The no_error parameter is useful only if the function has ALWAYS_INLINE.
Same for other functions.

Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180401/50753558/attachment-0001.html>


More information about the mesa-dev mailing list