Commit Graph

94 Commits

Author SHA1 Message Date
Mike Blumenkrantz 285a5144cc zink: add batch api for adding a wait semaphore
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17066>
2022-06-16 02:01:53 +00:00
Mike Blumenkrantz 48b56d2efd zink: use a dynarray for semaphore wait flags
ensure that any number of semaphore waits is handled as expected

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17066>
2022-06-16 02:01:53 +00:00
Mike Blumenkrantz f5ac058812 zink: remove thread_queue
I had originally intended to hook this up properly with synchronization et al,
but I didn't do it, and now it's seeming less smart anyway, so let's
remove the footgun

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17066>
2022-06-16 02:01:53 +00:00
Mike Blumenkrantz bc2e29accd zink: require timeline semaphores
this allows the removal of tons of awful code

Acked-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15904>
2022-04-18 23:45:30 +00:00
Mike Blumenkrantz 7f56fd9655 zink: it's kopperin' time
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14541>
2022-04-07 00:17:40 +00:00
Mike Blumenkrantz 9e20d68785 zink: add some nice docs for batch usage and tracking
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15429>
2022-03-18 12:42:31 +00:00
Mike Blumenkrantz 32597e116d zink: implement GL semaphores
this is basically just a wrapper around vulkan semaphores, so it maps
fairly well

the existing fence function was a big ??? and should never have been triggered
like it was

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14498>
2022-01-18 23:31:01 +00:00
Mike Blumenkrantz 6cb2787984 zink: rework in-use batch states hash table to be a singly-linked list
it was useful to have this be a hash table back before timeline semaphores when
the batch state needed to be looked up every time to determine resource busy state,
but now in the modern world, this is almost never happening, and storing them like
this is actually worse for performance, so flatten it out into a simpler list

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13265>
2021-10-08 04:16:38 +00:00
Mike Blumenkrantz bc202553e9 zink: implement bindless textures
this works by tracking 1024-member arrays of images and textures using idalloc
for indexing. each idalloc id is an index into the array that is returned as a handle,
and this handle is used to index into the array in shaders.

in the driver, VK_EXT_descriptor_indexing features are used to enable updates on the live
bindless descriptor set and leave unused members of the arrays unbound, which works as
long as no member is updated while it is in use. to avoid this, idalloc ids must cycle through
a batch once the image/texture handle is destroyed before being returned to the available pool

in shaders, bindless ops come in one of two types:
- i/o variables
- bindless instructions

for i/o, the image/texture variables have to be rewritten back to the integer
handles which represent them so that the successive shader stage utilizing them
can perform the indexing

for instructions, the src representing the image/texture has to be rewritten as a deref
into the bindless image/texture array

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12855>
2021-09-27 01:40:54 +00:00
Mike Blumenkrantz 46b6ecd4ab zink: move resource unrefs to flush thread
unrefs here (almost always) mean destruction, which means eating the cost
of the atomics for the unrefs and then also the destructors

