#include "i915_drm.h"
+#include "intel_bufmgr_ttm.h"
+
#define BUFMGR_DEBUG 0
#define MAX_RELOCS_PER_LIST 511
} dri_fence_ttm;
-static int i830AdjustListNodes(struct intel_bo_list *list)
+static int intel_adjust_list_nodes(struct intel_bo_list *list)
{
struct intel_bo_node *node;
drmMMListHead *l;
return ret;
}
+#if 0
void intel_bo_free_list(struct intel_bo_list *list)
{
struct intel_bo_node *node;
list->numCurrent--;
}
}
-
-int intel_bo_reset_list(struct intel_bo_list *list)
+#endif
+
+static int intel_bo_reset_list(struct intel_bo_list *list)
{
drmMMListHead *l;
int ret;
- ret = i830AdjustListNodes(list);
+ ret = intel_adjust_list_nodes(list);
if (ret)
return ret;
list->numOnList--;
l = list->list.next;
}
- return i830AdjustListNodes(list);
+ return intel_adjust_list_nodes(list);
}
static void generic_destroy(void *nodep)
free(nodep);
}
-int intel_create_bo_list(int numTarget, struct intel_bo_list *list, void (*destroy)(void *))
+static int intel_create_bo_list(int numTarget, struct intel_bo_list *list, void (*destroy)(void *))
{
DRMINITLISTHEAD(&list->list);
DRMINITLISTHEAD(&list->free);
list->destroy = destroy;
else
list->destroy = generic_destroy;
- return i830AdjustListNodes(list);
+ return intel_adjust_list_nodes(list);
}
-struct drm_i915_op_arg *
+static struct drm_i915_op_arg *
intel_setup_validate_list(int fd, struct intel_bo_list *list, struct intel_bo_list *reloc_list)
{
struct intel_bo_node *node;
if (rl_node->handle == node->buf->handle) {
arg->reloc_handle = rl_node->type_list.buf.handle;
- // drmBOUnmap(fd, &rl_node->type_list.buf);
}
}
}
return first;
}
-void intel_free_validate_list(int fd, struct intel_bo_list *list)
+static void intel_free_validate_list(int fd, struct intel_bo_list *list)
{
struct intel_bo_node *node;
drmMMListHead *l;
}
}
-void intel_free_reloc_list(int fd, struct intel_bo_list *reloc_list)
+static void intel_free_reloc_list(int fd, struct intel_bo_list *reloc_list)
{
struct intel_bo_reloc_node *reloc_node;
drmMMListHead *rl, *tmp;
for (rl = reloc_list->list.next, tmp = rl->next; rl != &reloc_list->list; rl = tmp, tmp = rl->next) {
reloc_node = DRMLISTENTRY(struct intel_bo_reloc_node, rl, head);
-
+
DRMLISTDEL(rl);
if (reloc_node->nr_reloc_types > 1) {
/* TODO */
}
-
+
drmBOUnmap(fd, &reloc_node->type_list.buf);
drmBODestroy(fd, &reloc_node->type_list.buf);
free(reloc_node);
}
}
-int intel_add_validate_buffer(struct intel_bo_list *list, dri_bo *buf, unsigned flags,
- unsigned mask, int *itemLoc, void (*destroy_cb)(void *))
+static int intel_add_validate_buffer(struct intel_bo_list *list, dri_bo *buf, unsigned flags,
+ unsigned mask, int *itemLoc, void (*destroy_cb)(void *))
{
struct intel_bo_node *node, *cur;
drmMMListHead *l;
for (l = list->list.next; l != &list->list; l = l->next) {
node = DRMLISTENTRY(struct intel_bo_node, l, head);
- if (node->buf == buf_bo) {
+ if (node->buf->handle == buf_bo->handle) {
cur = node;
break;
}
unsigned memFlags = cur->arg0 & flags & memMask;
if (!memFlags) {
-#if 0
- ErrorF("Incompatible memory location requests "
- "on validate list.\n");
- ErrorF("Previous flag: 0x%08lx, mask: 0x%08lx\n",
- cur->arg0, cur->arg1);
- ErrorF("Current flag: 0x%08lx, mask: 0x%08lx\n",
- flags, mask);
-#endif
return -EINVAL;
}
if (mask & cur->arg1 & ~DRM_BO_MASK_MEM & (cur->arg0 ^ flags)) {
-#if 0
- ErrorF("Incompatible buffer flag requests "
- "on validate list.\n");
- ErrorF("Previous flag: 0x%08lx, mask: 0x%08lx\n",
- cur->arg0, cur->arg1);
- ErrorF("Current flag: 0x%08lx, mask: 0x%08lx\n",
- flags, mask);
-#endif
return -EINVAL;
}
cur->arg1 |= mask;
}
-int intel_add_validate_reloc(int fd, struct intel_bo_list *reloc_list, struct intel_reloc_info *reloc_info)
+static int intel_add_validate_reloc(int fd, struct intel_bo_list *reloc_list, struct intel_reloc_info *reloc_info)
{
struct intel_bo_reloc_node *rl_node, *cur;
drmMMListHead *rl, *l;
if (rl_node->handle == reloc_info->handle) {
cur = rl_node;
break;
-
}
}
ttm_buf->owner = GL_FALSE;
#if BUFMGR_DEBUG
- fprintf(stderr, "bo_create_from_handle: %p (%s)\n", &ttm_buf->bo,
+ fprintf(stderr, "bo_create_from_handle: %p %08x (%s)\n", &ttm_buf->bo, handle,
ttm_buf->name);
#endif
return err;
}
-static dri_fence *
-dri_ttm_fence_validated(dri_bufmgr *bufmgr, const char *name,
- GLboolean flushed)
+/* Returns a dri_bo wrapping the given buffer object handle.
+ *
+ * This can be used when one application needs to pass a buffer object
+ * to another.
+ */
+dri_fence *
+intel_ttm_fence_create_from_arg(dri_bufmgr *bufmgr, const char *name,
+ drm_fence_arg_t *arg)
{
- dri_fence_ttm *fence_ttm = malloc(sizeof(*fence_ttm));
- dri_bufmgr_ttm *bufmgr_ttm = (dri_bufmgr_ttm *)bufmgr;
- int ret;
- unsigned int type;
+ dri_bufmgr_ttm *ttm_bufmgr;
+ dri_fence_ttm *ttm_fence;
- if (!fence_ttm)
- return NULL;
+ ttm_bufmgr = (dri_bufmgr_ttm *)bufmgr;
- if (flushed)
- type = bufmgr_ttm->fence_type_flush;
- else
- type = bufmgr_ttm->fence_type;
-
- fence_ttm->refcount = 1;
- fence_ttm->name = name;
- fence_ttm->fence.bufmgr = bufmgr;
- ret = drmFenceBuffers(bufmgr_ttm->fd, type, 0, &fence_ttm->drm_fence);
- if (ret) {
- fprintf(stderr, "failed to fence (%s): %s\n", name, strerror(-ret));
- free(fence_ttm);
+ ttm_fence = malloc(sizeof(*ttm_fence));
+ if (!ttm_fence)
return NULL;
- }
+
+ ttm_fence->drm_fence.handle = arg->handle;
+ ttm_fence->drm_fence.fence_class = arg->fence_class;
+ ttm_fence->drm_fence.type = arg->type;
+ ttm_fence->drm_fence.flags = arg->flags;
+ ttm_fence->drm_fence.signaled = 0;
+ ttm_fence->drm_fence.sequence = arg->sequence;
+
+ ttm_fence->fence.bufmgr = bufmgr;
+ ttm_fence->name = name;
+ ttm_fence->refcount = 1;
#if BUFMGR_DEBUG
- fprintf(stderr, "fence_validated: %p (%s)\n", &fence_ttm->fence,
- fence_ttm->name);
+ fprintf(stderr, "fence_create_from_handle: %p (%s)\n", &ttm_fence->fence,
+ ttm_fence->name);
#endif
- return &fence_ttm->fence;
+ return &ttm_fence->fence;
+}
+
+static dri_fence *
+dri_ttm_fence_validated(dri_bufmgr *bufmgr, const char *name,
+ GLboolean flushed)
+{
+ return NULL;
}
static void
_glthread_LOCK_MUTEX(bufmgr_ttm->mutex);
++fence_ttm->refcount;
_glthread_UNLOCK_MUTEX(bufmgr_ttm->mutex);
+#if BUFMGR_DEBUG
+ fprintf(stderr, "fence_reference: %p (%s)\n", &fence_ttm->fence,
+ fence_ttm->name);
+#endif
}
static void
if (!fence)
return;
+#if BUFMGR_DEBUG
+ fprintf(stderr, "fence_unreference: %p (%s)\n", &fence_ttm->fence,
+ fence_ttm->name);
+#endif
_glthread_LOCK_MUTEX(bufmgr_ttm->mutex);
if (--fence_ttm->refcount == 0) {
int ret;
dri_bo *dribo = priv;
if (dribo) {
- dri_bo_unreference(dribo);
+ dri_bo_unreference(dribo);
}
}
dri_bo *relocatee)
{
dri_bo_ttm *ttm_buf = (dri_bo_ttm *)batch_buf;
- dri_bo_ttm *relocatee_buf = (dri_bo_ttm *)relocatee;
dri_bufmgr_ttm *bufmgr_ttm = (dri_bufmgr_ttm *)batch_buf->bufmgr;
int newItem;
struct intel_reloc_info reloc;
+ int mask;
+ int ret;
+
+ mask = DRM_BO_MASK_MEM;
+ mask |= flags & (DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_EXE);
+
+ ret = intel_add_validate_buffer(&bufmgr_ttm->list, relocatee, flags, mask, &newItem, intel_dribo_destroy_callback);
+ if (ret < 0)
+ return;
- intel_add_validate_buffer(&bufmgr_ttm->list, relocatee, flags, flags, &newItem, intel_dribo_destroy_callback);
+ if (ret == 1) {
+ dri_bo_reference(relocatee);
+ }
reloc.type = I915_RELOC_TYPE_0;
reloc.reloc = offset;
static void *
-dri_ttm_process_reloc(dri_bo *batch_buf, GLuint *hack)
+dri_ttm_process_reloc(dri_bo *batch_buf)
{
dri_bufmgr_ttm *bufmgr_ttm = (dri_bufmgr_ttm *)batch_buf->bufmgr;
void *ptr;
int itemLoc;
+ dri_bo_unmap(batch_buf);
+
intel_add_validate_buffer(&bufmgr_ttm->list, batch_buf, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_EXE,
DRM_BO_MASK_MEM | DRM_BO_FLAG_EXE, &itemLoc, NULL);
ptr = intel_setup_validate_list(bufmgr_ttm->fd, &bufmgr_ttm->list, &bufmgr_ttm->reloc_list);
- *hack = ((dri_bo_ttm *)batch_buf)->drm_bo.handle;
return ptr;
}
intel_free_validate_list(bufmgr_ttm->fd, &bufmgr_ttm->list);
intel_free_reloc_list(bufmgr_ttm->fd, &bufmgr_ttm->reloc_list);
- /*
-
- bb->fence.handle = execbuf.fence_arg.handle;
- bb->fence.fence_class = execbuf.fence_arg.fence_class;
- bb->fence.type = execbuf.fence_arg.type;
- bb->fence.flags = execbuf.fence_arg.flags;
- bb->fence.signaled = 0;
- */
+ intel_bo_reset_list(&bufmgr_ttm->list);
}
/**
bufmgr_ttm->fence_type_flush = fence_type_flush;
_glthread_INIT_MUTEX(bufmgr_ttm->mutex);
- intel_create_bo_list(40, &bufmgr_ttm->list, NULL);
+ intel_create_bo_list(10, &bufmgr_ttm->list, NULL);
intel_create_bo_list(1, &bufmgr_ttm->reloc_list, NULL);
bufmgr_ttm->bufmgr.bo_alloc = dri_ttm_alloc;
#include "intel_regions.h"
#include "drm.h"
+#include "intel_bufmgr_ttm.h"
+
#define FILE_DEBUG_FLAG DEBUG_IOCTL
int
intel_exec_ioctl(struct intel_context *intel,
GLuint used,
GLboolean ignore_cliprects, GLboolean allow_unlock,
- void *start, uint32_t *hack)
+ void *start, dri_fence **fence)
{
struct drm_i915_execbuffer execbuf;
-
+ dri_fence *fo;
+
assert(intel->locked);
assert(used);
+ if (*fence) {
+ dri_fence_unreference(*fence);
+ }
+
memset(&execbuf, 0, sizeof(execbuf));
- execbuf.cmdbuf_handle = *hack; // TODO
execbuf.batch.used = used;
execbuf.batch.cliprects = intel->pClipRects;
execbuf.batch.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects;
(((GLuint) intel->drawY) << 16));
execbuf.ops_list = (unsigned)start; // TODO
- execbuf.fence_arg.flags = DRM_I915_FENCE_FLAG_FLUSHED;
+ execbuf.fence_arg.flags = DRM_FENCE_FLAG_SHAREABLE | DRM_I915_FENCE_FLAG_FLUSHED;
- if (drmCommandWrite(intel->driFd, DRM_I915_EXECBUFFER, &execbuf,
+ if (drmCommandWriteRead(intel->driFd, DRM_I915_EXECBUFFER, &execbuf,
sizeof(execbuf))) {
fprintf(stderr, "DRM_I830_EXECBUFFER: %d\n", -errno);
UNLOCK_HARDWARE(intel);
exit(1);
}
+
+ fo = intel_ttm_fence_create_from_arg(intel->intelScreen->bufmgr, "fence buffers",
+ &execbuf.fence_arg);
+ if (!fo) {
+ fprintf(stderr, "failed to fence handle: %08x\n", execbuf.fence_arg.handle);
+ UNLOCK_HARDWARE(intel);
+ exit(1);
+ }
+ *fence = fo;
+
/* FIXME: use hardware contexts to avoid 'losing' hardware after
* each buffer flush.
*/
intel->vtbl.lost_hardware(intel);
-#if 0
- fence->handle = execbuf.fence_arg.handle;
- fence->fence_class = execbuf.fence_arg.fence_class;
- fence->type = execbuf.fence_arg.type;
- fence->flags = execbuf.fence_arg.flags;
- fence->fence.signaled = 0;
-#endif
}