Debian Codegraph @

src/gallium/drivers/freedreno/a6xx/fd6_barrier.cc

raw symbols SCIP
1 /*
2 * Copyright © 2023 Google, Inc.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "freedreno_batch.h"
7
8 #include "fd6_barrier.h"
9 #include "fd6_emit.h"
10
11 template <chip CHIP>
12 void
13 fd6_emit_flushes(struct fd_context *ctx, fd_cs &cs, unsigned flushes)
14 {
15 /* Experiments show that invalidating CCU while it still has data in it
16 * doesn't work, so make sure to always flush before invalidating in case
17 * any data remains that hasn't yet been made available through a barrier.
18 * However it does seem to work for UCHE.
19 */
20 if (flushes & (FD6_FLUSH_CCU_COLOR | FD6_INVALIDATE_CCU_COLOR))
21 fd6_event_write<CHIP>(ctx, cs, FD_CCU_CLEAN_COLOR);
22
23 if (flushes & (FD6_FLUSH_CCU_DEPTH | FD6_INVALIDATE_CCU_DEPTH))
24 fd6_event_write<CHIP>(ctx, cs, FD_CCU_CLEAN_DEPTH);
25
26 if (flushes & FD6_INVALIDATE_CCU_COLOR)
27 fd6_event_write<CHIP>(ctx, cs, FD_CCU_INVALIDATE_COLOR);
28
29 if (flushes & FD6_INVALIDATE_CCU_DEPTH)
30 fd6_event_write<CHIP>(ctx, cs, FD_CCU_INVALIDATE_DEPTH);
31
32 if (flushes & FD6_FLUSH_CACHE)
33 fd6_event_write<CHIP>(ctx, cs, FD_CACHE_CLEAN);
34
35 if (flushes & FD6_INVALIDATE_CACHE)
36 fd6_event_write<CHIP>(ctx, cs, FD_CACHE_INVALIDATE);
37
38 if ((CHIP >= A7XX) && (flushes & FD6_BLIT_CLEAN_CACHE))
39 fd6_event_write<CHIP>(ctx, cs, FD_CCU_CLEAN_BLIT_CACHE);
40
41 if ((CHIP >= A7XX) && (flushes & FD6_INVALIDATE_CCHE))
42 fd_pkt7(cs, CP_CCHE_INVALIDATE, 0);
43
44 if (flushes & FD6_WAIT_MEM_WRITES)
45 fd_pkt7(cs, CP_WAIT_MEM_WRITES, 0);
46
47 if (flushes & FD6_WAIT_FOR_IDLE)
48 fd_pkt7(cs, CP_WAIT_FOR_IDLE, 0);
49
50 if (flushes & FD6_WAIT_FOR_ME)
51 fd_pkt7(cs, CP_WAIT_FOR_ME, 0);
52 }
53 FD_GENX(fd6_emit_flushes);
54
55 static void
56 add_flushes(struct pipe_context *pctx, unsigned flushes)
57 assert_dt
58 {
59 struct fd_context *ctx = fd_context(pctx);
60 struct fd_batch *batch = NULL;
61
62 DBG("flushes=0x%x", flushes);
63
64 /* If there is an active compute/nondraw batch, that is the one
65 * we want to add the flushes to. Ie. last op was a launch_grid,
66 * if the next one is a launch_grid then the barriers should come
67 * between them. If the next op is a draw_vbo then the batch
68 * switch is a sufficient barrier so it doesn't really matter.
69 */
70 fd_batch_reference(&batch, ctx->batch_nondraw);
71 if (!batch)
72 fd_batch_reference(&batch, ctx->batch);
73
74 /* A batch flush is already a sufficient barrier: */
75 if (!batch)
76 return;
77
78 batch->barrier |= flushes;
79
80 fd_batch_reference(&batch, NULL);
81 }
82
83 static void
84 fd6_texture_barrier(struct pipe_context *pctx, unsigned flags)
85 in_dt
86 {
87 unsigned flushes = 0;
88
89 DBG("flags=0x%x", flags);
90
91 if (flags & PIPE_TEXTURE_BARRIER_SAMPLER) {
92 /* If we are sampling from the fb, we could get away with treating
93 * this as a PIPE_TEXTURE_BARRIER_FRAMEBUFFER in sysmem mode, but
94 * that won't work out in gmem mode because we don't patch the tex
95 * state outside of the case that the frag shader tells us it is
96 * an fb-read. And in particular, the fb-read case guarantees us
97 * that the read will be from the same texel, but the fb-bound-as-
98 * tex case does not.
99 *
100 * We could try to be clever here and detect if zsbuf/cbuf[n] is
101 * bound as a texture, but that doesn't really help if it is bound
102 * as a texture after the barrier without a lot of extra book-
103 * keeping. So hopefully no one calls glTextureBarrierNV() just
104 * for lolz.
105 */
106 pctx->flush(pctx, NULL, 0);
107 return;
108 }
109
110 if (flags & PIPE_TEXTURE_BARRIER_FRAMEBUFFER) {
111 flushes |= FD6_WAIT_FOR_IDLE | FD6_WAIT_FOR_ME |
112 FD6_FLUSH_CCU_COLOR | FD6_FLUSH_CCU_DEPTH |
113 FD6_FLUSH_CACHE | FD6_INVALIDATE_CACHE;
114 }
115
116 add_flushes(pctx, flushes);
117 }
118
119 static void
120 fd6_memory_barrier(struct pipe_context *pctx, unsigned flags)
121 in_dt
122 {
123 unsigned flushes = 0;
124
125 DBG("flags=0x%x", flags);
126
127 if (flags & (PIPE_BARRIER_SHADER_BUFFER |
128 PIPE_BARRIER_CONSTANT_BUFFER |
129 PIPE_BARRIER_VERTEX_BUFFER |
130 PIPE_BARRIER_INDEX_BUFFER |
131 PIPE_BARRIER_STREAMOUT_BUFFER)) {
132 flushes |= FD6_WAIT_FOR_IDLE;
133 }
134
135 if (flags & (PIPE_BARRIER_TEXTURE |
136 PIPE_BARRIER_IMAGE |
137 PIPE_BARRIER_UPDATE_BUFFER |
138 PIPE_BARRIER_UPDATE_TEXTURE)) {
139 flushes |= FD6_FLUSH_CACHE | FD6_WAIT_FOR_IDLE;
140 }
141
142 if (flags & PIPE_BARRIER_INDIRECT_BUFFER) {
143 flushes |= FD6_FLUSH_CACHE | FD6_WAIT_FOR_IDLE;
144
145 /* Various firmware bugs/inconsistencies mean that some indirect draw opcodes
146 * do not wait for WFI's to complete before executing. Add a WAIT_FOR_ME if
147 * pending for these opcodes. This may result in a few extra WAIT_FOR_ME's
148 * with these opcodes, but the alternative would add unnecessary WAIT_FOR_ME's
149 * before draw opcodes that don't need it.
150 */
151 if (fd_context(pctx)->screen->info->props.indirect_draw_wfm_quirk) {
152 flushes |= FD6_WAIT_FOR_ME;
153 }
154 }
155
156 if (flags & PIPE_BARRIER_FRAMEBUFFER) {
157 fd6_texture_barrier(pctx, PIPE_TEXTURE_BARRIER_FRAMEBUFFER);
158 }
159
160 add_flushes(pctx, flushes);
161 }
162
163 void
164 fd6_barrier_init(struct pipe_context *pctx)
165 {
166 pctx->texture_barrier = fd6_texture_barrier;
167 pctx->memory_barrier = fd6_memory_barrier;
168 }