{
struct drm_gem_close args = {};
- if (!p_atomic_dec_zero(&bo->cref))
+ if (!p_atomic_dec_zero(&bo->ref_count))
return;
if (bo->name) {
/* Close object. */
args.handle = bo->handle;
- drmIoctl(bo->mgr->rws->fd, DRM_IOCTL_GEM_CLOSE, &args);
+ drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args);
FREE(bo);
}
struct drm_radeon_gem_wait_idle args = {};
args.handle = bo->handle;
- while (drmCommandWriteRead(bo->mgr->rws->fd, DRM_RADEON_GEM_WAIT_IDLE,
+ while (drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_WAIT_IDLE,
&args, sizeof(args)) == -EBUSY);
}
struct drm_radeon_gem_busy args = {};
args.handle = bo->handle;
- return drmCommandWriteRead(bo->mgr->rws->fd, DRM_RADEON_GEM_BUSY,
+ return drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_BUSY,
&args, sizeof(args)) != 0;
}
args.handle = bo->handle;
args.offset = 0;
args.size = (uint64_t)bo->size;
- if (drmCommandWriteRead(bo->mgr->rws->fd,
+ if (drmCommandWriteRead(bo->rws->fd,
DRM_RADEON_GEM_MMAP,
&args,
sizeof(args))) {
return NULL;
}
ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED,
- bo->mgr->rws->fd, args.addr_ptr);
+ bo->rws->fd, args.addr_ptr);
if (ptr == MAP_FAILED) {
fprintf(stderr, "radeon: mmap failed, errno: %i\n", errno);
return NULL;
bo->base.base.size = size;
bo->base.vtbl = &radeon_bo_vtbl;
bo->mgr = mgr;
+ bo->rws = mgr->rws;
bo->handle = args.handle;
bo->size = size;
args.handle = bo->handle;
- drmCommandWriteRead(bo->mgr->rws->fd,
+ drmCommandWriteRead(bo->rws->fd,
DRM_RADEON_GEM_GET_TILING,
&args,
sizeof(args));
args.handle = bo->handle;
args.pitch = pitch;
- drmCommandWriteRead(bo->mgr->rws->fd,
+ drmCommandWriteRead(bo->rws->fd,
DRM_RADEON_GEM_SET_TILING,
&args,
sizeof(args));
bo->base.base.size = bo->size;
bo->base.vtbl = &radeon_bo_vtbl;
bo->mgr = mgr;
+ bo->rws = mgr->rws;
util_hash_table_set(mgr->bo_handles, (void*)(uintptr_t)whandle->handle, bo);
{
struct drm_gem_flink flink = {};
struct radeon_bo *bo = get_radeon_bo(pb_buffer(buffer));
- whandle->stride = stride;
-
if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
if (!bo->flinked) {
flink.handle = bo->handle;
- if (ioctl(bo->mgr->rws->fd, DRM_IOCTL_GEM_FLINK, &flink)) {
+ if (ioctl(bo->rws->fd, DRM_IOCTL_GEM_FLINK, &flink)) {
return FALSE;
}
} else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
whandle->handle = bo->handle;
}
+
+ whandle->stride = stride;
return TRUE;
}
cs->chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS;
cs->chunks[1].length_dw = 0;
cs->chunks[1].chunk_data = (uint64_t)(uintptr_t)cs->relocs;
+ p_atomic_inc(&ws->num_cs);
return &cs->base;
}
/* Initialize the new relocation. */
radeon_bo_ref(bo);
+ p_atomic_inc(&bo->num_cs_references);
cs->relocs_bo[cs->crelocs] = bo;
reloc = &cs->relocs[cs->crelocs];
reloc->handle = bo->handle;
/* Unreference buffers, cleanup. */
for (i = 0; i < cs->crelocs; i++) {
radeon_bo_unref(cs->relocs_bo[i]);
+ p_atomic_dec(&cs->relocs_bo[i]->num_cs_references);
cs->relocs_bo[i] = NULL;
}
static void radeon_drm_cs_destroy(struct r300_winsys_cs *rcs)
{
struct radeon_drm_cs *cs = radeon_drm_cs(rcs);
+ p_atomic_dec(&cs->ws->num_cs);
FREE(cs->relocs_bo);
FREE(cs->relocs);
FREE(cs);
return (struct radeon_drm_cs*)base;
}
-static INLINE int radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs,
- struct radeon_bo *bo)
+static INLINE boolean radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs,
+ struct radeon_bo *bo)
{
- return radeon_get_reloc(cs, bo) != -1;
+ return bo->num_cs_references == bo->rws->num_cs ||
+ (bo->num_cs_references && radeon_get_reloc(cs, bo) != -1);
}
-static INLINE int radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo)
+static INLINE boolean radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo)
{
- return bo->cref > 1;
+ return bo->num_cs_references;
}
void radeon_drm_cs_init_functions(struct radeon_drm_winsys *ws);