r600g, radeonsi: fix primitives-generated query with disabled streamout
[mesa.git] / src / gallium / drivers / r600 / r600_pipe.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * 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:
10 *
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
13 * 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 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.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef R600_PIPE_H
27 #define R600_PIPE_H
28
29 #include "../radeon/r600_pipe_common.h"
30 #include "../radeon/r600_cs.h"
31
32 #include "r600_llvm.h"
33 #include "r600_public.h"
34
35 #include "util/u_blitter.h"
36 #include "util/u_suballoc.h"
37 #include "util/u_double_list.h"
38 #include "util/u_transfer.h"
39
40 #define R600_NUM_ATOMS 73
41
42 /* the number of CS dwords for flushing and drawing */
43 #define R600_MAX_FLUSH_CS_DWORDS 16
44 #define R600_MAX_DRAW_CS_DWORDS 34
45 #define R600_TRACE_CS_DWORDS 7
46
47 #define R600_MAX_USER_CONST_BUFFERS 13
48 #define R600_MAX_DRIVER_CONST_BUFFERS 4
49 #define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
50
51 /* start driver buffers after user buffers */
52 #define R600_UCP_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
53 #define R600_TXQ_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
54 #define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
55 #define R600_GS_RING_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 3)
56
57 #define R600_MAX_CONST_BUFFER_SIZE 4096
58
59 #ifdef PIPE_ARCH_BIG_ENDIAN
60 #define R600_BIG_ENDIAN 1
61 #else
62 #define R600_BIG_ENDIAN 0
63 #endif
64
65 struct r600_context;
66 struct r600_bytecode;
67 struct r600_shader_key;
68
69 /* This is an atom containing GPU commands that never change.
70 * This is supposed to be copied directly into the CS. */
71 struct r600_command_buffer {
72 uint32_t *buf;
73 unsigned num_dw;
74 unsigned max_num_dw;
75 unsigned pkt_flags;
76 };
77
78 struct r600_db_state {
79 struct r600_atom atom;
80 struct r600_surface *rsurf;
81 };
82
83 struct r600_db_misc_state {
84 struct r600_atom atom;
85 bool occlusion_query_enabled;
86 bool flush_depthstencil_through_cb;
87 bool flush_depthstencil_in_place;
88 bool copy_depth, copy_stencil;
89 unsigned copy_sample;
90 unsigned log_samples;
91 unsigned db_shader_control;
92 bool htile_clear;
93 };
94
95 struct r600_cb_misc_state {
96 struct r600_atom atom;
97 unsigned cb_color_control; /* this comes from blend state */
98 unsigned blend_colormask; /* 8*4 bits for 8 RGBA colorbuffers */
99 unsigned nr_cbufs;
100 unsigned nr_ps_color_outputs;
101 bool multiwrite;
102 bool dual_src_blend;
103 };
104
105 struct r600_clip_misc_state {
106 struct r600_atom atom;
107 unsigned pa_cl_clip_cntl; /* from rasterizer */
108 unsigned pa_cl_vs_out_cntl; /* from vertex shader */
109 unsigned clip_plane_enable; /* from rasterizer */
110 unsigned clip_dist_write; /* from vertex shader */
111 };
112
113 struct r600_alphatest_state {
114 struct r600_atom atom;
115 unsigned sx_alpha_test_control; /* this comes from dsa state */
116 unsigned sx_alpha_ref; /* this comes from dsa state */
117 bool bypass;
118 bool cb0_export_16bpc; /* from set_framebuffer_state */
119 };
120
121 struct r600_vgt_state {
122 struct r600_atom atom;
123 uint32_t vgt_multi_prim_ib_reset_en;
124 uint32_t vgt_multi_prim_ib_reset_indx;
125 uint32_t vgt_indx_offset;
126 };
127
128 struct r600_blend_color {
129 struct r600_atom atom;
130 struct pipe_blend_color state;
131 };
132
133 struct r600_clip_state {
134 struct r600_atom atom;
135 struct pipe_clip_state state;
136 };
137
138 struct r600_cs_shader_state {
139 struct r600_atom atom;
140 unsigned kernel_index;
141 struct r600_pipe_compute *shader;
142 };
143
144 struct r600_framebuffer {
145 struct r600_atom atom;
146 struct pipe_framebuffer_state state;
147 unsigned compressed_cb_mask;
148 unsigned nr_samples;
149 bool export_16bpc;
150 bool cb0_is_integer;
151 bool is_msaa_resolve;
152 };
153
154 struct r600_sample_mask {
155 struct r600_atom atom;
156 uint16_t sample_mask; /* there are only 8 bits on EG, 16 bits on Cayman */
157 };
158
159 struct r600_config_state {
160 struct r600_atom atom;
161 unsigned sq_gpr_resource_mgmt_1;
162 unsigned sq_gpr_resource_mgmt_2;
163 };
164
165 struct r600_stencil_ref
166 {
167 ubyte ref_value[2];
168 ubyte valuemask[2];
169 ubyte writemask[2];
170 };
171
172 struct r600_stencil_ref_state {
173 struct r600_atom atom;
174 struct r600_stencil_ref state;
175 struct pipe_stencil_ref pipe_state;
176 };
177
178 struct r600_viewport_state {
179 struct r600_atom atom;
180 struct pipe_viewport_state state;
181 int idx;
182 };
183
184 struct r600_shader_stages_state {
185 struct r600_atom atom;
186 unsigned geom_enable;
187 };
188
189 struct r600_gs_rings_state {
190 struct r600_atom atom;
191 unsigned enable;
192 struct pipe_constant_buffer esgs_ring;
193 struct pipe_constant_buffer gsvs_ring;
194 };
195
196 /* This must start from 16. */
197 /* features */
198 #define DBG_NO_LLVM (1 << 17)
199 #define DBG_NO_CP_DMA (1 << 18)
200 #define DBG_NO_ASYNC_DMA (1 << 19)
201 /* shader backend */
202 #define DBG_NO_SB (1 << 21)
203 #define DBG_SB_CS (1 << 22)
204 #define DBG_SB_DRY_RUN (1 << 23)
205 #define DBG_SB_STAT (1 << 24)
206 #define DBG_SB_DUMP (1 << 25)
207 #define DBG_SB_NO_FALLBACK (1 << 26)
208 #define DBG_SB_DISASM (1 << 27)
209 #define DBG_SB_SAFEMATH (1 << 28)
210
211 struct r600_screen {
212 struct r600_common_screen b;
213 bool has_msaa;
214 bool has_compressed_msaa_texturing;
215
216 /*for compute global memory binding, we allocate stuff here, instead of
217 * buffers.
218 * XXX: Not sure if this is the best place for global_pool. Also,
219 * it's not thread safe, so it won't work with multiple contexts. */
220 struct compute_memory_pool *global_pool;
221 };
222
223 struct r600_pipe_sampler_view {
224 struct pipe_sampler_view base;
225 struct r600_resource *tex_resource;
226 uint32_t tex_resource_words[8];
227 bool skip_mip_address_reloc;
228 };
229
230 struct r600_rasterizer_state {
231 struct r600_command_buffer buffer;
232 boolean flatshade;
233 boolean two_side;
234 unsigned sprite_coord_enable;
235 unsigned clip_plane_enable;
236 unsigned pa_sc_line_stipple;
237 unsigned pa_cl_clip_cntl;
238 float offset_units;
239 float offset_scale;
240 bool offset_enable;
241 bool scissor_enable;
242 bool multisample_enable;
243 };
244
245 struct r600_poly_offset_state {
246 struct r600_atom atom;
247 enum pipe_format zs_format;
248 float offset_units;
249 float offset_scale;
250 };
251
252 struct r600_blend_state {
253 struct r600_command_buffer buffer;
254 struct r600_command_buffer buffer_no_blend;
255 unsigned cb_target_mask;
256 unsigned cb_color_control;
257 unsigned cb_color_control_no_blend;
258 bool dual_src_blend;
259 bool alpha_to_one;
260 };
261
262 struct r600_dsa_state {
263 struct r600_command_buffer buffer;
264 unsigned alpha_ref;
265 ubyte valuemask[2];
266 ubyte writemask[2];
267 unsigned zwritemask;
268 unsigned sx_alpha_test_control;
269 };
270
271 struct r600_pipe_shader;
272
273 struct r600_pipe_shader_selector {
274 struct r600_pipe_shader *current;
275
276 struct tgsi_token *tokens;
277 struct pipe_stream_output_info so;
278
279 unsigned num_shaders;
280
281 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
282 unsigned type;
283
284 unsigned nr_ps_max_color_exports;
285 };
286
287 struct r600_pipe_sampler_state {
288 uint32_t tex_sampler_words[3];
289 union pipe_color_union border_color;
290 bool border_color_use;
291 bool seamless_cube_map;
292 };
293
294 /* needed for blitter save */
295 #define NUM_TEX_UNITS 16
296
297 struct r600_seamless_cube_map {
298 struct r600_atom atom;
299 bool enabled;
300 };
301
302 struct r600_samplerview_state {
303 struct r600_atom atom;
304 struct r600_pipe_sampler_view *views[NUM_TEX_UNITS];
305 uint32_t enabled_mask;
306 uint32_t dirty_mask;
307 uint32_t compressed_depthtex_mask; /* which textures are depth */
308 uint32_t compressed_colortex_mask;
309 boolean dirty_txq_constants;
310 boolean dirty_buffer_constants;
311 };
312
313 struct r600_sampler_states {
314 struct r600_atom atom;
315 struct r600_pipe_sampler_state *states[NUM_TEX_UNITS];
316 uint32_t enabled_mask;
317 uint32_t dirty_mask;
318 uint32_t has_bordercolor_mask; /* which states contain the border color */
319 };
320
321 struct r600_textures_info {
322 struct r600_samplerview_state views;
323 struct r600_sampler_states states;
324 bool is_array_sampler[NUM_TEX_UNITS];
325
326 /* cube array txq workaround */
327 uint32_t *txq_constants;
328 /* buffer related workarounds */
329 uint32_t *buffer_constants;
330 };
331
332 struct r600_constbuf_state
333 {
334 struct r600_atom atom;
335 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
336 uint32_t enabled_mask;
337 uint32_t dirty_mask;
338 };
339
340 struct r600_vertexbuf_state
341 {
342 struct r600_atom atom;
343 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
344 uint32_t enabled_mask; /* non-NULL buffers */
345 uint32_t dirty_mask;
346 };
347
348 /* CSO (constant state object, in other words, immutable state). */
349 struct r600_cso_state
350 {
351 struct r600_atom atom;
352 void *cso; /* e.g. r600_blend_state */
353 struct r600_command_buffer *cb;
354 };
355
356 struct r600_scissor_state
357 {
358 struct r600_atom atom;
359 struct pipe_scissor_state scissor;
360 bool enable; /* r6xx only */
361 int idx;
362 };
363
364 struct r600_fetch_shader {
365 struct r600_resource *buffer;
366 unsigned offset;
367 };
368
369 struct r600_shader_state {
370 struct r600_atom atom;
371 struct r600_pipe_shader *shader;
372 };
373
374 struct r600_context {
375 struct r600_common_context b;
376 struct r600_screen *screen;
377 struct blitter_context *blitter;
378 struct u_suballocator *allocator_fetch_shader;
379
380 /* Hardware info. */
381 boolean has_vertex_cache;
382 boolean keep_tiling_flags;
383 unsigned default_ps_gprs, default_vs_gprs;
384 unsigned r6xx_num_clause_temp_gprs;
385
386 /* Miscellaneous state objects. */
387 void *custom_dsa_flush;
388 void *custom_blend_resolve;
389 void *custom_blend_decompress;
390 void *custom_blend_fastclear;
391 /* With rasterizer discard, there doesn't have to be a pixel shader.
392 * In that case, we bind this one: */
393 void *dummy_pixel_shader;
394 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
395 * bug where valid CMASK and FMASK are required to be present to avoid
396 * a hardlock in certain operations but aren't actually used
397 * for anything useful. */
398 struct r600_resource *dummy_fmask;
399 struct r600_resource *dummy_cmask;
400
401 /* State binding slots are here. */
402 struct r600_atom *atoms[R600_NUM_ATOMS];
403 /* States for CS initialization. */
404 struct r600_command_buffer start_cs_cmd; /* invariant state mostly */
405 /** Compute specific registers initializations. The start_cs_cmd atom
406 * must be emitted before start_compute_cs_cmd. */
407 struct r600_command_buffer start_compute_cs_cmd;
408 /* Register states. */
409 struct r600_alphatest_state alphatest_state;
410 struct r600_cso_state blend_state;
411 struct r600_blend_color blend_color;
412 struct r600_cb_misc_state cb_misc_state;
413 struct r600_clip_misc_state clip_misc_state;
414 struct r600_clip_state clip_state;
415 struct r600_db_misc_state db_misc_state;
416 struct r600_db_state db_state;
417 struct r600_cso_state dsa_state;
418 struct r600_framebuffer framebuffer;
419 struct r600_poly_offset_state poly_offset_state;
420 struct r600_cso_state rasterizer_state;
421 struct r600_sample_mask sample_mask;
422 struct r600_scissor_state scissor[16];
423 struct r600_seamless_cube_map seamless_cube_map;
424 struct r600_config_state config_state;
425 struct r600_stencil_ref_state stencil_ref;
426 struct r600_vgt_state vgt_state;
427 struct r600_viewport_state viewport[16];
428 /* Shaders and shader resources. */
429 struct r600_cso_state vertex_fetch_shader;
430 struct r600_shader_state vertex_shader;
431 struct r600_shader_state pixel_shader;
432 struct r600_shader_state geometry_shader;
433 struct r600_shader_state export_shader;
434 struct r600_cs_shader_state cs_shader_state;
435 struct r600_shader_stages_state shader_stages;
436 struct r600_gs_rings_state gs_rings;
437 struct r600_constbuf_state constbuf_state[PIPE_SHADER_TYPES];
438 struct r600_textures_info samplers[PIPE_SHADER_TYPES];
439 /** Vertex buffers for fetch shaders */
440 struct r600_vertexbuf_state vertex_buffer_state;
441 /** Vertex buffers for compute shaders */
442 struct r600_vertexbuf_state cs_vertex_buffer_state;
443
444 /* Additional context states. */
445 unsigned compute_cb_target_mask;
446 struct r600_pipe_shader_selector *ps_shader;
447 struct r600_pipe_shader_selector *vs_shader;
448 struct r600_pipe_shader_selector *gs_shader;
449 struct r600_rasterizer_state *rasterizer;
450 bool alpha_to_one;
451 bool force_blend_disable;
452 boolean dual_src_blend;
453 unsigned zwritemask;
454
455 /* Index buffer. */
456 struct pipe_index_buffer index_buffer;
457
458 /* Last draw state (-1 = unset). */
459 int last_primitive_type; /* Last primitive type used in draw_vbo. */
460 int last_start_instance;
461
462 void *sb_context;
463 struct r600_isa *isa;
464 };
465
466 static INLINE void r600_emit_command_buffer(struct radeon_winsys_cs *cs,
467 struct r600_command_buffer *cb)
468 {
469 assert(cs->cdw + cb->num_dw <= RADEON_MAX_CMDBUF_DWORDS);
470 memcpy(cs->buf + cs->cdw, cb->buf, 4 * cb->num_dw);
471 cs->cdw += cb->num_dw;
472 }
473
474 void r600_trace_emit(struct r600_context *rctx);
475
476 static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
477 {
478 atom->emit(&rctx->b, atom);
479 atom->dirty = false;
480 if (rctx->screen->b.trace_bo) {
481 r600_trace_emit(rctx);
482 }
483 }
484
485 static INLINE void r600_set_cso_state(struct r600_cso_state *state, void *cso)
486 {
487 state->cso = cso;
488 state->atom.dirty = cso != NULL;
489 }
490
491 static INLINE void r600_set_cso_state_with_cb(struct r600_cso_state *state, void *cso,
492 struct r600_command_buffer *cb)
493 {
494 state->cb = cb;
495 state->atom.num_dw = cb ? cb->num_dw : 0;
496 r600_set_cso_state(state, cso);
497 }
498
499 /* compute_memory_pool.c */
500 struct compute_memory_pool;
501 void compute_memory_pool_delete(struct compute_memory_pool* pool);
502 struct compute_memory_pool* compute_memory_pool_new(
503 struct r600_screen *rscreen);
504
505 /* evergreen_compute.c */
506 void evergreen_set_cs_sampler_view(struct pipe_context *ctx_,
507 unsigned start_slot, unsigned count,
508 struct pipe_sampler_view **views);
509
510 /* evergreen_state.c */
511 struct pipe_sampler_view *
512 evergreen_create_sampler_view_custom(struct pipe_context *ctx,
513 struct pipe_resource *texture,
514 const struct pipe_sampler_view *state,
515 unsigned width0, unsigned height0,
516 unsigned force_level);
517 void evergreen_init_common_regs(struct r600_command_buffer *cb,
518 enum chip_class ctx_chip_class,
519 enum radeon_family ctx_family,
520 int ctx_drm_minor);
521 void cayman_init_common_regs(struct r600_command_buffer *cb,
522 enum chip_class ctx_chip_class,
523 enum radeon_family ctx_family,
524 int ctx_drm_minor);
525
526 void evergreen_init_state_functions(struct r600_context *rctx);
527 void evergreen_init_atom_start_cs(struct r600_context *rctx);
528 void evergreen_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
529 void evergreen_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
530 void evergreen_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
531 void evergreen_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
532 void *evergreen_create_db_flush_dsa(struct r600_context *rctx);
533 void *evergreen_create_resolve_blend(struct r600_context *rctx);
534 void *evergreen_create_decompress_blend(struct r600_context *rctx);
535 void *evergreen_create_fastclear_blend(struct r600_context *rctx);
536 boolean evergreen_is_format_supported(struct pipe_screen *screen,
537 enum pipe_format format,
538 enum pipe_texture_target target,
539 unsigned sample_count,
540 unsigned usage);
541 void evergreen_init_color_surface(struct r600_context *rctx,
542 struct r600_surface *surf);
543 void evergreen_init_color_surface_rat(struct r600_context *rctx,
544 struct r600_surface *surf);
545 void evergreen_update_db_shader_control(struct r600_context * rctx);
546
547 /* r600_blit.c */
548 void r600_init_blit_functions(struct r600_context *rctx);
549 void r600_decompress_depth_textures(struct r600_context *rctx,
550 struct r600_samplerview_state *textures);
551 void r600_decompress_color_textures(struct r600_context *rctx,
552 struct r600_samplerview_state *textures);
553
554 /* r600_shader.c */
555 int r600_pipe_shader_create(struct pipe_context *ctx,
556 struct r600_pipe_shader *shader,
557 struct r600_shader_key key);
558
559 void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
560
561 /* r600_state.c */
562 struct pipe_sampler_view *
563 r600_create_sampler_view_custom(struct pipe_context *ctx,
564 struct pipe_resource *texture,
565 const struct pipe_sampler_view *state,
566 unsigned width_first_level, unsigned height_first_level);
567 void r600_init_state_functions(struct r600_context *rctx);
568 void r600_init_atom_start_cs(struct r600_context *rctx);
569 void r600_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
570 void r600_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
571 void r600_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
572 void r600_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
573 void *r600_create_db_flush_dsa(struct r600_context *rctx);
574 void *r600_create_resolve_blend(struct r600_context *rctx);
575 void *r700_create_resolve_blend(struct r600_context *rctx);
576 void *r600_create_decompress_blend(struct r600_context *rctx);
577 bool r600_adjust_gprs(struct r600_context *rctx);
578 boolean r600_is_format_supported(struct pipe_screen *screen,
579 enum pipe_format format,
580 enum pipe_texture_target target,
581 unsigned sample_count,
582 unsigned usage);
583 void r600_update_db_shader_control(struct r600_context * rctx);
584
585 /* r600_hw_context.c */
586 void r600_context_flush(struct r600_context *ctx, unsigned flags);
587 void r600_begin_new_cs(struct r600_context *ctx);
588 void r600_flush_emit(struct r600_context *ctx);
589 void r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
590 void r600_need_dma_space(struct r600_context *ctx, unsigned num_dw);
591 void r600_cp_dma_copy_buffer(struct r600_context *rctx,
592 struct pipe_resource *dst, uint64_t dst_offset,
593 struct pipe_resource *src, uint64_t src_offset,
594 unsigned size);
595 void evergreen_cp_dma_clear_buffer(struct r600_context *rctx,
596 struct pipe_resource *dst, uint64_t offset,
597 unsigned size, uint32_t clear_value);
598 void r600_dma_copy(struct r600_context *rctx,
599 struct pipe_resource *dst,
600 struct pipe_resource *src,
601 uint64_t dst_offset,
602 uint64_t src_offset,
603 uint64_t size);
604
605 /*
606 * evergreen_hw_context.c
607 */
608 void evergreen_dma_copy(struct r600_context *rctx,
609 struct pipe_resource *dst,
610 struct pipe_resource *src,
611 uint64_t dst_offset,
612 uint64_t src_offset,
613 uint64_t size);
614
615 /* r600_state_common.c */
616 void r600_init_common_state_functions(struct r600_context *rctx);
617 void r600_emit_cso_state(struct r600_context *rctx, struct r600_atom *atom);
618 void r600_emit_alphatest_state(struct r600_context *rctx, struct r600_atom *atom);
619 void r600_emit_blend_color(struct r600_context *rctx, struct r600_atom *atom);
620 void r600_emit_vgt_state(struct r600_context *rctx, struct r600_atom *atom);
621 void r600_emit_clip_misc_state(struct r600_context *rctx, struct r600_atom *atom);
622 void r600_emit_stencil_ref(struct r600_context *rctx, struct r600_atom *atom);
623 void r600_emit_viewport_state(struct r600_context *rctx, struct r600_atom *atom);
624 void r600_emit_shader(struct r600_context *rctx, struct r600_atom *a);
625 void r600_init_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id,
626 void (*emit)(struct r600_context *ctx, struct r600_atom *state),
627 unsigned num_dw);
628 void r600_vertex_buffers_dirty(struct r600_context *rctx);
629 void r600_sampler_views_dirty(struct r600_context *rctx,
630 struct r600_samplerview_state *state);
631 void r600_sampler_states_dirty(struct r600_context *rctx,
632 struct r600_sampler_states *state);
633 void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
634 void r600_draw_rectangle(struct blitter_context *blitter,
635 int x1, int y1, int x2, int y2, float depth,
636 enum blitter_attrib_type type, const union pipe_color_union *attrib);
637 uint32_t r600_translate_stencil_op(int s_op);
638 uint32_t r600_translate_fill(uint32_t func);
639 unsigned r600_tex_wrap(unsigned wrap);
640 unsigned r600_tex_filter(unsigned filter);
641 unsigned r600_tex_mipfilter(unsigned filter);
642 unsigned r600_tex_compare(unsigned compare);
643 bool sampler_state_needs_border_color(const struct pipe_sampler_state *state);
644 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
645 struct pipe_resource *texture,
646 const struct pipe_surface *templ,
647 unsigned width, unsigned height);
648 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
649 const unsigned char *swizzle_view,
650 boolean vtx);
651 uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
652 const unsigned char *swizzle_view,
653 uint32_t *word4_p, uint32_t *yuv_format_p);
654 uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format);
655 uint32_t r600_colorformat_endian_swap(uint32_t colorformat);
656
657 /* r600_uvd.c */
658 struct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context,
659 const struct pipe_video_codec *decoder);
660
661 struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
662 const struct pipe_video_buffer *tmpl);
663
664 /*
665 * Helpers for building command buffers
666 */
667
668 #define PKT3_SET_CONFIG_REG 0x68
669 #define PKT3_SET_CONTEXT_REG 0x69
670 #define PKT3_SET_CTL_CONST 0x6F
671 #define PKT3_SET_LOOP_CONST 0x6C
672
673 #define R600_CONFIG_REG_OFFSET 0x08000
674 #define R600_CONTEXT_REG_OFFSET 0x28000
675 #define R600_CTL_CONST_OFFSET 0x3CFF0
676 #define R600_LOOP_CONST_OFFSET 0X0003E200
677 #define EG_LOOP_CONST_OFFSET 0x0003A200
678
679 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
680 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
681 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
682 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
683 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
684
685 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
686
687 /*Evergreen Compute packet3*/
688 #define PKT3C(op, count, predicate) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count) | PKT3_PREDICATE(predicate) | RADEON_CP_PACKET3_COMPUTE_MODE)
689
690 static INLINE void r600_store_value(struct r600_command_buffer *cb, unsigned value)
691 {
692 cb->buf[cb->num_dw++] = value;
693 }
694
695 static INLINE void r600_store_array(struct r600_command_buffer *cb, unsigned num, unsigned *ptr)
696 {
697 assert(cb->num_dw+num <= cb->max_num_dw);
698 memcpy(&cb->buf[cb->num_dw], ptr, num * sizeof(ptr[0]));
699 cb->num_dw += num;
700 }
701
702 static INLINE void r600_store_config_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
703 {
704 assert(reg < R600_CONTEXT_REG_OFFSET);
705 assert(cb->num_dw+2+num <= cb->max_num_dw);
706 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
707 cb->buf[cb->num_dw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
708 }
709
710 /**
711 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
712 * shaders.
713 */
714 static INLINE void r600_store_context_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
715 {
716 assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
717 assert(cb->num_dw+2+num <= cb->max_num_dw);
718 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0) | cb->pkt_flags;
719 cb->buf[cb->num_dw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
720 }
721
722 /**
723 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
724 * shaders.
725 */
726 static INLINE void r600_store_ctl_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
727 {
728 assert(reg >= R600_CTL_CONST_OFFSET);
729 assert(cb->num_dw+2+num <= cb->max_num_dw);
730 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CTL_CONST, num, 0) | cb->pkt_flags;
731 cb->buf[cb->num_dw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
732 }
733
734 static INLINE void r600_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
735 {
736 assert(reg >= R600_LOOP_CONST_OFFSET);
737 assert(cb->num_dw+2+num <= cb->max_num_dw);
738 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0);
739 cb->buf[cb->num_dw++] = (reg - R600_LOOP_CONST_OFFSET) >> 2;
740 }
741
742 /**
743 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
744 * shaders.
745 */
746 static INLINE void eg_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
747 {
748 assert(reg >= EG_LOOP_CONST_OFFSET);
749 assert(cb->num_dw+2+num <= cb->max_num_dw);
750 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0) | cb->pkt_flags;
751 cb->buf[cb->num_dw++] = (reg - EG_LOOP_CONST_OFFSET) >> 2;
752 }
753
754 static INLINE void r600_store_config_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
755 {
756 r600_store_config_reg_seq(cb, reg, 1);
757 r600_store_value(cb, value);
758 }
759
760 static INLINE void r600_store_context_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
761 {
762 r600_store_context_reg_seq(cb, reg, 1);
763 r600_store_value(cb, value);
764 }
765
766 static INLINE void r600_store_ctl_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
767 {
768 r600_store_ctl_const_seq(cb, reg, 1);
769 r600_store_value(cb, value);
770 }
771
772 static INLINE void r600_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
773 {
774 r600_store_loop_const_seq(cb, reg, 1);
775 r600_store_value(cb, value);
776 }
777
778 static INLINE void eg_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
779 {
780 eg_store_loop_const_seq(cb, reg, 1);
781 r600_store_value(cb, value);
782 }
783
784 void r600_init_command_buffer(struct r600_command_buffer *cb, unsigned num_dw);
785 void r600_release_command_buffer(struct r600_command_buffer *cb);
786
787 static INLINE void r600_write_compute_context_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
788 {
789 r600_write_context_reg_seq(cs, reg, num);
790 /* Set the compute bit on the packet header */
791 cs->buf[cs->cdw - 2] |= RADEON_CP_PACKET3_COMPUTE_MODE;
792 }
793
794 static INLINE void r600_write_ctl_const_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
795 {
796 assert(reg >= R600_CTL_CONST_OFFSET);
797 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
798 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CTL_CONST, num, 0);
799 cs->buf[cs->cdw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
800 }
801
802 static INLINE void r600_write_compute_context_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
803 {
804 r600_write_compute_context_reg_seq(cs, reg, 1);
805 radeon_emit(cs, value);
806 }
807
808 static INLINE void r600_write_context_reg_flag(struct radeon_winsys_cs *cs, unsigned reg, unsigned value, unsigned flag)
809 {
810 if (flag & RADEON_CP_PACKET3_COMPUTE_MODE) {
811 r600_write_compute_context_reg(cs, reg, value);
812 } else {
813 r600_write_context_reg(cs, reg, value);
814 }
815 }
816
817 static INLINE void r600_write_ctl_const(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
818 {
819 r600_write_ctl_const_seq(cs, reg, 1);
820 radeon_emit(cs, value);
821 }
822
823 /*
824 * common helpers
825 */
826 static INLINE uint32_t S_FIXED(float value, uint32_t frac_bits)
827 {
828 return value * (1 << frac_bits);
829 }
830 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
831
832 static inline unsigned r600_tex_aniso_filter(unsigned filter)
833 {
834 if (filter <= 1) return 0;
835 if (filter <= 2) return 1;
836 if (filter <= 4) return 2;
837 if (filter <= 8) return 3;
838 /* else */ return 4;
839 }
840
841 /* 12.4 fixed-point */
842 static INLINE unsigned r600_pack_float_12p4(float x)
843 {
844 return x <= 0 ? 0 :
845 x >= 4096 ? 0xffff : x * 16;
846 }
847
848 /* Return if the depth format can be read without the DB->CB copy on r6xx-r7xx. */
849 static INLINE bool r600_can_read_depth(struct r600_texture *rtex)
850 {
851 return rtex->resource.b.b.nr_samples <= 1 &&
852 (rtex->resource.b.b.format == PIPE_FORMAT_Z16_UNORM ||
853 rtex->resource.b.b.format == PIPE_FORMAT_Z32_FLOAT);
854 }
855
856 #endif