• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #ifndef FREEDRENO_FENCE_H_
28 #define FREEDRENO_FENCE_H_
29 
30 #include "pipe/p_context.h"
31 #include "util/u_queue.h"
32 
33 #include "common/freedreno_common.h"
34 #include "drm/freedreno_drmif.h"
35 
36 BEGINC;
37 
38 struct pipe_fence_handle {
39    struct pipe_reference reference;
40 
41    /* When a pre-created unflushed fence has no actual rendering to flush, and
42     * the last_fence optimization is used, this will be a reference to the
43     * *actualy* fence which needs to be flushed before waiting.
44     */
45    struct pipe_fence_handle *last_fence;
46 
47    /* fence holds a reference to the batch until the batch is flushed, to
48     * accommodate PIPE_FLUSH_DEFERRED.  When the batch is actually flushed, it
49     * is cleared (before the batch reference is dropped).  If we need to wait
50     * on a fence, and the batch is not NULL, we need to flush it.
51     *
52     * Note that with u_threaded_context async flushes, if a fence is requested
53     * by the frontend, the fence is initially created without a reference
54     * to the batch, which is filled in later when fd_context_flush() is called
55     * from the driver thread.  In this case tc_token will be non-null, in
56     * which case threaded_context_flush() should be called in fd_fence_finish()
57     */
58    struct fd_batch *batch;
59 
60    struct tc_unflushed_batch_token *tc_token;
61    bool needs_signal;
62 
63    /* For threaded_context async flushes, we must wait on the fence, signaled
64     * when fence->batch is cleared, to know that the rendering has been actually
65     * flushed from the driver thread.
66     *
67     * The ready fence is created signaled for non-async-flush fences, and only
68     * transitions once from unsignalled->signalled for async-flush fences
69     */
70    struct util_queue_fence ready;
71 
72    /* Note that a fence can outlive the ctx, so we can only assume this is a
73     * valid ptr for unflushed fences.  However we hold a reference to the
74     * fence->pipe so that is safe to use after flushing.
75     */
76    struct fd_context *ctx;
77    struct fd_pipe *pipe;
78    struct fd_screen *screen;
79    struct fd_fence *fence;
80 
81    bool use_fence_fd;
82    bool flushed;
83    uint32_t syncobj;
84 };
85 
86 void fd_pipe_fence_repopulate(struct pipe_fence_handle *fence,
87                               struct pipe_fence_handle *last_fence);
88 void fd_pipe_fence_ref(struct pipe_fence_handle **ptr,
89                        struct pipe_fence_handle *pfence);
90 bool fd_pipe_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
91                           struct pipe_fence_handle *pfence, uint64_t timeout);
92 void fd_create_pipe_fence_fd(struct pipe_context *pctx,
93                              struct pipe_fence_handle **pfence, int fd,
94                              enum pipe_fd_type type);
95 void fd_pipe_fence_server_sync(struct pipe_context *pctx,
96                                struct pipe_fence_handle *fence);
97 void fd_pipe_fence_server_signal(struct pipe_context *ctx,
98                                  struct pipe_fence_handle *fence);
99 int fd_pipe_fence_get_fd(struct pipe_screen *pscreen,
100                          struct pipe_fence_handle *pfence);
101 bool fd_pipe_fence_is_fd(struct pipe_fence_handle *fence);
102 
103 struct fd_batch;
104 struct pipe_fence_handle *fd_pipe_fence_create(struct fd_batch *batch);
105 
106 void fd_pipe_fence_set_batch(struct pipe_fence_handle *fence,
107                              struct fd_batch *batch);
108 void fd_pipe_fence_set_submit_fence(struct pipe_fence_handle *fence,
109                         struct fd_fence *submit_fence);
110 
111 struct tc_unflushed_batch_token;
112 struct pipe_fence_handle *
113 fd_pipe_fence_create_unflushed(struct pipe_context *pctx,
114                                struct tc_unflushed_batch_token *tc_token);
115 
116 ENDC;
117 
118 #endif /* FREEDRENO_FENCE_H_ */
119