freedreno: import libdrm_freedreno + redesign submit
authorRob Clark <robdclark@gmail.com>
Sun, 21 Oct 2018 14:22:11 +0000 (10:22 -0400)
committerRob Clark <robdclark@gmail.com>
Fri, 26 Oct 2018 22:10:00 +0000 (18:10 -0400)
commitf3cc0d2747568a186dba433ac94af607c38fa024
treea6db86fd1cfbb044180d3aba07e047714e6b9f1d
parentaa02d7e8781c25ee18b6da97606300808c84973a
freedreno: import libdrm_freedreno + redesign submit

In the pursuit of lowering driver overhead, it became clear that some
amount of redesign of how libdrm_freedreno constructs the submit ioctl
would be needed.  In particular, as the gallium driver is starting to
make heavier use of CP_SET_DRAW_STATE state groups/objects, the over-
head of tracking cmd buffers and relocs becomes too much.  And for
"streaming" state, which isn't ever reused (like uniform uploads) the
overhead of allocating/freeing ringbuffer[1] objects is too high.

This redesign makes two main changes:

 1) Introduces a fd_submit object for tracking bos and cmds table
    for the submit ioctl, making ringbuffer objects more light-
    weight.  This was previously done in the ringbuffer.  But we
    have many ringbuffer instances involved in a submit (gmem +
    draw + potentially 1000's of state-group rbs), and only need
    a single bos and cmds table.  (Reloc table is still per-rb)

    The submit is also a convenient place for a slab allocator for
    ringbuffer objects.  Other options would have required locking
    because, while we can guarantee allocations will only happen on
    a single thread, free's could happen either on the application
    thread or the flush_queue thread.  With the slab allocator in
    the submit object, any frees that happen on the flush_queue
    thread happen after we know that the application thread is done
    with the submit.

 2) Introduce a new "softpin" msm_ringbuffer_sp implementation that
    does not use relocs and only has cmds table entries for IB1 (ie.
    the cmdstream buffers that kernel needs to CP_INDIRECT_BUFFER
    to from the RB).  To do this properly will require some updates
    on the kernel side, so whether you get the softpin or legacy
    submit/ringbuffer implementation at runtime depends on your
    kernel version.

To make all these changes in libdrm would basically require adding a
libdrm_freedreno2, so this is a good point to just pull the libdrm code
into mesa.  Plus it allows for using mesa's hashtable, slab allocator,
etc.  And it lets us have asserts enabled for debug mesa buids but
omitted for release builds.  And it makes life easier if further API
changes become necessary.

At this point I haven't tried to pull in the kgsl backend.  Although
I left the level of vfunc indirection which would make it possible
to have other backends.  (And this was convenient to keep to allow
for the "softpin" ringbuffer to coexist.)

NOTE: if bisecting a build error takes you here, try a clean build.
There are a bunch of ways things can go wrong if you still have
libdrm_freedreno cflags.

[1] "ringbuffer" is probably a bad name, the only level of cmdstream
    buffer that is actually a ring is RB managed by kernel.  User-
    space cmdstream is all IB1/IB2 and state-groups.

Reviewed-by: Kristian H. Kristensen <hoegsberg@chromium.org>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Signed-off-by: Rob Clark <robdclark@gmail.com>
36 files changed:
configure.ac
meson.build
src/gallium/drivers/freedreno/Android.mk
src/gallium/drivers/freedreno/Makefile.am
src/gallium/drivers/freedreno/Makefile.sources
src/gallium/drivers/freedreno/a3xx/fd3_context.h
src/gallium/drivers/freedreno/a4xx/fd4_context.h
src/gallium/drivers/freedreno/a5xx/fd5_context.h
src/gallium/drivers/freedreno/a5xx/fd5_draw.c
src/gallium/drivers/freedreno/a6xx/fd6_context.h
src/gallium/drivers/freedreno/a6xx/fd6_draw.c
src/gallium/drivers/freedreno/a6xx/fd6_emit.c
src/gallium/drivers/freedreno/drm/freedreno_bo.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_bo_cache.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_device.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_drmif.h [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_pipe.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_priv.h [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_ringbuffer.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/freedreno_ringbuffer.h [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_bo.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_device.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_drm.h [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_pipe.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_priv.h [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_ringbuffer.c [new file with mode: 0644]
src/gallium/drivers/freedreno/drm/msm_ringbuffer_sp.c [new file with mode: 0644]
src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_batch.h
src/gallium/drivers/freedreno/freedreno_gmem.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/freedreno_screen.h
src/gallium/drivers/freedreno/freedreno_util.h
src/gallium/drivers/freedreno/ir3/ir3_shader.c
src/gallium/drivers/freedreno/meson.build
src/gallium/winsys/freedreno/drm/meson.build