Skip to content

Commit

Permalink
Mali-bifrost
Browse files Browse the repository at this point in the history
  • Loading branch information
Saikatsaha1996 committed Apr 22, 2023
1 parent 59e3f87 commit c1b608a
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 21 deletions.
8 changes: 7 additions & 1 deletion bin/install_megadrivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
"""Script to install megadriver symlinks for meson."""

import argparse
import os
import os, shutil
def link(src, dest):
shutil.copyfile(src, dest)
def unlink(src):
os.remove(src)
os.link = link
os.unlink = unlink


def main():
Expand Down
12 changes: 12 additions & 0 deletions src/gallium/auxiliary/target-helpers/sw_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "asahi/agx_public.h"
#endif

#ifdef GALLIUM_PANFROST
#include "panfrost/pan_public.h"
#endif

#ifdef GALLIUM_SOFTPIPE
#include "softpipe/sp_public.h"
#endif
Expand Down Expand Up @@ -75,6 +79,11 @@ sw_screen_create_named(struct sw_winsys *winsys, const struct pipe_screen_config
screen = agx_screen_create(0, NULL, winsys);
#endif

#if defined(GALLIUM_PANFROST)
if (screen == NULL && strcmp(driver, "panfrost") == 0)
screen = panfrost_create_screen_sw(winsys);
#endif

return screen;
}

