[Mesa-dev] [PATCH 2/2] st/mesa: add support for GL_ARB_viewport_array (v0.2)

Ian Romanick idr at freedesktop.org
Fri Feb 7 00:54:25 CET 2014


On 02/04/2014 02:50 PM, Ilia Mirkin wrote:
> On Tue, Jan 21, 2014 at 1:09 AM, Dave Airlie <airlied at gmail.com> wrote:
>> From: Dave Airlie <airlied at redhat.com>
>>
>> this just ties the mesa code to the pre-existing gallium interface,
>> I'm not sure what to do with the CSO stuff yet.
>>
>> 0.2: fix min/max bounds
>>
>> Signed-off-by: Dave Airlie <airlied at redhat.com>
> 
> Series is Acked-by: Ilia Mirkin <imirkin at alum.mit.edu>
> 
> Don't know if I have enough knowledge here for a R-b, but this works
> with my nv50 impl now (after changing the piglit tests around :) )
> 
> It's a little inefficient that the st does diffing but sets all the
> viewports anyways, and then the driver basically has to do that as
> well. But perhaps that's the convention. [Also note that your r600
> impl last I looked didn't do the diffing in the driver, so it would
> set all the viewports/scissors every time. But perhaps I misread.]

I had considered keeping a mask of "dirty" viewports in the gl_context.
 This could be used in the dd_function_table::Viewport (and friends)
handlers to do smarter updates.  i965 needs to reprogram all of them in
one go, so I didn't need it.  It should be easy enough to add, if that
helps.

