freedreno: gallium driver for adreno
[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_blend_stateobj;
41 struct fd_rasterizer_stateobj;
42 struct fd_zsa_stateobj;
43 struct fd_sampler_stateobj;
44 struct fd_vertex_stateobj;
45 struct fd_shader_stateobj;
46
47 struct fd_texture_stateobj {
48 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
49 unsigned num_textures;
50 struct fd_sampler_stateobj *samplers[PIPE_MAX_SAMPLERS];
51 unsigned num_samplers;
52 unsigned dirty_samplers;
53 };
54
55 struct fd_program_stateobj {
56 struct fd_shader_stateobj *vp, *fp;
57 enum {
58 FD_SHADER_DIRTY_VP = (1 << 0),
59 FD_SHADER_DIRTY_FP = (1 << 1),
60 } dirty;
61 uint8_t num_exports;
62 /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
63 * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point-
64 * size) are not included in this
65 */
66 uint8_t export_linkage[63];
67 };
68
69 struct fd_constbuf_stateobj {
70 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
71 uint32_t enabled_mask;
72 uint32_t dirty_mask;
73 };
74
75 struct fd_vertexbuf_stateobj {
76 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
77 unsigned count;
78 uint32_t enabled_mask;
79 uint32_t dirty_mask;
80 };
81
82 struct fd_framebuffer_stateobj {
83 struct pipe_framebuffer_state base;
84 uint16_t bin_h, nbins_y;
85 uint16_t bin_w, nbins_x;
86 uint32_t pa_su_sc_mode_cntl;
87 };
88
89 struct fd_context {
90 struct pipe_context base;
91
92 struct fd_screen *screen;
93 struct blitter_context *blitter;
94
95 struct util_slab_mempool transfer_pool;
96
97 /* shaders used by clear, and gmem->mem blits: */
98 struct fd_program_stateobj solid_prog; // TODO move to screen?
99
100 /* shaders used by mem->gmem blits: */
101 struct fd_program_stateobj blit_prog; // TODO move to screen?
102
103 /* vertex buff used for clear/gmem->mem vertices, and mem->gmem
104 * vertices and tex coords:
105 */
106 struct pipe_resource *solid_vertexbuf;
107
108 /* do we need to mem2gmem before rendering. We don't, if for example,
109 * there was a glClear() that invalidated the entire previous buffer
110 * contents. Keep track of which buffer(s) are cleared, or needs
111 * restore. Masks of PIPE_CLEAR_*
112 */
113 enum {
114 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
115 FD_BUFFER_COLOR = PIPE_CLEAR_COLOR,
116 FD_BUFFER_DEPTH = PIPE_CLEAR_DEPTH,
117 FD_BUFFER_STENCIL = PIPE_CLEAR_STENCIL,
118 FD_BUFFER_ALL = FD_BUFFER_COLOR | FD_BUFFER_DEPTH | FD_BUFFER_STENCIL,
119 } cleared, restore, resolve;
120
121 bool needs_flush;
122
123 struct fd_ringbuffer *ring;
124 struct fd_ringmarker *draw_start, *draw_end;
125
126 /* scissor can't really be changed mid-render.. we probably need
127 * to flush out all pending draws and then start a new tile pass
128 * w/ new stencil state..
129 */
130 struct pipe_scissor_state scissor;
131
132 /* which state objects need to be re-emit'd: */
133 enum {
134 FD_DIRTY_BLEND = (1 << 0),
135 FD_DIRTY_RASTERIZER = (1 << 1),
136 FD_DIRTY_ZSA = (1 << 2),
137 FD_DIRTY_FRAGTEX = (1 << 3),
138 FD_DIRTY_VERTTEX = (1 << 4),
139 FD_DIRTY_PROG = (1 << 5),
140 FD_DIRTY_VTX = (1 << 6),
141 FD_DIRTY_BLEND_COLOR = (1 << 7),
142 FD_DIRTY_STENCIL_REF = (1 << 8),
143 FD_DIRTY_SAMPLE_MASK = (1 << 9),
144 FD_DIRTY_FRAMEBUFFER = (1 << 10),
145 FD_DIRTY_STIPPLE = (1 << 12),
146 FD_DIRTY_VIEWPORT = (1 << 12),
147 FD_DIRTY_CONSTBUF = (1 << 13),
148 FD_DIRTY_VERTEXBUF = (1 << 14),
149 FD_DIRTY_INDEXBUF = (1 << 15),
150 FD_DIRTY_SCISSOR = (1 << 16),
151 } dirty;
152
153 struct fd_blend_stateobj *blend;
154 struct fd_rasterizer_stateobj *rasterizer;
155 struct fd_zsa_stateobj *zsa;
156
157 struct fd_texture_stateobj verttex, fragtex;
158
159 struct fd_program_stateobj prog;
160
161 struct fd_vertex_stateobj *vtx;
162
163 struct pipe_blend_color blend_color;
164 struct pipe_stencil_ref stencil_ref;
165 unsigned sample_mask;
166 struct fd_framebuffer_stateobj framebuffer;
167 struct pipe_poly_stipple stipple;
168 struct pipe_viewport_state viewport;
169 struct fd_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
170 struct fd_vertexbuf_stateobj vertexbuf;
171 struct pipe_index_buffer indexbuf;
172 };
173
174 static INLINE struct fd_context *
175 fd_context(struct pipe_context *pctx)
176 {
177 return (struct fd_context *)pctx;
178 }
179
180 struct pipe_context * fd_context_create(struct pipe_screen *pscreen, void *priv);
181
182 void fd_context_render(struct pipe_context *pctx);
183
184 #endif /* FREEDRENO_CONTEXT_H_ */