lima_context.h revision 9f464c52
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#include "util/u_dynarray.h"
30
31#include "pipe/p_context.h"
32#include "pipe/p_state.h"
33
34struct lima_context_framebuffer {
35   struct pipe_framebuffer_state base;
36   int tiled_w, tiled_h;
37   int shift_w, shift_h;
38   int block_w, block_h;
39   int shift_min;
40};
41
42struct lima_context_clear {
43   unsigned buffers;
44   uint32_t color_8pc;
45   uint32_t depth;
46   uint32_t stencil;
47   uint64_t color_16pc;
48};
49
50struct lima_depth_stencil_alpha_state {
51   struct pipe_depth_stencil_alpha_state base;
52};
53
54struct lima_fs_shader_state {
55   void *shader;
56   int shader_size;
57   int stack_size;
58   struct lima_bo *bo;
59};
60
61#define LIMA_MAX_VARYING_NUM 13
62
63struct lima_varying_info {
64   int components;
65   int component_size;
66   int offset;
67};
68
69struct lima_vs_shader_state {
70   void *shader;
71   int shader_size;
72   int prefetch;
73
74   /* pipe_constant_buffer.size is aligned with some pad bytes,
75    * so record here for the real start place of gpir lowered
76    * uniforms */
77   int uniform_pending_offset;
78
79   void *constant;
80   int constant_size;
81
82   struct lima_varying_info varying[LIMA_MAX_VARYING_NUM];
83   int varying_stride;
84   int num_varying;
85
86   struct lima_bo *bo;
87};
88
89struct lima_rasterizer_state {
90   struct pipe_rasterizer_state base;
91};
92
93struct lima_blend_state {
94   struct pipe_blend_state base;
95};
96
97struct lima_vertex_element_state {
98   struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
99   unsigned num_elements;
100};
101
102struct lima_context_vertex_buffer {
103   struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
104   unsigned count;
105   uint32_t enabled_mask;
106};
107
108struct lima_context_viewport_state {
109   struct pipe_viewport_state transform;
110   float x, y, width, height;
111   float near, far;
112};
113
114struct lima_context_constant_buffer {
115   const void *buffer;
116   uint32_t size;
117   bool dirty;
118};
119
120enum lima_ctx_buff {
121   lima_ctx_buff_sh_varying,
122   lima_ctx_buff_sh_gl_pos,
123   lima_ctx_buff_gp_varying_info,
124   lima_ctx_buff_gp_attribute_info,
125   lima_ctx_buff_gp_uniform,
126   lima_ctx_buff_gp_vs_cmd,
127   lima_ctx_buff_gp_plbu_cmd,
128   lima_ctx_buff_pp_plb_rsw,
129   lima_ctx_buff_pp_uniform_array,
130   lima_ctx_buff_pp_uniform,
131   lima_ctx_buff_pp_tex_desc,
132   lima_ctx_buff_num,
133};
134
135struct lima_ctx_buff_state {
136   struct pipe_resource *res;
137   unsigned offset;
138   unsigned size;
139};
140
141struct lima_texture_stateobj {
142   struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
143   unsigned num_textures;
144   struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
145   unsigned num_samplers;
146};
147
148struct lima_ctx_plb_pp_stream_key {
149   uint32_t plb_index;
150   uint32_t tiled_w;
151   uint32_t tiled_h;
152};
153
154struct lima_ctx_plb_pp_stream {
155   struct lima_ctx_plb_pp_stream_key key;
156   uint32_t refcnt;
157   struct lima_bo *bo;
158   uint32_t offset[4];
159};
160
161struct lima_damage_state {
162   struct pipe_scissor_state *region;
163   unsigned num_region;
164   bool aligned;
165};
166
167struct lima_pp_stream_state {
168   struct lima_bo *bo;
169   uint32_t bo_offset;
170   uint32_t offset[8];
171};
172
173struct lima_context {
174   struct pipe_context base;
175
176   enum {
177      LIMA_CONTEXT_DIRTY_FRAMEBUFFER  = (1 << 0),
178      LIMA_CONTEXT_DIRTY_CLEAR        = (1 << 1),
179      LIMA_CONTEXT_DIRTY_SHADER_VERT  = (1 << 2),
180      LIMA_CONTEXT_DIRTY_SHADER_FRAG  = (1 << 3),
181      LIMA_CONTEXT_DIRTY_VERTEX_ELEM  = (1 << 4),
182      LIMA_CONTEXT_DIRTY_VERTEX_BUFF  = (1 << 5),
183      LIMA_CONTEXT_DIRTY_VIEWPORT     = (1 << 6),
184      LIMA_CONTEXT_DIRTY_SCISSOR      = (1 << 7),
185      LIMA_CONTEXT_DIRTY_RASTERIZER   = (1 << 8),
186      LIMA_CONTEXT_DIRTY_ZSA          = (1 << 9),
187      LIMA_CONTEXT_DIRTY_BLEND_COLOR  = (1 << 10),
188      LIMA_CONTEXT_DIRTY_BLEND        = (1 << 11),
189      LIMA_CONTEXT_DIRTY_STENCIL_REF  = (1 << 12),
190      LIMA_CONTEXT_DIRTY_CONST_BUFF   = (1 << 13),
191      LIMA_CONTEXT_DIRTY_TEXTURES     = (1 << 14),
192   } dirty;
193
194   struct u_upload_mgr *uploader;
195   struct u_suballocator *suballocator;
196   struct blitter_context *blitter;
197
198   struct slab_child_pool transfer_pool;
199
200   struct lima_context_framebuffer framebuffer;
201   struct lima_context_viewport_state viewport;
202   struct pipe_scissor_state scissor;
203   struct lima_context_clear clear;
204   struct lima_vs_shader_state *vs;
205   struct lima_fs_shader_state *fs;
206   struct lima_vertex_element_state *vertex_elements;
207   struct lima_context_vertex_buffer vertex_buffers;
208   struct lima_rasterizer_state *rasterizer;
209   struct lima_depth_stencil_alpha_state *zsa;
210   struct pipe_blend_color blend_color;
211   struct lima_blend_state *blend;
212   struct pipe_stencil_ref stencil_ref;
213   struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES];
214   struct lima_texture_stateobj tex_stateobj;
215   struct lima_damage_state damage;
216   struct lima_pp_stream_state pp_stream;
217
218   unsigned min_index;
219   unsigned max_index;
220
221   #define LIMA_CTX_PLB_MIN_NUM  1
222   #define LIMA_CTX_PLB_MAX_NUM  4
223   #define LIMA_CTX_PLB_DEF_NUM  2
224   #define LIMA_CTX_PLB_BLK_SIZE 512
225   unsigned plb_max_blk;
226   unsigned plb_size;
227   unsigned plb_gp_size;
228
229   struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];
230   struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];
231   #define gp_tile_heap_size         0x100000
232   struct lima_bo *plb_gp_stream;
233
234   struct hash_table *plb_pp_stream;
235   uint32_t plb_index;
236
237   struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num];
238
239   struct util_dynarray vs_cmd_array;
240   struct util_dynarray plbu_cmd_array;
241
242   struct lima_submit *gp_submit;
243   struct lima_submit *pp_submit;
244
245   int id;
246};
247
248static inline struct lima_context *
249lima_context(struct pipe_context *pctx)
250{
251   return (struct lima_context *)pctx;
252}
253
254struct lima_sampler_state {
255   struct pipe_sampler_state base;
256};
257
258static inline struct lima_sampler_state *
259lima_sampler_state(struct pipe_sampler_state *psstate)
260{
261   return (struct lima_sampler_state *)psstate;
262}
263
264struct lima_sampler_view {
265   struct pipe_sampler_view base;
266};
267
268static inline struct lima_sampler_view *
269lima_sampler_view(struct pipe_sampler_view *psview)
270{
271   return (struct lima_sampler_view *)psview;
272}
273
274#define LIMA_CTX_BUFF_SUBMIT_GP (1 << 0)
275#define LIMA_CTX_BUFF_SUBMIT_PP (1 << 1)
276
277uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff,
278                          unsigned submit);
279void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);
280void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
281                          unsigned size, bool uploader);
282
283void lima_state_init(struct lima_context *ctx);
284void lima_state_fini(struct lima_context *ctx);
285void lima_draw_init(struct lima_context *ctx);
286void lima_program_init(struct lima_context *ctx);
287void lima_query_init(struct lima_context *ctx);
288
289struct pipe_context *
290lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
291
292void lima_flush(struct lima_context *ctx);
293
294bool lima_need_flush(struct lima_context *ctx, struct lima_bo *bo, bool write);
295bool lima_is_scanout(struct lima_context *ctx);
296
297#endif
298