instead, handle this at the end of the next submit from this batch, since the
submit thread is never as busy as the driver thread

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12759>
2021-09-13 00:38:42 +00:00
Mike Blumenkrantz c71e662ae2 zink: remove refcounting from batch states
these are always destroyed by the context, no exceptions

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12633>
2021-09-01 02:46:00 +00:00
Mike Blumenkrantz 3674839d11 zink: batch mem barrier hooks
memory barriers are redundant, so batch them and apply based on actual
usage to be slightly more efficient

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12576>
2021-08-27 02:59:24 +00:00
Mike Blumenkrantz 8e2159a57f zink: stop referencing framebuffers
this is a waste of cycles now that surfaces are accurately tracked;
no-attachment fbs are still deferred to avoid premature deletion

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12429>
2021-08-24 19:23:48 +00:00
Mike Blumenkrantz 1af6618694 zink: defer deletion of no-attachment framebuffers
the ref on these is owned by the context, so defer deletion to avoid
premature destruction if the fb might be in use

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12429>
2021-08-24 19:23:48 +00:00
Mike Blumenkrantz 9460c350b1 zink: merge draw_count and compute_count, move to batch struct
one fewer deref and now it's a single counter

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12010>
2021-07-27 00:28:02 +00:00
Mike Blumenkrantz 5bab4cc546 zink: add screen function for checking usage completion
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12008>
2021-07-26 19:48:07 -04:00
Mike Blumenkrantz db32c3aff3 zink: add util function for transferring resource refs to batch
there's no point in doing unref->ref if it's known that this will happen

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11692>
2021-07-07 00:22:09 +00:00
Mike Blumenkrantz 6acd2e9de3 zink: split batch usage setting from refcounting
batch tracking has until now been the same as refcounting, but this
is inefficient and incurs additional overhead from constant atomic ops,
so make them separate

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11684>
2021-07-02 01:38:04 +00:00
Mike Blumenkrantz b302ab5167 zink: split out resource tracking into more incremental functions
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11684>
2021-07-02 01:38:04 +00:00
Mike Blumenkrantz b432bdc035 zink: add c++ header guards
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11685>
2021-07-01 21:13:06 -04:00
Mike Blumenkrantz e58eb3f269 zink: add a ref for flush resource
the lifetime of this needs to always be preserved

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11665>
2021-07-01 23:04:34 +00:00
Erik Faye-Lund f815026d36 zink: cast pointers to uintptr_t
The way p_atomic_cmpxchg is implemented on Windows really wants us to
use integers instead of things like pointers. So let's use uintptr_t
here. It seems cleaner to use that than the value zero for the last
argument, because it shows the intent of the code more clearly.

Fixes: d80d9e1c93 ("zink: queue v3.0")
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11424>
2021-06-24 17:51:47 +00:00
Mike Blumenkrantz 5cecf826d3 zink: don't clear batch resources on fence finish
this eliminates the need for locking here and has no noticeable
increase in overhead, so the reduction of complexity seems worthwhile

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz d8dc03c213 zink: flag scanout updates to batch state, not resource
now that submission is serialized better, it's not actually the resource that should be
tagged for scanout sync, it's the batch state, as multiple contexts might reuse the same
resource, thus requiring synchronization on every submit

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz 478f129ee7 zink: move queue submit thread to screen
this needs to be a screen-based queue in order to serialize properly
with multiple contexts

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz d4159963e3 zink: enforce multi-context waiting for unflushed resources on foreign batches
this doesn't seem to be a real issue now that tc doesn't break makeCurrent
anymore, but if such a thing were to once again become a problem, at least
there will be handling for it

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz d80d9e1c93 zink: queue v3.0
this uses a pointer to a batch state substruct for timeline tracking,
which provides a few nice benefits:
* explicit ability to detect unflushed batches (even on other contexts)
* the context doesn't need to have a "current" timeline id
* timeline (batch) ids can be distributed during submit, not when recording begins
* an abstracted api which can be more easily changed under the hood

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz 1226628eb6 zink: add and use fencing functions which take batch usage structs
this hides the exact mechanics of fencing based on batch usage and makes
the usage a bit more explicit

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz 982a2dfbd4 zink: improve tc fence disambiguation
instead of storing separate batch_id values onto the tc fence for matching:
* use a fence pointer on the main context to indicate the current deferred fence
* add a monotonic counter to each batch state which double-increments on each use,
  thereby enabling direct determination by the tc fence as to whether this is the same
  batch state it was created with

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11437>
2021-06-22 20:57:33 +00:00
Mike Blumenkrantz 806251c72d zink: move queue init to screen creation
this is a race condition

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11398>
2021-06-16 15:03:22 +00:00
Mike Blumenkrantz 1108db982e zink: make batch_usage_matches take a batch state param
no functional changes, just some unwinding in some cases

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11399>
2021-06-16 02:45:45 +00:00
Mike Blumenkrantz 6e0f552fd2 zink: make batch_usage_set take a batch state param
no functional changes

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11399>
2021-06-16 02:45:45 +00:00
Mike Blumenkrantz 48add48209 zink: make batch_usage_unset take a batch state param
no functional changes

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11399>
2021-06-16 02:45:45 +00:00
Mike Blumenkrantz 50cfe0dbd1 zink: remove atomic from batch usage setting
this shouldn't be necessary since usage can only be set from the context thread
and only needs to be accessed atomically for the cmpxchg when unsetting

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11399>
2021-06-16 02:45:45 +00:00
Mike Blumenkrantz 559f534e11 zink: move batch usage functions to static inlines
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11399>
2021-06-16 02:45:45 +00:00
Mike Blumenkrantz 1c1b0f7c91 zink: reorder has_barriers flag in batch state struct
better struct packing

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11400>
2021-06-16 01:28:12 +00:00
Mike Blumenkrantz e1ba1b5b25 zink: split batch state work_count into separate vars
this has better struct packing

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11400>
2021-06-16 01:28:12 +00:00
Mike Blumenkrantz b85a6b9162 zink: remove zink_batch_state::descs_used
this is no longer used or needed

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11400>
2021-06-16 01:28:12 +00:00
Mike Blumenkrantz 425642bec1 zink: abstract descriptor functionality and make descriptor structs private
the first step to adding modular descriptor managers is to isolate the existing one
so that it can be easily swapped out

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10849>
2021-05-25 20:53:00 -04:00
Mike Blumenkrantz f20b3c5aa9 zink: rename ptr_add_usage -> batch_ptr_add_usage
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10849>
2021-05-25 20:52:37 -04:00
Mike Blumenkrantz 0f04a90ea3 zink: emit some barriers out of renderpass where possible
when emitting barriers, we don't need to end the renderpass in some cases

this handles the case of emitting barriers for new resources which have
never before been accessed and thus do not require synchronization at a
specific point in the batch

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10700>
2021-05-14 13:15:07 +00:00
Mike Blumenkrantz afb837523d zink: flush every 100k draws/computes
this ensures more consistent throughput in e.g., drawoverhead

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10760>
2021-05-13 10:31:59 +00:00
Mike Blumenkrantz fa36a16c68 zink: make timeline semaphores per-screen
I misread the spec, and it turns out timeline ids can't be reused across
semaphores. This is obvious in retrospect, but what can be done?

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Tested-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10115>
2021-04-09 13:31:55 +00:00
Mike Blumenkrantz 9a13add12e zink: hook up timeline semaphore signalling during batch submission
just basic parts, no waiting on semaphores yet

Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9963>
2021-04-01 13:25:51 +00:00
Mike Blumenkrantz d179c5d28e zink: implement threaded context
this includes:
* async buffer mapping/replacement
* async queue submission
* async (threaded) gallium flush handling

the main churn here is from handling async gallium flushes, which involves
creating multiple gallium fences (zink_tc_fence) for each zink fence (zink_fence).
a tc fence may begin waiting for completion at any time, even before the zink_fence
has had its cmdbuf(s) submitted, so handling this type of desync ends up needing
almost a complete rewrite of the existing queue architecture

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9935>
2021-03-31 20:16:05 -04:00
Mike Blumenkrantz dc5d02ca54 zink: break out queue submit into separate functions
to be used with async submission

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9885>
2021-03-30 15:12:59 +00:00
Mike Blumenkrantz 38c5e154df zink: move VkQueue to batch object
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9885>
2021-03-30 15:12:59 +00:00
Mike Blumenkrantz 3a344174dc zink: store context to batch state
this will be used for post-flush device resets when device is lost

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9885>
2021-03-30 15:12:59 +00:00
Mike Blumenkrantz 12dfba1951 zink: unify gfx and compute batches
now that batches aren't limited and flushing is less costly, there's no
reason to keep these separate

the primary changes here are removing the zink_queue enum and collapsing
related arrays which used it as an index, e.g., zink_batch_usage into single
members

remaining future work here will include removing synchronization flushes which
are no longer necessary and (eventually) removing batch params from a number of
functions since there is now only ever a single batch

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9765>
2021-03-24 03:26:20 +00:00
Mike Blumenkrantz e89f674c83 zink: add wrapper to reset batch state structs
this will be useful in the future when we need additional work to handle
resets of states that aren't detected as being "completed"

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9765>
2021-03-24 03:26:20 +00:00