zink_batch.h revision 7ec681f3
1/* 2 * Copyright 2018 Collabora Ltd. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24#ifndef ZINK_BATCH_H 25#define ZINK_BATCH_H 26 27#include <vulkan/vulkan.h> 28 29#include "util/list.h" 30#include "util/set.h" 31#include "util/u_dynarray.h" 32 33#include "zink_fence.h" 34 35#ifdef __cplusplus 36extern "C" { 37#endif 38 39struct pipe_reference; 40 41struct zink_buffer_view; 42struct zink_context; 43struct zink_descriptor_set; 44struct zink_image_view; 45struct zink_program; 46struct zink_render_pass; 47struct zink_resource; 48struct zink_sampler_view; 49struct zink_surface; 50 51struct zink_batch_usage { 52 uint32_t usage; 53 cnd_t flush; 54 mtx_t mtx; 55 bool unflushed; 56}; 57 58/* not real api don't use */ 59bool 60batch_ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr); 61 62struct zink_batch_state { 63 struct zink_fence fence; 64 struct zink_batch_state *next; 65 66 struct zink_batch_usage usage; 67 struct zink_context *ctx; 68 VkCommandPool cmdpool; 69 VkCommandBuffer cmdbuf; 70 VkCommandBuffer barrier_cmdbuf; 71 72 VkQueue queue; //duplicated from batch for threading 73 VkSemaphore sem; 74 75 struct util_queue_fence flush_completed; 76 77 struct pipe_resource *flush_res; 78 79 struct set *programs; 80 81 struct set *resources; 82 struct set *surfaces; 83 struct set *bufferviews; 84 85 struct util_dynarray unref_resources; 86 struct util_dynarray bindless_releases[2]; 87 88 struct util_dynarray persistent_resources; 89 struct util_dynarray zombie_samplers; 90 struct util_dynarray dead_framebuffers; 91 92 struct set *active_queries; /* zink_query objects which were active at some point in this batch */ 93 94 struct zink_batch_descriptor_data *dd; 95 96 VkDeviceSize resource_size; 97 98 /* this is a monotonic int used to disambiguate internal fences from their tc fence references */ 99 unsigned submit_count; 100 101 bool is_device_lost; 102 bool have_timelines; 103 bool has_barriers; 104 bool scanout_flush; 105}; 106 107struct zink_batch { 108 struct zink_batch_state *state; 109 110 struct zink_batch_usage *last_batch_usage; 111 112 unsigned work_count; 113 114 bool has_work; 115 bool last_was_compute; 116 bool in_rp; //renderpass is currently active 117}; 118 119 120static inline struct zink_batch_state * 121zink_batch_state(struct zink_fence *fence) 122{ 123 return (struct zink_batch_state *)fence; 124} 125 126void 127zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs); 128 129void 130zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs); 131 132void 133zink_batch_reset_all(struct zink_context *ctx); 134 135void 136zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs); 137 138void 139zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs); 140 141void 142zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch); 143void 144zink_start_batch(struct zink_context *ctx, struct zink_batch *batch); 145 146void 147zink_end_batch(struct zink_context *ctx, struct zink_batch *batch); 148 149void 150zink_batch_resource_usage_set(struct zink_batch *batch, struct zink_resource *res, bool write); 151 152void 153zink_batch_reference_resource_rw(struct zink_batch *batch, 154 struct zink_resource *res, 155 bool write); 156void 157zink_batch_reference_resource(struct zink_batch *batch, struct zink_resource *res); 158 159void 160zink_batch_reference_resource_move(struct zink_batch *batch, struct zink_resource *res); 161 162void 163zink_batch_reference_sampler_view(struct zink_batch *batch, 164 struct zink_sampler_view *sv); 165 166void 167zink_batch_reference_program(struct zink_batch *batch, 168 struct zink_program *pg); 169 170void 171zink_batch_reference_image_view(struct zink_batch *batch, 172 struct zink_image_view *image_view); 173 174void 175zink_batch_reference_bufferview(struct zink_batch *batch, struct zink_buffer_view *buffer_view); 176void 177zink_batch_reference_surface(struct zink_batch *batch, struct zink_surface *surface); 178 179void 180debug_describe_zink_batch_state(char *buf, const struct zink_batch_state *ptr); 181 182static inline bool 183zink_batch_usage_is_unflushed(const struct zink_batch_usage *u) 184{ 185 return u && u->unflushed; 186} 187 188static inline void 189zink_batch_usage_unset(struct zink_batch_usage **u, struct zink_batch_state *bs) 190{ 191 (void)p_atomic_cmpxchg((uintptr_t *)u, (uintptr_t)&bs->usage, (uintptr_t)NULL); 192} 193 194static inline void 195zink_batch_usage_set(struct zink_batch_usage **u, struct zink_batch_state *bs) 196{ 197 *u = &bs->usage; 198} 199 200static inline bool 201zink_batch_usage_matches(const struct zink_batch_usage *u, const struct zink_batch_state *bs) 202{ 203 return u == &bs->usage; 204} 205 206static inline bool 207zink_batch_usage_exists(const struct zink_batch_usage *u) 208{ 209 return u && (u->usage || u->unflushed); 210} 211 212bool 213zink_screen_usage_check_completion(struct zink_screen *screen, const struct zink_batch_usage *u); 214 215bool 216zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u); 217 218void 219zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u); 220 221#ifdef __cplusplus 222} 223#endif 224 225#endif 226