Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_batch.h
4570 views
/*1* Copyright 2018 Collabora Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef ZINK_BATCH_H24#define ZINK_BATCH_H2526#include <vulkan/vulkan.h>2728#include "util/list.h"29#include "util/set.h"30#include "util/u_dynarray.h"3132#include "zink_fence.h"3334#ifdef __cplusplus35extern "C" {36#endif3738struct pipe_reference;3940struct zink_buffer_view;41struct zink_context;42struct zink_descriptor_set;43struct zink_framebuffer;44struct zink_image_view;45struct zink_program;46struct zink_render_pass;47struct zink_resource;48struct zink_sampler_view;49struct zink_surface;5051struct zink_batch_usage {52uint32_t usage;53cnd_t flush;54mtx_t mtx;55bool unflushed;56};5758/* not real api don't use */59bool60batch_ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr);6162struct zink_batch_state {63struct zink_fence fence;64struct pipe_reference reference;65unsigned draw_count;6667struct zink_batch_usage usage;68struct zink_context *ctx;69VkCommandPool cmdpool;70VkCommandBuffer cmdbuf;71VkCommandBuffer barrier_cmdbuf;7273VkQueue queue; //duplicated from batch for threading74VkSemaphore sem;7576struct util_queue_fence flush_completed;77unsigned compute_count;7879struct pipe_resource *flush_res;8081struct set *fbs;82struct set *programs;8384struct set *resources;85struct set *surfaces;86struct set *bufferviews;8788struct util_dynarray persistent_resources;89struct util_dynarray zombie_samplers;9091struct set *active_queries; /* zink_query objects which were active at some point in this batch */9293struct zink_batch_descriptor_data *dd;9495VkDeviceSize resource_size;9697/* this is a monotonic int used to disambiguate internal fences from their tc fence references */98unsigned submit_count;99100bool is_device_lost;101bool have_timelines;102bool has_barriers;103bool scanout_flush;104};105106struct zink_batch {107struct zink_batch_state *state;108109struct zink_batch_usage *last_batch_usage;110111bool has_work;112bool in_rp; //renderpass is currently active113};114115116static inline struct zink_batch_state *117zink_batch_state(struct zink_fence *fence)118{119return (struct zink_batch_state *)fence;120}121122void123zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);124125void126zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);127128void129zink_batch_reset_all(struct zink_context *ctx);130131void132zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs);133134void135zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs);136137void138zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch);139void140zink_batch_reference_framebuffer(struct zink_batch *batch,141struct zink_framebuffer *fb);142void143zink_start_batch(struct zink_context *ctx, struct zink_batch *batch);144145void146zink_end_batch(struct zink_context *ctx, struct zink_batch *batch);147148void149zink_batch_resource_usage_set(struct zink_batch *batch, struct zink_resource *res, bool write);150151void152zink_batch_reference_resource_rw(struct zink_batch *batch,153struct zink_resource *res,154bool write);155void156zink_batch_reference_resource(struct zink_batch *batch, struct zink_resource *res);157158void159zink_batch_reference_resource_move(struct zink_batch *batch, struct zink_resource *res);160161void162zink_batch_reference_sampler_view(struct zink_batch *batch,163struct zink_sampler_view *sv);164165void166zink_batch_reference_program(struct zink_batch *batch,167struct zink_program *pg);168169void170zink_batch_reference_image_view(struct zink_batch *batch,171struct zink_image_view *image_view);172173void174zink_batch_reference_bufferview(struct zink_batch *batch, struct zink_buffer_view *buffer_view);175void176zink_batch_reference_surface(struct zink_batch *batch, struct zink_surface *surface);177178void179debug_describe_zink_batch_state(char *buf, const struct zink_batch_state *ptr);180181static inline void182zink_batch_state_reference(struct zink_screen *screen,183struct zink_batch_state **dst,184struct zink_batch_state *src)185{186struct zink_batch_state *old_dst = dst ? *dst : NULL;187188if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, src ? &src->reference : NULL,189(debug_reference_descriptor)debug_describe_zink_batch_state))190zink_batch_state_destroy(screen, old_dst);191if (dst) *dst = src;192}193194static inline bool195zink_batch_usage_is_unflushed(const struct zink_batch_usage *u)196{197return u && u->unflushed;198}199200static inline void201zink_batch_usage_unset(struct zink_batch_usage **u, struct zink_batch_state *bs)202{203(void)p_atomic_cmpxchg((uintptr_t *)u, (uintptr_t)&bs->usage, (uintptr_t)NULL);204}205206static inline void207zink_batch_usage_set(struct zink_batch_usage **u, struct zink_batch_state *bs)208{209*u = &bs->usage;210}211212static inline bool213zink_batch_usage_matches(const struct zink_batch_usage *u, const struct zink_batch_state *bs)214{215return u == &bs->usage;216}217218static inline bool219zink_batch_usage_exists(const struct zink_batch_usage *u)220{221return u && (u->usage || u->unflushed);222}223224bool225zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);226227void228zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u);229230#ifdef __cplusplus231}232#endif233234#endif235236237