st/mesa: add a second pipeline for compute
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index 371f7fcdae7027cc9a9bf365553071c391c0430e..1e965b182ea99b8a9ae308dd3d1f1b087a51486d 100644 (file)
@@ -41,6 +41,7 @@
 #include "program/prog_instruction.h"
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_cb_bitmap.h"
 #include "st_cb_clear.h"
 #include "st_cb_fbo.h"
 #include "st_format.h"
@@ -88,13 +89,21 @@ st_destroy_clear(struct st_context *st)
       cso_delete_vertex_shader(st->cso_context, st->clear.vs);
       st->clear.vs = NULL;
    }
+   if (st->clear.vs_layered) {
+      cso_delete_vertex_shader(st->cso_context, 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->clear.gs_layered = NULL;
+   }
 }
 
 
 /**
  * Helper function to set the fragment shaders.
  */
-static INLINE void
+static inline void
 set_fragment_shader(struct st_context *st)
 {
    if (!st->clear.fs)
@@ -110,7 +119,7 @@ set_fragment_shader(struct st_context *st)
 /**
  * Helper function to set the vertex shader.
  */
-static INLINE void
+static inline void
 set_vertex_shader(struct st_context *st)
 {
    /* vertex shader - still required to provide the linkage between
@@ -123,10 +132,12 @@ set_vertex_shader(struct st_context *st)
       const uint semantic_indexes[] = { 0, 0 };
       st->clear.vs = util_make_vertex_passthrough_shader(st->pipe, 2,
                                                          semantic_names,
-                                                         semantic_indexes);
+                                                         semantic_indexes,
+                                                         FALSE);
    }
 
    cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
+   cso_set_geometry_shader_handle(st->cso_context, NULL);
 }
 
 
@@ -135,18 +146,25 @@ set_vertex_shader_layered(struct st_context *st)
 {
    struct pipe_context *pipe = st->pipe;
 
-   if (!pipe->screen->get_param(pipe->screen, PIPE_CAP_TGSI_INSTANCEID) ||
-       !pipe->screen->get_param(pipe->screen, PIPE_CAP_TGSI_VS_LAYER)) {
-      assert(!"Got layered clear, but the VS layer output is unsupported");
+   if (!pipe->screen->get_param(pipe->screen, PIPE_CAP_TGSI_INSTANCEID)) {
+      assert(!"Got layered clear, but VS instancing is unsupported");
       set_vertex_shader(st);
       return;
    }
 
    if (!st->clear.vs_layered) {
-      st->clear.vs_layered = util_make_layered_clear_vertex_shader(pipe);
+      bool vs_layer =
+         pipe->screen->get_param(pipe->screen, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT);
+      if (vs_layer) {
+         st->clear.vs_layered = util_make_layered_clear_vertex_shader(pipe);
+      } else {
+         st->clear.vs_layered = util_make_layered_clear_helper_vertex_shader(pipe);
+         st->clear.gs_layered = util_make_layered_clear_geometry_shader(pipe);
+      }
    }
 
    cso_set_vertex_shader_handle(st->cso_context, st->clear.vs_layered);
+   cso_set_geometry_shader_handle(st->cso_context, st->clear.gs_layered);
 }
 
 
@@ -167,12 +185,16 @@ draw_quad(struct st_context *st,
 
    vb.stride = 8 * sizeof(float);
 
-   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
-                      &vb.buffer_offset, &vb.buffer,
-                      (void **) &vertices) != PIPE_OK) {
+   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4,
+                  &vb.buffer_offset, &vb.buffer,
+                  (void **) &vertices);
+   if (!vb.buffer) {
       return;
    }
 
+   /* Convert Z from [0,1] to [-1,1] range */
+   z = z * 2.0f - 1.0f;
+
    /* positions */
    vertices[0][0][0] = x0;
    vertices[0][0][1] = y0;
@@ -227,7 +249,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
       util_framebuffer_get_num_layers(&st->state.framebuffer);
 
    /*
-   printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__, 
+   printf("%s %s%s%s %f,%f %f,%f\n", __func__,
          color ? "color, " : "",
          depth ? "depth, " : "",
          stencil ? "stencil" : "",
@@ -245,6 +267,8 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
    cso_save_fragment_shader(st->cso_context);
    cso_save_stream_outputs(st->cso_context);
    cso_save_vertex_shader(st->cso_context);
+   cso_save_tessctrl_shader(st->cso_context);
+   cso_save_tesseval_shader(st->cso_context);
    cso_save_geometry_shader(st->cso_context);
    cso_save_vertex_elements(st->cso_context);
    cso_save_aux_vertex_buffer_slot(st->cso_context);
@@ -319,17 +343,16 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
       struct pipe_viewport_state vp;
       vp.scale[0] = 0.5f * fb_width;
       vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f);
-      vp.scale[2] = 1.0f;
-      vp.scale[3] = 1.0f;
+      vp.scale[2] = 0.5f;
       vp.translate[0] = 0.5f * fb_width;
       vp.translate[1] = 0.5f * fb_height;
-      vp.translate[2] = 0.0f;
-      vp.translate[3] = 0.0f;
+      vp.translate[2] = 0.5f;
       cso_set_viewport(st->cso_context, &vp);
    }
 
    set_fragment_shader(st);
-   cso_set_geometry_shader_handle(st->cso_context, NULL);
+   cso_set_tessctrl_shader_handle(st->cso_context, NULL);
+   cso_set_tesseval_shader_handle(st->cso_context, NULL);
 
    if (num_layers > 1)
       set_vertex_shader_layered(st);
@@ -354,6 +377,8 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
    cso_restore_viewport(st->cso_context);
    cso_restore_fragment_shader(st->cso_context);
    cso_restore_vertex_shader(st->cso_context);
+   cso_restore_tessctrl_shader(st->cso_context);
+   cso_restore_tesseval_shader(st->cso_context);
    cso_restore_geometry_shader(st->cso_context);
    cso_restore_vertex_elements(st->cso_context);
    cso_restore_aux_vertex_buffer_slot(st->cso_context);
@@ -364,7 +389,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
 /**
  * Return if the scissor must be enabled during the clear.
  */
-static INLINE GLboolean
+static inline GLboolean
 is_scissor_enabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    return (ctx->Scissor.EnableFlags & 1) &&
@@ -378,7 +403,7 @@ is_scissor_enabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
 /**
  * Return if all of the color channels are masked.
  */
-static INLINE GLboolean
+static inline GLboolean
 is_color_disabled(struct gl_context *ctx, int i)
 {
    return !ctx->Color.ColorMask[i][0] &&
@@ -391,7 +416,7 @@ is_color_disabled(struct gl_context *ctx, int i)
 /**
  * Return if any of the color channels are masked.
  */
-static INLINE GLboolean
+static inline GLboolean
 is_color_masked(struct gl_context *ctx, int i)
 {
    return !ctx->Color.ColorMask[i][0] ||
@@ -404,7 +429,7 @@ is_color_masked(struct gl_context *ctx, int i)
 /**
  * Return if all of the stencil bits are masked.
  */
-static INLINE GLboolean
+static inline GLboolean
 is_stencil_disabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    const GLuint stencilMax = 0xff;
@@ -417,7 +442,7 @@ is_stencil_disabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
 /**
  * Return if any of the stencil bits are masked.
  */
-static INLINE GLboolean
+static inline GLboolean
 is_stencil_masked(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    const GLuint stencilMax = 0xff;
@@ -442,8 +467,10 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
    GLbitfield clear_buffers = 0x0;
    GLuint i;
 
+   st_flush_bitmap_cache(st);
+
    /* This makes sure the pipe has the latest scissor, etc values */
-   st_validate_state( st );
+   st_validate_state( st, ST_PIPELINE_RENDER );
 
    if (mask & BUFFER_BITS_COLOR) {
       for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {