mesa/src/gallium/drivers/zink/zink_batch.h
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

215 lines
6 KiB
C

/*
* Copyright 2018 Collabora Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef ZINK_BATCH_H
#define ZINK_BATCH_H
#include <vulkan/vulkan.h>
#include "util/list.h"
#include "util/u_dynarray.h"
#include "zink_fence.h"
struct pipe_reference;
struct zink_buffer_view;
struct zink_context;
struct zink_descriptor_set;
struct zink_framebuffer;
struct zink_image_view;
struct zink_program;
struct zink_render_pass;
struct zink_resource;
struct zink_sampler_view;
struct zink_surface;
struct zink_batch_usage {
uint32_t usage;
bool unflushed;
};
/* not real api don't use */
bool
batch_ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr, struct zink_batch_usage **u);
struct zink_batch_state {
struct zink_fence fence;
struct pipe_reference reference;
unsigned draw_count;
struct zink_batch_usage usage;
struct zink_context *ctx;
VkCommandPool cmdpool;
VkCommandBuffer cmdbuf;
VkCommandBuffer barrier_cmdbuf;
VkQueue queue; //duplicated from batch for threading
VkSemaphore sem;
struct util_queue_fence flush_completed;
unsigned compute_count;
struct zink_resource *flush_res;
struct set *fbs;
struct set *programs;
struct set *surfaces;
struct set *bufferviews;
struct util_dynarray persistent_resources;
struct util_dynarray zombie_samplers;
struct set *active_queries; /* zink_query objects which were active at some point in this batch */
struct zink_batch_descriptor_data *dd;
VkDeviceSize resource_size;
/* this is a monotonic int used to disambiguate internal fences from their tc fence references */
unsigned submit_count;
bool is_device_lost;
bool have_timelines;
bool has_barriers;
};
struct zink_batch {
struct zink_batch_state *state;
struct zink_batch_usage *last_batch_usage;
struct util_queue flush_queue; //TODO: move to wsi
bool has_work;
bool in_rp; //renderpass is currently active
};
static inline struct zink_batch_state *
zink_batch_state(struct zink_fence *fence)
{
return (struct zink_batch_state *)fence;
}
void
zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
void
zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
void
zink_batch_reset_all(struct zink_context *ctx);
void
zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs);
void
zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs);
void
zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch);
void
zink_batch_reference_framebuffer(struct zink_batch *batch,
struct zink_framebuffer *fb);
void
zink_start_batch(struct zink_context *ctx, struct zink_batch *batch);
void
zink_end_batch(struct zink_context *ctx, struct zink_batch *batch);
void
zink_batch_reference_resource_rw(struct zink_batch *batch,
struct zink_resource *res,
bool write);
void
zink_batch_reference_sampler_view(struct zink_batch *batch,
struct zink_sampler_view *sv);
void
zink_batch_reference_program(struct zink_batch *batch,
struct zink_program *pg);
void
zink_batch_reference_image_view(struct zink_batch *batch,
struct zink_image_view *image_view);
void
zink_batch_reference_bufferview(struct zink_batch *batch, struct zink_buffer_view *buffer_view);
void
zink_batch_reference_surface(struct zink_batch *batch, struct zink_surface *surface);
void
debug_describe_zink_batch_state(char *buf, const struct zink_batch_state *ptr);
static inline void
zink_batch_state_reference(struct zink_screen *screen,
struct zink_batch_state **dst,
struct zink_batch_state *src)
{
struct zink_batch_state *old_dst = dst ? *dst : NULL;
if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, src ? &src->reference : NULL,
(debug_reference_descriptor)debug_describe_zink_batch_state))
zink_batch_state_destroy(screen, old_dst);
if (dst) *dst = src;
}
static inline bool
zink_batch_usage_is_unflushed(const struct zink_batch_usage *u)
{
return u && u->unflushed;
}
static inline void
zink_batch_usage_unset(struct zink_batch_usage **u, struct zink_batch_state *bs)
{
(void)p_atomic_cmpxchg(u, &bs->usage, NULL);
}
static inline void
zink_batch_usage_set(struct zink_batch_usage **u, struct zink_batch_state *bs)
{
*u = &bs->usage;
}
static inline bool
zink_batch_usage_matches(const struct zink_batch_usage *u, const struct zink_batch_state *bs)
{
return u == &bs->usage;
}
static inline bool
zink_batch_usage_exists(const struct zink_batch_usage *u)
{
return u && (u->usage || u->unflushed);
}
bool
zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);
void
zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u);
#endif