nvc0: add support for GL_EXT_window_rectangles
authorIlia Mirkin <imirkin@alum.mit.edu>
Sun, 12 Jun 2016 04:46:18 +0000 (00:46 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sat, 18 Jun 2016 17:38:30 +0000 (13:38 -0400)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
docs/relnotes/12.1.0.html
src/gallium/drivers/nouveau/nvc0/nvc0_context.h
src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
src/gallium/drivers/nouveau/nvc0/nvc0_screen.h
src/gallium/drivers/nouveau/nvc0/nvc0_state.c
src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
src/gallium/drivers/nouveau/nvc0/nvc0_stateobj.h
src/gallium/drivers/nouveau/nvc0/nvc0_surface.c

index ed8e5bcdad1ada08910ecfadf1e388f3b272180a..a33460223c64eda767486388a3c45b5e8984be43 100644 (file)
@@ -46,6 +46,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_ARB_ES3_1_compatibility on i965</li>
+<li>GL_EXT_window_rectangles on nvc0</li>
 </ul>
 
 <h2>Bug fixes</h2>
index 1b3f88becddc022c9a0bee3efb60a858c5465ff1..fe9f9f56e0aed89e27039d6b8add90916df62c70 100644 (file)
@@ -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;
index 1afa43a0b5c2ab97d2842b2847a78f45437959c2..08ec4136880494e5cec2fabc85bae900041e9784 100644 (file)
@@ -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 NVC0_MAX_WINDOW_RECTANGLES;
 
    /* 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:
index b6edc33993dc59e144a4241a9e19a5d5f0109673..4a89794853fe20d52e00b97301622a8c62cf889a 100644 (file)
@@ -25,6 +25,8 @@
 
 #define NVC0_MAX_IMAGES 8
 
+#define NVC0_MAX_WINDOW_RECTANGLES 8
+
 struct nvc0_context;
 
 struct nvc0_blitter;
index 92161ec9e6509266c56b6ee27dfd26419fe686ca..7e42be76bf1a5684295c15f937aebb6022f37fb9 100644 (file)
@@ -999,6 +999,22 @@ nvc0_set_viewport_states(struct pipe_context *pipe,
 
 }
 
+static void
+nvc0_set_window_rectangles(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, NVC0_MAX_WINDOW_RECTANGLES);
+   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],
@@ -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_rectangles = nvc0_set_window_rectangles;
    pipe->set_tess_state = nvc0_set_tess_state;
 
    pipe->create_vertex_elements_state = nvc0_vertex_state_create;
index ad44e859a7c547844507d5f786030de4e83ac89a..05c15ce070a4eaf540270cd852870341c11c6c66 100644 (file)
@@ -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)), NVC0_MAX_WINDOW_RECTANGLES * 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 < NVC0_MAX_WINDOW_RECTANGLES; 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 },
index f9680f5a90f447ff6f8908a997419ea9ad6af341..c900fcadcb7d9626727a3962854ed9e043252ff3 100644 (file)
@@ -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[PIPE_MAX_WINDOW_RECTANGLES];
+};
+
 struct nvc0_so_target {
    struct pipe_stream_output_target pipe;
    struct pipe_query *pq;
index a1775698a3dc1efa94ada637fd0ddec3bbb8c4d6..7556e7133fc6962b586a72d3c01a6c34a073f831 100644 (file)
@@ -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,13 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
    nvc0->gmtyprog = NULL;
    nvc0->fragprog = ctx->fp;
 
+   nvc0->window_rect.rects =
+      MIN2(info->num_window_rectangles, NVC0_MAX_WINDOW_RECTANGLES);
+   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);
+
    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 +1109,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
@@ -1127,6 +1137,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
    nvc0->fragprog = blit->saved.fp;
 
    nvc0->min_samples = blit->saved.min_samples;
+   nvc0->window_rect = blit->saved.window_rect;
 
    pipe_sampler_view_reference(&nvc0->textures[4][0], NULL);
    pipe_sampler_view_reference(&nvc0->textures[4][1], NULL);
@@ -1158,7 +1169,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 +1202,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 +1617,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);