This wraps libdrm functionality to create, destroy, and exec with contexts. This patch shouldn't be applied until libdrm for contexts is updated. Signed-off-by: Ben Widawsky <ben at bwidawsk.net> --- lib/drmtest.c | 16 ++++++++++++++++ lib/drmtest.h | 2 ++ lib/intel_batchbuffer.c | 40 ++++++++++++++++++++++++++++++++++++---- lib/intel_batchbuffer.h | 2 ++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index ebc396f..eb429b5 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -294,6 +294,22 @@ uint32_t gem_create(int fd, int size) return create.handle; } +uint32_t gem_context_create(int fd) +{ + struct drm_i915_gem_context_create create; + do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create); + assert(create.ctx_id); + + return create.ctx_id; +} + +void gem_context_destroy(int fd, uint32_t ctx_id) +{ + struct drm_i915_gem_context_destroy destroy; + destroy.ctx_id = ctx_id; + do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); +} + void *gem_mmap(int fd, uint32_t handle, int size, int prot) { struct drm_i915_gem_mmap_gtt mmap_arg; diff --git a/lib/drmtest.h b/lib/drmtest.h index f4462a2..170b420 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -50,6 +50,8 @@ void gem_set_domain(int fd, uint32_t handle, uint32_t read_domains, uint32_t write_domain); void gem_sync(int fd, uint32_t handle); uint32_t gem_create(int fd, int size); +uint32_t gem_context_create(int fd); +void gem_context_destroy(int fd, uint32_t ctx_id); void *gem_mmap(int fd, uint32_t handle, int size, int prot); uint64_t gem_aperture_size(int fd); uint64_t gem_mappable_aperture_size(void); diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c index 325066e..d9d49b6 100644 --- a/lib/intel_batchbuffer.c +++ b/lib/intel_batchbuffer.c @@ -75,13 +75,13 @@ intel_batchbuffer_free(struct intel_batchbuffer *batch) #define CMD_POLY_STIPPLE_OFFSET 0x7906 -void -intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring) +static unsigned int +flush_on_ring_common(struct intel_batchbuffer *batch, int ring) { unsigned int used = batch->ptr - batch->buffer; if (used == 0) - return; + return 0; if (IS_GEN5(batch->devid)) { BEGIN_BATCH(2); @@ -99,7 +99,17 @@ intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring) /* Mark the end of the buffer. */ *(uint32_t *)(batch->ptr) = MI_BATCH_BUFFER_END; /* noop */ batch->ptr += 4; - used = batch->ptr - batch->buffer; + return batch->ptr - batch->buffer; +} + +void +intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring) +{ + int ret; + unsigned int used = flush_on_ring_common(batch, ring); + + if (used == 0) + return; do_or_die(drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer)); @@ -111,6 +121,28 @@ intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring) } void +intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch, + drm_intel_context *context) +{ + int ret; + unsigned int used = flush_on_ring_common(batch, I915_EXEC_RENDER); + + if (used == 0) + return; + + ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer); + assert(ret == 0); + + batch->ptr = NULL; + + ret = drm_intel_gem_bo_context_exec(batch->bo, context, used, + I915_EXEC_RENDER); + assert(ret == 0); + + intel_batchbuffer_reset(batch); +} + +void intel_batchbuffer_flush(struct intel_batchbuffer *batch) { int ring = 0; diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h index 4dffda7..97224b5 100644 --- a/lib/intel_batchbuffer.h +++ b/lib/intel_batchbuffer.h @@ -25,6 +25,8 @@ void intel_batchbuffer_free(struct intel_batchbuffer *batch); void intel_batchbuffer_flush(struct intel_batchbuffer *batch); void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring); +void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch, + drm_intel_context *context); void intel_batchbuffer_reset(struct intel_batchbuffer *batch); -- 1.7.10.2