Expand All @@ -90,6 +99,9 @@ sw_screen_create_vk(struct sw_winsys *winsys, const struct pipe_screen_config *c
#if defined(GALLIUM_ASAHI) && __APPLE__
(sw_vk || only_sw) ? "" : "asahi",
#endif
#if defined(GALLIUM_PANFROST)
(sw_vk || only_sw) ? "" : "panfrost",
#endif
#if defined(GALLIUM_LLVMPIPE)
"llvmpipe",
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/gallium/drivers/panfrost/pan_cmdstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -4208,8 +4208,9 @@ panfrost_direct_draw(struct panfrost_batch *batch,
if (idvs) {
#if PAN_ARCH >= 6
tiler = pan_pool_alloc_desc(&batch->pool.base, INDEXED_VERTEX_JOB);
#endif
#else
unreachable("IDVS is unsupported on Midgard");
#endif
} else {
vertex = pan_pool_alloc_desc_cs_v10(&batch->pool.base, COMPUTE_JOB);
tiler = pan_pool_alloc_desc_cs_v10(&batch->pool.base, TILER_JOB);
Expand Down
4 changes: 4 additions & 0 deletions src/gallium/drivers/panfrost/pan_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ extern "C" {

struct pipe_screen;
struct renderonly;
struct sw_winsys;

struct pipe_screen *
panfrost_create_screen(int fd, struct renderonly *ro);

struct pipe_screen *
panfrost_create_screen_sw(struct sw_winsys *winsys);

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 16 additions & 0 deletions src/gallium/drivers/panfrost/pan_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
*
*/

#include <stdbool.h>
#include <xf86drm.h>
#include <fcntl.h>
#include "drm-uapi/drm_fourcc.h"
#include "drm-uapi/drm.h"

#include "frontend/winsys_handle.h"
#include "frontend/sw_winsys.h"
#include "util/format/u_format.h"
#include "util/u_memory.h"
#include "util/u_surface.h"
Expand Down Expand Up @@ -653,6 +655,20 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
so->base = *template;
so->base.screen = screen;

if (pan_screen(screen)->sw_winsys &&
(template->bind & PAN_BIND_SHARED_MASK)) {

so->dt = pan_screen(screen)->sw_winsys->displaytarget_create(
pan_screen(screen)->sw_winsys,
so->base.bind,
so->base.format,
so->base.width0,
so->base.height0,
64,
NULL /*map_front_private*/,
&so->dt_stride);
}

pipe_reference_init(&so->base.reference, 1);

util_range_init(&so->valid_buffer_range);
Expand Down
3 changes: 3 additions & 0 deletions src/gallium/drivers/panfrost/pan_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ struct panfrost_resource {

/* Cached min/max values for index buffers */
struct panfrost_minmax_cache *index_cache;

struct sw_displaytarget *dt;
unsigned dt_stride;
};

static inline struct panfrost_resource *
Expand Down
57 changes: 57 additions & 0 deletions src/gallium/drivers/panfrost/pan_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

#include "pan_context.h"

#include "pan_public.h"
#include "frontend/sw_winsys.h"

static const struct debug_named_value panfrost_debug_options[] = {
{"perf", PAN_DBG_PERF, "Enable performance warnings"},
{"trace", PAN_DBG_TRACE | PAN_DBG_BO_CLEAR, "Trace the command stream"},
Expand Down Expand Up @@ -813,6 +816,43 @@ panfrost_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
return 1;
}

static void
panfrost_flush_frontbuffer(struct pipe_screen *_screen,
struct pipe_context *pctx,
struct pipe_resource *prsrc,
unsigned level, unsigned layer,
void *context_private, struct pipe_box *box)
{
struct panfrost_resource *rsrc = pan_resource(prsrc);
struct panfrost_screen *screen = pan_screen(_screen);
struct sw_winsys *winsys = screen->sw_winsys;

assert(level == 0);

struct pipe_box my_box = {
.width = rsrc->base.width0,
.height = rsrc->base.height0,
.depth = 1,
};

assert(rsrc->dt);
uint8_t *map = winsys->displaytarget_map(winsys, rsrc->dt,
PIPE_USAGE_DEFAULT);
assert(map);

struct pipe_transfer *trans = NULL;
uint8_t *tex_map = pctx->texture_map(pctx, prsrc, level,
PIPE_MAP_READ, &my_box, &trans);

for (unsigned row = 0; row < rsrc->base.height0; ++row)
memcpy(map + row * rsrc->dt_stride,
tex_map + row * trans->stride,
MIN2(rsrc->dt_stride, trans->stride));

pctx->texture_unmap(pctx, trans);

winsys->displaytarget_display(winsys, rsrc->dt, context_private, box);
}

struct pipe_screen *
panfrost_create_screen(int fd, struct renderonly *ro)
Expand Down Expand Up @@ -867,6 +907,7 @@ panfrost_create_screen(int fd, struct renderonly *ro)
screen->base.fence_finish = panfrost_fence_finish;
screen->base.fence_get_fd = panfrost_fence_get_fd;
screen->base.set_damage_region = panfrost_resource_set_damage_region;
screen->base.flush_frontbuffer = panfrost_flush_frontbuffer;

panfrost_resource_screen_init(&screen->base);
pan_blend_shaders_init(dev);
Expand Down Expand Up @@ -897,3 +938,19 @@ panfrost_create_screen(int fd, struct renderonly *ro)

return &screen->base;
}

struct pipe_screen *
panfrost_create_screen_sw(struct sw_winsys *winsys)
{
int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
if (fd < 0)
fd = open("/dev/mali0", O_RDWR | O_CLOEXEC | O_NONBLOCK);
if (fd < 0)
return NULL;

struct pipe_screen *scr = panfrost_create_screen(fd, NULL);

if (scr)
pan_screen(scr)->sw_winsys = winsys;
return scr;
}
2 changes: 2 additions & 0 deletions src/gallium/drivers/panfrost/pan_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct panfrost_screen {
struct panfrost_pool bin_pool;
} indirect_draw;

struct sw_winsys *sw_winsys;

struct panfrost_vtable vtbl;
struct disk_cache *disk_cache;
};
Expand Down
17 changes: 0 additions & 17 deletions src/gallium/targets/dri/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,6 @@ foreach d : [[with_gallium_kmsro, [
endif
endforeach

if meson.version().version_compare('>= 0.58')
# This only works on Unix-like oses, which is probably fine for dri
prog_ln = find_program('ln', required : false)
if prog_ln.found()
devenv.set('LIBGL_DRIVERS_PATH', meson.current_build_dir())

foreach d : gallium_dri_drivers
custom_target(
'devenv_@0@'.format(d),
input : libgallium_dri,
output : d,
command : [prog_ln, '-f', '@INPUT@', '@OUTPUT@'],
build_by_default : true,
)
endforeach
endif
endif

meson.add_install_script(
install_megadrivers_py.path(),
Expand Down
3 changes: 1 addition & 2 deletions src/panfrost/base/pan_vX_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@ static struct kbase_op kbase_main[] = {
#endif
#if PAN_BASE_API >= 1
{ init_mem_exec, NULL, "Initialise EXEC_VA zone" },
{ init_mem_jit, NULL, "Initialise JIT allocator" },
#endif
#if PAN_BASE_API >= 2
{ init_mem_jit, NULL, "Initialise JIT allocator" },
{ alloc_event_mem, free_event_mem, "Allocate event memory" },
#endif
};
Expand Down Expand Up @@ -1817,7 +1817,6 @@ kbase_open_csf
for (unsigned i = 0; i < ARRAY_SIZE(kbase_main); ++i) {
++k->setup_state;
if (!kbase_main[i].part(k)) {
k->close(k);
return false;
}
}
Expand Down

0 comments on commit c1b608a

Please sign in to comment.