From c49a71c03c9166b0814db92420eadac74cbc4b11 Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Mon, 8 Jul 2024 19:18:53 +0200 Subject: [PATCH] gbm: mark surface buffers as explicit flushed Some drivers are able to optimize buffer usage when it is known that external visibility of buffer changes only needs to be guaranteed after well defined transition points, like eglSwapBuffers. Add a BO flag to specify this behavior and set it with GBM surfaces. Signed-off-by: Lucas Stach Acked-by: Daniel Stone Part-of: --- src/gbm/backends/dri/gbm_dri.c | 10 ++++++++-- src/gbm/main/gbm.h | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index 4e6b2b5278d..1979e8d8920 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -895,8 +895,14 @@ gbm_dri_bo_create(struct gbm_device *gbm, dri_use |= __DRI_IMAGE_USE_LINEAR; if (usage & GBM_BO_USE_PROTECTED) dri_use |= __DRI_IMAGE_USE_PROTECTED; - if (usage & GBM_BO_USE_FRONT_RENDERING) + if (usage & GBM_BO_USE_FRONT_RENDERING) { + assert (!(usage & GBM_BO_EXPLICIT_FLUSH)); dri_use |= __DRI_IMAGE_USE_FRONT_RENDERING; + } + if (usage & GBM_BO_EXPLICIT_FLUSH) { + assert (!(usage & GBM_BO_USE_FRONT_RENDERING)); + dri_use |= __DRI_IMAGE_USE_BACKBUFFER; + } /* Gallium drivers requires shared in order to get the handle/stride */ dri_use |= __DRI_IMAGE_USE_SHARE; @@ -1100,7 +1106,7 @@ gbm_dri_surface_create(struct gbm_device *gbm, surf->base.v0.width = width; surf->base.v0.height = height; surf->base.v0.format = core->v0.format_canonicalize(format); - surf->base.v0.flags = flags; + surf->base.v0.flags = flags | GBM_BO_EXPLICIT_FLUSH; if (!modifiers) { assert(!count); return &surf->base; diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h index 9c680f65b95..be529cd272d 100644 --- a/src/gbm/main/gbm.h +++ b/src/gbm/main/gbm.h @@ -330,7 +330,11 @@ enum gbm_bo_flags { */ GBM_BO_FIXED_COMPRESSION_12BPC = (13 << 7), - /* next available value is (1 << 11) */ + /** + * This buffer will be used with an API with well defined transition points + * between context internal usage and external visibility. + */ + GBM_BO_EXPLICIT_FLUSH = (1 << 11), }; #define GBM_BO_FIXED_COMPRESSION_MASK (((1 << 11) - 1) & ~((1 << 7) - 1))