2 * Copyright (c) 2017-2019 Lima Project
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
25 #ifndef H_LIMA_CONTEXT
26 #define H_LIMA_CONTEXT
28 #include "util/slab.h"
29 #include "util/u_dynarray.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
34 struct lima_context_framebuffer
{
35 struct pipe_framebuffer_state base
;
42 struct lima_context_clear
{
50 struct lima_depth_stencil_alpha_state
{
51 struct pipe_depth_stencil_alpha_state base
;
54 struct lima_fs_shader_state
{
61 #define LIMA_MAX_VARYING_NUM 13
63 struct lima_varying_info
{
69 struct lima_vs_shader_state
{
74 /* pipe_constant_buffer.size is aligned with some pad bytes,
75 * so record here for the real start place of gpir lowered
77 int uniform_pending_offset
;
82 struct lima_varying_info varying
[LIMA_MAX_VARYING_NUM
];
92 struct lima_rasterizer_state
{
93 struct pipe_rasterizer_state base
;
96 struct lima_blend_state
{
97 struct pipe_blend_state base
;
100 struct lima_vertex_element_state
{
101 struct pipe_vertex_element pipe
[PIPE_MAX_ATTRIBS
];
102 unsigned num_elements
;
105 struct lima_context_vertex_buffer
{
106 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
108 uint32_t enabled_mask
;
111 struct lima_context_viewport_state
{
112 struct pipe_viewport_state transform
;
113 float left
, right
, bottom
, top
;
117 struct lima_context_constant_buffer
{
124 lima_ctx_buff_sh_varying
,
125 lima_ctx_buff_sh_gl_pos
,
126 lima_ctx_buff_sh_gl_point_size
,
127 lima_ctx_buff_gp_varying_info
,
128 lima_ctx_buff_gp_attribute_info
,
129 lima_ctx_buff_gp_uniform
,
130 lima_ctx_buff_gp_vs_cmd
,
131 lima_ctx_buff_gp_plbu_cmd
,
132 lima_ctx_buff_pp_plb_rsw
,
133 lima_ctx_buff_pp_uniform_array
,
134 lima_ctx_buff_pp_uniform
,
135 lima_ctx_buff_pp_tex_desc
,
136 lima_ctx_buff_pp_stack
,
140 struct lima_ctx_buff_state
{
141 struct pipe_resource
*res
;
146 struct lima_texture_stateobj
{
147 struct pipe_sampler_view
*textures
[PIPE_MAX_SAMPLERS
];
148 unsigned num_textures
;
149 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
150 unsigned num_samplers
;
153 struct lima_ctx_plb_pp_stream_key
{
159 struct lima_ctx_plb_pp_stream
{
160 struct lima_ctx_plb_pp_stream_key key
;
166 struct lima_pp_stream_state
{
172 struct lima_context
{
173 struct pipe_context base
;
176 LIMA_CONTEXT_DIRTY_FRAMEBUFFER
= (1 << 0),
177 LIMA_CONTEXT_DIRTY_CLEAR
= (1 << 1),
178 LIMA_CONTEXT_DIRTY_SHADER_VERT
= (1 << 2),
179 LIMA_CONTEXT_DIRTY_SHADER_FRAG
= (1 << 3),
180 LIMA_CONTEXT_DIRTY_VERTEX_ELEM
= (1 << 4),
181 LIMA_CONTEXT_DIRTY_VERTEX_BUFF
= (1 << 5),
182 LIMA_CONTEXT_DIRTY_VIEWPORT
= (1 << 6),
183 LIMA_CONTEXT_DIRTY_SCISSOR
= (1 << 7),
184 LIMA_CONTEXT_DIRTY_RASTERIZER
= (1 << 8),
185 LIMA_CONTEXT_DIRTY_ZSA
= (1 << 9),
186 LIMA_CONTEXT_DIRTY_BLEND_COLOR
= (1 << 10),
187 LIMA_CONTEXT_DIRTY_BLEND
= (1 << 11),
188 LIMA_CONTEXT_DIRTY_STENCIL_REF
= (1 << 12),
189 LIMA_CONTEXT_DIRTY_CONST_BUFF
= (1 << 13),
190 LIMA_CONTEXT_DIRTY_TEXTURES
= (1 << 14),
193 struct u_upload_mgr
*uploader
;
194 struct u_suballocator
*suballocator
;
195 struct blitter_context
*blitter
;
197 struct slab_child_pool transfer_pool
;
199 struct lima_context_framebuffer framebuffer
;
200 struct lima_context_viewport_state viewport
;
201 struct pipe_scissor_state scissor
;
202 struct lima_context_clear clear
;
203 struct lima_vs_shader_state
*vs
;
204 struct lima_fs_shader_state
*fs
;
205 struct lima_vertex_element_state
*vertex_elements
;
206 struct lima_context_vertex_buffer vertex_buffers
;
207 struct lima_rasterizer_state
*rasterizer
;
208 struct lima_depth_stencil_alpha_state
*zsa
;
209 struct pipe_blend_color blend_color
;
210 struct lima_blend_state
*blend
;
211 struct pipe_stencil_ref stencil_ref
;
212 struct lima_context_constant_buffer const_buffer
[PIPE_SHADER_TYPES
];
213 struct lima_texture_stateobj tex_stateobj
;
214 struct lima_pp_stream_state pp_stream
;
219 #define LIMA_CTX_PLB_MIN_NUM 1
220 #define LIMA_CTX_PLB_MAX_NUM 4
221 #define LIMA_CTX_PLB_DEF_NUM 2
222 #define LIMA_CTX_PLB_BLK_SIZE 512
224 unsigned plb_gp_size
;
226 struct lima_bo
*plb
[LIMA_CTX_PLB_MAX_NUM
];
227 struct lima_bo
*gp_tile_heap
[LIMA_CTX_PLB_MAX_NUM
];
228 #define gp_tile_heap_size 0x100000
229 struct lima_bo
*plb_gp_stream
;
231 struct hash_table
*plb_pp_stream
;
234 struct lima_ctx_buff_state buffer_state
[lima_ctx_buff_num
];
236 struct util_dynarray vs_cmd_array
;
237 struct util_dynarray plbu_cmd_array
;
239 struct lima_submit
*gp_submit
;
240 struct lima_submit
*pp_submit
;
244 struct pipe_debug_callback debug
;
246 int pp_max_stack_size
;
249 static inline struct lima_context
*
250 lima_context(struct pipe_context
*pctx
)
252 return (struct lima_context
*)pctx
;
255 struct lima_sampler_state
{
256 struct pipe_sampler_state base
;
259 static inline struct lima_sampler_state
*
260 lima_sampler_state(struct pipe_sampler_state
*psstate
)
262 return (struct lima_sampler_state
*)psstate
;
265 struct lima_sampler_view
{
266 struct pipe_sampler_view base
;
269 static inline struct lima_sampler_view
*
270 lima_sampler_view(struct pipe_sampler_view
*psview
)
272 return (struct lima_sampler_view
*)psview
;
275 #define LIMA_CTX_BUFF_SUBMIT_GP (1 << 0)
276 #define LIMA_CTX_BUFF_SUBMIT_PP (1 << 1)
278 uint32_t lima_ctx_buff_va(struct lima_context
*ctx
, enum lima_ctx_buff buff
,
280 void *lima_ctx_buff_map(struct lima_context
*ctx
, enum lima_ctx_buff buff
);
281 void *lima_ctx_buff_alloc(struct lima_context
*ctx
, enum lima_ctx_buff buff
,
282 unsigned size
, bool uploader
);
284 void lima_state_init(struct lima_context
*ctx
);
285 void lima_state_fini(struct lima_context
*ctx
);
286 void lima_draw_init(struct lima_context
*ctx
);
287 void lima_program_init(struct lima_context
*ctx
);
288 void lima_query_init(struct lima_context
*ctx
);
290 struct pipe_context
*
291 lima_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
);
293 void lima_flush(struct lima_context
*ctx
);
295 bool lima_need_flush(struct lima_context
*ctx
, struct lima_bo
*bo
, bool write
);
296 bool lima_is_scanout(struct lima_context
*ctx
);