[PATCH 1/2] gallium: let drivers expose a fully capable clear function

Christoph Bumiller e0425955 at student.tuwien.ac.at
Sat Apr 10 10:40:28 PDT 2010


---
 src/gallium/include/pipe/p_context.h |    6 +++-
 src/gallium/include/pipe/p_defines.h |    5 +++-
 src/mesa/state_tracker/st_cb_clear.c |   50 ++++++++++++++++++++++++++++++++-
 src/mesa/state_tracker/st_cb_clear.h |    2 +-
 src/mesa/state_tracker/st_context.c  |    8 +++--
 src/mesa/state_tracker/st_context.h  |    3 +-
 6 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 1aa0cbe..7d1ebaf 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -260,7 +260,11 @@ struct pipe_context {
 
    /**
     * Clear the specified set of currently bound buffers to specified values.
-    * The entire buffers are cleared (no scissor, no colormask, etc).
+    * If the driver doesn't expose PIPE_CAP_OPENGL_CLEAR, the entire buffers
+    * will be cleared (no scissor, no colormask, etc).
+    *
+    * If PIPE_CAP_OPENGL_CLEAR is supported, the driver will apply currently
+    * bound scissors, color and stencil masks.
     *
     * \param buffers  bitfield of PIPE_CLEAR_* values.
     * \param rgba  pointer to an array of one float for each of r, g, b, a.
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 0a4bd58..c698403 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -189,8 +189,10 @@ enum pipe_texture_target {
  */
 /** All color buffers currently bound */
 #define PIPE_CLEAR_COLOR        (1 << 0)
+#define PIPE_CLEAR_DEPTH        (1 << 1)
+#define PIPE_CLEAR_STENCIL      (1 << 2)
 /** Depth/stencil combined */
-#define PIPE_CLEAR_DEPTHSTENCIL (1 << 1)
+#define PIPE_CLEAR_DEPTHSTENCIL (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)
 
 
 /**
@@ -453,6 +455,7 @@ enum pipe_transfer_usage {
 #define PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT 37
 #define PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER 38
 #define PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER 39
+#define PIPE_CAP_OPENGL_CLEAR            40
 
 
 /**
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index eb9ba05..b74d755 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -539,9 +539,55 @@ st_Clear(GLcontext *ctx, GLbitfield mask)
                             ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
 }
 
+static void
+st_Clear_no_fallback(GLcontext *ctx, GLbitfield mask)
+{
+   struct st_context *st = ctx->st;
+   struct gl_renderbuffer *depthRb
+      = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+   struct gl_renderbuffer *stencilRb
+      = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+   unsigned clear_buffers = 0x0;
+   GLuint i;
+
+   /* This makes sure the pipe has the latest scissor, etc values */
+   st_validate_state( st );
+
+   if (mask & BUFFER_BITS_COLOR) {
+      for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+         GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
+
+         if (mask & (1 << b)) {
+            struct gl_renderbuffer *rb
+               = ctx->DrawBuffer->Attachment[b].Renderbuffer;
+
+            assert(rb);
+            if (st_renderbuffer(rb)->surface)
+               clear_buffers |= PIPE_CLEAR_COLOR;
+         }
+      }
+   }
+
+   /* separate depth/stencil clears */
+   if (mask & BUFFER_BIT_DEPTH)
+         if (st_renderbuffer(depthRb)->surface)
+            clear_buffers |= PIPE_CLEAR_DEPTH;
+
+   if (mask & BUFFER_BIT_STENCIL)
+         if (st_renderbuffer(stencilRb)->surface)
+            clear_buffers |= PIPE_CLEAR_STENCIL;
+
+   st->pipe->clear(st->pipe, clear_buffers, ctx->Color.ClearColor,
+                   ctx->Depth.Clear, ctx->Stencil.Clear);
+
+   if (mask & BUFFER_BIT_ACCUM)
+      st_clear_accum_buffer(ctx,
+                            ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+}
+
 
 void
-st_init_clear_functions(struct dd_function_table *functions)
+st_init_clear_functions(struct dd_function_table *functions, boolean cap)
 {
-   functions->Clear = st_Clear;
+   functions->Clear = cap ? st_Clear_no_fallback : st_Clear;
 }
diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h
index bc035ac..edac611 100644
--- a/src/mesa/state_tracker/st_cb_clear.h
+++ b/src/mesa/state_tracker/st_cb_clear.h
@@ -42,7 +42,7 @@ st_flush_clear(struct st_context *st);
 
 
 extern void
-st_init_clear_functions(struct dd_function_table *functions);
+st_init_clear_functions(struct dd_function_table *functions, boolean cap);
 
 
 #endif /* ST_CB_CLEAR_H */
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 0a1503f..be0952c 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -198,7 +198,7 @@ struct st_context *st_create_context(struct pipe_context *pipe,
    struct dd_function_table funcs;
 
    memset(&funcs, 0, sizeof(funcs));
-   st_init_driver_functions(&funcs);
+   st_init_driver_functions(&funcs, pipe->screen);
 
    ctx = _mesa_create_context(visual, shareCtx, &funcs, NULL);
 
@@ -338,7 +338,8 @@ st_proc st_get_proc_address(const char *procname)
 
 
 
-void st_init_driver_functions(struct dd_function_table *functions)
+void st_init_driver_functions(struct dd_function_table *functions,
+                              struct pipe_screen *screen)
 {
    _mesa_init_glsl_driver_functions(functions);
 
@@ -349,7 +350,8 @@ void st_init_driver_functions(struct dd_function_table *functions)
    st_init_blit_functions(functions);
 #endif
    st_init_bufferobject_functions(functions);
-   st_init_clear_functions(functions);
+   st_init_clear_functions(functions,
+                           screen->get_param(screen, PIPE_CAP_OPENGL_CLEAR));
 #if FEATURE_drawpix
    st_init_bitmap_functions(functions);
    st_init_drawpixels_functions(functions);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index f28d5aa..3ff4c45 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -218,7 +218,8 @@ struct st_framebuffer
 };
 
 
-extern void st_init_driver_functions(struct dd_function_table *functions);
+extern void st_init_driver_functions(struct dd_function_table *functions,
+                                     struct pipe_screen *screen);
 
 void st_invalidate_state(GLcontext * ctx, GLuint new_state);
 
-- 
1.6.4.4


--------------060706050609060800020905
Content-Type: text/plain;
 name="0002-nv50-support-PIPE_CAP_OPENGL_CLEAR.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0002-nv50-support-PIPE_CAP_OPENGL_CLEAR.patch"



More information about the mesa-dev mailing list