Commit Graph

34 Commits

Author SHA1 Message Date
Danylo Piliaiev ecabd3b5a9 turnip: Allow nested CP_COND_REG_EXEC
This ends up being needed for moving tile loads into the draw cs.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16826>
2022-06-07 00:00:28 +00:00
Emma Anholt dc3203b087 turnip: Sub-allocate pipelines out of a device-global BO pool.
Allocating a BO for each pipeline meant that for apps with many pipelines
(such as Asphalt9 under ANGLE), we would end up spending too much time in
the kernel tracking the BO references.

Looking at CS:Source on zink, before we had 85 BOs for the pipelines for a
total of 1036 kb, and now we have 7 BOs for a total of 896 kb.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15038>
2022-04-12 01:01:56 +00:00
Danylo Piliaiev a814a4f9db turnip: Add a refcount mechanism to BOs
Until now we have lived without a refcount mechanism in the driver
because in Vulkan the user is responsible for handling the life
span of memory allocations for all Vulkan objects, however,
imported BOs are tricky because the kernel doesn't refcount
so user-space needs to make sure that:

1. When importing a BO into the same device used to create it
   (self-importing) it does not double free the same BO.
2. Frees imported BOs that were not allocated through the same
   device.

Our initial implementation always freed BOs when requested,
so we handled 2) correctly but not 1) on drm and we would
double-free self-imported BOs because kernel doesn't return
a unique gem_handle on each import.

Beside this the submit ioctl checks for duplicates in the
BO list and returns an error if there is one.

This fixes the problem for good by adding refcounts to BOs
so that self-imported BOs have a refcnt > 1 and are only freed
when all references are freed.

KGSL on the other hand does not have the same problems,
at least not with ION buffers which are used for exportable
BOs on pre 5.10 android kernels.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5936
Fixes CTS tests: dEQP-VK.drm_format_modifiers.export_import.*

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15031>
2022-02-19 15:16:55 +00:00
Rob Clark 6ac1d8dc4c turnip: Fix unitialized cs->device
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12856>
2021-09-20 19:13:25 +00:00
Danylo Piliaiev f38fd3c577 turnip: place a limit on the growth of BOs
There is a limit on IB size, which on freedreno is set to 0x100000.
Going beyond it results in hangs, however I found that the last
0x100000 packet just doesn't get executed. Thus the real limit is
0x0FFFFF.

This could be tested by appending nops to the cmdstream and placing
e.g. CP_INTERRUPT at the end, at any position other than being
0x100000 packet it results in a hang.

Fixes:
  dEQP-VK.api.command_buffers.record_many_draws_secondary_2
  dEQP-VK.api.command_buffers.record_many_draws_primary_2

However these tests could trigger hangcheck timeouts.

Also this fixes hangs when opening captures of games in RenderDoc.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10786>
2021-05-31 17:38:26 +00:00
Danylo Piliaiev 931ad19a18 turnip: make cmdstream bo's read-only to GPU
Would allow earlier faults instead of having corrupted cmdstream.

This was already done to Freedreno long ago in:
    04aff7e4 "freedreno: make cmdstream bo's read-only to GPU"

Since private memory should be GPU writable it is now allocated
separately, instead of suballocation from now read-only cmdstream.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10807>
2021-05-17 18:29:09 +00:00
Danylo Piliaiev 413e7c6dc8 turnip: make possible to create read-only bo with tu_bo_init_new
GPU won't be able to write to such BOs, which would to useful for
cmdstream BOs.

Move "bool dump" to the new flags along the way.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10807>
2021-05-17 18:29:09 +00:00
Jonathan Marek bea6290ca0 turnip: device global bo list
Avoid having to deal with BO tracking. However, the kernel still requires a
bo list, so keep a global one which can be re-used for every submit.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6686>
2020-09-13 04:04:58 +00:00
Jonathan Marek a58de1b8d3 turnip: fix ts_cs_memory typo
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5606>
2020-06-23 21:12:09 +00:00
Brian Ho 5715a61fa9 turnip: Promote tu_cs_get_size/is_empty to header
These will be used in tu_cmd_buffer.c.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3988>
2020-03-03 02:25:25 +00:00
Jonathan Marek a410e64b68 turnip: make cond_exec helper easier to use
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3925>
2020-02-24 21:52:46 +00:00
Jonathan Marek cf94124e1c turnip: automatically reserve cmdstream space in emit_pkt4/emit_pkt7
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3925>
2020-02-24 21:52:45 +00:00
Jonathan Marek 4b2a7dcd93 turnip: add tu_device pointer to tu_cs
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3925>
2020-02-24 21:52:45 +00:00
Eric Anholt fbd9b4ce08 turnip: Fix execution of secondary cmd bufs with nothing in primary.
We want to finish off cmd emission in the primary CS and add its entry to
the IB, but regardless of whether there had been anything in the primary
CS to emit, we still need a reserved CS entry for the loop below.

Fixes crashes in dEQP-VK.binding_model.shader_access.secondary_cmd_buf.*
and many more in dEQP-VK.renderpass*

