radeonsi: update surface sync packet emit for CIK
[mesa.git] / src / gallium / drivers / freedreno / freedreno_context.h
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #ifndef FREEDRENO_CONTEXT_H_
30 #define FREEDRENO_CONTEXT_H_
31
32 #include "draw/draw_context.h"
33 #include "pipe/p_context.h"
34 #include "util/u_blitter.h"
35 #include "util/u_slab.h"
36 #include "util/u_string.h"
37
38 #include "freedreno_screen.h"
39
40 struct fd_vertex_stateobj;
41
42 struct fd_texture_stateobj {
43 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
44 unsigned num_textures;
45 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
46 unsigned num_samplers;
47 unsigned dirty_samplers;
48 };
49
50 struct fd_program_stateobj {
51 void *vp, *fp;
52 enum {
53 FD_SHADER_DIRTY_VP = (1 << 0),
54 FD_SHADER_DIRTY_FP = (1 << 1),
55 } dirty;
56 uint8_t num_exports;
57 /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
58 * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point-
59 * size) are not included in this
60 */
61 uint8_t export_linkage[63];
62 };
63
64 struct fd_constbuf_stateobj {
65 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
66 uint32_t enabled_mask;
67 uint32_t dirty_mask;
68 };
69
70 struct fd_vertexbuf_stateobj {
71 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
72 unsigned count;
73 uint32_t enabled_mask;
74 uint32_t dirty_mask;
75 };
76
77 struct fd_vertex_stateobj {
78 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
79 unsigned num_elements;
80 };
81
82 struct fd_gmem_stateobj {
83 struct pipe_scissor_state scissor;
84 uint cpp;
85 uint16_t minx, miny;
86 uint16_t bin_h, nbins_y;
87 uint16_t bin_w, nbins_x;
88 uint16_t width, height;
89 };
90
91 struct fd_context {
92 struct pipe_context base;
93
94 struct fd_screen *screen;
95 struct blitter_context *blitter;
96
97 struct util_slab_mempool transfer_pool;
98
99 /* shaders used by clear, and gmem->mem blits: */
100 struct fd_program_stateobj solid_prog; // TODO move to screen?
101
102 /* shaders used by mem->gmem blits: */
103 struct fd_program_stateobj blit_prog; // TODO move to screen?
104
105 /* do we need to mem2gmem before rendering. We don't, if for example,
106 * there was a glClear() that invalidated the entire previous buffer
107 * contents. Keep track of which buffer(s) are cleared, or needs
108 * restore. Masks of PIPE_CLEAR_*
109 */
110 enum {
111 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
112 FD_BUFFER_COLOR = PIPE_CLEAR_COLOR,
113 FD_BUFFER_DEPTH = PIPE_CLEAR_DEPTH,
114 FD_BUFFER_STENCIL = PIPE_CLEAR_STENCIL,
115 FD_BUFFER_ALL = FD_BUFFER_COLOR | FD_BUFFER_DEPTH | FD_BUFFER_STENCIL,
116 } cleared, restore, resolve;
117
118 bool needs_flush;
119
120 /* To decide whether to render to system memory, keep track of the
121 * number of draws, and whether any of them require multisample,
122 * depth_test (or depth write), stencil_test, blending, and
123 * color_logic_Op (since those functions are disabled when by-
124 * passing GMEM.
125 */
126 enum {
127 FD_GMEM_CLEARS_DEPTH_STENCIL = 0x01,
128 FD_GMEM_DEPTH_ENABLED = 0x02,
129 FD_GMEM_STENCIL_ENABLED = 0x04,
130
131 FD_GMEM_MSAA_ENABLED = 0x08,
132 FD_GMEM_BLEND_ENABLED = 0x10,
133 FD_GMEM_LOGICOP_ENABLED = 0x20,
134 } gmem_reason;
135 unsigned num_draws;
136
137 struct fd_ringbuffer *ring;
138 struct fd_ringmarker *draw_start, *draw_end;
139
140 struct pipe_scissor_state scissor;
141
142 /* we don't have a disable/enable bit for scissor, so instead we keep
143 * a disabled-scissor state which matches the entire bound framebuffer
144 * and use that when scissor is not enabled.
145 */
146 struct pipe_scissor_state disabled_scissor;
147
148 /* Track the maximal bounds of the scissor of all the draws within a
149 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
150 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
151 */
152 struct pipe_scissor_state max_scissor;
153
154 /* Current gmem/tiling configuration.. gets updated on render_tiles()
155 * if out of date with current maximal-scissor/cpp:
156 */
157 struct fd_gmem_stateobj gmem;
158
159 /* which state objects need to be re-emit'd: */
160 enum {
161 FD_DIRTY_BLEND = (1 << 0),
162 FD_DIRTY_RASTERIZER = (1 << 1),
163 FD_DIRTY_ZSA = (1 << 2),
164 FD_DIRTY_FRAGTEX = (1 << 3),
165 FD_DIRTY_VERTTEX = (1 << 4),
166 FD_DIRTY_TEXSTATE = (1 << 5),
167 FD_DIRTY_PROG = (1 << 6),
168 FD_DIRTY_BLEND_COLOR = (1 << 7),
169 FD_DIRTY_STENCIL_REF = (1 << 8),
170 FD_DIRTY_SAMPLE_MASK = (1 << 9),
171 FD_DIRTY_FRAMEBUFFER = (1 << 10),
172 FD_DIRTY_STIPPLE = (1 << 11),
173 FD_DIRTY_VIEWPORT = (1 << 12),
174 FD_DIRTY_CONSTBUF = (1 << 13),
175 FD_DIRTY_VTXSTATE = (1 << 14),
176 FD_DIRTY_VTXBUF = (1 << 15),
177 FD_DIRTY_INDEXBUF = (1 << 16),
178 FD_DIRTY_SCISSOR = (1 << 17),
179 } dirty;
180
181 struct pipe_blend_state *blend;
182 struct pipe_rasterizer_state *rasterizer;
183 struct pipe_depth_stencil_alpha_state *zsa;
184
185 struct fd_texture_stateobj verttex, fragtex;
186
187 struct fd_program_stateobj prog;
188
189 struct fd_vertex_stateobj *vtx;
190
191 struct pipe_blend_color blend_color;
192 struct pipe_stencil_ref stencil_ref;
193 unsigned sample_mask;
194 struct pipe_framebuffer_state framebuffer;
195 struct pipe_poly_stipple stipple;
196 struct pipe_viewport_state viewport;
197 struct fd_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
198 struct fd_vertexbuf_stateobj vertexbuf;
199 struct pipe_index_buffer indexbuf;
200
201 /* GMEM/tile handling fxns: */
202 void (*emit_tile_init)(struct fd_context *ctx);
203 void (*emit_tile_prep)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
204 uint32_t bin_w, uint32_t bin_h);
205 void (*emit_tile_mem2gmem)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
206 uint32_t bin_w, uint32_t bin_h);
207 void (*emit_tile_renderprep)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
208 uint32_t bin_w, uint32_t bin_h);
209 void (*emit_tile_gmem2mem)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
210 uint32_t bin_w, uint32_t bin_h);
211
212 /* optional, for GMEM bypass: */
213 void (*emit_sysmem_prep)(struct fd_context *ctx);
214
215 /* draw: */
216 void (*draw)(struct fd_context *pctx, const struct pipe_draw_info *info);
217 void (*clear)(struct fd_context *ctx, unsigned buffers,
218 const union pipe_color_union *color, double depth, unsigned stencil);
219 };
220
221 static INLINE struct fd_context *
222 fd_context(struct pipe_context *pctx)
223 {
224 return (struct fd_context *)pctx;
225 }
226
227 static INLINE struct pipe_scissor_state *
228 fd_context_get_scissor(struct fd_context *ctx)
229 {
230 if (ctx->rasterizer && ctx->rasterizer->scissor)
231 return &ctx->scissor;
232 return &ctx->disabled_scissor;
233 }
234
235 struct pipe_context * fd_context_init(struct fd_context *ctx,
236 struct pipe_screen *pscreen, void *priv);
237
238 void fd_context_render(struct pipe_context *pctx);
239
240 void fd_context_destroy(struct pipe_context *pctx);
241
242 #endif /* FREEDRENO_CONTEXT_H_ */