mesa: update fallthrough comment so gcc can see it
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index 3a49bd4d6c1c65138533663345f5e3a864a46c4d..e38f44ed78bc5ac3ee17683e62deef74a6227cc8 100644 (file)
@@ -56,7 +56,7 @@
 #include "pipe/p_shader_tokens.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_simple_shaders.h"
 
@@ -85,19 +85,19 @@ void
 st_destroy_clear(struct st_context *st)
 {
    if (st->clear.fs) {
-      cso_delete_fragment_shader(st->cso_context, st->clear.fs);
+      st->pipe->delete_fs_state(st->pipe, st->clear.fs);
       st->clear.fs = NULL;
    }
    if (st->clear.vs) {
-      cso_delete_vertex_shader(st->cso_context, st->clear.vs);
+      st->pipe->delete_vs_state(st->pipe, st->clear.vs);
       st->clear.vs = NULL;
    }
    if (st->clear.vs_layered) {
-      cso_delete_vertex_shader(st->cso_context, st->clear.vs_layered);
+      st->pipe->delete_vs_state(st->pipe, st->clear.vs_layered);
       st->clear.vs_layered = NULL;
    }
    if (st->clear.gs_layered) {
-      cso_delete_geometry_shader(st->cso_context, st->clear.gs_layered);
+      st->pipe->delete_gs_state(st->pipe, st->clear.gs_layered);
       st->clear.gs_layered = NULL;
    }
 }
@@ -176,8 +176,10 @@ set_vertex_shader(struct st_context *st)
       if (use_nir) {
          st->clear.vs = make_nir_clear_vertex_shader(st, false);
       } else {
-         const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
-                                         TGSI_SEMANTIC_GENERIC };
+         const enum tgsi_semantic semantic_names[] = {
+            TGSI_SEMANTIC_POSITION,
+            TGSI_SEMANTIC_GENERIC
+         };
          const uint semantic_indexes[] = { 0, 0 };
          st->clear.vs = util_make_vertex_passthrough_shader(st->pipe, 2,
                                                             semantic_names,
@@ -265,7 +267,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
                         CSO_BIT_STREAM_OUTPUTS |
                         CSO_BIT_VERTEX_ELEMENTS |
                         CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
-                        CSO_BIT_PAUSE_QUERIES |
+                        (st->active_queries ? CSO_BIT_PAUSE_QUERIES : 0) |
                         CSO_BITS_ALL_SHADERS));
 
    /* blend state: RGBA masking */
@@ -278,6 +280,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
          int i;
 
          blend.independent_blend_enable = num_buffers > 1;
+         blend.max_rt = num_buffers - 1;
 
          for (i = 0; i < num_buffers; i++) {
             if (!(clear_buffers & (PIPE_CLEAR_COLOR0 << i)))
@@ -319,10 +322,13 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
       cso_set_depth_stencil_alpha(cso, &depth_stencil);
    }
 
-   cso_set_vertex_elements(cso, 2, st->util_velems);
+   st->util_velems.count = 2;
+   cso_set_vertex_elements(cso, &st->util_velems);
+
    cso_set_stream_outputs(cso, 0, NULL, NULL);
    cso_set_sample_mask(cso, ~0);
    cso_set_min_samples(cso, 1);
+   st->clear.raster.multisample = st->state.fb_num_samples > 1;
    cso_set_rasterizer(cso, &st->clear.raster);
 
    /* viewport state: viewport matching window dims */
@@ -426,6 +432,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
       = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
    GLbitfield quad_buffers = 0x0;
    GLbitfield clear_buffers = 0x0;
+   bool have_scissor_buffers = false;
    GLuint i;
 
    st_flush_bitmap_cache(st);
@@ -456,12 +463,14 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
             unsigned surf_colormask =
                util_format_colormask(util_format_description(strb->surface->format));
 
-            if (is_scissor_enabled(ctx, rb) ||
+            bool scissor = is_scissor_enabled(ctx, rb);
+            if ((scissor && !st->can_scissor_clear) ||
                 is_window_rectangle_enabled(ctx) ||
                 ((colormask & surf_colormask) != surf_colormask))
                quad_buffers |= PIPE_CLEAR_COLOR0 << i;
             else
                clear_buffers |= PIPE_CLEAR_COLOR0 << i;
+            have_scissor_buffers |= scissor && st->can_scissor_clear;
          }
       }
    }
@@ -504,10 +513,31 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
     * renderbuffers, because it's likely to be faster.
     */
    if (clear_buffers) {
+      const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
+      struct pipe_scissor_state scissor_state = {
+         .minx = MAX2(scissor->X, 0),
+         .miny = MAX2(scissor->Y, 0),
+         .maxx = MAX2(scissor->X + scissor->Width, 0),
+         .maxy = MAX2(scissor->Y + scissor->Height, 0),
+
+      };
+
+      /* Now invert Y if needed.
+       * Gallium drivers use the convention Y=0=top for surfaces.
+       */
+      if (st->state.fb_orientation == Y_0_TOP) {
+         const struct gl_framebuffer *fb = ctx->DrawBuffer;
+         /* use intermediate variables to avoid uint underflow */
+         GLint miny, maxy;
+         miny = fb->Height - scissor_state.maxy;
+         maxy = fb->Height - scissor_state.miny;
+         scissor_state.miny = MAX2(miny, 0);
+         scissor_state.maxy = MAX2(maxy, 0);
+      }
       /* We can't translate the clear color to the colorbuffer format,
        * because different colorbuffers may have different formats.
        */
-      st->pipe->clear(st->pipe, clear_buffers,
+      st->pipe->clear(st->pipe, clear_buffers, have_scissor_buffers ? &scissor_state : NULL,
                       (union pipe_color_union*)&ctx->Color.ClearColor,
                       ctx->Depth.Clear, ctx->Stencil.Clear);
    }