vc4: Fill out the stencil clear field.
[mesa.git] / src / gallium / drivers / vc4 / vc4_context.h
1 /*
2 * Copyright © 2014 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4 *
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:
11 *
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
14 * Software.
15 *
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
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #ifndef VC4_CONTEXT_H
26 #define VC4_CONTEXT_H
27
28 #include <stdio.h>
29
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32 #include "util/u_slab.h"
33
34 #define __user
35 #include "vc4_drm.h"
36 #include "vc4_bufmgr.h"
37 #include "vc4_resource.h"
38 #include "vc4_cl.h"
39 #include "vc4_qir.h"
40
41 #define VC4_DIRTY_BLEND (1 << 0)
42 #define VC4_DIRTY_RASTERIZER (1 << 1)
43 #define VC4_DIRTY_ZSA (1 << 2)
44 #define VC4_DIRTY_FRAGTEX (1 << 3)
45 #define VC4_DIRTY_VERTTEX (1 << 4)
46 #define VC4_DIRTY_TEXSTATE (1 << 5)
47 #define VC4_DIRTY_PROG (1 << 6)
48 #define VC4_DIRTY_BLEND_COLOR (1 << 7)
49 #define VC4_DIRTY_STENCIL_REF (1 << 8)
50 #define VC4_DIRTY_SAMPLE_MASK (1 << 9)
51 #define VC4_DIRTY_FRAMEBUFFER (1 << 10)
52 #define VC4_DIRTY_STIPPLE (1 << 11)
53 #define VC4_DIRTY_VIEWPORT (1 << 12)
54 #define VC4_DIRTY_CONSTBUF (1 << 13)
55 #define VC4_DIRTY_VTXSTATE (1 << 14)
56 #define VC4_DIRTY_VTXBUF (1 << 15)
57 #define VC4_DIRTY_INDEXBUF (1 << 16)
58 #define VC4_DIRTY_SCISSOR (1 << 17)
59
60 #define VC4_SHADER_DIRTY_VP (1 << 0)
61 #define VC4_SHADER_DIRTY_FP (1 << 1)
62
63 struct vc4_texture_stateobj {
64 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
65 unsigned num_textures;
66 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
67 unsigned num_samplers;
68 unsigned dirty_samplers;
69 };
70
71 struct vc4_shader_uniform_info {
72 enum quniform_contents *contents;
73 uint32_t *data;
74 uint32_t count;
75 uint32_t num_texture_samples;
76 };
77
78 struct vc4_compiled_shader {
79 struct vc4_bo *bo;
80
81 struct vc4_shader_uniform_info uniforms[2];
82
83 uint32_t coord_shader_offset;
84 uint8_t num_inputs;
85 };
86
87 struct vc4_program_stateobj {
88 struct pipe_shader_state *bind_vs, *bind_fs;
89 struct vc4_compiled_shader *vs, *fs;
90 uint32_t dirty;
91 uint8_t num_exports;
92 /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
93 * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point-
94 * size) are not included in this
95 */
96 uint8_t export_linkage[63];
97 };
98
99 struct vc4_constbuf_stateobj {
100 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
101 uint32_t enabled_mask;
102 uint32_t dirty_mask;
103 };
104
105 struct vc4_vertexbuf_stateobj {
106 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
107 unsigned count;
108 uint32_t enabled_mask;
109 uint32_t dirty_mask;
110 };
111
112 struct vc4_vertex_stateobj {
113 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
114 unsigned num_elements;
115 };
116
117 struct vc4_context {
118 struct pipe_context base;
119
120 int fd;
121 struct vc4_screen *screen;
122
123 struct vc4_cl bcl;
124 struct vc4_cl rcl;
125 struct vc4_cl shader_rec;
126 struct vc4_cl uniforms;
127 struct vc4_cl bo_handles;
128 struct vc4_cl bo_pointers;
129 uint32_t shader_rec_count;
130
131 struct vc4_bo *tile_alloc;
132 struct vc4_bo *tile_state;
133
134 struct util_slab_mempool transfer_pool;
135 struct blitter_context *blitter;
136
137 /** bitfield of VC4_DIRTY_* */
138 uint32_t dirty;
139 /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the
140 * first rendering.
141 */
142 uint32_t cleared;
143 /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to
144 * (either clears or draws).
145 */
146 uint32_t resolve;
147 uint32_t clear_color[2];
148 uint32_t clear_depth; /**< 24-bit unorm depth */
149 uint8_t clear_stencil;
150
151 /**
152 * Set if some drawing (triangles, blits, or just a glClear()) has
153 * been done to the FBO, meaning that we need to
154 * DRM_IOCTL_VC4_SUBMIT_CL.
155 */
156 bool needs_flush;
157
158 /**
159 * Set when needs_flush, and the queued rendering is not just composed
160 * of full-buffer clears.
161 */
162 bool draw_call_queued;
163
164 struct primconvert_context *primconvert;
165
166 struct util_hash_table *fs_cache, *vs_cache;
167
168 /** @{ Current pipeline state objects */
169 struct pipe_scissor_state scissor;
170 struct pipe_blend_state *blend;
171 struct vc4_rasterizer_state *rasterizer;
172 struct vc4_depth_stencil_alpha_state *zsa;
173
174 struct vc4_texture_stateobj verttex, fragtex;
175
176 struct vc4_program_stateobj prog;
177
178 struct vc4_vertex_stateobj *vtx;
179
180 struct pipe_blend_color blend_color;
181 struct pipe_stencil_ref stencil_ref;
182 unsigned sample_mask;
183 struct pipe_framebuffer_state framebuffer;
184 struct pipe_poly_stipple stipple;
185 struct pipe_viewport_state viewport;
186 struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
187 struct vc4_vertexbuf_stateobj vertexbuf;
188 struct pipe_index_buffer indexbuf;
189 /** @} */
190 };
191
192 struct vc4_rasterizer_state {
193 struct pipe_rasterizer_state base;
194
195 /* VC4_CONFIGURATION_BITS */
196 uint8_t config_bits[3];
197
198 float point_size;
199 };
200
201 struct vc4_depth_stencil_alpha_state {
202 struct pipe_depth_stencil_alpha_state base;
203
204 /* VC4_CONFIGURATION_BITS */
205 uint8_t config_bits[3];
206 };
207
208 static inline struct vc4_context *
209 vc4_context(struct pipe_context *pcontext)
210 {
211 return (struct vc4_context *)pcontext;
212 }
213
214 struct pipe_context *vc4_context_create(struct pipe_screen *pscreen,
215 void *priv);
216 void vc4_draw_init(struct pipe_context *pctx);
217 void vc4_state_init(struct pipe_context *pctx);
218 void vc4_program_init(struct pipe_context *pctx);
219 void vc4_simulator_init(struct vc4_screen *screen);
220 int vc4_simulator_flush(struct vc4_context *vc4,
221 struct drm_vc4_submit_cl *args);
222
223 void vc4_write_uniforms(struct vc4_context *vc4,
224 struct vc4_compiled_shader *shader,
225 struct vc4_constbuf_stateobj *cb,
226 struct vc4_texture_stateobj *texstate,
227 int shader_index);
228
229 void vc4_flush(struct pipe_context *pctx);
230 void vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo);
231 void vc4_emit_state(struct pipe_context *pctx);
232 void vc4_generate_code(struct vc4_compile *c);
233 void vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode);
234
235 bool vc4_rt_format_supported(enum pipe_format f);
236 bool vc4_rt_format_is_565(enum pipe_format f);
237 bool vc4_tex_format_supported(enum pipe_format f);
238 uint8_t vc4_get_tex_format(enum pipe_format f);
239 const uint8_t *vc4_get_format_swizzle(enum pipe_format f);
240
241 #endif /* VC4_CONTEXT_H */