mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 21:50:11 +01:00
lima: replace custom code with u_pipe_screen_lookup_or_create()
Signed-off-by: Eric Engestrom <eric@igalia.com> Acked-by: Vasily Khoruzhick <anarsoul@gmail.com> Acked-by: Erico Nunes <nunes.erico@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20180>
This commit is contained in:
parent
e17c3af593
commit
759496cc45
3 changed files with 16 additions and 75 deletions
|
|
@ -647,8 +647,16 @@ lima_get_disk_shader_cache (struct pipe_screen *pscreen)
|
|||
return screen->disk_cache;
|
||||
}
|
||||
|
||||
static int
|
||||
lima_screen_get_fd(struct pipe_screen *pscreen)
|
||||
{
|
||||
struct lima_screen *screen = lima_screen(pscreen);
|
||||
return screen->fd;
|
||||
}
|
||||
|
||||
struct pipe_screen *
|
||||
lima_screen_create(int fd, struct renderonly *ro)
|
||||
lima_screen_create(int fd, const struct pipe_screen_config *config,
|
||||
struct renderonly *ro)
|
||||
{
|
||||
uint64_t system_memory;
|
||||
struct lima_screen *screen;
|
||||
|
|
@ -731,6 +739,7 @@ lima_screen_create(int fd, struct renderonly *ro)
|
|||
pp_frame_rsw[13] = 0x00000100;
|
||||
|
||||
screen->base.destroy = lima_screen_destroy;
|
||||
screen->base.get_screen_fd = lima_screen_get_fd;
|
||||
screen->base.get_name = lima_screen_get_name;
|
||||
screen->base.get_vendor = lima_screen_get_vendor;
|
||||
screen->base.get_device_vendor = lima_screen_get_device_vendor;
|
||||
|
|
@ -750,8 +759,6 @@ lima_screen_create(int fd, struct renderonly *ro)
|
|||
|
||||
slab_create_parent(&screen->transfer_pool, sizeof(struct lima_transfer), 16);
|
||||
|
||||
screen->refcnt = 1;
|
||||
|
||||
return &screen->base;
|
||||
|
||||
err_out2:
|
||||
|
|
|
|||
|
|
@ -64,9 +64,6 @@ struct lima_screen {
|
|||
struct pipe_screen base;
|
||||
struct renderonly *ro;
|
||||
|
||||
int refcnt;
|
||||
void *winsys_priv;
|
||||
|
||||
int fd;
|
||||
int gpu_type;
|
||||
int num_pp;
|
||||
|
|
@ -104,6 +101,7 @@ lima_screen(struct pipe_screen *pscreen)
|
|||
}
|
||||
|
||||
struct pipe_screen *
|
||||
lima_screen_create(int fd, struct renderonly *ro);
|
||||
lima_screen_create(int fd, const struct pipe_screen_config *config,
|
||||
struct renderonly *ro);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,87 +21,23 @@
|
|||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "c11/threads.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_hash_table.h"
|
||||
#include "util/u_pointer.h"
|
||||
#include "util/u_screen.h"
|
||||
#include "renderonly/renderonly.h"
|
||||
|
||||
#include "lima_drm_public.h"
|
||||
|
||||
#include "lima/lima_screen.h"
|
||||
|
||||
static struct hash_table *fd_tab = NULL;
|
||||
static mtx_t lima_screen_mutex = _MTX_INITIALIZER_NP;
|
||||
|
||||
static void
|
||||
lima_drm_screen_destroy(struct pipe_screen *pscreen)
|
||||
{
|
||||
struct lima_screen *screen = lima_screen(pscreen);
|
||||
boolean destroy;
|
||||
int fd = screen->fd;
|
||||
|
||||
mtx_lock(&lima_screen_mutex);
|
||||
destroy = --screen->refcnt == 0;
|
||||
if (destroy) {
|
||||
_mesa_hash_table_remove_key(fd_tab, intptr_to_pointer(fd));
|
||||
|
||||
if (!fd_tab->entries) {
|
||||
_mesa_hash_table_destroy(fd_tab, NULL);
|
||||
fd_tab = NULL;
|
||||
}
|
||||
}
|
||||
mtx_unlock(&lima_screen_mutex);
|
||||
|
||||
if (destroy) {
|
||||
pscreen->destroy = screen->winsys_priv;
|
||||
pscreen->destroy(pscreen);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
struct pipe_screen *
|
||||
lima_drm_screen_create(int fd)
|
||||
{
|
||||
struct pipe_screen *pscreen = NULL;
|
||||
|
||||
mtx_lock(&lima_screen_mutex);
|
||||
if (!fd_tab) {
|
||||
fd_tab = util_hash_table_create_fd_keys();
|
||||
if (!fd_tab)
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
pscreen = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
|
||||
if (pscreen) {
|
||||
lima_screen(pscreen)->refcnt++;
|
||||
} else {
|
||||
int dup_fd = os_dupfd_cloexec(fd);
|
||||
|
||||
pscreen = lima_screen_create(dup_fd, NULL);
|
||||
if (pscreen) {
|
||||
_mesa_hash_table_insert(fd_tab, intptr_to_pointer(dup_fd), pscreen);
|
||||
|
||||
/* Bit of a hack, to avoid circular linkage dependency,
|
||||
* ie. pipe driver having to call in to winsys, we
|
||||
* override the pipe drivers screen->destroy():
|
||||
*/
|
||||
lima_screen(pscreen)->winsys_priv = pscreen->destroy;
|
||||
pscreen->destroy = lima_drm_screen_destroy;
|
||||
}
|
||||
}
|
||||
|
||||
unlock:
|
||||
mtx_unlock(&lima_screen_mutex);
|
||||
return pscreen;
|
||||
return u_pipe_screen_lookup_or_create(os_dupfd_cloexec(fd), NULL,
|
||||
NULL, lima_screen_create);
|
||||
}
|
||||
|
||||
struct pipe_screen *
|
||||
lima_drm_screen_create_renderonly(struct renderonly *ro)
|
||||
{
|
||||
return lima_screen_create(os_dupfd_cloexec(ro->gpu_fd), ro);
|
||||
return lima_screen_create(os_dupfd_cloexec(ro->gpu_fd), NULL, ro);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue