2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef RADEONSI_PIPE_H
27 #define RADEONSI_PIPE_H
29 #include "../../winsys/radeon/drm/radeon_winsys.h"
31 #include "pipe/p_state.h"
32 #include "pipe/p_screen.h"
33 #include "pipe/p_context.h"
34 #include "util/u_format.h"
35 #include "util/u_math.h"
36 #include "util/u_slab.h"
38 #include "radeonsi_public.h"
39 #include "r600_resource.h"
42 #define R600_MAX_CONST_BUFFERS 1
43 #define R600_MAX_CONST_BUFFER_SIZE 4096
45 #ifdef PIPE_ARCH_BIG_ENDIAN
46 #define R600_BIG_ENDIAN 1
48 #define R600_BIG_ENDIAN 0
51 enum r600_atom_flags
{
52 /* When set, atoms are added at the beginning of the dirty list
53 * instead of the end. */
57 /* This encapsulates a state or an operation which can emitted into the GPU
58 * command stream. It's not limited to states only, it can be used for anything
59 * that wants to write commands into the CS (e.g. cache flushes). */
61 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
);
64 enum r600_atom_flags flags
;
67 struct list_head head
;
70 struct r600_atom_surface_sync
{
71 struct r600_atom atom
;
72 unsigned flush_flags
; /* CP_COHER_CNTL */
75 enum r600_pipe_state_id
{
76 R600_PIPE_STATE_BLEND
= 0,
77 R600_PIPE_STATE_BLEND_COLOR
,
78 R600_PIPE_STATE_CONFIG
,
79 R600_PIPE_STATE_SEAMLESS_CUBEMAP
,
81 R600_PIPE_STATE_SCISSOR
,
82 R600_PIPE_STATE_VIEWPORT
,
83 R600_PIPE_STATE_RASTERIZER
,
85 R600_PIPE_STATE_FRAMEBUFFER
,
87 R600_PIPE_STATE_STENCIL_REF
,
88 R600_PIPE_STATE_PS_SHADER
,
89 R600_PIPE_STATE_VS_SHADER
,
90 R600_PIPE_STATE_CONSTANT
,
91 R600_PIPE_STATE_SAMPLER
,
92 R600_PIPE_STATE_RESOURCE
,
93 R600_PIPE_STATE_POLYGON_OFFSET
,
97 struct r600_pipe_fences
{
98 struct r600_resource
*bo
;
101 /* linked list of preallocated blocks */
102 struct list_head blocks
;
103 /* linked list of freed fences */
104 struct list_head pool
;
109 struct pipe_screen screen
;
110 struct radeon_winsys
*ws
;
112 enum chip_class chip_class
;
113 struct radeon_info info
;
114 struct r600_tiling_info tiling_info
;
115 struct util_slab_mempool pool_buffers
;
116 struct r600_pipe_fences fences
;
118 unsigned num_contexts
;
120 /* for thread-safe write accessing to num_contexts */
121 pipe_mutex mutex_num_contexts
;
124 struct si_pipe_sampler_view
{
125 struct pipe_sampler_view base
;
129 struct si_pipe_sampler_state
{
133 struct r600_pipe_rasterizer
{
134 struct r600_pipe_state rstate
;
136 unsigned sprite_coord_enable
;
137 unsigned pa_sc_line_stipple
;
138 unsigned pa_su_sc_mode_cntl
;
139 unsigned pa_cl_clip_cntl
;
140 unsigned pa_cl_vs_out_cntl
;
145 struct r600_pipe_blend
{
146 struct r600_pipe_state rstate
;
147 unsigned cb_target_mask
;
148 unsigned cb_color_control
;
151 struct r600_pipe_dsa
{
152 struct r600_pipe_state rstate
;
154 unsigned db_render_override
;
155 unsigned db_render_control
;
160 struct r600_vertex_element
163 struct pipe_vertex_element elements
[PIPE_MAX_ATTRIBS
];
165 struct r600_pipe_state rstate
;
166 /* if offset is to big for fetch instructio we need to alterate
167 * offset of vertex buffer, record here the offset need to add
169 unsigned vbuffer_need_offset
;
170 unsigned vbuffer_offset
[PIPE_MAX_ATTRIBS
];
173 struct r600_shader_io
{
178 unsigned interpolate
;
180 unsigned lds_pos
; /* for evergreen */
186 struct r600_shader_io input
[32];
187 struct r600_shader_io output
[32];
189 boolean fs_write_all
;
193 struct si_pipe_shader
{
194 struct r600_shader shader
;
195 struct r600_pipe_state rstate
;
196 struct r600_resource
*bo
;
197 struct r600_vertex_element vertex_elements
;
198 struct tgsi_token
*tokens
;
201 unsigned spi_ps_input_ena
;
202 unsigned sprite_coord_enable
;
203 struct pipe_stream_output_info so
;
204 unsigned so_strides
[4];
207 /* needed for blitter save */
208 #define NUM_TEX_UNITS 16
210 struct r600_textures_info
{
211 struct r600_pipe_state rstate
;
212 struct si_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
213 struct si_pipe_sampler_state
*samplers
[NUM_TEX_UNITS
];
217 bool is_array_sampler
[NUM_TEX_UNITS
];
221 struct pipe_reference reference
;
222 unsigned index
; /* in the shared bo */
223 struct r600_resource
*sleep_bo
;
224 struct list_head head
;
227 #define FENCE_BLOCK_SIZE 16
229 struct r600_fence_block
{
230 struct r600_fence fences
[FENCE_BLOCK_SIZE
];
231 struct list_head head
;
234 #define R600_CONSTANT_ARRAY_SIZE 256
235 #define R600_RESOURCE_ARRAY_SIZE 160
237 struct r600_stencil_ref
244 struct r600_context
{
245 struct pipe_context context
;
246 struct blitter_context
*blitter
;
247 enum radeon_family family
;
248 enum chip_class chip_class
;
249 void *custom_dsa_flush
;
250 struct r600_screen
*screen
;
251 struct radeon_winsys
*ws
;
252 struct r600_pipe_state
*states
[R600_PIPE_NSTATES
];
253 struct r600_vertex_element
*vertex_elements
;
254 struct pipe_framebuffer_state framebuffer
;
255 unsigned cb_target_mask
;
256 unsigned cb_color_control
;
257 unsigned pa_sc_line_stipple
;
258 unsigned pa_su_sc_mode_cntl
;
259 unsigned pa_cl_clip_cntl
;
260 unsigned pa_cl_vs_out_cntl
;
261 /* for saving when using blitter */
262 struct pipe_stencil_ref stencil_ref
;
263 struct pipe_viewport_state viewport
;
264 struct pipe_clip_state clip
;
265 struct r600_pipe_state config
;
266 struct si_pipe_shader
*ps_shader
;
267 struct si_pipe_shader
*vs_shader
;
268 struct r600_pipe_state vs_const_buffer
;
269 struct r600_pipe_state vs_user_data
;
270 struct r600_pipe_state ps_const_buffer
;
271 struct r600_pipe_rasterizer
*rasterizer
;
272 struct r600_pipe_state vgt
;
273 struct r600_pipe_state spi
;
274 struct pipe_query
*current_render_cond
;
275 unsigned current_render_cond_mode
;
276 struct pipe_query
*saved_render_cond
;
277 unsigned saved_render_cond_mode
;
278 /* shader information */
279 unsigned sprite_coord_enable
;
280 boolean export_16bpc
;
282 boolean alpha_ref_dirty
;
284 struct r600_textures_info vs_samplers
;
285 struct r600_textures_info ps_samplers
;
286 boolean shader_dirty
;
288 struct u_upload_mgr
*uploader
;
289 struct util_slab_mempool pool_transfers
;
290 boolean have_depth_texture
, have_depth_fb
;
292 unsigned default_ps_gprs
, default_vs_gprs
;
294 /* States based on r600_state. */
295 struct list_head dirty_states
;
296 struct r600_atom_surface_sync atom_surface_sync
;
297 struct r600_atom atom_r6xx_flush_and_inv
;
299 /* Below are variables from the old r600_context.
301 struct radeon_winsys_cs
*cs
;
303 struct r600_range
*range
;
305 struct r600_block
**blocks
;
306 struct list_head dirty
;
307 struct list_head enable_list
;
308 unsigned pm4_dirty_cdwords
;
309 unsigned ctx_pm4_ndwords
;
310 unsigned init_dwords
;
312 /* The list of active queries. Only one query of each type can be active. */
313 struct list_head active_query_list
;
314 unsigned num_cs_dw_queries_suspend
;
315 unsigned num_cs_dw_streamout_end
;
317 unsigned backend_mask
;
318 unsigned max_db
; /* for OQ */
320 boolean predicate_drawing
;
322 unsigned num_so_targets
;
323 struct r600_so_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
324 boolean streamout_start
;
325 unsigned streamout_append_bitmask
;
326 unsigned *vs_so_stride_in_dw
;
327 unsigned *vs_shader_so_strides
;
329 /* Vertex and index buffers. */
330 bool vertex_buffers_dirty
;
331 struct pipe_index_buffer index_buffer
;
332 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
333 unsigned nr_vertex_buffers
;
336 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
338 atom
->emit(rctx
, atom
);
340 if (atom
->head
.next
&& atom
->head
.prev
)
341 LIST_DELINIT(&atom
->head
);
344 static INLINE
void r600_atom_dirty(struct r600_context
*rctx
, struct r600_atom
*state
)
347 if (state
->flags
& EMIT_EARLY
) {
348 LIST_ADD(&state
->head
, &rctx
->dirty_states
);
350 LIST_ADDTAIL(&state
->head
, &rctx
->dirty_states
);
356 /* evergreen_state.c */
357 void cayman_init_state_functions(struct r600_context
*rctx
);
358 void si_init_config(struct r600_context
*rctx
);
359 void si_pipe_shader_ps(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
);
360 void si_pipe_shader_vs(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
);
361 void si_update_spi_map(struct r600_context
*rctx
);
362 void *cayman_create_db_flush_dsa(struct r600_context
*rctx
);
363 void cayman_polygon_offset_update(struct r600_context
*rctx
);
364 uint32_t si_translate_vertexformat(struct pipe_screen
*screen
,
365 enum pipe_format format
,
366 const struct util_format_description
*desc
,
368 boolean
si_is_format_supported(struct pipe_screen
*screen
,
369 enum pipe_format format
,
370 enum pipe_texture_target target
,
371 unsigned sample_count
,
375 void r600_init_blit_functions(struct r600_context
*rctx
);
376 void r600_blit_uncompress_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
377 void r600_blit_push_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
378 void r600_flush_depth_textures(struct r600_context
*rctx
);
381 bool r600_init_resource(struct r600_screen
*rscreen
,
382 struct r600_resource
*res
,
383 unsigned size
, unsigned alignment
,
384 unsigned bind
, unsigned usage
);
385 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
386 const struct pipe_resource
*templ
);
387 struct pipe_resource
*r600_user_buffer_create(struct pipe_screen
*screen
,
388 void *ptr
, unsigned bytes
,
390 void r600_upload_index_buffer(struct r600_context
*rctx
,
391 struct pipe_index_buffer
*ib
, unsigned count
);
395 void radeonsi_flush(struct pipe_context
*ctx
, struct pipe_fence_handle
**fence
,
399 void r600_init_query_functions(struct r600_context
*rctx
);
401 /* r600_resource.c */
402 void r600_init_context_resource_functions(struct r600_context
*r600
);
404 /* radeonsi_shader.c */
405 int si_pipe_shader_create(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
);
406 void si_pipe_shader_destroy(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
);
409 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
410 void r600_init_surface_functions(struct r600_context
*r600
);
411 unsigned r600_texture_get_offset(struct r600_resource_texture
*rtex
,
412 unsigned level
, unsigned layer
);
414 /* r600_translate.c */
415 void r600_translate_index_buffer(struct r600_context
*r600
,
416 struct pipe_index_buffer
*ib
,
419 /* r600_state_common.c */
420 void r600_init_common_atoms(struct r600_context
*rctx
);
421 unsigned r600_get_cb_flush_flags(struct r600_context
*rctx
);
422 void r600_texture_barrier(struct pipe_context
*ctx
);
423 void r600_set_index_buffer(struct pipe_context
*ctx
,
424 const struct pipe_index_buffer
*ib
);
425 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
426 const struct pipe_vertex_buffer
*buffers
);
427 void *si_create_vertex_elements(struct pipe_context
*ctx
,
429 const struct pipe_vertex_element
*elements
);
430 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
);
431 void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
);
432 void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
);
433 void r600_bind_rs_state(struct pipe_context
*ctx
, void *state
);
434 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
);
435 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
436 struct pipe_sampler_view
*state
);
437 void r600_delete_state(struct pipe_context
*ctx
, void *state
);
438 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
);
439 void *si_create_shader_state(struct pipe_context
*ctx
,
440 const struct pipe_shader_state
*state
);
441 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
);
442 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
);
443 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
);
444 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
);
445 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
446 struct pipe_constant_buffer
*cb
);
447 struct pipe_stream_output_target
*
448 r600_create_so_target(struct pipe_context
*ctx
,
449 struct pipe_resource
*buffer
,
450 unsigned buffer_offset
,
451 unsigned buffer_size
);
452 void r600_so_target_destroy(struct pipe_context
*ctx
,
453 struct pipe_stream_output_target
*target
);
454 void r600_set_so_targets(struct pipe_context
*ctx
,
455 unsigned num_targets
,
456 struct pipe_stream_output_target
**targets
,
457 unsigned append_bitmask
);
458 void r600_set_pipe_stencil_ref(struct pipe_context
*ctx
,
459 const struct pipe_stencil_ref
*state
);
460 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
);
465 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
467 return value
* (1 << frac_bits
);
469 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
471 static INLINE
unsigned si_map_swizzle(unsigned swizzle
)
474 case UTIL_FORMAT_SWIZZLE_Y
:
475 return V_008F0C_SQ_SEL_Y
;
476 case UTIL_FORMAT_SWIZZLE_Z
:
477 return V_008F0C_SQ_SEL_Z
;
478 case UTIL_FORMAT_SWIZZLE_W
:
479 return V_008F0C_SQ_SEL_W
;
480 case UTIL_FORMAT_SWIZZLE_0
:
481 return V_008F0C_SQ_SEL_0
;
482 case UTIL_FORMAT_SWIZZLE_1
:
483 return V_008F0C_SQ_SEL_1
;
484 default: /* UTIL_FORMAT_SWIZZLE_X */
485 return V_008F0C_SQ_SEL_X
;
489 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
491 if (filter
<= 1) return 0;
492 if (filter
<= 2) return 1;
493 if (filter
<= 4) return 2;
494 if (filter
<= 8) return 3;
498 /* 12.4 fixed-point */
499 static INLINE
unsigned r600_pack_float_12p4(float x
)
502 x
>= 4096 ? 0xffff : x
* 16;
505 static INLINE
uint64_t r600_resource_va(struct pipe_screen
*screen
, struct pipe_resource
*resource
)
507 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
508 struct r600_resource
*rresource
= (struct r600_resource
*)resource
;
510 return rscreen
->ws
->buffer_get_virtual_address(rresource
->cs_buf
);