lima: move clear into submit (v2)
[mesa.git] / src / gallium / drivers / lima / lima_context.h
1 /*
2 * Copyright (c) 2017-2019 Lima Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef H_LIMA_CONTEXT
26 #define H_LIMA_CONTEXT
27
28 #include "util/slab.h"
29
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32
33 struct lima_context_framebuffer {
34 struct pipe_framebuffer_state base;
35 int tiled_w, tiled_h;
36 int shift_w, shift_h;
37 int block_w, block_h;
38 int shift_min;
39 };
40
41 struct lima_depth_stencil_alpha_state {
42 struct pipe_depth_stencil_alpha_state base;
43 };
44
45 struct lima_fs_shader_state {
46 void *shader;
47 int shader_size;
48 int stack_size;
49 bool uses_discard;
50 struct lima_bo *bo;
51 };
52
53 #define LIMA_MAX_VARYING_NUM 13
54
55 struct lima_varying_info {
56 int components;
57 int component_size;
58 int offset;
59 };
60
61 struct lima_vs_shader_state {
62 void *shader;
63 int shader_size;
64 int prefetch;
65
66 /* pipe_constant_buffer.size is aligned with some pad bytes,
67 * so record here for the real start place of gpir lowered
68 * uniforms */
69 int uniform_pending_offset;
70
71 void *constant;
72 int constant_size;
73
74 struct lima_varying_info varying[LIMA_MAX_VARYING_NUM];
75 int varying_stride;
76 int num_outputs;
77 int num_varyings;
78 int gl_pos_idx;
79 int point_size_idx;
80
81 struct lima_bo *bo;
82 };
83
84 struct lima_rasterizer_state {
85 struct pipe_rasterizer_state base;
86 };
87
88 struct lima_blend_state {
89 struct pipe_blend_state base;
90 };
91
92 struct lima_vertex_element_state {
93 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
94 unsigned num_elements;
95 };
96
97 struct lima_context_vertex_buffer {
98 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
99 unsigned count;
100 uint32_t enabled_mask;
101 };
102
103 struct lima_context_viewport_state {
104 struct pipe_viewport_state transform;
105 float left, right, bottom, top;
106 float near, far;
107 };
108
109 struct lima_context_constant_buffer {
110 const void *buffer;
111 uint32_t size;
112 bool dirty;
113 };
114
115 enum lima_ctx_buff {
116 lima_ctx_buff_gp_varying_info,
117 lima_ctx_buff_gp_attribute_info,
118 lima_ctx_buff_gp_uniform,
119 lima_ctx_buff_pp_plb_rsw,
120 lima_ctx_buff_pp_uniform_array,
121 lima_ctx_buff_pp_uniform,
122 lima_ctx_buff_pp_tex_desc,
123 lima_ctx_buff_num,
124 lima_ctx_buff_num_gp = lima_ctx_buff_pp_plb_rsw,
125 };
126
127 struct lima_ctx_buff_state {
128 struct pipe_resource *res;
129 unsigned offset;
130 unsigned size;
131 };
132
133 struct lima_texture_stateobj {
134 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
135 unsigned num_textures;
136 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
137 unsigned num_samplers;
138 };
139
140 struct lima_ctx_plb_pp_stream_key {
141 uint32_t plb_index;
142 uint32_t tiled_w;
143 uint32_t tiled_h;
144 };
145
146 struct lima_ctx_plb_pp_stream {
147 struct lima_ctx_plb_pp_stream_key key;
148 uint32_t refcnt;
149 struct lima_bo *bo;
150 uint32_t offset[4];
151 };
152
153 struct lima_pp_stream_state {
154 void *map;
155 uint32_t va;
156 uint32_t offset[8];
157 };
158
159 struct lima_context {
160 struct pipe_context base;
161
162 enum {
163 LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0),
164 LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1),
165 LIMA_CONTEXT_DIRTY_SHADER_VERT = (1 << 2),
166 LIMA_CONTEXT_DIRTY_SHADER_FRAG = (1 << 3),
167 LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4),
168 LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5),
169 LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6),
170 LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7),
171 LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8),
172 LIMA_CONTEXT_DIRTY_ZSA = (1 << 9),
173 LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10),
174 LIMA_CONTEXT_DIRTY_BLEND = (1 << 11),
175 LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12),
176 LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13),
177 LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14),
178 } dirty;
179
180 struct u_upload_mgr *uploader;
181 struct blitter_context *blitter;
182
183 struct slab_child_pool transfer_pool;
184
185 struct lima_context_framebuffer framebuffer;
186 struct lima_context_viewport_state viewport;
187 struct pipe_scissor_state scissor;
188 struct lima_vs_shader_state *vs;
189 struct lima_fs_shader_state *fs;
190 struct lima_vertex_element_state *vertex_elements;
191 struct lima_context_vertex_buffer vertex_buffers;
192 struct lima_rasterizer_state *rasterizer;
193 struct lima_depth_stencil_alpha_state *zsa;
194 struct pipe_blend_color blend_color;
195 struct lima_blend_state *blend;
196 struct pipe_stencil_ref stencil_ref;
197 struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES];
198 struct lima_texture_stateobj tex_stateobj;
199 struct lima_pp_stream_state pp_stream;
200
201 unsigned min_index;
202 unsigned max_index;
203
204 #define LIMA_CTX_PLB_MIN_NUM 1
205 #define LIMA_CTX_PLB_MAX_NUM 4
206 #define LIMA_CTX_PLB_DEF_NUM 2
207 #define LIMA_CTX_PLB_BLK_SIZE 512
208 unsigned plb_size;
209 unsigned plb_gp_size;
210
211 struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];
212 struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];
213 uint32_t gp_tile_heap_size;
214 struct lima_bo *plb_gp_stream;
215 struct lima_bo *gp_output;
216 uint32_t gp_output_varyings_offt;
217 uint32_t gp_output_point_size_offt;
218
219 struct hash_table *plb_pp_stream;
220 uint32_t plb_index;
221
222 struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num];
223
224 /* current submit */
225 struct lima_submit *submit;
226
227 /* map from lima_submit_key to lima_submit */
228 struct hash_table *submits;
229
230 /* map from pipe_resource to lima_submit which write to it */
231 struct hash_table *write_submits;
232
233 int in_sync_fd;
234 uint32_t in_sync[2];
235 uint32_t out_sync[2];
236
237 int id;
238
239 struct pipe_debug_callback debug;
240
241 unsigned index_offset;
242 struct lima_resource *index_res;
243 };
244
245 static inline struct lima_context *
246 lima_context(struct pipe_context *pctx)
247 {
248 return (struct lima_context *)pctx;
249 }
250
251 struct lima_sampler_state {
252 struct pipe_sampler_state base;
253 };
254
255 static inline struct lima_sampler_state *
256 lima_sampler_state(struct pipe_sampler_state *psstate)
257 {
258 return (struct lima_sampler_state *)psstate;
259 }
260
261 struct lima_sampler_view {
262 struct pipe_sampler_view base;
263 };
264
265 static inline struct lima_sampler_view *
266 lima_sampler_view(struct pipe_sampler_view *psview)
267 {
268 return (struct lima_sampler_view *)psview;
269 }
270
271 uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff);
272 void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);
273 void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
274 unsigned size);
275
276 void lima_state_init(struct lima_context *ctx);
277 void lima_state_fini(struct lima_context *ctx);
278 void lima_draw_init(struct lima_context *ctx);
279 void lima_program_init(struct lima_context *ctx);
280 void lima_query_init(struct lima_context *ctx);
281
282 struct pipe_context *
283 lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
284
285 void lima_flush(struct lima_context *ctx);
286 void lima_flush_submit_accessing_bo(
287 struct lima_context *ctx, struct lima_bo *bo, bool write);
288 void lima_flush_previous_submit_writing_resource(
289 struct lima_context *ctx, struct pipe_resource *prsc);
290
291 #endif