Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_fine_fence.h
4565 views
/*1* Copyright © 2020 Intel Corporation2*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* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* 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 NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef IRIS_FINE_FENCE_DOT_H24#define IRIS_FINE_FENCE_DOT_H2526#include <stdbool.h>27#include <stdint.h>2829#include "iris_screen.h"30#include "iris_resource.h"3132/**33* A lightweight sequence number fence.34*35* We emit PIPE_CONTROLs inside a batch (possibly in the middle)36* which update a monotonically increasing, 32-bit counter. We37* can then check if that moment has passed by either:38*39* 1. Checking on the CPU by snooping on the DWord via a coherent map40*41* 2. Blocking on the GPU with MI_SEMAPHORE_WAIT from a second batch42* (relying on mid-batch preemption to switch GPU execution to the43* batch that writes it).44*/45struct iris_fine_fence {46struct pipe_reference reference;4748/** Buffer where the seqno lives */49struct iris_state_ref ref;5051/** Coherent CPU map of the buffer containing the seqno DWord. */52const uint32_t *map;5354/**55* A drm_syncobj pointing which will be signaled at the end of the56* batch which writes this seqno. This can be used to block until57* the seqno has definitely passed (but may wait longer than necessary).58*/59struct iris_syncobj *syncobj;6061#define IRIS_FENCE_BOTTOM_OF_PIPE 0x0 /**< Written by bottom-of-pipe flush */62#define IRIS_FENCE_TOP_OF_PIPE 0x1 /**< Written by top-of-pipe flush */63#define IRIS_FENCE_END 0x2 /**< Written at the end of a batch */6465/** Information about the type of flush involved (see IRIS_FENCE_*) */66uint32_t flags;6768/**69* Sequence number expected to be written by the flush we inserted70* when creating this fence. The iris_fine_fence is 'signaled' when *@map71* (written by the flush on the GPU) is greater-than-or-equal to @seqno.72*/73uint32_t seqno;74};7576void iris_fine_fence_init(struct iris_batch *batch);7778struct iris_fine_fence *iris_fine_fence_new(struct iris_batch *batch, unsigned flags);7980void iris_fine_fence_destroy(struct iris_screen *screen, struct iris_fine_fence *sq);8182static inline void83iris_fine_fence_reference(struct iris_screen *screen,84struct iris_fine_fence **dst,85struct iris_fine_fence *src)86{87if (pipe_reference(&(*dst)->reference, &src->reference))88iris_fine_fence_destroy(screen, *dst);8990*dst = src;91}9293/**94* Return true if this seqno has passed.95*96* NULL is considered signaled.97*/98static inline bool99iris_fine_fence_signaled(const struct iris_fine_fence *sq)100{101return !sq || (READ_ONCE(*sq->map) >= sq->seqno);102}103104#endif105106107