• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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_RINGBUFFER_SP_H_
28 #define FREEDRENO_RINGBUFFER_SP_H_
29 
30 #include <assert.h>
31 #include <inttypes.h>
32 #include <pthread.h>
33 
34 #include "util/hash_table.h"
35 #include "util/os_file.h"
36 #include "util/slab.h"
37 
38 #include "freedreno_priv.h"
39 #include "freedreno_ringbuffer.h"
40 
41 /* A "softpin" implementation of submit/ringbuffer, which lowers CPU overhead
42  * by avoiding the additional tracking necessary to build cmds/relocs tables
43  * (but still builds a bos table)
44  */
45 
46 typedef int (*flush_submit_list_fn)(struct list_head *submit_list);
47 
48 struct fd_submit_sp {
49    struct fd_submit base;
50 
51    DECLARE_ARRAY(struct fd_bo *, bos);
52 
53    /* maps fd_bo to idx in bos table: */
54    struct hash_table *bo_table;
55 
56    struct slab_child_pool ring_pool;
57 
58    /* Allow for sub-allocation of stateobj ring buffers (ie. sharing
59     * the same underlying bo)..
60     *
61     * We also rely on previous stateobj having been fully constructed
62     * so we can reclaim extra space at it's end.
63     */
64    struct fd_ringbuffer *suballoc_ring;
65 
66    /* Flush args, potentially attached to the last submit in the list
67     * of submits to merge:
68     */
69    int in_fence_fd;
70    struct fd_submit_fence *out_fence;
71 
72    /* State for enqueued submits:
73     */
74    struct list_head submit_list;   /* includes this submit as last element */
75 
76    /* Used in case out_fence==NULL: */
77    struct util_queue_fence fence;
78 
79    /* Used by retire_queue, if used by backend: */
80    int out_fence_fd;
81    struct util_queue_fence retire_fence;
82 
83    flush_submit_list_fn flush_submit_list;
84 };
85 FD_DEFINE_CAST(fd_submit, fd_submit_sp);
86 
87 /* for FD_RINGBUFFER_GROWABLE rb's, tracks the 'finalized' cmdstream buffers
88  * and sizes.  Ie. a finalized buffer can have no more commands appended to
89  * it.
90  */
91 struct fd_cmd_sp {
92    struct fd_bo *ring_bo;
93    unsigned size;
94 };
95 
96 struct fd_ringbuffer_sp {
97    struct fd_ringbuffer base;
98 
99    /* for FD_RINGBUFFER_STREAMING rb's which are sub-allocated */
100    unsigned offset;
101 
102    union {
103       /* for _FD_RINGBUFFER_OBJECT case, the array of BOs referenced from
104        * this one
105        */
106       struct {
107          struct fd_pipe *pipe;
108          DECLARE_ARRAY(struct fd_bo *, reloc_bos);
109       };
110       /* for other cases: */
111       struct {
112          struct fd_submit *submit;
113          DECLARE_ARRAY(struct fd_cmd_sp, cmds);
114       };
115    } u;
116 
117    struct fd_bo *ring_bo;
118 };
119 FD_DEFINE_CAST(fd_ringbuffer, fd_ringbuffer_sp);
120 
121 void fd_pipe_sp_flush(struct fd_pipe *pipe, uint32_t fence);
122 uint32_t fd_submit_append_bo(struct fd_submit_sp *submit, struct fd_bo *bo);
123 struct fd_submit *fd_submit_sp_new(struct fd_pipe *pipe,
124                                    flush_submit_list_fn flush_submit_list);
125 void fd_pipe_sp_ringpool_init(struct fd_pipe *pipe);
126 void fd_pipe_sp_ringpool_fini(struct fd_pipe *pipe);
127 struct fd_ringbuffer *fd_ringbuffer_sp_new_object(struct fd_pipe *pipe, uint32_t size);
128 
129 #endif /* FREEDRENO_RINGBUFFER_SP_H_ */
130