[Beignet] [PATCH 3/9 newRT] Refine intel batch buffer.
junyan.he at inbox.com
junyan.he at inbox.com
Sat Apr 1 09:43:28 UTC 2017
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/gen/intel_batchbuffer.c | 104 ++++++++++++++++++++++++++++++--------------
src/gen/intel_batchbuffer.h | 14 +++---
2 files changed, 78 insertions(+), 40 deletions(-)
diff --git a/src/gen/intel_batchbuffer.c b/src/gen/intel_batchbuffer.c
index 292be83..8815163 100644
--- a/src/gen/intel_batchbuffer.c
+++ b/src/gen/intel_batchbuffer.c
@@ -54,6 +54,19 @@
#include <assert.h>
#include <errno.h>
+LOCAL intel_batchbuffer_t *
+intel_batchbuffer_new(intel_driver_t *intel)
+{
+ intel_batchbuffer_t *batch = NULL;
+ assert(intel);
+ batch = CL_CALLOC(1, sizeof(intel_batchbuffer_t));
+ if (batch == NULL)
+ return NULL;
+
+ intel_batchbuffer_init(batch, intel);
+ return batch;
+}
+
LOCAL int
intel_batchbuffer_reset(intel_batchbuffer_t *batch, size_t sz)
{
@@ -73,7 +86,7 @@ intel_batchbuffer_reset(intel_batchbuffer_t *batch, size_t sz)
batch->buffer = NULL;
return -1;
}
- batch->map = (uint8_t*) batch->buffer->virtual;
+ batch->map = (uint8_t *)batch->buffer->virtual;
batch->size = sz;
batch->ptr = batch->map;
batch->atomic = 0;
@@ -89,20 +102,6 @@ intel_batchbuffer_init(intel_batchbuffer_t *batch, intel_driver_t *intel)
batch->intel = intel;
}
-LOCAL void
-intel_batchbuffer_terminate(intel_batchbuffer_t *batch)
-{
- assert(batch->buffer);
-
- if (batch->map) {
- dri_bo_unmap(batch->buffer);
- batch->map = NULL;
- }
-
- dri_bo_unreference(batch->buffer);
- batch->buffer = NULL;
-}
-
LOCAL int
intel_batchbuffer_flush(intel_batchbuffer_t *batch)
{
@@ -114,11 +113,11 @@ intel_batchbuffer_flush(intel_batchbuffer_t *batch)
return 0;
if ((used & 4) == 0) {
- *(uint32_t*) batch->ptr = 0;
+ *(uint32_t *)batch->ptr = 0;
batch->ptr += 4;
}
- *(uint32_t*)batch->ptr = MI_BATCH_BUFFER_END;
+ *(uint32_t *)batch->ptr = MI_BATCH_BUFFER_END;
batch->ptr += 4;
used = batch->ptr - batch->map;
dri_bo_unmap(batch->buffer);
@@ -128,10 +127,10 @@ intel_batchbuffer_flush(intel_batchbuffer_t *batch)
intel_driver_lock_hardware(batch->intel);
int flag = I915_EXEC_RENDER;
- if(batch->enable_slm) {
+ if (batch->enable_slm) {
/* use the hard code here temp, must change to
* I915_EXEC_ENABLE_SLM when it drm accept the patch */
- flag |= (1<<13);
+ flag |= (1 << 13);
}
if (drm_intel_gem_bo_context_exec(batch->buffer, batch->intel->ctx, used, flag) < 0) {
fprintf(stderr, "drm_intel_gem_bo_context_exec() failed: %s\n", strerror(errno));
@@ -144,11 +143,21 @@ intel_batchbuffer_flush(intel_batchbuffer_t *batch)
return err;
}
-LOCAL void
+LOCAL int
+intel_batchbuffer_finish(intel_batchbuffer_t *batch)
+{
+ assert(batch && batch->last_bo);
+ drm_intel_bo_reference(batch->last_bo);
+ drm_intel_bo_wait_rendering(batch->last_bo);
+ drm_intel_bo_unreference(batch->last_bo);
+ return 0;
+}
+
+LOCAL void
intel_batchbuffer_emit_reloc(intel_batchbuffer_t *batch,
- dri_bo *bo,
+ dri_bo *bo,
uint32_t read_domains,
- uint32_t write_domains,
+ uint32_t write_domains,
uint32_t delta)
{
assert(batch->ptr - batch->map < batch->size);
@@ -161,20 +170,41 @@ intel_batchbuffer_emit_reloc(intel_batchbuffer_t *batch,
intel_batchbuffer_emit_dword(batch, bo->offset + delta);
}
-LOCAL intel_batchbuffer_t*
-intel_batchbuffer_new(intel_driver_t *intel)
+LOCAL intel_batchbuffer_t *
+intel_batchbuffer_create(intel_driver_t *intel, size_t sz)
{
intel_batchbuffer_t *batch = NULL;
assert(intel);
- TRY_ALLOC_NO_ERR (batch, CL_CALLOC(1, sizeof(intel_batchbuffer_t)));
- intel_batchbuffer_init(batch, intel);
-exit:
+ batch = CL_CALLOC(1, sizeof(intel_batchbuffer_t));
+ if (batch == NULL)
+ return NULL;
+
+ batch->intel = intel;
+
+ batch->buffer = dri_bo_alloc(batch->intel->bufmgr,
+ "batch buffer",
+ sz,
+ 64);
+ if (batch->buffer == NULL) {
+ CL_FREE(batch);
+ return NULL;
+ }
+
+ if (dri_bo_map(batch->buffer, 1) != 0) {
+ dri_bo_unreference(batch->buffer);
+ CL_FREE(batch);
+ return NULL;
+ }
+
+ batch->map = (uint8_t *)batch->buffer->virtual;
+ batch->size = sz;
+ batch->ptr = batch->map;
+ batch->atomic = 0;
+ batch->last_bo = batch->buffer;
+ batch->enable_slm = 0;
+
return batch;
-error:
- intel_batchbuffer_delete(batch);
- batch = NULL;
- goto exit;
}
LOCAL void
@@ -182,8 +212,16 @@ intel_batchbuffer_delete(intel_batchbuffer_t *batch)
{
if (batch == NULL)
return;
- if(batch->buffer)
- intel_batchbuffer_terminate(batch);
+
+ if (batch->buffer) {
+ if (batch->map) {
+ dri_bo_unmap(batch->buffer);
+ batch->map = NULL;
+ }
+
+ dri_bo_unreference(batch->buffer);
+ batch->buffer = NULL;
+ }
CL_FREE(batch);
}
diff --git a/src/gen/intel_batchbuffer.h b/src/gen/intel_batchbuffer.h
index 0544e9a..95db24f 100644
--- a/src/gen/intel_batchbuffer.h
+++ b/src/gen/intel_batchbuffer.h
@@ -90,16 +90,16 @@ typedef struct intel_batchbuffer
} intel_batchbuffer_t;
extern intel_batchbuffer_t* intel_batchbuffer_new(struct intel_driver*);
+extern int intel_batchbuffer_reset(intel_batchbuffer_t*, size_t sz);
+
+
+extern intel_batchbuffer_t* intel_batchbuffer_create(struct intel_driver*, size_t);
extern void intel_batchbuffer_delete(intel_batchbuffer_t*);
-extern void intel_batchbuffer_emit_reloc(intel_batchbuffer_t*,
- drm_intel_bo*,
- uint32_t read_domains,
- uint32_t write_domains,
- uint32_t delta);
+extern void intel_batchbuffer_emit_reloc(intel_batchbuffer_t*, drm_intel_bo*, uint32_t read_domains,
+ uint32_t write_domains, uint32_t delta);
extern void intel_batchbuffer_init(intel_batchbuffer_t*, struct intel_driver*);
-extern void intel_batchbuffer_terminate(intel_batchbuffer_t*);
extern int intel_batchbuffer_flush(intel_batchbuffer_t*);
-extern int intel_batchbuffer_reset(intel_batchbuffer_t*, size_t sz);
+extern int intel_batchbuffer_finish(intel_batchbuffer_t*);
static INLINE uint32_t
intel_batchbuffer_space(const intel_batchbuffer_t *batch)
--
2.7.4
More information about the Beignet
mailing list