2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Rob Clark <robclark@freedesktop.org>
31 #include "pipe/p_context.h"
33 #include "freedreno_context.h"
34 #include "fd6_context.h"
35 #include "fd6_format.h"
36 #include "fd6_program.h"
37 #include "ir3_shader.h"
41 /* To collect all the state objects to emit in a single CP_SET_DRAW_STATE
42 * packet, the emit tracks a collection of however many state_group's that
47 FD6_GROUP_PROG_BINNING
,
49 FD6_GROUP_LRZ_BINNING
,
51 FD6_GROUP_VBO_BINNING
,
60 struct fd6_state_group
{
61 struct fd_ringbuffer
*stateobj
;
62 enum fd6_state_id group_id
;
66 /* grouped together emit-state for prog/vertex/state emit: */
68 struct fd_context
*ctx
;
69 const struct fd_vertex_state
*vtx
;
70 const struct pipe_draw_info
*info
;
71 struct ir3_cache_key key
;
72 enum fd_dirty_3d_state dirty
;
74 uint32_t sprite_coord_enable
; /* bitmask */
75 bool sprite_coord_mode
;
79 /* in binning pass, we don't have real frag shader, so we
80 * don't know if real draw disqualifies lrz write. So just
81 * figure that out up-front and stash it in the emit.
85 /* cached to avoid repeated lookups: */
86 const struct fd6_program_state
*prog
;
88 struct ir3_shader_variant
*bs
;
89 struct ir3_shader_variant
*vs
;
90 struct ir3_shader_variant
*fs
;
92 unsigned streamout_mask
;
94 struct fd6_state_group groups
[32];
98 static inline const struct fd6_program_state
*
99 fd6_emit_get_prog(struct fd6_emit
*emit
)
102 struct fd6_context
*fd6_ctx
= fd6_context(emit
->ctx
);
103 struct ir3_program_state
*s
=
104 ir3_cache_lookup(fd6_ctx
->shader_cache
, &emit
->key
, &emit
->ctx
->debug
);
105 emit
->prog
= fd6_program_state(s
);
111 fd6_emit_add_group(struct fd6_emit
*emit
, struct fd_ringbuffer
*stateobj
,
112 enum fd6_state_id group_id
, unsigned enable_mask
)
114 debug_assert(emit
->num_groups
< ARRAY_SIZE(emit
->groups
));
115 struct fd6_state_group
*g
= &emit
->groups
[emit
->num_groups
++];
116 g
->stateobj
= fd_ringbuffer_ref(stateobj
);
117 g
->group_id
= group_id
;
118 g
->enable_mask
= enable_mask
;
122 fd6_event_write(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
,
123 enum vgt_event_type evt
, bool timestamp
)
127 OUT_PKT7(ring
, CP_EVENT_WRITE
, timestamp
? 4 : 1);
128 OUT_RING(ring
, CP_EVENT_WRITE_0_EVENT(evt
));
130 struct fd6_context
*fd6_ctx
= fd6_context(batch
->ctx
);
131 OUT_RELOCW(ring
, fd6_ctx
->blit_mem
, 0, 0, 0); /* ADDR_LO/HI */
132 OUT_RING(ring
, ++fd6_ctx
->seqno
);
137 fd6_cache_flush(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
139 fd6_event_write(batch
, ring
, 0x31, false);
143 fd6_emit_blit(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
145 emit_marker6(ring
, 7);
146 fd6_event_write(batch
, ring
, BLIT
, false);
147 emit_marker6(ring
, 7);
151 fd6_emit_lrz_flush(struct fd_ringbuffer
*ring
)
153 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
154 OUT_RING(ring
, LRZ_FLUSH
);
157 static inline enum a6xx_state_block
158 fd6_stage2shadersb(enum shader_t type
)
162 return SB6_VS_SHADER
;
163 case SHADER_FRAGMENT
:
164 return SB6_FS_SHADER
;
166 return SB6_CS_SHADER
;
168 unreachable("bad shader type");
173 bool fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
174 enum a6xx_state_block sb
, struct fd_texture_stateobj
*tex
,
175 unsigned bcolor_offset
);
177 void fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
);
179 void fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
180 struct ir3_shader_variant
*cp
);
182 void fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
);
184 void fd6_emit_init(struct pipe_context
*pctx
);
187 fd6_emit_ib(struct fd_ringbuffer
*ring
, struct fd_ringbuffer
*target
)
189 emit_marker6(ring
, 6);
190 __OUT_IB5(ring
, target
);
191 emit_marker6(ring
, 6);
194 #define WRITE(reg, val) do { \
195 OUT_PKT4(ring, reg, 1); \
196 OUT_RING(ring, val); \
200 #endif /* FD6_EMIT_H */