1 /*
2 * Copyright (C) 2013 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 FD3_EMIT_H
28 #define FD3_EMIT_H
29
30 #include "pipe/p_context.h"
31
32 #include "fd3_format.h"
33 #include "fd3_program.h"
34 #include "freedreno_batch.h"
35 #include "freedreno_context.h"
36 #include "ir3_cache.h"
37 #include "ir3_gallium.h"
38
39 struct fd_ringbuffer;
40
41 void fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring,
42 struct pipe_surface **psurf, int bufs);
43
44 /* grouped together emit-state for prog/vertex/state emit: */
45 struct fd3_emit {
46 struct util_debug_callback *debug;
47 const struct fd_vertex_state *vtx;
48 const struct fd3_program_state *prog;
49 const struct pipe_draw_info *info;
50 unsigned drawid_offset;
51 const struct pipe_draw_indirect_info *indirect;
52 const struct pipe_draw_start_count_bias *draw;
53 bool binning_pass;
54 struct ir3_cache_key key;
55 enum fd_dirty_3d_state dirty;
56
57 uint32_t sprite_coord_enable;
58 bool sprite_coord_mode;
59 bool rasterflat;
60 bool skip_consts;
61
62 /* cached to avoid repeated lookups of same variants: */
63 const struct ir3_shader_variant *vs, *fs;
64 };
65
66 static inline const struct ir3_shader_variant *
fd3_emit_get_vp(struct fd3_emit * emit)67 fd3_emit_get_vp(struct fd3_emit *emit)
68 {
69 if (!emit->vs) {
70 emit->vs = emit->binning_pass ? emit->prog->bs : emit->prog->vs;
71 }
72 return emit->vs;
73 }
74
75 static inline const struct ir3_shader_variant *
fd3_emit_get_fp(struct fd3_emit * emit)76 fd3_emit_get_fp(struct fd3_emit *emit)
77 {
78 if (!emit->fs) {
79 if (emit->binning_pass) {
80 /* use dummy stateobj to simplify binning vs non-binning: */
81 static const struct ir3_shader_variant binning_fs = {};
82 emit->fs = &binning_fs;
83 } else {
84 emit->fs = emit->prog->fs;
85 }
86 }
87 return emit->fs;
88 }
89
90 void fd3_emit_vertex_bufs(struct fd_ringbuffer *ring,
91 struct fd3_emit *emit) assert_dt;
92
93 void fd3_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
94 struct fd3_emit *emit) assert_dt;
95
96 void fd3_emit_restore(struct fd_batch *batch,
97 struct fd_ringbuffer *ring) assert_dt;
98
99 void fd3_emit_init_screen(struct pipe_screen *pscreen);
100 void fd3_emit_init(struct pipe_context *pctx);
101
102 static inline void
fd3_emit_ib(struct fd_ringbuffer * ring,struct fd_ringbuffer * target)103 fd3_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target)
104 {
105 __OUT_IB(ring, true, target);
106 }
107
108 static inline void
fd3_emit_cache_flush(struct fd_batch * batch,struct fd_ringbuffer * ring)109 fd3_emit_cache_flush(struct fd_batch *batch,
110 struct fd_ringbuffer *ring) assert_dt
111 {
112 fd_wfi(batch, ring);
113 OUT_PKT0(ring, REG_A3XX_UCHE_CACHE_INVALIDATE0_REG, 2);
114 OUT_RING(ring, A3XX_UCHE_CACHE_INVALIDATE0_REG_ADDR(0));
115 OUT_RING(ring, A3XX_UCHE_CACHE_INVALIDATE1_REG_ADDR(0) |
116 A3XX_UCHE_CACHE_INVALIDATE1_REG_OPCODE(INVALIDATE) |
117 A3XX_UCHE_CACHE_INVALIDATE1_REG_ENTIRE_CACHE);
118 }
119
120 #endif /* FD3_EMIT_H */
121