[Mesa-dev] [PATCH v2 2/6] mesa: wire up InvalidateSubFramebuffer

Rob Clark robdclark at gmail.com
Wed Dec 12 15:48:39 UTC 2018


Signed-off-by: Rob Clark <robdclark at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/main/dd.h       |  3 +++
 src/mesa/main/fbobject.c | 43 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 1214eeaa474..c7112677223 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -786,6 +786,9 @@ struct dd_function_table {
                            GLbitfield mask, GLenum filter);
    void (*DiscardFramebuffer)(struct gl_context *ctx, struct gl_framebuffer *fb,
                               struct gl_renderbuffer_attachment *att);
+   void (*DiscardSubFramebuffer)(struct gl_context *ctx, struct gl_framebuffer *fb,
+                                 struct gl_renderbuffer_attachment *att, GLint x,
+                                 GLint y, GLsizei width, GLsizei height);
 
    /**
     * \name Functions for GL_ARB_sample_locations
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 442435655fa..c48067324dd 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -4697,12 +4697,50 @@ discard_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    }
 }
 
+static void
+discard_sub_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+                        GLsizei numAttachments, const GLenum *attachments,
+                        GLint x, GLint y, GLsizei width, GLsizei height)
+{
+   if (!ctx->Driver.DiscardSubFramebuffer)
+      return;
+
+   /* In the trivial case, turn it into discard_framebuffer(), on the
+    * premise that drivers are more likely to implement the simpler
+    * interface:
+    */
+   if (x == 0 && y == 0 &&
+       width >= fb->Width &&
+       height >= fb->Height) {
+      discard_framebuffer(ctx, fb, numAttachments, attachments);
+      return;
+   }
+
+   for (int i = 0; i < numAttachments; i++) {
+      struct gl_renderbuffer_attachment *att =
+            get_fb_attachment(ctx, fb, attachments[i]);
+
+      if (!att)
+         continue;
+
+      ctx->Driver.DiscardSubFramebuffer(ctx, fb, att, x, y, width, height);
+   }
+}
+
 void GLAPIENTRY
 _mesa_InvalidateSubFramebuffer_no_error(GLenum target, GLsizei numAttachments,
                                         const GLenum *attachments, GLint x,
                                         GLint y, GLsizei width, GLsizei height)
 {
-   /* no-op */
+   struct gl_framebuffer *fb;
+   GET_CURRENT_CONTEXT(ctx);
+
+   fb = get_framebuffer_target(ctx, target);
+   if (!fb)
+      return;
+
+   discard_sub_framebuffer(ctx, fb, numAttachments, attachments,
+                           x, y, width, height);
 }
 
 
@@ -4725,6 +4763,9 @@ _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments,
    invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments,
                                   x, y, width, height,
                                   "glInvalidateSubFramebuffer");
+
+   discard_sub_framebuffer(ctx, fb, numAttachments, attachments,
+                           x, y, width, height);
 }
 
 
-- 
2.19.2



More information about the mesa-dev mailing list