Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_fine_fence.h
4570 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 CROCUS_FINE_FENCE_DOT_H24#define CROCUS_FINE_FENCE_DOT_H2526#include <stdbool.h>27#include <stdint.h>2829#include "crocus_screen.h"30#include "crocus_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 crocus_fine_fence {46struct pipe_reference reference;4748/** Buffer where the seqno lives */49struct crocus_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 crocus_syncobj *syncobj;6061#define CROCUS_FENCE_BOTTOM_OF_PIPE 0x0 /**< Written by bottom-of-pipe flush */62#define CROCUS_FENCE_TOP_OF_PIPE 0x1 /**< Written by top-of-pipe flush */63#define CROCUS_FENCE_END 0x2 /**< Written at the end of a batch */6465/** Information about the type of flush involved (see CROCUS_FENCE_*) */66uint32_t flags;6768/**69* Sequence number expected to be written by the flush we inserted70* when creating this fence. The crocus_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 crocus_fine_fence_init(struct crocus_batch *batch);7778struct crocus_fine_fence *crocus_fine_fence_new(struct crocus_batch *batch,79unsigned flags);8081void crocus_fine_fence_destroy(struct crocus_screen *screen,82struct crocus_fine_fence *sq);8384static inline void85crocus_fine_fence_reference(struct crocus_screen *screen,86struct crocus_fine_fence **dst,87struct crocus_fine_fence *src)88{89if (pipe_reference(&(*dst)->reference, &src->reference))90crocus_fine_fence_destroy(screen, *dst);9192*dst = src;93}9495/**96* Return true if this seqno has passed.97*98* NULL is considered signaled.99*/100static inline bool101crocus_fine_fence_signaled(const struct crocus_fine_fence *sq)102{103if (sq && !sq->map)104return false;105return !sq || (READ_ONCE(*sq->map) >= sq->seqno);106}107108#endif109110111