&backend_vgem, &backend_virtio_gpu,
};
- for (i = 0; i < ARRAY_SIZE(backend_list); i++) {
- const struct backend *b = backend_list[i];
- // Exactly one of the main create functions must be defined.
- assert((b->bo_create != NULL) ^ (b->bo_create_from_metadata != NULL));
- // Either both or neither must be implemented.
- assert((b->bo_compute_metadata != NULL) == (b->bo_create_from_metadata != NULL));
- // Both can't be defined, but it's okay for neither to be (i.e. only bo_create).
- assert((b->bo_create_with_modifiers == NULL) ||
- (b->bo_create_from_metadata == NULL));
-
- if (!strcmp(drm_version->name, b->name)) {
+ for (i = 0; i < ARRAY_SIZE(backend_list); i++)
+ if (!strcmp(drm_version->name, backend_list[i]->name)) {
drmFreeVersion(drm_version);
- return b;
+ return backend_list[i];
}
- }
drmFreeVersion(drm_version);
return NULL;
}
struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format,
- uint64_t use_flags, bool is_test_buffer)
+ uint64_t use_flags)
{
struct bo *bo;
bo->meta.format = format;
bo->meta.use_flags = use_flags;
bo->meta.num_planes = drv_num_planes_from_format(format);
- bo->is_test_buffer = is_test_buffer;
if (!bo->meta.num_planes) {
free(bo);
int ret;
size_t plane;
struct bo *bo;
- bool is_test_alloc;
-
- is_test_alloc = use_flags & BO_USE_TEST_ALLOC;
- use_flags &= ~BO_USE_TEST_ALLOC;
- bo = drv_bo_new(drv, width, height, format, use_flags, is_test_alloc);
+ bo = drv_bo_new(drv, width, height, format, use_flags);
if (!bo)
return NULL;
- ret = -EINVAL;
- if (drv->backend->bo_compute_metadata) {
- ret = drv->backend->bo_compute_metadata(bo, width, height, format, use_flags, NULL,
- 0);
- if (!is_test_alloc && ret == 0) {
- ret = drv->backend->bo_create_from_metadata(bo);
- if (ret == 0)
- return bo;
- }
- } else if (!is_test_alloc) {
- ret = drv->backend->bo_create(bo, width, height, format, use_flags);
- }
+ ret = drv->backend->bo_create(bo, width, height, format, use_flags);
if (ret) {
free(bo);
size_t plane;
struct bo *bo;
- if (!drv->backend->bo_create_with_modifiers && !drv->backend->bo_compute_metadata) {
+ if (!drv->backend->bo_create_with_modifiers) {
errno = ENOENT;
return NULL;
}
- bo = drv_bo_new(drv, width, height, format, BO_USE_NONE, false);
+ bo = drv_bo_new(drv, width, height, format, BO_USE_NONE);
if (!bo)
return NULL;
- ret = -EINVAL;
- if (drv->backend->bo_compute_metadata) {
- ret = drv->backend->bo_compute_metadata(bo, width, height, format, BO_USE_NONE,
- modifiers, count);
- if (ret == 0)
- ret = drv->backend->bo_create_from_metadata(bo);
- } else {
- ret = drv->backend->bo_create_with_modifiers(bo, width, height, format, modifiers,
- count);
- }
+ ret = drv->backend->bo_create_with_modifiers(bo, width, height, format, modifiers, count);
if (ret) {
free(bo);
uintptr_t total = 0;
struct driver *drv = bo->drv;
- if (!bo->is_test_buffer) {
- pthread_mutex_lock(&drv->driver_lock);
+ pthread_mutex_lock(&drv->driver_lock);
- for (plane = 0; plane < bo->meta.num_planes; plane++)
- drv_decrement_reference_count(drv, bo, plane);
+ for (plane = 0; plane < bo->meta.num_planes; plane++)
+ drv_decrement_reference_count(drv, bo, plane);
- for (plane = 0; plane < bo->meta.num_planes; plane++)
- total += drv_get_reference_count(drv, bo, plane);
+ for (plane = 0; plane < bo->meta.num_planes; plane++)
+ total += drv_get_reference_count(drv, bo, plane);
- pthread_mutex_unlock(&drv->driver_lock);
+ pthread_mutex_unlock(&drv->driver_lock);
- if (total == 0) {
- ret = drv_mapping_destroy(bo);
- assert(ret == 0);
- bo->drv->backend->bo_destroy(bo);
- }
+ if (total == 0) {
+ ret = drv_mapping_destroy(bo);
+ assert(ret == 0);
+ bo->drv->backend->bo_destroy(bo);
}
free(bo);
struct bo *bo;
off_t seek_end;
- bo = drv_bo_new(drv, data->width, data->height, data->format, data->use_flags, false);
+ bo = drv_bo_new(drv, data->width, data->height, data->format, data->use_flags);
if (!bo)
return NULL;
/* No CPU access for protected buffers. */
assert(!(bo->meta.use_flags & BO_USE_PROTECTED));
- if (bo->is_test_buffer) {
- return MAP_FAILED;
- }
-
memset(&mapping, 0, sizeof(mapping));
mapping.rect = *rect;
mapping.refcount = 1;
int ret, fd;
assert(plane < bo->meta.num_planes);
- if (bo->is_test_buffer) {
- return -EINVAL;
- }
-
ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd);
// Older DRM implementations blocked DRM_RDWR, but gave a read/write mapping anyways
uint32_t count = 0;
size_t plane, p;
- if (bo->is_test_buffer) {
- return 0;
- }
-
for (plane = 0; plane < bo->meta.num_planes; plane++) {
for (p = 0; p < plane; p++)
if (bo->handles[p].u32 == bo->handles[plane].u32)
return 0;
}
-static int i915_bo_compute_metadata(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
- uint64_t use_flags, const uint64_t *modifiers, uint32_t count)
+static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t height,
+ uint32_t format, uint64_t modifier)
{
- static const uint64_t modifier_order[] = {
- I915_FORMAT_MOD_Y_TILED_CCS,
- I915_FORMAT_MOD_Y_TILED,
- I915_FORMAT_MOD_X_TILED,
- DRM_FORMAT_MOD_LINEAR,
- };
- uint64_t modifier;
-
- if (modifiers) {
- modifier =
- drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order));
- } else {
- struct combination *combo = drv_get_combination(bo->drv, format, use_flags);
- if (!combo)
- return -EINVAL;
- modifier = combo->metadata.modifier;
- }
+ int ret;
+ size_t plane;
+ struct drm_i915_gem_create gem_create;
+ struct drm_i915_gem_set_tiling gem_set_tiling;
switch (modifier) {
case DRM_FORMAT_MOD_LINEAR:
} else {
i915_bo_from_format(bo, width, height, format);
}
- return 0;
-}
-
-static int i915_bo_create_from_metadata(struct bo *bo)
-{
- int ret;
- size_t plane;
- struct drm_i915_gem_create gem_create;
- struct drm_i915_gem_set_tiling gem_set_tiling;
memset(&gem_create, 0, sizeof(gem_create));
gem_create.size = bo->meta.total_size;
return 0;
}
+static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint64_t use_flags)
+{
+ struct combination *combo;
+
+ combo = drv_get_combination(bo->drv, format, use_flags);
+ if (!combo)
+ return -EINVAL;
+
+ return i915_bo_create_for_modifier(bo, width, height, format, combo->metadata.modifier);
+}
+
+static int i915_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
+ uint32_t format, const uint64_t *modifiers, uint32_t count)
+{
+ static const uint64_t modifier_order[] = {
+ I915_FORMAT_MOD_Y_TILED_CCS,
+ I915_FORMAT_MOD_Y_TILED,
+ I915_FORMAT_MOD_X_TILED,
+ DRM_FORMAT_MOD_LINEAR,
+ };
+ uint64_t modifier;
+
+ modifier = drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order));
+
+ return i915_bo_create_for_modifier(bo, width, height, format, modifier);
+}
+
static void i915_close(struct driver *drv)
{
free(drv->priv);
.name = "i915",
.init = i915_init,
.close = i915_close,
- .bo_compute_metadata = i915_bo_compute_metadata,
- .bo_create_from_metadata = i915_bo_create_from_metadata,
+ .bo_create = i915_bo_create,
+ .bo_create_with_modifiers = i915_bo_create_with_modifiers,
.bo_destroy = drv_gem_bo_destroy,
.bo_import = i915_bo_import,
.bo_map = i915_bo_map,