iris_resource_disable_aux(res);
iris_bo_unreference(res->bo);
+ iris_pscreen_unref(res->base.screen);
+
free(res);
}
return NULL;
res->base = *templ;
- res->base.screen = pscreen;
+ res->base.screen = iris_pscreen_ref(pscreen);
pipe_reference_init(&res->base.reference, 1);
res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
return result;
}
-static void
-iris_destroy_screen(struct pipe_screen *pscreen)
+void
+iris_screen_destroy(struct iris_screen *screen)
{
- struct iris_screen *screen = (struct iris_screen *) pscreen;
iris_bo_unreference(screen->workaround_bo);
- u_transfer_helper_destroy(pscreen->transfer_helper);
+ u_transfer_helper_destroy(screen->base.transfer_helper);
iris_bufmgr_unref(screen->bufmgr);
disk_cache_destroy(screen->disk_cache);
ralloc_free(screen);
}
+static void
+iris_screen_unref(struct pipe_screen *pscreen)
+{
+ iris_pscreen_unref(pscreen);
+}
+
static void
iris_query_memory_info(struct pipe_screen *pscreen,
struct pipe_memory_info *info)
screen->pci_id = screen->devinfo.chipset_id;
screen->no_hw = screen->devinfo.no_hw;
+ p_atomic_set(&screen->refcount, 1);
+
if (screen->devinfo.gen < 8 || screen->devinfo.is_cherryview)
return NULL;
iris_init_screen_fence_functions(pscreen);
iris_init_screen_resource_functions(pscreen);
- pscreen->destroy = iris_destroy_screen;
+ pscreen->destroy = iris_screen_unref;
pscreen->get_name = iris_get_name;
pscreen->get_vendor = iris_get_vendor;
pscreen->get_device_vendor = iris_get_device_vendor;
struct iris_screen {
struct pipe_screen base;
+ uint32_t refcount;
+
/** Global slab allocator for iris_transfer_map objects */
struct slab_parent_pool transfer_pool;
struct pipe_screen *
iris_screen_create(int fd, const struct pipe_screen_config *config);
+void iris_screen_destroy(struct iris_screen *screen);
+
+UNUSED static inline struct pipe_screen *
+iris_pscreen_ref(struct pipe_screen *pscreen)
+{
+ struct iris_screen *screen = (struct iris_screen *) pscreen;
+
+ p_atomic_inc(&screen->refcount);
+ return pscreen;
+}
+
+UNUSED static inline void
+iris_pscreen_unref(struct pipe_screen *pscreen)
+{
+ struct iris_screen *screen = (struct iris_screen *) pscreen;
+
+ if (p_atomic_dec_zero(&screen->refcount))
+ iris_screen_destroy(screen);
+}
+
bool
iris_is_format_supported(struct pipe_screen *pscreen,
enum pipe_format format,