[Mesa-dev] [PATCH v3 6/6] nvc0: add support for GL_EXT_window_rectangles

Samuel Pitoiset samuel.pitoiset at gmail.com
Tue Jun 14 12:55:55 UTC 2016


On 06/12/2016 08:37 AM, Ilia Mirkin wrote:
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>  docs/relnotes/12.1.0.html                          |  1 +
>  src/gallium/drivers/nouveau/nvc0/nvc0_context.h    |  2 ++
>  src/gallium/drivers/nouveau/nvc0/nvc0_screen.c     |  3 ++-
>  src/gallium/drivers/nouveau/nvc0/nvc0_state.c      | 17 +++++++++++++++
>  .../drivers/nouveau/nvc0/nvc0_state_validate.c     | 25 ++++++++++++++++++++++
>  src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h   |  6 ++++++
>  src/gallium/drivers/nouveau/nvc0/nvc0_surface.c    | 22 ++++++++++++++-----
>  7 files changed, 70 insertions(+), 6 deletions(-)
>
> diff --git a/docs/relnotes/12.1.0.html b/docs/relnotes/12.1.0.html
> index 3f7b196..a664eba 100644
> --- a/docs/relnotes/12.1.0.html
> +++ b/docs/relnotes/12.1.0.html
> @@ -45,6 +45,7 @@ Note: some of the new features are only available with certain drivers.
>
>  <ul>
>  <li>GL_ARB_shader_group_vote on nvc0</li>
> +<li>GL_EXT_window_rectangles on nvc0</li>
>  </ul>
>
>  <h2>Bug fixes</h2>
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> index 1b3f88b..fe9f9f5 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> @@ -58,6 +58,7 @@
>  #define NVC0_NEW_3D_TESSFACTOR   (1 << 25)
>  #define NVC0_NEW_3D_BUFFERS      (1 << 26)
>  #define NVC0_NEW_3D_DRIVERCONST  (1 << 27)
> +#define NVC0_NEW_3D_WINDOW_RECTS (1 << 28)
>
>  #define NVC0_NEW_CP_PROGRAM   (1 << 0)
>  #define NVC0_NEW_CP_SURFACES  (1 << 1)
> @@ -214,6 +215,7 @@ struct nvc0_context {
>     struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
>     unsigned viewports_dirty;
>     struct pipe_clip_state clip;
> +   struct nvc0_window_rect_stateobj window_rect;
>
>     unsigned sample_mask;
>     unsigned min_samples;
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> index 1afa43a..8a8ac43 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> @@ -157,6 +157,8 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>        return PIPE_ENDIAN_LITTLE;
>     case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
>        return 30;
> +   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
> +      return 8;

How about
#define NVC0_NUM_WINDOW_RECTANGLES 8
to avoid using magic numbers at many places in your patch?

>
>     /* supported caps */
>     case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
> @@ -261,7 +263,6 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>     case PIPE_CAP_PCI_BUS:
>     case PIPE_CAP_PCI_DEVICE:
>     case PIPE_CAP_PCI_FUNCTION:
> -   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
>        return 0;
>
>     case PIPE_CAP_VENDOR_ID:
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> index 92161ec..f5b4b91 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> @@ -1000,6 +1000,22 @@ nvc0_set_viewport_states(struct pipe_context *pipe,
>  }
>
>  static void
> +nvc0_set_window_rectangle_states(struct pipe_context *pipe,
> +                                 boolean include,
> +                                 unsigned num_rectangles,
> +                                 const struct pipe_scissor_state *rectangles)
> +{
> +   struct nvc0_context *nvc0 = nvc0_context(pipe);
> +
> +   nvc0->window_rect.inclusive = include;
> +   nvc0->window_rect.rects = MIN2(num_rectangles, 8);
> +   memcpy(nvc0->window_rect.rect, rectangles,
> +          sizeof(struct pipe_scissor_state) * nvc0->window_rect.rects);
> +
> +   nvc0->dirty_3d |= NVC0_NEW_3D_WINDOW_RECTS;
> +}
> +
> +static void
>  nvc0_set_tess_state(struct pipe_context *pipe,
>                      const float default_tess_outer[4],
>                      const float default_tess_inner[2])
> @@ -1490,6 +1506,7 @@ nvc0_init_state_functions(struct nvc0_context *nvc0)
>     pipe->set_polygon_stipple = nvc0_set_polygon_stipple;
>     pipe->set_scissor_states = nvc0_set_scissor_states;
>     pipe->set_viewport_states = nvc0_set_viewport_states;
> +   pipe->set_window_rectangle_states = nvc0_set_window_rectangle_states;
>     pipe->set_tess_state = nvc0_set_tess_state;
>
>     pipe->create_vertex_elements_state = nvc0_vertex_state_create;
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> index ad44e85..a57cd63 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> @@ -326,6 +326,30 @@ nvc0_validate_viewport(struct nvc0_context *nvc0)
>     nvc0->viewports_dirty = 0;
>  }
>
> +static void
> +nvc0_validate_window_rects(struct nvc0_context *nvc0)
> +{
> +   struct nouveau_pushbuf *push = nvc0->base.pushbuf;
> +   bool enable = nvc0->window_rect.rects > 0 || nvc0->window_rect.inclusive;
> +   int i;
> +
> +   IMMED_NVC0(push, NVC0_3D(CLIP_RECTS_EN), enable);
> +   if (!enable)
> +      return;
> +
> +   IMMED_NVC0(push, NVC0_3D(CLIP_RECTS_MODE), !nvc0->window_rect.inclusive);
> +   BEGIN_NVC0(push, NVC0_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
> +   for (i = 0; i < nvc0->window_rect.rects; i++) {
> +      struct pipe_scissor_state *s = &nvc0->window_rect.rect[i];
> +      PUSH_DATA(push, (s->maxx << 16) | s->minx);
> +      PUSH_DATA(push, (s->maxy << 16) | s->miny);
> +   }
> +   for (; i < 8; i++) {
> +      PUSH_DATA(push, 0);
> +      PUSH_DATA(push, 0);
> +   }
> +}
> +
>  static inline void
>  nvc0_upload_uclip_planes(struct nvc0_context *nvc0, unsigned s)
>  {
> @@ -716,6 +740,7 @@ validate_list_3d[] = {
>      { nvc0_validate_stipple,       NVC0_NEW_3D_STIPPLE },
>      { nvc0_validate_scissor,       NVC0_NEW_3D_SCISSOR | NVC0_NEW_3D_RASTERIZER },
>      { nvc0_validate_viewport,      NVC0_NEW_3D_VIEWPORT },
> +    { nvc0_validate_window_rects,  NVC0_NEW_3D_WINDOW_RECTS },
>      { nvc0_vertprog_validate,      NVC0_NEW_3D_VERTPROG },
>      { nvc0_tctlprog_validate,      NVC0_NEW_3D_TCTLPROG },
>      { nvc0_tevlprog_validate,      NVC0_NEW_3D_TEVLPROG },
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h b/src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h
> index f9680f5..6dedb40 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h
> @@ -61,6 +61,12 @@ struct nvc0_vertex_stateobj {
>     struct nvc0_vertex_element element[0];
>  };
>
> +struct nvc0_window_rect_stateobj {
> +   bool inclusive;
> +   unsigned rects;
> +   struct pipe_scissor_state rect[8];
> +};
> +
>  struct nvc0_so_target {
>     struct pipe_stream_output_target pipe;
>     struct pipe_query *pq;
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
> index a177569..1c72249 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
> @@ -782,6 +782,7 @@ struct nvc0_blitctx
>     enum pipe_texture_target target;
>     struct {
>        struct pipe_framebuffer_state fb;
> +      struct nvc0_window_rect_stateobj window_rect;
>        struct nvc0_rasterizer_stateobj *rast;
>        struct nvc0_program *vp;
>        struct nvc0_program *tcp;
> @@ -1035,7 +1036,8 @@ nvc0_blitctx_prepare_state(struct nvc0_blitctx *blit)
>  }
>
>  static void
> -nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
> +nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx,
> +                      const struct pipe_blit_info *info)
>  {
>     struct nvc0_context *nvc0 = ctx->nvc0;
>     struct nvc0_blitter *blitter = nvc0->screen->blitter;
> @@ -1058,6 +1060,7 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
>     ctx->saved.fp = nvc0->fragprog;
>
>     ctx->saved.min_samples = nvc0->min_samples;
> +   ctx->saved.window_rect = nvc0->window_rect;
>
>     nvc0->rast = &ctx->rast;
>
> @@ -1067,6 +1070,12 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
>     nvc0->gmtyprog = NULL;
>     nvc0->fragprog = ctx->fp;
>
> +   nvc0->window_rect.rects = MIN2(info->num_window_rectangles, 8);
> +   nvc0->window_rect.inclusive = info->window_rectangle_include;
> +   if (nvc0->window_rect.rects)
> +      memcpy(nvc0->window_rect.rect, info->window_rectangles,
> +             sizeof(struct pipe_scissor_state) * nvc0->window_rect.rects);

This seems to be pretty similar to the validate function. Maybe you can 
try to refactor this part?

> +
>     for (s = 0; s <= 4; ++s) {
>        ctx->saved.num_textures[s] = nvc0->num_textures[s];
>        ctx->saved.num_samplers[s] = nvc0->num_samplers[s];
> @@ -1099,7 +1108,7 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
>     nvc0->dirty_3d = NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_MIN_SAMPLES |
>        NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |
>        NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |
> -      NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS;
> +      NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS | NVC0_NEW_3D_WINDOW_RECTS;
>  }
>
>  static void
> @@ -1126,7 +1135,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
>     nvc0->gmtyprog = blit->saved.gp;
>     nvc0->fragprog = blit->saved.fp;
>
> -   nvc0->min_samples = blit->saved.min_samples;
> +   nvc0->window_rect = blit->saved.window_rect;

Oops?

>
>     pipe_sampler_view_reference(&nvc0->textures[4][0], NULL);
>     pipe_sampler_view_reference(&nvc0->textures[4][1], NULL);
> @@ -1158,7 +1167,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
>     nvc0->dirty_3d = blit->saved.dirty_3d |
>        (NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_SCISSOR | NVC0_NEW_3D_SAMPLE_MASK |
>         NVC0_NEW_3D_RASTERIZER | NVC0_NEW_3D_ZSA | NVC0_NEW_3D_BLEND |
> -       NVC0_NEW_3D_VIEWPORT |
> +       NVC0_NEW_3D_VIEWPORT | NVC0_NEW_3D_WINDOW_RECTS |
>         NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS |
>         NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |
>         NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |
> @@ -1191,7 +1200,7 @@ nvc0_blit_3d(struct nvc0_context *nvc0, const struct pipe_blit_info *info)
>     blit->render_condition_enable = info->render_condition_enable;
>
>     nvc0_blit_select_fp(blit, info);
> -   nvc0_blitctx_pre_blit(blit);
> +   nvc0_blitctx_pre_blit(blit, info);
>
>     nvc0_blit_set_dst(blit, dst, info->dst.level, -1, info->dst.format);
>     nvc0_blit_set_src(blit, src, info->src.level, -1, info->src.format,
> @@ -1606,6 +1615,9 @@ nvc0_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)
>          info->src.box.height != -info->dst.box.height))
>        eng3d = true;
>
> +   if (info->num_window_rectangles > 0 || info->window_rectangle_include)
> +      eng3d = true;
> +
>     if (nvc0->screen->num_occlusion_queries_active)
>        IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 0);
>
>

-- 
-Samuel


More information about the mesa-dev mailing list