Reviewed-by: Jonathan Marek <jonathan@marek.ca>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3524>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3524>
2020-01-23 20:27:26 +00:00
Jonathan Marek e9a32af3bf turnip: implement secondary command buffers
Uses a new "tu_cs_add_entries" function because tu_cs_emit_call doesn't
work inside draw_cs (which is already called by tu_cs_emit_call).

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3075>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3075>
2019-12-19 20:42:08 +00:00
Jonathan Marek 3ab4f99461 turnip: add function to allocate aligned memory in a substream cs
To use with texture states that need alignment (texconst, sampler, border)

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
2019-12-05 22:12:29 -05:00
Chia-I Wu 57327626dc turnip: simplify tu_cs sub-streams usage
Let tu_cs_begin_sub_stream imply tu_cs_reserve_space, and
tu_cs_end_sub_stream imply tu_cs_sanity_check.  Callers are no
longer required to call them (but can still do if they choose to).
2019-03-11 10:02:13 -07:00
Chia-I Wu 59419bb691 turnip: fix tu_cs sub-streams
Update cs->start in tu_cs_end_sub_stream.  Otherwise, the entry
would include commands from all prior sub-streams.
2019-03-11 10:02:13 -07:00
Chia-I Wu aa7dd6cb7f turnip: use 32-bit offset in tu_cs_entry
We don't support nor expect BOs to be that big in tu_cs.
2019-03-11 10:02:13 -07:00
Chia-I Wu 0aeef7c8bd turnip: add TU_CS_MODE_SUB_STREAM
When in TU_CS_MODE_SUB_STREAM, tu_cs_begin_sub_stream (or
tu_cs_end_sub_stream) should be called instead of tu_cs_begin (or
tu_cs_end).  It gives the caller a TU_CS_MODE_EXTERNAL cs to emit
commands to.
2019-03-11 10:02:13 -07:00
Chia-I Wu f59c381423 turnip: add tu_cs_mode
Add tu_cs_mode and TU_CS_MODE_EXTERNAL.  When in
TU_CS_MODE_EXTERNAL, tu_cs wraps an external buffer and can not
grow.

This also moves tu_cs* up in tu_private.h, such that other structs
can embed tu_cs_entry.
2019-03-11 10:02:13 -07:00
Chia-I Wu 741a4325df turnip: add tu_cs_sanity_check
It replaces tu_cs_reserve_space_assert and can be called at any
time to sanity check tu_cs.
2019-03-11 10:02:13 -07:00
Chia-I Wu 29f1110003 turnip: never fail tu_cs_begin/tu_cs_end
Error checking tu_cs_begin/tu_cs_end is too tedious for the callers.
Move tu_cs_add_bo and tu_cs_reserve_entry to tu_cs_reserve_space
such that tu_cs_begin/tu_cs_end never fails.
2019-03-11 10:02:13 -07:00
Chia-I Wu 0d81be3959 turnip: specify initial size in tu_cs_init
We will drop size parameter from tu_cs_begin shortly, such that
tu_cs_begin never fails.
2019-03-11 10:02:13 -07:00
Chia-I Wu 2774a1b97d turnip: add tu_cs_{reserve,add}_entry
We will stop calling tu_cs_reserve_entry in tu_cs_end shortly, such
that tu_cs_end never fails.
2019-03-11 10:02:13 -07:00
Chia-I Wu c11580373f turnip: add internal helpers for tu_cs
Add tu_cs_get_offset, tu_cs_get_size, tu_cs_get_space, and
tu_cs_is_empty.
2019-03-11 10:02:13 -07:00
Chia-I Wu 3b3af6321b turnip: add tu_cs_reserve_space(_assert)
They are used like

 tu_cs_reserve_space(...);
 tu_cs_emit(...);
 ...;
 tu_cs_reserve_space_assert();

to make sure we reserved enough space at the beginning.
2019-03-11 10:01:41 -07:00
Chia-I Wu 39ba2b20d1 turnip: inline tu_cs_check_space
This allows the fast path (size check) to be inlined.
2019-03-11 10:01:41 -07:00
Chia-I Wu 2bcaa78236 turnip: update cs->start in tu_cs_end
This allows us to assert that there is no dangling command in
tu_cs_begin, rather than discarding them silently.
2019-03-11 10:01:41 -07:00
Chia-I Wu b01d1618a4 turnip: minor cleanup to tu_cs_end
Add comments and error checking.
2019-03-11 10:01:41 -07:00
Chia-I Wu af4eb20891 turnip: add tu_cs_add_bo
Refactor BO allocation code out of tu_cs_begin.  Add error checking.
2019-03-11 10:01:41 -07:00
Chia-I Wu ae9a72b48b turnip: document tu_cs 2019-03-11 10:01:41 -07:00
Chia-I Wu 45120127ea turnip: run sed and clang-format on tu_cs 2019-03-11 10:01:41 -07:00
Bas Nieuwenhuizen 23d6f0f970 turnip: Move stream functions to tu_cs.c 2019-03-11 10:01:41 -07:00