[Mesa-dev] [PATCH v2 1/5] intel/blorp: Support map/unmap of blorp_address

Jordan Justen jordan.l.justen at intel.com
Thu Dec 1 03:56:59 UTC 2016


Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/intel/blorp/blorp.h               |  8 +++++++
 src/mesa/drivers/dri/i965/brw_blorp.c | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/src/intel/blorp/blorp.h b/src/intel/blorp/blorp.h
index 823475b..006d7ac 100644
--- a/src/intel/blorp/blorp.h
+++ b/src/intel/blorp/blorp.h
@@ -38,6 +38,7 @@ extern "C" {
 
 struct blorp_batch;
 struct blorp_params;
+struct blorp_address;
 
 struct blorp_context {
    void *driver_ctx;
@@ -52,6 +53,13 @@ struct blorp_context {
       uint32_t vb;
    } mocs;
 
+   void (*map)(const struct blorp_context *blorp,
+               const struct blorp_address *blorp_addr,
+               void **addr,
+               unsigned int *map_size,
+               bool *mapped_previously);
+   void (*unmap)(const struct blorp_context *blorp,
+                 const struct blorp_address *blorp_addr);
    bool (*lookup_shader)(struct blorp_context *blorp,
                          const void *key, uint32_t key_size,
                          uint32_t *kernel_out, void *prog_data_out);
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c b/src/mesa/drivers/dri/i965/brw_blorp.c
index 4c1d858..6e91084 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.c
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c
@@ -34,10 +34,47 @@
 #include "brw_meta_util.h"
 #include "brw_state.h"
 #include "intel_fbo.h"
+#include "intel_batchbuffer.h"
 #include "intel_debug.h"
 
 #define FILE_DEBUG_FLAG DEBUG_BLORP
 
+static void
+brw_blorp_map(const struct blorp_context *blorp,
+              const struct blorp_address *blorp_addr,
+              void **addr,
+              unsigned int *size,
+              bool *mapped_previously)
+{
+   struct brw_context *brw = blorp->driver_ctx;
+   drm_intel_bo *bo = (drm_intel_bo *)blorp_addr->buffer;
+
+   *mapped_previously = bo->virtual != NULL;
+
+   if (!*mapped_previously) {
+      if (drm_intel_bo_references(brw->batch.bo, bo))
+         intel_batchbuffer_flush(brw);
+
+      int ret = drm_intel_bo_map(bo, /*write_enable*/ false);
+      if (ret == -1) {
+         assert(bo->virtual == NULL);
+         *addr = NULL;
+         return;
+      }
+   }
+
+   *addr = bo->virtual;
+   *size = bo->size;
+}
+
+static void
+brw_blorp_unmap(const struct blorp_context *blorp,
+                const struct blorp_address *blorp_addr)
+{
+   drm_intel_bo *bo = (drm_intel_bo *)blorp_addr->buffer;
+   drm_intel_bo_unmap(bo);
+}
+
 static bool
 brw_blorp_lookup_shader(struct blorp_context *blorp,
                         const void *key, uint32_t key_size,
@@ -102,6 +139,8 @@ brw_blorp_init(struct brw_context *brw)
       unreachable("Invalid gen");
    }
 
+   brw->blorp.map = brw_blorp_map;
+   brw->blorp.unmap = brw_blorp_unmap;
    brw->blorp.lookup_shader = brw_blorp_lookup_shader;
    brw->blorp.upload_shader = brw_blorp_upload_shader;
 }
-- 
2.10.2



More information about the mesa-dev mailing list