>> ---
>>  src/mesa/state_tracker/st_atom_scissor.c  | 75 ++++++++++++++++---------------
>>  src/mesa/state_tracker/st_atom_viewport.c | 37 ++++++++-------
>>  src/mesa/state_tracker/st_context.h       |  4 +-
>>  src/mesa/state_tracker/st_draw_feedback.c |  2 +-
>>  src/mesa/state_tracker/st_extensions.c    |  9 ++++
>>  5 files changed, 72 insertions(+), 55 deletions(-)
>>
>> diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c
>> index a1f72da..50b921a 100644
>> --- a/src/mesa/state_tracker/st_atom_scissor.c
>> +++ b/src/mesa/state_tracker/st_atom_scissor.c
>> @@ -43,51 +43,56 @@
>>  static void
>>  update_scissor( struct st_context *st )
>>  {
>> -   struct pipe_scissor_state scissor;
>> +   struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
>>     const struct gl_context *ctx = st->ctx;
>>     const struct gl_framebuffer *fb = ctx->DrawBuffer;
>>     GLint miny, maxy;
>> +   int i;
>> +   bool changed = false;
>> +   for (i = 0 ; i < ctx->Const.MaxViewports; i++) {
>> +      scissor[i].minx = 0;
>> +      scissor[i].miny = 0;
>> +      scissor[i].maxx = fb->Width;
>> +      scissor[i].maxy = fb->Height;
>>
>> -   scissor.minx = 0;
>> -   scissor.miny = 0;
>> -   scissor.maxx = fb->Width;
>> -   scissor.maxy = fb->Height;
>> +      if (ctx->Scissor.EnableFlags & (1 << i)) {
>> +         /* need to be careful here with xmax or ymax < 0 */
>> +         GLint xmax = MAX2(0, ctx->Scissor.ScissorArray[i].X + ctx->Scissor.ScissorArray[i].Width);
>> +         GLint ymax = MAX2(0, ctx->Scissor.ScissorArray[i].Y + ctx->Scissor.ScissorArray[i].Height);
>>
>> -   if (ctx->Scissor.EnableFlags & 1) {
>> -      /* need to be careful here with xmax or ymax < 0 */
>> -      GLint xmax = MAX2(0, ctx->Scissor.ScissorArray[0].X + ctx->Scissor.ScissorArray[0].Width);
>> -      GLint ymax = MAX2(0, ctx->Scissor.ScissorArray[0].Y + ctx->Scissor.ScissorArray[0].Height);
>> +         if (ctx->Scissor.ScissorArray[i].X > (GLint)scissor[i].minx)
>> +            scissor[i].minx = ctx->Scissor.ScissorArray[i].X;
>> +         if (ctx->Scissor.ScissorArray[i].Y > (GLint)scissor[i].miny)
>> +            scissor[i].miny = ctx->Scissor.ScissorArray[i].Y;
>>
>> -      if (ctx->Scissor.ScissorArray[0].X > (GLint)scissor.minx)
>> -         scissor.minx = ctx->Scissor.ScissorArray[0].X;
>> -      if (ctx->Scissor.ScissorArray[0].Y > (GLint)scissor.miny)
>> -         scissor.miny = ctx->Scissor.ScissorArray[0].Y;
>> +         if (xmax < (GLint) scissor[i].maxx)
>> +            scissor[i].maxx = xmax;
>> +         if (ymax < (GLint) scissor[i].maxy)
>> +            scissor[i].maxy = ymax;
>>
>> -      if (xmax < (GLint) scissor.maxx)
>> -         scissor.maxx = xmax;
>> -      if (ymax < (GLint) scissor.maxy)
>> -         scissor.maxy = ymax;
>> +         /* check for null space */
>> +         if (scissor[i].minx >= scissor[i].maxx || scissor[i].miny >= scissor[i].maxy)
>> +            scissor[i].minx = scissor[i].miny = scissor[i].maxx = scissor[i].maxy = 0;
>> +      }
>>
>> -      /* check for null space */
>> -      if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy)
>> -         scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0;
>> -   }
>> -
>> -   /* Now invert Y if needed.
>> -    * Gallium drivers use the convention Y=0=top for surfaces.
>> -    */
>> -   if (st_fb_orientation(fb) == Y_0_TOP) {
>> -      miny = fb->Height - scissor.maxy;
>> -      maxy = fb->Height - scissor.miny;
>> -      scissor.miny = miny;
>> -      scissor.maxy = maxy;
>> -   }
>> +      /* Now invert Y if needed.
>> +       * Gallium drivers use the convention Y=0=top for surfaces.
>> +       */
>> +      if (st_fb_orientation(fb) == Y_0_TOP) {
>> +         miny = fb->Height - scissor[i].maxy;
>> +         maxy = fb->Height - scissor[i].miny;
>> +         scissor[i].miny = miny;
>> +         scissor[i].maxy = maxy;
>> +      }
>>
>> -   if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) {
>> -      /* state has changed */
>> -      st->state.scissor = scissor;  /* struct copy */
>> -      st->pipe->set_scissor_states(st->pipe, 0, 1, &scissor); /* activate */
>> +      if (memcmp(&scissor[i], &st->state.scissor[i], sizeof(scissor)) != 0) {
>> +         /* state has changed */
>> +         st->state.scissor[i] = scissor[i];  /* struct copy */
>> +         changed = true;
>> +      }
>>     }
>> +   if (changed)
>> +      st->pipe->set_scissor_states(st->pipe, 0, ctx->Const.MaxViewports, scissor); /* activate */
>>  }
>>
>>
>> diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c
>> index 8c6d679..7584f9b 100644
>> --- a/src/mesa/state_tracker/st_atom_viewport.c
>> +++ b/src/mesa/state_tracker/st_atom_viewport.c
>> @@ -43,7 +43,7 @@ update_viewport( struct st_context *st )
>>  {
>>     struct gl_context *ctx = st->ctx;
>>     GLfloat yScale, yBias;
>> -
>> +   int i;
>>     /* _NEW_BUFFERS
>>      */
>>     if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
>> @@ -61,26 +61,29 @@ update_viewport( struct st_context *st )
>>
>>     /* _NEW_VIEWPORT
>>      */
>> +   for (i = 0; i < ctx->Const.MaxViewports; i++)
>>     {
>> -      GLfloat x = ctx->ViewportArray[0].X;
>> -      GLfloat y = ctx->ViewportArray[0].Y;
>> -      GLfloat z = ctx->ViewportArray[0].Near;
>> -      GLfloat half_width = ctx->ViewportArray[0].Width * 0.5f;
>> -      GLfloat half_height = ctx->ViewportArray[0].Height * 0.5f;
>> -      GLfloat half_depth = (GLfloat)(ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near) * 0.5f;
>> +      GLfloat x = ctx->ViewportArray[i].X;
>> +      GLfloat y = ctx->ViewportArray[i].Y;
>> +      GLfloat z = ctx->ViewportArray[i].Near;
>> +      GLfloat half_width = ctx->ViewportArray[i].Width * 0.5f;
>> +      GLfloat half_height = ctx->ViewportArray[i].Height * 0.5f;
>> +      GLfloat half_depth = (GLfloat)(ctx->ViewportArray[i].Far - ctx->ViewportArray[i].Near) * 0.5f;
>>
>> -      st->state.viewport.scale[0] = half_width;
>> -      st->state.viewport.scale[1] = half_height * yScale;
>> -      st->state.viewport.scale[2] = half_depth;
>> -      st->state.viewport.scale[3] = 1.0;
>> -
>> -      st->state.viewport.translate[0] = half_width + x;
>> -      st->state.viewport.translate[1] = (half_height + y) * yScale + yBias;
>> -      st->state.viewport.translate[2] = half_depth + z;
>> -      st->state.viewport.translate[3] = 0.0;
>> +      st->state.viewport[i].scale[0] = half_width;
>> +      st->state.viewport[i].scale[1] = half_height * yScale;
>> +      st->state.viewport[i].scale[2] = half_depth;
>> +      st->state.viewport[i].scale[3] = 1.0;
>>
>> -      cso_set_viewport(st->cso_context, &st->state.viewport);
>> +      st->state.viewport[i].translate[0] = half_width + x;
>> +      st->state.viewport[i].translate[1] = (half_height + y) * yScale + yBias;
>> +      st->state.viewport[i].translate[2] = half_depth + z;
>> +      st->state.viewport[i].translate[3] = 0.0;
>>     }
>> +
>> +   cso_set_viewport(st->cso_context, &st->state.viewport[0]);
>> +   if (ctx->Const.MaxViewports > 1)
>> +      st->pipe->set_viewport_states(st->pipe, 1, ctx->Const.MaxViewports - 1, &st->state.viewport[1]);
>>  }
>>
>>
>> diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
>> index 996e0c6..9c699a0 100644
>> --- a/src/mesa/state_tracker/st_context.h
>> +++ b/src/mesa/state_tracker/st_context.h
>> @@ -115,8 +115,8 @@ struct st_context
>>           unsigned size;
>>        } constants[PIPE_SHADER_TYPES];
>>        struct pipe_framebuffer_state framebuffer;
>> -      struct pipe_scissor_state scissor;
>> -      struct pipe_viewport_state viewport;
>> +      struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
>> +      struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
>>        unsigned sample_mask;
>>
>>        GLuint poly_stipple[32];  /**< In OpenGL's bottom-to-top order */
>> diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
>> index 09cd951..177f6b5 100644
>> --- a/src/mesa/state_tracker/st_draw_feedback.c
>> +++ b/src/mesa/state_tracker/st_draw_feedback.c
>> @@ -156,7 +156,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
>>      * code sends state updates to the pipe, not to our private draw module.
>>      */
>>     assert(draw);
>> -   draw_set_viewport_states(draw, 0, 1, &st->state.viewport);
>> +   draw_set_viewport_states(draw, 0, 1, &st->state.viewport[0]);
>>     draw_set_clip_state(draw, &st->state.clip);
>>     draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL);
>>     draw_bind_vertex_shader(draw, st->vp_variant->draw_shader);
>> diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
>> index 4eb2088..3e2c113 100644
>> --- a/src/mesa/state_tracker/st_extensions.c
>> +++ b/src/mesa/state_tracker/st_extensions.c
>> @@ -783,4 +783,13 @@ void st_init_extensions(struct st_context *st)
>>        if (!ctx->Extensions.EXT_transform_feedback)
>>           ctx->Const.DisableVaryingPacking = GL_TRUE;
>>     }
>> +
>> +   if (ctx->API == API_OPENGL_CORE) {
>> +      ctx->Const.MaxViewports = screen->get_param(screen, PIPE_CAP_MAX_VIEWPORTS);
>> +      if (ctx->Const.MaxViewports > 1) {
>> +         ctx->Const.ViewportBounds.Min = -(float)ctx->Const.MaxViewportWidth;
>> +         ctx->Const.ViewportBounds.Max = ctx->Const.MaxViewportWidth;
>> +         ctx->Extensions.ARB_viewport_array = GL_TRUE;
>> +      }
>> +   }
>>  }
>> --
>> 1.8.4.2
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev



More information about the mesa-dev mailing list