Commit Graph

264 Commits

Author SHA1 Message Date
Emma Anholt 3ade94df86 freedreno: Use a BO bitset for faster checks for resource referenced.
When moving the batch cache to the context, I added hash table lookups
from batch to rsc for "is this resource in use" because we could no longer
store data in the rsc bo under the batch cache's lock.

We can save that cost by tracking a bitfield of resources referenced by
the batch, which gives us very cheap checks in the draw path at a minor
cost in memory.  We can just use the GEM BO handle, since it's a nice
small integer already (we can't use the TC buffer ID, because the frontend
changes that, and we're in the driver thread).

This required moving the !pending() assert up in resource shadowing, since
the BO swap meant we were checking pending on the wrong resource.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11511>
2021-09-17 17:07:43 +00:00
Emma Anholt b2349a4671 freedreno: Move the batch cache to the context.
Our draw call rate was significantly limited by the atomics we had to do
to manage access to the batch cache.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11511>
2021-09-17 17:07:43 +00:00
Emma Anholt cbbe3e7641 freedreno: Precompute resource pointer hash values.
It was around half a percent of the CPU in the fd-bc-ctx branch, and adds
4b to our 472b struct.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11511>
2021-09-17 17:07:43 +00:00
Rob Clark f92877b7b8 freedreno: Reduce use of screen->gpu_id
Newer GPU's are moving away from using gpu_id, including the code
landing upstream for "7c Gen 3".  But most of the places in the gallium
driver where we were looking at gpu_id, we only cared about the major
generation.  So convert those to use screen->gen instead.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12159>
2021-08-06 18:51:50 +00:00
Rob Clark 8f6715862f freedreno: Convert fd_dev_info to const pointer
Split out from previous patch to reduce churn.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11790>
2021-07-14 01:58:00 +00:00
Emma Anholt 4300853edc freedreno: Flush the shadowed resource's write batch up front.
This simplifies my mental model of the swapping/blit process for resource
shadowing.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11544>
2021-06-30 21:39:11 +00:00
Emma Anholt 88161ced8d freedreno: Swap needs_ubwc_clear when shadowing.
The destination of the upcoming blit (the old rsc struct that houses the
fresh BO) wouldn't have its ubwc cleared first, which if it got
unfortunate data in a recycled BO could lead to blit failures.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11544>
2021-06-30 21:39:11 +00:00
Emma Anholt f413b30ad4 freedreno: swap ->valid when shadowing resources.
The valid flag indicates whether the bo has had any data written to it.
Failure to swap it meant that if for some reason we fell back to SW
mappings during the blit from shadow, the PIPE_MAP_READ staging blit would
get dropped.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11544>
2021-06-30 21:39:11 +00:00
Emma Anholt 172082f235 freedreno: Update comments about PIPE_BUFFER shadowing.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11544>
2021-06-30 21:39:11 +00:00
Emma Anholt ea43465dbf Revert "freedreno: Cooperate with tc to stop checking the BC for resource_busy()."
This reverts commit 5cb043cf82.

While the numbers were impressive for drawoverhead, it comes at the cost
of additional flushes, which for gmem access (what we actually care about
most!) would greatly increase the actual cost to render.  Also, gl_driver2
overhead is increased, probably due to spending time in the kernel for the
flushes.

drawoverhead's win came from the increased flushing causing the GPU to
start processing the buffers sooner on everything but test 1, which
already had some incremental flushing happening.  That was certainly not
intended by the change.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11599>
2021-06-24 23:24:44 +00:00
Emma Anholt 5cb043cf82 freedreno: Cooperate with tc to stop checking the BC for resource_busy().
The resource_busy() hook was having to check the batch cache for usage of
the resource, since TC didn't know how long our driver would.  By
committing to calling the tc_driver_internal_flush_notify() hook on
non-deferred flushes, TC keeps track of which buffers have been used but
not flushed and considers them busy, saving us needing to look in the BC
(which we won't be able to do once we move it to being per-context).

drawoverhead test results (all numbers are throughput, n=5):

   1, DrawElements ( 1 VBO| 0 UBO|  0    ) w/ no state change:      -4.94214% +/- 2.45047%
   7, DrawElements ( 1 VBO| 8 UBO|  8 Tex) w/ vertex attrib change: 48.3992% +/- 5.02827%
   8, DrawElements ( 1 VBO| 8 UBO|  8 Tex) w/ 1 texture change:     26.0974% +/- 1.14932%
   9, DrawElements ( 1 VBO| 8 UBO|  8 Tex) w/ 8 textures change:    12.6963% +/- 3.01077%
  17, DrawElements ( 1 VBO| 8 UBO|  8 Tex) w/ 8 UBOs change:        54.3846% +/- 35.0049%

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11513>
2021-06-22 09:51:21 -07:00
Emma Anholt 74ede4b353 freedreno: Move the rsc-based batch flushing to helper functions.
I want to reuse these, and this gives them nice names.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11455>
2021-06-21 20:48:21 +00:00
Emma Anholt df7fdae127 freedreno: Skip staging blits from uninitialized resources.
When storing depth- or stencil-only texture data that has been packed into
a depth/stencil texture, the tex store gets PIPE_MAP_READ added onto it
since the other channel will get ORed into the incoming data, but
sometimes we know that the other component is undefined because the whole
texture is either fresh or just invalidated.

Cleans up a confusing extra blit in a dEQP case I've been debugging, and
should be less work for dEQP CI.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11452>
2021-06-17 22:47:51 +00:00
Emma Anholt 4018c5f928 freedreno: Add more detailed blit debug in FD_MESA_DEBUG=msgs.
For debugging the batch cache, it really helps to see the blits that
happen, and which are staging blits in the transfer map process.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11452>
2021-06-17 22:47:51 +00:00
Emma Anholt d4203bf7ab freedreno: Add perf_debug() for our software conditional rendering.
We could do it in hardware, and turnip does, but it hasn't bubbled up our
priorities yet.  At least make it more discoverable when you stumble over
it.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11452>
2021-06-17 22:47:51 +00:00
Emma Anholt 2a9225d05f freedreno: Remove broken back_blit optimization.
It wasn't checking that the transfer map would definitely overwrite all of
the data being initialized by the back blit, and if we knew that it
would then the caller would have provided PIPE_MAP_DISCARD_WHOLE_RESOURCE.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11439>
2021-06-17 09:11:02 -07:00
Emma Anholt 09e1fb2bce freedreno: Move the !MAP_WRITE write batch refcounting to the branch.
For MAP_WRITE, we flush all the batches referencing the BO, so the write
batch will get flushed anyway.  No need to take an extra ref.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11439>
2021-06-17 09:11:02 -07:00
Emma Anholt fd571565d2 freedreno: Fix batch reference handling in flush_resource().
We take references under the lock, but then accessed the lock-requiring
batch_cache structure without holding the lock.  The batches wouldn't get
freed and removed from their slots until the last ref goes away so it was
safe (other than the assert at the end), but writing the simple code is
shorter and requires fewer assumptions.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11439>
2021-06-17 09:11:02 -07:00
Rob Clark c64f217495 freedreno: Flush batches on shadow/uncompress
Normally when we shadow a resource (whether it is changing the modifier
or not) we do not need to flush existing batches, since they reference
the original version of the resource.  There is a special case for
resources that are referenced by a batches framebuffer state, because
this state is emitted when the batch is flushed.  Because of this, we
need those batches to be flushed before we shadow the resource.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11371>
2021-06-15 19:09:24 +00:00
Rob Clark b97e3bb2e1 freedreno/a6xx: Handle R8G8 sharp edges in validate_format()
Because R8G8 has a different layout from R16, we not only need to demote
to uncompressed to (for example) sample R8G8 as R16 (or visa versa) but
we also need to demote further to linear.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11371>
2021-06-15 19:09:24 +00:00
Rob Clark 6d01c17805 freedreno: Add debugging for blitter fallback recursion
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11371>
2021-06-15 19:09:24 +00:00
Rob Clark fb8fe017ee freedreno: Don't try staging blit for non-renderable formats
If a format is not supported as a render target, there is no point in
trying a staging blit, as it will end up in a CPU copy fallback.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11371>
2021-06-15 19:09:24 +00:00
Mike Blumenkrantz 74abd5df0e aux/tc: pass rebind count and rebind bitmask with replace_buffer_storage func
tc already calculates all the rebinding that needs to be done on a given
context, so (some of) this info can be passed on to drivers to enable
optimizations

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11245>
2021-06-14 20:42:47 +00:00
Rob Clark 38dd2e6e41 freedreno: Remove assert
In multi-context scenarios, one context writing to a resource can race
with a pctx->flush_resource() on another context/thread.  Which means
that by the end of flush_resource() we can have a new write_batch.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11200>
2021-06-09 19:09:09 -07:00
Marek Olšák eb74f97769 gallium: split transfer_(un)map into buffer_(un)map and texture_(un)map
The u_resource_vtbl indirection is going to be removed.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10659>
2021-05-21 17:38:04 +00:00
Rob Clark ea112c5104 freedreno: Implement TC resource_busy
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10883>
2021-05-21 16:34:11 +00:00
Rob Clark a6d9a5f55a freedreno: Rename internal resource_busy
So I can re-use the name fd_resource_busy.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10883>
2021-05-21 16:34:11 +00:00
Marek Olšák ec77a2d43a gallium/u_threaded: add callbacks and documentation for resource busy checking
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10662>
2021-05-17 10:37:24 +00:00
Rob Clark bc3f66311d freedreno: Flush resources harder
pctx->flush_resource() has the same expectations that the resource can
be shared with an external client as pctx->flush(), but without the
convenience of a fence to know *when* the resource must be visible to
that external client.  So we need to ensure the batch is flushed all the
way to the kernel so that implicit-sync can do it's job.

Fixes: e9a9ac6f77 ("freedreno/drm: Async submit support")
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10530>
2021-05-01 08:46:27 -07:00
Rob Clark 8ab227c373 freedreno/drm: Cleanup bo cpu_prep flags
Also add some STATIC_ASSERT()

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
2021-04-28 15:36:42 +00:00
Rob Clark 7f0abd9048 freedreno/drm: Cleanup bo allocation flags
Most of them were actually unused.  The memory type (KMEM vs SMI) only
applied to very old a2xx era devices that had a small/fast stacked
memory (SMI) vs normal memory (KMEM).  And the cache flags are ignored
(ie. everything is writecombine), but we can add new cache flags later
when they actually do something.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
2021-04-28 15:36:42 +00:00
Rob Clark c64bc095e7 freedreno: Allow resource shadowing for TC
TC_TRANSFER_MAP_NO_INVALIDATE just means we can't invalidate.  It
doesn't preclude the resource shadow path.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
2021-04-28 15:36:42 +00:00
Rob Clark cb058a8922 freedreno: Avoid staging blits with stencil on older gens
This avoids infinite recursion with fallback to
util_resource_copy_region()

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
2021-04-28 15:36:42 +00:00
Rob Clark 224dbd77d5 freedreno: Small indent fix
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
2021-04-28 15:36:42 +00:00
Rob Clark 31782330da freedreno: Add missing foreach macros and update indentation
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10247>
2021-04-14 16:53:26 -07:00
Rob Clark 2d439343ea freedreno: Re-indent
clang-format -fallback-style=none --style=file -i src/gallium/drivers/freedreno/*.[ch] src/gallium/drivers/freedreno/*/*.[ch]

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8883>
2021-04-14 19:52:21 +00:00
Rob Clark 8cb51ba30e freedreno: Add dirty bit for state that needs rsc tracking
aa1ddb6fe3 skipped the tracking for the
!dirty case, but we can do a bit better and track at bind time whether
the state change is one that requires resource tracking.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9581>
2021-03-20 12:13:09 -07:00
Rob Clark 0cb989d71f freedreno: Add helpers to mark dirty state
Doesn't change anything yet, but this will let us more easily add
mapping from dirty gallium state to dirty gen-specific state-groups.

Note that the mapping from shader-state to global state in
fd_context_dirty_shader() optimizes out for release builds.  This
is kind of important, in the next patch we'll want ffs(SOME_CONST)
to optimize away even more.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9581>
2021-03-20 12:13:09 -07:00
Rob Clark 9dbe2405a3 freedreno: threaded_context support
Currently only initialized for a6xx, mostly because that is the easiest
setup for me to test and debug at the moment.  But the couple a6xx changes
should not require counterparts in older gens.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 1a12d682a6 freedreno: Check cb0 in rebind_resource()
Previously we were expecting cb0 to be user_buffer.  (We did in some
cases upload it to a gpu buffer, but this was an internally allocated
buffer and not something subject to rebind.)  But with TC it becomes
a gpu buffer.

(Technically, with pctx->const_uploader, we shouldn't hit the rebind
path for cb0, but better to not try to be overly clever.. sooner or
later that would bite us.)

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark acc2c015b3 freedreno: Add transfer_pool_unsync
With threaded_context, in the TC_TRANSFER_MAP_UNSYNC case, we are
getting called from the frontend thread, rather than driver thread.
So we need a different slab_child_pool for that.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 0c163e0a45 freedreno: Add fd_replace_buffer_storage()
This will be used by threaded_context to avoid stalls in the
DISCARD_WHOLE_RESOURCE case (and DISCARD_RANGE cases that can
be promoted to DISCARD_WHOLE_RESOURCE).

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 63649e4101 freedreno: Extract out helper for transfer-map flag munging
Split out the usage simplification from main part of transfer_map and
handle the threaded-context specific TC_TRANSFER_x flags.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 4f07a24e41 freedreno: Extend threaded_transfer
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 1017dc9f6e freedreno: Extend threaded_resource
No functional change, just big churny

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 5fbaa8033b freedreno: Restructure transfer_map()
Separate the parts that, with threaded_context, can be called from
either driver or frontend thread.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark 39d6343a3e freedreno: Split out batch/resource tracking
For threaded_context, to properly handle replace_buffer_storage, we'll
need to handle multiple "iterations" of a resource using the same
tracking in order to implement transfer_map() correctly.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:16 +00:00
Rob Clark f74ccde2c7 freedreno: Factor out common fd_resource init
Before adding new things that would need initialization in both paths,
refactor out a shared helper.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323>
2021-03-11 04:42:15 +00:00
Rob Clark f8714b2852 freedreno: Remove dead-cells MBR workaround
With threaded-context we won't have a chance to apply the workaround in
the backend driver.  But the previous commit moves it to a driconf
configured workaround in mesa/st, so we can drop this now.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9316>
2021-03-03 22:47:59 +00:00
Rob Clark 2ed9dfbe6f freedreno: Add macro for duration based warns
Add a macro to do a perf_debug() if a block of code takes longer than a
specified amount of time.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9264>
2021-02-25 20:09:44 +00:00