freedreno: prepare for a3xx
[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 struct fd_ringbuffer *ring;
121 struct fd_ringmarker *draw_start, *draw_end;
122
123 struct pipe_scissor_state scissor;
124
125 /* Track the maximal bounds of the scissor of all the draws within a
126 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
127 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
128 */
129 struct pipe_scissor_state max_scissor;
130
131 /* Current gmem/tiling configuration.. gets updated on render_tiles()
132 * if out of date with current maximal-scissor/cpp:
133 */
134 struct fd_gmem_stateobj gmem;
135
136 /* which state objects need to be re-emit'd: */
137 enum {
138 FD_DIRTY_BLEND = (1 << 0),
139 FD_DIRTY_RASTERIZER = (1 << 1),
140 FD_DIRTY_ZSA = (1 << 2),
141 FD_DIRTY_FRAGTEX = (1 << 3),
142 FD_DIRTY_VERTTEX = (1 << 4),
143 FD_DIRTY_TEXSTATE = (1 << 5),
144 FD_DIRTY_PROG = (1 << 6),
145 FD_DIRTY_BLEND_COLOR = (1 << 7),
146 FD_DIRTY_STENCIL_REF = (1 << 8),
147 FD_DIRTY_SAMPLE_MASK = (1 << 9),
148 FD_DIRTY_FRAMEBUFFER = (1 << 10),
149 FD_DIRTY_STIPPLE = (1 << 11),
150 FD_DIRTY_VIEWPORT = (1 << 12),
151 FD_DIRTY_CONSTBUF = (1 << 13),
152 FD_DIRTY_VTXSTATE = (1 << 14),
153 FD_DIRTY_VTXBUF = (1 << 15),
154 FD_DIRTY_INDEXBUF = (1 << 16),
155 FD_DIRTY_SCISSOR = (1 << 17),
156 } dirty;
157
158 struct pipe_blend_state *blend;
159 struct pipe_rasterizer_state *rasterizer;
160 struct pipe_depth_stencil_alpha_state *zsa;
161
162 struct fd_texture_stateobj verttex, fragtex;
163
164 struct fd_program_stateobj prog;
165
166 struct fd_vertex_stateobj *vtx;
167
168 struct pipe_blend_color blend_color;
169 struct pipe_stencil_ref stencil_ref;
170 unsigned sample_mask;
171 struct pipe_framebuffer_state framebuffer;
172 struct pipe_poly_stipple stipple;
173 struct pipe_viewport_state viewport;
174 struct fd_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
175 struct fd_vertexbuf_stateobj vertexbuf;
176 struct pipe_index_buffer indexbuf;
177
178 /* GMEM/tile handling fxns: */
179 void (*emit_tile_init)(struct fd_context *ctx);
180 void (*emit_tile_prep)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
181 uint32_t bin_w, uint32_t bin_h);
182 void (*emit_tile_mem2gmem)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
183 uint32_t bin_w, uint32_t bin_h);
184 void (*emit_tile_renderprep)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
185 uint32_t bin_w, uint32_t bin_h);
186 void (*emit_tile_gmem2mem)(struct fd_context *ctx, uint32_t xoff, uint32_t yoff,
187 uint32_t bin_w, uint32_t bin_h);
188
189 /* draw: */
190 void (*draw)(struct fd_context *pctx, const struct pipe_draw_info *info);
191 void (*clear)(struct fd_context *ctx, unsigned buffers,
192 const union pipe_color_union *color, double depth, unsigned stencil);
193 };
194
195 static INLINE struct fd_context *
196 fd_context(struct pipe_context *pctx)
197 {
198 return (struct fd_context *)pctx;
199 }
200
201 struct pipe_context * fd_context_init(struct fd_context *ctx,
202 struct pipe_screen *pscreen, void *priv);
203
204 void fd_context_render(struct pipe_context *pctx);
205
206 void fd_context_destroy(struct pipe_context *pctx);
207
208 #endif /* FREEDRENO_CONTEXT_H_ */