xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a3xx/fd3_emit.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2013 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  */
8 
9 #ifndef FD3_EMIT_H
10 #define FD3_EMIT_H
11 
12 #include "pipe/p_context.h"
13 
14 #include "fd3_format.h"
15 #include "fd3_program.h"
16 #include "freedreno_batch.h"
17 #include "freedreno_context.h"
18 #include "ir3_cache.h"
19 #include "ir3_gallium.h"
20 
21 struct fd_ringbuffer;
22 
23 void fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring,
24                                struct pipe_surface **psurf, int bufs);
25 
26 /* grouped together emit-state for prog/vertex/state emit: */
27 struct fd3_emit {
28    struct util_debug_callback *debug;
29    const struct fd_vertex_state *vtx;
30    const struct fd3_program_state *prog;
31    const struct pipe_draw_info *info;
32 	unsigned drawid_offset;
33    const struct pipe_draw_indirect_info *indirect;
34 	const struct pipe_draw_start_count_bias *draw;
35    bool binning_pass;
36    struct ir3_cache_key key;
37    enum fd_dirty_3d_state dirty;
38 
39    uint32_t sprite_coord_enable;
40    bool sprite_coord_mode;
41    bool rasterflat;
42    bool skip_consts;
43 
44    /* cached to avoid repeated lookups of same variants: */
45    const struct ir3_shader_variant *vs, *fs;
46 };
47 
48 static inline const struct ir3_shader_variant *
fd3_emit_get_vp(struct fd3_emit * emit)49 fd3_emit_get_vp(struct fd3_emit *emit)
50 {
51    if (!emit->vs) {
52       emit->vs = emit->binning_pass ? emit->prog->bs : emit->prog->vs;
53    }
54    return emit->vs;
55 }
56 
57 static inline const struct ir3_shader_variant *
fd3_emit_get_fp(struct fd3_emit * emit)58 fd3_emit_get_fp(struct fd3_emit *emit)
59 {
60    if (!emit->fs) {
61       if (emit->binning_pass) {
62          /* use dummy stateobj to simplify binning vs non-binning: */
63          static const struct ir3_shader_variant binning_fs = {};
64          emit->fs = &binning_fs;
65       } else {
66          emit->fs = emit->prog->fs;
67       }
68    }
69    return emit->fs;
70 }
71 
72 void fd3_emit_vertex_bufs(struct fd_ringbuffer *ring,
73                           struct fd3_emit *emit) assert_dt;
74 
75 void fd3_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
76                     struct fd3_emit *emit) assert_dt;
77 
78 void fd3_emit_restore(struct fd_batch *batch,
79                       struct fd_ringbuffer *ring) assert_dt;
80 
81 void fd3_emit_init_screen(struct pipe_screen *pscreen);
82 void fd3_emit_init(struct pipe_context *pctx);
83 
84 static inline void
fd3_emit_ib(struct fd_ringbuffer * ring,struct fd_ringbuffer * target)85 fd3_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target)
86 {
87    __OUT_IB(ring, true, target);
88 }
89 
90 static inline void
fd3_emit_cache_flush(struct fd_batch * batch,struct fd_ringbuffer * ring)91 fd3_emit_cache_flush(struct fd_batch *batch,
92                      struct fd_ringbuffer *ring) assert_dt
93 {
94    fd_wfi(batch, ring);
95    OUT_PKT0(ring, REG_A3XX_UCHE_CACHE_INVALIDATE0_REG, 2);
96    OUT_RING(ring, A3XX_UCHE_CACHE_INVALIDATE0_REG_ADDR(0));
97    OUT_RING(ring, A3XX_UCHE_CACHE_INVALIDATE1_REG_ADDR(0) |
98                      A3XX_UCHE_CACHE_INVALIDATE1_REG_OPCODE(INVALIDATE) |
99                      A3XX_UCHE_CACHE_INVALIDATE1_REG_ENTIRE_CACHE);
100 }
101 
102 #endif /* FD3_EMIT_H */
103